]> Pileus Git - ~andy/linux/blob - drivers/net/wireless/hostap/hostap_pci.c
[PATCH] hostap: Remove experimental PCI bus master/DMA code
[~andy/linux] / drivers / net / wireless / hostap / hostap_pci.c
1 #define PRISM2_PCI
2
3 /* Host AP driver's support for Intersil Prism2.5 PCI cards is based on
4  * driver patches from Reyk Floeter <reyk@vantronix.net> and
5  * Andy Warner <andyw@pobox.com> */
6
7 #include <linux/config.h>
8 #include <linux/version.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/if.h>
12 #include <linux/skbuff.h>
13 #include <linux/netdevice.h>
14 #include <linux/workqueue.h>
15 #include <linux/wireless.h>
16 #include <net/iw_handler.h>
17
18 #include <linux/ioport.h>
19 #include <linux/pci.h>
20 #include <asm/io.h>
21
22 #include "hostap_wlan.h"
23
24
25 static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
26 static char *dev_info = "hostap_pci";
27
28
29 MODULE_AUTHOR("Jouni Malinen");
30 MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
31                    "PCI cards.");
32 MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
33 MODULE_LICENSE("GPL");
34 MODULE_VERSION(PRISM2_VERSION);
35
36
37 /* FIX: do we need mb/wmb/rmb with memory operations? */
38
39
40 static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
41         /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
42         { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
43         /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
44         { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
45         /* Samsung MagicLAN SWL-2210P */
46         { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
47         { 0 }
48 };
49
50
51 #ifdef PRISM2_IO_DEBUG
52
53 static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
54 {
55         struct hostap_interface *iface;
56         local_info_t *local;
57         unsigned long flags;
58
59         iface = netdev_priv(dev);
60         local = iface->local;
61
62         spin_lock_irqsave(&local->lock, flags);
63         prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
64         writeb(v, local->mem_start + a);
65         spin_unlock_irqrestore(&local->lock, flags);
66 }
67
68 static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
69 {
70         struct hostap_interface *iface;
71         local_info_t *local;
72         unsigned long flags;
73         u8 v;
74
75         iface = netdev_priv(dev);
76         local = iface->local;
77
78         spin_lock_irqsave(&local->lock, flags);
79         v = readb(local->mem_start + a);
80         prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
81         spin_unlock_irqrestore(&local->lock, flags);
82         return v;
83 }
84
85 static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
86 {
87         struct hostap_interface *iface;
88         local_info_t *local;
89         unsigned long flags;
90
91         iface = netdev_priv(dev);
92         local = iface->local;
93
94         spin_lock_irqsave(&local->lock, flags);
95         prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
96         writew(v, local->mem_start + a);
97         spin_unlock_irqrestore(&local->lock, flags);
98 }
99
100 static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
101 {
102         struct hostap_interface *iface;
103         local_info_t *local;
104         unsigned long flags;
105         u16 v;
106
107         iface = netdev_priv(dev);
108         local = iface->local;
109
110         spin_lock_irqsave(&local->lock, flags);
111         v = readw(local->mem_start + a);
112         prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
113         spin_unlock_irqrestore(&local->lock, flags);
114         return v;
115 }
116
117 #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
118 #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
119 #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
120 #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
121 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
122 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
123
124 #else /* PRISM2_IO_DEBUG */
125
126 static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
127 {
128         struct hostap_interface *iface;
129         local_info_t *local;
130         iface = netdev_priv(dev);
131         local = iface->local;
132         writeb(v, local->mem_start + a);
133 }
134
135 static inline u8 hfa384x_inb(struct net_device *dev, int a)
136 {
137         struct hostap_interface *iface;
138         local_info_t *local;
139         iface = netdev_priv(dev);
140         local = iface->local;
141         return readb(local->mem_start + a);
142 }
143
144 static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
145 {
146         struct hostap_interface *iface;
147         local_info_t *local;
148         iface = netdev_priv(dev);
149         local = iface->local;
150         writew(v, local->mem_start + a);
151 }
152
153 static inline u16 hfa384x_inw(struct net_device *dev, int a)
154 {
155         struct hostap_interface *iface;
156         local_info_t *local;
157         iface = netdev_priv(dev);
158         local = iface->local;
159         return readw(local->mem_start + a);
160 }
161
162 #define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
163 #define HFA384X_INB(a) hfa384x_inb(dev, (a))
164 #define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
165 #define HFA384X_INW(a) hfa384x_inw(dev, (a))
166 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
167 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
168
169 #endif /* PRISM2_IO_DEBUG */
170
171
172 static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
173                             int len)
174 {
175         u16 d_off;
176         u16 *pos;
177
178         d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
179         pos = (u16 *) buf;
180
181         for ( ; len > 1; len -= 2)
182                 *pos++ = HFA384X_INW_DATA(d_off);
183
184         if (len & 1)
185                 *((char *) pos) = HFA384X_INB(d_off);
186
187         return 0;
188 }
189
190
191 static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
192 {
193         u16 d_off;
194         u16 *pos;
195
196         d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
197         pos = (u16 *) buf;
198
199         for ( ; len > 1; len -= 2)
200                 HFA384X_OUTW_DATA(*pos++, d_off);
201
202         if (len & 1)
203                 HFA384X_OUTB(*((char *) pos), d_off);
204
205         return 0;
206 }
207
208
209 /* FIX: This might change at some point.. */
210 #include "hostap_hw.c"
211
212 static void prism2_pci_cor_sreset(local_info_t *local)
213 {
214         struct net_device *dev = local->dev;
215         u16 reg;
216
217         reg = HFA384X_INB(HFA384X_PCICOR_OFF);
218         printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
219
220         /* linux-wlan-ng uses extremely long hold and settle times for
221          * COR sreset. A comment in the driver code mentions that the long
222          * delays appear to be necessary. However, at least IBM 22P6901 seems
223          * to work fine with shorter delays.
224          *
225          * Longer delays can be configured by uncommenting following line: */
226 /* #define PRISM2_PCI_USE_LONG_DELAYS */
227
228 #ifdef PRISM2_PCI_USE_LONG_DELAYS
229         int i;
230
231         HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
232         mdelay(250);
233
234         HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
235         mdelay(500);
236
237         /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
238         i = 2000000 / 10;
239         while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
240                 udelay(10);
241
242 #else /* PRISM2_PCI_USE_LONG_DELAYS */
243
244         HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
245         mdelay(2);
246         HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
247         mdelay(2);
248
249 #endif /* PRISM2_PCI_USE_LONG_DELAYS */
250
251         if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
252                 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
253         }
254 }
255
256
257 static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
258 {
259         struct net_device *dev = local->dev;
260
261         HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
262         mdelay(10);
263         HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
264         mdelay(10);
265         HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
266         mdelay(10);
267 }
268
269
270 static struct prism2_helper_functions prism2_pci_funcs =
271 {
272         .card_present   = NULL,
273         .cor_sreset     = prism2_pci_cor_sreset,
274         .dev_open       = NULL,
275         .dev_close      = NULL,
276         .genesis_reset  = prism2_pci_genesis_reset,
277         .hw_type        = HOSTAP_HW_PCI,
278 };
279
280
281 static int prism2_pci_probe(struct pci_dev *pdev,
282                             const struct pci_device_id *id)
283 {
284         unsigned long phymem;
285         void __iomem *mem = NULL;
286         local_info_t *local = NULL;
287         struct net_device *dev = NULL;
288         static int cards_found /* = 0 */;
289         int irq_registered = 0;
290         struct hostap_interface *iface;
291
292         if (pci_enable_device(pdev))
293                 return -EIO;
294
295         phymem = pci_resource_start(pdev, 0);
296
297         if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
298                 printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
299                 goto err_out_disable;
300         }
301
302         mem = ioremap(phymem, pci_resource_len(pdev, 0));
303         if (mem == NULL) {
304                 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
305                 goto fail;
306         }
307
308         dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
309                                      &pdev->dev);
310         if (dev == NULL)
311                 goto fail;
312         iface = netdev_priv(dev);
313         local = iface->local;
314         cards_found++;
315
316         dev->irq = pdev->irq;
317         local->mem_start = mem;
318
319         prism2_pci_cor_sreset(local);
320
321         pci_set_drvdata(pdev, dev);
322
323         if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
324                         dev)) {
325                 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
326                 goto fail;
327         } else
328                 irq_registered = 1;
329
330         if (!local->pri_only && prism2_hw_config(dev, 1)) {
331                 printk(KERN_DEBUG "%s: hardware initialization failed\n",
332                        dev_info);
333                 goto fail;
334         }
335
336         printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
337                "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
338
339         return hostap_hw_ready(dev);
340
341  fail:
342         if (irq_registered && dev)
343                 free_irq(dev->irq, dev);
344
345         if (mem)
346                 iounmap(mem);
347
348         release_mem_region(phymem, pci_resource_len(pdev, 0));
349
350  err_out_disable:
351         pci_disable_device(pdev);
352         prism2_free_local_data(dev);
353
354         return -ENODEV;
355 }
356
357
358 static void prism2_pci_remove(struct pci_dev *pdev)
359 {
360         struct net_device *dev;
361         struct hostap_interface *iface;
362         void __iomem *mem_start;
363
364         dev = pci_get_drvdata(pdev);
365         iface = netdev_priv(dev);
366
367         /* Reset the hardware, and ensure interrupts are disabled. */
368         prism2_pci_cor_sreset(iface->local);
369         hfa384x_disable_interrupts(dev);
370
371         if (dev->irq)
372                 free_irq(dev->irq, dev);
373
374         mem_start = iface->local->mem_start;
375         prism2_free_local_data(dev);
376
377         iounmap(mem_start);
378
379         release_mem_region(pci_resource_start(pdev, 0),
380                            pci_resource_len(pdev, 0));
381         pci_disable_device(pdev);
382 }
383
384
385 #ifdef CONFIG_PM
386 static int prism2_pci_suspend(struct pci_dev *pdev, u32 state)
387 {
388         struct net_device *dev = pci_get_drvdata(pdev);
389
390         if (netif_running(dev)) {
391                 netif_stop_queue(dev);
392                 netif_device_detach(dev);
393         }
394         prism2_suspend(dev);
395         pci_save_state(pdev);
396         pci_disable_device(pdev);
397         pci_set_power_state(pdev, 3);
398
399         return 0;
400 }
401
402 static int prism2_pci_resume(struct pci_dev *pdev)
403 {
404         struct net_device *dev = pci_get_drvdata(pdev);
405
406         pci_enable_device(pdev);
407         pci_restore_state(pdev);
408         prism2_hw_config(dev, 0);
409         if (netif_running(dev)) {
410                 netif_device_attach(dev);
411                 netif_start_queue(dev);
412         }
413
414         return 0;
415 }
416 #endif /* CONFIG_PM */
417
418
419 MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
420
421 static struct pci_driver prism2_pci_drv_id = {
422         .name           = "prism2_pci",
423         .id_table       = prism2_pci_id_table,
424         .probe          = prism2_pci_probe,
425         .remove         = prism2_pci_remove,
426 #ifdef CONFIG_PM
427         .suspend        = prism2_pci_suspend,
428         .resume         = prism2_pci_resume,
429 #endif /* CONFIG_PM */
430         /* Linux 2.4.6 added save_state and enable_wake that are not used here
431          */
432 };
433
434
435 static int __init init_prism2_pci(void)
436 {
437         printk(KERN_INFO "%s: %s\n", dev_info, version);
438
439         return pci_register_driver(&prism2_pci_drv_id);
440 }
441
442
443 static void __exit exit_prism2_pci(void)
444 {
445         pci_unregister_driver(&prism2_pci_drv_id);
446         printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
447 }
448
449
450 module_init(init_prism2_pci);
451 module_exit(exit_prism2_pci);