3 #include <linux/module.h>
5 #include <linux/slab.h>
6 #include <linux/wait.h>
7 #include <linux/timer.h>
8 #include <linux/skbuff.h>
9 #include <linux/netdevice.h>
10 #include <linux/workqueue.h>
11 #include <linux/wireless.h>
12 #include <net/iw_handler.h>
14 #include <pcmcia/cistpl.h>
15 #include <pcmcia/cisreg.h>
16 #include <pcmcia/ds.h>
20 #include "hostap_wlan.h"
23 static char *dev_info
= "hostap_cs";
25 MODULE_AUTHOR("Jouni Malinen");
26 MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
28 MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
29 MODULE_LICENSE("GPL");
32 static int ignore_cis_vcc
;
33 module_param(ignore_cis_vcc
, int, 0444);
34 MODULE_PARM_DESC(ignore_cis_vcc
, "Ignore broken CIS VCC entry");
37 /* struct local_info::hw_priv */
38 struct hostap_cs_priv
{
39 struct pcmcia_device
*link
;
40 int sandisk_connectplus
;
44 #ifdef PRISM2_IO_DEBUG
46 static inline void hfa384x_outb_debug(struct net_device
*dev
, int a
, u8 v
)
48 struct hostap_interface
*iface
;
52 iface
= netdev_priv(dev
);
54 spin_lock_irqsave(&local
->lock
, flags
);
55 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTB
, a
, v
);
56 outb(v
, dev
->base_addr
+ a
);
57 spin_unlock_irqrestore(&local
->lock
, flags
);
60 static inline u8
hfa384x_inb_debug(struct net_device
*dev
, int a
)
62 struct hostap_interface
*iface
;
67 iface
= netdev_priv(dev
);
69 spin_lock_irqsave(&local
->lock
, flags
);
70 v
= inb(dev
->base_addr
+ a
);
71 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INB
, a
, v
);
72 spin_unlock_irqrestore(&local
->lock
, flags
);
76 static inline void hfa384x_outw_debug(struct net_device
*dev
, int a
, u16 v
)
78 struct hostap_interface
*iface
;
82 iface
= netdev_priv(dev
);
84 spin_lock_irqsave(&local
->lock
, flags
);
85 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTW
, a
, v
);
86 outw(v
, dev
->base_addr
+ a
);
87 spin_unlock_irqrestore(&local
->lock
, flags
);
90 static inline u16
hfa384x_inw_debug(struct net_device
*dev
, int a
)
92 struct hostap_interface
*iface
;
97 iface
= netdev_priv(dev
);
99 spin_lock_irqsave(&local
->lock
, flags
);
100 v
= inw(dev
->base_addr
+ a
);
101 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INW
, a
, v
);
102 spin_unlock_irqrestore(&local
->lock
, flags
);
106 static inline void hfa384x_outsw_debug(struct net_device
*dev
, int a
,
109 struct hostap_interface
*iface
;
113 iface
= netdev_priv(dev
);
114 local
= iface
->local
;
115 spin_lock_irqsave(&local
->lock
, flags
);
116 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTSW
, a
, wc
);
117 outsw(dev
->base_addr
+ a
, buf
, wc
);
118 spin_unlock_irqrestore(&local
->lock
, flags
);
121 static inline void hfa384x_insw_debug(struct net_device
*dev
, int a
,
124 struct hostap_interface
*iface
;
128 iface
= netdev_priv(dev
);
129 local
= iface
->local
;
130 spin_lock_irqsave(&local
->lock
, flags
);
131 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INSW
, a
, wc
);
132 insw(dev
->base_addr
+ a
, buf
, wc
);
133 spin_unlock_irqrestore(&local
->lock
, flags
);
136 #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
137 #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
138 #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
139 #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
140 #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
141 #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
143 #else /* PRISM2_IO_DEBUG */
145 #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
146 #define HFA384X_INB(a) inb(dev->base_addr + (a))
147 #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
148 #define HFA384X_INW(a) inw(dev->base_addr + (a))
149 #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
150 #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
152 #endif /* PRISM2_IO_DEBUG */
155 static int hfa384x_from_bap(struct net_device
*dev
, u16 bap
, void *buf
,
161 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
165 HFA384X_INSW(d_off
, buf
, len
/ 2);
169 *((char *) pos
) = HFA384X_INB(d_off
);
175 static int hfa384x_to_bap(struct net_device
*dev
, u16 bap
, void *buf
, int len
)
180 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
184 HFA384X_OUTSW(d_off
, buf
, len
/ 2);
188 HFA384X_OUTB(*((char *) pos
), d_off
);
194 /* FIX: This might change at some point.. */
195 #include "hostap_hw.c"
199 static void prism2_detach(struct pcmcia_device
*p_dev
);
200 static void prism2_release(u_long arg
);
201 static int prism2_config(struct pcmcia_device
*link
);
204 static int prism2_pccard_card_present(local_info_t
*local
)
206 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
207 if (hw_priv
!= NULL
&& hw_priv
->link
!= NULL
&& pcmcia_dev_present(hw_priv
->link
))
214 * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
215 * Document No. 20-10-00058, January 2004
216 * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
218 #define SANDISK_WLAN_ACTIVATION_OFF 0x40
219 #define SANDISK_HCR_OFF 0x42
222 static void sandisk_set_iobase(local_info_t
*local
)
225 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
227 res
= pcmcia_write_config_byte(hw_priv
->link
, 0x10,
228 hw_priv
->link
->resource
[0]->start
& 0x00ff);
230 printk(KERN_DEBUG
"Prism3 SanDisk - failed to set I/O base 0 -"
235 res
= pcmcia_write_config_byte(hw_priv
->link
, 0x12,
236 (hw_priv
->link
->resource
[0]->start
>> 8) & 0x00ff);
238 printk(KERN_DEBUG
"Prism3 SanDisk - failed to set I/O base 1 -"
244 static void sandisk_write_hcr(local_info_t
*local
, int hcr
)
246 struct net_device
*dev
= local
->dev
;
249 HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF
);
251 for (i
= 0; i
< 10; i
++) {
252 HFA384X_OUTB(hcr
, SANDISK_HCR_OFF
);
255 HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF
);
259 static int sandisk_enable_wireless(struct net_device
*dev
)
262 struct hostap_interface
*iface
= netdev_priv(dev
);
263 local_info_t
*local
= iface
->local
;
264 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
266 if (resource_size(hw_priv
->link
->resource
[0]) < 0x42) {
267 /* Not enough ports to be SanDisk multi-function card */
272 if (hw_priv
->link
->manf_id
!= 0xd601 || hw_priv
->link
->card_id
!= 0x0101) {
273 /* No SanDisk manfid found */
278 if (hw_priv
->link
->socket
->functions
< 2) {
279 /* No multi-function links found */
284 printk(KERN_DEBUG
"%s: Multi-function SanDisk ConnectPlus detected"
285 " - using vendor-specific initialization\n", dev
->name
);
286 hw_priv
->sandisk_connectplus
= 1;
288 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
291 printk(KERN_DEBUG
"%s: SanDisk - COR sreset failed (%d)\n",
298 * Do not enable interrupts here to avoid some bogus events. Interrupts
299 * will be enabled during the first cor_sreset call.
301 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
302 (COR_LEVEL_REQ
| 0x8 | COR_ADDR_DECODE
|
305 printk(KERN_DEBUG
"%s: SanDisk - COR sreset failed (%d)\n",
311 sandisk_set_iobase(local
);
313 HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF
);
315 HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF
);
323 static void prism2_pccard_cor_sreset(local_info_t
*local
)
327 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
329 if (!prism2_pccard_card_present(local
))
332 res
= pcmcia_read_config_byte(hw_priv
->link
, CISREG_COR
, &val
);
334 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 1 (%d)\n",
338 printk(KERN_DEBUG
"prism2_pccard_cor_sreset: original COR %02x\n",
341 val
|= COR_SOFT_RESET
;
342 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
, val
);
344 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 2 (%d)\n",
349 mdelay(hw_priv
->sandisk_connectplus
? 5 : 2);
351 val
&= ~COR_SOFT_RESET
;
352 if (hw_priv
->sandisk_connectplus
)
354 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
, val
);
356 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 3 (%d)\n",
361 mdelay(hw_priv
->sandisk_connectplus
? 5 : 2);
363 if (hw_priv
->sandisk_connectplus
)
364 sandisk_set_iobase(local
);
368 static void prism2_pccard_genesis_reset(local_info_t
*local
, int hcr
)
372 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
374 if (!prism2_pccard_card_present(local
))
377 if (hw_priv
->sandisk_connectplus
) {
378 sandisk_write_hcr(local
, hcr
);
382 res
= pcmcia_read_config_byte(hw_priv
->link
, CISREG_COR
, &old_cor
);
384 printk(KERN_DEBUG
"prism2_pccard_genesis_sreset failed 1 "
388 printk(KERN_DEBUG
"prism2_pccard_genesis_sreset: original COR %02x\n",
391 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
392 old_cor
| COR_SOFT_RESET
);
394 printk(KERN_DEBUG
"prism2_pccard_genesis_sreset failed 2 "
401 /* Setup Genesis mode */
402 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_CCSR
, hcr
);
404 printk(KERN_DEBUG
"prism2_pccard_genesis_sreset failed 3 "
410 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
411 old_cor
& ~COR_SOFT_RESET
);
413 printk(KERN_DEBUG
"prism2_pccard_genesis_sreset failed 4 "
422 static struct prism2_helper_functions prism2_pccard_funcs
=
424 .card_present
= prism2_pccard_card_present
,
425 .cor_sreset
= prism2_pccard_cor_sreset
,
426 .genesis_reset
= prism2_pccard_genesis_reset
,
427 .hw_type
= HOSTAP_HW_PCCARD
,
431 /* allocate local data and register with CardServices
432 * initialize dev_link structure, but do not configure the card yet */
433 static int hostap_cs_probe(struct pcmcia_device
*p_dev
)
437 PDEBUG(DEBUG_HW
, "%s: setting Vcc=33 (constant)\n", dev_info
);
439 ret
= prism2_config(p_dev
);
441 PDEBUG(DEBUG_EXTRA
, "prism2_config() failed\n");
448 static void prism2_detach(struct pcmcia_device
*link
)
450 PDEBUG(DEBUG_FLOW
, "prism2_detach\n");
452 prism2_release((u_long
)link
);
454 /* release net devices */
456 struct hostap_cs_priv
*hw_priv
;
457 struct net_device
*dev
;
458 struct hostap_interface
*iface
;
460 iface
= netdev_priv(dev
);
461 hw_priv
= iface
->local
->hw_priv
;
462 prism2_free_local_data(dev
);
468 static int prism2_config_check(struct pcmcia_device
*p_dev
, void *priv_data
)
470 if (p_dev
->config_index
== 0)
473 return pcmcia_request_io(p_dev
);
476 static int prism2_config(struct pcmcia_device
*link
)
478 struct net_device
*dev
;
479 struct hostap_interface
*iface
;
482 struct hostap_cs_priv
*hw_priv
;
485 PDEBUG(DEBUG_FLOW
, "prism2_config()\n");
487 hw_priv
= kzalloc(sizeof(*hw_priv
), GFP_KERNEL
);
488 if (hw_priv
== NULL
) {
493 /* Look for an appropriate configuration table entry in the CIS */
494 link
->config_flags
|= CONF_AUTO_SET_VPP
| CONF_AUTO_AUDIO
|
495 CONF_AUTO_CHECK_VCC
| CONF_AUTO_SET_IO
| CONF_ENABLE_IRQ
;
497 link
->config_flags
&= ~CONF_AUTO_CHECK_VCC
;
498 ret
= pcmcia_loop_config(link
, prism2_config_check
, NULL
);
501 printk(KERN_ERR
"GetNextTuple(): No matching "
502 "CIS configuration. Maybe you need the "
503 "ignore_cis_vcc=1 parameter.\n");
507 /* Need to allocate net_device before requesting IRQ handler */
508 dev
= prism2_init_local_data(&prism2_pccard_funcs
, 0,
514 iface
= netdev_priv(dev
);
515 local
= iface
->local
;
516 local
->hw_priv
= hw_priv
;
517 hw_priv
->link
= link
;
520 * We enable IRQ here, but IRQ handler will not proceed
521 * until dev->base_addr is set below. This protect us from
522 * receive interrupts when driver is not initialized.
524 ret
= pcmcia_request_irq(link
, prism2_interrupt
);
528 ret
= pcmcia_enable_device(link
);
532 spin_lock_irqsave(&local
->irq_init_lock
, flags
);
533 dev
->irq
= link
->irq
;
534 dev
->base_addr
= link
->resource
[0]->start
;
535 spin_unlock_irqrestore(&local
->irq_init_lock
, flags
);
539 sandisk_enable_wireless(dev
);
541 ret
= prism2_hw_config(dev
, 1);
543 ret
= hostap_hw_ready(dev
);
549 prism2_release((u_long
)link
);
554 static void prism2_release(u_long arg
)
556 struct pcmcia_device
*link
= (struct pcmcia_device
*)arg
;
558 PDEBUG(DEBUG_FLOW
, "prism2_release\n");
561 struct net_device
*dev
= link
->priv
;
562 struct hostap_interface
*iface
;
564 iface
= netdev_priv(dev
);
565 prism2_hw_shutdown(dev
, 0);
566 iface
->local
->shutdown
= 1;
569 pcmcia_disable_device(link
);
570 PDEBUG(DEBUG_FLOW
, "release - done\n");
573 static int hostap_cs_suspend(struct pcmcia_device
*link
)
575 struct net_device
*dev
= (struct net_device
*) link
->priv
;
577 struct hostap_interface
*iface
= NULL
;
582 iface
= netdev_priv(dev
);
584 PDEBUG(DEBUG_EXTRA
, "%s: CS_EVENT_PM_SUSPEND\n", dev_info
);
585 if (iface
&& iface
->local
)
586 dev_open
= iface
->local
->num_dev_open
> 0;
588 netif_stop_queue(dev
);
589 netif_device_detach(dev
);
596 static int hostap_cs_resume(struct pcmcia_device
*link
)
598 struct net_device
*dev
= (struct net_device
*) link
->priv
;
600 struct hostap_interface
*iface
= NULL
;
605 iface
= netdev_priv(dev
);
607 PDEBUG(DEBUG_EXTRA
, "%s: CS_EVENT_PM_RESUME\n", dev_info
);
609 if (iface
&& iface
->local
)
610 dev_open
= iface
->local
->num_dev_open
> 0;
612 prism2_hw_shutdown(dev
, 1);
613 prism2_hw_config(dev
, dev_open
? 0 : 1);
615 netif_device_attach(dev
);
616 netif_start_queue(dev
);
622 static const struct pcmcia_device_id hostap_cs_ids
[] = {
623 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
624 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
625 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
626 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
627 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
628 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3301),
629 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
630 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
631 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
632 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
633 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
634 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
635 PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
636 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
637 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
638 /* PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), conflict with pcnet_cs */
639 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
640 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
641 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
642 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
643 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
644 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0xd601, 0x0005, "ADLINK 345 CF",
646 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
648 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
650 PCMCIA_DEVICE_MANF_CARD_PROD_ID3(0x0156, 0x0002, "Version 01.02",
652 PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
653 0x7a954bd9, 0x74be00c6),
654 PCMCIA_DEVICE_PROD_ID123(
655 "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
656 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
657 PCMCIA_DEVICE_PROD_ID123(
658 "Canon", "Wireless LAN CF Card K30225", "Version 01.00",
659 0x96ef6fe2, 0x263fcbab, 0xa57adb8c),
660 PCMCIA_DEVICE_PROD_ID123(
661 "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
662 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
663 PCMCIA_DEVICE_PROD_ID123(
664 "Instant Wireless ", " Network PC CARD", "Version 01.02",
665 0x11d901af, 0x6e9bd926, 0x4b74baa0),
666 PCMCIA_DEVICE_PROD_ID123(
667 "SMC", "SMC2632W", "Version 01.02",
668 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
669 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
670 0x2decece3, 0x82067c18),
671 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
672 0x54f7c49c, 0x15a75e5b),
673 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
674 0x74c5e40d, 0xdb472a18),
675 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
676 0x0733cc81, 0x0c52f395),
677 PCMCIA_DEVICE_PROD_ID12(
678 "ZoomAir 11Mbps High", "Rate wireless Networking",
679 0x273fe3db, 0x32a1eaee),
680 PCMCIA_DEVICE_PROD_ID123(
681 "Pretec", "CompactWLAN Card 802.11b", "2.5",
682 0x1cadd3e5, 0xe697636c, 0x7a5bfcf1),
683 PCMCIA_DEVICE_PROD_ID123(
684 "U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02",
685 0xc7b8df9d, 0x1700d087, 0x4b74baa0),
686 PCMCIA_DEVICE_PROD_ID123(
687 "Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio",
689 0x5cd01705, 0x4271660f, 0x9d08ee12),
690 PCMCIA_DEVICE_PROD_ID123(
691 "Wireless LAN" , "11Mbps PC Card", "Version 01.02",
692 0x4b8870ff, 0x70e946d1, 0x4b74baa0),
693 PCMCIA_DEVICE_PROD_ID3("HFA3863", 0x355cb092),
694 PCMCIA_DEVICE_PROD_ID3("ISL37100P", 0x630d52b2),
695 PCMCIA_DEVICE_PROD_ID3("ISL37101P-10", 0xdd97a26b),
696 PCMCIA_DEVICE_PROD_ID3("ISL37300P", 0xc9049a39),
699 MODULE_DEVICE_TABLE(pcmcia
, hostap_cs_ids
);
702 static struct pcmcia_driver hostap_driver
= {
704 .probe
= hostap_cs_probe
,
705 .remove
= prism2_detach
,
706 .owner
= THIS_MODULE
,
707 .id_table
= hostap_cs_ids
,
708 .suspend
= hostap_cs_suspend
,
709 .resume
= hostap_cs_resume
,
711 module_pcmcia_driver(hostap_driver
);