2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2500usb device specific routines.
24 Supported chipsets: RT2570.
28 * Set enviroment defines for rt2x00.h
30 #define DRV_NAME "rt2500usb"
32 #include <linux/delay.h>
33 #include <linux/etherdevice.h>
34 #include <linux/init.h>
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/usb.h>
40 #include "rt2x00usb.h"
41 #include "rt2500usb.h"
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_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.
56 static inline void rt2500usb_register_read(const struct rt2x00_dev
*rt2x00dev
,
57 const unsigned int offset
,
61 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_READ
,
62 USB_VENDOR_REQUEST_IN
, offset
,
63 ®
, sizeof(u16
), REGISTER_TIMEOUT
);
64 *value
= le16_to_cpu(reg
);
67 static inline void rt2500usb_register_multiread(const struct rt2x00_dev
69 const unsigned int offset
,
70 void *value
, const u16 length
)
72 int timeout
= REGISTER_TIMEOUT
* (length
/ sizeof(u16
));
73 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_READ
,
74 USB_VENDOR_REQUEST_IN
, offset
,
75 value
, length
, timeout
);
78 static inline void rt2500usb_register_write(const struct rt2x00_dev
*rt2x00dev
,
79 const unsigned int offset
,
82 __le16 reg
= cpu_to_le16(value
);
83 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_WRITE
,
84 USB_VENDOR_REQUEST_OUT
, offset
,
85 ®
, sizeof(u16
), REGISTER_TIMEOUT
);
88 static inline void rt2500usb_register_multiwrite(const struct rt2x00_dev
90 const unsigned int offset
,
91 void *value
, const u16 length
)
93 int timeout
= REGISTER_TIMEOUT
* (length
/ sizeof(u16
));
94 rt2x00usb_vendor_request_buff(rt2x00dev
, USB_MULTI_WRITE
,
95 USB_VENDOR_REQUEST_OUT
, offset
,
96 value
, length
, timeout
);
99 static u16
rt2500usb_bbp_check(const struct rt2x00_dev
*rt2x00dev
)
104 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
105 rt2500usb_register_read(rt2x00dev
, PHY_CSR8
, ®
);
106 if (!rt2x00_get_field16(reg
, PHY_CSR8_BUSY
))
108 udelay(REGISTER_BUSY_DELAY
);
114 static void rt2500usb_bbp_write(const struct rt2x00_dev
*rt2x00dev
,
115 const unsigned int word
, const u8 value
)
120 * Wait until the BBP becomes ready.
122 reg
= rt2500usb_bbp_check(rt2x00dev
);
123 if (rt2x00_get_field16(reg
, PHY_CSR8_BUSY
)) {
124 ERROR(rt2x00dev
, "PHY_CSR8 register busy. Write failed.\n");
129 * Write the data into the BBP.
132 rt2x00_set_field16(®
, PHY_CSR7_DATA
, value
);
133 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, word
);
134 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 0);
136 rt2500usb_register_write(rt2x00dev
, PHY_CSR7
, reg
);
139 static void rt2500usb_bbp_read(const struct rt2x00_dev
*rt2x00dev
,
140 const unsigned int word
, u8
*value
)
145 * Wait until the BBP becomes ready.
147 reg
= rt2500usb_bbp_check(rt2x00dev
);
148 if (rt2x00_get_field16(reg
, PHY_CSR8_BUSY
)) {
149 ERROR(rt2x00dev
, "PHY_CSR8 register busy. Read failed.\n");
154 * Write the request into the BBP.
157 rt2x00_set_field16(®
, PHY_CSR7_REG_ID
, word
);
158 rt2x00_set_field16(®
, PHY_CSR7_READ_CONTROL
, 1);
160 rt2500usb_register_write(rt2x00dev
, PHY_CSR7
, reg
);
163 * Wait until the BBP becomes ready.
165 reg
= rt2500usb_bbp_check(rt2x00dev
);
166 if (rt2x00_get_field16(reg
, PHY_CSR8_BUSY
)) {
167 ERROR(rt2x00dev
, "PHY_CSR8 register busy. Read failed.\n");
172 rt2500usb_register_read(rt2x00dev
, PHY_CSR7
, ®
);
173 *value
= rt2x00_get_field16(reg
, PHY_CSR7_DATA
);
176 static void rt2500usb_rf_write(const struct rt2x00_dev
*rt2x00dev
,
177 const unsigned int word
, const u32 value
)
185 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
186 rt2500usb_register_read(rt2x00dev
, PHY_CSR10
, ®
);
187 if (!rt2x00_get_field16(reg
, PHY_CSR10_RF_BUSY
))
189 udelay(REGISTER_BUSY_DELAY
);
192 ERROR(rt2x00dev
, "PHY_CSR10 register busy. Write failed.\n");
197 rt2x00_set_field16(®
, PHY_CSR9_RF_VALUE
, value
);
198 rt2500usb_register_write(rt2x00dev
, PHY_CSR9
, reg
);
201 rt2x00_set_field16(®
, PHY_CSR10_RF_VALUE
, value
>> 16);
202 rt2x00_set_field16(®
, PHY_CSR10_RF_NUMBER_OF_BITS
, 20);
203 rt2x00_set_field16(®
, PHY_CSR10_RF_IF_SELECT
, 0);
204 rt2x00_set_field16(®
, PHY_CSR10_RF_BUSY
, 1);
206 rt2500usb_register_write(rt2x00dev
, PHY_CSR10
, reg
);
207 rt2x00_rf_write(rt2x00dev
, word
, value
);
210 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
211 #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
213 static void rt2500usb_read_csr(const struct rt2x00_dev
*rt2x00dev
,
214 const unsigned int word
, u32
*data
)
216 rt2500usb_register_read(rt2x00dev
, CSR_OFFSET(word
), (u16
*) data
);
219 static void rt2500usb_write_csr(const struct rt2x00_dev
*rt2x00dev
,
220 const unsigned int word
, u32 data
)
222 rt2500usb_register_write(rt2x00dev
, CSR_OFFSET(word
), data
);
225 static const struct rt2x00debug rt2500usb_rt2x00debug
= {
226 .owner
= THIS_MODULE
,
228 .read
= rt2500usb_read_csr
,
229 .write
= rt2500usb_write_csr
,
230 .word_size
= sizeof(u16
),
231 .word_count
= CSR_REG_SIZE
/ sizeof(u16
),
234 .read
= rt2x00_eeprom_read
,
235 .write
= rt2x00_eeprom_write
,
236 .word_size
= sizeof(u16
),
237 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
240 .read
= rt2500usb_bbp_read
,
241 .write
= rt2500usb_bbp_write
,
242 .word_size
= sizeof(u8
),
243 .word_count
= BBP_SIZE
/ sizeof(u8
),
246 .read
= rt2x00_rf_read
,
247 .write
= rt2500usb_rf_write
,
248 .word_size
= sizeof(u32
),
249 .word_count
= RF_SIZE
/ sizeof(u32
),
252 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
255 * Configuration handlers.
257 static void rt2500usb_config_mac_addr(struct rt2x00_dev
*rt2x00dev
, u8
*addr
)
261 memset(®
, 0, sizeof(reg
));
262 memcpy(®
, addr
, ETH_ALEN
);
265 * The MAC address is passed to us as an array of bytes,
266 * that array is little endian, so no need for byte ordering.
268 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR2
, ®
, sizeof(reg
));
271 static void rt2500usb_config_bssid(struct rt2x00_dev
*rt2x00dev
, u8
*bssid
)
275 memset(®
, 0, sizeof(reg
));
276 memcpy(®
, bssid
, ETH_ALEN
);
279 * The BSSID is passed to us as an array of bytes,
280 * that array is little endian, so no need for byte ordering.
282 rt2500usb_register_multiwrite(rt2x00dev
, MAC_CSR5
, ®
, sizeof(reg
));
285 static void rt2500usb_config_packet_filter(struct rt2x00_dev
*rt2x00dev
,
286 const unsigned int filter
)
288 int promisc
= !!(filter
& IFF_PROMISC
);
289 int multicast
= !!(filter
& IFF_MULTICAST
);
290 int broadcast
= !!(filter
& IFF_BROADCAST
);
293 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
294 rt2x00_set_field16(®
, TXRX_CSR2_DROP_NOT_TO_ME
, !promisc
);
295 rt2x00_set_field16(®
, TXRX_CSR2_DROP_MULTICAST
, !multicast
);
296 rt2x00_set_field16(®
, TXRX_CSR2_DROP_BROADCAST
, !broadcast
);
297 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
300 static void rt2500usb_config_type(struct rt2x00_dev
*rt2x00dev
, const int type
)
304 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
307 * Apply hardware packet filter.
309 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
311 if (!is_monitor_present(&rt2x00dev
->interface
) &&
312 (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_STA
))
313 rt2x00_set_field16(®
, TXRX_CSR2_DROP_TODS
, 1);
315 rt2x00_set_field16(®
, TXRX_CSR2_DROP_TODS
, 0);
318 * If there is a non-monitor interface present
319 * the packet should be strict (even if a monitor interface is present!).
320 * When there is only 1 interface present which is in monitor mode
321 * we should start accepting _all_ frames.
323 if (is_interface_present(&rt2x00dev
->interface
)) {
324 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CRC
, 1);
325 rt2x00_set_field16(®
, TXRX_CSR2_DROP_PHYSICAL
, 1);
326 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CONTROL
, 1);
327 rt2x00_set_field16(®
, TXRX_CSR2_DROP_VERSION_ERROR
, 1);
328 } else if (is_monitor_present(&rt2x00dev
->interface
)) {
329 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CRC
, 0);
330 rt2x00_set_field16(®
, TXRX_CSR2_DROP_PHYSICAL
, 0);
331 rt2x00_set_field16(®
, TXRX_CSR2_DROP_CONTROL
, 0);
332 rt2x00_set_field16(®
, TXRX_CSR2_DROP_VERSION_ERROR
, 0);
335 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
338 * Enable beacon config
340 rt2500usb_register_read(rt2x00dev
, TXRX_CSR20
, ®
);
341 rt2x00_set_field16(®
, TXRX_CSR20_OFFSET
,
342 (PREAMBLE
+ get_duration(IEEE80211_HEADER
, 2)) >> 6);
343 if (type
== IEEE80211_IF_TYPE_STA
)
344 rt2x00_set_field16(®
, TXRX_CSR20_BCN_EXPECT_WINDOW
, 0);
346 rt2x00_set_field16(®
, TXRX_CSR20_BCN_EXPECT_WINDOW
, 2);
347 rt2500usb_register_write(rt2x00dev
, TXRX_CSR20
, reg
);
350 * Enable synchronisation.
352 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
353 rt2x00_set_field16(®
, TXRX_CSR18_OFFSET
, 0);
354 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
356 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
357 if (is_interface_present(&rt2x00dev
->interface
)) {
358 rt2x00_set_field16(®
, TXRX_CSR19_TSF_COUNT
, 1);
359 rt2x00_set_field16(®
, TXRX_CSR19_TBCN
, 1);
362 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 0);
363 if (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_AP
)
364 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 2);
365 else if (type
== IEEE80211_IF_TYPE_STA
)
366 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 1);
367 else if (is_monitor_present(&rt2x00dev
->interface
) &&
368 !is_interface_present(&rt2x00dev
->interface
))
369 rt2x00_set_field16(®
, TXRX_CSR19_TSF_SYNC
, 0);
371 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
374 static void rt2500usb_config_rate(struct rt2x00_dev
*rt2x00dev
, const int rate
)
376 struct ieee80211_conf
*conf
= &rt2x00dev
->hw
->conf
;
381 if (DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
))
382 preamble
= SHORT_PREAMBLE
;
386 reg
= DEVICE_GET_RATE_FIELD(rate
, RATEMASK
) & DEV_BASIC_RATEMASK
;
388 rt2500usb_register_write(rt2x00dev
, TXRX_CSR11
, reg
);
390 rt2500usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
391 value
= ((conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
) ?
393 PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
394 rt2x00_set_field16(®
, TXRX_CSR1_ACK_TIMEOUT
, value
);
395 rt2500usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
397 rt2500usb_register_read(rt2x00dev
, TXRX_CSR10
, ®
);
398 if (preamble
== SHORT_PREAMBLE
)
399 rt2x00_set_field16(®
, TXRX_CSR10_AUTORESPOND_PREAMBLE
, 1);
401 rt2x00_set_field16(®
, TXRX_CSR10_AUTORESPOND_PREAMBLE
, 0);
402 rt2500usb_register_write(rt2x00dev
, TXRX_CSR10
, reg
);
405 static void rt2500usb_config_phymode(struct rt2x00_dev
*rt2x00dev
,
408 struct ieee80211_hw_mode
*mode
;
409 struct ieee80211_rate
*rate
;
411 if (phymode
== MODE_IEEE80211A
)
412 rt2x00dev
->curr_hwmode
= HWMODE_A
;
413 else if (phymode
== MODE_IEEE80211B
)
414 rt2x00dev
->curr_hwmode
= HWMODE_B
;
416 rt2x00dev
->curr_hwmode
= HWMODE_G
;
418 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
419 rate
= &mode
->rates
[mode
->num_rates
- 1];
421 rt2500usb_config_rate(rt2x00dev
, rate
->val2
);
423 if (phymode
== MODE_IEEE80211B
) {
424 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x000b);
425 rt2500usb_register_write(rt2x00dev
, MAC_CSR12
, 0x0040);
427 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x0005);
428 rt2500usb_register_write(rt2x00dev
, MAC_CSR12
, 0x016c);
432 static void rt2500usb_config_channel(struct rt2x00_dev
*rt2x00dev
,
433 const int index
, const int channel
,
436 struct rf_channel reg
;
439 * Fill rf_reg structure.
441 memcpy(®
, &rt2x00dev
->spec
.channels
[index
], sizeof(reg
));
446 rt2x00_set_field32(®
.rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
449 * For RT2525E we should first set the channel to half band higher.
451 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
)) {
452 static const u32 vals
[] = {
453 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
454 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
455 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
456 0x00000902, 0x00000906
459 rt2500usb_rf_write(rt2x00dev
, 2, vals
[channel
- 1]);
461 rt2500usb_rf_write(rt2x00dev
, 4, reg
.rf4
);
464 rt2500usb_rf_write(rt2x00dev
, 1, reg
.rf1
);
465 rt2500usb_rf_write(rt2x00dev
, 2, reg
.rf2
);
466 rt2500usb_rf_write(rt2x00dev
, 3, reg
.rf3
);
468 rt2500usb_rf_write(rt2x00dev
, 4, reg
.rf4
);
471 static void rt2500usb_config_txpower(struct rt2x00_dev
*rt2x00dev
,
476 rt2x00_rf_read(rt2x00dev
, 3, &rf3
);
477 rt2x00_set_field32(&rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
478 rt2500usb_rf_write(rt2x00dev
, 3, rf3
);
481 static void rt2500usb_config_antenna(struct rt2x00_dev
*rt2x00dev
,
482 const int antenna_tx
, const int antenna_rx
)
489 rt2500usb_bbp_read(rt2x00dev
, 2, &r2
);
490 rt2500usb_bbp_read(rt2x00dev
, 14, &r14
);
491 rt2500usb_register_read(rt2x00dev
, PHY_CSR5
, &csr5
);
492 rt2500usb_register_read(rt2x00dev
, PHY_CSR6
, &csr6
);
495 * Configure the TX antenna.
497 switch (antenna_tx
) {
498 case ANTENNA_SW_DIVERSITY
:
499 case ANTENNA_HW_DIVERSITY
:
500 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 1);
501 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 1);
502 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 1);
505 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 0);
506 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 0);
507 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 0);
510 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 2);
511 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK
, 2);
512 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM
, 2);
517 * Configure the RX antenna.
519 switch (antenna_rx
) {
520 case ANTENNA_SW_DIVERSITY
:
521 case ANTENNA_HW_DIVERSITY
:
522 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 1);
525 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 0);
528 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 2);
533 * RT2525E and RT5222 need to flip TX I/Q
535 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) ||
536 rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
537 rt2x00_set_field8(&r2
, BBP_R2_TX_IQ_FLIP
, 1);
538 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 1);
539 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 1);
542 * RT2525E does not need RX I/Q Flip.
544 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
))
545 rt2x00_set_field8(&r14
, BBP_R14_RX_IQ_FLIP
, 0);
547 rt2x00_set_field16(&csr5
, PHY_CSR5_CCK_FLIP
, 0);
548 rt2x00_set_field16(&csr6
, PHY_CSR6_OFDM_FLIP
, 0);
551 rt2500usb_bbp_write(rt2x00dev
, 2, r2
);
552 rt2500usb_bbp_write(rt2x00dev
, 14, r14
);
553 rt2500usb_register_write(rt2x00dev
, PHY_CSR5
, csr5
);
554 rt2500usb_register_write(rt2x00dev
, PHY_CSR6
, csr6
);
557 static void rt2500usb_config_duration(struct rt2x00_dev
*rt2x00dev
,
558 const int short_slot_time
,
559 const int beacon_int
)
563 rt2500usb_register_write(rt2x00dev
, MAC_CSR10
,
564 short_slot_time
? SHORT_SLOT_TIME
: SLOT_TIME
);
566 rt2500usb_register_read(rt2x00dev
, TXRX_CSR18
, ®
);
567 rt2x00_set_field16(®
, TXRX_CSR18_INTERVAL
, beacon_int
* 4);
568 rt2500usb_register_write(rt2x00dev
, TXRX_CSR18
, reg
);
571 static void rt2500usb_config(struct rt2x00_dev
*rt2x00dev
,
572 const unsigned int flags
,
573 struct ieee80211_conf
*conf
)
575 int short_slot_time
= conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
;
577 if (flags
& CONFIG_UPDATE_PHYMODE
)
578 rt2500usb_config_phymode(rt2x00dev
, conf
->phymode
);
579 if (flags
& CONFIG_UPDATE_CHANNEL
)
580 rt2500usb_config_channel(rt2x00dev
, conf
->channel_val
,
581 conf
->channel
, conf
->power_level
);
582 if ((flags
& CONFIG_UPDATE_TXPOWER
) && !(flags
& CONFIG_UPDATE_CHANNEL
))
583 rt2500usb_config_txpower(rt2x00dev
, conf
->power_level
);
584 if (flags
& CONFIG_UPDATE_ANTENNA
)
585 rt2500usb_config_antenna(rt2x00dev
, conf
->antenna_sel_tx
,
586 conf
->antenna_sel_rx
);
587 if (flags
& (CONFIG_UPDATE_SLOT_TIME
| CONFIG_UPDATE_BEACON_INT
))
588 rt2500usb_config_duration(rt2x00dev
, short_slot_time
,
595 static void rt2500usb_enable_led(struct rt2x00_dev
*rt2x00dev
)
599 rt2500usb_register_read(rt2x00dev
, MAC_CSR21
, ®
);
600 rt2x00_set_field16(®
, MAC_CSR21_ON_PERIOD
, 70);
601 rt2x00_set_field16(®
, MAC_CSR21_OFF_PERIOD
, 30);
602 rt2500usb_register_write(rt2x00dev
, MAC_CSR21
, reg
);
604 rt2500usb_register_read(rt2x00dev
, MAC_CSR20
, ®
);
606 if (rt2x00dev
->led_mode
== LED_MODE_TXRX_ACTIVITY
) {
607 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 1);
608 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 0);
609 } else if (rt2x00dev
->led_mode
== LED_MODE_ASUS
) {
610 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 0);
611 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 1);
613 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 1);
614 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 1);
617 rt2500usb_register_write(rt2x00dev
, MAC_CSR20
, reg
);
620 static void rt2500usb_disable_led(struct rt2x00_dev
*rt2x00dev
)
624 rt2500usb_register_read(rt2x00dev
, MAC_CSR20
, ®
);
625 rt2x00_set_field16(®
, MAC_CSR20_LINK
, 0);
626 rt2x00_set_field16(®
, MAC_CSR20_ACTIVITY
, 0);
627 rt2500usb_register_write(rt2x00dev
, MAC_CSR20
, reg
);
633 static void rt2500usb_link_stats(struct rt2x00_dev
*rt2x00dev
)
638 * Update FCS error count from register.
640 rt2500usb_register_read(rt2x00dev
, STA_CSR0
, ®
);
641 rt2x00dev
->link
.rx_failed
= rt2x00_get_field16(reg
, STA_CSR0_FCS_ERROR
);
644 * Update False CCA count from register.
646 rt2500usb_register_read(rt2x00dev
, STA_CSR3
, ®
);
647 rt2x00dev
->link
.false_cca
=
648 rt2x00_get_field16(reg
, STA_CSR3_FALSE_CCA_ERROR
);
651 static void rt2500usb_reset_tuner(struct rt2x00_dev
*rt2x00dev
)
656 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &eeprom
);
657 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R24_LOW
);
658 rt2500usb_bbp_write(rt2x00dev
, 24, value
);
660 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &eeprom
);
661 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R25_LOW
);
662 rt2500usb_bbp_write(rt2x00dev
, 25, value
);
664 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &eeprom
);
665 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_R61_LOW
);
666 rt2500usb_bbp_write(rt2x00dev
, 61, value
);
668 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &eeprom
);
669 value
= rt2x00_get_field16(eeprom
, EEPROM_BBPTUNE_VGCUPPER
);
670 rt2500usb_bbp_write(rt2x00dev
, 17, value
);
672 rt2x00dev
->link
.vgc_level
= value
;
675 static void rt2500usb_link_tuner(struct rt2x00_dev
*rt2x00dev
)
677 int rssi
= rt2x00_get_link_rssi(&rt2x00dev
->link
);
690 * Determine the BBP tuning threshold and correctly
691 * set BBP 24, 25 and 61.
693 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE
, &bbp_thresh
);
694 bbp_thresh
= rt2x00_get_field16(bbp_thresh
, EEPROM_BBPTUNE_THRESHOLD
);
696 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &r24
);
697 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &r25
);
698 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &r61
);
700 if ((rssi
+ bbp_thresh
) > 0) {
701 r24
= rt2x00_get_field16(r24
, EEPROM_BBPTUNE_R24_HIGH
);
702 r25
= rt2x00_get_field16(r25
, EEPROM_BBPTUNE_R25_HIGH
);
703 r61
= rt2x00_get_field16(r61
, EEPROM_BBPTUNE_R61_HIGH
);
705 r24
= rt2x00_get_field16(r24
, EEPROM_BBPTUNE_R24_LOW
);
706 r25
= rt2x00_get_field16(r25
, EEPROM_BBPTUNE_R25_LOW
);
707 r61
= rt2x00_get_field16(r61
, EEPROM_BBPTUNE_R61_LOW
);
710 rt2500usb_bbp_write(rt2x00dev
, 24, r24
);
711 rt2500usb_bbp_write(rt2x00dev
, 25, r25
);
712 rt2500usb_bbp_write(rt2x00dev
, 61, r61
);
715 * Read current r17 value, as well as the sensitivity values
716 * for the r17 register.
718 rt2500usb_bbp_read(rt2x00dev
, 17, &r17
);
719 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R17
, &r17_sens
);
722 * A too low RSSI will cause too much false CCA which will
723 * then corrupt the R17 tuning. To remidy this the tuning should
724 * be stopped (While making sure the R17 value will not exceed limits)
728 rt2500usb_bbp_write(rt2x00dev
, 17, 0x60);
733 * Special big-R17 for short distance
736 sens
= rt2x00_get_field16(r17_sens
, EEPROM_BBPTUNE_R17_LOW
);
738 rt2500usb_bbp_write(rt2x00dev
, 17, sens
);
743 * Special mid-R17 for middle distance
746 sens
= rt2x00_get_field16(r17_sens
, EEPROM_BBPTUNE_R17_HIGH
);
748 rt2500usb_bbp_write(rt2x00dev
, 17, sens
);
753 * Leave short or middle distance condition, restore r17
754 * to the dynamic tuning range.
756 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &vgc_bound
);
757 vgc_bound
= rt2x00_get_field16(vgc_bound
, EEPROM_BBPTUNE_VGCUPPER
);
761 up_bound
= vgc_bound
;
763 up_bound
= vgc_bound
- (-77 - rssi
);
765 if (up_bound
< low_bound
)
766 up_bound
= low_bound
;
768 if (r17
> up_bound
) {
769 rt2500usb_bbp_write(rt2x00dev
, 17, up_bound
);
770 rt2x00dev
->link
.vgc_level
= up_bound
;
771 } else if (rt2x00dev
->link
.false_cca
> 512 && r17
< up_bound
) {
772 rt2500usb_bbp_write(rt2x00dev
, 17, ++r17
);
773 rt2x00dev
->link
.vgc_level
= r17
;
774 } else if (rt2x00dev
->link
.false_cca
< 100 && r17
> low_bound
) {
775 rt2500usb_bbp_write(rt2x00dev
, 17, --r17
);
776 rt2x00dev
->link
.vgc_level
= r17
;
781 * Initialization functions.
783 static int rt2500usb_init_registers(struct rt2x00_dev
*rt2x00dev
)
787 rt2x00usb_vendor_request_sw(rt2x00dev
, USB_DEVICE_MODE
, 0x0001,
788 USB_MODE_TEST
, REGISTER_TIMEOUT
);
789 rt2x00usb_vendor_request_sw(rt2x00dev
, USB_SINGLE_WRITE
, 0x0308,
790 0x00f0, REGISTER_TIMEOUT
);
792 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
793 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
, 1);
794 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
796 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x1111);
797 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x1e11);
799 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
800 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 1);
801 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 1);
802 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 0);
803 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
805 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
806 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 0);
807 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 0);
808 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 0);
809 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
811 rt2500usb_register_read(rt2x00dev
, TXRX_CSR5
, ®
);
812 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID0
, 13);
813 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID0_VALID
, 1);
814 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID1
, 12);
815 rt2x00_set_field16(®
, TXRX_CSR5_BBP_ID1_VALID
, 1);
816 rt2500usb_register_write(rt2x00dev
, TXRX_CSR5
, reg
);
818 rt2500usb_register_read(rt2x00dev
, TXRX_CSR6
, ®
);
819 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID0
, 10);
820 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID0_VALID
, 1);
821 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID1
, 11);
822 rt2x00_set_field16(®
, TXRX_CSR6_BBP_ID1_VALID
, 1);
823 rt2500usb_register_write(rt2x00dev
, TXRX_CSR6
, reg
);
825 rt2500usb_register_read(rt2x00dev
, TXRX_CSR7
, ®
);
826 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID0
, 7);
827 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID0_VALID
, 1);
828 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID1
, 6);
829 rt2x00_set_field16(®
, TXRX_CSR7_BBP_ID1_VALID
, 1);
830 rt2500usb_register_write(rt2x00dev
, TXRX_CSR7
, reg
);
832 rt2500usb_register_read(rt2x00dev
, TXRX_CSR8
, ®
);
833 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID0
, 5);
834 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID0_VALID
, 1);
835 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID1
, 0);
836 rt2x00_set_field16(®
, TXRX_CSR8_BBP_ID1_VALID
, 0);
837 rt2500usb_register_write(rt2x00dev
, TXRX_CSR8
, reg
);
839 rt2500usb_register_write(rt2x00dev
, TXRX_CSR21
, 0xe78f);
840 rt2500usb_register_write(rt2x00dev
, MAC_CSR9
, 0xff1d);
842 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
845 rt2500usb_register_read(rt2x00dev
, MAC_CSR1
, ®
);
846 rt2x00_set_field16(®
, MAC_CSR1_SOFT_RESET
, 0);
847 rt2x00_set_field16(®
, MAC_CSR1_BBP_RESET
, 0);
848 rt2x00_set_field16(®
, MAC_CSR1_HOST_READY
, 1);
849 rt2500usb_register_write(rt2x00dev
, MAC_CSR1
, reg
);
851 if (rt2x00_get_rev(&rt2x00dev
->chip
) >= RT2570_VERSION_C
) {
852 rt2500usb_register_read(rt2x00dev
, PHY_CSR2
, ®
);
857 rt2500usb_register_write(rt2x00dev
, PHY_CSR2
, reg
);
859 rt2500usb_register_write(rt2x00dev
, MAC_CSR11
, 0x0002);
860 rt2500usb_register_write(rt2x00dev
, MAC_CSR22
, 0x0053);
861 rt2500usb_register_write(rt2x00dev
, MAC_CSR15
, 0x01ee);
862 rt2500usb_register_write(rt2x00dev
, MAC_CSR16
, 0x0000);
864 rt2500usb_register_read(rt2x00dev
, MAC_CSR8
, ®
);
865 rt2x00_set_field16(®
, MAC_CSR8_MAX_FRAME_UNIT
,
866 rt2x00dev
->rx
->data_size
);
867 rt2500usb_register_write(rt2x00dev
, MAC_CSR8
, reg
);
869 rt2500usb_register_read(rt2x00dev
, TXRX_CSR0
, ®
);
870 rt2x00_set_field16(®
, TXRX_CSR0_IV_OFFSET
, IEEE80211_HEADER
);
871 rt2x00_set_field16(®
, TXRX_CSR0_KEY_ID
, 0xff);
872 rt2500usb_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
874 rt2500usb_register_read(rt2x00dev
, MAC_CSR18
, ®
);
875 rt2x00_set_field16(®
, MAC_CSR18_DELAY_AFTER_BEACON
, 90);
876 rt2500usb_register_write(rt2x00dev
, MAC_CSR18
, reg
);
878 rt2500usb_register_read(rt2x00dev
, PHY_CSR4
, ®
);
879 rt2x00_set_field16(®
, PHY_CSR4_LOW_RF_LE
, 1);
880 rt2500usb_register_write(rt2x00dev
, PHY_CSR4
, reg
);
882 rt2500usb_register_read(rt2x00dev
, TXRX_CSR1
, ®
);
883 rt2x00_set_field16(®
, TXRX_CSR1_AUTO_SEQUENCE
, 1);
884 rt2500usb_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
889 static int rt2500usb_init_bbp(struct rt2x00_dev
*rt2x00dev
)
896 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
897 rt2500usb_bbp_read(rt2x00dev
, 0, &value
);
898 if ((value
!= 0xff) && (value
!= 0x00))
899 goto continue_csr_init
;
900 NOTICE(rt2x00dev
, "Waiting for BBP register.\n");
901 udelay(REGISTER_BUSY_DELAY
);
904 ERROR(rt2x00dev
, "BBP register access failed, aborting.\n");
908 rt2500usb_bbp_write(rt2x00dev
, 3, 0x02);
909 rt2500usb_bbp_write(rt2x00dev
, 4, 0x19);
910 rt2500usb_bbp_write(rt2x00dev
, 14, 0x1c);
911 rt2500usb_bbp_write(rt2x00dev
, 15, 0x30);
912 rt2500usb_bbp_write(rt2x00dev
, 16, 0xac);
913 rt2500usb_bbp_write(rt2x00dev
, 18, 0x18);
914 rt2500usb_bbp_write(rt2x00dev
, 19, 0xff);
915 rt2500usb_bbp_write(rt2x00dev
, 20, 0x1e);
916 rt2500usb_bbp_write(rt2x00dev
, 21, 0x08);
917 rt2500usb_bbp_write(rt2x00dev
, 22, 0x08);
918 rt2500usb_bbp_write(rt2x00dev
, 23, 0x08);
919 rt2500usb_bbp_write(rt2x00dev
, 24, 0x80);
920 rt2500usb_bbp_write(rt2x00dev
, 25, 0x50);
921 rt2500usb_bbp_write(rt2x00dev
, 26, 0x08);
922 rt2500usb_bbp_write(rt2x00dev
, 27, 0x23);
923 rt2500usb_bbp_write(rt2x00dev
, 30, 0x10);
924 rt2500usb_bbp_write(rt2x00dev
, 31, 0x2b);
925 rt2500usb_bbp_write(rt2x00dev
, 32, 0xb9);
926 rt2500usb_bbp_write(rt2x00dev
, 34, 0x12);
927 rt2500usb_bbp_write(rt2x00dev
, 35, 0x50);
928 rt2500usb_bbp_write(rt2x00dev
, 39, 0xc4);
929 rt2500usb_bbp_write(rt2x00dev
, 40, 0x02);
930 rt2500usb_bbp_write(rt2x00dev
, 41, 0x60);
931 rt2500usb_bbp_write(rt2x00dev
, 53, 0x10);
932 rt2500usb_bbp_write(rt2x00dev
, 54, 0x18);
933 rt2500usb_bbp_write(rt2x00dev
, 56, 0x08);
934 rt2500usb_bbp_write(rt2x00dev
, 57, 0x10);
935 rt2500usb_bbp_write(rt2x00dev
, 58, 0x08);
936 rt2500usb_bbp_write(rt2x00dev
, 61, 0x60);
937 rt2500usb_bbp_write(rt2x00dev
, 62, 0x10);
938 rt2500usb_bbp_write(rt2x00dev
, 75, 0xff);
940 DEBUG(rt2x00dev
, "Start initialization from EEPROM...\n");
941 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
942 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
944 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
945 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
946 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
947 DEBUG(rt2x00dev
, "BBP: 0x%02x, value: 0x%02x.\n",
949 rt2500usb_bbp_write(rt2x00dev
, reg_id
, value
);
952 DEBUG(rt2x00dev
, "...End initialization from EEPROM.\n");
958 * Device state switch handlers.
960 static void rt2500usb_toggle_rx(struct rt2x00_dev
*rt2x00dev
,
961 enum dev_state state
)
965 rt2500usb_register_read(rt2x00dev
, TXRX_CSR2
, ®
);
966 rt2x00_set_field16(®
, TXRX_CSR2_DISABLE_RX
,
967 state
== STATE_RADIO_RX_OFF
);
968 rt2500usb_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
971 static int rt2500usb_enable_radio(struct rt2x00_dev
*rt2x00dev
)
974 * Initialize all registers.
976 if (rt2500usb_init_registers(rt2x00dev
) ||
977 rt2500usb_init_bbp(rt2x00dev
)) {
978 ERROR(rt2x00dev
, "Register initialization failed.\n");
982 rt2x00usb_enable_radio(rt2x00dev
);
987 rt2500usb_enable_led(rt2x00dev
);
992 static void rt2500usb_disable_radio(struct rt2x00_dev
*rt2x00dev
)
997 rt2500usb_disable_led(rt2x00dev
);
999 rt2500usb_register_write(rt2x00dev
, MAC_CSR13
, 0x2121);
1000 rt2500usb_register_write(rt2x00dev
, MAC_CSR14
, 0x2121);
1003 * Disable synchronisation.
1005 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
1007 rt2x00usb_disable_radio(rt2x00dev
);
1010 static int rt2500usb_set_state(struct rt2x00_dev
*rt2x00dev
,
1011 enum dev_state state
)
1020 put_to_sleep
= (state
!= STATE_AWAKE
);
1023 rt2x00_set_field16(®
, MAC_CSR17_BBP_DESIRE_STATE
, state
);
1024 rt2x00_set_field16(®
, MAC_CSR17_RF_DESIRE_STATE
, state
);
1025 rt2x00_set_field16(®
, MAC_CSR17_PUT_TO_SLEEP
, put_to_sleep
);
1026 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1027 rt2x00_set_field16(®
, MAC_CSR17_SET_STATE
, 1);
1028 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1031 * Device is not guaranteed to be in the requested state yet.
1032 * We must wait until the register indicates that the
1033 * device has entered the correct state.
1035 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1036 rt2500usb_register_read(rt2x00dev
, MAC_CSR17
, ®2
);
1037 bbp_state
= rt2x00_get_field16(reg2
, MAC_CSR17_BBP_CURR_STATE
);
1038 rf_state
= rt2x00_get_field16(reg2
, MAC_CSR17_RF_CURR_STATE
);
1039 if (bbp_state
== state
&& rf_state
== state
)
1041 rt2500usb_register_write(rt2x00dev
, MAC_CSR17
, reg
);
1045 NOTICE(rt2x00dev
, "Device failed to enter state %d, "
1046 "current device state: bbp %d and rf %d.\n",
1047 state
, bbp_state
, rf_state
);
1052 static int rt2500usb_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1053 enum dev_state state
)
1058 case STATE_RADIO_ON
:
1059 retval
= rt2500usb_enable_radio(rt2x00dev
);
1061 case STATE_RADIO_OFF
:
1062 rt2500usb_disable_radio(rt2x00dev
);
1064 case STATE_RADIO_RX_ON
:
1065 case STATE_RADIO_RX_OFF
:
1066 rt2500usb_toggle_rx(rt2x00dev
, state
);
1068 case STATE_DEEP_SLEEP
:
1072 retval
= rt2500usb_set_state(rt2x00dev
, state
);
1083 * TX descriptor initialization
1085 static void rt2500usb_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
1086 struct data_desc
*txd
,
1087 struct data_entry_desc
*desc
,
1088 struct ieee80211_hdr
*ieee80211hdr
,
1089 unsigned int length
,
1090 struct ieee80211_tx_control
*control
)
1095 * Start writing the descriptor words.
1097 rt2x00_desc_read(txd
, 1, &word
);
1098 rt2x00_set_field32(&word
, TXD_W1_IV_OFFSET
, IEEE80211_HEADER
);
1099 rt2x00_set_field32(&word
, TXD_W1_AIFS
, desc
->aifs
);
1100 rt2x00_set_field32(&word
, TXD_W1_CWMIN
, desc
->cw_min
);
1101 rt2x00_set_field32(&word
, TXD_W1_CWMAX
, desc
->cw_max
);
1102 rt2x00_desc_write(txd
, 1, word
);
1104 rt2x00_desc_read(txd
, 2, &word
);
1105 rt2x00_set_field32(&word
, TXD_W2_PLCP_SIGNAL
, desc
->signal
);
1106 rt2x00_set_field32(&word
, TXD_W2_PLCP_SERVICE
, desc
->service
);
1107 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_LOW
, desc
->length_low
);
1108 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_HIGH
, desc
->length_high
);
1109 rt2x00_desc_write(txd
, 2, word
);
1111 rt2x00_desc_read(txd
, 0, &word
);
1112 rt2x00_set_field32(&word
, TXD_W0_RETRY_LIMIT
, control
->retry_limit
);
1113 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1114 test_bit(ENTRY_TXD_MORE_FRAG
, &desc
->flags
));
1115 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1116 !(control
->flags
& IEEE80211_TXCTL_NO_ACK
));
1117 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1118 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &desc
->flags
));
1119 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1120 test_bit(ENTRY_TXD_OFDM_RATE
, &desc
->flags
));
1121 rt2x00_set_field32(&word
, TXD_W0_NEW_SEQ
,
1122 !!(control
->flags
& IEEE80211_TXCTL_FIRST_FRAGMENT
));
1123 rt2x00_set_field32(&word
, TXD_W0_IFS
, desc
->ifs
);
1124 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, length
);
1125 rt2x00_set_field32(&word
, TXD_W0_CIPHER
, CIPHER_NONE
);
1126 rt2x00_desc_write(txd
, 0, word
);
1130 * TX data initialization
1132 static void rt2500usb_kick_tx_queue(struct rt2x00_dev
*rt2x00dev
,
1137 if (queue
!= IEEE80211_TX_QUEUE_BEACON
)
1140 rt2500usb_register_read(rt2x00dev
, TXRX_CSR19
, ®
);
1141 if (!rt2x00_get_field16(reg
, TXRX_CSR19_BEACON_GEN
)) {
1142 rt2x00_set_field16(®
, TXRX_CSR19_BEACON_GEN
, 1);
1144 * Beacon generation will fail initially.
1145 * To prevent this we need to register the TXRX_CSR19
1146 * register several times.
1148 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1149 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
1150 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1151 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, 0);
1152 rt2500usb_register_write(rt2x00dev
, TXRX_CSR19
, reg
);
1157 * RX control handlers
1159 static int rt2500usb_fill_rxdone(struct data_entry
*entry
,
1160 int *signal
, int *rssi
, int *ofdm
, int *size
)
1162 struct urb
*urb
= entry
->priv
;
1163 struct data_desc
*rxd
= (struct data_desc
*)(entry
->skb
->data
+
1164 (urb
->actual_length
-
1165 entry
->ring
->desc_size
));
1169 rt2x00_desc_read(rxd
, 0, &word0
);
1170 rt2x00_desc_read(rxd
, 1, &word1
);
1172 if (rt2x00_get_field32(word0
, RXD_W0_CRC_ERROR
) ||
1173 rt2x00_get_field32(word0
, RXD_W0_PHYSICAL_ERROR
) ||
1174 rt2x00_get_field32(word0
, RXD_W0_CIPHER_ERROR
))
1178 * Obtain the status about this packet.
1180 *signal
= rt2x00_get_field32(word1
, RXD_W1_SIGNAL
);
1181 *rssi
= rt2x00_get_field32(word1
, RXD_W1_RSSI
) -
1182 entry
->ring
->rt2x00dev
->rssi_offset
;
1183 *ofdm
= rt2x00_get_field32(word0
, RXD_W0_OFDM
);
1184 *size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
1190 * Interrupt functions.
1192 static void rt2500usb_beacondone(struct urb
*urb
)
1194 struct data_entry
*entry
= (struct data_entry
*)urb
->context
;
1195 struct data_ring
*ring
= entry
->ring
;
1197 if (!test_bit(DEVICE_ENABLED_RADIO
, &ring
->rt2x00dev
->flags
))
1201 * Check if this was the guardian beacon,
1202 * if that was the case we need to send the real beacon now.
1203 * Otherwise we should free the sk_buffer, the device
1204 * should be doing the rest of the work now.
1206 if (ring
->index
== 1) {
1207 rt2x00_ring_index_done_inc(ring
);
1208 entry
= rt2x00_get_data_entry(ring
);
1209 usb_submit_urb(entry
->priv
, GFP_ATOMIC
);
1210 rt2x00_ring_index_inc(ring
);
1211 } else if (ring
->index_done
== 1) {
1212 entry
= rt2x00_get_data_entry_done(ring
);
1214 dev_kfree_skb(entry
->skb
);
1217 rt2x00_ring_index_done_inc(ring
);
1222 * Device probe functions.
1224 static int rt2500usb_validate_eeprom(struct rt2x00_dev
*rt2x00dev
)
1229 rt2x00usb_eeprom_read(rt2x00dev
, rt2x00dev
->eeprom
, EEPROM_SIZE
);
1232 * Start validation of the data that has been read.
1234 mac
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1235 if (!is_valid_ether_addr(mac
)) {
1236 DECLARE_MAC_BUF(macbuf
);
1238 random_ether_addr(mac
);
1239 EEPROM(rt2x00dev
, "MAC: %s\n", print_mac(macbuf
, mac
));
1242 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1243 if (word
== 0xffff) {
1244 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
1245 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
, 0);
1246 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
, 0);
1247 rt2x00_set_field16(&word
, EEPROM_ANTENNA_LED_MODE
, 0);
1248 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
1249 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
1250 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF2522
);
1251 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
1252 EEPROM(rt2x00dev
, "Antenna: 0x%04x\n", word
);
1255 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &word
);
1256 if (word
== 0xffff) {
1257 rt2x00_set_field16(&word
, EEPROM_NIC_CARDBUS_ACCEL
, 0);
1258 rt2x00_set_field16(&word
, EEPROM_NIC_DYN_BBP_TUNE
, 0);
1259 rt2x00_set_field16(&word
, EEPROM_NIC_CCK_TX_POWER
, 0);
1260 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
1261 EEPROM(rt2x00dev
, "NIC: 0x%04x\n", word
);
1264 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &word
);
1265 if (word
== 0xffff) {
1266 rt2x00_set_field16(&word
, EEPROM_CALIBRATE_OFFSET_RSSI
,
1267 DEFAULT_RSSI_OFFSET
);
1268 rt2x00_eeprom_write(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, word
);
1269 EEPROM(rt2x00dev
, "Calibrate offset: 0x%04x\n", word
);
1272 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE
, &word
);
1273 if (word
== 0xffff) {
1274 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_THRESHOLD
, 45);
1275 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE
, word
);
1276 EEPROM(rt2x00dev
, "BBPtune: 0x%04x\n", word
);
1279 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_VGC
, &word
);
1280 if (word
== 0xffff) {
1281 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_VGCUPPER
, 0x40);
1282 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_VGC
, word
);
1283 EEPROM(rt2x00dev
, "BBPtune vgc: 0x%04x\n", word
);
1286 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R17
, &word
);
1287 if (word
== 0xffff) {
1288 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_LOW
, 0x48);
1289 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R17_HIGH
, 0x41);
1290 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R17
, word
);
1291 EEPROM(rt2x00dev
, "BBPtune r17: 0x%04x\n", word
);
1294 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R24
, &word
);
1295 if (word
== 0xffff) {
1296 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_LOW
, 0x40);
1297 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R24_HIGH
, 0x80);
1298 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R24
, word
);
1299 EEPROM(rt2x00dev
, "BBPtune r24: 0x%04x\n", word
);
1302 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R25
, &word
);
1303 if (word
== 0xffff) {
1304 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_LOW
, 0x40);
1305 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R25_HIGH
, 0x50);
1306 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R25
, word
);
1307 EEPROM(rt2x00dev
, "BBPtune r25: 0x%04x\n", word
);
1310 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBPTUNE_R61
, &word
);
1311 if (word
== 0xffff) {
1312 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_LOW
, 0x60);
1313 rt2x00_set_field16(&word
, EEPROM_BBPTUNE_R61_HIGH
, 0x6d);
1314 rt2x00_eeprom_write(rt2x00dev
, EEPROM_BBPTUNE_R61
, word
);
1315 EEPROM(rt2x00dev
, "BBPtune r61: 0x%04x\n", word
);
1321 static int rt2500usb_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1328 * Read EEPROM word for configuration.
1330 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1333 * Identify RF chipset.
1335 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1336 rt2500usb_register_read(rt2x00dev
, MAC_CSR0
, ®
);
1337 rt2x00_set_chip(rt2x00dev
, RT2570
, value
, reg
);
1339 if (rt2x00_rev(&rt2x00dev
->chip
, 0xffff0)) {
1340 ERROR(rt2x00dev
, "Invalid RT chipset detected.\n");
1344 if (!rt2x00_rf(&rt2x00dev
->chip
, RF2522
) &&
1345 !rt2x00_rf(&rt2x00dev
->chip
, RF2523
) &&
1346 !rt2x00_rf(&rt2x00dev
->chip
, RF2524
) &&
1347 !rt2x00_rf(&rt2x00dev
->chip
, RF2525
) &&
1348 !rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) &&
1349 !rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
1350 ERROR(rt2x00dev
, "Invalid RF chipset detected.\n");
1355 * Identify default antenna configuration.
1357 rt2x00dev
->hw
->conf
.antenna_sel_tx
=
1358 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_TX_DEFAULT
);
1359 rt2x00dev
->hw
->conf
.antenna_sel_rx
=
1360 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RX_DEFAULT
);
1363 * Store led mode, for correct led behaviour.
1365 rt2x00dev
->led_mode
=
1366 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_LED_MODE
);
1369 * Check if the BBP tuning should be disabled.
1371 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &eeprom
);
1372 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_DYN_BBP_TUNE
))
1373 __set_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
);
1376 * Read the RSSI <-> dBm offset information.
1378 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &eeprom
);
1379 rt2x00dev
->rssi_offset
=
1380 rt2x00_get_field16(eeprom
, EEPROM_CALIBRATE_OFFSET_RSSI
);
1386 * RF value list for RF2522
1389 static const struct rf_channel rf_vals_bg_2522
[] = {
1390 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1391 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1392 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1393 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1394 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1395 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1396 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1397 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1398 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1399 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1400 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1401 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1402 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1403 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1407 * RF value list for RF2523
1410 static const struct rf_channel rf_vals_bg_2523
[] = {
1411 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1412 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1413 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1414 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1415 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1416 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1417 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1418 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1419 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1420 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1421 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1422 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1423 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1424 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1428 * RF value list for RF2524
1431 static const struct rf_channel rf_vals_bg_2524
[] = {
1432 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1433 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1434 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1435 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1436 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1437 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1438 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1439 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1440 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1441 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1442 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1443 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1444 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1445 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1449 * RF value list for RF2525
1452 static const struct rf_channel rf_vals_bg_2525
[] = {
1453 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1454 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1455 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1456 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1457 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1458 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1459 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1460 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1461 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1462 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1463 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1464 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1465 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1466 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1470 * RF value list for RF2525e
1473 static const struct rf_channel rf_vals_bg_2525e
[] = {
1474 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1475 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1476 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1477 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1478 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1479 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1480 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1481 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1482 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1483 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1484 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1485 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1486 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1487 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1491 * RF value list for RF5222
1492 * Supports: 2.4 GHz & 5.2 GHz
1494 static const struct rf_channel rf_vals_5222
[] = {
1495 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1496 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1497 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1498 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1499 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1500 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1501 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1502 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1503 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1504 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1505 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1506 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1507 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1508 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1510 /* 802.11 UNI / HyperLan 2 */
1511 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1512 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1513 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1514 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1515 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1516 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1517 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1518 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1520 /* 802.11 HyperLan 2 */
1521 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1522 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1523 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1524 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1525 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1526 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1527 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1528 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1529 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1530 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1533 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1534 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1535 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1536 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1537 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1540 static void rt2500usb_probe_hw_mode(struct rt2x00_dev
*rt2x00dev
)
1542 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1547 * Initialize all hw fields.
1549 rt2x00dev
->hw
->flags
=
1550 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
|
1551 IEEE80211_HW_RX_INCLUDES_FCS
|
1552 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
1553 IEEE80211_HW_MONITOR_DURING_OPER
|
1554 IEEE80211_HW_NO_PROBE_FILTERING
;
1555 rt2x00dev
->hw
->extra_tx_headroom
= TXD_DESC_SIZE
;
1556 rt2x00dev
->hw
->max_signal
= MAX_SIGNAL
;
1557 rt2x00dev
->hw
->max_rssi
= MAX_RX_SSI
;
1558 rt2x00dev
->hw
->queues
= 2;
1560 SET_IEEE80211_DEV(rt2x00dev
->hw
, &rt2x00dev_usb(rt2x00dev
)->dev
);
1561 SET_IEEE80211_PERM_ADDR(rt2x00dev
->hw
,
1562 rt2x00_eeprom_addr(rt2x00dev
,
1563 EEPROM_MAC_ADDR_0
));
1566 * Convert tx_power array in eeprom.
1568 txpower
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_START
);
1569 for (i
= 0; i
< 14; i
++)
1570 txpower
[i
] = TXPOWER_FROM_DEV(txpower
[i
]);
1573 * Initialize hw_mode information.
1575 spec
->num_modes
= 2;
1576 spec
->num_rates
= 12;
1577 spec
->tx_power_a
= NULL
;
1578 spec
->tx_power_bg
= txpower
;
1579 spec
->tx_power_default
= DEFAULT_TXPOWER
;
1581 if (rt2x00_rf(&rt2x00dev
->chip
, RF2522
)) {
1582 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2522
);
1583 spec
->channels
= rf_vals_bg_2522
;
1584 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF2523
)) {
1585 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2523
);
1586 spec
->channels
= rf_vals_bg_2523
;
1587 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF2524
)) {
1588 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2524
);
1589 spec
->channels
= rf_vals_bg_2524
;
1590 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF2525
)) {
1591 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2525
);
1592 spec
->channels
= rf_vals_bg_2525
;
1593 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
)) {
1594 spec
->num_channels
= ARRAY_SIZE(rf_vals_bg_2525e
);
1595 spec
->channels
= rf_vals_bg_2525e
;
1596 } else if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
1597 spec
->num_channels
= ARRAY_SIZE(rf_vals_5222
);
1598 spec
->channels
= rf_vals_5222
;
1599 spec
->num_modes
= 3;
1603 static int rt2500usb_probe_hw(struct rt2x00_dev
*rt2x00dev
)
1608 * Allocate eeprom data.
1610 retval
= rt2500usb_validate_eeprom(rt2x00dev
);
1614 retval
= rt2500usb_init_eeprom(rt2x00dev
);
1619 * Initialize hw specifications.
1621 rt2500usb_probe_hw_mode(rt2x00dev
);
1624 * USB devices require scheduled packet filter toggling
1625 *This device requires the beacon ring
1627 __set_bit(PACKET_FILTER_SCHEDULED
, &rt2x00dev
->flags
);
1628 __set_bit(REQUIRE_BEACON_RING
, &rt2x00dev
->flags
);
1631 * Set the rssi offset.
1633 rt2x00dev
->rssi_offset
= DEFAULT_RSSI_OFFSET
;
1639 * IEEE80211 stack callback functions.
1641 static int rt2500usb_beacon_update(struct ieee80211_hw
*hw
,
1642 struct sk_buff
*skb
,
1643 struct ieee80211_tx_control
*control
)
1645 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1646 struct usb_device
*usb_dev
=
1647 interface_to_usbdev(rt2x00dev_usb(rt2x00dev
));
1648 struct data_ring
*ring
=
1649 rt2x00lib_get_ring(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
1650 struct data_entry
*beacon
;
1651 struct data_entry
*guardian
;
1655 * Just in case the ieee80211 doesn't set this,
1656 * but we need this queue set for the descriptor
1659 control
->queue
= IEEE80211_TX_QUEUE_BEACON
;
1662 * Obtain 2 entries, one for the guardian byte,
1663 * the second for the actual beacon.
1665 guardian
= rt2x00_get_data_entry(ring
);
1666 rt2x00_ring_index_inc(ring
);
1667 beacon
= rt2x00_get_data_entry(ring
);
1670 * First we create the beacon.
1672 skb_push(skb
, ring
->desc_size
);
1673 rt2x00lib_write_tx_desc(rt2x00dev
, (struct data_desc
*)skb
->data
,
1674 (struct ieee80211_hdr
*)(skb
->data
+
1676 skb
->len
- ring
->desc_size
, control
);
1679 * Length passed to usb_fill_urb cannot be an odd number,
1680 * so add 1 byte to make it even.
1686 usb_fill_bulk_urb(beacon
->priv
, usb_dev
,
1687 usb_sndbulkpipe(usb_dev
, 1),
1688 skb
->data
, length
, rt2500usb_beacondone
, beacon
);
1693 * Second we need to create the guardian byte.
1694 * We only need a single byte, so lets recycle
1695 * the 'flags' field we are not using for beacons.
1697 guardian
->flags
= 0;
1698 usb_fill_bulk_urb(guardian
->priv
, usb_dev
,
1699 usb_sndbulkpipe(usb_dev
, 1),
1700 &guardian
->flags
, 1, rt2500usb_beacondone
, guardian
);
1703 * Send out the guardian byte.
1705 usb_submit_urb(guardian
->priv
, GFP_ATOMIC
);
1708 * Enable beacon generation.
1710 rt2500usb_kick_tx_queue(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
1715 static const struct ieee80211_ops rt2500usb_mac80211_ops
= {
1717 .add_interface
= rt2x00mac_add_interface
,
1718 .remove_interface
= rt2x00mac_remove_interface
,
1719 .config
= rt2x00mac_config
,
1720 .config_interface
= rt2x00mac_config_interface
,
1721 .set_multicast_list
= rt2x00mac_set_multicast_list
,
1722 .get_stats
= rt2x00mac_get_stats
,
1723 .conf_tx
= rt2x00mac_conf_tx
,
1724 .get_tx_stats
= rt2x00mac_get_tx_stats
,
1725 .beacon_update
= rt2500usb_beacon_update
,
1728 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops
= {
1729 .probe_hw
= rt2500usb_probe_hw
,
1730 .initialize
= rt2x00usb_initialize
,
1731 .uninitialize
= rt2x00usb_uninitialize
,
1732 .set_device_state
= rt2500usb_set_device_state
,
1733 .link_stats
= rt2500usb_link_stats
,
1734 .reset_tuner
= rt2500usb_reset_tuner
,
1735 .link_tuner
= rt2500usb_link_tuner
,
1736 .write_tx_desc
= rt2500usb_write_tx_desc
,
1737 .write_tx_data
= rt2x00usb_write_tx_data
,
1738 .kick_tx_queue
= rt2500usb_kick_tx_queue
,
1739 .fill_rxdone
= rt2500usb_fill_rxdone
,
1740 .config_mac_addr
= rt2500usb_config_mac_addr
,
1741 .config_bssid
= rt2500usb_config_bssid
,
1742 .config_packet_filter
= rt2500usb_config_packet_filter
,
1743 .config_type
= rt2500usb_config_type
,
1744 .config
= rt2500usb_config
,
1747 static const struct rt2x00_ops rt2500usb_ops
= {
1749 .rxd_size
= RXD_DESC_SIZE
,
1750 .txd_size
= TXD_DESC_SIZE
,
1751 .eeprom_size
= EEPROM_SIZE
,
1753 .lib
= &rt2500usb_rt2x00_ops
,
1754 .hw
= &rt2500usb_mac80211_ops
,
1755 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1756 .debugfs
= &rt2500usb_rt2x00debug
,
1757 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1761 * rt2500usb module information.
1763 static struct usb_device_id rt2500usb_device_table
[] = {
1765 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops
) },
1766 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops
) },
1768 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops
) },
1769 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops
) },
1770 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops
) },
1772 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops
) },
1773 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops
) },
1774 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops
) },
1776 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops
) },
1778 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops
) },
1780 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops
) },
1781 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops
) },
1783 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops
) },
1785 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops
) },
1786 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops
) },
1787 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops
) },
1788 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops
) },
1791 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops
) },
1792 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops
) },
1793 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops
) },
1795 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops
) },
1796 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops
) },
1797 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops
) },
1798 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops
) },
1800 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops
) },
1802 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops
) },
1804 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops
) },
1806 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops
) },
1808 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops
) },
1812 MODULE_AUTHOR(DRV_PROJECT
);
1813 MODULE_VERSION(DRV_VERSION
);
1814 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1815 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1816 MODULE_DEVICE_TABLE(usb
, rt2500usb_device_table
);
1817 MODULE_LICENSE("GPL");
1819 static struct usb_driver rt2500usb_driver
= {
1821 .id_table
= rt2500usb_device_table
,
1822 .probe
= rt2x00usb_probe
,
1823 .disconnect
= rt2x00usb_disconnect
,
1824 .suspend
= rt2x00usb_suspend
,
1825 .resume
= rt2x00usb_resume
,
1828 static int __init
rt2500usb_init(void)
1830 return usb_register(&rt2500usb_driver
);
1833 static void __exit
rt2500usb_exit(void)
1835 usb_deregister(&rt2500usb_driver
);
1838 module_init(rt2500usb_init
);
1839 module_exit(rt2500usb_exit
);