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/interrupt.h>
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/fcntl.h>
37 #include <linux/if_arp.h>
38 #include <linux/ioport.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/skbuff.h>
42 #include <linux/slab.h>
43 #include <linux/string.h>
44 #include <linux/wireless.h>
45 #include <net/cfg80211.h>
47 #include <net/iw_handler.h>
49 #include <pcmcia/cistpl.h>
50 #include <pcmcia/cisreg.h>
51 #include <pcmcia/ds.h>
54 #include <asm/uaccess.h>
59 #define slow_down_io()
62 /* For rough constant delay */
63 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
67 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
68 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
69 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
71 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
72 #define WL3501_MAX_ADHOC_TRIES 16
74 #define WL3501_RESUME 0
75 #define WL3501_SUSPEND 1
77 static int wl3501_config(struct pcmcia_device *link);
78 static void wl3501_release(struct pcmcia_device *link);
83 } iw_channel_table[] = {
85 .reg_domain = IW_REG_DOMAIN_FCC,
91 .reg_domain = IW_REG_DOMAIN_DOC,
97 .reg_domain = IW_REG_DOMAIN_ETSI,
103 .reg_domain = IW_REG_DOMAIN_SPAIN,
109 .reg_domain = IW_REG_DOMAIN_FRANCE,
115 .reg_domain = IW_REG_DOMAIN_MKK,
121 .reg_domain = IW_REG_DOMAIN_MKK1,
127 .reg_domain = IW_REG_DOMAIN_ISRAEL,
135 * iw_valid_channel - validate channel in regulatory domain
136 * @reg_comain - regulatory domain
137 * @channel - channel to validate
139 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
141 static int iw_valid_channel(int reg_domain, int channel)
145 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
146 if (reg_domain == iw_channel_table[i].reg_domain) {
147 rc = channel >= iw_channel_table[i].min &&
148 channel <= iw_channel_table[i].max;
155 * iw_default_channel - get default channel for a regulatory domain
156 * @reg_comain - regulatory domain
158 * Returns the default channel for a regulatory domain
160 static int iw_default_channel(int reg_domain)
164 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
165 if (reg_domain == iw_channel_table[i].reg_domain) {
166 rc = iw_channel_table[i].deflt;
172 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
173 struct iw_mgmt_info_element *el,
174 void *value, int len)
178 memcpy(el->data, value, len);
181 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
182 struct iw_mgmt_info_element *from)
184 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
187 static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
189 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
193 * Get Ethernet MAC address.
195 * WARNING: We switch to FPAGE0 and switc back again.
196 * Making sure there is no other WL function beening called by ISR.
198 static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
200 int base_addr = this->base_addr;
203 wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
204 wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL); /* LMAL */
205 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH); /* LMAH */
207 /* wait for reading EEPROM */
209 this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
211 this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
213 this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
215 this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
217 this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
219 this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
221 this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
223 wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
224 wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
225 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
227 this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
229 this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
230 /* switch to SRAM Page 0 (for safety) */
231 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
233 /* The MAC addr should be 00:60:... */
234 return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
238 * wl3501_set_to_wla - Move 'size' bytes from PC to card
239 * @dest: Card addressing space
240 * @src: PC addressing space
241 * @size: Bytes to move
243 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
245 static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
248 /* switch to SRAM Page 0 */
249 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
251 /* set LMAL and LMAH */
252 wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
253 wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
255 /* rep out to Port A */
256 wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
260 * wl3501_get_from_wla - Move 'size' bytes from card to PC
261 * @src: Card addressing space
262 * @dest: PC addressing space
263 * @size: Bytes to move
265 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
267 static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
270 /* switch to SRAM Page 0 */
271 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
273 /* set LMAL and LMAH */
274 wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
275 wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
277 /* rep get from Port A */
278 insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
282 * Get/Allocate a free Tx Data Buffer
284 * *--------------*-----------------*----------------------------------*
285 * | PLCP | MAC Header | DST SRC Data ... |
286 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
287 * *--------------*-----------------*----------------------------------*
288 * \ \- IEEE 802.11 -/ \-------------- len --------------/
289 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
291 * Return = Position in Card
293 static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
295 u16 next, blk_cnt = 0, zero = 0;
296 u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
299 if (full_len > this->tx_buffer_cnt * 254)
301 ret = this->tx_buffer_head;
307 wl3501_get_from_wla(this, this->tx_buffer_head, &next,
310 wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
312 this->tx_buffer_head = next;
314 /* if buffer is not enough */
315 if (!next && full_len) {
316 this->tx_buffer_head = ret;
321 this->tx_buffer_cnt -= blk_cnt;
327 * Free an allocated Tx Buffer. ptr must be correct position.
329 static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
331 /* check if all space is not free */
332 if (!this->tx_buffer_head)
333 this->tx_buffer_head = ptr;
335 wl3501_set_to_wla(this, this->tx_buffer_tail,
340 this->tx_buffer_cnt++;
341 wl3501_get_from_wla(this, ptr, &next, sizeof(next));
342 this->tx_buffer_tail = ptr;
347 static int wl3501_esbq_req_test(struct wl3501_card *this)
351 wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
355 static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
359 wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
360 wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
361 this->esbq_req_head += 4;
362 if (this->esbq_req_head >= this->esbq_req_end)
363 this->esbq_req_head = this->esbq_req_start;
366 static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
370 if (wl3501_esbq_req_test(this)) {
371 u16 ptr = wl3501_get_tx_buffer(this, sig_size);
373 wl3501_set_to_wla(this, ptr, sig, sig_size);
374 wl3501_esbq_req(this, &ptr);
381 static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
384 struct wl3501_get_req sig = {
385 .sig_id = WL3501_SIG_GET_REQ,
391 spin_lock_irqsave(&this->lock, flags);
392 if (wl3501_esbq_req_test(this)) {
393 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
395 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
396 wl3501_esbq_req(this, &ptr);
397 this->sig_get_confirm.mib_status = 255;
398 spin_unlock_irqrestore(&this->lock, flags);
399 rc = wait_event_interruptible(this->wait,
400 this->sig_get_confirm.mib_status != 255);
402 memcpy(bf, this->sig_get_confirm.mib_value,
407 spin_unlock_irqrestore(&this->lock, flags);
412 static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
414 struct wl3501_pwr_mgmt_req sig = {
415 .sig_id = WL3501_SIG_PWR_MGMT_REQ,
423 spin_lock_irqsave(&this->lock, flags);
424 if (wl3501_esbq_req_test(this)) {
425 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
427 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
428 wl3501_esbq_req(this, &ptr);
429 this->sig_pwr_mgmt_confirm.status = 255;
430 spin_unlock_irqrestore(&this->lock, flags);
431 rc = wait_event_interruptible(this->wait,
432 this->sig_pwr_mgmt_confirm.status != 255);
433 printk(KERN_INFO "%s: %s status=%d\n", __func__,
434 suspend ? "suspend" : "resume",
435 this->sig_pwr_mgmt_confirm.status);
439 spin_unlock_irqrestore(&this->lock, flags);
445 * wl3501_send_pkt - Send a packet.
450 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
451 * data[6] - data[11] is Src MAC Addr)
454 static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
456 u16 bf, sig_bf, next, tmplen, pktlen;
457 struct wl3501_md_req sig = {
458 .sig_id = WL3501_SIG_MD_REQ,
460 size_t sig_addr_len = sizeof(sig.addr);
461 u8 *pdata = (char *)data;
464 if (wl3501_esbq_req_test(this)) {
465 sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
467 if (!sig_bf) /* No free buffer available */
469 bf = wl3501_get_tx_buffer(this, len + 26 + 24);
471 /* No free buffer available */
472 wl3501_free_tx_buffer(this, sig_bf);
476 memcpy(&sig.addr, pdata, sig_addr_len);
477 pktlen = len - sig_addr_len;
478 pdata += sig_addr_len;
480 if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
481 u8 addr4[ETH_ALEN] = {
482 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
485 wl3501_set_to_wla(this, bf + 2 +
486 offsetof(struct wl3501_tx_hdr, addr4),
487 addr4, sizeof(addr4));
488 sig.size = pktlen + 24 + 4 + 6;
489 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
490 tmplen = 254 - sizeof(struct wl3501_tx_hdr);
496 wl3501_set_to_wla(this,
497 bf + 2 + sizeof(struct wl3501_tx_hdr),
500 wl3501_get_from_wla(this, bf, &next, sizeof(next));
503 sig.size = pktlen + 24 + 4 - 2;
506 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
507 tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
513 wl3501_set_to_wla(this, bf + 2 +
514 offsetof(struct wl3501_tx_hdr, addr4),
517 wl3501_get_from_wla(this, bf, &next, sizeof(next));
528 wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
530 wl3501_get_from_wla(this, bf, &next, sizeof(next));
533 wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
534 wl3501_esbq_req(this, &sig_bf);
540 static int wl3501_mgmt_resync(struct wl3501_card *this)
542 struct wl3501_resync_req sig = {
543 .sig_id = WL3501_SIG_RESYNC_REQ,
546 return wl3501_esbq_exec(this, &sig, sizeof(sig));
549 static inline int wl3501_fw_bss_type(struct wl3501_card *this)
551 return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
552 WL3501_NET_TYPE_ADHOC;
555 static inline int wl3501_fw_cap_info(struct wl3501_card *this)
557 return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
558 WL3501_MGMT_CAPABILITY_IBSS;
561 static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
563 struct wl3501_scan_req sig = {
564 .sig_id = WL3501_SIG_SCAN_REQ,
565 .scan_type = WL3501_SCAN_TYPE_ACTIVE,
567 .min_chan_time = chan_time,
568 .max_chan_time = chan_time,
569 .bss_type = wl3501_fw_bss_type(this),
572 this->bss_cnt = this->join_sta_bss = 0;
573 return wl3501_esbq_exec(this, &sig, sizeof(sig));
576 static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
578 struct wl3501_join_req sig = {
579 .sig_id = WL3501_SIG_JOIN_REQ,
583 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
590 memcpy(&sig.req, &this->bss_set[stas].req, sizeof(sig.req));
591 return wl3501_esbq_exec(this, &sig, sizeof(sig));
594 static int wl3501_mgmt_start(struct wl3501_card *this)
596 struct wl3501_start_req sig = {
597 .sig_id = WL3501_SIG_START_REQ,
598 .beacon_period = 400,
602 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
609 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
612 .data_rate_labels = {
613 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
614 IW_MGMT_RATE_LABEL_1MBIT,
615 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
616 IW_MGMT_RATE_LABEL_2MBIT,
619 .operational_rset = {
621 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
624 .data_rate_labels = {
625 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
626 IW_MGMT_RATE_LABEL_1MBIT,
627 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
628 IW_MGMT_RATE_LABEL_2MBIT,
633 .id = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
638 .bss_type = wl3501_fw_bss_type(this),
639 .cap_info = wl3501_fw_cap_info(this),
642 iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
643 iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
644 return wl3501_esbq_exec(this, &sig, sizeof(sig));
647 static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
651 struct wl3501_scan_confirm sig;
654 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
655 if (sig.status == WL3501_STATUS_SUCCESS) {
657 if ((this->net_type == IW_MODE_INFRA &&
658 (sig.req.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
659 (this->net_type == IW_MODE_ADHOC &&
660 (sig.req.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
661 this->net_type == IW_MODE_AUTO) {
662 if (!this->essid.el.len)
664 else if (this->essid.el.len == 3 &&
665 !memcmp(this->essid.essid, "ANY", 3))
667 else if (this->essid.el.len != sig.req.ssid.el.len)
669 else if (memcmp(this->essid.essid, sig.req.ssid.essid,
675 for (i = 0; i < this->bss_cnt; i++) {
676 if (ether_addr_equal_unaligned(this->bss_set[i].req.bssid,
683 if (matchflag && (i < 20)) {
684 memcpy(&this->bss_set[i].req,
685 &sig.req, sizeof(sig.req));
687 this->rssi = sig.rssi;
688 this->bss_set[i].rssi = sig.rssi;
691 } else if (sig.status == WL3501_STATUS_TIMEOUT) {
693 this->join_sta_bss = 0;
694 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
695 if (!wl3501_mgmt_join(this, i))
697 this->join_sta_bss = i;
698 if (this->join_sta_bss == this->bss_cnt) {
699 if (this->net_type == IW_MODE_INFRA)
700 wl3501_mgmt_scan(this, 100);
703 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
704 wl3501_mgmt_start(this);
706 wl3501_mgmt_scan(this, 100);
713 * wl3501_block_interrupt - Mask interrupt from SUTRO
716 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
717 * Return: 1 if interrupt is originally enabled
719 static int wl3501_block_interrupt(struct wl3501_card *this)
721 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
722 u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
723 WL3501_GCR_ENECINT));
725 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
726 return old & WL3501_GCR_ENECINT;
730 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
733 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
734 * Return: 1 if interrupt is originally enabled
736 static int wl3501_unblock_interrupt(struct wl3501_card *this)
738 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
739 u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
742 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
743 return old & WL3501_GCR_ENECINT;
747 * wl3501_receive - Receive data from Receive Queue.
749 * Receive data from Receive Queue.
752 * @bf: address of host
753 * @size: size of buffer.
755 static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
757 u16 next_addr, next_addr1;
761 wl3501_get_from_wla(this, this->start_seg + 2,
762 &next_addr, sizeof(next_addr));
763 if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
764 wl3501_get_from_wla(this,
766 sizeof(struct wl3501_rx_hdr), data,
768 sizeof(struct wl3501_rx_hdr));
769 size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
770 data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
772 wl3501_get_from_wla(this,
774 sizeof(struct wl3501_rx_hdr),
779 if (size > WL3501_BLKSZ - 5) {
780 wl3501_get_from_wla(this, next_addr + 5, data,
782 size -= WL3501_BLKSZ - 5;
783 data += WL3501_BLKSZ - 5;
784 wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
786 next_addr = next_addr1;
788 wl3501_get_from_wla(this, next_addr + 5, data, size);
795 static void wl3501_esbq_req_free(struct wl3501_card *this)
800 if (this->esbq_req_head == this->esbq_req_tail)
802 wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
805 wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
806 wl3501_free_tx_buffer(this, addr);
807 this->esbq_req_tail += 4;
808 if (this->esbq_req_tail >= this->esbq_req_end)
809 this->esbq_req_tail = this->esbq_req_start;
814 static int wl3501_esbq_confirm(struct wl3501_card *this)
818 wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
822 static void wl3501_online(struct net_device *dev)
824 struct wl3501_card *this = netdev_priv(dev);
826 printk(KERN_INFO "%s: Wireless LAN online. BSSID: %pM\n",
827 dev->name, this->bssid);
828 netif_wake_queue(dev);
831 static void wl3501_esbq_confirm_done(struct wl3501_card *this)
835 wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
836 this->esbq_confirm += 4;
837 if (this->esbq_confirm >= this->esbq_confirm_end)
838 this->esbq_confirm = this->esbq_confirm_start;
841 static int wl3501_mgmt_auth(struct wl3501_card *this)
843 struct wl3501_auth_req sig = {
844 .sig_id = WL3501_SIG_AUTH_REQ,
845 .type = WL3501_SYS_TYPE_OPEN,
850 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
851 return wl3501_esbq_exec(this, &sig, sizeof(sig));
854 static int wl3501_mgmt_association(struct wl3501_card *this)
856 struct wl3501_assoc_req sig = {
857 .sig_id = WL3501_SIG_ASSOC_REQ,
859 .listen_interval = 5,
860 .cap_info = this->cap_info,
864 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
865 return wl3501_esbq_exec(this, &sig, sizeof(sig));
868 static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
870 struct wl3501_card *this = netdev_priv(dev);
871 struct wl3501_join_confirm sig;
874 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
875 if (sig.status == WL3501_STATUS_SUCCESS) {
876 if (this->net_type == IW_MODE_INFRA) {
877 if (this->join_sta_bss < this->bss_cnt) {
878 const int i = this->join_sta_bss;
880 this->bss_set[i].req.bssid, ETH_ALEN);
881 this->chan = this->bss_set[i].req.ds_pset.chan;
882 iw_copy_mgmt_info_element(&this->keep_essid.el,
883 &this->bss_set[i].req.ssid.el);
884 wl3501_mgmt_auth(this);
887 const int i = this->join_sta_bss;
889 memcpy(&this->bssid, &this->bss_set[i].req.bssid, ETH_ALEN);
890 this->chan = this->bss_set[i].req.ds_pset.chan;
891 iw_copy_mgmt_info_element(&this->keep_essid.el,
892 &this->bss_set[i].req.ssid.el);
897 this->join_sta_bss++;
898 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
899 if (!wl3501_mgmt_join(this, i))
901 this->join_sta_bss = i;
902 if (this->join_sta_bss == this->bss_cnt) {
903 if (this->net_type == IW_MODE_INFRA)
904 wl3501_mgmt_scan(this, 100);
907 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
908 wl3501_mgmt_start(this);
910 wl3501_mgmt_scan(this, 100);
916 static inline void wl3501_alarm_interrupt(struct net_device *dev,
917 struct wl3501_card *this)
919 if (this->net_type == IW_MODE_INFRA) {
920 printk(KERN_INFO "Wireless LAN offline\n");
921 netif_stop_queue(dev);
922 wl3501_mgmt_resync(this);
926 static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
927 struct wl3501_card *this,
930 struct wl3501_md_confirm sig;
933 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
934 wl3501_free_tx_buffer(this, sig.data);
935 if (netif_queue_stopped(dev))
936 netif_wake_queue(dev);
939 static inline void wl3501_md_ind_interrupt(struct net_device *dev,
940 struct wl3501_card *this, u16 addr)
942 struct wl3501_md_ind sig;
944 u8 rssi, addr4[ETH_ALEN];
947 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
948 this->start_seg = sig.data;
949 wl3501_get_from_wla(this,
950 sig.data + offsetof(struct wl3501_rx_hdr, rssi),
951 &rssi, sizeof(rssi));
952 this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
954 wl3501_get_from_wla(this,
956 offsetof(struct wl3501_rx_hdr, addr4),
957 &addr4, sizeof(addr4));
958 if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
959 addr4[2] == 0x03 && addr4[4] == 0x00)) {
960 printk(KERN_INFO "Insupported packet type!\n");
963 pkt_len = sig.size + 12 - 24 - 4 - 6;
965 skb = dev_alloc_skb(pkt_len + 5);
968 printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
970 dev->stats.rx_dropped++;
973 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
974 skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
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;
1407 * wl3501_detach - deletes a driver "instance"
1410 * This deletes a driver "instance". The device is de-registered with Card
1411 * Services. If it has been released, all local data structures are freed.
1412 * Otherwise, the structures will be freed when the device is released.
1414 static void wl3501_detach(struct pcmcia_device *link)
1416 struct net_device *dev = link->priv;
1418 /* If the device is currently configured and active, we won't actually
1419 * delete it yet. Instead, it is marked so that when the release()
1420 * function is called, that will trigger a proper detach(). */
1422 while (link->open > 0)
1425 netif_device_detach(dev);
1426 wl3501_release(link);
1428 unregister_netdev(dev);
1431 free_netdev(link->priv);
1434 static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
1435 union iwreq_data *wrqu, char *extra)
1437 strlcpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
1441 static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
1442 union iwreq_data *wrqu, char *extra)
1444 struct wl3501_card *this = netdev_priv(dev);
1445 int channel = wrqu->freq.m;
1448 if (iw_valid_channel(this->reg_domain, channel)) {
1449 this->chan = channel;
1450 rc = wl3501_reset(dev);
1455 static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
1456 union iwreq_data *wrqu, char *extra)
1458 struct wl3501_card *this = netdev_priv(dev);
1460 wrqu->freq.m = 100000 *
1461 ieee80211_channel_to_frequency(this->chan, IEEE80211_BAND_2GHZ);
1466 static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
1467 union iwreq_data *wrqu, char *extra)
1471 if (wrqu->mode == IW_MODE_INFRA ||
1472 wrqu->mode == IW_MODE_ADHOC ||
1473 wrqu->mode == IW_MODE_AUTO) {
1474 struct wl3501_card *this = netdev_priv(dev);
1476 this->net_type = wrqu->mode;
1477 rc = wl3501_reset(dev);
1482 static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
1483 union iwreq_data *wrqu, char *extra)
1485 struct wl3501_card *this = netdev_priv(dev);
1487 wrqu->mode = this->net_type;
1491 static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
1492 union iwreq_data *wrqu, char *extra)
1494 struct wl3501_card *this = netdev_priv(dev);
1496 wrqu->sens.value = this->rssi;
1497 wrqu->sens.disabled = !wrqu->sens.value;
1498 wrqu->sens.fixed = 1;
1502 static int wl3501_get_range(struct net_device *dev,
1503 struct iw_request_info *info,
1504 union iwreq_data *wrqu, char *extra)
1506 struct iw_range *range = (struct iw_range *)extra;
1508 /* Set the length (very important for backward compatibility) */
1509 wrqu->data.length = sizeof(*range);
1511 /* Set all the info we don't care or don't know about to zero */
1512 memset(range, 0, sizeof(*range));
1514 /* Set the Wireless Extension versions */
1515 range->we_version_compiled = WIRELESS_EXT;
1516 range->we_version_source = 1;
1517 range->throughput = 2 * 1000 * 1000; /* ~2 Mb/s */
1518 /* FIXME: study the code to fill in more fields... */
1522 static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
1523 union iwreq_data *wrqu, char *extra)
1525 struct wl3501_card *this = netdev_priv(dev);
1528 /* FIXME: we support other ARPHRDs...*/
1529 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
1531 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data)) {
1532 /* FIXME: rescan? */
1534 memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
1535 /* FIXME: rescan? deassoc & scan? */
1541 static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
1542 union iwreq_data *wrqu, char *extra)
1544 struct wl3501_card *this = netdev_priv(dev);
1546 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1547 memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
1551 static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
1552 union iwreq_data *wrqu, char *extra)
1555 * FIXME: trigger scanning with a reset, yes, I'm lazy
1557 return wl3501_reset(dev);
1560 static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
1561 union iwreq_data *wrqu, char *extra)
1563 struct wl3501_card *this = netdev_priv(dev);
1565 char *current_ev = extra;
1566 struct iw_event iwe;
1568 for (i = 0; i < this->bss_cnt; ++i) {
1569 iwe.cmd = SIOCGIWAP;
1570 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1571 memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].req.bssid, ETH_ALEN);
1572 current_ev = iwe_stream_add_event(info, current_ev,
1573 extra + IW_SCAN_MAX_DATA,
1574 &iwe, IW_EV_ADDR_LEN);
1575 iwe.cmd = SIOCGIWESSID;
1576 iwe.u.data.flags = 1;
1577 iwe.u.data.length = this->bss_set[i].req.ssid.el.len;
1578 current_ev = iwe_stream_add_point(info, current_ev,
1579 extra + IW_SCAN_MAX_DATA,
1581 this->bss_set[i].req.ssid.essid);
1582 iwe.cmd = SIOCGIWMODE;
1583 iwe.u.mode = this->bss_set[i].req.bss_type;
1584 current_ev = iwe_stream_add_event(info, current_ev,
1585 extra + IW_SCAN_MAX_DATA,
1586 &iwe, IW_EV_UINT_LEN);
1587 iwe.cmd = SIOCGIWFREQ;
1588 iwe.u.freq.m = this->bss_set[i].req.ds_pset.chan;
1590 current_ev = iwe_stream_add_event(info, current_ev,
1591 extra + IW_SCAN_MAX_DATA,
1592 &iwe, IW_EV_FREQ_LEN);
1593 iwe.cmd = SIOCGIWENCODE;
1594 if (this->bss_set[i].req.cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1595 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1597 iwe.u.data.flags = IW_ENCODE_DISABLED;
1598 iwe.u.data.length = 0;
1599 current_ev = iwe_stream_add_point(info, current_ev,
1600 extra + IW_SCAN_MAX_DATA,
1603 /* Length of data */
1604 wrqu->data.length = (current_ev - extra);
1605 wrqu->data.flags = 0; /* FIXME: set properly these flags */
1609 static int wl3501_set_essid(struct net_device *dev,
1610 struct iw_request_info *info,
1611 union iwreq_data *wrqu, char *extra)
1613 struct wl3501_card *this = netdev_priv(dev);
1615 if (wrqu->data.flags) {
1616 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1618 extra, wrqu->data.length);
1619 } else { /* We accept any ESSID */
1620 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1621 &this->essid.el, "ANY", 3);
1623 return wl3501_reset(dev);
1626 static int wl3501_get_essid(struct net_device *dev,
1627 struct iw_request_info *info,
1628 union iwreq_data *wrqu, char *extra)
1630 struct wl3501_card *this = netdev_priv(dev);
1631 unsigned long flags;
1633 spin_lock_irqsave(&this->lock, flags);
1634 wrqu->essid.flags = 1;
1635 wrqu->essid.length = this->essid.el.len;
1636 memcpy(extra, this->essid.essid, this->essid.el.len);
1637 spin_unlock_irqrestore(&this->lock, flags);
1641 static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
1642 union iwreq_data *wrqu, char *extra)
1644 struct wl3501_card *this = netdev_priv(dev);
1646 if (wrqu->data.length > sizeof(this->nick))
1648 strlcpy(this->nick, extra, wrqu->data.length);
1652 static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
1653 union iwreq_data *wrqu, char *extra)
1655 struct wl3501_card *this = netdev_priv(dev);
1657 strlcpy(extra, this->nick, 32);
1658 wrqu->data.length = strlen(extra);
1662 static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
1663 union iwreq_data *wrqu, char *extra)
1666 * FIXME: have to see from where to get this info, perhaps this card
1667 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1668 * common with the Planet Access Points. -acme
1670 wrqu->bitrate.value = 2000000;
1671 wrqu->bitrate.fixed = 1;
1675 static int wl3501_get_rts_threshold(struct net_device *dev,
1676 struct iw_request_info *info,
1677 union iwreq_data *wrqu, char *extra)
1679 u16 threshold; /* size checked: it is u16 */
1680 struct wl3501_card *this = netdev_priv(dev);
1681 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
1682 &threshold, sizeof(threshold));
1684 wrqu->rts.value = threshold;
1685 wrqu->rts.disabled = threshold >= 2347;
1686 wrqu->rts.fixed = 1;
1691 static int wl3501_get_frag_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_FRAG_THRESHOLD,
1698 &threshold, sizeof(threshold));
1700 wrqu->frag.value = threshold;
1701 wrqu->frag.disabled = threshold >= 2346;
1702 wrqu->frag.fixed = 1;
1707 static int wl3501_get_txpow(struct net_device *dev,
1708 struct iw_request_info *info,
1709 union iwreq_data *wrqu, char *extra)
1712 struct wl3501_card *this = netdev_priv(dev);
1713 int rc = wl3501_get_mib_value(this,
1714 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
1715 &txpow, sizeof(txpow));
1717 wrqu->txpower.value = txpow;
1718 wrqu->txpower.disabled = 0;
1720 * From the MIB values I think this can be configurable,
1721 * as it lists several tx power levels -acme
1723 wrqu->txpower.fixed = 0;
1724 wrqu->txpower.flags = IW_TXPOW_MWATT;
1729 static int wl3501_get_retry(struct net_device *dev,
1730 struct iw_request_info *info,
1731 union iwreq_data *wrqu, char *extra)
1733 u8 retry; /* size checked: it is u8 */
1734 struct wl3501_card *this = netdev_priv(dev);
1735 int rc = wl3501_get_mib_value(this,
1736 WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
1737 &retry, sizeof(retry));
1740 if (wrqu->retry.flags & IW_RETRY_LONG) {
1741 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1744 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1745 &retry, sizeof(retry));
1748 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1750 wrqu->retry.value = retry;
1751 wrqu->retry.disabled = 0;
1756 static int wl3501_get_encode(struct net_device *dev,
1757 struct iw_request_info *info,
1758 union iwreq_data *wrqu, char *extra)
1760 u8 implemented, restricted, keys[100], len_keys, tocopy;
1761 struct wl3501_card *this = netdev_priv(dev);
1762 int rc = wl3501_get_mib_value(this,
1763 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
1764 &implemented, sizeof(implemented));
1768 wrqu->encoding.flags = IW_ENCODE_DISABLED;
1771 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
1772 &restricted, sizeof(restricted));
1775 wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
1777 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
1778 &len_keys, sizeof(len_keys));
1781 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
1785 tocopy = min_t(u16, len_keys, wrqu->encoding.length);
1786 tocopy = min_t(u8, tocopy, 100);
1787 wrqu->encoding.length = tocopy;
1788 memcpy(extra, keys, tocopy);
1793 static int wl3501_get_power(struct net_device *dev,
1794 struct iw_request_info *info,
1795 union iwreq_data *wrqu, char *extra)
1798 struct wl3501_card *this = netdev_priv(dev);
1799 int rc = wl3501_get_mib_value(this,
1800 WL3501_MIB_ATTR_CURRENT_PWR_STATE,
1801 &pwr_state, sizeof(pwr_state));
1804 wrqu->power.disabled = !pwr_state;
1805 wrqu->power.flags = IW_POWER_ON;
1810 static const iw_handler wl3501_handler[] = {
1811 IW_HANDLER(SIOCGIWNAME, wl3501_get_name),
1812 IW_HANDLER(SIOCSIWFREQ, wl3501_set_freq),
1813 IW_HANDLER(SIOCGIWFREQ, wl3501_get_freq),
1814 IW_HANDLER(SIOCSIWMODE, wl3501_set_mode),
1815 IW_HANDLER(SIOCGIWMODE, wl3501_get_mode),
1816 IW_HANDLER(SIOCGIWSENS, wl3501_get_sens),
1817 IW_HANDLER(SIOCGIWRANGE, wl3501_get_range),
1818 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1819 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1820 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1821 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1822 IW_HANDLER(SIOCSIWAP, wl3501_set_wap),
1823 IW_HANDLER(SIOCGIWAP, wl3501_get_wap),
1824 IW_HANDLER(SIOCSIWSCAN, wl3501_set_scan),
1825 IW_HANDLER(SIOCGIWSCAN, wl3501_get_scan),
1826 IW_HANDLER(SIOCSIWESSID, wl3501_set_essid),
1827 IW_HANDLER(SIOCGIWESSID, wl3501_get_essid),
1828 IW_HANDLER(SIOCSIWNICKN, wl3501_set_nick),
1829 IW_HANDLER(SIOCGIWNICKN, wl3501_get_nick),
1830 IW_HANDLER(SIOCGIWRATE, wl3501_get_rate),
1831 IW_HANDLER(SIOCGIWRTS, wl3501_get_rts_threshold),
1832 IW_HANDLER(SIOCGIWFRAG, wl3501_get_frag_threshold),
1833 IW_HANDLER(SIOCGIWTXPOW, wl3501_get_txpow),
1834 IW_HANDLER(SIOCGIWRETRY, wl3501_get_retry),
1835 IW_HANDLER(SIOCGIWENCODE, wl3501_get_encode),
1836 IW_HANDLER(SIOCGIWPOWER, wl3501_get_power),
1839 static const struct iw_handler_def wl3501_handler_def = {
1840 .num_standard = ARRAY_SIZE(wl3501_handler),
1841 .standard = (iw_handler *)wl3501_handler,
1842 .get_wireless_stats = wl3501_get_wireless_stats,
1845 static const struct net_device_ops wl3501_netdev_ops = {
1846 .ndo_open = wl3501_open,
1847 .ndo_stop = wl3501_close,
1848 .ndo_start_xmit = wl3501_hard_start_xmit,
1849 .ndo_tx_timeout = wl3501_tx_timeout,
1850 .ndo_change_mtu = eth_change_mtu,
1851 .ndo_set_mac_address = eth_mac_addr,
1852 .ndo_validate_addr = eth_validate_addr,
1855 static int wl3501_probe(struct pcmcia_device *p_dev)
1857 struct net_device *dev;
1858 struct wl3501_card *this;
1860 /* The io structure describes IO port mapping */
1861 p_dev->resource[0]->end = 16;
1862 p_dev->resource[0]->flags = IO_DATA_PATH_WIDTH_8;
1864 /* General socket configuration */
1865 p_dev->config_flags = CONF_ENABLE_IRQ;
1866 p_dev->config_index = 1;
1868 dev = alloc_etherdev(sizeof(struct wl3501_card));
1873 dev->netdev_ops = &wl3501_netdev_ops;
1874 dev->watchdog_timeo = 5 * HZ;
1876 this = netdev_priv(dev);
1877 this->wireless_data.spy_data = &this->spy_data;
1878 this->p_dev = p_dev;
1879 dev->wireless_data = &this->wireless_data;
1880 dev->wireless_handlers = &wl3501_handler_def;
1881 netif_stop_queue(dev);
1884 return wl3501_config(p_dev);
1889 static int wl3501_config(struct pcmcia_device *link)
1891 struct net_device *dev = link->priv;
1893 struct wl3501_card *this;
1895 /* Try allocating IO ports. This tries a few fixed addresses. If you
1896 * want, you can also read the card's config table to pick addresses --
1897 * see the serial driver for an example. */
1900 for (j = 0x280; j < 0x400; j += 0x20) {
1901 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1902 * 0x200-0x2ff, and so on, because this seems safer */
1903 link->resource[0]->start = j;
1904 link->resource[1]->start = link->resource[0]->start + 0x10;
1905 i = pcmcia_request_io(link);
1912 /* Now allocate an interrupt line. Note that this does not actually
1913 * assign a handler to the interrupt. */
1915 ret = pcmcia_request_irq(link, wl3501_interrupt);
1919 ret = pcmcia_enable_device(link);
1923 dev->irq = link->irq;
1924 dev->base_addr = link->resource[0]->start;
1925 SET_NETDEV_DEV(dev, &link->dev);
1926 if (register_netdev(dev)) {
1927 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
1931 this = netdev_priv(dev);
1933 this->base_addr = dev->base_addr;
1935 if (!wl3501_get_flash_mac_addr(this)) {
1936 printk(KERN_WARNING "%s: Can't read MAC addr in flash ROM?\n",
1938 unregister_netdev(dev);
1942 for (i = 0; i < 6; i++)
1943 dev->dev_addr[i] = ((char *)&this->mac_addr)[i];
1945 /* print probe information */
1946 printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, "
1947 "MAC addr in flash ROM:%pM\n",
1948 dev->name, this->base_addr, (int)dev->irq,
1951 * Initialize card parameters - added by jss
1953 this->net_type = IW_MODE_INFRA;
1955 this->join_sta_bss = 0;
1956 this->adhoc_times = 0;
1957 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
1959 this->card_name[0] = '\0';
1960 this->firmware_date[0] = '\0';
1962 this->chan = iw_default_channel(this->reg_domain);
1963 strlcpy(this->nick, "Planet WL3501", sizeof(this->nick));
1964 spin_lock_init(&this->lock);
1965 init_waitqueue_head(&this->wait);
1966 netif_start_queue(dev);
1970 wl3501_release(link);
1974 static void wl3501_release(struct pcmcia_device *link)
1976 pcmcia_disable_device(link);
1979 static int wl3501_suspend(struct pcmcia_device *link)
1981 struct net_device *dev = link->priv;
1983 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_SUSPEND);
1985 netif_device_detach(dev);
1990 static int wl3501_resume(struct pcmcia_device *link)
1992 struct net_device *dev = link->priv;
1994 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_RESUME);
1997 netif_device_attach(dev);
2004 static const struct pcmcia_device_id wl3501_ids[] = {
2005 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2008 MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2010 static struct pcmcia_driver wl3501_driver = {
2011 .owner = THIS_MODULE,
2012 .name = "wl3501_cs",
2013 .probe = wl3501_probe,
2014 .remove = wl3501_detach,
2015 .id_table = wl3501_ids,
2016 .suspend = wl3501_suspend,
2017 .resume = wl3501_resume,
2019 module_pcmcia_driver(wl3501_driver);
2021 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2022 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2023 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2024 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2025 MODULE_LICENSE("GPL");