3 * Copyright (C) 2002 Intersil Americas Inc.
4 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
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
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.
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
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 */
27 #include "prismcompat.h"
28 #include "islpci_dev.h"
29 #include "islpci_mgt.h" /* for pc_debug */
32 #define DRV_NAME "prism54"
33 #define DRV_VERSION "1.2"
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");
39 static int init_pcitm = 0;
40 module_param(init_pcitm, int, 0);
42 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
44 * If you have an update for this please contact prism54-devel@prism54.org
45 * The latest list can be found at http://prism54.org/supported_cards.php */
46 static const struct pci_device_id prism54_id_tbl[] = {
47 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
50 PCI_ANY_ID, PCI_ANY_ID,
54 /* 3COM 3CRWE154G72 Wireless LAN adapter */
57 PCI_ANY_ID, PCI_ANY_ID,
61 /* Intersil PRISM Indigo Wireless LAN adapter */
64 PCI_ANY_ID, PCI_ANY_ID,
68 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
71 PCI_ANY_ID, PCI_ANY_ID,
79 /* register the device with the Hotplug facilities of the kernel */
80 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
82 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
83 static void prism54_remove(struct pci_dev *);
84 static int prism54_suspend(struct pci_dev *, u32 state);
85 static int prism54_resume(struct pci_dev *);
87 static struct pci_driver prism54_driver = {
89 .id_table = prism54_id_tbl,
90 .probe = prism54_probe,
91 .remove = prism54_remove,
92 .suspend = prism54_suspend,
93 .resume = prism54_resume,
94 /* .enable_wake ; we don't support this yet */
97 /******************************************************************************
98 Module initialization functions
99 ******************************************************************************/
102 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
104 struct net_device *ndev;
107 islpci_private *priv;
110 /* TRACE(DRV_NAME); */
113 /* Enable the pci device */
114 if (pci_enable_device(pdev)) {
115 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
119 /* check whether the latency timer is set correctly */
120 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
121 #if VERBOSE > SHOW_ERROR_MESSAGES
122 DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
124 if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
125 /* set the latency timer */
126 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
127 PCIDEVICE_LATENCY_TIMER_VAL);
131 if (pci_set_dma_mask(pdev, 0xffffffff)) {
132 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
133 goto do_pci_disable_device;
136 /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
137 * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
138 * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
139 * Master, will perform before abandoning a cycle. The default value for
140 * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
141 * devices. A write of zero to the RETRY_TIMEOUT register disables this
142 * function to allow use with any non-compliant legacy devices that may
143 * execute more retries.
145 * Writing zero to both these two registers will disable both timeouts and
146 * *can* solve problems caused by devices that are slow to respond.
147 * Make this configurable - MSW
149 if ( init_pcitm >= 0 ) {
150 pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
151 pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
153 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
156 /* request the pci device I/O regions */
157 rvalue = pci_request_regions(pdev, DRV_NAME);
159 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
161 goto do_pci_disable_device;
164 /* check if the memory window is indeed set */
165 rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
166 if (rvalue || !mem_addr) {
167 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
169 goto do_pci_disable_device;
172 /* enable PCI bus-mastering */
173 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
174 pci_set_master(pdev);
179 /* setup the network device interface and its structure */
180 if (!(ndev = islpci_setup(pdev))) {
181 /* error configuring the driver as a network device */
182 printk(KERN_ERR "%s: could not configure network device\n",
184 goto do_pci_release_regions;
187 priv = netdev_priv(ndev);
188 islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
190 /* card is in unknown state yet, might have some interrupts pending */
191 isl38xx_disable_interrupts(priv->device_base);
193 /* request for the interrupt before uploading the firmware */
194 rvalue = request_irq(pdev->irq, &islpci_interrupt,
195 SA_SHIRQ, ndev->name, priv);
198 /* error, could not hook the handler to the irq */
199 printk(KERN_ERR "%s: could not install IRQ handler\n",
201 goto do_unregister_netdev;
204 /* firmware upload is triggered in islpci_open */
208 do_unregister_netdev:
209 unregister_netdev(ndev);
210 islpci_free_memory(priv);
211 pci_set_drvdata(pdev, NULL);
214 do_pci_release_regions:
215 pci_release_regions(pdev);
216 do_pci_disable_device:
217 pci_disable_device(pdev);
221 /* set by cleanup_module */
222 static volatile int __in_cleanup_module = 0;
224 /* this one removes one(!!) instance only */
226 prism54_remove(struct pci_dev *pdev)
228 struct net_device *ndev = pci_get_drvdata(pdev);
229 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
232 if (!__in_cleanup_module) {
233 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
234 islpci_set_state(priv, PRV_STATE_OFF);
237 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
239 unregister_netdev(ndev);
241 /* free the interrupt request */
243 if (islpci_get_state(priv) != PRV_STATE_OFF) {
244 isl38xx_disable_interrupts(priv->device_base);
245 islpci_set_state(priv, PRV_STATE_OFF);
246 /* This bellow causes a lockup at rmmod time. It might be
247 * because some interrupts still linger after rmmod time,
249 /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
252 free_irq(pdev->irq, priv);
254 /* free the PCI memory and unmap the remapped page */
255 islpci_free_memory(priv);
257 pci_set_drvdata(pdev, NULL);
261 pci_release_regions(pdev);
263 pci_disable_device(pdev);
267 prism54_suspend(struct pci_dev *pdev, u32 state)
269 struct net_device *ndev = pci_get_drvdata(pdev);
270 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
273 printk(KERN_NOTICE "%s: got suspend request (state %d)\n",
276 pci_save_state(pdev, priv->pci_state);
278 /* tell the device not to trigger interrupts for now... */
279 isl38xx_disable_interrupts(priv->device_base);
281 /* from now on assume the hardware was already powered down
282 and don't touch it anymore */
283 islpci_set_state(priv, PRV_STATE_OFF);
285 netif_stop_queue(ndev);
286 netif_device_detach(ndev);
292 prism54_resume(struct pci_dev *pdev)
294 struct net_device *ndev = pci_get_drvdata(pdev);
295 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
298 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
300 pci_restore_state(pdev, priv->pci_state);
302 /* alright let's go into the PREBOOT state */
303 islpci_reset(priv, 1);
305 netif_device_attach(ndev);
306 netif_start_queue(ndev);
312 prism54_module_init(void)
314 printk(KERN_INFO "Loaded %s driver, version %s\n",
315 DRV_NAME, DRV_VERSION);
317 __bug_on_wrong_struct_sizes ();
319 return pci_module_init(&prism54_driver);
322 /* by the time prism54_module_exit() terminates, as a postcondition
323 * all instances will have been destroyed by calls to
324 * prism54_remove() */
326 prism54_module_exit(void)
328 __in_cleanup_module = 1;
330 pci_unregister_driver(&prism54_driver);
332 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
334 __in_cleanup_module = 0;
337 /* register entry points */
338 module_init(prism54_module_init);
339 module_exit(prism54_module_exit);