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