blob: dc14420a9adc03e65f5541e0ef9851a44b791c17 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/module.h>
21#include <linux/pci.h>
22#include <linux/delay.h>
23#include <linux/init.h> /* For __init, __exit */
Matthias Gehre910638a2006-03-28 01:56:48 -080024#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include "prismcompat.h"
27#include "islpci_dev.h"
28#include "islpci_mgt.h" /* for pc_debug */
29#include "isl_oid.h"
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
32MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
33MODULE_LICENSE("GPL");
34
35static int init_pcitm = 0;
36module_param(init_pcitm, int, 0);
37
38/* In this order: vendor, device, subvendor, subdevice, class, class_mask,
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -040039 * driver_data
40 * If you have an update for this please contact prism54-devel@prism54.org
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * The latest list can be found at http://prism54.org/supported_cards.php */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000042static DEFINE_PCI_DEVICE_TABLE(prism54_id_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
44 {
45 0x1260, 0x3890,
46 PCI_ANY_ID, PCI_ANY_ID,
47 0, 0, 0
48 },
49
50 /* 3COM 3CRWE154G72 Wireless LAN adapter */
51 {
Joe Perches8ab0ea72009-06-24 22:13:27 -070052 PCI_VDEVICE(3COM, 0x6001), 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 },
54
55 /* Intersil PRISM Indigo Wireless LAN adapter */
56 {
57 0x1260, 0x3877,
58 PCI_ANY_ID, PCI_ANY_ID,
59 0, 0, 0
60 },
61
62 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
63 {
64 0x1260, 0x3886,
65 PCI_ANY_ID, PCI_ANY_ID,
66 0, 0, 0
67 },
68
69 /* End of list */
70 {0,0,0,0,0,0,0}
71};
72
73/* register the device with the Hotplug facilities of the kernel */
74MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
75
76static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
77static void prism54_remove(struct pci_dev *);
Pavel Machek05adc3b2005-04-16 15:25:25 -070078static int prism54_suspend(struct pci_dev *, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static int prism54_resume(struct pci_dev *);
80
81static struct pci_driver prism54_driver = {
82 .name = DRV_NAME,
83 .id_table = prism54_id_tbl,
84 .probe = prism54_probe,
85 .remove = prism54_remove,
86 .suspend = prism54_suspend,
87 .resume = prism54_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
90/******************************************************************************
91 Module initialization functions
92******************************************************************************/
93
Hannes Eder6dd01482008-12-26 00:15:03 -080094static int
Linus Torvalds1da177e2005-04-16 15:20:36 -070095prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
96{
97 struct net_device *ndev;
98 u8 latency_tmr;
99 u32 mem_addr;
100 islpci_private *priv;
101 int rvalue;
102
103 /* Enable the pci device */
104 if (pci_enable_device(pdev)) {
105 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
106 return -ENODEV;
107 }
108
109 /* check whether the latency timer is set correctly */
110 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
111#if VERBOSE > SHOW_ERROR_MESSAGES
112 DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
113#endif
114 if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
115 /* set the latency timer */
116 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
117 PCIDEVICE_LATENCY_TIMER_VAL);
118 }
119
120 /* enable PCI DMA */
Yang Hongyang284901a2009-04-06 19:01:15 -0700121 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
123 goto do_pci_disable_device;
124 }
125
126 /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
127 * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400128 * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
129 * Master, will perform before abandoning a cycle. The default value for
130 * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
131 * devices. A write of zero to the RETRY_TIMEOUT register disables this
132 * function to allow use with any non-compliant legacy devices that may
133 * execute more retries.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 *
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400135 * Writing zero to both these two registers will disable both timeouts and
136 * *can* solve problems caused by devices that are slow to respond.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 * Make this configurable - MSW
138 */
139 if ( init_pcitm >= 0 ) {
140 pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
141 pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
142 } else {
143 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
144 }
145
146 /* request the pci device I/O regions */
147 rvalue = pci_request_regions(pdev, DRV_NAME);
148 if (rvalue) {
149 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
150 DRV_NAME, rvalue);
151 goto do_pci_disable_device;
152 }
153
154 /* check if the memory window is indeed set */
155 rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
156 if (rvalue || !mem_addr) {
157 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
158 DRV_NAME);
159 goto do_pci_release_regions;
160 }
161
162 /* enable PCI bus-mastering */
163 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
164 pci_set_master(pdev);
165
166 /* enable MWI */
Randy Dunlap694625c2007-07-09 11:55:54 -0700167 pci_try_set_mwi(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* setup the network device interface and its structure */
170 if (!(ndev = islpci_setup(pdev))) {
171 /* error configuring the driver as a network device */
172 printk(KERN_ERR "%s: could not configure network device\n",
173 DRV_NAME);
John W. Linville02e0e5e2006-11-07 20:53:48 -0500174 goto do_pci_clear_mwi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176
177 priv = netdev_priv(ndev);
178 islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
179
180 /* card is in unknown state yet, might have some interrupts pending */
181 isl38xx_disable_interrupts(priv->device_base);
182
183 /* request for the interrupt before uploading the firmware */
Joe Perchesa0607fd2009-11-18 23:29:17 -0800184 rvalue = request_irq(pdev->irq, islpci_interrupt,
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700185 IRQF_SHARED, ndev->name, priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 if (rvalue) {
188 /* error, could not hook the handler to the irq */
189 printk(KERN_ERR "%s: could not install IRQ handler\n",
190 ndev->name);
191 goto do_unregister_netdev;
192 }
193
194 /* firmware upload is triggered in islpci_open */
195
196 return 0;
197
198 do_unregister_netdev:
199 unregister_netdev(ndev);
200 islpci_free_memory(priv);
201 pci_set_drvdata(pdev, NULL);
202 free_netdev(ndev);
203 priv = NULL;
John W. Linville02e0e5e2006-11-07 20:53:48 -0500204 do_pci_clear_mwi:
205 pci_clear_mwi(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 do_pci_release_regions:
207 pci_release_regions(pdev);
208 do_pci_disable_device:
209 pci_disable_device(pdev);
210 return -EIO;
211}
212
213/* set by cleanup_module */
214static volatile int __in_cleanup_module = 0;
215
216/* this one removes one(!!) instance only */
Hannes Eder6dd01482008-12-26 00:15:03 -0800217static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218prism54_remove(struct pci_dev *pdev)
219{
220 struct net_device *ndev = pci_get_drvdata(pdev);
221 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
222 BUG_ON(!priv);
223
224 if (!__in_cleanup_module) {
225 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
226 islpci_set_state(priv, PRV_STATE_OFF);
227 }
228
229 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
230
231 unregister_netdev(ndev);
232
233 /* free the interrupt request */
234
235 if (islpci_get_state(priv) != PRV_STATE_OFF) {
236 isl38xx_disable_interrupts(priv->device_base);
237 islpci_set_state(priv, PRV_STATE_OFF);
238 /* This bellow causes a lockup at rmmod time. It might be
Dmitry Torokhov93b2dd12006-10-08 00:38:15 -0400239 * because some interrupts still linger after rmmod time,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 * see bug #17 */
241 /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
242 }
243
244 free_irq(pdev->irq, priv);
245
246 /* free the PCI memory and unmap the remapped page */
247 islpci_free_memory(priv);
248
249 pci_set_drvdata(pdev, NULL);
250 free_netdev(ndev);
251 priv = NULL;
252
John W. Linville02e0e5e2006-11-07 20:53:48 -0500253 pci_clear_mwi(pdev);
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 pci_release_regions(pdev);
256
257 pci_disable_device(pdev);
258}
259
Hannes Eder6dd01482008-12-26 00:15:03 -0800260static int
Pavel Machek05adc3b2005-04-16 15:25:25 -0700261prism54_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 struct net_device *ndev = pci_get_drvdata(pdev);
264 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
265 BUG_ON(!priv);
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 pci_save_state(pdev);
269
270 /* tell the device not to trigger interrupts for now... */
271 isl38xx_disable_interrupts(priv->device_base);
272
273 /* from now on assume the hardware was already powered down
274 and don't touch it anymore */
275 islpci_set_state(priv, PRV_STATE_OFF);
276
277 netif_stop_queue(ndev);
278 netif_device_detach(ndev);
279
280 return 0;
281}
282
Hannes Eder6dd01482008-12-26 00:15:03 -0800283static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284prism54_resume(struct pci_dev *pdev)
285{
286 struct net_device *ndev = pci_get_drvdata(pdev);
287 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
John W. Linville02e0e5e2006-11-07 20:53:48 -0500288 int err;
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 BUG_ON(!priv);
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
293
John W. Linville02e0e5e2006-11-07 20:53:48 -0500294 err = pci_enable_device(pdev);
295 if (err) {
296 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
297 ndev->name);
298 return err;
299 }
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 pci_restore_state(pdev);
302
303 /* alright let's go into the PREBOOT state */
304 islpci_reset(priv, 1);
305
306 netif_device_attach(ndev);
307 netif_start_queue(ndev);
308
309 return 0;
310}
311
312static int __init
313prism54_module_init(void)
314{
315 printk(KERN_INFO "Loaded %s driver, version %s\n",
316 DRV_NAME, DRV_VERSION);
317
318 __bug_on_wrong_struct_sizes ();
319
Jeff Garzik29917622006-08-19 17:48:59 -0400320 return pci_register_driver(&prism54_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323/* by the time prism54_module_exit() terminates, as a postcondition
324 * all instances will have been destroyed by calls to
325 * prism54_remove() */
326static void __exit
327prism54_module_exit(void)
328{
329 __in_cleanup_module = 1;
330
331 pci_unregister_driver(&prism54_driver);
332
333 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
334
335 __in_cleanup_module = 0;
336}
337
338/* register entry points */
339module_init(prism54_module_init);
340module_exit(prism54_module_exit);
341/* EOF */