blob: 41efac22ba6a396a43965e2cc4749f9b1194c35c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_pci.c
2 *
3 * Driver for Prism II devices that have a direct PCI interface
4 * (i.e., not in a Pcmcia or PLX bridge)
5 *
6 * Specifically here we're talking about the Linksys WMP11
7 *
8 * Current maintainers (as of 29 September 2003) are:
9 * Pavel Roskin <proski AT gnu.org>
10 * and David Gibson <hermes AT gibson.dropbear.id.au>
11 *
12 * Some of this code is borrowed from orinoco_plx.c
13 * Copyright (C) 2001 Daniel Barlow <dan AT telent.net>
14 * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
15 * has been copied from it. linux-wlan-ng-0.1.10 is originally :
16 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
17 * This file originally written by:
18 * Copyright (C) 2001 Jean Tourrilhes <jt AT hpl.hp.com>
19 * And is now maintained by:
20 * (C) Copyright David Gibson, IBM Corp. 2002-2003.
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
26 *
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
31 *
32 * Alternatively, the contents of this file may be used under the
33 * terms of the GNU General Public License version 2 (the "GPL"), in
34 * which case the provisions of the GPL are applicable instead of the
35 * above. If you wish to allow the use of your version of this file
36 * only under the terms of the GPL and not to allow others to use your
37 * version of this file under the MPL, indicate your decision by
38 * deleting the provisions above and replace them with the notice and
39 * other provisions required by the GPL. If you do not delete the
40 * provisions above, a recipient may use your version of this file
41 * under either the MPL or the GPL.
42 */
43
44/*
45 * Theory of operation...
46 * -------------------
47 * Maybe you had a look in orinoco_plx. Well, this is totally different...
48 *
49 * The card contains only one PCI region, which contains all the usual
50 * hermes registers.
51 *
52 * The driver will memory map this region in normal memory. Because
53 * the hermes registers are mapped in normal memory and not in ISA I/O
54 * post space, we can't use the usual inw/outw macros and we need to
55 * use readw/writew.
56 * This slight difference force us to compile our own version of
57 * hermes.c with the register access macro changed. That's a bit
58 * hackish but works fine.
59 *
60 * Note that the PCI region is pretty big (4K). That's much more than
61 * the usual set of hermes register (0x0 -> 0x3E). I've got a strong
62 * suspicion that the whole memory space of the adapter is in fact in
63 * this region. Accessing directly the adapter memory instead of going
64 * through the usual register would speed up significantely the
65 * operations...
66 *
67 * Finally, the card looks like this :
68-----------------------
69 Bus 0, device 14, function 0:
70 Network controller: PCI device 1260:3873 (Harris Semiconductor) (rev 1).
71 IRQ 11.
72 Master Capable. Latency=248.
73 Prefetchable 32 bit memory at 0xffbcc000 [0xffbccfff].
74-----------------------
7500:0e.0 Network controller: Harris Semiconductor: Unknown device 3873 (rev 01)
76 Subsystem: Unknown device 1737:3874
77 Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
78 Status: Cap+ 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
79 Latency: 248 set, cache line size 08
80 Interrupt: pin A routed to IRQ 11
81 Region 0: Memory at ffbcc000 (32-bit, prefetchable) [size=4K]
82 Capabilities: [dc] Power Management version 2
83 Flags: PMEClk- AuxPwr- DSI- D1+ D2+ PME+
84 Status: D0 PME-Enable- DSel=0 DScale=0 PME-
85-----------------------
86 *
87 * That's all..
88 *
89 * Jean II
90 */
91
92#define DRIVER_NAME "orinoco_pci"
93#define PFX DRIVER_NAME ": "
94
95#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#include <linux/module.h>
97#include <linux/kernel.h>
98#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -040099#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -0400103#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/* All the magic there is from wlan-ng */
106/* Magic offset of the reset register of the PCI card */
107#define HERMES_PCI_COR (0x26)
108/* Magic bitmask to reset the card */
109#define HERMES_PCI_COR_MASK (0x0080)
110/* Magic timeouts for doing the reset.
111 * Those times are straight from wlan-ng, and it is claimed that they
112 * are necessary. Alan will kill me. Take your time and grab a coffee. */
113#define HERMES_PCI_COR_ONT (250) /* ms */
114#define HERMES_PCI_COR_OFFT (500) /* ms */
115#define HERMES_PCI_COR_BUSYT (500) /* ms */
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/*
118 * Do a soft reset of the PCI card using the Configuration Option Register
119 * We need this to get going...
120 * This is the part of the code that is strongly inspired from wlan-ng
121 *
122 * Note : This code is done with irq enabled. This mean that many
123 * interrupts will occur while we are there. This is why we use the
124 * jiffies to regulate time instead of a straight mdelay(). Usually we
125 * need only around 245 iteration of the loop to do 250 ms delay.
126 *
127 * Note bis : Don't try to access HERMES_CMD during the reset phase.
128 * It just won't work !
129 */
Pavel Roskinb884c872006-04-07 04:10:57 -0400130static int orinoco_pci_cor_reset(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 hermes_t *hw = &priv->hw;
Pavel Roskinb884c872006-04-07 04:10:57 -0400133 unsigned long timeout;
134 u16 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* Assert the reset until the card notice */
137 hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
138 mdelay(HERMES_PCI_COR_ONT);
139
140 /* Give time for the card to recover from this hard effort */
141 hermes_write_regn(hw, PCI_COR, 0x0000);
142 mdelay(HERMES_PCI_COR_OFFT);
143
144 /* The card is ready when it's no longer busy */
145 timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
146 reg = hermes_read_regn(hw, CMD);
147 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
148 mdelay(1);
149 reg = hermes_read_regn(hw, CMD);
150 }
151
152 /* Still busy? */
153 if (reg & HERMES_CMD_BUSY) {
154 printk(KERN_ERR PFX "Busy timeout\n");
155 return -ETIMEDOUT;
156 }
157
158 return 0;
159}
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161static int orinoco_pci_init_one(struct pci_dev *pdev,
162 const struct pci_device_id *ent)
163{
Pavel Roskinb884c872006-04-07 04:10:57 -0400164 int err;
165 struct orinoco_private *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 struct orinoco_pci_card *card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400167 struct net_device *dev;
168 void __iomem *hermes_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 err = pci_enable_device(pdev);
171 if (err) {
172 printk(KERN_ERR PFX "Cannot enable PCI device\n");
173 return err;
174 }
175
176 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400177 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
179 goto fail_resources;
180 }
181
Pavel Roskinb884c872006-04-07 04:10:57 -0400182 hermes_io = pci_iomap(pdev, 0, 0);
183 if (!hermes_io) {
184 printk(KERN_ERR PFX "Cannot remap chipset registers\n");
Pavel Roskin3d529962006-04-07 04:10:53 -0400185 err = -EIO;
Pavel Roskinb884c872006-04-07 04:10:57 -0400186 goto fail_map_hermes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 /* Allocate network device */
190 dev = alloc_orinocodev(sizeof(*card), orinoco_pci_cor_reset);
Pavel Roskinb884c872006-04-07 04:10:57 -0400191 if (!dev) {
192 printk(KERN_ERR PFX "Cannot allocate network device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 err = -ENOMEM;
194 goto fail_alloc;
195 }
196
197 priv = netdev_priv(dev);
198 card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 SET_MODULE_OWNER(dev);
200 SET_NETDEV_DEV(dev, &pdev->dev);
201
Pavel Roskinb884c872006-04-07 04:10:57 -0400202 hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
205 dev->name, dev);
206 if (err) {
207 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
208 err = -EBUSY;
209 goto fail_irq;
210 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400211 orinoco_pci_setup_netdev(dev, pdev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 err = orinoco_pci_cor_reset(priv);
214 if (err) {
215 printk(KERN_ERR PFX "Initial reset failed\n");
216 goto fail;
217 }
218
219 err = register_netdev(dev);
220 if (err) {
Pavel Roskinb884c872006-04-07 04:10:57 -0400221 printk(KERN_ERR PFX "Cannot register network device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 goto fail;
223 }
224
225 pci_set_drvdata(pdev, dev);
226
227 return 0;
228
229 fail:
230 free_irq(pdev->irq, dev);
231
232 fail_irq:
233 pci_set_drvdata(pdev, NULL);
234 free_orinocodev(dev);
235
236 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400237 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Pavel Roskinb884c872006-04-07 04:10:57 -0400239 fail_map_hermes:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 pci_release_regions(pdev);
241
242 fail_resources:
243 pci_disable_device(pdev);
244
245 return err;
246}
247
248static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
249{
250 struct net_device *dev = pci_get_drvdata(pdev);
251 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 unregister_netdev(dev);
254 free_irq(dev->irq, dev);
255 pci_set_drvdata(pdev, NULL);
256 free_orinocodev(dev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400257 pci_iounmap(pdev, priv->hw.iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 pci_release_regions(pdev);
259 pci_disable_device(pdev);
260}
261
Pavel Roskinb884c872006-04-07 04:10:57 -0400262static struct pci_device_id orinoco_pci_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Intersil Prism 3 */
264 {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
265 /* Intersil Prism 2.5 */
266 {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
267 /* Samsung MagicLAN SWL-2210P */
268 {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
269 {0,},
270};
271
Pavel Roskinb884c872006-04-07 04:10:57 -0400272MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274static struct pci_driver orinoco_pci_driver = {
275 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400276 .id_table = orinoco_pci_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .probe = orinoco_pci_init_one,
278 .remove = __devexit_p(orinoco_pci_remove_one),
279 .suspend = orinoco_pci_suspend,
280 .resume = orinoco_pci_resume,
281};
282
283static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
284 " (Pavel Roskin <proski@gnu.org>,"
285 " David Gibson <hermes@gibson.dropbear.id.au> &"
286 " Jean Tourrilhes <jt@hpl.hp.com>)";
287MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
288MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
289MODULE_LICENSE("Dual MPL/GPL");
290
291static int __init orinoco_pci_init(void)
292{
293 printk(KERN_DEBUG "%s\n", version);
294 return pci_module_init(&orinoco_pci_driver);
295}
296
297static void __exit orinoco_pci_exit(void)
298{
299 pci_unregister_driver(&orinoco_pci_driver);
300}
301
302module_init(orinoco_pci_init);
303module_exit(orinoco_pci_exit);
304
305/*
306 * Local variables:
307 * c-indent-level: 8
308 * c-basic-offset: 8
309 * tab-width: 8
310 * End:
311 */