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/fcntl.h>
107 #include <asm/uaccess.h>
109 #include <asm/system.h>
114 /* All the magic there is from wlan-ng */
115 /* Magic offset of the reset register of the PCI card */
116 #define HERMES_PCI_COR (0x26)
117 /* Magic bitmask to reset the card */
118 #define HERMES_PCI_COR_MASK (0x0080)
119 /* Magic timeouts for doing the reset.
120 * Those times are straight from wlan-ng, and it is claimed that they
121 * are necessary. Alan will kill me. Take your time and grab a coffee. */
122 #define HERMES_PCI_COR_ONT (250) /* ms */
123 #define HERMES_PCI_COR_OFFT (500) /* ms */
124 #define HERMES_PCI_COR_BUSYT (500) /* ms */
127 * Do a soft reset of the PCI card using the Configuration Option Register
128 * We need this to get going...
129 * This is the part of the code that is strongly inspired from wlan-ng
131 * Note : This code is done with irq enabled. This mean that many
132 * interrupts will occur while we are there. This is why we use the
133 * jiffies to regulate time instead of a straight mdelay(). Usually we
134 * need only around 245 iteration of the loop to do 250 ms delay.
136 * Note bis : Don't try to access HERMES_CMD during the reset phase.
137 * It just won't work !
140 orinoco_pci_cor_reset(struct orinoco_private *priv)
142 hermes_t *hw = &priv->hw;
143 unsigned long timeout;
146 /* Assert the reset until the card notice */
147 hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
148 printk(KERN_NOTICE "Reset done");
149 timeout = jiffies + (HERMES_PCI_COR_ONT * HZ / 1000);
150 while(time_before(jiffies, timeout)) {
155 //mdelay(HERMES_PCI_COR_ONT);
157 /* Give time for the card to recover from this hard effort */
158 hermes_write_regn(hw, PCI_COR, 0x0000);
159 printk(KERN_NOTICE "Clear Reset");
160 timeout = jiffies + (HERMES_PCI_COR_OFFT * HZ / 1000);
161 while(time_before(jiffies, timeout)) {
166 //mdelay(HERMES_PCI_COR_OFFT);
168 /* The card is ready when it's no longer busy */
169 timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
170 reg = hermes_read_regn(hw, CMD);
171 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
173 reg = hermes_read_regn(hw, CMD);
175 /* Did we timeout ? */
176 if(time_after_eq(jiffies, timeout)) {
177 printk(KERN_ERR "orinoco_pci: Busy timeout\n");
180 printk(KERN_NOTICE "pci_cor : reg = 0x%X - %lX - %lX\n", reg, timeout, jiffies);
186 * Initialise a card. Mostly similar to PLX code.
188 static int orinoco_pci_init_one(struct pci_dev *pdev,
189 const struct pci_device_id *ent)
192 unsigned long pci_iorange;
193 u16 *pci_ioaddr = NULL;
194 unsigned long pci_iolen;
195 struct orinoco_private *priv = NULL;
196 struct net_device *dev = NULL;
198 err = pci_enable_device(pdev);
202 /* Resource 0 is mapped to the hermes registers */
203 pci_iorange = pci_resource_start(pdev, 0);
204 pci_iolen = pci_resource_len(pdev, 0);
205 pci_ioaddr = ioremap(pci_iorange, pci_iolen);
209 /* Usual setup of structures */
210 dev = alloc_orinocodev(0, NULL);
217 dev->base_addr = (unsigned long) pci_ioaddr;
218 dev->mem_start = pci_iorange;
219 dev->mem_end = pci_iorange + pci_iolen - 1;
221 SET_MODULE_OWNER(dev);
222 SET_NETDEV_DEV(dev, &pdev->dev);
225 "Detected Orinoco/Prism2 PCI device at %s, mem:0x%lX to 0x%lX -> 0x%p, irq:%d\n",
226 pci_name(pdev), dev->mem_start, dev->mem_end, pci_ioaddr, pdev->irq);
228 hermes_struct_init(&priv->hw, dev->base_addr,
229 HERMES_MEM, HERMES_32BIT_REGSPACING);
230 pci_set_drvdata(pdev, dev);
232 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
235 printk(KERN_ERR "orinoco_pci: Error allocating IRQ %d.\n",
240 dev->irq = pdev->irq;
241 /* Perform a COR reset to start the card */
242 if(orinoco_pci_cor_reset(priv) != 0) {
243 printk(KERN_ERR "%s: Failed to start the card\n", dev->name);
248 /* Override the normal firmware detection - the Prism 2.5 PCI
249 * cards look like Lucent firmware but are actually Intersil */
250 priv->firmware_type = FIRMWARE_TYPE_INTERSIL;
252 err = register_netdev(dev);
254 printk(KERN_ERR "%s: Failed to register net device\n", dev->name);
258 return 0; /* succeeded */
262 free_irq(dev->irq, dev);
270 pci_disable_device(pdev);
275 static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
277 struct net_device *dev = pci_get_drvdata(pdev);
278 struct orinoco_private *priv = dev->priv;
280 unregister_netdev(dev);
283 free_irq(dev->irq, dev);
286 iounmap((unsigned char *) priv->hw.iobase);
288 pci_set_drvdata(pdev, NULL);
291 pci_disable_device(pdev);
294 static int orinoco_pci_suspend(struct pci_dev *pdev, u32 state)
296 struct net_device *dev = pci_get_drvdata(pdev);
297 struct orinoco_private *priv = dev->priv;
301 printk(KERN_DEBUG "%s: Orinoco-PCI entering sleep mode (state=%d)\n",
304 err = orinoco_lock(priv, &flags);
306 printk(KERN_ERR "%s: hw_unavailable on orinoco_pci_suspend\n",
311 err = __orinoco_down(dev);
313 printk(KERN_WARNING "%s: orinoco_pci_suspend(): Error %d downing interface\n",
316 netif_device_detach(dev);
318 priv->hw_unavailable++;
320 orinoco_unlock(priv, &flags);
325 static int orinoco_pci_resume(struct pci_dev *pdev)
327 struct net_device *dev = pci_get_drvdata(pdev);
328 struct orinoco_private *priv = dev->priv;
332 printk(KERN_DEBUG "%s: Orinoco-PCI waking up\n", dev->name);
334 err = orinoco_reinit_firmware(dev);
336 printk(KERN_ERR "%s: Error %d re-initializing firmware on orinoco_pci_resume()\n",
341 spin_lock_irqsave(&priv->lock, flags);
343 netif_device_attach(dev);
345 priv->hw_unavailable--;
347 if (priv->open && (! priv->hw_unavailable)) {
348 err = __orinoco_up(dev);
350 printk(KERN_ERR "%s: Error %d restarting card on orinoco_pci_resume()\n",
354 spin_unlock_irqrestore(&priv->lock, flags);
359 static struct pci_device_id orinoco_pci_pci_id_table[] = {
360 {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
361 {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
365 MODULE_DEVICE_TABLE(pci, orinoco_pci_pci_id_table);
367 static struct pci_driver orinoco_pci_driver = {
368 .name = "orinoco_pci",
369 .id_table = orinoco_pci_pci_id_table,
370 .probe = orinoco_pci_init_one,
371 .remove = __devexit_p(orinoco_pci_remove_one),
372 .suspend = orinoco_pci_suspend,
373 .resume = orinoco_pci_resume,
376 static char version[] __initdata = "orinoco_pci.c 0.13e (David Gibson <hermes@gibson.dropbear.id.au> & Jean Tourrilhes <jt@hpl.hp.com>)";
377 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
378 MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
379 MODULE_LICENSE("Dual MPL/GPL");
381 static int __init orinoco_pci_init(void)
383 printk(KERN_DEBUG "%s\n", version);
384 return pci_module_init(&orinoco_pci_driver);
387 void __exit orinoco_pci_exit(void)
389 pci_unregister_driver(&orinoco_pci_driver);
392 module_init(orinoco_pci_init);
393 module_exit(orinoco_pci_exit);