Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/net/wireless/wl3501_cs.c (Version 2.6.25.8) and /linux/drivers/net/wireless/wl3501_cs.c (Version 2.6.31.13)


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