1 // SPDX-License-Identifier: GPL-2.0-only
3 * WL3501 Wireless LAN PCMCIA Card Driver for Linux
8 * References used by Fox Chen while writing the original driver for 2.0.30:
10 * 1. WL24xx packet drivers (tooasm.asm)
11 * 2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
13 * 4. Linux network driver (/usr/src/linux/drivers/net)
14 * 5. ISA card driver - wl24.c
15 * 6. Linux PCMCIA skeleton driver - skeleton.c
16 * 7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
18 * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
19 * 1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
20 * rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
21 * (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
22 * ETHER/IP/UDP/TCP header, and acknowledgement overhead)
24 * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
25 * 173 Kbytes/s in TCP.
27 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
28 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
31 #include <linux/delay.h>
32 #include <linux/types.h>
33 #include <linux/interrupt.h>
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/fcntl.h>
38 #include <linux/if_arp.h>
39 #include <linux/ioport.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
43 #include <linux/slab.h>
44 #include <linux/string.h>
45 #include <linux/wireless.h>
46 #include <net/cfg80211.h>
48 #include <net/iw_handler.h>
50 #include <pcmcia/cistpl.h>
51 #include <pcmcia/cisreg.h>
52 #include <pcmcia/ds.h>
55 #include <linux/uaccess.h>
60 #define slow_down_io()
63 /* For rough constant delay */
64 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
68 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
69 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
70 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
72 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
73 #define WL3501_MAX_ADHOC_TRIES 16
75 #define WL3501_RESUME 0
76 #define WL3501_SUSPEND 1
78 static int wl3501_config(struct pcmcia_device *link);
79 static void wl3501_release(struct pcmcia_device *link);
84 } iw_channel_table[] = {
86 .reg_domain = IW_REG_DOMAIN_FCC,
92 .reg_domain = IW_REG_DOMAIN_DOC,
98 .reg_domain = IW_REG_DOMAIN_ETSI,
104 .reg_domain = IW_REG_DOMAIN_SPAIN,
110 .reg_domain = IW_REG_DOMAIN_FRANCE,
116 .reg_domain = IW_REG_DOMAIN_MKK,
122 .reg_domain = IW_REG_DOMAIN_MKK1,
128 .reg_domain = IW_REG_DOMAIN_ISRAEL,
136 * iw_valid_channel - validate channel in regulatory domain
137 * @reg_domain: regulatory domain
138 * @channel: channel to validate
140 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
142 static int iw_valid_channel(int reg_domain, int channel)
146 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
147 if (reg_domain == iw_channel_table[i].reg_domain) {
148 rc = channel >= iw_channel_table[i].min &&
149 channel <= iw_channel_table[i].max;
156 * iw_default_channel - get default channel for a regulatory domain
157 * @reg_domain: regulatory domain
159 * Returns the default channel for a regulatory domain
161 static int iw_default_channel(int reg_domain)
165 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
166 if (reg_domain == iw_channel_table[i].reg_domain) {
167 rc = iw_channel_table[i].deflt;
173 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
174 struct iw_mgmt_info_element *el,
175 void *value, int len)
179 memcpy(el->data, value, len);
182 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
183 struct iw_mgmt_info_element *from)
185 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
188 static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
190 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
194 * Get Ethernet MAC address.
196 * WARNING: We switch to FPAGE0 and switc back again.
197 * Making sure there is no other WL function beening called by ISR.
199 static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
201 int base_addr = this->base_addr;
204 wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
205 wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL); /* LMAL */
206 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH); /* LMAH */
208 /* wait for reading EEPROM */
210 this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
212 this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
214 this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
216 this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
218 this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
220 this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
222 this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
224 wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
225 wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
226 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
228 this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
230 this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
231 /* switch to SRAM Page 0 (for safety) */
232 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
234 /* The MAC addr should be 00:60:... */
235 return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
239 * wl3501_set_to_wla - Move 'size' bytes from PC to card
241 * @dest: Card addressing space
242 * @src: PC addressing space
243 * @size: Bytes to move
245 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
247 static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
250 /* switch to SRAM Page 0 */
251 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
253 /* set LMAL and LMAH */
254 wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
255 wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
257 /* rep out to Port A */
258 wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
262 * wl3501_get_from_wla - Move 'size' bytes from card to PC
264 * @src: Card addressing space
265 * @dest: PC addressing space
266 * @size: Bytes to move
268 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
270 static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
273 /* switch to SRAM Page 0 */
274 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
276 /* set LMAL and LMAH */
277 wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
278 wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
280 /* rep get from Port A */
281 insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
285 * Get/Allocate a free Tx Data Buffer
287 * *--------------*-----------------*----------------------------------*
288 * | PLCP | MAC Header | DST SRC Data ... |
289 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
290 * *--------------*-----------------*----------------------------------*
291 * \ \- IEEE 802.11 -/ \-------------- len --------------/
292 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
294 * Return = Position in Card
296 static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
298 u16 next, blk_cnt = 0, zero = 0;
299 u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
302 if (full_len > this->tx_buffer_cnt * 254)
304 ret = this->tx_buffer_head;
310 wl3501_get_from_wla(this, this->tx_buffer_head, &next,
313 wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
315 this->tx_buffer_head = next;
317 /* if buffer is not enough */
318 if (!next && full_len) {
319 this->tx_buffer_head = ret;
324 this->tx_buffer_cnt -= blk_cnt;
330 * Free an allocated Tx Buffer. ptr must be correct position.
332 static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
334 /* check if all space is not free */
335 if (!this->tx_buffer_head)
336 this->tx_buffer_head = ptr;
338 wl3501_set_to_wla(this, this->tx_buffer_tail,
343 this->tx_buffer_cnt++;
344 wl3501_get_from_wla(this, ptr, &next, sizeof(next));
345 this->tx_buffer_tail = ptr;
350 static int wl3501_esbq_req_test(struct wl3501_card *this)
354 wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
358 static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
362 wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
363 wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
364 this->esbq_req_head += 4;
365 if (this->esbq_req_head >= this->esbq_req_end)
366 this->esbq_req_head = this->esbq_req_start;
369 static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
373 if (wl3501_esbq_req_test(this)) {
374 u16 ptr = wl3501_get_tx_buffer(this, sig_size);
376 wl3501_set_to_wla(this, ptr, sig, sig_size);
377 wl3501_esbq_req(this, &ptr);
384 static int wl3501_request_mib(struct wl3501_card *this, u8 index, void *bf)
386 struct wl3501_get_req sig = {
387 .sig_id = WL3501_SIG_GET_REQ,
393 spin_lock_irqsave(&this->lock, flags);
394 if (wl3501_esbq_req_test(this)) {
395 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
397 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
398 wl3501_esbq_req(this, &ptr);
399 this->sig_get_confirm.mib_status = 255;
403 spin_unlock_irqrestore(&this->lock, flags);
408 static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
413 rc = wl3501_request_mib(this, index, bf);
417 rc = wait_event_interruptible(this->wait,
418 this->sig_get_confirm.mib_status != 255);
422 memcpy(bf, this->sig_get_confirm.mib_value, size);
426 static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
428 struct wl3501_pwr_mgmt_req sig = {
429 .sig_id = WL3501_SIG_PWR_MGMT_REQ,
437 spin_lock_irqsave(&this->lock, flags);
438 if (wl3501_esbq_req_test(this)) {
439 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
441 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
442 wl3501_esbq_req(this, &ptr);
443 this->sig_pwr_mgmt_confirm.status = 255;
444 spin_unlock_irqrestore(&this->lock, flags);
445 rc = wait_event_interruptible(this->wait,
446 this->sig_pwr_mgmt_confirm.status != 255);
447 printk(KERN_INFO "%s: %s status=%d\n", __func__,
448 suspend ? "suspend" : "resume",
449 this->sig_pwr_mgmt_confirm.status);
453 spin_unlock_irqrestore(&this->lock, flags);
459 * wl3501_send_pkt - Send a packet.
461 * @data: Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
462 * data[6] - data[11] is Src MAC Addr)
463 * @len: Packet length
466 static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
468 u16 bf, sig_bf, next, tmplen, pktlen;
469 struct wl3501_md_req sig = {
470 .sig_id = WL3501_SIG_MD_REQ,
472 size_t sig_addr_len = sizeof(sig.addr);
473 u8 *pdata = (char *)data;
476 if (wl3501_esbq_req_test(this)) {
477 sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
479 if (!sig_bf) /* No free buffer available */
481 bf = wl3501_get_tx_buffer(this, len + 26 + 24);
483 /* No free buffer available */
484 wl3501_free_tx_buffer(this, sig_bf);
488 memcpy(&sig.addr, pdata, sig_addr_len);
489 pktlen = len - sig_addr_len;
490 pdata += sig_addr_len;
492 if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
493 u8 addr4[ETH_ALEN] = {
494 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
497 wl3501_set_to_wla(this, bf + 2 +
498 offsetof(struct wl3501_tx_hdr, addr4),
499 addr4, sizeof(addr4));
500 sig.size = pktlen + 24 + 4 + 6;
501 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
502 tmplen = 254 - sizeof(struct wl3501_tx_hdr);
508 wl3501_set_to_wla(this,
509 bf + 2 + sizeof(struct wl3501_tx_hdr),
512 wl3501_get_from_wla(this, bf, &next, sizeof(next));
515 sig.size = pktlen + 24 + 4 - 2;
518 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
519 tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
525 wl3501_set_to_wla(this, bf + 2 +
526 offsetof(struct wl3501_tx_hdr, addr4),
529 wl3501_get_from_wla(this, bf, &next, sizeof(next));
540 wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
542 wl3501_get_from_wla(this, bf, &next, sizeof(next));
545 wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
546 wl3501_esbq_req(this, &sig_bf);
552 static int wl3501_mgmt_resync(struct wl3501_card *this)
554 struct wl3501_resync_req sig = {
555 .sig_id = WL3501_SIG_RESYNC_REQ,
558 return wl3501_esbq_exec(this, &sig, sizeof(sig));
561 static inline int wl3501_fw_bss_type(struct wl3501_card *this)
563 return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
564 WL3501_NET_TYPE_ADHOC;
567 static inline int wl3501_fw_cap_info(struct wl3501_card *this)
569 return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
570 WL3501_MGMT_CAPABILITY_IBSS;
573 static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
575 struct wl3501_scan_req sig = {
576 .sig_id = WL3501_SIG_SCAN_REQ,
577 .scan_type = WL3501_SCAN_TYPE_ACTIVE,
579 .min_chan_time = chan_time,
580 .max_chan_time = chan_time,
581 .bss_type = wl3501_fw_bss_type(this),
584 this->bss_cnt = this->join_sta_bss = 0;
585 return wl3501_esbq_exec(this, &sig, sizeof(sig));
588 static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
590 struct wl3501_join_req sig = {
591 .sig_id = WL3501_SIG_JOIN_REQ,
595 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
602 memcpy(&sig.req, &this->bss_set[stas].req, sizeof(sig.req));
603 return wl3501_esbq_exec(this, &sig, sizeof(sig));
606 static int wl3501_mgmt_start(struct wl3501_card *this)
608 struct wl3501_start_req sig = {
609 .sig_id = WL3501_SIG_START_REQ,
610 .beacon_period = 400,
614 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
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,
631 .operational_rset = {
633 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
636 .data_rate_labels = {
637 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
638 IW_MGMT_RATE_LABEL_1MBIT,
639 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
640 IW_MGMT_RATE_LABEL_2MBIT,
645 .id = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
650 .bss_type = wl3501_fw_bss_type(this),
651 .cap_info = wl3501_fw_cap_info(this),
654 iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
655 iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
656 return wl3501_esbq_exec(this, &sig, sizeof(sig));
659 static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
663 struct wl3501_scan_confirm sig;
666 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
667 if (sig.status == WL3501_STATUS_SUCCESS) {
669 if ((this->net_type == IW_MODE_INFRA &&
670 (sig.req.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
671 (this->net_type == IW_MODE_ADHOC &&
672 (sig.req.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
673 this->net_type == IW_MODE_AUTO) {
674 if (!this->essid.el.len)
676 else if (this->essid.el.len == 3 &&
677 !memcmp(this->essid.essid, "ANY", 3))
679 else if (this->essid.el.len != sig.req.ssid.el.len)
681 else if (memcmp(this->essid.essid, sig.req.ssid.essid,
687 for (i = 0; i < this->bss_cnt; i++) {
688 if (ether_addr_equal_unaligned(this->bss_set[i].req.bssid,
695 if (matchflag && (i < 20)) {
696 memcpy(&this->bss_set[i].req,
697 &sig.req, sizeof(sig.req));
699 this->rssi = sig.rssi;
700 this->bss_set[i].rssi = sig.rssi;
703 } else if (sig.status == WL3501_STATUS_TIMEOUT) {
705 this->join_sta_bss = 0;
706 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
707 if (!wl3501_mgmt_join(this, i))
709 this->join_sta_bss = i;
710 if (this->join_sta_bss == this->bss_cnt) {
711 if (this->net_type == IW_MODE_INFRA)
712 wl3501_mgmt_scan(this, 100);
715 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
716 wl3501_mgmt_start(this);
718 wl3501_mgmt_scan(this, 100);
725 * wl3501_block_interrupt - Mask interrupt from SUTRO
728 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
729 * Return: 1 if interrupt is originally enabled
731 static int wl3501_block_interrupt(struct wl3501_card *this)
733 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
734 u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
735 WL3501_GCR_ENECINT));
737 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
738 return old & WL3501_GCR_ENECINT;
742 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
745 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
746 * Return: 1 if interrupt is originally enabled
748 static int wl3501_unblock_interrupt(struct wl3501_card *this)
750 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
751 u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
754 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
755 return old & WL3501_GCR_ENECINT;
759 * wl3501_receive - Receive data from Receive Queue.
761 * Receive data from Receive Queue.
764 * @bf: address of host
765 * @size: size of buffer.
767 static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
769 u16 next_addr, next_addr1;
773 wl3501_get_from_wla(this, this->start_seg + 2,
774 &next_addr, sizeof(next_addr));
775 if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
776 wl3501_get_from_wla(this,
778 sizeof(struct wl3501_rx_hdr), data,
780 sizeof(struct wl3501_rx_hdr));
781 size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
782 data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
784 wl3501_get_from_wla(this,
786 sizeof(struct wl3501_rx_hdr),
791 if (size > WL3501_BLKSZ - 5) {
792 wl3501_get_from_wla(this, next_addr + 5, data,
794 size -= WL3501_BLKSZ - 5;
795 data += WL3501_BLKSZ - 5;
796 wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
798 next_addr = next_addr1;
800 wl3501_get_from_wla(this, next_addr + 5, data, size);
807 static void wl3501_esbq_req_free(struct wl3501_card *this)
812 if (this->esbq_req_head == this->esbq_req_tail)
814 wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
817 wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
818 wl3501_free_tx_buffer(this, addr);
819 this->esbq_req_tail += 4;
820 if (this->esbq_req_tail >= this->esbq_req_end)
821 this->esbq_req_tail = this->esbq_req_start;
826 static int wl3501_esbq_confirm(struct wl3501_card *this)
830 wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
834 static void wl3501_online(struct net_device *dev)
836 struct wl3501_card *this = netdev_priv(dev);
838 printk(KERN_INFO "%s: Wireless LAN online. BSSID: %pM\n",
839 dev->name, this->bssid);
840 netif_wake_queue(dev);
843 static void wl3501_esbq_confirm_done(struct wl3501_card *this)
847 wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
848 this->esbq_confirm += 4;
849 if (this->esbq_confirm >= this->esbq_confirm_end)
850 this->esbq_confirm = this->esbq_confirm_start;
853 static int wl3501_mgmt_auth(struct wl3501_card *this)
855 struct wl3501_auth_req sig = {
856 .sig_id = WL3501_SIG_AUTH_REQ,
857 .type = WL3501_SYS_TYPE_OPEN,
862 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
863 return wl3501_esbq_exec(this, &sig, sizeof(sig));
866 static int wl3501_mgmt_association(struct wl3501_card *this)
868 struct wl3501_assoc_req sig = {
869 .sig_id = WL3501_SIG_ASSOC_REQ,
871 .listen_interval = 5,
872 .cap_info = this->cap_info,
876 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
877 return wl3501_esbq_exec(this, &sig, sizeof(sig));
880 static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
882 struct wl3501_card *this = netdev_priv(dev);
883 struct wl3501_join_confirm sig;
886 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
887 if (sig.status == WL3501_STATUS_SUCCESS) {
888 if (this->net_type == IW_MODE_INFRA) {
889 if (this->join_sta_bss < this->bss_cnt) {
890 const int i = this->join_sta_bss;
892 this->bss_set[i].req.bssid, ETH_ALEN);
893 this->chan = this->bss_set[i].req.ds_pset.chan;
894 iw_copy_mgmt_info_element(&this->keep_essid.el,
895 &this->bss_set[i].req.ssid.el);
896 wl3501_mgmt_auth(this);
899 const int i = this->join_sta_bss;
901 memcpy(&this->bssid, &this->bss_set[i].req.bssid, ETH_ALEN);
902 this->chan = this->bss_set[i].req.ds_pset.chan;
903 iw_copy_mgmt_info_element(&this->keep_essid.el,
904 &this->bss_set[i].req.ssid.el);
909 this->join_sta_bss++;
910 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
911 if (!wl3501_mgmt_join(this, i))
913 this->join_sta_bss = i;
914 if (this->join_sta_bss == this->bss_cnt) {
915 if (this->net_type == IW_MODE_INFRA)
916 wl3501_mgmt_scan(this, 100);
919 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
920 wl3501_mgmt_start(this);
922 wl3501_mgmt_scan(this, 100);
928 static inline void wl3501_alarm_interrupt(struct net_device *dev,
929 struct wl3501_card *this)
931 if (this->net_type == IW_MODE_INFRA) {
932 printk(KERN_INFO "Wireless LAN offline\n");
933 netif_stop_queue(dev);
934 wl3501_mgmt_resync(this);
938 static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
939 struct wl3501_card *this,
942 struct wl3501_md_confirm sig;
945 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
946 wl3501_free_tx_buffer(this, sig.data);
947 if (netif_queue_stopped(dev))
948 netif_wake_queue(dev);
951 static inline void wl3501_md_ind_interrupt(struct net_device *dev,
952 struct wl3501_card *this, u16 addr)
954 struct wl3501_md_ind sig;
956 u8 rssi, addr4[ETH_ALEN];
959 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
960 this->start_seg = sig.data;
961 wl3501_get_from_wla(this,
962 sig.data + offsetof(struct wl3501_rx_hdr, rssi),
963 &rssi, sizeof(rssi));
964 this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
966 wl3501_get_from_wla(this,
968 offsetof(struct wl3501_rx_hdr, addr4),
969 &addr4, sizeof(addr4));
970 if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
971 addr4[2] == 0x03 && addr4[4] == 0x00)) {
972 printk(KERN_INFO "Unsupported packet type!\n");
975 pkt_len = sig.size + 12 - 24 - 4 - 6;
977 skb = dev_alloc_skb(pkt_len + 5);
980 printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
982 dev->stats.rx_dropped++;
985 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
986 skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
988 wl3501_receive(this, skb->data, pkt_len);
989 skb_put(skb, pkt_len);
990 skb->protocol = eth_type_trans(skb, dev);
991 dev->stats.rx_packets++;
992 dev->stats.rx_bytes += skb->len;
997 static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
998 u16 addr, void *sig, int size)
1001 wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
1002 sizeof(this->sig_get_confirm));
1003 wake_up(&this->wait);
1006 static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
1007 struct wl3501_card *this,
1010 struct wl3501_start_confirm sig;
1013 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1014 if (sig.status == WL3501_STATUS_SUCCESS)
1015 netif_wake_queue(dev);
1018 static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
1021 struct wl3501_card *this = netdev_priv(dev);
1022 struct wl3501_assoc_confirm sig;
1025 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1027 if (sig.status == WL3501_STATUS_SUCCESS)
1031 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
1034 struct wl3501_auth_confirm sig;
1037 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1039 if (sig.status == WL3501_STATUS_SUCCESS)
1040 wl3501_mgmt_association(this);
1042 wl3501_mgmt_resync(this);
1045 static inline void wl3501_rx_interrupt(struct net_device *dev)
1050 struct wl3501_card *this = netdev_priv(dev);
1055 if (!wl3501_esbq_confirm(this))
1057 wl3501_get_from_wla(this, this->esbq_confirm, &addr, sizeof(addr));
1058 wl3501_get_from_wla(this, addr + 2, &sig_id, sizeof(sig_id));
1061 case WL3501_SIG_DEAUTH_IND:
1062 case WL3501_SIG_DISASSOC_IND:
1063 case WL3501_SIG_ALARM:
1064 wl3501_alarm_interrupt(dev, this);
1066 case WL3501_SIG_MD_CONFIRM:
1067 wl3501_md_confirm_interrupt(dev, this, addr);
1069 case WL3501_SIG_MD_IND:
1070 wl3501_md_ind_interrupt(dev, this, addr);
1072 case WL3501_SIG_GET_CONFIRM:
1073 wl3501_get_confirm_interrupt(this, addr,
1074 &this->sig_get_confirm,
1075 sizeof(this->sig_get_confirm));
1077 case WL3501_SIG_PWR_MGMT_CONFIRM:
1078 wl3501_get_confirm_interrupt(this, addr,
1079 &this->sig_pwr_mgmt_confirm,
1080 sizeof(this->sig_pwr_mgmt_confirm));
1082 case WL3501_SIG_START_CONFIRM:
1083 wl3501_start_confirm_interrupt(dev, this, addr);
1085 case WL3501_SIG_SCAN_CONFIRM:
1086 wl3501_mgmt_scan_confirm(this, addr);
1088 case WL3501_SIG_JOIN_CONFIRM:
1089 wl3501_mgmt_join_confirm(dev, addr);
1091 case WL3501_SIG_ASSOC_CONFIRM:
1092 wl3501_assoc_confirm_interrupt(dev, addr);
1094 case WL3501_SIG_AUTH_CONFIRM:
1095 wl3501_auth_confirm_interrupt(this, addr);
1097 case WL3501_SIG_RESYNC_CONFIRM:
1098 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1101 wl3501_esbq_confirm_done(this);
1103 /* free request if necessary */
1105 wl3501_esbq_req_free(this);
1110 static inline void wl3501_ack_interrupt(struct wl3501_card *this)
1112 wl3501_outb(WL3501_GCR_ECINT, this->base_addr + WL3501_NIC_GCR);
1116 * wl3501_interrupt - Hardware interrupt from card.
1117 * @irq: Interrupt number
1118 * @dev_id: net_device
1120 * We must acknowledge the interrupt as soon as possible, and block the
1121 * interrupt from the same card immediately to prevent re-entry.
1123 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1124 * On the other hand, to prevent SUTRO from malfunctioning, we must
1125 * unlock the SUTRO as soon as possible.
1127 static irqreturn_t wl3501_interrupt(int irq, void *dev_id)
1129 struct net_device *dev = dev_id;
1130 struct wl3501_card *this;
1132 this = netdev_priv(dev);
1133 spin_lock(&this->lock);
1134 wl3501_ack_interrupt(this);
1135 wl3501_block_interrupt(this);
1136 wl3501_rx_interrupt(dev);
1137 wl3501_unblock_interrupt(this);
1138 spin_unlock(&this->lock);
1143 static int wl3501_reset_board(struct wl3501_card *this)
1149 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1150 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1151 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1153 /* Reset SRAM 0x480 to zero */
1154 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1157 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1159 WL3501_NOPLOOP(1024 * 50);
1161 wl3501_unblock_interrupt(this); /* acme: was commented */
1163 /* Polling Self_Test_Status */
1164 for (i = 0; i < 10000; i++) {
1165 wl3501_get_from_wla(this, 0x480, &tmp, sizeof(tmp));
1168 /* firmware complete all test successfully */
1170 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1175 printk(KERN_WARNING "%s: failed to reset the board!\n", __func__);
1181 static int wl3501_init_firmware(struct wl3501_card *this)
1184 int rc = wl3501_reset_board(this);
1188 this->card_name[0] = '\0';
1189 wl3501_get_from_wla(this, 0x1a00,
1190 this->card_name, sizeof(this->card_name));
1191 this->card_name[sizeof(this->card_name) - 1] = '\0';
1192 this->firmware_date[0] = '\0';
1193 wl3501_get_from_wla(this, 0x1a40,
1194 this->firmware_date, sizeof(this->firmware_date));
1195 this->firmware_date[sizeof(this->firmware_date) - 1] = '\0';
1196 /* Switch to SRAM Page 0 */
1197 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
1198 /* Read parameter from card */
1199 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start, 2);
1200 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end, 2);
1201 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start, 2);
1202 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end, 2);
1203 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head, 2);
1204 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size, 2);
1205 this->esbq_req_tail = this->esbq_req_head = this->esbq_req_start;
1206 this->esbq_req_end += this->esbq_req_start;
1207 this->esbq_confirm = this->esbq_confirm_start;
1208 this->esbq_confirm_end += this->esbq_confirm_start;
1209 /* Initial Tx Buffer */
1210 this->tx_buffer_cnt = 1;
1211 ptr = this->tx_buffer_head;
1212 next = ptr + WL3501_BLKSZ;
1213 while ((next - this->tx_buffer_head) < this->tx_buffer_size) {
1214 this->tx_buffer_cnt++;
1215 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1217 next = ptr + WL3501_BLKSZ;
1221 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1222 this->tx_buffer_tail = ptr;
1226 printk(KERN_WARNING "%s: failed!\n", __func__);
1230 static int wl3501_close(struct net_device *dev)
1232 struct wl3501_card *this = netdev_priv(dev);
1233 unsigned long flags;
1234 struct pcmcia_device *link;
1237 spin_lock_irqsave(&this->lock, flags);
1240 /* Stop wl3501_hard_start_xmit() from now on */
1241 netif_stop_queue(dev);
1242 wl3501_ack_interrupt(this);
1244 /* Mask interrupts from the SUTRO */
1245 wl3501_block_interrupt(this);
1247 printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
1248 spin_unlock_irqrestore(&this->lock, flags);
1253 * wl3501_reset - Reset the SUTRO.
1254 * @dev: network device
1256 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1257 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1258 * is running. It seems to be dangerous.
1260 static int wl3501_reset(struct net_device *dev)
1262 struct wl3501_card *this = netdev_priv(dev);
1264 unsigned long flags;
1266 spin_lock_irqsave(&this->lock, flags);
1267 wl3501_block_interrupt(this);
1269 if (wl3501_init_firmware(this)) {
1270 printk(KERN_WARNING "%s: Can't initialize Firmware!\n",
1272 /* Free IRQ, and mark IRQ as unused */
1273 free_irq(dev->irq, dev);
1278 * Queue has to be started only when the Card is Started
1280 netif_stop_queue(dev);
1281 this->adhoc_times = 0;
1282 wl3501_ack_interrupt(this);
1283 wl3501_unblock_interrupt(this);
1284 wl3501_mgmt_scan(this, 100);
1285 pr_debug("%s: device reset", dev->name);
1288 spin_unlock_irqrestore(&this->lock, flags);
1292 static void wl3501_tx_timeout(struct net_device *dev, unsigned int txqueue)
1294 struct net_device_stats *stats = &dev->stats;
1298 rc = wl3501_reset(dev);
1300 printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
1303 netif_trans_update(dev); /* prevent tx timeout */
1304 netif_wake_queue(dev);
1310 * 1 - Could not transmit (dev_queue_xmit will queue it)
1311 * and try to sent it later
1313 static netdev_tx_t wl3501_hard_start_xmit(struct sk_buff *skb,
1314 struct net_device *dev)
1317 struct wl3501_card *this = netdev_priv(dev);
1318 unsigned long flags;
1320 spin_lock_irqsave(&this->lock, flags);
1321 enabled = wl3501_block_interrupt(this);
1322 rc = wl3501_send_pkt(this, skb->data, skb->len);
1324 wl3501_unblock_interrupt(this);
1326 ++dev->stats.tx_dropped;
1327 netif_stop_queue(dev);
1329 ++dev->stats.tx_packets;
1330 dev->stats.tx_bytes += skb->len;
1333 if (this->tx_buffer_cnt < 2)
1334 netif_stop_queue(dev);
1336 spin_unlock_irqrestore(&this->lock, flags);
1337 return NETDEV_TX_OK;
1340 static int wl3501_open(struct net_device *dev)
1343 struct wl3501_card *this = netdev_priv(dev);
1344 unsigned long flags;
1345 struct pcmcia_device *link;
1348 spin_lock_irqsave(&this->lock, flags);
1349 if (!pcmcia_dev_present(link))
1351 netif_device_attach(dev);
1354 /* Initial WL3501 firmware */
1355 pr_debug("%s: Initialize WL3501 firmware...", dev->name);
1356 if (wl3501_init_firmware(this))
1358 /* Initial device variables */
1359 this->adhoc_times = 0;
1360 /* Acknowledge Interrupt, for cleaning last state */
1361 wl3501_ack_interrupt(this);
1363 /* Enable interrupt from card after all */
1364 wl3501_unblock_interrupt(this);
1365 wl3501_mgmt_scan(this, 100);
1367 pr_debug("%s: WL3501 opened", dev->name);
1368 printk(KERN_INFO "%s: Card Name: %s\n"
1369 "%s: Firmware Date: %s\n",
1370 dev->name, this->card_name,
1371 dev->name, this->firmware_date);
1373 spin_unlock_irqrestore(&this->lock, flags);
1376 printk(KERN_WARNING "%s: Can't initialize firmware!\n", dev->name);
1380 static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
1382 struct wl3501_card *this = netdev_priv(dev);
1383 struct iw_statistics *wstats = &this->wstats;
1384 u32 value; /* size checked: it is u32 */
1386 memset(wstats, 0, sizeof(*wstats));
1387 wstats->status = netif_running(dev);
1388 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT,
1389 &value, sizeof(value)))
1390 wstats->discard.code += value;
1391 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT,
1392 &value, sizeof(value)))
1393 wstats->discard.code += value;
1394 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT,
1395 &value, sizeof(value)))
1396 wstats->discard.code += value;
1397 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT,
1398 &value, sizeof(value)))
1399 wstats->discard.retries = value;
1400 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT,
1401 &value, sizeof(value)))
1402 wstats->discard.misc += value;
1403 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT,
1404 &value, sizeof(value)))
1405 wstats->discard.misc += value;
1406 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT,
1407 &value, sizeof(value)))
1408 wstats->discard.misc += value;
1409 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT,
1410 &value, sizeof(value)))
1411 wstats->discard.misc += value;
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);
1441 static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
1442 union iwreq_data *wrqu, char *extra)
1444 strlcpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
1448 static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
1449 union iwreq_data *wrqu, char *extra)
1451 struct wl3501_card *this = netdev_priv(dev);
1452 int channel = wrqu->freq.m;
1455 if (iw_valid_channel(this->reg_domain, channel)) {
1456 this->chan = channel;
1457 rc = wl3501_reset(dev);
1462 static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
1463 union iwreq_data *wrqu, char *extra)
1465 struct wl3501_card *this = netdev_priv(dev);
1467 wrqu->freq.m = 100000 *
1468 ieee80211_channel_to_frequency(this->chan, NL80211_BAND_2GHZ);
1473 static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
1474 union iwreq_data *wrqu, char *extra)
1478 if (wrqu->mode == IW_MODE_INFRA ||
1479 wrqu->mode == IW_MODE_ADHOC ||
1480 wrqu->mode == IW_MODE_AUTO) {
1481 struct wl3501_card *this = netdev_priv(dev);
1483 this->net_type = wrqu->mode;
1484 rc = wl3501_reset(dev);
1489 static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
1490 union iwreq_data *wrqu, char *extra)
1492 struct wl3501_card *this = netdev_priv(dev);
1494 wrqu->mode = this->net_type;
1498 static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
1499 union iwreq_data *wrqu, char *extra)
1501 struct wl3501_card *this = netdev_priv(dev);
1503 wrqu->sens.value = this->rssi;
1504 wrqu->sens.disabled = !wrqu->sens.value;
1505 wrqu->sens.fixed = 1;
1509 static int wl3501_get_range(struct net_device *dev,
1510 struct iw_request_info *info,
1511 union iwreq_data *wrqu, char *extra)
1513 struct iw_range *range = (struct iw_range *)extra;
1515 /* Set the length (very important for backward compatibility) */
1516 wrqu->data.length = sizeof(*range);
1518 /* Set all the info we don't care or don't know about to zero */
1519 memset(range, 0, sizeof(*range));
1521 /* Set the Wireless Extension versions */
1522 range->we_version_compiled = WIRELESS_EXT;
1523 range->we_version_source = 1;
1524 range->throughput = 2 * 1000 * 1000; /* ~2 Mb/s */
1525 /* FIXME: study the code to fill in more fields... */
1529 static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
1530 union iwreq_data *wrqu, char *extra)
1532 struct wl3501_card *this = netdev_priv(dev);
1535 /* FIXME: we support other ARPHRDs...*/
1536 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
1538 if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data)) {
1539 /* FIXME: rescan? */
1541 memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
1542 /* FIXME: rescan? deassoc & scan? */
1548 static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
1549 union iwreq_data *wrqu, char *extra)
1551 struct wl3501_card *this = netdev_priv(dev);
1553 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1554 memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
1558 static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
1559 union iwreq_data *wrqu, char *extra)
1562 * FIXME: trigger scanning with a reset, yes, I'm lazy
1564 return wl3501_reset(dev);
1567 static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
1568 union iwreq_data *wrqu, char *extra)
1570 struct wl3501_card *this = netdev_priv(dev);
1572 char *current_ev = extra;
1573 struct iw_event iwe;
1575 for (i = 0; i < this->bss_cnt; ++i) {
1576 iwe.cmd = SIOCGIWAP;
1577 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1578 memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].req.bssid, ETH_ALEN);
1579 current_ev = iwe_stream_add_event(info, current_ev,
1580 extra + IW_SCAN_MAX_DATA,
1581 &iwe, IW_EV_ADDR_LEN);
1582 iwe.cmd = SIOCGIWESSID;
1583 iwe.u.data.flags = 1;
1584 iwe.u.data.length = this->bss_set[i].req.ssid.el.len;
1585 current_ev = iwe_stream_add_point(info, current_ev,
1586 extra + IW_SCAN_MAX_DATA,
1588 this->bss_set[i].req.ssid.essid);
1589 iwe.cmd = SIOCGIWMODE;
1590 iwe.u.mode = this->bss_set[i].req.bss_type;
1591 current_ev = iwe_stream_add_event(info, current_ev,
1592 extra + IW_SCAN_MAX_DATA,
1593 &iwe, IW_EV_UINT_LEN);
1594 iwe.cmd = SIOCGIWFREQ;
1595 iwe.u.freq.m = this->bss_set[i].req.ds_pset.chan;
1597 current_ev = iwe_stream_add_event(info, current_ev,
1598 extra + IW_SCAN_MAX_DATA,
1599 &iwe, IW_EV_FREQ_LEN);
1600 iwe.cmd = SIOCGIWENCODE;
1601 if (this->bss_set[i].req.cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1602 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1604 iwe.u.data.flags = IW_ENCODE_DISABLED;
1605 iwe.u.data.length = 0;
1606 current_ev = iwe_stream_add_point(info, current_ev,
1607 extra + IW_SCAN_MAX_DATA,
1610 /* Length of data */
1611 wrqu->data.length = (current_ev - extra);
1612 wrqu->data.flags = 0; /* FIXME: set properly these flags */
1616 static int wl3501_set_essid(struct net_device *dev,
1617 struct iw_request_info *info,
1618 union iwreq_data *wrqu, char *extra)
1620 struct wl3501_card *this = netdev_priv(dev);
1622 if (wrqu->data.flags) {
1623 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1625 extra, wrqu->data.length);
1626 } else { /* We accept any ESSID */
1627 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1628 &this->essid.el, "ANY", 3);
1630 return wl3501_reset(dev);
1633 static int wl3501_get_essid(struct net_device *dev,
1634 struct iw_request_info *info,
1635 union iwreq_data *wrqu, char *extra)
1637 struct wl3501_card *this = netdev_priv(dev);
1638 unsigned long flags;
1640 spin_lock_irqsave(&this->lock, flags);
1641 wrqu->essid.flags = 1;
1642 wrqu->essid.length = this->essid.el.len;
1643 memcpy(extra, this->essid.essid, this->essid.el.len);
1644 spin_unlock_irqrestore(&this->lock, flags);
1648 static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
1649 union iwreq_data *wrqu, char *extra)
1651 struct wl3501_card *this = netdev_priv(dev);
1653 if (wrqu->data.length > sizeof(this->nick))
1655 strlcpy(this->nick, extra, wrqu->data.length);
1659 static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
1660 union iwreq_data *wrqu, char *extra)
1662 struct wl3501_card *this = netdev_priv(dev);
1664 strlcpy(extra, this->nick, 32);
1665 wrqu->data.length = strlen(extra);
1669 static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
1670 union iwreq_data *wrqu, char *extra)
1673 * FIXME: have to see from where to get this info, perhaps this card
1674 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1675 * common with the Planet Access Points. -acme
1677 wrqu->bitrate.value = 2000000;
1678 wrqu->bitrate.fixed = 1;
1682 static int wl3501_get_rts_threshold(struct net_device *dev,
1683 struct iw_request_info *info,
1684 union iwreq_data *wrqu, char *extra)
1686 u16 threshold; /* size checked: it is u16 */
1687 struct wl3501_card *this = netdev_priv(dev);
1688 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
1689 &threshold, sizeof(threshold));
1691 wrqu->rts.value = threshold;
1692 wrqu->rts.disabled = threshold >= 2347;
1693 wrqu->rts.fixed = 1;
1698 static int wl3501_get_frag_threshold(struct net_device *dev,
1699 struct iw_request_info *info,
1700 union iwreq_data *wrqu, char *extra)
1702 u16 threshold; /* size checked: it is u16 */
1703 struct wl3501_card *this = netdev_priv(dev);
1704 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD,
1705 &threshold, sizeof(threshold));
1707 wrqu->frag.value = threshold;
1708 wrqu->frag.disabled = threshold >= 2346;
1709 wrqu->frag.fixed = 1;
1714 static int wl3501_get_txpow(struct net_device *dev,
1715 struct iw_request_info *info,
1716 union iwreq_data *wrqu, char *extra)
1719 struct wl3501_card *this = netdev_priv(dev);
1720 int rc = wl3501_get_mib_value(this,
1721 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
1722 &txpow, sizeof(txpow));
1724 wrqu->txpower.value = txpow;
1725 wrqu->txpower.disabled = 0;
1727 * From the MIB values I think this can be configurable,
1728 * as it lists several tx power levels -acme
1730 wrqu->txpower.fixed = 0;
1731 wrqu->txpower.flags = IW_TXPOW_MWATT;
1736 static int wl3501_get_retry(struct net_device *dev,
1737 struct iw_request_info *info,
1738 union iwreq_data *wrqu, char *extra)
1740 u8 retry; /* size checked: it is u8 */
1741 struct wl3501_card *this = netdev_priv(dev);
1742 int rc = wl3501_get_mib_value(this,
1743 WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
1744 &retry, sizeof(retry));
1747 if (wrqu->retry.flags & IW_RETRY_LONG) {
1748 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1751 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1752 &retry, sizeof(retry));
1755 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1757 wrqu->retry.value = retry;
1758 wrqu->retry.disabled = 0;
1763 static int wl3501_get_encode(struct net_device *dev,
1764 struct iw_request_info *info,
1765 union iwreq_data *wrqu, char *extra)
1767 u8 implemented, restricted, keys[100], len_keys, tocopy;
1768 struct wl3501_card *this = netdev_priv(dev);
1769 int rc = wl3501_get_mib_value(this,
1770 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
1771 &implemented, sizeof(implemented));
1775 wrqu->encoding.flags = IW_ENCODE_DISABLED;
1778 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
1779 &restricted, sizeof(restricted));
1782 wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
1784 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
1785 &len_keys, sizeof(len_keys));
1788 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
1792 tocopy = min_t(u16, len_keys, wrqu->encoding.length);
1793 tocopy = min_t(u8, tocopy, 100);
1794 wrqu->encoding.length = tocopy;
1795 memcpy(extra, keys, tocopy);
1800 static int wl3501_get_power(struct net_device *dev,
1801 struct iw_request_info *info,
1802 union iwreq_data *wrqu, char *extra)
1805 struct wl3501_card *this = netdev_priv(dev);
1806 int rc = wl3501_get_mib_value(this,
1807 WL3501_MIB_ATTR_CURRENT_PWR_STATE,
1808 &pwr_state, sizeof(pwr_state));
1811 wrqu->power.disabled = !pwr_state;
1812 wrqu->power.flags = IW_POWER_ON;
1817 static const iw_handler wl3501_handler[] = {
1818 IW_HANDLER(SIOCGIWNAME, wl3501_get_name),
1819 IW_HANDLER(SIOCSIWFREQ, wl3501_set_freq),
1820 IW_HANDLER(SIOCGIWFREQ, wl3501_get_freq),
1821 IW_HANDLER(SIOCSIWMODE, wl3501_set_mode),
1822 IW_HANDLER(SIOCGIWMODE, wl3501_get_mode),
1823 IW_HANDLER(SIOCGIWSENS, wl3501_get_sens),
1824 IW_HANDLER(SIOCGIWRANGE, wl3501_get_range),
1825 IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1826 IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1827 IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1828 IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1829 IW_HANDLER(SIOCSIWAP, wl3501_set_wap),
1830 IW_HANDLER(SIOCGIWAP, wl3501_get_wap),
1831 IW_HANDLER(SIOCSIWSCAN, wl3501_set_scan),
1832 IW_HANDLER(SIOCGIWSCAN, wl3501_get_scan),
1833 IW_HANDLER(SIOCSIWESSID, wl3501_set_essid),
1834 IW_HANDLER(SIOCGIWESSID, wl3501_get_essid),
1835 IW_HANDLER(SIOCSIWNICKN, wl3501_set_nick),
1836 IW_HANDLER(SIOCGIWNICKN, wl3501_get_nick),
1837 IW_HANDLER(SIOCGIWRATE, wl3501_get_rate),
1838 IW_HANDLER(SIOCGIWRTS, wl3501_get_rts_threshold),
1839 IW_HANDLER(SIOCGIWFRAG, wl3501_get_frag_threshold),
1840 IW_HANDLER(SIOCGIWTXPOW, wl3501_get_txpow),
1841 IW_HANDLER(SIOCGIWRETRY, wl3501_get_retry),
1842 IW_HANDLER(SIOCGIWENCODE, wl3501_get_encode),
1843 IW_HANDLER(SIOCGIWPOWER, wl3501_get_power),
1846 static const struct iw_handler_def wl3501_handler_def = {
1847 .num_standard = ARRAY_SIZE(wl3501_handler),
1848 .standard = (iw_handler *)wl3501_handler,
1849 .get_wireless_stats = wl3501_get_wireless_stats,
1852 static const struct net_device_ops wl3501_netdev_ops = {
1853 .ndo_open = wl3501_open,
1854 .ndo_stop = wl3501_close,
1855 .ndo_start_xmit = wl3501_hard_start_xmit,
1856 .ndo_tx_timeout = wl3501_tx_timeout,
1857 .ndo_set_mac_address = eth_mac_addr,
1858 .ndo_validate_addr = eth_validate_addr,
1861 static int wl3501_probe(struct pcmcia_device *p_dev)
1863 struct net_device *dev;
1864 struct wl3501_card *this;
1866 /* The io structure describes IO port mapping */
1867 p_dev->resource[0]->end = 16;
1868 p_dev->resource[0]->flags = IO_DATA_PATH_WIDTH_8;
1870 /* General socket configuration */
1871 p_dev->config_flags = CONF_ENABLE_IRQ;
1872 p_dev->config_index = 1;
1874 dev = alloc_etherdev(sizeof(struct wl3501_card));
1879 dev->netdev_ops = &wl3501_netdev_ops;
1880 dev->watchdog_timeo = 5 * HZ;
1882 this = netdev_priv(dev);
1883 this->wireless_data.spy_data = &this->spy_data;
1884 this->p_dev = p_dev;
1885 dev->wireless_data = &this->wireless_data;
1886 dev->wireless_handlers = &wl3501_handler_def;
1887 netif_stop_queue(dev);
1890 return wl3501_config(p_dev);
1895 static int wl3501_config(struct pcmcia_device *link)
1897 struct net_device *dev = link->priv;
1899 struct wl3501_card *this;
1901 /* Try allocating IO ports. This tries a few fixed addresses. If you
1902 * want, you can also read the card's config table to pick addresses --
1903 * see the serial driver for an example. */
1906 for (j = 0x280; j < 0x400; j += 0x20) {
1907 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1908 * 0x200-0x2ff, and so on, because this seems safer */
1909 link->resource[0]->start = j;
1910 link->resource[1]->start = link->resource[0]->start + 0x10;
1911 i = pcmcia_request_io(link);
1918 /* Now allocate an interrupt line. Note that this does not actually
1919 * assign a handler to the interrupt. */
1921 ret = pcmcia_request_irq(link, wl3501_interrupt);
1925 ret = pcmcia_enable_device(link);
1929 dev->irq = link->irq;
1930 dev->base_addr = link->resource[0]->start;
1931 SET_NETDEV_DEV(dev, &link->dev);
1932 if (register_netdev(dev)) {
1933 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
1937 this = netdev_priv(dev);
1939 this->base_addr = dev->base_addr;
1941 if (!wl3501_get_flash_mac_addr(this)) {
1942 printk(KERN_WARNING "%s: Can't read MAC addr in flash ROM?\n",
1944 unregister_netdev(dev);
1948 eth_hw_addr_set(dev, this->mac_addr);
1950 /* print probe information */
1951 printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, "
1952 "MAC addr in flash ROM:%pM\n",
1953 dev->name, this->base_addr, (int)dev->irq,
1956 * Initialize card parameters - added by jss
1958 this->net_type = IW_MODE_INFRA;
1960 this->join_sta_bss = 0;
1961 this->adhoc_times = 0;
1962 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
1964 this->card_name[0] = '\0';
1965 this->firmware_date[0] = '\0';
1967 this->chan = iw_default_channel(this->reg_domain);
1968 strlcpy(this->nick, "Planet WL3501", sizeof(this->nick));
1969 spin_lock_init(&this->lock);
1970 init_waitqueue_head(&this->wait);
1971 netif_start_queue(dev);
1975 wl3501_release(link);
1979 static void wl3501_release(struct pcmcia_device *link)
1981 pcmcia_disable_device(link);
1984 static int wl3501_suspend(struct pcmcia_device *link)
1986 struct net_device *dev = link->priv;
1988 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_SUSPEND);
1990 netif_device_detach(dev);
1995 static int wl3501_resume(struct pcmcia_device *link)
1997 struct net_device *dev = link->priv;
1999 wl3501_pwr_mgmt(netdev_priv(dev), WL3501_RESUME);
2002 netif_device_attach(dev);
2009 static const struct pcmcia_device_id wl3501_ids[] = {
2010 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2013 MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2015 static struct pcmcia_driver wl3501_driver = {
2016 .owner = THIS_MODULE,
2017 .name = "wl3501_cs",
2018 .probe = wl3501_probe,
2019 .remove = wl3501_detach,
2020 .id_table = wl3501_ids,
2021 .suspend = wl3501_suspend,
2022 .resume = wl3501_resume,
2024 module_pcmcia_driver(wl3501_driver);
2029 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2030 MODULE_LICENSE("GPL");