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 /* struct local_info::hw_priv */
38 struct hostap_pci_priv {
39 void __iomem *mem_start;
43 /* FIX: do we need mb/wmb/rmb with memory operations? */
46 static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
47 /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
48 { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
49 /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
50 { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
51 /* Samsung MagicLAN SWL-2210P */
52 { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
57 #ifdef PRISM2_IO_DEBUG
59 static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
61 struct hostap_interface *iface;
62 struct hostap_pci_priv *hw_priv;
66 iface = netdev_priv(dev);
68 hw_priv = local->hw_priv;
70 spin_lock_irqsave(&local->lock, flags);
71 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
72 writeb(v, hw_priv->mem_start + a);
73 spin_unlock_irqrestore(&local->lock, flags);
76 static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
78 struct hostap_interface *iface;
79 struct hostap_pci_priv *hw_priv;
84 iface = netdev_priv(dev);
86 hw_priv = local->hw_priv;
88 spin_lock_irqsave(&local->lock, flags);
89 v = readb(hw_priv->mem_start + a);
90 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
91 spin_unlock_irqrestore(&local->lock, flags);
95 static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
97 struct hostap_interface *iface;
98 struct hostap_pci_priv *hw_priv;
102 iface = netdev_priv(dev);
103 local = iface->local;
104 hw_priv = local->hw_priv;
106 spin_lock_irqsave(&local->lock, flags);
107 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
108 writew(v, hw_priv->mem_start + a);
109 spin_unlock_irqrestore(&local->lock, flags);
112 static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
114 struct hostap_interface *iface;
115 struct hostap_pci_priv *hw_priv;
120 iface = netdev_priv(dev);
121 local = iface->local;
122 hw_priv = local->hw_priv;
124 spin_lock_irqsave(&local->lock, flags);
125 v = readw(hw_priv->mem_start + a);
126 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
127 spin_unlock_irqrestore(&local->lock, flags);
131 #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
132 #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
133 #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
134 #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
135 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
136 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
138 #else /* PRISM2_IO_DEBUG */
140 static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
142 struct hostap_interface *iface;
143 struct hostap_pci_priv *hw_priv;
144 iface = netdev_priv(dev);
145 hw_priv = iface->local->hw_priv;
146 writeb(v, hw_priv->mem_start + a);
149 static inline u8 hfa384x_inb(struct net_device *dev, int a)
151 struct hostap_interface *iface;
152 struct hostap_pci_priv *hw_priv;
153 iface = netdev_priv(dev);
154 hw_priv = iface->local->hw_priv;
155 return readb(hw_priv->mem_start + a);
158 static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
160 struct hostap_interface *iface;
161 struct hostap_pci_priv *hw_priv;
162 iface = netdev_priv(dev);
163 hw_priv = iface->local->hw_priv;
164 writew(v, hw_priv->mem_start + a);
167 static inline u16 hfa384x_inw(struct net_device *dev, int a)
169 struct hostap_interface *iface;
170 struct hostap_pci_priv *hw_priv;
171 iface = netdev_priv(dev);
172 hw_priv = iface->local->hw_priv;
173 return readw(hw_priv->mem_start + a);
176 #define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
177 #define HFA384X_INB(a) hfa384x_inb(dev, (a))
178 #define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
179 #define HFA384X_INW(a) hfa384x_inw(dev, (a))
180 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
181 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
183 #endif /* PRISM2_IO_DEBUG */
186 static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
192 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
195 for ( ; len > 1; len -= 2)
196 *pos++ = HFA384X_INW_DATA(d_off);
199 *((char *) pos) = HFA384X_INB(d_off);
205 static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
210 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
213 for ( ; len > 1; len -= 2)
214 HFA384X_OUTW_DATA(*pos++, d_off);
217 HFA384X_OUTB(*((char *) pos), d_off);
223 /* FIX: This might change at some point.. */
224 #include "hostap_hw.c"
226 static void prism2_pci_cor_sreset(local_info_t *local)
228 struct net_device *dev = local->dev;
231 reg = HFA384X_INB(HFA384X_PCICOR_OFF);
232 printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
234 /* linux-wlan-ng uses extremely long hold and settle times for
235 * COR sreset. A comment in the driver code mentions that the long
236 * delays appear to be necessary. However, at least IBM 22P6901 seems
237 * to work fine with shorter delays.
239 * Longer delays can be configured by uncommenting following line: */
240 /* #define PRISM2_PCI_USE_LONG_DELAYS */
242 #ifdef PRISM2_PCI_USE_LONG_DELAYS
245 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
248 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
251 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
253 while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
256 #else /* PRISM2_PCI_USE_LONG_DELAYS */
258 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
260 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
263 #endif /* PRISM2_PCI_USE_LONG_DELAYS */
265 if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
266 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
271 static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
273 struct net_device *dev = local->dev;
275 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
277 HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
279 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
284 static struct prism2_helper_functions prism2_pci_funcs =
286 .card_present = NULL,
287 .cor_sreset = prism2_pci_cor_sreset,
288 .genesis_reset = prism2_pci_genesis_reset,
289 .hw_type = HOSTAP_HW_PCI,
293 static int prism2_pci_probe(struct pci_dev *pdev,
294 const struct pci_device_id *id)
296 unsigned long phymem;
297 void __iomem *mem = NULL;
298 local_info_t *local = NULL;
299 struct net_device *dev = NULL;
300 static int cards_found /* = 0 */;
301 int irq_registered = 0;
302 struct hostap_interface *iface;
303 struct hostap_pci_priv *hw_priv;
305 hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
308 memset(hw_priv, 0, sizeof(*hw_priv));
310 if (pci_enable_device(pdev))
313 phymem = pci_resource_start(pdev, 0);
315 if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
316 printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
317 goto err_out_disable;
320 mem = ioremap(phymem, pci_resource_len(pdev, 0));
322 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
326 dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
330 iface = netdev_priv(dev);
331 local = iface->local;
332 local->hw_priv = hw_priv;
335 dev->irq = pdev->irq;
336 hw_priv->mem_start = mem;
338 prism2_pci_cor_sreset(local);
340 pci_set_drvdata(pdev, dev);
342 if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
344 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
349 if (!local->pri_only && prism2_hw_config(dev, 1)) {
350 printk(KERN_DEBUG "%s: hardware initialization failed\n",
355 printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
356 "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
358 return hostap_hw_ready(dev);
361 if (irq_registered && dev)
362 free_irq(dev->irq, dev);
367 release_mem_region(phymem, pci_resource_len(pdev, 0));
370 pci_disable_device(pdev);
371 prism2_free_local_data(dev);
378 static void prism2_pci_remove(struct pci_dev *pdev)
380 struct net_device *dev;
381 struct hostap_interface *iface;
382 void __iomem *mem_start;
383 struct hostap_pci_priv *hw_priv;
385 dev = pci_get_drvdata(pdev);
386 iface = netdev_priv(dev);
387 hw_priv = iface->local->hw_priv;
389 /* Reset the hardware, and ensure interrupts are disabled. */
390 prism2_pci_cor_sreset(iface->local);
391 hfa384x_disable_interrupts(dev);
394 free_irq(dev->irq, dev);
396 mem_start = hw_priv->mem_start;
397 prism2_free_local_data(dev);
402 release_mem_region(pci_resource_start(pdev, 0),
403 pci_resource_len(pdev, 0));
404 pci_disable_device(pdev);
409 static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state)
411 struct net_device *dev = pci_get_drvdata(pdev);
413 if (netif_running(dev)) {
414 netif_stop_queue(dev);
415 netif_device_detach(dev);
418 pci_save_state(pdev);
419 pci_disable_device(pdev);
420 pci_set_power_state(pdev, PCI_D3hot);
425 static int prism2_pci_resume(struct pci_dev *pdev)
427 struct net_device *dev = pci_get_drvdata(pdev);
429 pci_enable_device(pdev);
430 pci_restore_state(pdev);
431 prism2_hw_config(dev, 0);
432 if (netif_running(dev)) {
433 netif_device_attach(dev);
434 netif_start_queue(dev);
439 #endif /* CONFIG_PM */
442 MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
444 static struct pci_driver prism2_pci_drv_id = {
445 .name = "hostap_pci",
446 .id_table = prism2_pci_id_table,
447 .probe = prism2_pci_probe,
448 .remove = prism2_pci_remove,
450 .suspend = prism2_pci_suspend,
451 .resume = prism2_pci_resume,
452 #endif /* CONFIG_PM */
453 /* Linux 2.4.6 added save_state and enable_wake that are not used here
458 static int __init init_prism2_pci(void)
460 printk(KERN_INFO "%s: %s\n", dev_info, version);
462 return pci_register_driver(&prism2_pci_drv_id);
466 static void __exit exit_prism2_pci(void)
468 pci_unregister_driver(&prism2_pci_drv_id);
469 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
473 module_init(init_prism2_pci);
474 module_exit(exit_prism2_pci);