xref: /openbmc/linux/drivers/net/wireless/legacy/wl3501_cs.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1*298e50adSKalle Valo // SPDX-License-Identifier: GPL-2.0-only
2*298e50adSKalle Valo /*
3*298e50adSKalle Valo  * WL3501 Wireless LAN PCMCIA Card Driver for Linux
4*298e50adSKalle Valo  * Written originally for Linux 2.0.30 by Fox Chen, mhchen@golf.ccl.itri.org.tw
5*298e50adSKalle Valo  * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6*298e50adSKalle Valo  * Wireless extensions in 2.4 by Gustavo Niemeyer <niemeyer@conectiva.com>
7*298e50adSKalle Valo  *
8*298e50adSKalle Valo  * References used by Fox Chen while writing the original driver for 2.0.30:
9*298e50adSKalle Valo  *
10*298e50adSKalle Valo  *   1. WL24xx packet drivers (tooasm.asm)
11*298e50adSKalle Valo  *   2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
12*298e50adSKalle Valo  *   3. IEEE 802.11
13*298e50adSKalle Valo  *   4. Linux network driver (/usr/src/linux/drivers/net)
14*298e50adSKalle Valo  *   5. ISA card driver - wl24.c
15*298e50adSKalle Valo  *   6. Linux PCMCIA skeleton driver - skeleton.c
16*298e50adSKalle Valo  *   7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
17*298e50adSKalle Valo  *
18*298e50adSKalle Valo  * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
19*298e50adSKalle Valo  *   1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
20*298e50adSKalle Valo  *      rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
21*298e50adSKalle Valo  *      (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
22*298e50adSKalle Valo  *       ETHER/IP/UDP/TCP header, and acknowledgement overhead)
23*298e50adSKalle Valo  *
24*298e50adSKalle Valo  * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
25*298e50adSKalle Valo  * 173 Kbytes/s in TCP.
26*298e50adSKalle Valo  *
27*298e50adSKalle Valo  * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
28*298e50adSKalle Valo  * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
29*298e50adSKalle Valo  */
30*298e50adSKalle Valo 
31*298e50adSKalle Valo #include <linux/delay.h>
32*298e50adSKalle Valo #include <linux/types.h>
33*298e50adSKalle Valo #include <linux/interrupt.h>
34*298e50adSKalle Valo #include <linux/in.h>
35*298e50adSKalle Valo #include <linux/kernel.h>
36*298e50adSKalle Valo #include <linux/module.h>
37*298e50adSKalle Valo #include <linux/fcntl.h>
38*298e50adSKalle Valo #include <linux/if_arp.h>
39*298e50adSKalle Valo #include <linux/ioport.h>
40*298e50adSKalle Valo #include <linux/netdevice.h>
41*298e50adSKalle Valo #include <linux/etherdevice.h>
42*298e50adSKalle Valo #include <linux/skbuff.h>
43*298e50adSKalle Valo #include <linux/slab.h>
44*298e50adSKalle Valo #include <linux/string.h>
45*298e50adSKalle Valo #include <linux/wireless.h>
46*298e50adSKalle Valo #include <net/cfg80211.h>
47*298e50adSKalle Valo 
48*298e50adSKalle Valo #include <net/iw_handler.h>
49*298e50adSKalle Valo 
50*298e50adSKalle Valo #include <pcmcia/cistpl.h>
51*298e50adSKalle Valo #include <pcmcia/cisreg.h>
52*298e50adSKalle Valo #include <pcmcia/ds.h>
53*298e50adSKalle Valo 
54*298e50adSKalle Valo #include <asm/io.h>
55*298e50adSKalle Valo #include <linux/uaccess.h>
56*298e50adSKalle Valo 
57*298e50adSKalle Valo #include "wl3501.h"
58*298e50adSKalle Valo 
59*298e50adSKalle Valo #ifndef __i386__
60*298e50adSKalle Valo #define slow_down_io()
61*298e50adSKalle Valo #endif
62*298e50adSKalle Valo 
63*298e50adSKalle Valo /* For rough constant delay */
64*298e50adSKalle Valo #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
65*298e50adSKalle Valo 
66*298e50adSKalle Valo 
67*298e50adSKalle Valo 
68*298e50adSKalle Valo #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
69*298e50adSKalle Valo #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
70*298e50adSKalle Valo #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
71*298e50adSKalle Valo 
72*298e50adSKalle Valo #define WL3501_RELEASE_TIMEOUT (25 * HZ)
73*298e50adSKalle Valo #define WL3501_MAX_ADHOC_TRIES 16
74*298e50adSKalle Valo 
75*298e50adSKalle Valo #define WL3501_RESUME	0
76*298e50adSKalle Valo #define WL3501_SUSPEND	1
77*298e50adSKalle Valo 
78*298e50adSKalle Valo static int wl3501_config(struct pcmcia_device *link);
79*298e50adSKalle Valo static void wl3501_release(struct pcmcia_device *link);
80*298e50adSKalle Valo 
81*298e50adSKalle Valo static const struct {
82*298e50adSKalle Valo 	int reg_domain;
83*298e50adSKalle Valo 	int min, max, deflt;
84*298e50adSKalle Valo } iw_channel_table[] = {
85*298e50adSKalle Valo 	{
86*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_FCC,
87*298e50adSKalle Valo 		.min	    = 1,
88*298e50adSKalle Valo 		.max	    = 11,
89*298e50adSKalle Valo 		.deflt	    = 1,
90*298e50adSKalle Valo 	},
91*298e50adSKalle Valo 	{
92*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_DOC,
93*298e50adSKalle Valo 		.min	    = 1,
94*298e50adSKalle Valo 		.max	    = 11,
95*298e50adSKalle Valo 		.deflt	    = 1,
96*298e50adSKalle Valo 	},
97*298e50adSKalle Valo 	{
98*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_ETSI,
99*298e50adSKalle Valo 		.min	    = 1,
100*298e50adSKalle Valo 		.max	    = 13,
101*298e50adSKalle Valo 		.deflt	    = 1,
102*298e50adSKalle Valo 	},
103*298e50adSKalle Valo 	{
104*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_SPAIN,
105*298e50adSKalle Valo 		.min	    = 10,
106*298e50adSKalle Valo 		.max	    = 11,
107*298e50adSKalle Valo 		.deflt	    = 10,
108*298e50adSKalle Valo 	},
109*298e50adSKalle Valo 	{
110*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_FRANCE,
111*298e50adSKalle Valo 		.min	    = 10,
112*298e50adSKalle Valo 		.max	    = 13,
113*298e50adSKalle Valo 		.deflt	    = 10,
114*298e50adSKalle Valo 	},
115*298e50adSKalle Valo 	{
116*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_MKK,
117*298e50adSKalle Valo 		.min	    = 14,
118*298e50adSKalle Valo 		.max	    = 14,
119*298e50adSKalle Valo 		.deflt	    = 14,
120*298e50adSKalle Valo 	},
121*298e50adSKalle Valo 	{
122*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_MKK1,
123*298e50adSKalle Valo 		.min	    = 1,
124*298e50adSKalle Valo 		.max	    = 14,
125*298e50adSKalle Valo 		.deflt	    = 1,
126*298e50adSKalle Valo 	},
127*298e50adSKalle Valo 	{
128*298e50adSKalle Valo 		.reg_domain = IW_REG_DOMAIN_ISRAEL,
129*298e50adSKalle Valo 		.min	    = 3,
130*298e50adSKalle Valo 		.max	    = 9,
131*298e50adSKalle Valo 		.deflt	    = 9,
132*298e50adSKalle Valo 	},
133*298e50adSKalle Valo };
134*298e50adSKalle Valo 
135*298e50adSKalle Valo /**
136*298e50adSKalle Valo  * iw_valid_channel - validate channel in regulatory domain
137*298e50adSKalle Valo  * @reg_domain: regulatory domain
138*298e50adSKalle Valo  * @channel: channel to validate
139*298e50adSKalle Valo  *
140*298e50adSKalle Valo  * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
141*298e50adSKalle Valo  */
iw_valid_channel(int reg_domain,int channel)142*298e50adSKalle Valo static int iw_valid_channel(int reg_domain, int channel)
143*298e50adSKalle Valo {
144*298e50adSKalle Valo 	int i, rc = 0;
145*298e50adSKalle Valo 
146*298e50adSKalle Valo 	for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
147*298e50adSKalle Valo 		if (reg_domain == iw_channel_table[i].reg_domain) {
148*298e50adSKalle Valo 			rc = channel >= iw_channel_table[i].min &&
149*298e50adSKalle Valo 			     channel <= iw_channel_table[i].max;
150*298e50adSKalle Valo 			break;
151*298e50adSKalle Valo 		}
152*298e50adSKalle Valo 	return rc;
153*298e50adSKalle Valo }
154*298e50adSKalle Valo 
155*298e50adSKalle Valo /**
156*298e50adSKalle Valo  * iw_default_channel - get default channel for a regulatory domain
157*298e50adSKalle Valo  * @reg_domain: regulatory domain
158*298e50adSKalle Valo  *
159*298e50adSKalle Valo  * Returns the default channel for a regulatory domain
160*298e50adSKalle Valo  */
iw_default_channel(int reg_domain)161*298e50adSKalle Valo static int iw_default_channel(int reg_domain)
162*298e50adSKalle Valo {
163*298e50adSKalle Valo 	int i, rc = 1;
164*298e50adSKalle Valo 
165*298e50adSKalle Valo 	for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
166*298e50adSKalle Valo 		if (reg_domain == iw_channel_table[i].reg_domain) {
167*298e50adSKalle Valo 			rc = iw_channel_table[i].deflt;
168*298e50adSKalle Valo 			break;
169*298e50adSKalle Valo 		}
170*298e50adSKalle Valo 	return rc;
171*298e50adSKalle Valo }
172*298e50adSKalle Valo 
iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,struct iw_mgmt_info_element * el,void * value,int len)173*298e50adSKalle Valo static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
174*298e50adSKalle Valo 				     struct iw_mgmt_info_element *el,
175*298e50adSKalle Valo 				     void *value, int len)
176*298e50adSKalle Valo {
177*298e50adSKalle Valo 	el->id  = id;
178*298e50adSKalle Valo 	el->len = len;
179*298e50adSKalle Valo 	memcpy(el->data, value, len);
180*298e50adSKalle Valo }
181*298e50adSKalle Valo 
iw_copy_mgmt_info_element(struct iw_mgmt_info_element * to,struct iw_mgmt_info_element * from)182*298e50adSKalle Valo static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
183*298e50adSKalle Valo 				      struct iw_mgmt_info_element *from)
184*298e50adSKalle Valo {
185*298e50adSKalle Valo 	iw_set_mgmt_info_element(from->id, to, from->data, from->len);
186*298e50adSKalle Valo }
187*298e50adSKalle Valo 
wl3501_switch_page(struct wl3501_card * this,u8 page)188*298e50adSKalle Valo static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
189*298e50adSKalle Valo {
190*298e50adSKalle Valo 	wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
191*298e50adSKalle Valo }
192*298e50adSKalle Valo 
193*298e50adSKalle Valo /*
194*298e50adSKalle Valo  * Get Ethernet MAC address.
195*298e50adSKalle Valo  *
196*298e50adSKalle Valo  * WARNING: We switch to FPAGE0 and switc back again.
197*298e50adSKalle Valo  *          Making sure there is no other WL function beening called by ISR.
198*298e50adSKalle Valo  */
wl3501_get_flash_mac_addr(struct wl3501_card * this)199*298e50adSKalle Valo static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
200*298e50adSKalle Valo {
201*298e50adSKalle Valo 	int base_addr = this->base_addr;
202*298e50adSKalle Valo 
203*298e50adSKalle Valo 	/* get MAC addr */
204*298e50adSKalle Valo 	wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
205*298e50adSKalle Valo 	wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL);	/* LMAL */
206*298e50adSKalle Valo 	wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);	/* LMAH */
207*298e50adSKalle Valo 
208*298e50adSKalle Valo 	/* wait for reading EEPROM */
209*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
210*298e50adSKalle Valo 	this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
211*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
212*298e50adSKalle Valo 	this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
213*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
214*298e50adSKalle Valo 	this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
215*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
216*298e50adSKalle Valo 	this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
217*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
218*298e50adSKalle Valo 	this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
219*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
220*298e50adSKalle Valo 	this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
221*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
222*298e50adSKalle Valo 	this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
223*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
224*298e50adSKalle Valo 	wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
225*298e50adSKalle Valo 	wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
226*298e50adSKalle Valo 	wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
227*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
228*298e50adSKalle Valo 	this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
229*298e50adSKalle Valo 	WL3501_NOPLOOP(100);
230*298e50adSKalle Valo 	this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
231*298e50adSKalle Valo 	/* switch to SRAM Page 0 (for safety) */
232*298e50adSKalle Valo 	wl3501_switch_page(this, WL3501_BSS_SPAGE0);
233*298e50adSKalle Valo 
234*298e50adSKalle Valo 	/* The MAC addr should be 00:60:... */
235*298e50adSKalle Valo 	return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
236*298e50adSKalle Valo }
237*298e50adSKalle Valo 
238*298e50adSKalle Valo /**
239*298e50adSKalle Valo  * wl3501_set_to_wla - Move 'size' bytes from PC to card
240*298e50adSKalle Valo  * @this: Card
241*298e50adSKalle Valo  * @dest: Card addressing space
242*298e50adSKalle Valo  * @src: PC addressing space
243*298e50adSKalle Valo  * @size: Bytes to move
244*298e50adSKalle Valo  *
245*298e50adSKalle Valo  * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
246*298e50adSKalle Valo  */
wl3501_set_to_wla(struct wl3501_card * this,u16 dest,void * src,int size)247*298e50adSKalle Valo static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
248*298e50adSKalle Valo 			      int size)
249*298e50adSKalle Valo {
250*298e50adSKalle Valo 	/* switch to SRAM Page 0 */
251*298e50adSKalle Valo 	wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
252*298e50adSKalle Valo 						   WL3501_BSS_SPAGE0);
253*298e50adSKalle Valo 	/* set LMAL and LMAH */
254*298e50adSKalle Valo 	wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
255*298e50adSKalle Valo 	wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
256*298e50adSKalle Valo 
257*298e50adSKalle Valo 	/* rep out to Port A */
258*298e50adSKalle Valo 	wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
259*298e50adSKalle Valo }
260*298e50adSKalle Valo 
261*298e50adSKalle Valo /**
262*298e50adSKalle Valo  * wl3501_get_from_wla - Move 'size' bytes from card to PC
263*298e50adSKalle Valo  * @this: Card
264*298e50adSKalle Valo  * @src: Card addressing space
265*298e50adSKalle Valo  * @dest: PC addressing space
266*298e50adSKalle Valo  * @size: Bytes to move
267*298e50adSKalle Valo  *
268*298e50adSKalle Valo  * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
269*298e50adSKalle Valo  */
wl3501_get_from_wla(struct wl3501_card * this,u16 src,void * dest,int size)270*298e50adSKalle Valo static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
271*298e50adSKalle Valo 				int size)
272*298e50adSKalle Valo {
273*298e50adSKalle Valo 	/* switch to SRAM Page 0 */
274*298e50adSKalle Valo 	wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
275*298e50adSKalle Valo 						  WL3501_BSS_SPAGE0);
276*298e50adSKalle Valo 	/* set LMAL and LMAH */
277*298e50adSKalle Valo 	wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
278*298e50adSKalle Valo 	wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
279*298e50adSKalle Valo 
280*298e50adSKalle Valo 	/* rep get from Port A */
281*298e50adSKalle Valo 	insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
282*298e50adSKalle Valo }
283*298e50adSKalle Valo 
284*298e50adSKalle Valo /*
285*298e50adSKalle Valo  * Get/Allocate a free Tx Data Buffer
286*298e50adSKalle Valo  *
287*298e50adSKalle Valo  *  *--------------*-----------------*----------------------------------*
288*298e50adSKalle Valo  *  |    PLCP      |    MAC Header   |  DST  SRC         Data ...       |
289*298e50adSKalle Valo  *  |  (24 bytes)  |    (30 bytes)   |  (6)  (6)  (Ethernet Row Data)   |
290*298e50adSKalle Valo  *  *--------------*-----------------*----------------------------------*
291*298e50adSKalle Valo  *  \               \- IEEE 802.11 -/ \-------------- len --------------/
292*298e50adSKalle Valo  *   \-struct wl3501_80211_tx_hdr--/   \-------- Ethernet Frame -------/
293*298e50adSKalle Valo  *
294*298e50adSKalle Valo  * Return = Position in Card
295*298e50adSKalle Valo  */
wl3501_get_tx_buffer(struct wl3501_card * this,u16 len)296*298e50adSKalle Valo static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
297*298e50adSKalle Valo {
298*298e50adSKalle Valo 	u16 next, blk_cnt = 0, zero = 0;
299*298e50adSKalle Valo 	u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
300*298e50adSKalle Valo 	u16 ret = 0;
301*298e50adSKalle Valo 
302*298e50adSKalle Valo 	if (full_len > this->tx_buffer_cnt * 254)
303*298e50adSKalle Valo 		goto out;
304*298e50adSKalle Valo 	ret = this->tx_buffer_head;
305*298e50adSKalle Valo 	while (full_len) {
306*298e50adSKalle Valo 		if (full_len < 254)
307*298e50adSKalle Valo 			full_len = 0;
308*298e50adSKalle Valo 		else
309*298e50adSKalle Valo 			full_len -= 254;
310*298e50adSKalle Valo 		wl3501_get_from_wla(this, this->tx_buffer_head, &next,
311*298e50adSKalle Valo 				    sizeof(next));
312*298e50adSKalle Valo 		if (!full_len)
313*298e50adSKalle Valo 			wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
314*298e50adSKalle Valo 					  sizeof(zero));
315*298e50adSKalle Valo 		this->tx_buffer_head = next;
316*298e50adSKalle Valo 		blk_cnt++;
317*298e50adSKalle Valo 		/* if buffer is not enough */
318*298e50adSKalle Valo 		if (!next && full_len) {
319*298e50adSKalle Valo 			this->tx_buffer_head = ret;
320*298e50adSKalle Valo 			ret = 0;
321*298e50adSKalle Valo 			goto out;
322*298e50adSKalle Valo 		}
323*298e50adSKalle Valo 	}
324*298e50adSKalle Valo 	this->tx_buffer_cnt -= blk_cnt;
325*298e50adSKalle Valo out:
326*298e50adSKalle Valo 	return ret;
327*298e50adSKalle Valo }
328*298e50adSKalle Valo 
329*298e50adSKalle Valo /*
330*298e50adSKalle Valo  * Free an allocated Tx Buffer. ptr must be correct position.
331*298e50adSKalle Valo  */
wl3501_free_tx_buffer(struct wl3501_card * this,u16 ptr)332*298e50adSKalle Valo static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
333*298e50adSKalle Valo {
334*298e50adSKalle Valo 	/* check if all space is not free */
335*298e50adSKalle Valo 	if (!this->tx_buffer_head)
336*298e50adSKalle Valo 		this->tx_buffer_head = ptr;
337*298e50adSKalle Valo 	else
338*298e50adSKalle Valo 		wl3501_set_to_wla(this, this->tx_buffer_tail,
339*298e50adSKalle Valo 				  &ptr, sizeof(ptr));
340*298e50adSKalle Valo 	while (ptr) {
341*298e50adSKalle Valo 		u16 next;
342*298e50adSKalle Valo 
343*298e50adSKalle Valo 		this->tx_buffer_cnt++;
344*298e50adSKalle Valo 		wl3501_get_from_wla(this, ptr, &next, sizeof(next));
345*298e50adSKalle Valo 		this->tx_buffer_tail = ptr;
346*298e50adSKalle Valo 		ptr = next;
347*298e50adSKalle Valo 	}
348*298e50adSKalle Valo }
349*298e50adSKalle Valo 
wl3501_esbq_req_test(struct wl3501_card * this)350*298e50adSKalle Valo static int wl3501_esbq_req_test(struct wl3501_card *this)
351*298e50adSKalle Valo {
352*298e50adSKalle Valo 	u8 tmp = 0;
353*298e50adSKalle Valo 
354*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
355*298e50adSKalle Valo 	return tmp & 0x80;
356*298e50adSKalle Valo }
357*298e50adSKalle Valo 
wl3501_esbq_req(struct wl3501_card * this,u16 * ptr)358*298e50adSKalle Valo static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
359*298e50adSKalle Valo {
360*298e50adSKalle Valo 	u16 tmp = 0;
361*298e50adSKalle Valo 
362*298e50adSKalle Valo 	wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
363*298e50adSKalle Valo 	wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
364*298e50adSKalle Valo 	this->esbq_req_head += 4;
365*298e50adSKalle Valo 	if (this->esbq_req_head >= this->esbq_req_end)
366*298e50adSKalle Valo 		this->esbq_req_head = this->esbq_req_start;
367*298e50adSKalle Valo }
368*298e50adSKalle Valo 
wl3501_esbq_exec(struct wl3501_card * this,void * sig,int sig_size)369*298e50adSKalle Valo static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
370*298e50adSKalle Valo {
371*298e50adSKalle Valo 	int rc = -EIO;
372*298e50adSKalle Valo 
373*298e50adSKalle Valo 	if (wl3501_esbq_req_test(this)) {
374*298e50adSKalle Valo 		u16 ptr = wl3501_get_tx_buffer(this, sig_size);
375*298e50adSKalle Valo 		if (ptr) {
376*298e50adSKalle Valo 			wl3501_set_to_wla(this, ptr, sig, sig_size);
377*298e50adSKalle Valo 			wl3501_esbq_req(this, &ptr);
378*298e50adSKalle Valo 			rc = 0;
379*298e50adSKalle Valo 		}
380*298e50adSKalle Valo 	}
381*298e50adSKalle Valo 	return rc;
382*298e50adSKalle Valo }
383*298e50adSKalle Valo 
wl3501_request_mib(struct wl3501_card * this,u8 index,void * bf)384*298e50adSKalle Valo static int wl3501_request_mib(struct wl3501_card *this, u8 index, void *bf)
385*298e50adSKalle Valo {
386*298e50adSKalle Valo 	struct wl3501_get_req sig = {
387*298e50adSKalle Valo 		.sig_id	    = WL3501_SIG_GET_REQ,
388*298e50adSKalle Valo 		.mib_attrib = index,
389*298e50adSKalle Valo 	};
390*298e50adSKalle Valo 	unsigned long flags;
391*298e50adSKalle Valo 	int rc = -EIO;
392*298e50adSKalle Valo 
393*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
394*298e50adSKalle Valo 	if (wl3501_esbq_req_test(this)) {
395*298e50adSKalle Valo 		u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
396*298e50adSKalle Valo 		if (ptr) {
397*298e50adSKalle Valo 			wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
398*298e50adSKalle Valo 			wl3501_esbq_req(this, &ptr);
399*298e50adSKalle Valo 			this->sig_get_confirm.mib_status = 255;
400*298e50adSKalle Valo 			rc = 0;
401*298e50adSKalle Valo 		}
402*298e50adSKalle Valo 	}
403*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
404*298e50adSKalle Valo 
405*298e50adSKalle Valo 	return rc;
406*298e50adSKalle Valo }
407*298e50adSKalle Valo 
wl3501_get_mib_value(struct wl3501_card * this,u8 index,void * bf,int size)408*298e50adSKalle Valo static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
409*298e50adSKalle Valo 				void *bf, int size)
410*298e50adSKalle Valo {
411*298e50adSKalle Valo 	int rc;
412*298e50adSKalle Valo 
413*298e50adSKalle Valo 	rc = wl3501_request_mib(this, index, bf);
414*298e50adSKalle Valo 	if (rc)
415*298e50adSKalle Valo 		return rc;
416*298e50adSKalle Valo 
417*298e50adSKalle Valo 	rc = wait_event_interruptible(this->wait,
418*298e50adSKalle Valo 		this->sig_get_confirm.mib_status != 255);
419*298e50adSKalle Valo 	if (rc)
420*298e50adSKalle Valo 		return rc;
421*298e50adSKalle Valo 
422*298e50adSKalle Valo 	memcpy(bf, this->sig_get_confirm.mib_value, size);
423*298e50adSKalle Valo 	return 0;
424*298e50adSKalle Valo }
425*298e50adSKalle Valo 
wl3501_pwr_mgmt(struct wl3501_card * this,int suspend)426*298e50adSKalle Valo static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
427*298e50adSKalle Valo {
428*298e50adSKalle Valo 	struct wl3501_pwr_mgmt_req sig = {
429*298e50adSKalle Valo 		.sig_id		= WL3501_SIG_PWR_MGMT_REQ,
430*298e50adSKalle Valo 		.pwr_save	= suspend,
431*298e50adSKalle Valo 		.wake_up	= !suspend,
432*298e50adSKalle Valo 		.receive_dtims	= 10,
433*298e50adSKalle Valo 	};
434*298e50adSKalle Valo 	unsigned long flags;
435*298e50adSKalle Valo 	int rc = -EIO;
436*298e50adSKalle Valo 
437*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
438*298e50adSKalle Valo 	if (wl3501_esbq_req_test(this)) {
439*298e50adSKalle Valo 		u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
440*298e50adSKalle Valo 		if (ptr) {
441*298e50adSKalle Valo 			wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
442*298e50adSKalle Valo 			wl3501_esbq_req(this, &ptr);
443*298e50adSKalle Valo 			this->sig_pwr_mgmt_confirm.status = 255;
444*298e50adSKalle Valo 			spin_unlock_irqrestore(&this->lock, flags);
445*298e50adSKalle Valo 			rc = wait_event_interruptible(this->wait,
446*298e50adSKalle Valo 				this->sig_pwr_mgmt_confirm.status != 255);
447*298e50adSKalle Valo 			printk(KERN_INFO "%s: %s status=%d\n", __func__,
448*298e50adSKalle Valo 			       suspend ? "suspend" : "resume",
449*298e50adSKalle Valo 			       this->sig_pwr_mgmt_confirm.status);
450*298e50adSKalle Valo 			goto out;
451*298e50adSKalle Valo 		}
452*298e50adSKalle Valo 	}
453*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
454*298e50adSKalle Valo out:
455*298e50adSKalle Valo 	return rc;
456*298e50adSKalle Valo }
457*298e50adSKalle Valo 
458*298e50adSKalle Valo /**
459*298e50adSKalle Valo  * wl3501_send_pkt - Send a packet.
460*298e50adSKalle Valo  * @this: Card
461*298e50adSKalle Valo  * @data: Ethernet raw frame.  (e.g. data[0] - data[5] is Dest MAC Addr,
462*298e50adSKalle Valo  *                                   data[6] - data[11] is Src MAC Addr)
463*298e50adSKalle Valo  * @len: Packet length
464*298e50adSKalle Valo  * Ref: IEEE 802.11
465*298e50adSKalle Valo  */
wl3501_send_pkt(struct wl3501_card * this,u8 * data,u16 len)466*298e50adSKalle Valo static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
467*298e50adSKalle Valo {
468*298e50adSKalle Valo 	u16 bf, sig_bf, next, tmplen, pktlen;
469*298e50adSKalle Valo 	struct wl3501_md_req sig = {
470*298e50adSKalle Valo 		.sig_id = WL3501_SIG_MD_REQ,
471*298e50adSKalle Valo 	};
472*298e50adSKalle Valo 	size_t sig_addr_len = sizeof(sig.addr);
473*298e50adSKalle Valo 	u8 *pdata = (char *)data;
474*298e50adSKalle Valo 	int rc = -EIO;
475*298e50adSKalle Valo 
476*298e50adSKalle Valo 	if (wl3501_esbq_req_test(this)) {
477*298e50adSKalle Valo 		sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
478*298e50adSKalle Valo 		rc = -ENOMEM;
479*298e50adSKalle Valo 		if (!sig_bf)	/* No free buffer available */
480*298e50adSKalle Valo 			goto out;
481*298e50adSKalle Valo 		bf = wl3501_get_tx_buffer(this, len + 26 + 24);
482*298e50adSKalle Valo 		if (!bf) {
483*298e50adSKalle Valo 			/* No free buffer available */
484*298e50adSKalle Valo 			wl3501_free_tx_buffer(this, sig_bf);
485*298e50adSKalle Valo 			goto out;
486*298e50adSKalle Valo 		}
487*298e50adSKalle Valo 		rc = 0;
488*298e50adSKalle Valo 		memcpy(&sig.addr, pdata, sig_addr_len);
489*298e50adSKalle Valo 		pktlen = len - sig_addr_len;
490*298e50adSKalle Valo 		pdata += sig_addr_len;
491*298e50adSKalle Valo 		sig.data = bf;
492*298e50adSKalle Valo 		if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
493*298e50adSKalle Valo 			u8 addr4[ETH_ALEN] = {
494*298e50adSKalle Valo 				[0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
495*298e50adSKalle Valo 			};
496*298e50adSKalle Valo 
497*298e50adSKalle Valo 			wl3501_set_to_wla(this, bf + 2 +
498*298e50adSKalle Valo 					  offsetof(struct wl3501_tx_hdr, addr4),
499*298e50adSKalle Valo 					  addr4, sizeof(addr4));
500*298e50adSKalle Valo 			sig.size = pktlen + 24 + 4 + 6;
501*298e50adSKalle Valo 			if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
502*298e50adSKalle Valo 				tmplen = 254 - sizeof(struct wl3501_tx_hdr);
503*298e50adSKalle Valo 				pktlen -= tmplen;
504*298e50adSKalle Valo 			} else {
505*298e50adSKalle Valo 				tmplen = pktlen;
506*298e50adSKalle Valo 				pktlen = 0;
507*298e50adSKalle Valo 			}
508*298e50adSKalle Valo 			wl3501_set_to_wla(this,
509*298e50adSKalle Valo 					  bf + 2 + sizeof(struct wl3501_tx_hdr),
510*298e50adSKalle Valo 					  pdata, tmplen);
511*298e50adSKalle Valo 			pdata += tmplen;
512*298e50adSKalle Valo 			wl3501_get_from_wla(this, bf, &next, sizeof(next));
513*298e50adSKalle Valo 			bf = next;
514*298e50adSKalle Valo 		} else {
515*298e50adSKalle Valo 			sig.size = pktlen + 24 + 4 - 2;
516*298e50adSKalle Valo 			pdata += 2;
517*298e50adSKalle Valo 			pktlen -= 2;
518*298e50adSKalle Valo 			if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
519*298e50adSKalle Valo 				tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
520*298e50adSKalle Valo 				pktlen -= tmplen;
521*298e50adSKalle Valo 			} else {
522*298e50adSKalle Valo 				tmplen = pktlen;
523*298e50adSKalle Valo 				pktlen = 0;
524*298e50adSKalle Valo 			}
525*298e50adSKalle Valo 			wl3501_set_to_wla(this, bf + 2 +
526*298e50adSKalle Valo 					  offsetof(struct wl3501_tx_hdr, addr4),
527*298e50adSKalle Valo 					  pdata, tmplen);
528*298e50adSKalle Valo 			pdata += tmplen;
529*298e50adSKalle Valo 			wl3501_get_from_wla(this, bf, &next, sizeof(next));
530*298e50adSKalle Valo 			bf = next;
531*298e50adSKalle Valo 		}
532*298e50adSKalle Valo 		while (pktlen > 0) {
533*298e50adSKalle Valo 			if (pktlen > 254) {
534*298e50adSKalle Valo 				tmplen = 254;
535*298e50adSKalle Valo 				pktlen -= 254;
536*298e50adSKalle Valo 			} else {
537*298e50adSKalle Valo 				tmplen = pktlen;
538*298e50adSKalle Valo 				pktlen = 0;
539*298e50adSKalle Valo 			}
540*298e50adSKalle Valo 			wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
541*298e50adSKalle Valo 			pdata += tmplen;
542*298e50adSKalle Valo 			wl3501_get_from_wla(this, bf, &next, sizeof(next));
543*298e50adSKalle Valo 			bf = next;
544*298e50adSKalle Valo 		}
545*298e50adSKalle Valo 		wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
546*298e50adSKalle Valo 		wl3501_esbq_req(this, &sig_bf);
547*298e50adSKalle Valo 	}
548*298e50adSKalle Valo out:
549*298e50adSKalle Valo 	return rc;
550*298e50adSKalle Valo }
551*298e50adSKalle Valo 
wl3501_mgmt_resync(struct wl3501_card * this)552*298e50adSKalle Valo static int wl3501_mgmt_resync(struct wl3501_card *this)
553*298e50adSKalle Valo {
554*298e50adSKalle Valo 	struct wl3501_resync_req sig = {
555*298e50adSKalle Valo 		.sig_id = WL3501_SIG_RESYNC_REQ,
556*298e50adSKalle Valo 	};
557*298e50adSKalle Valo 
558*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
559*298e50adSKalle Valo }
560*298e50adSKalle Valo 
wl3501_fw_bss_type(struct wl3501_card * this)561*298e50adSKalle Valo static inline int wl3501_fw_bss_type(struct wl3501_card *this)
562*298e50adSKalle Valo {
563*298e50adSKalle Valo 	return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
564*298e50adSKalle Valo 						 WL3501_NET_TYPE_ADHOC;
565*298e50adSKalle Valo }
566*298e50adSKalle Valo 
wl3501_fw_cap_info(struct wl3501_card * this)567*298e50adSKalle Valo static inline int wl3501_fw_cap_info(struct wl3501_card *this)
568*298e50adSKalle Valo {
569*298e50adSKalle Valo 	return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
570*298e50adSKalle Valo 						 WL3501_MGMT_CAPABILITY_IBSS;
571*298e50adSKalle Valo }
572*298e50adSKalle Valo 
wl3501_mgmt_scan(struct wl3501_card * this,u16 chan_time)573*298e50adSKalle Valo static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
574*298e50adSKalle Valo {
575*298e50adSKalle Valo 	struct wl3501_scan_req sig = {
576*298e50adSKalle Valo 		.sig_id		= WL3501_SIG_SCAN_REQ,
577*298e50adSKalle Valo 		.scan_type	= WL3501_SCAN_TYPE_ACTIVE,
578*298e50adSKalle Valo 		.probe_delay	= 0x10,
579*298e50adSKalle Valo 		.min_chan_time	= chan_time,
580*298e50adSKalle Valo 		.max_chan_time	= chan_time,
581*298e50adSKalle Valo 		.bss_type	= wl3501_fw_bss_type(this),
582*298e50adSKalle Valo 	};
583*298e50adSKalle Valo 
584*298e50adSKalle Valo 	this->bss_cnt = this->join_sta_bss = 0;
585*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
586*298e50adSKalle Valo }
587*298e50adSKalle Valo 
wl3501_mgmt_join(struct wl3501_card * this,u16 stas)588*298e50adSKalle Valo static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
589*298e50adSKalle Valo {
590*298e50adSKalle Valo 	struct wl3501_join_req sig = {
591*298e50adSKalle Valo 		.sig_id		  = WL3501_SIG_JOIN_REQ,
592*298e50adSKalle Valo 		.timeout	  = 10,
593*298e50adSKalle Valo 		.req.ds_pset = {
594*298e50adSKalle Valo 			.el = {
595*298e50adSKalle Valo 				.id  = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
596*298e50adSKalle Valo 				.len = 1,
597*298e50adSKalle Valo 			},
598*298e50adSKalle Valo 			.chan	= this->chan,
599*298e50adSKalle Valo 		},
600*298e50adSKalle Valo 	};
601*298e50adSKalle Valo 
602*298e50adSKalle Valo 	memcpy(&sig.req, &this->bss_set[stas].req, sizeof(sig.req));
603*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
604*298e50adSKalle Valo }
605*298e50adSKalle Valo 
wl3501_mgmt_start(struct wl3501_card * this)606*298e50adSKalle Valo static int wl3501_mgmt_start(struct wl3501_card *this)
607*298e50adSKalle Valo {
608*298e50adSKalle Valo 	struct wl3501_start_req sig = {
609*298e50adSKalle Valo 		.sig_id			= WL3501_SIG_START_REQ,
610*298e50adSKalle Valo 		.beacon_period		= 400,
611*298e50adSKalle Valo 		.dtim_period		= 1,
612*298e50adSKalle Valo 		.ds_pset = {
613*298e50adSKalle Valo 			.el = {
614*298e50adSKalle Valo 				.id  = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
615*298e50adSKalle Valo 				.len = 1,
616*298e50adSKalle Valo 			},
617*298e50adSKalle Valo 			.chan	= this->chan,
618*298e50adSKalle Valo 		},
619*298e50adSKalle Valo 		.bss_basic_rset	= {
620*298e50adSKalle Valo 			.el = {
621*298e50adSKalle Valo 				.id	= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
622*298e50adSKalle Valo 				.len = 2,
623*298e50adSKalle Valo 			},
624*298e50adSKalle Valo 			.data_rate_labels = {
625*298e50adSKalle Valo 				[0] = IW_MGMT_RATE_LABEL_MANDATORY |
626*298e50adSKalle Valo 				      IW_MGMT_RATE_LABEL_1MBIT,
627*298e50adSKalle Valo 				[1] = IW_MGMT_RATE_LABEL_MANDATORY |
628*298e50adSKalle Valo 				      IW_MGMT_RATE_LABEL_2MBIT,
629*298e50adSKalle Valo 			},
630*298e50adSKalle Valo 		},
631*298e50adSKalle Valo 		.operational_rset	= {
632*298e50adSKalle Valo 			.el = {
633*298e50adSKalle Valo 				.id	= IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
634*298e50adSKalle Valo 				.len = 2,
635*298e50adSKalle Valo 			},
636*298e50adSKalle Valo 			.data_rate_labels = {
637*298e50adSKalle Valo 				[0] = IW_MGMT_RATE_LABEL_MANDATORY |
638*298e50adSKalle Valo 				      IW_MGMT_RATE_LABEL_1MBIT,
639*298e50adSKalle Valo 				[1] = IW_MGMT_RATE_LABEL_MANDATORY |
640*298e50adSKalle Valo 				      IW_MGMT_RATE_LABEL_2MBIT,
641*298e50adSKalle Valo 			},
642*298e50adSKalle Valo 		},
643*298e50adSKalle Valo 		.ibss_pset		= {
644*298e50adSKalle Valo 			.el = {
645*298e50adSKalle Valo 				.id	 = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
646*298e50adSKalle Valo 				.len     = 2,
647*298e50adSKalle Valo 			},
648*298e50adSKalle Valo 			.atim_window = 10,
649*298e50adSKalle Valo 		},
650*298e50adSKalle Valo 		.bss_type		= wl3501_fw_bss_type(this),
651*298e50adSKalle Valo 		.cap_info		= wl3501_fw_cap_info(this),
652*298e50adSKalle Valo 	};
653*298e50adSKalle Valo 
654*298e50adSKalle Valo 	iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
655*298e50adSKalle Valo 	iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
656*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
657*298e50adSKalle Valo }
658*298e50adSKalle Valo 
wl3501_mgmt_scan_confirm(struct wl3501_card * this,u16 addr)659*298e50adSKalle Valo static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
660*298e50adSKalle Valo {
661*298e50adSKalle Valo 	u16 i = 0;
662*298e50adSKalle Valo 	int matchflag = 0;
663*298e50adSKalle Valo 	struct wl3501_scan_confirm sig;
664*298e50adSKalle Valo 
665*298e50adSKalle Valo 	pr_debug("entry");
666*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
667*298e50adSKalle Valo 	if (sig.status == WL3501_STATUS_SUCCESS) {
668*298e50adSKalle Valo 		pr_debug("success");
669*298e50adSKalle Valo 		if ((this->net_type == IW_MODE_INFRA &&
670*298e50adSKalle Valo 		     (sig.req.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
671*298e50adSKalle Valo 		    (this->net_type == IW_MODE_ADHOC &&
672*298e50adSKalle Valo 		     (sig.req.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
673*298e50adSKalle Valo 		    this->net_type == IW_MODE_AUTO) {
674*298e50adSKalle Valo 			if (!this->essid.el.len)
675*298e50adSKalle Valo 				matchflag = 1;
676*298e50adSKalle Valo 			else if (this->essid.el.len == 3 &&
677*298e50adSKalle Valo 				 !memcmp(this->essid.essid, "ANY", 3))
678*298e50adSKalle Valo 				matchflag = 1;
679*298e50adSKalle Valo 			else if (this->essid.el.len != sig.req.ssid.el.len)
680*298e50adSKalle Valo 				matchflag = 0;
681*298e50adSKalle Valo 			else if (memcmp(this->essid.essid, sig.req.ssid.essid,
682*298e50adSKalle Valo 					this->essid.el.len))
683*298e50adSKalle Valo 				matchflag = 0;
684*298e50adSKalle Valo 			else
685*298e50adSKalle Valo 				matchflag = 1;
686*298e50adSKalle Valo 			if (matchflag) {
687*298e50adSKalle Valo 				for (i = 0; i < this->bss_cnt; i++) {
688*298e50adSKalle Valo 					if (ether_addr_equal_unaligned(this->bss_set[i].req.bssid,
689*298e50adSKalle Valo 								       sig.req.bssid)) {
690*298e50adSKalle Valo 						matchflag = 0;
691*298e50adSKalle Valo 						break;
692*298e50adSKalle Valo 					}
693*298e50adSKalle Valo 				}
694*298e50adSKalle Valo 			}
695*298e50adSKalle Valo 			if (matchflag && (i < 20)) {
696*298e50adSKalle Valo 				memcpy(&this->bss_set[i].req,
697*298e50adSKalle Valo 				       &sig.req, sizeof(sig.req));
698*298e50adSKalle Valo 				this->bss_cnt++;
699*298e50adSKalle Valo 				this->rssi = sig.rssi;
700*298e50adSKalle Valo 				this->bss_set[i].rssi = sig.rssi;
701*298e50adSKalle Valo 			}
702*298e50adSKalle Valo 		}
703*298e50adSKalle Valo 	} else if (sig.status == WL3501_STATUS_TIMEOUT) {
704*298e50adSKalle Valo 		pr_debug("timeout");
705*298e50adSKalle Valo 		this->join_sta_bss = 0;
706*298e50adSKalle Valo 		for (i = this->join_sta_bss; i < this->bss_cnt; i++)
707*298e50adSKalle Valo 			if (!wl3501_mgmt_join(this, i))
708*298e50adSKalle Valo 				break;
709*298e50adSKalle Valo 		this->join_sta_bss = i;
710*298e50adSKalle Valo 		if (this->join_sta_bss == this->bss_cnt) {
711*298e50adSKalle Valo 			if (this->net_type == IW_MODE_INFRA)
712*298e50adSKalle Valo 				wl3501_mgmt_scan(this, 100);
713*298e50adSKalle Valo 			else {
714*298e50adSKalle Valo 				this->adhoc_times++;
715*298e50adSKalle Valo 				if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
716*298e50adSKalle Valo 					wl3501_mgmt_start(this);
717*298e50adSKalle Valo 				else
718*298e50adSKalle Valo 					wl3501_mgmt_scan(this, 100);
719*298e50adSKalle Valo 			}
720*298e50adSKalle Valo 		}
721*298e50adSKalle Valo 	}
722*298e50adSKalle Valo }
723*298e50adSKalle Valo 
724*298e50adSKalle Valo /**
725*298e50adSKalle Valo  * wl3501_block_interrupt - Mask interrupt from SUTRO
726*298e50adSKalle Valo  * @this: Card
727*298e50adSKalle Valo  *
728*298e50adSKalle Valo  * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
729*298e50adSKalle Valo  * Return: 1 if interrupt is originally enabled
730*298e50adSKalle Valo  */
wl3501_block_interrupt(struct wl3501_card * this)731*298e50adSKalle Valo static int wl3501_block_interrupt(struct wl3501_card *this)
732*298e50adSKalle Valo {
733*298e50adSKalle Valo 	u8 old = inb(this->base_addr + WL3501_NIC_GCR);
734*298e50adSKalle Valo 	u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
735*298e50adSKalle Valo 			WL3501_GCR_ENECINT));
736*298e50adSKalle Valo 
737*298e50adSKalle Valo 	wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
738*298e50adSKalle Valo 	return old & WL3501_GCR_ENECINT;
739*298e50adSKalle Valo }
740*298e50adSKalle Valo 
741*298e50adSKalle Valo /**
742*298e50adSKalle Valo  * wl3501_unblock_interrupt - Enable interrupt from SUTRO
743*298e50adSKalle Valo  * @this: Card
744*298e50adSKalle Valo  *
745*298e50adSKalle Valo  * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
746*298e50adSKalle Valo  * Return: 1 if interrupt is originally enabled
747*298e50adSKalle Valo  */
wl3501_unblock_interrupt(struct wl3501_card * this)748*298e50adSKalle Valo static int wl3501_unblock_interrupt(struct wl3501_card *this)
749*298e50adSKalle Valo {
750*298e50adSKalle Valo 	u8 old = inb(this->base_addr + WL3501_NIC_GCR);
751*298e50adSKalle Valo 	u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
752*298e50adSKalle Valo 		  WL3501_GCR_ENECINT;
753*298e50adSKalle Valo 
754*298e50adSKalle Valo 	wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
755*298e50adSKalle Valo 	return old & WL3501_GCR_ENECINT;
756*298e50adSKalle Valo }
757*298e50adSKalle Valo 
758*298e50adSKalle Valo /**
759*298e50adSKalle Valo  * wl3501_receive - Receive data from Receive Queue.
760*298e50adSKalle Valo  *
761*298e50adSKalle Valo  * Receive data from Receive Queue.
762*298e50adSKalle Valo  *
763*298e50adSKalle Valo  * @this: card
764*298e50adSKalle Valo  * @bf: address of host
765*298e50adSKalle Valo  * @size: size of buffer.
766*298e50adSKalle Valo  */
wl3501_receive(struct wl3501_card * this,u8 * bf,u16 size)767*298e50adSKalle Valo static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
768*298e50adSKalle Valo {
769*298e50adSKalle Valo 	u16 next_addr, next_addr1;
770*298e50adSKalle Valo 	u8 *data = bf + 12;
771*298e50adSKalle Valo 
772*298e50adSKalle Valo 	size -= 12;
773*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->start_seg + 2,
774*298e50adSKalle Valo 			    &next_addr, sizeof(next_addr));
775*298e50adSKalle Valo 	if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
776*298e50adSKalle Valo 		wl3501_get_from_wla(this,
777*298e50adSKalle Valo 				    this->start_seg +
778*298e50adSKalle Valo 					sizeof(struct wl3501_rx_hdr), data,
779*298e50adSKalle Valo 				    WL3501_BLKSZ -
780*298e50adSKalle Valo 					sizeof(struct wl3501_rx_hdr));
781*298e50adSKalle Valo 		size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
782*298e50adSKalle Valo 		data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
783*298e50adSKalle Valo 	} else {
784*298e50adSKalle Valo 		wl3501_get_from_wla(this,
785*298e50adSKalle Valo 				    this->start_seg +
786*298e50adSKalle Valo 					sizeof(struct wl3501_rx_hdr),
787*298e50adSKalle Valo 				    data, size);
788*298e50adSKalle Valo 		size = 0;
789*298e50adSKalle Valo 	}
790*298e50adSKalle Valo 	while (size > 0) {
791*298e50adSKalle Valo 		if (size > WL3501_BLKSZ - 5) {
792*298e50adSKalle Valo 			wl3501_get_from_wla(this, next_addr + 5, data,
793*298e50adSKalle Valo 					    WL3501_BLKSZ - 5);
794*298e50adSKalle Valo 			size -= WL3501_BLKSZ - 5;
795*298e50adSKalle Valo 			data += WL3501_BLKSZ - 5;
796*298e50adSKalle Valo 			wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
797*298e50adSKalle Valo 					    sizeof(next_addr1));
798*298e50adSKalle Valo 			next_addr = next_addr1;
799*298e50adSKalle Valo 		} else {
800*298e50adSKalle Valo 			wl3501_get_from_wla(this, next_addr + 5, data, size);
801*298e50adSKalle Valo 			size = 0;
802*298e50adSKalle Valo 		}
803*298e50adSKalle Valo 	}
804*298e50adSKalle Valo 	return 0;
805*298e50adSKalle Valo }
806*298e50adSKalle Valo 
wl3501_esbq_req_free(struct wl3501_card * this)807*298e50adSKalle Valo static void wl3501_esbq_req_free(struct wl3501_card *this)
808*298e50adSKalle Valo {
809*298e50adSKalle Valo 	u8 tmp;
810*298e50adSKalle Valo 	u16 addr;
811*298e50adSKalle Valo 
812*298e50adSKalle Valo 	if (this->esbq_req_head == this->esbq_req_tail)
813*298e50adSKalle Valo 		goto out;
814*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
815*298e50adSKalle Valo 	if (!(tmp & 0x80))
816*298e50adSKalle Valo 		goto out;
817*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
818*298e50adSKalle Valo 	wl3501_free_tx_buffer(this, addr);
819*298e50adSKalle Valo 	this->esbq_req_tail += 4;
820*298e50adSKalle Valo 	if (this->esbq_req_tail >= this->esbq_req_end)
821*298e50adSKalle Valo 		this->esbq_req_tail = this->esbq_req_start;
822*298e50adSKalle Valo out:
823*298e50adSKalle Valo 	return;
824*298e50adSKalle Valo }
825*298e50adSKalle Valo 
wl3501_esbq_confirm(struct wl3501_card * this)826*298e50adSKalle Valo static int wl3501_esbq_confirm(struct wl3501_card *this)
827*298e50adSKalle Valo {
828*298e50adSKalle Valo 	u8 tmp;
829*298e50adSKalle Valo 
830*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
831*298e50adSKalle Valo 	return tmp & 0x80;
832*298e50adSKalle Valo }
833*298e50adSKalle Valo 
wl3501_online(struct net_device * dev)834*298e50adSKalle Valo static void wl3501_online(struct net_device *dev)
835*298e50adSKalle Valo {
836*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
837*298e50adSKalle Valo 
838*298e50adSKalle Valo 	printk(KERN_INFO "%s: Wireless LAN online. BSSID: %pM\n",
839*298e50adSKalle Valo 	       dev->name, this->bssid);
840*298e50adSKalle Valo 	netif_wake_queue(dev);
841*298e50adSKalle Valo }
842*298e50adSKalle Valo 
wl3501_esbq_confirm_done(struct wl3501_card * this)843*298e50adSKalle Valo static void wl3501_esbq_confirm_done(struct wl3501_card *this)
844*298e50adSKalle Valo {
845*298e50adSKalle Valo 	u8 tmp = 0;
846*298e50adSKalle Valo 
847*298e50adSKalle Valo 	wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
848*298e50adSKalle Valo 	this->esbq_confirm += 4;
849*298e50adSKalle Valo 	if (this->esbq_confirm >= this->esbq_confirm_end)
850*298e50adSKalle Valo 		this->esbq_confirm = this->esbq_confirm_start;
851*298e50adSKalle Valo }
852*298e50adSKalle Valo 
wl3501_mgmt_auth(struct wl3501_card * this)853*298e50adSKalle Valo static int wl3501_mgmt_auth(struct wl3501_card *this)
854*298e50adSKalle Valo {
855*298e50adSKalle Valo 	struct wl3501_auth_req sig = {
856*298e50adSKalle Valo 		.sig_id	 = WL3501_SIG_AUTH_REQ,
857*298e50adSKalle Valo 		.type	 = WL3501_SYS_TYPE_OPEN,
858*298e50adSKalle Valo 		.timeout = 1000,
859*298e50adSKalle Valo 	};
860*298e50adSKalle Valo 
861*298e50adSKalle Valo 	pr_debug("entry");
862*298e50adSKalle Valo 	memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
863*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
864*298e50adSKalle Valo }
865*298e50adSKalle Valo 
wl3501_mgmt_association(struct wl3501_card * this)866*298e50adSKalle Valo static int wl3501_mgmt_association(struct wl3501_card *this)
867*298e50adSKalle Valo {
868*298e50adSKalle Valo 	struct wl3501_assoc_req sig = {
869*298e50adSKalle Valo 		.sig_id		 = WL3501_SIG_ASSOC_REQ,
870*298e50adSKalle Valo 		.timeout	 = 1000,
871*298e50adSKalle Valo 		.listen_interval = 5,
872*298e50adSKalle Valo 		.cap_info	 = this->cap_info,
873*298e50adSKalle Valo 	};
874*298e50adSKalle Valo 
875*298e50adSKalle Valo 	pr_debug("entry");
876*298e50adSKalle Valo 	memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
877*298e50adSKalle Valo 	return wl3501_esbq_exec(this, &sig, sizeof(sig));
878*298e50adSKalle Valo }
879*298e50adSKalle Valo 
wl3501_mgmt_join_confirm(struct net_device * dev,u16 addr)880*298e50adSKalle Valo static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
881*298e50adSKalle Valo {
882*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
883*298e50adSKalle Valo 	struct wl3501_join_confirm sig;
884*298e50adSKalle Valo 
885*298e50adSKalle Valo 	pr_debug("entry");
886*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
887*298e50adSKalle Valo 	if (sig.status == WL3501_STATUS_SUCCESS) {
888*298e50adSKalle Valo 		if (this->net_type == IW_MODE_INFRA) {
889*298e50adSKalle Valo 			if (this->join_sta_bss < this->bss_cnt) {
890*298e50adSKalle Valo 				const int i = this->join_sta_bss;
891*298e50adSKalle Valo 				memcpy(this->bssid,
892*298e50adSKalle Valo 				       this->bss_set[i].req.bssid, ETH_ALEN);
893*298e50adSKalle Valo 				this->chan = this->bss_set[i].req.ds_pset.chan;
894*298e50adSKalle Valo 				iw_copy_mgmt_info_element(&this->keep_essid.el,
895*298e50adSKalle Valo 						     &this->bss_set[i].req.ssid.el);
896*298e50adSKalle Valo 				wl3501_mgmt_auth(this);
897*298e50adSKalle Valo 			}
898*298e50adSKalle Valo 		} else {
899*298e50adSKalle Valo 			const int i = this->join_sta_bss;
900*298e50adSKalle Valo 
901*298e50adSKalle Valo 			memcpy(&this->bssid, &this->bss_set[i].req.bssid, ETH_ALEN);
902*298e50adSKalle Valo 			this->chan = this->bss_set[i].req.ds_pset.chan;
903*298e50adSKalle Valo 			iw_copy_mgmt_info_element(&this->keep_essid.el,
904*298e50adSKalle Valo 						  &this->bss_set[i].req.ssid.el);
905*298e50adSKalle Valo 			wl3501_online(dev);
906*298e50adSKalle Valo 		}
907*298e50adSKalle Valo 	} else {
908*298e50adSKalle Valo 		int i;
909*298e50adSKalle Valo 		this->join_sta_bss++;
910*298e50adSKalle Valo 		for (i = this->join_sta_bss; i < this->bss_cnt; i++)
911*298e50adSKalle Valo 			if (!wl3501_mgmt_join(this, i))
912*298e50adSKalle Valo 				break;
913*298e50adSKalle Valo 		this->join_sta_bss = i;
914*298e50adSKalle Valo 		if (this->join_sta_bss == this->bss_cnt) {
915*298e50adSKalle Valo 			if (this->net_type == IW_MODE_INFRA)
916*298e50adSKalle Valo 				wl3501_mgmt_scan(this, 100);
917*298e50adSKalle Valo 			else {
918*298e50adSKalle Valo 				this->adhoc_times++;
919*298e50adSKalle Valo 				if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
920*298e50adSKalle Valo 					wl3501_mgmt_start(this);
921*298e50adSKalle Valo 				else
922*298e50adSKalle Valo 					wl3501_mgmt_scan(this, 100);
923*298e50adSKalle Valo 			}
924*298e50adSKalle Valo 		}
925*298e50adSKalle Valo 	}
926*298e50adSKalle Valo }
927*298e50adSKalle Valo 
wl3501_alarm_interrupt(struct net_device * dev,struct wl3501_card * this)928*298e50adSKalle Valo static inline void wl3501_alarm_interrupt(struct net_device *dev,
929*298e50adSKalle Valo 					  struct wl3501_card *this)
930*298e50adSKalle Valo {
931*298e50adSKalle Valo 	if (this->net_type == IW_MODE_INFRA) {
932*298e50adSKalle Valo 		printk(KERN_INFO "Wireless LAN offline\n");
933*298e50adSKalle Valo 		netif_stop_queue(dev);
934*298e50adSKalle Valo 		wl3501_mgmt_resync(this);
935*298e50adSKalle Valo 	}
936*298e50adSKalle Valo }
937*298e50adSKalle Valo 
wl3501_md_confirm_interrupt(struct net_device * dev,struct wl3501_card * this,u16 addr)938*298e50adSKalle Valo static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
939*298e50adSKalle Valo 					       struct wl3501_card *this,
940*298e50adSKalle Valo 					       u16 addr)
941*298e50adSKalle Valo {
942*298e50adSKalle Valo 	struct wl3501_md_confirm sig;
943*298e50adSKalle Valo 
944*298e50adSKalle Valo 	pr_debug("entry");
945*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
946*298e50adSKalle Valo 	wl3501_free_tx_buffer(this, sig.data);
947*298e50adSKalle Valo 	if (netif_queue_stopped(dev))
948*298e50adSKalle Valo 		netif_wake_queue(dev);
949*298e50adSKalle Valo }
950*298e50adSKalle Valo 
wl3501_md_ind_interrupt(struct net_device * dev,struct wl3501_card * this,u16 addr)951*298e50adSKalle Valo static inline void wl3501_md_ind_interrupt(struct net_device *dev,
952*298e50adSKalle Valo 					   struct wl3501_card *this, u16 addr)
953*298e50adSKalle Valo {
954*298e50adSKalle Valo 	struct wl3501_md_ind sig;
955*298e50adSKalle Valo 	struct sk_buff *skb;
956*298e50adSKalle Valo 	u8 rssi, addr4[ETH_ALEN];
957*298e50adSKalle Valo 	u16 pkt_len;
958*298e50adSKalle Valo 
959*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
960*298e50adSKalle Valo 	this->start_seg = sig.data;
961*298e50adSKalle Valo 	wl3501_get_from_wla(this,
962*298e50adSKalle Valo 			    sig.data + offsetof(struct wl3501_rx_hdr, rssi),
963*298e50adSKalle Valo 			    &rssi, sizeof(rssi));
964*298e50adSKalle Valo 	this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
965*298e50adSKalle Valo 
966*298e50adSKalle Valo 	wl3501_get_from_wla(this,
967*298e50adSKalle Valo 			    sig.data +
968*298e50adSKalle Valo 				offsetof(struct wl3501_rx_hdr, addr4),
969*298e50adSKalle Valo 			    &addr4, sizeof(addr4));
970*298e50adSKalle Valo 	if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
971*298e50adSKalle Valo 	      addr4[2] == 0x03 && addr4[4] == 0x00)) {
972*298e50adSKalle Valo 		printk(KERN_INFO "Unsupported packet type!\n");
973*298e50adSKalle Valo 		return;
974*298e50adSKalle Valo 	}
975*298e50adSKalle Valo 	pkt_len = sig.size + 12 - 24 - 4 - 6;
976*298e50adSKalle Valo 
977*298e50adSKalle Valo 	skb = dev_alloc_skb(pkt_len + 5);
978*298e50adSKalle Valo 
979*298e50adSKalle Valo 	if (!skb) {
980*298e50adSKalle Valo 		printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
981*298e50adSKalle Valo 		       dev->name, pkt_len);
982*298e50adSKalle Valo 		dev->stats.rx_dropped++;
983*298e50adSKalle Valo 	} else {
984*298e50adSKalle Valo 		skb->dev = dev;
985*298e50adSKalle Valo 		skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
986*298e50adSKalle Valo 		skb_copy_to_linear_data(skb, (unsigned char *)&sig.addr,
987*298e50adSKalle Valo 					sizeof(sig.addr));
988*298e50adSKalle Valo 		wl3501_receive(this, skb->data, pkt_len);
989*298e50adSKalle Valo 		skb_put(skb, pkt_len);
990*298e50adSKalle Valo 		skb->protocol	= eth_type_trans(skb, dev);
991*298e50adSKalle Valo 		dev->stats.rx_packets++;
992*298e50adSKalle Valo 		dev->stats.rx_bytes += skb->len;
993*298e50adSKalle Valo 		netif_rx(skb);
994*298e50adSKalle Valo 	}
995*298e50adSKalle Valo }
996*298e50adSKalle Valo 
wl3501_get_confirm_interrupt(struct wl3501_card * this,u16 addr,void * sig,int size)997*298e50adSKalle Valo static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
998*298e50adSKalle Valo 						u16 addr, void *sig, int size)
999*298e50adSKalle Valo {
1000*298e50adSKalle Valo 	pr_debug("entry");
1001*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
1002*298e50adSKalle Valo 			    sizeof(this->sig_get_confirm));
1003*298e50adSKalle Valo 	wake_up(&this->wait);
1004*298e50adSKalle Valo }
1005*298e50adSKalle Valo 
wl3501_start_confirm_interrupt(struct net_device * dev,struct wl3501_card * this,u16 addr)1006*298e50adSKalle Valo static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
1007*298e50adSKalle Valo 						  struct wl3501_card *this,
1008*298e50adSKalle Valo 						  u16 addr)
1009*298e50adSKalle Valo {
1010*298e50adSKalle Valo 	struct wl3501_start_confirm sig;
1011*298e50adSKalle Valo 
1012*298e50adSKalle Valo 	pr_debug("entry");
1013*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1014*298e50adSKalle Valo 	if (sig.status == WL3501_STATUS_SUCCESS)
1015*298e50adSKalle Valo 		netif_wake_queue(dev);
1016*298e50adSKalle Valo }
1017*298e50adSKalle Valo 
wl3501_assoc_confirm_interrupt(struct net_device * dev,u16 addr)1018*298e50adSKalle Valo static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
1019*298e50adSKalle Valo 						  u16 addr)
1020*298e50adSKalle Valo {
1021*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1022*298e50adSKalle Valo 	struct wl3501_assoc_confirm sig;
1023*298e50adSKalle Valo 
1024*298e50adSKalle Valo 	pr_debug("entry");
1025*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1026*298e50adSKalle Valo 
1027*298e50adSKalle Valo 	if (sig.status == WL3501_STATUS_SUCCESS)
1028*298e50adSKalle Valo 		wl3501_online(dev);
1029*298e50adSKalle Valo }
1030*298e50adSKalle Valo 
wl3501_auth_confirm_interrupt(struct wl3501_card * this,u16 addr)1031*298e50adSKalle Valo static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
1032*298e50adSKalle Valo 						 u16 addr)
1033*298e50adSKalle Valo {
1034*298e50adSKalle Valo 	struct wl3501_auth_confirm sig;
1035*298e50adSKalle Valo 
1036*298e50adSKalle Valo 	pr_debug("entry");
1037*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1038*298e50adSKalle Valo 
1039*298e50adSKalle Valo 	if (sig.status == WL3501_STATUS_SUCCESS)
1040*298e50adSKalle Valo 		wl3501_mgmt_association(this);
1041*298e50adSKalle Valo 	else
1042*298e50adSKalle Valo 		wl3501_mgmt_resync(this);
1043*298e50adSKalle Valo }
1044*298e50adSKalle Valo 
wl3501_rx_interrupt(struct net_device * dev)1045*298e50adSKalle Valo static inline void wl3501_rx_interrupt(struct net_device *dev)
1046*298e50adSKalle Valo {
1047*298e50adSKalle Valo 	int morepkts;
1048*298e50adSKalle Valo 	u16 addr;
1049*298e50adSKalle Valo 	u8 sig_id;
1050*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1051*298e50adSKalle Valo 
1052*298e50adSKalle Valo 	pr_debug("entry");
1053*298e50adSKalle Valo loop:
1054*298e50adSKalle Valo 	morepkts = 0;
1055*298e50adSKalle Valo 	if (!wl3501_esbq_confirm(this))
1056*298e50adSKalle Valo 		goto free;
1057*298e50adSKalle Valo 	wl3501_get_from_wla(this, this->esbq_confirm, &addr, sizeof(addr));
1058*298e50adSKalle Valo 	wl3501_get_from_wla(this, addr + 2, &sig_id, sizeof(sig_id));
1059*298e50adSKalle Valo 
1060*298e50adSKalle Valo 	switch (sig_id) {
1061*298e50adSKalle Valo 	case WL3501_SIG_DEAUTH_IND:
1062*298e50adSKalle Valo 	case WL3501_SIG_DISASSOC_IND:
1063*298e50adSKalle Valo 	case WL3501_SIG_ALARM:
1064*298e50adSKalle Valo 		wl3501_alarm_interrupt(dev, this);
1065*298e50adSKalle Valo 		break;
1066*298e50adSKalle Valo 	case WL3501_SIG_MD_CONFIRM:
1067*298e50adSKalle Valo 		wl3501_md_confirm_interrupt(dev, this, addr);
1068*298e50adSKalle Valo 		break;
1069*298e50adSKalle Valo 	case WL3501_SIG_MD_IND:
1070*298e50adSKalle Valo 		wl3501_md_ind_interrupt(dev, this, addr);
1071*298e50adSKalle Valo 		break;
1072*298e50adSKalle Valo 	case WL3501_SIG_GET_CONFIRM:
1073*298e50adSKalle Valo 		wl3501_get_confirm_interrupt(this, addr,
1074*298e50adSKalle Valo 					     &this->sig_get_confirm,
1075*298e50adSKalle Valo 					     sizeof(this->sig_get_confirm));
1076*298e50adSKalle Valo 		break;
1077*298e50adSKalle Valo 	case WL3501_SIG_PWR_MGMT_CONFIRM:
1078*298e50adSKalle Valo 		wl3501_get_confirm_interrupt(this, addr,
1079*298e50adSKalle Valo 					     &this->sig_pwr_mgmt_confirm,
1080*298e50adSKalle Valo 					    sizeof(this->sig_pwr_mgmt_confirm));
1081*298e50adSKalle Valo 		break;
1082*298e50adSKalle Valo 	case WL3501_SIG_START_CONFIRM:
1083*298e50adSKalle Valo 		wl3501_start_confirm_interrupt(dev, this, addr);
1084*298e50adSKalle Valo 		break;
1085*298e50adSKalle Valo 	case WL3501_SIG_SCAN_CONFIRM:
1086*298e50adSKalle Valo 		wl3501_mgmt_scan_confirm(this, addr);
1087*298e50adSKalle Valo 		break;
1088*298e50adSKalle Valo 	case WL3501_SIG_JOIN_CONFIRM:
1089*298e50adSKalle Valo 		wl3501_mgmt_join_confirm(dev, addr);
1090*298e50adSKalle Valo 		break;
1091*298e50adSKalle Valo 	case WL3501_SIG_ASSOC_CONFIRM:
1092*298e50adSKalle Valo 		wl3501_assoc_confirm_interrupt(dev, addr);
1093*298e50adSKalle Valo 		break;
1094*298e50adSKalle Valo 	case WL3501_SIG_AUTH_CONFIRM:
1095*298e50adSKalle Valo 		wl3501_auth_confirm_interrupt(this, addr);
1096*298e50adSKalle Valo 		break;
1097*298e50adSKalle Valo 	case WL3501_SIG_RESYNC_CONFIRM:
1098*298e50adSKalle Valo 		wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1099*298e50adSKalle Valo 		break;
1100*298e50adSKalle Valo 	}
1101*298e50adSKalle Valo 	wl3501_esbq_confirm_done(this);
1102*298e50adSKalle Valo 	morepkts = 1;
1103*298e50adSKalle Valo 	/* free request if necessary */
1104*298e50adSKalle Valo free:
1105*298e50adSKalle Valo 	wl3501_esbq_req_free(this);
1106*298e50adSKalle Valo 	if (morepkts)
1107*298e50adSKalle Valo 		goto loop;
1108*298e50adSKalle Valo }
1109*298e50adSKalle Valo 
wl3501_ack_interrupt(struct wl3501_card * this)1110*298e50adSKalle Valo static inline void wl3501_ack_interrupt(struct wl3501_card *this)
1111*298e50adSKalle Valo {
1112*298e50adSKalle Valo 	wl3501_outb(WL3501_GCR_ECINT, this->base_addr + WL3501_NIC_GCR);
1113*298e50adSKalle Valo }
1114*298e50adSKalle Valo 
1115*298e50adSKalle Valo /**
1116*298e50adSKalle Valo  * wl3501_interrupt - Hardware interrupt from card.
1117*298e50adSKalle Valo  * @irq: Interrupt number
1118*298e50adSKalle Valo  * @dev_id: net_device
1119*298e50adSKalle Valo  *
1120*298e50adSKalle Valo  * We must acknowledge the interrupt as soon as possible, and block the
1121*298e50adSKalle Valo  * interrupt from the same card immediately to prevent re-entry.
1122*298e50adSKalle Valo  *
1123*298e50adSKalle Valo  * Before accessing the Control_Status_Block, we must lock SUTRO first.
1124*298e50adSKalle Valo  * On the other hand, to prevent SUTRO from malfunctioning, we must
1125*298e50adSKalle Valo  * unlock the SUTRO as soon as possible.
1126*298e50adSKalle Valo  */
wl3501_interrupt(int irq,void * dev_id)1127*298e50adSKalle Valo static irqreturn_t wl3501_interrupt(int irq, void *dev_id)
1128*298e50adSKalle Valo {
1129*298e50adSKalle Valo 	struct net_device *dev = dev_id;
1130*298e50adSKalle Valo 	struct wl3501_card *this;
1131*298e50adSKalle Valo 
1132*298e50adSKalle Valo 	this = netdev_priv(dev);
1133*298e50adSKalle Valo 	spin_lock(&this->lock);
1134*298e50adSKalle Valo 	wl3501_ack_interrupt(this);
1135*298e50adSKalle Valo 	wl3501_block_interrupt(this);
1136*298e50adSKalle Valo 	wl3501_rx_interrupt(dev);
1137*298e50adSKalle Valo 	wl3501_unblock_interrupt(this);
1138*298e50adSKalle Valo 	spin_unlock(&this->lock);
1139*298e50adSKalle Valo 
1140*298e50adSKalle Valo 	return IRQ_HANDLED;
1141*298e50adSKalle Valo }
1142*298e50adSKalle Valo 
wl3501_reset_board(struct wl3501_card * this)1143*298e50adSKalle Valo static int wl3501_reset_board(struct wl3501_card *this)
1144*298e50adSKalle Valo {
1145*298e50adSKalle Valo 	u8 tmp = 0;
1146*298e50adSKalle Valo 	int i, rc = 0;
1147*298e50adSKalle Valo 
1148*298e50adSKalle Valo 	/* Coreset */
1149*298e50adSKalle Valo 	wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1150*298e50adSKalle Valo 	wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1151*298e50adSKalle Valo 	wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1152*298e50adSKalle Valo 
1153*298e50adSKalle Valo 	/* Reset SRAM 0x480 to zero */
1154*298e50adSKalle Valo 	wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1155*298e50adSKalle Valo 
1156*298e50adSKalle Valo 	/* Start up */
1157*298e50adSKalle Valo 	wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1158*298e50adSKalle Valo 
1159*298e50adSKalle Valo 	WL3501_NOPLOOP(1024 * 50);
1160*298e50adSKalle Valo 
1161*298e50adSKalle Valo 	wl3501_unblock_interrupt(this);	/* acme: was commented */
1162*298e50adSKalle Valo 
1163*298e50adSKalle Valo 	/* Polling Self_Test_Status */
1164*298e50adSKalle Valo 	for (i = 0; i < 10000; i++) {
1165*298e50adSKalle Valo 		wl3501_get_from_wla(this, 0x480, &tmp, sizeof(tmp));
1166*298e50adSKalle Valo 
1167*298e50adSKalle Valo 		if (tmp == 'W') {
1168*298e50adSKalle Valo 			/* firmware complete all test successfully */
1169*298e50adSKalle Valo 			tmp = 'A';
1170*298e50adSKalle Valo 			wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1171*298e50adSKalle Valo 			goto out;
1172*298e50adSKalle Valo 		}
1173*298e50adSKalle Valo 		WL3501_NOPLOOP(10);
1174*298e50adSKalle Valo 	}
1175*298e50adSKalle Valo 	printk(KERN_WARNING "%s: failed to reset the board!\n", __func__);
1176*298e50adSKalle Valo 	rc = -ENODEV;
1177*298e50adSKalle Valo out:
1178*298e50adSKalle Valo 	return rc;
1179*298e50adSKalle Valo }
1180*298e50adSKalle Valo 
wl3501_init_firmware(struct wl3501_card * this)1181*298e50adSKalle Valo static int wl3501_init_firmware(struct wl3501_card *this)
1182*298e50adSKalle Valo {
1183*298e50adSKalle Valo 	u16 ptr, next;
1184*298e50adSKalle Valo 	int rc = wl3501_reset_board(this);
1185*298e50adSKalle Valo 
1186*298e50adSKalle Valo 	if (rc)
1187*298e50adSKalle Valo 		goto fail;
1188*298e50adSKalle Valo 	this->card_name[0] = '\0';
1189*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x1a00,
1190*298e50adSKalle Valo 			    this->card_name, sizeof(this->card_name));
1191*298e50adSKalle Valo 	this->card_name[sizeof(this->card_name) - 1] = '\0';
1192*298e50adSKalle Valo 	this->firmware_date[0] = '\0';
1193*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x1a40,
1194*298e50adSKalle Valo 			    this->firmware_date, sizeof(this->firmware_date));
1195*298e50adSKalle Valo 	this->firmware_date[sizeof(this->firmware_date) - 1] = '\0';
1196*298e50adSKalle Valo 	/* Switch to SRAM Page 0 */
1197*298e50adSKalle Valo 	wl3501_switch_page(this, WL3501_BSS_SPAGE0);
1198*298e50adSKalle Valo 	/* Read parameter from card */
1199*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x482, &this->esbq_req_start, 2);
1200*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x486, &this->esbq_req_end, 2);
1201*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start, 2);
1202*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end, 2);
1203*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head, 2);
1204*298e50adSKalle Valo 	wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size, 2);
1205*298e50adSKalle Valo 	this->esbq_req_tail	= this->esbq_req_head = this->esbq_req_start;
1206*298e50adSKalle Valo 	this->esbq_req_end     += this->esbq_req_start;
1207*298e50adSKalle Valo 	this->esbq_confirm	= this->esbq_confirm_start;
1208*298e50adSKalle Valo 	this->esbq_confirm_end += this->esbq_confirm_start;
1209*298e50adSKalle Valo 	/* Initial Tx Buffer */
1210*298e50adSKalle Valo 	this->tx_buffer_cnt = 1;
1211*298e50adSKalle Valo 	ptr = this->tx_buffer_head;
1212*298e50adSKalle Valo 	next = ptr + WL3501_BLKSZ;
1213*298e50adSKalle Valo 	while ((next - this->tx_buffer_head) < this->tx_buffer_size) {
1214*298e50adSKalle Valo 		this->tx_buffer_cnt++;
1215*298e50adSKalle Valo 		wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1216*298e50adSKalle Valo 		ptr = next;
1217*298e50adSKalle Valo 		next = ptr + WL3501_BLKSZ;
1218*298e50adSKalle Valo 	}
1219*298e50adSKalle Valo 	rc = 0;
1220*298e50adSKalle Valo 	next = 0;
1221*298e50adSKalle Valo 	wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1222*298e50adSKalle Valo 	this->tx_buffer_tail = ptr;
1223*298e50adSKalle Valo out:
1224*298e50adSKalle Valo 	return rc;
1225*298e50adSKalle Valo fail:
1226*298e50adSKalle Valo 	printk(KERN_WARNING "%s: failed!\n", __func__);
1227*298e50adSKalle Valo 	goto out;
1228*298e50adSKalle Valo }
1229*298e50adSKalle Valo 
wl3501_close(struct net_device * dev)1230*298e50adSKalle Valo static int wl3501_close(struct net_device *dev)
1231*298e50adSKalle Valo {
1232*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1233*298e50adSKalle Valo 	unsigned long flags;
1234*298e50adSKalle Valo 	struct pcmcia_device *link;
1235*298e50adSKalle Valo 	link = this->p_dev;
1236*298e50adSKalle Valo 
1237*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
1238*298e50adSKalle Valo 	link->open--;
1239*298e50adSKalle Valo 
1240*298e50adSKalle Valo 	/* Stop wl3501_hard_start_xmit() from now on */
1241*298e50adSKalle Valo 	netif_stop_queue(dev);
1242*298e50adSKalle Valo 	wl3501_ack_interrupt(this);
1243*298e50adSKalle Valo 
1244*298e50adSKalle Valo 	/* Mask interrupts from the SUTRO */
1245*298e50adSKalle Valo 	wl3501_block_interrupt(this);
1246*298e50adSKalle Valo 
1247*298e50adSKalle Valo 	printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
1248*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
1249*298e50adSKalle Valo 	return 0;
1250*298e50adSKalle Valo }
1251*298e50adSKalle Valo 
1252*298e50adSKalle Valo /**
1253*298e50adSKalle Valo  * wl3501_reset - Reset the SUTRO.
1254*298e50adSKalle Valo  * @dev: network device
1255*298e50adSKalle Valo  *
1256*298e50adSKalle Valo  * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1257*298e50adSKalle Valo  * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1258*298e50adSKalle Valo  * is running. It seems to be dangerous.
1259*298e50adSKalle Valo  */
wl3501_reset(struct net_device * dev)1260*298e50adSKalle Valo static int wl3501_reset(struct net_device *dev)
1261*298e50adSKalle Valo {
1262*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1263*298e50adSKalle Valo 	int rc = -ENODEV;
1264*298e50adSKalle Valo 	unsigned long flags;
1265*298e50adSKalle Valo 
1266*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
1267*298e50adSKalle Valo 	wl3501_block_interrupt(this);
1268*298e50adSKalle Valo 
1269*298e50adSKalle Valo 	if (wl3501_init_firmware(this)) {
1270*298e50adSKalle Valo 		printk(KERN_WARNING "%s: Can't initialize Firmware!\n",
1271*298e50adSKalle Valo 		       dev->name);
1272*298e50adSKalle Valo 		/* Free IRQ, and mark IRQ as unused */
1273*298e50adSKalle Valo 		free_irq(dev->irq, dev);
1274*298e50adSKalle Valo 		goto out;
1275*298e50adSKalle Valo 	}
1276*298e50adSKalle Valo 
1277*298e50adSKalle Valo 	/*
1278*298e50adSKalle Valo 	 * Queue has to be started only when the Card is Started
1279*298e50adSKalle Valo 	 */
1280*298e50adSKalle Valo 	netif_stop_queue(dev);
1281*298e50adSKalle Valo 	this->adhoc_times = 0;
1282*298e50adSKalle Valo 	wl3501_ack_interrupt(this);
1283*298e50adSKalle Valo 	wl3501_unblock_interrupt(this);
1284*298e50adSKalle Valo 	wl3501_mgmt_scan(this, 100);
1285*298e50adSKalle Valo 	pr_debug("%s: device reset", dev->name);
1286*298e50adSKalle Valo 	rc = 0;
1287*298e50adSKalle Valo out:
1288*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
1289*298e50adSKalle Valo 	return rc;
1290*298e50adSKalle Valo }
1291*298e50adSKalle Valo 
wl3501_tx_timeout(struct net_device * dev,unsigned int txqueue)1292*298e50adSKalle Valo static void wl3501_tx_timeout(struct net_device *dev, unsigned int txqueue)
1293*298e50adSKalle Valo {
1294*298e50adSKalle Valo 	struct net_device_stats *stats = &dev->stats;
1295*298e50adSKalle Valo 	int rc;
1296*298e50adSKalle Valo 
1297*298e50adSKalle Valo 	stats->tx_errors++;
1298*298e50adSKalle Valo 	rc = wl3501_reset(dev);
1299*298e50adSKalle Valo 	if (rc)
1300*298e50adSKalle Valo 		printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
1301*298e50adSKalle Valo 		       dev->name, rc);
1302*298e50adSKalle Valo 	else {
1303*298e50adSKalle Valo 		netif_trans_update(dev); /* prevent tx timeout */
1304*298e50adSKalle Valo 		netif_wake_queue(dev);
1305*298e50adSKalle Valo 	}
1306*298e50adSKalle Valo }
1307*298e50adSKalle Valo 
1308*298e50adSKalle Valo /*
1309*298e50adSKalle Valo  * Return : 0 - OK
1310*298e50adSKalle Valo  *	    1 - Could not transmit (dev_queue_xmit will queue it)
1311*298e50adSKalle Valo  *		and try to sent it later
1312*298e50adSKalle Valo  */
wl3501_hard_start_xmit(struct sk_buff * skb,struct net_device * dev)1313*298e50adSKalle Valo static netdev_tx_t wl3501_hard_start_xmit(struct sk_buff *skb,
1314*298e50adSKalle Valo 						struct net_device *dev)
1315*298e50adSKalle Valo {
1316*298e50adSKalle Valo 	int enabled, rc;
1317*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1318*298e50adSKalle Valo 	unsigned long flags;
1319*298e50adSKalle Valo 
1320*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
1321*298e50adSKalle Valo 	enabled = wl3501_block_interrupt(this);
1322*298e50adSKalle Valo 	rc = wl3501_send_pkt(this, skb->data, skb->len);
1323*298e50adSKalle Valo 	if (enabled)
1324*298e50adSKalle Valo 		wl3501_unblock_interrupt(this);
1325*298e50adSKalle Valo 	if (rc) {
1326*298e50adSKalle Valo 		++dev->stats.tx_dropped;
1327*298e50adSKalle Valo 		netif_stop_queue(dev);
1328*298e50adSKalle Valo 	} else {
1329*298e50adSKalle Valo 		++dev->stats.tx_packets;
1330*298e50adSKalle Valo 		dev->stats.tx_bytes += skb->len;
1331*298e50adSKalle Valo 		dev_kfree_skb_irq(skb);
1332*298e50adSKalle Valo 
1333*298e50adSKalle Valo 		if (this->tx_buffer_cnt < 2)
1334*298e50adSKalle Valo 			netif_stop_queue(dev);
1335*298e50adSKalle Valo 	}
1336*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
1337*298e50adSKalle Valo 	return NETDEV_TX_OK;
1338*298e50adSKalle Valo }
1339*298e50adSKalle Valo 
wl3501_open(struct net_device * dev)1340*298e50adSKalle Valo static int wl3501_open(struct net_device *dev)
1341*298e50adSKalle Valo {
1342*298e50adSKalle Valo 	int rc = -ENODEV;
1343*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1344*298e50adSKalle Valo 	unsigned long flags;
1345*298e50adSKalle Valo 	struct pcmcia_device *link;
1346*298e50adSKalle Valo 	link = this->p_dev;
1347*298e50adSKalle Valo 
1348*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
1349*298e50adSKalle Valo 	if (!pcmcia_dev_present(link))
1350*298e50adSKalle Valo 		goto out;
1351*298e50adSKalle Valo 	netif_device_attach(dev);
1352*298e50adSKalle Valo 	link->open++;
1353*298e50adSKalle Valo 
1354*298e50adSKalle Valo 	/* Initial WL3501 firmware */
1355*298e50adSKalle Valo 	pr_debug("%s: Initialize WL3501 firmware...", dev->name);
1356*298e50adSKalle Valo 	if (wl3501_init_firmware(this))
1357*298e50adSKalle Valo 		goto fail;
1358*298e50adSKalle Valo 	/* Initial device variables */
1359*298e50adSKalle Valo 	this->adhoc_times = 0;
1360*298e50adSKalle Valo 	/* Acknowledge Interrupt, for cleaning last state */
1361*298e50adSKalle Valo 	wl3501_ack_interrupt(this);
1362*298e50adSKalle Valo 
1363*298e50adSKalle Valo 	/* Enable interrupt from card after all */
1364*298e50adSKalle Valo 	wl3501_unblock_interrupt(this);
1365*298e50adSKalle Valo 	wl3501_mgmt_scan(this, 100);
1366*298e50adSKalle Valo 	rc = 0;
1367*298e50adSKalle Valo 	pr_debug("%s: WL3501 opened", dev->name);
1368*298e50adSKalle Valo 	printk(KERN_INFO "%s: Card Name: %s\n"
1369*298e50adSKalle Valo 			 "%s: Firmware Date: %s\n",
1370*298e50adSKalle Valo 			 dev->name, this->card_name,
1371*298e50adSKalle Valo 			 dev->name, this->firmware_date);
1372*298e50adSKalle Valo out:
1373*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
1374*298e50adSKalle Valo 	return rc;
1375*298e50adSKalle Valo fail:
1376*298e50adSKalle Valo 	printk(KERN_WARNING "%s: Can't initialize firmware!\n", dev->name);
1377*298e50adSKalle Valo 	goto out;
1378*298e50adSKalle Valo }
1379*298e50adSKalle Valo 
wl3501_get_wireless_stats(struct net_device * dev)1380*298e50adSKalle Valo static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
1381*298e50adSKalle Valo {
1382*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1383*298e50adSKalle Valo 	struct iw_statistics *wstats = &this->wstats;
1384*298e50adSKalle Valo 	u32 value; /* size checked: it is u32 */
1385*298e50adSKalle Valo 
1386*298e50adSKalle Valo 	memset(wstats, 0, sizeof(*wstats));
1387*298e50adSKalle Valo 	wstats->status = netif_running(dev);
1388*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT,
1389*298e50adSKalle Valo 				  &value, sizeof(value)))
1390*298e50adSKalle Valo 		wstats->discard.code += value;
1391*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT,
1392*298e50adSKalle Valo 				  &value, sizeof(value)))
1393*298e50adSKalle Valo 		wstats->discard.code += value;
1394*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT,
1395*298e50adSKalle Valo 				  &value, sizeof(value)))
1396*298e50adSKalle Valo 		wstats->discard.code += value;
1397*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT,
1398*298e50adSKalle Valo 				  &value, sizeof(value)))
1399*298e50adSKalle Valo 		wstats->discard.retries	= value;
1400*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT,
1401*298e50adSKalle Valo 				  &value, sizeof(value)))
1402*298e50adSKalle Valo 		wstats->discard.misc += value;
1403*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT,
1404*298e50adSKalle Valo 				  &value, sizeof(value)))
1405*298e50adSKalle Valo 		wstats->discard.misc += value;
1406*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT,
1407*298e50adSKalle Valo 				  &value, sizeof(value)))
1408*298e50adSKalle Valo 		wstats->discard.misc += value;
1409*298e50adSKalle Valo 	if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT,
1410*298e50adSKalle Valo 				  &value, sizeof(value)))
1411*298e50adSKalle Valo 		wstats->discard.misc += value;
1412*298e50adSKalle Valo 	return wstats;
1413*298e50adSKalle Valo }
1414*298e50adSKalle Valo 
1415*298e50adSKalle Valo /**
1416*298e50adSKalle Valo  * wl3501_detach - deletes a driver "instance"
1417*298e50adSKalle Valo  * @link: FILL_IN
1418*298e50adSKalle Valo  *
1419*298e50adSKalle Valo  * This deletes a driver "instance". The device is de-registered with Card
1420*298e50adSKalle Valo  * Services. If it has been released, all local data structures are freed.
1421*298e50adSKalle Valo  * Otherwise, the structures will be freed when the device is released.
1422*298e50adSKalle Valo  */
wl3501_detach(struct pcmcia_device * link)1423*298e50adSKalle Valo static void wl3501_detach(struct pcmcia_device *link)
1424*298e50adSKalle Valo {
1425*298e50adSKalle Valo 	struct net_device *dev = link->priv;
1426*298e50adSKalle Valo 
1427*298e50adSKalle Valo 	/* If the device is currently configured and active, we won't actually
1428*298e50adSKalle Valo 	 * delete it yet.  Instead, it is marked so that when the release()
1429*298e50adSKalle Valo 	 * function is called, that will trigger a proper detach(). */
1430*298e50adSKalle Valo 
1431*298e50adSKalle Valo 	while (link->open > 0)
1432*298e50adSKalle Valo 		wl3501_close(dev);
1433*298e50adSKalle Valo 
1434*298e50adSKalle Valo 	netif_device_detach(dev);
1435*298e50adSKalle Valo 	wl3501_release(link);
1436*298e50adSKalle Valo 
1437*298e50adSKalle Valo 	unregister_netdev(dev);
1438*298e50adSKalle Valo 	free_netdev(dev);
1439*298e50adSKalle Valo }
1440*298e50adSKalle Valo 
wl3501_get_name(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1441*298e50adSKalle Valo static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
1442*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1443*298e50adSKalle Valo {
1444*298e50adSKalle Valo 	strscpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
1445*298e50adSKalle Valo 	return 0;
1446*298e50adSKalle Valo }
1447*298e50adSKalle Valo 
wl3501_set_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1448*298e50adSKalle Valo static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
1449*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1450*298e50adSKalle Valo {
1451*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1452*298e50adSKalle Valo 	int channel = wrqu->freq.m;
1453*298e50adSKalle Valo 	int rc = -EINVAL;
1454*298e50adSKalle Valo 
1455*298e50adSKalle Valo 	if (iw_valid_channel(this->reg_domain, channel)) {
1456*298e50adSKalle Valo 		this->chan = channel;
1457*298e50adSKalle Valo 		rc = wl3501_reset(dev);
1458*298e50adSKalle Valo 	}
1459*298e50adSKalle Valo 	return rc;
1460*298e50adSKalle Valo }
1461*298e50adSKalle Valo 
wl3501_get_freq(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1462*298e50adSKalle Valo static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
1463*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1464*298e50adSKalle Valo {
1465*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1466*298e50adSKalle Valo 
1467*298e50adSKalle Valo 	wrqu->freq.m = 100000 *
1468*298e50adSKalle Valo 		ieee80211_channel_to_frequency(this->chan, NL80211_BAND_2GHZ);
1469*298e50adSKalle Valo 	wrqu->freq.e = 1;
1470*298e50adSKalle Valo 	return 0;
1471*298e50adSKalle Valo }
1472*298e50adSKalle Valo 
wl3501_set_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1473*298e50adSKalle Valo static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
1474*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1475*298e50adSKalle Valo {
1476*298e50adSKalle Valo 	int rc = -EINVAL;
1477*298e50adSKalle Valo 
1478*298e50adSKalle Valo 	if (wrqu->mode == IW_MODE_INFRA ||
1479*298e50adSKalle Valo 	    wrqu->mode == IW_MODE_ADHOC ||
1480*298e50adSKalle Valo 	    wrqu->mode == IW_MODE_AUTO) {
1481*298e50adSKalle Valo 		struct wl3501_card *this = netdev_priv(dev);
1482*298e50adSKalle Valo 
1483*298e50adSKalle Valo 		this->net_type = wrqu->mode;
1484*298e50adSKalle Valo 		rc = wl3501_reset(dev);
1485*298e50adSKalle Valo 	}
1486*298e50adSKalle Valo 	return rc;
1487*298e50adSKalle Valo }
1488*298e50adSKalle Valo 
wl3501_get_mode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1489*298e50adSKalle Valo static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
1490*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1491*298e50adSKalle Valo {
1492*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1493*298e50adSKalle Valo 
1494*298e50adSKalle Valo 	wrqu->mode = this->net_type;
1495*298e50adSKalle Valo 	return 0;
1496*298e50adSKalle Valo }
1497*298e50adSKalle Valo 
wl3501_get_sens(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1498*298e50adSKalle Valo static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
1499*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1500*298e50adSKalle Valo {
1501*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1502*298e50adSKalle Valo 
1503*298e50adSKalle Valo 	wrqu->sens.value = this->rssi;
1504*298e50adSKalle Valo 	wrqu->sens.disabled = !wrqu->sens.value;
1505*298e50adSKalle Valo 	wrqu->sens.fixed = 1;
1506*298e50adSKalle Valo 	return 0;
1507*298e50adSKalle Valo }
1508*298e50adSKalle Valo 
wl3501_get_range(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1509*298e50adSKalle Valo static int wl3501_get_range(struct net_device *dev,
1510*298e50adSKalle Valo 			    struct iw_request_info *info,
1511*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1512*298e50adSKalle Valo {
1513*298e50adSKalle Valo 	struct iw_range *range = (struct iw_range *)extra;
1514*298e50adSKalle Valo 
1515*298e50adSKalle Valo 	/* Set the length (very important for backward compatibility) */
1516*298e50adSKalle Valo 	wrqu->data.length = sizeof(*range);
1517*298e50adSKalle Valo 
1518*298e50adSKalle Valo 	/* Set all the info we don't care or don't know about to zero */
1519*298e50adSKalle Valo 	memset(range, 0, sizeof(*range));
1520*298e50adSKalle Valo 
1521*298e50adSKalle Valo 	/* Set the Wireless Extension versions */
1522*298e50adSKalle Valo 	range->we_version_compiled	= WIRELESS_EXT;
1523*298e50adSKalle Valo 	range->we_version_source	= 1;
1524*298e50adSKalle Valo 	range->throughput		= 2 * 1000 * 1000;     /* ~2 Mb/s */
1525*298e50adSKalle Valo 	/* FIXME: study the code to fill in more fields... */
1526*298e50adSKalle Valo 	return 0;
1527*298e50adSKalle Valo }
1528*298e50adSKalle Valo 
wl3501_set_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1529*298e50adSKalle Valo static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
1530*298e50adSKalle Valo 			  union iwreq_data *wrqu, char *extra)
1531*298e50adSKalle Valo {
1532*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1533*298e50adSKalle Valo 	int rc = -EINVAL;
1534*298e50adSKalle Valo 
1535*298e50adSKalle Valo 	/* FIXME: we support other ARPHRDs...*/
1536*298e50adSKalle Valo 	if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
1537*298e50adSKalle Valo 		goto out;
1538*298e50adSKalle Valo 	if (is_broadcast_ether_addr(wrqu->ap_addr.sa_data)) {
1539*298e50adSKalle Valo 		/* FIXME: rescan? */
1540*298e50adSKalle Valo 	} else
1541*298e50adSKalle Valo 		memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
1542*298e50adSKalle Valo 		/* FIXME: rescan? deassoc & scan? */
1543*298e50adSKalle Valo 	rc = 0;
1544*298e50adSKalle Valo out:
1545*298e50adSKalle Valo 	return rc;
1546*298e50adSKalle Valo }
1547*298e50adSKalle Valo 
wl3501_get_wap(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1548*298e50adSKalle Valo static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
1549*298e50adSKalle Valo 			  union iwreq_data *wrqu, char *extra)
1550*298e50adSKalle Valo {
1551*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1552*298e50adSKalle Valo 
1553*298e50adSKalle Valo 	wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1554*298e50adSKalle Valo 	memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
1555*298e50adSKalle Valo 	return 0;
1556*298e50adSKalle Valo }
1557*298e50adSKalle Valo 
wl3501_set_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1558*298e50adSKalle Valo static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
1559*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1560*298e50adSKalle Valo {
1561*298e50adSKalle Valo 	/*
1562*298e50adSKalle Valo 	 * FIXME: trigger scanning with a reset, yes, I'm lazy
1563*298e50adSKalle Valo 	 */
1564*298e50adSKalle Valo 	return wl3501_reset(dev);
1565*298e50adSKalle Valo }
1566*298e50adSKalle Valo 
wl3501_get_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1567*298e50adSKalle Valo static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
1568*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1569*298e50adSKalle Valo {
1570*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1571*298e50adSKalle Valo 	int i;
1572*298e50adSKalle Valo 	char *current_ev = extra;
1573*298e50adSKalle Valo 	struct iw_event iwe;
1574*298e50adSKalle Valo 
1575*298e50adSKalle Valo 	for (i = 0; i < this->bss_cnt; ++i) {
1576*298e50adSKalle Valo 		iwe.cmd			= SIOCGIWAP;
1577*298e50adSKalle Valo 		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1578*298e50adSKalle Valo 		memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].req.bssid, ETH_ALEN);
1579*298e50adSKalle Valo 		current_ev = iwe_stream_add_event(info, current_ev,
1580*298e50adSKalle Valo 						  extra + IW_SCAN_MAX_DATA,
1581*298e50adSKalle Valo 						  &iwe, IW_EV_ADDR_LEN);
1582*298e50adSKalle Valo 		iwe.cmd		  = SIOCGIWESSID;
1583*298e50adSKalle Valo 		iwe.u.data.flags  = 1;
1584*298e50adSKalle Valo 		iwe.u.data.length = this->bss_set[i].req.ssid.el.len;
1585*298e50adSKalle Valo 		current_ev = iwe_stream_add_point(info, current_ev,
1586*298e50adSKalle Valo 						  extra + IW_SCAN_MAX_DATA,
1587*298e50adSKalle Valo 						  &iwe,
1588*298e50adSKalle Valo 						  this->bss_set[i].req.ssid.essid);
1589*298e50adSKalle Valo 		iwe.cmd	   = SIOCGIWMODE;
1590*298e50adSKalle Valo 		iwe.u.mode = this->bss_set[i].req.bss_type;
1591*298e50adSKalle Valo 		current_ev = iwe_stream_add_event(info, current_ev,
1592*298e50adSKalle Valo 						  extra + IW_SCAN_MAX_DATA,
1593*298e50adSKalle Valo 						  &iwe, IW_EV_UINT_LEN);
1594*298e50adSKalle Valo 		iwe.cmd = SIOCGIWFREQ;
1595*298e50adSKalle Valo 		iwe.u.freq.m = this->bss_set[i].req.ds_pset.chan;
1596*298e50adSKalle Valo 		iwe.u.freq.e = 0;
1597*298e50adSKalle Valo 		current_ev = iwe_stream_add_event(info, current_ev,
1598*298e50adSKalle Valo 						  extra + IW_SCAN_MAX_DATA,
1599*298e50adSKalle Valo 						  &iwe, IW_EV_FREQ_LEN);
1600*298e50adSKalle Valo 		iwe.cmd = SIOCGIWENCODE;
1601*298e50adSKalle Valo 		if (this->bss_set[i].req.cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1602*298e50adSKalle Valo 			iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1603*298e50adSKalle Valo 		else
1604*298e50adSKalle Valo 			iwe.u.data.flags = IW_ENCODE_DISABLED;
1605*298e50adSKalle Valo 		iwe.u.data.length = 0;
1606*298e50adSKalle Valo 		current_ev = iwe_stream_add_point(info, current_ev,
1607*298e50adSKalle Valo 						  extra + IW_SCAN_MAX_DATA,
1608*298e50adSKalle Valo 						  &iwe, NULL);
1609*298e50adSKalle Valo 	}
1610*298e50adSKalle Valo 	/* Length of data */
1611*298e50adSKalle Valo 	wrqu->data.length = (current_ev - extra);
1612*298e50adSKalle Valo 	wrqu->data.flags = 0; /* FIXME: set properly these flags */
1613*298e50adSKalle Valo 	return 0;
1614*298e50adSKalle Valo }
1615*298e50adSKalle Valo 
wl3501_set_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1616*298e50adSKalle Valo static int wl3501_set_essid(struct net_device *dev,
1617*298e50adSKalle Valo 			    struct iw_request_info *info,
1618*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1619*298e50adSKalle Valo {
1620*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1621*298e50adSKalle Valo 
1622*298e50adSKalle Valo 	if (wrqu->data.flags) {
1623*298e50adSKalle Valo 		iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1624*298e50adSKalle Valo 					 &this->essid.el,
1625*298e50adSKalle Valo 					 extra, wrqu->data.length);
1626*298e50adSKalle Valo 	} else { /* We accept any ESSID */
1627*298e50adSKalle Valo 		iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1628*298e50adSKalle Valo 					 &this->essid.el, "ANY", 3);
1629*298e50adSKalle Valo 	}
1630*298e50adSKalle Valo 	return wl3501_reset(dev);
1631*298e50adSKalle Valo }
1632*298e50adSKalle Valo 
wl3501_get_essid(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1633*298e50adSKalle Valo static int wl3501_get_essid(struct net_device *dev,
1634*298e50adSKalle Valo 			    struct iw_request_info *info,
1635*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1636*298e50adSKalle Valo {
1637*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1638*298e50adSKalle Valo 	unsigned long flags;
1639*298e50adSKalle Valo 
1640*298e50adSKalle Valo 	spin_lock_irqsave(&this->lock, flags);
1641*298e50adSKalle Valo 	wrqu->essid.flags  = 1;
1642*298e50adSKalle Valo 	wrqu->essid.length = this->essid.el.len;
1643*298e50adSKalle Valo 	memcpy(extra, this->essid.essid, this->essid.el.len);
1644*298e50adSKalle Valo 	spin_unlock_irqrestore(&this->lock, flags);
1645*298e50adSKalle Valo 	return 0;
1646*298e50adSKalle Valo }
1647*298e50adSKalle Valo 
wl3501_set_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1648*298e50adSKalle Valo static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
1649*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1650*298e50adSKalle Valo {
1651*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1652*298e50adSKalle Valo 
1653*298e50adSKalle Valo 	if (wrqu->data.length > sizeof(this->nick))
1654*298e50adSKalle Valo 		return -E2BIG;
1655*298e50adSKalle Valo 	strscpy(this->nick, extra, wrqu->data.length);
1656*298e50adSKalle Valo 	return 0;
1657*298e50adSKalle Valo }
1658*298e50adSKalle Valo 
wl3501_get_nick(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1659*298e50adSKalle Valo static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
1660*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1661*298e50adSKalle Valo {
1662*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1663*298e50adSKalle Valo 
1664*298e50adSKalle Valo 	strscpy(extra, this->nick, 32);
1665*298e50adSKalle Valo 	wrqu->data.length = strlen(extra);
1666*298e50adSKalle Valo 	return 0;
1667*298e50adSKalle Valo }
1668*298e50adSKalle Valo 
wl3501_get_rate(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1669*298e50adSKalle Valo static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
1670*298e50adSKalle Valo 			   union iwreq_data *wrqu, char *extra)
1671*298e50adSKalle Valo {
1672*298e50adSKalle Valo 	/*
1673*298e50adSKalle Valo 	 * FIXME: have to see from where to get this info, perhaps this card
1674*298e50adSKalle Valo 	 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1675*298e50adSKalle Valo 	 * common with the Planet Access Points. -acme
1676*298e50adSKalle Valo 	 */
1677*298e50adSKalle Valo 	wrqu->bitrate.value = 2000000;
1678*298e50adSKalle Valo 	wrqu->bitrate.fixed = 1;
1679*298e50adSKalle Valo 	return 0;
1680*298e50adSKalle Valo }
1681*298e50adSKalle Valo 
wl3501_get_rts_threshold(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1682*298e50adSKalle Valo static int wl3501_get_rts_threshold(struct net_device *dev,
1683*298e50adSKalle Valo 				    struct iw_request_info *info,
1684*298e50adSKalle Valo 				    union iwreq_data *wrqu, char *extra)
1685*298e50adSKalle Valo {
1686*298e50adSKalle Valo 	u16 threshold; /* size checked: it is u16 */
1687*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1688*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
1689*298e50adSKalle Valo 				      &threshold, sizeof(threshold));
1690*298e50adSKalle Valo 	if (!rc) {
1691*298e50adSKalle Valo 		wrqu->rts.value = threshold;
1692*298e50adSKalle Valo 		wrqu->rts.disabled = threshold >= 2347;
1693*298e50adSKalle Valo 		wrqu->rts.fixed = 1;
1694*298e50adSKalle Valo 	}
1695*298e50adSKalle Valo 	return rc;
1696*298e50adSKalle Valo }
1697*298e50adSKalle Valo 
wl3501_get_frag_threshold(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1698*298e50adSKalle Valo static int wl3501_get_frag_threshold(struct net_device *dev,
1699*298e50adSKalle Valo 				     struct iw_request_info *info,
1700*298e50adSKalle Valo 				     union iwreq_data *wrqu, char *extra)
1701*298e50adSKalle Valo {
1702*298e50adSKalle Valo 	u16 threshold; /* size checked: it is u16 */
1703*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1704*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD,
1705*298e50adSKalle Valo 				      &threshold, sizeof(threshold));
1706*298e50adSKalle Valo 	if (!rc) {
1707*298e50adSKalle Valo 		wrqu->frag.value = threshold;
1708*298e50adSKalle Valo 		wrqu->frag.disabled = threshold >= 2346;
1709*298e50adSKalle Valo 		wrqu->frag.fixed = 1;
1710*298e50adSKalle Valo 	}
1711*298e50adSKalle Valo 	return rc;
1712*298e50adSKalle Valo }
1713*298e50adSKalle Valo 
wl3501_get_txpow(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1714*298e50adSKalle Valo static int wl3501_get_txpow(struct net_device *dev,
1715*298e50adSKalle Valo 			    struct iw_request_info *info,
1716*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1717*298e50adSKalle Valo {
1718*298e50adSKalle Valo 	u16 txpow;
1719*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1720*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this,
1721*298e50adSKalle Valo 				      WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
1722*298e50adSKalle Valo 				      &txpow, sizeof(txpow));
1723*298e50adSKalle Valo 	if (!rc) {
1724*298e50adSKalle Valo 		wrqu->txpower.value = txpow;
1725*298e50adSKalle Valo 		wrqu->txpower.disabled = 0;
1726*298e50adSKalle Valo 		/*
1727*298e50adSKalle Valo 		 * From the MIB values I think this can be configurable,
1728*298e50adSKalle Valo 		 * as it lists several tx power levels -acme
1729*298e50adSKalle Valo 		 */
1730*298e50adSKalle Valo 		wrqu->txpower.fixed = 0;
1731*298e50adSKalle Valo 		wrqu->txpower.flags = IW_TXPOW_MWATT;
1732*298e50adSKalle Valo 	}
1733*298e50adSKalle Valo 	return rc;
1734*298e50adSKalle Valo }
1735*298e50adSKalle Valo 
wl3501_get_retry(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1736*298e50adSKalle Valo static int wl3501_get_retry(struct net_device *dev,
1737*298e50adSKalle Valo 			    struct iw_request_info *info,
1738*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1739*298e50adSKalle Valo {
1740*298e50adSKalle Valo 	u8 retry; /* size checked: it is u8 */
1741*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1742*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this,
1743*298e50adSKalle Valo 				      WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
1744*298e50adSKalle Valo 				      &retry, sizeof(retry));
1745*298e50adSKalle Valo 	if (rc)
1746*298e50adSKalle Valo 		goto out;
1747*298e50adSKalle Valo 	if (wrqu->retry.flags & IW_RETRY_LONG) {
1748*298e50adSKalle Valo 		wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
1749*298e50adSKalle Valo 		goto set_value;
1750*298e50adSKalle Valo 	}
1751*298e50adSKalle Valo 	rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1752*298e50adSKalle Valo 				  &retry, sizeof(retry));
1753*298e50adSKalle Valo 	if (rc)
1754*298e50adSKalle Valo 		goto out;
1755*298e50adSKalle Valo 	wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
1756*298e50adSKalle Valo set_value:
1757*298e50adSKalle Valo 	wrqu->retry.value = retry;
1758*298e50adSKalle Valo 	wrqu->retry.disabled = 0;
1759*298e50adSKalle Valo out:
1760*298e50adSKalle Valo 	return rc;
1761*298e50adSKalle Valo }
1762*298e50adSKalle Valo 
wl3501_get_encode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1763*298e50adSKalle Valo static int wl3501_get_encode(struct net_device *dev,
1764*298e50adSKalle Valo 			     struct iw_request_info *info,
1765*298e50adSKalle Valo 			     union iwreq_data *wrqu, char *extra)
1766*298e50adSKalle Valo {
1767*298e50adSKalle Valo 	u8 implemented, restricted, keys[100], len_keys, tocopy;
1768*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1769*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this,
1770*298e50adSKalle Valo 				      WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
1771*298e50adSKalle Valo 				      &implemented, sizeof(implemented));
1772*298e50adSKalle Valo 	if (rc)
1773*298e50adSKalle Valo 		goto out;
1774*298e50adSKalle Valo 	if (!implemented) {
1775*298e50adSKalle Valo 		wrqu->encoding.flags = IW_ENCODE_DISABLED;
1776*298e50adSKalle Valo 		goto out;
1777*298e50adSKalle Valo 	}
1778*298e50adSKalle Valo 	rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
1779*298e50adSKalle Valo 				  &restricted, sizeof(restricted));
1780*298e50adSKalle Valo 	if (rc)
1781*298e50adSKalle Valo 		goto out;
1782*298e50adSKalle Valo 	wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
1783*298e50adSKalle Valo 					    IW_ENCODE_OPEN;
1784*298e50adSKalle Valo 	rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
1785*298e50adSKalle Valo 				  &len_keys, sizeof(len_keys));
1786*298e50adSKalle Valo 	if (rc)
1787*298e50adSKalle Valo 		goto out;
1788*298e50adSKalle Valo 	rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
1789*298e50adSKalle Valo 				  keys, len_keys);
1790*298e50adSKalle Valo 	if (rc)
1791*298e50adSKalle Valo 		goto out;
1792*298e50adSKalle Valo 	tocopy = min_t(u16, len_keys, wrqu->encoding.length);
1793*298e50adSKalle Valo 	tocopy = min_t(u8, tocopy, 100);
1794*298e50adSKalle Valo 	wrqu->encoding.length = tocopy;
1795*298e50adSKalle Valo 	memcpy(extra, keys, tocopy);
1796*298e50adSKalle Valo out:
1797*298e50adSKalle Valo 	return rc;
1798*298e50adSKalle Valo }
1799*298e50adSKalle Valo 
wl3501_get_power(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1800*298e50adSKalle Valo static int wl3501_get_power(struct net_device *dev,
1801*298e50adSKalle Valo 			    struct iw_request_info *info,
1802*298e50adSKalle Valo 			    union iwreq_data *wrqu, char *extra)
1803*298e50adSKalle Valo {
1804*298e50adSKalle Valo 	u8 pwr_state;
1805*298e50adSKalle Valo 	struct wl3501_card *this = netdev_priv(dev);
1806*298e50adSKalle Valo 	int rc = wl3501_get_mib_value(this,
1807*298e50adSKalle Valo 				      WL3501_MIB_ATTR_CURRENT_PWR_STATE,
1808*298e50adSKalle Valo 				      &pwr_state, sizeof(pwr_state));
1809*298e50adSKalle Valo 	if (rc)
1810*298e50adSKalle Valo 		goto out;
1811*298e50adSKalle Valo 	wrqu->power.disabled = !pwr_state;
1812*298e50adSKalle Valo 	wrqu->power.flags = IW_POWER_ON;
1813*298e50adSKalle Valo out:
1814*298e50adSKalle Valo 	return rc;
1815*298e50adSKalle Valo }
1816*298e50adSKalle Valo 
1817*298e50adSKalle Valo static const iw_handler	wl3501_handler[] = {
1818*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWNAME, wl3501_get_name),
1819*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWFREQ, wl3501_set_freq),
1820*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWFREQ, wl3501_get_freq),
1821*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWMODE, wl3501_set_mode),
1822*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWMODE, wl3501_get_mode),
1823*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWSENS, wl3501_get_sens),
1824*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWRANGE, wl3501_get_range),
1825*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
1826*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
1827*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
1828*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
1829*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWAP, wl3501_set_wap),
1830*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWAP, wl3501_get_wap),
1831*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWSCAN, wl3501_set_scan),
1832*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWSCAN, wl3501_get_scan),
1833*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWESSID, wl3501_set_essid),
1834*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWESSID, wl3501_get_essid),
1835*298e50adSKalle Valo 	IW_HANDLER(SIOCSIWNICKN, wl3501_set_nick),
1836*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWNICKN, wl3501_get_nick),
1837*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWRATE, wl3501_get_rate),
1838*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWRTS, wl3501_get_rts_threshold),
1839*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWFRAG, wl3501_get_frag_threshold),
1840*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWTXPOW, wl3501_get_txpow),
1841*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWRETRY, wl3501_get_retry),
1842*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWENCODE, wl3501_get_encode),
1843*298e50adSKalle Valo 	IW_HANDLER(SIOCGIWPOWER, wl3501_get_power),
1844*298e50adSKalle Valo };
1845*298e50adSKalle Valo 
1846*298e50adSKalle Valo static const struct iw_handler_def wl3501_handler_def = {
1847*298e50adSKalle Valo 	.num_standard	= ARRAY_SIZE(wl3501_handler),
1848*298e50adSKalle Valo 	.standard	= (iw_handler *)wl3501_handler,
1849*298e50adSKalle Valo 	.get_wireless_stats = wl3501_get_wireless_stats,
1850*298e50adSKalle Valo };
1851*298e50adSKalle Valo 
1852*298e50adSKalle Valo static const struct net_device_ops wl3501_netdev_ops = {
1853*298e50adSKalle Valo 	.ndo_open		= wl3501_open,
1854*298e50adSKalle Valo 	.ndo_stop		= wl3501_close,
1855*298e50adSKalle Valo 	.ndo_start_xmit		= wl3501_hard_start_xmit,
1856*298e50adSKalle Valo 	.ndo_tx_timeout		= wl3501_tx_timeout,
1857*298e50adSKalle Valo 	.ndo_set_mac_address 	= eth_mac_addr,
1858*298e50adSKalle Valo 	.ndo_validate_addr	= eth_validate_addr,
1859*298e50adSKalle Valo };
1860*298e50adSKalle Valo 
wl3501_probe(struct pcmcia_device * p_dev)1861*298e50adSKalle Valo static int wl3501_probe(struct pcmcia_device *p_dev)
1862*298e50adSKalle Valo {
1863*298e50adSKalle Valo 	struct net_device *dev;
1864*298e50adSKalle Valo 	struct wl3501_card *this;
1865*298e50adSKalle Valo 	int ret;
1866*298e50adSKalle Valo 
1867*298e50adSKalle Valo 	/* The io structure describes IO port mapping */
1868*298e50adSKalle Valo 	p_dev->resource[0]->end	= 16;
1869*298e50adSKalle Valo 	p_dev->resource[0]->flags	= IO_DATA_PATH_WIDTH_8;
1870*298e50adSKalle Valo 
1871*298e50adSKalle Valo 	/* General socket configuration */
1872*298e50adSKalle Valo 	p_dev->config_flags	= CONF_ENABLE_IRQ;
1873*298e50adSKalle Valo 	p_dev->config_index	= 1;
1874*298e50adSKalle Valo 
1875*298e50adSKalle Valo 	dev = alloc_etherdev(sizeof(struct wl3501_card));
1876*298e50adSKalle Valo 	if (!dev)
1877*298e50adSKalle Valo 		return -ENOMEM;
1878*298e50adSKalle Valo 
1879*298e50adSKalle Valo 	dev->netdev_ops		= &wl3501_netdev_ops;
1880*298e50adSKalle Valo 	dev->watchdog_timeo	= 5 * HZ;
1881*298e50adSKalle Valo 
1882*298e50adSKalle Valo 	this = netdev_priv(dev);
1883*298e50adSKalle Valo 	this->wireless_data.spy_data = &this->spy_data;
1884*298e50adSKalle Valo 	this->p_dev = p_dev;
1885*298e50adSKalle Valo 	dev->wireless_data	= &this->wireless_data;
1886*298e50adSKalle Valo 	dev->wireless_handlers	= &wl3501_handler_def;
1887*298e50adSKalle Valo 	netif_stop_queue(dev);
1888*298e50adSKalle Valo 	p_dev->priv = dev;
1889*298e50adSKalle Valo 
1890*298e50adSKalle Valo 	ret = wl3501_config(p_dev);
1891*298e50adSKalle Valo 	if (ret)
1892*298e50adSKalle Valo 		goto out_free_etherdev;
1893*298e50adSKalle Valo 
1894*298e50adSKalle Valo 	return 0;
1895*298e50adSKalle Valo 
1896*298e50adSKalle Valo out_free_etherdev:
1897*298e50adSKalle Valo 	free_netdev(dev);
1898*298e50adSKalle Valo 	return ret;
1899*298e50adSKalle Valo }
1900*298e50adSKalle Valo 
wl3501_config(struct pcmcia_device * link)1901*298e50adSKalle Valo static int wl3501_config(struct pcmcia_device *link)
1902*298e50adSKalle Valo {
1903*298e50adSKalle Valo 	struct net_device *dev = link->priv;
1904*298e50adSKalle Valo 	int i = 0, j, ret;
1905*298e50adSKalle Valo 	struct wl3501_card *this;
1906*298e50adSKalle Valo 
1907*298e50adSKalle Valo 	/* Try allocating IO ports.  This tries a few fixed addresses.  If you
1908*298e50adSKalle Valo 	 * want, you can also read the card's config table to pick addresses --
1909*298e50adSKalle Valo 	 * see the serial driver for an example. */
1910*298e50adSKalle Valo 	link->io_lines = 5;
1911*298e50adSKalle Valo 
1912*298e50adSKalle Valo 	for (j = 0x280; j < 0x400; j += 0x20) {
1913*298e50adSKalle Valo 		/* The '^0x300' is so that we probe 0x300-0x3ff first, then
1914*298e50adSKalle Valo 		 * 0x200-0x2ff, and so on, because this seems safer */
1915*298e50adSKalle Valo 		link->resource[0]->start = j;
1916*298e50adSKalle Valo 		link->resource[1]->start = link->resource[0]->start + 0x10;
1917*298e50adSKalle Valo 		i = pcmcia_request_io(link);
1918*298e50adSKalle Valo 		if (i == 0)
1919*298e50adSKalle Valo 			break;
1920*298e50adSKalle Valo 	}
1921*298e50adSKalle Valo 	if (i != 0)
1922*298e50adSKalle Valo 		goto failed;
1923*298e50adSKalle Valo 
1924*298e50adSKalle Valo 	/* Now allocate an interrupt line. Note that this does not actually
1925*298e50adSKalle Valo 	 * assign a handler to the interrupt. */
1926*298e50adSKalle Valo 
1927*298e50adSKalle Valo 	ret = pcmcia_request_irq(link, wl3501_interrupt);
1928*298e50adSKalle Valo 	if (ret)
1929*298e50adSKalle Valo 		goto failed;
1930*298e50adSKalle Valo 
1931*298e50adSKalle Valo 	ret = pcmcia_enable_device(link);
1932*298e50adSKalle Valo 	if (ret)
1933*298e50adSKalle Valo 		goto failed;
1934*298e50adSKalle Valo 
1935*298e50adSKalle Valo 	dev->irq = link->irq;
1936*298e50adSKalle Valo 	dev->base_addr = link->resource[0]->start;
1937*298e50adSKalle Valo 	SET_NETDEV_DEV(dev, &link->dev);
1938*298e50adSKalle Valo 	if (register_netdev(dev)) {
1939*298e50adSKalle Valo 		printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
1940*298e50adSKalle Valo 		goto failed;
1941*298e50adSKalle Valo 	}
1942*298e50adSKalle Valo 
1943*298e50adSKalle Valo 	this = netdev_priv(dev);
1944*298e50adSKalle Valo 
1945*298e50adSKalle Valo 	this->base_addr = dev->base_addr;
1946*298e50adSKalle Valo 
1947*298e50adSKalle Valo 	if (!wl3501_get_flash_mac_addr(this)) {
1948*298e50adSKalle Valo 		printk(KERN_WARNING "%s: Can't read MAC addr in flash ROM?\n",
1949*298e50adSKalle Valo 		       dev->name);
1950*298e50adSKalle Valo 		unregister_netdev(dev);
1951*298e50adSKalle Valo 		goto failed;
1952*298e50adSKalle Valo 	}
1953*298e50adSKalle Valo 
1954*298e50adSKalle Valo 	eth_hw_addr_set(dev, this->mac_addr);
1955*298e50adSKalle Valo 
1956*298e50adSKalle Valo 	/* print probe information */
1957*298e50adSKalle Valo 	printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, "
1958*298e50adSKalle Valo 	       "MAC addr in flash ROM:%pM\n",
1959*298e50adSKalle Valo 	       dev->name, this->base_addr, (int)dev->irq,
1960*298e50adSKalle Valo 	       dev->dev_addr);
1961*298e50adSKalle Valo 	/*
1962*298e50adSKalle Valo 	 * Initialize card parameters - added by jss
1963*298e50adSKalle Valo 	 */
1964*298e50adSKalle Valo 	this->net_type		= IW_MODE_INFRA;
1965*298e50adSKalle Valo 	this->bss_cnt		= 0;
1966*298e50adSKalle Valo 	this->join_sta_bss	= 0;
1967*298e50adSKalle Valo 	this->adhoc_times	= 0;
1968*298e50adSKalle Valo 	iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
1969*298e50adSKalle Valo 				 "ANY", 3);
1970*298e50adSKalle Valo 	this->card_name[0]	= '\0';
1971*298e50adSKalle Valo 	this->firmware_date[0]	= '\0';
1972*298e50adSKalle Valo 	this->rssi		= 255;
1973*298e50adSKalle Valo 	this->chan		= iw_default_channel(this->reg_domain);
1974*298e50adSKalle Valo 	strscpy(this->nick, "Planet WL3501", sizeof(this->nick));
1975*298e50adSKalle Valo 	spin_lock_init(&this->lock);
1976*298e50adSKalle Valo 	init_waitqueue_head(&this->wait);
1977*298e50adSKalle Valo 	netif_start_queue(dev);
1978*298e50adSKalle Valo 	return 0;
1979*298e50adSKalle Valo 
1980*298e50adSKalle Valo failed:
1981*298e50adSKalle Valo 	wl3501_release(link);
1982*298e50adSKalle Valo 	return -ENODEV;
1983*298e50adSKalle Valo }
1984*298e50adSKalle Valo 
wl3501_release(struct pcmcia_device * link)1985*298e50adSKalle Valo static void wl3501_release(struct pcmcia_device *link)
1986*298e50adSKalle Valo {
1987*298e50adSKalle Valo 	pcmcia_disable_device(link);
1988*298e50adSKalle Valo }
1989*298e50adSKalle Valo 
wl3501_suspend(struct pcmcia_device * link)1990*298e50adSKalle Valo static int wl3501_suspend(struct pcmcia_device *link)
1991*298e50adSKalle Valo {
1992*298e50adSKalle Valo 	struct net_device *dev = link->priv;
1993*298e50adSKalle Valo 
1994*298e50adSKalle Valo 	wl3501_pwr_mgmt(netdev_priv(dev), WL3501_SUSPEND);
1995*298e50adSKalle Valo 	if (link->open)
1996*298e50adSKalle Valo 		netif_device_detach(dev);
1997*298e50adSKalle Valo 
1998*298e50adSKalle Valo 	return 0;
1999*298e50adSKalle Valo }
2000*298e50adSKalle Valo 
wl3501_resume(struct pcmcia_device * link)2001*298e50adSKalle Valo static int wl3501_resume(struct pcmcia_device *link)
2002*298e50adSKalle Valo {
2003*298e50adSKalle Valo 	struct net_device *dev = link->priv;
2004*298e50adSKalle Valo 
2005*298e50adSKalle Valo 	wl3501_pwr_mgmt(netdev_priv(dev), WL3501_RESUME);
2006*298e50adSKalle Valo 	if (link->open) {
2007*298e50adSKalle Valo 		wl3501_reset(dev);
2008*298e50adSKalle Valo 		netif_device_attach(dev);
2009*298e50adSKalle Valo 	}
2010*298e50adSKalle Valo 
2011*298e50adSKalle Valo 	return 0;
2012*298e50adSKalle Valo }
2013*298e50adSKalle Valo 
2014*298e50adSKalle Valo 
2015*298e50adSKalle Valo static const struct pcmcia_device_id wl3501_ids[] = {
2016*298e50adSKalle Valo 	PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
2017*298e50adSKalle Valo 	PCMCIA_DEVICE_NULL
2018*298e50adSKalle Valo };
2019*298e50adSKalle Valo MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2020*298e50adSKalle Valo 
2021*298e50adSKalle Valo static struct pcmcia_driver wl3501_driver = {
2022*298e50adSKalle Valo 	.owner		= THIS_MODULE,
2023*298e50adSKalle Valo 	.name		= "wl3501_cs",
2024*298e50adSKalle Valo 	.probe		= wl3501_probe,
2025*298e50adSKalle Valo 	.remove		= wl3501_detach,
2026*298e50adSKalle Valo 	.id_table	= wl3501_ids,
2027*298e50adSKalle Valo 	.suspend	= wl3501_suspend,
2028*298e50adSKalle Valo 	.resume		= wl3501_resume,
2029*298e50adSKalle Valo };
2030*298e50adSKalle Valo module_pcmcia_driver(wl3501_driver);
2031 
2032 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2033 	      "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2034 	      "Gustavo Niemeyer <niemeyer@conectiva.com>");
2035 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2036 MODULE_LICENSE("GPL");
2037