2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
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.
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.
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.
23 Abstract: rt2500usb device specific routines.
24 Supported chipsets: RT2570.
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/usb.h>
35 #include "rt2x00usb.h"
36 #include "rt2500usb.h"
39 * Allow hardware encryption to be disabled.
41 static int modparam_nohwcrypt = 1;
42 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
43 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
47 * All access to the CSR registers will go through the methods
48 * rt2500usb_register_read and rt2500usb_register_write.
49 * BBP and RF register require indirect register access,
50 * and use the CSR registers BBPCSR and RFCSR to achieve this.
51 * These indirect registers work with busy bits,
52 * and we will try maximal REGISTER_BUSY_COUNT times to access
53 * the register while taking a REGISTER_BUSY_DELAY us delay
54 * between each attampt. When the busy bit is still set at that time,
55 * the access attempt is considered to have failed,
56 * and we will print an error.
57 * If the csr_mutex is already held then the _lock variants must
60 static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
61 const unsigned int offset,
65 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
66 USB_VENDOR_REQUEST_IN, offset,
67 ®, sizeof(reg), REGISTER_TIMEOUT);
68 *value = le16_to_cpu(reg);
71 static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
72 const unsigned int offset,
76 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
77 USB_VENDOR_REQUEST_IN, offset,
78 ®, sizeof(reg), REGISTER_TIMEOUT);
79 *value = le16_to_cpu(reg);
82 static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
83 const unsigned int offset,
84 void *value, const u16 length)
86 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
87 USB_VENDOR_REQUEST_IN, offset,
89 REGISTER_TIMEOUT16(length));
92 static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
93 const unsigned int offset,
96 __le16 reg = cpu_to_le16(value);
97 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
98 USB_VENDOR_REQUEST_OUT, offset,
99 ®, sizeof(reg), REGISTER_TIMEOUT);
102 static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
103 const unsigned int offset,
106 __le16 reg = cpu_to_le16(value);
107 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
108 USB_VENDOR_REQUEST_OUT, offset,
109 ®, sizeof(reg), REGISTER_TIMEOUT);
112 static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
113 const unsigned int offset,
114 void *value, const u16 length)
116 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
117 USB_VENDOR_REQUEST_OUT, offset,
119 REGISTER_TIMEOUT16(length));
122 static int rt2500usb_regbusy_read(struct rt2x00_dev *rt2x00dev,
123 const unsigned int offset,
124 struct rt2x00_field16 field,
129 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
130 rt2500usb_register_read_lock(rt2x00dev, offset, reg);
131 if (!rt2x00_get_field16(*reg, field))
133 udelay(REGISTER_BUSY_DELAY);
136 ERROR(rt2x00dev, "Indirect register access failed: "
137 "offset=0x%.08x, value=0x%.08x\n", offset, *reg);
143 #define WAIT_FOR_BBP(__dev, __reg) \
144 rt2500usb_regbusy_read((__dev), PHY_CSR8, PHY_CSR8_BUSY, (__reg))
145 #define WAIT_FOR_RF(__dev, __reg) \
146 rt2500usb_regbusy_read((__dev), PHY_CSR10, PHY_CSR10_RF_BUSY, (__reg))
148 static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
149 const unsigned int word, const u8 value)
153 mutex_lock(&rt2x00dev->csr_mutex);
156 * Wait until the BBP becomes available, afterwards we
157 * can safely write the new data into the register.
159 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
161 rt2x00_set_field16(®, PHY_CSR7_DATA, value);
162 rt2x00_set_field16(®, PHY_CSR7_REG_ID, word);
163 rt2x00_set_field16(®, PHY_CSR7_READ_CONTROL, 0);
165 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
168 mutex_unlock(&rt2x00dev->csr_mutex);
171 static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
172 const unsigned int word, u8 *value)
176 mutex_lock(&rt2x00dev->csr_mutex);
179 * Wait until the BBP becomes available, afterwards we
180 * can safely write the read request into the register.
181 * After the data has been written, we wait until hardware
182 * returns the correct value, if at any time the register
183 * doesn't become available in time, reg will be 0xffffffff
184 * which means we return 0xff to the caller.
186 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
188 rt2x00_set_field16(®, PHY_CSR7_REG_ID, word);
189 rt2x00_set_field16(®, PHY_CSR7_READ_CONTROL, 1);
191 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
193 if (WAIT_FOR_BBP(rt2x00dev, ®))
194 rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, ®);
197 *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
199 mutex_unlock(&rt2x00dev->csr_mutex);
202 static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
203 const unsigned int word, const u32 value)
210 mutex_lock(&rt2x00dev->csr_mutex);
213 * Wait until the RF becomes available, afterwards we
214 * can safely write the new data into the register.
216 if (WAIT_FOR_RF(rt2x00dev, ®)) {
218 rt2x00_set_field16(®, PHY_CSR9_RF_VALUE, value);
219 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
222 rt2x00_set_field16(®, PHY_CSR10_RF_VALUE, value >> 16);
223 rt2x00_set_field16(®, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
224 rt2x00_set_field16(®, PHY_CSR10_RF_IF_SELECT, 0);
225 rt2x00_set_field16(®, PHY_CSR10_RF_BUSY, 1);
227 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
228 rt2x00_rf_write(rt2x00dev, word, value);
231 mutex_unlock(&rt2x00dev->csr_mutex);
234 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
235 static void _rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
236 const unsigned int offset,
239 rt2500usb_register_read(rt2x00dev, offset, (u16 *)value);
242 static void _rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
243 const unsigned int offset,
246 rt2500usb_register_write(rt2x00dev, offset, value);
249 static const struct rt2x00debug rt2500usb_rt2x00debug = {
250 .owner = THIS_MODULE,
252 .read = _rt2500usb_register_read,
253 .write = _rt2500usb_register_write,
254 .flags = RT2X00DEBUGFS_OFFSET,
255 .word_base = CSR_REG_BASE,
256 .word_size = sizeof(u16),
257 .word_count = CSR_REG_SIZE / sizeof(u16),
260 .read = rt2x00_eeprom_read,
261 .write = rt2x00_eeprom_write,
262 .word_base = EEPROM_BASE,
263 .word_size = sizeof(u16),
264 .word_count = EEPROM_SIZE / sizeof(u16),
267 .read = rt2500usb_bbp_read,
268 .write = rt2500usb_bbp_write,
269 .word_base = BBP_BASE,
270 .word_size = sizeof(u8),
271 .word_count = BBP_SIZE / sizeof(u8),
274 .read = rt2x00_rf_read,
275 .write = rt2500usb_rf_write,
276 .word_base = RF_BASE,
277 .word_size = sizeof(u32),
278 .word_count = RF_SIZE / sizeof(u32),
281 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
283 #ifdef CONFIG_RT2X00_LIB_LEDS
284 static void rt2500usb_brightness_set(struct led_classdev *led_cdev,
285 enum led_brightness brightness)
287 struct rt2x00_led *led =
288 container_of(led_cdev, struct rt2x00_led, led_dev);
289 unsigned int enabled = brightness != LED_OFF;
292 rt2500usb_register_read(led->rt2x00dev, MAC_CSR20, ®);
294 if (led->type == LED_TYPE_RADIO || led->type == LED_TYPE_ASSOC)
295 rt2x00_set_field16(®, MAC_CSR20_LINK, enabled);
296 else if (led->type == LED_TYPE_ACTIVITY)
297 rt2x00_set_field16(®, MAC_CSR20_ACTIVITY, enabled);
299 rt2500usb_register_write(led->rt2x00dev, MAC_CSR20, reg);
302 static int rt2500usb_blink_set(struct led_classdev *led_cdev,
303 unsigned long *delay_on,
304 unsigned long *delay_off)
306 struct rt2x00_led *led =
307 container_of(led_cdev, struct rt2x00_led, led_dev);
310 rt2500usb_register_read(led->rt2x00dev, MAC_CSR21, ®);
311 rt2x00_set_field16(®, MAC_CSR21_ON_PERIOD, *delay_on);
312 rt2x00_set_field16(®, MAC_CSR21_OFF_PERIOD, *delay_off);
313 rt2500usb_register_write(led->rt2x00dev, MAC_CSR21, reg);
318 static void rt2500usb_init_led(struct rt2x00_dev *rt2x00dev,
319 struct rt2x00_led *led,
322 led->rt2x00dev = rt2x00dev;
324 led->led_dev.brightness_set = rt2500usb_brightness_set;
325 led->led_dev.blink_set = rt2500usb_blink_set;
326 led->flags = LED_INITIALIZED;
328 #endif /* CONFIG_RT2X00_LIB_LEDS */
331 * Configuration handlers.
335 * rt2500usb does not differentiate between shared and pairwise
336 * keys, so we should use the same function for both key types.
338 static int rt2500usb_config_key(struct rt2x00_dev *rt2x00dev,
339 struct rt2x00lib_crypto *crypto,
340 struct ieee80211_key_conf *key)
346 if (crypto->cmd == SET_KEY) {
348 * Pairwise key will always be entry 0, but this
349 * could collide with a shared key on the same
352 mask = TXRX_CSR0_KEY_ID.bit_mask;
354 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, ®);
357 if (reg && reg == mask)
360 reg = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
362 key->hw_key_idx += reg ? ffz(reg) : 0;
365 * The encryption key doesn't fit within the CSR cache,
366 * this means we should allocate it seperately and use
367 * rt2x00usb_vendor_request() to send the key to the hardware.
369 reg = KEY_ENTRY(key->hw_key_idx);
370 timeout = REGISTER_TIMEOUT32(sizeof(crypto->key));
371 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
372 USB_VENDOR_REQUEST_OUT, reg,
378 * The driver does not support the IV/EIV generation
379 * in hardware. However it doesn't support the IV/EIV
380 * inside the ieee80211 frame either, but requires it
381 * to be provided seperately for the descriptor.
382 * rt2x00lib will cut the IV/EIV data out of all frames
383 * given to us by mac80211, but we must tell mac80211
384 * to generate the IV/EIV data.
386 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
387 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
391 * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
392 * a particular key is valid.
394 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, ®);
395 rt2x00_set_field16(®, TXRX_CSR0_ALGORITHM, crypto->cipher);
396 rt2x00_set_field16(®, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
398 mask = rt2x00_get_field16(reg, TXRX_CSR0_KEY_ID);
399 if (crypto->cmd == SET_KEY)
400 mask |= 1 << key->hw_key_idx;
401 else if (crypto->cmd == DISABLE_KEY)
402 mask &= ~(1 << key->hw_key_idx);
403 rt2x00_set_field16(®, TXRX_CSR0_KEY_ID, mask);
404 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
409 static void rt2500usb_config_filter(struct rt2x00_dev *rt2x00dev,
410 const unsigned int filter_flags)
415 * Start configuration steps.
416 * Note that the version error will always be dropped
417 * and broadcast frames will always be accepted since
418 * there is no filter for it at this time.
420 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
421 rt2x00_set_field16(®, TXRX_CSR2_DROP_CRC,
422 !(filter_flags & FIF_FCSFAIL));
423 rt2x00_set_field16(®, TXRX_CSR2_DROP_PHYSICAL,
424 !(filter_flags & FIF_PLCPFAIL));
425 rt2x00_set_field16(®, TXRX_CSR2_DROP_CONTROL,
426 !(filter_flags & FIF_CONTROL));
427 rt2x00_set_field16(®, TXRX_CSR2_DROP_NOT_TO_ME,
428 !(filter_flags & FIF_PROMISC_IN_BSS));
429 rt2x00_set_field16(®, TXRX_CSR2_DROP_TODS,
430 !(filter_flags & FIF_PROMISC_IN_BSS) &&
431 !rt2x00dev->intf_ap_count);
432 rt2x00_set_field16(®, TXRX_CSR2_DROP_VERSION_ERROR, 1);
433 rt2x00_set_field16(®, TXRX_CSR2_DROP_MULTICAST,
434 !(filter_flags & FIF_ALLMULTI));
435 rt2x00_set_field16(®, TXRX_CSR2_DROP_BROADCAST, 0);
436 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
439 static void rt2500usb_config_intf(struct rt2x00_dev *rt2x00dev,
440 struct rt2x00_intf *intf,
441 struct rt2x00intf_conf *conf,
442 const unsigned int flags)
444 unsigned int bcn_preload;
447 if (flags & CONFIG_UPDATE_TYPE) {
449 * Enable beacon config
451 bcn_preload = PREAMBLE + GET_DURATION(IEEE80211_HEADER, 20);
452 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, ®);
453 rt2x00_set_field16(®, TXRX_CSR20_OFFSET, bcn_preload >> 6);
454 rt2x00_set_field16(®, TXRX_CSR20_BCN_EXPECT_WINDOW,
455 2 * (conf->type != NL80211_IFTYPE_STATION));
456 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
459 * Enable synchronisation.
461 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, ®);
462 rt2x00_set_field16(®, TXRX_CSR18_OFFSET, 0);
463 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
465 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
466 rt2x00_set_field16(®, TXRX_CSR19_TSF_COUNT, 1);
467 rt2x00_set_field16(®, TXRX_CSR19_TSF_SYNC, conf->sync);
468 rt2x00_set_field16(®, TXRX_CSR19_TBCN, 1);
469 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
472 if (flags & CONFIG_UPDATE_MAC)
473 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, conf->mac,
474 (3 * sizeof(__le16)));
476 if (flags & CONFIG_UPDATE_BSSID)
477 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, conf->bssid,
478 (3 * sizeof(__le16)));
481 static void rt2500usb_config_erp(struct rt2x00_dev *rt2x00dev,
482 struct rt2x00lib_erp *erp)
486 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, ®);
487 rt2x00_set_field16(®, TXRX_CSR1_ACK_TIMEOUT, erp->ack_timeout);
488 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
490 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, ®);
491 rt2x00_set_field16(®, TXRX_CSR10_AUTORESPOND_PREAMBLE,
492 !!erp->short_preamble);
493 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
495 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, erp->basic_rates);
497 rt2500usb_register_write(rt2x00dev, MAC_CSR10, erp->slot_time);
498 rt2500usb_register_write(rt2x00dev, MAC_CSR11, erp->sifs);
499 rt2500usb_register_write(rt2x00dev, MAC_CSR12, erp->eifs);
502 static void rt2500usb_config_ant(struct rt2x00_dev *rt2x00dev,
503 struct antenna_setup *ant)
511 * We should never come here because rt2x00lib is supposed
512 * to catch this and send us the correct antenna explicitely.
514 BUG_ON(ant->rx == ANTENNA_SW_DIVERSITY ||
515 ant->tx == ANTENNA_SW_DIVERSITY);
517 rt2500usb_bbp_read(rt2x00dev, 2, &r2);
518 rt2500usb_bbp_read(rt2x00dev, 14, &r14);
519 rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
520 rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
523 * Configure the TX antenna.
526 case ANTENNA_HW_DIVERSITY:
527 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
528 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
529 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
532 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
533 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
534 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
538 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
539 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
540 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
545 * Configure the RX antenna.
548 case ANTENNA_HW_DIVERSITY:
549 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
552 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
556 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
561 * RT2525E and RT5222 need to flip TX I/Q
563 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
564 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
565 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
566 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
567 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
570 * RT2525E does not need RX I/Q Flip.
572 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
573 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
575 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
576 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
579 rt2500usb_bbp_write(rt2x00dev, 2, r2);
580 rt2500usb_bbp_write(rt2x00dev, 14, r14);
581 rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
582 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
585 static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
586 struct rf_channel *rf, const int txpower)
591 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
594 * For RT2525E we should first set the channel to half band higher.
596 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
597 static const u32 vals[] = {
598 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
599 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
600 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
601 0x00000902, 0x00000906
604 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
606 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
609 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
610 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
611 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
613 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
616 static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
621 rt2x00_rf_read(rt2x00dev, 3, &rf3);
622 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
623 rt2500usb_rf_write(rt2x00dev, 3, rf3);
626 static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
627 struct rt2x00lib_conf *libconf)
631 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, ®);
632 rt2x00_set_field16(®, TXRX_CSR18_INTERVAL,
633 libconf->conf->beacon_int * 4);
634 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
637 static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
638 struct rt2x00lib_conf *libconf,
639 const unsigned int flags)
641 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
642 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
643 libconf->conf->power_level);
644 if ((flags & IEEE80211_CONF_CHANGE_POWER) &&
645 !(flags & IEEE80211_CONF_CHANGE_CHANNEL))
646 rt2500usb_config_txpower(rt2x00dev,
647 libconf->conf->power_level);
648 if (flags & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
649 rt2500usb_config_duration(rt2x00dev, libconf);
655 static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
656 struct link_qual *qual)
661 * Update FCS error count from register.
663 rt2500usb_register_read(rt2x00dev, STA_CSR0, ®);
664 qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
667 * Update False CCA count from register.
669 rt2500usb_register_read(rt2x00dev, STA_CSR3, ®);
670 qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
673 static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
678 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
679 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
680 rt2500usb_bbp_write(rt2x00dev, 24, value);
682 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
683 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
684 rt2500usb_bbp_write(rt2x00dev, 25, value);
686 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
687 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
688 rt2500usb_bbp_write(rt2x00dev, 61, value);
690 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
691 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
692 rt2500usb_bbp_write(rt2x00dev, 17, value);
694 rt2x00dev->link.vgc_level = value;
698 * NOTE: This function is directly ported from legacy driver, but
699 * despite it being declared it was never called. Although link tuning
700 * sounds like a good idea, and usually works well for the other drivers,
701 * it does _not_ work with rt2500usb. Enabling this function will result
702 * in TX capabilities only until association kicks in. Immediately
703 * after the successful association all TX frames will be kept in the
704 * hardware queue and never transmitted.
707 static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
709 int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
722 * Read current r17 value, as well as the sensitivity values
723 * for the r17 register.
725 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
726 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
728 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
729 up_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
730 low_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCLOWER);
733 * If we are not associated, we should go straight to the
734 * dynamic CCA tuning.
736 if (!rt2x00dev->intf_associated)
737 goto dynamic_cca_tune;
740 * Determine the BBP tuning threshold and correctly
741 * set BBP 24, 25 and 61.
743 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
744 bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
746 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
747 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
748 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
750 if ((rssi + bbp_thresh) > 0) {
751 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
752 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
753 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
755 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
756 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
757 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
760 rt2500usb_bbp_write(rt2x00dev, 24, r24);
761 rt2500usb_bbp_write(rt2x00dev, 25, r25);
762 rt2500usb_bbp_write(rt2x00dev, 61, r61);
765 * A too low RSSI will cause too much false CCA which will
766 * then corrupt the R17 tuning. To remidy this the tuning should
767 * be stopped (While making sure the R17 value will not exceed limits)
771 rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
776 * Special big-R17 for short distance
779 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
781 rt2500usb_bbp_write(rt2x00dev, 17, sens);
786 * Special mid-R17 for middle distance
789 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
791 rt2500usb_bbp_write(rt2x00dev, 17, sens);
796 * Leave short or middle distance condition, restore r17
797 * to the dynamic tuning range.
801 up_bound -= (-77 - rssi);
803 if (up_bound < low_bound)
804 up_bound = low_bound;
806 if (r17 > up_bound) {
807 rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
808 rt2x00dev->link.vgc_level = up_bound;
815 * R17 is inside the dynamic tuning range,
816 * start tuning the link based on the false cca counter.
818 if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
819 rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
820 rt2x00dev->link.vgc_level = r17;
821 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
822 rt2500usb_bbp_write(rt2x00dev, 17, --r17);
823 rt2x00dev->link.vgc_level = r17;
827 #define rt2500usb_link_tuner NULL
831 * Initialization functions.
833 static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
837 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
838 USB_MODE_TEST, REGISTER_TIMEOUT);
839 rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
840 0x00f0, REGISTER_TIMEOUT);
842 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
843 rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX, 1);
844 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
846 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
847 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
849 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
850 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 1);
851 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 1);
852 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 0);
853 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
855 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
856 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 0);
857 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 0);
858 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 0);
859 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
861 rt2500usb_register_read(rt2x00dev, TXRX_CSR5, ®);
862 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID0, 13);
863 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID0_VALID, 1);
864 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID1, 12);
865 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID1_VALID, 1);
866 rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
868 rt2500usb_register_read(rt2x00dev, TXRX_CSR6, ®);
869 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID0, 10);
870 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID0_VALID, 1);
871 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID1, 11);
872 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID1_VALID, 1);
873 rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
875 rt2500usb_register_read(rt2x00dev, TXRX_CSR7, ®);
876 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID0, 7);
877 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID0_VALID, 1);
878 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID1, 6);
879 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID1_VALID, 1);
880 rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
882 rt2500usb_register_read(rt2x00dev, TXRX_CSR8, ®);
883 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID0, 5);
884 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID0_VALID, 1);
885 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID1, 0);
886 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID1_VALID, 0);
887 rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
889 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
890 rt2x00_set_field16(®, TXRX_CSR19_TSF_COUNT, 0);
891 rt2x00_set_field16(®, TXRX_CSR19_TSF_SYNC, 0);
892 rt2x00_set_field16(®, TXRX_CSR19_TBCN, 0);
893 rt2x00_set_field16(®, TXRX_CSR19_BEACON_GEN, 0);
894 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
896 rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
897 rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
899 if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
902 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
903 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 0);
904 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 0);
905 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 1);
906 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
908 if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
909 rt2500usb_register_read(rt2x00dev, PHY_CSR2, ®);
910 rt2x00_set_field16(®, PHY_CSR2_LNA, 0);
913 rt2x00_set_field16(®, PHY_CSR2_LNA, 1);
914 rt2x00_set_field16(®, PHY_CSR2_LNA_MODE, 3);
916 rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
918 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
919 rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
920 rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
921 rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
923 rt2500usb_register_read(rt2x00dev, MAC_CSR8, ®);
924 rt2x00_set_field16(®, MAC_CSR8_MAX_FRAME_UNIT,
925 rt2x00dev->rx->data_size);
926 rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
928 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, ®);
929 rt2x00_set_field16(®, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
930 rt2x00_set_field16(®, TXRX_CSR0_KEY_ID, 0);
931 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
933 rt2500usb_register_read(rt2x00dev, MAC_CSR18, ®);
934 rt2x00_set_field16(®, MAC_CSR18_DELAY_AFTER_BEACON, 90);
935 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
937 rt2500usb_register_read(rt2x00dev, PHY_CSR4, ®);
938 rt2x00_set_field16(®, PHY_CSR4_LOW_RF_LE, 1);
939 rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
941 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, ®);
942 rt2x00_set_field16(®, TXRX_CSR1_AUTO_SEQUENCE, 1);
943 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
948 static int rt2500usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
953 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
954 rt2500usb_bbp_read(rt2x00dev, 0, &value);
955 if ((value != 0xff) && (value != 0x00))
957 udelay(REGISTER_BUSY_DELAY);
960 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
964 static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
971 if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev)))
974 rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
975 rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
976 rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
977 rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
978 rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
979 rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
980 rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
981 rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
982 rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
983 rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
984 rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
985 rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
986 rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
987 rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
988 rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
989 rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
990 rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
991 rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
992 rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
993 rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
994 rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
995 rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
996 rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
997 rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
998 rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
999 rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
1000 rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
1001 rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
1002 rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
1003 rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
1004 rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
1006 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1007 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1009 if (eeprom != 0xffff && eeprom != 0x0000) {
1010 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1011 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1012 rt2500usb_bbp_write(rt2x00dev, reg_id, value);
1020 * Device state switch handlers.
1022 static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1023 enum dev_state state)
1027 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
1028 rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX,
1029 (state == STATE_RADIO_RX_OFF) ||
1030 (state == STATE_RADIO_RX_OFF_LINK));
1031 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
1034 static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1037 * Initialize all registers.
1039 if (unlikely(rt2500usb_init_registers(rt2x00dev) ||
1040 rt2500usb_init_bbp(rt2x00dev)))
1046 static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
1048 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
1049 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
1052 * Disable synchronisation.
1054 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1056 rt2x00usb_disable_radio(rt2x00dev);
1059 static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
1060 enum dev_state state)
1069 put_to_sleep = (state != STATE_AWAKE);
1072 rt2x00_set_field16(®, MAC_CSR17_BBP_DESIRE_STATE, state);
1073 rt2x00_set_field16(®, MAC_CSR17_RF_DESIRE_STATE, state);
1074 rt2x00_set_field16(®, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
1075 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1076 rt2x00_set_field16(®, MAC_CSR17_SET_STATE, 1);
1077 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1080 * Device is not guaranteed to be in the requested state yet.
1081 * We must wait until the register indicates that the
1082 * device has entered the correct state.
1084 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1085 rt2500usb_register_read(rt2x00dev, MAC_CSR17, ®2);
1086 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
1087 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
1088 if (bbp_state == state && rf_state == state)
1090 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
1097 static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1098 enum dev_state state)
1103 case STATE_RADIO_ON:
1104 retval = rt2500usb_enable_radio(rt2x00dev);
1106 case STATE_RADIO_OFF:
1107 rt2500usb_disable_radio(rt2x00dev);
1109 case STATE_RADIO_RX_ON:
1110 case STATE_RADIO_RX_ON_LINK:
1111 case STATE_RADIO_RX_OFF:
1112 case STATE_RADIO_RX_OFF_LINK:
1113 rt2500usb_toggle_rx(rt2x00dev, state);
1115 case STATE_RADIO_IRQ_ON:
1116 case STATE_RADIO_IRQ_OFF:
1117 /* No support, but no error either */
1119 case STATE_DEEP_SLEEP:
1123 retval = rt2500usb_set_state(rt2x00dev, state);
1130 if (unlikely(retval))
1131 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1138 * TX descriptor initialization
1140 static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1141 struct sk_buff *skb,
1142 struct txentry_desc *txdesc)
1144 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
1145 __le32 *txd = skbdesc->desc;
1149 * Start writing the descriptor words.
1151 rt2x00_desc_read(txd, 1, &word);
1152 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, txdesc->iv_offset);
1153 rt2x00_set_field32(&word, TXD_W1_AIFS, txdesc->aifs);
1154 rt2x00_set_field32(&word, TXD_W1_CWMIN, txdesc->cw_min);
1155 rt2x00_set_field32(&word, TXD_W1_CWMAX, txdesc->cw_max);
1156 rt2x00_desc_write(txd, 1, word);
1158 rt2x00_desc_read(txd, 2, &word);
1159 rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, txdesc->signal);
1160 rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, txdesc->service);
1161 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, txdesc->length_low);
1162 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, txdesc->length_high);
1163 rt2x00_desc_write(txd, 2, word);
1165 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1166 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1167 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1170 rt2x00_desc_read(txd, 0, &word);
1171 rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, txdesc->retry_limit);
1172 rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
1173 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
1174 rt2x00_set_field32(&word, TXD_W0_ACK,
1175 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
1176 rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
1177 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
1178 rt2x00_set_field32(&word, TXD_W0_OFDM,
1179 test_bit(ENTRY_TXD_OFDM_RATE, &txdesc->flags));
1180 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
1181 test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags));
1182 rt2x00_set_field32(&word, TXD_W0_IFS, txdesc->ifs);
1183 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skb->len);
1184 rt2x00_set_field32(&word, TXD_W0_CIPHER, txdesc->cipher);
1185 rt2x00_set_field32(&word, TXD_W0_KEY_ID, txdesc->key_idx);
1186 rt2x00_desc_write(txd, 0, word);
1190 * TX data initialization
1192 static void rt2500usb_beacondone(struct urb *urb);
1194 static void rt2500usb_write_beacon(struct queue_entry *entry)
1196 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1197 struct usb_device *usb_dev = to_usb_device_intf(rt2x00dev->dev);
1198 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1199 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1200 int pipe = usb_sndbulkpipe(usb_dev, entry->queue->usb_endpoint);
1205 * Add the descriptor in front of the skb.
1207 skb_push(entry->skb, entry->queue->desc_size);
1208 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
1209 skbdesc->desc = entry->skb->data;
1212 * Disable beaconing while we are reloading the beacon data,
1213 * otherwise we might be sending out invalid data.
1215 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
1216 rt2x00_set_field16(®, TXRX_CSR19_TSF_COUNT, 0);
1217 rt2x00_set_field16(®, TXRX_CSR19_TBCN, 0);
1218 rt2x00_set_field16(®, TXRX_CSR19_BEACON_GEN, 0);
1219 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1222 * USB devices cannot blindly pass the skb->len as the
1223 * length of the data to usb_fill_bulk_urb. Pass the skb
1224 * to the driver to determine what the length should be.
1226 length = rt2x00dev->ops->lib->get_tx_data_len(entry);
1228 usb_fill_bulk_urb(bcn_priv->urb, usb_dev, pipe,
1229 entry->skb->data, length, rt2500usb_beacondone,
1233 * Second we need to create the guardian byte.
1234 * We only need a single byte, so lets recycle
1235 * the 'flags' field we are not using for beacons.
1237 bcn_priv->guardian_data = 0;
1238 usb_fill_bulk_urb(bcn_priv->guardian_urb, usb_dev, pipe,
1239 &bcn_priv->guardian_data, 1, rt2500usb_beacondone,
1243 * Send out the guardian byte.
1245 usb_submit_urb(bcn_priv->guardian_urb, GFP_ATOMIC);
1248 static int rt2500usb_get_tx_data_len(struct queue_entry *entry)
1253 * The length _must_ be a multiple of 2,
1254 * but it must _not_ be a multiple of the USB packet size.
1256 length = roundup(entry->skb->len, 2);
1257 length += (2 * !(length % entry->queue->usb_maxpacket));
1262 static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1263 const enum data_queue_qid queue)
1267 if (queue != QID_BEACON) {
1268 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
1272 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
1273 if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
1274 rt2x00_set_field16(®, TXRX_CSR19_TSF_COUNT, 1);
1275 rt2x00_set_field16(®, TXRX_CSR19_TBCN, 1);
1276 rt2x00_set_field16(®, TXRX_CSR19_BEACON_GEN, 1);
1278 * Beacon generation will fail initially.
1279 * To prevent this we need to register the TXRX_CSR19
1280 * register several times.
1282 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1283 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1284 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1285 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1286 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1291 * RX control handlers
1293 static void rt2500usb_fill_rxdone(struct queue_entry *entry,
1294 struct rxdone_entry_desc *rxdesc)
1296 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
1297 struct queue_entry_priv_usb *entry_priv = entry->priv_data;
1298 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
1300 (__le32 *)(entry->skb->data +
1301 (entry_priv->urb->actual_length -
1302 entry->queue->desc_size));
1307 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1308 * frame data in rt2x00usb.
1310 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
1311 rxd = (__le32 *)skbdesc->desc;
1314 * It is now safe to read the descriptor on all architectures.
1316 rt2x00_desc_read(rxd, 0, &word0);
1317 rt2x00_desc_read(rxd, 1, &word1);
1319 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1320 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
1321 if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
1322 rxdesc->flags |= RX_FLAG_FAILED_PLCP_CRC;
1324 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
1325 rxdesc->cipher = rt2x00_get_field32(word0, RXD_W0_CIPHER);
1326 if (rt2x00_get_field32(word0, RXD_W0_CIPHER_ERROR))
1327 rxdesc->cipher_status = RX_CRYPTO_FAIL_KEY;
1330 if (rxdesc->cipher != CIPHER_NONE) {
1331 _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
1332 _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
1333 /* ICV is located at the end of frame */
1336 * Hardware has stripped IV/EIV data from 802.11 frame during
1337 * decryption. It has provided the data seperately but rt2x00lib
1338 * should decide if it should be reinserted.
1340 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
1341 if (rxdesc->cipher != CIPHER_TKIP)
1342 rxdesc->flags |= RX_FLAG_MMIC_STRIPPED;
1343 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
1344 rxdesc->flags |= RX_FLAG_DECRYPTED;
1345 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
1346 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
1350 * Obtain the status about this packet.
1351 * When frame was received with an OFDM bitrate,
1352 * the signal is the PLCP value. If it was received with
1353 * a CCK bitrate the signal is the rate in 100kbit/s.
1355 rxdesc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1357 rt2x00_get_field32(word1, RXD_W1_RSSI) - rt2x00dev->rssi_offset;
1358 rxdesc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
1360 if (rt2x00_get_field32(word0, RXD_W0_OFDM))
1361 rxdesc->dev_flags |= RXDONE_SIGNAL_PLCP;
1363 rxdesc->dev_flags |= RXDONE_SIGNAL_BITRATE;
1364 if (rt2x00_get_field32(word0, RXD_W0_MY_BSS))
1365 rxdesc->dev_flags |= RXDONE_MY_BSS;
1368 * Adjust the skb memory window to the frame boundaries.
1370 skb_trim(entry->skb, rxdesc->size);
1374 * Interrupt functions.
1376 static void rt2500usb_beacondone(struct urb *urb)
1378 struct queue_entry *entry = (struct queue_entry *)urb->context;
1379 struct queue_entry_priv_usb_bcn *bcn_priv = entry->priv_data;
1381 if (!test_bit(DEVICE_STATE_ENABLED_RADIO, &entry->queue->rt2x00dev->flags))
1385 * Check if this was the guardian beacon,
1386 * if that was the case we need to send the real beacon now.
1387 * Otherwise we should free the sk_buffer, the device
1388 * should be doing the rest of the work now.
1390 if (bcn_priv->guardian_urb == urb) {
1391 usb_submit_urb(bcn_priv->urb, GFP_ATOMIC);
1392 } else if (bcn_priv->urb == urb) {
1393 dev_kfree_skb(entry->skb);
1399 * Device probe functions.
1401 static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1407 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1410 * Start validation of the data that has been read.
1412 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1413 if (!is_valid_ether_addr(mac)) {
1414 random_ether_addr(mac);
1415 EEPROM(rt2x00dev, "MAC: %pM\n", mac);
1418 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1419 if (word == 0xffff) {
1420 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
1421 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1422 ANTENNA_SW_DIVERSITY);
1423 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1424 ANTENNA_SW_DIVERSITY);
1425 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1427 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1428 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1429 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1430 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1431 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1434 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1435 if (word == 0xffff) {
1436 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1437 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1438 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1439 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1440 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1443 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1444 if (word == 0xffff) {
1445 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1446 DEFAULT_RSSI_OFFSET);
1447 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1448 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1451 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1452 if (word == 0xffff) {
1453 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1454 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1455 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1459 * Switch lower vgc bound to current BBP R17 value,
1460 * lower the value a bit for better quality.
1462 rt2500usb_bbp_read(rt2x00dev, 17, &bbp);
1465 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1466 if (word == 0xffff) {
1467 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
1468 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1469 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1470 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
1472 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCLOWER, bbp);
1473 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1476 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1477 if (word == 0xffff) {
1478 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1479 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1480 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1481 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1484 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1485 if (word == 0xffff) {
1486 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1487 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1488 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1489 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1492 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1493 if (word == 0xffff) {
1494 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1495 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1496 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1497 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1500 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1501 if (word == 0xffff) {
1502 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1503 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1504 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1505 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1511 static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1518 * Read EEPROM word for configuration.
1520 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1523 * Identify RF chipset.
1525 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1526 rt2500usb_register_read(rt2x00dev, MAC_CSR0, ®);
1527 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1529 if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
1530 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1534 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1535 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
1536 !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
1537 !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
1538 !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
1539 !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1540 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1545 * Identify default antenna configuration.
1547 rt2x00dev->default_ant.tx =
1548 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
1549 rt2x00dev->default_ant.rx =
1550 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1553 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1554 * I am not 100% sure about this, but the legacy drivers do not
1555 * indicate antenna swapping in software is required when
1556 * diversity is enabled.
1558 if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1559 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1560 if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1561 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1564 * Store led mode, for correct led behaviour.
1566 #ifdef CONFIG_RT2X00_LIB_LEDS
1567 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1569 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
1570 if (value == LED_MODE_TXRX_ACTIVITY)
1571 rt2500usb_init_led(rt2x00dev, &rt2x00dev->led_qual,
1573 #endif /* CONFIG_RT2X00_LIB_LEDS */
1576 * Check if the BBP tuning should be disabled.
1578 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1579 if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
1580 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1583 * Read the RSSI <-> dBm offset information.
1585 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1586 rt2x00dev->rssi_offset =
1587 rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1593 * RF value list for RF2522
1596 static const struct rf_channel rf_vals_bg_2522[] = {
1597 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1598 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1599 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1600 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1601 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1602 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1603 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1604 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1605 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1606 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1607 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1608 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1609 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1610 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1614 * RF value list for RF2523
1617 static const struct rf_channel rf_vals_bg_2523[] = {
1618 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1619 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1620 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1621 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1622 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1623 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1624 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1625 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1626 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1627 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1628 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1629 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1630 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1631 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1635 * RF value list for RF2524
1638 static const struct rf_channel rf_vals_bg_2524[] = {
1639 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1640 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1641 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1642 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1643 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1644 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1645 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1646 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1647 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1648 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1649 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1650 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1651 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1652 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1656 * RF value list for RF2525
1659 static const struct rf_channel rf_vals_bg_2525[] = {
1660 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1661 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1662 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1663 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1664 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1665 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1666 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1667 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1668 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1669 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1670 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1671 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1672 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1673 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1677 * RF value list for RF2525e
1680 static const struct rf_channel rf_vals_bg_2525e[] = {
1681 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1682 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1683 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1684 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1685 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1686 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1687 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1688 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1689 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1690 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1691 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1692 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1693 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1694 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1698 * RF value list for RF5222
1699 * Supports: 2.4 GHz & 5.2 GHz
1701 static const struct rf_channel rf_vals_5222[] = {
1702 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1703 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1704 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1705 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1706 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1707 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1708 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1709 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1710 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1711 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1712 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1713 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1714 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1715 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1717 /* 802.11 UNI / HyperLan 2 */
1718 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1719 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1720 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1721 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1722 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1723 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1724 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1725 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1727 /* 802.11 HyperLan 2 */
1728 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1729 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1730 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1731 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1732 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1733 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1734 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1735 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1736 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1737 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1740 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1741 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1742 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1743 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1744 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1747 static int rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1749 struct hw_mode_spec *spec = &rt2x00dev->spec;
1750 struct channel_info *info;
1755 * Initialize all hw fields.
1757 rt2x00dev->hw->flags =
1758 IEEE80211_HW_RX_INCLUDES_FCS |
1759 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
1760 IEEE80211_HW_SIGNAL_DBM;
1762 rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
1764 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
1765 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1766 rt2x00_eeprom_addr(rt2x00dev,
1767 EEPROM_MAC_ADDR_0));
1770 * Initialize hw_mode information.
1772 spec->supported_bands = SUPPORT_BAND_2GHZ;
1773 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
1775 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1776 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1777 spec->channels = rf_vals_bg_2522;
1778 } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
1779 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1780 spec->channels = rf_vals_bg_2523;
1781 } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
1782 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1783 spec->channels = rf_vals_bg_2524;
1784 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
1785 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1786 spec->channels = rf_vals_bg_2525;
1787 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
1788 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1789 spec->channels = rf_vals_bg_2525e;
1790 } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1791 spec->supported_bands |= SUPPORT_BAND_5GHZ;
1792 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1793 spec->channels = rf_vals_5222;
1797 * Create channel information array
1799 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
1803 spec->channels_info = info;
1805 tx_power = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1806 for (i = 0; i < 14; i++)
1807 info[i].tx_power1 = TXPOWER_FROM_DEV(tx_power[i]);
1809 if (spec->num_channels > 14) {
1810 for (i = 14; i < spec->num_channels; i++)
1811 info[i].tx_power1 = DEFAULT_TXPOWER;
1817 static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1822 * Allocate eeprom data.
1824 retval = rt2500usb_validate_eeprom(rt2x00dev);
1828 retval = rt2500usb_init_eeprom(rt2x00dev);
1833 * Initialize hw specifications.
1835 retval = rt2500usb_probe_hw_mode(rt2x00dev);
1840 * This device requires the atim queue
1842 __set_bit(DRIVER_REQUIRE_ATIM_QUEUE, &rt2x00dev->flags);
1843 __set_bit(DRIVER_REQUIRE_BEACON_GUARD, &rt2x00dev->flags);
1844 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
1845 if (!modparam_nohwcrypt) {
1846 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
1847 __set_bit(CONFIG_CRYPTO_COPY_IV, &rt2x00dev->flags);
1849 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1852 * Set the rssi offset.
1854 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1859 static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1861 .start = rt2x00mac_start,
1862 .stop = rt2x00mac_stop,
1863 .add_interface = rt2x00mac_add_interface,
1864 .remove_interface = rt2x00mac_remove_interface,
1865 .config = rt2x00mac_config,
1866 .config_interface = rt2x00mac_config_interface,
1867 .configure_filter = rt2x00mac_configure_filter,
1868 .set_key = rt2x00mac_set_key,
1869 .get_stats = rt2x00mac_get_stats,
1870 .bss_info_changed = rt2x00mac_bss_info_changed,
1871 .conf_tx = rt2x00mac_conf_tx,
1872 .get_tx_stats = rt2x00mac_get_tx_stats,
1875 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1876 .probe_hw = rt2500usb_probe_hw,
1877 .initialize = rt2x00usb_initialize,
1878 .uninitialize = rt2x00usb_uninitialize,
1879 .clear_entry = rt2x00usb_clear_entry,
1880 .set_device_state = rt2500usb_set_device_state,
1881 .link_stats = rt2500usb_link_stats,
1882 .reset_tuner = rt2500usb_reset_tuner,
1883 .link_tuner = rt2500usb_link_tuner,
1884 .write_tx_desc = rt2500usb_write_tx_desc,
1885 .write_tx_data = rt2x00usb_write_tx_data,
1886 .write_beacon = rt2500usb_write_beacon,
1887 .get_tx_data_len = rt2500usb_get_tx_data_len,
1888 .kick_tx_queue = rt2500usb_kick_tx_queue,
1889 .fill_rxdone = rt2500usb_fill_rxdone,
1890 .config_shared_key = rt2500usb_config_key,
1891 .config_pairwise_key = rt2500usb_config_key,
1892 .config_filter = rt2500usb_config_filter,
1893 .config_intf = rt2500usb_config_intf,
1894 .config_erp = rt2500usb_config_erp,
1895 .config_ant = rt2500usb_config_ant,
1896 .config = rt2500usb_config,
1899 static const struct data_queue_desc rt2500usb_queue_rx = {
1900 .entry_num = RX_ENTRIES,
1901 .data_size = DATA_FRAME_SIZE,
1902 .desc_size = RXD_DESC_SIZE,
1903 .priv_size = sizeof(struct queue_entry_priv_usb),
1906 static const struct data_queue_desc rt2500usb_queue_tx = {
1907 .entry_num = TX_ENTRIES,
1908 .data_size = DATA_FRAME_SIZE,
1909 .desc_size = TXD_DESC_SIZE,
1910 .priv_size = sizeof(struct queue_entry_priv_usb),
1913 static const struct data_queue_desc rt2500usb_queue_bcn = {
1914 .entry_num = BEACON_ENTRIES,
1915 .data_size = MGMT_FRAME_SIZE,
1916 .desc_size = TXD_DESC_SIZE,
1917 .priv_size = sizeof(struct queue_entry_priv_usb_bcn),
1920 static const struct data_queue_desc rt2500usb_queue_atim = {
1921 .entry_num = ATIM_ENTRIES,
1922 .data_size = DATA_FRAME_SIZE,
1923 .desc_size = TXD_DESC_SIZE,
1924 .priv_size = sizeof(struct queue_entry_priv_usb),
1927 static const struct rt2x00_ops rt2500usb_ops = {
1928 .name = KBUILD_MODNAME,
1931 .eeprom_size = EEPROM_SIZE,
1933 .tx_queues = NUM_TX_QUEUES,
1934 .rx = &rt2500usb_queue_rx,
1935 .tx = &rt2500usb_queue_tx,
1936 .bcn = &rt2500usb_queue_bcn,
1937 .atim = &rt2500usb_queue_atim,
1938 .lib = &rt2500usb_rt2x00_ops,
1939 .hw = &rt2500usb_mac80211_ops,
1940 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1941 .debugfs = &rt2500usb_rt2x00debug,
1942 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1946 * rt2500usb module information.
1948 static struct usb_device_id rt2500usb_device_table[] = {
1950 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1951 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1953 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
1954 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
1955 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
1957 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
1958 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
1959 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
1961 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
1963 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
1965 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
1966 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
1968 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
1970 { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
1971 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
1972 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
1973 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
1974 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
1976 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
1977 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
1978 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
1980 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1981 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
1982 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
1983 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1985 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
1987 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
1989 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
1991 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1993 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
1997 MODULE_AUTHOR(DRV_PROJECT);
1998 MODULE_VERSION(DRV_VERSION);
1999 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
2000 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
2001 MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
2002 MODULE_LICENSE("GPL");
2004 static struct usb_driver rt2500usb_driver = {
2005 .name = KBUILD_MODNAME,
2006 .id_table = rt2500usb_device_table,
2007 .probe = rt2x00usb_probe,
2008 .disconnect = rt2x00usb_disconnect,
2009 .suspend = rt2x00usb_suspend,
2010 .resume = rt2x00usb_resume,
2013 static int __init rt2500usb_init(void)
2015 return usb_register(&rt2500usb_driver);
2018 static void __exit rt2500usb_exit(void)
2020 usb_deregister(&rt2500usb_driver);
2023 module_init(rt2500usb_init);
2024 module_exit(rt2500usb_exit);