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.
55 * If the usb_cache_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,
65 ®, sizeof(u16), REGISTER_TIMEOUT);
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(u16), 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 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
85 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
86 USB_VENDOR_REQUEST_IN, offset,
87 value, length, timeout);
90 static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
91 const unsigned int offset,
94 __le16 reg = cpu_to_le16(value);
95 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
96 USB_VENDOR_REQUEST_OUT, offset,
97 ®, sizeof(u16), REGISTER_TIMEOUT);
100 static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
101 const unsigned int offset,
104 __le16 reg = cpu_to_le16(value);
105 rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
106 USB_VENDOR_REQUEST_OUT, offset,
107 ®, sizeof(u16), REGISTER_TIMEOUT);
110 static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
111 const unsigned int offset,
112 void *value, const u16 length)
114 int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
115 rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
116 USB_VENDOR_REQUEST_OUT, offset,
117 value, length, timeout);
120 static u16 rt2500usb_bbp_check(struct rt2x00_dev *rt2x00dev)
125 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
126 rt2500usb_register_read_lock(rt2x00dev, PHY_CSR8, ®);
127 if (!rt2x00_get_field16(reg, PHY_CSR8_BUSY))
129 udelay(REGISTER_BUSY_DELAY);
135 static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
136 const unsigned int word, const u8 value)
140 mutex_lock(&rt2x00dev->usb_cache_mutex);
143 * Wait until the BBP becomes ready.
145 reg = rt2500usb_bbp_check(rt2x00dev);
146 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
147 ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n");
148 mutex_unlock(&rt2x00dev->usb_cache_mutex);
153 * Write the data into the BBP.
156 rt2x00_set_field16(®, PHY_CSR7_DATA, value);
157 rt2x00_set_field16(®, PHY_CSR7_REG_ID, word);
158 rt2x00_set_field16(®, PHY_CSR7_READ_CONTROL, 0);
160 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
162 mutex_unlock(&rt2x00dev->usb_cache_mutex);
165 static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
166 const unsigned int word, u8 *value)
170 mutex_lock(&rt2x00dev->usb_cache_mutex);
173 * Wait until the BBP becomes ready.
175 reg = rt2500usb_bbp_check(rt2x00dev);
176 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
177 ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
182 * Write the request into the BBP.
185 rt2x00_set_field16(®, PHY_CSR7_REG_ID, word);
186 rt2x00_set_field16(®, PHY_CSR7_READ_CONTROL, 1);
188 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
191 * Wait until the BBP becomes ready.
193 reg = rt2500usb_bbp_check(rt2x00dev);
194 if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
195 ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
197 mutex_unlock(&rt2x00dev->usb_cache_mutex);
201 rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, ®);
202 *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
204 mutex_unlock(&rt2x00dev->usb_cache_mutex);
207 static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
208 const unsigned int word, const u32 value)
216 mutex_lock(&rt2x00dev->usb_cache_mutex);
218 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
219 rt2500usb_register_read_lock(rt2x00dev, PHY_CSR10, ®);
220 if (!rt2x00_get_field16(reg, PHY_CSR10_RF_BUSY))
222 udelay(REGISTER_BUSY_DELAY);
225 mutex_unlock(&rt2x00dev->usb_cache_mutex);
226 ERROR(rt2x00dev, "PHY_CSR10 register busy. Write failed.\n");
231 rt2x00_set_field16(®, PHY_CSR9_RF_VALUE, value);
232 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
235 rt2x00_set_field16(®, PHY_CSR10_RF_VALUE, value >> 16);
236 rt2x00_set_field16(®, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
237 rt2x00_set_field16(®, PHY_CSR10_RF_IF_SELECT, 0);
238 rt2x00_set_field16(®, PHY_CSR10_RF_BUSY, 1);
240 rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
241 rt2x00_rf_write(rt2x00dev, word, value);
243 mutex_unlock(&rt2x00dev->usb_cache_mutex);
246 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
247 #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
249 static void rt2500usb_read_csr(struct rt2x00_dev *rt2x00dev,
250 const unsigned int word, u32 *data)
252 rt2500usb_register_read(rt2x00dev, CSR_OFFSET(word), (u16 *) data);
255 static void rt2500usb_write_csr(struct rt2x00_dev *rt2x00dev,
256 const unsigned int word, u32 data)
258 rt2500usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
261 static const struct rt2x00debug rt2500usb_rt2x00debug = {
262 .owner = THIS_MODULE,
264 .read = rt2500usb_read_csr,
265 .write = rt2500usb_write_csr,
266 .word_size = sizeof(u16),
267 .word_count = CSR_REG_SIZE / sizeof(u16),
270 .read = rt2x00_eeprom_read,
271 .write = rt2x00_eeprom_write,
272 .word_size = sizeof(u16),
273 .word_count = EEPROM_SIZE / sizeof(u16),
276 .read = rt2500usb_bbp_read,
277 .write = rt2500usb_bbp_write,
278 .word_size = sizeof(u8),
279 .word_count = BBP_SIZE / sizeof(u8),
282 .read = rt2x00_rf_read,
283 .write = rt2500usb_rf_write,
284 .word_size = sizeof(u32),
285 .word_count = RF_SIZE / sizeof(u32),
288 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
291 * Configuration handlers.
293 static void rt2500usb_config_mac_addr(struct rt2x00_dev *rt2x00dev,
296 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, mac,
297 (3 * sizeof(__le16)));
300 static void rt2500usb_config_bssid(struct rt2x00_dev *rt2x00dev,
303 rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, bssid,
304 (3 * sizeof(__le16)));
307 static void rt2500usb_config_type(struct rt2x00_dev *rt2x00dev, const int type,
312 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
315 * Enable beacon config
317 rt2500usb_register_read(rt2x00dev, TXRX_CSR20, ®);
318 rt2x00_set_field16(®, TXRX_CSR20_OFFSET,
319 (PREAMBLE + get_duration(IEEE80211_HEADER, 20)) >> 6);
320 if (type == IEEE80211_IF_TYPE_STA)
321 rt2x00_set_field16(®, TXRX_CSR20_BCN_EXPECT_WINDOW, 0);
323 rt2x00_set_field16(®, TXRX_CSR20_BCN_EXPECT_WINDOW, 2);
324 rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
327 * Enable synchronisation.
329 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, ®);
330 rt2x00_set_field16(®, TXRX_CSR18_OFFSET, 0);
331 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
333 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
334 rt2x00_set_field16(®, TXRX_CSR19_TSF_COUNT, 1);
335 rt2x00_set_field16(®, TXRX_CSR19_TBCN, 1);
336 rt2x00_set_field16(®, TXRX_CSR19_BEACON_GEN, 0);
337 rt2x00_set_field16(®, TXRX_CSR19_TSF_SYNC, tsf_sync);
338 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
341 static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
342 const int short_preamble,
343 const int ack_timeout,
344 const int ack_consume_time)
349 * When in atomic context, reschedule and let rt2x00lib
350 * call this function again.
353 queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work);
357 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, ®);
358 rt2x00_set_field16(®, TXRX_CSR1_ACK_TIMEOUT, ack_timeout);
359 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
361 rt2500usb_register_read(rt2x00dev, TXRX_CSR10, ®);
362 rt2x00_set_field16(®, TXRX_CSR10_AUTORESPOND_PREAMBLE,
364 rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
367 static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
369 const int basic_rate_mask)
371 rt2500usb_register_write(rt2x00dev, TXRX_CSR11, basic_rate_mask);
373 if (phymode == HWMODE_B) {
374 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x000b);
375 rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x0040);
377 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0005);
378 rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x016c);
382 static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
383 struct rf_channel *rf, const int txpower)
388 rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
391 * For RT2525E we should first set the channel to half band higher.
393 if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
394 static const u32 vals[] = {
395 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
396 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
397 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
398 0x00000902, 0x00000906
401 rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
403 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
406 rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
407 rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
408 rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
410 rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
413 static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
418 rt2x00_rf_read(rt2x00dev, 3, &rf3);
419 rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
420 rt2500usb_rf_write(rt2x00dev, 3, rf3);
423 static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev,
424 struct antenna_setup *ant)
431 rt2500usb_bbp_read(rt2x00dev, 2, &r2);
432 rt2500usb_bbp_read(rt2x00dev, 14, &r14);
433 rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
434 rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
437 * Configure the TX antenna.
440 case ANTENNA_HW_DIVERSITY:
441 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
442 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
443 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
446 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
447 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
448 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
450 case ANTENNA_SW_DIVERSITY:
452 * NOTE: We should never come here because rt2x00lib is
453 * supposed to catch this and send us the correct antenna
454 * explicitely. However we are nog going to bug about this.
455 * Instead, just default to antenna B.
458 rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
459 rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
460 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
465 * Configure the RX antenna.
468 case ANTENNA_HW_DIVERSITY:
469 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
472 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
474 case ANTENNA_SW_DIVERSITY:
476 * NOTE: We should never come here because rt2x00lib is
477 * supposed to catch this and send us the correct antenna
478 * explicitely. However we are nog going to bug about this.
479 * Instead, just default to antenna B.
482 rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
487 * RT2525E and RT5222 need to flip TX I/Q
489 if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
490 rt2x00_rf(&rt2x00dev->chip, RF5222)) {
491 rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
492 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
493 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
496 * RT2525E does not need RX I/Q Flip.
498 if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
499 rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
501 rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
502 rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
505 rt2500usb_bbp_write(rt2x00dev, 2, r2);
506 rt2500usb_bbp_write(rt2x00dev, 14, r14);
507 rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
508 rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
511 static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
512 struct rt2x00lib_conf *libconf)
516 rt2500usb_register_write(rt2x00dev, MAC_CSR10, libconf->slot_time);
518 rt2500usb_register_read(rt2x00dev, TXRX_CSR18, ®);
519 rt2x00_set_field16(®, TXRX_CSR18_INTERVAL,
520 libconf->conf->beacon_int * 4);
521 rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
524 static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
525 const unsigned int flags,
526 struct rt2x00lib_conf *libconf)
528 if (flags & CONFIG_UPDATE_PHYMODE)
529 rt2500usb_config_phymode(rt2x00dev, libconf->phymode,
530 libconf->basic_rates);
531 if (flags & CONFIG_UPDATE_CHANNEL)
532 rt2500usb_config_channel(rt2x00dev, &libconf->rf,
533 libconf->conf->power_level);
534 if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
535 rt2500usb_config_txpower(rt2x00dev,
536 libconf->conf->power_level);
537 if (flags & CONFIG_UPDATE_ANTENNA)
538 rt2500usb_config_antenna(rt2x00dev, &libconf->ant);
539 if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
540 rt2500usb_config_duration(rt2x00dev, libconf);
546 static void rt2500usb_enable_led(struct rt2x00_dev *rt2x00dev)
550 rt2500usb_register_read(rt2x00dev, MAC_CSR21, ®);
551 rt2x00_set_field16(®, MAC_CSR21_ON_PERIOD, 70);
552 rt2x00_set_field16(®, MAC_CSR21_OFF_PERIOD, 30);
553 rt2500usb_register_write(rt2x00dev, MAC_CSR21, reg);
555 rt2500usb_register_read(rt2x00dev, MAC_CSR20, ®);
556 rt2x00_set_field16(®, MAC_CSR20_LINK,
557 (rt2x00dev->led_mode != LED_MODE_ASUS));
558 rt2x00_set_field16(®, MAC_CSR20_ACTIVITY,
559 (rt2x00dev->led_mode != LED_MODE_TXRX_ACTIVITY));
560 rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
563 static void rt2500usb_disable_led(struct rt2x00_dev *rt2x00dev)
567 rt2500usb_register_read(rt2x00dev, MAC_CSR20, ®);
568 rt2x00_set_field16(®, MAC_CSR20_LINK, 0);
569 rt2x00_set_field16(®, MAC_CSR20_ACTIVITY, 0);
570 rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
576 static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
577 struct link_qual *qual)
582 * Update FCS error count from register.
584 rt2500usb_register_read(rt2x00dev, STA_CSR0, ®);
585 qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
588 * Update False CCA count from register.
590 rt2500usb_register_read(rt2x00dev, STA_CSR3, ®);
591 qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
594 static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
599 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
600 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
601 rt2500usb_bbp_write(rt2x00dev, 24, value);
603 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
604 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
605 rt2500usb_bbp_write(rt2x00dev, 25, value);
607 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
608 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
609 rt2500usb_bbp_write(rt2x00dev, 61, value);
611 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
612 value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
613 rt2500usb_bbp_write(rt2x00dev, 17, value);
615 rt2x00dev->link.vgc_level = value;
618 static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
620 int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
633 * Determine the BBP tuning threshold and correctly
634 * set BBP 24, 25 and 61.
636 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
637 bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
639 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
640 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
641 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
643 if ((rssi + bbp_thresh) > 0) {
644 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
645 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
646 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
648 r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
649 r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
650 r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
653 rt2500usb_bbp_write(rt2x00dev, 24, r24);
654 rt2500usb_bbp_write(rt2x00dev, 25, r25);
655 rt2500usb_bbp_write(rt2x00dev, 61, r61);
658 * Read current r17 value, as well as the sensitivity values
659 * for the r17 register.
661 rt2500usb_bbp_read(rt2x00dev, 17, &r17);
662 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
665 * A too low RSSI will cause too much false CCA which will
666 * then corrupt the R17 tuning. To remidy this the tuning should
667 * be stopped (While making sure the R17 value will not exceed limits)
671 rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
676 * Special big-R17 for short distance
679 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
681 rt2500usb_bbp_write(rt2x00dev, 17, sens);
686 * Special mid-R17 for middle distance
689 sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
691 rt2500usb_bbp_write(rt2x00dev, 17, sens);
696 * Leave short or middle distance condition, restore r17
697 * to the dynamic tuning range.
699 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
700 vgc_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
704 up_bound = vgc_bound;
706 up_bound = vgc_bound - (-77 - rssi);
708 if (up_bound < low_bound)
709 up_bound = low_bound;
711 if (r17 > up_bound) {
712 rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
713 rt2x00dev->link.vgc_level = up_bound;
714 } else if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
715 rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
716 rt2x00dev->link.vgc_level = r17;
717 } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
718 rt2500usb_bbp_write(rt2x00dev, 17, --r17);
719 rt2x00dev->link.vgc_level = r17;
724 * Initialization functions.
726 static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
730 rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
731 USB_MODE_TEST, REGISTER_TIMEOUT);
732 rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
733 0x00f0, REGISTER_TIMEOUT);
735 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
736 rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX, 1);
737 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
739 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
740 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
742 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
743 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 1);
744 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 1);
745 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 0);
746 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
748 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
749 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 0);
750 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 0);
751 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 0);
752 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
754 rt2500usb_register_read(rt2x00dev, TXRX_CSR5, ®);
755 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID0, 13);
756 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID0_VALID, 1);
757 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID1, 12);
758 rt2x00_set_field16(®, TXRX_CSR5_BBP_ID1_VALID, 1);
759 rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
761 rt2500usb_register_read(rt2x00dev, TXRX_CSR6, ®);
762 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID0, 10);
763 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID0_VALID, 1);
764 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID1, 11);
765 rt2x00_set_field16(®, TXRX_CSR6_BBP_ID1_VALID, 1);
766 rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
768 rt2500usb_register_read(rt2x00dev, TXRX_CSR7, ®);
769 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID0, 7);
770 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID0_VALID, 1);
771 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID1, 6);
772 rt2x00_set_field16(®, TXRX_CSR7_BBP_ID1_VALID, 1);
773 rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
775 rt2500usb_register_read(rt2x00dev, TXRX_CSR8, ®);
776 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID0, 5);
777 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID0_VALID, 1);
778 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID1, 0);
779 rt2x00_set_field16(®, TXRX_CSR8_BBP_ID1_VALID, 0);
780 rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
782 rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
783 rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
785 if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
788 rt2500usb_register_read(rt2x00dev, MAC_CSR1, ®);
789 rt2x00_set_field16(®, MAC_CSR1_SOFT_RESET, 0);
790 rt2x00_set_field16(®, MAC_CSR1_BBP_RESET, 0);
791 rt2x00_set_field16(®, MAC_CSR1_HOST_READY, 1);
792 rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
794 if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
795 rt2500usb_register_read(rt2x00dev, PHY_CSR2, ®);
796 rt2x00_set_field16(®, PHY_CSR2_LNA, 0);
799 rt2x00_set_field16(®, PHY_CSR2_LNA, 1);
800 rt2x00_set_field16(®, PHY_CSR2_LNA_MODE, 3);
802 rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
804 rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
805 rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
806 rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
807 rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
809 rt2500usb_register_read(rt2x00dev, MAC_CSR8, ®);
810 rt2x00_set_field16(®, MAC_CSR8_MAX_FRAME_UNIT,
811 rt2x00dev->rx->data_size);
812 rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
814 rt2500usb_register_read(rt2x00dev, TXRX_CSR0, ®);
815 rt2x00_set_field16(®, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
816 rt2x00_set_field16(®, TXRX_CSR0_KEY_ID, 0xff);
817 rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
819 rt2500usb_register_read(rt2x00dev, MAC_CSR18, ®);
820 rt2x00_set_field16(®, MAC_CSR18_DELAY_AFTER_BEACON, 90);
821 rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
823 rt2500usb_register_read(rt2x00dev, PHY_CSR4, ®);
824 rt2x00_set_field16(®, PHY_CSR4_LOW_RF_LE, 1);
825 rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
827 rt2500usb_register_read(rt2x00dev, TXRX_CSR1, ®);
828 rt2x00_set_field16(®, TXRX_CSR1_AUTO_SEQUENCE, 1);
829 rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
834 static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
841 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
842 rt2500usb_bbp_read(rt2x00dev, 0, &value);
843 if ((value != 0xff) && (value != 0x00))
844 goto continue_csr_init;
845 NOTICE(rt2x00dev, "Waiting for BBP register.\n");
846 udelay(REGISTER_BUSY_DELAY);
849 ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
853 rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
854 rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
855 rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
856 rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
857 rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
858 rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
859 rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
860 rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
861 rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
862 rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
863 rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
864 rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
865 rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
866 rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
867 rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
868 rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
869 rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
870 rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
871 rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
872 rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
873 rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
874 rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
875 rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
876 rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
877 rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
878 rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
879 rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
880 rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
881 rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
882 rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
883 rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
885 DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
886 for (i = 0; i < EEPROM_BBP_SIZE; i++) {
887 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
889 if (eeprom != 0xffff && eeprom != 0x0000) {
890 reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
891 value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
892 DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
894 rt2500usb_bbp_write(rt2x00dev, reg_id, value);
897 DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
903 * Device state switch handlers.
905 static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
906 enum dev_state state)
910 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
911 rt2x00_set_field16(®, TXRX_CSR2_DISABLE_RX,
912 state == STATE_RADIO_RX_OFF);
913 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
916 static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
919 * Initialize all registers.
921 if (rt2500usb_init_registers(rt2x00dev) ||
922 rt2500usb_init_bbp(rt2x00dev)) {
923 ERROR(rt2x00dev, "Register initialization failed.\n");
927 rt2x00usb_enable_radio(rt2x00dev);
932 rt2500usb_enable_led(rt2x00dev);
937 static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
942 rt2500usb_disable_led(rt2x00dev);
944 rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
945 rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
948 * Disable synchronisation.
950 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
952 rt2x00usb_disable_radio(rt2x00dev);
955 static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
956 enum dev_state state)
965 put_to_sleep = (state != STATE_AWAKE);
968 rt2x00_set_field16(®, MAC_CSR17_BBP_DESIRE_STATE, state);
969 rt2x00_set_field16(®, MAC_CSR17_RF_DESIRE_STATE, state);
970 rt2x00_set_field16(®, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
971 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
972 rt2x00_set_field16(®, MAC_CSR17_SET_STATE, 1);
973 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
976 * Device is not guaranteed to be in the requested state yet.
977 * We must wait until the register indicates that the
978 * device has entered the correct state.
980 for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
981 rt2500usb_register_read(rt2x00dev, MAC_CSR17, ®2);
982 bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
983 rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
984 if (bbp_state == state && rf_state == state)
986 rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
990 NOTICE(rt2x00dev, "Device failed to enter state %d, "
991 "current device state: bbp %d and rf %d.\n",
992 state, bbp_state, rf_state);
997 static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
998 enum dev_state state)
1003 case STATE_RADIO_ON:
1004 retval = rt2500usb_enable_radio(rt2x00dev);
1006 case STATE_RADIO_OFF:
1007 rt2500usb_disable_radio(rt2x00dev);
1009 case STATE_RADIO_RX_ON:
1010 case STATE_RADIO_RX_OFF:
1011 rt2500usb_toggle_rx(rt2x00dev, state);
1013 case STATE_DEEP_SLEEP:
1017 retval = rt2500usb_set_state(rt2x00dev, state);
1028 * TX descriptor initialization
1030 static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1032 struct txdata_entry_desc *desc,
1033 struct ieee80211_hdr *ieee80211hdr,
1034 unsigned int length,
1035 struct ieee80211_tx_control *control)
1040 * Start writing the descriptor words.
1042 rt2x00_desc_read(txd, 1, &word);
1043 rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER);
1044 rt2x00_set_field32(&word, TXD_W1_AIFS, desc->aifs);
1045 rt2x00_set_field32(&word, TXD_W1_CWMIN, desc->cw_min);
1046 rt2x00_set_field32(&word, TXD_W1_CWMAX, desc->cw_max);
1047 rt2x00_desc_write(txd, 1, word);
1049 rt2x00_desc_read(txd, 2, &word);
1050 rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, desc->signal);
1051 rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, desc->service);
1052 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, desc->length_low);
1053 rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, desc->length_high);
1054 rt2x00_desc_write(txd, 2, word);
1056 rt2x00_desc_read(txd, 0, &word);
1057 rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, control->retry_limit);
1058 rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
1059 test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
1060 rt2x00_set_field32(&word, TXD_W0_ACK,
1061 test_bit(ENTRY_TXD_ACK, &desc->flags));
1062 rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
1063 test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
1064 rt2x00_set_field32(&word, TXD_W0_OFDM,
1065 test_bit(ENTRY_TXD_OFDM_RATE, &desc->flags));
1066 rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
1067 !!(control->flags & IEEE80211_TXCTL_FIRST_FRAGMENT));
1068 rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
1069 rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, length);
1070 rt2x00_set_field32(&word, TXD_W0_CIPHER, CIPHER_NONE);
1071 rt2x00_desc_write(txd, 0, word);
1074 static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
1075 struct sk_buff *skb)
1080 * The length _must_ be a multiple of 2,
1081 * but it must _not_ be a multiple of the USB packet size.
1083 length = roundup(skb->len, 2);
1084 length += (2 * !(length % rt2x00dev->usb_maxpacket));
1090 * TX data initialization
1092 static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
1097 if (queue != IEEE80211_TX_QUEUE_BEACON)
1100 rt2500usb_register_read(rt2x00dev, TXRX_CSR19, ®);
1101 if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
1102 rt2x00_set_field16(®, TXRX_CSR19_BEACON_GEN, 1);
1104 * Beacon generation will fail initially.
1105 * To prevent this we need to register the TXRX_CSR19
1106 * register several times.
1108 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1109 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1110 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1111 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
1112 rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
1117 * RX control handlers
1119 static void rt2500usb_fill_rxdone(struct data_entry *entry,
1120 struct rxdata_entry_desc *desc)
1122 struct urb *urb = entry->priv;
1123 __le32 *rxd = (__le32 *)(entry->skb->data +
1124 (urb->actual_length - entry->ring->desc_size));
1128 rt2x00_desc_read(rxd, 0, &word0);
1129 rt2x00_desc_read(rxd, 1, &word1);
1132 if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
1133 desc->flags |= RX_FLAG_FAILED_FCS_CRC;
1134 if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
1135 desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
1138 * Obtain the status about this packet.
1140 desc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
1141 desc->rssi = rt2x00_get_field32(word1, RXD_W1_RSSI) -
1142 entry->ring->rt2x00dev->rssi_offset;
1143 desc->ofdm = rt2x00_get_field32(word0, RXD_W0_OFDM);
1144 desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
1150 * Interrupt functions.
1152 static void rt2500usb_beacondone(struct urb *urb)
1154 struct data_entry *entry = (struct data_entry *)urb->context;
1155 struct data_ring *ring = entry->ring;
1157 if (!test_bit(DEVICE_ENABLED_RADIO, &ring->rt2x00dev->flags))
1161 * Check if this was the guardian beacon,
1162 * if that was the case we need to send the real beacon now.
1163 * Otherwise we should free the sk_buffer, the device
1164 * should be doing the rest of the work now.
1166 if (ring->index == 1) {
1167 rt2x00_ring_index_done_inc(ring);
1168 entry = rt2x00_get_data_entry(ring);
1169 usb_submit_urb(entry->priv, GFP_ATOMIC);
1170 rt2x00_ring_index_inc(ring);
1171 } else if (ring->index_done == 1) {
1172 entry = rt2x00_get_data_entry_done(ring);
1174 dev_kfree_skb(entry->skb);
1177 rt2x00_ring_index_done_inc(ring);
1182 * Device probe functions.
1184 static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
1189 rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
1192 * Start validation of the data that has been read.
1194 mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
1195 if (!is_valid_ether_addr(mac)) {
1196 DECLARE_MAC_BUF(macbuf);
1198 random_ether_addr(mac);
1199 EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
1202 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
1203 if (word == 0xffff) {
1204 rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
1205 rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
1206 ANTENNA_SW_DIVERSITY);
1207 rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
1208 ANTENNA_SW_DIVERSITY);
1209 rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
1211 rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
1212 rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
1213 rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
1214 rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
1215 EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
1218 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
1219 if (word == 0xffff) {
1220 rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
1221 rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
1222 rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
1223 rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
1224 EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
1227 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
1228 if (word == 0xffff) {
1229 rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
1230 DEFAULT_RSSI_OFFSET);
1231 rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
1232 EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
1235 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
1236 if (word == 0xffff) {
1237 rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
1238 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
1239 EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
1242 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
1243 if (word == 0xffff) {
1244 rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
1245 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
1246 EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
1249 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
1250 if (word == 0xffff) {
1251 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
1252 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
1253 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
1254 EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
1257 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
1258 if (word == 0xffff) {
1259 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
1260 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
1261 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
1262 EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
1265 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
1266 if (word == 0xffff) {
1267 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
1268 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
1269 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
1270 EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
1273 rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
1274 if (word == 0xffff) {
1275 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
1276 rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
1277 rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
1278 EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
1284 static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
1291 * Read EEPROM word for configuration.
1293 rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
1296 * Identify RF chipset.
1298 value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
1299 rt2500usb_register_read(rt2x00dev, MAC_CSR0, ®);
1300 rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
1302 if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
1303 ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
1307 if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
1308 !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
1309 !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
1310 !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
1311 !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
1312 !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1313 ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
1318 * Identify default antenna configuration.
1320 rt2x00dev->default_ant.tx =
1321 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
1322 rt2x00dev->default_ant.rx =
1323 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
1326 * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
1327 * I am not 100% sure about this, but the legacy drivers do not
1328 * indicate antenna swapping in software is required when
1329 * diversity is enabled.
1331 if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
1332 rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
1333 if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
1334 rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
1337 * Store led mode, for correct led behaviour.
1339 rt2x00dev->led_mode =
1340 rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
1343 * Check if the BBP tuning should be disabled.
1345 rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
1346 if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
1347 __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
1350 * Read the RSSI <-> dBm offset information.
1352 rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
1353 rt2x00dev->rssi_offset =
1354 rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
1360 * RF value list for RF2522
1363 static const struct rf_channel rf_vals_bg_2522[] = {
1364 { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
1365 { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
1366 { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
1367 { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
1368 { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
1369 { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
1370 { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
1371 { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
1372 { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
1373 { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
1374 { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
1375 { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
1376 { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
1377 { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
1381 * RF value list for RF2523
1384 static const struct rf_channel rf_vals_bg_2523[] = {
1385 { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
1386 { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
1387 { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
1388 { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
1389 { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
1390 { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
1391 { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
1392 { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
1393 { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
1394 { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
1395 { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
1396 { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
1397 { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
1398 { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
1402 * RF value list for RF2524
1405 static const struct rf_channel rf_vals_bg_2524[] = {
1406 { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
1407 { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
1408 { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
1409 { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
1410 { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
1411 { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
1412 { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
1413 { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
1414 { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
1415 { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
1416 { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
1417 { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
1418 { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
1419 { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
1423 * RF value list for RF2525
1426 static const struct rf_channel rf_vals_bg_2525[] = {
1427 { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
1428 { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
1429 { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
1430 { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
1431 { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
1432 { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
1433 { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
1434 { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
1435 { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
1436 { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
1437 { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
1438 { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
1439 { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
1440 { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
1444 * RF value list for RF2525e
1447 static const struct rf_channel rf_vals_bg_2525e[] = {
1448 { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
1449 { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
1450 { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
1451 { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
1452 { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
1453 { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
1454 { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
1455 { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
1456 { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
1457 { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
1458 { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
1459 { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
1460 { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
1461 { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
1465 * RF value list for RF5222
1466 * Supports: 2.4 GHz & 5.2 GHz
1468 static const struct rf_channel rf_vals_5222[] = {
1469 { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
1470 { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
1471 { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
1472 { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
1473 { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
1474 { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
1475 { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
1476 { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
1477 { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
1478 { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
1479 { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
1480 { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
1481 { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
1482 { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
1484 /* 802.11 UNI / HyperLan 2 */
1485 { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
1486 { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
1487 { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
1488 { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
1489 { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
1490 { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
1491 { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
1492 { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
1494 /* 802.11 HyperLan 2 */
1495 { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
1496 { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
1497 { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
1498 { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
1499 { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
1500 { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
1501 { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
1502 { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
1503 { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
1504 { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
1507 { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
1508 { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
1509 { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
1510 { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
1511 { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
1514 static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
1516 struct hw_mode_spec *spec = &rt2x00dev->spec;
1521 * Initialize all hw fields.
1523 rt2x00dev->hw->flags =
1524 IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
1525 IEEE80211_HW_RX_INCLUDES_FCS |
1526 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
1527 rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
1528 rt2x00dev->hw->max_signal = MAX_SIGNAL;
1529 rt2x00dev->hw->max_rssi = MAX_RX_SSI;
1530 rt2x00dev->hw->queues = 2;
1532 SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_usb(rt2x00dev)->dev);
1533 SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
1534 rt2x00_eeprom_addr(rt2x00dev,
1535 EEPROM_MAC_ADDR_0));
1538 * Convert tx_power array in eeprom.
1540 txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
1541 for (i = 0; i < 14; i++)
1542 txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
1545 * Initialize hw_mode information.
1547 spec->num_modes = 2;
1548 spec->num_rates = 12;
1549 spec->tx_power_a = NULL;
1550 spec->tx_power_bg = txpower;
1551 spec->tx_power_default = DEFAULT_TXPOWER;
1553 if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
1554 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
1555 spec->channels = rf_vals_bg_2522;
1556 } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
1557 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
1558 spec->channels = rf_vals_bg_2523;
1559 } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
1560 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
1561 spec->channels = rf_vals_bg_2524;
1562 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
1563 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
1564 spec->channels = rf_vals_bg_2525;
1565 } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
1566 spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
1567 spec->channels = rf_vals_bg_2525e;
1568 } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
1569 spec->num_channels = ARRAY_SIZE(rf_vals_5222);
1570 spec->channels = rf_vals_5222;
1571 spec->num_modes = 3;
1575 static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
1580 * Allocate eeprom data.
1582 retval = rt2500usb_validate_eeprom(rt2x00dev);
1586 retval = rt2500usb_init_eeprom(rt2x00dev);
1591 * Initialize hw specifications.
1593 rt2500usb_probe_hw_mode(rt2x00dev);
1596 * This device requires the beacon ring
1598 __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
1601 * Set the rssi offset.
1603 rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
1609 * IEEE80211 stack callback functions.
1611 static void rt2500usb_configure_filter(struct ieee80211_hw *hw,
1612 unsigned int changed_flags,
1613 unsigned int *total_flags,
1615 struct dev_addr_list *mc_list)
1617 struct rt2x00_dev *rt2x00dev = hw->priv;
1618 struct interface *intf = &rt2x00dev->interface;
1622 * Mask off any flags we are going to ignore from
1623 * the total_flags field.
1634 * Apply some rules to the filters:
1635 * - Some filters imply different filters to be set.
1636 * - Some things we can't filter out at all.
1637 * - Some filters are set based on interface type.
1640 *total_flags |= FIF_ALLMULTI;
1641 if (*total_flags & FIF_OTHER_BSS ||
1642 *total_flags & FIF_PROMISC_IN_BSS)
1643 *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
1644 if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
1645 *total_flags |= FIF_PROMISC_IN_BSS;
1648 * Check if there is any work left for us.
1650 if (intf->filter == *total_flags)
1652 intf->filter = *total_flags;
1655 * When in atomic context, reschedule and let rt2x00lib
1656 * call this function again.
1659 queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
1664 * Start configuration steps.
1665 * Note that the version error will always be dropped
1666 * and broadcast frames will always be accepted since
1667 * there is no filter for it at this time.
1669 rt2500usb_register_read(rt2x00dev, TXRX_CSR2, ®);
1670 rt2x00_set_field16(®, TXRX_CSR2_DROP_CRC,
1671 !(*total_flags & FIF_FCSFAIL));
1672 rt2x00_set_field16(®, TXRX_CSR2_DROP_PHYSICAL,
1673 !(*total_flags & FIF_PLCPFAIL));
1674 rt2x00_set_field16(®, TXRX_CSR2_DROP_CONTROL,
1675 !(*total_flags & FIF_CONTROL));
1676 rt2x00_set_field16(®, TXRX_CSR2_DROP_NOT_TO_ME,
1677 !(*total_flags & FIF_PROMISC_IN_BSS));
1678 rt2x00_set_field16(®, TXRX_CSR2_DROP_TODS,
1679 !(*total_flags & FIF_PROMISC_IN_BSS));
1680 rt2x00_set_field16(®, TXRX_CSR2_DROP_VERSION_ERROR, 1);
1681 rt2x00_set_field16(®, TXRX_CSR2_DROP_MULTICAST,
1682 !(*total_flags & FIF_ALLMULTI));
1683 rt2x00_set_field16(®, TXRX_CSR2_DROP_BROADCAST, 0);
1684 rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
1687 static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
1688 struct sk_buff *skb,
1689 struct ieee80211_tx_control *control)
1691 struct rt2x00_dev *rt2x00dev = hw->priv;
1692 struct usb_device *usb_dev =
1693 interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
1694 struct data_ring *ring =
1695 rt2x00lib_get_ring(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
1696 struct data_entry *beacon;
1697 struct data_entry *guardian;
1698 int pipe = usb_sndbulkpipe(usb_dev, 1);
1702 * Just in case the ieee80211 doesn't set this,
1703 * but we need this queue set for the descriptor
1706 control->queue = IEEE80211_TX_QUEUE_BEACON;
1709 * Obtain 2 entries, one for the guardian byte,
1710 * the second for the actual beacon.
1712 guardian = rt2x00_get_data_entry(ring);
1713 rt2x00_ring_index_inc(ring);
1714 beacon = rt2x00_get_data_entry(ring);
1717 * First we create the beacon.
1719 skb_push(skb, ring->desc_size);
1720 memset(skb->data, 0, ring->desc_size);
1722 rt2x00lib_write_tx_desc(rt2x00dev, (__le32 *)skb->data,
1723 (struct ieee80211_hdr *)(skb->data +
1725 skb->len - ring->desc_size, control);
1727 length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
1729 usb_fill_bulk_urb(beacon->priv, usb_dev, pipe,
1730 skb->data, length, rt2500usb_beacondone, beacon);
1735 * Second we need to create the guardian byte.
1736 * We only need a single byte, so lets recycle
1737 * the 'flags' field we are not using for beacons.
1739 guardian->flags = 0;
1740 usb_fill_bulk_urb(guardian->priv, usb_dev, pipe,
1741 &guardian->flags, 1, rt2500usb_beacondone, guardian);
1744 * Send out the guardian byte.
1746 usb_submit_urb(guardian->priv, GFP_ATOMIC);
1749 * Enable beacon generation.
1751 rt2500usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
1756 static const struct ieee80211_ops rt2500usb_mac80211_ops = {
1758 .start = rt2x00mac_start,
1759 .stop = rt2x00mac_stop,
1760 .add_interface = rt2x00mac_add_interface,
1761 .remove_interface = rt2x00mac_remove_interface,
1762 .config = rt2x00mac_config,
1763 .config_interface = rt2x00mac_config_interface,
1764 .configure_filter = rt2500usb_configure_filter,
1765 .get_stats = rt2x00mac_get_stats,
1766 .erp_ie_changed = rt2x00mac_erp_ie_changed,
1767 .conf_tx = rt2x00mac_conf_tx,
1768 .get_tx_stats = rt2x00mac_get_tx_stats,
1769 .beacon_update = rt2500usb_beacon_update,
1772 static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
1773 .probe_hw = rt2500usb_probe_hw,
1774 .initialize = rt2x00usb_initialize,
1775 .uninitialize = rt2x00usb_uninitialize,
1776 .set_device_state = rt2500usb_set_device_state,
1777 .link_stats = rt2500usb_link_stats,
1778 .reset_tuner = rt2500usb_reset_tuner,
1779 .link_tuner = rt2500usb_link_tuner,
1780 .write_tx_desc = rt2500usb_write_tx_desc,
1781 .write_tx_data = rt2x00usb_write_tx_data,
1782 .get_tx_data_len = rt2500usb_get_tx_data_len,
1783 .kick_tx_queue = rt2500usb_kick_tx_queue,
1784 .fill_rxdone = rt2500usb_fill_rxdone,
1785 .config_mac_addr = rt2500usb_config_mac_addr,
1786 .config_bssid = rt2500usb_config_bssid,
1787 .config_type = rt2500usb_config_type,
1788 .config_preamble = rt2500usb_config_preamble,
1789 .config = rt2500usb_config,
1792 static const struct rt2x00_ops rt2500usb_ops = {
1794 .rxd_size = RXD_DESC_SIZE,
1795 .txd_size = TXD_DESC_SIZE,
1796 .eeprom_size = EEPROM_SIZE,
1798 .lib = &rt2500usb_rt2x00_ops,
1799 .hw = &rt2500usb_mac80211_ops,
1800 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1801 .debugfs = &rt2500usb_rt2x00debug,
1802 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1806 * rt2500usb module information.
1808 static struct usb_device_id rt2500usb_device_table[] = {
1810 { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1811 { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
1813 { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
1814 { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
1815 { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
1817 { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
1818 { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
1819 { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
1821 { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
1823 { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
1825 { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
1826 { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
1828 { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
1830 { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
1831 { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
1832 { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
1833 { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
1836 { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
1837 { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
1838 { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
1840 { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
1841 { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
1842 { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
1843 { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1845 { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
1847 { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
1849 { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
1851 { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
1853 { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
1857 MODULE_AUTHOR(DRV_PROJECT);
1858 MODULE_VERSION(DRV_VERSION);
1859 MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
1860 MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
1861 MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
1862 MODULE_LICENSE("GPL");
1864 static struct usb_driver rt2500usb_driver = {
1866 .id_table = rt2500usb_device_table,
1867 .probe = rt2x00usb_probe,
1868 .disconnect = rt2x00usb_disconnect,
1869 .suspend = rt2x00usb_suspend,
1870 .resume = rt2x00usb_resume,
1873 static int __init rt2500usb_init(void)
1875 return usb_register(&rt2500usb_driver);
1878 static void __exit rt2500usb_exit(void)
1880 usb_deregister(&rt2500usb_driver);
1883 module_init(rt2500usb_init);
1884 module_exit(rt2500usb_exit);