1 // SPDX-License-Identifier: GPL-2.0-only
3 * WL3501 Wireless LAN PCMCIA Card Driver for Linux
4 * Written originally for Linux 2.0.30 by Fox Chen, mhchen@golf.ccl.itri.org.tw
5 * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * Wireless extensions in 2.4 by Gustavo Niemeyer <niemeyer@conectiva.com>
8 * References used by Fox Chen while writing the original driver for 2.0.30:
10 * 1. WL24xx packet drivers (tooasm.asm)
11 * 2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
13 * 4. Linux network driver (/usr/src/linux/drivers/net)
14 * 5. ISA card driver - wl24.c
15 * 6. Linux PCMCIA skeleton driver - skeleton.c
16 * 7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
18 * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
19 * 1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
20 * rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
21 * (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
22 * ETHER/IP/UDP/TCP header, and acknowledgement overhead)
24 * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
25 * 173 Kbytes/s in TCP.
27 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
28 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
31 #include <linux/delay.h>
32 #include <linux/types.h>
33 #include <linux/interrupt.h>
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/fcntl.h>
38 #include <linux/if_arp.h>
39 #include <linux/ioport.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
43 #include <linux/slab.h>
44 #include <linux/string.h>
45 #include <linux/wireless.h>
46 #include <net/cfg80211.h>
48 #include <net/iw_handler.h>
50 #include <pcmcia/cistpl.h>
51 #include <pcmcia/cisreg.h>
52 #include <pcmcia/ds.h>
55 #include <linux/uaccess.h>
60 #define slow_down_io()
63 /* For rough constant delay */
64 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
68 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
69 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
70 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
72 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
73 #define WL3501_MAX_ADHOC_TRIES 16
75 #define WL3501_RESUME 0
76 #define WL3501_SUSPEND 1
78 static int wl3501_config(struct pcmcia_device
*link
);
79 static void wl3501_release(struct pcmcia_device
*link
);
84 } iw_channel_table
[] = {
86 .reg_domain
= IW_REG_DOMAIN_FCC
,
92 .reg_domain
= IW_REG_DOMAIN_DOC
,
98 .reg_domain
= IW_REG_DOMAIN_ETSI
,
104 .reg_domain
= IW_REG_DOMAIN_SPAIN
,
110 .reg_domain
= IW_REG_DOMAIN_FRANCE
,
116 .reg_domain
= IW_REG_DOMAIN_MKK
,
122 .reg_domain
= IW_REG_DOMAIN_MKK1
,
128 .reg_domain
= IW_REG_DOMAIN_ISRAEL
,
136 * iw_valid_channel - validate channel in regulatory domain
137 * @reg_domain: regulatory domain
138 * @channel: channel to validate
140 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
142 static int iw_valid_channel(int reg_domain
, int channel
)
146 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
147 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
148 rc
= channel
>= iw_channel_table
[i
].min
&&
149 channel
<= iw_channel_table
[i
].max
;
156 * iw_default_channel - get default channel for a regulatory domain
157 * @reg_domain: regulatory domain
159 * Returns the default channel for a regulatory domain
161 static int iw_default_channel(int reg_domain
)
165 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
166 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
167 rc
= iw_channel_table
[i
].deflt
;
173 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id
,
174 struct iw_mgmt_info_element
*el
,
175 void *value
, int len
)
179 memcpy(el
->data
, value
, len
);
182 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element
*to
,
183 struct iw_mgmt_info_element
*from
)
185 iw_set_mgmt_info_element(from
->id
, to
, from
->data
, from
->len
);
188 static inline void wl3501_switch_page(struct wl3501_card
*this, u8 page
)
190 wl3501_outb(page
, this->base_addr
+ WL3501_NIC_BSS
);
194 * Get Ethernet MAC address.
196 * WARNING: We switch to FPAGE0 and switc back again.
197 * Making sure there is no other WL function beening called by ISR.
199 static int wl3501_get_flash_mac_addr(struct wl3501_card
*this)
201 int base_addr
= this->base_addr
;
204 wl3501_outb(WL3501_BSS_FPAGE3
, base_addr
+ WL3501_NIC_BSS
); /* BSS */
205 wl3501_outb(0x00, base_addr
+ WL3501_NIC_LMAL
); /* LMAL */
206 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
); /* LMAH */
208 /* wait for reading EEPROM */
210 this->mac_addr
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
212 this->mac_addr
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
214 this->mac_addr
[2] = inb(base_addr
+ WL3501_NIC_IODPA
);
216 this->mac_addr
[3] = inb(base_addr
+ WL3501_NIC_IODPA
);
218 this->mac_addr
[4] = inb(base_addr
+ WL3501_NIC_IODPA
);
220 this->mac_addr
[5] = inb(base_addr
+ WL3501_NIC_IODPA
);
222 this->reg_domain
= inb(base_addr
+ WL3501_NIC_IODPA
);
224 wl3501_outb(WL3501_BSS_FPAGE0
, base_addr
+ WL3501_NIC_BSS
);
225 wl3501_outb(0x04, base_addr
+ WL3501_NIC_LMAL
);
226 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
);
228 this->version
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
230 this->version
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
231 /* switch to SRAM Page 0 (for safety) */
232 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
234 /* The MAC addr should be 00:60:... */
235 return this->mac_addr
[0] == 0x00 && this->mac_addr
[1] == 0x60;
239 * wl3501_set_to_wla - Move 'size' bytes from PC to card
241 * @dest: Card addressing space
242 * @src: PC addressing space
243 * @size: Bytes to move
245 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
247 static void wl3501_set_to_wla(struct wl3501_card
*this, u16 dest
, void *src
,
250 /* switch to SRAM Page 0 */
251 wl3501_switch_page(this, (dest
& 0x8000) ? WL3501_BSS_SPAGE1
:
253 /* set LMAL and LMAH */
254 wl3501_outb(dest
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
255 wl3501_outb(((dest
>> 8) & 0x7f), this->base_addr
+ WL3501_NIC_LMAH
);
257 /* rep out to Port A */
258 wl3501_outsb(this->base_addr
+ WL3501_NIC_IODPA
, src
, size
);
262 * wl3501_get_from_wla - Move 'size' bytes from card to PC
264 * @src: Card addressing space
265 * @dest: PC addressing space
266 * @size: Bytes to move
268 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
270 static void wl3501_get_from_wla(struct wl3501_card
*this, u16 src
, void *dest
,
273 /* switch to SRAM Page 0 */
274 wl3501_switch_page(this, (src
& 0x8000) ? WL3501_BSS_SPAGE1
:
276 /* set LMAL and LMAH */
277 wl3501_outb(src
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
278 wl3501_outb((src
>> 8) & 0x7f, this->base_addr
+ WL3501_NIC_LMAH
);
280 /* rep get from Port A */
281 insb(this->base_addr
+ WL3501_NIC_IODPA
, dest
, size
);
285 * Get/Allocate a free Tx Data Buffer
287 * *--------------*-----------------*----------------------------------*
288 * | PLCP | MAC Header | DST SRC Data ... |
289 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
290 * *--------------*-----------------*----------------------------------*
291 * \ \- IEEE 802.11 -/ \-------------- len --------------/
292 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
294 * Return = Position in Card
296 static u16
wl3501_get_tx_buffer(struct wl3501_card
*this, u16 len
)
298 u16 next
, blk_cnt
= 0, zero
= 0;
299 u16 full_len
= sizeof(struct wl3501_80211_tx_hdr
) + len
;
302 if (full_len
> this->tx_buffer_cnt
* 254)
304 ret
= this->tx_buffer_head
;
310 wl3501_get_from_wla(this, this->tx_buffer_head
, &next
,
313 wl3501_set_to_wla(this, this->tx_buffer_head
, &zero
,
315 this->tx_buffer_head
= next
;
317 /* if buffer is not enough */
318 if (!next
&& full_len
) {
319 this->tx_buffer_head
= ret
;
324 this->tx_buffer_cnt
-= blk_cnt
;
330 * Free an allocated Tx Buffer. ptr must be correct position.
332 static void wl3501_free_tx_buffer(struct wl3501_card
*this, u16 ptr
)
334 /* check if all space is not free */
335 if (!this->tx_buffer_head
)
336 this->tx_buffer_head
= ptr
;
338 wl3501_set_to_wla(this, this->tx_buffer_tail
,
343 this->tx_buffer_cnt
++;
344 wl3501_get_from_wla(this, ptr
, &next
, sizeof(next
));
345 this->tx_buffer_tail
= ptr
;
350 static int wl3501_esbq_req_test(struct wl3501_card
*this)
354 wl3501_get_from_wla(this, this->esbq_req_head
+ 3, &tmp
, sizeof(tmp
));
358 static void wl3501_esbq_req(struct wl3501_card
*this, u16
*ptr
)
362 wl3501_set_to_wla(this, this->esbq_req_head
, ptr
, 2);
363 wl3501_set_to_wla(this, this->esbq_req_head
+ 2, &tmp
, sizeof(tmp
));
364 this->esbq_req_head
+= 4;
365 if (this->esbq_req_head
>= this->esbq_req_end
)
366 this->esbq_req_head
= this->esbq_req_start
;
369 static int wl3501_esbq_exec(struct wl3501_card
*this, void *sig
, int sig_size
)
373 if (wl3501_esbq_req_test(this)) {
374 u16 ptr
= wl3501_get_tx_buffer(this, sig_size
);
376 wl3501_set_to_wla(this, ptr
, sig
, sig_size
);
377 wl3501_esbq_req(this, &ptr
);
384 static int wl3501_request_mib(struct wl3501_card
*this, u8 index
, void *bf
)
386 struct wl3501_get_req sig
= {
387 .sig_id
= WL3501_SIG_GET_REQ
,
393 spin_lock_irqsave(&this->lock
, flags
);
394 if (wl3501_esbq_req_test(this)) {
395 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
397 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
398 wl3501_esbq_req(this, &ptr
);
399 this->sig_get_confirm
.mib_status
= 255;
403 spin_unlock_irqrestore(&this->lock
, flags
);
408 static int wl3501_get_mib_value(struct wl3501_card
*this, u8 index
,
413 rc
= wl3501_request_mib(this, index
, bf
);
417 rc
= wait_event_interruptible(this->wait
,
418 this->sig_get_confirm
.mib_status
!= 255);
422 memcpy(bf
, this->sig_get_confirm
.mib_value
, size
);
426 static int wl3501_pwr_mgmt(struct wl3501_card
*this, int suspend
)
428 struct wl3501_pwr_mgmt_req sig
= {
429 .sig_id
= WL3501_SIG_PWR_MGMT_REQ
,
437 spin_lock_irqsave(&this->lock
, flags
);
438 if (wl3501_esbq_req_test(this)) {
439 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
441 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
442 wl3501_esbq_req(this, &ptr
);
443 this->sig_pwr_mgmt_confirm
.status
= 255;
444 spin_unlock_irqrestore(&this->lock
, flags
);
445 rc
= wait_event_interruptible(this->wait
,
446 this->sig_pwr_mgmt_confirm
.status
!= 255);
447 printk(KERN_INFO
"%s: %s status=%d\n", __func__
,
448 suspend
? "suspend" : "resume",
449 this->sig_pwr_mgmt_confirm
.status
);
453 spin_unlock_irqrestore(&this->lock
, flags
);
459 * wl3501_send_pkt - Send a packet.
461 * @data: Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
462 * data[6] - data[11] is Src MAC Addr)
463 * @len: Packet length
466 static int wl3501_send_pkt(struct wl3501_card
*this, u8
*data
, u16 len
)
468 u16 bf
, sig_bf
, next
, tmplen
, pktlen
;
469 struct wl3501_md_req sig
= {
470 .sig_id
= WL3501_SIG_MD_REQ
,
472 u8
*pdata
= (char *)data
;
475 if (wl3501_esbq_req_test(this)) {
476 sig_bf
= wl3501_get_tx_buffer(this, sizeof(sig
));
478 if (!sig_bf
) /* No free buffer available */
480 bf
= wl3501_get_tx_buffer(this, len
+ 26 + 24);
482 /* No free buffer available */
483 wl3501_free_tx_buffer(this, sig_bf
);
487 memcpy(&sig
.daddr
[0], pdata
, 12);
491 if (((*pdata
) * 256 + (*(pdata
+ 1))) > 1500) {
492 u8 addr4
[ETH_ALEN
] = {
493 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
496 wl3501_set_to_wla(this, bf
+ 2 +
497 offsetof(struct wl3501_tx_hdr
, addr4
),
498 addr4
, sizeof(addr4
));
499 sig
.size
= pktlen
+ 24 + 4 + 6;
500 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
))) {
501 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
);
507 wl3501_set_to_wla(this,
508 bf
+ 2 + sizeof(struct wl3501_tx_hdr
),
511 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
514 sig
.size
= pktlen
+ 24 + 4 - 2;
517 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
) + 6)) {
518 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
) + 6;
524 wl3501_set_to_wla(this, bf
+ 2 +
525 offsetof(struct wl3501_tx_hdr
, addr4
),
528 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
539 wl3501_set_to_wla(this, bf
+ 2, pdata
, tmplen
);
541 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
544 wl3501_set_to_wla(this, sig_bf
, &sig
, sizeof(sig
));
545 wl3501_esbq_req(this, &sig_bf
);
551 static int wl3501_mgmt_resync(struct wl3501_card
*this)
553 struct wl3501_resync_req sig
= {
554 .sig_id
= WL3501_SIG_RESYNC_REQ
,
557 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
560 static inline int wl3501_fw_bss_type(struct wl3501_card
*this)
562 return this->net_type
== IW_MODE_INFRA
? WL3501_NET_TYPE_INFRA
:
563 WL3501_NET_TYPE_ADHOC
;
566 static inline int wl3501_fw_cap_info(struct wl3501_card
*this)
568 return this->net_type
== IW_MODE_INFRA
? WL3501_MGMT_CAPABILITY_ESS
:
569 WL3501_MGMT_CAPABILITY_IBSS
;
572 static int wl3501_mgmt_scan(struct wl3501_card
*this, u16 chan_time
)
574 struct wl3501_scan_req sig
= {
575 .sig_id
= WL3501_SIG_SCAN_REQ
,
576 .scan_type
= WL3501_SCAN_TYPE_ACTIVE
,
578 .min_chan_time
= chan_time
,
579 .max_chan_time
= chan_time
,
580 .bss_type
= wl3501_fw_bss_type(this),
583 this->bss_cnt
= this->join_sta_bss
= 0;
584 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
587 static int wl3501_mgmt_join(struct wl3501_card
*this, u16 stas
)
589 struct wl3501_join_req sig
= {
590 .sig_id
= WL3501_SIG_JOIN_REQ
,
594 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
601 memcpy(&sig
.beacon_period
, &this->bss_set
[stas
].beacon_period
, 72);
602 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
605 static int wl3501_mgmt_start(struct wl3501_card
*this)
607 struct wl3501_start_req sig
= {
608 .sig_id
= WL3501_SIG_START_REQ
,
609 .beacon_period
= 400,
613 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
620 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
623 .data_rate_labels
= {
624 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
625 IW_MGMT_RATE_LABEL_1MBIT
,
626 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
627 IW_MGMT_RATE_LABEL_2MBIT
,
630 .operational_rset
= {
632 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
635 .data_rate_labels
= {
636 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
637 IW_MGMT_RATE_LABEL_1MBIT
,
638 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
639 IW_MGMT_RATE_LABEL_2MBIT
,
644 .id
= IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET
,
649 .bss_type
= wl3501_fw_bss_type(this),
650 .cap_info
= wl3501_fw_cap_info(this),
653 iw_copy_mgmt_info_element(&sig
.ssid
.el
, &this->essid
.el
);
654 iw_copy_mgmt_info_element(&this->keep_essid
.el
, &this->essid
.el
);
655 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
658 static void wl3501_mgmt_scan_confirm(struct wl3501_card
*this, u16 addr
)
662 struct wl3501_scan_confirm sig
;
665 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
666 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
668 if ((this->net_type
== IW_MODE_INFRA
&&
669 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_ESS
)) ||
670 (this->net_type
== IW_MODE_ADHOC
&&
671 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_IBSS
)) ||
672 this->net_type
== IW_MODE_AUTO
) {
673 if (!this->essid
.el
.len
)
675 else if (this->essid
.el
.len
== 3 &&
676 !memcmp(this->essid
.essid
, "ANY", 3))
678 else if (this->essid
.el
.len
!= sig
.ssid
.el
.len
)
680 else if (memcmp(this->essid
.essid
, sig
.ssid
.essid
,
686 for (i
= 0; i
< this->bss_cnt
; i
++) {
687 if (ether_addr_equal_unaligned(this->bss_set
[i
].bssid
, sig
.bssid
)) {
693 if (matchflag
&& (i
< 20)) {
694 memcpy(&this->bss_set
[i
].beacon_period
,
695 &sig
.beacon_period
, 73);
697 this->rssi
= sig
.rssi
;
700 } else if (sig
.status
== WL3501_STATUS_TIMEOUT
) {
702 this->join_sta_bss
= 0;
703 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
704 if (!wl3501_mgmt_join(this, i
))
706 this->join_sta_bss
= i
;
707 if (this->join_sta_bss
== this->bss_cnt
) {
708 if (this->net_type
== IW_MODE_INFRA
)
709 wl3501_mgmt_scan(this, 100);
712 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
713 wl3501_mgmt_start(this);
715 wl3501_mgmt_scan(this, 100);
722 * wl3501_block_interrupt - Mask interrupt from SUTRO
725 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
726 * Return: 1 if interrupt is originally enabled
728 static int wl3501_block_interrupt(struct wl3501_card
*this)
730 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
731 u8
new = old
& (~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
|
732 WL3501_GCR_ENECINT
));
734 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
735 return old
& WL3501_GCR_ENECINT
;
739 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
742 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
743 * Return: 1 if interrupt is originally enabled
745 static int wl3501_unblock_interrupt(struct wl3501_card
*this)
747 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
748 u8
new = (old
& ~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
)) |
751 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
752 return old
& WL3501_GCR_ENECINT
;
756 * wl3501_receive - Receive data from Receive Queue.
758 * Receive data from Receive Queue.
761 * @bf: address of host
762 * @size: size of buffer.
764 static u16
wl3501_receive(struct wl3501_card
*this, u8
*bf
, u16 size
)
766 u16 next_addr
, next_addr1
;
770 wl3501_get_from_wla(this, this->start_seg
+ 2,
771 &next_addr
, sizeof(next_addr
));
772 if (size
> WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
)) {
773 wl3501_get_from_wla(this,
775 sizeof(struct wl3501_rx_hdr
), data
,
777 sizeof(struct wl3501_rx_hdr
));
778 size
-= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
779 data
+= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
781 wl3501_get_from_wla(this,
783 sizeof(struct wl3501_rx_hdr
),
788 if (size
> WL3501_BLKSZ
- 5) {
789 wl3501_get_from_wla(this, next_addr
+ 5, data
,
791 size
-= WL3501_BLKSZ
- 5;
792 data
+= WL3501_BLKSZ
- 5;
793 wl3501_get_from_wla(this, next_addr
+ 2, &next_addr1
,
795 next_addr
= next_addr1
;
797 wl3501_get_from_wla(this, next_addr
+ 5, data
, size
);
804 static void wl3501_esbq_req_free(struct wl3501_card
*this)
809 if (this->esbq_req_head
== this->esbq_req_tail
)
811 wl3501_get_from_wla(this, this->esbq_req_tail
+ 3, &tmp
, sizeof(tmp
));
814 wl3501_get_from_wla(this, this->esbq_req_tail
, &addr
, sizeof(addr
));
815 wl3501_free_tx_buffer(this, addr
);
816 this->esbq_req_tail
+= 4;
817 if (this->esbq_req_tail
>= this->esbq_req_end
)
818 this->esbq_req_tail
= this->esbq_req_start
;
823 static int wl3501_esbq_confirm(struct wl3501_card
*this)
827 wl3501_get_from_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
831 static void wl3501_online(struct net_device
*dev
)
833 struct wl3501_card
*this = netdev_priv(dev
);
835 printk(KERN_INFO
"%s: Wireless LAN online. BSSID: %pM\n",
836 dev
->name
, this->bssid
);
837 netif_wake_queue(dev
);
840 static void wl3501_esbq_confirm_done(struct wl3501_card
*this)
844 wl3501_set_to_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
845 this->esbq_confirm
+= 4;
846 if (this->esbq_confirm
>= this->esbq_confirm_end
)
847 this->esbq_confirm
= this->esbq_confirm_start
;
850 static int wl3501_mgmt_auth(struct wl3501_card
*this)
852 struct wl3501_auth_req sig
= {
853 .sig_id
= WL3501_SIG_AUTH_REQ
,
854 .type
= WL3501_SYS_TYPE_OPEN
,
859 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
860 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
863 static int wl3501_mgmt_association(struct wl3501_card
*this)
865 struct wl3501_assoc_req sig
= {
866 .sig_id
= WL3501_SIG_ASSOC_REQ
,
868 .listen_interval
= 5,
869 .cap_info
= this->cap_info
,
873 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
874 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
877 static void wl3501_mgmt_join_confirm(struct net_device
*dev
, u16 addr
)
879 struct wl3501_card
*this = netdev_priv(dev
);
880 struct wl3501_join_confirm sig
;
883 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
884 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
885 if (this->net_type
== IW_MODE_INFRA
) {
886 if (this->join_sta_bss
< this->bss_cnt
) {
887 const int i
= this->join_sta_bss
;
889 this->bss_set
[i
].bssid
, ETH_ALEN
);
890 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
891 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
892 &this->bss_set
[i
].ssid
.el
);
893 wl3501_mgmt_auth(this);
896 const int i
= this->join_sta_bss
;
898 memcpy(&this->bssid
, &this->bss_set
[i
].bssid
, ETH_ALEN
);
899 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
900 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
901 &this->bss_set
[i
].ssid
.el
);
906 this->join_sta_bss
++;
907 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
908 if (!wl3501_mgmt_join(this, i
))
910 this->join_sta_bss
= i
;
911 if (this->join_sta_bss
== this->bss_cnt
) {
912 if (this->net_type
== IW_MODE_INFRA
)
913 wl3501_mgmt_scan(this, 100);
916 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
917 wl3501_mgmt_start(this);
919 wl3501_mgmt_scan(this, 100);
925 static inline void wl3501_alarm_interrupt(struct net_device
*dev
,
926 struct wl3501_card
*this)
928 if (this->net_type
== IW_MODE_INFRA
) {
929 printk(KERN_INFO
"Wireless LAN offline\n");
930 netif_stop_queue(dev
);
931 wl3501_mgmt_resync(this);
935 static inline void wl3501_md_confirm_interrupt(struct net_device
*dev
,
936 struct wl3501_card
*this,
939 struct wl3501_md_confirm sig
;
942 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
943 wl3501_free_tx_buffer(this, sig
.data
);
944 if (netif_queue_stopped(dev
))
945 netif_wake_queue(dev
);
948 static inline void wl3501_md_ind_interrupt(struct net_device
*dev
,
949 struct wl3501_card
*this, u16 addr
)
951 struct wl3501_md_ind sig
;
953 u8 rssi
, addr4
[ETH_ALEN
];
956 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
957 this->start_seg
= sig
.data
;
958 wl3501_get_from_wla(this,
959 sig
.data
+ offsetof(struct wl3501_rx_hdr
, rssi
),
960 &rssi
, sizeof(rssi
));
961 this->rssi
= rssi
<= 63 ? (rssi
* 100) / 64 : 255;
963 wl3501_get_from_wla(this,
965 offsetof(struct wl3501_rx_hdr
, addr4
),
966 &addr4
, sizeof(addr4
));
967 if (!(addr4
[0] == 0xAA && addr4
[1] == 0xAA &&
968 addr4
[2] == 0x03 && addr4
[4] == 0x00)) {
969 printk(KERN_INFO
"Unsupported packet type!\n");
972 pkt_len
= sig
.size
+ 12 - 24 - 4 - 6;
974 skb
= dev_alloc_skb(pkt_len
+ 5);
977 printk(KERN_WARNING
"%s: Can't alloc a sk_buff of size %d.\n",
979 dev
->stats
.rx_dropped
++;
982 skb_reserve(skb
, 2); /* IP headers on 16 bytes boundaries */
983 skb_copy_to_linear_data(skb
, (unsigned char *)&sig
.daddr
, 12);
984 wl3501_receive(this, skb
->data
, pkt_len
);
985 skb_put(skb
, pkt_len
);
986 skb
->protocol
= eth_type_trans(skb
, dev
);
987 dev
->stats
.rx_packets
++;
988 dev
->stats
.rx_bytes
+= skb
->len
;
993 static inline void wl3501_get_confirm_interrupt(struct wl3501_card
*this,
994 u16 addr
, void *sig
, int size
)
997 wl3501_get_from_wla(this, addr
, &this->sig_get_confirm
,
998 sizeof(this->sig_get_confirm
));
999 wake_up(&this->wait
);
1002 static inline void wl3501_start_confirm_interrupt(struct net_device
*dev
,
1003 struct wl3501_card
*this,
1006 struct wl3501_start_confirm sig
;
1009 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1010 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1011 netif_wake_queue(dev
);
1014 static inline void wl3501_assoc_confirm_interrupt(struct net_device
*dev
,
1017 struct wl3501_card
*this = netdev_priv(dev
);
1018 struct wl3501_assoc_confirm sig
;
1021 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1023 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1027 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card
*this,
1030 struct wl3501_auth_confirm sig
;
1033 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1035 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1036 wl3501_mgmt_association(this);
1038 wl3501_mgmt_resync(this);
1041 static inline void wl3501_rx_interrupt(struct net_device
*dev
)
1046 struct wl3501_card
*this = netdev_priv(dev
);
1051 if (!wl3501_esbq_confirm(this))
1053 wl3501_get_from_wla(this, this->esbq_confirm
, &addr
, sizeof(addr
));
1054 wl3501_get_from_wla(this, addr
+ 2, &sig_id
, sizeof(sig_id
));
1057 case WL3501_SIG_DEAUTH_IND
:
1058 case WL3501_SIG_DISASSOC_IND
:
1059 case WL3501_SIG_ALARM
:
1060 wl3501_alarm_interrupt(dev
, this);
1062 case WL3501_SIG_MD_CONFIRM
:
1063 wl3501_md_confirm_interrupt(dev
, this, addr
);
1065 case WL3501_SIG_MD_IND
:
1066 wl3501_md_ind_interrupt(dev
, this, addr
);
1068 case WL3501_SIG_GET_CONFIRM
:
1069 wl3501_get_confirm_interrupt(this, addr
,
1070 &this->sig_get_confirm
,
1071 sizeof(this->sig_get_confirm
));
1073 case WL3501_SIG_PWR_MGMT_CONFIRM
:
1074 wl3501_get_confirm_interrupt(this, addr
,
1075 &this->sig_pwr_mgmt_confirm
,
1076 sizeof(this->sig_pwr_mgmt_confirm
));
1078 case WL3501_SIG_START_CONFIRM
:
1079 wl3501_start_confirm_interrupt(dev
, this, addr
);
1081 case WL3501_SIG_SCAN_CONFIRM
:
1082 wl3501_mgmt_scan_confirm(this, addr
);
1084 case WL3501_SIG_JOIN_CONFIRM
:
1085 wl3501_mgmt_join_confirm(dev
, addr
);
1087 case WL3501_SIG_ASSOC_CONFIRM
:
1088 wl3501_assoc_confirm_interrupt(dev
, addr
);
1090 case WL3501_SIG_AUTH_CONFIRM
:
1091 wl3501_auth_confirm_interrupt(this, addr
);
1093 case WL3501_SIG_RESYNC_CONFIRM
:
1094 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1097 wl3501_esbq_confirm_done(this);
1099 /* free request if necessary */
1101 wl3501_esbq_req_free(this);
1106 static inline void wl3501_ack_interrupt(struct wl3501_card
*this)
1108 wl3501_outb(WL3501_GCR_ECINT
, this->base_addr
+ WL3501_NIC_GCR
);
1112 * wl3501_interrupt - Hardware interrupt from card.
1113 * @irq: Interrupt number
1114 * @dev_id: net_device
1116 * We must acknowledge the interrupt as soon as possible, and block the
1117 * interrupt from the same card immediately to prevent re-entry.
1119 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1120 * On the other hand, to prevent SUTRO from malfunctioning, we must
1121 * unlock the SUTRO as soon as possible.
1123 static irqreturn_t
wl3501_interrupt(int irq
, void *dev_id
)
1125 struct net_device
*dev
= dev_id
;
1126 struct wl3501_card
*this;
1128 this = netdev_priv(dev
);
1129 spin_lock(&this->lock
);
1130 wl3501_ack_interrupt(this);
1131 wl3501_block_interrupt(this);
1132 wl3501_rx_interrupt(dev
);
1133 wl3501_unblock_interrupt(this);
1134 spin_unlock(&this->lock
);
1139 static int wl3501_reset_board(struct wl3501_card
*this)
1145 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1146 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1147 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1149 /* Reset SRAM 0x480 to zero */
1150 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1153 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1155 WL3501_NOPLOOP(1024 * 50);
1157 wl3501_unblock_interrupt(this); /* acme: was commented */
1159 /* Polling Self_Test_Status */
1160 for (i
= 0; i
< 10000; i
++) {
1161 wl3501_get_from_wla(this, 0x480, &tmp
, sizeof(tmp
));
1164 /* firmware complete all test successfully */
1166 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1171 printk(KERN_WARNING
"%s: failed to reset the board!\n", __func__
);
1177 static int wl3501_init_firmware(struct wl3501_card
*this)
1180 int rc
= wl3501_reset_board(this);
1184 this->card_name
[0] = '\0';
1185 wl3501_get_from_wla(this, 0x1a00,
1186 this->card_name
, sizeof(this->card_name
));
1187 this->card_name
[sizeof(this->card_name
) - 1] = '\0';
1188 this->firmware_date
[0] = '\0';
1189 wl3501_get_from_wla(this, 0x1a40,
1190 this->firmware_date
, sizeof(this->firmware_date
));
1191 this->firmware_date
[sizeof(this->firmware_date
) - 1] = '\0';
1192 /* Switch to SRAM Page 0 */
1193 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
1194 /* Read parameter from card */
1195 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start
, 2);
1196 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end
, 2);
1197 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start
, 2);
1198 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end
, 2);
1199 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head
, 2);
1200 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size
, 2);
1201 this->esbq_req_tail
= this->esbq_req_head
= this->esbq_req_start
;
1202 this->esbq_req_end
+= this->esbq_req_start
;
1203 this->esbq_confirm
= this->esbq_confirm_start
;
1204 this->esbq_confirm_end
+= this->esbq_confirm_start
;
1205 /* Initial Tx Buffer */
1206 this->tx_buffer_cnt
= 1;
1207 ptr
= this->tx_buffer_head
;
1208 next
= ptr
+ WL3501_BLKSZ
;
1209 while ((next
- this->tx_buffer_head
) < this->tx_buffer_size
) {
1210 this->tx_buffer_cnt
++;
1211 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1213 next
= ptr
+ WL3501_BLKSZ
;
1217 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1218 this->tx_buffer_tail
= ptr
;
1222 printk(KERN_WARNING
"%s: failed!\n", __func__
);
1226 static int wl3501_close(struct net_device
*dev
)
1228 struct wl3501_card
*this = netdev_priv(dev
);
1229 unsigned long flags
;
1230 struct pcmcia_device
*link
;
1233 spin_lock_irqsave(&this->lock
, flags
);
1236 /* Stop wl3501_hard_start_xmit() from now on */
1237 netif_stop_queue(dev
);
1238 wl3501_ack_interrupt(this);
1240 /* Mask interrupts from the SUTRO */
1241 wl3501_block_interrupt(this);
1243 printk(KERN_INFO
"%s: WL3501 closed\n", dev
->name
);
1244 spin_unlock_irqrestore(&this->lock
, flags
);
1249 * wl3501_reset - Reset the SUTRO.
1250 * @dev: network device
1252 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1253 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1254 * is running. It seems to be dangerous.
1256 static int wl3501_reset(struct net_device
*dev
)
1258 struct wl3501_card
*this = netdev_priv(dev
);
1260 unsigned long flags
;
1262 spin_lock_irqsave(&this->lock
, flags
);
1263 wl3501_block_interrupt(this);
1265 if (wl3501_init_firmware(this)) {
1266 printk(KERN_WARNING
"%s: Can't initialize Firmware!\n",
1268 /* Free IRQ, and mark IRQ as unused */
1269 free_irq(dev
->irq
, dev
);
1274 * Queue has to be started only when the Card is Started
1276 netif_stop_queue(dev
);
1277 this->adhoc_times
= 0;
1278 wl3501_ack_interrupt(this);
1279 wl3501_unblock_interrupt(this);
1280 wl3501_mgmt_scan(this, 100);
1281 pr_debug("%s: device reset", dev
->name
);
1284 spin_unlock_irqrestore(&this->lock
, flags
);
1288 static void wl3501_tx_timeout(struct net_device
*dev
, unsigned int txqueue
)
1290 struct net_device_stats
*stats
= &dev
->stats
;
1294 rc
= wl3501_reset(dev
);
1296 printk(KERN_ERR
"%s: Error %d resetting card on Tx timeout!\n",
1299 netif_trans_update(dev
); /* prevent tx timeout */
1300 netif_wake_queue(dev
);
1306 * 1 - Could not transmit (dev_queue_xmit will queue it)
1307 * and try to sent it later
1309 static netdev_tx_t
wl3501_hard_start_xmit(struct sk_buff
*skb
,
1310 struct net_device
*dev
)
1313 struct wl3501_card
*this = netdev_priv(dev
);
1314 unsigned long flags
;
1316 spin_lock_irqsave(&this->lock
, flags
);
1317 enabled
= wl3501_block_interrupt(this);
1318 rc
= wl3501_send_pkt(this, skb
->data
, skb
->len
);
1320 wl3501_unblock_interrupt(this);
1322 ++dev
->stats
.tx_dropped
;
1323 netif_stop_queue(dev
);
1325 ++dev
->stats
.tx_packets
;
1326 dev
->stats
.tx_bytes
+= skb
->len
;
1329 if (this->tx_buffer_cnt
< 2)
1330 netif_stop_queue(dev
);
1332 spin_unlock_irqrestore(&this->lock
, flags
);
1333 return NETDEV_TX_OK
;
1336 static int wl3501_open(struct net_device
*dev
)
1339 struct wl3501_card
*this = netdev_priv(dev
);
1340 unsigned long flags
;
1341 struct pcmcia_device
*link
;
1344 spin_lock_irqsave(&this->lock
, flags
);
1345 if (!pcmcia_dev_present(link
))
1347 netif_device_attach(dev
);
1350 /* Initial WL3501 firmware */
1351 pr_debug("%s: Initialize WL3501 firmware...", dev
->name
);
1352 if (wl3501_init_firmware(this))
1354 /* Initial device variables */
1355 this->adhoc_times
= 0;
1356 /* Acknowledge Interrupt, for cleaning last state */
1357 wl3501_ack_interrupt(this);
1359 /* Enable interrupt from card after all */
1360 wl3501_unblock_interrupt(this);
1361 wl3501_mgmt_scan(this, 100);
1363 pr_debug("%s: WL3501 opened", dev
->name
);
1364 printk(KERN_INFO
"%s: Card Name: %s\n"
1365 "%s: Firmware Date: %s\n",
1366 dev
->name
, this->card_name
,
1367 dev
->name
, this->firmware_date
);
1369 spin_unlock_irqrestore(&this->lock
, flags
);
1372 printk(KERN_WARNING
"%s: Can't initialize firmware!\n", dev
->name
);
1376 static struct iw_statistics
*wl3501_get_wireless_stats(struct net_device
*dev
)
1378 struct wl3501_card
*this = netdev_priv(dev
);
1379 struct iw_statistics
*wstats
= &this->wstats
;
1380 u32 value
; /* size checked: it is u32 */
1382 memset(wstats
, 0, sizeof(*wstats
));
1383 wstats
->status
= netif_running(dev
);
1384 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT
,
1385 &value
, sizeof(value
)))
1386 wstats
->discard
.code
+= value
;
1387 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT
,
1388 &value
, sizeof(value
)))
1389 wstats
->discard
.code
+= value
;
1390 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT
,
1391 &value
, sizeof(value
)))
1392 wstats
->discard
.code
+= value
;
1393 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT
,
1394 &value
, sizeof(value
)))
1395 wstats
->discard
.retries
= value
;
1396 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT
,
1397 &value
, sizeof(value
)))
1398 wstats
->discard
.misc
+= value
;
1399 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT
,
1400 &value
, sizeof(value
)))
1401 wstats
->discard
.misc
+= value
;
1402 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT
,
1403 &value
, sizeof(value
)))
1404 wstats
->discard
.misc
+= value
;
1405 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT
,
1406 &value
, sizeof(value
)))
1407 wstats
->discard
.misc
+= value
;
1412 * wl3501_detach - deletes a driver "instance"
1415 * This deletes a driver "instance". The device is de-registered with Card
1416 * Services. If it has been released, all local data structures are freed.
1417 * Otherwise, the structures will be freed when the device is released.
1419 static void wl3501_detach(struct pcmcia_device
*link
)
1421 struct net_device
*dev
= link
->priv
;
1423 /* If the device is currently configured and active, we won't actually
1424 * delete it yet. Instead, it is marked so that when the release()
1425 * function is called, that will trigger a proper detach(). */
1427 while (link
->open
> 0)
1430 netif_device_detach(dev
);
1431 wl3501_release(link
);
1433 unregister_netdev(dev
);
1437 static int wl3501_get_name(struct net_device
*dev
, struct iw_request_info
*info
,
1438 union iwreq_data
*wrqu
, char *extra
)
1440 strlcpy(wrqu
->name
, "IEEE 802.11-DS", sizeof(wrqu
->name
));
1444 static int wl3501_set_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1445 union iwreq_data
*wrqu
, char *extra
)
1447 struct wl3501_card
*this = netdev_priv(dev
);
1448 int channel
= wrqu
->freq
.m
;
1451 if (iw_valid_channel(this->reg_domain
, channel
)) {
1452 this->chan
= channel
;
1453 rc
= wl3501_reset(dev
);
1458 static int wl3501_get_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1459 union iwreq_data
*wrqu
, char *extra
)
1461 struct wl3501_card
*this = netdev_priv(dev
);
1463 wrqu
->freq
.m
= 100000 *
1464 ieee80211_channel_to_frequency(this->chan
, NL80211_BAND_2GHZ
);
1469 static int wl3501_set_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1470 union iwreq_data
*wrqu
, char *extra
)
1474 if (wrqu
->mode
== IW_MODE_INFRA
||
1475 wrqu
->mode
== IW_MODE_ADHOC
||
1476 wrqu
->mode
== IW_MODE_AUTO
) {
1477 struct wl3501_card
*this = netdev_priv(dev
);
1479 this->net_type
= wrqu
->mode
;
1480 rc
= wl3501_reset(dev
);
1485 static int wl3501_get_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1486 union iwreq_data
*wrqu
, char *extra
)
1488 struct wl3501_card
*this = netdev_priv(dev
);
1490 wrqu
->mode
= this->net_type
;
1494 static int wl3501_get_sens(struct net_device
*dev
, struct iw_request_info
*info
,
1495 union iwreq_data
*wrqu
, char *extra
)
1497 struct wl3501_card
*this = netdev_priv(dev
);
1499 wrqu
->sens
.value
= this->rssi
;
1500 wrqu
->sens
.disabled
= !wrqu
->sens
.value
;
1501 wrqu
->sens
.fixed
= 1;
1505 static int wl3501_get_range(struct net_device
*dev
,
1506 struct iw_request_info
*info
,
1507 union iwreq_data
*wrqu
, char *extra
)
1509 struct iw_range
*range
= (struct iw_range
*)extra
;
1511 /* Set the length (very important for backward compatibility) */
1512 wrqu
->data
.length
= sizeof(*range
);
1514 /* Set all the info we don't care or don't know about to zero */
1515 memset(range
, 0, sizeof(*range
));
1517 /* Set the Wireless Extension versions */
1518 range
->we_version_compiled
= WIRELESS_EXT
;
1519 range
->we_version_source
= 1;
1520 range
->throughput
= 2 * 1000 * 1000; /* ~2 Mb/s */
1521 /* FIXME: study the code to fill in more fields... */
1525 static int wl3501_set_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1526 union iwreq_data
*wrqu
, char *extra
)
1528 struct wl3501_card
*this = netdev_priv(dev
);
1531 /* FIXME: we support other ARPHRDs...*/
1532 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
1534 if (is_broadcast_ether_addr(wrqu
->ap_addr
.sa_data
)) {
1535 /* FIXME: rescan? */
1537 memcpy(this->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
1538 /* FIXME: rescan? deassoc & scan? */
1544 static int wl3501_get_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1545 union iwreq_data
*wrqu
, char *extra
)
1547 struct wl3501_card
*this = netdev_priv(dev
);
1549 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1550 memcpy(wrqu
->ap_addr
.sa_data
, this->bssid
, ETH_ALEN
);
1554 static int wl3501_set_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1555 union iwreq_data
*wrqu
, char *extra
)
1558 * FIXME: trigger scanning with a reset, yes, I'm lazy
1560 return wl3501_reset(dev
);
1563 static int wl3501_get_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1564 union iwreq_data
*wrqu
, char *extra
)
1566 struct wl3501_card
*this = netdev_priv(dev
);
1568 char *current_ev
= extra
;
1569 struct iw_event iwe
;
1571 for (i
= 0; i
< this->bss_cnt
; ++i
) {
1572 iwe
.cmd
= SIOCGIWAP
;
1573 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1574 memcpy(iwe
.u
.ap_addr
.sa_data
, this->bss_set
[i
].bssid
, ETH_ALEN
);
1575 current_ev
= iwe_stream_add_event(info
, current_ev
,
1576 extra
+ IW_SCAN_MAX_DATA
,
1577 &iwe
, IW_EV_ADDR_LEN
);
1578 iwe
.cmd
= SIOCGIWESSID
;
1579 iwe
.u
.data
.flags
= 1;
1580 iwe
.u
.data
.length
= this->bss_set
[i
].ssid
.el
.len
;
1581 current_ev
= iwe_stream_add_point(info
, current_ev
,
1582 extra
+ IW_SCAN_MAX_DATA
,
1584 this->bss_set
[i
].ssid
.essid
);
1585 iwe
.cmd
= SIOCGIWMODE
;
1586 iwe
.u
.mode
= this->bss_set
[i
].bss_type
;
1587 current_ev
= iwe_stream_add_event(info
, current_ev
,
1588 extra
+ IW_SCAN_MAX_DATA
,
1589 &iwe
, IW_EV_UINT_LEN
);
1590 iwe
.cmd
= SIOCGIWFREQ
;
1591 iwe
.u
.freq
.m
= this->bss_set
[i
].ds_pset
.chan
;
1593 current_ev
= iwe_stream_add_event(info
, current_ev
,
1594 extra
+ IW_SCAN_MAX_DATA
,
1595 &iwe
, IW_EV_FREQ_LEN
);
1596 iwe
.cmd
= SIOCGIWENCODE
;
1597 if (this->bss_set
[i
].cap_info
& WL3501_MGMT_CAPABILITY_PRIVACY
)
1598 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1600 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1601 iwe
.u
.data
.length
= 0;
1602 current_ev
= iwe_stream_add_point(info
, current_ev
,
1603 extra
+ IW_SCAN_MAX_DATA
,
1606 /* Length of data */
1607 wrqu
->data
.length
= (current_ev
- extra
);
1608 wrqu
->data
.flags
= 0; /* FIXME: set properly these flags */
1612 static int wl3501_set_essid(struct net_device
*dev
,
1613 struct iw_request_info
*info
,
1614 union iwreq_data
*wrqu
, char *extra
)
1616 struct wl3501_card
*this = netdev_priv(dev
);
1618 if (wrqu
->data
.flags
) {
1619 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1621 extra
, wrqu
->data
.length
);
1622 } else { /* We accept any ESSID */
1623 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1624 &this->essid
.el
, "ANY", 3);
1626 return wl3501_reset(dev
);
1629 static int wl3501_get_essid(struct net_device
*dev
,
1630 struct iw_request_info
*info
,
1631 union iwreq_data
*wrqu
, char *extra
)
1633 struct wl3501_card
*this = netdev_priv(dev
);
1634 unsigned long flags
;
1636 spin_lock_irqsave(&this->lock
, flags
);
1637 wrqu
->essid
.flags
= 1;
1638 wrqu
->essid
.length
= this->essid
.el
.len
;
1639 memcpy(extra
, this->essid
.essid
, this->essid
.el
.len
);
1640 spin_unlock_irqrestore(&this->lock
, flags
);
1644 static int wl3501_set_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1645 union iwreq_data
*wrqu
, char *extra
)
1647 struct wl3501_card
*this = netdev_priv(dev
);
1649 if (wrqu
->data
.length
> sizeof(this->nick
))
1651 strlcpy(this->nick
, extra
, wrqu
->data
.length
);
1655 static int wl3501_get_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1656 union iwreq_data
*wrqu
, char *extra
)
1658 struct wl3501_card
*this = netdev_priv(dev
);
1660 strlcpy(extra
, this->nick
, 32);
1661 wrqu
->data
.length
= strlen(extra
);
1665 static int wl3501_get_rate(struct net_device
*dev
, struct iw_request_info
*info
,
1666 union iwreq_data
*wrqu
, char *extra
)
1669 * FIXME: have to see from where to get this info, perhaps this card
1670 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1671 * common with the Planet Access Points. -acme
1673 wrqu
->bitrate
.value
= 2000000;
1674 wrqu
->bitrate
.fixed
= 1;
1678 static int wl3501_get_rts_threshold(struct net_device
*dev
,
1679 struct iw_request_info
*info
,
1680 union iwreq_data
*wrqu
, char *extra
)
1682 u16 threshold
; /* size checked: it is u16 */
1683 struct wl3501_card
*this = netdev_priv(dev
);
1684 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD
,
1685 &threshold
, sizeof(threshold
));
1687 wrqu
->rts
.value
= threshold
;
1688 wrqu
->rts
.disabled
= threshold
>= 2347;
1689 wrqu
->rts
.fixed
= 1;
1694 static int wl3501_get_frag_threshold(struct net_device
*dev
,
1695 struct iw_request_info
*info
,
1696 union iwreq_data
*wrqu
, char *extra
)
1698 u16 threshold
; /* size checked: it is u16 */
1699 struct wl3501_card
*this = netdev_priv(dev
);
1700 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD
,
1701 &threshold
, sizeof(threshold
));
1703 wrqu
->frag
.value
= threshold
;
1704 wrqu
->frag
.disabled
= threshold
>= 2346;
1705 wrqu
->frag
.fixed
= 1;
1710 static int wl3501_get_txpow(struct net_device
*dev
,
1711 struct iw_request_info
*info
,
1712 union iwreq_data
*wrqu
, char *extra
)
1715 struct wl3501_card
*this = netdev_priv(dev
);
1716 int rc
= wl3501_get_mib_value(this,
1717 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL
,
1718 &txpow
, sizeof(txpow
));
1720 wrqu
->txpower
.value
= txpow
;
1721 wrqu
->txpower
.disabled
= 0;
1723 * From the MIB values I think this can be configurable,
1724 * as it lists several tx power levels -acme
1726 wrqu
->txpower
.fixed
= 0;
1727 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
1732 static int wl3501_get_retry(struct net_device
*dev
,
1733 struct iw_request_info
*info
,
1734 union iwreq_data
*wrqu
, char *extra
)
1736 u8 retry
; /* size checked: it is u8 */
1737 struct wl3501_card
*this = netdev_priv(dev
);
1738 int rc
= wl3501_get_mib_value(this,
1739 WL3501_MIB_ATTR_LONG_RETRY_LIMIT
,
1740 &retry
, sizeof(retry
));
1743 if (wrqu
->retry
.flags
& IW_RETRY_LONG
) {
1744 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
1747 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT
,
1748 &retry
, sizeof(retry
));
1751 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_SHORT
;
1753 wrqu
->retry
.value
= retry
;
1754 wrqu
->retry
.disabled
= 0;
1759 static int wl3501_get_encode(struct net_device
*dev
,
1760 struct iw_request_info
*info
,
1761 union iwreq_data
*wrqu
, char *extra
)
1763 u8 implemented
, restricted
, keys
[100], len_keys
, tocopy
;
1764 struct wl3501_card
*this = netdev_priv(dev
);
1765 int rc
= wl3501_get_mib_value(this,
1766 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED
,
1767 &implemented
, sizeof(implemented
));
1771 wrqu
->encoding
.flags
= IW_ENCODE_DISABLED
;
1774 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED
,
1775 &restricted
, sizeof(restricted
));
1778 wrqu
->encoding
.flags
= restricted
? IW_ENCODE_RESTRICTED
:
1780 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN
,
1781 &len_keys
, sizeof(len_keys
));
1784 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS
,
1788 tocopy
= min_t(u16
, len_keys
, wrqu
->encoding
.length
);
1789 tocopy
= min_t(u8
, tocopy
, 100);
1790 wrqu
->encoding
.length
= tocopy
;
1791 memcpy(extra
, keys
, tocopy
);
1796 static int wl3501_get_power(struct net_device
*dev
,
1797 struct iw_request_info
*info
,
1798 union iwreq_data
*wrqu
, char *extra
)
1801 struct wl3501_card
*this = netdev_priv(dev
);
1802 int rc
= wl3501_get_mib_value(this,
1803 WL3501_MIB_ATTR_CURRENT_PWR_STATE
,
1804 &pwr_state
, sizeof(pwr_state
));
1807 wrqu
->power
.disabled
= !pwr_state
;
1808 wrqu
->power
.flags
= IW_POWER_ON
;
1813 static const iw_handler wl3501_handler
[] = {
1814 IW_HANDLER(SIOCGIWNAME
, wl3501_get_name
),
1815 IW_HANDLER(SIOCSIWFREQ
, wl3501_set_freq
),
1816 IW_HANDLER(SIOCGIWFREQ
, wl3501_get_freq
),
1817 IW_HANDLER(SIOCSIWMODE
, wl3501_set_mode
),
1818 IW_HANDLER(SIOCGIWMODE
, wl3501_get_mode
),
1819 IW_HANDLER(SIOCGIWSENS
, wl3501_get_sens
),
1820 IW_HANDLER(SIOCGIWRANGE
, wl3501_get_range
),
1821 IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
1822 IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
1823 IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
1824 IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
1825 IW_HANDLER(SIOCSIWAP
, wl3501_set_wap
),
1826 IW_HANDLER(SIOCGIWAP
, wl3501_get_wap
),
1827 IW_HANDLER(SIOCSIWSCAN
, wl3501_set_scan
),
1828 IW_HANDLER(SIOCGIWSCAN
, wl3501_get_scan
),
1829 IW_HANDLER(SIOCSIWESSID
, wl3501_set_essid
),
1830 IW_HANDLER(SIOCGIWESSID
, wl3501_get_essid
),
1831 IW_HANDLER(SIOCSIWNICKN
, wl3501_set_nick
),
1832 IW_HANDLER(SIOCGIWNICKN
, wl3501_get_nick
),
1833 IW_HANDLER(SIOCGIWRATE
, wl3501_get_rate
),
1834 IW_HANDLER(SIOCGIWRTS
, wl3501_get_rts_threshold
),
1835 IW_HANDLER(SIOCGIWFRAG
, wl3501_get_frag_threshold
),
1836 IW_HANDLER(SIOCGIWTXPOW
, wl3501_get_txpow
),
1837 IW_HANDLER(SIOCGIWRETRY
, wl3501_get_retry
),
1838 IW_HANDLER(SIOCGIWENCODE
, wl3501_get_encode
),
1839 IW_HANDLER(SIOCGIWPOWER
, wl3501_get_power
),
1842 static const struct iw_handler_def wl3501_handler_def
= {
1843 .num_standard
= ARRAY_SIZE(wl3501_handler
),
1844 .standard
= (iw_handler
*)wl3501_handler
,
1845 .get_wireless_stats
= wl3501_get_wireless_stats
,
1848 static const struct net_device_ops wl3501_netdev_ops
= {
1849 .ndo_open
= wl3501_open
,
1850 .ndo_stop
= wl3501_close
,
1851 .ndo_start_xmit
= wl3501_hard_start_xmit
,
1852 .ndo_tx_timeout
= wl3501_tx_timeout
,
1853 .ndo_set_mac_address
= eth_mac_addr
,
1854 .ndo_validate_addr
= eth_validate_addr
,
1857 static int wl3501_probe(struct pcmcia_device
*p_dev
)
1859 struct net_device
*dev
;
1860 struct wl3501_card
*this;
1862 /* The io structure describes IO port mapping */
1863 p_dev
->resource
[0]->end
= 16;
1864 p_dev
->resource
[0]->flags
= IO_DATA_PATH_WIDTH_8
;
1866 /* General socket configuration */
1867 p_dev
->config_flags
= CONF_ENABLE_IRQ
;
1868 p_dev
->config_index
= 1;
1870 dev
= alloc_etherdev(sizeof(struct wl3501_card
));
1875 dev
->netdev_ops
= &wl3501_netdev_ops
;
1876 dev
->watchdog_timeo
= 5 * HZ
;
1878 this = netdev_priv(dev
);
1879 this->wireless_data
.spy_data
= &this->spy_data
;
1880 this->p_dev
= p_dev
;
1881 dev
->wireless_data
= &this->wireless_data
;
1882 dev
->wireless_handlers
= &wl3501_handler_def
;
1883 netif_stop_queue(dev
);
1886 return wl3501_config(p_dev
);
1891 static int wl3501_config(struct pcmcia_device
*link
)
1893 struct net_device
*dev
= link
->priv
;
1895 struct wl3501_card
*this;
1897 /* Try allocating IO ports. This tries a few fixed addresses. If you
1898 * want, you can also read the card's config table to pick addresses --
1899 * see the serial driver for an example. */
1902 for (j
= 0x280; j
< 0x400; j
+= 0x20) {
1903 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1904 * 0x200-0x2ff, and so on, because this seems safer */
1905 link
->resource
[0]->start
= j
;
1906 link
->resource
[1]->start
= link
->resource
[0]->start
+ 0x10;
1907 i
= pcmcia_request_io(link
);
1914 /* Now allocate an interrupt line. Note that this does not actually
1915 * assign a handler to the interrupt. */
1917 ret
= pcmcia_request_irq(link
, wl3501_interrupt
);
1921 ret
= pcmcia_enable_device(link
);
1925 dev
->irq
= link
->irq
;
1926 dev
->base_addr
= link
->resource
[0]->start
;
1927 SET_NETDEV_DEV(dev
, &link
->dev
);
1928 if (register_netdev(dev
)) {
1929 printk(KERN_NOTICE
"wl3501_cs: register_netdev() failed\n");
1933 this = netdev_priv(dev
);
1935 this->base_addr
= dev
->base_addr
;
1937 if (!wl3501_get_flash_mac_addr(this)) {
1938 printk(KERN_WARNING
"%s: Can't read MAC addr in flash ROM?\n",
1940 unregister_netdev(dev
);
1944 for (i
= 0; i
< 6; i
++)
1945 dev
->dev_addr
[i
] = ((char *)&this->mac_addr
)[i
];
1947 /* print probe information */
1948 printk(KERN_INFO
"%s: wl3501 @ 0x%3.3x, IRQ %d, "
1949 "MAC addr in flash ROM:%pM\n",
1950 dev
->name
, this->base_addr
, (int)dev
->irq
,
1953 * Initialize card parameters - added by jss
1955 this->net_type
= IW_MODE_INFRA
;
1957 this->join_sta_bss
= 0;
1958 this->adhoc_times
= 0;
1959 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
, &this->essid
.el
,
1961 this->card_name
[0] = '\0';
1962 this->firmware_date
[0] = '\0';
1964 this->chan
= iw_default_channel(this->reg_domain
);
1965 strlcpy(this->nick
, "Planet WL3501", sizeof(this->nick
));
1966 spin_lock_init(&this->lock
);
1967 init_waitqueue_head(&this->wait
);
1968 netif_start_queue(dev
);
1972 wl3501_release(link
);
1976 static void wl3501_release(struct pcmcia_device
*link
)
1978 pcmcia_disable_device(link
);
1981 static int wl3501_suspend(struct pcmcia_device
*link
)
1983 struct net_device
*dev
= link
->priv
;
1985 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_SUSPEND
);
1987 netif_device_detach(dev
);
1992 static int wl3501_resume(struct pcmcia_device
*link
)
1994 struct net_device
*dev
= link
->priv
;
1996 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_RESUME
);
1999 netif_device_attach(dev
);
2006 static const struct pcmcia_device_id wl3501_ids
[] = {
2007 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2010 MODULE_DEVICE_TABLE(pcmcia
, wl3501_ids
);
2012 static struct pcmcia_driver wl3501_driver
= {
2013 .owner
= THIS_MODULE
,
2014 .name
= "wl3501_cs",
2015 .probe
= wl3501_probe
,
2016 .remove
= wl3501_detach
,
2017 .id_table
= wl3501_ids
,
2018 .suspend
= wl3501_suspend
,
2019 .resume
= wl3501_resume
,
2021 module_pcmcia_driver(wl3501_driver
);
2023 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2024 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2025 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2026 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2027 MODULE_LICENSE("GPL");