blob: c00388ec9460ff4385dfcec5e989da33e199dbf7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco_plx.c
2 *
3 * Driver for Prism II devices which would usually be driven by orinoco_cs,
4 * but are connected to the PCI bus by a PLX9052.
5 *
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
9 *
10 * (C) Copyright David Gibson, IBM Corp. 2001-2003.
11 * Copyright (C) 2001 Daniel Barlow
12 *
13 * The contents of this file are subject to the Mozilla Public License
14 * Version 1.1 (the "License"); you may not use this file except in
15 * compliance with the License. You may obtain a copy of the License
16 * at http://www.mozilla.org/MPL/
17 *
18 * Software distributed under the License is distributed on an "AS IS"
19 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
20 * the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU General Public License version 2 (the "GPL"), in
25 * which case the provisions of the GPL are applicable instead of the
26 * above. If you wish to allow the use of your version of this file
27 * only under the terms of the GPL and not to allow others to use your
28 * version of this file under the MPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice and
30 * other provisions required by the GPL. If you do not delete the
31 * provisions above, a recipient may use your version of this file
32 * under either the MPL or the GPL.
33
34 * Caution: this is experimental and probably buggy. For success and
35 * failure reports for different cards and adaptors, see
Pavel Roskinb884c872006-04-07 04:10:57 -040036 * orinoco_plx_id_table near the end of the file. If you have a
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 * card we don't have the PCI id for, and looks like it should work,
38 * drop me mail with the id and "it works"/"it doesn't work".
39 *
40 * Note: if everything gets detected fine but it doesn't actually send
41 * or receive packets, your first port of call should probably be to
42 * try newer firmware in the card. Especially if you're doing Ad-Hoc
43 * modes.
44 *
45 * The actual driving is done by orinoco.c, this is just resource
46 * allocation stuff. The explanation below is courtesy of Ryan Niemi
47 * on the linux-wlan-ng list at
48 * http://archives.neohapsis.com/archives/dev/linux-wlan/2001-q1/0026.html
49 *
50 * The PLX9052-based cards (WL11000 and several others) are a
51 * different beast than the usual PCMCIA-based PRISM2 configuration
52 * expected by wlan-ng. Here's the general details on how the WL11000
53 * PCI adapter works:
54 *
55 * - Two PCI I/O address spaces, one 0x80 long which contains the
56 * PLX9052 registers, and one that's 0x40 long mapped to the PCMCIA
57 * slot I/O address space.
58 *
59 * - One PCI memory address space, mapped to the PCMCIA memory space
60 * (containing the CIS).
61 *
62 * After identifying the I/O and memory space, you can read through
63 * the memory space to confirm the CIS's device ID or manufacturer ID
64 * to make sure it's the expected card. qKeep in mind that the PCMCIA
65 * spec specifies the CIS as the lower 8 bits of each word read from
66 * the CIS, so to read the bytes of the CIS, read every other byte
67 * (0,2,4,...). Passing that test, you need to enable the I/O address
68 * space on the PCMCIA card via the PCMCIA COR register. This is the
69 * first byte following the CIS. In my case (which may not have any
70 * relation to what's on the PRISM2 cards), COR was at offset 0x800
71 * within the PCI memory space. Write 0x41 to the COR register to
72 * enable I/O mode and to select level triggered interrupts. To
73 * confirm you actually succeeded, read the COR register back and make
74 * sure it actually got set to 0x41, incase you have an unexpected
75 * card inserted.
76 *
77 * Following that, you can treat the second PCI I/O address space (the
78 * one that's not 0x80 in length) as the PCMCIA I/O space.
79 *
80 * Note that in the Eumitcom's source for their drivers, they register
81 * the interrupt as edge triggered when registering it with the
82 * Windows kernel. I don't recall how to register edge triggered on
83 * Linux (if it can be done at all). But in some experimentation, I
84 * don't see much operational difference between using either
85 * interrupt mode. Don't mess with the interrupt mode in the COR
86 * register though, as the PLX9052 wants level triggers with the way
87 * the serial EEPROM configures it on the WL11000.
88 *
89 * There's some other little quirks related to timing that I bumped
90 * into, but I don't recall right now. Also, there's two variants of
91 * the WL11000 I've seen, revision A1 and T2. These seem to differ
92 * slightly in the timings configured in the wait-state generator in
93 * the PLX9052. There have also been some comments from Eumitcom that
94 * cards shouldn't be hot swapped, apparently due to risk of cooking
95 * the PLX9052. I'm unsure why they believe this, as I can't see
96 * anything in the design that would really cause a problem, except
97 * for crashing drivers not written to expect it. And having developed
98 * drivers for the WL11000, I'd say it's quite tricky to write code
99 * that will successfully deal with a hot unplug. Very odd things
100 * happen on the I/O side of things. But anyway, be warned. Despite
101 * that, I've hot-swapped a number of times during debugging and
102 * driver development for various reasons (stuck WAIT# line after the
103 * radio card's firmware locks up).
104 *
105 * Hope this is enough info for someone to add PLX9052 support to the
106 * wlan-ng card. In the case of the WL11000, the PCI ID's are
107 * 0x1639/0x0200, with matching subsystem ID's. Other PLX9052-based
108 * manufacturers other than Eumitcom (or on cards other than the
109 * WL11000) may have different PCI ID's.
110 *
111 * If anyone needs any more specific info, let me know. I haven't had
112 * time to implement support myself yet, and with the way things are
113 * going, might not have time for a while..
114 */
115
116#define DRIVER_NAME "orinoco_plx"
117#define PFX DRIVER_NAME ": "
118
119#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#include <linux/module.h>
121#include <linux/kernel.h>
122#include <linux/init.h>
Pavel Roskinef846bf2005-09-23 04:18:07 -0400123#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#include <pcmcia/cisreg.h>
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#include "orinoco.h"
Pavel Roskinb884c872006-04-07 04:10:57 -0400128#include "orinoco_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130#define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */
131#define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
132#define COR_RESET (0x80) /* reset bit in the COR register */
133#define PLX_RESET_TIME (500) /* milliseconds */
134
135#define PLX_INTCSR 0x4c /* Interrupt Control & Status Register */
136#define PLX_INTCSR_INTEN (1<<6) /* Interrupt Enable bit */
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*
139 * Do a soft reset of the card using the Configuration Option Register
140 */
141static int orinoco_plx_cor_reset(struct orinoco_private *priv)
142{
143 hermes_t *hw = &priv->hw;
Pavel Roskinb884c872006-04-07 04:10:57 -0400144 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 unsigned long timeout;
146 u16 reg;
147
Pavel Roskinb884c872006-04-07 04:10:57 -0400148 iowrite8(COR_VALUE | COR_RESET, card->attr_io + COR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 mdelay(1);
150
Pavel Roskinb884c872006-04-07 04:10:57 -0400151 iowrite8(COR_VALUE, card->attr_io + COR_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 mdelay(1);
153
154 /* Just in case, wait more until the card is no longer busy */
155 timeout = jiffies + (PLX_RESET_TIME * HZ / 1000);
156 reg = hermes_read_regn(hw, CMD);
157 while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
158 mdelay(1);
159 reg = hermes_read_regn(hw, CMD);
160 }
161
Pavel Roskinb884c872006-04-07 04:10:57 -0400162 /* Still busy? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (reg & HERMES_CMD_BUSY) {
164 printk(KERN_ERR PFX "Busy timeout\n");
165 return -ETIMEDOUT;
166 }
167
168 return 0;
169}
170
Pavel Roskinb884c872006-04-07 04:10:57 -0400171static int orinoco_plx_hw_init(struct orinoco_pci_card *card)
172{
173 int i;
174 u32 csr_reg;
175 static const u8 cis_magic[] = {
176 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67
177 };
178
179 printk(KERN_DEBUG PFX "CIS: ");
180 for (i = 0; i < 16; i++) {
181 printk("%02X:", ioread8(card->attr_io + (i << 1)));
182 }
183 printk("\n");
184
185 /* Verify whether a supported PC card is present */
186 /* FIXME: we probably need to be smarted about this */
187 for (i = 0; i < sizeof(cis_magic); i++) {
188 if (cis_magic[i] != ioread8(card->attr_io + (i << 1))) {
189 printk(KERN_ERR PFX "The CIS value of Prism2 PC "
190 "card is unexpected\n");
191 return -ENODEV;
192 }
193 }
194
195 /* bjoern: We need to tell the card to enable interrupts, in
196 case the serial eprom didn't do this already. See the
197 PLX9052 data book, p8-1 and 8-24 for reference. */
198 csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
199 if (!(csr_reg & PLX_INTCSR_INTEN)) {
200 csr_reg |= PLX_INTCSR_INTEN;
201 iowrite32(csr_reg, card->bridge_io + PLX_INTCSR);
202 csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
203 if (!(csr_reg & PLX_INTCSR_INTEN)) {
204 printk(KERN_ERR PFX "Cannot enable interrupts\n");
205 return -EIO;
206 }
207 }
208
209 return 0;
210}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212static int orinoco_plx_init_one(struct pci_dev *pdev,
213 const struct pci_device_id *ent)
214{
Pavel Roskinb884c872006-04-07 04:10:57 -0400215 int err;
216 struct orinoco_private *priv;
217 struct orinoco_pci_card *card;
218 struct net_device *dev;
219 void __iomem *hermes_io, *attr_io, *bridge_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 err = pci_enable_device(pdev);
222 if (err) {
223 printk(KERN_ERR PFX "Cannot enable PCI device\n");
224 return err;
225 }
226
227 err = pci_request_regions(pdev, DRIVER_NAME);
Pavel Roskinb884c872006-04-07 04:10:57 -0400228 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
230 goto fail_resources;
231 }
232
Pavel Roskinb884c872006-04-07 04:10:57 -0400233 bridge_io = pci_iomap(pdev, 1, 0);
234 if (!bridge_io) {
235 printk(KERN_ERR PFX "Cannot map bridge registers\n");
236 err = -EIO;
237 goto fail_map_bridge;
238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Pavel Roskinb884c872006-04-07 04:10:57 -0400240 attr_io = pci_iomap(pdev, 2, 0);
241 if (!attr_io) {
242 printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
243 err = -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 goto fail_map_attr;
245 }
246
Pavel Roskinb884c872006-04-07 04:10:57 -0400247 hermes_io = pci_iomap(pdev, 3, 0);
248 if (!hermes_io) {
249 printk(KERN_ERR PFX "Cannot map chipset registers\n");
250 err = -EIO;
251 goto fail_map_hermes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253
254 /* Allocate network device */
255 dev = alloc_orinocodev(sizeof(*card), orinoco_plx_cor_reset);
256 if (!dev) {
257 printk(KERN_ERR PFX "Cannot allocate network device\n");
258 err = -ENOMEM;
259 goto fail_alloc;
260 }
261
262 priv = netdev_priv(dev);
263 card = priv->card;
Pavel Roskinb884c872006-04-07 04:10:57 -0400264 card->bridge_io = bridge_io;
265 card->attr_io = attr_io;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 SET_MODULE_OWNER(dev);
267 SET_NETDEV_DEV(dev, &pdev->dev);
268
Pavel Roskinb884c872006-04-07 04:10:57 -0400269 hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
272 dev->name, dev);
273 if (err) {
274 printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
275 err = -EBUSY;
276 goto fail_irq;
277 }
Pavel Roskinb884c872006-04-07 04:10:57 -0400278 orinoco_pci_setup_netdev(dev, pdev, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Pavel Roskinb884c872006-04-07 04:10:57 -0400280 err = orinoco_plx_hw_init(card);
281 if (err) {
282 printk(KERN_ERR PFX "Hardware initialization failed\n");
283 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 err = orinoco_plx_cor_reset(priv);
287 if (err) {
288 printk(KERN_ERR PFX "Initial reset failed\n");
289 goto fail;
290 }
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 err = register_netdev(dev);
293 if (err) {
294 printk(KERN_ERR PFX "Cannot register network device\n");
295 goto fail;
296 }
297
298 pci_set_drvdata(pdev, dev);
299
300 return 0;
301
302 fail:
303 free_irq(pdev->irq, dev);
304
305 fail_irq:
306 pci_set_drvdata(pdev, NULL);
307 free_orinocodev(dev);
308
309 fail_alloc:
Pavel Roskinb884c872006-04-07 04:10:57 -0400310 pci_iounmap(pdev, hermes_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Pavel Roskinb884c872006-04-07 04:10:57 -0400312 fail_map_hermes:
313 pci_iounmap(pdev, attr_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 fail_map_attr:
Pavel Roskinb884c872006-04-07 04:10:57 -0400316 pci_iounmap(pdev, bridge_io);
317
318 fail_map_bridge:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 pci_release_regions(pdev);
320
321 fail_resources:
322 pci_disable_device(pdev);
323
324 return err;
325}
326
327static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev)
328{
329 struct net_device *dev = pci_get_drvdata(pdev);
330 struct orinoco_private *priv = netdev_priv(dev);
Pavel Roskinb884c872006-04-07 04:10:57 -0400331 struct orinoco_pci_card *card = priv->card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 unregister_netdev(dev);
334 free_irq(dev->irq, dev);
335 pci_set_drvdata(pdev, NULL);
336 free_orinocodev(dev);
337 pci_iounmap(pdev, priv->hw.iobase);
Pavel Roskinb884c872006-04-07 04:10:57 -0400338 pci_iounmap(pdev, card->attr_io);
339 pci_iounmap(pdev, card->bridge_io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 pci_release_regions(pdev);
341 pci_disable_device(pdev);
342}
343
Pavel Roskinb884c872006-04-07 04:10:57 -0400344static struct pci_device_id orinoco_plx_id_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 {0x111a, 0x1023, PCI_ANY_ID, PCI_ANY_ID,}, /* Siemens SpeedStream SS1023 */
346 {0x1385, 0x4100, PCI_ANY_ID, PCI_ANY_ID,}, /* Netgear MA301 */
347 {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,}, /* Correga - does this work? */
348 {0x1638, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* SMC EZConnect SMC2602W,
349 Eumitcom PCI WL11000,
350 Addtron AWA-100 */
351 {0x16ab, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* Global Sun Tech GL24110P */
352 {0x16ab, 0x1101, PCI_ANY_ID, PCI_ANY_ID,}, /* Reported working, but unknown */
353 {0x16ab, 0x1102, PCI_ANY_ID, PCI_ANY_ID,}, /* Linksys WDT11 */
354 {0x16ec, 0x3685, PCI_ANY_ID, PCI_ANY_ID,}, /* USR 2415 */
355 {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,}, /* Belkin F5D6000 tested by
356 Brendan W. McAdams <rit AT jacked-in.org> */
357 {0x10b7, 0x7770, PCI_ANY_ID, PCI_ANY_ID,}, /* 3Com AirConnect PCI tested by
358 Damien Persohn <damien AT persohn.net> */
359 {0,},
360};
361
Pavel Roskinb884c872006-04-07 04:10:57 -0400362MODULE_DEVICE_TABLE(pci, orinoco_plx_id_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364static struct pci_driver orinoco_plx_driver = {
365 .name = DRIVER_NAME,
Pavel Roskinb884c872006-04-07 04:10:57 -0400366 .id_table = orinoco_plx_id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 .probe = orinoco_plx_init_one,
368 .remove = __devexit_p(orinoco_plx_remove_one),
Pavel Roskinb884c872006-04-07 04:10:57 -0400369 .suspend = orinoco_pci_suspend,
370 .resume = orinoco_pci_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371};
372
373static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
374 " (Pavel Roskin <proski@gnu.org>,"
375 " David Gibson <hermes@gibson.dropbear.id.au>,"
376 " Daniel Barlow <dan@telent.net>)";
377MODULE_AUTHOR("Daniel Barlow <dan@telent.net>");
378MODULE_DESCRIPTION("Driver for wireless LAN cards using the PLX9052 PCI bridge");
379MODULE_LICENSE("Dual MPL/GPL");
380
381static int __init orinoco_plx_init(void)
382{
383 printk(KERN_DEBUG "%s\n", version);
384 return pci_module_init(&orinoco_plx_driver);
385}
386
387static void __exit orinoco_plx_exit(void)
388{
389 pci_unregister_driver(&orinoco_plx_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
392module_init(orinoco_plx_init);
393module_exit(orinoco_plx_exit);
394
395/*
396 * Local variables:
397 * c-indent-level: 8
398 * c-basic-offset: 8
399 * tab-width: 8
400 * End:
401 */