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");
36 /* FIX: do we need mb/wmb/rmb with memory operations? */
39 static struct pci_device_id prism2_pci_id_table
[] __devinitdata
= {
40 /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
41 { 0x1260, 0x3872, PCI_ANY_ID
, PCI_ANY_ID
},
42 /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
43 { 0x1260, 0x3873, PCI_ANY_ID
, PCI_ANY_ID
},
44 /* Samsung MagicLAN SWL-2210P */
45 { 0x167d, 0xa000, PCI_ANY_ID
, PCI_ANY_ID
},
50 #ifdef PRISM2_IO_DEBUG
52 static inline void hfa384x_outb_debug(struct net_device
*dev
, int a
, u8 v
)
54 struct hostap_interface
*iface
;
58 iface
= netdev_priv(dev
);
61 spin_lock_irqsave(&local
->lock
, flags
);
62 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTB
, a
, v
);
63 writeb(v
, local
->mem_start
+ a
);
64 spin_unlock_irqrestore(&local
->lock
, flags
);
67 static inline u8
hfa384x_inb_debug(struct net_device
*dev
, int a
)
69 struct hostap_interface
*iface
;
74 iface
= netdev_priv(dev
);
77 spin_lock_irqsave(&local
->lock
, flags
);
78 v
= readb(local
->mem_start
+ a
);
79 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INB
, a
, v
);
80 spin_unlock_irqrestore(&local
->lock
, flags
);
84 static inline void hfa384x_outw_debug(struct net_device
*dev
, int a
, u16 v
)
86 struct hostap_interface
*iface
;
90 iface
= netdev_priv(dev
);
93 spin_lock_irqsave(&local
->lock
, flags
);
94 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTW
, a
, v
);
95 writew(v
, local
->mem_start
+ a
);
96 spin_unlock_irqrestore(&local
->lock
, flags
);
99 static inline u16
hfa384x_inw_debug(struct net_device
*dev
, int a
)
101 struct hostap_interface
*iface
;
106 iface
= netdev_priv(dev
);
107 local
= iface
->local
;
109 spin_lock_irqsave(&local
->lock
, flags
);
110 v
= readw(local
->mem_start
+ a
);
111 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INW
, a
, v
);
112 spin_unlock_irqrestore(&local
->lock
, flags
);
116 #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
117 #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
118 #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
119 #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
120 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
121 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
123 #else /* PRISM2_IO_DEBUG */
125 static inline void hfa384x_outb(struct net_device
*dev
, int a
, u8 v
)
127 struct hostap_interface
*iface
;
129 iface
= netdev_priv(dev
);
130 local
= iface
->local
;
131 writeb(v
, local
->mem_start
+ a
);
134 static inline u8
hfa384x_inb(struct net_device
*dev
, int a
)
136 struct hostap_interface
*iface
;
138 iface
= netdev_priv(dev
);
139 local
= iface
->local
;
140 return readb(local
->mem_start
+ a
);
143 static inline void hfa384x_outw(struct net_device
*dev
, int a
, u16 v
)
145 struct hostap_interface
*iface
;
147 iface
= netdev_priv(dev
);
148 local
= iface
->local
;
149 writew(v
, local
->mem_start
+ a
);
152 static inline u16
hfa384x_inw(struct net_device
*dev
, int a
)
154 struct hostap_interface
*iface
;
156 iface
= netdev_priv(dev
);
157 local
= iface
->local
;
158 return readw(local
->mem_start
+ a
);
161 #define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
162 #define HFA384X_INB(a) hfa384x_inb(dev, (a))
163 #define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
164 #define HFA384X_INW(a) hfa384x_inw(dev, (a))
165 #define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
166 #define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
168 #endif /* PRISM2_IO_DEBUG */
171 static int hfa384x_from_bap(struct net_device
*dev
, u16 bap
, void *buf
,
177 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
180 for ( ; len
> 1; len
-= 2)
181 *pos
++ = HFA384X_INW_DATA(d_off
);
184 *((char *) pos
) = HFA384X_INB(d_off
);
190 static int hfa384x_to_bap(struct net_device
*dev
, u16 bap
, void *buf
, int len
)
195 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
198 for ( ; len
> 1; len
-= 2)
199 HFA384X_OUTW_DATA(*pos
++, d_off
);
202 HFA384X_OUTB(*((char *) pos
), d_off
);
208 /* FIX: This might change at some point.. */
209 #include "hostap_hw.c"
211 static void prism2_pci_cor_sreset(local_info_t
*local
)
213 struct net_device
*dev
= local
->dev
;
216 reg
= HFA384X_INB(HFA384X_PCICOR_OFF
);
217 printk(KERN_DEBUG
"%s: Original COR value: 0x%0x\n", dev
->name
, reg
);
219 /* linux-wlan-ng uses extremely long hold and settle times for
220 * COR sreset. A comment in the driver code mentions that the long
221 * delays appear to be necessary. However, at least IBM 22P6901 seems
222 * to work fine with shorter delays.
224 * Longer delays can be configured by uncommenting following line: */
225 /* #define PRISM2_PCI_USE_LONG_DELAYS */
227 #ifdef PRISM2_PCI_USE_LONG_DELAYS
230 HFA384X_OUTW(reg
| 0x0080, HFA384X_PCICOR_OFF
);
233 HFA384X_OUTW(reg
& ~0x0080, HFA384X_PCICOR_OFF
);
236 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
238 while ((HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
) && --i
)
241 #else /* PRISM2_PCI_USE_LONG_DELAYS */
243 HFA384X_OUTW(reg
| 0x0080, HFA384X_PCICOR_OFF
);
245 HFA384X_OUTW(reg
& ~0x0080, HFA384X_PCICOR_OFF
);
248 #endif /* PRISM2_PCI_USE_LONG_DELAYS */
250 if (HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
) {
251 printk(KERN_DEBUG
"%s: COR sreset timeout\n", dev
->name
);
256 static void prism2_pci_genesis_reset(local_info_t
*local
, int hcr
)
258 struct net_device
*dev
= local
->dev
;
260 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF
);
262 HFA384X_OUTW(hcr
, HFA384X_PCIHCR_OFF
);
264 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF
);
269 static struct prism2_helper_functions prism2_pci_funcs
=
271 .card_present
= NULL
,
272 .cor_sreset
= prism2_pci_cor_sreset
,
275 .genesis_reset
= prism2_pci_genesis_reset
,
276 .hw_type
= HOSTAP_HW_PCI
,
280 static int prism2_pci_probe(struct pci_dev
*pdev
,
281 const struct pci_device_id
*id
)
283 unsigned long phymem
;
284 void __iomem
*mem
= NULL
;
285 local_info_t
*local
= NULL
;
286 struct net_device
*dev
= NULL
;
287 static int cards_found
/* = 0 */;
288 int irq_registered
= 0;
289 struct hostap_interface
*iface
;
291 if (pci_enable_device(pdev
))
294 phymem
= pci_resource_start(pdev
, 0);
296 if (!request_mem_region(phymem
, pci_resource_len(pdev
, 0), "Prism2")) {
297 printk(KERN_ERR
"prism2: Cannot reserve PCI memory region\n");
298 goto err_out_disable
;
301 mem
= ioremap(phymem
, pci_resource_len(pdev
, 0));
303 printk(KERN_ERR
"prism2: Cannot remap PCI memory region\n") ;
307 #ifdef PRISM2_BUS_MASTER
308 pci_set_master(pdev
);
309 #endif /* PRISM2_BUS_MASTER */
311 dev
= prism2_init_local_data(&prism2_pci_funcs
, cards_found
);
314 iface
= netdev_priv(dev
);
315 local
= iface
->local
;
318 dev
->irq
= pdev
->irq
;
319 local
->mem_start
= mem
;
321 prism2_pci_cor_sreset(local
);
323 pci_set_drvdata(pdev
, dev
);
325 if (request_irq(dev
->irq
, prism2_interrupt
, SA_SHIRQ
, dev
->name
,
327 printk(KERN_WARNING
"%s: request_irq failed\n", dev
->name
);
332 if (!local
->pri_only
&& prism2_hw_config(dev
, 1)) {
333 printk(KERN_DEBUG
"%s: hardware initialization failed\n",
338 printk(KERN_INFO
"%s: Intersil Prism2.5 PCI: "
339 "mem=0x%lx, irq=%d\n", dev
->name
, phymem
, dev
->irq
);
341 return hostap_hw_ready(dev
);
344 if (irq_registered
&& dev
)
345 free_irq(dev
->irq
, dev
);
350 release_mem_region(phymem
, pci_resource_len(pdev
, 0));
353 pci_disable_device(pdev
);
354 prism2_free_local_data(dev
);
360 static void prism2_pci_remove(struct pci_dev
*pdev
)
362 struct net_device
*dev
;
363 struct hostap_interface
*iface
;
364 void __iomem
*mem_start
;
366 dev
= pci_get_drvdata(pdev
);
367 iface
= netdev_priv(dev
);
369 /* Reset the hardware, and ensure interrupts are disabled. */
370 prism2_pci_cor_sreset(iface
->local
);
371 hfa384x_disable_interrupts(dev
);
374 free_irq(dev
->irq
, dev
);
376 mem_start
= iface
->local
->mem_start
;
377 prism2_free_local_data(dev
);
381 release_mem_region(pci_resource_start(pdev
, 0),
382 pci_resource_len(pdev
, 0));
383 pci_disable_device(pdev
);
388 static int prism2_pci_suspend(struct pci_dev
*pdev
, u32 state
)
390 struct net_device
*dev
= pci_get_drvdata(pdev
);
392 if (netif_running(dev
)) {
393 netif_stop_queue(dev
);
394 netif_device_detach(dev
);
397 pci_save_state(pdev
);
398 pci_disable_device(pdev
);
399 pci_set_power_state(pdev
, 3);
404 static int prism2_pci_resume(struct pci_dev
*pdev
)
406 struct net_device
*dev
= pci_get_drvdata(pdev
);
408 pci_enable_device(pdev
);
409 pci_restore_state(pdev
);
410 prism2_hw_config(dev
, 0);
411 if (netif_running(dev
)) {
412 netif_device_attach(dev
);
413 netif_start_queue(dev
);
418 #endif /* CONFIG_PM */
421 MODULE_DEVICE_TABLE(pci
, prism2_pci_id_table
);
423 static struct pci_driver prism2_pci_drv_id
= {
424 .name
= "prism2_pci",
425 .id_table
= prism2_pci_id_table
,
426 .probe
= prism2_pci_probe
,
427 .remove
= prism2_pci_remove
,
429 .suspend
= prism2_pci_suspend
,
430 .resume
= prism2_pci_resume
,
431 #endif /* CONFIG_PM */
432 /* Linux 2.4.6 added save_state and enable_wake that are not used here
437 static int __init
init_prism2_pci(void)
439 printk(KERN_INFO
"%s: %s\n", dev_info
, version
);
441 return pci_register_driver(&prism2_pci_drv_id
);
445 static void __exit
exit_prism2_pci(void)
447 pci_unregister_driver(&prism2_pci_drv_id
);
448 printk(KERN_INFO
"%s: Driver unloaded\n", dev_info
);
452 module_init(init_prism2_pci
);
453 module_exit(exit_prism2_pci
);