1
2
3
4
5
6
7#include <linux/interrupt.h>
8#include <linux/module.h>
9#include <linux/pci.h>
10#include <linux/delay.h>
11#include <linux/init.h>
12#include <linux/dma-mapping.h>
13
14#include "prismcompat.h"
15#include "islpci_dev.h"
16#include "islpci_mgt.h"
17#include "isl_oid.h"
18
19MODULE_AUTHOR("[Intersil] R.Bastings and W.Termorshuizen, The prism54.org Development Team <prism54-devel@prism54.org>");
20MODULE_DESCRIPTION("The Prism54 802.11 Wireless LAN adapter");
21MODULE_LICENSE("GPL");
22
23static int init_pcitm = 0;
24module_param(init_pcitm, int, 0);
25
26
27
28
29
30
31static const struct pci_device_id prism54_id_tbl[] = {
32
33 {
34 0x1260, 0x3890,
35 PCI_ANY_ID, PCI_ANY_ID,
36 0, 0, 0
37 },
38
39
40 {
41 PCI_VDEVICE(3COM, 0x6001), 0
42 },
43
44
45 {
46 0x1260, 0x3877,
47 PCI_ANY_ID, PCI_ANY_ID,
48 0, 0, 0
49 },
50
51
52 {
53 0x1260, 0x3886,
54 PCI_ANY_ID, PCI_ANY_ID,
55 0, 0, 0
56 },
57
58
59 {0,0,0,0,0,0,0}
60};
61
62
63MODULE_DEVICE_TABLE(pci, prism54_id_tbl);
64
65static int prism54_probe(struct pci_dev *, const struct pci_device_id *);
66static void prism54_remove(struct pci_dev *);
67static int __maybe_unused prism54_suspend(struct device *);
68static int __maybe_unused prism54_resume(struct device *);
69
70static SIMPLE_DEV_PM_OPS(prism54_pm_ops, prism54_suspend, prism54_resume);
71
72static struct pci_driver prism54_driver = {
73 .name = DRV_NAME,
74 .id_table = prism54_id_tbl,
75 .probe = prism54_probe,
76 .remove = prism54_remove,
77 .driver.pm = &prism54_pm_ops,
78};
79
80
81
82
83
84static int
85prism54_probe(struct pci_dev *pdev, const struct pci_device_id *id)
86{
87 struct net_device *ndev;
88 u8 latency_tmr;
89 u32 mem_addr;
90 islpci_private *priv;
91 int rvalue;
92
93
94 if (pci_enable_device(pdev)) {
95 printk(KERN_ERR "%s: pci_enable_device() failed.\n", DRV_NAME);
96 return -ENODEV;
97 }
98
99
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);
103#endif
104 if (latency_tmr < PCIDEVICE_LATENCY_TIMER_MIN) {
105
106 pci_write_config_byte(pdev, PCI_LATENCY_TIMER,
107 PCIDEVICE_LATENCY_TIMER_VAL);
108 }
109
110
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;
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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);
132 } else {
133 printk(KERN_INFO "PCI TRDY/RETRY unchanged\n");
134 }
135
136
137 rvalue = pci_request_regions(pdev, DRV_NAME);
138 if (rvalue) {
139 printk(KERN_ERR "%s: pci_request_regions failure (rc=%d)\n",
140 DRV_NAME, rvalue);
141 goto do_pci_disable_device;
142 }
143
144
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",
148 DRV_NAME);
149 goto do_pci_release_regions;
150 }
151
152
153 DEBUG(SHOW_TRACING, "%s: pci_set_master(pdev)\n", DRV_NAME);
154 pci_set_master(pdev);
155
156
157 pci_try_set_mwi(pdev);
158
159
160 if (!(ndev = islpci_setup(pdev))) {
161
162 printk(KERN_ERR "%s: could not configure network device\n",
163 DRV_NAME);
164 goto do_pci_clear_mwi;
165 }
166
167 priv = netdev_priv(ndev);
168 islpci_set_state(priv, PRV_STATE_PREBOOT);
169
170
171 isl38xx_disable_interrupts(priv->device_base);
172
173
174 rvalue = request_irq(pdev->irq, islpci_interrupt,
175 IRQF_SHARED, ndev->name, priv);
176
177 if (rvalue) {
178
179 printk(KERN_ERR "%s: could not install IRQ handler\n",
180 ndev->name);
181 goto do_unregister_netdev;
182 }
183
184
185
186 return 0;
187
188 do_unregister_netdev:
189 unregister_netdev(ndev);
190 islpci_free_memory(priv);
191 free_netdev(ndev);
192 priv = NULL;
193 do_pci_clear_mwi:
194 pci_clear_mwi(pdev);
195 do_pci_release_regions:
196 pci_release_regions(pdev);
197 do_pci_disable_device:
198 pci_disable_device(pdev);
199 return -EIO;
200}
201
202
203static volatile int __in_cleanup_module = 0;
204
205
206static void
207prism54_remove(struct pci_dev *pdev)
208{
209 struct net_device *ndev = pci_get_drvdata(pdev);
210 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
211 BUG_ON(!priv);
212
213 if (!__in_cleanup_module) {
214 printk(KERN_DEBUG "%s: hot unplug detected\n", ndev->name);
215 islpci_set_state(priv, PRV_STATE_OFF);
216 }
217
218 printk(KERN_DEBUG "%s: removing device\n", ndev->name);
219
220 unregister_netdev(ndev);
221
222
223
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
228
229
230
231 }
232
233 free_irq(pdev->irq, priv);
234
235
236 islpci_free_memory(priv);
237
238 free_netdev(ndev);
239 priv = NULL;
240
241 pci_clear_mwi(pdev);
242
243 pci_release_regions(pdev);
244
245 pci_disable_device(pdev);
246}
247
248static int __maybe_unused
249prism54_suspend(struct device *dev)
250{
251 struct net_device *ndev = dev_get_drvdata(dev);
252 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
253 BUG_ON(!priv);
254
255
256 isl38xx_disable_interrupts(priv->device_base);
257
258
259
260 islpci_set_state(priv, PRV_STATE_OFF);
261
262 netif_stop_queue(ndev);
263 netif_device_detach(ndev);
264
265 return 0;
266}
267
268static int __maybe_unused
269prism54_resume(struct device *dev)
270{
271 struct net_device *ndev = dev_get_drvdata(dev);
272 islpci_private *priv = ndev ? netdev_priv(ndev) : NULL;
273
274 BUG_ON(!priv);
275
276 printk(KERN_NOTICE "%s: got resume request\n", ndev->name);
277
278
279 islpci_reset(priv, 1);
280
281 netif_device_attach(ndev);
282 netif_start_queue(ndev);
283
284 return 0;
285}
286
287static int __init
288prism54_module_init(void)
289{
290 printk(KERN_INFO "Loaded %s driver, version %s\n",
291 DRV_NAME, DRV_VERSION);
292
293 __bug_on_wrong_struct_sizes ();
294
295 return pci_register_driver(&prism54_driver);
296}
297
298
299
300
301static void __exit
302prism54_module_exit(void)
303{
304 __in_cleanup_module = 1;
305
306 pci_unregister_driver(&prism54_driver);
307
308 printk(KERN_INFO "Unloaded %s driver\n", DRV_NAME);
309
310 __in_cleanup_module = 0;
311}
312
313
314module_init(prism54_module_init);
315module_exit(prism54_module_exit);
316
317