This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / net / wireless / prism54 / islpci_hotplug.c
1 /*
2  *  
3  *  Copyright (C) 2002 Intersil Americas Inc.
4  *  Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include <linux/version.h>
22 #include <linux/module.h>
23 #include <linux/pci.h>
24 #include <linux/delay.h>
25 #include <linux/init.h> /* For __init, __exit */
26
27 #include "prismcompat.h"
28 #include "islpci_dev.h"
29 #include "islpci_mgt.h"         /* for pc_debug */
30 #include "isl_oid.h"
31
32 #define DRV_NAME        "prism54"
33 #define DRV_VERSION     "1.2"
34
35 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
36 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
37 MODULE_LICENSE("GPL");
38
39 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
40  * driver_data 
41  * If you have an update for this please contact prism54-devel@prism54.org 
42  * The latest list can be found at http://prism54.org/supported_cards.php */
43 static const struct pci_device_id prism54_id_tbl[] = {
44         /* 3COM 3CRWE154G72 Wireless LAN adapter */
45         {
46          PCIVENDOR_3COM, PCIDEVICE_3COM6001,
47          PCIVENDOR_3COM, PCIDEVICE_3COM6001,
48          0, 0, 0
49         },
50
51         /* D-Link Air Plus Xtreme G A1 - DWL-g650 A1 */
52         {
53          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
54          PCIVENDOR_DLINK, 0x3202UL, 
55          0, 0, 0
56         },
57
58         /* I-O Data WN-G54/CB - WN-G54/CB */
59         {
60          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
61          PCIVENDOR_IODATA, 0xd019UL, 
62          0, 0, 0
63         },
64
65         /* Netgear WG511 */
66         {
67          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
68          PCIVENDOR_NETGEAR, 0x4800UL,
69          0, 0, 0
70         },
71
72         /* Tekram Technology clones, Allnet, Netcomm, Zyxel */
73         {
74          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
75          PCIVENDOR_TTL, 0x1605UL,
76          0, 0, 0
77         },
78
79         /* SMC2802W */
80         {
81          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
82          PCIVENDOR_SMC, 0x2802UL,
83          0, 0, 0
84         },
85
86         /* SMC2835W */
87         {
88          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
89          PCIVENDOR_SMC, 0x2835UL,
90          0, 0, 0
91         },
92
93         /* Corega CG-WLCB54GT */
94         {
95          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
96          PCIVENDOR_ATI, 0xc104UL,
97          0, 0, 0
98         },
99
100         /* I4 Z-Com XG-600 */
101         {
102          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
103          PCIVENDOR_I4, 0x0014UL,
104          0, 0, 0
105         },
106
107         /* I4 Z-Com XG-900  and clones Macer, Ovislink, Planex, Peabird, */
108         /* Sitecom, Xterasys */
109         {
110          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
111          PCIVENDOR_I4, 0x0020UL,
112          0, 0, 0
113         },
114
115         /* SMC 2802W V2 */
116         {
117          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
118          PCIVENDOR_ACCTON, 0xee03UL,
119          0, 0, 0
120         },
121
122         /* SMC 2835W V2 */
123         {
124          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
125          PCIVENDOR_SMC, 0xa835UL,
126          0, 0, 0
127         },
128
129         /* Intersil PRISM Indigo Wireless LAN adapter */
130         {
131          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3877,
132          PCI_ANY_ID, PCI_ANY_ID,
133          0, 0, 0
134         },
135
136         /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
137         /* Default */
138         {
139          PCIVENDOR_INTERSIL, PCIDEVICE_ISL3890,
140          PCI_ANY_ID, PCI_ANY_ID,
141          0, 0, 0
142         },
143
144         /* End of list */
145         {0,0,0,0,0,0,0}
146 };
147
148 /* register the device with the Hotplug facilities of the kernel */
149 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
150
151 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
152 static void prism54_remove(struct pci_dev *);
153 static int prism54_suspend(struct pci_dev *, u32 state);
154 static int prism54_resume(struct pci_dev *);
155
156 static struct pci_driver prism54_driver = {
157         .name = DRV_NAME,
158         .id_table = prism54_id_tbl,
159         .probe = prism54_probe,
160         .remove = prism54_remove,
161         .suspend = prism54_suspend,
162         .resume = prism54_resume,
163         /* .enable_wake ; we don't support this yet */
164 };
165
166 static void
167 prism54_get_card_model(struct net_device *ndev)
168 {
169         islpci_private  *priv;
170         char            *modelp;
171         int             notwork = 0;
172
173         priv = netdev_priv(ndev);
174         switch (priv->pdev->subsystem_device) {
175         case PCIDEVICE_ISL3877:
176                 modelp = "PRISM Indigo";
177                 break;
178         case PCIDEVICE_ISL3886:
179                 modelp = "PRISM Javelin / Xbow";
180                 break;
181         case PCIDEVICE_3COM6001:
182                 modelp = "3COM 3CRWE154G72";
183                 break;
184         case 0x3202UL:
185                 modelp = "D-Link DWL-g650 A1";
186                 break;
187         case 0xd019UL:
188                 modelp = "WN-G54/CB";
189                 break;
190         case 0x4800UL:
191                 modelp = "Netgear WG511";
192                 break;
193         case 0x2802UL:
194                 modelp = "SMC2802W";
195                 break;
196         case 0xee03UL:
197                 modelp = "SMC2802W V2";
198                 notwork = 1;
199                 break;
200         case 0x2835UL:
201                 modelp = "SMC2835W";
202                 break;
203         case 0xa835UL:
204                 modelp = "SMC2835W V2";
205                 notwork = 1;
206                 break;
207         case 0xc104UL:
208                 modelp = "CG-WLCB54GT";
209                 break;
210         case 0x1605UL:
211                 modelp = "Tekram Technology clone";
212                 break;
213         /* Let's leave this one out for now since it seems bogus/wrong 
214          * Even if the manufacturer did use 0x0000UL it may not be correct
215          * by their part, therefore deserving no name ;) */
216         /*      case 0x0000UL: 
217          *              modelp = "SparkLAN WL-850F";
218          *              break;*/
219
220         /* We have two reported for the one below :( */
221         case 0x0014UL:
222                 modelp = "I4 Z-Com XG-600 and clones";
223                 break;
224         case 0x0020UL:
225                 modelp = "I4 Z-Com XG-900 and clones";
226                 break;
227 /* Default it */
228 /*
229         case PCIDEVICE_ISL3890:
230                 modelp = "PRISM Duette/GT";
231                 break;
232 */
233         default:
234                 modelp = "PRISM Duette/GT";
235         }
236         printk(KERN_DEBUG "%s: %s driver detected card model: %s\n",
237                         ndev->name, DRV_NAME, modelp);
238         if ( notwork ) {
239                 printk(KERN_DEBUG "%s: %s Warning - This may not work\n",
240                         ndev->name, DRV_NAME);
241         }
242         return;
243 }
244
245 /******************************************************************************
246     Module initialization functions
247 ******************************************************************************/
248
249 int
250 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
251 {
252         struct net_device *ndev;
253         u8 latency_tmr;
254         u32 mem_addr;
255         islpci_private *priv;
256         int rvalue;
257
258         /* TRACE(DRV_NAME); */
259         
260         
261         /* Enable the pci device */
262         if (pci_enable_device(pdev)) {
263                 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
264                 return -ENODEV;
265         }
266
267         /* check whether the latency timer is set correctly */
268         pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
269 #if VERBOSE > SHOW_ERROR_MESSAGES
270         DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
271 #endif
272         if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
273                 /* set the latency timer */
274                 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
275                                       PCIDEVICE_LATENCY_TIMER_VAL);
276         }
277
278         /* enable PCI DMA */
279         if (pci_set_dma_mask(pdev, 0xffffffff)) {
280                 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
281                 goto do_pci_disable_device;
282         }
283
284         /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
285          * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
286          *      The RETRY_TIMEOUT is used to set the number of retries that the core, as a
287          *      Master, will perform before abandoning a cycle. The default value for
288          *      RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
289          *      devices. A write of zero to the RETRY_TIMEOUT register disables this
290          *      function to allow use with any non-compliant legacy devices that may
291          *      execute more retries.
292          *
293          *      Writing zero to both these two registers will disable both timeouts and
294          *      *can* solve problems caused by devices that are slow to respond.
295          */
296         /*      I am taking these out, we should not be poking around in the
297          *      programmable timers - MSW
298         */
299 /*      Do not zero the programmable timers
300         pci_write_config_byte(pdev, 0x40, 0);
301         pci_write_config_byte(pdev, 0x41, 0);
302 */
303
304         /* request the pci device I/O regions */
305         rvalue = pci_request_regions(pdev, DRV_NAME);
306         if (rvalue) {
307                 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
308                        DRV_NAME, rvalue);
309                 goto do_pci_disable_device;
310         }
311
312         /* check if the memory window is indeed set */
313         rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
314         if (rvalue || !mem_addr) {
315                 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
316                        DRV_NAME);
317                 goto do_pci_disable_device;
318         }
319
320         /* enable PCI bus-mastering */
321         DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
322         pci_set_master(pdev);
323
324         /* enable MWI */
325         pci_set_mwi(pdev);
326
327         /* setup the network device interface and its structure */
328         if (!(ndev = islpci_setup(pdev))) {
329                 /* error configuring the driver as a network device */
330                 printk(KERN_ERR "%s: could not configure network device\n",
331                        DRV_NAME);
332                 goto do_pci_release_regions;
333         }
334
335         priv = netdev_priv(ndev);
336         islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
337
338         /* card is in unknown state yet, might have some interrupts pending */
339         isl38xx_disable_interrupts(priv->device_base);
340
341         /* request for the interrupt before uploading the firmware */
342         rvalue = request_irq(pdev->irq, &islpci_interrupt,
343                              SA_SHIRQ, ndev->name, priv);
344
345         if (rvalue) {
346                 /* error, could not hook the handler to the irq */
347                 printk(KERN_ERR "%s: could not install IRQ handler\n",
348                        ndev->name);
349                 goto do_unregister_netdev;
350         }
351
352         /* firmware upload is triggered in islpci_open */
353
354         /* Pretty card model discovery output */
355         prism54_get_card_model(ndev);
356
357         return 0;
358
359       do_unregister_netdev:
360         unregister_netdev(ndev);
361         islpci_free_memory(priv);
362         pci_set_drvdata(pdev, 0);
363         free_netdev(ndev);
364         priv = 0;
365       do_pci_release_regions:
366         pci_release_regions(pdev);
367       do_pci_disable_device:
368         pci_disable_device(pdev);
369         return -EIO;
370 }
371
372 /* set by cleanup_module */
373 static volatile int __in_cleanup_module = 0;
374
375 /* this one removes one(!!) instance only */
376 void
377 prism54_remove(struct pci_dev *pdev)
378 {
379         struct net_device *ndev = pci_get_drvdata(pdev);
380         islpci_private *priv = ndev ? netdev_priv(ndev) : 0;
381         BUG_ON(!priv);
382
383         if (!__in_cleanup_module) {
384                 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
385                 islpci_set_state(priv, PRV_STATE_OFF);
386         }
387
388         printk(KERN_DEBUG "%s: removing device\n", ndev->name);
389
390         unregister_netdev(ndev);
391
392         /* free the interrupt request */
393
394         if (islpci_get_state(priv) != PRV_STATE_OFF) {
395                 isl38xx_disable_interrupts(priv->device_base);
396                 islpci_set_state(priv, PRV_STATE_OFF);
397                 /* This bellow causes a lockup at rmmod time. It might be
398                  * because some interrupts still linger after rmmod time, 
399                  * see bug #17 */
400                 /* pci_set_power_state(pdev, 3);*/      /* try to power-off */
401         }
402
403         free_irq(pdev->irq, priv);
404
405         /* free the PCI memory and unmap the remapped page */
406         islpci_free_memory(priv);
407
408         pci_set_drvdata(pdev, 0);
409         free_netdev(ndev);
410         priv = 0;
411
412         pci_release_regions(pdev);
413
414         pci_disable_device(pdev);
415 }
416
417 int
418 prism54_suspend(struct pci_dev *pdev, u32 state)
419 {
420         struct net_device *ndev = pci_get_drvdata(pdev);
421         islpci_private *priv = ndev ? netdev_priv(ndev) : 0;
422         BUG_ON(!priv);
423
424         printk(KERN_NOTICE "%s: got suspend request (state %d)\n",
425                ndev->name, state);
426
427         pci_save_state(pdev, priv->pci_state);
428
429         /* tell the device not to trigger interrupts for now... */
430         isl38xx_disable_interrupts(priv->device_base);
431
432         /* from now on assume the hardware was already powered down
433            and don't touch it anymore */
434         islpci_set_state(priv, PRV_STATE_OFF);
435
436         netif_stop_queue(ndev);
437         netif_device_detach(ndev);
438
439         return 0;
440 }
441
442 int
443 prism54_resume(struct pci_dev *pdev)
444 {
445         struct net_device *ndev = pci_get_drvdata(pdev);
446         islpci_private *priv = ndev ? netdev_priv(ndev) : 0;
447         BUG_ON(!priv);
448
449         printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
450
451         pci_restore_state(pdev, priv->pci_state);
452
453         /* alright let's go into the PREBOOT state */
454         islpci_reset(priv, 1);
455
456         netif_device_attach(ndev);
457         netif_start_queue(ndev);
458
459         return 0;
460 }
461
462 static int __init
463 prism54_module_init(void)
464 {
465         printk(KERN_INFO "Loaded %s driver, version %s\n",
466                DRV_NAME, DRV_VERSION);
467
468         __bug_on_wrong_struct_sizes ();
469
470         return pci_module_init(&prism54_driver);
471 }
472
473 /* by the time prism54_module_exit() terminates, as a postcondition
474  * all instances will have been destroyed by calls to
475  * prism54_remove() */
476 static void __exit
477 prism54_module_exit(void)
478 {
479         __in_cleanup_module = 1;
480
481         pci_unregister_driver(&prism54_driver);
482
483         printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
484
485         __in_cleanup_module = 0;
486 }
487
488 /* register entry points */
489 module_init(prism54_module_init);
490 module_exit(prism54_module_exit);
491 /* EOF */