Diff markup
1 /* 1 /*
2 * WL3501 Wireless LAN PCMCIA Card Driver for 2 * WL3501 Wireless LAN PCMCIA Card Driver for Linux
3 * Written originally for Linux 2.0.30 by Fox 3 * Written originally for Linux 2.0.30 by Fox Chen, mhchen@golf.ccl.itri.org.tw
4 * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalh 4 * Ported to 2.2, 2.4 & 2.5 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
5 * Wireless extensions in 2.4 by Gustavo Nieme 5 * Wireless extensions in 2.4 by Gustavo Niemeyer <niemeyer@conectiva.com>
6 * 6 *
7 * References used by Fox Chen while writing t 7 * References used by Fox Chen while writing the original driver for 2.0.30:
8 * 8 *
9 * 1. WL24xx packet drivers (tooasm.asm) 9 * 1. WL24xx packet drivers (tooasm.asm)
10 * 2. Access Point Firmware Interface Specif 10 * 2. Access Point Firmware Interface Specification for IEEE 802.11 SUTRO
11 * 3. IEEE 802.11 11 * 3. IEEE 802.11
12 * 4. Linux network driver (/usr/src/linux/d 12 * 4. Linux network driver (/usr/src/linux/drivers/net)
13 * 5. ISA card driver - wl24.c 13 * 5. ISA card driver - wl24.c
14 * 6. Linux PCMCIA skeleton driver - skeleto 14 * 6. Linux PCMCIA skeleton driver - skeleton.c
15 * 7. Linux PCMCIA 3c589 network driver - 3c 15 * 7. Linux PCMCIA 3c589 network driver - 3c589_cs.c
16 * 16 *
17 * Tested with WL2400 firmware 1.2, Linux 2.0. 17 * Tested with WL2400 firmware 1.2, Linux 2.0.30, and pcmcia-cs-2.9.12
18 * 1. Performance: about 165 Kbytes/sec in T 18 * 1. Performance: about 165 Kbytes/sec in TCP/IP with Ad-Hoc mode.
19 * rsh 192.168.1.3 "dd if=/dev/zero bs=1k 19 * rsh 192.168.1.3 "dd if=/dev/zero bs=1k count=1000" > /dev/null
20 * (Specification 2M bits/sec. is about 2 20 * (Specification 2M bits/sec. is about 250 Kbytes/sec., but we must deduct
21 * ETHER/IP/UDP/TCP header, and acknowle 21 * ETHER/IP/UDP/TCP header, and acknowledgement overhead)
22 * 22 *
23 * Tested with Planet AP in 2.4.17, 184 Kbytes 23 * Tested with Planet AP in 2.4.17, 184 Kbytes/s in UDP in Infrastructure mode,
24 * 173 Kbytes/s in TCP. 24 * 173 Kbytes/s in TCP.
25 * 25 *
26 * Tested with Planet AP in 2.5.73-bk, 216 Kby 26 * Tested with Planet AP in 2.5.73-bk, 216 Kbytes/s in Infrastructure mode
27 * with a SMP machine (dual pentium 100), usin 27 * with a SMP machine (dual pentium 100), using pktgen, 432 pps (pkt_size = 60)
28 */ 28 */
>> 29 #undef REALLY_SLOW_IO /* most systems can safely undef this */
29 30
>> 31 #include <linux/config.h>
30 #include <linux/delay.h> 32 #include <linux/delay.h>
31 #include <linux/types.h> 33 #include <linux/types.h>
32 #include <linux/ethtool.h> 34 #include <linux/ethtool.h>
33 #include <linux/init.h> 35 #include <linux/init.h>
34 #include <linux/interrupt.h> 36 #include <linux/interrupt.h>
35 #include <linux/in.h> 37 #include <linux/in.h>
36 #include <linux/kernel.h> 38 #include <linux/kernel.h>
37 #include <linux/module.h> 39 #include <linux/module.h>
38 #include <linux/fcntl.h> 40 #include <linux/fcntl.h>
39 #include <linux/if_arp.h> 41 #include <linux/if_arp.h>
40 #include <linux/ioport.h> 42 #include <linux/ioport.h>
41 #include <linux/netdevice.h> 43 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h> 44 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h> 45 #include <linux/skbuff.h>
44 #include <linux/slab.h> 46 #include <linux/slab.h>
45 #include <linux/string.h> 47 #include <linux/string.h>
46 #include <linux/wireless.h> 48 #include <linux/wireless.h>
47 49
48 #include <net/iw_handler.h> 50 #include <net/iw_handler.h>
49 51
>> 52 #include <pcmcia/version.h>
50 #include <pcmcia/cs_types.h> 53 #include <pcmcia/cs_types.h>
51 #include <pcmcia/cs.h> 54 #include <pcmcia/cs.h>
52 #include <pcmcia/cistpl.h> 55 #include <pcmcia/cistpl.h>
53 #include <pcmcia/cisreg.h> 56 #include <pcmcia/cisreg.h>
54 #include <pcmcia/ds.h> 57 #include <pcmcia/ds.h>
55 58
56 #include <asm/io.h> 59 #include <asm/io.h>
57 #include <asm/uaccess.h> 60 #include <asm/uaccess.h>
58 #include <asm/system.h> 61 #include <asm/system.h>
59 62
60 #include "wl3501.h" 63 #include "wl3501.h"
61 64
62 #ifndef __i386__ 65 #ifndef __i386__
63 #define slow_down_io() 66 #define slow_down_io()
64 #endif 67 #endif
65 68
66 /* For rough constant delay */ 69 /* For rough constant delay */
67 #define WL3501_NOPLOOP(n) { int x = 0; while ( 70 #define WL3501_NOPLOOP(n) { int x = 0; while (x++ < n) slow_down_io(); }
68 71
69 /* 72 /*
70 * All the PCMCIA modules use PCMCIA_DEBUG to 73 * All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If you do not
71 * define PCMCIA_DEBUG at all, all the debug c 74 * define PCMCIA_DEBUG at all, all the debug code will be left out. If you
72 * compile with PCMCIA_DEBUG=0, the debug code 75 * compile with PCMCIA_DEBUG=0, the debug code will be present but disabled --
73 * but it can then be enabled for specific mod 76 * but it can then be enabled for specific modules at load time with a
74 * 'pc_debug=#' option to insmod. 77 * 'pc_debug=#' option to insmod.
75 */ 78 */
76 #define PCMCIA_DEBUG 0 79 #define PCMCIA_DEBUG 0
77 #ifdef PCMCIA_DEBUG 80 #ifdef PCMCIA_DEBUG
78 static int pc_debug = PCMCIA_DEBUG; 81 static int pc_debug = PCMCIA_DEBUG;
79 module_param(pc_debug, int, 0); 82 module_param(pc_debug, int, 0);
80 #define dprintk(n, format, args...) \ 83 #define dprintk(n, format, args...) \
81 { if (pc_debug > (n)) \ 84 { if (pc_debug > (n)) \
82 printk(KERN_INFO "%s: " format 85 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##args); }
83 #else 86 #else
84 #define dprintk(n, format, args...) 87 #define dprintk(n, format, args...)
85 #endif 88 #endif
86 89
87 #define wl3501_outb(a, b) { outb(a, b); slow_d 90 #define wl3501_outb(a, b) { outb(a, b); slow_down_io(); }
88 #define wl3501_outb_p(a, b) { outb_p(a, b); sl 91 #define wl3501_outb_p(a, b) { outb_p(a, b); slow_down_io(); }
89 #define wl3501_outsb(a, b, c) { outsb(a, b, c) 92 #define wl3501_outsb(a, b, c) { outsb(a, b, c); slow_down_io(); }
90 93
91 #define WL3501_RELEASE_TIMEOUT (25 * HZ) 94 #define WL3501_RELEASE_TIMEOUT (25 * HZ)
92 #define WL3501_MAX_ADHOC_TRIES 16 95 #define WL3501_MAX_ADHOC_TRIES 16
93 96
94 #define WL3501_RESUME 0 97 #define WL3501_RESUME 0
95 #define WL3501_SUSPEND 1 98 #define WL3501_SUSPEND 1
96 99
97 /* 100 /*
98 * The event() function is this driver's Card 101 * The event() function is this driver's Card Services event handler. It will
99 * be called by Card Services when an appropri 102 * be called by Card Services when an appropriate card status event is
100 * received. The config() and release() entry 103 * received. The config() and release() entry points are used to configure or
101 * release a socket, in response to card inser 104 * release a socket, in response to card insertion and ejection events. They
102 * are invoked from the wl24 event handler. 105 * are invoked from the wl24 event handler.
103 */ 106 */
104 static int wl3501_config(struct pcmcia_device !! 107 static void wl3501_config(dev_link_t *link);
105 static void wl3501_release(struct pcmcia_devic !! 108 static void wl3501_release(dev_link_t *link);
>> 109 static int wl3501_event(event_t event, int pri, event_callback_args_t *args);
106 110
107 /* 111 /*
108 * The dev_info variable is the "key" that is 112 * The dev_info variable is the "key" that is used to match up this
109 * device driver with appropriate cards, throu 113 * device driver with appropriate cards, through the card configuration
110 * database. 114 * database.
111 */ 115 */
112 static dev_info_t wl3501_dev_info = "wl3501_cs 116 static dev_info_t wl3501_dev_info = "wl3501_cs";
113 117
114 static int wl3501_chan2freq[] = { 118 static int wl3501_chan2freq[] = {
115 [0] = 2412, [1] = 2417, [2] = 2422, 119 [0] = 2412, [1] = 2417, [2] = 2422, [3] = 2427, [4] = 2432,
116 [5] = 2437, [6] = 2442, [7] = 2447, 120 [5] = 2437, [6] = 2442, [7] = 2447, [8] = 2452, [9] = 2457,
117 [10] = 2462, [11] = 2467, [12] = 2472, 121 [10] = 2462, [11] = 2467, [12] = 2472, [13] = 2477,
118 }; 122 };
119 123
120 static const struct { 124 static const struct {
121 int reg_domain; 125 int reg_domain;
122 int min, max, deflt; 126 int min, max, deflt;
123 } iw_channel_table[] = { 127 } iw_channel_table[] = {
124 { 128 {
125 .reg_domain = IW_REG_DOMAIN_FC 129 .reg_domain = IW_REG_DOMAIN_FCC,
126 .min = 1, 130 .min = 1,
127 .max = 11, 131 .max = 11,
128 .deflt = 1, 132 .deflt = 1,
129 }, 133 },
130 { 134 {
131 .reg_domain = IW_REG_DOMAIN_DO 135 .reg_domain = IW_REG_DOMAIN_DOC,
132 .min = 1, 136 .min = 1,
133 .max = 11, 137 .max = 11,
134 .deflt = 1, 138 .deflt = 1,
135 }, 139 },
136 { 140 {
137 .reg_domain = IW_REG_DOMAIN_ET 141 .reg_domain = IW_REG_DOMAIN_ETSI,
138 .min = 1, 142 .min = 1,
139 .max = 13, 143 .max = 13,
140 .deflt = 1, 144 .deflt = 1,
141 }, 145 },
142 { 146 {
143 .reg_domain = IW_REG_DOMAIN_SP 147 .reg_domain = IW_REG_DOMAIN_SPAIN,
144 .min = 10, 148 .min = 10,
145 .max = 11, 149 .max = 11,
146 .deflt = 10, 150 .deflt = 10,
147 }, 151 },
148 { 152 {
149 .reg_domain = IW_REG_DOMAIN_FR 153 .reg_domain = IW_REG_DOMAIN_FRANCE,
150 .min = 10, 154 .min = 10,
151 .max = 13, 155 .max = 13,
152 .deflt = 10, 156 .deflt = 10,
153 }, 157 },
154 { 158 {
155 .reg_domain = IW_REG_DOMAIN_MK 159 .reg_domain = IW_REG_DOMAIN_MKK,
156 .min = 14, 160 .min = 14,
157 .max = 14, 161 .max = 14,
158 .deflt = 14, 162 .deflt = 14,
159 }, 163 },
160 { 164 {
161 .reg_domain = IW_REG_DOMAIN_MK 165 .reg_domain = IW_REG_DOMAIN_MKK1,
162 .min = 1, 166 .min = 1,
163 .max = 14, 167 .max = 14,
164 .deflt = 1, 168 .deflt = 1,
165 }, 169 },
166 { 170 {
167 .reg_domain = IW_REG_DOMAIN_IS 171 .reg_domain = IW_REG_DOMAIN_ISRAEL,
168 .min = 3, 172 .min = 3,
169 .max = 9, 173 .max = 9,
170 .deflt = 9, 174 .deflt = 9,
171 }, 175 },
172 }; 176 };
173 177
174 /** 178 /**
175 * iw_valid_channel - validate channel in regu 179 * iw_valid_channel - validate channel in regulatory domain
176 * @reg_comain - regulatory domain 180 * @reg_comain - regulatory domain
177 * @channel - channel to validate 181 * @channel - channel to validate
178 * 182 *
179 * Returns 0 if invalid in the specified regul 183 * Returns 0 if invalid in the specified regulatory domain, non-zero if valid.
180 */ 184 */
181 static int iw_valid_channel(int reg_domain, in 185 static int iw_valid_channel(int reg_domain, int channel)
182 { 186 {
183 int i, rc = 0; 187 int i, rc = 0;
184 188
185 for (i = 0; i < ARRAY_SIZE(iw_channel_ 189 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
186 if (reg_domain == iw_channel_t 190 if (reg_domain == iw_channel_table[i].reg_domain) {
187 rc = channel >= iw_cha 191 rc = channel >= iw_channel_table[i].min &&
188 channel <= iw_cha 192 channel <= iw_channel_table[i].max;
189 break; 193 break;
190 } 194 }
191 return rc; 195 return rc;
192 } 196 }
193 197
194 /** 198 /**
195 * iw_default_channel - get default channel fo 199 * iw_default_channel - get default channel for a regulatory domain
196 * @reg_comain - regulatory domain 200 * @reg_comain - regulatory domain
197 * 201 *
198 * Returns the default channel for a regulator 202 * Returns the default channel for a regulatory domain
199 */ 203 */
200 static int iw_default_channel(int reg_domain) 204 static int iw_default_channel(int reg_domain)
201 { 205 {
202 int i, rc = 1; 206 int i, rc = 1;
203 207
204 for (i = 0; i < ARRAY_SIZE(iw_channel_ 208 for (i = 0; i < ARRAY_SIZE(iw_channel_table); i++)
205 if (reg_domain == iw_channel_t 209 if (reg_domain == iw_channel_table[i].reg_domain) {
206 rc = iw_channel_table[ 210 rc = iw_channel_table[i].deflt;
207 break; 211 break;
208 } 212 }
209 return rc; 213 return rc;
210 } 214 }
211 215
212 static void iw_set_mgmt_info_element(enum iw_m 216 static void iw_set_mgmt_info_element(enum iw_mgmt_info_element_ids id,
213 struct iw 217 struct iw_mgmt_info_element *el,
214 void *val 218 void *value, int len)
215 { 219 {
216 el->id = id; 220 el->id = id;
217 el->len = len; 221 el->len = len;
218 memcpy(el->data, value, len); 222 memcpy(el->data, value, len);
219 } 223 }
220 224
221 static void iw_copy_mgmt_info_element(struct i 225 static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
222 struct i 226 struct iw_mgmt_info_element *from)
223 { 227 {
224 iw_set_mgmt_info_element(from->id, to, 228 iw_set_mgmt_info_element(from->id, to, from->data, from->len);
225 } 229 }
226 230
>> 231 /*
>> 232 * A linked list of "instances" of the wl24 device. Each actual PCMCIA card
>> 233 * corresponds to one device instance, and is described by one dev_link_t
>> 234 * structure (defined in ds.h).
>> 235 *
>> 236 * You may not want to use a linked list for this -- for example, the memory
>> 237 * card driver uses an array of dev_link_t pointers, where minor device numbers
>> 238 * are used to derive the corresponding array index.
>> 239 */
>> 240 static dev_link_t *wl3501_dev_list;
>> 241
227 static inline void wl3501_switch_page(struct w 242 static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
228 { 243 {
229 wl3501_outb(page, this->base_addr + WL 244 wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
230 } 245 }
231 246
232 /* 247 /*
233 * Get Ethernet MAC addresss. 248 * Get Ethernet MAC addresss.
234 * 249 *
235 * WARNING: We switch to FPAGE0 and switc back 250 * WARNING: We switch to FPAGE0 and switc back again.
236 * Making sure there is no other WL f 251 * Making sure there is no other WL function beening called by ISR.
237 */ 252 */
238 static int wl3501_get_flash_mac_addr(struct wl 253 static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
239 { 254 {
240 int base_addr = this->base_addr; 255 int base_addr = this->base_addr;
241 256
242 /* get MAC addr */ 257 /* get MAC addr */
243 wl3501_outb(WL3501_BSS_FPAGE3, base_ad 258 wl3501_outb(WL3501_BSS_FPAGE3, base_addr + WL3501_NIC_BSS); /* BSS */
244 wl3501_outb(0x00, base_addr + WL3501_N 259 wl3501_outb(0x00, base_addr + WL3501_NIC_LMAL); /* LMAL */
245 wl3501_outb(0x40, base_addr + WL3501_N 260 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH); /* LMAH */
246 261
247 /* wait for reading EEPROM */ 262 /* wait for reading EEPROM */
248 WL3501_NOPLOOP(100); 263 WL3501_NOPLOOP(100);
249 this->mac_addr[0] = inb(base_addr + WL 264 this->mac_addr[0] = inb(base_addr + WL3501_NIC_IODPA);
250 WL3501_NOPLOOP(100); 265 WL3501_NOPLOOP(100);
251 this->mac_addr[1] = inb(base_addr + WL 266 this->mac_addr[1] = inb(base_addr + WL3501_NIC_IODPA);
252 WL3501_NOPLOOP(100); 267 WL3501_NOPLOOP(100);
253 this->mac_addr[2] = inb(base_addr + WL 268 this->mac_addr[2] = inb(base_addr + WL3501_NIC_IODPA);
254 WL3501_NOPLOOP(100); 269 WL3501_NOPLOOP(100);
255 this->mac_addr[3] = inb(base_addr + WL 270 this->mac_addr[3] = inb(base_addr + WL3501_NIC_IODPA);
256 WL3501_NOPLOOP(100); 271 WL3501_NOPLOOP(100);
257 this->mac_addr[4] = inb(base_addr + WL 272 this->mac_addr[4] = inb(base_addr + WL3501_NIC_IODPA);
258 WL3501_NOPLOOP(100); 273 WL3501_NOPLOOP(100);
259 this->mac_addr[5] = inb(base_addr + WL 274 this->mac_addr[5] = inb(base_addr + WL3501_NIC_IODPA);
260 WL3501_NOPLOOP(100); 275 WL3501_NOPLOOP(100);
261 this->reg_domain = inb(base_addr + WL3 276 this->reg_domain = inb(base_addr + WL3501_NIC_IODPA);
262 WL3501_NOPLOOP(100); 277 WL3501_NOPLOOP(100);
263 wl3501_outb(WL3501_BSS_FPAGE0, base_ad 278 wl3501_outb(WL3501_BSS_FPAGE0, base_addr + WL3501_NIC_BSS);
264 wl3501_outb(0x04, base_addr + WL3501_N 279 wl3501_outb(0x04, base_addr + WL3501_NIC_LMAL);
265 wl3501_outb(0x40, base_addr + WL3501_N 280 wl3501_outb(0x40, base_addr + WL3501_NIC_LMAH);
266 WL3501_NOPLOOP(100); 281 WL3501_NOPLOOP(100);
267 this->version[0] = inb(base_addr + WL3 282 this->version[0] = inb(base_addr + WL3501_NIC_IODPA);
268 WL3501_NOPLOOP(100); 283 WL3501_NOPLOOP(100);
269 this->version[1] = inb(base_addr + WL3 284 this->version[1] = inb(base_addr + WL3501_NIC_IODPA);
270 /* switch to SRAM Page 0 (for safety) 285 /* switch to SRAM Page 0 (for safety) */
271 wl3501_switch_page(this, WL3501_BSS_SP 286 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
272 287
273 /* The MAC addr should be 00:60:... */ 288 /* The MAC addr should be 00:60:... */
274 return this->mac_addr[0] == 0x00 && th 289 return this->mac_addr[0] == 0x00 && this->mac_addr[1] == 0x60;
275 } 290 }
276 291
277 /** 292 /**
278 * wl3501_set_to_wla - Move 'size' bytes from 293 * wl3501_set_to_wla - Move 'size' bytes from PC to card
279 * @dest: Card addressing space 294 * @dest: Card addressing space
280 * @src: PC addressing space 295 * @src: PC addressing space
281 * @size: Bytes to move 296 * @size: Bytes to move
282 * 297 *
283 * Move 'size' bytes from PC to card. (Shouldn 298 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
284 */ 299 */
285 static void wl3501_set_to_wla(struct wl3501_ca !! 300 void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
286 int size) <<
287 { 301 {
288 /* switch to SRAM Page 0 */ 302 /* switch to SRAM Page 0 */
289 wl3501_switch_page(this, (dest & 0x800 303 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
290 304 WL3501_BSS_SPAGE0);
291 /* set LMAL and LMAH */ 305 /* set LMAL and LMAH */
292 wl3501_outb(dest & 0xff, this->base_ad 306 wl3501_outb(dest & 0xff, this->base_addr + WL3501_NIC_LMAL);
293 wl3501_outb(((dest >> 8) & 0x7f), this 307 wl3501_outb(((dest >> 8) & 0x7f), this->base_addr + WL3501_NIC_LMAH);
294 308
295 /* rep out to Port A */ 309 /* rep out to Port A */
296 wl3501_outsb(this->base_addr + WL3501_ 310 wl3501_outsb(this->base_addr + WL3501_NIC_IODPA, src, size);
297 } 311 }
298 312
299 /** 313 /**
300 * wl3501_get_from_wla - Move 'size' bytes fro 314 * wl3501_get_from_wla - Move 'size' bytes from card to PC
301 * @src: Card addressing space 315 * @src: Card addressing space
302 * @dest: PC addressing space 316 * @dest: PC addressing space
303 * @size: Bytes to move 317 * @size: Bytes to move
304 * 318 *
305 * Move 'size' bytes from card to PC. (Shouldn 319 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
306 */ 320 */
307 static void wl3501_get_from_wla(struct wl3501_ !! 321 void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
308 int size) !! 322 int size)
309 { 323 {
310 /* switch to SRAM Page 0 */ 324 /* switch to SRAM Page 0 */
311 wl3501_switch_page(this, (src & 0x8000 325 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
312 326 WL3501_BSS_SPAGE0);
313 /* set LMAL and LMAH */ 327 /* set LMAL and LMAH */
314 wl3501_outb(src & 0xff, this->base_add 328 wl3501_outb(src & 0xff, this->base_addr + WL3501_NIC_LMAL);
315 wl3501_outb((src >> 8) & 0x7f, this->b 329 wl3501_outb((src >> 8) & 0x7f, this->base_addr + WL3501_NIC_LMAH);
316 330
317 /* rep get from Port A */ 331 /* rep get from Port A */
318 insb(this->base_addr + WL3501_NIC_IODP 332 insb(this->base_addr + WL3501_NIC_IODPA, dest, size);
319 } 333 }
320 334
321 /* 335 /*
322 * Get/Allocate a free Tx Data Buffer 336 * Get/Allocate a free Tx Data Buffer
323 * 337 *
324 * *--------------*-----------------*-------- 338 * *--------------*-----------------*----------------------------------*
325 * | PLCP | MAC Header | DST S 339 * | PLCP | MAC Header | DST SRC Data ... |
326 * | (24 bytes) | (30 bytes) | (6) ( 340 * | (24 bytes) | (30 bytes) | (6) (6) (Ethernet Row Data) |
327 * *--------------*-----------------*-------- 341 * *--------------*-----------------*----------------------------------*
328 * \ \- IEEE 802.11 -/ \------- 342 * \ \- IEEE 802.11 -/ \-------------- len --------------/
329 * \-struct wl3501_80211_tx_hdr--/ \------ 343 * \-struct wl3501_80211_tx_hdr--/ \-------- Ethernet Frame -------/
330 * 344 *
331 * Return = Postion in Card 345 * Return = Postion in Card
332 */ 346 */
333 static u16 wl3501_get_tx_buffer(struct wl3501_ 347 static u16 wl3501_get_tx_buffer(struct wl3501_card *this, u16 len)
334 { 348 {
335 u16 next, blk_cnt = 0, zero = 0; 349 u16 next, blk_cnt = 0, zero = 0;
336 u16 full_len = sizeof(struct wl3501_80 350 u16 full_len = sizeof(struct wl3501_80211_tx_hdr) + len;
337 u16 ret = 0; 351 u16 ret = 0;
338 352
339 if (full_len > this->tx_buffer_cnt * 2 353 if (full_len > this->tx_buffer_cnt * 254)
340 goto out; 354 goto out;
341 ret = this->tx_buffer_head; 355 ret = this->tx_buffer_head;
342 while (full_len) { 356 while (full_len) {
343 if (full_len < 254) 357 if (full_len < 254)
344 full_len = 0; 358 full_len = 0;
345 else 359 else
346 full_len -= 254; 360 full_len -= 254;
347 wl3501_get_from_wla(this, this 361 wl3501_get_from_wla(this, this->tx_buffer_head, &next,
348 sizeof(nex 362 sizeof(next));
349 if (!full_len) 363 if (!full_len)
350 wl3501_set_to_wla(this 364 wl3501_set_to_wla(this, this->tx_buffer_head, &zero,
351 size 365 sizeof(zero));
352 this->tx_buffer_head = next; 366 this->tx_buffer_head = next;
353 blk_cnt++; 367 blk_cnt++;
354 /* if buffer is not enough */ 368 /* if buffer is not enough */
355 if (!next && full_len) { 369 if (!next && full_len) {
356 this->tx_buffer_head = 370 this->tx_buffer_head = ret;
357 ret = 0; 371 ret = 0;
358 goto out; 372 goto out;
359 } 373 }
360 } 374 }
361 this->tx_buffer_cnt -= blk_cnt; 375 this->tx_buffer_cnt -= blk_cnt;
362 out: 376 out:
363 return ret; 377 return ret;
364 } 378 }
365 379
366 /* 380 /*
367 * Free an allocated Tx Buffer. ptr must be co 381 * Free an allocated Tx Buffer. ptr must be correct position.
368 */ 382 */
369 static void wl3501_free_tx_buffer(struct wl350 383 static void wl3501_free_tx_buffer(struct wl3501_card *this, u16 ptr)
370 { 384 {
371 /* check if all space is not free */ 385 /* check if all space is not free */
372 if (!this->tx_buffer_head) 386 if (!this->tx_buffer_head)
373 this->tx_buffer_head = ptr; 387 this->tx_buffer_head = ptr;
374 else 388 else
375 wl3501_set_to_wla(this, this-> 389 wl3501_set_to_wla(this, this->tx_buffer_tail,
376 &ptr, sizeof 390 &ptr, sizeof(ptr));
377 while (ptr) { 391 while (ptr) {
378 u16 next; 392 u16 next;
379 393
380 this->tx_buffer_cnt++; 394 this->tx_buffer_cnt++;
381 wl3501_get_from_wla(this, ptr, 395 wl3501_get_from_wla(this, ptr, &next, sizeof(next));
382 this->tx_buffer_tail = ptr; 396 this->tx_buffer_tail = ptr;
383 ptr = next; 397 ptr = next;
384 } 398 }
385 } 399 }
386 400
387 static int wl3501_esbq_req_test(struct wl3501_ 401 static int wl3501_esbq_req_test(struct wl3501_card *this)
388 { 402 {
389 u8 tmp; 403 u8 tmp;
390 404
391 wl3501_get_from_wla(this, this->esbq_r 405 wl3501_get_from_wla(this, this->esbq_req_head + 3, &tmp, sizeof(tmp));
392 return tmp & 0x80; 406 return tmp & 0x80;
393 } 407 }
394 408
395 static void wl3501_esbq_req(struct wl3501_card 409 static void wl3501_esbq_req(struct wl3501_card *this, u16 *ptr)
396 { 410 {
397 u16 tmp = 0; 411 u16 tmp = 0;
398 412
399 wl3501_set_to_wla(this, this->esbq_req 413 wl3501_set_to_wla(this, this->esbq_req_head, ptr, 2);
400 wl3501_set_to_wla(this, this->esbq_req 414 wl3501_set_to_wla(this, this->esbq_req_head + 2, &tmp, sizeof(tmp));
401 this->esbq_req_head += 4; 415 this->esbq_req_head += 4;
402 if (this->esbq_req_head >= this->esbq_ 416 if (this->esbq_req_head >= this->esbq_req_end)
403 this->esbq_req_head = this->es 417 this->esbq_req_head = this->esbq_req_start;
404 } 418 }
405 419
406 static int wl3501_esbq_exec(struct wl3501_card 420 static int wl3501_esbq_exec(struct wl3501_card *this, void *sig, int sig_size)
407 { 421 {
408 int rc = -EIO; 422 int rc = -EIO;
409 423
410 if (wl3501_esbq_req_test(this)) { 424 if (wl3501_esbq_req_test(this)) {
411 u16 ptr = wl3501_get_tx_buffer 425 u16 ptr = wl3501_get_tx_buffer(this, sig_size);
412 if (ptr) { 426 if (ptr) {
413 wl3501_set_to_wla(this 427 wl3501_set_to_wla(this, ptr, sig, sig_size);
414 wl3501_esbq_req(this, 428 wl3501_esbq_req(this, &ptr);
415 rc = 0; 429 rc = 0;
416 } 430 }
417 } 431 }
418 return rc; 432 return rc;
419 } 433 }
420 434
421 static int wl3501_get_mib_value(struct wl3501_ 435 static int wl3501_get_mib_value(struct wl3501_card *this, u8 index,
422 void *bf, int 436 void *bf, int size)
423 { 437 {
424 struct wl3501_get_req sig = { 438 struct wl3501_get_req sig = {
425 .sig_id = WL3501_SIG_GET_R 439 .sig_id = WL3501_SIG_GET_REQ,
426 .mib_attrib = index, 440 .mib_attrib = index,
427 }; 441 };
428 unsigned long flags; 442 unsigned long flags;
429 int rc = -EIO; 443 int rc = -EIO;
430 444
431 spin_lock_irqsave(&this->lock, flags); 445 spin_lock_irqsave(&this->lock, flags);
432 if (wl3501_esbq_req_test(this)) { 446 if (wl3501_esbq_req_test(this)) {
433 u16 ptr = wl3501_get_tx_buffer 447 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
434 if (ptr) { 448 if (ptr) {
435 wl3501_set_to_wla(this 449 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
436 wl3501_esbq_req(this, 450 wl3501_esbq_req(this, &ptr);
437 this->sig_get_confirm. 451 this->sig_get_confirm.mib_status = 255;
438 spin_unlock_irqrestore 452 spin_unlock_irqrestore(&this->lock, flags);
439 rc = wait_event_interr 453 rc = wait_event_interruptible(this->wait,
440 this->sig_get_ 454 this->sig_get_confirm.mib_status != 255);
441 if (!rc) 455 if (!rc)
442 memcpy(bf, thi 456 memcpy(bf, this->sig_get_confirm.mib_value,
443 size); 457 size);
444 goto out; 458 goto out;
445 } 459 }
446 } 460 }
447 spin_unlock_irqrestore(&this->lock, fl 461 spin_unlock_irqrestore(&this->lock, flags);
448 out: 462 out:
449 return rc; 463 return rc;
450 } 464 }
451 465
452 static int wl3501_pwr_mgmt(struct wl3501_card 466 static int wl3501_pwr_mgmt(struct wl3501_card *this, int suspend)
453 { 467 {
454 struct wl3501_pwr_mgmt_req sig = { 468 struct wl3501_pwr_mgmt_req sig = {
455 .sig_id = WL3501_SIG_P 469 .sig_id = WL3501_SIG_PWR_MGMT_REQ,
456 .pwr_save = suspend, 470 .pwr_save = suspend,
457 .wake_up = !suspend, 471 .wake_up = !suspend,
458 .receive_dtims = 10, 472 .receive_dtims = 10,
459 }; 473 };
460 unsigned long flags; 474 unsigned long flags;
461 int rc = -EIO; 475 int rc = -EIO;
462 476
463 spin_lock_irqsave(&this->lock, flags); 477 spin_lock_irqsave(&this->lock, flags);
464 if (wl3501_esbq_req_test(this)) { 478 if (wl3501_esbq_req_test(this)) {
465 u16 ptr = wl3501_get_tx_buffer 479 u16 ptr = wl3501_get_tx_buffer(this, sizeof(sig));
466 if (ptr) { 480 if (ptr) {
467 wl3501_set_to_wla(this 481 wl3501_set_to_wla(this, ptr, &sig, sizeof(sig));
468 wl3501_esbq_req(this, 482 wl3501_esbq_req(this, &ptr);
469 this->sig_pwr_mgmt_con 483 this->sig_pwr_mgmt_confirm.status = 255;
470 spin_unlock_irqrestore 484 spin_unlock_irqrestore(&this->lock, flags);
471 rc = wait_event_interr 485 rc = wait_event_interruptible(this->wait,
472 this->sig_pwr_ 486 this->sig_pwr_mgmt_confirm.status != 255);
473 printk(KERN_INFO "%s: 487 printk(KERN_INFO "%s: %s status=%d\n", __FUNCTION__,
474 suspend ? "susp 488 suspend ? "suspend" : "resume",
475 this->sig_pwr_m 489 this->sig_pwr_mgmt_confirm.status);
476 goto out; 490 goto out;
477 } 491 }
478 } 492 }
479 spin_unlock_irqrestore(&this->lock, fl 493 spin_unlock_irqrestore(&this->lock, flags);
480 out: 494 out:
481 return rc; 495 return rc;
482 } 496 }
483 497
484 /** 498 /**
485 * wl3501_send_pkt - Send a packet. 499 * wl3501_send_pkt - Send a packet.
486 * @this - card 500 * @this - card
487 * 501 *
488 * Send a packet. 502 * Send a packet.
489 * 503 *
490 * data = Ethernet raw frame. (e.g. data[0] - 504 * data = Ethernet raw frame. (e.g. data[0] - data[5] is Dest MAC Addr,
491 * data[6] - 505 * data[6] - data[11] is Src MAC Addr)
492 * Ref: IEEE 802.11 506 * Ref: IEEE 802.11
493 */ 507 */
494 static int wl3501_send_pkt(struct wl3501_card 508 static int wl3501_send_pkt(struct wl3501_card *this, u8 *data, u16 len)
495 { 509 {
496 u16 bf, sig_bf, next, tmplen, pktlen; 510 u16 bf, sig_bf, next, tmplen, pktlen;
497 struct wl3501_md_req sig = { 511 struct wl3501_md_req sig = {
498 .sig_id = WL3501_SIG_MD_REQ, 512 .sig_id = WL3501_SIG_MD_REQ,
499 }; 513 };
500 u8 *pdata = (char *)data; 514 u8 *pdata = (char *)data;
501 int rc = -EIO; 515 int rc = -EIO;
502 516
503 if (wl3501_esbq_req_test(this)) { 517 if (wl3501_esbq_req_test(this)) {
504 sig_bf = wl3501_get_tx_buffer( 518 sig_bf = wl3501_get_tx_buffer(this, sizeof(sig));
505 rc = -ENOMEM; 519 rc = -ENOMEM;
506 if (!sig_bf) /* No free buf 520 if (!sig_bf) /* No free buffer available */
507 goto out; 521 goto out;
508 bf = wl3501_get_tx_buffer(this 522 bf = wl3501_get_tx_buffer(this, len + 26 + 24);
509 if (!bf) { 523 if (!bf) {
510 /* No free buffer avai 524 /* No free buffer available */
511 wl3501_free_tx_buffer( 525 wl3501_free_tx_buffer(this, sig_bf);
512 goto out; 526 goto out;
513 } 527 }
514 rc = 0; 528 rc = 0;
515 memcpy(&sig.daddr[0], pdata, 1 529 memcpy(&sig.daddr[0], pdata, 12);
516 pktlen = len - 12; 530 pktlen = len - 12;
517 pdata += 12; 531 pdata += 12;
518 sig.data = bf; 532 sig.data = bf;
519 if (((*pdata) * 256 + (*(pdata 533 if (((*pdata) * 256 + (*(pdata + 1))) > 1500) {
520 u8 addr4[ETH_ALEN] = { 534 u8 addr4[ETH_ALEN] = {
521 [0] = 0xAA, [1 535 [0] = 0xAA, [1] = 0xAA, [2] = 0x03, [4] = 0x00,
522 }; 536 };
523 537
524 wl3501_set_to_wla(this 538 wl3501_set_to_wla(this, bf + 2 +
525 offs 539 offsetof(struct wl3501_tx_hdr, addr4),
526 addr 540 addr4, sizeof(addr4));
527 sig.size = pktlen + 24 541 sig.size = pktlen + 24 + 4 + 6;
528 if (pktlen > (254 - si 542 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr))) {
529 tmplen = 254 - 543 tmplen = 254 - sizeof(struct wl3501_tx_hdr);
530 pktlen -= tmpl 544 pktlen -= tmplen;
531 } else { 545 } else {
532 tmplen = pktle 546 tmplen = pktlen;
533 pktlen = 0; 547 pktlen = 0;
534 } 548 }
535 wl3501_set_to_wla(this 549 wl3501_set_to_wla(this,
536 bf + 550 bf + 2 + sizeof(struct wl3501_tx_hdr),
537 pdat 551 pdata, tmplen);
538 pdata += tmplen; 552 pdata += tmplen;
539 wl3501_get_from_wla(th 553 wl3501_get_from_wla(this, bf, &next, sizeof(next));
540 bf = next; 554 bf = next;
541 } else { 555 } else {
542 sig.size = pktlen + 24 556 sig.size = pktlen + 24 + 4 - 2;
543 pdata += 2; 557 pdata += 2;
544 pktlen -= 2; 558 pktlen -= 2;
545 if (pktlen > (254 - si 559 if (pktlen > (254 - sizeof(struct wl3501_tx_hdr) + 6)) {
546 tmplen = 254 - 560 tmplen = 254 - sizeof(struct wl3501_tx_hdr) + 6;
547 pktlen -= tmpl 561 pktlen -= tmplen;
548 } else { 562 } else {
549 tmplen = pktle 563 tmplen = pktlen;
550 pktlen = 0; 564 pktlen = 0;
551 } 565 }
552 wl3501_set_to_wla(this 566 wl3501_set_to_wla(this, bf + 2 +
553 offs 567 offsetof(struct wl3501_tx_hdr, addr4),
554 pdat 568 pdata, tmplen);
555 pdata += tmplen; 569 pdata += tmplen;
556 wl3501_get_from_wla(th 570 wl3501_get_from_wla(this, bf, &next, sizeof(next));
557 bf = next; 571 bf = next;
558 } 572 }
559 while (pktlen > 0) { 573 while (pktlen > 0) {
560 if (pktlen > 254) { 574 if (pktlen > 254) {
561 tmplen = 254; 575 tmplen = 254;
562 pktlen -= 254; 576 pktlen -= 254;
563 } else { 577 } else {
564 tmplen = pktle 578 tmplen = pktlen;
565 pktlen = 0; 579 pktlen = 0;
566 } 580 }
567 wl3501_set_to_wla(this 581 wl3501_set_to_wla(this, bf + 2, pdata, tmplen);
568 pdata += tmplen; 582 pdata += tmplen;
569 wl3501_get_from_wla(th 583 wl3501_get_from_wla(this, bf, &next, sizeof(next));
570 bf = next; 584 bf = next;
571 } 585 }
572 wl3501_set_to_wla(this, sig_bf 586 wl3501_set_to_wla(this, sig_bf, &sig, sizeof(sig));
573 wl3501_esbq_req(this, &sig_bf) 587 wl3501_esbq_req(this, &sig_bf);
574 } 588 }
575 out: 589 out:
576 return rc; 590 return rc;
577 } 591 }
578 592
579 static int wl3501_mgmt_resync(struct wl3501_ca 593 static int wl3501_mgmt_resync(struct wl3501_card *this)
580 { 594 {
581 struct wl3501_resync_req sig = { 595 struct wl3501_resync_req sig = {
582 .sig_id = WL3501_SIG_RESYNC_RE 596 .sig_id = WL3501_SIG_RESYNC_REQ,
583 }; 597 };
584 598
585 return wl3501_esbq_exec(this, &sig, si 599 return wl3501_esbq_exec(this, &sig, sizeof(sig));
586 } 600 }
587 601
588 static inline int wl3501_fw_bss_type(struct wl 602 static inline int wl3501_fw_bss_type(struct wl3501_card *this)
589 { 603 {
590 return this->net_type == IW_MODE_INFRA 604 return this->net_type == IW_MODE_INFRA ? WL3501_NET_TYPE_INFRA :
591 605 WL3501_NET_TYPE_ADHOC;
592 } 606 }
593 607
594 static inline int wl3501_fw_cap_info(struct wl 608 static inline int wl3501_fw_cap_info(struct wl3501_card *this)
595 { 609 {
596 return this->net_type == IW_MODE_INFRA 610 return this->net_type == IW_MODE_INFRA ? WL3501_MGMT_CAPABILITY_ESS :
597 611 WL3501_MGMT_CAPABILITY_IBSS;
598 } 612 }
599 613
600 static int wl3501_mgmt_scan(struct wl3501_card 614 static int wl3501_mgmt_scan(struct wl3501_card *this, u16 chan_time)
601 { 615 {
602 struct wl3501_scan_req sig = { 616 struct wl3501_scan_req sig = {
603 .sig_id = WL3501_SIG_S 617 .sig_id = WL3501_SIG_SCAN_REQ,
604 .scan_type = WL3501_SCAN_ 618 .scan_type = WL3501_SCAN_TYPE_ACTIVE,
605 .probe_delay = 0x10, 619 .probe_delay = 0x10,
606 .min_chan_time = chan_time, 620 .min_chan_time = chan_time,
607 .max_chan_time = chan_time, 621 .max_chan_time = chan_time,
608 .bss_type = wl3501_fw_bs 622 .bss_type = wl3501_fw_bss_type(this),
609 }; 623 };
610 624
611 this->bss_cnt = this->join_sta_bss = 0 625 this->bss_cnt = this->join_sta_bss = 0;
612 return wl3501_esbq_exec(this, &sig, si 626 return wl3501_esbq_exec(this, &sig, sizeof(sig));
613 } 627 }
614 628
615 static int wl3501_mgmt_join(struct wl3501_card 629 static int wl3501_mgmt_join(struct wl3501_card *this, u16 stas)
616 { 630 {
617 struct wl3501_join_req sig = { 631 struct wl3501_join_req sig = {
618 .sig_id = WL3501_SIG 632 .sig_id = WL3501_SIG_JOIN_REQ,
619 .timeout = 10, 633 .timeout = 10,
620 .ds_pset = { 634 .ds_pset = {
621 .el = { 635 .el = {
622 .id = IW_MGMT 636 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
623 .len = 1, 637 .len = 1,
624 }, 638 },
625 .chan = this->chan, 639 .chan = this->chan,
626 }, 640 },
627 }; 641 };
628 642
629 memcpy(&sig.beacon_period, &this->bss_ 643 memcpy(&sig.beacon_period, &this->bss_set[stas].beacon_period, 72);
630 return wl3501_esbq_exec(this, &sig, si 644 return wl3501_esbq_exec(this, &sig, sizeof(sig));
631 } 645 }
632 646
633 static int wl3501_mgmt_start(struct wl3501_car 647 static int wl3501_mgmt_start(struct wl3501_card *this)
634 { 648 {
635 struct wl3501_start_req sig = { 649 struct wl3501_start_req sig = {
636 .sig_id = WL35 650 .sig_id = WL3501_SIG_START_REQ,
637 .beacon_period = 400, 651 .beacon_period = 400,
638 .dtim_period = 1, 652 .dtim_period = 1,
639 .ds_pset = { 653 .ds_pset = {
640 .el = { 654 .el = {
641 .id = IW_MGMT 655 .id = IW_MGMT_INFO_ELEMENT_DS_PARAMETER_SET,
642 .len = 1, 656 .len = 1,
643 }, 657 },
644 .chan = this->chan, 658 .chan = this->chan,
645 }, 659 },
646 .bss_basic_rset = { 660 .bss_basic_rset = {
647 .el = { 661 .el = {
648 .id = IW_M 662 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
649 .len = 2, 663 .len = 2,
650 }, 664 },
651 .data_rate_labels = { 665 .data_rate_labels = {
652 [0] = IW_MGMT_ 666 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
653 IW_MGMT_ 667 IW_MGMT_RATE_LABEL_1MBIT,
654 [1] = IW_MGMT_ 668 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
655 IW_MGMT_ 669 IW_MGMT_RATE_LABEL_2MBIT,
656 }, 670 },
657 }, 671 },
658 .operational_rset = { 672 .operational_rset = {
659 .el = { 673 .el = {
660 .id = IW_M 674 .id = IW_MGMT_INFO_ELEMENT_SUPPORTED_RATES,
661 .len = 2, 675 .len = 2,
662 }, 676 },
663 .data_rate_labels = { 677 .data_rate_labels = {
664 [0] = IW_MGMT_ 678 [0] = IW_MGMT_RATE_LABEL_MANDATORY |
665 IW_MGMT_ 679 IW_MGMT_RATE_LABEL_1MBIT,
666 [1] = IW_MGMT_ 680 [1] = IW_MGMT_RATE_LABEL_MANDATORY |
667 IW_MGMT_ 681 IW_MGMT_RATE_LABEL_2MBIT,
668 }, 682 },
669 }, 683 },
670 .ibss_pset = { 684 .ibss_pset = {
671 .el = { 685 .el = {
672 .id = IW_ 686 .id = IW_MGMT_INFO_ELEMENT_IBSS_PARAMETER_SET,
673 .len = 2, 687 .len = 2,
674 }, 688 },
675 .atim_window = 10, 689 .atim_window = 10,
676 }, 690 },
677 .bss_type = wl35 691 .bss_type = wl3501_fw_bss_type(this),
678 .cap_info = wl35 692 .cap_info = wl3501_fw_cap_info(this),
679 }; 693 };
680 694
681 iw_copy_mgmt_info_element(&sig.ssid.el 695 iw_copy_mgmt_info_element(&sig.ssid.el, &this->essid.el);
682 iw_copy_mgmt_info_element(&this->keep_ 696 iw_copy_mgmt_info_element(&this->keep_essid.el, &this->essid.el);
683 return wl3501_esbq_exec(this, &sig, si 697 return wl3501_esbq_exec(this, &sig, sizeof(sig));
684 } 698 }
685 699
686 static void wl3501_mgmt_scan_confirm(struct wl 700 static void wl3501_mgmt_scan_confirm(struct wl3501_card *this, u16 addr)
687 { 701 {
688 u16 i = 0; 702 u16 i = 0;
689 int matchflag = 0; 703 int matchflag = 0;
690 struct wl3501_scan_confirm sig; 704 struct wl3501_scan_confirm sig;
691 705
692 dprintk(3, "entry"); 706 dprintk(3, "entry");
693 wl3501_get_from_wla(this, addr, &sig, 707 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
694 if (sig.status == WL3501_STATUS_SUCCES 708 if (sig.status == WL3501_STATUS_SUCCESS) {
695 dprintk(3, "success"); 709 dprintk(3, "success");
696 if ((this->net_type == IW_MODE 710 if ((this->net_type == IW_MODE_INFRA &&
697 (sig.cap_info & WL3501_MG 711 (sig.cap_info & WL3501_MGMT_CAPABILITY_ESS)) ||
698 (this->net_type == IW_MODE 712 (this->net_type == IW_MODE_ADHOC &&
699 (sig.cap_info & WL3501_MG 713 (sig.cap_info & WL3501_MGMT_CAPABILITY_IBSS)) ||
700 this->net_type == IW_MODE_ 714 this->net_type == IW_MODE_AUTO) {
701 if (!this->essid.el.le 715 if (!this->essid.el.len)
702 matchflag = 1; 716 matchflag = 1;
703 else if (this->essid.e 717 else if (this->essid.el.len == 3 &&
704 !memcmp(this- 718 !memcmp(this->essid.essid, "ANY", 3))
705 matchflag = 1; 719 matchflag = 1;
706 else if (this->essid.e 720 else if (this->essid.el.len != sig.ssid.el.len)
707 matchflag = 0; 721 matchflag = 0;
708 else if (memcmp(this-> 722 else if (memcmp(this->essid.essid, sig.ssid.essid,
709 this-> 723 this->essid.el.len))
710 matchflag = 0; 724 matchflag = 0;
711 else 725 else
712 matchflag = 1; 726 matchflag = 1;
713 if (matchflag) { 727 if (matchflag) {
714 for (i = 0; i 728 for (i = 0; i < this->bss_cnt; i++) {
715 if (!m 729 if (!memcmp(this->bss_set[i].bssid,
716 730 sig.bssid, ETH_ALEN)) {
717 731 matchflag = 0;
718 732 break;
719 } 733 }
720 } 734 }
721 } 735 }
722 if (matchflag && (i < 736 if (matchflag && (i < 20)) {
723 memcpy(&this-> 737 memcpy(&this->bss_set[i].beacon_period,
724 &sig.be 738 &sig.beacon_period, 73);
725 this->bss_cnt+ 739 this->bss_cnt++;
726 this->rssi = s 740 this->rssi = sig.rssi;
727 } 741 }
728 } 742 }
729 } else if (sig.status == WL3501_STATUS 743 } else if (sig.status == WL3501_STATUS_TIMEOUT) {
730 dprintk(3, "timeout"); 744 dprintk(3, "timeout");
731 this->join_sta_bss = 0; 745 this->join_sta_bss = 0;
732 for (i = this->join_sta_bss; i 746 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
733 if (!wl3501_mgmt_join( 747 if (!wl3501_mgmt_join(this, i))
734 break; 748 break;
735 this->join_sta_bss = i; 749 this->join_sta_bss = i;
736 if (this->join_sta_bss == this 750 if (this->join_sta_bss == this->bss_cnt) {
737 if (this->net_type == 751 if (this->net_type == IW_MODE_INFRA)
738 wl3501_mgmt_sc 752 wl3501_mgmt_scan(this, 100);
739 else { 753 else {
740 this->adhoc_ti 754 this->adhoc_times++;
741 if (this->adho 755 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
742 wl3501 756 wl3501_mgmt_start(this);
743 else 757 else
744 wl3501 758 wl3501_mgmt_scan(this, 100);
745 } 759 }
746 } 760 }
747 } 761 }
748 } 762 }
749 763
750 /** 764 /**
751 * wl3501_block_interrupt - Mask interrupt fro 765 * wl3501_block_interrupt - Mask interrupt from SUTRO
752 * @this - card 766 * @this - card
753 * 767 *
754 * Mask interrupt from SUTRO. (i.e. SUTRO cann 768 * Mask interrupt from SUTRO. (i.e. SUTRO cannot interrupt the HOST)
755 * Return: 1 if interrupt is originally enable 769 * Return: 1 if interrupt is originally enabled
756 */ 770 */
757 static int wl3501_block_interrupt(struct wl350 771 static int wl3501_block_interrupt(struct wl3501_card *this)
758 { 772 {
759 u8 old = inb(this->base_addr + WL3501_ 773 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
760 u8 new = old & (~(WL3501_GCR_ECINT | W 774 u8 new = old & (~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC |
761 WL3501_GCR_ENECINT)); 775 WL3501_GCR_ENECINT));
762 776
763 wl3501_outb(new, this->base_addr + WL3 777 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
764 return old & WL3501_GCR_ENECINT; 778 return old & WL3501_GCR_ENECINT;
765 } 779 }
766 780
767 /** 781 /**
768 * wl3501_unblock_interrupt - Enable interrupt 782 * wl3501_unblock_interrupt - Enable interrupt from SUTRO
769 * @this - card 783 * @this - card
770 * 784 *
771 * Enable interrupt from SUTRO. (i.e. SUTRO ca 785 * Enable interrupt from SUTRO. (i.e. SUTRO can interrupt the HOST)
772 * Return: 1 if interrupt is originally enable 786 * Return: 1 if interrupt is originally enabled
773 */ 787 */
774 static int wl3501_unblock_interrupt(struct wl3 788 static int wl3501_unblock_interrupt(struct wl3501_card *this)
775 { 789 {
776 u8 old = inb(this->base_addr + WL3501_ 790 u8 old = inb(this->base_addr + WL3501_NIC_GCR);
777 u8 new = (old & ~(WL3501_GCR_ECINT | W 791 u8 new = (old & ~(WL3501_GCR_ECINT | WL3501_GCR_INT2EC)) |
778 WL3501_GCR_ENECINT; 792 WL3501_GCR_ENECINT;
779 793
780 wl3501_outb(new, this->base_addr + WL3 794 wl3501_outb(new, this->base_addr + WL3501_NIC_GCR);
781 return old & WL3501_GCR_ENECINT; 795 return old & WL3501_GCR_ENECINT;
782 } 796 }
783 797
784 /** 798 /**
785 * wl3501_receive - Receive data from Receive 799 * wl3501_receive - Receive data from Receive Queue.
786 * 800 *
787 * Receive data from Receive Queue. 801 * Receive data from Receive Queue.
788 * 802 *
789 * @this: card 803 * @this: card
790 * @bf: address of host 804 * @bf: address of host
791 * @size: size of buffer. 805 * @size: size of buffer.
792 */ 806 */
793 static u16 wl3501_receive(struct wl3501_card * 807 static u16 wl3501_receive(struct wl3501_card *this, u8 *bf, u16 size)
794 { 808 {
795 u16 next_addr, next_addr1; 809 u16 next_addr, next_addr1;
796 u8 *data = bf + 12; 810 u8 *data = bf + 12;
797 811
798 size -= 12; 812 size -= 12;
799 wl3501_get_from_wla(this, this->start_ 813 wl3501_get_from_wla(this, this->start_seg + 2,
800 &next_addr, sizeof 814 &next_addr, sizeof(next_addr));
801 if (size > WL3501_BLKSZ - sizeof(struc 815 if (size > WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr)) {
802 wl3501_get_from_wla(this, 816 wl3501_get_from_wla(this,
803 this->star 817 this->start_seg +
804 sizeof 818 sizeof(struct wl3501_rx_hdr), data,
805 WL3501_BLK 819 WL3501_BLKSZ -
806 sizeof 820 sizeof(struct wl3501_rx_hdr));
807 size -= WL3501_BLKSZ - sizeof( 821 size -= WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
808 data += WL3501_BLKSZ - sizeof( 822 data += WL3501_BLKSZ - sizeof(struct wl3501_rx_hdr);
809 } else { 823 } else {
810 wl3501_get_from_wla(this, 824 wl3501_get_from_wla(this,
811 this->star 825 this->start_seg +
812 sizeof 826 sizeof(struct wl3501_rx_hdr),
813 data, size 827 data, size);
814 size = 0; 828 size = 0;
815 } 829 }
816 while (size > 0) { 830 while (size > 0) {
817 if (size > WL3501_BLKSZ - 5) { 831 if (size > WL3501_BLKSZ - 5) {
818 wl3501_get_from_wla(th 832 wl3501_get_from_wla(this, next_addr + 5, data,
819 WL 833 WL3501_BLKSZ - 5);
820 size -= WL3501_BLKSZ - 834 size -= WL3501_BLKSZ - 5;
821 data += WL3501_BLKSZ - 835 data += WL3501_BLKSZ - 5;
822 wl3501_get_from_wla(th 836 wl3501_get_from_wla(this, next_addr + 2, &next_addr1,
823 si 837 sizeof(next_addr1));
824 next_addr = next_addr1 838 next_addr = next_addr1;
825 } else { 839 } else {
826 wl3501_get_from_wla(th 840 wl3501_get_from_wla(this, next_addr + 5, data, size);
827 size = 0; 841 size = 0;
828 } 842 }
829 } 843 }
830 return 0; 844 return 0;
831 } 845 }
832 846
833 static void wl3501_esbq_req_free(struct wl3501 847 static void wl3501_esbq_req_free(struct wl3501_card *this)
834 { 848 {
835 u8 tmp; 849 u8 tmp;
836 u16 addr; 850 u16 addr;
837 851
838 if (this->esbq_req_head == this->esbq_ 852 if (this->esbq_req_head == this->esbq_req_tail)
839 goto out; 853 goto out;
840 wl3501_get_from_wla(this, this->esbq_r 854 wl3501_get_from_wla(this, this->esbq_req_tail + 3, &tmp, sizeof(tmp));
841 if (!(tmp & 0x80)) 855 if (!(tmp & 0x80))
842 goto out; 856 goto out;
843 wl3501_get_from_wla(this, this->esbq_r 857 wl3501_get_from_wla(this, this->esbq_req_tail, &addr, sizeof(addr));
844 wl3501_free_tx_buffer(this, addr); 858 wl3501_free_tx_buffer(this, addr);
845 this->esbq_req_tail += 4; 859 this->esbq_req_tail += 4;
846 if (this->esbq_req_tail >= this->esbq_ 860 if (this->esbq_req_tail >= this->esbq_req_end)
847 this->esbq_req_tail = this->es 861 this->esbq_req_tail = this->esbq_req_start;
848 out: 862 out:
849 return; 863 return;
850 } 864 }
851 865
852 static int wl3501_esbq_confirm(struct wl3501_c 866 static int wl3501_esbq_confirm(struct wl3501_card *this)
853 { 867 {
854 u8 tmp; 868 u8 tmp;
855 869
856 wl3501_get_from_wla(this, this->esbq_c 870 wl3501_get_from_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
857 return tmp & 0x80; 871 return tmp & 0x80;
858 } 872 }
859 873
860 static void wl3501_online(struct net_device *d 874 static void wl3501_online(struct net_device *dev)
861 { 875 {
862 struct wl3501_card *this = netdev_priv !! 876 struct wl3501_card *this = dev->priv;
863 DECLARE_MAC_BUF(mac); <<
864 877
865 printk(KERN_INFO "%s: Wireless LAN onl !! 878 printk(KERN_INFO "%s: Wireless LAN online. BSSID: "
866 dev->name, print_mac(mac, this- !! 879 "%02X %02X %02X %02X %02X %02X\n", dev->name,
>> 880 this->bssid[0], this->bssid[1], this->bssid[2],
>> 881 this->bssid[3], this->bssid[4], this->bssid[5]);
867 netif_wake_queue(dev); 882 netif_wake_queue(dev);
868 } 883 }
869 884
870 static void wl3501_esbq_confirm_done(struct wl 885 static void wl3501_esbq_confirm_done(struct wl3501_card *this)
871 { 886 {
872 u8 tmp = 0; 887 u8 tmp = 0;
873 888
874 wl3501_set_to_wla(this, this->esbq_con 889 wl3501_set_to_wla(this, this->esbq_confirm + 3, &tmp, sizeof(tmp));
875 this->esbq_confirm += 4; 890 this->esbq_confirm += 4;
876 if (this->esbq_confirm >= this->esbq_c 891 if (this->esbq_confirm >= this->esbq_confirm_end)
877 this->esbq_confirm = this->esb 892 this->esbq_confirm = this->esbq_confirm_start;
878 } 893 }
879 894
880 static int wl3501_mgmt_auth(struct wl3501_card 895 static int wl3501_mgmt_auth(struct wl3501_card *this)
881 { 896 {
882 struct wl3501_auth_req sig = { 897 struct wl3501_auth_req sig = {
883 .sig_id = WL3501_SIG_AUTH_REQ 898 .sig_id = WL3501_SIG_AUTH_REQ,
884 .type = WL3501_SYS_TYPE_OPE 899 .type = WL3501_SYS_TYPE_OPEN,
885 .timeout = 1000, 900 .timeout = 1000,
886 }; 901 };
887 902
888 dprintk(3, "entry"); 903 dprintk(3, "entry");
889 memcpy(sig.mac_addr, this->bssid, ETH_ 904 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
890 return wl3501_esbq_exec(this, &sig, si 905 return wl3501_esbq_exec(this, &sig, sizeof(sig));
891 } 906 }
892 907
893 static int wl3501_mgmt_association(struct wl35 908 static int wl3501_mgmt_association(struct wl3501_card *this)
894 { 909 {
895 struct wl3501_assoc_req sig = { 910 struct wl3501_assoc_req sig = {
896 .sig_id = WL3501_SIG_ 911 .sig_id = WL3501_SIG_ASSOC_REQ,
897 .timeout = 1000, 912 .timeout = 1000,
898 .listen_interval = 5, 913 .listen_interval = 5,
899 .cap_info = this->cap_i 914 .cap_info = this->cap_info,
900 }; 915 };
901 916
902 dprintk(3, "entry"); 917 dprintk(3, "entry");
903 memcpy(sig.mac_addr, this->bssid, ETH_ 918 memcpy(sig.mac_addr, this->bssid, ETH_ALEN);
904 return wl3501_esbq_exec(this, &sig, si 919 return wl3501_esbq_exec(this, &sig, sizeof(sig));
905 } 920 }
906 921
907 static void wl3501_mgmt_join_confirm(struct ne 922 static void wl3501_mgmt_join_confirm(struct net_device *dev, u16 addr)
908 { 923 {
909 struct wl3501_card *this = netdev_priv !! 924 struct wl3501_card *this = dev->priv;
910 struct wl3501_join_confirm sig; 925 struct wl3501_join_confirm sig;
911 926
912 dprintk(3, "entry"); 927 dprintk(3, "entry");
913 wl3501_get_from_wla(this, addr, &sig, 928 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
914 if (sig.status == WL3501_STATUS_SUCCES 929 if (sig.status == WL3501_STATUS_SUCCESS) {
915 if (this->net_type == IW_MODE_ 930 if (this->net_type == IW_MODE_INFRA) {
916 if (this->join_sta_bss 931 if (this->join_sta_bss < this->bss_cnt) {
917 const int i = 932 const int i = this->join_sta_bss;
918 memcpy(this->b 933 memcpy(this->bssid,
919 this->b 934 this->bss_set[i].bssid, ETH_ALEN);
920 this->chan = t 935 this->chan = this->bss_set[i].ds_pset.chan;
921 iw_copy_mgmt_i 936 iw_copy_mgmt_info_element(&this->keep_essid.el,
922 937 &this->bss_set[i].ssid.el);
923 wl3501_mgmt_au 938 wl3501_mgmt_auth(this);
924 } 939 }
925 } else { 940 } else {
926 const int i = this->jo 941 const int i = this->join_sta_bss;
927 942
928 memcpy(&this->bssid, & 943 memcpy(&this->bssid, &this->bss_set[i].bssid, ETH_ALEN);
929 this->chan = this->bss 944 this->chan = this->bss_set[i].ds_pset.chan;
930 iw_copy_mgmt_info_elem 945 iw_copy_mgmt_info_element(&this->keep_essid.el,
931 946 &this->bss_set[i].ssid.el);
932 wl3501_online(dev); 947 wl3501_online(dev);
933 } 948 }
934 } else { 949 } else {
935 int i; 950 int i;
936 this->join_sta_bss++; 951 this->join_sta_bss++;
937 for (i = this->join_sta_bss; i 952 for (i = this->join_sta_bss; i < this->bss_cnt; i++)
938 if (!wl3501_mgmt_join( 953 if (!wl3501_mgmt_join(this, i))
939 break; 954 break;
940 this->join_sta_bss = i; 955 this->join_sta_bss = i;
941 if (this->join_sta_bss == this 956 if (this->join_sta_bss == this->bss_cnt) {
942 if (this->net_type == 957 if (this->net_type == IW_MODE_INFRA)
943 wl3501_mgmt_sc 958 wl3501_mgmt_scan(this, 100);
944 else { 959 else {
945 this->adhoc_ti 960 this->adhoc_times++;
946 if (this->adho 961 if (this->adhoc_times > WL3501_MAX_ADHOC_TRIES)
947 wl3501 962 wl3501_mgmt_start(this);
948 else 963 else
949 wl3501 964 wl3501_mgmt_scan(this, 100);
950 } 965 }
951 } 966 }
952 } 967 }
953 } 968 }
954 969
955 static inline void wl3501_alarm_interrupt(stru 970 static inline void wl3501_alarm_interrupt(struct net_device *dev,
956 stru 971 struct wl3501_card *this)
957 { 972 {
958 if (this->net_type == IW_MODE_INFRA) { 973 if (this->net_type == IW_MODE_INFRA) {
959 printk(KERN_INFO "Wireless LAN 974 printk(KERN_INFO "Wireless LAN offline\n");
960 netif_stop_queue(dev); 975 netif_stop_queue(dev);
961 wl3501_mgmt_resync(this); 976 wl3501_mgmt_resync(this);
962 } 977 }
963 } 978 }
964 979
965 static inline void wl3501_md_confirm_interrupt 980 static inline void wl3501_md_confirm_interrupt(struct net_device *dev,
966 981 struct wl3501_card *this,
967 982 u16 addr)
968 { 983 {
969 struct wl3501_md_confirm sig; 984 struct wl3501_md_confirm sig;
970 985
971 dprintk(3, "entry"); 986 dprintk(3, "entry");
972 wl3501_get_from_wla(this, addr, &sig, 987 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
973 wl3501_free_tx_buffer(this, sig.data); 988 wl3501_free_tx_buffer(this, sig.data);
974 if (netif_queue_stopped(dev)) 989 if (netif_queue_stopped(dev))
975 netif_wake_queue(dev); 990 netif_wake_queue(dev);
976 } 991 }
977 992
978 static inline void wl3501_md_ind_interrupt(str 993 static inline void wl3501_md_ind_interrupt(struct net_device *dev,
979 str 994 struct wl3501_card *this, u16 addr)
980 { 995 {
981 struct wl3501_md_ind sig; 996 struct wl3501_md_ind sig;
982 struct sk_buff *skb; 997 struct sk_buff *skb;
983 u8 rssi, addr4[ETH_ALEN]; 998 u8 rssi, addr4[ETH_ALEN];
984 u16 pkt_len; 999 u16 pkt_len;
985 1000
986 wl3501_get_from_wla(this, addr, &sig, 1001 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
987 this->start_seg = sig.data; 1002 this->start_seg = sig.data;
988 wl3501_get_from_wla(this, 1003 wl3501_get_from_wla(this,
989 sig.data + offseto 1004 sig.data + offsetof(struct wl3501_rx_hdr, rssi),
990 &rssi, sizeof(rssi 1005 &rssi, sizeof(rssi));
991 this->rssi = rssi <= 63 ? (rssi * 100) 1006 this->rssi = rssi <= 63 ? (rssi * 100) / 64 : 255;
992 1007
993 wl3501_get_from_wla(this, 1008 wl3501_get_from_wla(this,
994 sig.data + 1009 sig.data +
995 offsetof(struc 1010 offsetof(struct wl3501_rx_hdr, addr4),
996 &addr4, sizeof(add 1011 &addr4, sizeof(addr4));
997 if (!(addr4[0] == 0xAA && addr4[1] == 1012 if (!(addr4[0] == 0xAA && addr4[1] == 0xAA &&
998 addr4[2] == 0x03 && addr4[4] == 1013 addr4[2] == 0x03 && addr4[4] == 0x00)) {
999 printk(KERN_INFO "Insupported 1014 printk(KERN_INFO "Insupported packet type!\n");
1000 return; 1015 return;
1001 } 1016 }
1002 pkt_len = sig.size + 12 - 24 - 4 - 6; 1017 pkt_len = sig.size + 12 - 24 - 4 - 6;
1003 1018
1004 skb = dev_alloc_skb(pkt_len + 5); 1019 skb = dev_alloc_skb(pkt_len + 5);
1005 1020
1006 if (!skb) { 1021 if (!skb) {
1007 printk(KERN_WARNING "%s: Can' 1022 printk(KERN_WARNING "%s: Can't alloc a sk_buff of size %d.\n",
1008 dev->name, pkt_len); 1023 dev->name, pkt_len);
1009 this->stats.rx_dropped++; 1024 this->stats.rx_dropped++;
1010 } else { 1025 } else {
1011 skb->dev = dev; 1026 skb->dev = dev;
1012 skb_reserve(skb, 2); /* IP he 1027 skb_reserve(skb, 2); /* IP headers on 16 bytes boundaries */
1013 skb_copy_to_linear_data(skb, !! 1028 eth_copy_and_sum(skb, (unsigned char *)&sig.daddr, 12, 0);
1014 wl3501_receive(this, skb->dat 1029 wl3501_receive(this, skb->data, pkt_len);
1015 skb_put(skb, pkt_len); 1030 skb_put(skb, pkt_len);
1016 skb->protocol = eth_type_tr 1031 skb->protocol = eth_type_trans(skb, dev);
1017 dev->last_rx = jiffies; 1032 dev->last_rx = jiffies;
1018 this->stats.rx_packets++; 1033 this->stats.rx_packets++;
1019 this->stats.rx_bytes += skb-> 1034 this->stats.rx_bytes += skb->len;
1020 netif_rx(skb); 1035 netif_rx(skb);
1021 } 1036 }
1022 } 1037 }
1023 1038
1024 static inline void wl3501_get_confirm_interru 1039 static inline void wl3501_get_confirm_interrupt(struct wl3501_card *this,
1025 1040 u16 addr, void *sig, int size)
1026 { 1041 {
1027 dprintk(3, "entry"); 1042 dprintk(3, "entry");
1028 wl3501_get_from_wla(this, addr, &this 1043 wl3501_get_from_wla(this, addr, &this->sig_get_confirm,
1029 sizeof(this->sig_ 1044 sizeof(this->sig_get_confirm));
1030 wake_up(&this->wait); 1045 wake_up(&this->wait);
1031 } 1046 }
1032 1047
1033 static inline void wl3501_start_confirm_inter 1048 static inline void wl3501_start_confirm_interrupt(struct net_device *dev,
1034 1049 struct wl3501_card *this,
1035 1050 u16 addr)
1036 { 1051 {
1037 struct wl3501_start_confirm sig; 1052 struct wl3501_start_confirm sig;
1038 1053
1039 dprintk(3, "entry"); 1054 dprintk(3, "entry");
1040 wl3501_get_from_wla(this, addr, &sig, 1055 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1041 if (sig.status == WL3501_STATUS_SUCCE 1056 if (sig.status == WL3501_STATUS_SUCCESS)
1042 netif_wake_queue(dev); 1057 netif_wake_queue(dev);
1043 } 1058 }
1044 1059
1045 static inline void wl3501_assoc_confirm_inter 1060 static inline void wl3501_assoc_confirm_interrupt(struct net_device *dev,
1046 1061 u16 addr)
1047 { 1062 {
1048 struct wl3501_card *this = netdev_pri !! 1063 struct wl3501_card *this = dev->priv;
1049 struct wl3501_assoc_confirm sig; 1064 struct wl3501_assoc_confirm sig;
1050 1065
1051 dprintk(3, "entry"); 1066 dprintk(3, "entry");
1052 wl3501_get_from_wla(this, addr, &sig, 1067 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1053 1068
1054 if (sig.status == WL3501_STATUS_SUCCE 1069 if (sig.status == WL3501_STATUS_SUCCESS)
1055 wl3501_online(dev); 1070 wl3501_online(dev);
1056 } 1071 }
1057 1072
1058 static inline void wl3501_auth_confirm_interr 1073 static inline void wl3501_auth_confirm_interrupt(struct wl3501_card *this,
1059 1074 u16 addr)
1060 { 1075 {
1061 struct wl3501_auth_confirm sig; 1076 struct wl3501_auth_confirm sig;
1062 1077
1063 dprintk(3, "entry"); 1078 dprintk(3, "entry");
1064 wl3501_get_from_wla(this, addr, &sig, 1079 wl3501_get_from_wla(this, addr, &sig, sizeof(sig));
1065 1080
1066 if (sig.status == WL3501_STATUS_SUCCE 1081 if (sig.status == WL3501_STATUS_SUCCESS)
1067 wl3501_mgmt_association(this) 1082 wl3501_mgmt_association(this);
1068 else 1083 else
1069 wl3501_mgmt_resync(this); 1084 wl3501_mgmt_resync(this);
1070 } 1085 }
1071 1086
1072 static inline void wl3501_rx_interrupt(struct 1087 static inline void wl3501_rx_interrupt(struct net_device *dev)
1073 { 1088 {
1074 int morepkts; 1089 int morepkts;
1075 u16 addr; 1090 u16 addr;
1076 u8 sig_id; 1091 u8 sig_id;
1077 struct wl3501_card *this = netdev_pri !! 1092 struct wl3501_card *this = dev->priv;
1078 1093
1079 dprintk(3, "entry"); 1094 dprintk(3, "entry");
1080 loop: 1095 loop:
1081 morepkts = 0; 1096 morepkts = 0;
1082 if (!wl3501_esbq_confirm(this)) 1097 if (!wl3501_esbq_confirm(this))
1083 goto free; 1098 goto free;
1084 wl3501_get_from_wla(this, this->esbq_ 1099 wl3501_get_from_wla(this, this->esbq_confirm, &addr, sizeof(addr));
1085 wl3501_get_from_wla(this, addr + 2, & 1100 wl3501_get_from_wla(this, addr + 2, &sig_id, sizeof(sig_id));
1086 1101
1087 switch (sig_id) { 1102 switch (sig_id) {
1088 case WL3501_SIG_DEAUTH_IND: 1103 case WL3501_SIG_DEAUTH_IND:
1089 case WL3501_SIG_DISASSOC_IND: 1104 case WL3501_SIG_DISASSOC_IND:
1090 case WL3501_SIG_ALARM: 1105 case WL3501_SIG_ALARM:
1091 wl3501_alarm_interrupt(dev, t 1106 wl3501_alarm_interrupt(dev, this);
1092 break; 1107 break;
1093 case WL3501_SIG_MD_CONFIRM: 1108 case WL3501_SIG_MD_CONFIRM:
1094 wl3501_md_confirm_interrupt(d 1109 wl3501_md_confirm_interrupt(dev, this, addr);
1095 break; 1110 break;
1096 case WL3501_SIG_MD_IND: 1111 case WL3501_SIG_MD_IND:
1097 wl3501_md_ind_interrupt(dev, 1112 wl3501_md_ind_interrupt(dev, this, addr);
1098 break; 1113 break;
1099 case WL3501_SIG_GET_CONFIRM: 1114 case WL3501_SIG_GET_CONFIRM:
1100 wl3501_get_confirm_interrupt( 1115 wl3501_get_confirm_interrupt(this, addr,
1101 1116 &this->sig_get_confirm,
1102 1117 sizeof(this->sig_get_confirm));
1103 break; 1118 break;
1104 case WL3501_SIG_PWR_MGMT_CONFIRM: 1119 case WL3501_SIG_PWR_MGMT_CONFIRM:
1105 wl3501_get_confirm_interrupt( 1120 wl3501_get_confirm_interrupt(this, addr,
1106 1121 &this->sig_pwr_mgmt_confirm,
1107 s 1122 sizeof(this->sig_pwr_mgmt_confirm));
1108 break; 1123 break;
1109 case WL3501_SIG_START_CONFIRM: 1124 case WL3501_SIG_START_CONFIRM:
1110 wl3501_start_confirm_interrup 1125 wl3501_start_confirm_interrupt(dev, this, addr);
1111 break; 1126 break;
1112 case WL3501_SIG_SCAN_CONFIRM: 1127 case WL3501_SIG_SCAN_CONFIRM:
1113 wl3501_mgmt_scan_confirm(this 1128 wl3501_mgmt_scan_confirm(this, addr);
1114 break; 1129 break;
1115 case WL3501_SIG_JOIN_CONFIRM: 1130 case WL3501_SIG_JOIN_CONFIRM:
1116 wl3501_mgmt_join_confirm(dev, 1131 wl3501_mgmt_join_confirm(dev, addr);
1117 break; 1132 break;
1118 case WL3501_SIG_ASSOC_CONFIRM: 1133 case WL3501_SIG_ASSOC_CONFIRM:
1119 wl3501_assoc_confirm_interrup 1134 wl3501_assoc_confirm_interrupt(dev, addr);
1120 break; 1135 break;
1121 case WL3501_SIG_AUTH_CONFIRM: 1136 case WL3501_SIG_AUTH_CONFIRM:
1122 wl3501_auth_confirm_interrupt 1137 wl3501_auth_confirm_interrupt(this, addr);
1123 break; 1138 break;
1124 case WL3501_SIG_RESYNC_CONFIRM: 1139 case WL3501_SIG_RESYNC_CONFIRM:
1125 wl3501_mgmt_resync(this); /* 1140 wl3501_mgmt_resync(this); /* FIXME: should be resync_confirm */
1126 break; 1141 break;
1127 } 1142 }
1128 wl3501_esbq_confirm_done(this); 1143 wl3501_esbq_confirm_done(this);
1129 morepkts = 1; 1144 morepkts = 1;
1130 /* free request if necessary */ 1145 /* free request if necessary */
1131 free: 1146 free:
1132 wl3501_esbq_req_free(this); 1147 wl3501_esbq_req_free(this);
1133 if (morepkts) 1148 if (morepkts)
1134 goto loop; 1149 goto loop;
1135 } 1150 }
1136 1151
1137 static inline void wl3501_ack_interrupt(struc 1152 static inline void wl3501_ack_interrupt(struct wl3501_card *this)
1138 { 1153 {
1139 wl3501_outb(WL3501_GCR_ECINT, this->b 1154 wl3501_outb(WL3501_GCR_ECINT, this->base_addr + WL3501_NIC_GCR);
1140 } 1155 }
1141 1156
1142 /** 1157 /**
1143 * wl3501_interrupt - Hardware interrupt from 1158 * wl3501_interrupt - Hardware interrupt from card.
1144 * @irq - Interrupt number 1159 * @irq - Interrupt number
1145 * @dev_id - net_device 1160 * @dev_id - net_device
>> 1161 * @regs - registers
1146 * 1162 *
1147 * We must acknowledge the interrupt as soon 1163 * We must acknowledge the interrupt as soon as possible, and block the
1148 * interrupt from the same card immediately t 1164 * interrupt from the same card immediately to prevent re-entry.
1149 * 1165 *
1150 * Before accessing the Control_Status_Block, 1166 * Before accessing the Control_Status_Block, we must lock SUTRO first.
1151 * On the other hand, to prevent SUTRO from m 1167 * On the other hand, to prevent SUTRO from malfunctioning, we must
1152 * unlock the SUTRO as soon as possible. 1168 * unlock the SUTRO as soon as possible.
1153 */ 1169 */
1154 static irqreturn_t wl3501_interrupt(int irq, !! 1170 static irqreturn_t wl3501_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1155 { 1171 {
1156 struct net_device *dev = dev_id; !! 1172 struct net_device *dev = (struct net_device *)dev_id;
1157 struct wl3501_card *this; 1173 struct wl3501_card *this;
>> 1174 int handled = 1;
1158 1175
1159 this = netdev_priv(dev); !! 1176 if (!dev)
>> 1177 goto unknown;
>> 1178 this = dev->priv;
1160 spin_lock(&this->lock); 1179 spin_lock(&this->lock);
1161 wl3501_ack_interrupt(this); 1180 wl3501_ack_interrupt(this);
1162 wl3501_block_interrupt(this); 1181 wl3501_block_interrupt(this);
1163 wl3501_rx_interrupt(dev); 1182 wl3501_rx_interrupt(dev);
1164 wl3501_unblock_interrupt(this); 1183 wl3501_unblock_interrupt(this);
1165 spin_unlock(&this->lock); 1184 spin_unlock(&this->lock);
1166 !! 1185 out:
1167 return IRQ_HANDLED; !! 1186 return IRQ_RETVAL(handled);
>> 1187 unknown:
>> 1188 handled = 0;
>> 1189 printk(KERN_ERR "%s: irq %d for unknown device.\n", __FUNCTION__, irq);
>> 1190 goto out;
1168 } 1191 }
1169 1192
1170 static int wl3501_reset_board(struct wl3501_c 1193 static int wl3501_reset_board(struct wl3501_card *this)
1171 { 1194 {
1172 u8 tmp = 0; 1195 u8 tmp = 0;
1173 int i, rc = 0; 1196 int i, rc = 0;
1174 1197
1175 /* Coreset */ 1198 /* Coreset */
1176 wl3501_outb_p(WL3501_GCR_CORESET, thi 1199 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1177 wl3501_outb_p(0, this->base_addr + WL 1200 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1178 wl3501_outb_p(WL3501_GCR_CORESET, thi 1201 wl3501_outb_p(WL3501_GCR_CORESET, this->base_addr + WL3501_NIC_GCR);
1179 1202
1180 /* Reset SRAM 0x480 to zero */ 1203 /* Reset SRAM 0x480 to zero */
1181 wl3501_set_to_wla(this, 0x480, &tmp, 1204 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1182 1205
1183 /* Start up */ 1206 /* Start up */
1184 wl3501_outb_p(0, this->base_addr + WL 1207 wl3501_outb_p(0, this->base_addr + WL3501_NIC_GCR);
1185 1208
1186 WL3501_NOPLOOP(1024 * 50); 1209 WL3501_NOPLOOP(1024 * 50);
1187 1210
1188 wl3501_unblock_interrupt(this); /* ac 1211 wl3501_unblock_interrupt(this); /* acme: was commented */
1189 1212
1190 /* Polling Self_Test_Status */ 1213 /* Polling Self_Test_Status */
1191 for (i = 0; i < 10000; i++) { 1214 for (i = 0; i < 10000; i++) {
1192 wl3501_get_from_wla(this, 0x4 1215 wl3501_get_from_wla(this, 0x480, &tmp, sizeof(tmp));
1193 1216
1194 if (tmp == 'W') { 1217 if (tmp == 'W') {
1195 /* firmware complete 1218 /* firmware complete all test successfully */
1196 tmp = 'A'; 1219 tmp = 'A';
1197 wl3501_set_to_wla(thi 1220 wl3501_set_to_wla(this, 0x480, &tmp, sizeof(tmp));
1198 goto out; 1221 goto out;
1199 } 1222 }
1200 WL3501_NOPLOOP(10); 1223 WL3501_NOPLOOP(10);
1201 } 1224 }
1202 printk(KERN_WARNING "%s: failed to re 1225 printk(KERN_WARNING "%s: failed to reset the board!\n", __FUNCTION__);
1203 rc = -ENODEV; 1226 rc = -ENODEV;
1204 out: 1227 out:
1205 return rc; 1228 return rc;
1206 } 1229 }
1207 1230
1208 static int wl3501_init_firmware(struct wl3501 1231 static int wl3501_init_firmware(struct wl3501_card *this)
1209 { 1232 {
1210 u16 ptr, next; 1233 u16 ptr, next;
1211 int rc = wl3501_reset_board(this); 1234 int rc = wl3501_reset_board(this);
1212 1235
1213 if (rc) 1236 if (rc)
1214 goto fail; 1237 goto fail;
1215 this->card_name[0] = '\0'; 1238 this->card_name[0] = '\0';
1216 wl3501_get_from_wla(this, 0x1a00, 1239 wl3501_get_from_wla(this, 0x1a00,
1217 this->card_name, 1240 this->card_name, sizeof(this->card_name));
1218 this->card_name[sizeof(this->card_nam 1241 this->card_name[sizeof(this->card_name) - 1] = '\0';
1219 this->firmware_date[0] = '\0'; 1242 this->firmware_date[0] = '\0';
1220 wl3501_get_from_wla(this, 0x1a40, 1243 wl3501_get_from_wla(this, 0x1a40,
1221 this->firmware_da 1244 this->firmware_date, sizeof(this->firmware_date));
1222 this->firmware_date[sizeof(this->firm 1245 this->firmware_date[sizeof(this->firmware_date) - 1] = '\0';
1223 /* Switch to SRAM Page 0 */ 1246 /* Switch to SRAM Page 0 */
1224 wl3501_switch_page(this, WL3501_BSS_S 1247 wl3501_switch_page(this, WL3501_BSS_SPAGE0);
1225 /* Read parameter from card */ 1248 /* Read parameter from card */
1226 wl3501_get_from_wla(this, 0x482, &thi 1249 wl3501_get_from_wla(this, 0x482, &this->esbq_req_start, 2);
1227 wl3501_get_from_wla(this, 0x486, &thi 1250 wl3501_get_from_wla(this, 0x486, &this->esbq_req_end, 2);
1228 wl3501_get_from_wla(this, 0x488, &thi 1251 wl3501_get_from_wla(this, 0x488, &this->esbq_confirm_start, 2);
1229 wl3501_get_from_wla(this, 0x48c, &thi 1252 wl3501_get_from_wla(this, 0x48c, &this->esbq_confirm_end, 2);
1230 wl3501_get_from_wla(this, 0x48e, &thi 1253 wl3501_get_from_wla(this, 0x48e, &this->tx_buffer_head, 2);
1231 wl3501_get_from_wla(this, 0x492, &thi 1254 wl3501_get_from_wla(this, 0x492, &this->tx_buffer_size, 2);
1232 this->esbq_req_tail = this->esbq_ 1255 this->esbq_req_tail = this->esbq_req_head = this->esbq_req_start;
1233 this->esbq_req_end += this->esbq_ 1256 this->esbq_req_end += this->esbq_req_start;
1234 this->esbq_confirm = this->esbq_ 1257 this->esbq_confirm = this->esbq_confirm_start;
1235 this->esbq_confirm_end += this->esbq_ 1258 this->esbq_confirm_end += this->esbq_confirm_start;
1236 /* Initial Tx Buffer */ 1259 /* Initial Tx Buffer */
1237 this->tx_buffer_cnt = 1; 1260 this->tx_buffer_cnt = 1;
1238 ptr = this->tx_buffer_head; 1261 ptr = this->tx_buffer_head;
1239 next = ptr + WL3501_BLKSZ; 1262 next = ptr + WL3501_BLKSZ;
1240 while ((next - this->tx_buffer_head) 1263 while ((next - this->tx_buffer_head) < this->tx_buffer_size) {
1241 this->tx_buffer_cnt++; 1264 this->tx_buffer_cnt++;
1242 wl3501_set_to_wla(this, ptr, 1265 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1243 ptr = next; 1266 ptr = next;
1244 next = ptr + WL3501_BLKSZ; 1267 next = ptr + WL3501_BLKSZ;
1245 } 1268 }
1246 rc = 0; 1269 rc = 0;
1247 next = 0; 1270 next = 0;
1248 wl3501_set_to_wla(this, ptr, &next, s 1271 wl3501_set_to_wla(this, ptr, &next, sizeof(next));
1249 this->tx_buffer_tail = ptr; 1272 this->tx_buffer_tail = ptr;
1250 out: 1273 out:
1251 return rc; 1274 return rc;
1252 fail: 1275 fail:
1253 printk(KERN_WARNING "%s: failed!\n", 1276 printk(KERN_WARNING "%s: failed!\n", __FUNCTION__);
1254 goto out; 1277 goto out;
1255 } 1278 }
1256 1279
1257 static int wl3501_close(struct net_device *de 1280 static int wl3501_close(struct net_device *dev)
1258 { 1281 {
1259 struct wl3501_card *this = netdev_pri !! 1282 struct wl3501_card *this = dev->priv;
1260 int rc = -ENODEV; 1283 int rc = -ENODEV;
1261 unsigned long flags; 1284 unsigned long flags;
1262 struct pcmcia_device *link; !! 1285 dev_link_t *link;
1263 link = this->p_dev; <<
1264 1286
1265 spin_lock_irqsave(&this->lock, flags) 1287 spin_lock_irqsave(&this->lock, flags);
>> 1288 /* Check if the device is in wl3501_dev_list */
>> 1289 for (link = wl3501_dev_list; link; link = link->next)
>> 1290 if (link->priv == dev)
>> 1291 break;
>> 1292 if (!link)
>> 1293 goto out;
1266 link->open--; 1294 link->open--;
1267 1295
1268 /* Stop wl3501_hard_start_xmit() from 1296 /* Stop wl3501_hard_start_xmit() from now on */
1269 netif_stop_queue(dev); 1297 netif_stop_queue(dev);
1270 wl3501_ack_interrupt(this); 1298 wl3501_ack_interrupt(this);
1271 1299
1272 /* Mask interrupts from the SUTRO */ 1300 /* Mask interrupts from the SUTRO */
1273 wl3501_block_interrupt(this); 1301 wl3501_block_interrupt(this);
1274 1302
1275 rc = 0; 1303 rc = 0;
1276 printk(KERN_INFO "%s: WL3501 closed\n 1304 printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
>> 1305 out:
1277 spin_unlock_irqrestore(&this->lock, f 1306 spin_unlock_irqrestore(&this->lock, flags);
1278 return rc; 1307 return rc;
1279 } 1308 }
1280 1309
1281 /** 1310 /**
1282 * wl3501_reset - Reset the SUTRO. 1311 * wl3501_reset - Reset the SUTRO.
1283 * @dev - network device 1312 * @dev - network device
1284 * 1313 *
1285 * It is almost the same as wl3501_open(). In 1314 * It is almost the same as wl3501_open(). In fact, we may just wl3501_close()
1286 * and wl3501_open() again, but I wouldn't li 1315 * and wl3501_open() again, but I wouldn't like to free_irq() when the driver
1287 * is running. It seems to be dangerous. 1316 * is running. It seems to be dangerous.
1288 */ 1317 */
1289 static int wl3501_reset(struct net_device *de 1318 static int wl3501_reset(struct net_device *dev)
1290 { 1319 {
1291 struct wl3501_card *this = netdev_pri !! 1320 struct wl3501_card *this = dev->priv;
1292 int rc = -ENODEV; 1321 int rc = -ENODEV;
1293 1322
1294 wl3501_block_interrupt(this); 1323 wl3501_block_interrupt(this);
1295 1324
1296 if (wl3501_init_firmware(this)) { 1325 if (wl3501_init_firmware(this)) {
1297 printk(KERN_WARNING "%s: Can' 1326 printk(KERN_WARNING "%s: Can't initialize Firmware!\n",
1298 dev->name); 1327 dev->name);
1299 /* Free IRQ, and mark IRQ as 1328 /* Free IRQ, and mark IRQ as unused */
1300 free_irq(dev->irq, dev); 1329 free_irq(dev->irq, dev);
1301 goto out; 1330 goto out;
1302 } 1331 }
1303 1332
1304 /* 1333 /*
1305 * Queue has to be started only when 1334 * Queue has to be started only when the Card is Started
1306 */ 1335 */
1307 netif_stop_queue(dev); 1336 netif_stop_queue(dev);
1308 this->adhoc_times = 0; 1337 this->adhoc_times = 0;
1309 wl3501_ack_interrupt(this); 1338 wl3501_ack_interrupt(this);
1310 wl3501_unblock_interrupt(this); 1339 wl3501_unblock_interrupt(this);
1311 wl3501_mgmt_scan(this, 100); 1340 wl3501_mgmt_scan(this, 100);
1312 dprintk(1, "%s: device reset", dev->n 1341 dprintk(1, "%s: device reset", dev->name);
1313 rc = 0; 1342 rc = 0;
1314 out: 1343 out:
1315 return rc; 1344 return rc;
1316 } 1345 }
1317 1346
1318 static void wl3501_tx_timeout(struct net_devi 1347 static void wl3501_tx_timeout(struct net_device *dev)
1319 { 1348 {
1320 struct wl3501_card *this = netdev_pri !! 1349 struct wl3501_card *this = dev->priv;
1321 struct net_device_stats *stats = &thi 1350 struct net_device_stats *stats = &this->stats;
1322 unsigned long flags; 1351 unsigned long flags;
1323 int rc; 1352 int rc;
1324 1353
1325 stats->tx_errors++; 1354 stats->tx_errors++;
1326 spin_lock_irqsave(&this->lock, flags) 1355 spin_lock_irqsave(&this->lock, flags);
1327 rc = wl3501_reset(dev); 1356 rc = wl3501_reset(dev);
1328 spin_unlock_irqrestore(&this->lock, f 1357 spin_unlock_irqrestore(&this->lock, flags);
1329 if (rc) 1358 if (rc)
1330 printk(KERN_ERR "%s: Error %d 1359 printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
1331 dev->name, rc); 1360 dev->name, rc);
1332 else { 1361 else {
1333 dev->trans_start = jiffies; 1362 dev->trans_start = jiffies;
1334 netif_wake_queue(dev); 1363 netif_wake_queue(dev);
1335 } 1364 }
1336 } 1365 }
1337 1366
1338 /* 1367 /*
1339 * Return : 0 - OK 1368 * Return : 0 - OK
1340 * 1 - Could not transmit (dev_queue 1369 * 1 - Could not transmit (dev_queue_xmit will queue it)
1341 * and try to sent it later 1370 * and try to sent it later
1342 */ 1371 */
1343 static int wl3501_hard_start_xmit(struct sk_b 1372 static int wl3501_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1344 { 1373 {
1345 int enabled, rc; 1374 int enabled, rc;
1346 struct wl3501_card *this = netdev_pri !! 1375 struct wl3501_card *this = dev->priv;
1347 unsigned long flags; 1376 unsigned long flags;
1348 1377
1349 spin_lock_irqsave(&this->lock, flags) 1378 spin_lock_irqsave(&this->lock, flags);
1350 enabled = wl3501_block_interrupt(this 1379 enabled = wl3501_block_interrupt(this);
1351 dev->trans_start = jiffies; 1380 dev->trans_start = jiffies;
1352 rc = wl3501_send_pkt(this, skb->data, 1381 rc = wl3501_send_pkt(this, skb->data, skb->len);
1353 if (enabled) 1382 if (enabled)
1354 wl3501_unblock_interrupt(this 1383 wl3501_unblock_interrupt(this);
1355 if (rc) { 1384 if (rc) {
1356 ++this->stats.tx_dropped; 1385 ++this->stats.tx_dropped;
1357 netif_stop_queue(dev); 1386 netif_stop_queue(dev);
1358 } else { 1387 } else {
1359 ++this->stats.tx_packets; 1388 ++this->stats.tx_packets;
1360 this->stats.tx_bytes += skb-> 1389 this->stats.tx_bytes += skb->len;
1361 kfree_skb(skb); 1390 kfree_skb(skb);
1362 1391
1363 if (this->tx_buffer_cnt < 2) 1392 if (this->tx_buffer_cnt < 2)
1364 netif_stop_queue(dev) 1393 netif_stop_queue(dev);
1365 } 1394 }
1366 spin_unlock_irqrestore(&this->lock, f 1395 spin_unlock_irqrestore(&this->lock, flags);
1367 return rc; 1396 return rc;
1368 } 1397 }
1369 1398
1370 static int wl3501_open(struct net_device *dev 1399 static int wl3501_open(struct net_device *dev)
1371 { 1400 {
1372 int rc = -ENODEV; 1401 int rc = -ENODEV;
1373 struct wl3501_card *this = netdev_pri !! 1402 struct wl3501_card *this = dev->priv;
1374 unsigned long flags; 1403 unsigned long flags;
1375 struct pcmcia_device *link; !! 1404 dev_link_t *link;
1376 link = this->p_dev; <<
1377 1405
1378 spin_lock_irqsave(&this->lock, flags) 1406 spin_lock_irqsave(&this->lock, flags);
1379 if (!pcmcia_dev_present(link)) !! 1407 /* Check if the device is in wl3501_dev_list */
>> 1408 for (link = wl3501_dev_list; link; link = link->next)
>> 1409 if (link->priv == dev)
>> 1410 break;
>> 1411 if (!DEV_OK(link))
1380 goto out; 1412 goto out;
1381 netif_device_attach(dev); 1413 netif_device_attach(dev);
1382 link->open++; 1414 link->open++;
1383 1415
1384 /* Initial WL3501 firmware */ 1416 /* Initial WL3501 firmware */
1385 dprintk(1, "%s: Initialize WL3501 fir 1417 dprintk(1, "%s: Initialize WL3501 firmware...", dev->name);
1386 if (wl3501_init_firmware(this)) 1418 if (wl3501_init_firmware(this))
1387 goto fail; 1419 goto fail;
1388 /* Initial device variables */ 1420 /* Initial device variables */
1389 this->adhoc_times = 0; 1421 this->adhoc_times = 0;
1390 /* Acknowledge Interrupt, for cleanin 1422 /* Acknowledge Interrupt, for cleaning last state */
1391 wl3501_ack_interrupt(this); 1423 wl3501_ack_interrupt(this);
1392 1424
1393 /* Enable interrupt from card after a 1425 /* Enable interrupt from card after all */
1394 wl3501_unblock_interrupt(this); 1426 wl3501_unblock_interrupt(this);
1395 wl3501_mgmt_scan(this, 100); 1427 wl3501_mgmt_scan(this, 100);
1396 rc = 0; 1428 rc = 0;
1397 dprintk(1, "%s: WL3501 opened", dev-> 1429 dprintk(1, "%s: WL3501 opened", dev->name);
1398 printk(KERN_INFO "%s: Card Name: %s\n 1430 printk(KERN_INFO "%s: Card Name: %s\n"
1399 "%s: Firmware Date: 1431 "%s: Firmware Date: %s\n",
1400 dev->name, this->car 1432 dev->name, this->card_name,
1401 dev->name, this->fir 1433 dev->name, this->firmware_date);
1402 out: 1434 out:
1403 spin_unlock_irqrestore(&this->lock, f 1435 spin_unlock_irqrestore(&this->lock, flags);
1404 return rc; 1436 return rc;
1405 fail: 1437 fail:
1406 printk(KERN_WARNING "%s: Can't initia 1438 printk(KERN_WARNING "%s: Can't initialize firmware!\n", dev->name);
1407 goto out; 1439 goto out;
1408 } 1440 }
1409 1441
1410 static struct net_device_stats *wl3501_get_st !! 1442 struct net_device_stats *wl3501_get_stats(struct net_device *dev)
1411 { 1443 {
1412 struct wl3501_card *this = netdev_pri !! 1444 struct wl3501_card *this = dev->priv;
1413 1445
1414 return &this->stats; 1446 return &this->stats;
1415 } 1447 }
1416 1448
1417 static struct iw_statistics *wl3501_get_wirel !! 1449 struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
1418 { 1450 {
1419 struct wl3501_card *this = netdev_pri !! 1451 struct wl3501_card *this = dev->priv;
1420 struct iw_statistics *wstats = &this- 1452 struct iw_statistics *wstats = &this->wstats;
1421 u32 value; /* size checked: it is u32 1453 u32 value; /* size checked: it is u32 */
1422 1454
1423 memset(wstats, 0, sizeof(*wstats)); 1455 memset(wstats, 0, sizeof(*wstats));
1424 wstats->status = netif_running(dev); 1456 wstats->status = netif_running(dev);
1425 if (!wl3501_get_mib_value(this, WL350 1457 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_ICV_ERROR_COUNT,
1426 &value, siz 1458 &value, sizeof(value)))
1427 wstats->discard.code += value 1459 wstats->discard.code += value;
1428 if (!wl3501_get_mib_value(this, WL350 1460 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_UNDECRYPTABLE_COUNT,
1429 &value, siz 1461 &value, sizeof(value)))
1430 wstats->discard.code += value 1462 wstats->discard.code += value;
1431 if (!wl3501_get_mib_value(this, WL350 1463 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_EXCLUDED_COUNT,
1432 &value, siz 1464 &value, sizeof(value)))
1433 wstats->discard.code += value 1465 wstats->discard.code += value;
1434 if (!wl3501_get_mib_value(this, WL350 1466 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RETRY_COUNT,
1435 &value, siz 1467 &value, sizeof(value)))
1436 wstats->discard.retries = val 1468 wstats->discard.retries = value;
1437 if (!wl3501_get_mib_value(this, WL350 1469 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FAILED_COUNT,
1438 &value, siz 1470 &value, sizeof(value)))
1439 wstats->discard.misc += value 1471 wstats->discard.misc += value;
1440 if (!wl3501_get_mib_value(this, WL350 1472 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_FAILURE_COUNT,
1441 &value, siz 1473 &value, sizeof(value)))
1442 wstats->discard.misc += value 1474 wstats->discard.misc += value;
1443 if (!wl3501_get_mib_value(this, WL350 1475 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_ACK_FAILURE_COUNT,
1444 &value, siz 1476 &value, sizeof(value)))
1445 wstats->discard.misc += value 1477 wstats->discard.misc += value;
1446 if (!wl3501_get_mib_value(this, WL350 1478 if (!wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAME_DUPLICATE_COUNT,
1447 &value, siz 1479 &value, sizeof(value)))
1448 wstats->discard.misc += value 1480 wstats->discard.misc += value;
1449 return wstats; 1481 return wstats;
1450 } 1482 }
1451 1483
1452 static void wl3501_get_drvinfo(struct net_dev 1484 static void wl3501_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1453 { 1485 {
1454 strlcpy(info->driver, wl3501_dev_info 1486 strlcpy(info->driver, wl3501_dev_info, sizeof(info->driver));
1455 } 1487 }
1456 1488
1457 static const struct ethtool_ops ops = { !! 1489 static struct ethtool_ops ops = {
1458 .get_drvinfo = wl3501_get_drvinfo 1490 .get_drvinfo = wl3501_get_drvinfo
1459 }; 1491 };
1460 1492
1461 /** 1493 /**
1462 * wl3501_detach - deletes a driver "instance 1494 * wl3501_detach - deletes a driver "instance"
1463 * @link - FILL_IN 1495 * @link - FILL_IN
1464 * 1496 *
1465 * This deletes a driver "instance". The devi 1497 * This deletes a driver "instance". The device is de-registered with Card
1466 * Services. If it has been released, all loc 1498 * Services. If it has been released, all local data structures are freed.
1467 * Otherwise, the structures will be freed wh 1499 * Otherwise, the structures will be freed when the device is released.
1468 */ 1500 */
1469 static void wl3501_detach(struct pcmcia_devic !! 1501 static void wl3501_detach(dev_link_t *link)
1470 { 1502 {
1471 struct net_device *dev = link->priv; !! 1503 dev_link_t **linkp;
>> 1504
>> 1505 /* Locate device structure */
>> 1506 for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
>> 1507 if (*linkp == link)
>> 1508 break;
>> 1509 if (!*linkp)
>> 1510 goto out;
1472 1511
1473 /* If the device is currently configu 1512 /* If the device is currently configured and active, we won't actually
1474 * delete it yet. Instead, it is mar 1513 * delete it yet. Instead, it is marked so that when the release()
1475 * function is called, that will trig 1514 * function is called, that will trigger a proper detach(). */
1476 1515
1477 while (link->open > 0) !! 1516 if (link->state & DEV_CONFIG) {
1478 wl3501_close(dev); !! 1517 #ifdef PCMCIA_DEBUG
>> 1518 printk(KERN_DEBUG "wl3501_cs: detach postponed, '%s' "
>> 1519 "still locked\n", link->dev->dev_name);
>> 1520 #endif
>> 1521 goto out;
>> 1522 }
>> 1523
>> 1524 /* Break the link with Card Services */
>> 1525 if (link->handle)
>> 1526 pcmcia_deregister_client(link->handle);
1479 1527
1480 netif_device_detach(dev); !! 1528 /* Unlink device structure, free pieces */
1481 wl3501_release(link); !! 1529 *linkp = link->next;
1482 1530
1483 if (link->priv) 1531 if (link->priv)
1484 free_netdev(link->priv); 1532 free_netdev(link->priv);
1485 !! 1533 kfree(link);
>> 1534 out:
1486 return; 1535 return;
1487 } 1536 }
1488 1537
1489 static int wl3501_get_name(struct net_device 1538 static int wl3501_get_name(struct net_device *dev, struct iw_request_info *info,
1490 union iwreq_data * 1539 union iwreq_data *wrqu, char *extra)
1491 { 1540 {
1492 strlcpy(wrqu->name, "IEEE 802.11-DS", 1541 strlcpy(wrqu->name, "IEEE 802.11-DS", sizeof(wrqu->name));
1493 return 0; 1542 return 0;
1494 } 1543 }
1495 1544
1496 static int wl3501_set_freq(struct net_device 1545 static int wl3501_set_freq(struct net_device *dev, struct iw_request_info *info,
1497 union iwreq_data * 1546 union iwreq_data *wrqu, char *extra)
1498 { 1547 {
1499 struct wl3501_card *this = netdev_pri !! 1548 struct wl3501_card *this = dev->priv;
1500 int channel = wrqu->freq.m; 1549 int channel = wrqu->freq.m;
1501 int rc = -EINVAL; 1550 int rc = -EINVAL;
1502 1551
1503 if (iw_valid_channel(this->reg_domain 1552 if (iw_valid_channel(this->reg_domain, channel)) {
1504 this->chan = channel; 1553 this->chan = channel;
1505 rc = wl3501_reset(dev); 1554 rc = wl3501_reset(dev);
1506 } 1555 }
1507 return rc; 1556 return rc;
1508 } 1557 }
1509 1558
1510 static int wl3501_get_freq(struct net_device 1559 static int wl3501_get_freq(struct net_device *dev, struct iw_request_info *info,
1511 union iwreq_data * 1560 union iwreq_data *wrqu, char *extra)
1512 { 1561 {
1513 struct wl3501_card *this = netdev_pri !! 1562 struct wl3501_card *this = dev->priv;
1514 1563
1515 wrqu->freq.m = wl3501_chan2freq[this- 1564 wrqu->freq.m = wl3501_chan2freq[this->chan - 1] * 100000;
1516 wrqu->freq.e = 1; 1565 wrqu->freq.e = 1;
1517 return 0; 1566 return 0;
1518 } 1567 }
1519 1568
1520 static int wl3501_set_mode(struct net_device 1569 static int wl3501_set_mode(struct net_device *dev, struct iw_request_info *info,
1521 union iwreq_data * 1570 union iwreq_data *wrqu, char *extra)
1522 { 1571 {
1523 int rc = -EINVAL; 1572 int rc = -EINVAL;
1524 1573
1525 if (wrqu->mode == IW_MODE_INFRA || 1574 if (wrqu->mode == IW_MODE_INFRA ||
1526 wrqu->mode == IW_MODE_ADHOC || 1575 wrqu->mode == IW_MODE_ADHOC ||
1527 wrqu->mode == IW_MODE_AUTO) { 1576 wrqu->mode == IW_MODE_AUTO) {
1528 struct wl3501_card *this = ne !! 1577 struct wl3501_card *this = dev->priv;
1529 1578
1530 this->net_type = wrqu->mode; 1579 this->net_type = wrqu->mode;
1531 rc = wl3501_reset(dev); 1580 rc = wl3501_reset(dev);
1532 } 1581 }
1533 return rc; 1582 return rc;
1534 } 1583 }
1535 1584
1536 static int wl3501_get_mode(struct net_device 1585 static int wl3501_get_mode(struct net_device *dev, struct iw_request_info *info,
1537 union iwreq_data * 1586 union iwreq_data *wrqu, char *extra)
1538 { 1587 {
1539 struct wl3501_card *this = netdev_pri !! 1588 struct wl3501_card *this = dev->priv;
1540 1589
1541 wrqu->mode = this->net_type; 1590 wrqu->mode = this->net_type;
1542 return 0; 1591 return 0;
1543 } 1592 }
1544 1593
1545 static int wl3501_get_sens(struct net_device 1594 static int wl3501_get_sens(struct net_device *dev, struct iw_request_info *info,
1546 union iwreq_data * 1595 union iwreq_data *wrqu, char *extra)
1547 { 1596 {
1548 struct wl3501_card *this = netdev_pri !! 1597 struct wl3501_card *this = dev->priv;
1549 1598
1550 wrqu->sens.value = this->rssi; 1599 wrqu->sens.value = this->rssi;
1551 wrqu->sens.disabled = !wrqu->sens.val 1600 wrqu->sens.disabled = !wrqu->sens.value;
1552 wrqu->sens.fixed = 1; 1601 wrqu->sens.fixed = 1;
1553 return 0; 1602 return 0;
1554 } 1603 }
1555 1604
1556 static int wl3501_get_range(struct net_device 1605 static int wl3501_get_range(struct net_device *dev,
1557 struct iw_request 1606 struct iw_request_info *info,
1558 union iwreq_data 1607 union iwreq_data *wrqu, char *extra)
1559 { 1608 {
1560 struct iw_range *range = (struct iw_r 1609 struct iw_range *range = (struct iw_range *)extra;
1561 1610
1562 /* Set the length (very important for 1611 /* Set the length (very important for backward compatibility) */
1563 wrqu->data.length = sizeof(*range); 1612 wrqu->data.length = sizeof(*range);
1564 1613
1565 /* Set all the info we don't care or 1614 /* Set all the info we don't care or don't know about to zero */
1566 memset(range, 0, sizeof(*range)); 1615 memset(range, 0, sizeof(*range));
1567 1616
1568 /* Set the Wireless Extension version 1617 /* Set the Wireless Extension versions */
1569 range->we_version_compiled = WIR 1618 range->we_version_compiled = WIRELESS_EXT;
1570 range->we_version_source = 1; 1619 range->we_version_source = 1;
1571 range->throughput = 2 * 1620 range->throughput = 2 * 1000 * 1000; /* ~2 Mb/s */
1572 /* FIXME: study the code to fill in m 1621 /* FIXME: study the code to fill in more fields... */
1573 return 0; 1622 return 0;
1574 } 1623 }
1575 1624
1576 static int wl3501_set_wap(struct net_device * 1625 static int wl3501_set_wap(struct net_device *dev, struct iw_request_info *info,
1577 union iwreq_data *w 1626 union iwreq_data *wrqu, char *extra)
1578 { 1627 {
1579 struct wl3501_card *this = netdev_pri !! 1628 struct wl3501_card *this = dev->priv;
1580 static const u8 bcast[ETH_ALEN] = { 2 1629 static const u8 bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
1581 int rc = -EINVAL; 1630 int rc = -EINVAL;
1582 1631
1583 /* FIXME: we support other ARPHRDs... 1632 /* FIXME: we support other ARPHRDs...*/
1584 if (wrqu->ap_addr.sa_family != ARPHRD 1633 if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
1585 goto out; 1634 goto out;
1586 if (!memcmp(bcast, wrqu->ap_addr.sa_d 1635 if (!memcmp(bcast, wrqu->ap_addr.sa_data, ETH_ALEN)) {
1587 /* FIXME: rescan? */ 1636 /* FIXME: rescan? */
1588 } else 1637 } else
1589 memcpy(this->bssid, wrqu->ap_ 1638 memcpy(this->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
1590 /* FIXME: rescan? deassoc & s 1639 /* FIXME: rescan? deassoc & scan? */
1591 rc = 0; 1640 rc = 0;
1592 out: 1641 out:
1593 return rc; 1642 return rc;
1594 } 1643 }
1595 1644
1596 static int wl3501_get_wap(struct net_device * 1645 static int wl3501_get_wap(struct net_device *dev, struct iw_request_info *info,
1597 union iwreq_data *w 1646 union iwreq_data *wrqu, char *extra)
1598 { 1647 {
1599 struct wl3501_card *this = netdev_pri !! 1648 struct wl3501_card *this = dev->priv;
1600 1649
1601 wrqu->ap_addr.sa_family = ARPHRD_ETHE 1650 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1602 memcpy(wrqu->ap_addr.sa_data, this->b 1651 memcpy(wrqu->ap_addr.sa_data, this->bssid, ETH_ALEN);
1603 return 0; 1652 return 0;
1604 } 1653 }
1605 1654
1606 static int wl3501_set_scan(struct net_device 1655 static int wl3501_set_scan(struct net_device *dev, struct iw_request_info *info,
1607 union iwreq_data * 1656 union iwreq_data *wrqu, char *extra)
1608 { 1657 {
1609 /* 1658 /*
1610 * FIXME: trigger scanning with a res 1659 * FIXME: trigger scanning with a reset, yes, I'm lazy
1611 */ 1660 */
1612 return wl3501_reset(dev); 1661 return wl3501_reset(dev);
1613 } 1662 }
1614 1663
1615 static int wl3501_get_scan(struct net_device 1664 static int wl3501_get_scan(struct net_device *dev, struct iw_request_info *info,
1616 union iwreq_data * 1665 union iwreq_data *wrqu, char *extra)
1617 { 1666 {
1618 struct wl3501_card *this = netdev_pri !! 1667 struct wl3501_card *this = dev->priv;
1619 int i; 1668 int i;
1620 char *current_ev = extra; 1669 char *current_ev = extra;
1621 struct iw_event iwe; 1670 struct iw_event iwe;
1622 1671
1623 for (i = 0; i < this->bss_cnt; ++i) { 1672 for (i = 0; i < this->bss_cnt; ++i) {
1624 iwe.cmd = SIO 1673 iwe.cmd = SIOCGIWAP;
1625 iwe.u.ap_addr.sa_family = ARP 1674 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1626 memcpy(iwe.u.ap_addr.sa_data, 1675 memcpy(iwe.u.ap_addr.sa_data, this->bss_set[i].bssid, ETH_ALEN);
1627 current_ev = iwe_stream_add_e 1676 current_ev = iwe_stream_add_event(current_ev,
1628 1677 extra + IW_SCAN_MAX_DATA,
1629 1678 &iwe, IW_EV_ADDR_LEN);
1630 iwe.cmd = SIOCGIWES 1679 iwe.cmd = SIOCGIWESSID;
1631 iwe.u.data.flags = 1; 1680 iwe.u.data.flags = 1;
1632 iwe.u.data.length = this->bss 1681 iwe.u.data.length = this->bss_set[i].ssid.el.len;
1633 current_ev = iwe_stream_add_p 1682 current_ev = iwe_stream_add_point(current_ev,
1634 1683 extra + IW_SCAN_MAX_DATA,
1635 1684 &iwe,
1636 1685 this->bss_set[i].ssid.essid);
1637 iwe.cmd = SIOCGIWMODE; 1686 iwe.cmd = SIOCGIWMODE;
1638 iwe.u.mode = this->bss_set[i] 1687 iwe.u.mode = this->bss_set[i].bss_type;
1639 current_ev = iwe_stream_add_e 1688 current_ev = iwe_stream_add_event(current_ev,
1640 1689 extra + IW_SCAN_MAX_DATA,
1641 1690 &iwe, IW_EV_UINT_LEN);
1642 iwe.cmd = SIOCGIWFREQ; 1691 iwe.cmd = SIOCGIWFREQ;
1643 iwe.u.freq.m = this->bss_set[ 1692 iwe.u.freq.m = this->bss_set[i].ds_pset.chan;
1644 iwe.u.freq.e = 0; 1693 iwe.u.freq.e = 0;
1645 current_ev = iwe_stream_add_e 1694 current_ev = iwe_stream_add_event(current_ev,
1646 1695 extra + IW_SCAN_MAX_DATA,
1647 1696 &iwe, IW_EV_FREQ_LEN);
1648 iwe.cmd = SIOCGIWENCODE; 1697 iwe.cmd = SIOCGIWENCODE;
1649 if (this->bss_set[i].cap_info 1698 if (this->bss_set[i].cap_info & WL3501_MGMT_CAPABILITY_PRIVACY)
1650 iwe.u.data.flags = IW 1699 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1651 else 1700 else
1652 iwe.u.data.flags = IW 1701 iwe.u.data.flags = IW_ENCODE_DISABLED;
1653 iwe.u.data.length = 0; 1702 iwe.u.data.length = 0;
1654 current_ev = iwe_stream_add_p 1703 current_ev = iwe_stream_add_point(current_ev,
1655 1704 extra + IW_SCAN_MAX_DATA,
1656 1705 &iwe, NULL);
1657 } 1706 }
1658 /* Length of data */ 1707 /* Length of data */
1659 wrqu->data.length = (current_ev - ext 1708 wrqu->data.length = (current_ev - extra);
1660 wrqu->data.flags = 0; /* FIXME: set p 1709 wrqu->data.flags = 0; /* FIXME: set properly these flags */
1661 return 0; 1710 return 0;
1662 } 1711 }
1663 1712
1664 static int wl3501_set_essid(struct net_device 1713 static int wl3501_set_essid(struct net_device *dev,
1665 struct iw_request 1714 struct iw_request_info *info,
1666 union iwreq_data 1715 union iwreq_data *wrqu, char *extra)
1667 { 1716 {
1668 struct wl3501_card *this = netdev_pri !! 1717 struct wl3501_card *this = dev->priv;
1669 1718
1670 if (wrqu->data.flags) { 1719 if (wrqu->data.flags) {
1671 iw_set_mgmt_info_element(IW_M 1720 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1672 &thi 1721 &this->essid.el,
1673 extr 1722 extra, wrqu->data.length);
1674 } else { /* We accept any ESSID */ 1723 } else { /* We accept any ESSID */
1675 iw_set_mgmt_info_element(IW_M 1724 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID,
1676 &thi 1725 &this->essid.el, "ANY", 3);
1677 } 1726 }
1678 return wl3501_reset(dev); 1727 return wl3501_reset(dev);
1679 } 1728 }
1680 1729
1681 static int wl3501_get_essid(struct net_device 1730 static int wl3501_get_essid(struct net_device *dev,
1682 struct iw_request 1731 struct iw_request_info *info,
1683 union iwreq_data 1732 union iwreq_data *wrqu, char *extra)
1684 { 1733 {
1685 struct wl3501_card *this = netdev_pri !! 1734 struct wl3501_card *this = dev->priv;
1686 unsigned long flags; 1735 unsigned long flags;
1687 1736
1688 spin_lock_irqsave(&this->lock, flags) 1737 spin_lock_irqsave(&this->lock, flags);
1689 wrqu->essid.flags = 1; 1738 wrqu->essid.flags = 1;
1690 wrqu->essid.length = this->essid.el.l 1739 wrqu->essid.length = this->essid.el.len;
1691 memcpy(extra, this->essid.essid, this 1740 memcpy(extra, this->essid.essid, this->essid.el.len);
1692 spin_unlock_irqrestore(&this->lock, f 1741 spin_unlock_irqrestore(&this->lock, flags);
1693 return 0; 1742 return 0;
1694 } 1743 }
1695 1744
1696 static int wl3501_set_nick(struct net_device 1745 static int wl3501_set_nick(struct net_device *dev, struct iw_request_info *info,
1697 union iwreq_data * 1746 union iwreq_data *wrqu, char *extra)
1698 { 1747 {
1699 struct wl3501_card *this = netdev_pri !! 1748 struct wl3501_card *this = dev->priv;
1700 1749
1701 if (wrqu->data.length > sizeof(this-> 1750 if (wrqu->data.length > sizeof(this->nick))
1702 return -E2BIG; 1751 return -E2BIG;
1703 strlcpy(this->nick, extra, wrqu->data 1752 strlcpy(this->nick, extra, wrqu->data.length);
1704 return 0; 1753 return 0;
1705 } 1754 }
1706 1755
1707 static int wl3501_get_nick(struct net_device 1756 static int wl3501_get_nick(struct net_device *dev, struct iw_request_info *info,
1708 union iwreq_data * 1757 union iwreq_data *wrqu, char *extra)
1709 { 1758 {
1710 struct wl3501_card *this = netdev_pri !! 1759 struct wl3501_card *this = dev->priv;
1711 1760
1712 strlcpy(extra, this->nick, 32); 1761 strlcpy(extra, this->nick, 32);
1713 wrqu->data.length = strlen(extra); 1762 wrqu->data.length = strlen(extra);
1714 return 0; 1763 return 0;
1715 } 1764 }
1716 1765
1717 static int wl3501_get_rate(struct net_device 1766 static int wl3501_get_rate(struct net_device *dev, struct iw_request_info *info,
1718 union iwreq_data * 1767 union iwreq_data *wrqu, char *extra)
1719 { 1768 {
1720 /* 1769 /*
1721 * FIXME: have to see from where to g 1770 * FIXME: have to see from where to get this info, perhaps this card
1722 * works at 1 Mbit/s too... for now l 1771 * works at 1 Mbit/s too... for now leave at 2 Mbit/s that is the most
1723 * common with the Planet Access Poin 1772 * common with the Planet Access Points. -acme
1724 */ 1773 */
1725 wrqu->bitrate.value = 2000000; 1774 wrqu->bitrate.value = 2000000;
1726 wrqu->bitrate.fixed = 1; 1775 wrqu->bitrate.fixed = 1;
1727 return 0; 1776 return 0;
1728 } 1777 }
1729 1778
1730 static int wl3501_get_rts_threshold(struct ne 1779 static int wl3501_get_rts_threshold(struct net_device *dev,
1731 struct iw 1780 struct iw_request_info *info,
1732 union iwr 1781 union iwreq_data *wrqu, char *extra)
1733 { 1782 {
1734 u16 threshold; /* size checked: it is 1783 u16 threshold; /* size checked: it is u16 */
1735 struct wl3501_card *this = netdev_pri !! 1784 struct wl3501_card *this = dev->priv;
1736 int rc = wl3501_get_mib_value(this, W 1785 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_RTS_THRESHOLD,
1737 &thresh 1786 &threshold, sizeof(threshold));
1738 if (!rc) { 1787 if (!rc) {
1739 wrqu->rts.value = threshold; 1788 wrqu->rts.value = threshold;
1740 wrqu->rts.disabled = threshol 1789 wrqu->rts.disabled = threshold >= 2347;
1741 wrqu->rts.fixed = 1; 1790 wrqu->rts.fixed = 1;
1742 } 1791 }
1743 return rc; 1792 return rc;
1744 } 1793 }
1745 1794
1746 static int wl3501_get_frag_threshold(struct n 1795 static int wl3501_get_frag_threshold(struct net_device *dev,
1747 struct i 1796 struct iw_request_info *info,
1748 union iw 1797 union iwreq_data *wrqu, char *extra)
1749 { 1798 {
1750 u16 threshold; /* size checked: it is 1799 u16 threshold; /* size checked: it is u16 */
1751 struct wl3501_card *this = netdev_pri !! 1800 struct wl3501_card *this = dev->priv;
1752 int rc = wl3501_get_mib_value(this, W 1801 int rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_FRAG_THRESHOLD,
1753 &thresh 1802 &threshold, sizeof(threshold));
1754 if (!rc) { 1803 if (!rc) {
1755 wrqu->frag.value = threshold; 1804 wrqu->frag.value = threshold;
1756 wrqu->frag.disabled = thresho 1805 wrqu->frag.disabled = threshold >= 2346;
1757 wrqu->frag.fixed = 1; 1806 wrqu->frag.fixed = 1;
1758 } 1807 }
1759 return rc; 1808 return rc;
1760 } 1809 }
1761 1810
1762 static int wl3501_get_txpow(struct net_device 1811 static int wl3501_get_txpow(struct net_device *dev,
1763 struct iw_request 1812 struct iw_request_info *info,
1764 union iwreq_data 1813 union iwreq_data *wrqu, char *extra)
1765 { 1814 {
1766 u16 txpow; 1815 u16 txpow;
1767 struct wl3501_card *this = netdev_pri !! 1816 struct wl3501_card *this = dev->priv;
1768 int rc = wl3501_get_mib_value(this, 1817 int rc = wl3501_get_mib_value(this,
1769 WL3501_ 1818 WL3501_MIB_ATTR_CURRENT_TX_PWR_LEVEL,
1770 &txpow, 1819 &txpow, sizeof(txpow));
1771 if (!rc) { 1820 if (!rc) {
1772 wrqu->txpower.value = txpow; 1821 wrqu->txpower.value = txpow;
1773 wrqu->txpower.disabled = 0; 1822 wrqu->txpower.disabled = 0;
1774 /* 1823 /*
1775 * From the MIB values I thin 1824 * From the MIB values I think this can be configurable,
1776 * as it lists several tx pow 1825 * as it lists several tx power levels -acme
1777 */ 1826 */
1778 wrqu->txpower.fixed = 0; 1827 wrqu->txpower.fixed = 0;
1779 wrqu->txpower.flags = IW_TXPO 1828 wrqu->txpower.flags = IW_TXPOW_MWATT;
1780 } 1829 }
1781 return rc; 1830 return rc;
1782 } 1831 }
1783 1832
1784 static int wl3501_get_retry(struct net_device 1833 static int wl3501_get_retry(struct net_device *dev,
1785 struct iw_request 1834 struct iw_request_info *info,
1786 union iwreq_data 1835 union iwreq_data *wrqu, char *extra)
1787 { 1836 {
1788 u8 retry; /* size checked: it is u8 * 1837 u8 retry; /* size checked: it is u8 */
1789 struct wl3501_card *this = netdev_pri !! 1838 struct wl3501_card *this = dev->priv;
1790 int rc = wl3501_get_mib_value(this, 1839 int rc = wl3501_get_mib_value(this,
1791 WL3501_ 1840 WL3501_MIB_ATTR_LONG_RETRY_LIMIT,
1792 &retry, 1841 &retry, sizeof(retry));
1793 if (rc) 1842 if (rc)
1794 goto out; 1843 goto out;
1795 if (wrqu->retry.flags & IW_RETRY_LONG !! 1844 if (wrqu->retry.flags & IW_RETRY_MAX) {
1796 wrqu->retry.flags = IW_RETRY_ !! 1845 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1797 goto set_value; 1846 goto set_value;
1798 } 1847 }
1799 rc = wl3501_get_mib_value(this, WL350 1848 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_SHORT_RETRY_LIMIT,
1800 &retry, siz 1849 &retry, sizeof(retry));
1801 if (rc) 1850 if (rc)
1802 goto out; 1851 goto out;
1803 wrqu->retry.flags = IW_RETRY_LIMIT | !! 1852 wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
1804 set_value: 1853 set_value:
1805 wrqu->retry.value = retry; 1854 wrqu->retry.value = retry;
1806 wrqu->retry.disabled = 0; 1855 wrqu->retry.disabled = 0;
1807 out: 1856 out:
1808 return rc; 1857 return rc;
1809 } 1858 }
1810 1859
1811 static int wl3501_get_encode(struct net_devic 1860 static int wl3501_get_encode(struct net_device *dev,
1812 struct iw_reques 1861 struct iw_request_info *info,
1813 union iwreq_data 1862 union iwreq_data *wrqu, char *extra)
1814 { 1863 {
1815 u8 implemented, restricted, keys[100] 1864 u8 implemented, restricted, keys[100], len_keys, tocopy;
1816 struct wl3501_card *this = netdev_pri !! 1865 struct wl3501_card *this = dev->priv;
1817 int rc = wl3501_get_mib_value(this, 1866 int rc = wl3501_get_mib_value(this,
1818 WL3501_ 1867 WL3501_MIB_ATTR_PRIV_OPT_IMPLEMENTED,
1819 &implem 1868 &implemented, sizeof(implemented));
1820 if (rc) 1869 if (rc)
1821 goto out; 1870 goto out;
1822 if (!implemented) { 1871 if (!implemented) {
1823 wrqu->encoding.flags = IW_ENC 1872 wrqu->encoding.flags = IW_ENCODE_DISABLED;
1824 goto out; 1873 goto out;
1825 } 1874 }
1826 rc = wl3501_get_mib_value(this, WL350 1875 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_EXCLUDE_UNENCRYPTED,
1827 &restricted 1876 &restricted, sizeof(restricted));
1828 if (rc) 1877 if (rc)
1829 goto out; 1878 goto out;
1830 wrqu->encoding.flags = restricted ? I 1879 wrqu->encoding.flags = restricted ? IW_ENCODE_RESTRICTED :
1831 I 1880 IW_ENCODE_OPEN;
1832 rc = wl3501_get_mib_value(this, WL350 1881 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS_LEN,
1833 &len_keys, 1882 &len_keys, sizeof(len_keys));
1834 if (rc) 1883 if (rc)
1835 goto out; 1884 goto out;
1836 rc = wl3501_get_mib_value(this, WL350 1885 rc = wl3501_get_mib_value(this, WL3501_MIB_ATTR_WEP_KEY_MAPPINGS,
1837 keys, len_k 1886 keys, len_keys);
1838 if (rc) 1887 if (rc)
1839 goto out; 1888 goto out;
1840 tocopy = min_t(u8, len_keys, wrqu->en 1889 tocopy = min_t(u8, len_keys, wrqu->encoding.length);
1841 tocopy = min_t(u8, tocopy, 100); 1890 tocopy = min_t(u8, tocopy, 100);
1842 wrqu->encoding.length = tocopy; 1891 wrqu->encoding.length = tocopy;
>> 1892 memset(extra, 0, tocopy);
1843 memcpy(extra, keys, tocopy); 1893 memcpy(extra, keys, tocopy);
1844 out: 1894 out:
1845 return rc; 1895 return rc;
1846 } 1896 }
1847 1897
1848 static int wl3501_get_power(struct net_device 1898 static int wl3501_get_power(struct net_device *dev,
1849 struct iw_request 1899 struct iw_request_info *info,
1850 union iwreq_data 1900 union iwreq_data *wrqu, char *extra)
1851 { 1901 {
1852 u8 pwr_state; 1902 u8 pwr_state;
1853 struct wl3501_card *this = netdev_pri !! 1903 struct wl3501_card *this = dev->priv;
1854 int rc = wl3501_get_mib_value(this, 1904 int rc = wl3501_get_mib_value(this,
1855 WL3501_ 1905 WL3501_MIB_ATTR_CURRENT_PWR_STATE,
1856 &pwr_st 1906 &pwr_state, sizeof(pwr_state));
1857 if (rc) 1907 if (rc)
1858 goto out; 1908 goto out;
1859 wrqu->power.disabled = !pwr_state; 1909 wrqu->power.disabled = !pwr_state;
1860 wrqu->power.flags = IW_POWER_ON; 1910 wrqu->power.flags = IW_POWER_ON;
1861 out: 1911 out:
1862 return rc; 1912 return rc;
1863 } 1913 }
1864 1914
1865 static const iw_handler wl3501_handler[] = { 1915 static const iw_handler wl3501_handler[] = {
1866 [SIOCGIWNAME - SIOCIWFIRST] = wl35 1916 [SIOCGIWNAME - SIOCIWFIRST] = wl3501_get_name,
1867 [SIOCSIWFREQ - SIOCIWFIRST] = wl35 1917 [SIOCSIWFREQ - SIOCIWFIRST] = wl3501_set_freq,
1868 [SIOCGIWFREQ - SIOCIWFIRST] = wl35 1918 [SIOCGIWFREQ - SIOCIWFIRST] = wl3501_get_freq,
1869 [SIOCSIWMODE - SIOCIWFIRST] = wl35 1919 [SIOCSIWMODE - SIOCIWFIRST] = wl3501_set_mode,
1870 [SIOCGIWMODE - SIOCIWFIRST] = wl35 1920 [SIOCGIWMODE - SIOCIWFIRST] = wl3501_get_mode,
1871 [SIOCGIWSENS - SIOCIWFIRST] = wl35 1921 [SIOCGIWSENS - SIOCIWFIRST] = wl3501_get_sens,
1872 [SIOCGIWRANGE - SIOCIWFIRST] = wl35 1922 [SIOCGIWRANGE - SIOCIWFIRST] = wl3501_get_range,
1873 [SIOCSIWSPY - SIOCIWFIRST] = iw_h 1923 [SIOCSIWSPY - SIOCIWFIRST] = iw_handler_set_spy,
1874 [SIOCGIWSPY - SIOCIWFIRST] = iw_h 1924 [SIOCGIWSPY - SIOCIWFIRST] = iw_handler_get_spy,
1875 [SIOCSIWTHRSPY - SIOCIWFIRST] = iw_h 1925 [SIOCSIWTHRSPY - SIOCIWFIRST] = iw_handler_set_thrspy,
1876 [SIOCGIWTHRSPY - SIOCIWFIRST] = iw_h 1926 [SIOCGIWTHRSPY - SIOCIWFIRST] = iw_handler_get_thrspy,
1877 [SIOCSIWAP - SIOCIWFIRST] = wl35 1927 [SIOCSIWAP - SIOCIWFIRST] = wl3501_set_wap,
1878 [SIOCGIWAP - SIOCIWFIRST] = wl35 1928 [SIOCGIWAP - SIOCIWFIRST] = wl3501_get_wap,
1879 [SIOCSIWSCAN - SIOCIWFIRST] = wl35 1929 [SIOCSIWSCAN - SIOCIWFIRST] = wl3501_set_scan,
1880 [SIOCGIWSCAN - SIOCIWFIRST] = wl35 1930 [SIOCGIWSCAN - SIOCIWFIRST] = wl3501_get_scan,
1881 [SIOCSIWESSID - SIOCIWFIRST] = wl35 1931 [SIOCSIWESSID - SIOCIWFIRST] = wl3501_set_essid,
1882 [SIOCGIWESSID - SIOCIWFIRST] = wl35 1932 [SIOCGIWESSID - SIOCIWFIRST] = wl3501_get_essid,
1883 [SIOCSIWNICKN - SIOCIWFIRST] = wl35 1933 [SIOCSIWNICKN - SIOCIWFIRST] = wl3501_set_nick,
1884 [SIOCGIWNICKN - SIOCIWFIRST] = wl35 1934 [SIOCGIWNICKN - SIOCIWFIRST] = wl3501_get_nick,
1885 [SIOCGIWRATE - SIOCIWFIRST] = wl35 1935 [SIOCGIWRATE - SIOCIWFIRST] = wl3501_get_rate,
1886 [SIOCGIWRTS - SIOCIWFIRST] = wl35 1936 [SIOCGIWRTS - SIOCIWFIRST] = wl3501_get_rts_threshold,
1887 [SIOCGIWFRAG - SIOCIWFIRST] = wl35 1937 [SIOCGIWFRAG - SIOCIWFIRST] = wl3501_get_frag_threshold,
1888 [SIOCGIWTXPOW - SIOCIWFIRST] = wl35 1938 [SIOCGIWTXPOW - SIOCIWFIRST] = wl3501_get_txpow,
1889 [SIOCGIWRETRY - SIOCIWFIRST] = wl35 1939 [SIOCGIWRETRY - SIOCIWFIRST] = wl3501_get_retry,
1890 [SIOCGIWENCODE - SIOCIWFIRST] = wl35 1940 [SIOCGIWENCODE - SIOCIWFIRST] = wl3501_get_encode,
1891 [SIOCGIWPOWER - SIOCIWFIRST] = wl35 1941 [SIOCGIWPOWER - SIOCIWFIRST] = wl3501_get_power,
1892 }; 1942 };
1893 1943
1894 static const struct iw_handler_def wl3501_han 1944 static const struct iw_handler_def wl3501_handler_def = {
1895 .num_standard = ARRAY_SIZE(wl3501_h !! 1945 .num_standard = sizeof(wl3501_handler) / sizeof(iw_handler),
1896 .standard = (iw_handler *)wl350 1946 .standard = (iw_handler *)wl3501_handler,
1897 .get_wireless_stats = wl3501_get_wire !! 1947 .spy_offset = offsetof(struct wl3501_card, spy_data),
1898 }; 1948 };
1899 1949
1900 /** 1950 /**
1901 * wl3501_attach - creates an "instance" of t 1951 * wl3501_attach - creates an "instance" of the driver
1902 * 1952 *
1903 * Creates an "instance" of the driver, alloc 1953 * Creates an "instance" of the driver, allocating local data structures for
1904 * one device. The device is registered with 1954 * one device. The device is registered with Card Services.
1905 * 1955 *
1906 * The dev_link structure is initialized, but 1956 * The dev_link structure is initialized, but we don't actually configure the
1907 * card at this point -- we wait until we rec 1957 * card at this point -- we wait until we receive a card insertion event.
1908 */ 1958 */
1909 static int wl3501_probe(struct pcmcia_device !! 1959 static dev_link_t *wl3501_attach(void)
1910 { 1960 {
>> 1961 client_reg_t client_reg;
>> 1962 dev_link_t *link;
1911 struct net_device *dev; 1963 struct net_device *dev;
1912 struct wl3501_card *this; !! 1964 int ret;
>> 1965
>> 1966 /* Initialize the dev_link_t structure */
>> 1967 link = kmalloc(sizeof(*link), GFP_KERNEL);
>> 1968 if (!link)
>> 1969 goto out;
>> 1970 memset(link, 0, sizeof(struct dev_link_t));
1913 1971
1914 /* The io structure describes IO port 1972 /* The io structure describes IO port mapping */
1915 p_dev->io.NumPorts1 = 16; !! 1973 link->io.NumPorts1 = 16;
1916 p_dev->io.Attributes1 = IO_DATA_PAT !! 1974 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1917 p_dev->io.IOAddrLines = 5; !! 1975 link->io.IOAddrLines = 5;
1918 1976
1919 /* Interrupt setup */ 1977 /* Interrupt setup */
1920 p_dev->irq.Attributes = IRQ_TYPE_EX !! 1978 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
1921 p_dev->irq.IRQInfo1 = IRQ_LEVEL_I !! 1979 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
1922 p_dev->irq.Handler = wl3501_interrupt !! 1980 link->irq.Handler = wl3501_interrupt;
1923 1981
1924 /* General socket configuration */ 1982 /* General socket configuration */
1925 p_dev->conf.Attributes = CONF_ENABLE !! 1983 link->conf.Attributes = CONF_ENABLE_IRQ;
1926 p_dev->conf.IntType = INT_MEMORY_ !! 1984 link->conf.Vcc = 50;
1927 p_dev->conf.ConfigIndex = 1; !! 1985 link->conf.IntType = INT_MEMORY_AND_IO;
>> 1986 link->conf.ConfigIndex = 1;
>> 1987 link->conf.Present = PRESENT_OPTION;
1928 1988
1929 dev = alloc_etherdev(sizeof(struct wl 1989 dev = alloc_etherdev(sizeof(struct wl3501_card));
1930 if (!dev) 1990 if (!dev)
1931 goto out_link; 1991 goto out_link;
1932 dev->open = wl3501_open 1992 dev->open = wl3501_open;
1933 dev->stop = wl3501_clos 1993 dev->stop = wl3501_close;
1934 dev->hard_start_xmit = wl3501_hard 1994 dev->hard_start_xmit = wl3501_hard_start_xmit;
1935 dev->tx_timeout = wl3501_tx_t 1995 dev->tx_timeout = wl3501_tx_timeout;
1936 dev->watchdog_timeo = 5 * HZ; 1996 dev->watchdog_timeo = 5 * HZ;
1937 dev->get_stats = wl3501_get_ 1997 dev->get_stats = wl3501_get_stats;
1938 this = netdev_priv(dev); !! 1998 dev->get_wireless_stats = wl3501_get_wireless_stats;
1939 this->wireless_data.spy_data = &this- <<
1940 this->p_dev = p_dev; <<
1941 dev->wireless_data = &this->wire <<
1942 dev->wireless_handlers = (struct iw_ 1999 dev->wireless_handlers = (struct iw_handler_def *)&wl3501_handler_def;
1943 SET_ETHTOOL_OPS(dev, &ops); 2000 SET_ETHTOOL_OPS(dev, &ops);
1944 netif_stop_queue(dev); 2001 netif_stop_queue(dev);
1945 p_dev->priv = p_dev->irq.Instance = d !! 2002 link->priv = link->irq.Instance = dev;
1946 2003
1947 return wl3501_config(p_dev); !! 2004 /* Register with Card Services */
>> 2005 link->next = wl3501_dev_list;
>> 2006 wl3501_dev_list = link;
>> 2007 client_reg.dev_info = &wl3501_dev_info;
>> 2008 client_reg.EventMask = CS_EVENT_CARD_INSERTION |
>> 2009 CS_EVENT_RESET_PHYSICAL |
>> 2010 CS_EVENT_CARD_RESET |
>> 2011 CS_EVENT_CARD_REMOVAL |
>> 2012 CS_EVENT_PM_SUSPEND |
>> 2013 CS_EVENT_PM_RESUME;
>> 2014 client_reg.event_handler = wl3501_event;
>> 2015 client_reg.Version = 0x0210;
>> 2016 client_reg.event_callback_args.client_data = link;
>> 2017 ret = pcmcia_register_client(&link->handle, &client_reg);
>> 2018 if (ret) {
>> 2019 cs_error(link->handle, RegisterClient, ret);
>> 2020 wl3501_detach(link);
>> 2021 link = NULL;
>> 2022 }
>> 2023 out:
>> 2024 return link;
1948 out_link: 2025 out_link:
1949 return -ENOMEM; !! 2026 kfree(link);
>> 2027 link = NULL;
>> 2028 goto out;
1950 } 2029 }
1951 2030
1952 #define CS_CHECK(fn, ret) \ 2031 #define CS_CHECK(fn, ret) \
1953 do { last_fn = (fn); if ((last_ret = (ret)) ! 2032 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1954 2033
1955 /** 2034 /**
1956 * wl3501_config - configure the PCMCIA socke 2035 * wl3501_config - configure the PCMCIA socket and make eth device available
1957 * @link - FILL_IN 2036 * @link - FILL_IN
1958 * 2037 *
1959 * wl3501_config() is scheduled to run after 2038 * wl3501_config() is scheduled to run after a CARD_INSERTION event is
1960 * received, to configure the PCMCIA socket, 2039 * received, to configure the PCMCIA socket, and to make the ethernet device
1961 * available to the system. 2040 * available to the system.
1962 */ 2041 */
1963 static int wl3501_config(struct pcmcia_device !! 2042 static void wl3501_config(dev_link_t *link)
1964 { 2043 {
>> 2044 tuple_t tuple;
>> 2045 cisparse_t parse;
>> 2046 client_handle_t handle = link->handle;
1965 struct net_device *dev = link->priv; 2047 struct net_device *dev = link->priv;
1966 int i = 0, j, last_fn, last_ret; 2048 int i = 0, j, last_fn, last_ret;
>> 2049 unsigned char bf[64];
1967 struct wl3501_card *this; 2050 struct wl3501_card *this;
1968 DECLARE_MAC_BUF(mac); !! 2051
>> 2052 /* This reads the card's CONFIG tuple to find its config registers. */
>> 2053 tuple.Attributes = 0;
>> 2054 tuple.DesiredTuple = CISTPL_CONFIG;
>> 2055 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
>> 2056 tuple.TupleData = bf;
>> 2057 tuple.TupleDataMax = sizeof(bf);
>> 2058 tuple.TupleOffset = 0;
>> 2059 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
>> 2060 CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
>> 2061 link->conf.ConfigBase = parse.config.base;
>> 2062 link->conf.Present = parse.config.rmask[0];
>> 2063
>> 2064 /* Configure card */
>> 2065 link->state |= DEV_CONFIG;
1969 2066
1970 /* Try allocating IO ports. This tri 2067 /* Try allocating IO ports. This tries a few fixed addresses. If you
1971 * want, you can also read the card's 2068 * want, you can also read the card's config table to pick addresses --
1972 * see the serial driver for an examp 2069 * see the serial driver for an example. */
1973 2070
1974 for (j = 0x280; j < 0x400; j += 0x20) 2071 for (j = 0x280; j < 0x400; j += 0x20) {
1975 /* The '^0x300' is so that we 2072 /* The '^0x300' is so that we probe 0x300-0x3ff first, then
1976 * 0x200-0x2ff, and so on, be 2073 * 0x200-0x2ff, and so on, because this seems safer */
1977 link->io.BasePort1 = j; 2074 link->io.BasePort1 = j;
1978 link->io.BasePort2 = link->io 2075 link->io.BasePort2 = link->io.BasePort1 + 0x10;
1979 i = pcmcia_request_io(link, & !! 2076 i = pcmcia_request_io(link->handle, &link->io);
1980 if (i == CS_SUCCESS) 2077 if (i == CS_SUCCESS)
1981 break; 2078 break;
1982 } 2079 }
1983 if (i != CS_SUCCESS) { 2080 if (i != CS_SUCCESS) {
1984 cs_error(link, RequestIO, i); !! 2081 cs_error(link->handle, RequestIO, i);
1985 goto failed; 2082 goto failed;
1986 } 2083 }
1987 2084
1988 /* Now allocate an interrupt line. No 2085 /* Now allocate an interrupt line. Note that this does not actually
1989 * assign a handler to the interrupt. 2086 * assign a handler to the interrupt. */
1990 2087
1991 CS_CHECK(RequestIRQ, pcmcia_request_i !! 2088 CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
1992 2089
1993 /* This actually configures the PCMCI 2090 /* This actually configures the PCMCIA socket -- setting up the I/O
1994 * windows and the interrupt mapping. 2091 * windows and the interrupt mapping. */
1995 2092
1996 CS_CHECK(RequestConfiguration, pcmcia !! 2093 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
1997 2094
1998 dev->irq = link->irq.AssignedIRQ; 2095 dev->irq = link->irq.AssignedIRQ;
1999 dev->base_addr = link->io.BasePort1; 2096 dev->base_addr = link->io.BasePort1;
2000 SET_NETDEV_DEV(dev, &handle_to_dev(li !! 2097 SET_NETDEV_DEV(dev, &handle_to_dev(handle));
2001 if (register_netdev(dev)) { 2098 if (register_netdev(dev)) {
2002 printk(KERN_NOTICE "wl3501_cs 2099 printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
2003 goto failed; 2100 goto failed;
2004 } 2101 }
2005 2102
2006 this = netdev_priv(dev); !! 2103 SET_MODULE_OWNER(dev);
>> 2104
>> 2105 this = dev->priv;
2007 /* 2106 /*
2008 * At this point, the dev_node_t stru 2107 * At this point, the dev_node_t structure(s) should be initialized and
2009 * arranged in a linked list at link- !! 2108 * arranged in a linked list at link->dev.
2010 */ 2109 */
2011 link->dev_node = &this->node; !! 2110 link->dev = &this->node;
>> 2111 link->state &= ~DEV_CONFIG_PENDING;
2012 2112
2013 this->base_addr = dev->base_addr; 2113 this->base_addr = dev->base_addr;
2014 2114
2015 if (!wl3501_get_flash_mac_addr(this)) 2115 if (!wl3501_get_flash_mac_addr(this)) {
2016 printk(KERN_WARNING "%s: Cant 2116 printk(KERN_WARNING "%s: Cant read MAC addr in flash ROM?\n",
2017 dev->name); 2117 dev->name);
2018 goto failed; 2118 goto failed;
2019 } 2119 }
2020 strcpy(this->node.dev_name, dev->name 2120 strcpy(this->node.dev_name, dev->name);
2021 2121
2022 for (i = 0; i < 6; i++) <<
2023 dev->dev_addr[i] = ((char *)& <<
2024 <<
2025 /* print probe information */ 2122 /* print probe information */
2026 printk(KERN_INFO "%s: wl3501 @ 0x%3.3 !! 2123 printk(KERN_INFO "%s: wl3501 @ 0x%3.3x, IRQ %d, MAC addr in flash ROM:",
2027 "MAC addr in flash ROM:%s\n", !! 2124 dev->name, this->base_addr, (int)dev->irq);
2028 dev->name, this->base_addr, (i !! 2125 for (i = 0; i < 6; i++) {
2029 print_mac(mac, dev->dev_addr)) !! 2126 dev->dev_addr[i] = ((char *)&this->mac_addr)[i];
>> 2127 printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
>> 2128 }
>> 2129 printk("\n");
2030 /* 2130 /*
2031 * Initialize card parameters - added 2131 * Initialize card parameters - added by jss
2032 */ 2132 */
2033 this->net_type = IW_MODE_INF 2133 this->net_type = IW_MODE_INFRA;
2034 this->bss_cnt = 0; 2134 this->bss_cnt = 0;
2035 this->join_sta_bss = 0; 2135 this->join_sta_bss = 0;
2036 this->adhoc_times = 0; 2136 this->adhoc_times = 0;
2037 iw_set_mgmt_info_element(IW_MGMT_INFO 2137 iw_set_mgmt_info_element(IW_MGMT_INFO_ELEMENT_SSID, &this->essid.el,
2038 "ANY", 3); 2138 "ANY", 3);
2039 this->card_name[0] = '\0'; 2139 this->card_name[0] = '\0';
2040 this->firmware_date[0] = '\0'; 2140 this->firmware_date[0] = '\0';
2041 this->rssi = 255; 2141 this->rssi = 255;
2042 this->chan = iw_default_ 2142 this->chan = iw_default_channel(this->reg_domain);
2043 strlcpy(this->nick, "Planet WL3501", 2143 strlcpy(this->nick, "Planet WL3501", sizeof(this->nick));
2044 spin_lock_init(&this->lock); 2144 spin_lock_init(&this->lock);
2045 init_waitqueue_head(&this->wait); 2145 init_waitqueue_head(&this->wait);
2046 netif_start_queue(dev); 2146 netif_start_queue(dev);
2047 return 0; !! 2147 goto out;
2048 <<
2049 cs_failed: 2148 cs_failed:
2050 cs_error(link, last_fn, last_ret); !! 2149 cs_error(link->handle, last_fn, last_ret);
2051 failed: 2150 failed:
2052 wl3501_release(link); 2151 wl3501_release(link);
2053 return -ENODEV; !! 2152 out:
>> 2153 return;
2054 } 2154 }
2055 2155
2056 /** 2156 /**
2057 * wl3501_release - unregister the net, relea 2157 * wl3501_release - unregister the net, release PCMCIA configuration
2058 * @arg - link 2158 * @arg - link
2059 * 2159 *
2060 * After a card is removed, wl3501_release() 2160 * After a card is removed, wl3501_release() will unregister the net device,
2061 * and release the PCMCIA configuration. If 2161 * and release the PCMCIA configuration. If the device is still open, this
2062 * will be postponed until it is closed. 2162 * will be postponed until it is closed.
2063 */ 2163 */
2064 static void wl3501_release(struct pcmcia_devi !! 2164 static void wl3501_release(dev_link_t *link)
2065 { 2165 {
2066 struct net_device *dev = link->priv; 2166 struct net_device *dev = link->priv;
2067 2167
2068 /* Unlink the device chain */ 2168 /* Unlink the device chain */
2069 if (link->dev_node) !! 2169 if (link->dev) {
2070 unregister_netdev(dev); 2170 unregister_netdev(dev);
>> 2171 link->dev = NULL;
>> 2172 }
2071 2173
2072 pcmcia_disable_device(link); !! 2174 /* Don't bother checking to see if these succeed or not */
>> 2175 pcmcia_release_configuration(link->handle);
>> 2176 pcmcia_release_io(link->handle, &link->io);
>> 2177 pcmcia_release_irq(link->handle, &link->irq);
>> 2178 link->state &= ~DEV_CONFIG;
2073 } 2179 }
2074 2180
2075 static int wl3501_suspend(struct pcmcia_devic !! 2181 /**
2076 { !! 2182 * wl3501_event - The card status event handler
2077 struct net_device *dev = link->priv; !! 2183 * @event - event
2078 !! 2184 * @pri - priority
2079 wl3501_pwr_mgmt(netdev_priv(dev), WL3 !! 2185 * @args - arguments for this event
2080 if (link->open) !! 2186 *
2081 netif_device_detach(dev); !! 2187 * The card status event handler. Mostly, this schedules other stuff to run
2082 !! 2188 * after an event is received. A CARD_REMOVAL event also sets some flags to
2083 return 0; !! 2189 * discourage the net drivers from trying to talk to the card any more.
2084 } !! 2190 *
2085 !! 2191 * When a CARD_REMOVAL event is received, we immediately set a flag to block
2086 static int wl3501_resume(struct pcmcia_device !! 2192 * future accesses to this device. All the functions that actually access the
>> 2193 * device should check this flag to make sure the card is still present.
>> 2194 */
>> 2195 static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
2087 { 2196 {
>> 2197 dev_link_t *link = args->client_data;
2088 struct net_device *dev = link->priv; 2198 struct net_device *dev = link->priv;
2089 2199
2090 wl3501_pwr_mgmt(netdev_priv(dev), WL3 !! 2200 switch (event) {
2091 if (link->open) { !! 2201 case CS_EVENT_CARD_REMOVAL:
2092 wl3501_reset(dev); !! 2202 link->state &= ~DEV_PRESENT;
2093 netif_device_attach(dev); !! 2203 if (link->state & DEV_CONFIG) {
>> 2204 while (link->open > 0)
>> 2205 wl3501_close(dev);
>> 2206 netif_device_detach(dev);
>> 2207 wl3501_release(link);
>> 2208 }
>> 2209 break;
>> 2210 case CS_EVENT_CARD_INSERTION:
>> 2211 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
>> 2212 wl3501_config(link);
>> 2213 break;
>> 2214 case CS_EVENT_PM_SUSPEND:
>> 2215 link->state |= DEV_SUSPEND;
>> 2216 wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
>> 2217 /* Fall through... */
>> 2218 case CS_EVENT_RESET_PHYSICAL:
>> 2219 if (link->state & DEV_CONFIG) {
>> 2220 if (link->open)
>> 2221 netif_device_detach(dev);
>> 2222 pcmcia_release_configuration(link->handle);
>> 2223 }
>> 2224 break;
>> 2225 case CS_EVENT_PM_RESUME:
>> 2226 link->state &= ~DEV_SUSPEND;
>> 2227 wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
>> 2228 /* Fall through... */
>> 2229 case CS_EVENT_CARD_RESET:
>> 2230 if (link->state & DEV_CONFIG) {
>> 2231 pcmcia_request_configuration(link->handle, &link->conf);
>> 2232 if (link->open) {
>> 2233 wl3501_reset(dev);
>> 2234 netif_device_attach(dev);
>> 2235 }
>> 2236 }
>> 2237 break;
2094 } 2238 }
2095 <<
2096 return 0; 2239 return 0;
2097 } 2240 }
2098 2241
2099 <<
2100 static struct pcmcia_device_id wl3501_ids[] = <<
2101 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x000 <<
2102 PCMCIA_DEVICE_NULL <<
2103 }; <<
2104 MODULE_DEVICE_TABLE(pcmcia, wl3501_ids); <<
2105 <<
2106 static struct pcmcia_driver wl3501_driver = { 2242 static struct pcmcia_driver wl3501_driver = {
2107 .owner = THIS_MODULE, !! 2243 .owner = THIS_MODULE,
2108 .drv = { !! 2244 .drv = {
2109 .name = "wl3501_cs", !! 2245 .name = "wl3501_cs",
2110 }, 2246 },
2111 .probe = wl3501_probe, !! 2247 .attach = wl3501_attach,
2112 .remove = wl3501_detach, !! 2248 .detach = wl3501_detach,
2113 .id_table = wl3501_ids, <<
2114 .suspend = wl3501_suspend, <<
2115 .resume = wl3501_resume, <<
2116 }; 2249 };
2117 2250
2118 static int __init wl3501_init_module(void) 2251 static int __init wl3501_init_module(void)
2119 { 2252 {
2120 return pcmcia_register_driver(&wl3501 2253 return pcmcia_register_driver(&wl3501_driver);
2121 } 2254 }
2122 2255
2123 static void __exit wl3501_exit_module(void) 2256 static void __exit wl3501_exit_module(void)
2124 { 2257 {
>> 2258 dprintk(0, ": unloading");
2125 pcmcia_unregister_driver(&wl3501_driv 2259 pcmcia_unregister_driver(&wl3501_driver);
>> 2260 BUG_ON(wl3501_dev_list != NULL);
2126 } 2261 }
2127 2262
2128 module_init(wl3501_init_module); 2263 module_init(wl3501_init_module);
2129 module_exit(wl3501_exit_module); 2264 module_exit(wl3501_exit_module);
2130 2265
2131 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri 2266 MODULE_AUTHOR("Fox Chen <mhchen@golf.ccl.itri.org.tw>, "
2132 "Arnaldo Carvalho de Melo <acme 2267 "Arnaldo Carvalho de Melo <acme@conectiva.com.br>,"
2133 "Gustavo Niemeyer <niemeyer@con 2268 "Gustavo Niemeyer <niemeyer@conectiva.com>");
2134 MODULE_DESCRIPTION("Planet wl3501 wireless dr 2269 MODULE_DESCRIPTION("Planet wl3501 wireless driver");
2135 MODULE_LICENSE("GPL"); 2270 MODULE_LICENSE("GPL");
2136 2271
|
This page was automatically generated by the
LXR engine.
|