2 * WL3501 Wireless LAN PCMCIA Card Driver for Linux
3 * Written originally for Linux 2.0.30 by Fox Chen, mhchen@golf.ccl.itri.org.tw
4 * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 * Wireless extensions in 2.4 by Gustavo Niemeyer <niemeyer@conectiva.com>
7 * References used by Fox Chen while writing the original driver for 2.0.30:
9 * 1. WL24xx packet drivers (tooasm.asm)
10 * 2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
12 * 4. Linux network driver (/usr/src/linux/drivers/net)
13 * 5. ISA card driver - wl24.c
14 * 6. Linux PCMCIA skeleton driver - skeleton.c
15 * 7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
17 * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
18 * 1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
19 * rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
20 * (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
21 * ETHER/IP/UDP/TCP header, and acknowledgement overhead)
23 * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
24 * 173 Kbytes/s in TCP.
26 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
27 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
30 #include <linux/delay.h>
31 #include <linux/types.h>
32 #include <linux/init.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 <linux/ieee80211.h>
48 #include <net/iw_handler.h>
50 #include <pcmcia/cistpl.h>
51 #include <pcmcia/cisreg.h>
52 #include <pcmcia/ds.h>
55 #include <asm/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_comain - 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_comain - 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
240 * @dest: Card addressing space
241 * @src: PC addressing space
242 * @size: Bytes to move
244 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
246 static void wl3501_set_to_wla(struct wl3501_card
*this, u16 dest
, void *src
,
249 /* switch to SRAM Page 0 */
250 wl3501_switch_page(this, (dest
& 0x8000) ? WL3501_BSS_SPAGE1
:
252 /* set LMAL and LMAH */
253 wl3501_outb(dest
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
254 wl3501_outb(((dest
>> 8) & 0x7f), this->base_addr
+ WL3501_NIC_LMAH
);
256 /* rep out to Port A */
257 wl3501_outsb(this->base_addr
+ WL3501_NIC_IODPA
, src
, size
);
261 * wl3501_get_from_wla - Move 'size' bytes from card to PC
262 * @src: Card addressing space
263 * @dest: PC addressing space
264 * @size: Bytes to move
266 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
268 static void wl3501_get_from_wla(struct wl3501_card
*this, u16 src
, void *dest
,
271 /* switch to SRAM Page 0 */
272 wl3501_switch_page(this, (src
& 0x8000) ? WL3501_BSS_SPAGE1
:
274 /* set LMAL and LMAH */
275 wl3501_outb(src
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
276 wl3501_outb((src
>> 8) & 0x7f, this->base_addr
+ WL3501_NIC_LMAH
);
278 /* rep get from Port A */
279 insb(this->base_addr
+ WL3501_NIC_IODPA
, dest
, size
);
283 * Get/Allocate a free Tx Data Buffer
285 * *--------------*-----------------*----------------------------------*
286 * | PLCP | MAC Header | DST SRC Data ... |
287 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
288 * *--------------*-----------------*----------------------------------*
289 * \ \- IEEE 802.11 -/ \-------------- len --------------/
290 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
292 * Return = Position in Card
294 static u16
wl3501_get_tx_buffer(struct wl3501_card
*this, u16 len
)
296 u16 next
, blk_cnt
= 0, zero
= 0;
297 u16 full_len
= sizeof(struct wl3501_80211_tx_hdr
) + len
;
300 if (full_len
> this->tx_buffer_cnt
* 254)
302 ret
= this->tx_buffer_head
;
308 wl3501_get_from_wla(this, this->tx_buffer_head
, &next
,
311 wl3501_set_to_wla(this, this->tx_buffer_head
, &zero
,
313 this->tx_buffer_head
= next
;
315 /* if buffer is not enough */
316 if (!next
&& full_len
) {
317 this->tx_buffer_head
= ret
;
322 this->tx_buffer_cnt
-= blk_cnt
;
328 * Free an allocated Tx Buffer. ptr must be correct position.
330 static void wl3501_free_tx_buffer(struct wl3501_card
*this, u16 ptr
)
332 /* check if all space is not free */
333 if (!this->tx_buffer_head
)
334 this->tx_buffer_head
= ptr
;
336 wl3501_set_to_wla(this, this->tx_buffer_tail
,
341 this->tx_buffer_cnt
++;
342 wl3501_get_from_wla(this, ptr
, &next
, sizeof(next
));
343 this->tx_buffer_tail
= ptr
;
348 static int wl3501_esbq_req_test(struct wl3501_card
*this)
352 wl3501_get_from_wla(this, this->esbq_req_head
+ 3, &tmp
, sizeof(tmp
));
356 static void wl3501_esbq_req(struct wl3501_card
*this, u16
*ptr
)
360 wl3501_set_to_wla(this, this->esbq_req_head
, ptr
, 2);
361 wl3501_set_to_wla(this, this->esbq_req_head
+ 2, &tmp
, sizeof(tmp
));
362 this->esbq_req_head
+= 4;
363 if (this->esbq_req_head
>= this->esbq_req_end
)
364 this->esbq_req_head
= this->esbq_req_start
;
367 static int wl3501_esbq_exec(struct wl3501_card
*this, void *sig
, int sig_size
)
371 if (wl3501_esbq_req_test(this)) {
372 u16 ptr
= wl3501_get_tx_buffer(this, sig_size
);
374 wl3501_set_to_wla(this, ptr
, sig
, sig_size
);
375 wl3501_esbq_req(this, &ptr
);
382 static int wl3501_get_mib_value(struct wl3501_card
*this, u8 index
,
385 struct wl3501_get_req sig
= {
386 .sig_id
= WL3501_SIG_GET_REQ
,
392 spin_lock_irqsave(&this->lock
, flags
);
393 if (wl3501_esbq_req_test(this)) {
394 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
396 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
397 wl3501_esbq_req(this, &ptr
);
398 this->sig_get_confirm
.mib_status
= 255;
399 spin_unlock_irqrestore(&this->lock
, flags
);
400 rc
= wait_event_interruptible(this->wait
,
401 this->sig_get_confirm
.mib_status
!= 255);
403 memcpy(bf
, this->sig_get_confirm
.mib_value
,
408 spin_unlock_irqrestore(&this->lock
, flags
);
413 static int wl3501_pwr_mgmt(struct wl3501_card
*this, int suspend
)
415 struct wl3501_pwr_mgmt_req sig
= {
416 .sig_id
= WL3501_SIG_PWR_MGMT_REQ
,
424 spin_lock_irqsave(&this->lock
, flags
);
425 if (wl3501_esbq_req_test(this)) {
426 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
428 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
429 wl3501_esbq_req(this, &ptr
);
430 this->sig_pwr_mgmt_confirm
.status
= 255;
431 spin_unlock_irqrestore(&this->lock
, flags
);
432 rc
= wait_event_interruptible(this->wait
,
433 this->sig_pwr_mgmt_confirm
.status
!= 255);
434 printk(KERN_INFO
"%s: %s status=%d\n", __func__
,
435 suspend
? "suspend" : "resume",
436 this->sig_pwr_mgmt_confirm
.status
);
440 spin_unlock_irqrestore(&this->lock
, flags
);
446 * wl3501_send_pkt - Send a packet.
451 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
452 * data[6] - data[11] is Src MAC Addr)
455 static int wl3501_send_pkt(struct wl3501_card
*this, u8
*data
, u16 len
)
457 u16 bf
, sig_bf
, next
, tmplen
, pktlen
;
458 struct wl3501_md_req sig
= {
459 .sig_id
= WL3501_SIG_MD_REQ
,
461 u8
*pdata
= (char *)data
;
464 if (wl3501_esbq_req_test(this)) {
465 sig_bf
= wl3501_get_tx_buffer(this, sizeof(sig
));
467 if (!sig_bf
) /* No free buffer available */
469 bf
= wl3501_get_tx_buffer(this, len
+ 26 + 24);
471 /* No free buffer available */
472 wl3501_free_tx_buffer(this, sig_bf
);
476 memcpy(&sig
.daddr
[0], pdata
, 12);
480 if (((*pdata
) * 256 + (*(pdata
+ 1))) > 1500) {
481 u8 addr4
[ETH_ALEN
] = {
482 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
485 wl3501_set_to_wla(this, bf
+ 2 +
486 offsetof(struct wl3501_tx_hdr
, addr4
),
487 addr4
, sizeof(addr4
));
488 sig
.size
= pktlen
+ 24 + 4 + 6;
489 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
))) {
490 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
);
496 wl3501_set_to_wla(this,
497 bf
+ 2 + sizeof(struct wl3501_tx_hdr
),
500 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
503 sig
.size
= pktlen
+ 24 + 4 - 2;
506 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
) + 6)) {
507 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
) + 6;
513 wl3501_set_to_wla(this, bf
+ 2 +
514 offsetof(struct wl3501_tx_hdr
, addr4
),
517 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
528 wl3501_set_to_wla(this, bf
+ 2, pdata
, tmplen
);
530 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
533 wl3501_set_to_wla(this, sig_bf
, &sig
, sizeof(sig
));
534 wl3501_esbq_req(this, &sig_bf
);
540 static int wl3501_mgmt_resync(struct wl3501_card
*this)
542 struct wl3501_resync_req sig
= {
543 .sig_id
= WL3501_SIG_RESYNC_REQ
,
546 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
549 static inline int wl3501_fw_bss_type(struct wl3501_card
*this)
551 return this->net_type
== IW_MODE_INFRA
? WL3501_NET_TYPE_INFRA
:
552 WL3501_NET_TYPE_ADHOC
;
555 static inline int wl3501_fw_cap_info(struct wl3501_card
*this)
557 return this->net_type
== IW_MODE_INFRA
? WL3501_MGMT_CAPABILITY_ESS
:
558 WL3501_MGMT_CAPABILITY_IBSS
;
561 static int wl3501_mgmt_scan(struct wl3501_card
*this, u16 chan_time
)
563 struct wl3501_scan_req sig
= {
564 .sig_id
= WL3501_SIG_SCAN_REQ
,
565 .scan_type
= WL3501_SCAN_TYPE_ACTIVE
,
567 .min_chan_time
= chan_time
,
568 .max_chan_time
= chan_time
,
569 .bss_type
= wl3501_fw_bss_type(this),
572 this->bss_cnt
= this->join_sta_bss
= 0;
573 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
576 static int wl3501_mgmt_join(struct wl3501_card
*this, u16 stas
)
578 struct wl3501_join_req sig
= {
579 .sig_id
= WL3501_SIG_JOIN_REQ
,
583 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
590 memcpy(&sig
.beacon_period
, &this->bss_set
[stas
].beacon_period
, 72);
591 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
594 static int wl3501_mgmt_start(struct wl3501_card
*this)
596 struct wl3501_start_req sig
= {
597 .sig_id
= WL3501_SIG_START_REQ
,
598 .beacon_period
= 400,
602 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
609 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
612 .data_rate_labels
= {
613 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
614 IW_MGMT_RATE_LABEL_1MBIT
,
615 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
616 IW_MGMT_RATE_LABEL_2MBIT
,
619 .operational_rset
= {
621 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
624 .data_rate_labels
= {
625 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
626 IW_MGMT_RATE_LABEL_1MBIT
,
627 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
628 IW_MGMT_RATE_LABEL_2MBIT
,
633 .id
= IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET
,
638 .bss_type
= wl3501_fw_bss_type(this),
639 .cap_info
= wl3501_fw_cap_info(this),
642 iw_copy_mgmt_info_element(&sig
.ssid
.el
, &this->essid
.el
);
643 iw_copy_mgmt_info_element(&this->keep_essid
.el
, &this->essid
.el
);
644 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
647 static void wl3501_mgmt_scan_confirm(struct wl3501_card
*this, u16 addr
)
651 struct wl3501_scan_confirm sig
;
654 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
655 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
657 if ((this->net_type
== IW_MODE_INFRA
&&
658 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_ESS
)) ||
659 (this->net_type
== IW_MODE_ADHOC
&&
660 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_IBSS
)) ||
661 this->net_type
== IW_MODE_AUTO
) {
662 if (!this->essid
.el
.len
)
664 else if (this->essid
.el
.len
== 3 &&
665 !memcmp(this->essid
.essid
, "ANY", 3))
667 else if (this->essid
.el
.len
!= sig
.ssid
.el
.len
)
669 else if (memcmp(this->essid
.essid
, sig
.ssid
.essid
,
675 for (i
= 0; i
< this->bss_cnt
; i
++) {
676 if (!memcmp(this->bss_set
[i
].bssid
,
677 sig
.bssid
, ETH_ALEN
)) {
683 if (matchflag
&& (i
< 20)) {
684 memcpy(&this->bss_set
[i
].beacon_period
,
685 &sig
.beacon_period
, 73);
687 this->rssi
= sig
.rssi
;
690 } else if (sig
.status
== WL3501_STATUS_TIMEOUT
) {
692 this->join_sta_bss
= 0;
693 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
694 if (!wl3501_mgmt_join(this, i
))
696 this->join_sta_bss
= i
;
697 if (this->join_sta_bss
== this->bss_cnt
) {
698 if (this->net_type
== IW_MODE_INFRA
)
699 wl3501_mgmt_scan(this, 100);
702 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
703 wl3501_mgmt_start(this);
705 wl3501_mgmt_scan(this, 100);
712 * wl3501_block_interrupt - Mask interrupt from SUTRO
715 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
716 * Return: 1 if interrupt is originally enabled
718 static int wl3501_block_interrupt(struct wl3501_card
*this)
720 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
721 u8
new = old
& (~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
|
722 WL3501_GCR_ENECINT
));
724 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
725 return old
& WL3501_GCR_ENECINT
;
729 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
732 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
733 * Return: 1 if interrupt is originally enabled
735 static int wl3501_unblock_interrupt(struct wl3501_card
*this)
737 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
738 u8
new = (old
& ~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
)) |
741 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
742 return old
& WL3501_GCR_ENECINT
;
746 * wl3501_receive - Receive data from Receive Queue.
748 * Receive data from Receive Queue.
751 * @bf: address of host
752 * @size: size of buffer.
754 static u16
wl3501_receive(struct wl3501_card
*this, u8
*bf
, u16 size
)
756 u16 next_addr
, next_addr1
;
760 wl3501_get_from_wla(this, this->start_seg
+ 2,
761 &next_addr
, sizeof(next_addr
));
762 if (size
> WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
)) {
763 wl3501_get_from_wla(this,
765 sizeof(struct wl3501_rx_hdr
), data
,
767 sizeof(struct wl3501_rx_hdr
));
768 size
-= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
769 data
+= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
771 wl3501_get_from_wla(this,
773 sizeof(struct wl3501_rx_hdr
),
778 if (size
> WL3501_BLKSZ
- 5) {
779 wl3501_get_from_wla(this, next_addr
+ 5, data
,
781 size
-= WL3501_BLKSZ
- 5;
782 data
+= WL3501_BLKSZ
- 5;
783 wl3501_get_from_wla(this, next_addr
+ 2, &next_addr1
,
785 next_addr
= next_addr1
;
787 wl3501_get_from_wla(this, next_addr
+ 5, data
, size
);
794 static void wl3501_esbq_req_free(struct wl3501_card
*this)
799 if (this->esbq_req_head
== this->esbq_req_tail
)
801 wl3501_get_from_wla(this, this->esbq_req_tail
+ 3, &tmp
, sizeof(tmp
));
804 wl3501_get_from_wla(this, this->esbq_req_tail
, &addr
, sizeof(addr
));
805 wl3501_free_tx_buffer(this, addr
);
806 this->esbq_req_tail
+= 4;
807 if (this->esbq_req_tail
>= this->esbq_req_end
)
808 this->esbq_req_tail
= this->esbq_req_start
;
813 static int wl3501_esbq_confirm(struct wl3501_card
*this)
817 wl3501_get_from_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
821 static void wl3501_online(struct net_device
*dev
)
823 struct wl3501_card
*this = netdev_priv(dev
);
825 printk(KERN_INFO
"%s: Wireless LAN online. BSSID: %pM\n",
826 dev
->name
, this->bssid
);
827 netif_wake_queue(dev
);
830 static void wl3501_esbq_confirm_done(struct wl3501_card
*this)
834 wl3501_set_to_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
835 this->esbq_confirm
+= 4;
836 if (this->esbq_confirm
>= this->esbq_confirm_end
)
837 this->esbq_confirm
= this->esbq_confirm_start
;
840 static int wl3501_mgmt_auth(struct wl3501_card
*this)
842 struct wl3501_auth_req sig
= {
843 .sig_id
= WL3501_SIG_AUTH_REQ
,
844 .type
= WL3501_SYS_TYPE_OPEN
,
849 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
850 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
853 static int wl3501_mgmt_association(struct wl3501_card
*this)
855 struct wl3501_assoc_req sig
= {
856 .sig_id
= WL3501_SIG_ASSOC_REQ
,
858 .listen_interval
= 5,
859 .cap_info
= this->cap_info
,
863 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
864 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
867 static void wl3501_mgmt_join_confirm(struct net_device
*dev
, u16 addr
)
869 struct wl3501_card
*this = netdev_priv(dev
);
870 struct wl3501_join_confirm sig
;
873 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
874 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
875 if (this->net_type
== IW_MODE_INFRA
) {
876 if (this->join_sta_bss
< this->bss_cnt
) {
877 const int i
= this->join_sta_bss
;
879 this->bss_set
[i
].bssid
, ETH_ALEN
);
880 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
881 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
882 &this->bss_set
[i
].ssid
.el
);
883 wl3501_mgmt_auth(this);
886 const int i
= this->join_sta_bss
;
888 memcpy(&this->bssid
, &this->bss_set
[i
].bssid
, ETH_ALEN
);
889 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
890 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
891 &this->bss_set
[i
].ssid
.el
);
896 this->join_sta_bss
++;
897 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
898 if (!wl3501_mgmt_join(this, i
))
900 this->join_sta_bss
= i
;
901 if (this->join_sta_bss
== this->bss_cnt
) {
902 if (this->net_type
== IW_MODE_INFRA
)
903 wl3501_mgmt_scan(this, 100);
906 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
907 wl3501_mgmt_start(this);
909 wl3501_mgmt_scan(this, 100);
915 static inline void wl3501_alarm_interrupt(struct net_device
*dev
,
916 struct wl3501_card
*this)
918 if (this->net_type
== IW_MODE_INFRA
) {
919 printk(KERN_INFO
"Wireless LAN offline\n");
920 netif_stop_queue(dev
);
921 wl3501_mgmt_resync(this);
925 static inline void wl3501_md_confirm_interrupt(struct net_device
*dev
,
926 struct wl3501_card
*this,
929 struct wl3501_md_confirm sig
;
932 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
933 wl3501_free_tx_buffer(this, sig
.data
);
934 if (netif_queue_stopped(dev
))
935 netif_wake_queue(dev
);
938 static inline void wl3501_md_ind_interrupt(struct net_device
*dev
,
939 struct wl3501_card
*this, u16 addr
)
941 struct wl3501_md_ind sig
;
943 u8 rssi
, addr4
[ETH_ALEN
];
946 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
947 this->start_seg
= sig
.data
;
948 wl3501_get_from_wla(this,
949 sig
.data
+ offsetof(struct wl3501_rx_hdr
, rssi
),
950 &rssi
, sizeof(rssi
));
951 this->rssi
= rssi
<= 63 ? (rssi
* 100) / 64 : 255;
953 wl3501_get_from_wla(this,
955 offsetof(struct wl3501_rx_hdr
, addr4
),
956 &addr4
, sizeof(addr4
));
957 if (!(addr4
[0] == 0xAA && addr4
[1] == 0xAA &&
958 addr4
[2] == 0x03 && addr4
[4] == 0x00)) {
959 printk(KERN_INFO
"Insupported packet type!\n");
962 pkt_len
= sig
.size
+ 12 - 24 - 4 - 6;
964 skb
= dev_alloc_skb(pkt_len
+ 5);
967 printk(KERN_WARNING
"%s: Can't alloc a sk_buff of size %d.\n",
969 dev
->stats
.rx_dropped
++;
972 skb_reserve(skb
, 2); /* IP headers on 16 bytes boundaries */
973 skb_copy_to_linear_data(skb
, (unsigned char *)&sig
.daddr
, 12);
974 wl3501_receive(this, skb
->data
, pkt_len
);
975 skb_put(skb
, pkt_len
);
976 skb
->protocol
= eth_type_trans(skb
, dev
);
977 dev
->stats
.rx_packets
++;
978 dev
->stats
.rx_bytes
+= skb
->len
;
983 static inline void wl3501_get_confirm_interrupt(struct wl3501_card
*this,
984 u16 addr
, void *sig
, int size
)
987 wl3501_get_from_wla(this, addr
, &this->sig_get_confirm
,
988 sizeof(this->sig_get_confirm
));
989 wake_up(&this->wait
);
992 static inline void wl3501_start_confirm_interrupt(struct net_device
*dev
,
993 struct wl3501_card
*this,
996 struct wl3501_start_confirm sig
;
999 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1000 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1001 netif_wake_queue(dev
);
1004 static inline void wl3501_assoc_confirm_interrupt(struct net_device
*dev
,
1007 struct wl3501_card
*this = netdev_priv(dev
);
1008 struct wl3501_assoc_confirm sig
;
1011 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1013 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1017 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card
*this,
1020 struct wl3501_auth_confirm sig
;
1023 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1025 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1026 wl3501_mgmt_association(this);
1028 wl3501_mgmt_resync(this);
1031 static inline void wl3501_rx_interrupt(struct net_device
*dev
)
1036 struct wl3501_card
*this = netdev_priv(dev
);
1041 if (!wl3501_esbq_confirm(this))
1043 wl3501_get_from_wla(this, this->esbq_confirm
, &addr
, sizeof(addr
));
1044 wl3501_get_from_wla(this, addr
+ 2, &sig_id
, sizeof(sig_id
));
1047 case WL3501_SIG_DEAUTH_IND
:
1048 case WL3501_SIG_DISASSOC_IND
:
1049 case WL3501_SIG_ALARM
:
1050 wl3501_alarm_interrupt(dev
, this);
1052 case WL3501_SIG_MD_CONFIRM
:
1053 wl3501_md_confirm_interrupt(dev
, this, addr
);
1055 case WL3501_SIG_MD_IND
:
1056 wl3501_md_ind_interrupt(dev
, this, addr
);
1058 case WL3501_SIG_GET_CONFIRM
:
1059 wl3501_get_confirm_interrupt(this, addr
,
1060 &this->sig_get_confirm
,
1061 sizeof(this->sig_get_confirm
));
1063 case WL3501_SIG_PWR_MGMT_CONFIRM
:
1064 wl3501_get_confirm_interrupt(this, addr
,
1065 &this->sig_pwr_mgmt_confirm
,
1066 sizeof(this->sig_pwr_mgmt_confirm
));
1068 case WL3501_SIG_START_CONFIRM
:
1069 wl3501_start_confirm_interrupt(dev
, this, addr
);
1071 case WL3501_SIG_SCAN_CONFIRM
:
1072 wl3501_mgmt_scan_confirm(this, addr
);
1074 case WL3501_SIG_JOIN_CONFIRM
:
1075 wl3501_mgmt_join_confirm(dev
, addr
);
1077 case WL3501_SIG_ASSOC_CONFIRM
:
1078 wl3501_assoc_confirm_interrupt(dev
, addr
);
1080 case WL3501_SIG_AUTH_CONFIRM
:
1081 wl3501_auth_confirm_interrupt(this, addr
);
1083 case WL3501_SIG_RESYNC_CONFIRM
:
1084 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1087 wl3501_esbq_confirm_done(this);
1089 /* free request if necessary */
1091 wl3501_esbq_req_free(this);
1096 static inline void wl3501_ack_interrupt(struct wl3501_card
*this)
1098 wl3501_outb(WL3501_GCR_ECINT
, this->base_addr
+ WL3501_NIC_GCR
);
1102 * wl3501_interrupt - Hardware interrupt from card.
1103 * @irq - Interrupt number
1104 * @dev_id - net_device
1106 * We must acknowledge the interrupt as soon as possible, and block the
1107 * interrupt from the same card immediately to prevent re-entry.
1109 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1110 * On the other hand, to prevent SUTRO from malfunctioning, we must
1111 * unlock the SUTRO as soon as possible.
1113 static irqreturn_t
wl3501_interrupt(int irq
, void *dev_id
)
1115 struct net_device
*dev
= dev_id
;
1116 struct wl3501_card
*this;
1118 this = netdev_priv(dev
);
1119 spin_lock(&this->lock
);
1120 wl3501_ack_interrupt(this);
1121 wl3501_block_interrupt(this);
1122 wl3501_rx_interrupt(dev
);
1123 wl3501_unblock_interrupt(this);
1124 spin_unlock(&this->lock
);
1129 static int wl3501_reset_board(struct wl3501_card
*this)
1135 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1136 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1137 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1139 /* Reset SRAM 0x480 to zero */
1140 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1143 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1145 WL3501_NOPLOOP(1024 * 50);
1147 wl3501_unblock_interrupt(this); /* acme: was commented */
1149 /* Polling Self_Test_Status */
1150 for (i
= 0; i
< 10000; i
++) {
1151 wl3501_get_from_wla(this, 0x480, &tmp
, sizeof(tmp
));
1154 /* firmware complete all test successfully */
1156 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1161 printk(KERN_WARNING
"%s: failed to reset the board!\n", __func__
);
1167 static int wl3501_init_firmware(struct wl3501_card
*this)
1170 int rc
= wl3501_reset_board(this);
1174 this->card_name
[0] = '\0';
1175 wl3501_get_from_wla(this, 0x1a00,
1176 this->card_name
, sizeof(this->card_name
));
1177 this->card_name
[sizeof(this->card_name
) - 1] = '\0';
1178 this->firmware_date
[0] = '\0';
1179 wl3501_get_from_wla(this, 0x1a40,
1180 this->firmware_date
, sizeof(this->firmware_date
));
1181 this->firmware_date
[sizeof(this->firmware_date
) - 1] = '\0';
1182 /* Switch to SRAM Page 0 */
1183 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
1184 /* Read parameter from card */
1185 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start
, 2);
1186 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end
, 2);
1187 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start
, 2);
1188 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end
, 2);
1189 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head
, 2);
1190 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size
, 2);
1191 this->esbq_req_tail
= this->esbq_req_head
= this->esbq_req_start
;
1192 this->esbq_req_end
+= this->esbq_req_start
;
1193 this->esbq_confirm
= this->esbq_confirm_start
;
1194 this->esbq_confirm_end
+= this->esbq_confirm_start
;
1195 /* Initial Tx Buffer */
1196 this->tx_buffer_cnt
= 1;
1197 ptr
= this->tx_buffer_head
;
1198 next
= ptr
+ WL3501_BLKSZ
;
1199 while ((next
- this->tx_buffer_head
) < this->tx_buffer_size
) {
1200 this->tx_buffer_cnt
++;
1201 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1203 next
= ptr
+ WL3501_BLKSZ
;
1207 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1208 this->tx_buffer_tail
= ptr
;
1212 printk(KERN_WARNING
"%s: failed!\n", __func__
);
1216 static int wl3501_close(struct net_device
*dev
)
1218 struct wl3501_card
*this = netdev_priv(dev
);
1220 unsigned long flags
;
1221 struct pcmcia_device
*link
;
1224 spin_lock_irqsave(&this->lock
, flags
);
1227 /* Stop wl3501_hard_start_xmit() from now on */
1228 netif_stop_queue(dev
);
1229 wl3501_ack_interrupt(this);
1231 /* Mask interrupts from the SUTRO */
1232 wl3501_block_interrupt(this);
1235 printk(KERN_INFO
"%s: WL3501 closed\n", dev
->name
);
1236 spin_unlock_irqrestore(&this->lock
, flags
);
1241 * wl3501_reset - Reset the SUTRO.
1242 * @dev - network device
1244 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1245 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1246 * is running. It seems to be dangerous.
1248 static int wl3501_reset(struct net_device
*dev
)
1250 struct wl3501_card
*this = netdev_priv(dev
);
1253 wl3501_block_interrupt(this);
1255 if (wl3501_init_firmware(this)) {
1256 printk(KERN_WARNING
"%s: Can't initialize Firmware!\n",
1258 /* Free IRQ, and mark IRQ as unused */
1259 free_irq(dev
->irq
, dev
);
1264 * Queue has to be started only when the Card is Started
1266 netif_stop_queue(dev
);
1267 this->adhoc_times
= 0;
1268 wl3501_ack_interrupt(this);
1269 wl3501_unblock_interrupt(this);
1270 wl3501_mgmt_scan(this, 100);
1271 pr_debug("%s: device reset", dev
->name
);
1277 static void wl3501_tx_timeout(struct net_device
*dev
)
1279 struct wl3501_card
*this = netdev_priv(dev
);
1280 struct net_device_stats
*stats
= &dev
->stats
;
1281 unsigned long flags
;
1285 spin_lock_irqsave(&this->lock
, flags
);
1286 rc
= wl3501_reset(dev
);
1287 spin_unlock_irqrestore(&this->lock
, flags
);
1289 printk(KERN_ERR
"%s: Error %d resetting card on Tx timeout!\n",
1292 dev
->trans_start
= jiffies
; /* prevent tx timeout */
1293 netif_wake_queue(dev
);
1299 * 1 - Could not transmit (dev_queue_xmit will queue it)
1300 * and try to sent it later
1302 static netdev_tx_t
wl3501_hard_start_xmit(struct sk_buff
*skb
,
1303 struct net_device
*dev
)
1306 struct wl3501_card
*this = netdev_priv(dev
);
1307 unsigned long flags
;
1309 spin_lock_irqsave(&this->lock
, flags
);
1310 enabled
= wl3501_block_interrupt(this);
1311 rc
= wl3501_send_pkt(this, skb
->data
, skb
->len
);
1313 wl3501_unblock_interrupt(this);
1315 ++dev
->stats
.tx_dropped
;
1316 netif_stop_queue(dev
);
1318 ++dev
->stats
.tx_packets
;
1319 dev
->stats
.tx_bytes
+= skb
->len
;
1322 if (this->tx_buffer_cnt
< 2)
1323 netif_stop_queue(dev
);
1325 spin_unlock_irqrestore(&this->lock
, flags
);
1326 return NETDEV_TX_OK
;
1329 static int wl3501_open(struct net_device
*dev
)
1332 struct wl3501_card
*this = netdev_priv(dev
);
1333 unsigned long flags
;
1334 struct pcmcia_device
*link
;
1337 spin_lock_irqsave(&this->lock
, flags
);
1338 if (!pcmcia_dev_present(link
))
1340 netif_device_attach(dev
);
1343 /* Initial WL3501 firmware */
1344 pr_debug("%s: Initialize WL3501 firmware...", dev
->name
);
1345 if (wl3501_init_firmware(this))
1347 /* Initial device variables */
1348 this->adhoc_times
= 0;
1349 /* Acknowledge Interrupt, for cleaning last state */
1350 wl3501_ack_interrupt(this);
1352 /* Enable interrupt from card after all */
1353 wl3501_unblock_interrupt(this);
1354 wl3501_mgmt_scan(this, 100);
1356 pr_debug("%s: WL3501 opened", dev
->name
);
1357 printk(KERN_INFO
"%s: Card Name: %s\n"
1358 "%s: Firmware Date: %s\n",
1359 dev
->name
, this->card_name
,
1360 dev
->name
, this->firmware_date
);
1362 spin_unlock_irqrestore(&this->lock
, flags
);
1365 printk(KERN_WARNING
"%s: Can't initialize firmware!\n", dev
->name
);
1369 static struct iw_statistics
*wl3501_get_wireless_stats(struct net_device
*dev
)
1371 struct wl3501_card
*this = netdev_priv(dev
);
1372 struct iw_statistics
*wstats
= &this->wstats
;
1373 u32 value
; /* size checked: it is u32 */
1375 memset(wstats
, 0, sizeof(*wstats
));
1376 wstats
->status
= netif_running(dev
);
1377 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT
,
1378 &value
, sizeof(value
)))
1379 wstats
->discard
.code
+= value
;
1380 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT
,
1381 &value
, sizeof(value
)))
1382 wstats
->discard
.code
+= value
;
1383 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT
,
1384 &value
, sizeof(value
)))
1385 wstats
->discard
.code
+= value
;
1386 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT
,
1387 &value
, sizeof(value
)))
1388 wstats
->discard
.retries
= value
;
1389 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT
,
1390 &value
, sizeof(value
)))
1391 wstats
->discard
.misc
+= value
;
1392 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT
,
1393 &value
, sizeof(value
)))
1394 wstats
->discard
.misc
+= value
;
1395 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT
,
1396 &value
, sizeof(value
)))
1397 wstats
->discard
.misc
+= value
;
1398 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT
,
1399 &value
, sizeof(value
)))
1400 wstats
->discard
.misc
+= value
;
1405 * wl3501_detach - deletes a driver "instance"
1408 * This deletes a driver "instance". The device is de-registered with Card
1409 * Services. If it has been released, all local data structures are freed.
1410 * Otherwise, the structures will be freed when the device is released.
1412 static void wl3501_detach(struct pcmcia_device
*link
)
1414 struct net_device
*dev
= link
->priv
;
1416 /* If the device is currently configured and active, we won't actually
1417 * delete it yet. Instead, it is marked so that when the release()
1418 * function is called, that will trigger a proper detach(). */
1420 while (link
->open
> 0)
1423 netif_device_detach(dev
);
1424 wl3501_release(link
);
1426 unregister_netdev(dev
);
1429 free_netdev(link
->priv
);
1432 static int wl3501_get_name(struct net_device
*dev
, struct iw_request_info
*info
,
1433 union iwreq_data
*wrqu
, char *extra
)
1435 strlcpy(wrqu
->name
, "IEEE 802.11-DS", sizeof(wrqu
->name
));
1439 static int wl3501_set_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1440 union iwreq_data
*wrqu
, char *extra
)
1442 struct wl3501_card
*this = netdev_priv(dev
);
1443 int channel
= wrqu
->freq
.m
;
1446 if (iw_valid_channel(this->reg_domain
, channel
)) {
1447 this->chan
= channel
;
1448 rc
= wl3501_reset(dev
);
1453 static int wl3501_get_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1454 union iwreq_data
*wrqu
, char *extra
)
1456 struct wl3501_card
*this = netdev_priv(dev
);
1458 wrqu
->freq
.m
= ieee80211_dsss_chan_to_freq(this->chan
) * 100000;
1463 static int wl3501_set_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1464 union iwreq_data
*wrqu
, char *extra
)
1468 if (wrqu
->mode
== IW_MODE_INFRA
||
1469 wrqu
->mode
== IW_MODE_ADHOC
||
1470 wrqu
->mode
== IW_MODE_AUTO
) {
1471 struct wl3501_card
*this = netdev_priv(dev
);
1473 this->net_type
= wrqu
->mode
;
1474 rc
= wl3501_reset(dev
);
1479 static int wl3501_get_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1480 union iwreq_data
*wrqu
, char *extra
)
1482 struct wl3501_card
*this = netdev_priv(dev
);
1484 wrqu
->mode
= this->net_type
;
1488 static int wl3501_get_sens(struct net_device
*dev
, struct iw_request_info
*info
,
1489 union iwreq_data
*wrqu
, char *extra
)
1491 struct wl3501_card
*this = netdev_priv(dev
);
1493 wrqu
->sens
.value
= this->rssi
;
1494 wrqu
->sens
.disabled
= !wrqu
->sens
.value
;
1495 wrqu
->sens
.fixed
= 1;
1499 static int wl3501_get_range(struct net_device
*dev
,
1500 struct iw_request_info
*info
,
1501 union iwreq_data
*wrqu
, char *extra
)
1503 struct iw_range
*range
= (struct iw_range
*)extra
;
1505 /* Set the length (very important for backward compatibility) */
1506 wrqu
->data
.length
= sizeof(*range
);
1508 /* Set all the info we don't care or don't know about to zero */
1509 memset(range
, 0, sizeof(*range
));
1511 /* Set the Wireless Extension versions */
1512 range
->we_version_compiled
= WIRELESS_EXT
;
1513 range
->we_version_source
= 1;
1514 range
->throughput
= 2 * 1000 * 1000; /* ~2 Mb/s */
1515 /* FIXME: study the code to fill in more fields... */
1519 static int wl3501_set_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1520 union iwreq_data
*wrqu
, char *extra
)
1522 struct wl3501_card
*this = netdev_priv(dev
);
1525 /* FIXME: we support other ARPHRDs...*/
1526 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
1528 if (is_broadcast_ether_addr(wrqu
->ap_addr
.sa_data
)) {
1529 /* FIXME: rescan? */
1531 memcpy(this->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
1532 /* FIXME: rescan? deassoc & scan? */
1538 static int wl3501_get_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1539 union iwreq_data
*wrqu
, char *extra
)
1541 struct wl3501_card
*this = netdev_priv(dev
);
1543 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1544 memcpy(wrqu
->ap_addr
.sa_data
, this->bssid
, ETH_ALEN
);
1548 static int wl3501_set_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1549 union iwreq_data
*wrqu
, char *extra
)
1552 * FIXME: trigger scanning with a reset, yes, I'm lazy
1554 return wl3501_reset(dev
);
1557 static int wl3501_get_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1558 union iwreq_data
*wrqu
, char *extra
)
1560 struct wl3501_card
*this = netdev_priv(dev
);
1562 char *current_ev
= extra
;
1563 struct iw_event iwe
;
1565 for (i
= 0; i
< this->bss_cnt
; ++i
) {
1566 iwe
.cmd
= SIOCGIWAP
;
1567 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1568 memcpy(iwe
.u
.ap_addr
.sa_data
, this->bss_set
[i
].bssid
, ETH_ALEN
);
1569 current_ev
= iwe_stream_add_event(info
, current_ev
,
1570 extra
+ IW_SCAN_MAX_DATA
,
1571 &iwe
, IW_EV_ADDR_LEN
);
1572 iwe
.cmd
= SIOCGIWESSID
;
1573 iwe
.u
.data
.flags
= 1;
1574 iwe
.u
.data
.length
= this->bss_set
[i
].ssid
.el
.len
;
1575 current_ev
= iwe_stream_add_point(info
, current_ev
,
1576 extra
+ IW_SCAN_MAX_DATA
,
1578 this->bss_set
[i
].ssid
.essid
);
1579 iwe
.cmd
= SIOCGIWMODE
;
1580 iwe
.u
.mode
= this->bss_set
[i
].bss_type
;
1581 current_ev
= iwe_stream_add_event(info
, current_ev
,
1582 extra
+ IW_SCAN_MAX_DATA
,
1583 &iwe
, IW_EV_UINT_LEN
);
1584 iwe
.cmd
= SIOCGIWFREQ
;
1585 iwe
.u
.freq
.m
= this->bss_set
[i
].ds_pset
.chan
;
1587 current_ev
= iwe_stream_add_event(info
, current_ev
,
1588 extra
+ IW_SCAN_MAX_DATA
,
1589 &iwe
, IW_EV_FREQ_LEN
);
1590 iwe
.cmd
= SIOCGIWENCODE
;
1591 if (this->bss_set
[i
].cap_info
& WL3501_MGMT_CAPABILITY_PRIVACY
)
1592 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1594 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1595 iwe
.u
.data
.length
= 0;
1596 current_ev
= iwe_stream_add_point(info
, current_ev
,
1597 extra
+ IW_SCAN_MAX_DATA
,
1600 /* Length of data */
1601 wrqu
->data
.length
= (current_ev
- extra
);
1602 wrqu
->data
.flags
= 0; /* FIXME: set properly these flags */
1606 static int wl3501_set_essid(struct net_device
*dev
,
1607 struct iw_request_info
*info
,
1608 union iwreq_data
*wrqu
, char *extra
)
1610 struct wl3501_card
*this = netdev_priv(dev
);
1612 if (wrqu
->data
.flags
) {
1613 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1615 extra
, wrqu
->data
.length
);
1616 } else { /* We accept any ESSID */
1617 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1618 &this->essid
.el
, "ANY", 3);
1620 return wl3501_reset(dev
);
1623 static int wl3501_get_essid(struct net_device
*dev
,
1624 struct iw_request_info
*info
,
1625 union iwreq_data
*wrqu
, char *extra
)
1627 struct wl3501_card
*this = netdev_priv(dev
);
1628 unsigned long flags
;
1630 spin_lock_irqsave(&this->lock
, flags
);
1631 wrqu
->essid
.flags
= 1;
1632 wrqu
->essid
.length
= this->essid
.el
.len
;
1633 memcpy(extra
, this->essid
.essid
, this->essid
.el
.len
);
1634 spin_unlock_irqrestore(&this->lock
, flags
);
1638 static int wl3501_set_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1639 union iwreq_data
*wrqu
, char *extra
)
1641 struct wl3501_card
*this = netdev_priv(dev
);
1643 if (wrqu
->data
.length
> sizeof(this->nick
))
1645 strlcpy(this->nick
, extra
, wrqu
->data
.length
);
1649 static int wl3501_get_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1650 union iwreq_data
*wrqu
, char *extra
)
1652 struct wl3501_card
*this = netdev_priv(dev
);
1654 strlcpy(extra
, this->nick
, 32);
1655 wrqu
->data
.length
= strlen(extra
);
1659 static int wl3501_get_rate(struct net_device
*dev
, struct iw_request_info
*info
,
1660 union iwreq_data
*wrqu
, char *extra
)
1663 * FIXME: have to see from where to get this info, perhaps this card
1664 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1665 * common with the Planet Access Points. -acme
1667 wrqu
->bitrate
.value
= 2000000;
1668 wrqu
->bitrate
.fixed
= 1;
1672 static int wl3501_get_rts_threshold(struct net_device
*dev
,
1673 struct iw_request_info
*info
,
1674 union iwreq_data
*wrqu
, char *extra
)
1676 u16 threshold
; /* size checked: it is u16 */
1677 struct wl3501_card
*this = netdev_priv(dev
);
1678 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD
,
1679 &threshold
, sizeof(threshold
));
1681 wrqu
->rts
.value
= threshold
;
1682 wrqu
->rts
.disabled
= threshold
>= 2347;
1683 wrqu
->rts
.fixed
= 1;
1688 static int wl3501_get_frag_threshold(struct net_device
*dev
,
1689 struct iw_request_info
*info
,
1690 union iwreq_data
*wrqu
, char *extra
)
1692 u16 threshold
; /* size checked: it is u16 */
1693 struct wl3501_card
*this = netdev_priv(dev
);
1694 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD
,
1695 &threshold
, sizeof(threshold
));
1697 wrqu
->frag
.value
= threshold
;
1698 wrqu
->frag
.disabled
= threshold
>= 2346;
1699 wrqu
->frag
.fixed
= 1;
1704 static int wl3501_get_txpow(struct net_device
*dev
,
1705 struct iw_request_info
*info
,
1706 union iwreq_data
*wrqu
, char *extra
)
1709 struct wl3501_card
*this = netdev_priv(dev
);
1710 int rc
= wl3501_get_mib_value(this,
1711 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL
,
1712 &txpow
, sizeof(txpow
));
1714 wrqu
->txpower
.value
= txpow
;
1715 wrqu
->txpower
.disabled
= 0;
1717 * From the MIB values I think this can be configurable,
1718 * as it lists several tx power levels -acme
1720 wrqu
->txpower
.fixed
= 0;
1721 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
1726 static int wl3501_get_retry(struct net_device
*dev
,
1727 struct iw_request_info
*info
,
1728 union iwreq_data
*wrqu
, char *extra
)
1730 u8 retry
; /* size checked: it is u8 */
1731 struct wl3501_card
*this = netdev_priv(dev
);
1732 int rc
= wl3501_get_mib_value(this,
1733 WL3501_MIB_ATTR_LONG_RETRY_LIMIT
,
1734 &retry
, sizeof(retry
));
1737 if (wrqu
->retry
.flags
& IW_RETRY_LONG
) {
1738 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
1741 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT
,
1742 &retry
, sizeof(retry
));
1745 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_SHORT
;
1747 wrqu
->retry
.value
= retry
;
1748 wrqu
->retry
.disabled
= 0;
1753 static int wl3501_get_encode(struct net_device
*dev
,
1754 struct iw_request_info
*info
,
1755 union iwreq_data
*wrqu
, char *extra
)
1757 u8 implemented
, restricted
, keys
[100], len_keys
, tocopy
;
1758 struct wl3501_card
*this = netdev_priv(dev
);
1759 int rc
= wl3501_get_mib_value(this,
1760 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED
,
1761 &implemented
, sizeof(implemented
));
1765 wrqu
->encoding
.flags
= IW_ENCODE_DISABLED
;
1768 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED
,
1769 &restricted
, sizeof(restricted
));
1772 wrqu
->encoding
.flags
= restricted
? IW_ENCODE_RESTRICTED
:
1774 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN
,
1775 &len_keys
, sizeof(len_keys
));
1778 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS
,
1782 tocopy
= min_t(u16
, len_keys
, wrqu
->encoding
.length
);
1783 tocopy
= min_t(u8
, tocopy
, 100);
1784 wrqu
->encoding
.length
= tocopy
;
1785 memcpy(extra
, keys
, tocopy
);
1790 static int wl3501_get_power(struct net_device
*dev
,
1791 struct iw_request_info
*info
,
1792 union iwreq_data
*wrqu
, char *extra
)
1795 struct wl3501_card
*this = netdev_priv(dev
);
1796 int rc
= wl3501_get_mib_value(this,
1797 WL3501_MIB_ATTR_CURRENT_PWR_STATE
,
1798 &pwr_state
, sizeof(pwr_state
));
1801 wrqu
->power
.disabled
= !pwr_state
;
1802 wrqu
->power
.flags
= IW_POWER_ON
;
1807 static const iw_handler wl3501_handler
[] = {
1808 IW_HANDLER(SIOCGIWNAME
, wl3501_get_name
),
1809 IW_HANDLER(SIOCSIWFREQ
, wl3501_set_freq
),
1810 IW_HANDLER(SIOCGIWFREQ
, wl3501_get_freq
),
1811 IW_HANDLER(SIOCSIWMODE
, wl3501_set_mode
),
1812 IW_HANDLER(SIOCGIWMODE
, wl3501_get_mode
),
1813 IW_HANDLER(SIOCGIWSENS
, wl3501_get_sens
),
1814 IW_HANDLER(SIOCGIWRANGE
, wl3501_get_range
),
1815 IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
1816 IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
1817 IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
1818 IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
1819 IW_HANDLER(SIOCSIWAP
, wl3501_set_wap
),
1820 IW_HANDLER(SIOCGIWAP
, wl3501_get_wap
),
1821 IW_HANDLER(SIOCSIWSCAN
, wl3501_set_scan
),
1822 IW_HANDLER(SIOCGIWSCAN
, wl3501_get_scan
),
1823 IW_HANDLER(SIOCSIWESSID
, wl3501_set_essid
),
1824 IW_HANDLER(SIOCGIWESSID
, wl3501_get_essid
),
1825 IW_HANDLER(SIOCSIWNICKN
, wl3501_set_nick
),
1826 IW_HANDLER(SIOCGIWNICKN
, wl3501_get_nick
),
1827 IW_HANDLER(SIOCGIWRATE
, wl3501_get_rate
),
1828 IW_HANDLER(SIOCGIWRTS
, wl3501_get_rts_threshold
),
1829 IW_HANDLER(SIOCGIWFRAG
, wl3501_get_frag_threshold
),
1830 IW_HANDLER(SIOCGIWTXPOW
, wl3501_get_txpow
),
1831 IW_HANDLER(SIOCGIWRETRY
, wl3501_get_retry
),
1832 IW_HANDLER(SIOCGIWENCODE
, wl3501_get_encode
),
1833 IW_HANDLER(SIOCGIWPOWER
, wl3501_get_power
),
1836 static const struct iw_handler_def wl3501_handler_def
= {
1837 .num_standard
= ARRAY_SIZE(wl3501_handler
),
1838 .standard
= (iw_handler
*)wl3501_handler
,
1839 .get_wireless_stats
= wl3501_get_wireless_stats
,
1842 static const struct net_device_ops wl3501_netdev_ops
= {
1843 .ndo_open
= wl3501_open
,
1844 .ndo_stop
= wl3501_close
,
1845 .ndo_start_xmit
= wl3501_hard_start_xmit
,
1846 .ndo_tx_timeout
= wl3501_tx_timeout
,
1847 .ndo_change_mtu
= eth_change_mtu
,
1848 .ndo_set_mac_address
= eth_mac_addr
,
1849 .ndo_validate_addr
= eth_validate_addr
,
1852 static int wl3501_probe(struct pcmcia_device
*p_dev
)
1854 struct net_device
*dev
;
1855 struct wl3501_card
*this;
1857 /* The io structure describes IO port mapping */
1858 p_dev
->resource
[0]->end
= 16;
1859 p_dev
->resource
[0]->flags
= IO_DATA_PATH_WIDTH_8
;
1861 /* General socket configuration */
1862 p_dev
->config_flags
= CONF_ENABLE_IRQ
;
1863 p_dev
->config_index
= 1;
1865 dev
= alloc_etherdev(sizeof(struct wl3501_card
));
1870 dev
->netdev_ops
= &wl3501_netdev_ops
;
1871 dev
->watchdog_timeo
= 5 * HZ
;
1873 this = netdev_priv(dev
);
1874 this->wireless_data
.spy_data
= &this->spy_data
;
1875 this->p_dev
= p_dev
;
1876 dev
->wireless_data
= &this->wireless_data
;
1877 dev
->wireless_handlers
= &wl3501_handler_def
;
1878 netif_stop_queue(dev
);
1881 return wl3501_config(p_dev
);
1886 static int wl3501_config(struct pcmcia_device
*link
)
1888 struct net_device
*dev
= link
->priv
;
1890 struct wl3501_card
*this;
1892 /* Try allocating IO ports. This tries a few fixed addresses. If you
1893 * want, you can also read the card's config table to pick addresses --
1894 * see the serial driver for an example. */
1897 for (j
= 0x280; j
< 0x400; j
+= 0x20) {
1898 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1899 * 0x200-0x2ff, and so on, because this seems safer */
1900 link
->resource
[0]->start
= j
;
1901 link
->resource
[1]->start
= link
->resource
[0]->start
+ 0x10;
1902 i
= pcmcia_request_io(link
);
1909 /* Now allocate an interrupt line. Note that this does not actually
1910 * assign a handler to the interrupt. */
1912 ret
= pcmcia_request_irq(link
, wl3501_interrupt
);
1916 ret
= pcmcia_enable_device(link
);
1920 dev
->irq
= link
->irq
;
1921 dev
->base_addr
= link
->resource
[0]->start
;
1922 SET_NETDEV_DEV(dev
, &link
->dev
);
1923 if (register_netdev(dev
)) {
1924 printk(KERN_NOTICE
"wl3501_cs: register_netdev() failed\n");
1928 this = netdev_priv(dev
);
1930 this->base_addr
= dev
->base_addr
;
1932 if (!wl3501_get_flash_mac_addr(this)) {
1933 printk(KERN_WARNING
"%s: Can't read MAC addr in flash ROM?\n",
1935 unregister_netdev(dev
);
1939 for (i
= 0; i
< 6; i
++)
1940 dev
->dev_addr
[i
] = ((char *)&this->mac_addr
)[i
];
1942 /* print probe information */
1943 printk(KERN_INFO
"%s: wl3501 @ 0x%3.3x, IRQ %d, "
1944 "MAC addr in flash ROM:%pM\n",
1945 dev
->name
, this->base_addr
, (int)dev
->irq
,
1948 * Initialize card parameters - added by jss
1950 this->net_type
= IW_MODE_INFRA
;
1952 this->join_sta_bss
= 0;
1953 this->adhoc_times
= 0;
1954 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
, &this->essid
.el
,
1956 this->card_name
[0] = '\0';
1957 this->firmware_date
[0] = '\0';
1959 this->chan
= iw_default_channel(this->reg_domain
);
1960 strlcpy(this->nick
, "Planet WL3501", sizeof(this->nick
));
1961 spin_lock_init(&this->lock
);
1962 init_waitqueue_head(&this->wait
);
1963 netif_start_queue(dev
);
1967 wl3501_release(link
);
1971 static void wl3501_release(struct pcmcia_device
*link
)
1973 pcmcia_disable_device(link
);
1976 static int wl3501_suspend(struct pcmcia_device
*link
)
1978 struct net_device
*dev
= link
->priv
;
1980 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_SUSPEND
);
1982 netif_device_detach(dev
);
1987 static int wl3501_resume(struct pcmcia_device
*link
)
1989 struct net_device
*dev
= link
->priv
;
1991 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_RESUME
);
1994 netif_device_attach(dev
);
2001 static const struct pcmcia_device_id wl3501_ids
[] = {
2002 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2005 MODULE_DEVICE_TABLE(pcmcia
, wl3501_ids
);
2007 static struct pcmcia_driver wl3501_driver
= {
2008 .owner
= THIS_MODULE
,
2009 .name
= "wl3501_cs",
2010 .probe
= wl3501_probe
,
2011 .remove
= wl3501_detach
,
2012 .id_table
= wl3501_ids
,
2013 .suspend
= wl3501_suspend
,
2014 .resume
= wl3501_resume
,
2016 module_pcmcia_driver(wl3501_driver
);
2018 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2019 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2020 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2021 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2022 MODULE_LICENSE("GPL");