2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
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
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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include <linux/interrupt.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/delay.h>
23 #include <linux/init.h> /* For __init, __exit */
24 #include <linux/dma-mapping.h>
26 #include "prismcompat.h"
27 #include "islpci_dev.h"
28 #include "islpci_mgt.h" /* for pc_debug */
31 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
32 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
33 MODULE_LICENSE("GPL");
35 static int init_pcitm = 0;
36 module_param(init_pcitm, int, 0);
38 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
40 * If you have an update for this please contact prism54-devel@prism54.org
41 * The latest list can be found at http://wireless.kernel.org/en/users/Drivers/p54 */
42 static const struct pci_device_id prism54_id_tbl[] = {
43 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
46 PCI_ANY_ID, PCI_ANY_ID,
50 /* 3COM 3CRWE154G72 Wireless LAN adapter */
52 PCI_VDEVICE(3COM, 0x6001), 0
55 /* Intersil PRISM Indigo Wireless LAN adapter */
58 PCI_ANY_ID, PCI_ANY_ID,
62 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
65 PCI_ANY_ID, PCI_ANY_ID,
73 /* register the device with the Hotplug facilities of the kernel */
74 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
76 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
77 static void prism54_remove(struct pci_dev *);
78 static int prism54_suspend(struct pci_dev *, pm_message_t state);
79 static int prism54_resume(struct pci_dev *);
81 static struct pci_driver prism54_driver = {
83 .id_table = prism54_id_tbl,
84 .probe = prism54_probe,
85 .remove = prism54_remove,
86 .suspend = prism54_suspend,
87 .resume = prism54_resume,
90 /******************************************************************************
91 Module initialization functions
92 ******************************************************************************/
95 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
97 struct net_device *ndev;
100 islpci_private *priv;
103 /* Enable the pci device */
104 if (pci_enable_device(pdev)) {
105 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
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);
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);
121 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
122 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
123 goto do_pci_disable_device;
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)
128 * 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.
135 * Writing zero to both these two registers will disable both timeouts and
136 * *can* solve problems caused by devices that are slow to respond.
137 * Make this configurable - MSW
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);
143 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
146 /* request the pci device I/O regions */
147 rvalue = pci_request_regions(pdev, DRV_NAME);
149 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
151 goto do_pci_disable_device;
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",
159 goto do_pci_release_regions;
162 /* enable PCI bus-mastering */
163 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
164 pci_set_master(pdev);
167 pci_try_set_mwi(pdev);
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",
174 goto do_pci_clear_mwi;
177 priv = netdev_priv(ndev);
178 islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
180 /* card is in unknown state yet, might have some interrupts pending */
181 isl38xx_disable_interrupts(priv->device_base);
183 /* request for the interrupt before uploading the firmware */
184 rvalue = request_irq(pdev->irq, islpci_interrupt,
185 IRQF_SHARED, ndev->name, priv);
188 /* error, could not hook the handler to the irq */
189 printk(KERN_ERR "%s: could not install IRQ handler\n",
191 goto do_unregister_netdev;
194 /* firmware upload is triggered in islpci_open */
198 do_unregister_netdev:
199 unregister_netdev(ndev);
200 islpci_free_memory(priv);
205 do_pci_release_regions:
206 pci_release_regions(pdev);
207 do_pci_disable_device:
208 pci_disable_device(pdev);
212 /* set by cleanup_module */
213 static volatile int __in_cleanup_module = 0;
215 /* this one removes one(!!) instance only */
217 prism54_remove(struct pci_dev *pdev)
219 struct net_device *ndev = pci_get_drvdata(pdev);
220 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
223 if (!__in_cleanup_module) {
224 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
225 islpci_set_state(priv, PRV_STATE_OFF);
228 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
230 unregister_netdev(ndev);
232 /* free the interrupt request */
234 if (islpci_get_state(priv) != PRV_STATE_OFF) {
235 isl38xx_disable_interrupts(priv->device_base);
236 islpci_set_state(priv, PRV_STATE_OFF);
237 /* This bellow causes a lockup at rmmod time. It might be
238 * because some interrupts still linger after rmmod time,
240 /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
243 free_irq(pdev->irq, priv);
245 /* free the PCI memory and unmap the remapped page */
246 islpci_free_memory(priv);
253 pci_release_regions(pdev);
255 pci_disable_device(pdev);
259 prism54_suspend(struct pci_dev *pdev, pm_message_t state)
261 struct net_device *ndev = pci_get_drvdata(pdev);
262 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
266 pci_save_state(pdev);
268 /* tell the device not to trigger interrupts for now... */
269 isl38xx_disable_interrupts(priv->device_base);
271 /* from now on assume the hardware was already powered down
272 and don't touch it anymore */
273 islpci_set_state(priv, PRV_STATE_OFF);
275 netif_stop_queue(ndev);
276 netif_device_detach(ndev);
282 prism54_resume(struct pci_dev *pdev)
284 struct net_device *ndev = pci_get_drvdata(pdev);
285 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
290 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
292 err = pci_enable_device(pdev);
294 printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
299 pci_restore_state(pdev);
301 /* alright let's go into the PREBOOT state */
302 islpci_reset(priv, 1);
304 netif_device_attach(ndev);
305 netif_start_queue(ndev);
311 prism54_module_init(void)
313 printk(KERN_INFO "Loaded %s driver, version %s\n",
314 DRV_NAME, DRV_VERSION);
316 __bug_on_wrong_struct_sizes ();
318 return pci_register_driver(&prism54_driver);
321 /* by the time prism54_module_exit() terminates, as a postcondition
322 * all instances will have been destroyed by calls to
323 * prism54_remove() */
325 prism54_module_exit(void)
327 __in_cleanup_module = 1;
329 pci_unregister_driver(&prism54_driver);
331 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
333 __in_cleanup_module = 0;
336 /* register entry points */
337 module_init(prism54_module_init);
338 module_exit(prism54_module_exit);