1 // SPDX-License-Identifier: GPL-2.0-only
4 #include <linux/module.h>
6 #include <linux/slab.h>
7 #include <linux/wait.h>
8 #include <linux/timer.h>
9 #include <linux/skbuff.h>
10 #include <linux/netdevice.h>
11 #include <linux/workqueue.h>
12 #include <linux/wireless.h>
13 #include <net/iw_handler.h>
15 #include <pcmcia/cistpl.h>
16 #include <pcmcia/cisreg.h>
17 #include <pcmcia/ds.h>
21 #include "hostap_wlan.h"
24 static char *dev_info
= "hostap_cs";
26 MODULE_AUTHOR("Jouni Malinen");
27 MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
29 MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
30 MODULE_LICENSE("GPL");
33 static int ignore_cis_vcc
;
34 module_param(ignore_cis_vcc
, int, 0444);
35 MODULE_PARM_DESC(ignore_cis_vcc
, "Ignore broken CIS VCC entry");
38 /* struct local_info::hw_priv */
39 struct hostap_cs_priv
{
40 struct pcmcia_device
*link
;
41 int sandisk_connectplus
;
45 #ifdef PRISM2_IO_DEBUG
47 static inline void hfa384x_outb_debug(struct net_device
*dev
, int a
, u8 v
)
49 struct hostap_interface
*iface
;
53 iface
= netdev_priv(dev
);
55 spin_lock_irqsave(&local
->lock
, flags
);
56 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTB
, a
, v
);
57 outb(v
, dev
->base_addr
+ a
);
58 spin_unlock_irqrestore(&local
->lock
, flags
);
61 static inline u8
hfa384x_inb_debug(struct net_device
*dev
, int a
)
63 struct hostap_interface
*iface
;
68 iface
= netdev_priv(dev
);
70 spin_lock_irqsave(&local
->lock
, flags
);
71 v
= inb(dev
->base_addr
+ a
);
72 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INB
, a
, v
);
73 spin_unlock_irqrestore(&local
->lock
, flags
);
77 static inline void hfa384x_outw_debug(struct net_device
*dev
, int a
, u16 v
)
79 struct hostap_interface
*iface
;
83 iface
= netdev_priv(dev
);
85 spin_lock_irqsave(&local
->lock
, flags
);
86 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTW
, a
, v
);
87 outw(v
, dev
->base_addr
+ a
);
88 spin_unlock_irqrestore(&local
->lock
, flags
);
91 static inline u16
hfa384x_inw_debug(struct net_device
*dev
, int a
)
93 struct hostap_interface
*iface
;
98 iface
= netdev_priv(dev
);
100 spin_lock_irqsave(&local
->lock
, flags
);
101 v
= inw(dev
->base_addr
+ a
);
102 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INW
, a
, v
);
103 spin_unlock_irqrestore(&local
->lock
, flags
);
107 static inline void hfa384x_outsw_debug(struct net_device
*dev
, int a
,
110 struct hostap_interface
*iface
;
114 iface
= netdev_priv(dev
);
115 local
= iface
->local
;
116 spin_lock_irqsave(&local
->lock
, flags
);
117 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_OUTSW
, a
, wc
);
118 outsw(dev
->base_addr
+ a
, buf
, wc
);
119 spin_unlock_irqrestore(&local
->lock
, flags
);
122 static inline void hfa384x_insw_debug(struct net_device
*dev
, int a
,
125 struct hostap_interface
*iface
;
129 iface
= netdev_priv(dev
);
130 local
= iface
->local
;
131 spin_lock_irqsave(&local
->lock
, flags
);
132 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INSW
, a
, wc
);
133 insw(dev
->base_addr
+ a
, buf
, wc
);
134 spin_unlock_irqrestore(&local
->lock
, flags
);
137 #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
138 #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
139 #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
140 #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
141 #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
142 #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
144 #else /* PRISM2_IO_DEBUG */
146 #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
147 #define HFA384X_INB(a) inb(dev->base_addr + (a))
148 #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
149 #define HFA384X_INW(a) inw(dev->base_addr + (a))
150 #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
151 #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
153 #endif /* PRISM2_IO_DEBUG */
156 static int hfa384x_from_bap(struct net_device
*dev
, u16 bap
, void *buf
,
162 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
166 HFA384X_INSW(d_off
, buf
, len
/ 2);
170 *((char *) pos
) = HFA384X_INB(d_off
);
176 static int hfa384x_to_bap(struct net_device
*dev
, u16 bap
, void *buf
, int len
)
181 d_off
= (bap
== 1) ? HFA384X_DATA1_OFF
: HFA384X_DATA0_OFF
;
185 HFA384X_OUTSW(d_off
, buf
, len
/ 2);
189 HFA384X_OUTB(*((char *) pos
), d_off
);
195 /* FIX: This might change at some point.. */
196 #include "hostap_hw.c"
200 static void prism2_detach(struct pcmcia_device
*p_dev
);
201 static void prism2_release(u_long arg
);
202 static int prism2_config(struct pcmcia_device
*link
);
205 static int prism2_pccard_card_present(local_info_t
*local
)
207 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
208 if (hw_priv
!= NULL
&& hw_priv
->link
!= NULL
&& pcmcia_dev_present(hw_priv
->link
))
215 * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
216 * Document No. 20-10-00058, January 2004
217 * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
219 #define SANDISK_WLAN_ACTIVATION_OFF 0x40
220 #define SANDISK_HCR_OFF 0x42
223 static void sandisk_set_iobase(local_info_t
*local
)
226 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
228 res
= pcmcia_write_config_byte(hw_priv
->link
, 0x10,
229 hw_priv
->link
->resource
[0]->start
& 0x00ff);
231 printk(KERN_DEBUG
"Prism3 SanDisk - failed to set I/O base 0 -"
236 res
= pcmcia_write_config_byte(hw_priv
->link
, 0x12,
237 (hw_priv
->link
->resource
[0]->start
>> 8) & 0x00ff);
239 printk(KERN_DEBUG
"Prism3 SanDisk - failed to set I/O base 1 -"
245 static void sandisk_write_hcr(local_info_t
*local
, int hcr
)
247 struct net_device
*dev
= local
->dev
;
250 HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF
);
252 for (i
= 0; i
< 10; i
++) {
253 HFA384X_OUTB(hcr
, SANDISK_HCR_OFF
);
256 HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF
);
260 static int sandisk_enable_wireless(struct net_device
*dev
)
263 struct hostap_interface
*iface
= netdev_priv(dev
);
264 local_info_t
*local
= iface
->local
;
265 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
267 if (resource_size(hw_priv
->link
->resource
[0]) < 0x42) {
268 /* Not enough ports to be SanDisk multi-function card */
273 if (hw_priv
->link
->manf_id
!= 0xd601 || hw_priv
->link
->card_id
!= 0x0101) {
274 /* No SanDisk manfid found */
279 if (hw_priv
->link
->socket
->functions
< 2) {
280 /* No multi-function links found */
285 printk(KERN_DEBUG
"%s: Multi-function SanDisk ConnectPlus detected"
286 " - using vendor-specific initialization\n", dev
->name
);
287 hw_priv
->sandisk_connectplus
= 1;
289 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
292 printk(KERN_DEBUG
"%s: SanDisk - COR sreset failed (%d)\n",
299 * Do not enable interrupts here to avoid some bogus events. Interrupts
300 * will be enabled during the first cor_sreset call.
302 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
303 (COR_LEVEL_REQ
| 0x8 | COR_ADDR_DECODE
|
306 printk(KERN_DEBUG
"%s: SanDisk - COR sreset failed (%d)\n",
312 sandisk_set_iobase(local
);
314 HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF
);
316 HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF
);
324 static void prism2_pccard_cor_sreset(local_info_t
*local
)
328 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
330 if (!prism2_pccard_card_present(local
))
333 res
= pcmcia_read_config_byte(hw_priv
->link
, CISREG_COR
, &val
);
335 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 1 (%d)\n",
339 printk(KERN_DEBUG
"prism2_pccard_cor_sreset: original COR %02x\n",
342 val
|= COR_SOFT_RESET
;
343 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
, val
);
345 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 2 (%d)\n",
350 mdelay(hw_priv
->sandisk_connectplus
? 5 : 2);
352 val
&= ~COR_SOFT_RESET
;
353 if (hw_priv
->sandisk_connectplus
)
355 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
, val
);
357 printk(KERN_DEBUG
"prism2_pccard_cor_sreset failed 3 (%d)\n",
362 mdelay(hw_priv
->sandisk_connectplus
? 5 : 2);
364 if (hw_priv
->sandisk_connectplus
)
365 sandisk_set_iobase(local
);
369 static void prism2_pccard_genesis_reset(local_info_t
*local
, int hcr
)
373 struct hostap_cs_priv
*hw_priv
= local
->hw_priv
;
375 if (!prism2_pccard_card_present(local
))
378 if (hw_priv
->sandisk_connectplus
) {
379 sandisk_write_hcr(local
, hcr
);
383 res
= pcmcia_read_config_byte(hw_priv
->link
, CISREG_COR
, &old_cor
);
385 printk(KERN_DEBUG
"%s failed 1 (%d)\n", __func__
, res
);
388 printk(KERN_DEBUG
"%s: original COR %02x\n", __func__
, old_cor
);
390 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
391 old_cor
| COR_SOFT_RESET
);
393 printk(KERN_DEBUG
"%s failed 2 (%d)\n", __func__
, res
);
399 /* Setup Genesis mode */
400 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_CCSR
, hcr
);
402 printk(KERN_DEBUG
"%s failed 3 (%d)\n", __func__
, res
);
407 res
= pcmcia_write_config_byte(hw_priv
->link
, CISREG_COR
,
408 old_cor
& ~COR_SOFT_RESET
);
410 printk(KERN_DEBUG
"%s failed 4 (%d)\n", __func__
, res
);
418 static struct prism2_helper_functions prism2_pccard_funcs
=
420 .card_present
= prism2_pccard_card_present
,
421 .cor_sreset
= prism2_pccard_cor_sreset
,
422 .genesis_reset
= prism2_pccard_genesis_reset
,
423 .hw_type
= HOSTAP_HW_PCCARD
,
427 /* allocate local data and register with CardServices
428 * initialize dev_link structure, but do not configure the card yet */
429 static int hostap_cs_probe(struct pcmcia_device
*p_dev
)
433 PDEBUG(DEBUG_HW
, "%s: setting Vcc=33 (constant)\n", dev_info
);
435 ret
= prism2_config(p_dev
);
437 PDEBUG(DEBUG_EXTRA
, "prism2_config() failed\n");
444 static void prism2_detach(struct pcmcia_device
*link
)
446 PDEBUG(DEBUG_FLOW
, "prism2_detach\n");
448 prism2_release((u_long
)link
);
450 /* release net devices */
452 struct hostap_cs_priv
*hw_priv
;
453 struct net_device
*dev
;
454 struct hostap_interface
*iface
;
456 iface
= netdev_priv(dev
);
457 hw_priv
= iface
->local
->hw_priv
;
458 prism2_free_local_data(dev
);
464 static int prism2_config_check(struct pcmcia_device
*p_dev
, void *priv_data
)
466 if (p_dev
->config_index
== 0)
469 return pcmcia_request_io(p_dev
);
472 static int prism2_config(struct pcmcia_device
*link
)
474 struct net_device
*dev
;
475 struct hostap_interface
*iface
;
478 struct hostap_cs_priv
*hw_priv
;
481 PDEBUG(DEBUG_FLOW
, "prism2_config()\n");
483 hw_priv
= kzalloc(sizeof(*hw_priv
), GFP_KERNEL
);
484 if (hw_priv
== NULL
) {
489 /* Look for an appropriate configuration table entry in the CIS */
490 link
->config_flags
|= CONF_AUTO_SET_VPP
| CONF_AUTO_AUDIO
|
491 CONF_AUTO_CHECK_VCC
| CONF_AUTO_SET_IO
| CONF_ENABLE_IRQ
;
493 link
->config_flags
&= ~CONF_AUTO_CHECK_VCC
;
494 ret
= pcmcia_loop_config(link
, prism2_config_check
, NULL
);
497 printk(KERN_ERR
"GetNextTuple(): No matching "
498 "CIS configuration. Maybe you need the "
499 "ignore_cis_vcc=1 parameter.\n");
503 /* Need to allocate net_device before requesting IRQ handler */
504 dev
= prism2_init_local_data(&prism2_pccard_funcs
, 0,
512 iface
= netdev_priv(dev
);
513 local
= iface
->local
;
514 local
->hw_priv
= hw_priv
;
515 hw_priv
->link
= link
;
518 * We enable IRQ here, but IRQ handler will not proceed
519 * until dev->base_addr is set below. This protect us from
520 * receive interrupts when driver is not initialized.
522 ret
= pcmcia_request_irq(link
, prism2_interrupt
);
526 ret
= pcmcia_enable_device(link
);
530 spin_lock_irqsave(&local
->irq_init_lock
, flags
);
531 dev
->irq
= link
->irq
;
532 dev
->base_addr
= link
->resource
[0]->start
;
533 spin_unlock_irqrestore(&local
->irq_init_lock
, flags
);
537 sandisk_enable_wireless(dev
);
539 ret
= prism2_hw_config(dev
, 1);
541 ret
= hostap_hw_ready(dev
);
547 prism2_release((u_long
)link
);
552 static void prism2_release(u_long arg
)
554 struct pcmcia_device
*link
= (struct pcmcia_device
*)arg
;
556 PDEBUG(DEBUG_FLOW
, "prism2_release\n");
559 struct net_device
*dev
= link
->priv
;
560 struct hostap_interface
*iface
;
562 iface
= netdev_priv(dev
);
563 prism2_hw_shutdown(dev
, 0);
564 iface
->local
->shutdown
= 1;
567 pcmcia_disable_device(link
);
568 PDEBUG(DEBUG_FLOW
, "release - done\n");
571 static int hostap_cs_suspend(struct pcmcia_device
*link
)
573 struct net_device
*dev
= (struct net_device
*) link
->priv
;
575 struct hostap_interface
*iface
= NULL
;
580 iface
= netdev_priv(dev
);
582 PDEBUG(DEBUG_EXTRA
, "%s: CS_EVENT_PM_SUSPEND\n", dev_info
);
583 if (iface
&& iface
->local
)
584 dev_open
= iface
->local
->num_dev_open
> 0;
586 netif_stop_queue(dev
);
587 netif_device_detach(dev
);
594 static int hostap_cs_resume(struct pcmcia_device
*link
)
596 struct net_device
*dev
= (struct net_device
*) link
->priv
;
598 struct hostap_interface
*iface
= NULL
;
603 iface
= netdev_priv(dev
);
605 PDEBUG(DEBUG_EXTRA
, "%s: CS_EVENT_PM_RESUME\n", dev_info
);
607 if (iface
&& iface
->local
)
608 dev_open
= iface
->local
->num_dev_open
> 0;
610 prism2_hw_shutdown(dev
, 1);
611 prism2_hw_config(dev
, dev_open
? 0 : 1);
613 netif_device_attach(dev
);
614 netif_start_queue(dev
);
620 static const struct pcmcia_device_id hostap_cs_ids
[] = {
621 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
622 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
623 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
624 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
625 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
626 PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3301),
627 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
628 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
629 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
630 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
631 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
632 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
633 PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
634 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
635 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
636 /* PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), conflict with pcnet_cs */
637 PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
638 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
639 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
640 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
641 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
642 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0xd601, 0x0005, "ADLINK 345 CF",
644 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
646 PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
648 PCMCIA_DEVICE_MANF_CARD_PROD_ID3(0x0156, 0x0002, "Version 01.02",
650 PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
651 0x7a954bd9, 0x74be00c6),
652 PCMCIA_DEVICE_PROD_ID123(
653 "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
654 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
655 PCMCIA_DEVICE_PROD_ID123(
656 "Canon", "Wireless LAN CF Card K30225", "Version 01.00",
657 0x96ef6fe2, 0x263fcbab, 0xa57adb8c),
658 PCMCIA_DEVICE_PROD_ID123(
659 "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
660 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
661 PCMCIA_DEVICE_PROD_ID123(
662 "Instant Wireless ", " Network PC CARD", "Version 01.02",
663 0x11d901af, 0x6e9bd926, 0x4b74baa0),
664 PCMCIA_DEVICE_PROD_ID123(
665 "SMC", "SMC2632W", "Version 01.02",
666 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
667 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
668 0x2decece3, 0x82067c18),
669 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
670 0x54f7c49c, 0x15a75e5b),
671 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
672 0x74c5e40d, 0xdb472a18),
673 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
674 0x0733cc81, 0x0c52f395),
675 PCMCIA_DEVICE_PROD_ID12(
676 "ZoomAir 11Mbps High", "Rate wireless Networking",
677 0x273fe3db, 0x32a1eaee),
678 PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401 Wireless PC", "Card",
679 0xa37434e9, 0x9762e8f1),
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
);