2 Copyright (C) 2004 - 2009 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: rt2800usb device specific routines.
24 Supported chipsets: RT2800U.
27 #include <linux/crc-ccitt.h>
28 #include <linux/delay.h>
29 #include <linux/etherdevice.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
32 #include <linux/module.h>
33 #include <linux/usb.h>
36 #include "rt2x00usb.h"
37 #include "rt2800usb.h"
40 * Allow hardware encryption to be disabled.
42 static int modparam_nohwcrypt = 1;
43 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
44 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
48 * All access to the CSR registers will go through the methods
49 * rt2x00usb_register_read and rt2x00usb_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 * The _lock versions must be used if you already hold the csr_mutex
60 #define WAIT_FOR_BBP(__dev, __reg) \
61 rt2x00usb_regbusy_read((__dev), BBP_CSR_CFG, BBP_CSR_CFG_BUSY, (__reg))
62 #define WAIT_FOR_RFCSR(__dev, __reg) \
63 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG, RF_CSR_CFG_BUSY, (__reg))
64 #define WAIT_FOR_RF(__dev, __reg) \
65 rt2x00usb_regbusy_read((__dev), RF_CSR_CFG0, RF_CSR_CFG0_BUSY, (__reg))
66 #define WAIT_FOR_MCU(__dev, __reg) \
67 rt2x00usb_regbusy_read((__dev), H2M_MAILBOX_CSR, \
68 H2M_MAILBOX_CSR_OWNER, (__reg))
70 static void rt2800usb_bbp_write(struct rt2x00_dev *rt2x00dev,
71 const unsigned int word, const u8 value)
75 mutex_lock(&rt2x00dev->csr_mutex);
78 * Wait until the BBP becomes available, afterwards we
79 * can safely write the new data into the register.
81 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
83 rt2x00_set_field32(®, BBP_CSR_CFG_VALUE, value);
84 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
85 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
86 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 0);
88 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
91 mutex_unlock(&rt2x00dev->csr_mutex);
94 static void rt2800usb_bbp_read(struct rt2x00_dev *rt2x00dev,
95 const unsigned int word, u8 *value)
99 mutex_lock(&rt2x00dev->csr_mutex);
102 * Wait until the BBP becomes available, afterwards we
103 * can safely write the read request into the register.
104 * After the data has been written, we wait until hardware
105 * returns the correct value, if at any time the register
106 * doesn't become available in time, reg will be 0xffffffff
107 * which means we return 0xff to the caller.
109 if (WAIT_FOR_BBP(rt2x00dev, ®)) {
111 rt2x00_set_field32(®, BBP_CSR_CFG_REGNUM, word);
112 rt2x00_set_field32(®, BBP_CSR_CFG_BUSY, 1);
113 rt2x00_set_field32(®, BBP_CSR_CFG_READ_CONTROL, 1);
115 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
117 WAIT_FOR_BBP(rt2x00dev, ®);
120 *value = rt2x00_get_field32(reg, BBP_CSR_CFG_VALUE);
122 mutex_unlock(&rt2x00dev->csr_mutex);
125 static void rt2800usb_rfcsr_write(struct rt2x00_dev *rt2x00dev,
126 const unsigned int word, const u8 value)
130 mutex_lock(&rt2x00dev->csr_mutex);
133 * Wait until the RFCSR becomes available, afterwards we
134 * can safely write the new data into the register.
136 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
138 rt2x00_set_field32(®, RF_CSR_CFG_DATA, value);
139 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
140 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 1);
141 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
143 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG, reg);
146 mutex_unlock(&rt2x00dev->csr_mutex);
149 static void rt2800usb_rfcsr_read(struct rt2x00_dev *rt2x00dev,
150 const unsigned int word, u8 *value)
154 mutex_lock(&rt2x00dev->csr_mutex);
157 * Wait until the RFCSR becomes available, afterwards we
158 * can safely write the read request into the register.
159 * After the data has been written, we wait until hardware
160 * returns the correct value, if at any time the register
161 * doesn't become available in time, reg will be 0xffffffff
162 * which means we return 0xff to the caller.
164 if (WAIT_FOR_RFCSR(rt2x00dev, ®)) {
166 rt2x00_set_field32(®, RF_CSR_CFG_REGNUM, word);
167 rt2x00_set_field32(®, RF_CSR_CFG_WRITE, 0);
168 rt2x00_set_field32(®, RF_CSR_CFG_BUSY, 1);
170 rt2x00usb_register_write_lock(rt2x00dev, BBP_CSR_CFG, reg);
172 WAIT_FOR_RFCSR(rt2x00dev, ®);
175 *value = rt2x00_get_field32(reg, RF_CSR_CFG_DATA);
177 mutex_unlock(&rt2x00dev->csr_mutex);
180 static void rt2800usb_rf_write(struct rt2x00_dev *rt2x00dev,
181 const unsigned int word, const u32 value)
185 mutex_lock(&rt2x00dev->csr_mutex);
188 * Wait until the RF becomes available, afterwards we
189 * can safely write the new data into the register.
191 if (WAIT_FOR_RF(rt2x00dev, ®)) {
193 rt2x00_set_field32(®, RF_CSR_CFG0_REG_VALUE_BW, value);
194 rt2x00_set_field32(®, RF_CSR_CFG0_STANDBYMODE, 0);
195 rt2x00_set_field32(®, RF_CSR_CFG0_SEL, 0);
196 rt2x00_set_field32(®, RF_CSR_CFG0_BUSY, 1);
198 rt2x00usb_register_write_lock(rt2x00dev, RF_CSR_CFG0, reg);
199 rt2x00_rf_write(rt2x00dev, word, value);
202 mutex_unlock(&rt2x00dev->csr_mutex);
205 static void rt2800usb_mcu_request(struct rt2x00_dev *rt2x00dev,
206 const u8 command, const u8 token,
207 const u8 arg0, const u8 arg1)
211 mutex_lock(&rt2x00dev->csr_mutex);
214 * Wait until the MCU becomes available, afterwards we
215 * can safely write the new data into the register.
217 if (WAIT_FOR_MCU(rt2x00dev, ®)) {
218 rt2x00_set_field32(®, H2M_MAILBOX_CSR_OWNER, 1);
219 rt2x00_set_field32(®, H2M_MAILBOX_CSR_CMD_TOKEN, token);
220 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG0, arg0);
221 rt2x00_set_field32(®, H2M_MAILBOX_CSR_ARG1, arg1);
222 rt2x00usb_register_write_lock(rt2x00dev, H2M_MAILBOX_CSR, reg);
225 rt2x00_set_field32(®, HOST_CMD_CSR_HOST_COMMAND, command);
226 rt2x00usb_register_write_lock(rt2x00dev, HOST_CMD_CSR, reg);
229 mutex_unlock(&rt2x00dev->csr_mutex);
232 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
233 static const struct rt2x00debug rt2800usb_rt2x00debug = {
234 .owner = THIS_MODULE,
236 .read = rt2x00usb_register_read,
237 .write = rt2x00usb_register_write,
238 .flags = RT2X00DEBUGFS_OFFSET,
239 .word_base = CSR_REG_BASE,
240 .word_size = sizeof(u32),
241 .word_count = CSR_REG_SIZE / sizeof(u32),
244 .read = rt2x00_eeprom_read,
245 .write = rt2x00_eeprom_write,
246 .word_base = EEPROM_BASE,
247 .word_size = sizeof(u16),
248 .word_count = EEPROM_SIZE / sizeof(u16),
251 .read = rt2800usb_bbp_read,
252 .write = rt2800usb_bbp_write,
253 .word_base = BBP_BASE,
254 .word_size = sizeof(u8),
255 .word_count = BBP_SIZE / sizeof(u8),
258 .read = rt2x00_rf_read,
259 .write = rt2800usb_rf_write,
260 .word_base = RF_BASE,
261 .word_size = sizeof(u32),
262 .word_count = RF_SIZE / sizeof(u32),
265 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
267 #ifdef CONFIG_RT2X00_LIB_RFKILL
268 static int rt2800usb_rfkill_poll(struct rt2x00_dev *rt2x00dev)
272 rt2x00usb_register_read(rt2x00dev, GPIO_CTRL_CFG, ®);
273 return rt2x00_get_field32(reg, GPIO_CTRL_CFG_BIT2);
276 #define rt2800usb_rfkill_poll NULL
277 #endif /* CONFIG_RT2X00_LIB_RFKILL */
279 #ifdef CONFIG_RT2X00_LIB_LEDS
280 static void rt2800usb_brightness_set(struct led_classdev *led_cdev,
281 enum led_brightness brightness)
283 struct rt2x00_led *led =
284 container_of(led_cdev, struct rt2x00_led, led_dev);
285 unsigned int enabled = brightness != LED_OFF;
286 unsigned int bg_mode =
287 (enabled && led->rt2x00dev->curr_band == IEEE80211_BAND_2GHZ);
288 unsigned int polarity =
289 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
290 EEPROM_FREQ_LED_POLARITY);
291 unsigned int ledmode =
292 rt2x00_get_field16(led->rt2x00dev->led_mcu_reg,
293 EEPROM_FREQ_LED_MODE);
295 if (led->type == LED_TYPE_RADIO) {
296 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
298 } else if (led->type == LED_TYPE_ASSOC) {
299 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED, 0xff, ledmode,
300 enabled ? (bg_mode ? 0x60 : 0xa0) : 0x20);
301 } else if (led->type == LED_TYPE_QUALITY) {
303 * The brightness is divided into 6 levels (0 - 5),
304 * The specs tell us the following levels:
306 * to determine the level in a simple way we can simply
307 * work with bitshifting:
310 rt2800usb_mcu_request(led->rt2x00dev, MCU_LED_STRENGTH, 0xff,
311 (1 << brightness / (LED_FULL / 6)) - 1,
316 static int rt2800usb_blink_set(struct led_classdev *led_cdev,
317 unsigned long *delay_on,
318 unsigned long *delay_off)
320 struct rt2x00_led *led =
321 container_of(led_cdev, struct rt2x00_led, led_dev);
324 rt2x00usb_register_read(led->rt2x00dev, LED_CFG, ®);
325 rt2x00_set_field32(®, LED_CFG_ON_PERIOD, *delay_on);
326 rt2x00_set_field32(®, LED_CFG_OFF_PERIOD, *delay_off);
327 rt2x00_set_field32(®, LED_CFG_SLOW_BLINK_PERIOD, 3);
328 rt2x00_set_field32(®, LED_CFG_R_LED_MODE, 3);
329 rt2x00_set_field32(®, LED_CFG_G_LED_MODE, 12);
330 rt2x00_set_field32(®, LED_CFG_Y_LED_MODE, 3);
331 rt2x00_set_field32(®, LED_CFG_LED_POLAR, 1);
332 rt2x00usb_register_write(led->rt2x00dev, LED_CFG, reg);
337 static void rt2800usb_init_led(struct rt2x00_dev *rt2x00dev,
338 struct rt2x00_led *led,
341 led->rt2x00dev = rt2x00dev;
343 led->led_dev.brightness_set = rt2800usb_brightness_set;
344 led->led_dev.blink_set = rt2800usb_blink_set;
345 led->flags = LED_INITIALIZED;
347 #endif /* CONFIG_RT2X00_LIB_LEDS */
350 * Configuration handlers.
352 static void rt2800usb_config_wcid_attr(struct rt2x00_dev *rt2x00dev,
353 struct rt2x00lib_crypto *crypto,
354 struct ieee80211_key_conf *key)
356 struct mac_wcid_entry wcid_entry;
357 struct mac_iveiv_entry iveiv_entry;
361 offset = MAC_WCID_ATTR_ENTRY(key->hw_key_idx);
363 rt2x00usb_register_read(rt2x00dev, offset, ®);
364 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_KEYTAB,
365 !!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE));
366 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_CIPHER,
367 (crypto->cmd == SET_KEY) * crypto->cipher);
368 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_BSS_IDX,
369 (crypto->cmd == SET_KEY) * crypto->bssidx);
370 rt2x00_set_field32(®, MAC_WCID_ATTRIBUTE_RX_WIUDF, crypto->cipher);
371 rt2x00usb_register_write(rt2x00dev, offset, reg);
373 offset = MAC_IVEIV_ENTRY(key->hw_key_idx);
375 memset(&iveiv_entry, 0, sizeof(iveiv_entry));
376 if ((crypto->cipher == CIPHER_TKIP) ||
377 (crypto->cipher == CIPHER_TKIP_NO_MIC) ||
378 (crypto->cipher == CIPHER_AES))
379 iveiv_entry.iv[3] |= 0x20;
380 iveiv_entry.iv[3] |= key->keyidx << 6;
381 rt2x00usb_register_multiwrite(rt2x00dev, offset,
382 &iveiv_entry, sizeof(iveiv_entry));
384 offset = MAC_WCID_ENTRY(key->hw_key_idx);
386 memset(&wcid_entry, 0, sizeof(wcid_entry));
387 if (crypto->cmd == SET_KEY)
388 memcpy(&wcid_entry, crypto->address, ETH_ALEN);
389 rt2x00usb_register_multiwrite(rt2x00dev, offset,
390 &wcid_entry, sizeof(wcid_entry));
393 static int rt2800usb_config_shared_key(struct rt2x00_dev *rt2x00dev,
394 struct rt2x00lib_crypto *crypto,
395 struct ieee80211_key_conf *key)
397 struct hw_key_entry key_entry;
398 struct rt2x00_field32 field;
403 if (crypto->cmd == SET_KEY) {
404 key->hw_key_idx = (4 * crypto->bssidx) + key->keyidx;
406 memcpy(key_entry.key, crypto->key,
407 sizeof(key_entry.key));
408 memcpy(key_entry.tx_mic, crypto->tx_mic,
409 sizeof(key_entry.tx_mic));
410 memcpy(key_entry.rx_mic, crypto->rx_mic,
411 sizeof(key_entry.rx_mic));
413 offset = SHARED_KEY_ENTRY(key->hw_key_idx);
414 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
415 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
416 USB_VENDOR_REQUEST_OUT,
423 * The cipher types are stored over multiple registers
424 * starting with SHARED_KEY_MODE_BASE each word will have
425 * 32 bits and contains the cipher types for 2 bssidx each.
426 * Using the correct defines correctly will cause overhead,
427 * so just calculate the correct offset.
429 field.bit_offset = 4 * (key->hw_key_idx % 8);
430 field.bit_mask = 0x7 << field.bit_offset;
432 offset = SHARED_KEY_MODE_ENTRY(key->hw_key_idx / 8);
434 rt2x00usb_register_read(rt2x00dev, offset, ®);
435 rt2x00_set_field32(®, field,
436 (crypto->cmd == SET_KEY) * crypto->cipher);
437 rt2x00usb_register_write(rt2x00dev, offset, reg);
440 * Update WCID information
442 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
447 static int rt2800usb_config_pairwise_key(struct rt2x00_dev *rt2x00dev,
448 struct rt2x00lib_crypto *crypto,
449 struct ieee80211_key_conf *key)
451 struct hw_key_entry key_entry;
455 if (crypto->cmd == SET_KEY) {
457 * 1 pairwise key is possible per AID, this means that the AID
458 * equals our hw_key_idx. Make sure the WCID starts _after_ the
459 * last possible shared key entry.
461 if (crypto->aid > (256 - 32))
464 key->hw_key_idx = 32 + crypto->aid;
466 memcpy(key_entry.key, crypto->key,
467 sizeof(key_entry.key));
468 memcpy(key_entry.tx_mic, crypto->tx_mic,
469 sizeof(key_entry.tx_mic));
470 memcpy(key_entry.rx_mic, crypto->rx_mic,
471 sizeof(key_entry.rx_mic));
473 offset = PAIRWISE_KEY_ENTRY(key->hw_key_idx);
474 timeout = REGISTER_TIMEOUT32(sizeof(key_entry));
475 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
476 USB_VENDOR_REQUEST_OUT,
483 * Update WCID information
485 rt2800usb_config_wcid_attr(rt2x00dev, crypto, key);
490 static void rt2800usb_config_filter(struct rt2x00_dev *rt2x00dev,
491 const unsigned int filter_flags)
496 * Start configuration steps.
497 * Note that the version error will always be dropped
498 * and broadcast frames will always be accepted since
499 * there is no filter for it at this time.
501 rt2x00usb_register_read(rt2x00dev, RX_FILTER_CFG, ®);
502 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CRC_ERROR,
503 !(filter_flags & FIF_FCSFAIL));
504 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PHY_ERROR,
505 !(filter_flags & FIF_PLCPFAIL));
506 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_TO_ME,
507 !(filter_flags & FIF_PROMISC_IN_BSS));
508 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_NOT_MY_BSSD, 0);
509 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_VER_ERROR, 1);
510 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_MULTICAST,
511 !(filter_flags & FIF_ALLMULTI));
512 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BROADCAST, 0);
513 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_DUPLICATE, 1);
514 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END_ACK,
515 !(filter_flags & FIF_CONTROL));
516 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CF_END,
517 !(filter_flags & FIF_CONTROL));
518 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_ACK,
519 !(filter_flags & FIF_CONTROL));
520 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CTS,
521 !(filter_flags & FIF_CONTROL));
522 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_RTS,
523 !(filter_flags & FIF_CONTROL));
524 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_PSPOLL,
525 !(filter_flags & FIF_CONTROL));
526 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BA, 1);
527 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_BAR, 0);
528 rt2x00_set_field32(®, RX_FILTER_CFG_DROP_CNTL,
529 !(filter_flags & FIF_CONTROL));
530 rt2x00usb_register_write(rt2x00dev, RX_FILTER_CFG, reg);
533 static void rt2800usb_config_intf(struct rt2x00_dev *rt2x00dev,
534 struct rt2x00_intf *intf,
535 struct rt2x00intf_conf *conf,
536 const unsigned int flags)
538 unsigned int beacon_base;
541 if (flags & CONFIG_UPDATE_TYPE) {
543 * Clear current synchronisation setup.
544 * For the Beacon base registers we only need to clear
545 * the first byte since that byte contains the VALID and OWNER
546 * bits which (when set to 0) will invalidate the entire beacon.
548 beacon_base = HW_BEACON_OFFSET(intf->beacon->entry_idx);
549 rt2x00usb_register_write(rt2x00dev, beacon_base, 0);
552 * Enable synchronisation.
554 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
555 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1);
556 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, conf->sync);
557 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1);
558 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
561 if (flags & CONFIG_UPDATE_MAC) {
562 reg = le32_to_cpu(conf->mac[1]);
563 rt2x00_set_field32(®, MAC_ADDR_DW1_UNICAST_TO_ME_MASK, 0xff);
564 conf->mac[1] = cpu_to_le32(reg);
566 rt2x00usb_register_multiwrite(rt2x00dev, MAC_ADDR_DW0,
567 conf->mac, sizeof(conf->mac));
570 if (flags & CONFIG_UPDATE_BSSID) {
571 reg = le32_to_cpu(conf->bssid[1]);
572 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_ID_MASK, 0);
573 rt2x00_set_field32(®, MAC_BSSID_DW1_BSS_BCN_NUM, 0);
574 conf->bssid[1] = cpu_to_le32(reg);
576 rt2x00usb_register_multiwrite(rt2x00dev, MAC_BSSID_DW0,
577 conf->bssid, sizeof(conf->bssid));
581 static void rt2800usb_config_erp(struct rt2x00_dev *rt2x00dev,
582 struct rt2x00lib_erp *erp)
586 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®);
587 rt2x00_set_field32(®, TX_TIMEOUT_CFG_RX_ACK_TIMEOUT,
588 DIV_ROUND_UP(erp->ack_timeout, erp->slot_time));
589 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
591 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
592 rt2x00_set_field32(®, AUTO_RSP_CFG_BAC_ACK_POLICY,
593 !!erp->short_preamble);
594 rt2x00_set_field32(®, AUTO_RSP_CFG_AR_PREAMBLE,
595 !!erp->short_preamble);
596 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
598 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
599 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL,
600 erp->cts_protection ? 2 : 0);
601 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
603 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE,
605 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
607 rt2x00usb_register_read(rt2x00dev, BKOFF_SLOT_CFG, ®);
608 rt2x00_set_field32(®, BKOFF_SLOT_CFG_SLOT_TIME, erp->slot_time);
609 rt2x00_set_field32(®, BKOFF_SLOT_CFG_CC_DELAY_TIME, 2);
610 rt2x00usb_register_write(rt2x00dev, BKOFF_SLOT_CFG, reg);
612 rt2x00usb_register_read(rt2x00dev, XIFS_TIME_CFG, ®);
613 rt2x00_set_field32(®, XIFS_TIME_CFG_CCKM_SIFS_TIME, erp->sifs);
614 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_SIFS_TIME, erp->sifs);
615 rt2x00_set_field32(®, XIFS_TIME_CFG_OFDM_XIFS_TIME, 4);
616 rt2x00_set_field32(®, XIFS_TIME_CFG_EIFS, erp->eifs);
617 rt2x00_set_field32(®, XIFS_TIME_CFG_BB_RXEND_ENABLE, 1);
618 rt2x00usb_register_write(rt2x00dev, XIFS_TIME_CFG, reg);
620 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
621 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL,
622 erp->beacon_int * 16);
623 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
626 static void rt2800usb_config_ant(struct rt2x00_dev *rt2x00dev,
627 struct antenna_setup *ant)
632 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
633 rt2800usb_bbp_read(rt2x00dev, 3, &r3);
636 * Configure the TX antenna.
638 switch ((int)ant->tx) {
640 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 0);
643 rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
651 * Configure the RX antenna.
653 switch ((int)ant->rx) {
655 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
658 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 1);
661 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 2);
665 rt2800usb_bbp_write(rt2x00dev, 3, r3);
666 rt2800usb_bbp_write(rt2x00dev, 1, r1);
669 static void rt2800usb_config_lna_gain(struct rt2x00_dev *rt2x00dev,
670 struct rt2x00lib_conf *libconf)
675 if (libconf->rf.channel <= 14) {
676 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
677 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_BG);
678 } else if (libconf->rf.channel <= 64) {
679 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &eeprom);
680 lna_gain = rt2x00_get_field16(eeprom, EEPROM_LNA_A0);
681 } else if (libconf->rf.channel <= 128) {
682 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &eeprom);
683 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_BG2_LNA_A1);
685 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &eeprom);
686 lna_gain = rt2x00_get_field16(eeprom, EEPROM_RSSI_A2_LNA_A2);
689 rt2x00dev->lna_gain = lna_gain;
692 static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
693 struct ieee80211_conf *conf,
694 struct rf_channel *rf,
695 struct channel_info *info)
697 rt2x00_set_field32(&rf->rf4, RF4_FREQ_OFFSET, rt2x00dev->freq_offset);
699 if (rt2x00dev->default_ant.tx == 1)
700 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
702 if (rt2x00dev->default_ant.rx == 1) {
703 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX1, 1);
704 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
705 } else if (rt2x00dev->default_ant.rx == 2)
706 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_RX2, 1);
708 if (rf->channel > 14) {
710 * When TX power is below 0, we should increase it by 7 to
711 * make it a positive value (Minumum value is -7).
712 * However this means that values between 0 and 7 have
713 * double meaning, and we should set a 7DBm boost flag.
715 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A_7DBM_BOOST,
716 (info->tx_power1 >= 0));
718 if (info->tx_power1 < 0)
719 info->tx_power1 += 7;
721 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_A,
722 TXPOWER_A_TO_DEV(info->tx_power1));
724 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A_7DBM_BOOST,
725 (info->tx_power2 >= 0));
727 if (info->tx_power2 < 0)
728 info->tx_power2 += 7;
730 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_A,
731 TXPOWER_A_TO_DEV(info->tx_power2));
733 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER_G,
734 TXPOWER_G_TO_DEV(info->tx_power1));
735 rt2x00_set_field32(&rf->rf4, RF4_TXPOWER_G,
736 TXPOWER_G_TO_DEV(info->tx_power2));
739 rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
741 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
742 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
743 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
744 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
748 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
749 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
750 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 | 0x00000004);
751 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
755 rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
756 rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
757 rt2800usb_rf_write(rt2x00dev, 3, rf->rf3 & ~0x00000004);
758 rt2800usb_rf_write(rt2x00dev, 4, rf->rf4);
761 static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
762 struct ieee80211_conf *conf,
763 struct rf_channel *rf,
764 struct channel_info *info)
768 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf1);
769 rt2800usb_rfcsr_write(rt2x00dev, 2, rf->rf3);
771 rt2800usb_rfcsr_read(rt2x00dev, 6, &rfcsr);
772 rt2x00_set_field8(&rfcsr, RFCSR6_R, rf->rf2);
773 rt2800usb_rfcsr_write(rt2x00dev, 6, rfcsr);
775 rt2800usb_rfcsr_read(rt2x00dev, 12, &rfcsr);
776 rt2x00_set_field8(&rfcsr, RFCSR12_TX_POWER,
777 TXPOWER_G_TO_DEV(info->tx_power1));
778 rt2800usb_rfcsr_write(rt2x00dev, 12, rfcsr);
780 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
781 rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
782 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
784 rt2800usb_rfcsr_write(rt2x00dev, 24,
785 rt2x00dev->calibration[conf_is_ht40(conf)]);
787 rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
788 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
789 rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
792 static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
793 struct ieee80211_conf *conf,
794 struct rf_channel *rf,
795 struct channel_info *info)
801 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
802 rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
804 rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
807 * Change BBP settings
809 rt2800usb_bbp_write(rt2x00dev, 62, 0x37 - rt2x00dev->lna_gain);
810 rt2800usb_bbp_write(rt2x00dev, 63, 0x37 - rt2x00dev->lna_gain);
811 rt2800usb_bbp_write(rt2x00dev, 64, 0x37 - rt2x00dev->lna_gain);
812 rt2800usb_bbp_write(rt2x00dev, 86, 0);
814 if (rf->channel <= 14) {
815 if (test_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags)) {
816 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
817 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
819 rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
820 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
823 rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
825 if (test_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags))
826 rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
828 rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
831 rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, ®);
832 rt2x00_set_field32(®, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
833 rt2x00_set_field32(®, TX_BAND_CFG_A, rf->channel > 14);
834 rt2x00_set_field32(®, TX_BAND_CFG_BG, rf->channel <= 14);
835 rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
839 /* Turn on unused PA or LNA when not using 1T or 1R */
840 if (rt2x00dev->default_ant.tx != 1) {
841 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
842 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
845 /* Turn on unused PA or LNA when not using 1T or 1R */
846 if (rt2x00dev->default_ant.rx != 1) {
847 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
848 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
851 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
852 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
853 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
854 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
855 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
856 rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
858 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
860 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
861 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
862 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
864 rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
865 rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
866 rt2800usb_bbp_write(rt2x00dev, 3, bbp);
868 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
869 if (conf_is_ht40(conf)) {
870 rt2800usb_bbp_write(rt2x00dev, 69, 0x1a);
871 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
872 rt2800usb_bbp_write(rt2x00dev, 73, 0x16);
874 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
875 rt2800usb_bbp_write(rt2x00dev, 70, 0x08);
876 rt2800usb_bbp_write(rt2x00dev, 73, 0x11);
883 static void rt2800usb_config_txpower(struct rt2x00_dev *rt2x00dev,
887 u32 value = TXPOWER_G_TO_DEV(txpower);
890 rt2800usb_bbp_read(rt2x00dev, 1, &r1);
891 rt2x00_set_field8(®, BBP1_TX_POWER, 0);
892 rt2800usb_bbp_write(rt2x00dev, 1, r1);
894 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_0, ®);
895 rt2x00_set_field32(®, TX_PWR_CFG_0_1MBS, value);
896 rt2x00_set_field32(®, TX_PWR_CFG_0_2MBS, value);
897 rt2x00_set_field32(®, TX_PWR_CFG_0_55MBS, value);
898 rt2x00_set_field32(®, TX_PWR_CFG_0_11MBS, value);
899 rt2x00_set_field32(®, TX_PWR_CFG_0_6MBS, value);
900 rt2x00_set_field32(®, TX_PWR_CFG_0_9MBS, value);
901 rt2x00_set_field32(®, TX_PWR_CFG_0_12MBS, value);
902 rt2x00_set_field32(®, TX_PWR_CFG_0_18MBS, value);
903 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_0, reg);
905 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_1, ®);
906 rt2x00_set_field32(®, TX_PWR_CFG_1_24MBS, value);
907 rt2x00_set_field32(®, TX_PWR_CFG_1_36MBS, value);
908 rt2x00_set_field32(®, TX_PWR_CFG_1_48MBS, value);
909 rt2x00_set_field32(®, TX_PWR_CFG_1_54MBS, value);
910 rt2x00_set_field32(®, TX_PWR_CFG_1_MCS0, value);
911 rt2x00_set_field32(®, TX_PWR_CFG_1_MCS1, value);
912 rt2x00_set_field32(®, TX_PWR_CFG_1_MCS2, value);
913 rt2x00_set_field32(®, TX_PWR_CFG_1_MCS3, value);
914 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_1, reg);
916 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_2, ®);
917 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS4, value);
918 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS5, value);
919 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS6, value);
920 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS7, value);
921 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS8, value);
922 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS9, value);
923 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS10, value);
924 rt2x00_set_field32(®, TX_PWR_CFG_2_MCS11, value);
925 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_2, reg);
927 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_3, ®);
928 rt2x00_set_field32(®, TX_PWR_CFG_3_MCS12, value);
929 rt2x00_set_field32(®, TX_PWR_CFG_3_MCS13, value);
930 rt2x00_set_field32(®, TX_PWR_CFG_3_MCS14, value);
931 rt2x00_set_field32(®, TX_PWR_CFG_3_MCS15, value);
932 rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN1, value);
933 rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN2, value);
934 rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN3, value);
935 rt2x00_set_field32(®, TX_PWR_CFG_3_UKNOWN4, value);
936 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_3, reg);
938 rt2x00usb_register_read(rt2x00dev, TX_PWR_CFG_4, ®);
939 rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN5, value);
940 rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN6, value);
941 rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN7, value);
942 rt2x00_set_field32(®, TX_PWR_CFG_4_UKNOWN8, value);
943 rt2x00usb_register_write(rt2x00dev, TX_PWR_CFG_4, reg);
946 static void rt2800usb_config_retry_limit(struct rt2x00_dev *rt2x00dev,
947 struct rt2x00lib_conf *libconf)
951 rt2x00usb_register_read(rt2x00dev, TX_RTY_CFG, ®);
952 rt2x00_set_field32(®, TX_RTY_CFG_SHORT_RTY_LIMIT,
953 libconf->conf->short_frame_max_tx_count);
954 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_LIMIT,
955 libconf->conf->long_frame_max_tx_count);
956 rt2x00_set_field32(®, TX_RTY_CFG_LONG_RTY_THRE, 2000);
957 rt2x00_set_field32(®, TX_RTY_CFG_NON_AGG_RTY_MODE, 0);
958 rt2x00_set_field32(®, TX_RTY_CFG_AGG_RTY_MODE, 0);
959 rt2x00_set_field32(®, TX_RTY_CFG_TX_AUTO_FB_ENABLE, 1);
960 rt2x00usb_register_write(rt2x00dev, TX_RTY_CFG, reg);
963 static void rt2800usb_config_ps(struct rt2x00_dev *rt2x00dev,
964 struct rt2x00lib_conf *libconf)
966 enum dev_state state =
967 (libconf->conf->flags & IEEE80211_CONF_PS) ?
968 STATE_SLEEP : STATE_AWAKE;
971 if (state == STATE_SLEEP) {
972 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, 0);
974 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
975 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 5);
976 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE,
977 libconf->conf->listen_interval - 1);
978 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 1);
979 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
981 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
983 rt2x00dev->ops->lib->set_device_state(rt2x00dev, state);
985 rt2x00usb_register_read(rt2x00dev, AUTOWAKEUP_CFG, ®);
986 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTO_LEAD_TIME, 0);
987 rt2x00_set_field32(®, AUTOWAKEUP_CFG_TBCN_BEFORE_WAKE, 0);
988 rt2x00_set_field32(®, AUTOWAKEUP_CFG_AUTOWAKE, 0);
989 rt2x00usb_register_write(rt2x00dev, AUTOWAKEUP_CFG, reg);
993 static void rt2800usb_config(struct rt2x00_dev *rt2x00dev,
994 struct rt2x00lib_conf *libconf,
995 const unsigned int flags)
997 /* Always recalculate LNA gain before changing configuration */
998 rt2800usb_config_lna_gain(rt2x00dev, libconf);
1000 if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
1001 rt2800usb_config_channel(rt2x00dev, libconf->conf,
1002 &libconf->rf, &libconf->channel);
1003 if (flags & IEEE80211_CONF_CHANGE_POWER)
1004 rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
1005 if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
1006 rt2800usb_config_retry_limit(rt2x00dev, libconf);
1007 if (flags & IEEE80211_CONF_CHANGE_PS)
1008 rt2800usb_config_ps(rt2x00dev, libconf);
1014 static void rt2800usb_link_stats(struct rt2x00_dev *rt2x00dev,
1015 struct link_qual *qual)
1020 * Update FCS error count from register.
1022 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, ®);
1023 qual->rx_failed = rt2x00_get_field32(reg, RX_STA_CNT0_CRC_ERR);
1026 static u8 rt2800usb_get_default_vgc(struct rt2x00_dev *rt2x00dev)
1028 if (rt2x00dev->curr_band == IEEE80211_BAND_2GHZ) {
1029 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION)
1030 return 0x1c + (2 * rt2x00dev->lna_gain);
1032 return 0x2e + rt2x00dev->lna_gain;
1035 if (!test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
1036 return 0x32 + (rt2x00dev->lna_gain * 5) / 3;
1038 return 0x3a + (rt2x00dev->lna_gain * 5) / 3;
1041 static inline void rt2800usb_set_vgc(struct rt2x00_dev *rt2x00dev,
1042 struct link_qual *qual, u8 vgc_level)
1044 if (qual->vgc_level != vgc_level) {
1045 rt2800usb_bbp_write(rt2x00dev, 66, vgc_level);
1046 qual->vgc_level = vgc_level;
1047 qual->vgc_level_reg = vgc_level;
1051 static void rt2800usb_reset_tuner(struct rt2x00_dev *rt2x00dev,
1052 struct link_qual *qual)
1054 rt2800usb_set_vgc(rt2x00dev, qual,
1055 rt2800usb_get_default_vgc(rt2x00dev));
1058 static void rt2800usb_link_tuner(struct rt2x00_dev *rt2x00dev,
1059 struct link_qual *qual, const u32 count)
1061 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION)
1065 * When RSSI is better then -80 increase VGC level with 0x10
1067 rt2800usb_set_vgc(rt2x00dev, qual,
1068 rt2800usb_get_default_vgc(rt2x00dev) +
1069 ((qual->rssi > -80) * 0x10));
1073 * Firmware functions
1075 static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1077 return FIRMWARE_RT2870;
1080 static bool rt2800usb_check_crc(const u8 *data, const size_t len)
1086 * The last 2 bytes in the firmware array are the crc checksum itself,
1087 * this means that we should never pass those 2 bytes to the crc
1090 fw_crc = (data[len - 2] << 8 | data[len - 1]);
1093 * Use the crc ccitt algorithm.
1094 * This will return the same value as the legacy driver which
1095 * used bit ordering reversion on the both the firmware bytes
1096 * before input input as well as on the final output.
1097 * Obviously using crc ccitt directly is much more efficient.
1099 crc = crc_ccitt(~0, data, len - 2);
1102 * There is a small difference between the crc-itu-t + bitrev and
1103 * the crc-ccitt crc calculation. In the latter method the 2 bytes
1104 * will be swapped, use swab16 to convert the crc to the correct
1109 return fw_crc == crc;
1112 static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
1113 const u8 *data, const size_t len)
1115 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
1120 * There are 2 variations of the rt2870 firmware.
1123 * Note that (b) contains 2 seperate firmware blobs of 4k
1124 * within the file. The first blob is the same firmware as (a),
1125 * but the second blob is for the additional chipsets.
1127 if (len != 4096 && len != 8192)
1128 return FW_BAD_LENGTH;
1131 * Check if we need the upper 4kb firmware data or not.
1133 if ((len == 4096) &&
1134 (chipset != 0x2860) &&
1135 (chipset != 0x2872) &&
1136 (chipset != 0x3070))
1137 return FW_BAD_VERSION;
1140 * 8kb firmware files must be checked as if it were
1141 * 2 seperate firmware files.
1143 while (offset < len) {
1144 if (!rt2800usb_check_crc(data + offset, 4096))
1153 static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
1154 const u8 *data, const size_t len)
1161 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
1164 * Check which section of the firmware we need.
1166 if ((chipset == 0x2860) ||
1167 (chipset == 0x2872) ||
1168 (chipset == 0x3070)) {
1177 * Wait for stable hardware.
1179 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1180 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, ®);
1181 if (reg && reg != ~0)
1186 if (i == REGISTER_BUSY_COUNT) {
1187 ERROR(rt2x00dev, "Unstable hardware.\n");
1192 * Write firmware to device.
1194 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
1195 USB_VENDOR_REQUEST_OUT,
1196 FIRMWARE_IMAGE_BASE,
1197 data + offset, length,
1198 REGISTER_TIMEOUT32(length));
1200 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
1201 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
1204 * Send firmware request to device to load firmware,
1205 * we need to specify a long timeout time.
1207 status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
1208 0, USB_MODE_FIRMWARE,
1209 REGISTER_TIMEOUT_FIRMWARE);
1211 ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
1216 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1219 * Send signal to firmware during boot time.
1221 rt2800usb_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
1223 if ((chipset == 0x3070) ||
1224 (chipset == 0x3071) ||
1225 (chipset == 0x3572)) {
1227 rt2800usb_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
1232 * Wait for device to stabilize.
1234 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1235 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
1236 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
1241 if (i == REGISTER_BUSY_COUNT) {
1242 ERROR(rt2x00dev, "PBF system register not ready.\n");
1247 * Initialize firmware.
1249 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1250 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1257 * Initialization functions.
1259 static int rt2800usb_init_registers(struct rt2x00_dev *rt2x00dev)
1265 * Wait untill BBP and RF are ready.
1267 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1268 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, ®);
1269 if (reg && reg != ~0)
1274 if (i == REGISTER_BUSY_COUNT) {
1275 ERROR(rt2x00dev, "Unstable hardware.\n");
1279 rt2x00usb_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
1280 rt2x00usb_register_write(rt2x00dev, PBF_SYS_CTRL, reg & ~0x00002000);
1282 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
1283 rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_CSR, 1);
1284 rt2x00_set_field32(®, MAC_SYS_CTRL_RESET_BBP, 1);
1285 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1287 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, 0x00000000);
1289 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0,
1290 USB_MODE_RESET, REGISTER_TIMEOUT);
1292 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1294 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET0, ®);
1295 rt2x00_set_field32(®, BCN_OFFSET0_BCN0, 0xe0); /* 0x3800 */
1296 rt2x00_set_field32(®, BCN_OFFSET0_BCN1, 0xe8); /* 0x3a00 */
1297 rt2x00_set_field32(®, BCN_OFFSET0_BCN2, 0xf0); /* 0x3c00 */
1298 rt2x00_set_field32(®, BCN_OFFSET0_BCN3, 0xf8); /* 0x3e00 */
1299 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET0, reg);
1301 rt2x00usb_register_read(rt2x00dev, BCN_OFFSET1, ®);
1302 rt2x00_set_field32(®, BCN_OFFSET1_BCN4, 0xc8); /* 0x3200 */
1303 rt2x00_set_field32(®, BCN_OFFSET1_BCN5, 0xd0); /* 0x3400 */
1304 rt2x00_set_field32(®, BCN_OFFSET1_BCN6, 0x77); /* 0x1dc0 */
1305 rt2x00_set_field32(®, BCN_OFFSET1_BCN7, 0x6f); /* 0x1bc0 */
1306 rt2x00usb_register_write(rt2x00dev, BCN_OFFSET1, reg);
1308 rt2x00usb_register_write(rt2x00dev, LEGACY_BASIC_RATE, 0x0000013f);
1309 rt2x00usb_register_write(rt2x00dev, HT_BASIC_RATE, 0x00008003);
1311 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0x00000000);
1313 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
1314 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_INTERVAL, 0);
1315 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
1316 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_SYNC, 0);
1317 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
1318 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
1319 rt2x00_set_field32(®, BCN_TIME_CFG_TX_TIME_COMPENSATE, 0);
1320 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
1322 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1323 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000400);
1324 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00000000);
1325 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG2, 0x00000000);
1327 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG0, 0x00000000);
1328 rt2x00usb_register_write(rt2x00dev, TX_SW_CFG1, 0x00080606);
1331 rt2x00usb_register_read(rt2x00dev, TX_LINK_CFG, ®);
1332 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB_LIFETIME, 32);
1333 rt2x00_set_field32(®, TX_LINK_CFG_MFB_ENABLE, 0);
1334 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_UMFS_ENABLE, 0);
1335 rt2x00_set_field32(®, TX_LINK_CFG_TX_MRQ_EN, 0);
1336 rt2x00_set_field32(®, TX_LINK_CFG_TX_RDG_EN, 0);
1337 rt2x00_set_field32(®, TX_LINK_CFG_TX_CF_ACK_EN, 1);
1338 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFB, 0);
1339 rt2x00_set_field32(®, TX_LINK_CFG_REMOTE_MFS, 0);
1340 rt2x00usb_register_write(rt2x00dev, TX_LINK_CFG, reg);
1342 rt2x00usb_register_read(rt2x00dev, TX_TIMEOUT_CFG, ®);
1343 rt2x00_set_field32(®, TX_TIMEOUT_CFG_MPDU_LIFETIME, 9);
1344 rt2x00_set_field32(®, TX_TIMEOUT_CFG_TX_OP_TIMEOUT, 10);
1345 rt2x00usb_register_write(rt2x00dev, TX_TIMEOUT_CFG, reg);
1347 rt2x00usb_register_read(rt2x00dev, MAX_LEN_CFG, ®);
1348 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_MPDU, AGGREGATION_SIZE);
1349 if (rt2x00_rev(&rt2x00dev->chip) >= RT2880E_VERSION &&
1350 rt2x00_rev(&rt2x00dev->chip) < RT3070_VERSION)
1351 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 2);
1353 rt2x00_set_field32(®, MAX_LEN_CFG_MAX_PSDU, 1);
1354 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_PSDU, 0);
1355 rt2x00_set_field32(®, MAX_LEN_CFG_MIN_MPDU, 0);
1356 rt2x00usb_register_write(rt2x00dev, MAX_LEN_CFG, reg);
1358 rt2x00usb_register_write(rt2x00dev, PBF_MAX_PCNT, 0x1f3fbf9f);
1360 rt2x00usb_register_read(rt2x00dev, AUTO_RSP_CFG, ®);
1361 rt2x00_set_field32(®, AUTO_RSP_CFG_AUTORESPONDER, 1);
1362 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MMODE, 0);
1363 rt2x00_set_field32(®, AUTO_RSP_CFG_CTS_40_MREF, 0);
1364 rt2x00_set_field32(®, AUTO_RSP_CFG_DUAL_CTS_EN, 0);
1365 rt2x00_set_field32(®, AUTO_RSP_CFG_ACK_CTS_PSM_BIT, 0);
1366 rt2x00usb_register_write(rt2x00dev, AUTO_RSP_CFG, reg);
1368 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, ®);
1369 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_RATE, 8);
1370 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_CTRL, 0);
1371 rt2x00_set_field32(®, CCK_PROT_CFG_PROTECT_NAV, 1);
1372 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1373 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1374 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1375 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1376 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1377 rt2x00_set_field32(®, CCK_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1378 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
1380 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
1381 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_RATE, 8);
1382 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_CTRL, 0);
1383 rt2x00_set_field32(®, OFDM_PROT_CFG_PROTECT_NAV, 1);
1384 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1385 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1386 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1387 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1388 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1389 rt2x00_set_field32(®, OFDM_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1390 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
1392 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, ®);
1393 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_RATE, 0x4004);
1394 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_CTRL, 0);
1395 rt2x00_set_field32(®, MM20_PROT_CFG_PROTECT_NAV, 1);
1396 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1397 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1398 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1399 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1400 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1401 rt2x00_set_field32(®, MM20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1402 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
1404 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, ®);
1405 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_RATE, 0x4084);
1406 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_CTRL, 0);
1407 rt2x00_set_field32(®, MM40_PROT_CFG_PROTECT_NAV, 1);
1408 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1409 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1410 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1411 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1412 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1413 rt2x00_set_field32(®, MM40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1414 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
1416 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, ®);
1417 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_RATE, 0x4004);
1418 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_CTRL, 0);
1419 rt2x00_set_field32(®, GF20_PROT_CFG_PROTECT_NAV, 1);
1420 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1421 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1422 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1423 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_MM40, 0);
1424 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1425 rt2x00_set_field32(®, GF20_PROT_CFG_TX_OP_ALLOW_GF40, 0);
1426 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
1428 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, ®);
1429 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_RATE, 0x4084);
1430 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_CTRL, 0);
1431 rt2x00_set_field32(®, GF40_PROT_CFG_PROTECT_NAV, 1);
1432 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_CCK, 1);
1433 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_OFDM, 1);
1434 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM20, 1);
1435 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_MM40, 1);
1436 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF20, 1);
1437 rt2x00_set_field32(®, GF40_PROT_CFG_TX_OP_ALLOW_GF40, 1);
1438 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
1440 rt2x00usb_register_write(rt2x00dev, PBF_CFG, 0xf40006);
1442 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
1443 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1444 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
1445 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1446 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
1447 rt2x00_set_field32(®, WPDMA_GLO_CFG_WP_DMA_BURST_SIZE, 3);
1448 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 0);
1449 rt2x00_set_field32(®, WPDMA_GLO_CFG_BIG_ENDIAN, 0);
1450 rt2x00_set_field32(®, WPDMA_GLO_CFG_RX_HDR_SCATTER, 0);
1451 rt2x00_set_field32(®, WPDMA_GLO_CFG_HDR_SEG_LEN, 0);
1452 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1454 rt2x00usb_register_write(rt2x00dev, TXOP_CTRL_CFG, 0x0000583f);
1455 rt2x00usb_register_write(rt2x00dev, TXOP_HLDR_ET, 0x00000002);
1457 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, ®);
1458 rt2x00_set_field32(®, TX_RTS_CFG_AUTO_RTS_RETRY_LIMIT, 32);
1459 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES,
1460 IEEE80211_MAX_RTS_THRESHOLD);
1461 rt2x00_set_field32(®, TX_RTS_CFG_RTS_FBK_EN, 0);
1462 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
1464 rt2x00usb_register_write(rt2x00dev, EXP_ACK_TIME, 0x002400ca);
1465 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000003);
1468 * ASIC will keep garbage value after boot, clear encryption keys.
1470 for (i = 0; i < 256; i++) {
1471 u32 wcid[2] = { 0xffffffff, 0x00ffffff };
1472 rt2x00usb_register_multiwrite(rt2x00dev, MAC_WCID_ENTRY(i),
1473 wcid, sizeof(wcid));
1475 rt2x00usb_register_write(rt2x00dev, MAC_WCID_ATTR_ENTRY(i), 1);
1476 rt2x00usb_register_write(rt2x00dev, MAC_IVEIV_ENTRY(i), 0);
1479 for (i = 0; i < 16; i++)
1480 rt2x00usb_register_write(rt2x00dev,
1481 SHARED_KEY_MODE_ENTRY(i), 0);
1485 * For the Beacon base registers we only need to clear
1486 * the first byte since that byte contains the VALID and OWNER
1487 * bits which (when set to 0) will invalidate the entire beacon.
1489 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE0, 0);
1490 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE1, 0);
1491 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE2, 0);
1492 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE3, 0);
1493 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE4, 0);
1494 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE5, 0);
1495 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE6, 0);
1496 rt2x00usb_register_write(rt2x00dev, HW_BEACON_BASE7, 0);
1498 rt2x00usb_register_read(rt2x00dev, USB_CYC_CFG, ®);
1499 rt2x00_set_field32(®, USB_CYC_CFG_CLOCK_CYCLE, 30);
1500 rt2x00usb_register_write(rt2x00dev, USB_CYC_CFG, reg);
1502 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG0, ®);
1503 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS0FBK, 0);
1504 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS1FBK, 0);
1505 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS2FBK, 1);
1506 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS3FBK, 2);
1507 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS4FBK, 3);
1508 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS5FBK, 4);
1509 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS6FBK, 5);
1510 rt2x00_set_field32(®, HT_FBK_CFG0_HTMCS7FBK, 6);
1511 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG0, reg);
1513 rt2x00usb_register_read(rt2x00dev, HT_FBK_CFG1, ®);
1514 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS8FBK, 8);
1515 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS9FBK, 8);
1516 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS10FBK, 9);
1517 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS11FBK, 10);
1518 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS12FBK, 11);
1519 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS13FBK, 12);
1520 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS14FBK, 13);
1521 rt2x00_set_field32(®, HT_FBK_CFG1_HTMCS15FBK, 14);
1522 rt2x00usb_register_write(rt2x00dev, HT_FBK_CFG1, reg);
1524 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG0, ®);
1525 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS0FBK, 8);
1526 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS1FBK, 8);
1527 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS2FBK, 3);
1528 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS3FBK, 10);
1529 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS4FBK, 11);
1530 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS5FBK, 12);
1531 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS6FBK, 13);
1532 rt2x00_set_field32(®, LG_FBK_CFG0_OFDMMCS7FBK, 14);
1533 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG0, reg);
1535 rt2x00usb_register_read(rt2x00dev, LG_FBK_CFG1, ®);
1536 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS0FBK, 0);
1537 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS1FBK, 0);
1538 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS2FBK, 1);
1539 rt2x00_set_field32(®, LG_FBK_CFG0_CCKMCS3FBK, 2);
1540 rt2x00usb_register_write(rt2x00dev, LG_FBK_CFG1, reg);
1543 * We must clear the error counters.
1544 * These registers are cleared on read,
1545 * so we may pass a useless variable to store the value.
1547 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT0, ®);
1548 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT1, ®);
1549 rt2x00usb_register_read(rt2x00dev, RX_STA_CNT2, ®);
1550 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT0, ®);
1551 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT1, ®);
1552 rt2x00usb_register_read(rt2x00dev, TX_STA_CNT2, ®);
1557 static int rt2800usb_wait_bbp_rf_ready(struct rt2x00_dev *rt2x00dev)
1562 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1563 rt2x00usb_register_read(rt2x00dev, MAC_STATUS_CFG, ®);
1564 if (!rt2x00_get_field32(reg, MAC_STATUS_CFG_BBP_RF_BUSY))
1567 udelay(REGISTER_BUSY_DELAY);
1570 ERROR(rt2x00dev, "BBP/RF register access failed, aborting.\n");
1574 static int rt2800usb_wait_bbp_ready(struct rt2x00_dev *rt2x00dev)
1580 * BBP was enabled after firmware was loaded,
1581 * but we need to reactivate it now.
1583 rt2x00usb_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
1584 rt2x00usb_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
1587 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1588 rt2800usb_bbp_read(rt2x00dev, 0, &value);
1589 if ((value != 0xff) && (value != 0x00))
1591 udelay(REGISTER_BUSY_DELAY);
1594 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
1598 static int rt2800usb_init_bbp(struct rt2x00_dev *rt2x00dev)
1605 if (unlikely(rt2800usb_wait_bbp_rf_ready(rt2x00dev) ||
1606 rt2800usb_wait_bbp_ready(rt2x00dev)))
1609 rt2800usb_bbp_write(rt2x00dev, 65, 0x2c);
1610 rt2800usb_bbp_write(rt2x00dev, 66, 0x38);
1611 rt2800usb_bbp_write(rt2x00dev, 69, 0x12);
1612 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1613 rt2800usb_bbp_write(rt2x00dev, 73, 0x10);
1614 rt2800usb_bbp_write(rt2x00dev, 81, 0x37);
1615 rt2800usb_bbp_write(rt2x00dev, 82, 0x62);
1616 rt2800usb_bbp_write(rt2x00dev, 83, 0x6a);
1617 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1618 rt2800usb_bbp_write(rt2x00dev, 86, 0x00);
1619 rt2800usb_bbp_write(rt2x00dev, 91, 0x04);
1620 rt2800usb_bbp_write(rt2x00dev, 92, 0x00);
1621 rt2800usb_bbp_write(rt2x00dev, 103, 0x00);
1622 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1624 if (rt2x00_rev(&rt2x00dev->chip) == RT2860C_VERSION) {
1625 rt2800usb_bbp_write(rt2x00dev, 69, 0x16);
1626 rt2800usb_bbp_write(rt2x00dev, 73, 0x12);
1629 if (rt2x00_rev(&rt2x00dev->chip) > RT2860D_VERSION) {
1630 rt2800usb_bbp_write(rt2x00dev, 84, 0x19);
1633 if (rt2x00_rev(&rt2x00dev->chip) == RT3070_VERSION) {
1634 rt2800usb_bbp_write(rt2x00dev, 70, 0x0a);
1635 rt2800usb_bbp_write(rt2x00dev, 84, 0x99);
1636 rt2800usb_bbp_write(rt2x00dev, 105, 0x05);
1639 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
1640 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
1642 if (eeprom != 0xffff && eeprom != 0x0000) {
1643 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
1644 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
1645 rt2800usb_bbp_write(rt2x00dev, reg_id, value);
1652 static u8 rt2800usb_init_rx_filter(struct rt2x00_dev *rt2x00dev,
1653 bool bw40, u8 rfcsr24, u8 filter_target)
1662 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1664 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1665 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * bw40);
1666 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1668 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1669 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 1);
1670 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1673 * Set power & frequency of passband test tone
1675 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1677 for (i = 0; i < 100; i++) {
1678 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1681 rt2800usb_bbp_read(rt2x00dev, 55, &passband);
1687 * Set power & frequency of stopband test tone
1689 rt2800usb_bbp_write(rt2x00dev, 24, 0x06);
1691 for (i = 0; i < 100; i++) {
1692 rt2800usb_bbp_write(rt2x00dev, 25, 0x90);
1695 rt2800usb_bbp_read(rt2x00dev, 55, &stopband);
1697 if ((passband - stopband) <= filter_target) {
1699 overtuned += ((passband - stopband) == filter_target);
1703 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1706 rfcsr24 -= !!overtuned;
1708 rt2800usb_rfcsr_write(rt2x00dev, 24, rfcsr24);
1712 static int rt2800usb_init_rfcsr(struct rt2x00_dev *rt2x00dev)
1717 if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
1721 * Init RF calibration.
1723 rt2800usb_rfcsr_read(rt2x00dev, 30, &rfcsr);
1724 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
1725 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1727 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 0);
1728 rt2800usb_rfcsr_write(rt2x00dev, 30, rfcsr);
1730 rt2800usb_rfcsr_write(rt2x00dev, 4, 0x40);
1731 rt2800usb_rfcsr_write(rt2x00dev, 5, 0x03);
1732 rt2800usb_rfcsr_write(rt2x00dev, 6, 0x02);
1733 rt2800usb_rfcsr_write(rt2x00dev, 7, 0x70);
1734 rt2800usb_rfcsr_write(rt2x00dev, 9, 0x0f);
1735 rt2800usb_rfcsr_write(rt2x00dev, 10, 0x71);
1736 rt2800usb_rfcsr_write(rt2x00dev, 11, 0x21);
1737 rt2800usb_rfcsr_write(rt2x00dev, 12, 0x7b);
1738 rt2800usb_rfcsr_write(rt2x00dev, 14, 0x90);
1739 rt2800usb_rfcsr_write(rt2x00dev, 15, 0x58);
1740 rt2800usb_rfcsr_write(rt2x00dev, 16, 0xb3);
1741 rt2800usb_rfcsr_write(rt2x00dev, 17, 0x92);
1742 rt2800usb_rfcsr_write(rt2x00dev, 18, 0x2c);
1743 rt2800usb_rfcsr_write(rt2x00dev, 19, 0x02);
1744 rt2800usb_rfcsr_write(rt2x00dev, 20, 0xba);
1745 rt2800usb_rfcsr_write(rt2x00dev, 21, 0xdb);
1746 rt2800usb_rfcsr_write(rt2x00dev, 24, 0x16);
1747 rt2800usb_rfcsr_write(rt2x00dev, 25, 0x01);
1748 rt2800usb_rfcsr_write(rt2x00dev, 27, 0x03);
1749 rt2800usb_rfcsr_write(rt2x00dev, 29, 0x1f);
1752 * Set RX Filter calibration for 20MHz and 40MHz
1754 rt2x00dev->calibration[0] =
1755 rt2800usb_init_rx_filter(rt2x00dev, false, 0x07, 0x16);
1756 rt2x00dev->calibration[1] =
1757 rt2800usb_init_rx_filter(rt2x00dev, true, 0x27, 0x19);
1760 * Set back to initial state
1762 rt2800usb_bbp_write(rt2x00dev, 24, 0);
1764 rt2800usb_rfcsr_read(rt2x00dev, 22, &rfcsr);
1765 rt2x00_set_field8(&rfcsr, RFCSR22_BASEBAND_LOOPBACK, 0);
1766 rt2800usb_rfcsr_write(rt2x00dev, 22, rfcsr);
1769 * set BBP back to BW20
1771 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
1772 rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0);
1773 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
1779 * Device state switch handlers.
1781 static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
1782 enum dev_state state)
1786 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
1787 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX,
1788 (state == STATE_RADIO_RX_ON) ||
1789 (state == STATE_RADIO_RX_ON_LINK));
1790 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1793 static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
1798 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
1799 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
1800 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
1801 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
1807 ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
1811 static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
1817 * Initialize all registers.
1819 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
1820 rt2800usb_init_registers(rt2x00dev) ||
1821 rt2800usb_init_bbp(rt2x00dev) ||
1822 rt2800usb_init_rfcsr(rt2x00dev)))
1825 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
1826 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
1827 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1831 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
1832 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
1833 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
1834 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
1835 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1838 rt2x00usb_register_read(rt2x00dev, USB_DMA_CFG, ®);
1839 rt2x00_set_field32(®, USB_DMA_CFG_PHY_CLEAR, 0);
1840 /* Don't use bulk in aggregation when working with USB 1.1 */
1841 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_EN,
1842 (rt2x00dev->rx->usb_maxpacket == 512));
1843 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
1845 * Total room for RX frames in kilobytes, PBF might still exceed
1846 * this limit so reduce the number to prevent errors.
1848 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
1849 ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
1850 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_EN, 1);
1851 rt2x00_set_field32(®, USB_DMA_CFG_TX_BULK_EN, 1);
1852 rt2x00usb_register_write(rt2x00dev, USB_DMA_CFG, reg);
1854 rt2x00usb_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
1855 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
1856 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
1857 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
1860 * Initialize LED control
1862 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
1863 rt2800usb_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
1864 word & 0xff, (word >> 8) & 0xff);
1866 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
1867 rt2800usb_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
1868 word & 0xff, (word >> 8) & 0xff);
1870 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
1871 rt2800usb_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
1872 word & 0xff, (word >> 8) & 0xff);
1877 static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
1881 rt2x00usb_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
1882 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
1883 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
1884 rt2x00usb_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
1886 rt2x00usb_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
1887 rt2x00usb_register_write(rt2x00dev, PWR_PIN_CFG, 0);
1888 rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, 0);
1890 /* Wait for DMA, ignore error */
1891 rt2800usb_wait_wpdma_ready(rt2x00dev);
1893 rt2x00usb_disable_radio(rt2x00dev);
1896 static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
1897 enum dev_state state)
1899 if (state == STATE_AWAKE)
1900 rt2800usb_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
1902 rt2800usb_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
1907 static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
1908 enum dev_state state)
1913 case STATE_RADIO_ON:
1915 * Before the radio can be enabled, the device first has
1916 * to be woken up. After that it needs a bit of time
1917 * to be fully awake and the radio can be enabled.
1919 rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
1921 retval = rt2800usb_enable_radio(rt2x00dev);
1923 case STATE_RADIO_OFF:
1925 * After the radio has been disablee, the device should
1926 * be put to sleep for powersaving.
1928 rt2800usb_disable_radio(rt2x00dev);
1929 rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
1931 case STATE_RADIO_RX_ON:
1932 case STATE_RADIO_RX_ON_LINK:
1933 case STATE_RADIO_RX_OFF:
1934 case STATE_RADIO_RX_OFF_LINK:
1935 rt2800usb_toggle_rx(rt2x00dev, state);
1937 case STATE_RADIO_IRQ_ON:
1938 case STATE_RADIO_IRQ_OFF:
1939 /* No support, but no error either */
1941 case STATE_DEEP_SLEEP:
1945 retval = rt2800usb_set_state(rt2x00dev, state);
1952 if (unlikely(retval))
1953 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
1960 * TX descriptor initialization
1962 static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1963 struct sk_buff *skb,
1964 struct txentry_desc *txdesc)
1966 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
1967 __le32 *txi = skbdesc->desc;
1968 __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
1972 * Initialize TX Info descriptor
1974 rt2x00_desc_read(txwi, 0, &word);
1975 rt2x00_set_field32(&word, TXWI_W0_FRAG,
1976 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
1977 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
1978 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
1979 rt2x00_set_field32(&word, TXWI_W0_TS,
1980 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
1981 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
1982 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
1983 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
1984 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
1985 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
1986 rt2x00_set_field32(&word, TXWI_W0_BW,
1987 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
1988 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
1989 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
1990 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
1991 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
1992 rt2x00_desc_write(txwi, 0, word);
1994 rt2x00_desc_read(txwi, 1, &word);
1995 rt2x00_set_field32(&word, TXWI_W1_ACK,
1996 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
1997 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
1998 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
1999 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
2000 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
2001 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
2002 txdesc->key_idx : 0xff);
2003 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
2004 skb->len - txdesc->l2pad);
2005 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
2006 skbdesc->entry->entry_idx);
2007 rt2x00_desc_write(txwi, 1, word);
2010 * Always write 0 to IV/EIV fields, hardware will insert the IV
2011 * from the IVEIV register when TXINFO_W0_WIV is set to 0.
2012 * When TXINFO_W0_WIV is set to 1 it will use the IV data
2013 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
2014 * crypto entry in the registers should be used to encrypt the frame.
2016 _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
2017 _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
2020 * Initialize TX descriptor
2022 rt2x00_desc_read(txi, 0, &word);
2023 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
2024 skb->len + TXWI_DESC_SIZE);
2025 rt2x00_set_field32(&word, TXINFO_W0_WIV,
2026 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
2027 rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
2028 rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
2029 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
2030 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
2031 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
2032 rt2x00_desc_write(txi, 0, word);
2036 * TX data initialization
2038 static void rt2800usb_write_beacon(struct queue_entry *entry)
2040 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2041 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2042 unsigned int beacon_base;
2046 * Add the descriptor in front of the skb.
2048 skb_push(entry->skb, entry->queue->desc_size);
2049 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
2050 skbdesc->desc = entry->skb->data;
2053 * Disable beaconing while we are reloading the beacon data,
2054 * otherwise we might be sending out invalid data.
2056 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
2057 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 0);
2058 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 0);
2059 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
2060 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2063 * Write entire beacon with descriptor to register.
2065 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
2066 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
2067 USB_VENDOR_REQUEST_OUT, beacon_base,
2068 entry->skb->data, entry->skb->len,
2069 REGISTER_TIMEOUT32(entry->skb->len));
2072 * Clean up the beacon skb.
2074 dev_kfree_skb(entry->skb);
2078 static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
2083 * The length _must_ include 4 bytes padding,
2084 * it should always be multiple of 4,
2085 * but it must _not_ be a multiple of the USB packet size.
2087 length = roundup(entry->skb->len + 4, 4);
2088 length += (4 * !(length % entry->queue->usb_maxpacket));
2093 static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
2094 const enum data_queue_qid queue)
2098 if (queue != QID_BEACON) {
2099 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
2103 rt2x00usb_register_read(rt2x00dev, BCN_TIME_CFG, ®);
2104 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
2105 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1);
2106 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1);
2107 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
2108 rt2x00usb_register_write(rt2x00dev, BCN_TIME_CFG, reg);
2113 * RX control handlers
2115 static void rt2800usb_fill_rxdone(struct queue_entry *entry,
2116 struct rxdone_entry_desc *rxdesc)
2118 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
2119 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
2120 __le32 *rxd = (__le32 *)entry->skb->data;
2129 * Copy descriptor to the skbdesc->desc buffer, making it safe from
2130 * moving of frame data in rt2x00usb.
2132 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
2133 rxd = (__le32 *)skbdesc->desc;
2134 rxwi = &rxd[RXD_DESC_SIZE / sizeof(__le32)];
2137 * It is now safe to read the descriptor on all architectures.
2139 rt2x00_desc_read(rxd, 0, &rxd0);
2140 rt2x00_desc_read(rxwi, 0, &rxwi0);
2141 rt2x00_desc_read(rxwi, 1, &rxwi1);
2142 rt2x00_desc_read(rxwi, 2, &rxwi2);
2143 rt2x00_desc_read(rxwi, 3, &rxwi3);
2145 if (rt2x00_get_field32(rxd0, RXD_W0_CRC_ERROR))
2146 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
2148 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
2149 rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
2150 rxdesc->cipher_status =
2151 rt2x00_get_field32(rxd0, RXD_W0_CIPHER_ERROR);
2154 if (rt2x00_get_field32(rxd0, RXD_W0_DECRYPTED)) {
2156 * Hardware has stripped IV/EIV data from 802.11 frame during
2157 * decryption. Unfortunately the descriptor doesn't contain
2158 * any fields with the EIV/IV data either, so they can't
2159 * be restored by rt2x00lib.
2161 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
2163 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
2164 rxdesc->flags |= RX_FLAG_DECRYPTED;
2165 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
2166 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
2169 if (rt2x00_get_field32(rxd0, RXD_W0_MY_BSS))
2170 rxdesc->dev_flags |= RXDONE_MY_BSS;
2172 if (rt2x00_get_field32(rxd0, RXD_W0_L2PAD))
2173 rxdesc->dev_flags |= RXDONE_L2PAD;
2175 if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
2176 rxdesc->flags |= RX_FLAG_SHORT_GI;
2178 if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
2179 rxdesc->flags |= RX_FLAG_40MHZ;
2182 * Detect RX rate, always use MCS as signal type.
2184 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
2185 rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
2186 rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
2189 * Mask of 0x8 bit to remove the short preamble flag.
2191 if (rxdesc->rate_mode == RATE_MODE_CCK)
2192 rxdesc->signal &= ~0x8;
2195 (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
2196 rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
2199 (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
2200 rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
2202 rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
2205 * Remove RXWI descriptor from start of buffer.
2207 skb_pull(entry->skb, skbdesc->desc_len);
2208 skb_trim(entry->skb, rxdesc->size);
2212 * Device probe functions.
2214 static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
2218 u8 default_lna_gain;
2220 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
2223 * Start validation of the data that has been read.
2225 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
2226 if (!is_valid_ether_addr(mac)) {
2227 DECLARE_MAC_BUF(macbuf);
2229 random_ether_addr(mac);
2230 EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
2233 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
2234 if (word == 0xffff) {
2235 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2236 rt2x00_set_field16(&word, EEPROM_ANTENNA_TXPATH, 1);
2237 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2820);
2238 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2239 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
2240 } else if (rt2x00_rev(&rt2x00dev->chip) < RT2883_VERSION) {
2242 * There is a max of 2 RX streams for RT2870 series
2244 if (rt2x00_get_field16(word, EEPROM_ANTENNA_RXPATH) > 2)
2245 rt2x00_set_field16(&word, EEPROM_ANTENNA_RXPATH, 2);
2246 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
2249 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
2250 if (word == 0xffff) {
2251 rt2x00_set_field16(&word, EEPROM_NIC_HW_RADIO, 0);
2252 rt2x00_set_field16(&word, EEPROM_NIC_DYNAMIC_TX_AGC, 0);
2253 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_BG, 0);
2254 rt2x00_set_field16(&word, EEPROM_NIC_EXTERNAL_LNA_A, 0);
2255 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
2256 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_BG, 0);
2257 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_SB_A, 0);
2258 rt2x00_set_field16(&word, EEPROM_NIC_WPS_PBC, 0);
2259 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_BG, 0);
2260 rt2x00_set_field16(&word, EEPROM_NIC_BW40M_A, 0);
2261 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
2262 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
2265 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &word);
2266 if ((word & 0x00ff) == 0x00ff) {
2267 rt2x00_set_field16(&word, EEPROM_FREQ_OFFSET, 0);
2268 rt2x00_set_field16(&word, EEPROM_FREQ_LED_MODE,
2269 LED_MODE_TXRX_ACTIVITY);
2270 rt2x00_set_field16(&word, EEPROM_FREQ_LED_POLARITY, 0);
2271 rt2x00_eeprom_write(rt2x00dev, EEPROM_FREQ, word);
2272 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED1, 0x5555);
2273 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED2, 0x2221);
2274 rt2x00_eeprom_write(rt2x00dev, EEPROM_LED3, 0xa9f8);
2275 EEPROM(rt2x00dev, "Freq: 0x%04x\n", word);
2279 * During the LNA validation we are going to use
2280 * lna0 as correct value. Note that EEPROM_LNA
2281 * is never validated.
2283 rt2x00_eeprom_read(rt2x00dev, EEPROM_LNA, &word);
2284 default_lna_gain = rt2x00_get_field16(word, EEPROM_LNA_A0);
2286 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG, &word);
2287 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET0)) > 10)
2288 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET0, 0);
2289 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG_OFFSET1)) > 10)
2290 rt2x00_set_field16(&word, EEPROM_RSSI_BG_OFFSET1, 0);
2291 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG, word);
2293 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_BG2, &word);
2294 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_BG2_OFFSET2)) > 10)
2295 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_OFFSET2, 0);
2296 if (rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0x00 ||
2297 rt2x00_get_field16(word, EEPROM_RSSI_BG2_LNA_A1) == 0xff)
2298 rt2x00_set_field16(&word, EEPROM_RSSI_BG2_LNA_A1,
2300 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_BG2, word);
2302 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A, &word);
2303 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET0)) > 10)
2304 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET0, 0);
2305 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A_OFFSET1)) > 10)
2306 rt2x00_set_field16(&word, EEPROM_RSSI_A_OFFSET1, 0);
2307 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A, word);
2309 rt2x00_eeprom_read(rt2x00dev, EEPROM_RSSI_A2, &word);
2310 if (abs(rt2x00_get_field16(word, EEPROM_RSSI_A2_OFFSET2)) > 10)
2311 rt2x00_set_field16(&word, EEPROM_RSSI_A2_OFFSET2, 0);
2312 if (rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0x00 ||
2313 rt2x00_get_field16(word, EEPROM_RSSI_A2_LNA_A2) == 0xff)
2314 rt2x00_set_field16(&word, EEPROM_RSSI_A2_LNA_A2,
2316 rt2x00_eeprom_write(rt2x00dev, EEPROM_RSSI_A2, word);
2321 static int rt2800usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
2328 * Read EEPROM word for configuration.
2330 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2333 * Identify RF chipset.
2335 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
2336 rt2x00usb_register_read(rt2x00dev, MAC_CSR0, ®);
2337 rt2x00_set_chip(rt2x00dev, RT2870, value, reg);
2340 * The check for rt2860 is not a typo, some rt2870 hardware
2341 * identifies itself as rt2860 in the CSR register.
2343 if (!rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28600000) &&
2344 !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28700000) &&
2345 !rt2x00_check_rev(&rt2x00dev->chip, 0xfff00000, 0x28800000) &&
2346 !rt2x00_check_rev(&rt2x00dev->chip, 0xffff0000, 0x30700000)) {
2347 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
2351 if (!rt2x00_rf(&rt2x00dev->chip, RF2820) &&
2352 !rt2x00_rf(&rt2x00dev->chip, RF2850) &&
2353 !rt2x00_rf(&rt2x00dev->chip, RF2720) &&
2354 !rt2x00_rf(&rt2x00dev->chip, RF2750) &&
2355 !rt2x00_rf(&rt2x00dev->chip, RF3020) &&
2356 !rt2x00_rf(&rt2x00dev->chip, RF2020)) {
2357 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
2362 * Identify default antenna configuration.
2364 rt2x00dev->default_ant.tx =
2365 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH);
2366 rt2x00dev->default_ant.rx =
2367 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH);
2370 * Read frequency offset and RF programming sequence.
2372 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ, &eeprom);
2373 rt2x00dev->freq_offset = rt2x00_get_field16(eeprom, EEPROM_FREQ_OFFSET);
2376 * Read external LNA informations.
2378 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
2380 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_A))
2381 __set_bit(CONFIG_EXTERNAL_LNA_A, &rt2x00dev->flags);
2382 if (rt2x00_get_field16(eeprom, EEPROM_NIC_EXTERNAL_LNA_BG))
2383 __set_bit(CONFIG_EXTERNAL_LNA_BG, &rt2x00dev->flags);
2386 * Detect if this device has an hardware controlled radio.
2388 #ifdef CONFIG_RT2X00_LIB_RFKILL
2389 if (rt2x00_get_field16(eeprom, EEPROM_NIC_HW_RADIO))
2390 __set_bit(CONFIG_SUPPORT_HW_BUTTON, &rt2x00dev->flags);
2391 #endif /* CONFIG_RT2X00_LIB_RFKILL */
2394 * Store led settings, for correct led behaviour.
2396 #ifdef CONFIG_RT2X00_LIB_LEDS
2397 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_radio, LED_TYPE_RADIO);
2398 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_assoc, LED_TYPE_ASSOC);
2399 rt2800usb_init_led(rt2x00dev, &rt2x00dev->led_qual, LED_TYPE_QUALITY);
2401 rt2x00_eeprom_read(rt2x00dev, EEPROM_FREQ,
2402 &rt2x00dev->led_mcu_reg);
2403 #endif /* CONFIG_RT2X00_LIB_LEDS */
2409 * RF value list for rt2870
2410 * Supports: 2.4 GHz (all) & 5.2 GHz (RF2850 & RF2750)
2412 static const struct rf_channel rf_vals[] = {
2413 { 1, 0x18402ecc, 0x184c0786, 0x1816b455, 0x1800510b },
2414 { 2, 0x18402ecc, 0x184c0786, 0x18168a55, 0x1800519f },
2415 { 3, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800518b },
2416 { 4, 0x18402ecc, 0x184c078a, 0x18168a55, 0x1800519f },
2417 { 5, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800518b },
2418 { 6, 0x18402ecc, 0x184c078e, 0x18168a55, 0x1800519f },
2419 { 7, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800518b },
2420 { 8, 0x18402ecc, 0x184c0792, 0x18168a55, 0x1800519f },
2421 { 9, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800518b },
2422 { 10, 0x18402ecc, 0x184c0796, 0x18168a55, 0x1800519f },
2423 { 11, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800518b },
2424 { 12, 0x18402ecc, 0x184c079a, 0x18168a55, 0x1800519f },
2425 { 13, 0x18402ecc, 0x184c079e, 0x18168a55, 0x1800518b },
2426 { 14, 0x18402ecc, 0x184c07a2, 0x18168a55, 0x18005193 },
2428 /* 802.11 UNI / HyperLan 2 */
2429 { 36, 0x18402ecc, 0x184c099a, 0x18158a55, 0x180ed1a3 },
2430 { 38, 0x18402ecc, 0x184c099e, 0x18158a55, 0x180ed193 },
2431 { 40, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed183 },
2432 { 44, 0x18402ec8, 0x184c0682, 0x18158a55, 0x180ed1a3 },
2433 { 46, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed18b },
2434 { 48, 0x18402ec8, 0x184c0686, 0x18158a55, 0x180ed19b },
2435 { 52, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed193 },
2436 { 54, 0x18402ec8, 0x184c068a, 0x18158a55, 0x180ed1a3 },
2437 { 56, 0x18402ec8, 0x184c068e, 0x18158a55, 0x180ed18b },
2438 { 60, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed183 },
2439 { 62, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed193 },
2440 { 64, 0x18402ec8, 0x184c0692, 0x18158a55, 0x180ed1a3 },
2442 /* 802.11 HyperLan 2 */
2443 { 100, 0x18402ec8, 0x184c06b2, 0x18178a55, 0x180ed783 },
2444 { 102, 0x18402ec8, 0x184c06b2, 0x18578a55, 0x180ed793 },
2445 { 104, 0x18402ec8, 0x185c06b2, 0x18578a55, 0x180ed1a3 },
2446 { 108, 0x18402ecc, 0x185c0a32, 0x18578a55, 0x180ed193 },
2447 { 110, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed183 },
2448 { 112, 0x18402ecc, 0x184c0a36, 0x18178a55, 0x180ed19b },
2449 { 116, 0x18402ecc, 0x184c0a3a, 0x18178a55, 0x180ed1a3 },
2450 { 118, 0x18402ecc, 0x184c0a3e, 0x18178a55, 0x180ed193 },
2451 { 120, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed183 },
2452 { 124, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed193 },
2453 { 126, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed15b },
2454 { 128, 0x18402ec4, 0x184c0382, 0x18178a55, 0x180ed1a3 },
2455 { 132, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed18b },
2456 { 134, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed193 },
2457 { 136, 0x18402ec4, 0x184c0386, 0x18178a55, 0x180ed19b },
2458 { 140, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed183 },
2461 { 149, 0x18402ec4, 0x184c038a, 0x18178a55, 0x180ed1a7 },
2462 { 151, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed187 },
2463 { 153, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed18f },
2464 { 157, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed19f },
2465 { 159, 0x18402ec4, 0x184c038e, 0x18178a55, 0x180ed1a7 },
2466 { 161, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed187 },
2467 { 165, 0x18402ec4, 0x184c0392, 0x18178a55, 0x180ed197 },
2468 { 167, 0x18402ec4, 0x184c03d2, 0x18179855, 0x1815531f },
2469 { 169, 0x18402ec4, 0x184c03d2, 0x18179855, 0x18155327 },
2470 { 171, 0x18402ec4, 0x184c03d6, 0x18179855, 0x18155307 },
2471 { 173, 0x18402ec4, 0x184c03d6, 0x18179855, 0x1815530f },
2474 { 184, 0x15002ccc, 0x1500491e, 0x1509be55, 0x150c0a0b },
2475 { 188, 0x15002ccc, 0x15004922, 0x1509be55, 0x150c0a13 },
2476 { 192, 0x15002ccc, 0x15004926, 0x1509be55, 0x150c0a1b },
2477 { 196, 0x15002ccc, 0x1500492a, 0x1509be55, 0x150c0a23 },
2478 { 208, 0x15002ccc, 0x1500493a, 0x1509be55, 0x150c0a13 },
2479 { 212, 0x15002ccc, 0x1500493e, 0x1509be55, 0x150c0a1b },
2480 { 216, 0x15002ccc, 0x15004982, 0x1509be55, 0x150c0a23 },
2484 * RF value list for rt3070
2487 static const struct rf_channel rf_vals_3070[] = {
2504 static int rt2800usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
2506 struct hw_mode_spec *spec = &rt2x00dev->spec;
2507 struct channel_info *info;
2514 * Initialize all hw fields.
2516 rt2x00dev->hw->flags =
2517 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
2518 IEEE80211_HW_SIGNAL_DBM |
2519 IEEE80211_HW_SUPPORTS_PS |
2520 IEEE80211_HW_PS_NULLFUNC_STACK;
2521 rt2x00dev->hw->extra_tx_headroom = TXINFO_DESC_SIZE + TXWI_DESC_SIZE;
2523 SET_IEEE80211_DEV(rt2x00dev->hw, rt2x00dev->dev);
2524 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
2525 rt2x00_eeprom_addr(rt2x00dev,
2526 EEPROM_MAC_ADDR_0));
2528 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
2531 * Initialize HT information.
2533 spec->ht.ht_supported = true;
2535 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2536 IEEE80211_HT_CAP_GRN_FLD |
2537 IEEE80211_HT_CAP_SGI_20 |
2538 IEEE80211_HT_CAP_SGI_40 |
2539 IEEE80211_HT_CAP_TX_STBC |
2540 IEEE80211_HT_CAP_RX_STBC |
2541 IEEE80211_HT_CAP_PSMP_SUPPORT;
2542 spec->ht.ampdu_factor = 3;
2543 spec->ht.ampdu_density = 4;
2544 spec->ht.mcs.tx_params =
2545 IEEE80211_HT_MCS_TX_DEFINED |
2546 IEEE80211_HT_MCS_TX_RX_DIFF |
2547 ((rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) - 1) <<
2548 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
2550 switch (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH)) {
2552 spec->ht.mcs.rx_mask[2] = 0xff;
2554 spec->ht.mcs.rx_mask[1] = 0xff;
2556 spec->ht.mcs.rx_mask[0] = 0xff;
2557 spec->ht.mcs.rx_mask[4] = 0x1; /* MCS32 */
2562 * Initialize hw_mode information.
2564 spec->supported_bands = SUPPORT_BAND_2GHZ;
2565 spec->supported_rates = SUPPORT_RATE_CCK | SUPPORT_RATE_OFDM;
2567 if (rt2x00_rf(&rt2x00dev->chip, RF2820) ||
2568 rt2x00_rf(&rt2x00dev->chip, RF2720)) {
2569 spec->num_channels = 14;
2570 spec->channels = rf_vals;
2571 } else if (rt2x00_rf(&rt2x00dev->chip, RF2850) ||
2572 rt2x00_rf(&rt2x00dev->chip, RF2750)) {
2573 spec->supported_bands |= SUPPORT_BAND_5GHZ;
2574 spec->num_channels = ARRAY_SIZE(rf_vals);
2575 spec->channels = rf_vals;
2576 } else if (rt2x00_rf(&rt2x00dev->chip, RF3020) ||
2577 rt2x00_rf(&rt2x00dev->chip, RF2020)) {
2578 spec->num_channels = ARRAY_SIZE(rf_vals_3070);
2579 spec->channels = rf_vals_3070;
2583 * Create channel information array
2585 info = kzalloc(spec->num_channels * sizeof(*info), GFP_KERNEL);
2589 spec->channels_info = info;
2591 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG1);
2592 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_BG2);
2594 for (i = 0; i < 14; i++) {
2595 info[i].tx_power1 = TXPOWER_G_FROM_DEV(tx_power1[i]);
2596 info[i].tx_power2 = TXPOWER_G_FROM_DEV(tx_power2[i]);
2599 if (spec->num_channels > 14) {
2600 tx_power1 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A1);
2601 tx_power2 = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_A2);
2603 for (i = 14; i < spec->num_channels; i++) {
2604 info[i].tx_power1 = TXPOWER_A_FROM_DEV(tx_power1[i]);
2605 info[i].tx_power2 = TXPOWER_A_FROM_DEV(tx_power2[i]);
2612 static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
2617 * Allocate eeprom data.
2619 retval = rt2800usb_validate_eeprom(rt2x00dev);
2623 retval = rt2800usb_init_eeprom(rt2x00dev);
2628 * Initialize hw specifications.
2630 retval = rt2800usb_probe_hw_mode(rt2x00dev);
2635 * This device requires firmware.
2637 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
2638 __set_bit(DRIVER_REQUIRE_SCHEDULED, &rt2x00dev->flags);
2639 __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
2640 if (!modparam_nohwcrypt)
2641 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
2644 * Set the rssi offset.
2646 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
2652 * IEEE80211 stack callback functions.
2654 static void rt2800usb_get_tkip_seq(struct ieee80211_hw *hw, u8 hw_key_idx,
2655 u32 *iv32, u16 *iv16)
2657 struct rt2x00_dev *rt2x00dev = hw->priv;
2658 struct mac_iveiv_entry iveiv_entry;
2661 offset = MAC_IVEIV_ENTRY(hw_key_idx);
2662 rt2x00usb_register_multiread(rt2x00dev, offset,
2663 &iveiv_entry, sizeof(iveiv_entry));
2665 memcpy(&iveiv_entry.iv[0], iv16, sizeof(iv16));
2666 memcpy(&iveiv_entry.iv[4], iv32, sizeof(iv32));
2669 static int rt2800usb_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2671 struct rt2x00_dev *rt2x00dev = hw->priv;
2673 bool enabled = (value < IEEE80211_MAX_RTS_THRESHOLD);
2675 rt2x00usb_register_read(rt2x00dev, TX_RTS_CFG, ®);
2676 rt2x00_set_field32(®, TX_RTS_CFG_RTS_THRES, value);
2677 rt2x00usb_register_write(rt2x00dev, TX_RTS_CFG, reg);
2679 rt2x00usb_register_read(rt2x00dev, CCK_PROT_CFG, ®);
2680 rt2x00_set_field32(®, CCK_PROT_CFG_RTS_TH_EN, enabled);
2681 rt2x00usb_register_write(rt2x00dev, CCK_PROT_CFG, reg);
2683 rt2x00usb_register_read(rt2x00dev, OFDM_PROT_CFG, ®);
2684 rt2x00_set_field32(®, OFDM_PROT_CFG_RTS_TH_EN, enabled);
2685 rt2x00usb_register_write(rt2x00dev, OFDM_PROT_CFG, reg);
2687 rt2x00usb_register_read(rt2x00dev, MM20_PROT_CFG, ®);
2688 rt2x00_set_field32(®, MM20_PROT_CFG_RTS_TH_EN, enabled);
2689 rt2x00usb_register_write(rt2x00dev, MM20_PROT_CFG, reg);
2691 rt2x00usb_register_read(rt2x00dev, MM40_PROT_CFG, ®);
2692 rt2x00_set_field32(®, MM40_PROT_CFG_RTS_TH_EN, enabled);
2693 rt2x00usb_register_write(rt2x00dev, MM40_PROT_CFG, reg);
2695 rt2x00usb_register_read(rt2x00dev, GF20_PROT_CFG, ®);
2696 rt2x00_set_field32(®, GF20_PROT_CFG_RTS_TH_EN, enabled);
2697 rt2x00usb_register_write(rt2x00dev, GF20_PROT_CFG, reg);
2699 rt2x00usb_register_read(rt2x00dev, GF40_PROT_CFG, ®);
2700 rt2x00_set_field32(®, GF40_PROT_CFG_RTS_TH_EN, enabled);
2701 rt2x00usb_register_write(rt2x00dev, GF40_PROT_CFG, reg);
2706 static int rt2800usb_conf_tx(struct ieee80211_hw *hw, u16 queue_idx,
2707 const struct ieee80211_tx_queue_params *params)
2709 struct rt2x00_dev *rt2x00dev = hw->priv;
2710 struct data_queue *queue;
2711 struct rt2x00_field32 field;
2717 * First pass the configuration through rt2x00lib, that will
2718 * update the queue settings and validate the input. After that
2719 * we are free to update the registers based on the value
2720 * in the queue parameter.
2722 retval = rt2x00mac_conf_tx(hw, queue_idx, params);
2727 * We only need to perform additional register initialization
2733 queue = rt2x00queue_get_queue(rt2x00dev, queue_idx);
2735 /* Update WMM TXOP register */
2736 offset = WMM_TXOP0_CFG + (sizeof(u32) * (!!(queue_idx & 2)));
2737 field.bit_offset = (queue_idx & 1) * 16;
2738 field.bit_mask = 0xffff << field.bit_offset;
2740 rt2x00usb_register_read(rt2x00dev, offset, ®);
2741 rt2x00_set_field32(®, field, queue->txop);
2742 rt2x00usb_register_write(rt2x00dev, offset, reg);
2744 /* Update WMM registers */
2745 field.bit_offset = queue_idx * 4;
2746 field.bit_mask = 0xf << field.bit_offset;
2748 rt2x00usb_register_read(rt2x00dev, WMM_AIFSN_CFG, ®);
2749 rt2x00_set_field32(®, field, queue->aifs);
2750 rt2x00usb_register_write(rt2x00dev, WMM_AIFSN_CFG, reg);
2752 rt2x00usb_register_read(rt2x00dev, WMM_CWMIN_CFG, ®);
2753 rt2x00_set_field32(®, field, queue->cw_min);
2754 rt2x00usb_register_write(rt2x00dev, WMM_CWMIN_CFG, reg);
2756 rt2x00usb_register_read(rt2x00dev, WMM_CWMAX_CFG, ®);
2757 rt2x00_set_field32(®, field, queue->cw_max);
2758 rt2x00usb_register_write(rt2x00dev, WMM_CWMAX_CFG, reg);
2760 /* Update EDCA registers */
2761 offset = EDCA_AC0_CFG + (sizeof(u32) * queue_idx);
2763 rt2x00usb_register_read(rt2x00dev, offset, ®);
2764 rt2x00_set_field32(®, EDCA_AC0_CFG_TX_OP, queue->txop);
2765 rt2x00_set_field32(®, EDCA_AC0_CFG_AIFSN, queue->aifs);
2766 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMIN, queue->cw_min);
2767 rt2x00_set_field32(®, EDCA_AC0_CFG_CWMAX, queue->cw_max);
2768 rt2x00usb_register_write(rt2x00dev, offset, reg);
2773 static u64 rt2800usb_get_tsf(struct ieee80211_hw *hw)
2775 struct rt2x00_dev *rt2x00dev = hw->priv;
2779 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW1, ®);
2780 tsf = (u64) rt2x00_get_field32(reg, TSF_TIMER_DW1_HIGH_WORD) << 32;
2781 rt2x00usb_register_read(rt2x00dev, TSF_TIMER_DW0, ®);
2782 tsf |= rt2x00_get_field32(reg, TSF_TIMER_DW0_LOW_WORD);
2787 static const struct ieee80211_ops rt2800usb_mac80211_ops = {
2789 .start = rt2x00mac_start,
2790 .stop = rt2x00mac_stop,
2791 .add_interface = rt2x00mac_add_interface,
2792 .remove_interface = rt2x00mac_remove_interface,
2793 .config = rt2x00mac_config,
2794 .configure_filter = rt2x00mac_configure_filter,
2795 .set_key = rt2x00mac_set_key,
2796 .get_stats = rt2x00mac_get_stats,
2797 .get_tkip_seq = rt2800usb_get_tkip_seq,
2798 .set_rts_threshold = rt2800usb_set_rts_threshold,
2799 .bss_info_changed = rt2x00mac_bss_info_changed,
2800 .conf_tx = rt2800usb_conf_tx,
2801 .get_tx_stats = rt2x00mac_get_tx_stats,
2802 .get_tsf = rt2800usb_get_tsf,
2805 static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
2806 .probe_hw = rt2800usb_probe_hw,
2807 .get_firmware_name = rt2800usb_get_firmware_name,
2808 .check_firmware = rt2800usb_check_firmware,
2809 .load_firmware = rt2800usb_load_firmware,
2810 .initialize = rt2x00usb_initialize,
2811 .uninitialize = rt2x00usb_uninitialize,
2812 .clear_entry = rt2x00usb_clear_entry,
2813 .set_device_state = rt2800usb_set_device_state,
2814 .rfkill_poll = rt2800usb_rfkill_poll,
2815 .link_stats = rt2800usb_link_stats,
2816 .reset_tuner = rt2800usb_reset_tuner,
2817 .link_tuner = rt2800usb_link_tuner,
2818 .write_tx_desc = rt2800usb_write_tx_desc,
2819 .write_tx_data = rt2x00usb_write_tx_data,
2820 .write_beacon = rt2800usb_write_beacon,
2821 .get_tx_data_len = rt2800usb_get_tx_data_len,
2822 .kick_tx_queue = rt2800usb_kick_tx_queue,
2823 .kill_tx_queue = rt2x00usb_kill_tx_queue,
2824 .fill_rxdone = rt2800usb_fill_rxdone,
2825 .config_shared_key = rt2800usb_config_shared_key,
2826 .config_pairwise_key = rt2800usb_config_pairwise_key,
2827 .config_filter = rt2800usb_config_filter,
2828 .config_intf = rt2800usb_config_intf,
2829 .config_erp = rt2800usb_config_erp,
2830 .config_ant = rt2800usb_config_ant,
2831 .config = rt2800usb_config,
2834 static const struct data_queue_desc rt2800usb_queue_rx = {
2835 .entry_num = RX_ENTRIES,
2836 .data_size = AGGREGATION_SIZE,
2837 .desc_size = RXD_DESC_SIZE + RXWI_DESC_SIZE,
2838 .priv_size = sizeof(struct queue_entry_priv_usb),
2841 static const struct data_queue_desc rt2800usb_queue_tx = {
2842 .entry_num = TX_ENTRIES,
2843 .data_size = AGGREGATION_SIZE,
2844 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
2845 .priv_size = sizeof(struct queue_entry_priv_usb),
2848 static const struct data_queue_desc rt2800usb_queue_bcn = {
2849 .entry_num = 8 * BEACON_ENTRIES,
2850 .data_size = MGMT_FRAME_SIZE,
2851 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
2852 .priv_size = sizeof(struct queue_entry_priv_usb),
2855 static const struct rt2x00_ops rt2800usb_ops = {
2856 .name = KBUILD_MODNAME,
2859 .eeprom_size = EEPROM_SIZE,
2861 .tx_queues = NUM_TX_QUEUES,
2862 .rx = &rt2800usb_queue_rx,
2863 .tx = &rt2800usb_queue_tx,
2864 .bcn = &rt2800usb_queue_bcn,
2865 .lib = &rt2800usb_rt2x00_ops,
2866 .hw = &rt2800usb_mac80211_ops,
2867 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
2868 .debugfs = &rt2800usb_rt2x00debug,
2869 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2873 * rt2800usb module information.
2875 static struct usb_device_id rt2800usb_device_table[] = {
2877 { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
2878 { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
2879 { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
2880 { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
2881 { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
2882 { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2884 { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
2886 { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
2887 { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
2889 { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
2891 { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
2892 { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
2893 { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
2894 { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
2895 { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
2897 { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
2898 { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
2899 { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
2900 { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
2902 { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
2903 { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
2904 { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
2905 { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
2907 { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
2908 { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
2910 { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
2911 { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
2912 { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
2913 { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2914 { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
2915 { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
2916 { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
2917 { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
2918 { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
2919 { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
2921 { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
2922 { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
2923 { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
2924 { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
2925 { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
2927 { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
2928 { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
2929 { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
2930 { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
2931 { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
2932 { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
2933 { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
2934 { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
2936 { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
2937 { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
2938 { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
2940 { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
2942 { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
2943 { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
2944 { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
2945 { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
2946 { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
2947 { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
2949 { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
2951 { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
2952 { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
2953 { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
2955 { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
2956 { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
2957 { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
2958 { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
2960 { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
2962 { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
2963 { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
2965 { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
2966 { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
2967 { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
2969 { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
2970 { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
2971 { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
2973 { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
2974 { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
2976 { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
2978 { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
2979 { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
2980 { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
2982 { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
2984 { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
2985 { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
2986 { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
2988 { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
2990 { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
2992 { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
2993 { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
2994 { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
2995 { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
2996 { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
2997 { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
2998 { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
2999 { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
3000 { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
3002 { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
3004 { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
3006 { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
3007 { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
3008 { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
3009 { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
3010 { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
3011 { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
3012 { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
3013 { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
3014 { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
3015 { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
3016 { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
3017 { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
3019 { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
3020 { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
3021 { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
3022 { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
3023 { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
3024 { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
3025 { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
3026 { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
3027 { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
3029 { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
3031 { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
3032 { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
3033 { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
3035 { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
3037 { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
3038 { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
3040 { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
3041 { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
3042 { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
3043 { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
3045 { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
3046 { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
3050 MODULE_AUTHOR(DRV_PROJECT);
3051 MODULE_VERSION(DRV_VERSION);
3052 MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
3053 MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
3054 MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
3055 MODULE_FIRMWARE(FIRMWARE_RT2870);
3056 MODULE_LICENSE("GPL");
3058 static struct usb_driver rt2800usb_driver = {
3059 .name = KBUILD_MODNAME,
3060 .id_table = rt2800usb_device_table,
3061 .probe = rt2x00usb_probe,
3062 .disconnect = rt2x00usb_disconnect,
3063 .suspend = rt2x00usb_suspend,
3064 .resume = rt2x00usb_resume,
3067 static int __init rt2800usb_init(void)
3069 return usb_register(&rt2800usb_driver);
3072 static void __exit rt2800usb_exit(void)
3074 usb_deregister(&rt2800usb_driver);
3077 module_init(rt2800usb_init);
3078 module_exit(rt2800usb_exit);