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)
29 #undef REALLY_SLOW_IO /* most systems can safely undef this */
31 #include <linux/config.h>
32 #include <linux/delay.h>
33 #include <linux/types.h>
34 #include <linux/ethtool.h>
35 #include <linux/init.h>
36 #include <linux/interrupt.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/fcntl.h>
41 #include <linux/if_arp.h>
42 #include <linux/ioport.h>
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46 #include <linux/slab.h>
47 #include <linux/string.h>
48 #include <linux/wireless.h>
50 #include <net/iw_handler.h>
52 #include <pcmcia/version.h>
53 #include <pcmcia/cs_types.h>
54 #include <pcmcia/cs.h>
55 #include <pcmcia/cistpl.h>
56 #include <pcmcia/cisreg.h>
57 #include <pcmcia/ds.h>
60 #include <asm/uaccess.h>
61 #include <asm/system.h>
66 #define slow_down_io()
69 /* For rough constant delay */
70 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
73 * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If you do not
74 * define PCMCIA_DEBUG at all, all the debug code will be left out. If you
75 * compile with PCMCIA_DEBUG=0, the debug code will be present but disabled --
76 * but it can then be enabled for specific modules at load time with a
77 * 'pc_debug=#' option to insmod.
79 #define PCMCIA_DEBUG 0
81 static int pc_debug
= PCMCIA_DEBUG
;
82 module_param(pc_debug
, int, 0);
83 #define dprintk(n, format, args...) \
84 { if (pc_debug > (n)) \
85 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##args); }
87 #define dprintk(n, format, args...)
90 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
91 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
92 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
94 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
95 #define WL3501_MAX_ADHOC_TRIES 16
97 #define WL3501_RESUME 0
98 #define WL3501_SUSPEND 1
101 * The event() function is this driver's Card Services event handler. It will
102 * be called by Card Services when an appropriate card status event is
103 * received. The config() and release() entry points are used to configure or
104 * release a socket, in response to card insertion and ejection events. They
105 * are invoked from the wl24 event handler.
107 static void wl3501_config(dev_link_t
*link
);
108 static void wl3501_release(dev_link_t
*link
);
109 static int wl3501_event(event_t event
, int pri
, event_callback_args_t
*args
);
112 * The dev_info variable is the "key" that is used to match up this
113 * device driver with appropriate cards, through the card configuration
116 static dev_info_t wl3501_dev_info
= "wl3501_cs";
118 static int wl3501_chan2freq
[] = {
119 [0] = 2412, [1] = 2417, [2] = 2422, [3] = 2427, [4] = 2432,
120 [5] = 2437, [6] = 2442, [7] = 2447, [8] = 2452, [9] = 2457,
121 [10] = 2462, [11] = 2467, [12] = 2472, [13] = 2477,
124 static const struct {
127 } iw_channel_table
[] = {
129 .reg_domain
= IW_REG_DOMAIN_FCC
,
135 .reg_domain
= IW_REG_DOMAIN_DOC
,
141 .reg_domain
= IW_REG_DOMAIN_ETSI
,
147 .reg_domain
= IW_REG_DOMAIN_SPAIN
,
153 .reg_domain
= IW_REG_DOMAIN_FRANCE
,
159 .reg_domain
= IW_REG_DOMAIN_MKK
,
165 .reg_domain
= IW_REG_DOMAIN_MKK1
,
171 .reg_domain
= IW_REG_DOMAIN_ISRAEL
,
179 * iw_valid_channel - validate channel in regulatory domain
180 * @reg_comain - regulatory domain
181 * @channel - channel to validate
183 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
185 static int iw_valid_channel(int reg_domain
, int channel
)
189 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
190 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
191 rc
= channel
>= iw_channel_table
[i
].min
&&
192 channel
<= iw_channel_table
[i
].max
;
199 * iw_default_channel - get default channel for a regulatory domain
200 * @reg_comain - regulatory domain
202 * Returns the default channel for a regulatory domain
204 static int iw_default_channel(int reg_domain
)
208 for (i
= 0; i
< ARRAY_SIZE(iw_channel_table
); i
++)
209 if (reg_domain
== iw_channel_table
[i
].reg_domain
) {
210 rc
= iw_channel_table
[i
].deflt
;
216 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id
,
217 struct iw_mgmt_info_element
*el
,
218 void *value
, int len
)
222 memcpy(el
->data
, value
, len
);
225 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element
*to
,
226 struct iw_mgmt_info_element
*from
)
228 iw_set_mgmt_info_element(from
->id
, to
, from
->data
, from
->len
);
232 * A linked list of "instances" of the wl24 device. Each actual PCMCIA card
233 * corresponds to one device instance, and is described by one dev_link_t
234 * structure (defined in ds.h).
236 * You may not want to use a linked list for this -- for example, the memory
237 * card driver uses an array of dev_link_t pointers, where minor device numbers
238 * are used to derive the corresponding array index.
240 static dev_link_t
*wl3501_dev_list
;
242 static inline void wl3501_switch_page(struct wl3501_card
*this, u8 page
)
244 wl3501_outb(page
, this->base_addr
+ WL3501_NIC_BSS
);
248 * Get Ethernet MAC addresss.
250 * WARNING: We switch to FPAGE0 and switc back again.
251 * Making sure there is no other WL function beening called by ISR.
253 static int wl3501_get_flash_mac_addr(struct wl3501_card
*this)
255 int base_addr
= this->base_addr
;
258 wl3501_outb(WL3501_BSS_FPAGE3
, base_addr
+ WL3501_NIC_BSS
); /* BSS */
259 wl3501_outb(0x00, base_addr
+ WL3501_NIC_LMAL
); /* LMAL */
260 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
); /* LMAH */
262 /* wait for reading EEPROM */
264 this->mac_addr
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
266 this->mac_addr
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
268 this->mac_addr
[2] = inb(base_addr
+ WL3501_NIC_IODPA
);
270 this->mac_addr
[3] = inb(base_addr
+ WL3501_NIC_IODPA
);
272 this->mac_addr
[4] = inb(base_addr
+ WL3501_NIC_IODPA
);
274 this->mac_addr
[5] = inb(base_addr
+ WL3501_NIC_IODPA
);
276 this->reg_domain
= inb(base_addr
+ WL3501_NIC_IODPA
);
278 wl3501_outb(WL3501_BSS_FPAGE0
, base_addr
+ WL3501_NIC_BSS
);
279 wl3501_outb(0x04, base_addr
+ WL3501_NIC_LMAL
);
280 wl3501_outb(0x40, base_addr
+ WL3501_NIC_LMAH
);
282 this->version
[0] = inb(base_addr
+ WL3501_NIC_IODPA
);
284 this->version
[1] = inb(base_addr
+ WL3501_NIC_IODPA
);
285 /* switch to SRAM Page 0 (for safety) */
286 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
288 /* The MAC addr should be 00:60:... */
289 return this->mac_addr
[0] == 0x00 && this->mac_addr
[1] == 0x60;
293 * wl3501_set_to_wla - Move 'size' bytes from PC to card
294 * @dest: Card addressing space
295 * @src: PC addressing space
296 * @size: Bytes to move
298 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
300 void wl3501_set_to_wla(struct wl3501_card
*this, u16 dest
, void *src
, int size
)
302 /* switch to SRAM Page 0 */
303 wl3501_switch_page(this, (dest
& 0x8000) ? WL3501_BSS_SPAGE1
:
305 /* set LMAL and LMAH */
306 wl3501_outb(dest
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
307 wl3501_outb(((dest
>> 8) & 0x7f), this->base_addr
+ WL3501_NIC_LMAH
);
309 /* rep out to Port A */
310 wl3501_outsb(this->base_addr
+ WL3501_NIC_IODPA
, src
, size
);
314 * wl3501_get_from_wla - Move 'size' bytes from card to PC
315 * @src: Card addressing space
316 * @dest: PC addressing space
317 * @size: Bytes to move
319 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
321 void wl3501_get_from_wla(struct wl3501_card
*this, u16 src
, void *dest
,
324 /* switch to SRAM Page 0 */
325 wl3501_switch_page(this, (src
& 0x8000) ? WL3501_BSS_SPAGE1
:
327 /* set LMAL and LMAH */
328 wl3501_outb(src
& 0xff, this->base_addr
+ WL3501_NIC_LMAL
);
329 wl3501_outb((src
>> 8) & 0x7f, this->base_addr
+ WL3501_NIC_LMAH
);
331 /* rep get from Port A */
332 insb(this->base_addr
+ WL3501_NIC_IODPA
, dest
, size
);
336 * Get/Allocate a free Tx Data Buffer
338 * *--------------*-----------------*----------------------------------*
339 * | PLCP | MAC Header | DST SRC Data ... |
340 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
341 * *--------------*-----------------*----------------------------------*
342 * \ \- IEEE 802.11 -/ \-------------- len --------------/
343 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
345 * Return = Postion in Card
347 static u16
wl3501_get_tx_buffer(struct wl3501_card
*this, u16 len
)
349 u16 next
, blk_cnt
= 0, zero
= 0;
350 u16 full_len
= sizeof(struct wl3501_80211_tx_hdr
) + len
;
353 if (full_len
> this->tx_buffer_cnt
* 254)
355 ret
= this->tx_buffer_head
;
361 wl3501_get_from_wla(this, this->tx_buffer_head
, &next
,
364 wl3501_set_to_wla(this, this->tx_buffer_head
, &zero
,
366 this->tx_buffer_head
= next
;
368 /* if buffer is not enough */
369 if (!next
&& full_len
) {
370 this->tx_buffer_head
= ret
;
375 this->tx_buffer_cnt
-= blk_cnt
;
381 * Free an allocated Tx Buffer. ptr must be correct position.
383 static void wl3501_free_tx_buffer(struct wl3501_card
*this, u16 ptr
)
385 /* check if all space is not free */
386 if (!this->tx_buffer_head
)
387 this->tx_buffer_head
= ptr
;
389 wl3501_set_to_wla(this, this->tx_buffer_tail
,
394 this->tx_buffer_cnt
++;
395 wl3501_get_from_wla(this, ptr
, &next
, sizeof(next
));
396 this->tx_buffer_tail
= ptr
;
401 static int wl3501_esbq_req_test(struct wl3501_card
*this)
405 wl3501_get_from_wla(this, this->esbq_req_head
+ 3, &tmp
, sizeof(tmp
));
409 static void wl3501_esbq_req(struct wl3501_card
*this, u16
*ptr
)
413 wl3501_set_to_wla(this, this->esbq_req_head
, ptr
, 2);
414 wl3501_set_to_wla(this, this->esbq_req_head
+ 2, &tmp
, sizeof(tmp
));
415 this->esbq_req_head
+= 4;
416 if (this->esbq_req_head
>= this->esbq_req_end
)
417 this->esbq_req_head
= this->esbq_req_start
;
420 static int wl3501_esbq_exec(struct wl3501_card
*this, void *sig
, int sig_size
)
424 if (wl3501_esbq_req_test(this)) {
425 u16 ptr
= wl3501_get_tx_buffer(this, sig_size
);
427 wl3501_set_to_wla(this, ptr
, sig
, sig_size
);
428 wl3501_esbq_req(this, &ptr
);
435 static int wl3501_get_mib_value(struct wl3501_card
*this, u8 index
,
438 struct wl3501_get_req sig
= {
439 .sig_id
= WL3501_SIG_GET_REQ
,
445 spin_lock_irqsave(&this->lock
, flags
);
446 if (wl3501_esbq_req_test(this)) {
447 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
449 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
450 wl3501_esbq_req(this, &ptr
);
451 this->sig_get_confirm
.mib_status
= 255;
452 spin_unlock_irqrestore(&this->lock
, flags
);
453 rc
= wait_event_interruptible(this->wait
,
454 this->sig_get_confirm
.mib_status
!= 255);
456 memcpy(bf
, this->sig_get_confirm
.mib_value
,
461 spin_unlock_irqrestore(&this->lock
, flags
);
466 static int wl3501_pwr_mgmt(struct wl3501_card
*this, int suspend
)
468 struct wl3501_pwr_mgmt_req sig
= {
469 .sig_id
= WL3501_SIG_PWR_MGMT_REQ
,
477 spin_lock_irqsave(&this->lock
, flags
);
478 if (wl3501_esbq_req_test(this)) {
479 u16 ptr
= wl3501_get_tx_buffer(this, sizeof(sig
));
481 wl3501_set_to_wla(this, ptr
, &sig
, sizeof(sig
));
482 wl3501_esbq_req(this, &ptr
);
483 this->sig_pwr_mgmt_confirm
.status
= 255;
484 spin_unlock_irqrestore(&this->lock
, flags
);
485 rc
= wait_event_interruptible(this->wait
,
486 this->sig_pwr_mgmt_confirm
.status
!= 255);
487 printk(KERN_INFO
"%s: %s status=%d\n", __FUNCTION__
,
488 suspend
? "suspend" : "resume",
489 this->sig_pwr_mgmt_confirm
.status
);
493 spin_unlock_irqrestore(&this->lock
, flags
);
499 * wl3501_send_pkt - Send a packet.
504 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
505 * data[6] - data[11] is Src MAC Addr)
508 static int wl3501_send_pkt(struct wl3501_card
*this, u8
*data
, u16 len
)
510 u16 bf
, sig_bf
, next
, tmplen
, pktlen
;
511 struct wl3501_md_req sig
= {
512 .sig_id
= WL3501_SIG_MD_REQ
,
514 u8
*pdata
= (char *)data
;
517 if (wl3501_esbq_req_test(this)) {
518 sig_bf
= wl3501_get_tx_buffer(this, sizeof(sig
));
520 if (!sig_bf
) /* No free buffer available */
522 bf
= wl3501_get_tx_buffer(this, len
+ 26 + 24);
524 /* No free buffer available */
525 wl3501_free_tx_buffer(this, sig_bf
);
529 memcpy(&sig
.daddr
[0], pdata
, 12);
533 if (((*pdata
) * 256 + (*(pdata
+ 1))) > 1500) {
534 u8 addr4
[ETH_ALEN
] = {
535 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
538 wl3501_set_to_wla(this, bf
+ 2 +
539 offsetof(struct wl3501_tx_hdr
, addr4
),
540 addr4
, sizeof(addr4
));
541 sig
.size
= pktlen
+ 24 + 4 + 6;
542 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
))) {
543 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
);
549 wl3501_set_to_wla(this,
550 bf
+ 2 + sizeof(struct wl3501_tx_hdr
),
553 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
556 sig
.size
= pktlen
+ 24 + 4 - 2;
559 if (pktlen
> (254 - sizeof(struct wl3501_tx_hdr
) + 6)) {
560 tmplen
= 254 - sizeof(struct wl3501_tx_hdr
) + 6;
566 wl3501_set_to_wla(this, bf
+ 2 +
567 offsetof(struct wl3501_tx_hdr
, addr4
),
570 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
581 wl3501_set_to_wla(this, bf
+ 2, pdata
, tmplen
);
583 wl3501_get_from_wla(this, bf
, &next
, sizeof(next
));
586 wl3501_set_to_wla(this, sig_bf
, &sig
, sizeof(sig
));
587 wl3501_esbq_req(this, &sig_bf
);
593 static int wl3501_mgmt_resync(struct wl3501_card
*this)
595 struct wl3501_resync_req sig
= {
596 .sig_id
= WL3501_SIG_RESYNC_REQ
,
599 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
602 static inline int wl3501_fw_bss_type(struct wl3501_card
*this)
604 return this->net_type
== IW_MODE_INFRA
? WL3501_NET_TYPE_INFRA
:
605 WL3501_NET_TYPE_ADHOC
;
608 static inline int wl3501_fw_cap_info(struct wl3501_card
*this)
610 return this->net_type
== IW_MODE_INFRA
? WL3501_MGMT_CAPABILITY_ESS
:
611 WL3501_MGMT_CAPABILITY_IBSS
;
614 static int wl3501_mgmt_scan(struct wl3501_card
*this, u16 chan_time
)
616 struct wl3501_scan_req sig
= {
617 .sig_id
= WL3501_SIG_SCAN_REQ
,
618 .scan_type
= WL3501_SCAN_TYPE_ACTIVE
,
620 .min_chan_time
= chan_time
,
621 .max_chan_time
= chan_time
,
622 .bss_type
= wl3501_fw_bss_type(this),
625 this->bss_cnt
= this->join_sta_bss
= 0;
626 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
629 static int wl3501_mgmt_join(struct wl3501_card
*this, u16 stas
)
631 struct wl3501_join_req sig
= {
632 .sig_id
= WL3501_SIG_JOIN_REQ
,
636 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
643 memcpy(&sig
.beacon_period
, &this->bss_set
[stas
].beacon_period
, 72);
644 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
647 static int wl3501_mgmt_start(struct wl3501_card
*this)
649 struct wl3501_start_req sig
= {
650 .sig_id
= WL3501_SIG_START_REQ
,
651 .beacon_period
= 400,
655 .id
= IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET
,
662 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
665 .data_rate_labels
= {
666 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
667 IW_MGMT_RATE_LABEL_1MBIT
,
668 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
669 IW_MGMT_RATE_LABEL_2MBIT
,
672 .operational_rset
= {
674 .id
= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES
,
677 .data_rate_labels
= {
678 [0] = IW_MGMT_RATE_LABEL_MANDATORY
|
679 IW_MGMT_RATE_LABEL_1MBIT
,
680 [1] = IW_MGMT_RATE_LABEL_MANDATORY
|
681 IW_MGMT_RATE_LABEL_2MBIT
,
686 .id
= IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET
,
691 .bss_type
= wl3501_fw_bss_type(this),
692 .cap_info
= wl3501_fw_cap_info(this),
695 iw_copy_mgmt_info_element(&sig
.ssid
.el
, &this->essid
.el
);
696 iw_copy_mgmt_info_element(&this->keep_essid
.el
, &this->essid
.el
);
697 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
700 static void wl3501_mgmt_scan_confirm(struct wl3501_card
*this, u16 addr
)
704 struct wl3501_scan_confirm sig
;
707 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
708 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
709 dprintk(3, "success");
710 if ((this->net_type
== IW_MODE_INFRA
&&
711 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_ESS
)) ||
712 (this->net_type
== IW_MODE_ADHOC
&&
713 (sig
.cap_info
& WL3501_MGMT_CAPABILITY_IBSS
)) ||
714 this->net_type
== IW_MODE_AUTO
) {
715 if (!this->essid
.el
.len
)
717 else if (this->essid
.el
.len
== 3 &&
718 !memcmp(this->essid
.essid
, "ANY", 3))
720 else if (this->essid
.el
.len
!= sig
.ssid
.el
.len
)
722 else if (memcmp(this->essid
.essid
, sig
.ssid
.essid
,
728 for (i
= 0; i
< this->bss_cnt
; i
++) {
729 if (!memcmp(this->bss_set
[i
].bssid
,
730 sig
.bssid
, ETH_ALEN
)) {
736 if (matchflag
&& (i
< 20)) {
737 memcpy(&this->bss_set
[i
].beacon_period
,
738 &sig
.beacon_period
, 73);
740 this->rssi
= sig
.rssi
;
743 } else if (sig
.status
== WL3501_STATUS_TIMEOUT
) {
744 dprintk(3, "timeout");
745 this->join_sta_bss
= 0;
746 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
747 if (!wl3501_mgmt_join(this, i
))
749 this->join_sta_bss
= i
;
750 if (this->join_sta_bss
== this->bss_cnt
) {
751 if (this->net_type
== IW_MODE_INFRA
)
752 wl3501_mgmt_scan(this, 100);
755 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
756 wl3501_mgmt_start(this);
758 wl3501_mgmt_scan(this, 100);
765 * wl3501_block_interrupt - Mask interrupt from SUTRO
768 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
769 * Return: 1 if interrupt is originally enabled
771 static int wl3501_block_interrupt(struct wl3501_card
*this)
773 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
774 u8
new = old
& (~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
|
775 WL3501_GCR_ENECINT
));
777 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
778 return old
& WL3501_GCR_ENECINT
;
782 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
785 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
786 * Return: 1 if interrupt is originally enabled
788 static int wl3501_unblock_interrupt(struct wl3501_card
*this)
790 u8 old
= inb(this->base_addr
+ WL3501_NIC_GCR
);
791 u8
new = (old
& ~(WL3501_GCR_ECINT
| WL3501_GCR_INT2EC
)) |
794 wl3501_outb(new, this->base_addr
+ WL3501_NIC_GCR
);
795 return old
& WL3501_GCR_ENECINT
;
799 * wl3501_receive - Receive data from Receive Queue.
801 * Receive data from Receive Queue.
804 * @bf: address of host
805 * @size: size of buffer.
807 static u16
wl3501_receive(struct wl3501_card
*this, u8
*bf
, u16 size
)
809 u16 next_addr
, next_addr1
;
813 wl3501_get_from_wla(this, this->start_seg
+ 2,
814 &next_addr
, sizeof(next_addr
));
815 if (size
> WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
)) {
816 wl3501_get_from_wla(this,
818 sizeof(struct wl3501_rx_hdr
), data
,
820 sizeof(struct wl3501_rx_hdr
));
821 size
-= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
822 data
+= WL3501_BLKSZ
- sizeof(struct wl3501_rx_hdr
);
824 wl3501_get_from_wla(this,
826 sizeof(struct wl3501_rx_hdr
),
831 if (size
> WL3501_BLKSZ
- 5) {
832 wl3501_get_from_wla(this, next_addr
+ 5, data
,
834 size
-= WL3501_BLKSZ
- 5;
835 data
+= WL3501_BLKSZ
- 5;
836 wl3501_get_from_wla(this, next_addr
+ 2, &next_addr1
,
838 next_addr
= next_addr1
;
840 wl3501_get_from_wla(this, next_addr
+ 5, data
, size
);
847 static void wl3501_esbq_req_free(struct wl3501_card
*this)
852 if (this->esbq_req_head
== this->esbq_req_tail
)
854 wl3501_get_from_wla(this, this->esbq_req_tail
+ 3, &tmp
, sizeof(tmp
));
857 wl3501_get_from_wla(this, this->esbq_req_tail
, &addr
, sizeof(addr
));
858 wl3501_free_tx_buffer(this, addr
);
859 this->esbq_req_tail
+= 4;
860 if (this->esbq_req_tail
>= this->esbq_req_end
)
861 this->esbq_req_tail
= this->esbq_req_start
;
866 static int wl3501_esbq_confirm(struct wl3501_card
*this)
870 wl3501_get_from_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
874 static void wl3501_online(struct net_device
*dev
)
876 struct wl3501_card
*this = dev
->priv
;
878 printk(KERN_INFO
"%s: Wireless LAN online. BSSID: "
879 "%02X %02X %02X %02X %02X %02X\n", dev
->name
,
880 this->bssid
[0], this->bssid
[1], this->bssid
[2],
881 this->bssid
[3], this->bssid
[4], this->bssid
[5]);
882 netif_wake_queue(dev
);
885 static void wl3501_esbq_confirm_done(struct wl3501_card
*this)
889 wl3501_set_to_wla(this, this->esbq_confirm
+ 3, &tmp
, sizeof(tmp
));
890 this->esbq_confirm
+= 4;
891 if (this->esbq_confirm
>= this->esbq_confirm_end
)
892 this->esbq_confirm
= this->esbq_confirm_start
;
895 static int wl3501_mgmt_auth(struct wl3501_card
*this)
897 struct wl3501_auth_req sig
= {
898 .sig_id
= WL3501_SIG_AUTH_REQ
,
899 .type
= WL3501_SYS_TYPE_OPEN
,
904 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
905 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
908 static int wl3501_mgmt_association(struct wl3501_card
*this)
910 struct wl3501_assoc_req sig
= {
911 .sig_id
= WL3501_SIG_ASSOC_REQ
,
913 .listen_interval
= 5,
914 .cap_info
= this->cap_info
,
918 memcpy(sig
.mac_addr
, this->bssid
, ETH_ALEN
);
919 return wl3501_esbq_exec(this, &sig
, sizeof(sig
));
922 static void wl3501_mgmt_join_confirm(struct net_device
*dev
, u16 addr
)
924 struct wl3501_card
*this = dev
->priv
;
925 struct wl3501_join_confirm sig
;
928 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
929 if (sig
.status
== WL3501_STATUS_SUCCESS
) {
930 if (this->net_type
== IW_MODE_INFRA
) {
931 if (this->join_sta_bss
< this->bss_cnt
) {
932 const int i
= this->join_sta_bss
;
934 this->bss_set
[i
].bssid
, ETH_ALEN
);
935 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
936 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
937 &this->bss_set
[i
].ssid
.el
);
938 wl3501_mgmt_auth(this);
941 const int i
= this->join_sta_bss
;
943 memcpy(&this->bssid
, &this->bss_set
[i
].bssid
, ETH_ALEN
);
944 this->chan
= this->bss_set
[i
].ds_pset
.chan
;
945 iw_copy_mgmt_info_element(&this->keep_essid
.el
,
946 &this->bss_set
[i
].ssid
.el
);
951 this->join_sta_bss
++;
952 for (i
= this->join_sta_bss
; i
< this->bss_cnt
; i
++)
953 if (!wl3501_mgmt_join(this, i
))
955 this->join_sta_bss
= i
;
956 if (this->join_sta_bss
== this->bss_cnt
) {
957 if (this->net_type
== IW_MODE_INFRA
)
958 wl3501_mgmt_scan(this, 100);
961 if (this->adhoc_times
> WL3501_MAX_ADHOC_TRIES
)
962 wl3501_mgmt_start(this);
964 wl3501_mgmt_scan(this, 100);
970 static inline void wl3501_alarm_interrupt(struct net_device
*dev
,
971 struct wl3501_card
*this)
973 if (this->net_type
== IW_MODE_INFRA
) {
974 printk(KERN_INFO
"Wireless LAN offline\n");
975 netif_stop_queue(dev
);
976 wl3501_mgmt_resync(this);
980 static inline void wl3501_md_confirm_interrupt(struct net_device
*dev
,
981 struct wl3501_card
*this,
984 struct wl3501_md_confirm sig
;
987 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
988 wl3501_free_tx_buffer(this, sig
.data
);
989 if (netif_queue_stopped(dev
))
990 netif_wake_queue(dev
);
993 static inline void wl3501_md_ind_interrupt(struct net_device
*dev
,
994 struct wl3501_card
*this, u16 addr
)
996 struct wl3501_md_ind sig
;
998 u8 rssi
, addr4
[ETH_ALEN
];
1001 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1002 this->start_seg
= sig
.data
;
1003 wl3501_get_from_wla(this,
1004 sig
.data
+ offsetof(struct wl3501_rx_hdr
, rssi
),
1005 &rssi
, sizeof(rssi
));
1006 this->rssi
= rssi
<= 63 ? (rssi
* 100) / 64 : 255;
1008 wl3501_get_from_wla(this,
1010 offsetof(struct wl3501_rx_hdr
, addr4
),
1011 &addr4
, sizeof(addr4
));
1012 if (!(addr4
[0] == 0xAA && addr4
[1] == 0xAA &&
1013 addr4
[2] == 0x03 && addr4
[4] == 0x00)) {
1014 printk(KERN_INFO
"Insupported packet type!\n");
1017 pkt_len
= sig
.size
+ 12 - 24 - 4 - 6;
1019 skb
= dev_alloc_skb(pkt_len
+ 5);
1022 printk(KERN_WARNING
"%s: Can't alloc a sk_buff of size %d.\n",
1023 dev
->name
, pkt_len
);
1024 this->stats
.rx_dropped
++;
1027 skb_reserve(skb
, 2); /* IP headers on 16 bytes boundaries */
1028 eth_copy_and_sum(skb
, (unsigned char *)&sig
.daddr
, 12, 0);
1029 wl3501_receive(this, skb
->data
, pkt_len
);
1030 skb_put(skb
, pkt_len
);
1031 skb
->protocol
= eth_type_trans(skb
, dev
);
1032 dev
->last_rx
= jiffies
;
1033 this->stats
.rx_packets
++;
1034 this->stats
.rx_bytes
+= skb
->len
;
1039 static inline void wl3501_get_confirm_interrupt(struct wl3501_card
*this,
1040 u16 addr
, void *sig
, int size
)
1042 dprintk(3, "entry");
1043 wl3501_get_from_wla(this, addr
, &this->sig_get_confirm
,
1044 sizeof(this->sig_get_confirm
));
1045 wake_up(&this->wait
);
1048 static inline void wl3501_start_confirm_interrupt(struct net_device
*dev
,
1049 struct wl3501_card
*this,
1052 struct wl3501_start_confirm sig
;
1054 dprintk(3, "entry");
1055 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1056 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1057 netif_wake_queue(dev
);
1060 static inline void wl3501_assoc_confirm_interrupt(struct net_device
*dev
,
1063 struct wl3501_card
*this = dev
->priv
;
1064 struct wl3501_assoc_confirm sig
;
1066 dprintk(3, "entry");
1067 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1069 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1073 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card
*this,
1076 struct wl3501_auth_confirm sig
;
1078 dprintk(3, "entry");
1079 wl3501_get_from_wla(this, addr
, &sig
, sizeof(sig
));
1081 if (sig
.status
== WL3501_STATUS_SUCCESS
)
1082 wl3501_mgmt_association(this);
1084 wl3501_mgmt_resync(this);
1087 static inline void wl3501_rx_interrupt(struct net_device
*dev
)
1092 struct wl3501_card
*this = dev
->priv
;
1094 dprintk(3, "entry");
1097 if (!wl3501_esbq_confirm(this))
1099 wl3501_get_from_wla(this, this->esbq_confirm
, &addr
, sizeof(addr
));
1100 wl3501_get_from_wla(this, addr
+ 2, &sig_id
, sizeof(sig_id
));
1103 case WL3501_SIG_DEAUTH_IND
:
1104 case WL3501_SIG_DISASSOC_IND
:
1105 case WL3501_SIG_ALARM
:
1106 wl3501_alarm_interrupt(dev
, this);
1108 case WL3501_SIG_MD_CONFIRM
:
1109 wl3501_md_confirm_interrupt(dev
, this, addr
);
1111 case WL3501_SIG_MD_IND
:
1112 wl3501_md_ind_interrupt(dev
, this, addr
);
1114 case WL3501_SIG_GET_CONFIRM
:
1115 wl3501_get_confirm_interrupt(this, addr
,
1116 &this->sig_get_confirm
,
1117 sizeof(this->sig_get_confirm
));
1119 case WL3501_SIG_PWR_MGMT_CONFIRM
:
1120 wl3501_get_confirm_interrupt(this, addr
,
1121 &this->sig_pwr_mgmt_confirm
,
1122 sizeof(this->sig_pwr_mgmt_confirm
));
1124 case WL3501_SIG_START_CONFIRM
:
1125 wl3501_start_confirm_interrupt(dev
, this, addr
);
1127 case WL3501_SIG_SCAN_CONFIRM
:
1128 wl3501_mgmt_scan_confirm(this, addr
);
1130 case WL3501_SIG_JOIN_CONFIRM
:
1131 wl3501_mgmt_join_confirm(dev
, addr
);
1133 case WL3501_SIG_ASSOC_CONFIRM
:
1134 wl3501_assoc_confirm_interrupt(dev
, addr
);
1136 case WL3501_SIG_AUTH_CONFIRM
:
1137 wl3501_auth_confirm_interrupt(this, addr
);
1139 case WL3501_SIG_RESYNC_CONFIRM
:
1140 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1143 wl3501_esbq_confirm_done(this);
1145 /* free request if necessary */
1147 wl3501_esbq_req_free(this);
1152 static inline void wl3501_ack_interrupt(struct wl3501_card
*this)
1154 wl3501_outb(WL3501_GCR_ECINT
, this->base_addr
+ WL3501_NIC_GCR
);
1158 * wl3501_interrupt - Hardware interrupt from card.
1159 * @irq - Interrupt number
1160 * @dev_id - net_device
1163 * We must acknowledge the interrupt as soon as possible, and block the
1164 * interrupt from the same card immediately to prevent re-entry.
1166 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1167 * On the other hand, to prevent SUTRO from malfunctioning, we must
1168 * unlock the SUTRO as soon as possible.
1170 static irqreturn_t
wl3501_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1172 struct net_device
*dev
= (struct net_device
*)dev_id
;
1173 struct wl3501_card
*this;
1179 spin_lock(&this->lock
);
1180 wl3501_ack_interrupt(this);
1181 wl3501_block_interrupt(this);
1182 wl3501_rx_interrupt(dev
);
1183 wl3501_unblock_interrupt(this);
1184 spin_unlock(&this->lock
);
1186 return IRQ_RETVAL(handled
);
1189 printk(KERN_ERR
"%s: irq %d for unknown device.\n", __FUNCTION__
, irq
);
1193 static int wl3501_reset_board(struct wl3501_card
*this)
1199 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1200 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1201 wl3501_outb_p(WL3501_GCR_CORESET
, this->base_addr
+ WL3501_NIC_GCR
);
1203 /* Reset SRAM 0x480 to zero */
1204 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1207 wl3501_outb_p(0, this->base_addr
+ WL3501_NIC_GCR
);
1209 WL3501_NOPLOOP(1024 * 50);
1211 wl3501_unblock_interrupt(this); /* acme: was commented */
1213 /* Polling Self_Test_Status */
1214 for (i
= 0; i
< 10000; i
++) {
1215 wl3501_get_from_wla(this, 0x480, &tmp
, sizeof(tmp
));
1218 /* firmware complete all test successfully */
1220 wl3501_set_to_wla(this, 0x480, &tmp
, sizeof(tmp
));
1225 printk(KERN_WARNING
"%s: failed to reset the board!\n", __FUNCTION__
);
1231 static int wl3501_init_firmware(struct wl3501_card
*this)
1234 int rc
= wl3501_reset_board(this);
1238 this->card_name
[0] = '\0';
1239 wl3501_get_from_wla(this, 0x1a00,
1240 this->card_name
, sizeof(this->card_name
));
1241 this->card_name
[sizeof(this->card_name
) - 1] = '\0';
1242 this->firmware_date
[0] = '\0';
1243 wl3501_get_from_wla(this, 0x1a40,
1244 this->firmware_date
, sizeof(this->firmware_date
));
1245 this->firmware_date
[sizeof(this->firmware_date
) - 1] = '\0';
1246 /* Switch to SRAM Page 0 */
1247 wl3501_switch_page(this, WL3501_BSS_SPAGE0
);
1248 /* Read parameter from card */
1249 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start
, 2);
1250 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end
, 2);
1251 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start
, 2);
1252 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end
, 2);
1253 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head
, 2);
1254 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size
, 2);
1255 this->esbq_req_tail
= this->esbq_req_head
= this->esbq_req_start
;
1256 this->esbq_req_end
+= this->esbq_req_start
;
1257 this->esbq_confirm
= this->esbq_confirm_start
;
1258 this->esbq_confirm_end
+= this->esbq_confirm_start
;
1259 /* Initial Tx Buffer */
1260 this->tx_buffer_cnt
= 1;
1261 ptr
= this->tx_buffer_head
;
1262 next
= ptr
+ WL3501_BLKSZ
;
1263 while ((next
- this->tx_buffer_head
) < this->tx_buffer_size
) {
1264 this->tx_buffer_cnt
++;
1265 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1267 next
= ptr
+ WL3501_BLKSZ
;
1271 wl3501_set_to_wla(this, ptr
, &next
, sizeof(next
));
1272 this->tx_buffer_tail
= ptr
;
1276 printk(KERN_WARNING
"%s: failed!\n", __FUNCTION__
);
1280 static int wl3501_close(struct net_device
*dev
)
1282 struct wl3501_card
*this = dev
->priv
;
1284 unsigned long flags
;
1287 spin_lock_irqsave(&this->lock
, flags
);
1288 /* Check if the device is in wl3501_dev_list */
1289 for (link
= wl3501_dev_list
; link
; link
= link
->next
)
1290 if (link
->priv
== dev
)
1296 /* Stop wl3501_hard_start_xmit() from now on */
1297 netif_stop_queue(dev
);
1298 wl3501_ack_interrupt(this);
1300 /* Mask interrupts from the SUTRO */
1301 wl3501_block_interrupt(this);
1304 printk(KERN_INFO
"%s: WL3501 closed\n", dev
->name
);
1306 spin_unlock_irqrestore(&this->lock
, flags
);
1311 * wl3501_reset - Reset the SUTRO.
1312 * @dev - network device
1314 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1315 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1316 * is running. It seems to be dangerous.
1318 static int wl3501_reset(struct net_device
*dev
)
1320 struct wl3501_card
*this = dev
->priv
;
1323 wl3501_block_interrupt(this);
1325 if (wl3501_init_firmware(this)) {
1326 printk(KERN_WARNING
"%s: Can't initialize Firmware!\n",
1328 /* Free IRQ, and mark IRQ as unused */
1329 free_irq(dev
->irq
, dev
);
1334 * Queue has to be started only when the Card is Started
1336 netif_stop_queue(dev
);
1337 this->adhoc_times
= 0;
1338 wl3501_ack_interrupt(this);
1339 wl3501_unblock_interrupt(this);
1340 wl3501_mgmt_scan(this, 100);
1341 dprintk(1, "%s: device reset", dev
->name
);
1347 static void wl3501_tx_timeout(struct net_device
*dev
)
1349 struct wl3501_card
*this = dev
->priv
;
1350 struct net_device_stats
*stats
= &this->stats
;
1351 unsigned long flags
;
1355 spin_lock_irqsave(&this->lock
, flags
);
1356 rc
= wl3501_reset(dev
);
1357 spin_unlock_irqrestore(&this->lock
, flags
);
1359 printk(KERN_ERR
"%s: Error %d resetting card on Tx timeout!\n",
1362 dev
->trans_start
= jiffies
;
1363 netif_wake_queue(dev
);
1369 * 1 - Could not transmit (dev_queue_xmit will queue it)
1370 * and try to sent it later
1372 static int wl3501_hard_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1375 struct wl3501_card
*this = dev
->priv
;
1376 unsigned long flags
;
1378 spin_lock_irqsave(&this->lock
, flags
);
1379 enabled
= wl3501_block_interrupt(this);
1380 dev
->trans_start
= jiffies
;
1381 rc
= wl3501_send_pkt(this, skb
->data
, skb
->len
);
1383 wl3501_unblock_interrupt(this);
1385 ++this->stats
.tx_dropped
;
1386 netif_stop_queue(dev
);
1388 ++this->stats
.tx_packets
;
1389 this->stats
.tx_bytes
+= skb
->len
;
1392 if (this->tx_buffer_cnt
< 2)
1393 netif_stop_queue(dev
);
1395 spin_unlock_irqrestore(&this->lock
, flags
);
1399 static int wl3501_open(struct net_device
*dev
)
1402 struct wl3501_card
*this = dev
->priv
;
1403 unsigned long flags
;
1406 spin_lock_irqsave(&this->lock
, flags
);
1407 /* Check if the device is in wl3501_dev_list */
1408 for (link
= wl3501_dev_list
; link
; link
= link
->next
)
1409 if (link
->priv
== dev
)
1413 netif_device_attach(dev
);
1416 /* Initial WL3501 firmware */
1417 dprintk(1, "%s: Initialize WL3501 firmware...", dev
->name
);
1418 if (wl3501_init_firmware(this))
1420 /* Initial device variables */
1421 this->adhoc_times
= 0;
1422 /* Acknowledge Interrupt, for cleaning last state */
1423 wl3501_ack_interrupt(this);
1425 /* Enable interrupt from card after all */
1426 wl3501_unblock_interrupt(this);
1427 wl3501_mgmt_scan(this, 100);
1429 dprintk(1, "%s: WL3501 opened", dev
->name
);
1430 printk(KERN_INFO
"%s: Card Name: %s\n"
1431 "%s: Firmware Date: %s\n",
1432 dev
->name
, this->card_name
,
1433 dev
->name
, this->firmware_date
);
1435 spin_unlock_irqrestore(&this->lock
, flags
);
1438 printk(KERN_WARNING
"%s: Can't initialize firmware!\n", dev
->name
);
1442 struct net_device_stats
*wl3501_get_stats(struct net_device
*dev
)
1444 struct wl3501_card
*this = dev
->priv
;
1446 return &this->stats
;
1449 struct iw_statistics
*wl3501_get_wireless_stats(struct net_device
*dev
)
1451 struct wl3501_card
*this = dev
->priv
;
1452 struct iw_statistics
*wstats
= &this->wstats
;
1453 u32 value
; /* size checked: it is u32 */
1455 memset(wstats
, 0, sizeof(*wstats
));
1456 wstats
->status
= netif_running(dev
);
1457 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT
,
1458 &value
, sizeof(value
)))
1459 wstats
->discard
.code
+= value
;
1460 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT
,
1461 &value
, sizeof(value
)))
1462 wstats
->discard
.code
+= value
;
1463 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT
,
1464 &value
, sizeof(value
)))
1465 wstats
->discard
.code
+= value
;
1466 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT
,
1467 &value
, sizeof(value
)))
1468 wstats
->discard
.retries
= value
;
1469 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT
,
1470 &value
, sizeof(value
)))
1471 wstats
->discard
.misc
+= value
;
1472 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT
,
1473 &value
, sizeof(value
)))
1474 wstats
->discard
.misc
+= value
;
1475 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT
,
1476 &value
, sizeof(value
)))
1477 wstats
->discard
.misc
+= value
;
1478 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT
,
1479 &value
, sizeof(value
)))
1480 wstats
->discard
.misc
+= value
;
1484 static void wl3501_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*info
)
1486 strlcpy(info
->driver
, wl3501_dev_info
, sizeof(info
->driver
));
1489 static struct ethtool_ops ops
= {
1490 .get_drvinfo
= wl3501_get_drvinfo
1494 * wl3501_detach - deletes a driver "instance"
1497 * This deletes a driver "instance". The device is de-registered with Card
1498 * Services. If it has been released, all local data structures are freed.
1499 * Otherwise, the structures will be freed when the device is released.
1501 static void wl3501_detach(dev_link_t
*link
)
1505 /* Locate device structure */
1506 for (linkp
= &wl3501_dev_list
; *linkp
; linkp
= &(*linkp
)->next
)
1512 /* If the device is currently configured and active, we won't actually
1513 * delete it yet. Instead, it is marked so that when the release()
1514 * function is called, that will trigger a proper detach(). */
1516 if (link
->state
& DEV_CONFIG
) {
1518 printk(KERN_DEBUG
"wl3501_cs: detach postponed, '%s' "
1519 "still locked\n", link
->dev
->dev_name
);
1524 /* Break the link with Card Services */
1526 pcmcia_deregister_client(link
->handle
);
1528 /* Unlink device structure, free pieces */
1529 *linkp
= link
->next
;
1532 free_netdev(link
->priv
);
1538 static int wl3501_get_name(struct net_device
*dev
, struct iw_request_info
*info
,
1539 union iwreq_data
*wrqu
, char *extra
)
1541 strlcpy(wrqu
->name
, "IEEE 802.11-DS", sizeof(wrqu
->name
));
1545 static int wl3501_set_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1546 union iwreq_data
*wrqu
, char *extra
)
1548 struct wl3501_card
*this = dev
->priv
;
1549 int channel
= wrqu
->freq
.m
;
1552 if (iw_valid_channel(this->reg_domain
, channel
)) {
1553 this->chan
= channel
;
1554 rc
= wl3501_reset(dev
);
1559 static int wl3501_get_freq(struct net_device
*dev
, struct iw_request_info
*info
,
1560 union iwreq_data
*wrqu
, char *extra
)
1562 struct wl3501_card
*this = dev
->priv
;
1564 wrqu
->freq
.m
= wl3501_chan2freq
[this->chan
- 1] * 100000;
1569 static int wl3501_set_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1570 union iwreq_data
*wrqu
, char *extra
)
1574 if (wrqu
->mode
== IW_MODE_INFRA
||
1575 wrqu
->mode
== IW_MODE_ADHOC
||
1576 wrqu
->mode
== IW_MODE_AUTO
) {
1577 struct wl3501_card
*this = dev
->priv
;
1579 this->net_type
= wrqu
->mode
;
1580 rc
= wl3501_reset(dev
);
1585 static int wl3501_get_mode(struct net_device
*dev
, struct iw_request_info
*info
,
1586 union iwreq_data
*wrqu
, char *extra
)
1588 struct wl3501_card
*this = dev
->priv
;
1590 wrqu
->mode
= this->net_type
;
1594 static int wl3501_get_sens(struct net_device
*dev
, struct iw_request_info
*info
,
1595 union iwreq_data
*wrqu
, char *extra
)
1597 struct wl3501_card
*this = dev
->priv
;
1599 wrqu
->sens
.value
= this->rssi
;
1600 wrqu
->sens
.disabled
= !wrqu
->sens
.value
;
1601 wrqu
->sens
.fixed
= 1;
1605 static int wl3501_get_range(struct net_device
*dev
,
1606 struct iw_request_info
*info
,
1607 union iwreq_data
*wrqu
, char *extra
)
1609 struct iw_range
*range
= (struct iw_range
*)extra
;
1611 /* Set the length (very important for backward compatibility) */
1612 wrqu
->data
.length
= sizeof(*range
);
1614 /* Set all the info we don't care or don't know about to zero */
1615 memset(range
, 0, sizeof(*range
));
1617 /* Set the Wireless Extension versions */
1618 range
->we_version_compiled
= WIRELESS_EXT
;
1619 range
->we_version_source
= 1;
1620 range
->throughput
= 2 * 1000 * 1000; /* ~2 Mb/s */
1621 /* FIXME: study the code to fill in more fields... */
1625 static int wl3501_set_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1626 union iwreq_data
*wrqu
, char *extra
)
1628 struct wl3501_card
*this = dev
->priv
;
1629 static const u8 bcast
[ETH_ALEN
] = { 255, 255, 255, 255, 255, 255 };
1632 /* FIXME: we support other ARPHRDs...*/
1633 if (wrqu
->ap_addr
.sa_family
!= ARPHRD_ETHER
)
1635 if (!memcmp(bcast
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
)) {
1636 /* FIXME: rescan? */
1638 memcpy(this->bssid
, wrqu
->ap_addr
.sa_data
, ETH_ALEN
);
1639 /* FIXME: rescan? deassoc & scan? */
1645 static int wl3501_get_wap(struct net_device
*dev
, struct iw_request_info
*info
,
1646 union iwreq_data
*wrqu
, char *extra
)
1648 struct wl3501_card
*this = dev
->priv
;
1650 wrqu
->ap_addr
.sa_family
= ARPHRD_ETHER
;
1651 memcpy(wrqu
->ap_addr
.sa_data
, this->bssid
, ETH_ALEN
);
1655 static int wl3501_set_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1656 union iwreq_data
*wrqu
, char *extra
)
1659 * FIXME: trigger scanning with a reset, yes, I'm lazy
1661 return wl3501_reset(dev
);
1664 static int wl3501_get_scan(struct net_device
*dev
, struct iw_request_info
*info
,
1665 union iwreq_data
*wrqu
, char *extra
)
1667 struct wl3501_card
*this = dev
->priv
;
1669 char *current_ev
= extra
;
1670 struct iw_event iwe
;
1672 for (i
= 0; i
< this->bss_cnt
; ++i
) {
1673 iwe
.cmd
= SIOCGIWAP
;
1674 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1675 memcpy(iwe
.u
.ap_addr
.sa_data
, this->bss_set
[i
].bssid
, ETH_ALEN
);
1676 current_ev
= iwe_stream_add_event(current_ev
,
1677 extra
+ IW_SCAN_MAX_DATA
,
1678 &iwe
, IW_EV_ADDR_LEN
);
1679 iwe
.cmd
= SIOCGIWESSID
;
1680 iwe
.u
.data
.flags
= 1;
1681 iwe
.u
.data
.length
= this->bss_set
[i
].ssid
.el
.len
;
1682 current_ev
= iwe_stream_add_point(current_ev
,
1683 extra
+ IW_SCAN_MAX_DATA
,
1685 this->bss_set
[i
].ssid
.essid
);
1686 iwe
.cmd
= SIOCGIWMODE
;
1687 iwe
.u
.mode
= this->bss_set
[i
].bss_type
;
1688 current_ev
= iwe_stream_add_event(current_ev
,
1689 extra
+ IW_SCAN_MAX_DATA
,
1690 &iwe
, IW_EV_UINT_LEN
);
1691 iwe
.cmd
= SIOCGIWFREQ
;
1692 iwe
.u
.freq
.m
= this->bss_set
[i
].ds_pset
.chan
;
1694 current_ev
= iwe_stream_add_event(current_ev
,
1695 extra
+ IW_SCAN_MAX_DATA
,
1696 &iwe
, IW_EV_FREQ_LEN
);
1697 iwe
.cmd
= SIOCGIWENCODE
;
1698 if (this->bss_set
[i
].cap_info
& WL3501_MGMT_CAPABILITY_PRIVACY
)
1699 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
1701 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
1702 iwe
.u
.data
.length
= 0;
1703 current_ev
= iwe_stream_add_point(current_ev
,
1704 extra
+ IW_SCAN_MAX_DATA
,
1707 /* Length of data */
1708 wrqu
->data
.length
= (current_ev
- extra
);
1709 wrqu
->data
.flags
= 0; /* FIXME: set properly these flags */
1713 static int wl3501_set_essid(struct net_device
*dev
,
1714 struct iw_request_info
*info
,
1715 union iwreq_data
*wrqu
, char *extra
)
1717 struct wl3501_card
*this = dev
->priv
;
1719 if (wrqu
->data
.flags
) {
1720 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1722 extra
, wrqu
->data
.length
);
1723 } else { /* We accept any ESSID */
1724 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
,
1725 &this->essid
.el
, "ANY", 3);
1727 return wl3501_reset(dev
);
1730 static int wl3501_get_essid(struct net_device
*dev
,
1731 struct iw_request_info
*info
,
1732 union iwreq_data
*wrqu
, char *extra
)
1734 struct wl3501_card
*this = dev
->priv
;
1735 unsigned long flags
;
1737 spin_lock_irqsave(&this->lock
, flags
);
1738 wrqu
->essid
.flags
= 1;
1739 wrqu
->essid
.length
= this->essid
.el
.len
;
1740 memcpy(extra
, this->essid
.essid
, this->essid
.el
.len
);
1741 spin_unlock_irqrestore(&this->lock
, flags
);
1745 static int wl3501_set_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1746 union iwreq_data
*wrqu
, char *extra
)
1748 struct wl3501_card
*this = dev
->priv
;
1750 if (wrqu
->data
.length
> sizeof(this->nick
))
1752 strlcpy(this->nick
, extra
, wrqu
->data
.length
);
1756 static int wl3501_get_nick(struct net_device
*dev
, struct iw_request_info
*info
,
1757 union iwreq_data
*wrqu
, char *extra
)
1759 struct wl3501_card
*this = dev
->priv
;
1761 strlcpy(extra
, this->nick
, 32);
1762 wrqu
->data
.length
= strlen(extra
);
1766 static int wl3501_get_rate(struct net_device
*dev
, struct iw_request_info
*info
,
1767 union iwreq_data
*wrqu
, char *extra
)
1770 * FIXME: have to see from where to get this info, perhaps this card
1771 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1772 * common with the Planet Access Points. -acme
1774 wrqu
->bitrate
.value
= 2000000;
1775 wrqu
->bitrate
.fixed
= 1;
1779 static int wl3501_get_rts_threshold(struct net_device
*dev
,
1780 struct iw_request_info
*info
,
1781 union iwreq_data
*wrqu
, char *extra
)
1783 u16 threshold
; /* size checked: it is u16 */
1784 struct wl3501_card
*this = dev
->priv
;
1785 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD
,
1786 &threshold
, sizeof(threshold
));
1788 wrqu
->rts
.value
= threshold
;
1789 wrqu
->rts
.disabled
= threshold
>= 2347;
1790 wrqu
->rts
.fixed
= 1;
1795 static int wl3501_get_frag_threshold(struct net_device
*dev
,
1796 struct iw_request_info
*info
,
1797 union iwreq_data
*wrqu
, char *extra
)
1799 u16 threshold
; /* size checked: it is u16 */
1800 struct wl3501_card
*this = dev
->priv
;
1801 int rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD
,
1802 &threshold
, sizeof(threshold
));
1804 wrqu
->frag
.value
= threshold
;
1805 wrqu
->frag
.disabled
= threshold
>= 2346;
1806 wrqu
->frag
.fixed
= 1;
1811 static int wl3501_get_txpow(struct net_device
*dev
,
1812 struct iw_request_info
*info
,
1813 union iwreq_data
*wrqu
, char *extra
)
1816 struct wl3501_card
*this = dev
->priv
;
1817 int rc
= wl3501_get_mib_value(this,
1818 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL
,
1819 &txpow
, sizeof(txpow
));
1821 wrqu
->txpower
.value
= txpow
;
1822 wrqu
->txpower
.disabled
= 0;
1824 * From the MIB values I think this can be configurable,
1825 * as it lists several tx power levels -acme
1827 wrqu
->txpower
.fixed
= 0;
1828 wrqu
->txpower
.flags
= IW_TXPOW_MWATT
;
1833 static int wl3501_get_retry(struct net_device
*dev
,
1834 struct iw_request_info
*info
,
1835 union iwreq_data
*wrqu
, char *extra
)
1837 u8 retry
; /* size checked: it is u8 */
1838 struct wl3501_card
*this = dev
->priv
;
1839 int rc
= wl3501_get_mib_value(this,
1840 WL3501_MIB_ATTR_LONG_RETRY_LIMIT
,
1841 &retry
, sizeof(retry
));
1844 if (wrqu
->retry
.flags
& IW_RETRY_MAX
) {
1845 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1848 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT
,
1849 &retry
, sizeof(retry
));
1852 wrqu
->retry
.flags
= IW_RETRY_LIMIT
| IW_RETRY_MIN
;
1854 wrqu
->retry
.value
= retry
;
1855 wrqu
->retry
.disabled
= 0;
1860 static int wl3501_get_encode(struct net_device
*dev
,
1861 struct iw_request_info
*info
,
1862 union iwreq_data
*wrqu
, char *extra
)
1864 u8 implemented
, restricted
, keys
[100], len_keys
, tocopy
;
1865 struct wl3501_card
*this = dev
->priv
;
1866 int rc
= wl3501_get_mib_value(this,
1867 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED
,
1868 &implemented
, sizeof(implemented
));
1872 wrqu
->encoding
.flags
= IW_ENCODE_DISABLED
;
1875 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED
,
1876 &restricted
, sizeof(restricted
));
1879 wrqu
->encoding
.flags
= restricted
? IW_ENCODE_RESTRICTED
:
1881 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN
,
1882 &len_keys
, sizeof(len_keys
));
1885 rc
= wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS
,
1889 tocopy
= min_t(u8
, len_keys
, wrqu
->encoding
.length
);
1890 tocopy
= min_t(u8
, tocopy
, 100);
1891 wrqu
->encoding
.length
= tocopy
;
1892 memset(extra
, 0, tocopy
);
1893 memcpy(extra
, keys
, tocopy
);
1898 static int wl3501_get_power(struct net_device
*dev
,
1899 struct iw_request_info
*info
,
1900 union iwreq_data
*wrqu
, char *extra
)
1903 struct wl3501_card
*this = dev
->priv
;
1904 int rc
= wl3501_get_mib_value(this,
1905 WL3501_MIB_ATTR_CURRENT_PWR_STATE
,
1906 &pwr_state
, sizeof(pwr_state
));
1909 wrqu
->power
.disabled
= !pwr_state
;
1910 wrqu
->power
.flags
= IW_POWER_ON
;
1915 static const iw_handler wl3501_handler
[] = {
1916 [SIOCGIWNAME
- SIOCIWFIRST
] = wl3501_get_name
,
1917 [SIOCSIWFREQ
- SIOCIWFIRST
] = wl3501_set_freq
,
1918 [SIOCGIWFREQ
- SIOCIWFIRST
] = wl3501_get_freq
,
1919 [SIOCSIWMODE
- SIOCIWFIRST
] = wl3501_set_mode
,
1920 [SIOCGIWMODE
- SIOCIWFIRST
] = wl3501_get_mode
,
1921 [SIOCGIWSENS
- SIOCIWFIRST
] = wl3501_get_sens
,
1922 [SIOCGIWRANGE
- SIOCIWFIRST
] = wl3501_get_range
,
1923 [SIOCSIWSPY
- SIOCIWFIRST
] = iw_handler_set_spy
,
1924 [SIOCGIWSPY
- SIOCIWFIRST
] = iw_handler_get_spy
,
1925 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = iw_handler_set_thrspy
,
1926 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = iw_handler_get_thrspy
,
1927 [SIOCSIWAP
- SIOCIWFIRST
] = wl3501_set_wap
,
1928 [SIOCGIWAP
- SIOCIWFIRST
] = wl3501_get_wap
,
1929 [SIOCSIWSCAN
- SIOCIWFIRST
] = wl3501_set_scan
,
1930 [SIOCGIWSCAN
- SIOCIWFIRST
] = wl3501_get_scan
,
1931 [SIOCSIWESSID
- SIOCIWFIRST
] = wl3501_set_essid
,
1932 [SIOCGIWESSID
- SIOCIWFIRST
] = wl3501_get_essid
,
1933 [SIOCSIWNICKN
- SIOCIWFIRST
] = wl3501_set_nick
,
1934 [SIOCGIWNICKN
- SIOCIWFIRST
] = wl3501_get_nick
,
1935 [SIOCGIWRATE
- SIOCIWFIRST
] = wl3501_get_rate
,
1936 [SIOCGIWRTS
- SIOCIWFIRST
] = wl3501_get_rts_threshold
,
1937 [SIOCGIWFRAG
- SIOCIWFIRST
] = wl3501_get_frag_threshold
,
1938 [SIOCGIWTXPOW
- SIOCIWFIRST
] = wl3501_get_txpow
,
1939 [SIOCGIWRETRY
- SIOCIWFIRST
] = wl3501_get_retry
,
1940 [SIOCGIWENCODE
- SIOCIWFIRST
] = wl3501_get_encode
,
1941 [SIOCGIWPOWER
- SIOCIWFIRST
] = wl3501_get_power
,
1944 static const struct iw_handler_def wl3501_handler_def
= {
1945 .num_standard
= sizeof(wl3501_handler
) / sizeof(iw_handler
),
1946 .standard
= (iw_handler
*)wl3501_handler
,
1947 .spy_offset
= offsetof(struct wl3501_card
, spy_data
),
1951 * wl3501_attach - creates an "instance" of the driver
1953 * Creates an "instance" of the driver, allocating local data structures for
1954 * one device. The device is registered with Card Services.
1956 * The dev_link structure is initialized, but we don't actually configure the
1957 * card at this point -- we wait until we receive a card insertion event.
1959 static dev_link_t
*wl3501_attach(void)
1961 client_reg_t client_reg
;
1963 struct net_device
*dev
;
1966 /* Initialize the dev_link_t structure */
1967 link
= kmalloc(sizeof(*link
), GFP_KERNEL
);
1970 memset(link
, 0, sizeof(struct dev_link_t
));
1972 /* The io structure describes IO port mapping */
1973 link
->io
.NumPorts1
= 16;
1974 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
1975 link
->io
.IOAddrLines
= 5;
1977 /* Interrupt setup */
1978 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
| IRQ_HANDLE_PRESENT
;
1979 link
->irq
.IRQInfo1
= IRQ_LEVEL_ID
;
1980 link
->irq
.Handler
= wl3501_interrupt
;
1982 /* General socket configuration */
1983 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
1984 link
->conf
.Vcc
= 50;
1985 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
1986 link
->conf
.ConfigIndex
= 1;
1987 link
->conf
.Present
= PRESENT_OPTION
;
1989 dev
= alloc_etherdev(sizeof(struct wl3501_card
));
1992 dev
->open
= wl3501_open
;
1993 dev
->stop
= wl3501_close
;
1994 dev
->hard_start_xmit
= wl3501_hard_start_xmit
;
1995 dev
->tx_timeout
= wl3501_tx_timeout
;
1996 dev
->watchdog_timeo
= 5 * HZ
;
1997 dev
->get_stats
= wl3501_get_stats
;
1998 dev
->get_wireless_stats
= wl3501_get_wireless_stats
;
1999 dev
->wireless_handlers
= (struct iw_handler_def
*)&wl3501_handler_def
;
2000 SET_ETHTOOL_OPS(dev
, &ops
);
2001 netif_stop_queue(dev
);
2002 link
->priv
= link
->irq
.Instance
= dev
;
2004 /* Register with Card Services */
2005 link
->next
= wl3501_dev_list
;
2006 wl3501_dev_list
= link
;
2007 client_reg
.dev_info
= &wl3501_dev_info
;
2008 client_reg
.EventMask
= CS_EVENT_CARD_INSERTION
|
2009 CS_EVENT_RESET_PHYSICAL
|
2010 CS_EVENT_CARD_RESET
|
2011 CS_EVENT_CARD_REMOVAL
|
2012 CS_EVENT_PM_SUSPEND
|
2014 client_reg
.event_handler
= wl3501_event
;
2015 client_reg
.Version
= 0x0210;
2016 client_reg
.event_callback_args
.client_data
= link
;
2017 ret
= pcmcia_register_client(&link
->handle
, &client_reg
);
2019 cs_error(link
->handle
, RegisterClient
, ret
);
2020 wl3501_detach(link
);
2031 #define CS_CHECK(fn, ret) \
2032 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
2035 * wl3501_config - configure the PCMCIA socket and make eth device available
2038 * wl3501_config() is scheduled to run after a CARD_INSERTION event is
2039 * received, to configure the PCMCIA socket, and to make the ethernet device
2040 * available to the system.
2042 static void wl3501_config(dev_link_t
*link
)
2046 client_handle_t handle
= link
->handle
;
2047 struct net_device
*dev
= link
->priv
;
2048 int i
= 0, j
, last_fn
, last_ret
;
2049 unsigned char bf
[64];
2050 struct wl3501_card
*this;
2052 /* This reads the card's CONFIG tuple to find its config registers. */
2053 tuple
.Attributes
= 0;
2054 tuple
.DesiredTuple
= CISTPL_CONFIG
;
2055 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(handle
, &tuple
));
2056 tuple
.TupleData
= bf
;
2057 tuple
.TupleDataMax
= sizeof(bf
);
2058 tuple
.TupleOffset
= 0;
2059 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(handle
, &tuple
));
2060 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(handle
, &tuple
, &parse
));
2061 link
->conf
.ConfigBase
= parse
.config
.base
;
2062 link
->conf
.Present
= parse
.config
.rmask
[0];
2064 /* Configure card */
2065 link
->state
|= DEV_CONFIG
;
2067 /* Try allocating IO ports. This tries a few fixed addresses. If you
2068 * want, you can also read the card's config table to pick addresses --
2069 * see the serial driver for an example. */
2071 for (j
= 0x280; j
< 0x400; j
+= 0x20) {
2072 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
2073 * 0x200-0x2ff, and so on, because this seems safer */
2074 link
->io
.BasePort1
= j
;
2075 link
->io
.BasePort2
= link
->io
.BasePort1
+ 0x10;
2076 i
= pcmcia_request_io(link
->handle
, &link
->io
);
2077 if (i
== CS_SUCCESS
)
2080 if (i
!= CS_SUCCESS
) {
2081 cs_error(link
->handle
, RequestIO
, i
);
2085 /* Now allocate an interrupt line. Note that this does not actually
2086 * assign a handler to the interrupt. */
2088 CS_CHECK(RequestIRQ
, pcmcia_request_irq(link
->handle
, &link
->irq
));
2090 /* This actually configures the PCMCIA socket -- setting up the I/O
2091 * windows and the interrupt mapping. */
2093 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(link
->handle
, &link
->conf
));
2095 dev
->irq
= link
->irq
.AssignedIRQ
;
2096 dev
->base_addr
= link
->io
.BasePort1
;
2097 SET_NETDEV_DEV(dev
, &handle_to_dev(handle
));
2098 if (register_netdev(dev
)) {
2099 printk(KERN_NOTICE
"wl3501_cs: register_netdev() failed\n");
2103 SET_MODULE_OWNER(dev
);
2107 * At this point, the dev_node_t structure(s) should be initialized and
2108 * arranged in a linked list at link->dev.
2110 link
->dev
= &this->node
;
2111 link
->state
&= ~DEV_CONFIG_PENDING
;
2113 this->base_addr
= dev
->base_addr
;
2115 if (!wl3501_get_flash_mac_addr(this)) {
2116 printk(KERN_WARNING
"%s: Cant read MAC addr in flash ROM?\n",
2120 strcpy(this->node
.dev_name
, dev
->name
);
2122 /* print probe information */
2123 printk(KERN_INFO
"%s: wl3501 @ 0x%3.3x, IRQ %d, MAC addr in flash ROM:",
2124 dev
->name
, this->base_addr
, (int)dev
->irq
);
2125 for (i
= 0; i
< 6; i
++) {
2126 dev
->dev_addr
[i
] = ((char *)&this->mac_addr
)[i
];
2127 printk("%c%02x", i
? ':' : ' ', dev
->dev_addr
[i
]);
2131 * Initialize card parameters - added by jss
2133 this->net_type
= IW_MODE_INFRA
;
2135 this->join_sta_bss
= 0;
2136 this->adhoc_times
= 0;
2137 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID
, &this->essid
.el
,
2139 this->card_name
[0] = '\0';
2140 this->firmware_date
[0] = '\0';
2142 this->chan
= iw_default_channel(this->reg_domain
);
2143 strlcpy(this->nick
, "Planet WL3501", sizeof(this->nick
));
2144 spin_lock_init(&this->lock
);
2145 init_waitqueue_head(&this->wait
);
2146 netif_start_queue(dev
);
2149 cs_error(link
->handle
, last_fn
, last_ret
);
2151 wl3501_release(link
);
2157 * wl3501_release - unregister the net, release PCMCIA configuration
2160 * After a card is removed, wl3501_release() will unregister the net device,
2161 * and release the PCMCIA configuration. If the device is still open, this
2162 * will be postponed until it is closed.
2164 static void wl3501_release(dev_link_t
*link
)
2166 struct net_device
*dev
= link
->priv
;
2168 /* Unlink the device chain */
2170 unregister_netdev(dev
);
2174 /* Don't bother checking to see if these succeed or not */
2175 pcmcia_release_configuration(link
->handle
);
2176 pcmcia_release_io(link
->handle
, &link
->io
);
2177 pcmcia_release_irq(link
->handle
, &link
->irq
);
2178 link
->state
&= ~DEV_CONFIG
;
2182 * wl3501_event - The card status event handler
2185 * @args - arguments for this event
2187 * The card status event handler. Mostly, this schedules other stuff to run
2188 * after an event is received. A CARD_REMOVAL event also sets some flags to
2189 * discourage the net drivers from trying to talk to the card any more.
2191 * When a CARD_REMOVAL event is received, we immediately set a flag to block
2192 * future accesses to this device. All the functions that actually access the
2193 * device should check this flag to make sure the card is still present.
2195 static int wl3501_event(event_t event
, int pri
, event_callback_args_t
*args
)
2197 dev_link_t
*link
= args
->client_data
;
2198 struct net_device
*dev
= link
->priv
;
2201 case CS_EVENT_CARD_REMOVAL
:
2202 link
->state
&= ~DEV_PRESENT
;
2203 if (link
->state
& DEV_CONFIG
) {
2204 while (link
->open
> 0)
2206 netif_device_detach(dev
);
2207 wl3501_release(link
);
2210 case CS_EVENT_CARD_INSERTION
:
2211 link
->state
|= DEV_PRESENT
| DEV_CONFIG_PENDING
;
2212 wl3501_config(link
);
2214 case CS_EVENT_PM_SUSPEND
:
2215 link
->state
|= DEV_SUSPEND
;
2216 wl3501_pwr_mgmt(dev
->priv
, WL3501_SUSPEND
);
2217 /* Fall through... */
2218 case CS_EVENT_RESET_PHYSICAL
:
2219 if (link
->state
& DEV_CONFIG
) {
2221 netif_device_detach(dev
);
2222 pcmcia_release_configuration(link
->handle
);
2225 case CS_EVENT_PM_RESUME
:
2226 link
->state
&= ~DEV_SUSPEND
;
2227 wl3501_pwr_mgmt(dev
->priv
, WL3501_RESUME
);
2228 /* Fall through... */
2229 case CS_EVENT_CARD_RESET
:
2230 if (link
->state
& DEV_CONFIG
) {
2231 pcmcia_request_configuration(link
->handle
, &link
->conf
);
2234 netif_device_attach(dev
);
2242 static struct pcmcia_driver wl3501_driver
= {
2243 .owner
= THIS_MODULE
,
2245 .name
= "wl3501_cs",
2247 .attach
= wl3501_attach
,
2248 .detach
= wl3501_detach
,
2251 static int __init
wl3501_init_module(void)
2253 return pcmcia_register_driver(&wl3501_driver
);
2256 static void __exit
wl3501_exit_module(void)
2258 dprintk(0, ": unloading");
2259 pcmcia_unregister_driver(&wl3501_driver
);
2260 BUG_ON(wl3501_dev_list
!= NULL
);
2263 module_init(wl3501_init_module
);
2264 module_exit(wl3501_exit_module
);
2266 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2267 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2268 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2269 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2270 MODULE_LICENSE("GPL");