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> */
7 #include <linux/config.h>
8 #include <linux/version.h>
9 #include <linux/module.h>
10 #include <linux/init.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>
18 #include <linux/ioport.h>
19 #include <linux/pci.h>
22 #include "hostap_wlan.h"
25 static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
26 static char *dev_info = "hostap_pci";
29 MODULE_AUTHOR("Jouni Malinen");
30 MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
32 MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
33 MODULE_LICENSE("GPL");
34 MODULE_VERSION(PRISM2_VERSION);
37 /* FIX: do we need mb/wmb/rmb with memory operations? */
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 },
51 #ifdef PRISM2_IO_DEBUG
53 static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
55 struct hostap_interface *iface;
59 iface = netdev_priv(dev);
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);
68 static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
70 struct hostap_interface *iface;
75 iface = netdev_priv(dev);
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);
85 static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
87 struct hostap_interface *iface;
91 iface = netdev_priv(dev);
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);
100 static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
102 struct hostap_interface *iface;
107 iface = netdev_priv(dev);
108 local = iface->local;
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);
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)))
124 #else /* PRISM2_IO_DEBUG */
126 static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
128 struct hostap_interface *iface;
130 iface = netdev_priv(dev);
131 local = iface->local;
132 writeb(v, local->mem_start + a);
135 static inline u8 hfa384x_inb(struct net_device *dev, int a)
137 struct hostap_interface *iface;
139 iface = netdev_priv(dev);
140 local = iface->local;
141 return readb(local->mem_start + a);
144 static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
146 struct hostap_interface *iface;
148 iface = netdev_priv(dev);
149 local = iface->local;
150 writew(v, local->mem_start + a);
153 static inline u16 hfa384x_inw(struct net_device *dev, int a)
155 struct hostap_interface *iface;
157 iface = netdev_priv(dev);
158 local = iface->local;
159 return readw(local->mem_start + a);
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)))
169 #endif /* PRISM2_IO_DEBUG */
172 static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
178 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
181 for ( ; len > 1; len -= 2)
182 *pos++ = HFA384X_INW_DATA(d_off);
185 *((char *) pos) = HFA384X_INB(d_off);
191 static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
196 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
199 for ( ; len > 1; len -= 2)
200 HFA384X_OUTW_DATA(*pos++, d_off);
203 HFA384X_OUTB(*((char *) pos), d_off);
209 /* FIX: This might change at some point.. */
210 #include "hostap_hw.c"
212 static void prism2_pci_cor_sreset(local_info_t *local)
214 struct net_device *dev = local->dev;
217 reg = HFA384X_INB(HFA384X_PCICOR_OFF);
218 printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
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.
225 * Longer delays can be configured by uncommenting following line: */
226 /* #define PRISM2_PCI_USE_LONG_DELAYS */
228 #ifdef PRISM2_PCI_USE_LONG_DELAYS
231 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
234 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
237 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
239 while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
242 #else /* PRISM2_PCI_USE_LONG_DELAYS */
244 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
246 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
249 #endif /* PRISM2_PCI_USE_LONG_DELAYS */
251 if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
252 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
257 static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
259 struct net_device *dev = local->dev;
261 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
263 HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
265 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
270 static struct prism2_helper_functions prism2_pci_funcs =
272 .card_present = NULL,
273 .cor_sreset = prism2_pci_cor_sreset,
276 .genesis_reset = prism2_pci_genesis_reset,
277 .hw_type = HOSTAP_HW_PCI,
281 static int prism2_pci_probe(struct pci_dev *pdev,
282 const struct pci_device_id *id)
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;
292 if (pci_enable_device(pdev))
295 phymem = pci_resource_start(pdev, 0);
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;
302 mem = ioremap(phymem, pci_resource_len(pdev, 0));
304 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
308 dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
312 iface = netdev_priv(dev);
313 local = iface->local;
316 dev->irq = pdev->irq;
317 local->mem_start = mem;
319 prism2_pci_cor_sreset(local);
321 pci_set_drvdata(pdev, dev);
323 if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
325 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
330 if (!local->pri_only && prism2_hw_config(dev, 1)) {
331 printk(KERN_DEBUG "%s: hardware initialization failed\n",
336 printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
337 "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
339 return hostap_hw_ready(dev);
342 if (irq_registered && dev)
343 free_irq(dev->irq, dev);
348 release_mem_region(phymem, pci_resource_len(pdev, 0));
351 pci_disable_device(pdev);
352 prism2_free_local_data(dev);
358 static void prism2_pci_remove(struct pci_dev *pdev)
360 struct net_device *dev;
361 struct hostap_interface *iface;
362 void __iomem *mem_start;
364 dev = pci_get_drvdata(pdev);
365 iface = netdev_priv(dev);
367 /* Reset the hardware, and ensure interrupts are disabled. */
368 prism2_pci_cor_sreset(iface->local);
369 hfa384x_disable_interrupts(dev);
372 free_irq(dev->irq, dev);
374 mem_start = iface->local->mem_start;
375 prism2_free_local_data(dev);
379 release_mem_region(pci_resource_start(pdev, 0),
380 pci_resource_len(pdev, 0));
381 pci_disable_device(pdev);
386 static int prism2_pci_suspend(struct pci_dev *pdev, u32 state)
388 struct net_device *dev = pci_get_drvdata(pdev);
390 if (netif_running(dev)) {
391 netif_stop_queue(dev);
392 netif_device_detach(dev);
395 pci_save_state(pdev);
396 pci_disable_device(pdev);
397 pci_set_power_state(pdev, 3);
402 static int prism2_pci_resume(struct pci_dev *pdev)
404 struct net_device *dev = pci_get_drvdata(pdev);
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);
416 #endif /* CONFIG_PM */
419 MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
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,
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
435 static int __init init_prism2_pci(void)
437 printk(KERN_INFO "%s: %s\n", dev_info, version);
439 return pci_register_driver(&prism2_pci_drv_id);
443 static void __exit exit_prism2_pci(void)
445 pci_unregister_driver(&prism2_pci_drv_id);
446 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
450 module_init(init_prism2_pci);
451 module_exit(exit_prism2_pci);