1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2002 Intersil Americas Inc.
4 * Copyright (C) 2003 Herbert Valerio Riedel <hvr@gnu.org>
7 #include <linux/interrupt.h>
8 #include <linux/module.h>
10 #include <linux/delay.h>
11 #include <linux/init.h> /* For __init, __exit */
12 #include <linux/dma-mapping.h>
14 #include "prismcompat.h"
15 #include "islpci_dev.h"
16 #include "islpci_mgt.h" /* for pc_debug */
19 MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
20 MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
21 MODULE_LICENSE("GPL");
23 static int init_pcitm = 0;
24 module_param(init_pcitm, int, 0);
26 /* In this order: vendor, device, subvendor, subdevice, class, class_mask,
28 * If you have an update for this please contact prism54-devel@prism54.org
29 * The latest list can be found at http://wireless.wiki.kernel.org/en/users/Drivers/p54
31 static const struct pci_device_id prism54_id_tbl[] = {
32 /* Intersil PRISM Duette/Prism GT Wireless LAN adapter */
35 PCI_ANY_ID, PCI_ANY_ID,
39 /* 3COM 3CRWE154G72 Wireless LAN adapter */
41 PCI_VDEVICE(3COM, 0x6001), 0
44 /* Intersil PRISM Indigo Wireless LAN adapter */
47 PCI_ANY_ID, PCI_ANY_ID,
51 /* Intersil PRISM Javelin/Xbow Wireless LAN adapter */
54 PCI_ANY_ID, PCI_ANY_ID,
62 /* register the device with the Hotplug facilities of the kernel */
63 MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
65 static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
66 static void prism54_remove(struct pci_dev *);
67 static int __maybe_unused prism54_suspend(struct device *);
68 static int __maybe_unused prism54_resume(struct device *);
70 static SIMPLE_DEV_PM_OPS(prism54_pm_ops, prism54_suspend, prism54_resume);
72 static struct pci_driver prism54_driver = {
74 .id_table = prism54_id_tbl,
75 .probe = prism54_probe,
76 .remove = prism54_remove,
77 .driver.pm = &prism54_pm_ops,
80 /******************************************************************************
81 Module initialization functions
82 ******************************************************************************/
85 prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
87 struct net_device *ndev;
93 /* Enable the pci device */
94 if (pci_enable_device(pdev)) {
95 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
99 /* check whether the latency timer is set correctly */
100 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_tmr);
101 #if VERBOSE > SHOW_ERROR_MESSAGES
102 DEBUG(SHOW_TRACING, "latency timer: %x\n", latency_tmr);
104 if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
105 /* set the latency timer */
106 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
107 PCIDEVICE_LATENCY_TIMER_VAL);
111 if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
112 printk(KERN_ERR "%s: 32-bit PCI DMA not supported", DRV_NAME);
113 goto do_pci_disable_device;
116 /* 0x40 is the programmable timer to configure the response timeout (TRDY_TIMEOUT)
117 * 0x41 is the programmable timer to configure the retry timeout (RETRY_TIMEOUT)
118 * The RETRY_TIMEOUT is used to set the number of retries that the core, as a
119 * Master, will perform before abandoning a cycle. The default value for
120 * RETRY_TIMEOUT is 0x80, which far exceeds the PCI 2.1 requirement for new
121 * devices. A write of zero to the RETRY_TIMEOUT register disables this
122 * function to allow use with any non-compliant legacy devices that may
123 * execute more retries.
125 * Writing zero to both these two registers will disable both timeouts and
126 * *can* solve problems caused by devices that are slow to respond.
127 * Make this configurable - MSW
129 if ( init_pcitm >= 0 ) {
130 pci_write_config_byte(pdev, 0x40, (u8)init_pcitm);
131 pci_write_config_byte(pdev, 0x41, (u8)init_pcitm);
133 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
136 /* request the pci device I/O regions */
137 rvalue = pci_request_regions(pdev, DRV_NAME);
139 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
141 goto do_pci_disable_device;
144 /* check if the memory window is indeed set */
145 rvalue = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &mem_addr);
146 if (rvalue || !mem_addr) {
147 printk(KERN_ERR "%s: PCI device memory region not configured; fix your BIOS or CardBus bridge/drivers\n",
149 goto do_pci_release_regions;
152 /* enable PCI bus-mastering */
153 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
154 pci_set_master(pdev);
157 pci_try_set_mwi(pdev);
159 /* setup the network device interface and its structure */
160 if (!(ndev = islpci_setup(pdev))) {
161 /* error configuring the driver as a network device */
162 printk(KERN_ERR "%s: could not configure network device\n",
164 goto do_pci_clear_mwi;
167 priv = netdev_priv(ndev);
168 islpci_set_state(priv, PRV_STATE_PREBOOT); /* we are attempting to boot */
170 /* card is in unknown state yet, might have some interrupts pending */
171 isl38xx_disable_interrupts(priv->device_base);
173 /* request for the interrupt before uploading the firmware */
174 rvalue = request_irq(pdev->irq, islpci_interrupt,
175 IRQF_SHARED, ndev->name, priv);
178 /* error, could not hook the handler to the irq */
179 printk(KERN_ERR "%s: could not install IRQ handler\n",
181 goto do_unregister_netdev;
184 /* firmware upload is triggered in islpci_open */
188 do_unregister_netdev:
189 unregister_netdev(ndev);
190 islpci_free_memory(priv);
195 do_pci_release_regions:
196 pci_release_regions(pdev);
197 do_pci_disable_device:
198 pci_disable_device(pdev);
202 /* set by cleanup_module */
203 static volatile int __in_cleanup_module = 0;
205 /* this one removes one(!!) instance only */
207 prism54_remove(struct pci_dev *pdev)
209 struct net_device *ndev = pci_get_drvdata(pdev);
210 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
213 if (!__in_cleanup_module) {
214 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
215 islpci_set_state(priv, PRV_STATE_OFF);
218 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
220 unregister_netdev(ndev);
222 /* free the interrupt request */
224 if (islpci_get_state(priv) != PRV_STATE_OFF) {
225 isl38xx_disable_interrupts(priv->device_base);
226 islpci_set_state(priv, PRV_STATE_OFF);
227 /* This bellow causes a lockup at rmmod time. It might be
228 * because some interrupts still linger after rmmod time,
230 /* pci_set_power_state(pdev, 3);*/ /* try to power-off */
233 free_irq(pdev->irq, priv);
235 /* free the PCI memory and unmap the remapped page */
236 islpci_free_memory(priv);
243 pci_release_regions(pdev);
245 pci_disable_device(pdev);
248 static int __maybe_unused
249 prism54_suspend(struct device *dev)
251 struct net_device *ndev = dev_get_drvdata(dev);
252 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
255 /* tell the device not to trigger interrupts for now... */
256 isl38xx_disable_interrupts(priv->device_base);
258 /* from now on assume the hardware was already powered down
259 and don't touch it anymore */
260 islpci_set_state(priv, PRV_STATE_OFF);
262 netif_stop_queue(ndev);
263 netif_device_detach(ndev);
268 static int __maybe_unused
269 prism54_resume(struct device *dev)
271 struct net_device *ndev = dev_get_drvdata(dev);
272 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
276 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
278 /* alright let's go into the PREBOOT state */
279 islpci_reset(priv, 1);
281 netif_device_attach(ndev);
282 netif_start_queue(ndev);
288 prism54_module_init(void)
290 printk(KERN_INFO "Loaded %s driver, version %s\n",
291 DRV_NAME, DRV_VERSION);
293 __bug_on_wrong_struct_sizes ();
295 return pci_register_driver(&prism54_driver);
298 /* by the time prism54_module_exit() terminates, as a postcondition
299 * all instances will have been destroyed by calls to
300 * prism54_remove() */
302 prism54_module_exit(void)
304 __in_cleanup_module = 1;
306 pci_unregister_driver(&prism54_driver);
308 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
310 __in_cleanup_module = 0;
313 /* register entry points */
314 module_init(prism54_module_init);
315 module_exit(prism54_module_exit);