2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt73usb device specific routines.
24 Supported chipsets: rt2571W & rt2671.
27 #include <linux/crc-itu-t.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"
40 * Allow hardware encryption to be disabled.
42 static int modparam_nohwcrypt
= 0;
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), PHY_CSR3, PHY_CSR3_BUSY, (__reg))
62 #define WAIT_FOR_RF(__dev, __reg) \
63 rt2x00usb_regbusy_read((__dev), PHY_CSR4, PHY_CSR4_BUSY, (__reg))
65 static void rt73usb_bbp_write(struct rt2x00_dev
*rt2x00dev
,
66 const unsigned int word
, const u8 value
)
70 mutex_lock(&rt2x00dev
->csr_mutex
);
73 * Wait until the BBP becomes available, afterwards we
74 * can safely write the new data into the register.
76 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
78 rt2x00_set_field32(®
, PHY_CSR3_VALUE
, value
);
79 rt2x00_set_field32(®
, PHY_CSR3_REGNUM
, word
);
80 rt2x00_set_field32(®
, PHY_CSR3_BUSY
, 1);
81 rt2x00_set_field32(®
, PHY_CSR3_READ_CONTROL
, 0);
83 rt2x00usb_register_write_lock(rt2x00dev
, PHY_CSR3
, reg
);
86 mutex_unlock(&rt2x00dev
->csr_mutex
);
89 static void rt73usb_bbp_read(struct rt2x00_dev
*rt2x00dev
,
90 const unsigned int word
, u8
*value
)
94 mutex_lock(&rt2x00dev
->csr_mutex
);
97 * Wait until the BBP becomes available, afterwards we
98 * can safely write the read request into the register.
99 * After the data has been written, we wait until hardware
100 * returns the correct value, if at any time the register
101 * doesn't become available in time, reg will be 0xffffffff
102 * which means we return 0xff to the caller.
104 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
106 rt2x00_set_field32(®
, PHY_CSR3_REGNUM
, word
);
107 rt2x00_set_field32(®
, PHY_CSR3_BUSY
, 1);
108 rt2x00_set_field32(®
, PHY_CSR3_READ_CONTROL
, 1);
110 rt2x00usb_register_write_lock(rt2x00dev
, PHY_CSR3
, reg
);
112 WAIT_FOR_BBP(rt2x00dev
, ®
);
115 *value
= rt2x00_get_field32(reg
, PHY_CSR3_VALUE
);
117 mutex_unlock(&rt2x00dev
->csr_mutex
);
120 static void rt73usb_rf_write(struct rt2x00_dev
*rt2x00dev
,
121 const unsigned int word
, const u32 value
)
128 mutex_lock(&rt2x00dev
->csr_mutex
);
131 * Wait until the RF becomes available, afterwards we
132 * can safely write the new data into the register.
134 if (WAIT_FOR_RF(rt2x00dev
, ®
)) {
136 rt2x00_set_field32(®
, PHY_CSR4_VALUE
, value
);
138 * RF5225 and RF2527 contain 21 bits per RF register value,
139 * all others contain 20 bits.
141 rt2x00_set_field32(®
, PHY_CSR4_NUMBER_OF_BITS
,
142 20 + (rt2x00_rf(&rt2x00dev
->chip
, RF5225
) ||
143 rt2x00_rf(&rt2x00dev
->chip
, RF2527
)));
144 rt2x00_set_field32(®
, PHY_CSR4_IF_SELECT
, 0);
145 rt2x00_set_field32(®
, PHY_CSR4_BUSY
, 1);
147 rt2x00usb_register_write_lock(rt2x00dev
, PHY_CSR4
, reg
);
148 rt2x00_rf_write(rt2x00dev
, word
, value
);
151 mutex_unlock(&rt2x00dev
->csr_mutex
);
154 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
155 static const struct rt2x00debug rt73usb_rt2x00debug
= {
156 .owner
= THIS_MODULE
,
158 .read
= rt2x00usb_register_read
,
159 .write
= rt2x00usb_register_write
,
160 .flags
= RT2X00DEBUGFS_OFFSET
,
161 .word_base
= CSR_REG_BASE
,
162 .word_size
= sizeof(u32
),
163 .word_count
= CSR_REG_SIZE
/ sizeof(u32
),
166 .read
= rt2x00_eeprom_read
,
167 .write
= rt2x00_eeprom_write
,
168 .word_base
= EEPROM_BASE
,
169 .word_size
= sizeof(u16
),
170 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
173 .read
= rt73usb_bbp_read
,
174 .write
= rt73usb_bbp_write
,
175 .word_base
= BBP_BASE
,
176 .word_size
= sizeof(u8
),
177 .word_count
= BBP_SIZE
/ sizeof(u8
),
180 .read
= rt2x00_rf_read
,
181 .write
= rt73usb_rf_write
,
182 .word_base
= RF_BASE
,
183 .word_size
= sizeof(u32
),
184 .word_count
= RF_SIZE
/ sizeof(u32
),
187 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
189 #ifdef CONFIG_RT2X00_LIB_LEDS
190 static void rt73usb_brightness_set(struct led_classdev
*led_cdev
,
191 enum led_brightness brightness
)
193 struct rt2x00_led
*led
=
194 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
195 unsigned int enabled
= brightness
!= LED_OFF
;
196 unsigned int a_mode
=
197 (enabled
&& led
->rt2x00dev
->curr_band
== IEEE80211_BAND_5GHZ
);
198 unsigned int bg_mode
=
199 (enabled
&& led
->rt2x00dev
->curr_band
== IEEE80211_BAND_2GHZ
);
201 if (led
->type
== LED_TYPE_RADIO
) {
202 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
203 MCU_LEDCS_RADIO_STATUS
, enabled
);
205 rt2x00usb_vendor_request_sw(led
->rt2x00dev
, USB_LED_CONTROL
,
206 0, led
->rt2x00dev
->led_mcu_reg
,
208 } else if (led
->type
== LED_TYPE_ASSOC
) {
209 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
210 MCU_LEDCS_LINK_BG_STATUS
, bg_mode
);
211 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
212 MCU_LEDCS_LINK_A_STATUS
, a_mode
);
214 rt2x00usb_vendor_request_sw(led
->rt2x00dev
, USB_LED_CONTROL
,
215 0, led
->rt2x00dev
->led_mcu_reg
,
217 } else if (led
->type
== LED_TYPE_QUALITY
) {
219 * The brightness is divided into 6 levels (0 - 5),
220 * this means we need to convert the brightness
221 * argument into the matching level within that range.
223 rt2x00usb_vendor_request_sw(led
->rt2x00dev
, USB_LED_CONTROL
,
224 brightness
/ (LED_FULL
/ 6),
225 led
->rt2x00dev
->led_mcu_reg
,
230 static int rt73usb_blink_set(struct led_classdev
*led_cdev
,
231 unsigned long *delay_on
,
232 unsigned long *delay_off
)
234 struct rt2x00_led
*led
=
235 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
238 rt2x00usb_register_read(led
->rt2x00dev
, MAC_CSR14
, ®
);
239 rt2x00_set_field32(®
, MAC_CSR14_ON_PERIOD
, *delay_on
);
240 rt2x00_set_field32(®
, MAC_CSR14_OFF_PERIOD
, *delay_off
);
241 rt2x00usb_register_write(led
->rt2x00dev
, MAC_CSR14
, reg
);
246 static void rt73usb_init_led(struct rt2x00_dev
*rt2x00dev
,
247 struct rt2x00_led
*led
,
250 led
->rt2x00dev
= rt2x00dev
;
252 led
->led_dev
.brightness_set
= rt73usb_brightness_set
;
253 led
->led_dev
.blink_set
= rt73usb_blink_set
;
254 led
->flags
= LED_INITIALIZED
;
256 #endif /* CONFIG_RT2X00_LIB_LEDS */
259 * Configuration handlers.
261 static int rt73usb_config_shared_key(struct rt2x00_dev
*rt2x00dev
,
262 struct rt2x00lib_crypto
*crypto
,
263 struct ieee80211_key_conf
*key
)
265 struct hw_key_entry key_entry
;
266 struct rt2x00_field32 field
;
271 if (crypto
->cmd
== SET_KEY
) {
273 * rt2x00lib can't determine the correct free
274 * key_idx for shared keys. We have 1 register
275 * with key valid bits. The goal is simple, read
276 * the register, if that is full we have no slots
278 * Note that each BSS is allowed to have up to 4
279 * shared keys, so put a mask over the allowed
282 mask
= (0xf << crypto
->bssidx
);
284 rt2x00usb_register_read(rt2x00dev
, SEC_CSR0
, ®
);
287 if (reg
&& reg
== mask
)
290 key
->hw_key_idx
+= reg
? ffz(reg
) : 0;
293 * Upload key to hardware
295 memcpy(key_entry
.key
, crypto
->key
,
296 sizeof(key_entry
.key
));
297 memcpy(key_entry
.tx_mic
, crypto
->tx_mic
,
298 sizeof(key_entry
.tx_mic
));
299 memcpy(key_entry
.rx_mic
, crypto
->rx_mic
,
300 sizeof(key_entry
.rx_mic
));
302 reg
= SHARED_KEY_ENTRY(key
->hw_key_idx
);
303 timeout
= REGISTER_TIMEOUT32(sizeof(key_entry
));
304 rt2x00usb_vendor_request_large_buff(rt2x00dev
, USB_MULTI_WRITE
,
305 USB_VENDOR_REQUEST_OUT
, reg
,
311 * The cipher types are stored over 2 registers.
312 * bssidx 0 and 1 keys are stored in SEC_CSR1 and
313 * bssidx 1 and 2 keys are stored in SEC_CSR5.
314 * Using the correct defines correctly will cause overhead,
315 * so just calculate the correct offset.
317 if (key
->hw_key_idx
< 8) {
318 field
.bit_offset
= (3 * key
->hw_key_idx
);
319 field
.bit_mask
= 0x7 << field
.bit_offset
;
321 rt2x00usb_register_read(rt2x00dev
, SEC_CSR1
, ®
);
322 rt2x00_set_field32(®
, field
, crypto
->cipher
);
323 rt2x00usb_register_write(rt2x00dev
, SEC_CSR1
, reg
);
325 field
.bit_offset
= (3 * (key
->hw_key_idx
- 8));
326 field
.bit_mask
= 0x7 << field
.bit_offset
;
328 rt2x00usb_register_read(rt2x00dev
, SEC_CSR5
, ®
);
329 rt2x00_set_field32(®
, field
, crypto
->cipher
);
330 rt2x00usb_register_write(rt2x00dev
, SEC_CSR5
, reg
);
334 * The driver does not support the IV/EIV generation
335 * in hardware. However it doesn't support the IV/EIV
336 * inside the ieee80211 frame either, but requires it
337 * to be provided seperately for the descriptor.
338 * rt2x00lib will cut the IV/EIV data out of all frames
339 * given to us by mac80211, but we must tell mac80211
340 * to generate the IV/EIV data.
342 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
346 * SEC_CSR0 contains only single-bit fields to indicate
347 * a particular key is valid. Because using the FIELD32()
348 * defines directly will cause a lot of overhead we use
349 * a calculation to determine the correct bit directly.
351 mask
= 1 << key
->hw_key_idx
;
353 rt2x00usb_register_read(rt2x00dev
, SEC_CSR0
, ®
);
354 if (crypto
->cmd
== SET_KEY
)
356 else if (crypto
->cmd
== DISABLE_KEY
)
358 rt2x00usb_register_write(rt2x00dev
, SEC_CSR0
, reg
);
363 static int rt73usb_config_pairwise_key(struct rt2x00_dev
*rt2x00dev
,
364 struct rt2x00lib_crypto
*crypto
,
365 struct ieee80211_key_conf
*key
)
367 struct hw_pairwise_ta_entry addr_entry
;
368 struct hw_key_entry key_entry
;
373 if (crypto
->cmd
== SET_KEY
) {
375 * rt2x00lib can't determine the correct free
376 * key_idx for pairwise keys. We have 2 registers
377 * with key valid bits. The goal is simple, read
378 * the first register, if that is full move to
380 * When both registers are full, we drop the key,
381 * otherwise we use the first invalid entry.
383 rt2x00usb_register_read(rt2x00dev
, SEC_CSR2
, ®
);
384 if (reg
&& reg
== ~0) {
385 key
->hw_key_idx
= 32;
386 rt2x00usb_register_read(rt2x00dev
, SEC_CSR3
, ®
);
387 if (reg
&& reg
== ~0)
391 key
->hw_key_idx
+= reg
? ffz(reg
) : 0;
394 * Upload key to hardware
396 memcpy(key_entry
.key
, crypto
->key
,
397 sizeof(key_entry
.key
));
398 memcpy(key_entry
.tx_mic
, crypto
->tx_mic
,
399 sizeof(key_entry
.tx_mic
));
400 memcpy(key_entry
.rx_mic
, crypto
->rx_mic
,
401 sizeof(key_entry
.rx_mic
));
403 reg
= PAIRWISE_KEY_ENTRY(key
->hw_key_idx
);
404 timeout
= REGISTER_TIMEOUT32(sizeof(key_entry
));
405 rt2x00usb_vendor_request_large_buff(rt2x00dev
, USB_MULTI_WRITE
,
406 USB_VENDOR_REQUEST_OUT
, reg
,
412 * Send the address and cipher type to the hardware register.
413 * This data fits within the CSR cache size, so we can use
414 * rt2x00usb_register_multiwrite() directly.
416 memset(&addr_entry
, 0, sizeof(addr_entry
));
417 memcpy(&addr_entry
, crypto
->address
, ETH_ALEN
);
418 addr_entry
.cipher
= crypto
->cipher
;
420 reg
= PAIRWISE_TA_ENTRY(key
->hw_key_idx
);
421 rt2x00usb_register_multiwrite(rt2x00dev
, reg
,
422 &addr_entry
, sizeof(addr_entry
));
425 * Enable pairwise lookup table for given BSS idx,
426 * without this received frames will not be decrypted
429 rt2x00usb_register_read(rt2x00dev
, SEC_CSR4
, ®
);
430 reg
|= (1 << crypto
->bssidx
);
431 rt2x00usb_register_write(rt2x00dev
, SEC_CSR4
, reg
);
434 * The driver does not support the IV/EIV generation
435 * in hardware. However it doesn't support the IV/EIV
436 * inside the ieee80211 frame either, but requires it
437 * to be provided seperately for the descriptor.
438 * rt2x00lib will cut the IV/EIV data out of all frames
439 * given to us by mac80211, but we must tell mac80211
440 * to generate the IV/EIV data.
442 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
446 * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
447 * a particular key is valid. Because using the FIELD32()
448 * defines directly will cause a lot of overhead we use
449 * a calculation to determine the correct bit directly.
451 if (key
->hw_key_idx
< 32) {
452 mask
= 1 << key
->hw_key_idx
;
454 rt2x00usb_register_read(rt2x00dev
, SEC_CSR2
, ®
);
455 if (crypto
->cmd
== SET_KEY
)
457 else if (crypto
->cmd
== DISABLE_KEY
)
459 rt2x00usb_register_write(rt2x00dev
, SEC_CSR2
, reg
);
461 mask
= 1 << (key
->hw_key_idx
- 32);
463 rt2x00usb_register_read(rt2x00dev
, SEC_CSR3
, ®
);
464 if (crypto
->cmd
== SET_KEY
)
466 else if (crypto
->cmd
== DISABLE_KEY
)
468 rt2x00usb_register_write(rt2x00dev
, SEC_CSR3
, reg
);
474 static void rt73usb_config_filter(struct rt2x00_dev
*rt2x00dev
,
475 const unsigned int filter_flags
)
480 * Start configuration steps.
481 * Note that the version error will always be dropped
482 * and broadcast frames will always be accepted since
483 * there is no filter for it at this time.
485 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
486 rt2x00_set_field32(®
, TXRX_CSR0_DROP_CRC
,
487 !(filter_flags
& FIF_FCSFAIL
));
488 rt2x00_set_field32(®
, TXRX_CSR0_DROP_PHYSICAL
,
489 !(filter_flags
& FIF_PLCPFAIL
));
490 rt2x00_set_field32(®
, TXRX_CSR0_DROP_CONTROL
,
491 !(filter_flags
& FIF_CONTROL
));
492 rt2x00_set_field32(®
, TXRX_CSR0_DROP_NOT_TO_ME
,
493 !(filter_flags
& FIF_PROMISC_IN_BSS
));
494 rt2x00_set_field32(®
, TXRX_CSR0_DROP_TO_DS
,
495 !(filter_flags
& FIF_PROMISC_IN_BSS
) &&
496 !rt2x00dev
->intf_ap_count
);
497 rt2x00_set_field32(®
, TXRX_CSR0_DROP_VERSION_ERROR
, 1);
498 rt2x00_set_field32(®
, TXRX_CSR0_DROP_MULTICAST
,
499 !(filter_flags
& FIF_ALLMULTI
));
500 rt2x00_set_field32(®
, TXRX_CSR0_DROP_BROADCAST
, 0);
501 rt2x00_set_field32(®
, TXRX_CSR0_DROP_ACK_CTS
,
502 !(filter_flags
& FIF_CONTROL
));
503 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
506 static void rt73usb_config_intf(struct rt2x00_dev
*rt2x00dev
,
507 struct rt2x00_intf
*intf
,
508 struct rt2x00intf_conf
*conf
,
509 const unsigned int flags
)
511 unsigned int beacon_base
;
514 if (flags
& CONFIG_UPDATE_TYPE
) {
516 * Clear current synchronisation setup.
517 * For the Beacon base registers we only need to clear
518 * the first byte since that byte contains the VALID and OWNER
519 * bits which (when set to 0) will invalidate the entire beacon.
521 beacon_base
= HW_BEACON_OFFSET(intf
->beacon
->entry_idx
);
522 rt2x00usb_register_write(rt2x00dev
, beacon_base
, 0);
525 * Enable synchronisation.
527 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR9
, ®
);
528 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 1);
529 rt2x00_set_field32(®
, TXRX_CSR9_TSF_SYNC
, conf
->sync
);
530 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 1);
531 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
534 if (flags
& CONFIG_UPDATE_MAC
) {
535 reg
= le32_to_cpu(conf
->mac
[1]);
536 rt2x00_set_field32(®
, MAC_CSR3_UNICAST_TO_ME_MASK
, 0xff);
537 conf
->mac
[1] = cpu_to_le32(reg
);
539 rt2x00usb_register_multiwrite(rt2x00dev
, MAC_CSR2
,
540 conf
->mac
, sizeof(conf
->mac
));
543 if (flags
& CONFIG_UPDATE_BSSID
) {
544 reg
= le32_to_cpu(conf
->bssid
[1]);
545 rt2x00_set_field32(®
, MAC_CSR5_BSS_ID_MASK
, 3);
546 conf
->bssid
[1] = cpu_to_le32(reg
);
548 rt2x00usb_register_multiwrite(rt2x00dev
, MAC_CSR4
,
549 conf
->bssid
, sizeof(conf
->bssid
));
553 static void rt73usb_config_erp(struct rt2x00_dev
*rt2x00dev
,
554 struct rt2x00lib_erp
*erp
)
558 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
559 rt2x00_set_field32(®
, TXRX_CSR0_RX_ACK_TIMEOUT
, erp
->ack_timeout
);
560 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
562 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR4
, ®
);
563 rt2x00_set_field32(®
, TXRX_CSR4_AUTORESPOND_PREAMBLE
,
564 !!erp
->short_preamble
);
565 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR4
, reg
);
567 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR5
, erp
->basic_rates
);
569 rt2x00usb_register_read(rt2x00dev
, MAC_CSR9
, ®
);
570 rt2x00_set_field32(®
, MAC_CSR9_SLOT_TIME
, erp
->slot_time
);
571 rt2x00usb_register_write(rt2x00dev
, MAC_CSR9
, reg
);
573 rt2x00usb_register_read(rt2x00dev
, MAC_CSR8
, ®
);
574 rt2x00_set_field32(®
, MAC_CSR8_SIFS
, erp
->sifs
);
575 rt2x00_set_field32(®
, MAC_CSR8_SIFS_AFTER_RX_OFDM
, 3);
576 rt2x00_set_field32(®
, MAC_CSR8_EIFS
, erp
->eifs
);
577 rt2x00usb_register_write(rt2x00dev
, MAC_CSR8
, reg
);
580 static void rt73usb_config_antenna_5x(struct rt2x00_dev
*rt2x00dev
,
581 struct antenna_setup
*ant
)
588 rt73usb_bbp_read(rt2x00dev
, 3, &r3
);
589 rt73usb_bbp_read(rt2x00dev
, 4, &r4
);
590 rt73usb_bbp_read(rt2x00dev
, 77, &r77
);
592 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, 0);
595 * Configure the RX antenna.
598 case ANTENNA_HW_DIVERSITY
:
599 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 2);
600 temp
= !test_bit(CONFIG_FRAME_TYPE
, &rt2x00dev
->flags
)
601 && (rt2x00dev
->curr_band
!= IEEE80211_BAND_5GHZ
);
602 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
, temp
);
605 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
606 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
, 0);
607 if (rt2x00dev
->curr_band
== IEEE80211_BAND_5GHZ
)
608 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
610 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
614 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
615 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
, 0);
616 if (rt2x00dev
->curr_band
== IEEE80211_BAND_5GHZ
)
617 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
619 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
623 rt73usb_bbp_write(rt2x00dev
, 77, r77
);
624 rt73usb_bbp_write(rt2x00dev
, 3, r3
);
625 rt73usb_bbp_write(rt2x00dev
, 4, r4
);
628 static void rt73usb_config_antenna_2x(struct rt2x00_dev
*rt2x00dev
,
629 struct antenna_setup
*ant
)
635 rt73usb_bbp_read(rt2x00dev
, 3, &r3
);
636 rt73usb_bbp_read(rt2x00dev
, 4, &r4
);
637 rt73usb_bbp_read(rt2x00dev
, 77, &r77
);
639 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, 0);
640 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
,
641 !test_bit(CONFIG_FRAME_TYPE
, &rt2x00dev
->flags
));
644 * Configure the RX antenna.
647 case ANTENNA_HW_DIVERSITY
:
648 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 2);
651 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
652 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
656 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
657 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
661 rt73usb_bbp_write(rt2x00dev
, 77, r77
);
662 rt73usb_bbp_write(rt2x00dev
, 3, r3
);
663 rt73usb_bbp_write(rt2x00dev
, 4, r4
);
669 * value[0] -> non-LNA
675 static const struct antenna_sel antenna_sel_a
[] = {
676 { 96, { 0x58, 0x78 } },
677 { 104, { 0x38, 0x48 } },
678 { 75, { 0xfe, 0x80 } },
679 { 86, { 0xfe, 0x80 } },
680 { 88, { 0xfe, 0x80 } },
681 { 35, { 0x60, 0x60 } },
682 { 97, { 0x58, 0x58 } },
683 { 98, { 0x58, 0x58 } },
686 static const struct antenna_sel antenna_sel_bg
[] = {
687 { 96, { 0x48, 0x68 } },
688 { 104, { 0x2c, 0x3c } },
689 { 75, { 0xfe, 0x80 } },
690 { 86, { 0xfe, 0x80 } },
691 { 88, { 0xfe, 0x80 } },
692 { 35, { 0x50, 0x50 } },
693 { 97, { 0x48, 0x48 } },
694 { 98, { 0x48, 0x48 } },
697 static void rt73usb_config_ant(struct rt2x00_dev
*rt2x00dev
,
698 struct antenna_setup
*ant
)
700 const struct antenna_sel
*sel
;
706 * We should never come here because rt2x00lib is supposed
707 * to catch this and send us the correct antenna explicitely.
709 BUG_ON(ant
->rx
== ANTENNA_SW_DIVERSITY
||
710 ant
->tx
== ANTENNA_SW_DIVERSITY
);
712 if (rt2x00dev
->curr_band
== IEEE80211_BAND_5GHZ
) {
714 lna
= test_bit(CONFIG_EXTERNAL_LNA_A
, &rt2x00dev
->flags
);
716 sel
= antenna_sel_bg
;
717 lna
= test_bit(CONFIG_EXTERNAL_LNA_BG
, &rt2x00dev
->flags
);
720 for (i
= 0; i
< ARRAY_SIZE(antenna_sel_a
); i
++)
721 rt73usb_bbp_write(rt2x00dev
, sel
[i
].word
, sel
[i
].value
[lna
]);
723 rt2x00usb_register_read(rt2x00dev
, PHY_CSR0
, ®
);
725 rt2x00_set_field32(®
, PHY_CSR0_PA_PE_BG
,
726 (rt2x00dev
->curr_band
== IEEE80211_BAND_2GHZ
));
727 rt2x00_set_field32(®
, PHY_CSR0_PA_PE_A
,
728 (rt2x00dev
->curr_band
== IEEE80211_BAND_5GHZ
));
730 rt2x00usb_register_write(rt2x00dev
, PHY_CSR0
, reg
);
732 if (rt2x00_rf(&rt2x00dev
->chip
, RF5226
) ||
733 rt2x00_rf(&rt2x00dev
->chip
, RF5225
))
734 rt73usb_config_antenna_5x(rt2x00dev
, ant
);
735 else if (rt2x00_rf(&rt2x00dev
->chip
, RF2528
) ||
736 rt2x00_rf(&rt2x00dev
->chip
, RF2527
))
737 rt73usb_config_antenna_2x(rt2x00dev
, ant
);
740 static void rt73usb_config_lna_gain(struct rt2x00_dev
*rt2x00dev
,
741 struct rt2x00lib_conf
*libconf
)
746 if (libconf
->conf
->channel
->band
== IEEE80211_BAND_2GHZ
) {
747 if (test_bit(CONFIG_EXTERNAL_LNA_BG
, &rt2x00dev
->flags
))
750 rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, &eeprom
);
751 lna_gain
-= rt2x00_get_field16(eeprom
, EEPROM_RSSI_OFFSET_BG_1
);
753 rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, &eeprom
);
754 lna_gain
-= rt2x00_get_field16(eeprom
, EEPROM_RSSI_OFFSET_A_1
);
757 rt2x00dev
->lna_gain
= lna_gain
;
760 static void rt73usb_config_channel(struct rt2x00_dev
*rt2x00dev
,
761 struct rf_channel
*rf
, const int txpower
)
767 rt2x00_set_field32(&rf
->rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
768 rt2x00_set_field32(&rf
->rf4
, RF4_FREQ_OFFSET
, rt2x00dev
->freq_offset
);
770 smart
= !(rt2x00_rf(&rt2x00dev
->chip
, RF5225
) ||
771 rt2x00_rf(&rt2x00dev
->chip
, RF2527
));
773 rt73usb_bbp_read(rt2x00dev
, 3, &r3
);
774 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, smart
);
775 rt73usb_bbp_write(rt2x00dev
, 3, r3
);
778 if (txpower
> MAX_TXPOWER
&& txpower
<= (MAX_TXPOWER
+ r94
))
779 r94
+= txpower
- MAX_TXPOWER
;
780 else if (txpower
< MIN_TXPOWER
&& txpower
>= (MIN_TXPOWER
- r94
))
782 rt73usb_bbp_write(rt2x00dev
, 94, r94
);
784 rt73usb_rf_write(rt2x00dev
, 1, rf
->rf1
);
785 rt73usb_rf_write(rt2x00dev
, 2, rf
->rf2
);
786 rt73usb_rf_write(rt2x00dev
, 3, rf
->rf3
& ~0x00000004);
787 rt73usb_rf_write(rt2x00dev
, 4, rf
->rf4
);
789 rt73usb_rf_write(rt2x00dev
, 1, rf
->rf1
);
790 rt73usb_rf_write(rt2x00dev
, 2, rf
->rf2
);
791 rt73usb_rf_write(rt2x00dev
, 3, rf
->rf3
| 0x00000004);
792 rt73usb_rf_write(rt2x00dev
, 4, rf
->rf4
);
794 rt73usb_rf_write(rt2x00dev
, 1, rf
->rf1
);
795 rt73usb_rf_write(rt2x00dev
, 2, rf
->rf2
);
796 rt73usb_rf_write(rt2x00dev
, 3, rf
->rf3
& ~0x00000004);
797 rt73usb_rf_write(rt2x00dev
, 4, rf
->rf4
);
802 static void rt73usb_config_txpower(struct rt2x00_dev
*rt2x00dev
,
805 struct rf_channel rf
;
807 rt2x00_rf_read(rt2x00dev
, 1, &rf
.rf1
);
808 rt2x00_rf_read(rt2x00dev
, 2, &rf
.rf2
);
809 rt2x00_rf_read(rt2x00dev
, 3, &rf
.rf3
);
810 rt2x00_rf_read(rt2x00dev
, 4, &rf
.rf4
);
812 rt73usb_config_channel(rt2x00dev
, &rf
, txpower
);
815 static void rt73usb_config_retry_limit(struct rt2x00_dev
*rt2x00dev
,
816 struct rt2x00lib_conf
*libconf
)
820 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR4
, ®
);
821 rt2x00_set_field32(®
, TXRX_CSR4_LONG_RETRY_LIMIT
,
822 libconf
->conf
->long_frame_max_tx_count
);
823 rt2x00_set_field32(®
, TXRX_CSR4_SHORT_RETRY_LIMIT
,
824 libconf
->conf
->short_frame_max_tx_count
);
825 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR4
, reg
);
828 static void rt73usb_config_duration(struct rt2x00_dev
*rt2x00dev
,
829 struct rt2x00lib_conf
*libconf
)
833 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
834 rt2x00_set_field32(®
, TXRX_CSR0_TSF_OFFSET
, IEEE80211_HEADER
);
835 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
837 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR4
, ®
);
838 rt2x00_set_field32(®
, TXRX_CSR4_AUTORESPOND_ENABLE
, 1);
839 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR4
, reg
);
841 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR9
, ®
);
842 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_INTERVAL
,
843 libconf
->conf
->beacon_int
* 16);
844 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
847 static void rt73usb_config(struct rt2x00_dev
*rt2x00dev
,
848 struct rt2x00lib_conf
*libconf
,
849 const unsigned int flags
)
851 /* Always recalculate LNA gain before changing configuration */
852 rt73usb_config_lna_gain(rt2x00dev
, libconf
);
854 if (flags
& IEEE80211_CONF_CHANGE_CHANNEL
)
855 rt73usb_config_channel(rt2x00dev
, &libconf
->rf
,
856 libconf
->conf
->power_level
);
857 if ((flags
& IEEE80211_CONF_CHANGE_POWER
) &&
858 !(flags
& IEEE80211_CONF_CHANGE_CHANNEL
))
859 rt73usb_config_txpower(rt2x00dev
, libconf
->conf
->power_level
);
860 if (flags
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
861 rt73usb_config_retry_limit(rt2x00dev
, libconf
);
862 if (flags
& IEEE80211_CONF_CHANGE_BEACON_INTERVAL
)
863 rt73usb_config_duration(rt2x00dev
, libconf
);
869 static void rt73usb_link_stats(struct rt2x00_dev
*rt2x00dev
,
870 struct link_qual
*qual
)
875 * Update FCS error count from register.
877 rt2x00usb_register_read(rt2x00dev
, STA_CSR0
, ®
);
878 qual
->rx_failed
= rt2x00_get_field32(reg
, STA_CSR0_FCS_ERROR
);
881 * Update False CCA count from register.
883 rt2x00usb_register_read(rt2x00dev
, STA_CSR1
, ®
);
884 qual
->false_cca
= rt2x00_get_field32(reg
, STA_CSR1_FALSE_CCA_ERROR
);
887 static void rt73usb_reset_tuner(struct rt2x00_dev
*rt2x00dev
)
889 rt73usb_bbp_write(rt2x00dev
, 17, 0x20);
890 rt2x00dev
->link
.vgc_level
= 0x20;
893 static void rt73usb_link_tuner(struct rt2x00_dev
*rt2x00dev
)
895 int rssi
= rt2x00_get_link_rssi(&rt2x00dev
->link
);
900 rt73usb_bbp_read(rt2x00dev
, 17, &r17
);
903 * Determine r17 bounds.
905 if (rt2x00dev
->rx_status
.band
== IEEE80211_BAND_5GHZ
) {
909 if (test_bit(CONFIG_EXTERNAL_LNA_A
, &rt2x00dev
->flags
)) {
917 } else if (rssi
> -84) {
925 if (test_bit(CONFIG_EXTERNAL_LNA_BG
, &rt2x00dev
->flags
)) {
932 * If we are not associated, we should go straight to the
933 * dynamic CCA tuning.
935 if (!rt2x00dev
->intf_associated
)
936 goto dynamic_cca_tune
;
939 * Special big-R17 for very short distance
943 rt73usb_bbp_write(rt2x00dev
, 17, 0x60);
948 * Special big-R17 for short distance
952 rt73usb_bbp_write(rt2x00dev
, 17, up_bound
);
957 * Special big-R17 for middle-short distance
961 if (r17
!= low_bound
)
962 rt73usb_bbp_write(rt2x00dev
, 17, low_bound
);
967 * Special mid-R17 for middle distance
970 if (r17
!= (low_bound
+ 0x10))
971 rt73usb_bbp_write(rt2x00dev
, 17, low_bound
+ 0x08);
976 * Special case: Change up_bound based on the rssi.
977 * Lower up_bound when rssi is weaker then -74 dBm.
979 up_bound
-= 2 * (-74 - rssi
);
980 if (low_bound
> up_bound
)
981 up_bound
= low_bound
;
983 if (r17
> up_bound
) {
984 rt73usb_bbp_write(rt2x00dev
, 17, up_bound
);
991 * r17 does not yet exceed upper limit, continue and base
992 * the r17 tuning on the false CCA count.
994 if (rt2x00dev
->link
.qual
.false_cca
> 512 && r17
< up_bound
) {
998 rt73usb_bbp_write(rt2x00dev
, 17, r17
);
999 } else if (rt2x00dev
->link
.qual
.false_cca
< 100 && r17
> low_bound
) {
1001 if (r17
< low_bound
)
1003 rt73usb_bbp_write(rt2x00dev
, 17, r17
);
1008 * Firmware functions
1010 static char *rt73usb_get_firmware_name(struct rt2x00_dev
*rt2x00dev
)
1012 return FIRMWARE_RT2571
;
1015 static u16
rt73usb_get_firmware_crc(const void *data
, const size_t len
)
1020 * Use the crc itu-t algorithm.
1021 * The last 2 bytes in the firmware array are the crc checksum itself,
1022 * this means that we should never pass those 2 bytes to the crc
1025 crc
= crc_itu_t(0, data
, len
- 2);
1026 crc
= crc_itu_t_byte(crc
, 0);
1027 crc
= crc_itu_t_byte(crc
, 0);
1032 static int rt73usb_load_firmware(struct rt2x00_dev
*rt2x00dev
, const void *data
,
1040 * Wait for stable hardware.
1042 for (i
= 0; i
< 100; i
++) {
1043 rt2x00usb_register_read(rt2x00dev
, MAC_CSR0
, ®
);
1050 ERROR(rt2x00dev
, "Unstable hardware.\n");
1055 * Write firmware to device.
1057 rt2x00usb_vendor_request_large_buff(rt2x00dev
, USB_MULTI_WRITE
,
1058 USB_VENDOR_REQUEST_OUT
,
1059 FIRMWARE_IMAGE_BASE
,
1061 REGISTER_TIMEOUT32(len
));
1064 * Send firmware request to device to load firmware,
1065 * we need to specify a long timeout time.
1067 status
= rt2x00usb_vendor_request_sw(rt2x00dev
, USB_DEVICE_MODE
,
1068 0, USB_MODE_FIRMWARE
,
1069 REGISTER_TIMEOUT_FIRMWARE
);
1071 ERROR(rt2x00dev
, "Failed to write Firmware to device.\n");
1079 * Initialization functions.
1081 static int rt73usb_init_registers(struct rt2x00_dev
*rt2x00dev
)
1085 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
1086 rt2x00_set_field32(®
, TXRX_CSR0_AUTO_TX_SEQ
, 1);
1087 rt2x00_set_field32(®
, TXRX_CSR0_DISABLE_RX
, 0);
1088 rt2x00_set_field32(®
, TXRX_CSR0_TX_WITHOUT_WAITING
, 0);
1089 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
1091 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
1092 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID0
, 47); /* CCK Signal */
1093 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID0_VALID
, 1);
1094 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID1
, 30); /* Rssi */
1095 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID1_VALID
, 1);
1096 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID2
, 42); /* OFDM Rate */
1097 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID2_VALID
, 1);
1098 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID3
, 30); /* Rssi */
1099 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID3_VALID
, 1);
1100 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
1103 * CCK TXD BBP registers
1105 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
1106 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID0
, 13);
1107 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID0_VALID
, 1);
1108 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID1
, 12);
1109 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID1_VALID
, 1);
1110 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID2
, 11);
1111 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID2_VALID
, 1);
1112 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID3
, 10);
1113 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID3_VALID
, 1);
1114 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
1117 * OFDM TXD BBP registers
1119 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR3
, ®
);
1120 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID0
, 7);
1121 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID0_VALID
, 1);
1122 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID1
, 6);
1123 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID1_VALID
, 1);
1124 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID2
, 5);
1125 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID2_VALID
, 1);
1126 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR3
, reg
);
1128 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR7
, ®
);
1129 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_6MBS
, 59);
1130 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_9MBS
, 53);
1131 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_12MBS
, 49);
1132 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_18MBS
, 46);
1133 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR7
, reg
);
1135 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR8
, ®
);
1136 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_24MBS
, 44);
1137 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_36MBS
, 42);
1138 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_48MBS
, 42);
1139 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_54MBS
, 42);
1140 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR8
, reg
);
1142 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR9
, ®
);
1143 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_INTERVAL
, 0);
1144 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 0);
1145 rt2x00_set_field32(®
, TXRX_CSR9_TSF_SYNC
, 0);
1146 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 0);
1147 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1148 rt2x00_set_field32(®
, TXRX_CSR9_TIMESTAMP_COMPENSATE
, 0);
1149 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1151 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR15
, 0x0000000f);
1153 rt2x00usb_register_read(rt2x00dev
, MAC_CSR6
, ®
);
1154 rt2x00_set_field32(®
, MAC_CSR6_MAX_FRAME_UNIT
, 0xfff);
1155 rt2x00usb_register_write(rt2x00dev
, MAC_CSR6
, reg
);
1157 rt2x00usb_register_write(rt2x00dev
, MAC_CSR10
, 0x00000718);
1159 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
1162 rt2x00usb_register_write(rt2x00dev
, MAC_CSR13
, 0x00007f00);
1165 * Invalidate all Shared Keys (SEC_CSR0),
1166 * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
1168 rt2x00usb_register_write(rt2x00dev
, SEC_CSR0
, 0x00000000);
1169 rt2x00usb_register_write(rt2x00dev
, SEC_CSR1
, 0x00000000);
1170 rt2x00usb_register_write(rt2x00dev
, SEC_CSR5
, 0x00000000);
1173 if (rt2x00_rf(&rt2x00dev
->chip
, RF5225
) ||
1174 rt2x00_rf(&rt2x00dev
->chip
, RF2527
))
1175 rt2x00_set_field32(®
, PHY_CSR1_RF_RPI
, 1);
1176 rt2x00usb_register_write(rt2x00dev
, PHY_CSR1
, reg
);
1178 rt2x00usb_register_write(rt2x00dev
, PHY_CSR5
, 0x00040a06);
1179 rt2x00usb_register_write(rt2x00dev
, PHY_CSR6
, 0x00080606);
1180 rt2x00usb_register_write(rt2x00dev
, PHY_CSR7
, 0x00000408);
1182 rt2x00usb_register_read(rt2x00dev
, MAC_CSR9
, ®
);
1183 rt2x00_set_field32(®
, MAC_CSR9_CW_SELECT
, 0);
1184 rt2x00usb_register_write(rt2x00dev
, MAC_CSR9
, reg
);
1188 * For the Beacon base registers we only need to clear
1189 * the first byte since that byte contains the VALID and OWNER
1190 * bits which (when set to 0) will invalidate the entire beacon.
1192 rt2x00usb_register_write(rt2x00dev
, HW_BEACON_BASE0
, 0);
1193 rt2x00usb_register_write(rt2x00dev
, HW_BEACON_BASE1
, 0);
1194 rt2x00usb_register_write(rt2x00dev
, HW_BEACON_BASE2
, 0);
1195 rt2x00usb_register_write(rt2x00dev
, HW_BEACON_BASE3
, 0);
1198 * We must clear the error counters.
1199 * These registers are cleared on read,
1200 * so we may pass a useless variable to store the value.
1202 rt2x00usb_register_read(rt2x00dev
, STA_CSR0
, ®
);
1203 rt2x00usb_register_read(rt2x00dev
, STA_CSR1
, ®
);
1204 rt2x00usb_register_read(rt2x00dev
, STA_CSR2
, ®
);
1207 * Reset MAC and BBP registers.
1209 rt2x00usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
1210 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 1);
1211 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 1);
1212 rt2x00usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1214 rt2x00usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
1215 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 0);
1216 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 0);
1217 rt2x00usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1219 rt2x00usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
1220 rt2x00_set_field32(®
, MAC_CSR1_HOST_READY
, 1);
1221 rt2x00usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1226 static int rt73usb_wait_bbp_ready(struct rt2x00_dev
*rt2x00dev
)
1231 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1232 rt73usb_bbp_read(rt2x00dev
, 0, &value
);
1233 if ((value
!= 0xff) && (value
!= 0x00))
1235 udelay(REGISTER_BUSY_DELAY
);
1238 ERROR(rt2x00dev
, "BBP register access failed, aborting.\n");
1242 static int rt73usb_init_bbp(struct rt2x00_dev
*rt2x00dev
)
1249 if (unlikely(rt73usb_wait_bbp_ready(rt2x00dev
)))
1252 rt73usb_bbp_write(rt2x00dev
, 3, 0x80);
1253 rt73usb_bbp_write(rt2x00dev
, 15, 0x30);
1254 rt73usb_bbp_write(rt2x00dev
, 21, 0xc8);
1255 rt73usb_bbp_write(rt2x00dev
, 22, 0x38);
1256 rt73usb_bbp_write(rt2x00dev
, 23, 0x06);
1257 rt73usb_bbp_write(rt2x00dev
, 24, 0xfe);
1258 rt73usb_bbp_write(rt2x00dev
, 25, 0x0a);
1259 rt73usb_bbp_write(rt2x00dev
, 26, 0x0d);
1260 rt73usb_bbp_write(rt2x00dev
, 32, 0x0b);
1261 rt73usb_bbp_write(rt2x00dev
, 34, 0x12);
1262 rt73usb_bbp_write(rt2x00dev
, 37, 0x07);
1263 rt73usb_bbp_write(rt2x00dev
, 39, 0xf8);
1264 rt73usb_bbp_write(rt2x00dev
, 41, 0x60);
1265 rt73usb_bbp_write(rt2x00dev
, 53, 0x10);
1266 rt73usb_bbp_write(rt2x00dev
, 54, 0x18);
1267 rt73usb_bbp_write(rt2x00dev
, 60, 0x10);
1268 rt73usb_bbp_write(rt2x00dev
, 61, 0x04);
1269 rt73usb_bbp_write(rt2x00dev
, 62, 0x04);
1270 rt73usb_bbp_write(rt2x00dev
, 75, 0xfe);
1271 rt73usb_bbp_write(rt2x00dev
, 86, 0xfe);
1272 rt73usb_bbp_write(rt2x00dev
, 88, 0xfe);
1273 rt73usb_bbp_write(rt2x00dev
, 90, 0x0f);
1274 rt73usb_bbp_write(rt2x00dev
, 99, 0x00);
1275 rt73usb_bbp_write(rt2x00dev
, 102, 0x16);
1276 rt73usb_bbp_write(rt2x00dev
, 107, 0x04);
1278 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
1279 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
1281 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
1282 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
1283 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
1284 rt73usb_bbp_write(rt2x00dev
, reg_id
, value
);
1292 * Device state switch handlers.
1294 static void rt73usb_toggle_rx(struct rt2x00_dev
*rt2x00dev
,
1295 enum dev_state state
)
1299 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
1300 rt2x00_set_field32(®
, TXRX_CSR0_DISABLE_RX
,
1301 (state
== STATE_RADIO_RX_OFF
) ||
1302 (state
== STATE_RADIO_RX_OFF_LINK
));
1303 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
1306 static int rt73usb_enable_radio(struct rt2x00_dev
*rt2x00dev
)
1309 * Initialize all registers.
1311 if (unlikely(rt73usb_init_registers(rt2x00dev
) ||
1312 rt73usb_init_bbp(rt2x00dev
)))
1318 static void rt73usb_disable_radio(struct rt2x00_dev
*rt2x00dev
)
1320 rt2x00usb_register_write(rt2x00dev
, MAC_CSR10
, 0x00001818);
1323 * Disable synchronisation.
1325 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, 0);
1327 rt2x00usb_disable_radio(rt2x00dev
);
1330 static int rt73usb_set_state(struct rt2x00_dev
*rt2x00dev
, enum dev_state state
)
1336 put_to_sleep
= (state
!= STATE_AWAKE
);
1338 rt2x00usb_register_read(rt2x00dev
, MAC_CSR12
, ®
);
1339 rt2x00_set_field32(®
, MAC_CSR12_FORCE_WAKEUP
, !put_to_sleep
);
1340 rt2x00_set_field32(®
, MAC_CSR12_PUT_TO_SLEEP
, put_to_sleep
);
1341 rt2x00usb_register_write(rt2x00dev
, MAC_CSR12
, reg
);
1344 * Device is not guaranteed to be in the requested state yet.
1345 * We must wait until the register indicates that the
1346 * device has entered the correct state.
1348 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1349 rt2x00usb_register_read(rt2x00dev
, MAC_CSR12
, ®
);
1350 state
= rt2x00_get_field32(reg
, MAC_CSR12_BBP_CURRENT_STATE
);
1351 if (state
== !put_to_sleep
)
1359 static int rt73usb_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1360 enum dev_state state
)
1365 case STATE_RADIO_ON
:
1366 retval
= rt73usb_enable_radio(rt2x00dev
);
1368 case STATE_RADIO_OFF
:
1369 rt73usb_disable_radio(rt2x00dev
);
1371 case STATE_RADIO_RX_ON
:
1372 case STATE_RADIO_RX_ON_LINK
:
1373 case STATE_RADIO_RX_OFF
:
1374 case STATE_RADIO_RX_OFF_LINK
:
1375 rt73usb_toggle_rx(rt2x00dev
, state
);
1377 case STATE_RADIO_IRQ_ON
:
1378 case STATE_RADIO_IRQ_OFF
:
1379 /* No support, but no error either */
1381 case STATE_DEEP_SLEEP
:
1385 retval
= rt73usb_set_state(rt2x00dev
, state
);
1392 if (unlikely(retval
))
1393 ERROR(rt2x00dev
, "Device failed to enter state %d (%d).\n",
1400 * TX descriptor initialization
1402 static void rt73usb_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
1403 struct sk_buff
*skb
,
1404 struct txentry_desc
*txdesc
)
1406 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(skb
);
1407 __le32
*txd
= skbdesc
->desc
;
1411 * Start writing the descriptor words.
1413 rt2x00_desc_read(txd
, 1, &word
);
1414 rt2x00_set_field32(&word
, TXD_W1_HOST_Q_ID
, txdesc
->queue
);
1415 rt2x00_set_field32(&word
, TXD_W1_AIFSN
, txdesc
->aifs
);
1416 rt2x00_set_field32(&word
, TXD_W1_CWMIN
, txdesc
->cw_min
);
1417 rt2x00_set_field32(&word
, TXD_W1_CWMAX
, txdesc
->cw_max
);
1418 rt2x00_set_field32(&word
, TXD_W1_IV_OFFSET
, txdesc
->iv_offset
);
1419 rt2x00_set_field32(&word
, TXD_W1_HW_SEQUENCE
,
1420 test_bit(ENTRY_TXD_GENERATE_SEQ
, &txdesc
->flags
));
1421 rt2x00_desc_write(txd
, 1, word
);
1423 rt2x00_desc_read(txd
, 2, &word
);
1424 rt2x00_set_field32(&word
, TXD_W2_PLCP_SIGNAL
, txdesc
->signal
);
1425 rt2x00_set_field32(&word
, TXD_W2_PLCP_SERVICE
, txdesc
->service
);
1426 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_LOW
, txdesc
->length_low
);
1427 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_HIGH
, txdesc
->length_high
);
1428 rt2x00_desc_write(txd
, 2, word
);
1430 if (test_bit(ENTRY_TXD_ENCRYPT
, &txdesc
->flags
)) {
1431 _rt2x00_desc_write(txd
, 3, skbdesc
->iv
[0]);
1432 _rt2x00_desc_write(txd
, 4, skbdesc
->iv
[1]);
1435 rt2x00_desc_read(txd
, 5, &word
);
1436 rt2x00_set_field32(&word
, TXD_W5_TX_POWER
,
1437 TXPOWER_TO_DEV(rt2x00dev
->tx_power
));
1438 rt2x00_set_field32(&word
, TXD_W5_WAITING_DMA_DONE_INT
, 1);
1439 rt2x00_desc_write(txd
, 5, word
);
1441 rt2x00_desc_read(txd
, 0, &word
);
1442 rt2x00_set_field32(&word
, TXD_W0_BURST
,
1443 test_bit(ENTRY_TXD_BURST
, &txdesc
->flags
));
1444 rt2x00_set_field32(&word
, TXD_W0_VALID
, 1);
1445 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1446 test_bit(ENTRY_TXD_MORE_FRAG
, &txdesc
->flags
));
1447 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1448 test_bit(ENTRY_TXD_ACK
, &txdesc
->flags
));
1449 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1450 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &txdesc
->flags
));
1451 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1452 test_bit(ENTRY_TXD_OFDM_RATE
, &txdesc
->flags
));
1453 rt2x00_set_field32(&word
, TXD_W0_IFS
, txdesc
->ifs
);
1454 rt2x00_set_field32(&word
, TXD_W0_RETRY_MODE
,
1455 test_bit(ENTRY_TXD_RETRY_MODE
, &txdesc
->flags
));
1456 rt2x00_set_field32(&word
, TXD_W0_TKIP_MIC
,
1457 test_bit(ENTRY_TXD_ENCRYPT_MMIC
, &txdesc
->flags
));
1458 rt2x00_set_field32(&word
, TXD_W0_KEY_TABLE
,
1459 test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE
, &txdesc
->flags
));
1460 rt2x00_set_field32(&word
, TXD_W0_KEY_INDEX
, txdesc
->key_idx
);
1461 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, skb
->len
);
1462 rt2x00_set_field32(&word
, TXD_W0_BURST2
,
1463 test_bit(ENTRY_TXD_BURST
, &txdesc
->flags
));
1464 rt2x00_set_field32(&word
, TXD_W0_CIPHER_ALG
, txdesc
->cipher
);
1465 rt2x00_desc_write(txd
, 0, word
);
1469 * TX data initialization
1471 static void rt73usb_write_beacon(struct queue_entry
*entry
)
1473 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1474 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1475 unsigned int beacon_base
;
1479 * Add the descriptor in front of the skb.
1481 skb_push(entry
->skb
, entry
->queue
->desc_size
);
1482 memcpy(entry
->skb
->data
, skbdesc
->desc
, skbdesc
->desc_len
);
1483 skbdesc
->desc
= entry
->skb
->data
;
1486 * Disable beaconing while we are reloading the beacon data,
1487 * otherwise we might be sending out invalid data.
1489 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR9
, ®
);
1490 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 0);
1491 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 0);
1492 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1493 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1496 * Write entire beacon with descriptor to register.
1498 beacon_base
= HW_BEACON_OFFSET(entry
->entry_idx
);
1499 rt2x00usb_vendor_request_large_buff(rt2x00dev
, USB_MULTI_WRITE
,
1500 USB_VENDOR_REQUEST_OUT
, beacon_base
,
1501 entry
->skb
->data
, entry
->skb
->len
,
1502 REGISTER_TIMEOUT32(entry
->skb
->len
));
1505 * Clean up the beacon skb.
1507 dev_kfree_skb(entry
->skb
);
1511 static int rt73usb_get_tx_data_len(struct queue_entry
*entry
)
1516 * The length _must_ be a multiple of 4,
1517 * but it must _not_ be a multiple of the USB packet size.
1519 length
= roundup(entry
->skb
->len
, 4);
1520 length
+= (4 * !(length
% entry
->queue
->usb_maxpacket
));
1525 static void rt73usb_kick_tx_queue(struct rt2x00_dev
*rt2x00dev
,
1526 const enum data_queue_qid queue
)
1530 if (queue
!= QID_BEACON
) {
1531 rt2x00usb_kick_tx_queue(rt2x00dev
, queue
);
1536 * For Wi-Fi faily generated beacons between participating stations.
1537 * Set TBTT phase adaptive adjustment step to 8us (default 16us)
1539 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR10
, 0x00001008);
1541 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR9
, ®
);
1542 if (!rt2x00_get_field32(reg
, TXRX_CSR9_BEACON_GEN
)) {
1543 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 1);
1544 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 1);
1545 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 1);
1546 rt2x00usb_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1551 * RX control handlers
1553 static int rt73usb_agc_to_rssi(struct rt2x00_dev
*rt2x00dev
, int rxd_w1
)
1555 u8 offset
= rt2x00dev
->lna_gain
;
1558 lna
= rt2x00_get_field32(rxd_w1
, RXD_W1_RSSI_LNA
);
1573 if (rt2x00dev
->rx_status
.band
== IEEE80211_BAND_5GHZ
) {
1574 if (test_bit(CONFIG_EXTERNAL_LNA_A
, &rt2x00dev
->flags
)) {
1575 if (lna
== 3 || lna
== 2)
1585 return rt2x00_get_field32(rxd_w1
, RXD_W1_RSSI_AGC
) * 2 - offset
;
1588 static void rt73usb_fill_rxdone(struct queue_entry
*entry
,
1589 struct rxdone_entry_desc
*rxdesc
)
1591 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1592 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1593 __le32
*rxd
= (__le32
*)entry
->skb
->data
;
1598 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1599 * frame data in rt2x00usb.
1601 memcpy(skbdesc
->desc
, rxd
, skbdesc
->desc_len
);
1602 rxd
= (__le32
*)skbdesc
->desc
;
1605 * It is now safe to read the descriptor on all architectures.
1607 rt2x00_desc_read(rxd
, 0, &word0
);
1608 rt2x00_desc_read(rxd
, 1, &word1
);
1610 if (rt2x00_get_field32(word0
, RXD_W0_CRC_ERROR
))
1611 rxdesc
->flags
|= RX_FLAG_FAILED_FCS_CRC
;
1613 if (test_bit(CONFIG_SUPPORT_HW_CRYPTO
, &rt2x00dev
->flags
)) {
1615 rt2x00_get_field32(word0
, RXD_W0_CIPHER_ALG
);
1616 rxdesc
->cipher_status
=
1617 rt2x00_get_field32(word0
, RXD_W0_CIPHER_ERROR
);
1620 if (rxdesc
->cipher
!= CIPHER_NONE
) {
1621 _rt2x00_desc_read(rxd
, 2, &rxdesc
->iv
[0]);
1622 _rt2x00_desc_read(rxd
, 3, &rxdesc
->iv
[1]);
1623 rxdesc
->dev_flags
|= RXDONE_CRYPTO_IV
;
1625 _rt2x00_desc_read(rxd
, 4, &rxdesc
->icv
);
1626 rxdesc
->dev_flags
|= RXDONE_CRYPTO_ICV
;
1629 * Hardware has stripped IV/EIV data from 802.11 frame during
1630 * decryption. It has provided the data seperately but rt2x00lib
1631 * should decide if it should be reinserted.
1633 rxdesc
->flags
|= RX_FLAG_IV_STRIPPED
;
1636 * FIXME: Legacy driver indicates that the frame does
1637 * contain the Michael Mic. Unfortunately, in rt2x00
1638 * the MIC seems to be missing completely...
1640 rxdesc
->flags
|= RX_FLAG_MMIC_STRIPPED
;
1642 if (rxdesc
->cipher_status
== RX_CRYPTO_SUCCESS
)
1643 rxdesc
->flags
|= RX_FLAG_DECRYPTED
;
1644 else if (rxdesc
->cipher_status
== RX_CRYPTO_FAIL_MIC
)
1645 rxdesc
->flags
|= RX_FLAG_MMIC_ERROR
;
1649 * Obtain the status about this packet.
1650 * When frame was received with an OFDM bitrate,
1651 * the signal is the PLCP value. If it was received with
1652 * a CCK bitrate the signal is the rate in 100kbit/s.
1654 rxdesc
->signal
= rt2x00_get_field32(word1
, RXD_W1_SIGNAL
);
1655 rxdesc
->rssi
= rt73usb_agc_to_rssi(rt2x00dev
, word1
);
1656 rxdesc
->size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
1658 if (rt2x00_get_field32(word0
, RXD_W0_OFDM
))
1659 rxdesc
->dev_flags
|= RXDONE_SIGNAL_PLCP
;
1661 rxdesc
->dev_flags
|= RXDONE_SIGNAL_BITRATE
;
1662 if (rt2x00_get_field32(word0
, RXD_W0_MY_BSS
))
1663 rxdesc
->dev_flags
|= RXDONE_MY_BSS
;
1666 * Set skb pointers, and update frame information.
1668 skb_pull(entry
->skb
, entry
->queue
->desc_size
);
1669 skb_trim(entry
->skb
, rxdesc
->size
);
1673 * Device probe functions.
1675 static int rt73usb_validate_eeprom(struct rt2x00_dev
*rt2x00dev
)
1681 rt2x00usb_eeprom_read(rt2x00dev
, rt2x00dev
->eeprom
, EEPROM_SIZE
);
1684 * Start validation of the data that has been read.
1686 mac
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1687 if (!is_valid_ether_addr(mac
)) {
1688 random_ether_addr(mac
);
1689 EEPROM(rt2x00dev
, "MAC: %pM\n", mac
);
1692 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1693 if (word
== 0xffff) {
1694 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
1695 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
,
1697 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
,
1699 rt2x00_set_field16(&word
, EEPROM_ANTENNA_FRAME_TYPE
, 0);
1700 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
1701 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
1702 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF5226
);
1703 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
1704 EEPROM(rt2x00dev
, "Antenna: 0x%04x\n", word
);
1707 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &word
);
1708 if (word
== 0xffff) {
1709 rt2x00_set_field16(&word
, EEPROM_NIC_EXTERNAL_LNA
, 0);
1710 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
1711 EEPROM(rt2x00dev
, "NIC: 0x%04x\n", word
);
1714 rt2x00_eeprom_read(rt2x00dev
, EEPROM_LED
, &word
);
1715 if (word
== 0xffff) {
1716 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_RDY_G
, 0);
1717 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_RDY_A
, 0);
1718 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_ACT
, 0);
1719 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_GPIO_0
, 0);
1720 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_GPIO_1
, 0);
1721 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_GPIO_2
, 0);
1722 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_GPIO_3
, 0);
1723 rt2x00_set_field16(&word
, EEPROM_LED_POLARITY_GPIO_4
, 0);
1724 rt2x00_set_field16(&word
, EEPROM_LED_LED_MODE
,
1726 rt2x00_eeprom_write(rt2x00dev
, EEPROM_LED
, word
);
1727 EEPROM(rt2x00dev
, "Led: 0x%04x\n", word
);
1730 rt2x00_eeprom_read(rt2x00dev
, EEPROM_FREQ
, &word
);
1731 if (word
== 0xffff) {
1732 rt2x00_set_field16(&word
, EEPROM_FREQ_OFFSET
, 0);
1733 rt2x00_set_field16(&word
, EEPROM_FREQ_SEQ
, 0);
1734 rt2x00_eeprom_write(rt2x00dev
, EEPROM_FREQ
, word
);
1735 EEPROM(rt2x00dev
, "Freq: 0x%04x\n", word
);
1738 rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, &word
);
1739 if (word
== 0xffff) {
1740 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_1
, 0);
1741 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_2
, 0);
1742 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, word
);
1743 EEPROM(rt2x00dev
, "RSSI OFFSET BG: 0x%04x\n", word
);
1745 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_BG_1
);
1746 if (value
< -10 || value
> 10)
1747 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_1
, 0);
1748 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_BG_2
);
1749 if (value
< -10 || value
> 10)
1750 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_2
, 0);
1751 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, word
);
1754 rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, &word
);
1755 if (word
== 0xffff) {
1756 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_1
, 0);
1757 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_2
, 0);
1758 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, word
);
1759 EEPROM(rt2x00dev
, "RSSI OFFSET A: 0x%04x\n", word
);
1761 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_A_1
);
1762 if (value
< -10 || value
> 10)
1763 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_1
, 0);
1764 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_A_2
);
1765 if (value
< -10 || value
> 10)
1766 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_2
, 0);
1767 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, word
);
1773 static int rt73usb_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1780 * Read EEPROM word for configuration.
1782 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1785 * Identify RF chipset.
1787 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1788 rt2x00usb_register_read(rt2x00dev
, MAC_CSR0
, ®
);
1789 rt2x00_set_chip(rt2x00dev
, RT2571
, value
, reg
);
1791 if (!rt2x00_check_rev(&rt2x00dev
->chip
, 0x25730)) {
1792 ERROR(rt2x00dev
, "Invalid RT chipset detected.\n");
1796 if (!rt2x00_rf(&rt2x00dev
->chip
, RF5226
) &&
1797 !rt2x00_rf(&rt2x00dev
->chip
, RF2528
) &&
1798 !rt2x00_rf(&rt2x00dev
->chip
, RF5225
) &&
1799 !rt2x00_rf(&rt2x00dev
->chip
, RF2527
)) {
1800 ERROR(rt2x00dev
, "Invalid RF chipset detected.\n");
1805 * Identify default antenna configuration.
1807 rt2x00dev
->default_ant
.tx
=
1808 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_TX_DEFAULT
);
1809 rt2x00dev
->default_ant
.rx
=
1810 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RX_DEFAULT
);
1813 * Read the Frame type.
1815 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_FRAME_TYPE
))
1816 __set_bit(CONFIG_FRAME_TYPE
, &rt2x00dev
->flags
);
1819 * Read frequency offset.
1821 rt2x00_eeprom_read(rt2x00dev
, EEPROM_FREQ
, &eeprom
);
1822 rt2x00dev
->freq_offset
= rt2x00_get_field16(eeprom
, EEPROM_FREQ_OFFSET
);
1825 * Read external LNA informations.
1827 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &eeprom
);
1829 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_EXTERNAL_LNA
)) {
1830 __set_bit(CONFIG_EXTERNAL_LNA_A
, &rt2x00dev
->flags
);
1831 __set_bit(CONFIG_EXTERNAL_LNA_BG
, &rt2x00dev
->flags
);
1835 * Store led settings, for correct led behaviour.
1837 #ifdef CONFIG_RT2X00_LIB_LEDS
1838 rt2x00_eeprom_read(rt2x00dev
, EEPROM_LED
, &eeprom
);
1840 rt73usb_init_led(rt2x00dev
, &rt2x00dev
->led_radio
, LED_TYPE_RADIO
);
1841 rt73usb_init_led(rt2x00dev
, &rt2x00dev
->led_assoc
, LED_TYPE_ASSOC
);
1842 if (value
== LED_MODE_SIGNAL_STRENGTH
)
1843 rt73usb_init_led(rt2x00dev
, &rt2x00dev
->led_qual
,
1846 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_LED_MODE
, value
);
1847 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_0
,
1848 rt2x00_get_field16(eeprom
,
1849 EEPROM_LED_POLARITY_GPIO_0
));
1850 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_1
,
1851 rt2x00_get_field16(eeprom
,
1852 EEPROM_LED_POLARITY_GPIO_1
));
1853 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_2
,
1854 rt2x00_get_field16(eeprom
,
1855 EEPROM_LED_POLARITY_GPIO_2
));
1856 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_3
,
1857 rt2x00_get_field16(eeprom
,
1858 EEPROM_LED_POLARITY_GPIO_3
));
1859 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_4
,
1860 rt2x00_get_field16(eeprom
,
1861 EEPROM_LED_POLARITY_GPIO_4
));
1862 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_ACT
,
1863 rt2x00_get_field16(eeprom
, EEPROM_LED_POLARITY_ACT
));
1864 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_READY_BG
,
1865 rt2x00_get_field16(eeprom
,
1866 EEPROM_LED_POLARITY_RDY_G
));
1867 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_READY_A
,
1868 rt2x00_get_field16(eeprom
,
1869 EEPROM_LED_POLARITY_RDY_A
));
1870 #endif /* CONFIG_RT2X00_LIB_LEDS */
1876 * RF value list for RF2528
1879 static const struct rf_channel rf_vals_bg_2528
[] = {
1880 { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
1881 { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
1882 { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
1883 { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
1884 { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
1885 { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
1886 { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
1887 { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
1888 { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
1889 { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
1890 { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
1891 { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
1892 { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
1893 { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
1897 * RF value list for RF5226
1898 * Supports: 2.4 GHz & 5.2 GHz
1900 static const struct rf_channel rf_vals_5226
[] = {
1901 { 1, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea0b },
1902 { 2, 0x00002c0c, 0x00000786, 0x00068255, 0x000fea1f },
1903 { 3, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea0b },
1904 { 4, 0x00002c0c, 0x0000078a, 0x00068255, 0x000fea1f },
1905 { 5, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea0b },
1906 { 6, 0x00002c0c, 0x0000078e, 0x00068255, 0x000fea1f },
1907 { 7, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea0b },
1908 { 8, 0x00002c0c, 0x00000792, 0x00068255, 0x000fea1f },
1909 { 9, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea0b },
1910 { 10, 0x00002c0c, 0x00000796, 0x00068255, 0x000fea1f },
1911 { 11, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea0b },
1912 { 12, 0x00002c0c, 0x0000079a, 0x00068255, 0x000fea1f },
1913 { 13, 0x00002c0c, 0x0000079e, 0x00068255, 0x000fea0b },
1914 { 14, 0x00002c0c, 0x000007a2, 0x00068255, 0x000fea13 },
1916 /* 802.11 UNI / HyperLan 2 */
1917 { 36, 0x00002c0c, 0x0000099a, 0x00098255, 0x000fea23 },
1918 { 40, 0x00002c0c, 0x000009a2, 0x00098255, 0x000fea03 },
1919 { 44, 0x00002c0c, 0x000009a6, 0x00098255, 0x000fea0b },
1920 { 48, 0x00002c0c, 0x000009aa, 0x00098255, 0x000fea13 },
1921 { 52, 0x00002c0c, 0x000009ae, 0x00098255, 0x000fea1b },
1922 { 56, 0x00002c0c, 0x000009b2, 0x00098255, 0x000fea23 },
1923 { 60, 0x00002c0c, 0x000009ba, 0x00098255, 0x000fea03 },
1924 { 64, 0x00002c0c, 0x000009be, 0x00098255, 0x000fea0b },
1926 /* 802.11 HyperLan 2 */
1927 { 100, 0x00002c0c, 0x00000a2a, 0x000b8255, 0x000fea03 },
1928 { 104, 0x00002c0c, 0x00000a2e, 0x000b8255, 0x000fea0b },
1929 { 108, 0x00002c0c, 0x00000a32, 0x000b8255, 0x000fea13 },
1930 { 112, 0x00002c0c, 0x00000a36, 0x000b8255, 0x000fea1b },
1931 { 116, 0x00002c0c, 0x00000a3a, 0x000b8255, 0x000fea23 },
1932 { 120, 0x00002c0c, 0x00000a82, 0x000b8255, 0x000fea03 },
1933 { 124, 0x00002c0c, 0x00000a86, 0x000b8255, 0x000fea0b },
1934 { 128, 0x00002c0c, 0x00000a8a, 0x000b8255, 0x000fea13 },
1935 { 132, 0x00002c0c, 0x00000a8e, 0x000b8255, 0x000fea1b },
1936 { 136, 0x00002c0c, 0x00000a92, 0x000b8255, 0x000fea23 },
1939 { 140, 0x00002c0c, 0x00000a9a, 0x000b8255, 0x000fea03 },
1940 { 149, 0x00002c0c, 0x00000aa2, 0x000b8255, 0x000fea1f },
1941 { 153, 0x00002c0c, 0x00000aa6, 0x000b8255, 0x000fea27 },
1942 { 157, 0x00002c0c, 0x00000aae, 0x000b8255, 0x000fea07 },
1943 { 161, 0x00002c0c, 0x00000ab2, 0x000b8255, 0x000fea0f },
1944 { 165, 0x00002c0c, 0x00000ab6, 0x000b8255, 0x000fea17 },
1946 /* MMAC(Japan)J52 ch 34,38,42,46 */
1947 { 34, 0x00002c0c, 0x0008099a, 0x000da255, 0x000d3a0b },
1948 { 38, 0x00002c0c, 0x0008099e, 0x000da255, 0x000d3a13 },
1949 { 42, 0x00002c0c, 0x000809a2, 0x000da255, 0x000d3a1b },
1950 { 46, 0x00002c0c, 0x000809a6, 0x000da255, 0x000d3a23 },
1954 * RF value list for RF5225 & RF2527
1955 * Supports: 2.4 GHz & 5.2 GHz
1957 static const struct rf_channel rf_vals_5225_2527
[] = {
1958 { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
1959 { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
1960 { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
1961 { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
1962 { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
1963 { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
1964 { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
1965 { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
1966 { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
1967 { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
1968 { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
1969 { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
1970 { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
1971 { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
1973 /* 802.11 UNI / HyperLan 2 */
1974 { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
1975 { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
1976 { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
1977 { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
1978 { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
1979 { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
1980 { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
1981 { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
1983 /* 802.11 HyperLan 2 */
1984 { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
1985 { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
1986 { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
1987 { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
1988 { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
1989 { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
1990 { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
1991 { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
1992 { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
1993 { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
1996 { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
1997 { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
1998 { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
1999 { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
2000 { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
2001 { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
2003 /* MMAC(Japan)J52 ch 34,38,42,46 */
2004 { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
2005 { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
2006 { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
2007 { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
2011 static int rt73usb_probe_hw_mode(struct rt2x00_dev
*rt2x00dev
)
2013 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
2014 struct channel_info
*info
;
2019 * Initialize all hw fields.
2021 rt2x00dev
->hw
->flags
=
2022 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
2023 IEEE80211_HW_SIGNAL_DBM
;
2024 rt2x00dev
->hw
->extra_tx_headroom
= TXD_DESC_SIZE
;
2026 SET_IEEE80211_DEV(rt2x00dev
->hw
, rt2x00dev
->dev
);
2027 SET_IEEE80211_PERM_ADDR(rt2x00dev
->hw
,
2028 rt2x00_eeprom_addr(rt2x00dev
,
2029 EEPROM_MAC_ADDR_0
));
2032 * Initialize hw_mode information.
2034 spec
->supported_bands
= SUPPORT_BAND_2GHZ
;
2035 spec
->supported_rates
= SUPPORT_RATE_CCK
| SUPPORT_RATE_OFDM
;
2037 if (rt2x00_rf(&rt2x00dev
->chip
, RF2528
)) {
2038 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2528
);
2039 spec
->channels
= rf_vals_bg_2528
;
2040 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF5226
)) {
2041 spec
->supported_bands
|= SUPPORT_BAND_5GHZ
;
2042 spec
->num_channels
= ARRAY_SIZE(rf_vals_5226
);
2043 spec
->channels
= rf_vals_5226
;
2044 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF2527
)) {
2045 spec
->num_channels
= 14;
2046 spec
->channels
= rf_vals_5225_2527
;
2047 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF5225
)) {
2048 spec
->supported_bands
|= SUPPORT_BAND_5GHZ
;
2049 spec
->num_channels
= ARRAY_SIZE(rf_vals_5225_2527
);
2050 spec
->channels
= rf_vals_5225_2527
;
2054 * Create channel information array
2056 info
= kzalloc(spec
->num_channels
* sizeof(*info
), GFP_KERNEL
);
2060 spec
->channels_info
= info
;
2062 tx_power
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_G_START
);
2063 for (i
= 0; i
< 14; i
++)
2064 info
[i
].tx_power1
= TXPOWER_FROM_DEV(tx_power
[i
]);
2066 if (spec
->num_channels
> 14) {
2067 tx_power
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_A_START
);
2068 for (i
= 14; i
< spec
->num_channels
; i
++)
2069 info
[i
].tx_power1
= TXPOWER_FROM_DEV(tx_power
[i
]);
2075 static int rt73usb_probe_hw(struct rt2x00_dev
*rt2x00dev
)
2080 * Allocate eeprom data.
2082 retval
= rt73usb_validate_eeprom(rt2x00dev
);
2086 retval
= rt73usb_init_eeprom(rt2x00dev
);
2091 * Initialize hw specifications.
2093 retval
= rt73usb_probe_hw_mode(rt2x00dev
);
2098 * This device requires firmware.
2100 __set_bit(DRIVER_REQUIRE_FIRMWARE
, &rt2x00dev
->flags
);
2101 __set_bit(DRIVER_REQUIRE_SCHEDULED
, &rt2x00dev
->flags
);
2102 if (!modparam_nohwcrypt
)
2103 __set_bit(CONFIG_SUPPORT_HW_CRYPTO
, &rt2x00dev
->flags
);
2106 * Set the rssi offset.
2108 rt2x00dev
->rssi_offset
= DEFAULT_RSSI_OFFSET
;
2114 * IEEE80211 stack callback functions.
2116 static int rt73usb_conf_tx(struct ieee80211_hw
*hw
, u16 queue_idx
,
2117 const struct ieee80211_tx_queue_params
*params
)
2119 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
2120 struct data_queue
*queue
;
2121 struct rt2x00_field32 field
;
2126 * First pass the configuration through rt2x00lib, that will
2127 * update the queue settings and validate the input. After that
2128 * we are free to update the registers based on the value
2129 * in the queue parameter.
2131 retval
= rt2x00mac_conf_tx(hw
, queue_idx
, params
);
2135 queue
= rt2x00queue_get_queue(rt2x00dev
, queue_idx
);
2137 /* Update WMM TXOP register */
2138 if (queue_idx
< 2) {
2139 field
.bit_offset
= queue_idx
* 16;
2140 field
.bit_mask
= 0xffff << field
.bit_offset
;
2142 rt2x00usb_register_read(rt2x00dev
, AC_TXOP_CSR0
, ®
);
2143 rt2x00_set_field32(®
, field
, queue
->txop
);
2144 rt2x00usb_register_write(rt2x00dev
, AC_TXOP_CSR0
, reg
);
2145 } else if (queue_idx
< 4) {
2146 field
.bit_offset
= (queue_idx
- 2) * 16;
2147 field
.bit_mask
= 0xffff << field
.bit_offset
;
2149 rt2x00usb_register_read(rt2x00dev
, AC_TXOP_CSR1
, ®
);
2150 rt2x00_set_field32(®
, field
, queue
->txop
);
2151 rt2x00usb_register_write(rt2x00dev
, AC_TXOP_CSR1
, reg
);
2154 /* Update WMM registers */
2155 field
.bit_offset
= queue_idx
* 4;
2156 field
.bit_mask
= 0xf << field
.bit_offset
;
2158 rt2x00usb_register_read(rt2x00dev
, AIFSN_CSR
, ®
);
2159 rt2x00_set_field32(®
, field
, queue
->aifs
);
2160 rt2x00usb_register_write(rt2x00dev
, AIFSN_CSR
, reg
);
2162 rt2x00usb_register_read(rt2x00dev
, CWMIN_CSR
, ®
);
2163 rt2x00_set_field32(®
, field
, queue
->cw_min
);
2164 rt2x00usb_register_write(rt2x00dev
, CWMIN_CSR
, reg
);
2166 rt2x00usb_register_read(rt2x00dev
, CWMAX_CSR
, ®
);
2167 rt2x00_set_field32(®
, field
, queue
->cw_max
);
2168 rt2x00usb_register_write(rt2x00dev
, CWMAX_CSR
, reg
);
2175 * Mac80211 demands get_tsf must be atomic.
2176 * This is not possible for rt73usb since all register access
2177 * functions require sleeping. Untill mac80211 no longer needs
2178 * get_tsf to be atomic, this function should be disabled.
2180 static u64
rt73usb_get_tsf(struct ieee80211_hw
*hw
)
2182 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
2186 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR13
, ®
);
2187 tsf
= (u64
) rt2x00_get_field32(reg
, TXRX_CSR13_HIGH_TSFTIMER
) << 32;
2188 rt2x00usb_register_read(rt2x00dev
, TXRX_CSR12
, ®
);
2189 tsf
|= rt2x00_get_field32(reg
, TXRX_CSR12_LOW_TSFTIMER
);
2194 #define rt73usb_get_tsf NULL
2197 static const struct ieee80211_ops rt73usb_mac80211_ops
= {
2199 .start
= rt2x00mac_start
,
2200 .stop
= rt2x00mac_stop
,
2201 .add_interface
= rt2x00mac_add_interface
,
2202 .remove_interface
= rt2x00mac_remove_interface
,
2203 .config
= rt2x00mac_config
,
2204 .config_interface
= rt2x00mac_config_interface
,
2205 .configure_filter
= rt2x00mac_configure_filter
,
2206 .set_key
= rt2x00mac_set_key
,
2207 .get_stats
= rt2x00mac_get_stats
,
2208 .bss_info_changed
= rt2x00mac_bss_info_changed
,
2209 .conf_tx
= rt73usb_conf_tx
,
2210 .get_tx_stats
= rt2x00mac_get_tx_stats
,
2211 .get_tsf
= rt73usb_get_tsf
,
2214 static const struct rt2x00lib_ops rt73usb_rt2x00_ops
= {
2215 .probe_hw
= rt73usb_probe_hw
,
2216 .get_firmware_name
= rt73usb_get_firmware_name
,
2217 .get_firmware_crc
= rt73usb_get_firmware_crc
,
2218 .load_firmware
= rt73usb_load_firmware
,
2219 .initialize
= rt2x00usb_initialize
,
2220 .uninitialize
= rt2x00usb_uninitialize
,
2221 .clear_entry
= rt2x00usb_clear_entry
,
2222 .set_device_state
= rt73usb_set_device_state
,
2223 .link_stats
= rt73usb_link_stats
,
2224 .reset_tuner
= rt73usb_reset_tuner
,
2225 .link_tuner
= rt73usb_link_tuner
,
2226 .write_tx_desc
= rt73usb_write_tx_desc
,
2227 .write_tx_data
= rt2x00usb_write_tx_data
,
2228 .write_beacon
= rt73usb_write_beacon
,
2229 .get_tx_data_len
= rt73usb_get_tx_data_len
,
2230 .kick_tx_queue
= rt73usb_kick_tx_queue
,
2231 .fill_rxdone
= rt73usb_fill_rxdone
,
2232 .config_shared_key
= rt73usb_config_shared_key
,
2233 .config_pairwise_key
= rt73usb_config_pairwise_key
,
2234 .config_filter
= rt73usb_config_filter
,
2235 .config_intf
= rt73usb_config_intf
,
2236 .config_erp
= rt73usb_config_erp
,
2237 .config_ant
= rt73usb_config_ant
,
2238 .config
= rt73usb_config
,
2241 static const struct data_queue_desc rt73usb_queue_rx
= {
2242 .entry_num
= RX_ENTRIES
,
2243 .data_size
= DATA_FRAME_SIZE
,
2244 .desc_size
= RXD_DESC_SIZE
,
2245 .priv_size
= sizeof(struct queue_entry_priv_usb
),
2248 static const struct data_queue_desc rt73usb_queue_tx
= {
2249 .entry_num
= TX_ENTRIES
,
2250 .data_size
= DATA_FRAME_SIZE
,
2251 .desc_size
= TXD_DESC_SIZE
,
2252 .priv_size
= sizeof(struct queue_entry_priv_usb
),
2255 static const struct data_queue_desc rt73usb_queue_bcn
= {
2256 .entry_num
= 4 * BEACON_ENTRIES
,
2257 .data_size
= MGMT_FRAME_SIZE
,
2258 .desc_size
= TXINFO_SIZE
,
2259 .priv_size
= sizeof(struct queue_entry_priv_usb
),
2262 static const struct rt2x00_ops rt73usb_ops
= {
2263 .name
= KBUILD_MODNAME
,
2266 .eeprom_size
= EEPROM_SIZE
,
2268 .tx_queues
= NUM_TX_QUEUES
,
2269 .rx
= &rt73usb_queue_rx
,
2270 .tx
= &rt73usb_queue_tx
,
2271 .bcn
= &rt73usb_queue_bcn
,
2272 .lib
= &rt73usb_rt2x00_ops
,
2273 .hw
= &rt73usb_mac80211_ops
,
2274 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
2275 .debugfs
= &rt73usb_rt2x00debug
,
2276 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2280 * rt73usb module information.
2282 static struct usb_device_id rt73usb_device_table
[] = {
2284 { USB_DEVICE(0x07b8, 0xb21b), USB_DEVICE_DATA(&rt73usb_ops
) },
2285 { USB_DEVICE(0x07b8, 0xb21c), USB_DEVICE_DATA(&rt73usb_ops
) },
2286 { USB_DEVICE(0x07b8, 0xb21d), USB_DEVICE_DATA(&rt73usb_ops
) },
2287 { USB_DEVICE(0x07b8, 0xb21e), USB_DEVICE_DATA(&rt73usb_ops
) },
2288 { USB_DEVICE(0x07b8, 0xb21f), USB_DEVICE_DATA(&rt73usb_ops
) },
2290 { USB_DEVICE(0x14b2, 0x3c10), USB_DEVICE_DATA(&rt73usb_ops
) },
2292 { USB_DEVICE(0x148f, 0x9021), USB_DEVICE_DATA(&rt73usb_ops
) },
2293 { USB_DEVICE(0x0eb0, 0x9021), USB_DEVICE_DATA(&rt73usb_ops
) },
2295 { USB_DEVICE(0x18c5, 0x0002), USB_DEVICE_DATA(&rt73usb_ops
) },
2297 { USB_DEVICE(0x1690, 0x0722), USB_DEVICE_DATA(&rt73usb_ops
) },
2299 { USB_DEVICE(0x0b05, 0x1723), USB_DEVICE_DATA(&rt73usb_ops
) },
2300 { USB_DEVICE(0x0b05, 0x1724), USB_DEVICE_DATA(&rt73usb_ops
) },
2302 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt73usb_ops
) },
2303 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt73usb_ops
) },
2304 { USB_DEVICE(0x050d, 0x905b), USB_DEVICE_DATA(&rt73usb_ops
) },
2305 { USB_DEVICE(0x050d, 0x905c), USB_DEVICE_DATA(&rt73usb_ops
) },
2307 { USB_DEVICE(0x1631, 0xc019), USB_DEVICE_DATA(&rt73usb_ops
) },
2308 { USB_DEVICE(0x08dd, 0x0120), USB_DEVICE_DATA(&rt73usb_ops
) },
2310 { USB_DEVICE(0x0411, 0x00d8), USB_DEVICE_DATA(&rt73usb_ops
) },
2311 { USB_DEVICE(0x0411, 0x00f4), USB_DEVICE_DATA(&rt73usb_ops
) },
2313 { USB_DEVICE(0x1371, 0x9022), USB_DEVICE_DATA(&rt73usb_ops
) },
2314 { USB_DEVICE(0x1371, 0x9032), USB_DEVICE_DATA(&rt73usb_ops
) },
2316 { USB_DEVICE(0x14b2, 0x3c22), USB_DEVICE_DATA(&rt73usb_ops
) },
2318 { USB_DEVICE(0x07aa, 0x002e), USB_DEVICE_DATA(&rt73usb_ops
) },
2320 { USB_DEVICE(0x07d1, 0x3c03), USB_DEVICE_DATA(&rt73usb_ops
) },
2321 { USB_DEVICE(0x07d1, 0x3c04), USB_DEVICE_DATA(&rt73usb_ops
) },
2322 { USB_DEVICE(0x07d1, 0x3c06), USB_DEVICE_DATA(&rt73usb_ops
) },
2323 { USB_DEVICE(0x07d1, 0x3c07), USB_DEVICE_DATA(&rt73usb_ops
) },
2325 { USB_DEVICE(0x7392, 0x7318), USB_DEVICE_DATA(&rt73usb_ops
) },
2326 { USB_DEVICE(0x7392, 0x7618), USB_DEVICE_DATA(&rt73usb_ops
) },
2328 { USB_DEVICE(0x1740, 0x3701), USB_DEVICE_DATA(&rt73usb_ops
) },
2330 { USB_DEVICE(0x15a9, 0x0004), USB_DEVICE_DATA(&rt73usb_ops
) },
2332 { USB_DEVICE(0x1044, 0x8008), USB_DEVICE_DATA(&rt73usb_ops
) },
2333 { USB_DEVICE(0x1044, 0x800a), USB_DEVICE_DATA(&rt73usb_ops
) },
2335 { USB_DEVICE(0x1472, 0x0009), USB_DEVICE_DATA(&rt73usb_ops
) },
2337 { USB_DEVICE(0x06f8, 0xe010), USB_DEVICE_DATA(&rt73usb_ops
) },
2338 { USB_DEVICE(0x06f8, 0xe020), USB_DEVICE_DATA(&rt73usb_ops
) },
2340 { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops
) },
2341 { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops
) },
2342 { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops
) },
2344 { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops
) },
2345 { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops
) },
2346 { USB_DEVICE(0x0db0, 0xa861), USB_DEVICE_DATA(&rt73usb_ops
) },
2347 { USB_DEVICE(0x0db0, 0xa874), USB_DEVICE_DATA(&rt73usb_ops
) },
2349 { USB_DEVICE(0x04bb, 0x093d), USB_DEVICE_DATA(&rt73usb_ops
) },
2350 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt73usb_ops
) },
2351 { USB_DEVICE(0x148f, 0x2671), USB_DEVICE_DATA(&rt73usb_ops
) },
2353 { USB_DEVICE(0x18e8, 0x6196), USB_DEVICE_DATA(&rt73usb_ops
) },
2354 { USB_DEVICE(0x18e8, 0x6229), USB_DEVICE_DATA(&rt73usb_ops
) },
2355 { USB_DEVICE(0x18e8, 0x6238), USB_DEVICE_DATA(&rt73usb_ops
) },
2357 { USB_DEVICE(0x04e8, 0x4471), USB_DEVICE_DATA(&rt73usb_ops
) },
2359 { USB_DEVICE(0x1740, 0x7100), USB_DEVICE_DATA(&rt73usb_ops
) },
2361 { USB_DEVICE(0x0df6, 0x0024), USB_DEVICE_DATA(&rt73usb_ops
) },
2362 { USB_DEVICE(0x0df6, 0x0027), USB_DEVICE_DATA(&rt73usb_ops
) },
2363 { USB_DEVICE(0x0df6, 0x002f), USB_DEVICE_DATA(&rt73usb_ops
) },
2364 { USB_DEVICE(0x0df6, 0x90ac), USB_DEVICE_DATA(&rt73usb_ops
) },
2365 { USB_DEVICE(0x0df6, 0x9712), USB_DEVICE_DATA(&rt73usb_ops
) },
2367 { USB_DEVICE(0x0769, 0x31f3), USB_DEVICE_DATA(&rt73usb_ops
) },
2369 { USB_DEVICE(0x0471, 0x200a), USB_DEVICE_DATA(&rt73usb_ops
) },
2371 { USB_DEVICE(0x2019, 0xab01), USB_DEVICE_DATA(&rt73usb_ops
) },
2372 { USB_DEVICE(0x2019, 0xab50), USB_DEVICE_DATA(&rt73usb_ops
) },
2374 { USB_DEVICE(0x0cde, 0x001c), USB_DEVICE_DATA(&rt73usb_ops
) },
2376 { USB_DEVICE(0x0586, 0x3415), USB_DEVICE_DATA(&rt73usb_ops
) },
2380 MODULE_AUTHOR(DRV_PROJECT
);
2381 MODULE_VERSION(DRV_VERSION
);
2382 MODULE_DESCRIPTION("Ralink RT73 USB Wireless LAN driver.");
2383 MODULE_SUPPORTED_DEVICE("Ralink RT2571W & RT2671 USB chipset based cards");
2384 MODULE_DEVICE_TABLE(usb
, rt73usb_device_table
);
2385 MODULE_FIRMWARE(FIRMWARE_RT2571
);
2386 MODULE_LICENSE("GPL");
2388 static struct usb_driver rt73usb_driver
= {
2389 .name
= KBUILD_MODNAME
,
2390 .id_table
= rt73usb_device_table
,
2391 .probe
= rt2x00usb_probe
,
2392 .disconnect
= rt2x00usb_disconnect
,
2393 .suspend
= rt2x00usb_suspend
,
2394 .resume
= rt2x00usb_resume
,
2397 static int __init
rt73usb_init(void)
2399 return usb_register(&rt73usb_driver
);
2402 static void __exit
rt73usb_exit(void)
2404 usb_deregister(&rt73usb_driver
);
2407 module_init(rt73usb_init
);
2408 module_exit(rt73usb_exit
);