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/ethtool.h>
33 #include <linux/init.h>
34 #include <linux/interrupt.h>
36 #include <linux/kernel.h>
37 #include <linux/module.h>
38 #include <linux/fcntl.h>
39 #include <linux/if_arp.h>
40 #include <linux/ioport.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/slab.h>
45 #include <linux/string.h>
46 #include <linux/wireless.h>
47 #include <linux/ieee80211.h>
49 #include <net/iw_handler.h>
51 #include <pcmcia/cistpl.h>
52 #include <pcmcia/cisreg.h>
53 #include <pcmcia/ds.h>
56 #include <asm/uaccess.h>
57 #include <asm/system.h>
62 #define slow_down_io()
65 /* For rough constant delay */
66 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
70 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
71 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
72 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
74 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
75 #define WL3501_MAX_ADHOC_TRIES 16
77 #define WL3501_RESUME 0
78 #define WL3501_SUSPEND 1
81 * The event() function is this driver's Card Services event handler. It will
82 * be called by Card Services when an appropriate card status event is
83 * received. The config() and release() entry points are used to configure or
84 * release a socket, in response to card insertion and ejection events. They
85 * are invoked from the wl24 event handler.
87 static int wl3501_config(struct pcmcia_device
*link
);
88 static void wl3501_release(struct pcmcia_device
*link
);
93 } iw_channel_table
[] = {
95 .reg_domain
= IW_REG_DOMAIN_FCC
,
101 .reg_domain
= IW_REG_DOMAIN_DOC
,
107 .reg_domain
= IW_REG_DOMAIN_ETSI
,
113 .reg_domain
= IW_REG_DOMAIN_SPAIN
,
119 .reg_domain
= IW_REG_DOMAIN_FRANCE
,
125 .reg_domain
= IW_REG_DOMAIN_MKK
,
131 .reg_domain
= IW_REG_DOMAIN_MKK1
,
137 .reg_domain
= IW_REG_DOMAIN_ISRAEL
,
145 * iw_valid_channel - validate channel in regulatory domain
146 * @reg_comain - regulatory domain
147 * @channel - channel to validate
149 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
151 static int iw_valid_channel(int reg_domain
, int channel
)
155 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
156 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
157 rc
= channel
>= iw_channel_table
[i
].min
&&
158 channel
<= iw_channel_table
[i
].max
;
165 * iw_default_channel - get default channel for a regulatory domain
166 * @reg_comain - regulatory domain
168 * Returns the default channel for a regulatory domain
170 static int iw_default_channel(int reg_domain
)
174 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
175 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
176 rc
= iw_channel_table
[i
].deflt
;
182 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id
,
183 struct iw_mgmt_info_element
*el
,
184 void *value
, int len
)
188 memcpy(el
->data
, value
, len
);
191 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element
*to
,
192 struct iw_mgmt_info_element
*from
)
194 iw_set_mgmt_info_element(from
->id
, to
, from
->data
, from
->len
);
197 static inline void wl3501_switch_page(struct wl3501_card
*this, u8 page
)
199 wl3501_outb(page
, this->base_addr
+ WL3501_NIC_BSS
);
203 * Get Ethernet MAC addresss.
205 * WARNING: We switch to FPAGE0 and switc back again.
206 * Making sure there is no other WL function beening called by ISR.
208 static int wl3501_get_flash_mac_addr(struct wl3501_card
*this)
210 int base_addr
= this->base_addr
;
213 wl3501_outb(WL3501_BSS_FPAGE3
, base_addr
+ WL3501_NIC_BSS
); /* BSS */
214 wl3501_outb(0x00, base_addr
+ WL3501_NIC_LMAL
); /* LMAL */
215 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
); /* LMAH */
217 /* wait for reading EEPROM */
219 this->mac_addr
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
221 this->mac_addr
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
223 this->mac_addr
[2] = inb(base_addr
+ WL3501_NIC_IODPA
);
225 this->mac_addr
[3] = inb(base_addr
+ WL3501_NIC_IODPA
);
227 this->mac_addr
[4] = inb(base_addr
+ WL3501_NIC_IODPA
);
229 this->mac_addr
[5] = inb(base_addr
+ WL3501_NIC_IODPA
);
231 this->reg_domain
= inb(base_addr
+ WL3501_NIC_IODPA
);
233 wl3501_outb(WL3501_BSS_FPAGE0
, base_addr
+ WL3501_NIC_BSS
);
234 wl3501_outb(0x04, base_addr
+ WL3501_NIC_LMAL
);
235 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
);
237 this->version
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
239 this->version
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
240 /* switch to SRAM Page 0 (for safety) */
241 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
243 /* The MAC addr should be 00:60:... */
244 return this->mac_addr
[0] == 0x00 && this->mac_addr
[1] == 0x60;
248 * wl3501_set_to_wla - Move 'size' bytes from PC to card
249 * @dest: Card addressing space
250 * @src: PC addressing space
251 * @size: Bytes to move
253 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
255 static void wl3501_set_to_wla(struct wl3501_card
*this, u16 dest
, void *src
,
258 /* switch to SRAM Page 0 */
259 wl3501_switch_page(this, (dest
& 0x8000) ? WL3501_BSS_SPAGE1
:
261 /* set LMAL and LMAH */
262 wl3501_outb(dest
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
263 wl3501_outb(((dest
>> 8) & 0x7f), this->base_addr
+ WL3501_NIC_LMAH
);
265 /* rep out to Port A */
266 wl3501_outsb(this->base_addr
+ WL3501_NIC_IODPA
, src
, size
);
270 * wl3501_get_from_wla - Move 'size' bytes from card to PC
271 * @src: Card addressing space
272 * @dest: PC addressing space
273 * @size: Bytes to move
275 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
277 static void wl3501_get_from_wla(struct wl3501_card
*this, u16 src
, void *dest
,
280 /* switch to SRAM Page 0 */
281 wl3501_switch_page(this, (src
& 0x8000) ? WL3501_BSS_SPAGE1
:
283 /* set LMAL and LMAH */
284 wl3501_outb(src
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
285 wl3501_outb((src
>> 8) & 0x7f, this->base_addr
+ WL3501_NIC_LMAH
);
287 /* rep get from Port A */
288 insb(this->base_addr
+ WL3501_NIC_IODPA
, dest
, size
);
292 * Get/Allocate a free Tx Data Buffer
294 * *--------------*-----------------*----------------------------------*
295 * | PLCP | MAC Header | DST SRC Data ... |
296 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
297 * *--------------*-----------------*----------------------------------*
298 * \ \- IEEE 802.11 -/ \-------------- len --------------/
299 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
301 * Return = Postion in Card
303 static u16
wl3501_get_tx_buffer(struct wl3501_card
*this, u16 len
)
305 u16 next
, blk_cnt
= 0, zero
= 0;
306 u16 full_len
= sizeof(struct wl3501_80211_tx_hdr
) + len
;
309 if (full_len
> this->tx_buffer_cnt
* 254)
311 ret
= this->tx_buffer_head
;
317 wl3501_get_from_wla(this, this->tx_buffer_head
, &next
,
320 wl3501_set_to_wla(this, this->tx_buffer_head
, &zero
,
322 this->tx_buffer_head
= next
;
324 /* if buffer is not enough */
325 if (!next
&& full_len
) {
326 this->tx_buffer_head
= ret
;
331 this->tx_buffer_cnt
-= blk_cnt
;
337 * Free an allocated Tx Buffer. ptr must be correct position.
339 static void wl3501_free_tx_buffer(struct wl3501_card
*this, u16 ptr
)
341 /* check if all space is not free */
342 if (!this->tx_buffer_head
)
343 this->tx_buffer_head
= ptr
;
345 wl3501_set_to_wla(this, this->tx_buffer_tail
,
350 this->tx_buffer_cnt
++;
351 wl3501_get_from_wla(this, ptr
, &next
, sizeof(next
));
352 this->tx_buffer_tail
= ptr
;
357 static int wl3501_esbq_req_test(struct wl3501_card
*this)
361 wl3501_get_from_wla(this, this->esbq_req_head
+ 3, &tmp
, sizeof(tmp
));
365 static void wl3501_esbq_req(struct wl3501_card
*this, u16
*ptr
)
369 wl3501_set_to_wla(this, this->esbq_req_head
, ptr
, 2);
370 wl3501_set_to_wla(this, this->esbq_req_head
+ 2, &tmp
, sizeof(tmp
));
371 this->esbq_req_head
+= 4;
372 if (this->esbq_req_head
>= this->esbq_req_end
)
373 this->esbq_req_head
= this->esbq_req_start
;
376 static int wl3501_esbq_exec(struct wl3501_card
*this, void *sig
, int sig_size
)
380 if (wl3501_esbq_req_test(this)) {
381 u16 ptr
= wl3501_get_tx_buffer(this, sig_size
);
383 wl3501_set_to_wla(this, ptr
, sig
, sig_size
);
384 wl3501_esbq_req(this, &ptr
);
391 static int wl3501_get_mib_value(struct wl3501_card
*this, u8 index
,
394 struct wl3501_get_req sig
= {
395 .sig_id
= WL3501_SIG_GET_REQ
,
401 spin_lock_irqsave(&this->lock
, flags
);
402 if (wl3501_esbq_req_test(this)) {
403 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
405 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
406 wl3501_esbq_req(this, &ptr
);
407 this->sig_get_confirm
.mib_status
= 255;
408 spin_unlock_irqrestore(&this->lock
, flags
);
409 rc
= wait_event_interruptible(this->wait
,
410 this->sig_get_confirm
.mib_status
!= 255);
412 memcpy(bf
, this->sig_get_confirm
.mib_value
,
417 spin_unlock_irqrestore(&this->lock
, flags
);
422 static int wl3501_pwr_mgmt(struct wl3501_card
*this, int suspend
)
424 struct wl3501_pwr_mgmt_req sig
= {
425 .sig_id
= WL3501_SIG_PWR_MGMT_REQ
,
433 spin_lock_irqsave(&this->lock
, flags
);
434 if (wl3501_esbq_req_test(this)) {
435 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
437 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
438 wl3501_esbq_req(this, &ptr
);
439 this->sig_pwr_mgmt_confirm
.status
= 255;
440 spin_unlock_irqrestore(&this->lock
, flags
);
441 rc
= wait_event_interruptible(this->wait
,
442 this->sig_pwr_mgmt_confirm
.status
!= 255);
443 printk(KERN_INFO
"%s: %s status=%d\n", __func__
,
444 suspend
? "suspend" : "resume",
445 this->sig_pwr_mgmt_confirm
.status
);
449 spin_unlock_irqrestore(&this->lock
, flags
);
455 * wl3501_send_pkt - Send a packet.
460 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
461 * data[6] - data[11] is Src MAC Addr)
464 static int wl3501_send_pkt(struct wl3501_card
*this, u8
*data
, u16 len
)
466 u16 bf
, sig_bf
, next
, tmplen
, pktlen
;
467 struct wl3501_md_req sig
= {
468 .sig_id
= WL3501_SIG_MD_REQ
,
470 u8
*pdata
= (char *)data
;
473 if (wl3501_esbq_req_test(this)) {
474 sig_bf
= wl3501_get_tx_buffer(this, sizeof(sig
));
476 if (!sig_bf
) /* No free buffer available */
478 bf
= wl3501_get_tx_buffer(this, len
+ 26 + 24);
480 /* No free buffer available */
481 wl3501_free_tx_buffer(this, sig_bf
);
485 memcpy(&sig
.daddr
[0], pdata
, 12);
489 if (((*pdata
) * 256 + (*(pdata
+ 1))) > 1500) {
490 u8 addr4
[ETH_ALEN
] = {
491 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
494 wl3501_set_to_wla(this, bf
+ 2 +
495 offsetof(struct wl3501_tx_hdr
, addr4
),
496 addr4
, sizeof(addr4
));
497 sig
.size
= pktlen
+ 24 + 4 + 6;
498 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
))) {
499 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
);
505 wl3501_set_to_wla(this,
506 bf
+ 2 + sizeof(struct wl3501_tx_hdr
),
509 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
512 sig
.size
= pktlen
+ 24 + 4 - 2;
515 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
) + 6)) {
516 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
) + 6;
522 wl3501_set_to_wla(this, bf
+ 2 +
523 offsetof(struct wl3501_tx_hdr
, addr4
),
526 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
537 wl3501_set_to_wla(this, bf
+ 2, pdata
, tmplen
);
539 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
542 wl3501_set_to_wla(this, sig_bf
, &sig
, sizeof(sig
));
543 wl3501_esbq_req(this, &sig_bf
);
549 static int wl3501_mgmt_resync(struct wl3501_card
*this)
551 struct wl3501_resync_req sig
= {
552 .sig_id
= WL3501_SIG_RESYNC_REQ
,
555 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
558 static inline int wl3501_fw_bss_type(struct wl3501_card
*this)
560 return this->net_type
== IW_MODE_INFRA
? WL3501_NET_TYPE_INFRA
:
561 WL3501_NET_TYPE_ADHOC
;
564 static inline int wl3501_fw_cap_info(struct wl3501_card
*this)
566 return this->net_type
== IW_MODE_INFRA
? WL3501_MGMT_CAPABILITY_ESS
:
567 WL3501_MGMT_CAPABILITY_IBSS
;
570 static int wl3501_mgmt_scan(struct wl3501_card
*this, u16 chan_time
)
572 struct wl3501_scan_req sig
= {
573 .sig_id
= WL3501_SIG_SCAN_REQ
,
574 .scan_type
= WL3501_SCAN_TYPE_ACTIVE
,
576 .min_chan_time
= chan_time
,
577 .max_chan_time
= chan_time
,
578 .bss_type
= wl3501_fw_bss_type(this),
581 this->bss_cnt
= this->join_sta_bss
= 0;
582 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
585 static int wl3501_mgmt_join(struct wl3501_card
*this, u16 stas
)
587 struct wl3501_join_req sig
= {
588 .sig_id
= WL3501_SIG_JOIN_REQ
,
592 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
599 memcpy(&sig
.beacon_period
, &this->bss_set
[stas
].beacon_period
, 72);
600 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
603 static int wl3501_mgmt_start(struct wl3501_card
*this)
605 struct wl3501_start_req sig
= {
606 .sig_id
= WL3501_SIG_START_REQ
,
607 .beacon_period
= 400,
611 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
618 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
621 .data_rate_labels
= {
622 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
623 IW_MGMT_RATE_LABEL_1MBIT
,
624 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
625 IW_MGMT_RATE_LABEL_2MBIT
,
628 .operational_rset
= {
630 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
633 .data_rate_labels
= {
634 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
635 IW_MGMT_RATE_LABEL_1MBIT
,
636 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
637 IW_MGMT_RATE_LABEL_2MBIT
,
642 .id
= IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET
,
647 .bss_type
= wl3501_fw_bss_type(this),
648 .cap_info
= wl3501_fw_cap_info(this),
651 iw_copy_mgmt_info_element(&sig
.ssid
.el
, &this->essid
.el
);
652 iw_copy_mgmt_info_element(&this->keep_essid
.el
, &this->essid
.el
);
653 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
656 static void wl3501_mgmt_scan_confirm(struct wl3501_card
*this, u16 addr
)
660 struct wl3501_scan_confirm sig
;
663 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
664 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
666 if ((this->net_type
== IW_MODE_INFRA
&&
667 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_ESS
)) ||
668 (this->net_type
== IW_MODE_ADHOC
&&
669 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_IBSS
)) ||
670 this->net_type
== IW_MODE_AUTO
) {
671 if (!this->essid
.el
.len
)
673 else if (this->essid
.el
.len
== 3 &&
674 !memcmp(this->essid
.essid
, "ANY", 3))
676 else if (this->essid
.el
.len
!= sig
.ssid
.el
.len
)
678 else if (memcmp(this->essid
.essid
, sig
.ssid
.essid
,
684 for (i
= 0; i
< this->bss_cnt
; i
++) {
685 if (!memcmp(this->bss_set
[i
].bssid
,
686 sig
.bssid
, ETH_ALEN
)) {
692 if (matchflag
&& (i
< 20)) {
693 memcpy(&this->bss_set
[i
].beacon_period
,
694 &sig
.beacon_period
, 73);
696 this->rssi
= sig
.rssi
;
699 } else if (sig
.status
== WL3501_STATUS_TIMEOUT
) {
701 this->join_sta_bss
= 0;
702 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
703 if (!wl3501_mgmt_join(this, i
))
705 this->join_sta_bss
= i
;
706 if (this->join_sta_bss
== this->bss_cnt
) {
707 if (this->net_type
== IW_MODE_INFRA
)
708 wl3501_mgmt_scan(this, 100);
711 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
712 wl3501_mgmt_start(this);
714 wl3501_mgmt_scan(this, 100);
721 * wl3501_block_interrupt - Mask interrupt from SUTRO
724 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
725 * Return: 1 if interrupt is originally enabled
727 static int wl3501_block_interrupt(struct wl3501_card
*this)
729 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
730 u8
new = old
& (~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
|
731 WL3501_GCR_ENECINT
));
733 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
734 return old
& WL3501_GCR_ENECINT
;
738 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
741 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
742 * Return: 1 if interrupt is originally enabled
744 static int wl3501_unblock_interrupt(struct wl3501_card
*this)
746 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
747 u8
new = (old
& ~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
)) |
750 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
751 return old
& WL3501_GCR_ENECINT
;
755 * wl3501_receive - Receive data from Receive Queue.
757 * Receive data from Receive Queue.
760 * @bf: address of host
761 * @size: size of buffer.
763 static u16
wl3501_receive(struct wl3501_card
*this, u8
*bf
, u16 size
)
765 u16 next_addr
, next_addr1
;
769 wl3501_get_from_wla(this, this->start_seg
+ 2,
770 &next_addr
, sizeof(next_addr
));
771 if (size
> WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
)) {
772 wl3501_get_from_wla(this,
774 sizeof(struct wl3501_rx_hdr
), data
,
776 sizeof(struct wl3501_rx_hdr
));
777 size
-= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
778 data
+= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
780 wl3501_get_from_wla(this,
782 sizeof(struct wl3501_rx_hdr
),
787 if (size
> WL3501_BLKSZ
- 5) {
788 wl3501_get_from_wla(this, next_addr
+ 5, data
,
790 size
-= WL3501_BLKSZ
- 5;
791 data
+= WL3501_BLKSZ
- 5;
792 wl3501_get_from_wla(this, next_addr
+ 2, &next_addr1
,
794 next_addr
= next_addr1
;
796 wl3501_get_from_wla(this, next_addr
+ 5, data
, size
);
803 static void wl3501_esbq_req_free(struct wl3501_card
*this)
808 if (this->esbq_req_head
== this->esbq_req_tail
)
810 wl3501_get_from_wla(this, this->esbq_req_tail
+ 3, &tmp
, sizeof(tmp
));
813 wl3501_get_from_wla(this, this->esbq_req_tail
, &addr
, sizeof(addr
));
814 wl3501_free_tx_buffer(this, addr
);
815 this->esbq_req_tail
+= 4;
816 if (this->esbq_req_tail
>= this->esbq_req_end
)
817 this->esbq_req_tail
= this->esbq_req_start
;
822 static int wl3501_esbq_confirm(struct wl3501_card
*this)
826 wl3501_get_from_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
830 static void wl3501_online(struct net_device
*dev
)
832 struct wl3501_card
*this = netdev_priv(dev
);
834 printk(KERN_INFO
"%s: Wireless LAN online. BSSID: %pM\n",
835 dev
->name
, this->bssid
);
836 netif_wake_queue(dev
);
839 static void wl3501_esbq_confirm_done(struct wl3501_card
*this)
843 wl3501_set_to_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
844 this->esbq_confirm
+= 4;
845 if (this->esbq_confirm
>= this->esbq_confirm_end
)
846 this->esbq_confirm
= this->esbq_confirm_start
;
849 static int wl3501_mgmt_auth(struct wl3501_card
*this)
851 struct wl3501_auth_req sig
= {
852 .sig_id
= WL3501_SIG_AUTH_REQ
,
853 .type
= WL3501_SYS_TYPE_OPEN
,
858 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
859 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
862 static int wl3501_mgmt_association(struct wl3501_card
*this)
864 struct wl3501_assoc_req sig
= {
865 .sig_id
= WL3501_SIG_ASSOC_REQ
,
867 .listen_interval
= 5,
868 .cap_info
= this->cap_info
,
872 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
873 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
876 static void wl3501_mgmt_join_confirm(struct net_device
*dev
, u16 addr
)
878 struct wl3501_card
*this = netdev_priv(dev
);
879 struct wl3501_join_confirm sig
;
882 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
883 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
884 if (this->net_type
== IW_MODE_INFRA
) {
885 if (this->join_sta_bss
< this->bss_cnt
) {
886 const int i
= this->join_sta_bss
;
888 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
);
892 wl3501_mgmt_auth(this);
895 const int i
= this->join_sta_bss
;
897 memcpy(&this->bssid
, &this->bss_set
[i
].bssid
, ETH_ALEN
);
898 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
899 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
900 &this->bss_set
[i
].ssid
.el
);
905 this->join_sta_bss
++;
906 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
907 if (!wl3501_mgmt_join(this, i
))
909 this->join_sta_bss
= i
;
910 if (this->join_sta_bss
== this->bss_cnt
) {
911 if (this->net_type
== IW_MODE_INFRA
)
912 wl3501_mgmt_scan(this, 100);
915 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
916 wl3501_mgmt_start(this);
918 wl3501_mgmt_scan(this, 100);
924 static inline void wl3501_alarm_interrupt(struct net_device
*dev
,
925 struct wl3501_card
*this)
927 if (this->net_type
== IW_MODE_INFRA
) {
928 printk(KERN_INFO
"Wireless LAN offline\n");
929 netif_stop_queue(dev
);
930 wl3501_mgmt_resync(this);
934 static inline void wl3501_md_confirm_interrupt(struct net_device
*dev
,
935 struct wl3501_card
*this,
938 struct wl3501_md_confirm sig
;
941 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
942 wl3501_free_tx_buffer(this, sig
.data
);
943 if (netif_queue_stopped(dev
))
944 netif_wake_queue(dev
);
947 static inline void wl3501_md_ind_interrupt(struct net_device
*dev
,
948 struct wl3501_card
*this, u16 addr
)
950 struct wl3501_md_ind sig
;
952 u8 rssi
, addr4
[ETH_ALEN
];
955 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
956 this->start_seg
= sig
.data
;
957 wl3501_get_from_wla(this,
958 sig
.data
+ offsetof(struct wl3501_rx_hdr
, rssi
),
959 &rssi
, sizeof(rssi
));
960 this->rssi
= rssi
<= 63 ? (rssi
* 100) / 64 : 255;
962 wl3501_get_from_wla(this,
964 offsetof(struct wl3501_rx_hdr
, addr4
),
965 &addr4
, sizeof(addr4
));
966 if (!(addr4
[0] == 0xAA && addr4
[1] == 0xAA &&
967 addr4
[2] == 0x03 && addr4
[4] == 0x00)) {
968 printk(KERN_INFO
"Insupported packet type!\n");
971 pkt_len
= sig
.size
+ 12 - 24 - 4 - 6;
973 skb
= dev_alloc_skb(pkt_len
+ 5);
976 printk(KERN_WARNING
"%s: Can't alloc a sk_buff of size %d.\n",
978 dev
->stats
.rx_dropped
++;
981 skb_reserve(skb
, 2); /* IP headers on 16 bytes boundaries */
982 skb_copy_to_linear_data(skb
, (unsigned char *)&sig
.daddr
, 12);
983 wl3501_receive(this, skb
->data
, pkt_len
);
984 skb_put(skb
, pkt_len
);
985 skb
->protocol
= eth_type_trans(skb
, dev
);
986 dev
->stats
.rx_packets
++;
987 dev
->stats
.rx_bytes
+= skb
->len
;
992 static inline void wl3501_get_confirm_interrupt(struct wl3501_card
*this,
993 u16 addr
, void *sig
, int size
)
996 wl3501_get_from_wla(this, addr
, &this->sig_get_confirm
,
997 sizeof(this->sig_get_confirm
));
998 wake_up(&this->wait
);
1001 static inline void wl3501_start_confirm_interrupt(struct net_device
*dev
,
1002 struct wl3501_card
*this,
1005 struct wl3501_start_confirm sig
;
1008 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1009 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1010 netif_wake_queue(dev
);
1013 static inline void wl3501_assoc_confirm_interrupt(struct net_device
*dev
,
1016 struct wl3501_card
*this = netdev_priv(dev
);
1017 struct wl3501_assoc_confirm sig
;
1020 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1022 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1026 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card
*this,
1029 struct wl3501_auth_confirm sig
;
1032 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1034 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1035 wl3501_mgmt_association(this);
1037 wl3501_mgmt_resync(this);
1040 static inline void wl3501_rx_interrupt(struct net_device
*dev
)
1045 struct wl3501_card
*this = netdev_priv(dev
);
1050 if (!wl3501_esbq_confirm(this))
1052 wl3501_get_from_wla(this, this->esbq_confirm
, &addr
, sizeof(addr
));
1053 wl3501_get_from_wla(this, addr
+ 2, &sig_id
, sizeof(sig_id
));
1056 case WL3501_SIG_DEAUTH_IND
:
1057 case WL3501_SIG_DISASSOC_IND
:
1058 case WL3501_SIG_ALARM
:
1059 wl3501_alarm_interrupt(dev
, this);
1061 case WL3501_SIG_MD_CONFIRM
:
1062 wl3501_md_confirm_interrupt(dev
, this, addr
);
1064 case WL3501_SIG_MD_IND
:
1065 wl3501_md_ind_interrupt(dev
, this, addr
);
1067 case WL3501_SIG_GET_CONFIRM
:
1068 wl3501_get_confirm_interrupt(this, addr
,
1069 &this->sig_get_confirm
,
1070 sizeof(this->sig_get_confirm
));
1072 case WL3501_SIG_PWR_MGMT_CONFIRM
:
1073 wl3501_get_confirm_interrupt(this, addr
,
1074 &this->sig_pwr_mgmt_confirm
,
1075 sizeof(this->sig_pwr_mgmt_confirm
));
1077 case WL3501_SIG_START_CONFIRM
:
1078 wl3501_start_confirm_interrupt(dev
, this, addr
);
1080 case WL3501_SIG_SCAN_CONFIRM
:
1081 wl3501_mgmt_scan_confirm(this, addr
);
1083 case WL3501_SIG_JOIN_CONFIRM
:
1084 wl3501_mgmt_join_confirm(dev
, addr
);
1086 case WL3501_SIG_ASSOC_CONFIRM
:
1087 wl3501_assoc_confirm_interrupt(dev
, addr
);
1089 case WL3501_SIG_AUTH_CONFIRM
:
1090 wl3501_auth_confirm_interrupt(this, addr
);
1092 case WL3501_SIG_RESYNC_CONFIRM
:
1093 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1096 wl3501_esbq_confirm_done(this);
1098 /* free request if necessary */
1100 wl3501_esbq_req_free(this);
1105 static inline void wl3501_ack_interrupt(struct wl3501_card
*this)
1107 wl3501_outb(WL3501_GCR_ECINT
, this->base_addr
+ WL3501_NIC_GCR
);
1111 * wl3501_interrupt - Hardware interrupt from card.
1112 * @irq - Interrupt number
1113 * @dev_id - net_device
1115 * We must acknowledge the interrupt as soon as possible, and block the
1116 * interrupt from the same card immediately to prevent re-entry.
1118 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1119 * On the other hand, to prevent SUTRO from malfunctioning, we must
1120 * unlock the SUTRO as soon as possible.
1122 static irqreturn_t
wl3501_interrupt(int irq
, void *dev_id
)
1124 struct net_device
*dev
= dev_id
;
1125 struct wl3501_card
*this;
1127 this = netdev_priv(dev
);
1128 spin_lock(&this->lock
);
1129 wl3501_ack_interrupt(this);
1130 wl3501_block_interrupt(this);
1131 wl3501_rx_interrupt(dev
);
1132 wl3501_unblock_interrupt(this);
1133 spin_unlock(&this->lock
);
1138 static int wl3501_reset_board(struct wl3501_card
*this)
1144 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1145 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1146 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1148 /* Reset SRAM 0x480 to zero */
1149 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1152 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1154 WL3501_NOPLOOP(1024 * 50);
1156 wl3501_unblock_interrupt(this); /* acme: was commented */
1158 /* Polling Self_Test_Status */
1159 for (i
= 0; i
< 10000; i
++) {
1160 wl3501_get_from_wla(this, 0x480, &tmp
, sizeof(tmp
));
1163 /* firmware complete all test successfully */
1165 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1170 printk(KERN_WARNING
"%s: failed to reset the board!\n", __func__
);
1176 static int wl3501_init_firmware(struct wl3501_card
*this)
1179 int rc
= wl3501_reset_board(this);
1183 this->card_name
[0] = '\0';
1184 wl3501_get_from_wla(this, 0x1a00,
1185 this->card_name
, sizeof(this->card_name
));
1186 this->card_name
[sizeof(this->card_name
) - 1] = '\0';
1187 this->firmware_date
[0] = '\0';
1188 wl3501_get_from_wla(this, 0x1a40,
1189 this->firmware_date
, sizeof(this->firmware_date
));
1190 this->firmware_date
[sizeof(this->firmware_date
) - 1] = '\0';
1191 /* Switch to SRAM Page 0 */
1192 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
1193 /* Read parameter from card */
1194 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start
, 2);
1195 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end
, 2);
1196 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start
, 2);
1197 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end
, 2);
1198 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head
, 2);
1199 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size
, 2);
1200 this->esbq_req_tail
= this->esbq_req_head
= this->esbq_req_start
;
1201 this->esbq_req_end
+= this->esbq_req_start
;
1202 this->esbq_confirm
= this->esbq_confirm_start
;
1203 this->esbq_confirm_end
+= this->esbq_confirm_start
;
1204 /* Initial Tx Buffer */
1205 this->tx_buffer_cnt
= 1;
1206 ptr
= this->tx_buffer_head
;
1207 next
= ptr
+ WL3501_BLKSZ
;
1208 while ((next
- this->tx_buffer_head
) < this->tx_buffer_size
) {
1209 this->tx_buffer_cnt
++;
1210 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1212 next
= ptr
+ WL3501_BLKSZ
;
1216 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1217 this->tx_buffer_tail
= ptr
;
1221 printk(KERN_WARNING
"%s: failed!\n", __func__
);
1225 static int wl3501_close(struct net_device
*dev
)
1227 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);
1244 printk(KERN_INFO
"%s: WL3501 closed\n", dev
->name
);
1245 spin_unlock_irqrestore(&this->lock
, flags
);
1250 * wl3501_reset - Reset the SUTRO.
1251 * @dev - network device
1253 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1254 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1255 * is running. It seems to be dangerous.
1257 static int wl3501_reset(struct net_device
*dev
)
1259 struct wl3501_card
*this = netdev_priv(dev
);
1262 wl3501_block_interrupt(this);
1264 if (wl3501_init_firmware(this)) {
1265 printk(KERN_WARNING
"%s: Can't initialize Firmware!\n",
1267 /* Free IRQ, and mark IRQ as unused */
1268 free_irq(dev
->irq
, dev
);
1273 * Queue has to be started only when the Card is Started
1275 netif_stop_queue(dev
);
1276 this->adhoc_times
= 0;
1277 wl3501_ack_interrupt(this);
1278 wl3501_unblock_interrupt(this);
1279 wl3501_mgmt_scan(this, 100);
1280 pr_debug("%s: device reset", dev
->name
);
1286 static void wl3501_tx_timeout(struct net_device
*dev
)
1288 struct wl3501_card
*this = netdev_priv(dev
);
1289 struct net_device_stats
*stats
= &dev
->stats
;
1290 unsigned long flags
;
1294 spin_lock_irqsave(&this->lock
, flags
);
1295 rc
= wl3501_reset(dev
);
1296 spin_unlock_irqrestore(&this->lock
, flags
);
1298 printk(KERN_ERR
"%s: Error %d resetting card on Tx timeout!\n",
1301 dev
->trans_start
= jiffies
; /* prevent tx timeout */
1302 netif_wake_queue(dev
);
1308 * 1 - Could not transmit (dev_queue_xmit will queue it)
1309 * and try to sent it later
1311 static netdev_tx_t
wl3501_hard_start_xmit(struct sk_buff
*skb
,
1312 struct net_device
*dev
)
1315 struct wl3501_card
*this = netdev_priv(dev
);
1316 unsigned long flags
;
1318 spin_lock_irqsave(&this->lock
, flags
);
1319 enabled
= wl3501_block_interrupt(this);
1320 rc
= wl3501_send_pkt(this, skb
->data
, skb
->len
);
1322 wl3501_unblock_interrupt(this);
1324 ++dev
->stats
.tx_dropped
;
1325 netif_stop_queue(dev
);
1327 ++dev
->stats
.tx_packets
;
1328 dev
->stats
.tx_bytes
+= skb
->len
;
1331 if (this->tx_buffer_cnt
< 2)
1332 netif_stop_queue(dev
);
1334 spin_unlock_irqrestore(&this->lock
, flags
);
1335 return NETDEV_TX_OK
;
1338 static int wl3501_open(struct net_device
*dev
)
1341 struct wl3501_card
*this = netdev_priv(dev
);
1342 unsigned long flags
;
1343 struct pcmcia_device
*link
;
1346 spin_lock_irqsave(&this->lock
, flags
);
1347 if (!pcmcia_dev_present(link
))
1349 netif_device_attach(dev
);
1352 /* Initial WL3501 firmware */
1353 pr_debug("%s: Initialize WL3501 firmware...", dev
->name
);
1354 if (wl3501_init_firmware(this))
1356 /* Initial device variables */
1357 this->adhoc_times
= 0;
1358 /* Acknowledge Interrupt, for cleaning last state */
1359 wl3501_ack_interrupt(this);
1361 /* Enable interrupt from card after all */
1362 wl3501_unblock_interrupt(this);
1363 wl3501_mgmt_scan(this, 100);
1365 pr_debug("%s: WL3501 opened", dev
->name
);
1366 printk(KERN_INFO
"%s: Card Name: %s\n"
1367 "%s: Firmware Date: %s\n",
1368 dev
->name
, this->card_name
,
1369 dev
->name
, this->firmware_date
);
1371 spin_unlock_irqrestore(&this->lock
, flags
);
1374 printk(KERN_WARNING
"%s: Can't initialize firmware!\n", dev
->name
);
1378 static struct iw_statistics
*wl3501_get_wireless_stats(struct net_device
*dev
)
1380 struct wl3501_card
*this = netdev_priv(dev
);
1381 struct iw_statistics
*wstats
= &this->wstats
;
1382 u32 value
; /* size checked: it is u32 */
1384 memset(wstats
, 0, sizeof(*wstats
));
1385 wstats
->status
= netif_running(dev
);
1386 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT
,
1387 &value
, sizeof(value
)))
1388 wstats
->discard
.code
+= value
;
1389 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT
,
1390 &value
, sizeof(value
)))
1391 wstats
->discard
.code
+= value
;
1392 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT
,
1393 &value
, sizeof(value
)))
1394 wstats
->discard
.code
+= value
;
1395 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT
,
1396 &value
, sizeof(value
)))
1397 wstats
->discard
.retries
= value
;
1398 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT
,
1399 &value
, sizeof(value
)))
1400 wstats
->discard
.misc
+= value
;
1401 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT
,
1402 &value
, sizeof(value
)))
1403 wstats
->discard
.misc
+= value
;
1404 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT
,
1405 &value
, sizeof(value
)))
1406 wstats
->discard
.misc
+= value
;
1407 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT
,
1408 &value
, sizeof(value
)))
1409 wstats
->discard
.misc
+= value
;
1413 static void wl3501_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1415 strlcpy(info
->driver
, "wl3501_cs", sizeof(info
->driver
));
1418 static const struct ethtool_ops ops
= {
1419 .get_drvinfo
= wl3501_get_drvinfo
1423 * wl3501_detach - deletes a driver "instance"
1426 * This deletes a driver "instance". The device is de-registered with Card
1427 * Services. If it has been released, all local data structures are freed.
1428 * Otherwise, the structures will be freed when the device is released.
1430 static void wl3501_detach(struct pcmcia_device
*link
)
1432 struct net_device
*dev
= link
->priv
;
1434 /* If the device is currently configured and active, we won't actually
1435 * delete it yet. Instead, it is marked so that when the release()
1436 * function is called, that will trigger a proper detach(). */
1438 while (link
->open
> 0)
1441 netif_device_detach(dev
);
1442 wl3501_release(link
);
1444 unregister_netdev(dev
);
1447 free_netdev(link
->priv
);
1450 static int wl3501_get_name(struct net_device
*dev
, struct iw_request_info
*info
,
1451 union iwreq_data
*wrqu
, char *extra
)
1453 strlcpy(wrqu
->name
, "IEEE 802.11-DS", sizeof(wrqu
->name
));
1457 static int wl3501_set_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1458 union iwreq_data
*wrqu
, char *extra
)
1460 struct wl3501_card
*this = netdev_priv(dev
);
1461 int channel
= wrqu
->freq
.m
;
1464 if (iw_valid_channel(this->reg_domain
, channel
)) {
1465 this->chan
= channel
;
1466 rc
= wl3501_reset(dev
);
1471 static int wl3501_get_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1472 union iwreq_data
*wrqu
, char *extra
)
1474 struct wl3501_card
*this = netdev_priv(dev
);
1476 wrqu
->freq
.m
= ieee80211_dsss_chan_to_freq(this->chan
) * 100000;
1481 static int wl3501_set_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1482 union iwreq_data
*wrqu
, char *extra
)
1486 if (wrqu
->mode
== IW_MODE_INFRA
||
1487 wrqu
->mode
== IW_MODE_ADHOC
||
1488 wrqu
->mode
== IW_MODE_AUTO
) {
1489 struct wl3501_card
*this = netdev_priv(dev
);
1491 this->net_type
= wrqu
->mode
;
1492 rc
= wl3501_reset(dev
);
1497 static int wl3501_get_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1498 union iwreq_data
*wrqu
, char *extra
)
1500 struct wl3501_card
*this = netdev_priv(dev
);
1502 wrqu
->mode
= this->net_type
;
1506 static int wl3501_get_sens(struct net_device
*dev
, struct iw_request_info
*info
,
1507 union iwreq_data
*wrqu
, char *extra
)
1509 struct wl3501_card
*this = netdev_priv(dev
);
1511 wrqu
->sens
.value
= this->rssi
;
1512 wrqu
->sens
.disabled
= !wrqu
->sens
.value
;
1513 wrqu
->sens
.fixed
= 1;
1517 static int wl3501_get_range(struct net_device
*dev
,
1518 struct iw_request_info
*info
,
1519 union iwreq_data
*wrqu
, char *extra
)
1521 struct iw_range
*range
= (struct iw_range
*)extra
;
1523 /* Set the length (very important for backward compatibility) */
1524 wrqu
->data
.length
= sizeof(*range
);
1526 /* Set all the info we don't care or don't know about to zero */
1527 memset(range
, 0, sizeof(*range
));
1529 /* Set the Wireless Extension versions */
1530 range
->we_version_compiled
= WIRELESS_EXT
;
1531 range
->we_version_source
= 1;
1532 range
->throughput
= 2 * 1000 * 1000; /* ~2 Mb/s */
1533 /* FIXME: study the code to fill in more fields... */
1537 static int wl3501_set_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1538 union iwreq_data
*wrqu
, char *extra
)
1540 struct wl3501_card
*this = netdev_priv(dev
);
1541 static const u8 bcast
[ETH_ALEN
] = { 255, 255, 255, 255, 255, 255 };
1544 /* FIXME: we support other ARPHRDs...*/
1545 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
1547 if (!memcmp(bcast
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
1548 /* FIXME: rescan? */
1550 memcpy(this->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
1551 /* FIXME: rescan? deassoc & scan? */
1557 static int wl3501_get_wap(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 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1563 memcpy(wrqu
->ap_addr
.sa_data
, this->bssid
, ETH_ALEN
);
1567 static int wl3501_set_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1568 union iwreq_data
*wrqu
, char *extra
)
1571 * FIXME: trigger scanning with a reset, yes, I'm lazy
1573 return wl3501_reset(dev
);
1576 static int wl3501_get_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1577 union iwreq_data
*wrqu
, char *extra
)
1579 struct wl3501_card
*this = netdev_priv(dev
);
1581 char *current_ev
= extra
;
1582 struct iw_event iwe
;
1584 for (i
= 0; i
< this->bss_cnt
; ++i
) {
1585 iwe
.cmd
= SIOCGIWAP
;
1586 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1587 memcpy(iwe
.u
.ap_addr
.sa_data
, this->bss_set
[i
].bssid
, ETH_ALEN
);
1588 current_ev
= iwe_stream_add_event(info
, current_ev
,
1589 extra
+ IW_SCAN_MAX_DATA
,
1590 &iwe
, IW_EV_ADDR_LEN
);
1591 iwe
.cmd
= SIOCGIWESSID
;
1592 iwe
.u
.data
.flags
= 1;
1593 iwe
.u
.data
.length
= this->bss_set
[i
].ssid
.el
.len
;
1594 current_ev
= iwe_stream_add_point(info
, current_ev
,
1595 extra
+ IW_SCAN_MAX_DATA
,
1597 this->bss_set
[i
].ssid
.essid
);
1598 iwe
.cmd
= SIOCGIWMODE
;
1599 iwe
.u
.mode
= this->bss_set
[i
].bss_type
;
1600 current_ev
= iwe_stream_add_event(info
, current_ev
,
1601 extra
+ IW_SCAN_MAX_DATA
,
1602 &iwe
, IW_EV_UINT_LEN
);
1603 iwe
.cmd
= SIOCGIWFREQ
;
1604 iwe
.u
.freq
.m
= this->bss_set
[i
].ds_pset
.chan
;
1606 current_ev
= iwe_stream_add_event(info
, current_ev
,
1607 extra
+ IW_SCAN_MAX_DATA
,
1608 &iwe
, IW_EV_FREQ_LEN
);
1609 iwe
.cmd
= SIOCGIWENCODE
;
1610 if (this->bss_set
[i
].cap_info
& WL3501_MGMT_CAPABILITY_PRIVACY
)
1611 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1613 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1614 iwe
.u
.data
.length
= 0;
1615 current_ev
= iwe_stream_add_point(info
, current_ev
,
1616 extra
+ IW_SCAN_MAX_DATA
,
1619 /* Length of data */
1620 wrqu
->data
.length
= (current_ev
- extra
);
1621 wrqu
->data
.flags
= 0; /* FIXME: set properly these flags */
1625 static int wl3501_set_essid(struct net_device
*dev
,
1626 struct iw_request_info
*info
,
1627 union iwreq_data
*wrqu
, char *extra
)
1629 struct wl3501_card
*this = netdev_priv(dev
);
1631 if (wrqu
->data
.flags
) {
1632 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1634 extra
, wrqu
->data
.length
);
1635 } else { /* We accept any ESSID */
1636 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1637 &this->essid
.el
, "ANY", 3);
1639 return wl3501_reset(dev
);
1642 static int wl3501_get_essid(struct net_device
*dev
,
1643 struct iw_request_info
*info
,
1644 union iwreq_data
*wrqu
, char *extra
)
1646 struct wl3501_card
*this = netdev_priv(dev
);
1647 unsigned long flags
;
1649 spin_lock_irqsave(&this->lock
, flags
);
1650 wrqu
->essid
.flags
= 1;
1651 wrqu
->essid
.length
= this->essid
.el
.len
;
1652 memcpy(extra
, this->essid
.essid
, this->essid
.el
.len
);
1653 spin_unlock_irqrestore(&this->lock
, flags
);
1657 static int wl3501_set_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1658 union iwreq_data
*wrqu
, char *extra
)
1660 struct wl3501_card
*this = netdev_priv(dev
);
1662 if (wrqu
->data
.length
> sizeof(this->nick
))
1664 strlcpy(this->nick
, extra
, wrqu
->data
.length
);
1668 static int wl3501_get_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1669 union iwreq_data
*wrqu
, char *extra
)
1671 struct wl3501_card
*this = netdev_priv(dev
);
1673 strlcpy(extra
, this->nick
, 32);
1674 wrqu
->data
.length
= strlen(extra
);
1678 static int wl3501_get_rate(struct net_device
*dev
, struct iw_request_info
*info
,
1679 union iwreq_data
*wrqu
, char *extra
)
1682 * FIXME: have to see from where to get this info, perhaps this card
1683 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1684 * common with the Planet Access Points. -acme
1686 wrqu
->bitrate
.value
= 2000000;
1687 wrqu
->bitrate
.fixed
= 1;
1691 static int wl3501_get_rts_threshold(struct net_device
*dev
,
1692 struct iw_request_info
*info
,
1693 union iwreq_data
*wrqu
, char *extra
)
1695 u16 threshold
; /* size checked: it is u16 */
1696 struct wl3501_card
*this = netdev_priv(dev
);
1697 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD
,
1698 &threshold
, sizeof(threshold
));
1700 wrqu
->rts
.value
= threshold
;
1701 wrqu
->rts
.disabled
= threshold
>= 2347;
1702 wrqu
->rts
.fixed
= 1;
1707 static int wl3501_get_frag_threshold(struct net_device
*dev
,
1708 struct iw_request_info
*info
,
1709 union iwreq_data
*wrqu
, char *extra
)
1711 u16 threshold
; /* size checked: it is u16 */
1712 struct wl3501_card
*this = netdev_priv(dev
);
1713 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD
,
1714 &threshold
, sizeof(threshold
));
1716 wrqu
->frag
.value
= threshold
;
1717 wrqu
->frag
.disabled
= threshold
>= 2346;
1718 wrqu
->frag
.fixed
= 1;
1723 static int wl3501_get_txpow(struct net_device
*dev
,
1724 struct iw_request_info
*info
,
1725 union iwreq_data
*wrqu
, char *extra
)
1728 struct wl3501_card
*this = netdev_priv(dev
);
1729 int rc
= wl3501_get_mib_value(this,
1730 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL
,
1731 &txpow
, sizeof(txpow
));
1733 wrqu
->txpower
.value
= txpow
;
1734 wrqu
->txpower
.disabled
= 0;
1736 * From the MIB values I think this can be configurable,
1737 * as it lists several tx power levels -acme
1739 wrqu
->txpower
.fixed
= 0;
1740 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
1745 static int wl3501_get_retry(struct net_device
*dev
,
1746 struct iw_request_info
*info
,
1747 union iwreq_data
*wrqu
, char *extra
)
1749 u8 retry
; /* size checked: it is u8 */
1750 struct wl3501_card
*this = netdev_priv(dev
);
1751 int rc
= wl3501_get_mib_value(this,
1752 WL3501_MIB_ATTR_LONG_RETRY_LIMIT
,
1753 &retry
, sizeof(retry
));
1756 if (wrqu
->retry
.flags
& IW_RETRY_LONG
) {
1757 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
1760 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT
,
1761 &retry
, sizeof(retry
));
1764 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_SHORT
;
1766 wrqu
->retry
.value
= retry
;
1767 wrqu
->retry
.disabled
= 0;
1772 static int wl3501_get_encode(struct net_device
*dev
,
1773 struct iw_request_info
*info
,
1774 union iwreq_data
*wrqu
, char *extra
)
1776 u8 implemented
, restricted
, keys
[100], len_keys
, tocopy
;
1777 struct wl3501_card
*this = netdev_priv(dev
);
1778 int rc
= wl3501_get_mib_value(this,
1779 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED
,
1780 &implemented
, sizeof(implemented
));
1784 wrqu
->encoding
.flags
= IW_ENCODE_DISABLED
;
1787 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED
,
1788 &restricted
, sizeof(restricted
));
1791 wrqu
->encoding
.flags
= restricted
? IW_ENCODE_RESTRICTED
:
1793 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN
,
1794 &len_keys
, sizeof(len_keys
));
1797 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS
,
1801 tocopy
= min_t(u8
, len_keys
, wrqu
->encoding
.length
);
1802 tocopy
= min_t(u8
, tocopy
, 100);
1803 wrqu
->encoding
.length
= tocopy
;
1804 memcpy(extra
, keys
, tocopy
);
1809 static int wl3501_get_power(struct net_device
*dev
,
1810 struct iw_request_info
*info
,
1811 union iwreq_data
*wrqu
, char *extra
)
1814 struct wl3501_card
*this = netdev_priv(dev
);
1815 int rc
= wl3501_get_mib_value(this,
1816 WL3501_MIB_ATTR_CURRENT_PWR_STATE
,
1817 &pwr_state
, sizeof(pwr_state
));
1820 wrqu
->power
.disabled
= !pwr_state
;
1821 wrqu
->power
.flags
= IW_POWER_ON
;
1826 static const iw_handler wl3501_handler
[] = {
1827 IW_HANDLER(SIOCGIWNAME
, wl3501_get_name
),
1828 IW_HANDLER(SIOCSIWFREQ
, wl3501_set_freq
),
1829 IW_HANDLER(SIOCGIWFREQ
, wl3501_get_freq
),
1830 IW_HANDLER(SIOCSIWMODE
, wl3501_set_mode
),
1831 IW_HANDLER(SIOCGIWMODE
, wl3501_get_mode
),
1832 IW_HANDLER(SIOCGIWSENS
, wl3501_get_sens
),
1833 IW_HANDLER(SIOCGIWRANGE
, wl3501_get_range
),
1834 IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
1835 IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
1836 IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
1837 IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
1838 IW_HANDLER(SIOCSIWAP
, wl3501_set_wap
),
1839 IW_HANDLER(SIOCGIWAP
, wl3501_get_wap
),
1840 IW_HANDLER(SIOCSIWSCAN
, wl3501_set_scan
),
1841 IW_HANDLER(SIOCGIWSCAN
, wl3501_get_scan
),
1842 IW_HANDLER(SIOCSIWESSID
, wl3501_set_essid
),
1843 IW_HANDLER(SIOCGIWESSID
, wl3501_get_essid
),
1844 IW_HANDLER(SIOCSIWNICKN
, wl3501_set_nick
),
1845 IW_HANDLER(SIOCGIWNICKN
, wl3501_get_nick
),
1846 IW_HANDLER(SIOCGIWRATE
, wl3501_get_rate
),
1847 IW_HANDLER(SIOCGIWRTS
, wl3501_get_rts_threshold
),
1848 IW_HANDLER(SIOCGIWFRAG
, wl3501_get_frag_threshold
),
1849 IW_HANDLER(SIOCGIWTXPOW
, wl3501_get_txpow
),
1850 IW_HANDLER(SIOCGIWRETRY
, wl3501_get_retry
),
1851 IW_HANDLER(SIOCGIWENCODE
, wl3501_get_encode
),
1852 IW_HANDLER(SIOCGIWPOWER
, wl3501_get_power
),
1855 static const struct iw_handler_def wl3501_handler_def
= {
1856 .num_standard
= ARRAY_SIZE(wl3501_handler
),
1857 .standard
= (iw_handler
*)wl3501_handler
,
1858 .get_wireless_stats
= wl3501_get_wireless_stats
,
1861 static const struct net_device_ops wl3501_netdev_ops
= {
1862 .ndo_open
= wl3501_open
,
1863 .ndo_stop
= wl3501_close
,
1864 .ndo_start_xmit
= wl3501_hard_start_xmit
,
1865 .ndo_tx_timeout
= wl3501_tx_timeout
,
1866 .ndo_change_mtu
= eth_change_mtu
,
1867 .ndo_set_mac_address
= eth_mac_addr
,
1868 .ndo_validate_addr
= eth_validate_addr
,
1872 * wl3501_attach - creates an "instance" of the driver
1874 * Creates an "instance" of the driver, allocating local data structures for
1875 * one device. The device is registered with Card Services.
1877 * The dev_link structure is initialized, but we don't actually configure the
1878 * card at this point -- we wait until we receive a card insertion event.
1880 static int wl3501_probe(struct pcmcia_device
*p_dev
)
1882 struct net_device
*dev
;
1883 struct wl3501_card
*this;
1885 /* The io structure describes IO port mapping */
1886 p_dev
->resource
[0]->end
= 16;
1887 p_dev
->resource
[0]->flags
= IO_DATA_PATH_WIDTH_8
;
1889 /* General socket configuration */
1890 p_dev
->config_flags
= CONF_ENABLE_IRQ
;
1891 p_dev
->config_index
= 1;
1893 dev
= alloc_etherdev(sizeof(struct wl3501_card
));
1898 dev
->netdev_ops
= &wl3501_netdev_ops
;
1899 dev
->watchdog_timeo
= 5 * HZ
;
1901 this = netdev_priv(dev
);
1902 this->wireless_data
.spy_data
= &this->spy_data
;
1903 this->p_dev
= p_dev
;
1904 dev
->wireless_data
= &this->wireless_data
;
1905 dev
->wireless_handlers
= &wl3501_handler_def
;
1906 SET_ETHTOOL_OPS(dev
, &ops
);
1907 netif_stop_queue(dev
);
1910 return wl3501_config(p_dev
);
1916 * wl3501_config - configure the PCMCIA socket and make eth device available
1919 * wl3501_config() is scheduled to run after a CARD_INSERTION event is
1920 * received, to configure the PCMCIA socket, and to make the ethernet device
1921 * available to the system.
1923 static int wl3501_config(struct pcmcia_device
*link
)
1925 struct net_device
*dev
= link
->priv
;
1927 struct wl3501_card
*this;
1929 /* Try allocating IO ports. This tries a few fixed addresses. If you
1930 * want, you can also read the card's config table to pick addresses --
1931 * see the serial driver for an example. */
1934 for (j
= 0x280; j
< 0x400; j
+= 0x20) {
1935 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1936 * 0x200-0x2ff, and so on, because this seems safer */
1937 link
->resource
[0]->start
= j
;
1938 link
->resource
[1]->start
= link
->resource
[0]->start
+ 0x10;
1939 i
= pcmcia_request_io(link
);
1946 /* Now allocate an interrupt line. Note that this does not actually
1947 * assign a handler to the interrupt. */
1949 ret
= pcmcia_request_irq(link
, wl3501_interrupt
);
1953 /* This actually configures the PCMCIA socket -- setting up the I/O
1954 * windows and the interrupt mapping. */
1956 ret
= pcmcia_enable_device(link
);
1960 dev
->irq
= link
->irq
;
1961 dev
->base_addr
= link
->resource
[0]->start
;
1962 SET_NETDEV_DEV(dev
, &link
->dev
);
1963 if (register_netdev(dev
)) {
1964 printk(KERN_NOTICE
"wl3501_cs: register_netdev() failed\n");
1968 this = netdev_priv(dev
);
1970 this->base_addr
= dev
->base_addr
;
1972 if (!wl3501_get_flash_mac_addr(this)) {
1973 printk(KERN_WARNING
"%s: Cant read MAC addr in flash ROM?\n",
1975 unregister_netdev(dev
);
1979 for (i
= 0; i
< 6; i
++)
1980 dev
->dev_addr
[i
] = ((char *)&this->mac_addr
)[i
];
1982 /* print probe information */
1983 printk(KERN_INFO
"%s: wl3501 @ 0x%3.3x, IRQ %d, "
1984 "MAC addr in flash ROM:%pM\n",
1985 dev
->name
, this->base_addr
, (int)dev
->irq
,
1988 * Initialize card parameters - added by jss
1990 this->net_type
= IW_MODE_INFRA
;
1992 this->join_sta_bss
= 0;
1993 this->adhoc_times
= 0;
1994 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
, &this->essid
.el
,
1996 this->card_name
[0] = '\0';
1997 this->firmware_date
[0] = '\0';
1999 this->chan
= iw_default_channel(this->reg_domain
);
2000 strlcpy(this->nick
, "Planet WL3501", sizeof(this->nick
));
2001 spin_lock_init(&this->lock
);
2002 init_waitqueue_head(&this->wait
);
2003 netif_start_queue(dev
);
2007 wl3501_release(link
);
2012 * wl3501_release - unregister the net, release PCMCIA configuration
2015 * After a card is removed, wl3501_release() will unregister the net device,
2016 * and release the PCMCIA configuration. If the device is still open, this
2017 * will be postponed until it is closed.
2019 static void wl3501_release(struct pcmcia_device
*link
)
2021 pcmcia_disable_device(link
);
2024 static int wl3501_suspend(struct pcmcia_device
*link
)
2026 struct net_device
*dev
= link
->priv
;
2028 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_SUSPEND
);
2030 netif_device_detach(dev
);
2035 static int wl3501_resume(struct pcmcia_device
*link
)
2037 struct net_device
*dev
= link
->priv
;
2039 wl3501_pwr_mgmt(netdev_priv(dev
), WL3501_RESUME
);
2042 netif_device_attach(dev
);
2049 static struct pcmcia_device_id wl3501_ids
[] = {
2050 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2053 MODULE_DEVICE_TABLE(pcmcia
, wl3501_ids
);
2055 static struct pcmcia_driver wl3501_driver
= {
2056 .owner
= THIS_MODULE
,
2057 .name
= "wl3501_cs",
2058 .probe
= wl3501_probe
,
2059 .remove
= wl3501_detach
,
2060 .id_table
= wl3501_ids
,
2061 .suspend
= wl3501_suspend
,
2062 .resume
= wl3501_resume
,
2065 static int __init
wl3501_init_module(void)
2067 return pcmcia_register_driver(&wl3501_driver
);
2070 static void __exit
wl3501_exit_module(void)
2072 pcmcia_unregister_driver(&wl3501_driver
);
2075 module_init(wl3501_init_module
);
2076 module_exit(wl3501_exit_module
);
2078 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2079 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2080 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2081 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2082 MODULE_LICENSE("GPL");