2 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
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, see <http://www.gnu.org/licenses/>.
21 Abstract: rt2500usb device specific routines.
22 Supported chipsets: RT2570.
25 #include <linux/delay.h>
26 #include <linux/etherdevice.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/usb.h>
33 #include "rt2x00usb.h"
34 #include "rt2500usb.h"
37 * Allow hardware encryption to be disabled.
39 static bool modparam_nohwcrypt
;
40 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, S_IRUGO
);
41 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
45 * All access to the CSR registers will go through the methods
46 * rt2500usb_register_read and rt2500usb_register_write.
47 * BBP and RF register require indirect register access,
48 * and use the CSR registers BBPCSR and RFCSR to achieve this.
49 * These indirect registers work with busy bits,
50 * and we will try maximal REGISTER_USB_BUSY_COUNT times to access
51 * the register while taking a REGISTER_BUSY_DELAY us delay
52 * between each attampt. When the busy bit is still set at that time,
53 * the access attempt is considered to have failed,
54 * and we will print an error.
55 * If the csr_mutex is already held then the _lock variants must
58 static inline void rt2500usb_register_read(struct rt2x00_dev
*rt2x00dev
,
59 const unsigned int offset
,
63 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_READ
,
64 USB_VENDOR_REQUEST_IN
, offset
,
66 *value
= le16_to_cpu(reg
);
69 static inline void rt2500usb_register_read_lock(struct rt2x00_dev
*rt2x00dev
,
70 const unsigned int offset
,
74 rt2x00usb_vendor_req_buff_lock(rt2x00dev
, USB_MULTI_READ
,
75 USB_VENDOR_REQUEST_IN
, offset
,
76 ®
, sizeof(reg
), REGISTER_TIMEOUT
);
77 *value
= le16_to_cpu(reg
);
80 static inline void rt2500usb_register_multiread(struct rt2x00_dev
*rt2x00dev
,
81 const unsigned int offset
,
82 void *value
, const u16 length
)
84 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_READ
,
85 USB_VENDOR_REQUEST_IN
, offset
,
89 static inline void rt2500usb_register_write(struct rt2x00_dev
*rt2x00dev
,
90 const unsigned int offset
,
93 __le16 reg
= cpu_to_le16(value
);
94 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_WRITE
,
95 USB_VENDOR_REQUEST_OUT
, offset
,
99 static inline void rt2500usb_register_write_lock(struct rt2x00_dev
*rt2x00dev
,
100 const unsigned int offset
,
103 __le16 reg
= cpu_to_le16(value
);
104 rt2x00usb_vendor_req_buff_lock(rt2x00dev
, USB_MULTI_WRITE
,
105 USB_VENDOR_REQUEST_OUT
, offset
,
106 ®
, sizeof(reg
), REGISTER_TIMEOUT
);
109 static inline void rt2500usb_register_multiwrite(struct rt2x00_dev
*rt2x00dev
,
110 const unsigned int offset
,
111 void *value
, const u16 length
)
113 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_WRITE
,
114 USB_VENDOR_REQUEST_OUT
, offset
,
118 static int rt2500usb_regbusy_read(struct rt2x00_dev
*rt2x00dev
,
119 const unsigned int offset
,
120 struct rt2x00_field16 field
,
125 for (i
= 0; i
< REGISTER_USB_BUSY_COUNT
; i
++) {
126 rt2500usb_register_read_lock(rt2x00dev
, offset
, reg
);
127 if (!rt2x00_get_field16(*reg
, field
))
129 udelay(REGISTER_BUSY_DELAY
);
132 rt2x00_err(rt2x00dev
, "Indirect register access failed: offset=0x%.08x, value=0x%.08x\n",
139 #define WAIT_FOR_BBP(__dev, __reg) \
140 rt2500usb_regbusy_read((__dev), PHY_CSR8, PHY_CSR8_BUSY, (__reg))
141 #define WAIT_FOR_RF(__dev, __reg) \
142 rt2500usb_regbusy_read((__dev), PHY_CSR10, PHY_CSR10_RF_BUSY, (__reg))
144 static void rt2500usb_bbp_write(struct rt2x00_dev
*rt2x00dev
,
145 const unsigned int word
, const u8 value
)
149 mutex_lock(&rt2x00dev
->csr_mutex
);
152 * Wait until the BBP becomes available, afterwards we
153 * can safely write the new data into the register.
155 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
157 rt2x00_set_field16(®
, PHY_CSR7_DATA
, value
);
158 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, word
);
159 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 0);
161 rt2500usb_register_write_lock(rt2x00dev
, PHY_CSR7
, reg
);
164 mutex_unlock(&rt2x00dev
->csr_mutex
);
167 static void rt2500usb_bbp_read(struct rt2x00_dev
*rt2x00dev
,
168 const unsigned int word
, u8
*value
)
172 mutex_lock(&rt2x00dev
->csr_mutex
);
175 * Wait until the BBP becomes available, afterwards we
176 * can safely write the read request into the register.
177 * After the data has been written, we wait until hardware
178 * returns the correct value, if at any time the register
179 * doesn't become available in time, reg will be 0xffffffff
180 * which means we return 0xff to the caller.
182 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
184 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, word
);
185 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 1);
187 rt2500usb_register_write_lock(rt2x00dev
, PHY_CSR7
, reg
);
189 if (WAIT_FOR_BBP(rt2x00dev
, ®
))
190 rt2500usb_register_read_lock(rt2x00dev
, PHY_CSR7
, ®
);
193 *value
= rt2x00_get_field16(reg
, PHY_CSR7_DATA
);
195 mutex_unlock(&rt2x00dev
->csr_mutex
);
198 static void rt2500usb_rf_write(struct rt2x00_dev
*rt2x00dev
,
199 const unsigned int word
, const u32 value
)
203 mutex_lock(&rt2x00dev
->csr_mutex
);
206 * Wait until the RF becomes available, afterwards we
207 * can safely write the new data into the register.
209 if (WAIT_FOR_RF(rt2x00dev
, ®
)) {
211 rt2x00_set_field16(®
, PHY_CSR9_RF_VALUE
, value
);
212 rt2500usb_register_write_lock(rt2x00dev
, PHY_CSR9
, reg
);
215 rt2x00_set_field16(®
, PHY_CSR10_RF_VALUE
, value
>> 16);
216 rt2x00_set_field16(®
, PHY_CSR10_RF_NUMBER_OF_BITS
, 20);
217 rt2x00_set_field16(®
, PHY_CSR10_RF_IF_SELECT
, 0);
218 rt2x00_set_field16(®
, PHY_CSR10_RF_BUSY
, 1);
220 rt2500usb_register_write_lock(rt2x00dev
, PHY_CSR10
, reg
);
221 rt2x00_rf_write(rt2x00dev
, word
, value
);
224 mutex_unlock(&rt2x00dev
->csr_mutex
);
227 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
228 static void _rt2500usb_register_read(struct rt2x00_dev
*rt2x00dev
,
229 const unsigned int offset
,
232 rt2500usb_register_read(rt2x00dev
, offset
, (u16
*)value
);
235 static void _rt2500usb_register_write(struct rt2x00_dev
*rt2x00dev
,
236 const unsigned int offset
,
239 rt2500usb_register_write(rt2x00dev
, offset
, value
);
242 static const struct rt2x00debug rt2500usb_rt2x00debug
= {
243 .owner
= THIS_MODULE
,
245 .read
= _rt2500usb_register_read
,
246 .write
= _rt2500usb_register_write
,
247 .flags
= RT2X00DEBUGFS_OFFSET
,
248 .word_base
= CSR_REG_BASE
,
249 .word_size
= sizeof(u16
),
250 .word_count
= CSR_REG_SIZE
/ sizeof(u16
),
253 .read
= rt2x00_eeprom_read
,
254 .write
= rt2x00_eeprom_write
,
255 .word_base
= EEPROM_BASE
,
256 .word_size
= sizeof(u16
),
257 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
260 .read
= rt2500usb_bbp_read
,
261 .write
= rt2500usb_bbp_write
,
262 .word_base
= BBP_BASE
,
263 .word_size
= sizeof(u8
),
264 .word_count
= BBP_SIZE
/ sizeof(u8
),
267 .read
= rt2x00_rf_read
,
268 .write
= rt2500usb_rf_write
,
269 .word_base
= RF_BASE
,
270 .word_size
= sizeof(u32
),
271 .word_count
= RF_SIZE
/ sizeof(u32
),
274 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
276 static int rt2500usb_rfkill_poll(struct rt2x00_dev
*rt2x00dev
)
280 rt2500usb_register_read(rt2x00dev
, MAC_CSR19
, ®
);
281 return rt2x00_get_field16(reg
, MAC_CSR19_VAL7
);
284 #ifdef CONFIG_RT2X00_LIB_LEDS
285 static void rt2500usb_brightness_set(struct led_classdev
*led_cdev
,
286 enum led_brightness brightness
)
288 struct rt2x00_led
*led
=
289 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
290 unsigned int enabled
= brightness
!= LED_OFF
;
293 rt2500usb_register_read(led
->rt2x00dev
, MAC_CSR20
, ®
);
295 if (led
->type
== LED_TYPE_RADIO
|| led
->type
== LED_TYPE_ASSOC
)
296 rt2x00_set_field16(®
, MAC_CSR20_LINK
, enabled
);
297 else if (led
->type
== LED_TYPE_ACTIVITY
)
298 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, enabled
);
300 rt2500usb_register_write(led
->rt2x00dev
, MAC_CSR20
, reg
);
303 static int rt2500usb_blink_set(struct led_classdev
*led_cdev
,
304 unsigned long *delay_on
,
305 unsigned long *delay_off
)
307 struct rt2x00_led
*led
=
308 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
311 rt2500usb_register_read(led
->rt2x00dev
, MAC_CSR21
, ®
);
312 rt2x00_set_field16(®
, MAC_CSR21_ON_PERIOD
, *delay_on
);
313 rt2x00_set_field16(®
, MAC_CSR21_OFF_PERIOD
, *delay_off
);
314 rt2500usb_register_write(led
->rt2x00dev
, MAC_CSR21
, reg
);
319 static void rt2500usb_init_led(struct rt2x00_dev
*rt2x00dev
,
320 struct rt2x00_led
*led
,
323 led
->rt2x00dev
= rt2x00dev
;
325 led
->led_dev
.brightness_set
= rt2500usb_brightness_set
;
326 led
->led_dev
.blink_set
= rt2500usb_blink_set
;
327 led
->flags
= LED_INITIALIZED
;
329 #endif /* CONFIG_RT2X00_LIB_LEDS */
332 * Configuration handlers.
336 * rt2500usb does not differentiate between shared and pairwise
337 * keys, so we should use the same function for both key types.
339 static int rt2500usb_config_key(struct rt2x00_dev
*rt2x00dev
,
340 struct rt2x00lib_crypto
*crypto
,
341 struct ieee80211_key_conf
*key
)
345 enum cipher curr_cipher
;
347 if (crypto
->cmd
== SET_KEY
) {
349 * Disallow to set WEP key other than with index 0,
350 * it is known that not work at least on some hardware.
351 * SW crypto will be used in that case.
353 if ((key
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
354 key
->cipher
== WLAN_CIPHER_SUITE_WEP104
) &&
359 * Pairwise key will always be entry 0, but this
360 * could collide with a shared key on the same
363 mask
= TXRX_CSR0_KEY_ID
.bit_mask
;
365 rt2500usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
366 curr_cipher
= rt2x00_get_field16(reg
, TXRX_CSR0_ALGORITHM
);
369 if (reg
&& reg
== mask
)
372 reg
= rt2x00_get_field16(reg
, TXRX_CSR0_KEY_ID
);
374 key
->hw_key_idx
+= reg
? ffz(reg
) : 0;
376 * Hardware requires that all keys use the same cipher
377 * (e.g. TKIP-only, AES-only, but not TKIP+AES).
378 * If this is not the first key, compare the cipher with the
379 * first one and fall back to SW crypto if not the same.
381 if (key
->hw_key_idx
> 0 && crypto
->cipher
!= curr_cipher
)
384 rt2500usb_register_multiwrite(rt2x00dev
, KEY_ENTRY(key
->hw_key_idx
),
385 crypto
->key
, sizeof(crypto
->key
));
388 * The driver does not support the IV/EIV generation
389 * in hardware. However it demands the data to be provided
390 * both separately as well as inside the frame.
391 * We already provided the CONFIG_CRYPTO_COPY_IV to rt2x00lib
392 * to ensure rt2x00lib will not strip the data from the
393 * frame after the copy, now we must tell mac80211
394 * to generate the IV/EIV data.
396 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
397 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
401 * TXRX_CSR0_KEY_ID contains only single-bit fields to indicate
402 * a particular key is valid.
404 rt2500usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
405 rt2x00_set_field16(®
, TXRX_CSR0_ALGORITHM
, crypto
->cipher
);
406 rt2x00_set_field16(®
, TXRX_CSR0_IV_OFFSET
, IEEE80211_HEADER
);
408 mask
= rt2x00_get_field16(reg
, TXRX_CSR0_KEY_ID
);
409 if (crypto
->cmd
== SET_KEY
)
410 mask
|= 1 << key
->hw_key_idx
;
411 else if (crypto
->cmd
== DISABLE_KEY
)
412 mask
&= ~(1 << key
->hw_key_idx
);
413 rt2x00_set_field16(®
, TXRX_CSR0_KEY_ID
, mask
);
414 rt2500usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
419 static void rt2500usb_config_filter(struct rt2x00_dev
*rt2x00dev
,
420 const unsigned int filter_flags
)
425 * Start configuration steps.
426 * Note that the version error will always be dropped
427 * and broadcast frames will always be accepted since
428 * there is no filter for it at this time.
430 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
431 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CRC
,
432 !(filter_flags
& FIF_FCSFAIL
));
433 rt2x00_set_field16(®
, TXRX_CSR2_DROP_PHYSICAL
,
434 !(filter_flags
& FIF_PLCPFAIL
));
435 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CONTROL
,
436 !(filter_flags
& FIF_CONTROL
));
437 rt2x00_set_field16(®
, TXRX_CSR2_DROP_NOT_TO_ME
,
438 !(filter_flags
& FIF_PROMISC_IN_BSS
));
439 rt2x00_set_field16(®
, TXRX_CSR2_DROP_TODS
,
440 !(filter_flags
& FIF_PROMISC_IN_BSS
) &&
441 !rt2x00dev
->intf_ap_count
);
442 rt2x00_set_field16(®
, TXRX_CSR2_DROP_VERSION_ERROR
, 1);
443 rt2x00_set_field16(®
, TXRX_CSR2_DROP_MULTICAST
,
444 !(filter_flags
& FIF_ALLMULTI
));
445 rt2x00_set_field16(®
, TXRX_CSR2_DROP_BROADCAST
, 0);
446 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
449 static void rt2500usb_config_intf(struct rt2x00_dev
*rt2x00dev
,
450 struct rt2x00_intf
*intf
,
451 struct rt2x00intf_conf
*conf
,
452 const unsigned int flags
)
454 unsigned int bcn_preload
;
457 if (flags
& CONFIG_UPDATE_TYPE
) {
459 * Enable beacon config
461 bcn_preload
= PREAMBLE
+ GET_DURATION(IEEE80211_HEADER
, 20);
462 rt2500usb_register_read(rt2x00dev
, TXRX_CSR20
, ®
);
463 rt2x00_set_field16(®
, TXRX_CSR20_OFFSET
, bcn_preload
>> 6);
464 rt2x00_set_field16(®
, TXRX_CSR20_BCN_EXPECT_WINDOW
,
465 2 * (conf
->type
!= NL80211_IFTYPE_STATION
));
466 rt2500usb_register_write(rt2x00dev
, TXRX_CSR20
, reg
);
469 * Enable synchronisation.
471 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
472 rt2x00_set_field16(®
, TXRX_CSR18_OFFSET
, 0);
473 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
475 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
476 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, conf
->sync
);
477 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
480 if (flags
& CONFIG_UPDATE_MAC
)
481 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR2
, conf
->mac
,
482 (3 * sizeof(__le16
)));
484 if (flags
& CONFIG_UPDATE_BSSID
)
485 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR5
, conf
->bssid
,
486 (3 * sizeof(__le16
)));
489 static void rt2500usb_config_erp(struct rt2x00_dev
*rt2x00dev
,
490 struct rt2x00lib_erp
*erp
,
495 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
496 rt2500usb_register_read(rt2x00dev
, TXRX_CSR10
, ®
);
497 rt2x00_set_field16(®
, TXRX_CSR10_AUTORESPOND_PREAMBLE
,
498 !!erp
->short_preamble
);
499 rt2500usb_register_write(rt2x00dev
, TXRX_CSR10
, reg
);
502 if (changed
& BSS_CHANGED_BASIC_RATES
)
503 rt2500usb_register_write(rt2x00dev
, TXRX_CSR11
,
506 if (changed
& BSS_CHANGED_BEACON_INT
) {
507 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
508 rt2x00_set_field16(®
, TXRX_CSR18_INTERVAL
,
509 erp
->beacon_int
* 4);
510 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
513 if (changed
& BSS_CHANGED_ERP_SLOT
) {
514 rt2500usb_register_write(rt2x00dev
, MAC_CSR10
, erp
->slot_time
);
515 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, erp
->sifs
);
516 rt2500usb_register_write(rt2x00dev
, MAC_CSR12
, erp
->eifs
);
520 static void rt2500usb_config_ant(struct rt2x00_dev
*rt2x00dev
,
521 struct antenna_setup
*ant
)
529 * We should never come here because rt2x00lib is supposed
530 * to catch this and send us the correct antenna explicitely.
532 BUG_ON(ant
->rx
== ANTENNA_SW_DIVERSITY
||
533 ant
->tx
== ANTENNA_SW_DIVERSITY
);
535 rt2500usb_bbp_read(rt2x00dev
, 2, &r2
);
536 rt2500usb_bbp_read(rt2x00dev
, 14, &r14
);
537 rt2500usb_register_read(rt2x00dev
, PHY_CSR5
, &csr5
);
538 rt2500usb_register_read(rt2x00dev
, PHY_CSR6
, &csr6
);
541 * Configure the TX antenna.
544 case ANTENNA_HW_DIVERSITY
:
545 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 1);
546 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 1);
547 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 1);
550 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 0);
551 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 0);
552 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 0);
556 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 2);
557 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 2);
558 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 2);
563 * Configure the RX antenna.
566 case ANTENNA_HW_DIVERSITY
:
567 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 1);
570 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 0);
574 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 2);
579 * RT2525E and RT5222 need to flip TX I/Q
581 if (rt2x00_rf(rt2x00dev
, RF2525E
) || rt2x00_rf(rt2x00dev
, RF5222
)) {
582 rt2x00_set_field8(&r2
, BBP_R2_TX_IQ_FLIP
, 1);
583 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 1);
584 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 1);
587 * RT2525E does not need RX I/Q Flip.
589 if (rt2x00_rf(rt2x00dev
, RF2525E
))
590 rt2x00_set_field8(&r14
, BBP_R14_RX_IQ_FLIP
, 0);
592 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 0);
593 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 0);
596 rt2500usb_bbp_write(rt2x00dev
, 2, r2
);
597 rt2500usb_bbp_write(rt2x00dev
, 14, r14
);
598 rt2500usb_register_write(rt2x00dev
, PHY_CSR5
, csr5
);
599 rt2500usb_register_write(rt2x00dev
, PHY_CSR6
, csr6
);
602 static void rt2500usb_config_channel(struct rt2x00_dev
*rt2x00dev
,
603 struct rf_channel
*rf
, const int txpower
)
608 rt2x00_set_field32(&rf
->rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
611 * For RT2525E we should first set the channel to half band higher.
613 if (rt2x00_rf(rt2x00dev
, RF2525E
)) {
614 static const u32 vals
[] = {
615 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
616 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
617 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
618 0x00000902, 0x00000906
621 rt2500usb_rf_write(rt2x00dev
, 2, vals
[rf
->channel
- 1]);
623 rt2500usb_rf_write(rt2x00dev
, 4, rf
->rf4
);
626 rt2500usb_rf_write(rt2x00dev
, 1, rf
->rf1
);
627 rt2500usb_rf_write(rt2x00dev
, 2, rf
->rf2
);
628 rt2500usb_rf_write(rt2x00dev
, 3, rf
->rf3
);
630 rt2500usb_rf_write(rt2x00dev
, 4, rf
->rf4
);
633 static void rt2500usb_config_txpower(struct rt2x00_dev
*rt2x00dev
,
638 rt2x00_rf_read(rt2x00dev
, 3, &rf3
);
639 rt2x00_set_field32(&rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
640 rt2500usb_rf_write(rt2x00dev
, 3, rf3
);
643 static void rt2500usb_config_ps(struct rt2x00_dev
*rt2x00dev
,
644 struct rt2x00lib_conf
*libconf
)
646 enum dev_state state
=
647 (libconf
->conf
->flags
& IEEE80211_CONF_PS
) ?
648 STATE_SLEEP
: STATE_AWAKE
;
651 if (state
== STATE_SLEEP
) {
652 rt2500usb_register_read(rt2x00dev
, MAC_CSR18
, ®
);
653 rt2x00_set_field16(®
, MAC_CSR18_DELAY_AFTER_BEACON
,
654 rt2x00dev
->beacon_int
- 20);
655 rt2x00_set_field16(®
, MAC_CSR18_BEACONS_BEFORE_WAKEUP
,
656 libconf
->conf
->listen_interval
- 1);
658 /* We must first disable autowake before it can be enabled */
659 rt2x00_set_field16(®
, MAC_CSR18_AUTO_WAKE
, 0);
660 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
662 rt2x00_set_field16(®
, MAC_CSR18_AUTO_WAKE
, 1);
663 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
665 rt2500usb_register_read(rt2x00dev
, MAC_CSR18
, ®
);
666 rt2x00_set_field16(®
, MAC_CSR18_AUTO_WAKE
, 0);
667 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
670 rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, state
);
673 static void rt2500usb_config(struct rt2x00_dev
*rt2x00dev
,
674 struct rt2x00lib_conf
*libconf
,
675 const unsigned int flags
)
677 if (flags
& IEEE80211_CONF_CHANGE_CHANNEL
)
678 rt2500usb_config_channel(rt2x00dev
, &libconf
->rf
,
679 libconf
->conf
->power_level
);
680 if ((flags
& IEEE80211_CONF_CHANGE_POWER
) &&
681 !(flags
& IEEE80211_CONF_CHANGE_CHANNEL
))
682 rt2500usb_config_txpower(rt2x00dev
,
683 libconf
->conf
->power_level
);
684 if (flags
& IEEE80211_CONF_CHANGE_PS
)
685 rt2500usb_config_ps(rt2x00dev
, libconf
);
691 static void rt2500usb_link_stats(struct rt2x00_dev
*rt2x00dev
,
692 struct link_qual
*qual
)
697 * Update FCS error count from register.
699 rt2500usb_register_read(rt2x00dev
, STA_CSR0
, ®
);
700 qual
->rx_failed
= rt2x00_get_field16(reg
, STA_CSR0_FCS_ERROR
);
703 * Update False CCA count from register.
705 rt2500usb_register_read(rt2x00dev
, STA_CSR3
, ®
);
706 qual
->false_cca
= rt2x00_get_field16(reg
, STA_CSR3_FALSE_CCA_ERROR
);
709 static void rt2500usb_reset_tuner(struct rt2x00_dev
*rt2x00dev
,
710 struct link_qual
*qual
)
715 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &eeprom
);
716 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R24_LOW
);
717 rt2500usb_bbp_write(rt2x00dev
, 24, value
);
719 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &eeprom
);
720 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R25_LOW
);
721 rt2500usb_bbp_write(rt2x00dev
, 25, value
);
723 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &eeprom
);
724 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R61_LOW
);
725 rt2500usb_bbp_write(rt2x00dev
, 61, value
);
727 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &eeprom
);
728 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_VGCUPPER
);
729 rt2500usb_bbp_write(rt2x00dev
, 17, value
);
731 qual
->vgc_level
= value
;
737 static void rt2500usb_start_queue(struct data_queue
*queue
)
739 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
742 switch (queue
->qid
) {
744 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
745 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
, 0);
746 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
749 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
750 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 1);
751 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 1);
752 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 1);
753 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
760 static void rt2500usb_stop_queue(struct data_queue
*queue
)
762 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
765 switch (queue
->qid
) {
767 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
768 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
, 1);
769 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
772 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
773 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 0);
774 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 0);
775 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 0);
776 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
784 * Initialization functions.
786 static int rt2500usb_init_registers(struct rt2x00_dev
*rt2x00dev
)
790 rt2x00usb_vendor_request_sw(rt2x00dev
, USB_DEVICE_MODE
, 0x0001,
791 USB_MODE_TEST
, REGISTER_TIMEOUT
);
792 rt2x00usb_vendor_request_sw(rt2x00dev
, USB_SINGLE_WRITE
, 0x0308,
793 0x00f0, REGISTER_TIMEOUT
);
795 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
796 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
, 1);
797 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
799 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x1111);
800 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x1e11);
802 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
803 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 1);
804 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 1);
805 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 0);
806 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
808 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
809 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 0);
810 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 0);
811 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 0);
812 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
814 rt2500usb_register_read(rt2x00dev
, TXRX_CSR5
, ®
);
815 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID0
, 13);
816 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID0_VALID
, 1);
817 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID1
, 12);
818 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID1_VALID
, 1);
819 rt2500usb_register_write(rt2x00dev
, TXRX_CSR5
, reg
);
821 rt2500usb_register_read(rt2x00dev
, TXRX_CSR6
, ®
);
822 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID0
, 10);
823 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID0_VALID
, 1);
824 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID1
, 11);
825 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID1_VALID
, 1);
826 rt2500usb_register_write(rt2x00dev
, TXRX_CSR6
, reg
);
828 rt2500usb_register_read(rt2x00dev
, TXRX_CSR7
, ®
);
829 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID0
, 7);
830 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID0_VALID
, 1);
831 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID1
, 6);
832 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID1_VALID
, 1);
833 rt2500usb_register_write(rt2x00dev
, TXRX_CSR7
, reg
);
835 rt2500usb_register_read(rt2x00dev
, TXRX_CSR8
, ®
);
836 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID0
, 5);
837 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID0_VALID
, 1);
838 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID1
, 0);
839 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID1_VALID
, 0);
840 rt2500usb_register_write(rt2x00dev
, TXRX_CSR8
, reg
);
842 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
843 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 0);
844 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 0);
845 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 0);
846 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 0);
847 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
849 rt2500usb_register_write(rt2x00dev
, TXRX_CSR21
, 0xe78f);
850 rt2500usb_register_write(rt2x00dev
, MAC_CSR9
, 0xff1d);
852 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
855 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
856 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 0);
857 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 0);
858 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 1);
859 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
861 if (rt2x00_rev(rt2x00dev
) >= RT2570_VERSION_C
) {
862 rt2500usb_register_read(rt2x00dev
, PHY_CSR2
, ®
);
863 rt2x00_set_field16(®
, PHY_CSR2_LNA
, 0);
866 rt2x00_set_field16(®
, PHY_CSR2_LNA
, 1);
867 rt2x00_set_field16(®
, PHY_CSR2_LNA_MODE
, 3);
869 rt2500usb_register_write(rt2x00dev
, PHY_CSR2
, reg
);
871 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x0002);
872 rt2500usb_register_write(rt2x00dev
, MAC_CSR22
, 0x0053);
873 rt2500usb_register_write(rt2x00dev
, MAC_CSR15
, 0x01ee);
874 rt2500usb_register_write(rt2x00dev
, MAC_CSR16
, 0x0000);
876 rt2500usb_register_read(rt2x00dev
, MAC_CSR8
, ®
);
877 rt2x00_set_field16(®
, MAC_CSR8_MAX_FRAME_UNIT
,
878 rt2x00dev
->rx
->data_size
);
879 rt2500usb_register_write(rt2x00dev
, MAC_CSR8
, reg
);
881 rt2500usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
882 rt2x00_set_field16(®
, TXRX_CSR0_ALGORITHM
, CIPHER_NONE
);
883 rt2x00_set_field16(®
, TXRX_CSR0_IV_OFFSET
, IEEE80211_HEADER
);
884 rt2x00_set_field16(®
, TXRX_CSR0_KEY_ID
, 0);
885 rt2500usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
887 rt2500usb_register_read(rt2x00dev
, MAC_CSR18
, ®
);
888 rt2x00_set_field16(®
, MAC_CSR18_DELAY_AFTER_BEACON
, 90);
889 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
891 rt2500usb_register_read(rt2x00dev
, PHY_CSR4
, ®
);
892 rt2x00_set_field16(®
, PHY_CSR4_LOW_RF_LE
, 1);
893 rt2500usb_register_write(rt2x00dev
, PHY_CSR4
, reg
);
895 rt2500usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
896 rt2x00_set_field16(®
, TXRX_CSR1_AUTO_SEQUENCE
, 1);
897 rt2500usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
902 static int rt2500usb_wait_bbp_ready(struct rt2x00_dev
*rt2x00dev
)
907 for (i
= 0; i
< REGISTER_USB_BUSY_COUNT
; i
++) {
908 rt2500usb_bbp_read(rt2x00dev
, 0, &value
);
909 if ((value
!= 0xff) && (value
!= 0x00))
911 udelay(REGISTER_BUSY_DELAY
);
914 rt2x00_err(rt2x00dev
, "BBP register access failed, aborting\n");
918 static int rt2500usb_init_bbp(struct rt2x00_dev
*rt2x00dev
)
925 if (unlikely(rt2500usb_wait_bbp_ready(rt2x00dev
)))
928 rt2500usb_bbp_write(rt2x00dev
, 3, 0x02);
929 rt2500usb_bbp_write(rt2x00dev
, 4, 0x19);
930 rt2500usb_bbp_write(rt2x00dev
, 14, 0x1c);
931 rt2500usb_bbp_write(rt2x00dev
, 15, 0x30);
932 rt2500usb_bbp_write(rt2x00dev
, 16, 0xac);
933 rt2500usb_bbp_write(rt2x00dev
, 18, 0x18);
934 rt2500usb_bbp_write(rt2x00dev
, 19, 0xff);
935 rt2500usb_bbp_write(rt2x00dev
, 20, 0x1e);
936 rt2500usb_bbp_write(rt2x00dev
, 21, 0x08);
937 rt2500usb_bbp_write(rt2x00dev
, 22, 0x08);
938 rt2500usb_bbp_write(rt2x00dev
, 23, 0x08);
939 rt2500usb_bbp_write(rt2x00dev
, 24, 0x80);
940 rt2500usb_bbp_write(rt2x00dev
, 25, 0x50);
941 rt2500usb_bbp_write(rt2x00dev
, 26, 0x08);
942 rt2500usb_bbp_write(rt2x00dev
, 27, 0x23);
943 rt2500usb_bbp_write(rt2x00dev
, 30, 0x10);
944 rt2500usb_bbp_write(rt2x00dev
, 31, 0x2b);
945 rt2500usb_bbp_write(rt2x00dev
, 32, 0xb9);
946 rt2500usb_bbp_write(rt2x00dev
, 34, 0x12);
947 rt2500usb_bbp_write(rt2x00dev
, 35, 0x50);
948 rt2500usb_bbp_write(rt2x00dev
, 39, 0xc4);
949 rt2500usb_bbp_write(rt2x00dev
, 40, 0x02);
950 rt2500usb_bbp_write(rt2x00dev
, 41, 0x60);
951 rt2500usb_bbp_write(rt2x00dev
, 53, 0x10);
952 rt2500usb_bbp_write(rt2x00dev
, 54, 0x18);
953 rt2500usb_bbp_write(rt2x00dev
, 56, 0x08);
954 rt2500usb_bbp_write(rt2x00dev
, 57, 0x10);
955 rt2500usb_bbp_write(rt2x00dev
, 58, 0x08);
956 rt2500usb_bbp_write(rt2x00dev
, 61, 0x60);
957 rt2500usb_bbp_write(rt2x00dev
, 62, 0x10);
958 rt2500usb_bbp_write(rt2x00dev
, 75, 0xff);
960 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
961 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
963 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
964 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
965 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
966 rt2500usb_bbp_write(rt2x00dev
, reg_id
, value
);
974 * Device state switch handlers.
976 static int rt2500usb_enable_radio(struct rt2x00_dev
*rt2x00dev
)
979 * Initialize all registers.
981 if (unlikely(rt2500usb_init_registers(rt2x00dev
) ||
982 rt2500usb_init_bbp(rt2x00dev
)))
988 static void rt2500usb_disable_radio(struct rt2x00_dev
*rt2x00dev
)
990 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x2121);
991 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x2121);
994 * Disable synchronisation.
996 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
998 rt2x00usb_disable_radio(rt2x00dev
);
1001 static int rt2500usb_set_state(struct rt2x00_dev
*rt2x00dev
,
1002 enum dev_state state
)
1011 put_to_sleep
= (state
!= STATE_AWAKE
);
1014 rt2x00_set_field16(®
, MAC_CSR17_BBP_DESIRE_STATE
, state
);
1015 rt2x00_set_field16(®
, MAC_CSR17_RF_DESIRE_STATE
, state
);
1016 rt2x00_set_field16(®
, MAC_CSR17_PUT_TO_SLEEP
, put_to_sleep
);
1017 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1018 rt2x00_set_field16(®
, MAC_CSR17_SET_STATE
, 1);
1019 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1022 * Device is not guaranteed to be in the requested state yet.
1023 * We must wait until the register indicates that the
1024 * device has entered the correct state.
1026 for (i
= 0; i
< REGISTER_USB_BUSY_COUNT
; i
++) {
1027 rt2500usb_register_read(rt2x00dev
, MAC_CSR17
, ®2
);
1028 bbp_state
= rt2x00_get_field16(reg2
, MAC_CSR17_BBP_CURR_STATE
);
1029 rf_state
= rt2x00_get_field16(reg2
, MAC_CSR17_RF_CURR_STATE
);
1030 if (bbp_state
== state
&& rf_state
== state
)
1032 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1039 static int rt2500usb_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1040 enum dev_state state
)
1045 case STATE_RADIO_ON
:
1046 retval
= rt2500usb_enable_radio(rt2x00dev
);
1048 case STATE_RADIO_OFF
:
1049 rt2500usb_disable_radio(rt2x00dev
);
1051 case STATE_RADIO_IRQ_ON
:
1052 case STATE_RADIO_IRQ_OFF
:
1053 /* No support, but no error either */
1055 case STATE_DEEP_SLEEP
:
1059 retval
= rt2500usb_set_state(rt2x00dev
, state
);
1066 if (unlikely(retval
))
1067 rt2x00_err(rt2x00dev
, "Device failed to enter state %d (%d)\n",
1074 * TX descriptor initialization
1076 static void rt2500usb_write_tx_desc(struct queue_entry
*entry
,
1077 struct txentry_desc
*txdesc
)
1079 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1080 __le32
*txd
= (__le32
*) entry
->skb
->data
;
1084 * Start writing the descriptor words.
1086 rt2x00_desc_read(txd
, 0, &word
);
1087 rt2x00_set_field32(&word
, TXD_W0_RETRY_LIMIT
, txdesc
->retry_limit
);
1088 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1089 test_bit(ENTRY_TXD_MORE_FRAG
, &txdesc
->flags
));
1090 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1091 test_bit(ENTRY_TXD_ACK
, &txdesc
->flags
));
1092 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1093 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &txdesc
->flags
));
1094 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1095 (txdesc
->rate_mode
== RATE_MODE_OFDM
));
1096 rt2x00_set_field32(&word
, TXD_W0_NEW_SEQ
,
1097 test_bit(ENTRY_TXD_FIRST_FRAGMENT
, &txdesc
->flags
));
1098 rt2x00_set_field32(&word
, TXD_W0_IFS
, txdesc
->u
.plcp
.ifs
);
1099 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, txdesc
->length
);
1100 rt2x00_set_field32(&word
, TXD_W0_CIPHER
, !!txdesc
->cipher
);
1101 rt2x00_set_field32(&word
, TXD_W0_KEY_ID
, txdesc
->key_idx
);
1102 rt2x00_desc_write(txd
, 0, word
);
1104 rt2x00_desc_read(txd
, 1, &word
);
1105 rt2x00_set_field32(&word
, TXD_W1_IV_OFFSET
, txdesc
->iv_offset
);
1106 rt2x00_set_field32(&word
, TXD_W1_AIFS
, entry
->queue
->aifs
);
1107 rt2x00_set_field32(&word
, TXD_W1_CWMIN
, entry
->queue
->cw_min
);
1108 rt2x00_set_field32(&word
, TXD_W1_CWMAX
, entry
->queue
->cw_max
);
1109 rt2x00_desc_write(txd
, 1, word
);
1111 rt2x00_desc_read(txd
, 2, &word
);
1112 rt2x00_set_field32(&word
, TXD_W2_PLCP_SIGNAL
, txdesc
->u
.plcp
.signal
);
1113 rt2x00_set_field32(&word
, TXD_W2_PLCP_SERVICE
, txdesc
->u
.plcp
.service
);
1114 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_LOW
,
1115 txdesc
->u
.plcp
.length_low
);
1116 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_HIGH
,
1117 txdesc
->u
.plcp
.length_high
);
1118 rt2x00_desc_write(txd
, 2, word
);
1120 if (test_bit(ENTRY_TXD_ENCRYPT
, &txdesc
->flags
)) {
1121 _rt2x00_desc_write(txd
, 3, skbdesc
->iv
[0]);
1122 _rt2x00_desc_write(txd
, 4, skbdesc
->iv
[1]);
1126 * Register descriptor details in skb frame descriptor.
1128 skbdesc
->flags
|= SKBDESC_DESC_IN_SKB
;
1129 skbdesc
->desc
= txd
;
1130 skbdesc
->desc_len
= TXD_DESC_SIZE
;
1134 * TX data initialization
1136 static void rt2500usb_beacondone(struct urb
*urb
);
1138 static void rt2500usb_write_beacon(struct queue_entry
*entry
,
1139 struct txentry_desc
*txdesc
)
1141 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1142 struct usb_device
*usb_dev
= to_usb_device_intf(rt2x00dev
->dev
);
1143 struct queue_entry_priv_usb_bcn
*bcn_priv
= entry
->priv_data
;
1144 int pipe
= usb_sndbulkpipe(usb_dev
, entry
->queue
->usb_endpoint
);
1149 * Disable beaconing while we are reloading the beacon data,
1150 * otherwise we might be sending out invalid data.
1152 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
1153 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 0);
1154 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1157 * Add space for the descriptor in front of the skb.
1159 skb_push(entry
->skb
, TXD_DESC_SIZE
);
1160 memset(entry
->skb
->data
, 0, TXD_DESC_SIZE
);
1163 * Write the TX descriptor for the beacon.
1165 rt2500usb_write_tx_desc(entry
, txdesc
);
1168 * Dump beacon to userspace through debugfs.
1170 rt2x00debug_dump_frame(rt2x00dev
, DUMP_FRAME_BEACON
, entry
->skb
);
1173 * USB devices cannot blindly pass the skb->len as the
1174 * length of the data to usb_fill_bulk_urb. Pass the skb
1175 * to the driver to determine what the length should be.
1177 length
= rt2x00dev
->ops
->lib
->get_tx_data_len(entry
);
1179 usb_fill_bulk_urb(bcn_priv
->urb
, usb_dev
, pipe
,
1180 entry
->skb
->data
, length
, rt2500usb_beacondone
,
1184 * Second we need to create the guardian byte.
1185 * We only need a single byte, so lets recycle
1186 * the 'flags' field we are not using for beacons.
1188 bcn_priv
->guardian_data
= 0;
1189 usb_fill_bulk_urb(bcn_priv
->guardian_urb
, usb_dev
, pipe
,
1190 &bcn_priv
->guardian_data
, 1, rt2500usb_beacondone
,
1194 * Send out the guardian byte.
1196 usb_submit_urb(bcn_priv
->guardian_urb
, GFP_ATOMIC
);
1199 * Enable beaconing again.
1201 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 1);
1202 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 1);
1204 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 1);
1206 * Beacon generation will fail initially.
1207 * To prevent this we need to change the TXRX_CSR19
1208 * register several times (reg0 is the same as reg
1209 * except for TXRX_CSR19_BEACON_GEN, which is 0 in reg0
1212 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1213 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg0
);
1214 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1215 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg0
);
1216 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1219 static int rt2500usb_get_tx_data_len(struct queue_entry
*entry
)
1224 * The length _must_ be a multiple of 2,
1225 * but it must _not_ be a multiple of the USB packet size.
1227 length
= roundup(entry
->skb
->len
, 2);
1228 length
+= (2 * !(length
% entry
->queue
->usb_maxpacket
));
1234 * RX control handlers
1236 static void rt2500usb_fill_rxdone(struct queue_entry
*entry
,
1237 struct rxdone_entry_desc
*rxdesc
)
1239 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1240 struct queue_entry_priv_usb
*entry_priv
= entry
->priv_data
;
1241 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1243 (__le32
*)(entry
->skb
->data
+
1244 (entry_priv
->urb
->actual_length
-
1245 entry
->queue
->desc_size
));
1250 * Copy descriptor to the skbdesc->desc buffer, making it safe from moving of
1251 * frame data in rt2x00usb.
1253 memcpy(skbdesc
->desc
, rxd
, skbdesc
->desc_len
);
1254 rxd
= (__le32
*)skbdesc
->desc
;
1257 * It is now safe to read the descriptor on all architectures.
1259 rt2x00_desc_read(rxd
, 0, &word0
);
1260 rt2x00_desc_read(rxd
, 1, &word1
);
1262 if (rt2x00_get_field32(word0
, RXD_W0_CRC_ERROR
))
1263 rxdesc
->flags
|= RX_FLAG_FAILED_FCS_CRC
;
1264 if (rt2x00_get_field32(word0
, RXD_W0_PHYSICAL_ERROR
))
1265 rxdesc
->flags
|= RX_FLAG_FAILED_PLCP_CRC
;
1267 rxdesc
->cipher
= rt2x00_get_field32(word0
, RXD_W0_CIPHER
);
1268 if (rt2x00_get_field32(word0
, RXD_W0_CIPHER_ERROR
))
1269 rxdesc
->cipher_status
= RX_CRYPTO_FAIL_KEY
;
1271 if (rxdesc
->cipher
!= CIPHER_NONE
) {
1272 _rt2x00_desc_read(rxd
, 2, &rxdesc
->iv
[0]);
1273 _rt2x00_desc_read(rxd
, 3, &rxdesc
->iv
[1]);
1274 rxdesc
->dev_flags
|= RXDONE_CRYPTO_IV
;
1276 /* ICV is located at the end of frame */
1278 rxdesc
->flags
|= RX_FLAG_MMIC_STRIPPED
;
1279 if (rxdesc
->cipher_status
== RX_CRYPTO_SUCCESS
)
1280 rxdesc
->flags
|= RX_FLAG_DECRYPTED
;
1281 else if (rxdesc
->cipher_status
== RX_CRYPTO_FAIL_MIC
)
1282 rxdesc
->flags
|= RX_FLAG_MMIC_ERROR
;
1286 * Obtain the status about this packet.
1287 * When frame was received with an OFDM bitrate,
1288 * the signal is the PLCP value. If it was received with
1289 * a CCK bitrate the signal is the rate in 100kbit/s.
1291 rxdesc
->signal
= rt2x00_get_field32(word1
, RXD_W1_SIGNAL
);
1293 rt2x00_get_field32(word1
, RXD_W1_RSSI
) - rt2x00dev
->rssi_offset
;
1294 rxdesc
->size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
1296 if (rt2x00_get_field32(word0
, RXD_W0_OFDM
))
1297 rxdesc
->dev_flags
|= RXDONE_SIGNAL_PLCP
;
1299 rxdesc
->dev_flags
|= RXDONE_SIGNAL_BITRATE
;
1300 if (rt2x00_get_field32(word0
, RXD_W0_MY_BSS
))
1301 rxdesc
->dev_flags
|= RXDONE_MY_BSS
;
1304 * Adjust the skb memory window to the frame boundaries.
1306 skb_trim(entry
->skb
, rxdesc
->size
);
1310 * Interrupt functions.
1312 static void rt2500usb_beacondone(struct urb
*urb
)
1314 struct queue_entry
*entry
= (struct queue_entry
*)urb
->context
;
1315 struct queue_entry_priv_usb_bcn
*bcn_priv
= entry
->priv_data
;
1317 if (!test_bit(DEVICE_STATE_ENABLED_RADIO
, &entry
->queue
->rt2x00dev
->flags
))
1321 * Check if this was the guardian beacon,
1322 * if that was the case we need to send the real beacon now.
1323 * Otherwise we should free the sk_buffer, the device
1324 * should be doing the rest of the work now.
1326 if (bcn_priv
->guardian_urb
== urb
) {
1327 usb_submit_urb(bcn_priv
->urb
, GFP_ATOMIC
);
1328 } else if (bcn_priv
->urb
== urb
) {
1329 dev_kfree_skb(entry
->skb
);
1335 * Device probe functions.
1337 static int rt2500usb_validate_eeprom(struct rt2x00_dev
*rt2x00dev
)
1343 rt2x00usb_eeprom_read(rt2x00dev
, rt2x00dev
->eeprom
, EEPROM_SIZE
);
1346 * Start validation of the data that has been read.
1348 mac
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1349 if (!is_valid_ether_addr(mac
)) {
1350 eth_random_addr(mac
);
1351 rt2x00_eeprom_dbg(rt2x00dev
, "MAC: %pM\n", mac
);
1354 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1355 if (word
== 0xffff) {
1356 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
1357 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
,
1358 ANTENNA_SW_DIVERSITY
);
1359 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
,
1360 ANTENNA_SW_DIVERSITY
);
1361 rt2x00_set_field16(&word
, EEPROM_ANTENNA_LED_MODE
,
1363 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
1364 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
1365 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF2522
);
1366 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
1367 rt2x00_eeprom_dbg(rt2x00dev
, "Antenna: 0x%04x\n", word
);
1370 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &word
);
1371 if (word
== 0xffff) {
1372 rt2x00_set_field16(&word
, EEPROM_NIC_CARDBUS_ACCEL
, 0);
1373 rt2x00_set_field16(&word
, EEPROM_NIC_DYN_BBP_TUNE
, 0);
1374 rt2x00_set_field16(&word
, EEPROM_NIC_CCK_TX_POWER
, 0);
1375 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
1376 rt2x00_eeprom_dbg(rt2x00dev
, "NIC: 0x%04x\n", word
);
1379 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &word
);
1380 if (word
== 0xffff) {
1381 rt2x00_set_field16(&word
, EEPROM_CALIBRATE_OFFSET_RSSI
,
1382 DEFAULT_RSSI_OFFSET
);
1383 rt2x00_eeprom_write(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, word
);
1384 rt2x00_eeprom_dbg(rt2x00dev
, "Calibrate offset: 0x%04x\n",
1388 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE
, &word
);
1389 if (word
== 0xffff) {
1390 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_THRESHOLD
, 45);
1391 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE
, word
);
1392 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune: 0x%04x\n", word
);
1396 * Switch lower vgc bound to current BBP R17 value,
1397 * lower the value a bit for better quality.
1399 rt2500usb_bbp_read(rt2x00dev
, 17, &bbp
);
1402 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &word
);
1403 if (word
== 0xffff) {
1404 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_VGCUPPER
, 0x40);
1405 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_VGCLOWER
, bbp
);
1406 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_VGC
, word
);
1407 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune vgc: 0x%04x\n", word
);
1409 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_VGCLOWER
, bbp
);
1410 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_VGC
, word
);
1413 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R17
, &word
);
1414 if (word
== 0xffff) {
1415 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_LOW
, 0x48);
1416 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_HIGH
, 0x41);
1417 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R17
, word
);
1418 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune r17: 0x%04x\n", word
);
1421 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &word
);
1422 if (word
== 0xffff) {
1423 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_LOW
, 0x40);
1424 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_HIGH
, 0x80);
1425 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R24
, word
);
1426 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune r24: 0x%04x\n", word
);
1429 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &word
);
1430 if (word
== 0xffff) {
1431 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_LOW
, 0x40);
1432 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_HIGH
, 0x50);
1433 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R25
, word
);
1434 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune r25: 0x%04x\n", word
);
1437 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &word
);
1438 if (word
== 0xffff) {
1439 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_LOW
, 0x60);
1440 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_HIGH
, 0x6d);
1441 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R61
, word
);
1442 rt2x00_eeprom_dbg(rt2x00dev
, "BBPtune r61: 0x%04x\n", word
);
1448 static int rt2500usb_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1455 * Read EEPROM word for configuration.
1457 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1460 * Identify RF chipset.
1462 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1463 rt2500usb_register_read(rt2x00dev
, MAC_CSR0
, ®
);
1464 rt2x00_set_chip(rt2x00dev
, RT2570
, value
, reg
);
1466 if (((reg
& 0xfff0) != 0) || ((reg
& 0x0000000f) == 0)) {
1467 rt2x00_err(rt2x00dev
, "Invalid RT chipset detected\n");
1471 if (!rt2x00_rf(rt2x00dev
, RF2522
) &&
1472 !rt2x00_rf(rt2x00dev
, RF2523
) &&
1473 !rt2x00_rf(rt2x00dev
, RF2524
) &&
1474 !rt2x00_rf(rt2x00dev
, RF2525
) &&
1475 !rt2x00_rf(rt2x00dev
, RF2525E
) &&
1476 !rt2x00_rf(rt2x00dev
, RF5222
)) {
1477 rt2x00_err(rt2x00dev
, "Invalid RF chipset detected\n");
1482 * Identify default antenna configuration.
1484 rt2x00dev
->default_ant
.tx
=
1485 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_TX_DEFAULT
);
1486 rt2x00dev
->default_ant
.rx
=
1487 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RX_DEFAULT
);
1490 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1491 * I am not 100% sure about this, but the legacy drivers do not
1492 * indicate antenna swapping in software is required when
1493 * diversity is enabled.
1495 if (rt2x00dev
->default_ant
.tx
== ANTENNA_SW_DIVERSITY
)
1496 rt2x00dev
->default_ant
.tx
= ANTENNA_HW_DIVERSITY
;
1497 if (rt2x00dev
->default_ant
.rx
== ANTENNA_SW_DIVERSITY
)
1498 rt2x00dev
->default_ant
.rx
= ANTENNA_HW_DIVERSITY
;
1501 * Store led mode, for correct led behaviour.
1503 #ifdef CONFIG_RT2X00_LIB_LEDS
1504 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_LED_MODE
);
1506 rt2500usb_init_led(rt2x00dev
, &rt2x00dev
->led_radio
, LED_TYPE_RADIO
);
1507 if (value
== LED_MODE_TXRX_ACTIVITY
||
1508 value
== LED_MODE_DEFAULT
||
1509 value
== LED_MODE_ASUS
)
1510 rt2500usb_init_led(rt2x00dev
, &rt2x00dev
->led_qual
,
1512 #endif /* CONFIG_RT2X00_LIB_LEDS */
1515 * Detect if this device has an hardware controlled radio.
1517 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_HARDWARE_RADIO
))
1518 __set_bit(CAPABILITY_HW_BUTTON
, &rt2x00dev
->cap_flags
);
1521 * Read the RSSI <-> dBm offset information.
1523 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &eeprom
);
1524 rt2x00dev
->rssi_offset
=
1525 rt2x00_get_field16(eeprom
, EEPROM_CALIBRATE_OFFSET_RSSI
);
1531 * RF value list for RF2522
1534 static const struct rf_channel rf_vals_bg_2522
[] = {
1535 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1536 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1537 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1538 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1539 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1540 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1541 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1542 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1543 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1544 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1545 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1546 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1547 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1548 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1552 * RF value list for RF2523
1555 static const struct rf_channel rf_vals_bg_2523
[] = {
1556 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1557 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1558 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1559 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1560 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1561 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1562 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1563 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1564 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1565 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1566 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1567 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1568 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1569 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1573 * RF value list for RF2524
1576 static const struct rf_channel rf_vals_bg_2524
[] = {
1577 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1578 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1579 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1580 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1581 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1582 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1583 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1584 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1585 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1586 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1587 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1588 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1589 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1590 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1594 * RF value list for RF2525
1597 static const struct rf_channel rf_vals_bg_2525
[] = {
1598 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1599 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1600 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1601 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1602 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1603 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1604 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1605 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1606 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1607 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1608 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1609 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1610 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1611 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1615 * RF value list for RF2525e
1618 static const struct rf_channel rf_vals_bg_2525e
[] = {
1619 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1620 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1621 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1622 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1623 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1624 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1625 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1626 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1627 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1628 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1629 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1630 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1631 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1632 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1636 * RF value list for RF5222
1637 * Supports: 2.4 GHz & 5.2 GHz
1639 static const struct rf_channel rf_vals_5222
[] = {
1640 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1641 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1642 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1643 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1644 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1645 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1646 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1647 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1648 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1649 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1650 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1651 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1652 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1653 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1655 /* 802.11 UNI / HyperLan 2 */
1656 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1657 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1658 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1659 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1660 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1661 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1662 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1663 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1665 /* 802.11 HyperLan 2 */
1666 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1667 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1668 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1669 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1670 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1671 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1672 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1673 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1674 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1675 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1678 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1679 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1680 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1681 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1682 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1685 static int rt2500usb_probe_hw_mode(struct rt2x00_dev
*rt2x00dev
)
1687 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1688 struct channel_info
*info
;
1693 * Initialize all hw fields.
1695 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING unless we are
1696 * capable of sending the buffered frames out after the DTIM
1697 * transmission using rt2x00lib_beacondone. This will send out
1698 * multicast and broadcast traffic immediately instead of buffering it
1699 * infinitly and thus dropping it after some time.
1701 rt2x00dev
->hw
->flags
=
1702 IEEE80211_HW_RX_INCLUDES_FCS
|
1703 IEEE80211_HW_SIGNAL_DBM
|
1704 IEEE80211_HW_SUPPORTS_PS
|
1705 IEEE80211_HW_PS_NULLFUNC_STACK
;
1708 * Disable powersaving as default.
1710 rt2x00dev
->hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
1712 SET_IEEE80211_DEV(rt2x00dev
->hw
, rt2x00dev
->dev
);
1713 SET_IEEE80211_PERM_ADDR(rt2x00dev
->hw
,
1714 rt2x00_eeprom_addr(rt2x00dev
,
1715 EEPROM_MAC_ADDR_0
));
1718 * Initialize hw_mode information.
1720 spec
->supported_bands
= SUPPORT_BAND_2GHZ
;
1721 spec
->supported_rates
= SUPPORT_RATE_CCK
| SUPPORT_RATE_OFDM
;
1723 if (rt2x00_rf(rt2x00dev
, RF2522
)) {
1724 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2522
);
1725 spec
->channels
= rf_vals_bg_2522
;
1726 } else if (rt2x00_rf(rt2x00dev
, RF2523
)) {
1727 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2523
);
1728 spec
->channels
= rf_vals_bg_2523
;
1729 } else if (rt2x00_rf(rt2x00dev
, RF2524
)) {
1730 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2524
);
1731 spec
->channels
= rf_vals_bg_2524
;
1732 } else if (rt2x00_rf(rt2x00dev
, RF2525
)) {
1733 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2525
);
1734 spec
->channels
= rf_vals_bg_2525
;
1735 } else if (rt2x00_rf(rt2x00dev
, RF2525E
)) {
1736 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2525e
);
1737 spec
->channels
= rf_vals_bg_2525e
;
1738 } else if (rt2x00_rf(rt2x00dev
, RF5222
)) {
1739 spec
->supported_bands
|= SUPPORT_BAND_5GHZ
;
1740 spec
->num_channels
= ARRAY_SIZE(rf_vals_5222
);
1741 spec
->channels
= rf_vals_5222
;
1745 * Create channel information array
1747 info
= kcalloc(spec
->num_channels
, sizeof(*info
), GFP_KERNEL
);
1751 spec
->channels_info
= info
;
1753 tx_power
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_START
);
1754 for (i
= 0; i
< 14; i
++) {
1755 info
[i
].max_power
= MAX_TXPOWER
;
1756 info
[i
].default_power1
= TXPOWER_FROM_DEV(tx_power
[i
]);
1759 if (spec
->num_channels
> 14) {
1760 for (i
= 14; i
< spec
->num_channels
; i
++) {
1761 info
[i
].max_power
= MAX_TXPOWER
;
1762 info
[i
].default_power1
= DEFAULT_TXPOWER
;
1769 static int rt2500usb_probe_hw(struct rt2x00_dev
*rt2x00dev
)
1775 * Allocate eeprom data.
1777 retval
= rt2500usb_validate_eeprom(rt2x00dev
);
1781 retval
= rt2500usb_init_eeprom(rt2x00dev
);
1786 * Enable rfkill polling by setting GPIO direction of the
1787 * rfkill switch GPIO pin correctly.
1789 rt2500usb_register_read(rt2x00dev
, MAC_CSR19
, ®
);
1790 rt2x00_set_field16(®
, MAC_CSR19_DIR0
, 0);
1791 rt2500usb_register_write(rt2x00dev
, MAC_CSR19
, reg
);
1794 * Initialize hw specifications.
1796 retval
= rt2500usb_probe_hw_mode(rt2x00dev
);
1801 * This device requires the atim queue
1803 __set_bit(REQUIRE_ATIM_QUEUE
, &rt2x00dev
->cap_flags
);
1804 __set_bit(REQUIRE_BEACON_GUARD
, &rt2x00dev
->cap_flags
);
1805 if (!modparam_nohwcrypt
) {
1806 __set_bit(CAPABILITY_HW_CRYPTO
, &rt2x00dev
->cap_flags
);
1807 __set_bit(REQUIRE_COPY_IV
, &rt2x00dev
->cap_flags
);
1809 __set_bit(REQUIRE_SW_SEQNO
, &rt2x00dev
->cap_flags
);
1810 __set_bit(REQUIRE_PS_AUTOWAKE
, &rt2x00dev
->cap_flags
);
1813 * Set the rssi offset.
1815 rt2x00dev
->rssi_offset
= DEFAULT_RSSI_OFFSET
;
1820 static const struct ieee80211_ops rt2500usb_mac80211_ops
= {
1822 .start
= rt2x00mac_start
,
1823 .stop
= rt2x00mac_stop
,
1824 .add_interface
= rt2x00mac_add_interface
,
1825 .remove_interface
= rt2x00mac_remove_interface
,
1826 .config
= rt2x00mac_config
,
1827 .configure_filter
= rt2x00mac_configure_filter
,
1828 .set_tim
= rt2x00mac_set_tim
,
1829 .set_key
= rt2x00mac_set_key
,
1830 .sw_scan_start
= rt2x00mac_sw_scan_start
,
1831 .sw_scan_complete
= rt2x00mac_sw_scan_complete
,
1832 .get_stats
= rt2x00mac_get_stats
,
1833 .bss_info_changed
= rt2x00mac_bss_info_changed
,
1834 .conf_tx
= rt2x00mac_conf_tx
,
1835 .rfkill_poll
= rt2x00mac_rfkill_poll
,
1836 .flush
= rt2x00mac_flush
,
1837 .set_antenna
= rt2x00mac_set_antenna
,
1838 .get_antenna
= rt2x00mac_get_antenna
,
1839 .get_ringparam
= rt2x00mac_get_ringparam
,
1840 .tx_frames_pending
= rt2x00mac_tx_frames_pending
,
1843 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops
= {
1844 .probe_hw
= rt2500usb_probe_hw
,
1845 .initialize
= rt2x00usb_initialize
,
1846 .uninitialize
= rt2x00usb_uninitialize
,
1847 .clear_entry
= rt2x00usb_clear_entry
,
1848 .set_device_state
= rt2500usb_set_device_state
,
1849 .rfkill_poll
= rt2500usb_rfkill_poll
,
1850 .link_stats
= rt2500usb_link_stats
,
1851 .reset_tuner
= rt2500usb_reset_tuner
,
1852 .watchdog
= rt2x00usb_watchdog
,
1853 .start_queue
= rt2500usb_start_queue
,
1854 .kick_queue
= rt2x00usb_kick_queue
,
1855 .stop_queue
= rt2500usb_stop_queue
,
1856 .flush_queue
= rt2x00usb_flush_queue
,
1857 .write_tx_desc
= rt2500usb_write_tx_desc
,
1858 .write_beacon
= rt2500usb_write_beacon
,
1859 .get_tx_data_len
= rt2500usb_get_tx_data_len
,
1860 .fill_rxdone
= rt2500usb_fill_rxdone
,
1861 .config_shared_key
= rt2500usb_config_key
,
1862 .config_pairwise_key
= rt2500usb_config_key
,
1863 .config_filter
= rt2500usb_config_filter
,
1864 .config_intf
= rt2500usb_config_intf
,
1865 .config_erp
= rt2500usb_config_erp
,
1866 .config_ant
= rt2500usb_config_ant
,
1867 .config
= rt2500usb_config
,
1870 static void rt2500usb_queue_init(struct data_queue
*queue
)
1872 switch (queue
->qid
) {
1875 queue
->data_size
= DATA_FRAME_SIZE
;
1876 queue
->desc_size
= RXD_DESC_SIZE
;
1877 queue
->priv_size
= sizeof(struct queue_entry_priv_usb
);
1885 queue
->data_size
= DATA_FRAME_SIZE
;
1886 queue
->desc_size
= TXD_DESC_SIZE
;
1887 queue
->priv_size
= sizeof(struct queue_entry_priv_usb
);
1892 queue
->data_size
= MGMT_FRAME_SIZE
;
1893 queue
->desc_size
= TXD_DESC_SIZE
;
1894 queue
->priv_size
= sizeof(struct queue_entry_priv_usb_bcn
);
1899 queue
->data_size
= DATA_FRAME_SIZE
;
1900 queue
->desc_size
= TXD_DESC_SIZE
;
1901 queue
->priv_size
= sizeof(struct queue_entry_priv_usb
);
1910 static const struct rt2x00_ops rt2500usb_ops
= {
1911 .name
= KBUILD_MODNAME
,
1913 .eeprom_size
= EEPROM_SIZE
,
1915 .tx_queues
= NUM_TX_QUEUES
,
1916 .queue_init
= rt2500usb_queue_init
,
1917 .lib
= &rt2500usb_rt2x00_ops
,
1918 .hw
= &rt2500usb_mac80211_ops
,
1919 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1920 .debugfs
= &rt2500usb_rt2x00debug
,
1921 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1925 * rt2500usb module information.
1927 static struct usb_device_id rt2500usb_device_table
[] = {
1929 { USB_DEVICE(0x0b05, 0x1706) },
1930 { USB_DEVICE(0x0b05, 0x1707) },
1932 { USB_DEVICE(0x050d, 0x7050) }, /* FCC ID: K7SF5D7050A ver. 2.x */
1933 { USB_DEVICE(0x050d, 0x7051) },
1935 { USB_DEVICE(0x13b1, 0x000d) },
1936 { USB_DEVICE(0x13b1, 0x0011) },
1937 { USB_DEVICE(0x13b1, 0x001a) },
1939 { USB_DEVICE(0x14b2, 0x3c02) },
1941 { USB_DEVICE(0x2001, 0x3c00) },
1943 { USB_DEVICE(0x1044, 0x8001) },
1944 { USB_DEVICE(0x1044, 0x8007) },
1946 { USB_DEVICE(0x06f8, 0xe000) },
1948 { USB_DEVICE(0x0411, 0x005e) },
1949 { USB_DEVICE(0x0411, 0x0066) },
1950 { USB_DEVICE(0x0411, 0x0067) },
1951 { USB_DEVICE(0x0411, 0x008b) },
1952 { USB_DEVICE(0x0411, 0x0097) },
1954 { USB_DEVICE(0x0db0, 0x6861) },
1955 { USB_DEVICE(0x0db0, 0x6865) },
1956 { USB_DEVICE(0x0db0, 0x6869) },
1958 { USB_DEVICE(0x148f, 0x1706) },
1959 { USB_DEVICE(0x148f, 0x2570) },
1960 { USB_DEVICE(0x148f, 0x9020) },
1962 { USB_DEVICE(0x079b, 0x004b) },
1964 { USB_DEVICE(0x0681, 0x3c06) },
1966 { USB_DEVICE(0x0707, 0xee13) },
1968 { USB_DEVICE(0x114b, 0x0110) },
1970 { USB_DEVICE(0x0769, 0x11f3) },
1972 { USB_DEVICE(0x0eb0, 0x9020) },
1974 { USB_DEVICE(0x0f88, 0x3012) },
1976 { USB_DEVICE(0x5a57, 0x0260) },
1980 MODULE_AUTHOR(DRV_PROJECT
);
1981 MODULE_VERSION(DRV_VERSION
);
1982 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1983 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1984 MODULE_DEVICE_TABLE(usb
, rt2500usb_device_table
);
1985 MODULE_LICENSE("GPL");
1987 static int rt2500usb_probe(struct usb_interface
*usb_intf
,
1988 const struct usb_device_id
*id
)
1990 return rt2x00usb_probe(usb_intf
, &rt2500usb_ops
);
1993 static struct usb_driver rt2500usb_driver
= {
1994 .name
= KBUILD_MODNAME
,
1995 .id_table
= rt2500usb_device_table
,
1996 .probe
= rt2500usb_probe
,
1997 .disconnect
= rt2x00usb_disconnect
,
1998 .suspend
= rt2x00usb_suspend
,
1999 .resume
= rt2x00usb_resume
,
2000 .reset_resume
= rt2x00usb_resume
,
2001 .disable_hub_initiated_lpm
= 1,
2004 module_usb_driver(rt2500usb_driver
);