3 * Driver for Prism II devices that have a direct PCI interface
4 * (i.e., not in a Pcmcia or PLX bridge)
6 * Specifically here we're talking about the Linksys WMP11
8 * Some of this code is borrowed from orinoco_plx.c
9 * Copyright (C) 2001 Daniel Barlow <dan@telent.net>
10 * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
11 * has been copied from it. linux-wlan-ng-0.1.10 is originally :
12 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
13 * This file originally written by:
14 * Copyright (C) 2001 Jean Tourrilhes <jt@hpl.hp.com>
15 * And is now maintained by:
16 * Copyright (C) 2002 David Gibson, IBM Corporation <herme@gibson.dropbear.id.au>
18 * The contents of this file are subject to the Mozilla Public License
19 * Version 1.1 (the "License"); you may not use this file except in
20 * compliance with the License. You may obtain a copy of the License
21 * at http://www.mozilla.org/MPL/
23 * Software distributed under the License is distributed on an "AS IS"
24 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
25 * the License for the specific language governing rights and
26 * limitations under the License.
28 * Alternatively, the contents of this file may be used under the
29 * terms of the GNU General Public License version 2 (the "GPL"), in
30 * which case the provisions of the GPL are applicable instead of the
31 * above. If you wish to allow the use of your version of this file
32 * only under the terms of the GPL and not to allow others to use your
33 * version of this file under the MPL, indicate your decision by
34 * deleting the provisions above and replace them with the notice and
35 * other provisions required by the GPL. If you do not delete the
36 * provisions above, a recipient may use your version of this file
37 * under either the MPL or the GPL.
41 * Theory of operation...
43 * Maybe you had a look in orinoco_plx. Well, this is totally different...
45 * The card contains only one PCI region, which contains all the usual
48 * The driver will memory map this region in normal memory. Because
49 * the hermes registers are mapped in normal memory and not in ISA I/O
50 * post space, we can't use the usual inw/outw macros and we need to
52 * This slight difference force us to compile our own version of
53 * hermes.c with the register access macro changed. That's a bit
54 * hackish but works fine.
56 * Note that the PCI region is pretty big (4K). That's much more than
57 * the usual set of hermes register (0x0 -> 0x3E). I've got a strong
58 * suspicion that the whole memory space of the adapter is in fact in
59 * this region. Accessing directly the adapter memory instead of going
60 * through the usual register would speed up significantely the
63 * Finally, the card looks like this :
64 -----------------------
65 Bus 0, device 14, function 0:
66 Network controller: PCI device 1260:3873 (Harris Semiconductor) (rev 1).
68 Master Capable. Latency=248.
69 Prefetchable 32 bit memory at 0xffbcc000 [0xffbccfff].
70 -----------------------
71 00:0e.0 Network controller: Harris Semiconductor: Unknown device 3873 (rev 01)
72 Subsystem: Unknown device 1737:3874
73 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
74 Status: Cap+ 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
75 Latency: 248 set, cache line size 08
76 Interrupt: pin A routed to IRQ 11
77 Region 0: Memory at ffbcc000 (32-bit, prefetchable) [size=4K]
78 Capabilities: [dc] Power Management version 2
79 Flags: PMEClk- AuxPwr- DSI- D1+ D2+ PME+
80 Status: D0 PME-Enable- DSel=0 DScale=0 PME-
81 -----------------------
88 #include <linux/config.h>
90 #include <linux/module.h>
91 #include <linux/kernel.h>
92 #include <linux/init.h>
93 #include <linux/sched.h>
94 #include <linux/ptrace.h>
95 #include <linux/slab.h>
96 #include <linux/string.h>
97 #include <linux/timer.h>
98 #include <linux/ioport.h>
99 #include <linux/netdevice.h>
100 #include <linux/if_arp.h>
101 #include <linux/etherdevice.h>
102 #include <linux/wireless.h>
103 #include <linux/list.h>
104 #include <linux/pci.h>
105 #include <linux/wireless.h>
106 #include <linux/fcntl.h>
108 #include <asm/uaccess.h>
110 #include <asm/system.h>
115 /* All the magic there is from wlan-ng */
116 /* Magic offset of the reset register of the PCI card */
117 #define HERMES_PCI_COR (0x26)
118 /* Magic bitmask to reset the card */
119 #define HERMES_PCI_COR_MASK (0x0080)
120 /* Magic timeouts for doing the reset.
121 * Those times are straight from wlan-ng, and it is claimed that they
122 * are necessary. Alan will kill me. Take your time and grab a coffee. */
123 #define HERMES_PCI_COR_ONT (250) /* ms */
124 #define HERMES_PCI_COR_OFFT (500) /* ms */
125 #define HERMES_PCI_COR_BUSYT (500) /* ms */
128 * Do a soft reset of the PCI card using the Configuration Option Register
129 * We need this to get going...
130 * This is the part of the code that is strongly inspired from wlan-ng
132 * Note : This code is done with irq enabled. This mean that many
133 * interrupts will occur while we are there. This is why we use the
134 * jiffies to regulate time instead of a straight mdelay(). Usually we
135 * need only around 245 iteration of the loop to do 250 ms delay.
137 * Note bis : Don't try to access HERMES_CMD during the reset phase.
138 * It just won't work !
141 orinoco_pci_cor_reset(struct orinoco_private *priv)
143 hermes_t *hw = &priv->hw;
144 unsigned long timeout;
147 /* Assert the reset until the card notice */
148 hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
149 printk(KERN_NOTICE "Reset done");
150 timeout = jiffies + (HERMES_PCI_COR_ONT * HZ / 1000);
151 while(time_before(jiffies, timeout)) {
156 //mdelay(HERMES_PCI_COR_ONT);
158 /* Give time for the card to recover from this hard effort */
159 hermes_write_regn(hw, PCI_COR, 0x0000);
160 printk(KERN_NOTICE "Clear Reset");
161 timeout = jiffies + (HERMES_PCI_COR_OFFT * HZ / 1000);
162 while(time_before(jiffies, timeout)) {
167 //mdelay(HERMES_PCI_COR_OFFT);
169 /* The card is ready when it's no longer busy */
170 timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
171 reg = hermes_read_regn(hw, CMD);
172 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
174 reg = hermes_read_regn(hw, CMD);
176 /* Did we timeout ? */
177 if(time_after_eq(jiffies, timeout)) {
178 printk(KERN_ERR "orinoco_pci: Busy timeout\n");
181 printk(KERN_NOTICE "pci_cor : reg = 0x%X - %lX - %lX\n", reg, timeout, jiffies);
187 * Initialise a card. Mostly similar to PLX code.
189 static int orinoco_pci_init_one(struct pci_dev *pdev,
190 const struct pci_device_id *ent)
193 unsigned long pci_iorange;
194 u16 *pci_ioaddr = NULL;
195 unsigned long pci_iolen;
196 struct orinoco_private *priv = NULL;
197 struct net_device *dev = NULL;
199 err = pci_enable_device(pdev);
203 /* Resource 0 is mapped to the hermes registers */
204 pci_iorange = pci_resource_start(pdev, 0);
205 pci_iolen = pci_resource_len(pdev, 0);
206 pci_ioaddr = ioremap(pci_iorange, pci_iolen);
210 /* Usual setup of structures */
211 dev = alloc_orinocodev(0, NULL);
218 dev->base_addr = (unsigned long) pci_ioaddr;
219 dev->mem_start = pci_iorange;
220 dev->mem_end = pci_iorange + pci_iolen - 1;
222 SET_MODULE_OWNER(dev);
223 SET_NETDEV_DEV(dev, &pdev->dev);
226 "Detected Orinoco/Prism2 PCI device at %s, mem:0x%lX to 0x%lX -> 0x%p, irq:%d\n",
227 pci_name(pdev), dev->mem_start, dev->mem_end, pci_ioaddr, pdev->irq);
229 hermes_struct_init(&priv->hw, dev->base_addr,
230 HERMES_MEM, HERMES_32BIT_REGSPACING);
231 pci_set_drvdata(pdev, dev);
233 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
236 printk(KERN_ERR "orinoco_pci: Error allocating IRQ %d.\n",
241 dev->irq = pdev->irq;
242 /* Perform a COR reset to start the card */
243 if(orinoco_pci_cor_reset(priv) != 0) {
244 printk(KERN_ERR "%s: Failed to start the card\n", dev->name);
249 /* Override the normal firmware detection - the Prism 2.5 PCI
250 * cards look like Lucent firmware but are actually Intersil */
251 priv->firmware_type = FIRMWARE_TYPE_INTERSIL;
253 err = register_netdev(dev);
255 printk(KERN_ERR "%s: Failed to register net device\n", dev->name);
259 return 0; /* succeeded */
263 free_irq(dev->irq, dev);
271 pci_disable_device(pdev);
276 static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
278 struct net_device *dev = pci_get_drvdata(pdev);
279 struct orinoco_private *priv = dev->priv;
281 unregister_netdev(dev);
284 free_irq(dev->irq, dev);
287 iounmap((unsigned char *) priv->hw.iobase);
289 pci_set_drvdata(pdev, NULL);
292 pci_disable_device(pdev);
295 static int orinoco_pci_suspend(struct pci_dev *pdev, u32 state)
297 struct net_device *dev = pci_get_drvdata(pdev);
298 struct orinoco_private *priv = dev->priv;
302 printk(KERN_DEBUG "%s: Orinoco-PCI entering sleep mode (state=%d)\n",
305 err = orinoco_lock(priv, &flags);
307 printk(KERN_ERR "%s: hw_unavailable on orinoco_pci_suspend\n",
312 err = __orinoco_down(dev);
314 printk(KERN_WARNING "%s: orinoco_pci_suspend(): Error %d downing interface\n",
317 netif_device_detach(dev);
319 priv->hw_unavailable++;
321 orinoco_unlock(priv, &flags);
326 static int orinoco_pci_resume(struct pci_dev *pdev)
328 struct net_device *dev = pci_get_drvdata(pdev);
329 struct orinoco_private *priv = dev->priv;
333 printk(KERN_DEBUG "%s: Orinoco-PCI waking up\n", dev->name);
335 err = orinoco_reinit_firmware(dev);
337 printk(KERN_ERR "%s: Error %d re-initializing firmware on orinoco_pci_resume()\n",
342 spin_lock_irqsave(&priv->lock, flags);
344 netif_device_attach(dev);
346 priv->hw_unavailable--;
348 if (priv->open && (! priv->hw_unavailable)) {
349 err = __orinoco_up(dev);
351 printk(KERN_ERR "%s: Error %d restarting card on orinoco_pci_resume()\n",
355 spin_unlock_irqrestore(&priv->lock, flags);
360 static struct pci_device_id orinoco_pci_pci_id_table[] = {
361 {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
362 {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
366 MODULE_DEVICE_TABLE(pci, orinoco_pci_pci_id_table);
368 static struct pci_driver orinoco_pci_driver = {
369 .name = "orinoco_pci",
370 .id_table = orinoco_pci_pci_id_table,
371 .probe = orinoco_pci_init_one,
372 .remove = __devexit_p(orinoco_pci_remove_one),
373 .suspend = orinoco_pci_suspend,
374 .resume = orinoco_pci_resume,
377 static char version[] __initdata = "orinoco_pci.c 0.13e (David Gibson <hermes@gibson.dropbear.id.au> & Jean Tourrilhes <jt@hpl.hp.com>)";
378 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
379 MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
380 MODULE_LICENSE("Dual MPL/GPL");
382 static int __init orinoco_pci_init(void)
384 printk(KERN_DEBUG "%s\n", version);
385 return pci_module_init(&orinoco_pci_driver);
388 extern void __exit orinoco_pci_exit(void)
390 pci_unregister_driver(&orinoco_pci_driver);
393 module_init(orinoco_pci_init);
394 module_exit(orinoco_pci_exit);