2 Copyright (C) 2009 Ivo van Doorn <IvDoorn@gmail.com>
3 Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
4 Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
5 Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
6 Copyright (C) 2009 Axel Kollhofer <rain_maker@root-forum.org>
7 <http://rt2x00.serialmonkey.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the
21 Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 Abstract: rt2800usb device specific routines.
28 Supported chipsets: RT2800U.
31 #include <linux/crc-ccitt.h>
32 #include <linux/delay.h>
33 #include <linux/etherdevice.h>
34 #include <linux/init.h>
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/usb.h>
40 #include "rt2x00usb.h"
41 #include "rt2800lib.h"
43 #include "rt2800usb.h"
46 * Allow hardware encryption to be disabled.
48 static int modparam_nohwcrypt = 1;
49 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
50 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
55 static char *rt2800usb_get_firmware_name(struct rt2x00_dev *rt2x00dev)
57 return FIRMWARE_RT2870;
60 static bool rt2800usb_check_crc(const u8 *data, const size_t len)
66 * The last 2 bytes in the firmware array are the crc checksum itself,
67 * this means that we should never pass those 2 bytes to the crc
70 fw_crc = (data[len - 2] << 8 | data[len - 1]);
73 * Use the crc ccitt algorithm.
74 * This will return the same value as the legacy driver which
75 * used bit ordering reversion on the both the firmware bytes
76 * before input input as well as on the final output.
77 * Obviously using crc ccitt directly is much more efficient.
79 crc = crc_ccitt(~0, data, len - 2);
82 * There is a small difference between the crc-itu-t + bitrev and
83 * the crc-ccitt crc calculation. In the latter method the 2 bytes
84 * will be swapped, use swab16 to convert the crc to the correct
92 static int rt2800usb_check_firmware(struct rt2x00_dev *rt2x00dev,
93 const u8 *data, const size_t len)
95 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
100 * There are 2 variations of the rt2870 firmware.
103 * Note that (b) contains 2 seperate firmware blobs of 4k
104 * within the file. The first blob is the same firmware as (a),
105 * but the second blob is for the additional chipsets.
107 if (len != 4096 && len != 8192)
108 return FW_BAD_LENGTH;
111 * Check if we need the upper 4kb firmware data or not.
114 (chipset != 0x2860) &&
115 (chipset != 0x2872) &&
117 return FW_BAD_VERSION;
120 * 8kb firmware files must be checked as if it were
121 * 2 seperate firmware files.
123 while (offset < len) {
124 if (!rt2800usb_check_crc(data + offset, 4096))
133 static int rt2800usb_load_firmware(struct rt2x00_dev *rt2x00dev,
134 const u8 *data, const size_t len)
141 u16 chipset = (rt2x00_rev(&rt2x00dev->chip) >> 16) & 0xffff;
144 * Check which section of the firmware we need.
146 if ((chipset == 0x2860) ||
147 (chipset == 0x2872) ||
148 (chipset == 0x3070)) {
157 * Wait for stable hardware.
159 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
160 rt2800_register_read(rt2x00dev, MAC_CSR0, ®);
161 if (reg && reg != ~0)
166 if (i == REGISTER_BUSY_COUNT) {
167 ERROR(rt2x00dev, "Unstable hardware.\n");
172 * Write firmware to device.
174 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
175 USB_VENDOR_REQUEST_OUT,
177 data + offset, length,
178 REGISTER_TIMEOUT32(length));
180 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CID, ~0);
181 rt2800_register_write(rt2x00dev, H2M_MAILBOX_STATUS, ~0);
184 * Send firmware request to device to load firmware,
185 * we need to specify a long timeout time.
187 status = rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE,
188 0, USB_MODE_FIRMWARE,
189 REGISTER_TIMEOUT_FIRMWARE);
191 ERROR(rt2x00dev, "Failed to write Firmware to device.\n");
196 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
199 * Send signal to firmware during boot time.
201 rt2800_mcu_request(rt2x00dev, MCU_BOOT_SIGNAL, 0xff, 0, 0);
203 if ((chipset == 0x3070) ||
204 (chipset == 0x3071) ||
205 (chipset == 0x3572)) {
207 rt2800_mcu_request(rt2x00dev, MCU_CURRENT, 0, 0, 0);
212 * Wait for device to stabilize.
214 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
215 rt2800_register_read(rt2x00dev, PBF_SYS_CTRL, ®);
216 if (rt2x00_get_field32(reg, PBF_SYS_CTRL_READY))
221 if (i == REGISTER_BUSY_COUNT) {
222 ERROR(rt2x00dev, "PBF system register not ready.\n");
227 * Initialize firmware.
229 rt2800_register_write(rt2x00dev, H2M_BBP_AGENT, 0);
230 rt2800_register_write(rt2x00dev, H2M_MAILBOX_CSR, 0);
237 * Device state switch handlers.
239 static void rt2800usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
240 enum dev_state state)
244 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
245 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX,
246 (state == STATE_RADIO_RX_ON) ||
247 (state == STATE_RADIO_RX_ON_LINK));
248 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
251 static int rt2800usb_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
256 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
257 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
258 if (!rt2x00_get_field32(reg, WPDMA_GLO_CFG_TX_DMA_BUSY) &&
259 !rt2x00_get_field32(reg, WPDMA_GLO_CFG_RX_DMA_BUSY))
265 ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
269 static int rt2800usb_enable_radio(struct rt2x00_dev *rt2x00dev)
275 * Initialize all registers.
277 if (unlikely(rt2800usb_wait_wpdma_ready(rt2x00dev) ||
278 rt2800_init_registers(rt2x00dev) ||
279 rt2800_init_bbp(rt2x00dev) ||
280 rt2800_init_rfcsr(rt2x00dev)))
283 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
284 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
285 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
289 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
290 rt2x00_set_field32(®, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
291 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 1);
292 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 1);
293 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
296 rt2800_register_read(rt2x00dev, USB_DMA_CFG, ®);
297 rt2x00_set_field32(®, USB_DMA_CFG_PHY_CLEAR, 0);
298 /* Don't use bulk in aggregation when working with USB 1.1 */
299 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_EN,
300 (rt2x00dev->rx->usb_maxpacket == 512));
301 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_TIMEOUT, 128);
303 * Total room for RX frames in kilobytes, PBF might still exceed
304 * this limit so reduce the number to prevent errors.
306 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_AGG_LIMIT,
307 ((RX_ENTRIES * DATA_FRAME_SIZE) / 1024) - 3);
308 rt2x00_set_field32(®, USB_DMA_CFG_RX_BULK_EN, 1);
309 rt2x00_set_field32(®, USB_DMA_CFG_TX_BULK_EN, 1);
310 rt2800_register_write(rt2x00dev, USB_DMA_CFG, reg);
312 rt2800_register_read(rt2x00dev, MAC_SYS_CTRL, ®);
313 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_TX, 1);
314 rt2x00_set_field32(®, MAC_SYS_CTRL_ENABLE_RX, 1);
315 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, reg);
318 * Initialize LED control
320 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED1, &word);
321 rt2800_mcu_request(rt2x00dev, MCU_LED_1, 0xff,
322 word & 0xff, (word >> 8) & 0xff);
324 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED2, &word);
325 rt2800_mcu_request(rt2x00dev, MCU_LED_2, 0xff,
326 word & 0xff, (word >> 8) & 0xff);
328 rt2x00_eeprom_read(rt2x00dev, EEPROM_LED3, &word);
329 rt2800_mcu_request(rt2x00dev, MCU_LED_3, 0xff,
330 word & 0xff, (word >> 8) & 0xff);
335 static void rt2800usb_disable_radio(struct rt2x00_dev *rt2x00dev)
339 rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, ®);
340 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
341 rt2x00_set_field32(®, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
342 rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
344 rt2800_register_write(rt2x00dev, MAC_SYS_CTRL, 0);
345 rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0);
346 rt2800_register_write(rt2x00dev, TX_PIN_CFG, 0);
348 /* Wait for DMA, ignore error */
349 rt2800usb_wait_wpdma_ready(rt2x00dev);
351 rt2x00usb_disable_radio(rt2x00dev);
354 static int rt2800usb_set_state(struct rt2x00_dev *rt2x00dev,
355 enum dev_state state)
357 if (state == STATE_AWAKE)
358 rt2800_mcu_request(rt2x00dev, MCU_WAKEUP, 0xff, 0, 0);
360 rt2800_mcu_request(rt2x00dev, MCU_SLEEP, 0xff, 0, 2);
365 static int rt2800usb_set_device_state(struct rt2x00_dev *rt2x00dev,
366 enum dev_state state)
373 * Before the radio can be enabled, the device first has
374 * to be woken up. After that it needs a bit of time
375 * to be fully awake and then the radio can be enabled.
377 rt2800usb_set_state(rt2x00dev, STATE_AWAKE);
379 retval = rt2800usb_enable_radio(rt2x00dev);
381 case STATE_RADIO_OFF:
383 * After the radio has been disabled, the device should
384 * be put to sleep for powersaving.
386 rt2800usb_disable_radio(rt2x00dev);
387 rt2800usb_set_state(rt2x00dev, STATE_SLEEP);
389 case STATE_RADIO_RX_ON:
390 case STATE_RADIO_RX_ON_LINK:
391 case STATE_RADIO_RX_OFF:
392 case STATE_RADIO_RX_OFF_LINK:
393 rt2800usb_toggle_rx(rt2x00dev, state);
395 case STATE_RADIO_IRQ_ON:
396 case STATE_RADIO_IRQ_OFF:
397 /* No support, but no error either */
399 case STATE_DEEP_SLEEP:
403 retval = rt2800usb_set_state(rt2x00dev, state);
410 if (unlikely(retval))
411 ERROR(rt2x00dev, "Device failed to enter state %d (%d).\n",
418 * TX descriptor initialization
420 static void rt2800usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
422 struct txentry_desc *txdesc)
424 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
425 __le32 *txi = skbdesc->desc;
426 __le32 *txwi = &txi[TXINFO_DESC_SIZE / sizeof(__le32)];
430 * Initialize TX Info descriptor
432 rt2x00_desc_read(txwi, 0, &word);
433 rt2x00_set_field32(&word, TXWI_W0_FRAG,
434 test_bit(ENTRY_TXD_MORE_FRAG, &txdesc->flags));
435 rt2x00_set_field32(&word, TXWI_W0_MIMO_PS, 0);
436 rt2x00_set_field32(&word, TXWI_W0_CF_ACK, 0);
437 rt2x00_set_field32(&word, TXWI_W0_TS,
438 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &txdesc->flags));
439 rt2x00_set_field32(&word, TXWI_W0_AMPDU,
440 test_bit(ENTRY_TXD_HT_AMPDU, &txdesc->flags));
441 rt2x00_set_field32(&word, TXWI_W0_MPDU_DENSITY, txdesc->mpdu_density);
442 rt2x00_set_field32(&word, TXWI_W0_TX_OP, txdesc->ifs);
443 rt2x00_set_field32(&word, TXWI_W0_MCS, txdesc->mcs);
444 rt2x00_set_field32(&word, TXWI_W0_BW,
445 test_bit(ENTRY_TXD_HT_BW_40, &txdesc->flags));
446 rt2x00_set_field32(&word, TXWI_W0_SHORT_GI,
447 test_bit(ENTRY_TXD_HT_SHORT_GI, &txdesc->flags));
448 rt2x00_set_field32(&word, TXWI_W0_STBC, txdesc->stbc);
449 rt2x00_set_field32(&word, TXWI_W0_PHYMODE, txdesc->rate_mode);
450 rt2x00_desc_write(txwi, 0, word);
452 rt2x00_desc_read(txwi, 1, &word);
453 rt2x00_set_field32(&word, TXWI_W1_ACK,
454 test_bit(ENTRY_TXD_ACK, &txdesc->flags));
455 rt2x00_set_field32(&word, TXWI_W1_NSEQ,
456 test_bit(ENTRY_TXD_GENERATE_SEQ, &txdesc->flags));
457 rt2x00_set_field32(&word, TXWI_W1_BW_WIN_SIZE, txdesc->ba_size);
458 rt2x00_set_field32(&word, TXWI_W1_WIRELESS_CLI_ID,
459 test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags) ?
460 txdesc->key_idx : 0xff);
461 rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
462 skb->len - txdesc->l2pad);
463 rt2x00_set_field32(&word, TXWI_W1_PACKETID,
464 skbdesc->entry->queue->qid + 1);
465 rt2x00_desc_write(txwi, 1, word);
468 * Always write 0 to IV/EIV fields, hardware will insert the IV
469 * from the IVEIV register when TXINFO_W0_WIV is set to 0.
470 * When TXINFO_W0_WIV is set to 1 it will use the IV data
471 * from the descriptor. The TXWI_W1_WIRELESS_CLI_ID indicates which
472 * crypto entry in the registers should be used to encrypt the frame.
474 _rt2x00_desc_write(txwi, 2, 0 /* skbdesc->iv[0] */);
475 _rt2x00_desc_write(txwi, 3, 0 /* skbdesc->iv[1] */);
478 * Initialize TX descriptor
480 rt2x00_desc_read(txi, 0, &word);
481 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_PKT_LEN,
482 skb->len + TXWI_DESC_SIZE);
483 rt2x00_set_field32(&word, TXINFO_W0_WIV,
484 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc->flags));
485 rt2x00_set_field32(&word, TXINFO_W0_QSEL, 2);
486 rt2x00_set_field32(&word, TXINFO_W0_SW_USE_LAST_ROUND, 0);
487 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_NEXT_VALID, 0);
488 rt2x00_set_field32(&word, TXINFO_W0_USB_DMA_TX_BURST,
489 test_bit(ENTRY_TXD_BURST, &txdesc->flags));
490 rt2x00_desc_write(txi, 0, word);
494 * TX data initialization
496 static void rt2800usb_write_beacon(struct queue_entry *entry)
498 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
499 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
500 unsigned int beacon_base;
504 * Add the descriptor in front of the skb.
506 skb_push(entry->skb, entry->queue->desc_size);
507 memcpy(entry->skb->data, skbdesc->desc, skbdesc->desc_len);
508 skbdesc->desc = entry->skb->data;
511 * Disable beaconing while we are reloading the beacon data,
512 * otherwise we might be sending out invalid data.
514 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
515 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 0);
516 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
519 * Write entire beacon with descriptor to register.
521 beacon_base = HW_BEACON_OFFSET(entry->entry_idx);
522 rt2x00usb_vendor_request_large_buff(rt2x00dev, USB_MULTI_WRITE,
523 USB_VENDOR_REQUEST_OUT, beacon_base,
524 entry->skb->data, entry->skb->len,
525 REGISTER_TIMEOUT32(entry->skb->len));
528 * Clean up the beacon skb.
530 dev_kfree_skb(entry->skb);
534 static int rt2800usb_get_tx_data_len(struct queue_entry *entry)
539 * The length _must_ include 4 bytes padding,
540 * it should always be multiple of 4,
541 * but it must _not_ be a multiple of the USB packet size.
543 length = roundup(entry->skb->len + 4, 4);
544 length += (4 * !(length % entry->queue->usb_maxpacket));
549 static void rt2800usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
550 const enum data_queue_qid queue)
554 if (queue != QID_BEACON) {
555 rt2x00usb_kick_tx_queue(rt2x00dev, queue);
559 rt2800_register_read(rt2x00dev, BCN_TIME_CFG, ®);
560 if (!rt2x00_get_field32(reg, BCN_TIME_CFG_BEACON_GEN)) {
561 rt2x00_set_field32(®, BCN_TIME_CFG_TSF_TICKING, 1);
562 rt2x00_set_field32(®, BCN_TIME_CFG_TBTT_ENABLE, 1);
563 rt2x00_set_field32(®, BCN_TIME_CFG_BEACON_GEN, 1);
564 rt2800_register_write(rt2x00dev, BCN_TIME_CFG, reg);
569 * RX control handlers
571 static void rt2800usb_fill_rxdone(struct queue_entry *entry,
572 struct rxdone_entry_desc *rxdesc)
574 struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
575 struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
576 __le32 *rxd = (__le32 *)entry->skb->data;
585 * Copy descriptor to the skbdesc->desc buffer, making it safe from
586 * moving of frame data in rt2x00usb.
588 memcpy(skbdesc->desc, rxd, skbdesc->desc_len);
589 rxd = (__le32 *)skbdesc->desc;
590 rxwi = &rxd[RXINFO_DESC_SIZE / sizeof(__le32)];
593 * It is now safe to read the descriptor on all architectures.
595 rt2x00_desc_read(rxd, 0, &rxd0);
596 rt2x00_desc_read(rxwi, 0, &rxwi0);
597 rt2x00_desc_read(rxwi, 1, &rxwi1);
598 rt2x00_desc_read(rxwi, 2, &rxwi2);
599 rt2x00_desc_read(rxwi, 3, &rxwi3);
601 if (rt2x00_get_field32(rxd0, RXINFO_W0_CRC_ERROR))
602 rxdesc->flags |= RX_FLAG_FAILED_FCS_CRC;
604 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags)) {
605 rxdesc->cipher = rt2x00_get_field32(rxwi0, RXWI_W0_UDF);
606 rxdesc->cipher_status =
607 rt2x00_get_field32(rxd0, RXINFO_W0_CIPHER_ERROR);
610 if (rt2x00_get_field32(rxd0, RXINFO_W0_DECRYPTED)) {
612 * Hardware has stripped IV/EIV data from 802.11 frame during
613 * decryption. Unfortunately the descriptor doesn't contain
614 * any fields with the EIV/IV data either, so they can't
615 * be restored by rt2x00lib.
617 rxdesc->flags |= RX_FLAG_IV_STRIPPED;
619 if (rxdesc->cipher_status == RX_CRYPTO_SUCCESS)
620 rxdesc->flags |= RX_FLAG_DECRYPTED;
621 else if (rxdesc->cipher_status == RX_CRYPTO_FAIL_MIC)
622 rxdesc->flags |= RX_FLAG_MMIC_ERROR;
625 if (rt2x00_get_field32(rxd0, RXINFO_W0_MY_BSS))
626 rxdesc->dev_flags |= RXDONE_MY_BSS;
628 if (rt2x00_get_field32(rxd0, RXINFO_W0_L2PAD)) {
629 rxdesc->dev_flags |= RXDONE_L2PAD;
630 skbdesc->flags |= SKBDESC_L2_PADDED;
633 if (rt2x00_get_field32(rxwi1, RXWI_W1_SHORT_GI))
634 rxdesc->flags |= RX_FLAG_SHORT_GI;
636 if (rt2x00_get_field32(rxwi1, RXWI_W1_BW))
637 rxdesc->flags |= RX_FLAG_40MHZ;
640 * Detect RX rate, always use MCS as signal type.
642 rxdesc->dev_flags |= RXDONE_SIGNAL_MCS;
643 rxdesc->rate_mode = rt2x00_get_field32(rxwi1, RXWI_W1_PHYMODE);
644 rxdesc->signal = rt2x00_get_field32(rxwi1, RXWI_W1_MCS);
647 * Mask of 0x8 bit to remove the short preamble flag.
649 if (rxdesc->rate_mode == RATE_MODE_CCK)
650 rxdesc->signal &= ~0x8;
653 (rt2x00_get_field32(rxwi2, RXWI_W2_RSSI0) +
654 rt2x00_get_field32(rxwi2, RXWI_W2_RSSI1)) / 2;
657 (rt2x00_get_field32(rxwi3, RXWI_W3_SNR0) +
658 rt2x00_get_field32(rxwi3, RXWI_W3_SNR1)) / 2;
660 rxdesc->size = rt2x00_get_field32(rxwi0, RXWI_W0_MPDU_TOTAL_BYTE_COUNT);
663 * Remove RXWI descriptor from start of buffer.
665 skb_pull(entry->skb, skbdesc->desc_len);
666 skb_trim(entry->skb, rxdesc->size);
670 * Device probe functions.
672 static int rt2800usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
674 if (rt2800_efuse_detect(rt2x00dev))
675 rt2800_read_eeprom_efuse(rt2x00dev);
677 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom,
680 return rt2800_validate_eeprom(rt2x00dev);
683 static const struct rt2800_ops rt2800usb_rt2800_ops = {
684 .register_read = rt2x00usb_register_read,
685 .register_write = rt2x00usb_register_write,
686 .register_write_lock = rt2x00usb_register_write_lock,
688 .register_multiread = rt2x00usb_register_multiread,
689 .register_multiwrite = rt2x00usb_register_multiwrite,
691 .regbusy_read = rt2x00usb_regbusy_read,
694 static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
698 rt2x00dev->priv = (void *)&rt2800usb_rt2800_ops;
701 * Allocate eeprom data.
703 retval = rt2800usb_validate_eeprom(rt2x00dev);
707 retval = rt2800_init_eeprom(rt2x00dev);
712 * Initialize hw specifications.
714 retval = rt2800_probe_hw_mode(rt2x00dev);
719 * This device has multiple filters for control frames
720 * and has a separate filter for PS Poll frames.
722 __set_bit(DRIVER_SUPPORT_CONTROL_FILTERS, &rt2x00dev->flags);
723 __set_bit(DRIVER_SUPPORT_CONTROL_FILTER_PSPOLL, &rt2x00dev->flags);
726 * This device requires firmware.
728 __set_bit(DRIVER_REQUIRE_FIRMWARE, &rt2x00dev->flags);
729 __set_bit(DRIVER_REQUIRE_L2PAD, &rt2x00dev->flags);
730 if (!modparam_nohwcrypt)
731 __set_bit(CONFIG_SUPPORT_HW_CRYPTO, &rt2x00dev->flags);
734 * Set the rssi offset.
736 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
741 static const struct rt2x00lib_ops rt2800usb_rt2x00_ops = {
742 .probe_hw = rt2800usb_probe_hw,
743 .get_firmware_name = rt2800usb_get_firmware_name,
744 .check_firmware = rt2800usb_check_firmware,
745 .load_firmware = rt2800usb_load_firmware,
746 .initialize = rt2x00usb_initialize,
747 .uninitialize = rt2x00usb_uninitialize,
748 .clear_entry = rt2x00usb_clear_entry,
749 .set_device_state = rt2800usb_set_device_state,
750 .rfkill_poll = rt2800_rfkill_poll,
751 .link_stats = rt2800_link_stats,
752 .reset_tuner = rt2800_reset_tuner,
753 .link_tuner = rt2800_link_tuner,
754 .write_tx_desc = rt2800usb_write_tx_desc,
755 .write_tx_data = rt2x00usb_write_tx_data,
756 .write_beacon = rt2800usb_write_beacon,
757 .get_tx_data_len = rt2800usb_get_tx_data_len,
758 .kick_tx_queue = rt2800usb_kick_tx_queue,
759 .kill_tx_queue = rt2x00usb_kill_tx_queue,
760 .fill_rxdone = rt2800usb_fill_rxdone,
761 .config_shared_key = rt2800_config_shared_key,
762 .config_pairwise_key = rt2800_config_pairwise_key,
763 .config_filter = rt2800_config_filter,
764 .config_intf = rt2800_config_intf,
765 .config_erp = rt2800_config_erp,
766 .config_ant = rt2800_config_ant,
767 .config = rt2800_config,
770 static const struct data_queue_desc rt2800usb_queue_rx = {
771 .entry_num = RX_ENTRIES,
772 .data_size = AGGREGATION_SIZE,
773 .desc_size = RXINFO_DESC_SIZE + RXWI_DESC_SIZE,
774 .priv_size = sizeof(struct queue_entry_priv_usb),
777 static const struct data_queue_desc rt2800usb_queue_tx = {
778 .entry_num = TX_ENTRIES,
779 .data_size = AGGREGATION_SIZE,
780 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
781 .priv_size = sizeof(struct queue_entry_priv_usb),
784 static const struct data_queue_desc rt2800usb_queue_bcn = {
785 .entry_num = 8 * BEACON_ENTRIES,
786 .data_size = MGMT_FRAME_SIZE,
787 .desc_size = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
788 .priv_size = sizeof(struct queue_entry_priv_usb),
791 static const struct rt2x00_ops rt2800usb_ops = {
792 .name = KBUILD_MODNAME,
795 .eeprom_size = EEPROM_SIZE,
797 .tx_queues = NUM_TX_QUEUES,
798 .rx = &rt2800usb_queue_rx,
799 .tx = &rt2800usb_queue_tx,
800 .bcn = &rt2800usb_queue_bcn,
801 .lib = &rt2800usb_rt2x00_ops,
802 .hw = &rt2800_mac80211_ops,
803 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
804 .debugfs = &rt2800_rt2x00debug,
805 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
809 * rt2800usb module information.
811 static struct usb_device_id rt2800usb_device_table[] = {
813 { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
814 { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
815 { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
816 { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
817 { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
818 { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
820 { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) },
822 { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
823 { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) },
825 { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
827 { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) },
828 { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) },
829 { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) },
830 { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) },
831 { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) },
833 { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) },
834 { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) },
835 { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) },
836 { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) },
838 { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) },
839 { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) },
840 { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) },
841 { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) },
843 { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) },
844 { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) },
846 { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) },
847 { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) },
848 { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) },
849 { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
850 { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
851 { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) },
852 { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) },
853 { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) },
854 { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) },
855 { USB_DEVICE(0x14b2, 0x3c28), USB_DEVICE_DATA(&rt2800usb_ops) },
857 { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) },
858 { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
859 { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
860 { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) },
861 { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) },
863 { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) },
864 { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) },
865 { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) },
866 { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) },
867 { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) },
868 { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) },
869 { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) },
870 { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) },
872 { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) },
873 { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) },
874 { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) },
876 { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) },
878 { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) },
879 { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) },
880 { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) },
881 { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) },
882 { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) },
883 { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) },
885 { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) },
887 { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) },
888 { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) },
889 { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) },
891 { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) },
892 { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) },
893 { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) },
894 { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) },
896 { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) },
898 { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) },
899 { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) },
901 { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) },
902 { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) },
903 { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) },
905 { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) },
906 { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) },
907 { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) },
909 { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) },
910 { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) },
912 { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
914 { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) },
915 { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) },
916 { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) },
918 { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) },
920 { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) },
921 { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) },
922 { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) },
924 { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) },
926 { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) },
928 { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) },
929 { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) },
930 { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) },
931 { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) },
932 { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) },
933 { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) },
934 { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) },
935 { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) },
936 { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) },
938 { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) },
940 { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) },
942 { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) },
943 { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) },
944 { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) },
945 { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) },
946 { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) },
947 { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) },
948 { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) },
949 { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) },
950 { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) },
951 { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) },
952 { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) },
953 { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) },
955 { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) },
956 { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) },
957 { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) },
958 { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) },
959 { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) },
960 { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) },
961 { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) },
962 { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) },
963 { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) },
965 { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) },
967 { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) },
968 { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) },
969 { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) },
971 { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) },
973 { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) },
974 { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) },
976 { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) },
977 { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) },
978 { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) },
979 { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) },
981 { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) },
982 { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) },
986 MODULE_AUTHOR(DRV_PROJECT);
987 MODULE_VERSION(DRV_VERSION);
988 MODULE_DESCRIPTION("Ralink RT2800 USB Wireless LAN driver.");
989 MODULE_SUPPORTED_DEVICE("Ralink RT2870 USB chipset based cards");
990 MODULE_DEVICE_TABLE(usb, rt2800usb_device_table);
991 MODULE_FIRMWARE(FIRMWARE_RT2870);
992 MODULE_LICENSE("GPL");
994 static struct usb_driver rt2800usb_driver = {
995 .name = KBUILD_MODNAME,
996 .id_table = rt2800usb_device_table,
997 .probe = rt2x00usb_probe,
998 .disconnect = rt2x00usb_disconnect,
999 .suspend = rt2x00usb_suspend,
1000 .resume = rt2x00usb_resume,
1003 static int __init rt2800usb_init(void)
1005 return usb_register(&rt2800usb_driver);
1008 static void __exit rt2800usb_exit(void)
1010 usb_deregister(&rt2800usb_driver);
1013 module_init(rt2800usb_init);
1014 module_exit(rt2800usb_exit);