rt2x00: Introduce 3 queue commands in drivers (start, kick, stop).
[linux-2.6.git] / drivers / net / wireless / rt2x00 / rt2500usb.c
1 /*
2         Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
3         <http://rt2x00.serialmonkey.com>
4
5         This program is free software; you can redistribute it and/or modify
6         it under the terms of the GNU General Public License as published by
7         the Free Software Foundation; either version 2 of the License, or
8         (at your option) any later version.
9
10         This program is distributed in the hope that it will be useful,
11         but WITHOUT ANY WARRANTY; without even the implied warranty of
12         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13         GNU General Public License for more details.
14
15         You should have received a copy of the GNU General Public License
16         along with this program; if not, write to the
17         Free Software Foundation, Inc.,
18         59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 /*
22         Module: rt2500usb
23         Abstract: rt2500usb device specific routines.
24         Supported chipsets: RT2570.
25  */
26
27 #include <linux/delay.h>
28 #include <linux/etherdevice.h>
29 #include <linux/init.h>
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/usb.h>
34
35 #include "rt2x00.h"
36 #include "rt2x00usb.h"
37 #include "rt2500usb.h"
38
39 /*
40  * Allow hardware encryption to be disabled.
41  */
42 static int modparam_nohwcrypt;
43 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
44 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
45
46 /*
47  * Register access.
48  * All access to the CSR registers will go through the methods
49  * rt2500usb_register_read and rt2500usb_register_write.
50  * BBP and RF register require indirect register access,
51  * and use the CSR registers BBPCSR and RFCSR to achieve this.
52  * These indirect registers work with busy bits,
53  * and we will try maximal REGISTER_BUSY_COUNT times to access
54  * the register while taking a REGISTER_BUSY_DELAY us delay
55  * between each attampt. When the busy bit is still set at that time,
56  * the access attempt is considered to have failed,
57  * and we will print an error.
58  * If the csr_mutex is already held then the _lock variants must
59  * be used instead.
60  */
61 static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
62                                            const unsigned int offset,
63                                            u16 *value)
64 {
65         __le16 reg;
66         rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
67                                       USB_VENDOR_REQUEST_IN, offset,
68                                       &reg, sizeof(reg), REGISTER_TIMEOUT);
69         *value = le16_to_cpu(reg);
70 }
71
72 static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
73                                                 const unsigned int offset,
74                                                 u16 *value)
75 {
76         __le16 reg;
77         rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
78                                        USB_VENDOR_REQUEST_IN, offset,
79                                        &reg, sizeof(reg), REGISTER_TIMEOUT);
80         *value = le16_to_cpu(reg);
81 }
82
83 static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
84                                                 const unsigned int offset,
85                                                 void *value, const u16 length)
86 {
87         rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
88                                       USB_VENDOR_REQUEST_IN, offset,
89                                       value, length,
90                                       REGISTER_TIMEOUT16(length));
91 }
92
93 static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
94                                             const unsigned int offset,
95                                             u16 value)
96 {
97         __le16 reg = cpu_to_le16(value);
98         rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
99                                       USB_VENDOR_REQUEST_OUT, offset,
100                                       &reg, sizeof(reg), REGISTER_TIMEOUT);
101 }
102
103 static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
104                                                  const unsigned int offset,
105                                                  u16 value)
106 {
107         __le16 reg = cpu_to_le16(value);
108         rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
109                                        USB_VENDOR_REQUEST_OUT, offset,
110                                        &reg, sizeof(reg), REGISTER_TIMEOUT);
111 }
112
113 static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
114                                                  const unsigned int offset,
115                                                  void *value, const u16 length)
116 {
117         rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
118                                       USB_VENDOR_REQUEST_OUT, offset,
119                                       value, length,
120                                       REGISTER_TIMEOUT16(length));
121 }
122
123 static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
124                                   const unsigned int offset,
125                                   struct rt2x00_field16 field,
126                                   u16 *reg)
127 {
128         unsigned int i;
129
130         for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
131                 rt2500usb_register_read_lock(rt2x00dev, offset, reg);
132                 if (!rt2x00_get_field16(*reg, field))
133                         return 1;
134                 udelay(REGISTER_BUSY_DELAY);
135         }
136
137         ERROR(rt2x00dev, "Indirect register access failed: "
138               "offset=0x%.08x, value=0x%.08x\n", offset, *reg);
139         *reg = ~0;
140
141         return 0;
142 }
143
144 #define WAIT_FOR_BBP(__dev, __reg) \
145         rt2500usb_regbusy_read((__dev), PHY_CSR8, PHY_CSR8_BUSY, (__reg))
146 #define WAIT_FOR_RF(__dev, __reg) \
147         rt2500usb_regbusy_read((__dev), PHY_CSR10, PHY_CSR10_RF_BUSY, (__reg))
148
149 static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
150                                 const unsigned int word, const u8 value)
151 {
152         u16 reg;
153
154         mutex_lock(&rt2x00dev->csr_mutex);
155
156         /*
157          * Wait until the BBP becomes available, afterwards we
158          * can safely write the new data into the register.
159          */
160         if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
161                 reg = 0;
162                 rt2x00_set_field16(&reg, PHY_CSR7_DATA, value);
163                 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
164                 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 0);
165
166                 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
167         }
168
169         mutex_unlock(&rt2x00dev->csr_mutex);
170 }
171
172 static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
173                                const unsigned int word, u8 *value)
174 {
175         u16 reg;
176
177         mutex_lock(&rt2x00dev->csr_mutex);
178
179         /*
180          * Wait until the BBP becomes available, afterwards we
181          * can safely write the read request into the register.
182          * After the data has been written, we wait until hardware
183          * returns the correct value, if at any time the register
184          * doesn't become available in time, reg will be 0xffffffff
185          * which means we return 0xff to the caller.
186          */
187         if (WAIT_FOR_BBP(rt2x00dev, &reg)) {
188                 reg = 0;
189                 rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
190                 rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 1);
191
192                 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
193
194                 if (WAIT_FOR_BBP(rt2x00dev, &reg))
195                         rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, &reg);
196         }
197
198         *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
199
200         mutex_unlock(&rt2x00dev->csr_mutex);
201 }
202
203 static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
204                                const unsigned int word, const u32 value)
205 {
206         u16 reg;
207
208         mutex_lock(&rt2x00dev->csr_mutex);
209
210         /*
211          * Wait until the RF becomes available, afterwards we
212          * can safely write the new data into the register.
213          */
214         if (WAIT_FOR_RF(rt2x00dev, &reg)) {
215                 reg = 0;
216                 rt2x00_set_field16(&reg, PHY_CSR9_RF_VALUE, value);
217                 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
218
219                 reg = 0;
220                 rt2x00_set_field16(&reg, PHY_CSR10_RF_VALUE, value >> 16);
221                 rt2x00_set_field16(&reg, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
222                 rt2x00_set_field16(&reg, PHY_CSR10_RF_IF_SELECT, 0);
223                 rt2x00_set_field16(&reg, PHY_CSR10_RF_BUSY, 1);
224
225                 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
226                 rt2x00_rf_write(rt2x00dev, word, value);
227         }
228
229         mutex_unlock(&rt2x00dev->csr_mutex);
230 }
231
232 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
233 static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
234                                      const unsigned int offset,
235                                      u32 *value)
236 {
237         rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
238 }
239
240 static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
241                                       const unsigned int offset,
242                                       u32 value)
243 {
244         rt2500usb_register_write(rt2x00dev, offset, value);
245 }
246
247 static const struct rt2x00debug rt2500usb_rt2x00debug = {
248         .owner  = THIS_MODULE,
249         .csr    = {
250                 .read           = _rt2500usb_register_read,
251                 .write          = _rt2500usb_register_write,
252                 .flags          = RT2X00DEBUGFS_OFFSET,
253                 .word_base      = CSR_REG_BASE,
254                 .word_size      = sizeof(u16),
255                 .word_count     = CSR_REG_SIZE / sizeof(u16),
256         },
257         .eeprom = {
258                 .read           = rt2x00_eeprom_read,
259                 .write          = rt2x00_eeprom_write,
260                 .word_base      = EEPROM_BASE,
261                 .word_size      = sizeof(u16),
262                 .word_count     = EEPROM_SIZE / sizeof(u16),
263         },
264         .bbp    = {
265                 .read           = rt2500usb_bbp_read,
266                 .write          = rt2500usb_bbp_write,
267                 .word_base      = BBP_BASE,
268                 .word_size      = sizeof(u8),
269                 .word_count     = BBP_SIZE / sizeof(u8),
270         },
271         .rf     = {
272                 .read           = rt2x00_rf_read,
273                 .write          = rt2500usb_rf_write,
274                 .word_base      = RF_BASE,
275                 .word_size      = sizeof(u32),
276                 .word_count     = RF_SIZE / sizeof(u32),
277         },
278 };
279 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
280
281 static int rt2500usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
282 {
283         u16 reg;
284
285         rt2500usb_register_read(rt2x00dev, MAC_CSR19, &reg);
286         return rt2x00_get_field32(reg, MAC_CSR19_BIT7);
287 }
288
289 #ifdef CONFIG_RT2X00_LIB_LEDS
290 static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
291                                      enum led_brightness brightness)
292 {
293         struct rt2x00_led *led =
294             container_of(led_cdev, struct rt2x00_led, led_dev);
295         unsigned int enabled = brightness != LED_OFF;
296         u16 reg;
297
298         rt2500usb_register_read(led->rt2x00dev, MAC_CSR20, &reg);
299
300         if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC)
301                 rt2x00_set_field16(&reg, MAC_CSR20_LINK, enabled);
302         else if (led->type == LED_TYPE_ACTIVITY)
303                 rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, enabled);
304
305         rt2500usb_register_write(led->rt2x00dev, MAC_CSR20, reg);
306 }
307
308 static int rt2500usb_blink_set(struct led_classdev *led_cdev,
309                                unsigned long *delay_on,
310                                unsigned long *delay_off)
311 {
312         struct rt2x00_led *led =
313             container_of(led_cdev, struct rt2x00_led, led_dev);
314         u16 reg;
315
316         rt2500usb_register_read(led->rt2x00dev, MAC_CSR21, &reg);
317         rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, *delay_on);
318         rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, *delay_off);
319         rt2500usb_register_write(led->rt2x00dev, MAC_CSR21, reg);
320
321         return 0;
322 }
323
324 static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
325                                struct rt2x00_led *led,
326                                enum led_type type)
327 {
328         led->rt2x00dev = rt2x00dev;
329         led->type = type;
330         led->led_dev.brightness_set = rt2500usb_brightness_set;
331         led->led_dev.blink_set = rt2500usb_blink_set;
332         led->flags = LED_INITIALIZED;
333 }
334 #endif /* CONFIG_RT2X00_LIB_LEDS */
335
336 /*
337  * Configuration handlers.
338  */
339
340 /*
341  * rt2500usb does not differentiate between shared and pairwise
342  * keys, so we should use the same function for both key types.
343  */
344 static int rt2500usb_config_key(struct rt2x00_dev *rt2x00dev,
345                                 struct rt2x00lib_crypto *crypto,
346                                 struct ieee80211_key_conf *key)
347 {
348         u32 mask;
349         u16 reg;
350         enum cipher curr_cipher;
351
352         if (crypto->cmd == SET_KEY) {
353                 /*
354                  * Disallow to set WEP key other than with index 0,
355                  * it is known that not work at least on some hardware.
356                  * SW crypto will be used in that case.
357                  */
358                 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
359                      key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
360                     key->keyidx != 0)
361                         return -EOPNOTSUPP;
362
363                 /*
364                  * Pairwise key will always be entry 0, but this
365                  * could collide with a shared key on the same
366                  * position...
367                  */
368                 mask = TXRX_CSR0_KEY_ID.bit_mask;
369
370                 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
371                 curr_cipher = rt2x00_get_field16(reg, TXRX_CSR0_ALGORITHM);
372                 reg &= mask;
373
374                 if (reg && reg == mask)
375                         return -ENOSPC;
376
377                 reg = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
378
379                 key->hw_key_idx += reg ? ffz(reg) : 0;
380                 /*
381                  * Hardware requires that all keys use the same cipher
382                  * (e.g. TKIP-only, AES-only, but not TKIP+AES).
383                  * If this is not the first key, compare the cipher with the
384                  * first one and fall back to SW crypto if not the same.
385                  */
386                 if (key->hw_key_idx > 0 && crypto->cipher != curr_cipher)
387                         return -EOPNOTSUPP;
388
389                 rt2500usb_register_multiwrite(rt2x00dev, KEY_ENTRY(key->hw_key_idx),
390                                               crypto->key, sizeof(crypto->key));
391
392                 /*
393                  * The driver does not support the IV/EIV generation
394                  * in hardware. However it demands the data to be provided
395                  * both separately as well as inside the frame.
396                  * We already provided the CONFIG_CRYPTO_COPY_IV to rt2x00lib
397                  * to ensure rt2x00lib will not strip the data from the
398                  * frame after the copy, now we must tell mac80211
399                  * to generate the IV/EIV data.
400                  */
401                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
402                 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
403         }
404
405         /*
406          * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
407          * a particular key is valid.
408          */
409         rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
410         rt2x00_set_field16(&reg, TXRX_CSR0_ALGORITHM, crypto->cipher);
411         rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
412
413         mask = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
414         if (crypto->cmd == SET_KEY)
415                 mask |= 1 << key->hw_key_idx;
416         else if (crypto->cmd == DISABLE_KEY)
417                 mask &= ~(1 << key->hw_key_idx);
418         rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, mask);
419         rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
420
421         return 0;
422 }
423
424 static void rt2500usb_config_filter(struct rt2x00_dev *rt2x00dev,
425                                     const unsigned int filter_flags)
426 {
427         u16 reg;
428
429         /*
430          * Start configuration steps.
431          * Note that the version error will always be dropped
432          * and broadcast frames will always be accepted since
433          * there is no filter for it at this time.
434          */
435         rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
436         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
437                            !(filter_flags & FIF_FCSFAIL));
438         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
439                            !(filter_flags & FIF_PLCPFAIL));
440         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
441                            !(filter_flags & FIF_CONTROL));
442         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
443                            !(filter_flags & FIF_PROMISC_IN_BSS));
444         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
445                            !(filter_flags & FIF_PROMISC_IN_BSS) &&
446                            !rt2x00dev->intf_ap_count);
447         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
448         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
449                            !(filter_flags & FIF_ALLMULTI));
450         rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
451         rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
452 }
453
454 static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
455                                   struct rt2x00_intf *intf,
456                                   struct rt2x00intf_conf *conf,
457                                   const unsigned int flags)
458 {
459         unsigned int bcn_preload;
460         u16 reg;
461
462         if (flags & CONFIG_UPDATE_TYPE) {
463                 /*
464                  * Enable beacon config
465                  */
466                 bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20);
467                 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
468                 rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET, bcn_preload >> 6);
469                 rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW,
470                                    2 * (conf->type != NL80211_IFTYPE_STATION));
471                 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
472
473                 /*
474                  * Enable synchronisation.
475                  */
476                 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
477                 rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
478                 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
479
480                 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
481                 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
482                 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, conf->sync);
483                 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
484                 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
485         }
486
487         if (flags & CONFIG_UPDATE_MAC)
488                 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
489                                               (3 * sizeof(__le16)));
490
491         if (flags & CONFIG_UPDATE_BSSID)
492                 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
493                                               (3 * sizeof(__le16)));
494 }
495
496 static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
497                                  struct rt2x00lib_erp *erp,
498                                  u32 changed)
499 {
500         u16 reg;
501
502         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
503                 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
504                 rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
505                                    !!erp->short_preamble);
506                 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
507         }
508
509         if (changed & BSS_CHANGED_BASIC_RATES)
510                 rt2500usb_register_write(rt2x00dev, TXRX_CSR11,
511                                          erp->basic_rates);
512
513         if (changed & BSS_CHANGED_BEACON_INT) {
514                 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
515                 rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
516                                    erp->beacon_int * 4);
517                 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
518         }
519
520         if (changed & BSS_CHANGED_ERP_SLOT) {
521                 rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
522                 rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
523                 rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
524         }
525 }
526
527 static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
528                                  struct antenna_setup *ant)
529 {
530         u8 r2;
531         u8 r14;
532         u16 csr5;
533         u16 csr6;
534
535         /*
536          * We should never come here because rt2x00lib is supposed
537          * to catch this and send us the correct antenna explicitely.
538          */
539         BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
540                ant->tx == ANTENNA_SW_DIVERSITY);
541
542         rt2500usb_bbp_read(rt2x00dev, 2, &r2);
543         rt2500usb_bbp_read(rt2x00dev, 14, &r14);
544         rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
545         rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
546
547         /*
548          * Configure the TX antenna.
549          */
550         switch (ant->tx) {
551         case ANTENNA_HW_DIVERSITY:
552                 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
553                 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
554                 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
555                 break;
556         case ANTENNA_A:
557                 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
558                 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
559                 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
560                 break;
561         case ANTENNA_B:
562         default:
563                 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
564                 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
565                 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
566                 break;
567         }
568
569         /*
570          * Configure the RX antenna.
571          */
572         switch (ant->rx) {
573         case ANTENNA_HW_DIVERSITY:
574                 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
575                 break;
576         case ANTENNA_A:
577                 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
578                 break;
579         case ANTENNA_B:
580         default:
581                 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
582                 break;
583         }
584
585         /*
586          * RT2525E and RT5222 need to flip TX I/Q
587          */
588         if (rt2x00_rf(rt2x00dev, RF2525E) || rt2x00_rf(rt2x00dev, RF5222)) {
589                 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
590                 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
591                 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
592
593                 /*
594                  * RT2525E does not need RX I/Q Flip.
595                  */
596                 if (rt2x00_rf(rt2x00dev, RF2525E))
597                         rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
598         } else {
599                 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
600                 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
601         }
602
603         rt2500usb_bbp_write(rt2x00dev, 2, r2);
604         rt2500usb_bbp_write(rt2x00dev, 14, r14);
605         rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
606         rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
607 }
608
609 static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
610                                      struct rf_channel *rf, const int txpower)
611 {
612         /*
613          * Set TXpower.
614          */
615         rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
616
617         /*
618          * For RT2525E we should first set the channel to half band higher.
619          */
620         if (rt2x00_rf(rt2x00dev, RF2525E)) {
621                 static const u32 vals[] = {
622                         0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
623                         0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
624                         0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
625                         0x00000902, 0x00000906
626                 };
627
628                 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
629                 if (rf->rf4)
630                         rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
631         }
632
633         rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
634         rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
635         rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
636         if (rf->rf4)
637                 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
638 }
639
640 static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
641                                      const int txpower)
642 {
643         u32 rf3;
644
645         rt2x00_rf_read(rt2x00dev, 3, &rf3);
646         rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
647         rt2500usb_rf_write(rt2x00dev, 3, rf3);
648 }
649
650 static void rt2500usb_config_ps(struct rt2x00_dev *rt2x00dev,
651                                 struct rt2x00lib_conf *libconf)
652 {
653         enum dev_state state =
654             (libconf->conf->flags & IEEE80211_CONF_PS) ?
655                 STATE_SLEEP : STATE_AWAKE;
656         u16 reg;
657
658         if (state == STATE_SLEEP) {
659                 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
660                 rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON,
661                                    rt2x00dev->beacon_int - 20);
662                 rt2x00_set_field16(&reg, MAC_CSR18_BEACONS_BEFORE_WAKEUP,
663                                    libconf->conf->listen_interval - 1);
664
665                 /* We must first disable autowake before it can be enabled */
666                 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 0);
667                 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
668
669                 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 1);
670                 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
671         } else {
672                 rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
673                 rt2x00_set_field16(&reg, MAC_CSR18_AUTO_WAKE, 0);
674                 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
675         }
676
677         rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
678 }
679
680 static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
681                              struct rt2x00lib_conf *libconf,
682                              const unsigned int flags)
683 {
684         if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
685                 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
686                                          libconf->conf->power_level);
687         if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
688             !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
689                 rt2500usb_config_txpower(rt2x00dev,
690                                          libconf->conf->power_level);
691         if (flags & IEEE80211_CONF_CHANGE_PS)
692                 rt2500usb_config_ps(rt2x00dev, libconf);
693 }
694
695 /*
696  * Link tuning
697  */
698 static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
699                                  struct link_qual *qual)
700 {
701         u16 reg;
702
703         /*
704          * Update FCS error count from register.
705          */
706         rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
707         qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
708
709         /*
710          * Update False CCA count from register.
711          */
712         rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
713         qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
714 }
715
716 static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
717                                   struct link_qual *qual)
718 {
719         u16 eeprom;
720         u16 value;
721
722         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
723         value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
724         rt2500usb_bbp_write(rt2x00dev, 24, value);
725
726         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
727         value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
728         rt2500usb_bbp_write(rt2x00dev, 25, value);
729
730         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
731         value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
732         rt2500usb_bbp_write(rt2x00dev, 61, value);
733
734         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
735         value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
736         rt2500usb_bbp_write(rt2x00dev, 17, value);
737
738         qual->vgc_level = value;
739 }
740
741 /*
742  * Queue handlers.
743  */
744 static void rt2500usb_start_queue(struct data_queue *queue)
745 {
746         struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
747         u16 reg;
748
749         switch (queue->qid) {
750         case QID_RX:
751                 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
752                 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 0);
753                 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
754                 break;
755         case QID_BEACON:
756                 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
757                 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
758                 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
759                 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
760                 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
761                 break;
762         default:
763                 break;
764         }
765 }
766
767 static void rt2500usb_stop_queue(struct data_queue *queue)
768 {
769         struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
770         u16 reg;
771
772         switch (queue->qid) {
773         case QID_RX:
774                 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
775                 rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
776                 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
777                 break;
778         case QID_BEACON:
779                 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
780                 rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
781                 rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
782                 rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
783                 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
784                 break;
785         default:
786                 break;
787         }
788
789         rt2x00usb_stop_queue(queue);
790 }
791
792 /*
793  * Initialization functions.
794  */
795 static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
796 {
797         u16 reg;
798
799         rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
800                                     USB_MODE_TEST, REGISTER_TIMEOUT);
801         rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
802                                     0x00f0, REGISTER_TIMEOUT);
803
804         rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
805         rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
806         rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
807
808         rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
809         rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
810
811         rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
812         rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
813         rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
814         rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
815         rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
816
817         rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
818         rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
819         rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
820         rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
821         rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
822
823         rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
824         rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
825         rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
826         rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
827         rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
828         rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
829
830         rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
831         rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
832         rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
833         rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
834         rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
835         rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
836
837         rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
838         rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
839         rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
840         rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
841         rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
842         rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
843
844         rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
845         rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
846         rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
847         rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
848         rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
849         rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
850
851         rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
852         rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 0);
853         rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, 0);
854         rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 0);
855         rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
856         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
857
858         rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
859         rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
860
861         if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
862                 return -EBUSY;
863
864         rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
865         rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
866         rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
867         rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
868         rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
869
870         if (rt2x00_rev(rt2x00dev) >= RT2570_VERSION_C) {
871                 rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
872                 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
873         } else {
874                 reg = 0;
875                 rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
876                 rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
877         }
878         rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
879
880         rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
881         rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
882         rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
883         rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
884
885         rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
886         rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
887                            rt2x00dev->rx->data_size);
888         rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
889
890         rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
891         rt2x00_set_field16(&reg, TXRX_CSR0_ALGORITHM, CIPHER_NONE);
892         rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
893         rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0);
894         rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
895
896         rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
897         rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
898         rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
899
900         rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
901         rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
902         rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
903
904         rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
905         rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
906         rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
907
908         return 0;
909 }
910
911 static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
912 {
913         unsigned int i;
914         u8 value;
915
916         for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
917                 rt2500usb_bbp_read(rt2x00dev, 0, &value);
918                 if ((value != 0xff) && (value != 0x00))
919                         return 0;
920                 udelay(REGISTER_BUSY_DELAY);
921         }
922
923         ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
924         return -EACCES;
925 }
926
927 static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
928 {
929         unsigned int i;
930         u16 eeprom;
931         u8 value;
932         u8 reg_id;
933
934         if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
935                 return -EACCES;
936
937         rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
938         rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
939         rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
940         rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
941         rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
942         rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
943         rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
944         rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
945         rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
946         rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
947         rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
948         rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
949         rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
950         rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
951         rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
952         rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
953         rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
954         rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
955         rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
956         rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
957         rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
958         rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
959         rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
960         rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
961         rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
962         rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
963         rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
964         rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
965         rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
966         rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
967         rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
968
969         for (i = 0; i < EEPROM_BBP_SIZE; i++) {
970                 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
971
972                 if (eeprom != 0xffff && eeprom != 0x0000) {
973                         reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
974                         value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
975                         rt2500usb_bbp_write(rt2x00dev, reg_id, value);
976                 }
977         }
978
979         return 0;
980 }
981
982 /*
983  * Device state switch handlers.
984  */
985 static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
986 {
987         /*
988          * Initialize all registers.
989          */
990         if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
991                      rt2500usb_init_bbp(rt2x00dev)))
992                 return -EIO;
993
994         return 0;
995 }
996
997 static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
998 {
999         rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
1000         rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
1001
1002         /*
1003          * Disable synchronisation.
1004          */
1005         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1006
1007         rt2x00usb_disable_radio(rt2x00dev);
1008 }
1009
1010 static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
1011                                enum dev_state state)
1012 {
1013         u16 reg;
1014         u16 reg2;
1015         unsigned int i;
1016         char put_to_sleep;
1017         char bbp_state;
1018         char rf_state;
1019
1020         put_to_sleep = (state != STATE_AWAKE);
1021
1022         reg = 0;
1023         rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
1024         rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
1025         rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
1026         rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1027         rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
1028         rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1029
1030         /*
1031          * Device is not guaranteed to be in the requested state yet.
1032          * We must wait until the register indicates that the
1033          * device has entered the correct state.
1034          */
1035         for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1036                 rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
1037                 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
1038                 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
1039                 if (bbp_state == state && rf_state == state)
1040                         return 0;
1041                 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1042                 msleep(30);
1043         }
1044
1045         return -EBUSY;
1046 }
1047
1048 static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1049                                       enum dev_state state)
1050 {
1051         int retval = 0;
1052
1053         switch (state) {
1054         case STATE_RADIO_ON:
1055                 retval = rt2500usb_enable_radio(rt2x00dev);
1056                 break;
1057         case STATE_RADIO_OFF:
1058                 rt2500usb_disable_radio(rt2x00dev);
1059                 break;
1060         case STATE_RADIO_RX_ON:
1061                 rt2500usb_start_queue(rt2x00dev->rx);
1062                 break;
1063         case STATE_RADIO_RX_OFF:
1064                 rt2500usb_stop_queue(rt2x00dev->rx);
1065                 break;
1066         case STATE_RADIO_IRQ_ON:
1067         case STATE_RADIO_IRQ_ON_ISR:
1068         case STATE_RADIO_IRQ_OFF:
1069         case STATE_RADIO_IRQ_OFF_ISR:
1070                 /* No support, but no error either */
1071                 break;
1072         case STATE_DEEP_SLEEP:
1073         case STATE_SLEEP:
1074         case STATE_STANDBY:
1075         case STATE_AWAKE:
1076                 retval = rt2500usb_set_state(rt2x00dev, state);
1077                 break;
1078         default:
1079                 retval = -ENOTSUPP;
1080                 break;
1081         }
1082
1083         if (unlikely(retval))
1084                 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1085                       state, retval);
1086
1087         return retval;
1088 }
1089
1090 /*
1091  * TX descriptor initialization
1092  */
1093 static void rt2500usb_write_tx_desc(struct queue_entry *entry,
1094                                     struct txentry_desc *txdesc)
1095 {
1096         struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1097         __le32 *txd = (__le32 *) entry->skb->data;
1098         u32 word;
1099
1100         /*
1101          * Start writing the descriptor words.
1102          */
1103         rt2x00_desc_read(txd, 0, &word);
1104         rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, txdesc->retry_limit);
1105         rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
1106                            test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
1107         rt2x00_set_field32(&word, TXD_W0_ACK,
1108                            test_bit(ENTRY_TXD_ACK, &txdesc->flags));
1109         rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
1110                            test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
1111         rt2x00_set_field32(&word, TXD_W0_OFDM,
1112                            (txdesc->rate_mode == RATE_MODE_OFDM));
1113         rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
1114                            test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
1115         rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
1116         rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, txdesc->length);
1117         rt2x00_set_field32(&word, TXD_W0_CIPHER, !!txdesc->cipher);
1118         rt2x00_set_field32(&word, TXD_W0_KEY_ID, txdesc->key_idx);
1119         rt2x00_desc_write(txd, 0, word);
1120
1121         rt2x00_desc_read(txd, 1, &word);
1122         rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
1123         rt2x00_set_field32(&word, TXD_W1_AIFS, entry->queue->aifs);
1124         rt2x00_set_field32(&word, TXD_W1_CWMIN, entry->queue->cw_min);
1125         rt2x00_set_field32(&word, TXD_W1_CWMAX, entry->queue->cw_max);
1126         rt2x00_desc_write(txd, 1, word);
1127
1128         rt2x00_desc_read(txd, 2, &word);
1129         rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
1130         rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
1131         rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
1132         rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
1133         rt2x00_desc_write(txd, 2, word);
1134
1135         if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1136                 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1137                 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1138         }
1139
1140         /*
1141          * Register descriptor details in skb frame descriptor.
1142          */
1143         skbdesc->flags |= SKBDESC_DESC_IN_SKB;
1144         skbdesc->desc = txd;
1145         skbdesc->desc_len = TXD_DESC_SIZE;
1146 }
1147
1148 /*
1149  * TX data initialization
1150  */
1151 static void rt2500usb_beacondone(struct urb *urb);
1152
1153 static void rt2500usb_write_beacon(struct queue_entry *entry,
1154                                    struct txentry_desc *txdesc)
1155 {
1156         struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1157         struct usb_device *usb_dev = to_usb_device_intf(rt2x00dev->dev);
1158         struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1159         int pipe = usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint);
1160         int length;
1161         u16 reg, reg0;
1162
1163         /*
1164          * Disable beaconing while we are reloading the beacon data,
1165          * otherwise we might be sending out invalid data.
1166          */
1167         rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
1168         rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
1169         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1170
1171         /*
1172          * Add space for the descriptor in front of the skb.
1173          */
1174         skb_push(entry->skb, TXD_DESC_SIZE);
1175         memset(entry->skb->data, 0, TXD_DESC_SIZE);
1176
1177         /*
1178          * Write the TX descriptor for the beacon.
1179          */
1180         rt2500usb_write_tx_desc(entry, txdesc);
1181
1182         /*
1183          * Dump beacon to userspace through debugfs.
1184          */
1185         rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_BEACON, entry->skb);
1186
1187         /*
1188          * USB devices cannot blindly pass the skb->len as the
1189          * length of the data to usb_fill_bulk_urb. Pass the skb
1190          * to the driver to determine what the length should be.
1191          */
1192         length = rt2x00dev->ops->lib->get_tx_data_len(entry);
1193
1194         usb_fill_bulk_urb(bcn_priv->urb, usb_dev, pipe,
1195                           entry->skb->data, length, rt2500usb_beacondone,
1196                           entry);
1197
1198         /*
1199          * Second we need to create the guardian byte.
1200          * We only need a single byte, so lets recycle
1201          * the 'flags' field we are not using for beacons.
1202          */
1203         bcn_priv->guardian_data = 0;
1204         usb_fill_bulk_urb(bcn_priv->guardian_urb, usb_dev, pipe,
1205                           &bcn_priv->guardian_data, 1, rt2500usb_beacondone,
1206                           entry);
1207
1208         /*
1209          * Send out the guardian byte.
1210          */
1211         usb_submit_urb(bcn_priv->guardian_urb, GFP_ATOMIC);
1212
1213         /*
1214          * Enable beaconing again.
1215          */
1216         rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
1217         rt2x00_set_field16(&reg, TXRX_CSR19_TBCN, 1);
1218         reg0 = reg;
1219         rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
1220         /*
1221          * Beacon generation will fail initially.
1222          * To prevent this we need to change the TXRX_CSR19
1223          * register several times (reg0 is the same as reg
1224          * except for TXRX_CSR19_BEACON_GEN, which is 0 in reg0
1225          * and 1 in reg).
1226          */
1227         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1228         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg0);
1229         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1230         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg0);
1231         rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1232 }
1233
1234 static int rt2500usb_get_tx_data_len(struct queue_entry *entry)
1235 {
1236         int length;
1237
1238         /*
1239          * The length _must_ be a multiple of 2,
1240          * but it must _not_ be a multiple of the USB packet size.
1241          */
1242         length = roundup(entry->skb->len, 2);
1243         length += (2 * !(length % entry->queue->usb_maxpacket));
1244
1245         return length;
1246 }
1247
1248 /*
1249  * RX control handlers
1250  */
1251 static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1252                                   struct rxdone_entry_desc *rxdesc)
1253 {
1254         struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1255         struct queue_entry_priv_usb *entry_priv = entry->priv_data;
1256         struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1257         __le32 *rxd =
1258             (__le32 *)(entry->skb->data +
1259                        (entry_priv->urb->actual_length -
1260                         entry->queue->desc_size));
1261         u32 word0;
1262         u32 word1;
1263
1264         /*
1265          * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1266          * frame data in rt2x00usb.
1267          */
1268         memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
1269         rxd = (__le32 *)skbdesc->desc;
1270
1271         /*
1272          * It is now safe to read the descriptor on all architectures.
1273          */
1274         rt2x00_desc_read(rxd, 0, &word0);
1275         rt2x00_desc_read(rxd, 1, &word1);
1276
1277         if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1278                 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
1279         if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
1280                 rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC;
1281
1282         rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER);
1283         if (rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR))
1284                 rxdesc->cipher_status = RX_CRYPTO_FAIL_KEY;
1285
1286         if (rxdesc->cipher != CIPHER_NONE) {
1287                 _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
1288                 _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
1289                 rxdesc->dev_flags |= RXDONE_CRYPTO_IV;
1290
1291                 /* ICV is located at the end of frame */
1292
1293                 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
1294                 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1295                         rxdesc->flags |= RX_FLAG_DECRYPTED;
1296                 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1297                         rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1298         }
1299
1300         /*
1301          * Obtain the status about this packet.
1302          * When frame was received with an OFDM bitrate,
1303          * the signal is the PLCP value. If it was received with
1304          * a CCK bitrate the signal is the rate in 100kbit/s.
1305          */
1306         rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1307         rxdesc->rssi =
1308             rt2x00_get_field32(word1, RXD_W1_RSSI) - rt2x00dev->rssi_offset;
1309         rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
1310
1311         if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1312                 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1313         else
1314                 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1315         if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1316                 rxdesc->dev_flags |= RXDONE_MY_BSS;
1317
1318         /*
1319          * Adjust the skb memory window to the frame boundaries.
1320          */
1321         skb_trim(entry->skb, rxdesc->size);
1322 }
1323
1324 /*
1325  * Interrupt functions.
1326  */
1327 static void rt2500usb_beacondone(struct urb *urb)
1328 {
1329         struct queue_entry *entry = (struct queue_entry *)urb->context;
1330         struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1331
1332         if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
1333                 return;
1334
1335         /*
1336          * Check if this was the guardian beacon,
1337          * if that was the case we need to send the real beacon now.
1338          * Otherwise we should free the sk_buffer, the device
1339          * should be doing the rest of the work now.
1340          */
1341         if (bcn_priv->guardian_urb == urb) {
1342                 usb_submit_urb(bcn_priv->urb, GFP_ATOMIC);
1343         } else if (bcn_priv->urb == urb) {
1344                 dev_kfree_skb(entry->skb);
1345                 entry->skb = NULL;
1346         }
1347 }
1348
1349 /*
1350  * Device probe functions.
1351  */
1352 static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1353 {
1354         u16 word;
1355         u8 *mac;
1356         u8 bbp;
1357
1358         rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1359
1360         /*
1361          * Start validation of the data that has been read.
1362          */
1363         mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1364         if (!is_valid_ether_addr(mac)) {
1365                 random_ether_addr(mac);
1366                 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
1367         }
1368
1369         rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1370         if (word == 0xffff) {
1371                 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
1372                 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1373                                    ANTENNA_SW_DIVERSITY);
1374                 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1375                                    ANTENNA_SW_DIVERSITY);
1376                 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1377                                    LED_MODE_DEFAULT);
1378                 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1379                 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1380                 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1381                 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1382                 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1383         }
1384
1385         rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1386         if (word == 0xffff) {
1387                 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1388                 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1389                 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1390                 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1391                 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1392         }
1393
1394         rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1395         if (word == 0xffff) {
1396                 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1397                                    DEFAULT_RSSI_OFFSET);
1398                 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1399                 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1400         }
1401
1402         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1403         if (word == 0xffff) {
1404                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1405                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1406                 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1407         }
1408
1409         /*
1410          * Switch lower vgc bound to current BBP R17 value,
1411          * lower the value a bit for better quality.
1412          */
1413         rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
1414         bbp -= 6;
1415
1416         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1417         if (word == 0xffff) {
1418                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
1419                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1420                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1421                 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
1422         } else {
1423                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1424                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1425         }
1426
1427         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1428         if (word == 0xffff) {
1429                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1430                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1431                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1432                 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1433         }
1434
1435         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1436         if (word == 0xffff) {
1437                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1438                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1439                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1440                 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1441         }
1442
1443         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1444         if (word == 0xffff) {
1445                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1446                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1447                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1448                 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1449         }
1450
1451         rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1452         if (word == 0xffff) {
1453                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1454                 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1455                 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1456                 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1457         }
1458
1459         return 0;
1460 }
1461
1462 static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1463 {
1464         u16 reg;
1465         u16 value;
1466         u16 eeprom;
1467
1468         /*
1469          * Read EEPROM word for configuration.
1470          */
1471         rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1472
1473         /*
1474          * Identify RF chipset.
1475          */
1476         value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1477         rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
1478         rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1479
1480         if (((reg & 0xfff0) != 0) || ((reg & 0x0000000f) == 0)) {
1481                 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1482                 return -ENODEV;
1483         }
1484
1485         if (!rt2x00_rf(rt2x00dev, RF2522) &&
1486             !rt2x00_rf(rt2x00dev, RF2523) &&
1487             !rt2x00_rf(rt2x00dev, RF2524) &&
1488             !rt2x00_rf(rt2x00dev, RF2525) &&
1489             !rt2x00_rf(rt2x00dev, RF2525E) &&
1490             !rt2x00_rf(rt2x00dev, RF5222)) {
1491                 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1492                 return -ENODEV;
1493         }
1494
1495         /*
1496          * Identify default antenna configuration.
1497          */
1498         rt2x00dev->default_ant.tx =
1499             rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
1500         rt2x00dev->default_ant.rx =
1501             rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1502
1503         /*
1504          * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1505          * I am not 100% sure about this, but the legacy drivers do not
1506          * indicate antenna swapping in software is required when
1507          * diversity is enabled.
1508          */
1509         if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1510                 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1511         if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1512                 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1513
1514         /*
1515          * Store led mode, for correct led behaviour.
1516          */
1517 #ifdef CONFIG_RT2X00_LIB_LEDS
1518         value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1519
1520         rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1521         if (value == LED_MODE_TXRX_ACTIVITY ||
1522             value == LED_MODE_DEFAULT ||
1523             value == LED_MODE_ASUS)
1524                 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
1525                                    LED_TYPE_ACTIVITY);
1526 #endif /* CONFIG_RT2X00_LIB_LEDS */
1527
1528         /*
1529          * Detect if this device has an hardware controlled radio.
1530          */
1531         if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_HARDWARE_RADIO))
1532                 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
1533
1534         /*
1535          * Read the RSSI <-> dBm offset information.
1536          */
1537         rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1538         rt2x00dev->rssi_offset =
1539             rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1540
1541         return 0;
1542 }
1543
1544 /*
1545  * RF value list for RF2522
1546  * Supports: 2.4 GHz
1547  */
1548 static const struct rf_channel rf_vals_bg_2522[] = {
1549         { 1,  0x00002050, 0x000c1fda, 0x00000101, 0 },
1550         { 2,  0x00002050, 0x000c1fee, 0x00000101, 0 },
1551         { 3,  0x00002050, 0x000c2002, 0x00000101, 0 },
1552         { 4,  0x00002050, 0x000c2016, 0x00000101, 0 },
1553         { 5,  0x00002050, 0x000c202a, 0x00000101, 0 },
1554         { 6,  0x00002050, 0x000c203e, 0x00000101, 0 },
1555         { 7,  0x00002050, 0x000c2052, 0x00000101, 0 },
1556         { 8,  0x00002050, 0x000c2066, 0x00000101, 0 },
1557         { 9,  0x00002050, 0x000c207a, 0x00000101, 0 },
1558         { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1559         { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1560         { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1561         { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1562         { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1563 };
1564
1565 /*
1566  * RF value list for RF2523
1567  * Supports: 2.4 GHz
1568  */
1569 static const struct rf_channel rf_vals_bg_2523[] = {
1570         { 1,  0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1571         { 2,  0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1572         { 3,  0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1573         { 4,  0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1574         { 5,  0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1575         { 6,  0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1576         { 7,  0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1577         { 8,  0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1578         { 9,  0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1579         { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1580         { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1581         { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1582         { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1583         { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1584 };
1585
1586 /*
1587  * RF value list for RF2524
1588  * Supports: 2.4 GHz
1589  */
1590 static const struct rf_channel rf_vals_bg_2524[] = {
1591         { 1,  0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1592         { 2,  0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1593         { 3,  0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1594         { 4,  0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1595         { 5,  0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1596         { 6,  0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1597         { 7,  0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1598         { 8,  0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1599         { 9,  0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1600         { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1601         { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1602         { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1603         { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1604         { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1605 };
1606
1607 /*
1608  * RF value list for RF2525
1609  * Supports: 2.4 GHz
1610  */
1611 static const struct rf_channel rf_vals_bg_2525[] = {
1612         { 1,  0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1613         { 2,  0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1614         { 3,  0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1615         { 4,  0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1616         { 5,  0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1617         { 6,  0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1618         { 7,  0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1619         { 8,  0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1620         { 9,  0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1621         { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1622         { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1623         { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1624         { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1625         { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1626 };
1627
1628 /*
1629  * RF value list for RF2525e
1630  * Supports: 2.4 GHz
1631  */
1632 static const struct rf_channel rf_vals_bg_2525e[] = {
1633         { 1,  0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1634         { 2,  0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1635         { 3,  0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1636         { 4,  0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1637         { 5,  0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1638         { 6,  0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1639         { 7,  0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1640         { 8,  0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1641         { 9,  0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1642         { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1643         { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1644         { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1645         { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1646         { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1647 };
1648
1649 /*
1650  * RF value list for RF5222
1651  * Supports: 2.4 GHz & 5.2 GHz
1652  */
1653 static const struct rf_channel rf_vals_5222[] = {
1654         { 1,  0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1655         { 2,  0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1656         { 3,  0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1657         { 4,  0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1658         { 5,  0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1659         { 6,  0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1660         { 7,  0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1661         { 8,  0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1662         { 9,  0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1663         { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1664         { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1665         { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1666         { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1667         { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1668
1669         /* 802.11 UNI / HyperLan 2 */
1670         { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1671         { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1672         { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1673         { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1674         { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1675         { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1676         { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1677         { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1678
1679         /* 802.11 HyperLan 2 */
1680         { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1681         { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1682         { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1683         { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1684         { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1685         { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1686         { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1687         { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1688         { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1689         { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1690
1691         /* 802.11 UNII */
1692         { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1693         { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1694         { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1695         { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1696         { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1697 };
1698
1699 static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1700 {
1701         struct hw_mode_spec *spec = &rt2x00dev->spec;
1702         struct channel_info *info;
1703         char *tx_power;
1704         unsigned int i;
1705
1706         /*
1707          * Initialize all hw fields.
1708          *
1709          * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING unless we are
1710          * capable of sending the buffered frames out after the DTIM
1711          * transmission using rt2x00lib_beacondone. This will send out
1712          * multicast and broadcast traffic immediately instead of buffering it
1713          * infinitly and thus dropping it after some time.
1714          */
1715         rt2x00dev->hw->flags =
1716             IEEE80211_HW_RX_INCLUDES_FCS |
1717             IEEE80211_HW_SIGNAL_DBM |
1718             IEEE80211_HW_SUPPORTS_PS |
1719             IEEE80211_HW_PS_NULLFUNC_STACK;
1720
1721         SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
1722         SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1723                                 rt2x00_eeprom_addr(rt2x00dev,
1724                                                    EEPROM_MAC_ADDR_0));
1725
1726         /*
1727          * Initialize hw_mode information.
1728          */
1729         spec->supported_bands = SUPPORT_BAND_2GHZ;
1730         spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
1731
1732         if (rt2x00_rf(rt2x00dev, RF2522)) {
1733                 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1734                 spec->channels = rf_vals_bg_2522;
1735         } else if (rt2x00_rf(rt2x00dev, RF2523)) {
1736                 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1737                 spec->channels = rf_vals_bg_2523;
1738         } else if (rt2x00_rf(rt2x00dev, RF2524)) {
1739                 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1740                 spec->channels = rf_vals_bg_2524;
1741         } else if (rt2x00_rf(rt2x00dev, RF2525)) {
1742                 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1743                 spec->channels = rf_vals_bg_2525;
1744         } else if (rt2x00_rf(rt2x00dev, RF2525E)) {
1745                 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1746                 spec->channels = rf_vals_bg_2525e;
1747         } else if (rt2x00_rf(rt2x00dev, RF5222)) {
1748                 spec->supported_bands |= SUPPORT_BAND_5GHZ;
1749                 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1750                 spec->channels = rf_vals_5222;
1751         }
1752
1753         /*
1754          * Create channel information array
1755          */
1756         info = kcalloc(spec->num_channels, sizeof(*info), GFP_KERNEL);
1757         if (!info)
1758                 return -ENOMEM;
1759
1760         spec->channels_info = info;
1761
1762         tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1763         for (i = 0; i < 14; i++) {
1764                 info[i].max_power = MAX_TXPOWER;
1765                 info[i].default_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1766         }
1767
1768         if (spec->num_channels > 14) {
1769                 for (i = 14; i < spec->num_channels; i++) {
1770                         info[i].max_power = MAX_TXPOWER;
1771                         info[i].default_power1 = DEFAULT_TXPOWER;
1772                 }
1773         }
1774
1775         return 0;
1776 }
1777
1778 static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1779 {
1780         int retval;
1781
1782         /*
1783          * Allocate eeprom data.
1784          */
1785         retval = rt2500usb_validate_eeprom(rt2x00dev);
1786         if (retval)
1787                 return retval;
1788
1789         retval = rt2500usb_init_eeprom(rt2x00dev);
1790         if (retval)
1791                 return retval;
1792
1793         /*
1794          * Initialize hw specifications.
1795          */
1796         retval = rt2500usb_probe_hw_mode(rt2x00dev);
1797         if (retval)
1798                 return retval;
1799
1800         /*
1801          * This device requires the atim queue
1802          */
1803         __set_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
1804         __set_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags);
1805         if (!modparam_nohwcrypt) {
1806                 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
1807                 __set_bit(DRIVER_REQUIRE_COPY_IV, &rt2x00dev->flags);
1808         }
1809         __set_bit(DRIVER_SUPPORT_WATCHDOG, &rt2x00dev->flags);
1810
1811         /*
1812          * Set the rssi offset.
1813          */
1814         rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1815
1816         return 0;
1817 }
1818
1819 static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1820         .tx                     = rt2x00mac_tx,
1821         .start                  = rt2x00mac_start,
1822         .stop                   = rt2x00mac_stop,
1823         .add_interface          = rt2x00mac_add_interface,
1824         .remove_interface       = rt2x00mac_remove_interface,
1825         .config                 = rt2x00mac_config,
1826         .configure_filter       = rt2x00mac_configure_filter,
1827         .set_tim                = rt2x00mac_set_tim,
1828         .set_key                = rt2x00mac_set_key,
1829         .sw_scan_start          = rt2x00mac_sw_scan_start,
1830         .sw_scan_complete       = rt2x00mac_sw_scan_complete,
1831         .get_stats              = rt2x00mac_get_stats,
1832         .bss_info_changed       = rt2x00mac_bss_info_changed,
1833         .conf_tx                = rt2x00mac_conf_tx,
1834         .rfkill_poll            = rt2x00mac_rfkill_poll,
1835         .flush                  = rt2x00mac_flush,
1836 };
1837
1838 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1839         .probe_hw               = rt2500usb_probe_hw,
1840         .initialize             = rt2x00usb_initialize,
1841         .uninitialize           = rt2x00usb_uninitialize,
1842         .clear_entry            = rt2x00usb_clear_entry,
1843         .set_device_state       = rt2500usb_set_device_state,
1844         .rfkill_poll            = rt2500usb_rfkill_poll,
1845         .link_stats             = rt2500usb_link_stats,
1846         .reset_tuner            = rt2500usb_reset_tuner,
1847         .watchdog               = rt2x00usb_watchdog,
1848         .write_tx_desc          = rt2500usb_write_tx_desc,
1849         .write_beacon           = rt2500usb_write_beacon,
1850         .get_tx_data_len        = rt2500usb_get_tx_data_len,
1851         .kick_tx_queue          = rt2x00usb_kick_tx_queue,
1852         .kill_tx_queue          = rt2500usb_stop_queue,
1853         .fill_rxdone            = rt2500usb_fill_rxdone,
1854         .config_shared_key      = rt2500usb_config_key,
1855         .config_pairwise_key    = rt2500usb_config_key,
1856         .config_filter          = rt2500usb_config_filter,
1857         .config_intf            = rt2500usb_config_intf,
1858         .config_erp             = rt2500usb_config_erp,
1859         .config_ant             = rt2500usb_config_ant,
1860         .config                 = rt2500usb_config,
1861 };
1862
1863 static const struct data_queue_desc rt2500usb_queue_rx = {
1864         .entry_num              = 32,
1865         .data_size              = DATA_FRAME_SIZE,
1866         .desc_size              = RXD_DESC_SIZE,
1867         .priv_size              = sizeof(struct queue_entry_priv_usb),
1868 };
1869
1870 static const struct data_queue_desc rt2500usb_queue_tx = {
1871         .entry_num              = 32,
1872         .data_size              = DATA_FRAME_SIZE,
1873         .desc_size              = TXD_DESC_SIZE,
1874         .priv_size              = sizeof(struct queue_entry_priv_usb),
1875 };
1876
1877 static const struct data_queue_desc rt2500usb_queue_bcn = {
1878         .entry_num              = 1,
1879         .data_size              = MGMT_FRAME_SIZE,
1880         .desc_size              = TXD_DESC_SIZE,
1881         .priv_size              = sizeof(struct queue_entry_priv_usb_bcn),
1882 };
1883
1884 static const struct data_queue_desc rt2500usb_queue_atim = {
1885         .entry_num              = 8,
1886         .data_size              = DATA_FRAME_SIZE,
1887         .desc_size              = TXD_DESC_SIZE,
1888         .priv_size              = sizeof(struct queue_entry_priv_usb),
1889 };
1890
1891 static const struct rt2x00_ops rt2500usb_ops = {
1892         .name                   = KBUILD_MODNAME,
1893         .max_sta_intf           = 1,
1894         .max_ap_intf            = 1,
1895         .eeprom_size            = EEPROM_SIZE,
1896         .rf_size                = RF_SIZE,
1897         .tx_queues              = NUM_TX_QUEUES,
1898         .extra_tx_headroom      = TXD_DESC_SIZE,
1899         .rx                     = &rt2500usb_queue_rx,
1900         .tx                     = &rt2500usb_queue_tx,
1901         .bcn                    = &rt2500usb_queue_bcn,
1902         .atim                   = &rt2500usb_queue_atim,
1903         .lib                    = &rt2500usb_rt2x00_ops,
1904         .hw                     = &rt2500usb_mac80211_ops,
1905 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1906         .debugfs                = &rt2500usb_rt2x00debug,
1907 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1908 };
1909
1910 /*
1911  * rt2500usb module information.
1912  */
1913 static struct usb_device_id rt2500usb_device_table[] = {
1914         /* ASUS */
1915         { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1916         { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1917         /* Belkin */
1918         { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
1919         { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
1920         { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
1921         /* Cisco Systems */
1922         { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
1923         { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
1924         { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
1925         /* CNet */
1926         { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt2500usb_ops) },
1927         /* Conceptronic */
1928         { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
1929         /* D-LINK */
1930         { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
1931         /* Gigabyte */
1932         { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
1933         { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
1934         /* Hercules */
1935         { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
1936         /* Melco */
1937         { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
1938         { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
1939         { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
1940         { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
1941         { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
1942         /* MSI */
1943         { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
1944         { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
1945         { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
1946         /* Ralink */
1947         { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1948         { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
1949         { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
1950         { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1951         /* Sagem */
1952         { USB_DEVICE(0x079b, 0x004b), USB_DEVICE_DATA(&rt2500usb_ops) },
1953         /* Siemens */
1954         { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
1955         /* SMC */
1956         { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
1957         /* Spairon */
1958         { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
1959         /* SURECOM */
1960         { USB_DEVICE(0x0769, 0x11f3), USB_DEVICE_DATA(&rt2500usb_ops) },
1961         /* Trust */
1962         { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1963         /* VTech */
1964         { USB_DEVICE(0x0f88, 0x3012), USB_DEVICE_DATA(&rt2500usb_ops) },
1965         /* Zinwell */
1966         { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
1967         { 0, }
1968 };
1969
1970 MODULE_AUTHOR(DRV_PROJECT);
1971 MODULE_VERSION(DRV_VERSION);
1972 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1973 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1974 MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
1975 MODULE_LICENSE("GPL");
1976
1977 static struct usb_driver rt2500usb_driver = {
1978         .name           = KBUILD_MODNAME,
1979         .id_table       = rt2500usb_device_table,
1980         .probe          = rt2x00usb_probe,
1981         .disconnect     = rt2x00usb_disconnect,
1982         .suspend        = rt2x00usb_suspend,
1983         .resume         = rt2x00usb_resume,
1984 };
1985
1986 static int __init rt2500usb_init(void)
1987 {
1988         return usb_register(&rt2500usb_driver);
1989 }
1990
1991 static void __exit rt2500usb_exit(void)
1992 {
1993         usb_deregister(&rt2500usb_driver);
1994 }
1995
1996 module_init(rt2500usb_init);
1997 module_exit(rt2500usb_exit);