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
80 static int wl3501_config(struct pcmcia_device *link);
81 static void wl3501_release(struct pcmcia_device *link);
86 } iw_channel_table[] = {
88 .reg_domain = IW_REG_DOMAIN_FCC,
94 .reg_domain = IW_REG_DOMAIN_DOC,
100 .reg_domain = IW_REG_DOMAIN_ETSI,
106 .reg_domain = IW_REG_DOMAIN_SPAIN,
112 .reg_domain = IW_REG_DOMAIN_FRANCE,
118 .reg_domain = IW_REG_DOMAIN_MKK,
124 .reg_domain = IW_REG_DOMAIN_MKK1,
130 .reg_domain = IW_REG_DOMAIN_ISRAEL,
138 * iw_valid_channel - validate channel in regulatory domain
139 * @reg_comain - regulatory domain
140 * @channel - channel to validate
142 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
144 static int iw_valid_channel(int reg_domain, int channel)
148 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
149 if (reg_domain == iw_channel_table[i].reg_domain) {
150 rc = channel >= iw_channel_table[i].min &&
151 channel <= iw_channel_table[i].max;
158 * iw_default_channel - get default channel for a regulatory domain
159 * @reg_comain - regulatory domain
161 * Returns the default channel for a regulatory domain
163 static int iw_default_channel(int reg_domain)
167 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
168 if (reg_domain == iw_channel_table[i].reg_domain) {
169 rc = iw_channel_table[i].deflt;
175 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
176 struct iw_mgmt_info_element *el,
177 void *value, int len)
181 memcpy(el->data, value, len);
184 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
185 struct iw_mgmt_info_element *from)
187 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
190 static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
192 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
196 * Get Ethernet MAC addresss.
198 * WARNING: We switch to FPAGE0 and switc back again.
199 * Making sure there is no other WL function beening called by ISR.
201 static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
203 int base_addr = this->base_addr;
206 wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
207 wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL); /* LMAL */
208 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH); /* LMAH */
210 /* wait for reading EEPROM */
212 this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
214 this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
216 this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
218 this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
220 this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
222 this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
224 this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
226 wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
227 wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
228 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
230 this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
232 this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
233 /* switch to SRAM Page 0 (for safety) */
234 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
236 /* The MAC addr should be 00:60:... */
237 return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
241 * wl3501_set_to_wla - Move 'size' bytes from PC to card
242 * @dest: Card addressing space
243 * @src: PC addressing space
244 * @size: Bytes to move
246 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
248 static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
251 /* switch to SRAM Page 0 */
252 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
254 /* set LMAL and LMAH */
255 wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
256 wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
258 /* rep out to Port A */
259 wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
263 * wl3501_get_from_wla - Move 'size' bytes from card to PC
264 * @src: Card addressing space
265 * @dest: PC addressing space
266 * @size: Bytes to move
268 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
270 static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
273 /* switch to SRAM Page 0 */
274 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
276 /* set LMAL and LMAH */
277 wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
278 wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
280 /* rep get from Port A */
281 insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
285 * Get/Allocate a free Tx Data Buffer
287 * *--------------*-----------------*----------------------------------*
288 * | PLCP | MAC Header | DST SRC Data ... |
289 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
290 * *--------------*-----------------*----------------------------------*
291 * \ \- IEEE 802.11 -/ \-------------- len --------------/
292 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
294 * Return = Postion in Card
296 static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
298 u16 next, blk_cnt = 0, zero = 0;
299 u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
302 if (full_len > this->tx_buffer_cnt * 254)
304 ret = this->tx_buffer_head;
310 wl3501_get_from_wla(this, this->tx_buffer_head, &next,
313 wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
315 this->tx_buffer_head = next;
317 /* if buffer is not enough */
318 if (!next && full_len) {
319 this->tx_buffer_head = ret;
324 this->tx_buffer_cnt -= blk_cnt;
330 * Free an allocated Tx Buffer. ptr must be correct position.
332 static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
334 /* check if all space is not free */
335 if (!this->tx_buffer_head)
336 this->tx_buffer_head = ptr;
338 wl3501_set_to_wla(this, this->tx_buffer_tail,
343 this->tx_buffer_cnt++;
344 wl3501_get_from_wla(this, ptr, &next, sizeof(next));
345 this->tx_buffer_tail = ptr;
350 static int wl3501_esbq_req_test(struct wl3501_card *this)
354 wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
358 static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
362 wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
363 wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
364 this->esbq_req_head += 4;
365 if (this->esbq_req_head >= this->esbq_req_end)
366 this->esbq_req_head = this->esbq_req_start;
369 static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
373 if (wl3501_esbq_req_test(this)) {
374 u16 ptr = wl3501_get_tx_buffer(this, sig_size);
376 wl3501_set_to_wla(this, ptr, sig, sig_size);
377 wl3501_esbq_req(this, &ptr);
384 static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
387 struct wl3501_get_req sig = {
388 .sig_id = WL3501_SIG_GET_REQ,
394 spin_lock_irqsave(&this->lock, flags);
395 if (wl3501_esbq_req_test(this)) {
396 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
398 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
399 wl3501_esbq_req(this, &ptr);
400 this->sig_get_confirm.mib_status = 255;
401 spin_unlock_irqrestore(&this->lock, flags);
402 rc = wait_event_interruptible(this->wait,
403 this->sig_get_confirm.mib_status != 255);
405 memcpy(bf, this->sig_get_confirm.mib_value,
410 spin_unlock_irqrestore(&this->lock, flags);
415 static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
417 struct wl3501_pwr_mgmt_req sig = {
418 .sig_id = WL3501_SIG_PWR_MGMT_REQ,
426 spin_lock_irqsave(&this->lock, flags);
427 if (wl3501_esbq_req_test(this)) {
428 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
430 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
431 wl3501_esbq_req(this, &ptr);
432 this->sig_pwr_mgmt_confirm.status = 255;
433 spin_unlock_irqrestore(&this->lock, flags);
434 rc = wait_event_interruptible(this->wait,
435 this->sig_pwr_mgmt_confirm.status != 255);
436 printk(KERN_INFO "%s: %s status=%d\n", __func__,
437 suspend ? "suspend" : "resume",
438 this->sig_pwr_mgmt_confirm.status);
442 spin_unlock_irqrestore(&this->lock, flags);
448 * wl3501_send_pkt - Send a packet.
453 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
454 * data[6] - data[11] is Src MAC Addr)
457 static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
459 u16 bf, sig_bf, next, tmplen, pktlen;
460 struct wl3501_md_req sig = {
461 .sig_id = WL3501_SIG_MD_REQ,
463 u8 *pdata = (char *)data;
466 if (wl3501_esbq_req_test(this)) {
467 sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
469 if (!sig_bf) /* No free buffer available */
471 bf = wl3501_get_tx_buffer(this, len + 26 + 24);
473 /* No free buffer available */
474 wl3501_free_tx_buffer(this, sig_bf);
478 memcpy(&sig.daddr[0], pdata, 12);
482 if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
483 u8 addr4[ETH_ALEN] = {
484 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
487 wl3501_set_to_wla(this, bf + 2 +
488 offsetof(struct wl3501_tx_hdr, addr4),
489 addr4, sizeof(addr4));
490 sig.size = pktlen + 24 + 4 + 6;
491 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
492 tmplen = 254 - sizeof(struct wl3501_tx_hdr);
498 wl3501_set_to_wla(this,
499 bf + 2 + sizeof(struct wl3501_tx_hdr),
502 wl3501_get_from_wla(this, bf, &next, sizeof(next));
505 sig.size = pktlen + 24 + 4 - 2;
508 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
509 tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
515 wl3501_set_to_wla(this, bf + 2 +
516 offsetof(struct wl3501_tx_hdr, addr4),
519 wl3501_get_from_wla(this, bf, &next, sizeof(next));
530 wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
532 wl3501_get_from_wla(this, bf, &next, sizeof(next));
535 wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
536 wl3501_esbq_req(this, &sig_bf);
542 static int wl3501_mgmt_resync(struct wl3501_card *this)
544 struct wl3501_resync_req sig = {
545 .sig_id = WL3501_SIG_RESYNC_REQ,
548 return wl3501_esbq_exec(this, &sig, sizeof(sig));
551 static inline int wl3501_fw_bss_type(struct wl3501_card *this)
553 return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
554 WL3501_NET_TYPE_ADHOC;
557 static inline int wl3501_fw_cap_info(struct wl3501_card *this)
559 return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
560 WL3501_MGMT_CAPABILITY_IBSS;
563 static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
565 struct wl3501_scan_req sig = {
566 .sig_id = WL3501_SIG_SCAN_REQ,
567 .scan_type = WL3501_SCAN_TYPE_ACTIVE,
569 .min_chan_time = chan_time,
570 .max_chan_time = chan_time,
571 .bss_type = wl3501_fw_bss_type(this),
574 this->bss_cnt = this->join_sta_bss = 0;
575 return wl3501_esbq_exec(this, &sig, sizeof(sig));
578 static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
580 struct wl3501_join_req sig = {
581 .sig_id = WL3501_SIG_JOIN_REQ,
585 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
592 memcpy(&sig.beacon_period, &this->bss_set[stas].beacon_period, 72);
593 return wl3501_esbq_exec(this, &sig, sizeof(sig));
596 static int wl3501_mgmt_start(struct wl3501_card *this)
598 struct wl3501_start_req sig = {
599 .sig_id = WL3501_SIG_START_REQ,
600 .beacon_period = 400,
604 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
611 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
614 .data_rate_labels = {
615 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
616 IW_MGMT_RATE_LABEL_1MBIT,
617 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
618 IW_MGMT_RATE_LABEL_2MBIT,
621 .operational_rset = {
623 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
626 .data_rate_labels = {
627 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
628 IW_MGMT_RATE_LABEL_1MBIT,
629 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
630 IW_MGMT_RATE_LABEL_2MBIT,
635 .id = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
640 .bss_type = wl3501_fw_bss_type(this),
641 .cap_info = wl3501_fw_cap_info(this),
644 iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
645 iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
646 return wl3501_esbq_exec(this, &sig, sizeof(sig));
649 static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
653 struct wl3501_scan_confirm sig;
656 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
657 if (sig.status == WL3501_STATUS_SUCCESS) {
659 if ((this->net_type == IW_MODE_INFRA &&
660 (sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
661 (this->net_type == IW_MODE_ADHOC &&
662 (sig.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
663 this->net_type == IW_MODE_AUTO) {
664 if (!this->essid.el.len)
666 else if (this->essid.el.len == 3 &&
667 !memcmp(this->essid.essid, "ANY", 3))
669 else if (this->essid.el.len != sig.ssid.el.len)
671 else if (memcmp(this->essid.essid, sig.ssid.essid,
677 for (i = 0; i < this->bss_cnt; i++) {
678 if (!memcmp(this->bss_set[i].bssid,
679 sig.bssid, ETH_ALEN)) {
685 if (matchflag && (i < 20)) {
686 memcpy(&this->bss_set[i].beacon_period,
687 &sig.beacon_period, 73);
689 this->rssi = sig.rssi;
692 } else if (sig.status == WL3501_STATUS_TIMEOUT) {
694 this->join_sta_bss = 0;
695 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
696 if (!wl3501_mgmt_join(this, i))
698 this->join_sta_bss = i;
699 if (this->join_sta_bss == this->bss_cnt) {
700 if (this->net_type == IW_MODE_INFRA)
701 wl3501_mgmt_scan(this, 100);
704 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
705 wl3501_mgmt_start(this);
707 wl3501_mgmt_scan(this, 100);
714 * wl3501_block_interrupt - Mask interrupt from SUTRO
717 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
718 * Return: 1 if interrupt is originally enabled
720 static int wl3501_block_interrupt(struct wl3501_card *this)
722 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
723 u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
724 WL3501_GCR_ENECINT));
726 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
727 return old & WL3501_GCR_ENECINT;
731 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
734 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
735 * Return: 1 if interrupt is originally enabled
737 static int wl3501_unblock_interrupt(struct wl3501_card *this)
739 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
740 u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
743 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
744 return old & WL3501_GCR_ENECINT;
748 * wl3501_receive - Receive data from Receive Queue.
750 * Receive data from Receive Queue.
753 * @bf: address of host
754 * @size: size of buffer.
756 static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
758 u16 next_addr, next_addr1;
762 wl3501_get_from_wla(this, this->start_seg + 2,
763 &next_addr, sizeof(next_addr));
764 if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
765 wl3501_get_from_wla(this,
767 sizeof(struct wl3501_rx_hdr), data,
769 sizeof(struct wl3501_rx_hdr));
770 size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
771 data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
773 wl3501_get_from_wla(this,
775 sizeof(struct wl3501_rx_hdr),
780 if (size > WL3501_BLKSZ - 5) {
781 wl3501_get_from_wla(this, next_addr + 5, data,
783 size -= WL3501_BLKSZ - 5;
784 data += WL3501_BLKSZ - 5;
785 wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
787 next_addr = next_addr1;
789 wl3501_get_from_wla(this, next_addr + 5, data, size);
796 static void wl3501_esbq_req_free(struct wl3501_card *this)
801 if (this->esbq_req_head == this->esbq_req_tail)
803 wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
806 wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
807 wl3501_free_tx_buffer(this, addr);
808 this->esbq_req_tail += 4;
809 if (this->esbq_req_tail >= this->esbq_req_end)
810 this->esbq_req_tail = this->esbq_req_start;
815 static int wl3501_esbq_confirm(struct wl3501_card *this)
819 wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
823 static void wl3501_online(struct net_device *dev)
825 struct wl3501_card *this = netdev_priv(dev);
827 printk(KERN_INFO "%s: Wireless LAN online. BSSID: %pM\n",
828 dev->name, this->bssid);
829 netif_wake_queue(dev);
832 static void wl3501_esbq_confirm_done(struct wl3501_card *this)
836 wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
837 this->esbq_confirm += 4;
838 if (this->esbq_confirm >= this->esbq_confirm_end)
839 this->esbq_confirm = this->esbq_confirm_start;
842 static int wl3501_mgmt_auth(struct wl3501_card *this)
844 struct wl3501_auth_req sig = {
845 .sig_id = WL3501_SIG_AUTH_REQ,
846 .type = WL3501_SYS_TYPE_OPEN,
851 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
852 return wl3501_esbq_exec(this, &sig, sizeof(sig));
855 static int wl3501_mgmt_association(struct wl3501_card *this)
857 struct wl3501_assoc_req sig = {
858 .sig_id = WL3501_SIG_ASSOC_REQ,
860 .listen_interval = 5,
861 .cap_info = this->cap_info,
865 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
866 return wl3501_esbq_exec(this, &sig, sizeof(sig));
869 static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
871 struct wl3501_card *this = netdev_priv(dev);
872 struct wl3501_join_confirm sig;
875 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
876 if (sig.status == WL3501_STATUS_SUCCESS) {
877 if (this->net_type == IW_MODE_INFRA) {
878 if (this->join_sta_bss < this->bss_cnt) {
879 const int i = this->join_sta_bss;
881 this->bss_set[i].bssid, ETH_ALEN);
882 this->chan = this->bss_set[i].ds_pset.chan;
883 iw_copy_mgmt_info_element(&this->keep_essid.el,
884 &this->bss_set[i].ssid.el);
885 wl3501_mgmt_auth(this);
888 const int i = this->join_sta_bss;
890 memcpy(&this->bssid, &this->bss_set[i].bssid, ETH_ALEN);
891 this->chan = this->bss_set[i].ds_pset.chan;
892 iw_copy_mgmt_info_element(&this->keep_essid.el,
893 &this->bss_set[i].ssid.el);
898 this->join_sta_bss++;
899 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
900 if (!wl3501_mgmt_join(this, i))
902 this->join_sta_bss = i;
903 if (this->join_sta_bss == this->bss_cnt) {
904 if (this->net_type == IW_MODE_INFRA)
905 wl3501_mgmt_scan(this, 100);
908 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
909 wl3501_mgmt_start(this);
911 wl3501_mgmt_scan(this, 100);
917 static inline void wl3501_alarm_interrupt(struct net_device *dev,
918 struct wl3501_card *this)
920 if (this->net_type == IW_MODE_INFRA) {
921 printk(KERN_INFO "Wireless LAN offline\n");
922 netif_stop_queue(dev);
923 wl3501_mgmt_resync(this);
927 static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
928 struct wl3501_card *this,
931 struct wl3501_md_confirm sig;
934 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
935 wl3501_free_tx_buffer(this, sig.data);
936 if (netif_queue_stopped(dev))
937 netif_wake_queue(dev);
940 static inline void wl3501_md_ind_interrupt(struct net_device *dev,
941 struct wl3501_card *this, u16 addr)
943 struct wl3501_md_ind sig;
945 u8 rssi, addr4[ETH_ALEN];
948 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
949 this->start_seg = sig.data;
950 wl3501_get_from_wla(this,
951 sig.data + offsetof(struct wl3501_rx_hdr, rssi),
952 &rssi, sizeof(rssi));
953 this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
955 wl3501_get_from_wla(this,
957 offsetof(struct wl3501_rx_hdr, addr4),
958 &addr4, sizeof(addr4));
959 if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
960 addr4[2] == 0x03 && addr4[4] == 0x00)) {
961 printk(KERN_INFO "Insupported packet type!\n");
964 pkt_len = sig.size + 12 - 24 - 4 - 6;
966 skb = dev_alloc_skb(pkt_len + 5);
969 printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
971 dev->stats.rx_dropped++;
974 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
975 skb_copy_to_linear_data(skb, (unsigned char *)&sig.daddr, 12);
976 wl3501_receive(this, skb->data, pkt_len);
977 skb_put(skb, pkt_len);
978 skb->protocol = eth_type_trans(skb, dev);
979 dev->stats.rx_packets++;
980 dev->stats.rx_bytes += skb->len;
985 static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
986 u16 addr, void *sig, int size)
989 wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
990 sizeof(this->sig_get_confirm));
991 wake_up(&this->wait);
994 static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
995 struct wl3501_card *this,
998 struct wl3501_start_confirm sig;
1001 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1002 if (sig.status == WL3501_STATUS_SUCCESS)
1003 netif_wake_queue(dev);
1006 static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
1009 struct wl3501_card *this = netdev_priv(dev);
1010 struct wl3501_assoc_confirm sig;
1013 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1015 if (sig.status == WL3501_STATUS_SUCCESS)
1019 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
1022 struct wl3501_auth_confirm sig;
1025 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1027 if (sig.status == WL3501_STATUS_SUCCESS)
1028 wl3501_mgmt_association(this);
1030 wl3501_mgmt_resync(this);
1033 static inline void wl3501_rx_interrupt(struct net_device *dev)
1038 struct wl3501_card *this = netdev_priv(dev);
1043 if (!wl3501_esbq_confirm(this))
1045 wl3501_get_from_wla(this, this->esbq_confirm, &addr, sizeof(addr));
1046 wl3501_get_from_wla(this, addr + 2, &sig_id, sizeof(sig_id));
1049 case WL3501_SIG_DEAUTH_IND:
1050 case WL3501_SIG_DISASSOC_IND:
1051 case WL3501_SIG_ALARM:
1052 wl3501_alarm_interrupt(dev, this);
1054 case WL3501_SIG_MD_CONFIRM:
1055 wl3501_md_confirm_interrupt(dev, this, addr);
1057 case WL3501_SIG_MD_IND:
1058 wl3501_md_ind_interrupt(dev, this, addr);
1060 case WL3501_SIG_GET_CONFIRM:
1061 wl3501_get_confirm_interrupt(this, addr,
1062 &this->sig_get_confirm,
1063 sizeof(this->sig_get_confirm));
1065 case WL3501_SIG_PWR_MGMT_CONFIRM:
1066 wl3501_get_confirm_interrupt(this, addr,
1067 &this->sig_pwr_mgmt_confirm,
1068 sizeof(this->sig_pwr_mgmt_confirm));
1070 case WL3501_SIG_START_CONFIRM:
1071 wl3501_start_confirm_interrupt(dev, this, addr);
1073 case WL3501_SIG_SCAN_CONFIRM:
1074 wl3501_mgmt_scan_confirm(this, addr);
1076 case WL3501_SIG_JOIN_CONFIRM:
1077 wl3501_mgmt_join_confirm(dev, addr);
1079 case WL3501_SIG_ASSOC_CONFIRM:
1080 wl3501_assoc_confirm_interrupt(dev, addr);
1082 case WL3501_SIG_AUTH_CONFIRM:
1083 wl3501_auth_confirm_interrupt(this, addr);
1085 case WL3501_SIG_RESYNC_CONFIRM:
1086 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1089 wl3501_esbq_confirm_done(this);
1091 /* free request if necessary */
1093 wl3501_esbq_req_free(this);
1098 static inline void wl3501_ack_interrupt(struct wl3501_card *this)
1100 wl3501_outb(WL3501_GCR_ECINT, this->base_addr + WL3501_NIC_GCR);
1104 * wl3501_interrupt - Hardware interrupt from card.
1105 * @irq - Interrupt number
1106 * @dev_id - net_device
1108 * We must acknowledge the interrupt as soon as possible, and block the
1109 * interrupt from the same card immediately to prevent re-entry.
1111 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1112 * On the other hand, to prevent SUTRO from malfunctioning, we must
1113 * unlock the SUTRO as soon as possible.
1115 static irqreturn_t wl3501_interrupt(int irq, void *dev_id)
1117 struct net_device *dev = dev_id;
1118 struct wl3501_card *this;
1120 this = netdev_priv(dev);
1121 spin_lock(&this->lock);
1122 wl3501_ack_interrupt(this);
1123 wl3501_block_interrupt(this);
1124 wl3501_rx_interrupt(dev);
1125 wl3501_unblock_interrupt(this);
1126 spin_unlock(&this->lock);
1131 static int wl3501_reset_board(struct wl3501_card *this)
1137 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1138 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1139 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1141 /* Reset SRAM 0x480 to zero */
1142 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1145 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1147 WL3501_NOPLOOP(1024 * 50);
1149 wl3501_unblock_interrupt(this); /* acme: was commented */
1151 /* Polling Self_Test_Status */
1152 for (i = 0; i < 10000; i++) {
1153 wl3501_get_from_wla(this, 0x480, &tmp, sizeof(tmp));
1156 /* firmware complete all test successfully */
1158 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1163 printk(KERN_WARNING "%s: failed to reset the board!\n", __func__);
1169 static int wl3501_init_firmware(struct wl3501_card *this)
1172 int rc = wl3501_reset_board(this);
1176 this->card_name[0] = '\0';
1177 wl3501_get_from_wla(this, 0x1a00,
1178 this->card_name, sizeof(this->card_name));
1179 this->card_name[sizeof(this->card_name) - 1] = '\0';
1180 this->firmware_date[0] = '\0';
1181 wl3501_get_from_wla(this, 0x1a40,
1182 this->firmware_date, sizeof(this->firmware_date));
1183 this->firmware_date[sizeof(this->firmware_date) - 1] = '\0';
1184 /* Switch to SRAM Page 0 */
1185 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
1186 /* Read parameter from card */
1187 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start, 2);
1188 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end, 2);
1189 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start, 2);
1190 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end, 2);
1191 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head, 2);
1192 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size, 2);
1193 this->esbq_req_tail = this->esbq_req_head = this->esbq_req_start;
1194 this->esbq_req_end += this->esbq_req_start;
1195 this->esbq_confirm = this->esbq_confirm_start;
1196 this->esbq_confirm_end += this->esbq_confirm_start;
1197 /* Initial Tx Buffer */
1198 this->tx_buffer_cnt = 1;
1199 ptr = this->tx_buffer_head;
1200 next = ptr + WL3501_BLKSZ;
1201 while ((next - this->tx_buffer_head) < this->tx_buffer_size) {
1202 this->tx_buffer_cnt++;
1203 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1205 next = ptr + WL3501_BLKSZ;
1209 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1210 this->tx_buffer_tail = ptr;
1214 printk(KERN_WARNING "%s: failed!\n", __func__);
1218 static int wl3501_close(struct net_device *dev)
1220 struct wl3501_card *this = netdev_priv(dev);
1222 unsigned long flags;
1223 struct pcmcia_device *link;
1226 spin_lock_irqsave(&this->lock, flags);
1229 /* Stop wl3501_hard_start_xmit() from now on */
1230 netif_stop_queue(dev);
1231 wl3501_ack_interrupt(this);
1233 /* Mask interrupts from the SUTRO */
1234 wl3501_block_interrupt(this);
1237 printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
1238 spin_unlock_irqrestore(&this->lock, flags);
1243 * wl3501_reset - Reset the SUTRO.
1244 * @dev - network device
1246 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1247 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1248 * is running. It seems to be dangerous.
1250 static int wl3501_reset(struct net_device *dev)
1252 struct wl3501_card *this = netdev_priv(dev);
1255 wl3501_block_interrupt(this);
1257 if (wl3501_init_firmware(this)) {
1258 printk(KERN_WARNING "%s: Can't initialize Firmware!\n",
1260 /* Free IRQ, and mark IRQ as unused */
1261 free_irq(dev->irq, dev);
1266 * Queue has to be started only when the Card is Started
1268 netif_stop_queue(dev);
1269 this->adhoc_times = 0;
1270 wl3501_ack_interrupt(this);
1271 wl3501_unblock_interrupt(this);
1272 wl3501_mgmt_scan(this, 100);
1273 pr_debug("%s: device reset", dev->name);
1279 static void wl3501_tx_timeout(struct net_device *dev)
1281 struct wl3501_card *this = netdev_priv(dev);
1282 struct net_device_stats *stats = &dev->stats;
1283 unsigned long flags;
1287 spin_lock_irqsave(&this->lock, flags);
1288 rc = wl3501_reset(dev);
1289 spin_unlock_irqrestore(&this->lock, flags);
1291 printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
1294 dev->trans_start = jiffies; /* prevent tx timeout */
1295 netif_wake_queue(dev);
1301 * 1 - Could not transmit (dev_queue_xmit will queue it)
1302 * and try to sent it later
1304 static netdev_tx_t wl3501_hard_start_xmit(struct sk_buff *skb,
1305 struct net_device *dev)
1308 struct wl3501_card *this = netdev_priv(dev);
1309 unsigned long flags;
1311 spin_lock_irqsave(&this->lock, flags);
1312 enabled = wl3501_block_interrupt(this);
1313 rc = wl3501_send_pkt(this, skb->data, skb->len);
1315 wl3501_unblock_interrupt(this);
1317 ++dev->stats.tx_dropped;
1318 netif_stop_queue(dev);
1320 ++dev->stats.tx_packets;
1321 dev->stats.tx_bytes += skb->len;
1324 if (this->tx_buffer_cnt < 2)
1325 netif_stop_queue(dev);
1327 spin_unlock_irqrestore(&this->lock, flags);
1328 return NETDEV_TX_OK;
1331 static int wl3501_open(struct net_device *dev)
1334 struct wl3501_card *this = netdev_priv(dev);
1335 unsigned long flags;
1336 struct pcmcia_device *link;
1339 spin_lock_irqsave(&this->lock, flags);
1340 if (!pcmcia_dev_present(link))
1342 netif_device_attach(dev);
1345 /* Initial WL3501 firmware */
1346 pr_debug("%s: Initialize WL3501 firmware...", dev->name);
1347 if (wl3501_init_firmware(this))
1349 /* Initial device variables */
1350 this->adhoc_times = 0;
1351 /* Acknowledge Interrupt, for cleaning last state */
1352 wl3501_ack_interrupt(this);
1354 /* Enable interrupt from card after all */
1355 wl3501_unblock_interrupt(this);
1356 wl3501_mgmt_scan(this, 100);
1358 pr_debug("%s: WL3501 opened", dev->name);
1359 printk(KERN_INFO "%s: Card Name: %s\n"
1360 "%s: Firmware Date: %s\n",
1361 dev->name, this->card_name,
1362 dev->name, this->firmware_date);
1364 spin_unlock_irqrestore(&this->lock, flags);
1367 printk(KERN_WARNING "%s: Can't initialize firmware!\n", dev->name);
1371 static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
1373 struct wl3501_card *this = netdev_priv(dev);
1374 struct iw_statistics *wstats = &this->wstats;
1375 u32 value; /* size checked: it is u32 */
1377 memset(wstats, 0, sizeof(*wstats));
1378 wstats->status = netif_running(dev);
1379 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT,
1380 &value, sizeof(value)))
1381 wstats->discard.code += value;
1382 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT,
1383 &value, sizeof(value)))
1384 wstats->discard.code += value;
1385 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT,
1386 &value, sizeof(value)))
1387 wstats->discard.code += value;
1388 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT,
1389 &value, sizeof(value)))
1390 wstats->discard.retries = value;
1391 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT,
1392 &value, sizeof(value)))
1393 wstats->discard.misc += value;
1394 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT,
1395 &value, sizeof(value)))
1396 wstats->discard.misc += value;
1397 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT,
1398 &value, sizeof(value)))
1399 wstats->discard.misc += value;
1400 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT,
1401 &value, sizeof(value)))
1402 wstats->discard.misc += value;
1406 static void wl3501_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1408 strlcpy(info->driver, "wl3501_cs", sizeof(info->driver));
1411 static const struct ethtool_ops ops = {
1412 .get_drvinfo = wl3501_get_drvinfo
1416 * wl3501_detach - deletes a driver "instance"
1419 * This deletes a driver "instance". The device is de-registered with Card
1420 * Services. If it has been released, all local data structures are freed.
1421 * Otherwise, the structures will be freed when the device is released.
1423 static void wl3501_detach(struct pcmcia_device *link)
1425 struct net_device *dev = link->priv;
1427 /* If the device is currently configured and active, we won't actually
1428 * delete it yet. Instead, it is marked so that when the release()
1429 * function is called, that will trigger a proper detach(). */
1431 while (link->open > 0)
1434 netif_device_detach(dev);
1435 wl3501_release(link);
1437 unregister_netdev(dev);
1440 free_netdev(link->priv);
1443 static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
1444 union iwreq_data *wrqu, char *extra)
1446 strlcpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
1450 static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
1451 union iwreq_data *wrqu, char *extra)
1453 struct wl3501_card *this = netdev_priv(dev);
1454 int channel = wrqu->freq.m;
1457 if (iw_valid_channel(this->reg_domain, channel)) {
1458 this->chan = channel;
1459 rc = wl3501_reset(dev);
1464 static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
1465 union iwreq_data *wrqu, char *extra)
1467 struct wl3501_card *this = netdev_priv(dev);
1469 wrqu->freq.m = ieee80211_dsss_chan_to_freq(this->chan) * 100000;
1474 static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
1475 union iwreq_data *wrqu, char *extra)
1479 if (wrqu->mode == IW_MODE_INFRA ||
1480 wrqu->mode == IW_MODE_ADHOC ||
1481 wrqu->mode == IW_MODE_AUTO) {
1482 struct wl3501_card *this = netdev_priv(dev);
1484 this->net_type = wrqu->mode;
1485 rc = wl3501_reset(dev);
1490 static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
1491 union iwreq_data *wrqu, char *extra)
1493 struct wl3501_card *this = netdev_priv(dev);
1495 wrqu->mode = this->net_type;
1499 static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
1500 union iwreq_data *wrqu, char *extra)
1502 struct wl3501_card *this = netdev_priv(dev);
1504 wrqu->sens.value = this->rssi;
1505 wrqu->sens.disabled = !wrqu->sens.value;
1506 wrqu->sens.fixed = 1;
1510 static int wl3501_get_range(struct net_device *dev,
1511 struct iw_request_info *info,
1512 union iwreq_data *wrqu, char *extra)
1514 struct iw_range *range = (struct iw_range *)extra;
1516 /* Set the length (very important for backward compatibility) */
1517 wrqu->data.length = sizeof(*range);
1519 /* Set all the info we don't care or don't know about to zero */
1520 memset(range, 0, sizeof(*range));
1522 /* Set the Wireless Extension versions */
1523 range->we_version_compiled = WIRELESS_EXT;
1524 range->we_version_source = 1;
1525 range->throughput = 2 * 1000 * 1000; /* ~2 Mb/s */
1526 /* FIXME: study the code to fill in more fields... */
1530 static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
1531 union iwreq_data *wrqu, char *extra)
1533 struct wl3501_card *this = netdev_priv(dev);
1534 static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
1537 /* FIXME: we support other ARPHRDs...*/
1538 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
1540 if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
1541 /* FIXME: rescan? */
1543 memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
1544 /* FIXME: rescan? deassoc & scan? */
1550 static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
1551 union iwreq_data *wrqu, char *extra)
1553 struct wl3501_card *this = netdev_priv(dev);
1555 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1556 memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
1560 static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
1561 union iwreq_data *wrqu, char *extra)
1564 * FIXME: trigger scanning with a reset, yes, I'm lazy
1566 return wl3501_reset(dev);
1569 static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
1570 union iwreq_data *wrqu, char *extra)
1572 struct wl3501_card *this = netdev_priv(dev);
1574 char *current_ev = extra;
1575 struct iw_event iwe;
1577 for (i = 0; i < this->bss_cnt; ++i) {
1578 iwe.cmd = SIOCGIWAP;
1579 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1580 memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].bssid, ETH_ALEN);
1581 current_ev = iwe_stream_add_event(info, current_ev,
1582 extra + IW_SCAN_MAX_DATA,
1583 &iwe, IW_EV_ADDR_LEN);
1584 iwe.cmd = SIOCGIWESSID;
1585 iwe.u.data.flags = 1;
1586 iwe.u.data.length = this->bss_set[i].ssid.el.len;
1587 current_ev = iwe_stream_add_point(info, current_ev,
1588 extra + IW_SCAN_MAX_DATA,
1590 this->bss_set[i].ssid.essid);
1591 iwe.cmd = SIOCGIWMODE;
1592 iwe.u.mode = this->bss_set[i].bss_type;
1593 current_ev = iwe_stream_add_event(info, current_ev,
1594 extra + IW_SCAN_MAX_DATA,
1595 &iwe, IW_EV_UINT_LEN);
1596 iwe.cmd = SIOCGIWFREQ;
1597 iwe.u.freq.m = this->bss_set[i].ds_pset.chan;
1599 current_ev = iwe_stream_add_event(info, current_ev,
1600 extra + IW_SCAN_MAX_DATA,
1601 &iwe, IW_EV_FREQ_LEN);
1602 iwe.cmd = SIOCGIWENCODE;
1603 if (this->bss_set[i].cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1604 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1606 iwe.u.data.flags = IW_ENCODE_DISABLED;
1607 iwe.u.data.length = 0;
1608 current_ev = iwe_stream_add_point(info, current_ev,
1609 extra + IW_SCAN_MAX_DATA,
1612 /* Length of data */
1613 wrqu->data.length = (current_ev - extra);
1614 wrqu->data.flags = 0; /* FIXME: set properly these flags */
1618 static int wl3501_set_essid(struct net_device *dev,
1619 struct iw_request_info *info,
1620 union iwreq_data *wrqu, char *extra)
1622 struct wl3501_card *this = netdev_priv(dev);
1624 if (wrqu->data.flags) {
1625 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1627 extra, wrqu->data.length);
1628 } else { /* We accept any ESSID */
1629 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1630 &this->essid.el, "ANY", 3);
1632 return wl3501_reset(dev);
1635 static int wl3501_get_essid(struct net_device *dev,
1636 struct iw_request_info *info,
1637 union iwreq_data *wrqu, char *extra)
1639 struct wl3501_card *this = netdev_priv(dev);
1640 unsigned long flags;
1642 spin_lock_irqsave(&this->lock, flags);
1643 wrqu->essid.flags = 1;
1644 wrqu->essid.length = this->essid.el.len;
1645 memcpy(extra, this->essid.essid, this->essid.el.len);
1646 spin_unlock_irqrestore(&this->lock, flags);
1650 static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
1651 union iwreq_data *wrqu, char *extra)
1653 struct wl3501_card *this = netdev_priv(dev);
1655 if (wrqu->data.length > sizeof(this->nick))
1657 strlcpy(this->nick, extra, wrqu->data.length);
1661 static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
1662 union iwreq_data *wrqu, char *extra)
1664 struct wl3501_card *this = netdev_priv(dev);
1666 strlcpy(extra, this->nick, 32);
1667 wrqu->data.length = strlen(extra);
1671 static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
1672 union iwreq_data *wrqu, char *extra)
1675 * FIXME: have to see from where to get this info, perhaps this card
1676 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1677 * common with the Planet Access Points. -acme
1679 wrqu->bitrate.value = 2000000;
1680 wrqu->bitrate.fixed = 1;
1684 static int wl3501_get_rts_threshold(struct net_device *dev,
1685 struct iw_request_info *info,
1686 union iwreq_data *wrqu, char *extra)
1688 u16 threshold; /* size checked: it is u16 */
1689 struct wl3501_card *this = netdev_priv(dev);
1690 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
1691 &threshold, sizeof(threshold));
1693 wrqu->rts.value = threshold;
1694 wrqu->rts.disabled = threshold >= 2347;
1695 wrqu->rts.fixed = 1;
1700 static int wl3501_get_frag_threshold(struct net_device *dev,
1701 struct iw_request_info *info,
1702 union iwreq_data *wrqu, char *extra)
1704 u16 threshold; /* size checked: it is u16 */
1705 struct wl3501_card *this = netdev_priv(dev);
1706 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD,
1707 &threshold, sizeof(threshold));
1709 wrqu->frag.value = threshold;
1710 wrqu->frag.disabled = threshold >= 2346;
1711 wrqu->frag.fixed = 1;
1716 static int wl3501_get_txpow(struct net_device *dev,
1717 struct iw_request_info *info,
1718 union iwreq_data *wrqu, char *extra)
1721 struct wl3501_card *this = netdev_priv(dev);
1722 int rc = wl3501_get_mib_value(this,
1723 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
1724 &txpow, sizeof(txpow));
1726 wrqu->txpower.value = txpow;
1727 wrqu->txpower.disabled = 0;
1729 * From the MIB values I think this can be configurable,
1730 * as it lists several tx power levels -acme
1732 wrqu->txpower.fixed = 0;
1733 wrqu->txpower.flags = IW_TXPOW_MWATT;
1738 static int wl3501_get_retry(struct net_device *dev,
1739 struct iw_request_info *info,
1740 union iwreq_data *wrqu, char *extra)
1742 u8 retry; /* size checked: it is u8 */
1743 struct wl3501_card *this = netdev_priv(dev);
1744 int rc = wl3501_get_mib_value(this,
1745 WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
1746 &retry, sizeof(retry));
1749 if (wrqu->retry.flags & IW_RETRY_LONG) {
1750 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1753 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1754 &retry, sizeof(retry));
1757 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1759 wrqu->retry.value = retry;
1760 wrqu->retry.disabled = 0;
1765 static int wl3501_get_encode(struct net_device *dev,
1766 struct iw_request_info *info,
1767 union iwreq_data *wrqu, char *extra)
1769 u8 implemented, restricted, keys[100], len_keys, tocopy;
1770 struct wl3501_card *this = netdev_priv(dev);
1771 int rc = wl3501_get_mib_value(this,
1772 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
1773 &implemented, sizeof(implemented));
1777 wrqu->encoding.flags = IW_ENCODE_DISABLED;
1780 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
1781 &restricted, sizeof(restricted));
1784 wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
1786 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
1787 &len_keys, sizeof(len_keys));
1790 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
1794 tocopy = min_t(u8, len_keys, wrqu->encoding.length);
1795 tocopy = min_t(u8, tocopy, 100);
1796 wrqu->encoding.length = tocopy;
1797 memcpy(extra, keys, tocopy);
1802 static int wl3501_get_power(struct net_device *dev,
1803 struct iw_request_info *info,
1804 union iwreq_data *wrqu, char *extra)
1807 struct wl3501_card *this = netdev_priv(dev);
1808 int rc = wl3501_get_mib_value(this,
1809 WL3501_MIB_ATTR_CURRENT_PWR_STATE,
1810 &pwr_state, sizeof(pwr_state));
1813 wrqu->power.disabled = !pwr_state;
1814 wrqu->power.flags = IW_POWER_ON;
1819 static const iw_handler wl3501_handler[] = {
1820 IW_HANDLER(SIOCGIWNAME, wl3501_get_name),
1821 IW_HANDLER(SIOCSIWFREQ, wl3501_set_freq),
1822 IW_HANDLER(SIOCGIWFREQ, wl3501_get_freq),
1823 IW_HANDLER(SIOCSIWMODE, wl3501_set_mode),
1824 IW_HANDLER(SIOCGIWMODE, wl3501_get_mode),
1825 IW_HANDLER(SIOCGIWSENS, wl3501_get_sens),
1826 IW_HANDLER(SIOCGIWRANGE, wl3501_get_range),
1827 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1828 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1829 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1830 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1831 IW_HANDLER(SIOCSIWAP, wl3501_set_wap),
1832 IW_HANDLER(SIOCGIWAP, wl3501_get_wap),
1833 IW_HANDLER(SIOCSIWSCAN, wl3501_set_scan),
1834 IW_HANDLER(SIOCGIWSCAN, wl3501_get_scan),
1835 IW_HANDLER(SIOCSIWESSID, wl3501_set_essid),
1836 IW_HANDLER(SIOCGIWESSID, wl3501_get_essid),
1837 IW_HANDLER(SIOCSIWNICKN, wl3501_set_nick),
1838 IW_HANDLER(SIOCGIWNICKN, wl3501_get_nick),
1839 IW_HANDLER(SIOCGIWRATE, wl3501_get_rate),
1840 IW_HANDLER(SIOCGIWRTS, wl3501_get_rts_threshold),
1841 IW_HANDLER(SIOCGIWFRAG, wl3501_get_frag_threshold),
1842 IW_HANDLER(SIOCGIWTXPOW, wl3501_get_txpow),
1843 IW_HANDLER(SIOCGIWRETRY, wl3501_get_retry),
1844 IW_HANDLER(SIOCGIWENCODE, wl3501_get_encode),
1845 IW_HANDLER(SIOCGIWPOWER, wl3501_get_power),
1848 static const struct iw_handler_def wl3501_handler_def = {
1849 .num_standard = ARRAY_SIZE(wl3501_handler),
1850 .standard = (iw_handler *)wl3501_handler,
1851 .get_wireless_stats = wl3501_get_wireless_stats,
1854 static const struct net_device_ops wl3501_netdev_ops = {
1855 .ndo_open = wl3501_open,
1856 .ndo_stop = wl3501_close,
1857 .ndo_start_xmit = wl3501_hard_start_xmit,
1858 .ndo_tx_timeout = wl3501_tx_timeout,
1859 .ndo_change_mtu = eth_change_mtu,
1860 .ndo_set_mac_address = eth_mac_addr,
1861 .ndo_validate_addr = eth_validate_addr,
1864 static int wl3501_probe(struct pcmcia_device *p_dev)
1866 struct net_device *dev;
1867 struct wl3501_card *this;
1869 /* The io structure describes IO port mapping */
1870 p_dev->resource[0]->end = 16;
1871 p_dev->resource[0]->flags = IO_DATA_PATH_WIDTH_8;
1873 /* General socket configuration */
1874 p_dev->config_flags = CONF_ENABLE_IRQ;
1875 p_dev->config_index = 1;
1877 dev = alloc_etherdev(sizeof(struct wl3501_card));
1882 dev->netdev_ops = &wl3501_netdev_ops;
1883 dev->watchdog_timeo = 5 * HZ;
1885 this = netdev_priv(dev);
1886 this->wireless_data.spy_data = &this->spy_data;
1887 this->p_dev = p_dev;
1888 dev->wireless_data = &this->wireless_data;
1889 dev->wireless_handlers = &wl3501_handler_def;
1890 SET_ETHTOOL_OPS(dev, &ops);
1891 netif_stop_queue(dev);
1894 return wl3501_config(p_dev);
1899 static int wl3501_config(struct pcmcia_device *link)
1901 struct net_device *dev = link->priv;
1903 struct wl3501_card *this;
1905 /* Try allocating IO ports. This tries a few fixed addresses. If you
1906 * want, you can also read the card's config table to pick addresses --
1907 * see the serial driver for an example. */
1910 for (j = 0x280; j < 0x400; j += 0x20) {
1911 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1912 * 0x200-0x2ff, and so on, because this seems safer */
1913 link->resource[0]->start = j;
1914 link->resource[1]->start = link->resource[0]->start + 0x10;
1915 i = pcmcia_request_io(link);
1922 /* Now allocate an interrupt line. Note that this does not actually
1923 * assign a handler to the interrupt. */
1925 ret = pcmcia_request_irq(link, wl3501_interrupt);
1929 ret = pcmcia_enable_device(link);
1933 dev->irq = link->irq;
1934 dev->base_addr = link->resource[0]->start;
1935 SET_NETDEV_DEV(dev, &link->dev);
1936 if (register_netdev(dev)) {
1937 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
1941 this = netdev_priv(dev);
1943 this->base_addr = dev->base_addr;
1945 if (!wl3501_get_flash_mac_addr(this)) {
1946 printk(KERN_WARNING "%s: Cant read MAC addr in flash ROM?\n",
1948 unregister_netdev(dev);
1952 for (i = 0; i < 6; i++)
1953 dev->dev_addr[i] = ((char *)&this->mac_addr)[i];
1955 /* print probe information */
1956 printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, "
1957 "MAC addr in flash ROM:%pM\n",
1958 dev->name, this->base_addr, (int)dev->irq,
1961 * Initialize card parameters - added by jss
1963 this->net_type = IW_MODE_INFRA;
1965 this->join_sta_bss = 0;
1966 this->adhoc_times = 0;
1967 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
1969 this->card_name[0] = '\0';
1970 this->firmware_date[0] = '\0';
1972 this->chan = iw_default_channel(this->reg_domain);
1973 strlcpy(this->nick, "Planet WL3501", sizeof(this->nick));
1974 spin_lock_init(&this->lock);
1975 init_waitqueue_head(&this->wait);
1976 netif_start_queue(dev);
1980 wl3501_release(link);
1984 static void wl3501_release(struct pcmcia_device *link)
1986 pcmcia_disable_device(link);
1989 static int wl3501_suspend(struct pcmcia_device *link)
1991 struct net_device *dev = link->priv;
1993 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_SUSPEND);
1995 netif_device_detach(dev);
2000 static int wl3501_resume(struct pcmcia_device *link)
2002 struct net_device *dev = link->priv;
2004 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_RESUME);
2007 netif_device_attach(dev);
2014 static struct pcmcia_device_id wl3501_ids[] = {
2015 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2018 MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2020 static struct pcmcia_driver wl3501_driver = {
2021 .owner = THIS_MODULE,
2022 .name = "wl3501_cs",
2023 .probe = wl3501_probe,
2024 .remove = wl3501_detach,
2025 .id_table = wl3501_ids,
2026 .suspend = wl3501_suspend,
2027 .resume = wl3501_resume,
2030 static int __init wl3501_init_module(void)
2032 return pcmcia_register_driver(&wl3501_driver);
2035 static void __exit wl3501_exit_module(void)
2037 pcmcia_unregister_driver(&wl3501_driver);
2040 module_init(wl3501_init_module);
2041 module_exit(wl3501_exit_module);
2043 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2044 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2045 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2046 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2047 MODULE_LICENSE("GPL");