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