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