1 // SPDX-License-Identifier: GPL-2.0-or-later
3 Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com>
4 <http://rt2x00.serialmonkey.com>
10 Abstract: rt61pci device specific routines.
11 Supported chipsets: RT2561, RT2561s, RT2661.
14 #include <linux/crc-itu-t.h>
15 #include <linux/delay.h>
16 #include <linux/etherdevice.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/slab.h>
20 #include <linux/pci.h>
21 #include <linux/eeprom_93cx6.h>
24 #include "rt2x00mmio.h"
25 #include "rt2x00pci.h"
29 * Allow hardware encryption to be disabled.
31 static bool modparam_nohwcrypt
= false;
32 module_param_named(nohwcrypt
, modparam_nohwcrypt
, bool, 0444);
33 MODULE_PARM_DESC(nohwcrypt
, "Disable hardware encryption.");
37 * BBP and RF register require indirect register access,
38 * and use the CSR registers PHY_CSR3 and PHY_CSR4 to achieve this.
39 * These indirect registers work with busy bits,
40 * and we will try maximal REGISTER_BUSY_COUNT times to access
41 * the register while taking a REGISTER_BUSY_DELAY us delay
42 * between each attempt. When the busy bit is still set at that time,
43 * the access attempt is considered to have failed,
44 * and we will print an error.
46 #define WAIT_FOR_BBP(__dev, __reg) \
47 rt2x00mmio_regbusy_read((__dev), PHY_CSR3, PHY_CSR3_BUSY, (__reg))
48 #define WAIT_FOR_RF(__dev, __reg) \
49 rt2x00mmio_regbusy_read((__dev), PHY_CSR4, PHY_CSR4_BUSY, (__reg))
50 #define WAIT_FOR_MCU(__dev, __reg) \
51 rt2x00mmio_regbusy_read((__dev), H2M_MAILBOX_CSR, \
52 H2M_MAILBOX_CSR_OWNER, (__reg))
54 static void rt61pci_bbp_write(struct rt2x00_dev
*rt2x00dev
,
55 const unsigned int word
, const u8 value
)
59 mutex_lock(&rt2x00dev
->csr_mutex
);
62 * Wait until the BBP becomes available, afterwards we
63 * can safely write the new data into the register.
65 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
67 rt2x00_set_field32(®
, PHY_CSR3_VALUE
, value
);
68 rt2x00_set_field32(®
, PHY_CSR3_REGNUM
, word
);
69 rt2x00_set_field32(®
, PHY_CSR3_BUSY
, 1);
70 rt2x00_set_field32(®
, PHY_CSR3_READ_CONTROL
, 0);
72 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR3
, reg
);
75 mutex_unlock(&rt2x00dev
->csr_mutex
);
78 static u8
rt61pci_bbp_read(struct rt2x00_dev
*rt2x00dev
,
79 const unsigned int word
)
84 mutex_lock(&rt2x00dev
->csr_mutex
);
87 * Wait until the BBP becomes available, afterwards we
88 * can safely write the read request into the register.
89 * After the data has been written, we wait until hardware
90 * returns the correct value, if at any time the register
91 * doesn't become available in time, reg will be 0xffffffff
92 * which means we return 0xff to the caller.
94 if (WAIT_FOR_BBP(rt2x00dev
, ®
)) {
96 rt2x00_set_field32(®
, PHY_CSR3_REGNUM
, word
);
97 rt2x00_set_field32(®
, PHY_CSR3_BUSY
, 1);
98 rt2x00_set_field32(®
, PHY_CSR3_READ_CONTROL
, 1);
100 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR3
, reg
);
102 WAIT_FOR_BBP(rt2x00dev
, ®
);
105 value
= rt2x00_get_field32(reg
, PHY_CSR3_VALUE
);
107 mutex_unlock(&rt2x00dev
->csr_mutex
);
112 static void rt61pci_rf_write(struct rt2x00_dev
*rt2x00dev
,
113 const unsigned int word
, const u32 value
)
117 mutex_lock(&rt2x00dev
->csr_mutex
);
120 * Wait until the RF becomes available, afterwards we
121 * can safely write the new data into the register.
123 if (WAIT_FOR_RF(rt2x00dev
, ®
)) {
125 rt2x00_set_field32(®
, PHY_CSR4_VALUE
, value
);
126 rt2x00_set_field32(®
, PHY_CSR4_NUMBER_OF_BITS
, 21);
127 rt2x00_set_field32(®
, PHY_CSR4_IF_SELECT
, 0);
128 rt2x00_set_field32(®
, PHY_CSR4_BUSY
, 1);
130 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR4
, reg
);
131 rt2x00_rf_write(rt2x00dev
, word
, value
);
134 mutex_unlock(&rt2x00dev
->csr_mutex
);
137 static void rt61pci_mcu_request(struct rt2x00_dev
*rt2x00dev
,
138 const u8 command
, const u8 token
,
139 const u8 arg0
, const u8 arg1
)
143 mutex_lock(&rt2x00dev
->csr_mutex
);
146 * Wait until the MCU becomes available, afterwards we
147 * can safely write the new data into the register.
149 if (WAIT_FOR_MCU(rt2x00dev
, ®
)) {
150 rt2x00_set_field32(®
, H2M_MAILBOX_CSR_OWNER
, 1);
151 rt2x00_set_field32(®
, H2M_MAILBOX_CSR_CMD_TOKEN
, token
);
152 rt2x00_set_field32(®
, H2M_MAILBOX_CSR_ARG0
, arg0
);
153 rt2x00_set_field32(®
, H2M_MAILBOX_CSR_ARG1
, arg1
);
154 rt2x00mmio_register_write(rt2x00dev
, H2M_MAILBOX_CSR
, reg
);
156 reg
= rt2x00mmio_register_read(rt2x00dev
, HOST_CMD_CSR
);
157 rt2x00_set_field32(®
, HOST_CMD_CSR_HOST_COMMAND
, command
);
158 rt2x00_set_field32(®
, HOST_CMD_CSR_INTERRUPT_MCU
, 1);
159 rt2x00mmio_register_write(rt2x00dev
, HOST_CMD_CSR
, reg
);
162 mutex_unlock(&rt2x00dev
->csr_mutex
);
166 static void rt61pci_eepromregister_read(struct eeprom_93cx6
*eeprom
)
168 struct rt2x00_dev
*rt2x00dev
= eeprom
->data
;
171 reg
= rt2x00mmio_register_read(rt2x00dev
, E2PROM_CSR
);
173 eeprom
->reg_data_in
= !!rt2x00_get_field32(reg
, E2PROM_CSR_DATA_IN
);
174 eeprom
->reg_data_out
= !!rt2x00_get_field32(reg
, E2PROM_CSR_DATA_OUT
);
175 eeprom
->reg_data_clock
=
176 !!rt2x00_get_field32(reg
, E2PROM_CSR_DATA_CLOCK
);
177 eeprom
->reg_chip_select
=
178 !!rt2x00_get_field32(reg
, E2PROM_CSR_CHIP_SELECT
);
181 static void rt61pci_eepromregister_write(struct eeprom_93cx6
*eeprom
)
183 struct rt2x00_dev
*rt2x00dev
= eeprom
->data
;
186 rt2x00_set_field32(®
, E2PROM_CSR_DATA_IN
, !!eeprom
->reg_data_in
);
187 rt2x00_set_field32(®
, E2PROM_CSR_DATA_OUT
, !!eeprom
->reg_data_out
);
188 rt2x00_set_field32(®
, E2PROM_CSR_DATA_CLOCK
,
189 !!eeprom
->reg_data_clock
);
190 rt2x00_set_field32(®
, E2PROM_CSR_CHIP_SELECT
,
191 !!eeprom
->reg_chip_select
);
193 rt2x00mmio_register_write(rt2x00dev
, E2PROM_CSR
, reg
);
196 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
197 static const struct rt2x00debug rt61pci_rt2x00debug
= {
198 .owner
= THIS_MODULE
,
200 .read
= rt2x00mmio_register_read
,
201 .write
= rt2x00mmio_register_write
,
202 .flags
= RT2X00DEBUGFS_OFFSET
,
203 .word_base
= CSR_REG_BASE
,
204 .word_size
= sizeof(u32
),
205 .word_count
= CSR_REG_SIZE
/ sizeof(u32
),
208 .read
= rt2x00_eeprom_read
,
209 .write
= rt2x00_eeprom_write
,
210 .word_base
= EEPROM_BASE
,
211 .word_size
= sizeof(u16
),
212 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
215 .read
= rt61pci_bbp_read
,
216 .write
= rt61pci_bbp_write
,
217 .word_base
= BBP_BASE
,
218 .word_size
= sizeof(u8
),
219 .word_count
= BBP_SIZE
/ sizeof(u8
),
222 .read
= rt2x00_rf_read
,
223 .write
= rt61pci_rf_write
,
224 .word_base
= RF_BASE
,
225 .word_size
= sizeof(u32
),
226 .word_count
= RF_SIZE
/ sizeof(u32
),
229 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
231 static int rt61pci_rfkill_poll(struct rt2x00_dev
*rt2x00dev
)
235 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR13
);
236 return rt2x00_get_field32(reg
, MAC_CSR13_VAL5
);
239 #ifdef CONFIG_RT2X00_LIB_LEDS
240 static void rt61pci_brightness_set(struct led_classdev
*led_cdev
,
241 enum led_brightness brightness
)
243 struct rt2x00_led
*led
=
244 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
245 unsigned int enabled
= brightness
!= LED_OFF
;
246 unsigned int a_mode
=
247 (enabled
&& led
->rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
);
248 unsigned int bg_mode
=
249 (enabled
&& led
->rt2x00dev
->curr_band
== NL80211_BAND_2GHZ
);
251 if (led
->type
== LED_TYPE_RADIO
) {
252 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
253 MCU_LEDCS_RADIO_STATUS
, enabled
);
255 rt61pci_mcu_request(led
->rt2x00dev
, MCU_LED
, 0xff,
256 (led
->rt2x00dev
->led_mcu_reg
& 0xff),
257 ((led
->rt2x00dev
->led_mcu_reg
>> 8)));
258 } else if (led
->type
== LED_TYPE_ASSOC
) {
259 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
260 MCU_LEDCS_LINK_BG_STATUS
, bg_mode
);
261 rt2x00_set_field16(&led
->rt2x00dev
->led_mcu_reg
,
262 MCU_LEDCS_LINK_A_STATUS
, a_mode
);
264 rt61pci_mcu_request(led
->rt2x00dev
, MCU_LED
, 0xff,
265 (led
->rt2x00dev
->led_mcu_reg
& 0xff),
266 ((led
->rt2x00dev
->led_mcu_reg
>> 8)));
267 } else if (led
->type
== LED_TYPE_QUALITY
) {
269 * The brightness is divided into 6 levels (0 - 5),
270 * this means we need to convert the brightness
271 * argument into the matching level within that range.
273 rt61pci_mcu_request(led
->rt2x00dev
, MCU_LED_STRENGTH
, 0xff,
274 brightness
/ (LED_FULL
/ 6), 0);
278 static int rt61pci_blink_set(struct led_classdev
*led_cdev
,
279 unsigned long *delay_on
,
280 unsigned long *delay_off
)
282 struct rt2x00_led
*led
=
283 container_of(led_cdev
, struct rt2x00_led
, led_dev
);
286 reg
= rt2x00mmio_register_read(led
->rt2x00dev
, MAC_CSR14
);
287 rt2x00_set_field32(®
, MAC_CSR14_ON_PERIOD
, *delay_on
);
288 rt2x00_set_field32(®
, MAC_CSR14_OFF_PERIOD
, *delay_off
);
289 rt2x00mmio_register_write(led
->rt2x00dev
, MAC_CSR14
, reg
);
294 static void rt61pci_init_led(struct rt2x00_dev
*rt2x00dev
,
295 struct rt2x00_led
*led
,
298 led
->rt2x00dev
= rt2x00dev
;
300 led
->led_dev
.brightness_set
= rt61pci_brightness_set
;
301 led
->led_dev
.blink_set
= rt61pci_blink_set
;
302 led
->flags
= LED_INITIALIZED
;
304 #endif /* CONFIG_RT2X00_LIB_LEDS */
307 * Configuration handlers.
309 static int rt61pci_config_shared_key(struct rt2x00_dev
*rt2x00dev
,
310 struct rt2x00lib_crypto
*crypto
,
311 struct ieee80211_key_conf
*key
)
314 * Let the software handle the shared keys,
315 * since the hardware decryption does not work reliably,
316 * because the firmware does not know the key's keyidx.
321 static int rt61pci_config_pairwise_key(struct rt2x00_dev
*rt2x00dev
,
322 struct rt2x00lib_crypto
*crypto
,
323 struct ieee80211_key_conf
*key
)
325 struct hw_pairwise_ta_entry addr_entry
;
326 struct hw_key_entry key_entry
;
330 if (crypto
->cmd
== SET_KEY
) {
332 * rt2x00lib can't determine the correct free
333 * key_idx for pairwise keys. We have 2 registers
334 * with key valid bits. The goal is simple: read
335 * the first register. If that is full, move to
337 * When both registers are full, we drop the key.
338 * Otherwise, we use the first invalid entry.
340 reg
= rt2x00mmio_register_read(rt2x00dev
, SEC_CSR2
);
341 if (reg
&& reg
== ~0) {
342 key
->hw_key_idx
= 32;
343 reg
= rt2x00mmio_register_read(rt2x00dev
, SEC_CSR3
);
344 if (reg
&& reg
== ~0)
348 key
->hw_key_idx
+= reg
? ffz(reg
) : 0;
351 * Upload key to hardware
353 memcpy(key_entry
.key
, crypto
->key
,
354 sizeof(key_entry
.key
));
355 memcpy(key_entry
.tx_mic
, crypto
->tx_mic
,
356 sizeof(key_entry
.tx_mic
));
357 memcpy(key_entry
.rx_mic
, crypto
->rx_mic
,
358 sizeof(key_entry
.rx_mic
));
360 memset(&addr_entry
, 0, sizeof(addr_entry
));
361 memcpy(&addr_entry
, crypto
->address
, ETH_ALEN
);
362 addr_entry
.cipher
= crypto
->cipher
;
364 reg
= PAIRWISE_KEY_ENTRY(key
->hw_key_idx
);
365 rt2x00mmio_register_multiwrite(rt2x00dev
, reg
,
366 &key_entry
, sizeof(key_entry
));
368 reg
= PAIRWISE_TA_ENTRY(key
->hw_key_idx
);
369 rt2x00mmio_register_multiwrite(rt2x00dev
, reg
,
370 &addr_entry
, sizeof(addr_entry
));
373 * Enable pairwise lookup table for given BSS idx.
374 * Without this, received frames will not be decrypted
377 reg
= rt2x00mmio_register_read(rt2x00dev
, SEC_CSR4
);
378 reg
|= (1 << crypto
->bssidx
);
379 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR4
, reg
);
382 * The driver does not support the IV/EIV generation
383 * in hardware. However it doesn't support the IV/EIV
384 * inside the ieee80211 frame either, but requires it
385 * to be provided separately for the descriptor.
386 * rt2x00lib will cut the IV/EIV data out of all frames
387 * given to us by mac80211, but we must tell mac80211
388 * to generate the IV/EIV data.
390 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
394 * SEC_CSR2 and SEC_CSR3 contain only single-bit fields to indicate
395 * a particular key is valid. Because using the FIELD32()
396 * defines directly will cause a lot of overhead, we use
397 * a calculation to determine the correct bit directly.
399 if (key
->hw_key_idx
< 32) {
400 mask
= 1 << key
->hw_key_idx
;
402 reg
= rt2x00mmio_register_read(rt2x00dev
, SEC_CSR2
);
403 if (crypto
->cmd
== SET_KEY
)
405 else if (crypto
->cmd
== DISABLE_KEY
)
407 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR2
, reg
);
409 mask
= 1 << (key
->hw_key_idx
- 32);
411 reg
= rt2x00mmio_register_read(rt2x00dev
, SEC_CSR3
);
412 if (crypto
->cmd
== SET_KEY
)
414 else if (crypto
->cmd
== DISABLE_KEY
)
416 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR3
, reg
);
422 static void rt61pci_config_filter(struct rt2x00_dev
*rt2x00dev
,
423 const unsigned int filter_flags
)
428 * Start configuration steps.
429 * Note that the version error will always be dropped
430 * and broadcast frames will always be accepted since
431 * there is no filter for it at this time.
433 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR0
);
434 rt2x00_set_field32(®
, TXRX_CSR0_DROP_CRC
,
435 !(filter_flags
& FIF_FCSFAIL
));
436 rt2x00_set_field32(®
, TXRX_CSR0_DROP_PHYSICAL
,
437 !(filter_flags
& FIF_PLCPFAIL
));
438 rt2x00_set_field32(®
, TXRX_CSR0_DROP_CONTROL
,
439 !(filter_flags
& (FIF_CONTROL
| FIF_PSPOLL
)));
440 rt2x00_set_field32(®
, TXRX_CSR0_DROP_NOT_TO_ME
,
441 !test_bit(CONFIG_MONITORING
, &rt2x00dev
->flags
));
442 rt2x00_set_field32(®
, TXRX_CSR0_DROP_TO_DS
,
443 !test_bit(CONFIG_MONITORING
, &rt2x00dev
->flags
) &&
444 !rt2x00dev
->intf_ap_count
);
445 rt2x00_set_field32(®
, TXRX_CSR0_DROP_VERSION_ERROR
, 1);
446 rt2x00_set_field32(®
, TXRX_CSR0_DROP_MULTICAST
,
447 !(filter_flags
& FIF_ALLMULTI
));
448 rt2x00_set_field32(®
, TXRX_CSR0_DROP_BROADCAST
, 0);
449 rt2x00_set_field32(®
, TXRX_CSR0_DROP_ACK_CTS
,
450 !(filter_flags
& FIF_CONTROL
));
451 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
454 static void rt61pci_config_intf(struct rt2x00_dev
*rt2x00dev
,
455 struct rt2x00_intf
*intf
,
456 struct rt2x00intf_conf
*conf
,
457 const unsigned int flags
)
461 if (flags
& CONFIG_UPDATE_TYPE
) {
463 * Enable synchronisation.
465 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
466 rt2x00_set_field32(®
, TXRX_CSR9_TSF_SYNC
, conf
->sync
);
467 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
470 if (flags
& CONFIG_UPDATE_MAC
) {
471 reg
= le32_to_cpu(conf
->mac
[1]);
472 rt2x00_set_field32(®
, MAC_CSR3_UNICAST_TO_ME_MASK
, 0xff);
473 conf
->mac
[1] = cpu_to_le32(reg
);
475 rt2x00mmio_register_multiwrite(rt2x00dev
, MAC_CSR2
,
476 conf
->mac
, sizeof(conf
->mac
));
479 if (flags
& CONFIG_UPDATE_BSSID
) {
480 reg
= le32_to_cpu(conf
->bssid
[1]);
481 rt2x00_set_field32(®
, MAC_CSR5_BSS_ID_MASK
, 3);
482 conf
->bssid
[1] = cpu_to_le32(reg
);
484 rt2x00mmio_register_multiwrite(rt2x00dev
, MAC_CSR4
,
486 sizeof(conf
->bssid
));
490 static void rt61pci_config_erp(struct rt2x00_dev
*rt2x00dev
,
491 struct rt2x00lib_erp
*erp
,
496 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR0
);
497 rt2x00_set_field32(®
, TXRX_CSR0_RX_ACK_TIMEOUT
, 0x32);
498 rt2x00_set_field32(®
, TXRX_CSR0_TSF_OFFSET
, IEEE80211_HEADER
);
499 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
501 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
502 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR4
);
503 rt2x00_set_field32(®
, TXRX_CSR4_AUTORESPOND_ENABLE
, 1);
504 rt2x00_set_field32(®
, TXRX_CSR4_AUTORESPOND_PREAMBLE
,
505 !!erp
->short_preamble
);
506 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR4
, reg
);
509 if (changed
& BSS_CHANGED_BASIC_RATES
)
510 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR5
,
513 if (changed
& BSS_CHANGED_BEACON_INT
) {
514 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
515 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_INTERVAL
,
516 erp
->beacon_int
* 16);
517 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
520 if (changed
& BSS_CHANGED_ERP_SLOT
) {
521 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR9
);
522 rt2x00_set_field32(®
, MAC_CSR9_SLOT_TIME
, erp
->slot_time
);
523 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR9
, reg
);
525 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR8
);
526 rt2x00_set_field32(®
, MAC_CSR8_SIFS
, erp
->sifs
);
527 rt2x00_set_field32(®
, MAC_CSR8_SIFS_AFTER_RX_OFDM
, 3);
528 rt2x00_set_field32(®
, MAC_CSR8_EIFS
, erp
->eifs
);
529 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR8
, reg
);
533 static void rt61pci_config_antenna_5x(struct rt2x00_dev
*rt2x00dev
,
534 struct antenna_setup
*ant
)
540 r3
= rt61pci_bbp_read(rt2x00dev
, 3);
541 r4
= rt61pci_bbp_read(rt2x00dev
, 4);
542 r77
= rt61pci_bbp_read(rt2x00dev
, 77);
544 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, rt2x00_rf(rt2x00dev
, RF5325
));
547 * Configure the RX antenna.
550 case ANTENNA_HW_DIVERSITY
:
551 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 2);
552 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
,
553 (rt2x00dev
->curr_band
!= NL80211_BAND_5GHZ
));
556 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
557 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
, 0);
558 if (rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
)
559 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
561 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
565 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
566 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
, 0);
567 if (rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
)
568 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
570 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
574 rt61pci_bbp_write(rt2x00dev
, 77, r77
);
575 rt61pci_bbp_write(rt2x00dev
, 3, r3
);
576 rt61pci_bbp_write(rt2x00dev
, 4, r4
);
579 static void rt61pci_config_antenna_2x(struct rt2x00_dev
*rt2x00dev
,
580 struct antenna_setup
*ant
)
586 r3
= rt61pci_bbp_read(rt2x00dev
, 3);
587 r4
= rt61pci_bbp_read(rt2x00dev
, 4);
588 r77
= rt61pci_bbp_read(rt2x00dev
, 77);
590 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, rt2x00_rf(rt2x00dev
, RF2529
));
591 rt2x00_set_field8(&r4
, BBP_R4_RX_FRAME_END
,
592 !rt2x00_has_cap_frame_type(rt2x00dev
));
595 * Configure the RX antenna.
598 case ANTENNA_HW_DIVERSITY
:
599 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 2);
602 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
603 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
607 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
608 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
612 rt61pci_bbp_write(rt2x00dev
, 77, r77
);
613 rt61pci_bbp_write(rt2x00dev
, 3, r3
);
614 rt61pci_bbp_write(rt2x00dev
, 4, r4
);
617 static void rt61pci_config_antenna_2529_rx(struct rt2x00_dev
*rt2x00dev
,
618 const int p1
, const int p2
)
622 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR13
);
624 rt2x00_set_field32(®
, MAC_CSR13_DIR4
, 0);
625 rt2x00_set_field32(®
, MAC_CSR13_VAL4
, p1
);
627 rt2x00_set_field32(®
, MAC_CSR13_DIR3
, 0);
628 rt2x00_set_field32(®
, MAC_CSR13_VAL3
, !p2
);
630 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR13
, reg
);
633 static void rt61pci_config_antenna_2529(struct rt2x00_dev
*rt2x00dev
,
634 struct antenna_setup
*ant
)
640 r3
= rt61pci_bbp_read(rt2x00dev
, 3);
641 r4
= rt61pci_bbp_read(rt2x00dev
, 4);
642 r77
= rt61pci_bbp_read(rt2x00dev
, 77);
645 * Configure the RX antenna.
649 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
650 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 0);
651 rt61pci_config_antenna_2529_rx(rt2x00dev
, 0, 0);
653 case ANTENNA_HW_DIVERSITY
:
655 * FIXME: Antenna selection for the rf 2529 is very confusing
656 * in the legacy driver. Just default to antenna B until the
657 * legacy code can be properly translated into rt2x00 code.
661 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA_CONTROL
, 1);
662 rt2x00_set_field8(&r77
, BBP_R77_RX_ANTENNA
, 3);
663 rt61pci_config_antenna_2529_rx(rt2x00dev
, 1, 1);
667 rt61pci_bbp_write(rt2x00dev
, 77, r77
);
668 rt61pci_bbp_write(rt2x00dev
, 3, r3
);
669 rt61pci_bbp_write(rt2x00dev
, 4, r4
);
675 * value[0] -> non-LNA
681 static const struct antenna_sel antenna_sel_a
[] = {
682 { 96, { 0x58, 0x78 } },
683 { 104, { 0x38, 0x48 } },
684 { 75, { 0xfe, 0x80 } },
685 { 86, { 0xfe, 0x80 } },
686 { 88, { 0xfe, 0x80 } },
687 { 35, { 0x60, 0x60 } },
688 { 97, { 0x58, 0x58 } },
689 { 98, { 0x58, 0x58 } },
692 static const struct antenna_sel antenna_sel_bg
[] = {
693 { 96, { 0x48, 0x68 } },
694 { 104, { 0x2c, 0x3c } },
695 { 75, { 0xfe, 0x80 } },
696 { 86, { 0xfe, 0x80 } },
697 { 88, { 0xfe, 0x80 } },
698 { 35, { 0x50, 0x50 } },
699 { 97, { 0x48, 0x48 } },
700 { 98, { 0x48, 0x48 } },
703 static void rt61pci_config_ant(struct rt2x00_dev
*rt2x00dev
,
704 struct antenna_setup
*ant
)
706 const struct antenna_sel
*sel
;
712 * We should never come here because rt2x00lib is supposed
713 * to catch this and send us the correct antenna explicitely.
715 BUG_ON(ant
->rx
== ANTENNA_SW_DIVERSITY
||
716 ant
->tx
== ANTENNA_SW_DIVERSITY
);
718 if (rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
) {
720 lna
= rt2x00_has_cap_external_lna_a(rt2x00dev
);
722 sel
= antenna_sel_bg
;
723 lna
= rt2x00_has_cap_external_lna_bg(rt2x00dev
);
726 for (i
= 0; i
< ARRAY_SIZE(antenna_sel_a
); i
++)
727 rt61pci_bbp_write(rt2x00dev
, sel
[i
].word
, sel
[i
].value
[lna
]);
729 reg
= rt2x00mmio_register_read(rt2x00dev
, PHY_CSR0
);
731 rt2x00_set_field32(®
, PHY_CSR0_PA_PE_BG
,
732 rt2x00dev
->curr_band
== NL80211_BAND_2GHZ
);
733 rt2x00_set_field32(®
, PHY_CSR0_PA_PE_A
,
734 rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
);
736 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR0
, reg
);
738 if (rt2x00_rf(rt2x00dev
, RF5225
) || rt2x00_rf(rt2x00dev
, RF5325
))
739 rt61pci_config_antenna_5x(rt2x00dev
, ant
);
740 else if (rt2x00_rf(rt2x00dev
, RF2527
))
741 rt61pci_config_antenna_2x(rt2x00dev
, ant
);
742 else if (rt2x00_rf(rt2x00dev
, RF2529
)) {
743 if (rt2x00_has_cap_double_antenna(rt2x00dev
))
744 rt61pci_config_antenna_2x(rt2x00dev
, ant
);
746 rt61pci_config_antenna_2529(rt2x00dev
, ant
);
750 static void rt61pci_config_lna_gain(struct rt2x00_dev
*rt2x00dev
,
751 struct rt2x00lib_conf
*libconf
)
756 if (libconf
->conf
->chandef
.chan
->band
== NL80211_BAND_2GHZ
) {
757 if (rt2x00_has_cap_external_lna_bg(rt2x00dev
))
760 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
);
761 lna_gain
-= rt2x00_get_field16(eeprom
, EEPROM_RSSI_OFFSET_BG_1
);
763 if (rt2x00_has_cap_external_lna_a(rt2x00dev
))
766 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_A
);
767 lna_gain
-= rt2x00_get_field16(eeprom
, EEPROM_RSSI_OFFSET_A_1
);
770 rt2x00dev
->lna_gain
= lna_gain
;
773 static void rt61pci_config_channel(struct rt2x00_dev
*rt2x00dev
,
774 struct rf_channel
*rf
, const int txpower
)
780 rt2x00_set_field32(&rf
->rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
781 rt2x00_set_field32(&rf
->rf4
, RF4_FREQ_OFFSET
, rt2x00dev
->freq_offset
);
783 smart
= !(rt2x00_rf(rt2x00dev
, RF5225
) || rt2x00_rf(rt2x00dev
, RF2527
));
785 r3
= rt61pci_bbp_read(rt2x00dev
, 3);
786 rt2x00_set_field8(&r3
, BBP_R3_SMART_MODE
, smart
);
787 rt61pci_bbp_write(rt2x00dev
, 3, r3
);
790 if (txpower
> MAX_TXPOWER
&& txpower
<= (MAX_TXPOWER
+ r94
))
791 r94
+= txpower
- MAX_TXPOWER
;
792 else if (txpower
< MIN_TXPOWER
&& txpower
>= (MIN_TXPOWER
- r94
))
794 rt61pci_bbp_write(rt2x00dev
, 94, r94
);
796 rt61pci_rf_write(rt2x00dev
, 1, rf
->rf1
);
797 rt61pci_rf_write(rt2x00dev
, 2, rf
->rf2
);
798 rt61pci_rf_write(rt2x00dev
, 3, rf
->rf3
& ~0x00000004);
799 rt61pci_rf_write(rt2x00dev
, 4, rf
->rf4
);
803 rt61pci_rf_write(rt2x00dev
, 1, rf
->rf1
);
804 rt61pci_rf_write(rt2x00dev
, 2, rf
->rf2
);
805 rt61pci_rf_write(rt2x00dev
, 3, rf
->rf3
| 0x00000004);
806 rt61pci_rf_write(rt2x00dev
, 4, rf
->rf4
);
810 rt61pci_rf_write(rt2x00dev
, 1, rf
->rf1
);
811 rt61pci_rf_write(rt2x00dev
, 2, rf
->rf2
);
812 rt61pci_rf_write(rt2x00dev
, 3, rf
->rf3
& ~0x00000004);
813 rt61pci_rf_write(rt2x00dev
, 4, rf
->rf4
);
818 static void rt61pci_config_txpower(struct rt2x00_dev
*rt2x00dev
,
821 struct rf_channel rf
;
823 rf
.rf1
= rt2x00_rf_read(rt2x00dev
, 1);
824 rf
.rf2
= rt2x00_rf_read(rt2x00dev
, 2);
825 rf
.rf3
= rt2x00_rf_read(rt2x00dev
, 3);
826 rf
.rf4
= rt2x00_rf_read(rt2x00dev
, 4);
828 rt61pci_config_channel(rt2x00dev
, &rf
, txpower
);
831 static void rt61pci_config_retry_limit(struct rt2x00_dev
*rt2x00dev
,
832 struct rt2x00lib_conf
*libconf
)
836 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR4
);
837 rt2x00_set_field32(®
, TXRX_CSR4_OFDM_TX_RATE_DOWN
, 1);
838 rt2x00_set_field32(®
, TXRX_CSR4_OFDM_TX_RATE_STEP
, 0);
839 rt2x00_set_field32(®
, TXRX_CSR4_OFDM_TX_FALLBACK_CCK
, 0);
840 rt2x00_set_field32(®
, TXRX_CSR4_LONG_RETRY_LIMIT
,
841 libconf
->conf
->long_frame_max_tx_count
);
842 rt2x00_set_field32(®
, TXRX_CSR4_SHORT_RETRY_LIMIT
,
843 libconf
->conf
->short_frame_max_tx_count
);
844 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR4
, reg
);
847 static void rt61pci_config_ps(struct rt2x00_dev
*rt2x00dev
,
848 struct rt2x00lib_conf
*libconf
)
850 enum dev_state state
=
851 (libconf
->conf
->flags
& IEEE80211_CONF_PS
) ?
852 STATE_SLEEP
: STATE_AWAKE
;
855 if (state
== STATE_SLEEP
) {
856 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR11
);
857 rt2x00_set_field32(®
, MAC_CSR11_DELAY_AFTER_TBCN
,
858 rt2x00dev
->beacon_int
- 10);
859 rt2x00_set_field32(®
, MAC_CSR11_TBCN_BEFORE_WAKEUP
,
860 libconf
->conf
->listen_interval
- 1);
861 rt2x00_set_field32(®
, MAC_CSR11_WAKEUP_LATENCY
, 5);
863 /* We must first disable autowake before it can be enabled */
864 rt2x00_set_field32(®
, MAC_CSR11_AUTOWAKE
, 0);
865 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR11
, reg
);
867 rt2x00_set_field32(®
, MAC_CSR11_AUTOWAKE
, 1);
868 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR11
, reg
);
870 rt2x00mmio_register_write(rt2x00dev
, SOFT_RESET_CSR
,
872 rt2x00mmio_register_write(rt2x00dev
, IO_CNTL_CSR
, 0x0000001c);
873 rt2x00mmio_register_write(rt2x00dev
, PCI_USEC_CSR
, 0x00000060);
875 rt61pci_mcu_request(rt2x00dev
, MCU_SLEEP
, 0xff, 0, 0);
877 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR11
);
878 rt2x00_set_field32(®
, MAC_CSR11_DELAY_AFTER_TBCN
, 0);
879 rt2x00_set_field32(®
, MAC_CSR11_TBCN_BEFORE_WAKEUP
, 0);
880 rt2x00_set_field32(®
, MAC_CSR11_AUTOWAKE
, 0);
881 rt2x00_set_field32(®
, MAC_CSR11_WAKEUP_LATENCY
, 0);
882 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR11
, reg
);
884 rt2x00mmio_register_write(rt2x00dev
, SOFT_RESET_CSR
,
886 rt2x00mmio_register_write(rt2x00dev
, IO_CNTL_CSR
, 0x00000018);
887 rt2x00mmio_register_write(rt2x00dev
, PCI_USEC_CSR
, 0x00000020);
889 rt61pci_mcu_request(rt2x00dev
, MCU_WAKEUP
, 0xff, 0, 0);
893 static void rt61pci_config(struct rt2x00_dev
*rt2x00dev
,
894 struct rt2x00lib_conf
*libconf
,
895 const unsigned int flags
)
897 /* Always recalculate LNA gain before changing configuration */
898 rt61pci_config_lna_gain(rt2x00dev
, libconf
);
900 if (flags
& IEEE80211_CONF_CHANGE_CHANNEL
)
901 rt61pci_config_channel(rt2x00dev
, &libconf
->rf
,
902 libconf
->conf
->power_level
);
903 if ((flags
& IEEE80211_CONF_CHANGE_POWER
) &&
904 !(flags
& IEEE80211_CONF_CHANGE_CHANNEL
))
905 rt61pci_config_txpower(rt2x00dev
, libconf
->conf
->power_level
);
906 if (flags
& IEEE80211_CONF_CHANGE_RETRY_LIMITS
)
907 rt61pci_config_retry_limit(rt2x00dev
, libconf
);
908 if (flags
& IEEE80211_CONF_CHANGE_PS
)
909 rt61pci_config_ps(rt2x00dev
, libconf
);
915 static void rt61pci_link_stats(struct rt2x00_dev
*rt2x00dev
,
916 struct link_qual
*qual
)
921 * Update FCS error count from register.
923 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR0
);
924 qual
->rx_failed
= rt2x00_get_field32(reg
, STA_CSR0_FCS_ERROR
);
927 * Update False CCA count from register.
929 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR1
);
930 qual
->false_cca
= rt2x00_get_field32(reg
, STA_CSR1_FALSE_CCA_ERROR
);
933 static inline void rt61pci_set_vgc(struct rt2x00_dev
*rt2x00dev
,
934 struct link_qual
*qual
, u8 vgc_level
)
936 if (qual
->vgc_level
!= vgc_level
) {
937 rt61pci_bbp_write(rt2x00dev
, 17, vgc_level
);
938 qual
->vgc_level
= vgc_level
;
939 qual
->vgc_level_reg
= vgc_level
;
943 static void rt61pci_reset_tuner(struct rt2x00_dev
*rt2x00dev
,
944 struct link_qual
*qual
)
946 rt61pci_set_vgc(rt2x00dev
, qual
, 0x20);
949 static void rt61pci_link_tuner(struct rt2x00_dev
*rt2x00dev
,
950 struct link_qual
*qual
, const u32 count
)
956 * Determine r17 bounds.
958 if (rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
) {
961 if (rt2x00_has_cap_external_lna_a(rt2x00dev
)) {
968 if (rt2x00_has_cap_external_lna_bg(rt2x00dev
)) {
975 * If we are not associated, we should go straight to the
976 * dynamic CCA tuning.
978 if (!rt2x00dev
->intf_associated
)
979 goto dynamic_cca_tune
;
982 * Special big-R17 for very short distance
984 if (qual
->rssi
>= -35) {
985 rt61pci_set_vgc(rt2x00dev
, qual
, 0x60);
990 * Special big-R17 for short distance
992 if (qual
->rssi
>= -58) {
993 rt61pci_set_vgc(rt2x00dev
, qual
, up_bound
);
998 * Special big-R17 for middle-short distance
1000 if (qual
->rssi
>= -66) {
1001 rt61pci_set_vgc(rt2x00dev
, qual
, low_bound
+ 0x10);
1006 * Special mid-R17 for middle distance
1008 if (qual
->rssi
>= -74) {
1009 rt61pci_set_vgc(rt2x00dev
, qual
, low_bound
+ 0x08);
1014 * Special case: Change up_bound based on the rssi.
1015 * Lower up_bound when rssi is weaker then -74 dBm.
1017 up_bound
-= 2 * (-74 - qual
->rssi
);
1018 if (low_bound
> up_bound
)
1019 up_bound
= low_bound
;
1021 if (qual
->vgc_level
> up_bound
) {
1022 rt61pci_set_vgc(rt2x00dev
, qual
, up_bound
);
1029 * r17 does not yet exceed upper limit, continue and base
1030 * the r17 tuning on the false CCA count.
1032 if ((qual
->false_cca
> 512) && (qual
->vgc_level
< up_bound
))
1033 rt61pci_set_vgc(rt2x00dev
, qual
, ++qual
->vgc_level
);
1034 else if ((qual
->false_cca
< 100) && (qual
->vgc_level
> low_bound
))
1035 rt61pci_set_vgc(rt2x00dev
, qual
, --qual
->vgc_level
);
1041 static void rt61pci_start_queue(struct data_queue
*queue
)
1043 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
1046 switch (queue
->qid
) {
1048 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR0
);
1049 rt2x00_set_field32(®
, TXRX_CSR0_DISABLE_RX
, 0);
1050 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
1053 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
1054 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 1);
1055 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 1);
1056 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 1);
1057 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1064 static void rt61pci_kick_queue(struct data_queue
*queue
)
1066 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
1069 switch (queue
->qid
) {
1071 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1072 rt2x00_set_field32(®
, TX_CNTL_CSR_KICK_TX_AC0
, 1);
1073 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1076 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1077 rt2x00_set_field32(®
, TX_CNTL_CSR_KICK_TX_AC1
, 1);
1078 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1081 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1082 rt2x00_set_field32(®
, TX_CNTL_CSR_KICK_TX_AC2
, 1);
1083 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1086 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1087 rt2x00_set_field32(®
, TX_CNTL_CSR_KICK_TX_AC3
, 1);
1088 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1095 static void rt61pci_stop_queue(struct data_queue
*queue
)
1097 struct rt2x00_dev
*rt2x00dev
= queue
->rt2x00dev
;
1100 switch (queue
->qid
) {
1102 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1103 rt2x00_set_field32(®
, TX_CNTL_CSR_ABORT_TX_AC0
, 1);
1104 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1107 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1108 rt2x00_set_field32(®
, TX_CNTL_CSR_ABORT_TX_AC1
, 1);
1109 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1112 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1113 rt2x00_set_field32(®
, TX_CNTL_CSR_ABORT_TX_AC2
, 1);
1114 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1117 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_CNTL_CSR
);
1118 rt2x00_set_field32(®
, TX_CNTL_CSR_ABORT_TX_AC3
, 1);
1119 rt2x00mmio_register_write(rt2x00dev
, TX_CNTL_CSR
, reg
);
1122 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR0
);
1123 rt2x00_set_field32(®
, TXRX_CSR0_DISABLE_RX
, 1);
1124 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
1127 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
1128 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 0);
1129 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 0);
1130 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1131 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1134 * Wait for possibly running tbtt tasklets.
1136 tasklet_kill(&rt2x00dev
->tbtt_tasklet
);
1144 * Firmware functions
1146 static char *rt61pci_get_firmware_name(struct rt2x00_dev
*rt2x00dev
)
1151 pci_read_config_word(to_pci_dev(rt2x00dev
->dev
), PCI_DEVICE_ID
, &chip
);
1154 fw_name
= FIRMWARE_RT2561
;
1156 case RT2561s_PCI_ID
:
1157 fw_name
= FIRMWARE_RT2561s
;
1160 fw_name
= FIRMWARE_RT2661
;
1170 static int rt61pci_check_firmware(struct rt2x00_dev
*rt2x00dev
,
1171 const u8
*data
, const size_t len
)
1177 * Only support 8kb firmware files.
1180 return FW_BAD_LENGTH
;
1183 * The last 2 bytes in the firmware array are the crc checksum itself.
1184 * This means that we should never pass those 2 bytes to the crc
1187 fw_crc
= (data
[len
- 2] << 8 | data
[len
- 1]);
1190 * Use the crc itu-t algorithm.
1192 crc
= crc_itu_t(0, data
, len
- 2);
1193 crc
= crc_itu_t_byte(crc
, 0);
1194 crc
= crc_itu_t_byte(crc
, 0);
1196 return (fw_crc
== crc
) ? FW_OK
: FW_BAD_CRC
;
1199 static int rt61pci_load_firmware(struct rt2x00_dev
*rt2x00dev
,
1200 const u8
*data
, const size_t len
)
1206 * Wait for stable hardware.
1208 for (i
= 0; i
< 100; i
++) {
1209 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR0
);
1216 rt2x00_err(rt2x00dev
, "Unstable hardware\n");
1221 * Prepare MCU and mailbox for firmware loading.
1224 rt2x00_set_field32(®
, MCU_CNTL_CSR_RESET
, 1);
1225 rt2x00mmio_register_write(rt2x00dev
, MCU_CNTL_CSR
, reg
);
1226 rt2x00mmio_register_write(rt2x00dev
, M2H_CMD_DONE_CSR
, 0xffffffff);
1227 rt2x00mmio_register_write(rt2x00dev
, H2M_MAILBOX_CSR
, 0);
1228 rt2x00mmio_register_write(rt2x00dev
, HOST_CMD_CSR
, 0);
1231 * Write firmware to device.
1234 rt2x00_set_field32(®
, MCU_CNTL_CSR_RESET
, 1);
1235 rt2x00_set_field32(®
, MCU_CNTL_CSR_SELECT_BANK
, 1);
1236 rt2x00mmio_register_write(rt2x00dev
, MCU_CNTL_CSR
, reg
);
1238 rt2x00mmio_register_multiwrite(rt2x00dev
, FIRMWARE_IMAGE_BASE
,
1241 rt2x00_set_field32(®
, MCU_CNTL_CSR_SELECT_BANK
, 0);
1242 rt2x00mmio_register_write(rt2x00dev
, MCU_CNTL_CSR
, reg
);
1244 rt2x00_set_field32(®
, MCU_CNTL_CSR_RESET
, 0);
1245 rt2x00mmio_register_write(rt2x00dev
, MCU_CNTL_CSR
, reg
);
1247 for (i
= 0; i
< 100; i
++) {
1248 reg
= rt2x00mmio_register_read(rt2x00dev
, MCU_CNTL_CSR
);
1249 if (rt2x00_get_field32(reg
, MCU_CNTL_CSR_READY
))
1255 rt2x00_err(rt2x00dev
, "MCU Control register not ready\n");
1260 * Hardware needs another millisecond before it is ready.
1265 * Reset MAC and BBP registers.
1268 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 1);
1269 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 1);
1270 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1272 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR1
);
1273 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 0);
1274 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 0);
1275 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1277 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR1
);
1278 rt2x00_set_field32(®
, MAC_CSR1_HOST_READY
, 1);
1279 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1285 * Initialization functions.
1287 static bool rt61pci_get_entry_state(struct queue_entry
*entry
)
1289 struct queue_entry_priv_mmio
*entry_priv
= entry
->priv_data
;
1292 if (entry
->queue
->qid
== QID_RX
) {
1293 word
= rt2x00_desc_read(entry_priv
->desc
, 0);
1295 return rt2x00_get_field32(word
, RXD_W0_OWNER_NIC
);
1297 word
= rt2x00_desc_read(entry_priv
->desc
, 0);
1299 return (rt2x00_get_field32(word
, TXD_W0_OWNER_NIC
) ||
1300 rt2x00_get_field32(word
, TXD_W0_VALID
));
1304 static void rt61pci_clear_entry(struct queue_entry
*entry
)
1306 struct queue_entry_priv_mmio
*entry_priv
= entry
->priv_data
;
1307 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1310 if (entry
->queue
->qid
== QID_RX
) {
1311 word
= rt2x00_desc_read(entry_priv
->desc
, 5);
1312 rt2x00_set_field32(&word
, RXD_W5_BUFFER_PHYSICAL_ADDRESS
,
1314 rt2x00_desc_write(entry_priv
->desc
, 5, word
);
1316 word
= rt2x00_desc_read(entry_priv
->desc
, 0);
1317 rt2x00_set_field32(&word
, RXD_W0_OWNER_NIC
, 1);
1318 rt2x00_desc_write(entry_priv
->desc
, 0, word
);
1320 word
= rt2x00_desc_read(entry_priv
->desc
, 0);
1321 rt2x00_set_field32(&word
, TXD_W0_VALID
, 0);
1322 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 0);
1323 rt2x00_desc_write(entry_priv
->desc
, 0, word
);
1327 static int rt61pci_init_queues(struct rt2x00_dev
*rt2x00dev
)
1329 struct queue_entry_priv_mmio
*entry_priv
;
1333 * Initialize registers.
1335 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_RING_CSR0
);
1336 rt2x00_set_field32(®
, TX_RING_CSR0_AC0_RING_SIZE
,
1337 rt2x00dev
->tx
[0].limit
);
1338 rt2x00_set_field32(®
, TX_RING_CSR0_AC1_RING_SIZE
,
1339 rt2x00dev
->tx
[1].limit
);
1340 rt2x00_set_field32(®
, TX_RING_CSR0_AC2_RING_SIZE
,
1341 rt2x00dev
->tx
[2].limit
);
1342 rt2x00_set_field32(®
, TX_RING_CSR0_AC3_RING_SIZE
,
1343 rt2x00dev
->tx
[3].limit
);
1344 rt2x00mmio_register_write(rt2x00dev
, TX_RING_CSR0
, reg
);
1346 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_RING_CSR1
);
1347 rt2x00_set_field32(®
, TX_RING_CSR1_TXD_SIZE
,
1348 rt2x00dev
->tx
[0].desc_size
/ 4);
1349 rt2x00mmio_register_write(rt2x00dev
, TX_RING_CSR1
, reg
);
1351 entry_priv
= rt2x00dev
->tx
[0].entries
[0].priv_data
;
1352 reg
= rt2x00mmio_register_read(rt2x00dev
, AC0_BASE_CSR
);
1353 rt2x00_set_field32(®
, AC0_BASE_CSR_RING_REGISTER
,
1354 entry_priv
->desc_dma
);
1355 rt2x00mmio_register_write(rt2x00dev
, AC0_BASE_CSR
, reg
);
1357 entry_priv
= rt2x00dev
->tx
[1].entries
[0].priv_data
;
1358 reg
= rt2x00mmio_register_read(rt2x00dev
, AC1_BASE_CSR
);
1359 rt2x00_set_field32(®
, AC1_BASE_CSR_RING_REGISTER
,
1360 entry_priv
->desc_dma
);
1361 rt2x00mmio_register_write(rt2x00dev
, AC1_BASE_CSR
, reg
);
1363 entry_priv
= rt2x00dev
->tx
[2].entries
[0].priv_data
;
1364 reg
= rt2x00mmio_register_read(rt2x00dev
, AC2_BASE_CSR
);
1365 rt2x00_set_field32(®
, AC2_BASE_CSR_RING_REGISTER
,
1366 entry_priv
->desc_dma
);
1367 rt2x00mmio_register_write(rt2x00dev
, AC2_BASE_CSR
, reg
);
1369 entry_priv
= rt2x00dev
->tx
[3].entries
[0].priv_data
;
1370 reg
= rt2x00mmio_register_read(rt2x00dev
, AC3_BASE_CSR
);
1371 rt2x00_set_field32(®
, AC3_BASE_CSR_RING_REGISTER
,
1372 entry_priv
->desc_dma
);
1373 rt2x00mmio_register_write(rt2x00dev
, AC3_BASE_CSR
, reg
);
1375 reg
= rt2x00mmio_register_read(rt2x00dev
, RX_RING_CSR
);
1376 rt2x00_set_field32(®
, RX_RING_CSR_RING_SIZE
, rt2x00dev
->rx
->limit
);
1377 rt2x00_set_field32(®
, RX_RING_CSR_RXD_SIZE
,
1378 rt2x00dev
->rx
->desc_size
/ 4);
1379 rt2x00_set_field32(®
, RX_RING_CSR_RXD_WRITEBACK_SIZE
, 4);
1380 rt2x00mmio_register_write(rt2x00dev
, RX_RING_CSR
, reg
);
1382 entry_priv
= rt2x00dev
->rx
->entries
[0].priv_data
;
1383 reg
= rt2x00mmio_register_read(rt2x00dev
, RX_BASE_CSR
);
1384 rt2x00_set_field32(®
, RX_BASE_CSR_RING_REGISTER
,
1385 entry_priv
->desc_dma
);
1386 rt2x00mmio_register_write(rt2x00dev
, RX_BASE_CSR
, reg
);
1388 reg
= rt2x00mmio_register_read(rt2x00dev
, TX_DMA_DST_CSR
);
1389 rt2x00_set_field32(®
, TX_DMA_DST_CSR_DEST_AC0
, 2);
1390 rt2x00_set_field32(®
, TX_DMA_DST_CSR_DEST_AC1
, 2);
1391 rt2x00_set_field32(®
, TX_DMA_DST_CSR_DEST_AC2
, 2);
1392 rt2x00_set_field32(®
, TX_DMA_DST_CSR_DEST_AC3
, 2);
1393 rt2x00mmio_register_write(rt2x00dev
, TX_DMA_DST_CSR
, reg
);
1395 reg
= rt2x00mmio_register_read(rt2x00dev
, LOAD_TX_RING_CSR
);
1396 rt2x00_set_field32(®
, LOAD_TX_RING_CSR_LOAD_TXD_AC0
, 1);
1397 rt2x00_set_field32(®
, LOAD_TX_RING_CSR_LOAD_TXD_AC1
, 1);
1398 rt2x00_set_field32(®
, LOAD_TX_RING_CSR_LOAD_TXD_AC2
, 1);
1399 rt2x00_set_field32(®
, LOAD_TX_RING_CSR_LOAD_TXD_AC3
, 1);
1400 rt2x00mmio_register_write(rt2x00dev
, LOAD_TX_RING_CSR
, reg
);
1402 reg
= rt2x00mmio_register_read(rt2x00dev
, RX_CNTL_CSR
);
1403 rt2x00_set_field32(®
, RX_CNTL_CSR_LOAD_RXD
, 1);
1404 rt2x00mmio_register_write(rt2x00dev
, RX_CNTL_CSR
, reg
);
1409 static int rt61pci_init_registers(struct rt2x00_dev
*rt2x00dev
)
1413 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR0
);
1414 rt2x00_set_field32(®
, TXRX_CSR0_AUTO_TX_SEQ
, 1);
1415 rt2x00_set_field32(®
, TXRX_CSR0_DISABLE_RX
, 0);
1416 rt2x00_set_field32(®
, TXRX_CSR0_TX_WITHOUT_WAITING
, 0);
1417 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR0
, reg
);
1419 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR1
);
1420 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID0
, 47); /* CCK Signal */
1421 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID0_VALID
, 1);
1422 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID1
, 30); /* Rssi */
1423 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID1_VALID
, 1);
1424 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID2
, 42); /* OFDM Rate */
1425 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID2_VALID
, 1);
1426 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID3
, 30); /* Rssi */
1427 rt2x00_set_field32(®
, TXRX_CSR1_BBP_ID3_VALID
, 1);
1428 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR1
, reg
);
1431 * CCK TXD BBP registers
1433 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR2
);
1434 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID0
, 13);
1435 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID0_VALID
, 1);
1436 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID1
, 12);
1437 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID1_VALID
, 1);
1438 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID2
, 11);
1439 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID2_VALID
, 1);
1440 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID3
, 10);
1441 rt2x00_set_field32(®
, TXRX_CSR2_BBP_ID3_VALID
, 1);
1442 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR2
, reg
);
1445 * OFDM TXD BBP registers
1447 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR3
);
1448 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID0
, 7);
1449 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID0_VALID
, 1);
1450 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID1
, 6);
1451 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID1_VALID
, 1);
1452 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID2
, 5);
1453 rt2x00_set_field32(®
, TXRX_CSR3_BBP_ID2_VALID
, 1);
1454 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR3
, reg
);
1456 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR7
);
1457 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_6MBS
, 59);
1458 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_9MBS
, 53);
1459 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_12MBS
, 49);
1460 rt2x00_set_field32(®
, TXRX_CSR7_ACK_CTS_18MBS
, 46);
1461 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR7
, reg
);
1463 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR8
);
1464 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_24MBS
, 44);
1465 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_36MBS
, 42);
1466 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_48MBS
, 42);
1467 rt2x00_set_field32(®
, TXRX_CSR8_ACK_CTS_54MBS
, 42);
1468 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR8
, reg
);
1470 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
1471 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_INTERVAL
, 0);
1472 rt2x00_set_field32(®
, TXRX_CSR9_TSF_TICKING
, 0);
1473 rt2x00_set_field32(®
, TXRX_CSR9_TSF_SYNC
, 0);
1474 rt2x00_set_field32(®
, TXRX_CSR9_TBTT_ENABLE
, 0);
1475 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1476 rt2x00_set_field32(®
, TXRX_CSR9_TIMESTAMP_COMPENSATE
, 0);
1477 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1479 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR15
, 0x0000000f);
1481 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR6
, 0x00000fff);
1483 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR9
);
1484 rt2x00_set_field32(®
, MAC_CSR9_CW_SELECT
, 0);
1485 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR9
, reg
);
1487 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR10
, 0x0000071c);
1489 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
1492 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR13
, 0x0000e000);
1495 * Invalidate all Shared Keys (SEC_CSR0),
1496 * and clear the Shared key Cipher algorithms (SEC_CSR1 & SEC_CSR5)
1498 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR0
, 0x00000000);
1499 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR1
, 0x00000000);
1500 rt2x00mmio_register_write(rt2x00dev
, SEC_CSR5
, 0x00000000);
1502 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR1
, 0x000023b0);
1503 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR5
, 0x060a100c);
1504 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR6
, 0x00080606);
1505 rt2x00mmio_register_write(rt2x00dev
, PHY_CSR7
, 0x00000a08);
1507 rt2x00mmio_register_write(rt2x00dev
, PCI_CFG_CSR
, 0x28ca4404);
1509 rt2x00mmio_register_write(rt2x00dev
, TEST_MODE_CSR
, 0x00000200);
1511 rt2x00mmio_register_write(rt2x00dev
, M2H_CMD_DONE_CSR
, 0xffffffff);
1515 * For the Beacon base registers we only need to clear
1516 * the first byte since that byte contains the VALID and OWNER
1517 * bits which (when set to 0) will invalidate the entire beacon.
1519 rt2x00mmio_register_write(rt2x00dev
, HW_BEACON_BASE0
, 0);
1520 rt2x00mmio_register_write(rt2x00dev
, HW_BEACON_BASE1
, 0);
1521 rt2x00mmio_register_write(rt2x00dev
, HW_BEACON_BASE2
, 0);
1522 rt2x00mmio_register_write(rt2x00dev
, HW_BEACON_BASE3
, 0);
1525 * We must clear the error counters.
1526 * These registers are cleared on read,
1527 * so we may pass a useless variable to store the value.
1529 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR0
);
1530 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR1
);
1531 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR2
);
1534 * Reset MAC and BBP registers.
1536 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR1
);
1537 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 1);
1538 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 1);
1539 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1541 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR1
);
1542 rt2x00_set_field32(®
, MAC_CSR1_SOFT_RESET
, 0);
1543 rt2x00_set_field32(®
, MAC_CSR1_BBP_RESET
, 0);
1544 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1546 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR1
);
1547 rt2x00_set_field32(®
, MAC_CSR1_HOST_READY
, 1);
1548 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR1
, reg
);
1553 static int rt61pci_wait_bbp_ready(struct rt2x00_dev
*rt2x00dev
)
1558 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1559 value
= rt61pci_bbp_read(rt2x00dev
, 0);
1560 if ((value
!= 0xff) && (value
!= 0x00))
1562 udelay(REGISTER_BUSY_DELAY
);
1565 rt2x00_err(rt2x00dev
, "BBP register access failed, aborting\n");
1569 static int rt61pci_init_bbp(struct rt2x00_dev
*rt2x00dev
)
1576 if (unlikely(rt61pci_wait_bbp_ready(rt2x00dev
)))
1579 rt61pci_bbp_write(rt2x00dev
, 3, 0x00);
1580 rt61pci_bbp_write(rt2x00dev
, 15, 0x30);
1581 rt61pci_bbp_write(rt2x00dev
, 21, 0xc8);
1582 rt61pci_bbp_write(rt2x00dev
, 22, 0x38);
1583 rt61pci_bbp_write(rt2x00dev
, 23, 0x06);
1584 rt61pci_bbp_write(rt2x00dev
, 24, 0xfe);
1585 rt61pci_bbp_write(rt2x00dev
, 25, 0x0a);
1586 rt61pci_bbp_write(rt2x00dev
, 26, 0x0d);
1587 rt61pci_bbp_write(rt2x00dev
, 34, 0x12);
1588 rt61pci_bbp_write(rt2x00dev
, 37, 0x07);
1589 rt61pci_bbp_write(rt2x00dev
, 39, 0xf8);
1590 rt61pci_bbp_write(rt2x00dev
, 41, 0x60);
1591 rt61pci_bbp_write(rt2x00dev
, 53, 0x10);
1592 rt61pci_bbp_write(rt2x00dev
, 54, 0x18);
1593 rt61pci_bbp_write(rt2x00dev
, 60, 0x10);
1594 rt61pci_bbp_write(rt2x00dev
, 61, 0x04);
1595 rt61pci_bbp_write(rt2x00dev
, 62, 0x04);
1596 rt61pci_bbp_write(rt2x00dev
, 75, 0xfe);
1597 rt61pci_bbp_write(rt2x00dev
, 86, 0xfe);
1598 rt61pci_bbp_write(rt2x00dev
, 88, 0xfe);
1599 rt61pci_bbp_write(rt2x00dev
, 90, 0x0f);
1600 rt61pci_bbp_write(rt2x00dev
, 99, 0x00);
1601 rt61pci_bbp_write(rt2x00dev
, 102, 0x16);
1602 rt61pci_bbp_write(rt2x00dev
, 107, 0x04);
1604 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
1605 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
);
1607 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
1608 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
1609 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
1610 rt61pci_bbp_write(rt2x00dev
, reg_id
, value
);
1618 * Device state switch handlers.
1620 static void rt61pci_toggle_irq(struct rt2x00_dev
*rt2x00dev
,
1621 enum dev_state state
)
1623 int mask
= (state
== STATE_RADIO_IRQ_OFF
);
1625 unsigned long flags
;
1628 * When interrupts are being enabled, the interrupt registers
1629 * should clear the register to assure a clean state.
1631 if (state
== STATE_RADIO_IRQ_ON
) {
1632 reg
= rt2x00mmio_register_read(rt2x00dev
, INT_SOURCE_CSR
);
1633 rt2x00mmio_register_write(rt2x00dev
, INT_SOURCE_CSR
, reg
);
1635 reg
= rt2x00mmio_register_read(rt2x00dev
, MCU_INT_SOURCE_CSR
);
1636 rt2x00mmio_register_write(rt2x00dev
, MCU_INT_SOURCE_CSR
, reg
);
1640 * Only toggle the interrupts bits we are going to use.
1641 * Non-checked interrupt bits are disabled by default.
1643 spin_lock_irqsave(&rt2x00dev
->irqmask_lock
, flags
);
1645 reg
= rt2x00mmio_register_read(rt2x00dev
, INT_MASK_CSR
);
1646 rt2x00_set_field32(®
, INT_MASK_CSR_TXDONE
, mask
);
1647 rt2x00_set_field32(®
, INT_MASK_CSR_RXDONE
, mask
);
1648 rt2x00_set_field32(®
, INT_MASK_CSR_BEACON_DONE
, mask
);
1649 rt2x00_set_field32(®
, INT_MASK_CSR_ENABLE_MITIGATION
, mask
);
1650 rt2x00_set_field32(®
, INT_MASK_CSR_MITIGATION_PERIOD
, 0xff);
1651 rt2x00mmio_register_write(rt2x00dev
, INT_MASK_CSR
, reg
);
1653 reg
= rt2x00mmio_register_read(rt2x00dev
, MCU_INT_MASK_CSR
);
1654 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_0
, mask
);
1655 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_1
, mask
);
1656 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_2
, mask
);
1657 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_3
, mask
);
1658 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_4
, mask
);
1659 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_5
, mask
);
1660 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_6
, mask
);
1661 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_7
, mask
);
1662 rt2x00_set_field32(®
, MCU_INT_MASK_CSR_TWAKEUP
, mask
);
1663 rt2x00mmio_register_write(rt2x00dev
, MCU_INT_MASK_CSR
, reg
);
1665 spin_unlock_irqrestore(&rt2x00dev
->irqmask_lock
, flags
);
1667 if (state
== STATE_RADIO_IRQ_OFF
) {
1669 * Ensure that all tasklets are finished.
1671 tasklet_kill(&rt2x00dev
->txstatus_tasklet
);
1672 tasklet_kill(&rt2x00dev
->rxdone_tasklet
);
1673 tasklet_kill(&rt2x00dev
->autowake_tasklet
);
1674 tasklet_kill(&rt2x00dev
->tbtt_tasklet
);
1678 static int rt61pci_enable_radio(struct rt2x00_dev
*rt2x00dev
)
1683 * Initialize all registers.
1685 if (unlikely(rt61pci_init_queues(rt2x00dev
) ||
1686 rt61pci_init_registers(rt2x00dev
) ||
1687 rt61pci_init_bbp(rt2x00dev
)))
1693 reg
= rt2x00mmio_register_read(rt2x00dev
, RX_CNTL_CSR
);
1694 rt2x00_set_field32(®
, RX_CNTL_CSR_ENABLE_RX_DMA
, 1);
1695 rt2x00mmio_register_write(rt2x00dev
, RX_CNTL_CSR
, reg
);
1700 static void rt61pci_disable_radio(struct rt2x00_dev
*rt2x00dev
)
1705 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR10
, 0x00001818);
1708 static int rt61pci_set_state(struct rt2x00_dev
*rt2x00dev
, enum dev_state state
)
1714 put_to_sleep
= (state
!= STATE_AWAKE
);
1716 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR12
);
1717 rt2x00_set_field32(®
, MAC_CSR12_FORCE_WAKEUP
, !put_to_sleep
);
1718 rt2x00_set_field32(®
, MAC_CSR12_PUT_TO_SLEEP
, put_to_sleep
);
1719 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR12
, reg
);
1722 * Device is not guaranteed to be in the requested state yet.
1723 * We must wait until the register indicates that the
1724 * device has entered the correct state.
1726 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1727 reg2
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR12
);
1728 state
= rt2x00_get_field32(reg2
, MAC_CSR12_BBP_CURRENT_STATE
);
1729 if (state
== !put_to_sleep
)
1731 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR12
, reg
);
1738 static int rt61pci_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1739 enum dev_state state
)
1744 case STATE_RADIO_ON
:
1745 retval
= rt61pci_enable_radio(rt2x00dev
);
1747 case STATE_RADIO_OFF
:
1748 rt61pci_disable_radio(rt2x00dev
);
1750 case STATE_RADIO_IRQ_ON
:
1751 case STATE_RADIO_IRQ_OFF
:
1752 rt61pci_toggle_irq(rt2x00dev
, state
);
1754 case STATE_DEEP_SLEEP
:
1758 retval
= rt61pci_set_state(rt2x00dev
, state
);
1765 if (unlikely(retval
))
1766 rt2x00_err(rt2x00dev
, "Device failed to enter state %d (%d)\n",
1773 * TX descriptor initialization
1775 static void rt61pci_write_tx_desc(struct queue_entry
*entry
,
1776 struct txentry_desc
*txdesc
)
1778 struct skb_frame_desc
*skbdesc
= get_skb_frame_desc(entry
->skb
);
1779 struct queue_entry_priv_mmio
*entry_priv
= entry
->priv_data
;
1780 __le32
*txd
= entry_priv
->desc
;
1784 * Start writing the descriptor words.
1786 word
= rt2x00_desc_read(txd
, 1);
1787 rt2x00_set_field32(&word
, TXD_W1_HOST_Q_ID
, entry
->queue
->qid
);
1788 rt2x00_set_field32(&word
, TXD_W1_AIFSN
, entry
->queue
->aifs
);
1789 rt2x00_set_field32(&word
, TXD_W1_CWMIN
, entry
->queue
->cw_min
);
1790 rt2x00_set_field32(&word
, TXD_W1_CWMAX
, entry
->queue
->cw_max
);
1791 rt2x00_set_field32(&word
, TXD_W1_IV_OFFSET
, txdesc
->iv_offset
);
1792 rt2x00_set_field32(&word
, TXD_W1_HW_SEQUENCE
,
1793 test_bit(ENTRY_TXD_GENERATE_SEQ
, &txdesc
->flags
));
1794 rt2x00_set_field32(&word
, TXD_W1_BUFFER_COUNT
, 1);
1795 rt2x00_desc_write(txd
, 1, word
);
1797 word
= rt2x00_desc_read(txd
, 2);
1798 rt2x00_set_field32(&word
, TXD_W2_PLCP_SIGNAL
, txdesc
->u
.plcp
.signal
);
1799 rt2x00_set_field32(&word
, TXD_W2_PLCP_SERVICE
, txdesc
->u
.plcp
.service
);
1800 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_LOW
,
1801 txdesc
->u
.plcp
.length_low
);
1802 rt2x00_set_field32(&word
, TXD_W2_PLCP_LENGTH_HIGH
,
1803 txdesc
->u
.plcp
.length_high
);
1804 rt2x00_desc_write(txd
, 2, word
);
1806 if (test_bit(ENTRY_TXD_ENCRYPT
, &txdesc
->flags
)) {
1807 _rt2x00_desc_write(txd
, 3, skbdesc
->iv
[0]);
1808 _rt2x00_desc_write(txd
, 4, skbdesc
->iv
[1]);
1811 word
= rt2x00_desc_read(txd
, 5);
1812 rt2x00_set_field32(&word
, TXD_W5_PID_TYPE
, entry
->queue
->qid
);
1813 rt2x00_set_field32(&word
, TXD_W5_PID_SUBTYPE
, entry
->entry_idx
);
1814 rt2x00_set_field32(&word
, TXD_W5_TX_POWER
,
1815 TXPOWER_TO_DEV(entry
->queue
->rt2x00dev
->tx_power
));
1816 rt2x00_set_field32(&word
, TXD_W5_WAITING_DMA_DONE_INT
, 1);
1817 rt2x00_desc_write(txd
, 5, word
);
1819 if (entry
->queue
->qid
!= QID_BEACON
) {
1820 word
= rt2x00_desc_read(txd
, 6);
1821 rt2x00_set_field32(&word
, TXD_W6_BUFFER_PHYSICAL_ADDRESS
,
1823 rt2x00_desc_write(txd
, 6, word
);
1825 word
= rt2x00_desc_read(txd
, 11);
1826 rt2x00_set_field32(&word
, TXD_W11_BUFFER_LENGTH0
,
1828 rt2x00_desc_write(txd
, 11, word
);
1832 * Writing TXD word 0 must the last to prevent a race condition with
1833 * the device, whereby the device may take hold of the TXD before we
1834 * finished updating it.
1836 word
= rt2x00_desc_read(txd
, 0);
1837 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 1);
1838 rt2x00_set_field32(&word
, TXD_W0_VALID
, 1);
1839 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1840 test_bit(ENTRY_TXD_MORE_FRAG
, &txdesc
->flags
));
1841 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1842 test_bit(ENTRY_TXD_ACK
, &txdesc
->flags
));
1843 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1844 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &txdesc
->flags
));
1845 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1846 (txdesc
->rate_mode
== RATE_MODE_OFDM
));
1847 rt2x00_set_field32(&word
, TXD_W0_IFS
, txdesc
->u
.plcp
.ifs
);
1848 rt2x00_set_field32(&word
, TXD_W0_RETRY_MODE
,
1849 test_bit(ENTRY_TXD_RETRY_MODE
, &txdesc
->flags
));
1850 rt2x00_set_field32(&word
, TXD_W0_TKIP_MIC
,
1851 test_bit(ENTRY_TXD_ENCRYPT_MMIC
, &txdesc
->flags
));
1852 rt2x00_set_field32(&word
, TXD_W0_KEY_TABLE
,
1853 test_bit(ENTRY_TXD_ENCRYPT_PAIRWISE
, &txdesc
->flags
));
1854 rt2x00_set_field32(&word
, TXD_W0_KEY_INDEX
, txdesc
->key_idx
);
1855 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, txdesc
->length
);
1856 rt2x00_set_field32(&word
, TXD_W0_BURST
,
1857 test_bit(ENTRY_TXD_BURST
, &txdesc
->flags
));
1858 rt2x00_set_field32(&word
, TXD_W0_CIPHER_ALG
, txdesc
->cipher
);
1859 rt2x00_desc_write(txd
, 0, word
);
1862 * Register descriptor details in skb frame descriptor.
1864 skbdesc
->desc
= txd
;
1865 skbdesc
->desc_len
= (entry
->queue
->qid
== QID_BEACON
) ? TXINFO_SIZE
:
1870 * TX data initialization
1872 static void rt61pci_write_beacon(struct queue_entry
*entry
,
1873 struct txentry_desc
*txdesc
)
1875 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1876 struct queue_entry_priv_mmio
*entry_priv
= entry
->priv_data
;
1877 unsigned int beacon_base
;
1878 unsigned int padding_len
;
1882 * Disable beaconing while we are reloading the beacon data,
1883 * otherwise we might be sending out invalid data.
1885 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
1887 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1888 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1891 * Write the TX descriptor for the beacon.
1893 rt61pci_write_tx_desc(entry
, txdesc
);
1896 * Dump beacon to userspace through debugfs.
1898 rt2x00debug_dump_frame(rt2x00dev
, DUMP_FRAME_BEACON
, entry
);
1901 * Write entire beacon with descriptor and padding to register.
1903 padding_len
= roundup(entry
->skb
->len
, 4) - entry
->skb
->len
;
1904 if (padding_len
&& skb_pad(entry
->skb
, padding_len
)) {
1905 rt2x00_err(rt2x00dev
, "Failure padding beacon, aborting\n");
1906 /* skb freed by skb_pad() on failure */
1908 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, orig_reg
);
1912 beacon_base
= HW_BEACON_OFFSET(entry
->entry_idx
);
1913 rt2x00mmio_register_multiwrite(rt2x00dev
, beacon_base
,
1914 entry_priv
->desc
, TXINFO_SIZE
);
1915 rt2x00mmio_register_multiwrite(rt2x00dev
, beacon_base
+ TXINFO_SIZE
,
1917 entry
->skb
->len
+ padding_len
);
1920 * Enable beaconing again.
1922 * For Wi-Fi faily generated beacons between participating
1923 * stations. Set TBTT phase adaptive adjustment step to 8us.
1925 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR10
, 0x00001008);
1927 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 1);
1928 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1931 * Clean up beacon skb.
1933 dev_kfree_skb_any(entry
->skb
);
1937 static void rt61pci_clear_beacon(struct queue_entry
*entry
)
1939 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1943 * Disable beaconing while we are reloading the beacon data,
1944 * otherwise we might be sending out invalid data.
1946 orig_reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR9
);
1948 rt2x00_set_field32(®
, TXRX_CSR9_BEACON_GEN
, 0);
1949 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, reg
);
1954 rt2x00mmio_register_write(rt2x00dev
,
1955 HW_BEACON_OFFSET(entry
->entry_idx
), 0);
1958 * Restore global beaconing state.
1960 rt2x00mmio_register_write(rt2x00dev
, TXRX_CSR9
, orig_reg
);
1964 * RX control handlers
1966 static int rt61pci_agc_to_rssi(struct rt2x00_dev
*rt2x00dev
, int rxd_w1
)
1968 u8 offset
= rt2x00dev
->lna_gain
;
1971 lna
= rt2x00_get_field32(rxd_w1
, RXD_W1_RSSI_LNA
);
1986 if (rt2x00dev
->curr_band
== NL80211_BAND_5GHZ
) {
1987 if (lna
== 3 || lna
== 2)
1991 return rt2x00_get_field32(rxd_w1
, RXD_W1_RSSI_AGC
) * 2 - offset
;
1994 static void rt61pci_fill_rxdone(struct queue_entry
*entry
,
1995 struct rxdone_entry_desc
*rxdesc
)
1997 struct rt2x00_dev
*rt2x00dev
= entry
->queue
->rt2x00dev
;
1998 struct queue_entry_priv_mmio
*entry_priv
= entry
->priv_data
;
2002 word0
= rt2x00_desc_read(entry_priv
->desc
, 0);
2003 word1
= rt2x00_desc_read(entry_priv
->desc
, 1);
2005 if (rt2x00_get_field32(word0
, RXD_W0_CRC_ERROR
))
2006 rxdesc
->flags
|= RX_FLAG_FAILED_FCS_CRC
;
2008 rxdesc
->cipher
= rt2x00_get_field32(word0
, RXD_W0_CIPHER_ALG
);
2009 rxdesc
->cipher_status
= rt2x00_get_field32(word0
, RXD_W0_CIPHER_ERROR
);
2011 if (rxdesc
->cipher
!= CIPHER_NONE
) {
2012 rxdesc
->iv
[0] = _rt2x00_desc_read(entry_priv
->desc
, 2);
2013 rxdesc
->iv
[1] = _rt2x00_desc_read(entry_priv
->desc
, 3);
2014 rxdesc
->dev_flags
|= RXDONE_CRYPTO_IV
;
2016 rxdesc
->icv
= _rt2x00_desc_read(entry_priv
->desc
, 4);
2017 rxdesc
->dev_flags
|= RXDONE_CRYPTO_ICV
;
2020 * Hardware has stripped IV/EIV data from 802.11 frame during
2021 * decryption. It has provided the data separately but rt2x00lib
2022 * should decide if it should be reinserted.
2024 rxdesc
->flags
|= RX_FLAG_IV_STRIPPED
;
2027 * The hardware has already checked the Michael Mic and has
2028 * stripped it from the frame. Signal this to mac80211.
2030 rxdesc
->flags
|= RX_FLAG_MMIC_STRIPPED
;
2032 if (rxdesc
->cipher_status
== RX_CRYPTO_SUCCESS
)
2033 rxdesc
->flags
|= RX_FLAG_DECRYPTED
;
2034 else if (rxdesc
->cipher_status
== RX_CRYPTO_FAIL_MIC
)
2035 rxdesc
->flags
|= RX_FLAG_MMIC_ERROR
;
2039 * Obtain the status about this packet.
2040 * When frame was received with an OFDM bitrate,
2041 * the signal is the PLCP value. If it was received with
2042 * a CCK bitrate the signal is the rate in 100kbit/s.
2044 rxdesc
->signal
= rt2x00_get_field32(word1
, RXD_W1_SIGNAL
);
2045 rxdesc
->rssi
= rt61pci_agc_to_rssi(rt2x00dev
, word1
);
2046 rxdesc
->size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
2048 if (rt2x00_get_field32(word0
, RXD_W0_OFDM
))
2049 rxdesc
->dev_flags
|= RXDONE_SIGNAL_PLCP
;
2051 rxdesc
->dev_flags
|= RXDONE_SIGNAL_BITRATE
;
2052 if (rt2x00_get_field32(word0
, RXD_W0_MY_BSS
))
2053 rxdesc
->dev_flags
|= RXDONE_MY_BSS
;
2057 * Interrupt functions.
2059 static void rt61pci_txdone(struct rt2x00_dev
*rt2x00dev
)
2061 struct data_queue
*queue
;
2062 struct queue_entry
*entry
;
2063 struct queue_entry
*entry_done
;
2064 struct queue_entry_priv_mmio
*entry_priv
;
2065 struct txdone_entry_desc txdesc
;
2073 * TX_STA_FIFO is a stack of X entries, hence read TX_STA_FIFO
2074 * at most X times and also stop processing once the TX_STA_FIFO_VALID
2075 * flag is not set anymore.
2077 * The legacy drivers use X=TX_RING_SIZE but state in a comment
2078 * that the TX_STA_FIFO stack has a size of 16. We stick to our
2079 * tx ring size for now.
2081 for (i
= 0; i
< rt2x00dev
->tx
->limit
; i
++) {
2082 reg
= rt2x00mmio_register_read(rt2x00dev
, STA_CSR4
);
2083 if (!rt2x00_get_field32(reg
, STA_CSR4_VALID
))
2087 * Skip this entry when it contains an invalid
2088 * queue identication number.
2090 type
= rt2x00_get_field32(reg
, STA_CSR4_PID_TYPE
);
2091 queue
= rt2x00queue_get_tx_queue(rt2x00dev
, type
);
2092 if (unlikely(!queue
))
2096 * Skip this entry when it contains an invalid
2099 index
= rt2x00_get_field32(reg
, STA_CSR4_PID_SUBTYPE
);
2100 if (unlikely(index
>= queue
->limit
))
2103 entry
= &queue
->entries
[index
];
2104 entry_priv
= entry
->priv_data
;
2105 word
= rt2x00_desc_read(entry_priv
->desc
, 0);
2107 if (rt2x00_get_field32(word
, TXD_W0_OWNER_NIC
) ||
2108 !rt2x00_get_field32(word
, TXD_W0_VALID
))
2111 entry_done
= rt2x00queue_get_entry(queue
, Q_INDEX_DONE
);
2112 while (entry
!= entry_done
) {
2114 * Just report any entries we missed as failed.
2116 rt2x00_warn(rt2x00dev
, "TX status report missed for entry %d\n",
2117 entry_done
->entry_idx
);
2119 rt2x00lib_txdone_noinfo(entry_done
, TXDONE_UNKNOWN
);
2120 entry_done
= rt2x00queue_get_entry(queue
, Q_INDEX_DONE
);
2124 * Obtain the status about this packet.
2127 switch (rt2x00_get_field32(reg
, STA_CSR4_TX_RESULT
)) {
2128 case 0: /* Success, maybe with retry */
2129 __set_bit(TXDONE_SUCCESS
, &txdesc
.flags
);
2131 case 6: /* Failure, excessive retries */
2132 __set_bit(TXDONE_EXCESSIVE_RETRY
, &txdesc
.flags
);
2133 /* Fall through - this is a failed frame! */
2134 default: /* Failure */
2135 __set_bit(TXDONE_FAILURE
, &txdesc
.flags
);
2137 txdesc
.retry
= rt2x00_get_field32(reg
, STA_CSR4_RETRY_COUNT
);
2140 * the frame was retried at least once
2141 * -> hw used fallback rates
2144 __set_bit(TXDONE_FALLBACK
, &txdesc
.flags
);
2146 rt2x00lib_txdone(entry
, &txdesc
);
2150 static void rt61pci_wakeup(struct rt2x00_dev
*rt2x00dev
)
2152 struct rt2x00lib_conf libconf
= { .conf
= &rt2x00dev
->hw
->conf
};
2154 rt61pci_config(rt2x00dev
, &libconf
, IEEE80211_CONF_CHANGE_PS
);
2157 static inline void rt61pci_enable_interrupt(struct rt2x00_dev
*rt2x00dev
,
2158 struct rt2x00_field32 irq_field
)
2163 * Enable a single interrupt. The interrupt mask register
2164 * access needs locking.
2166 spin_lock_irq(&rt2x00dev
->irqmask_lock
);
2168 reg
= rt2x00mmio_register_read(rt2x00dev
, INT_MASK_CSR
);
2169 rt2x00_set_field32(®
, irq_field
, 0);
2170 rt2x00mmio_register_write(rt2x00dev
, INT_MASK_CSR
, reg
);
2172 spin_unlock_irq(&rt2x00dev
->irqmask_lock
);
2175 static void rt61pci_enable_mcu_interrupt(struct rt2x00_dev
*rt2x00dev
,
2176 struct rt2x00_field32 irq_field
)
2181 * Enable a single MCU interrupt. The interrupt mask register
2182 * access needs locking.
2184 spin_lock_irq(&rt2x00dev
->irqmask_lock
);
2186 reg
= rt2x00mmio_register_read(rt2x00dev
, MCU_INT_MASK_CSR
);
2187 rt2x00_set_field32(®
, irq_field
, 0);
2188 rt2x00mmio_register_write(rt2x00dev
, MCU_INT_MASK_CSR
, reg
);
2190 spin_unlock_irq(&rt2x00dev
->irqmask_lock
);
2193 static void rt61pci_txstatus_tasklet(unsigned long data
)
2195 struct rt2x00_dev
*rt2x00dev
= (struct rt2x00_dev
*)data
;
2196 rt61pci_txdone(rt2x00dev
);
2197 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
2198 rt61pci_enable_interrupt(rt2x00dev
, INT_MASK_CSR_TXDONE
);
2201 static void rt61pci_tbtt_tasklet(unsigned long data
)
2203 struct rt2x00_dev
*rt2x00dev
= (struct rt2x00_dev
*)data
;
2204 rt2x00lib_beacondone(rt2x00dev
);
2205 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
2206 rt61pci_enable_interrupt(rt2x00dev
, INT_MASK_CSR_BEACON_DONE
);
2209 static void rt61pci_rxdone_tasklet(unsigned long data
)
2211 struct rt2x00_dev
*rt2x00dev
= (struct rt2x00_dev
*)data
;
2212 if (rt2x00mmio_rxdone(rt2x00dev
))
2213 tasklet_schedule(&rt2x00dev
->rxdone_tasklet
);
2214 else if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
2215 rt61pci_enable_interrupt(rt2x00dev
, INT_MASK_CSR_RXDONE
);
2218 static void rt61pci_autowake_tasklet(unsigned long data
)
2220 struct rt2x00_dev
*rt2x00dev
= (struct rt2x00_dev
*)data
;
2221 rt61pci_wakeup(rt2x00dev
);
2222 rt2x00mmio_register_write(rt2x00dev
,
2223 M2H_CMD_DONE_CSR
, 0xffffffff);
2224 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
2225 rt61pci_enable_mcu_interrupt(rt2x00dev
, MCU_INT_MASK_CSR_TWAKEUP
);
2228 static irqreturn_t
rt61pci_interrupt(int irq
, void *dev_instance
)
2230 struct rt2x00_dev
*rt2x00dev
= dev_instance
;
2231 u32 reg_mcu
, mask_mcu
;
2235 * Get the interrupt sources & saved to local variable.
2236 * Write register value back to clear pending interrupts.
2238 reg_mcu
= rt2x00mmio_register_read(rt2x00dev
, MCU_INT_SOURCE_CSR
);
2239 rt2x00mmio_register_write(rt2x00dev
, MCU_INT_SOURCE_CSR
, reg_mcu
);
2241 reg
= rt2x00mmio_register_read(rt2x00dev
, INT_SOURCE_CSR
);
2242 rt2x00mmio_register_write(rt2x00dev
, INT_SOURCE_CSR
, reg
);
2244 if (!reg
&& !reg_mcu
)
2247 if (!test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
2251 * Schedule tasklets for interrupt handling.
2253 if (rt2x00_get_field32(reg
, INT_SOURCE_CSR_RXDONE
))
2254 tasklet_schedule(&rt2x00dev
->rxdone_tasklet
);
2256 if (rt2x00_get_field32(reg
, INT_SOURCE_CSR_TXDONE
))
2257 tasklet_schedule(&rt2x00dev
->txstatus_tasklet
);
2259 if (rt2x00_get_field32(reg
, INT_SOURCE_CSR_BEACON_DONE
))
2260 tasklet_hi_schedule(&rt2x00dev
->tbtt_tasklet
);
2262 if (rt2x00_get_field32(reg_mcu
, MCU_INT_SOURCE_CSR_TWAKEUP
))
2263 tasklet_schedule(&rt2x00dev
->autowake_tasklet
);
2266 * Since INT_MASK_CSR and INT_SOURCE_CSR use the same bits
2267 * for interrupts and interrupt masks we can just use the value of
2268 * INT_SOURCE_CSR to create the interrupt mask.
2274 * Disable all interrupts for which a tasklet was scheduled right now,
2275 * the tasklet will reenable the appropriate interrupts.
2277 spin_lock(&rt2x00dev
->irqmask_lock
);
2279 reg
= rt2x00mmio_register_read(rt2x00dev
, INT_MASK_CSR
);
2281 rt2x00mmio_register_write(rt2x00dev
, INT_MASK_CSR
, reg
);
2283 reg
= rt2x00mmio_register_read(rt2x00dev
, MCU_INT_MASK_CSR
);
2285 rt2x00mmio_register_write(rt2x00dev
, MCU_INT_MASK_CSR
, reg
);
2287 spin_unlock(&rt2x00dev
->irqmask_lock
);
2293 * Device probe functions.
2295 static int rt61pci_validate_eeprom(struct rt2x00_dev
*rt2x00dev
)
2297 struct eeprom_93cx6 eeprom
;
2303 reg
= rt2x00mmio_register_read(rt2x00dev
, E2PROM_CSR
);
2305 eeprom
.data
= rt2x00dev
;
2306 eeprom
.register_read
= rt61pci_eepromregister_read
;
2307 eeprom
.register_write
= rt61pci_eepromregister_write
;
2308 eeprom
.width
= rt2x00_get_field32(reg
, E2PROM_CSR_TYPE_93C46
) ?
2309 PCI_EEPROM_WIDTH_93C46
: PCI_EEPROM_WIDTH_93C66
;
2310 eeprom
.reg_data_in
= 0;
2311 eeprom
.reg_data_out
= 0;
2312 eeprom
.reg_data_clock
= 0;
2313 eeprom
.reg_chip_select
= 0;
2315 eeprom_93cx6_multiread(&eeprom
, EEPROM_BASE
, rt2x00dev
->eeprom
,
2316 EEPROM_SIZE
/ sizeof(u16
));
2319 * Start validation of the data that has been read.
2321 mac
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
2322 rt2x00lib_set_mac_address(rt2x00dev
, mac
);
2324 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
);
2325 if (word
== 0xffff) {
2326 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
2327 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
,
2329 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
,
2331 rt2x00_set_field16(&word
, EEPROM_ANTENNA_FRAME_TYPE
, 0);
2332 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
2333 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
2334 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF5225
);
2335 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
2336 rt2x00_eeprom_dbg(rt2x00dev
, "Antenna: 0x%04x\n", word
);
2339 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
);
2340 if (word
== 0xffff) {
2341 rt2x00_set_field16(&word
, EEPROM_NIC_ENABLE_DIVERSITY
, 0);
2342 rt2x00_set_field16(&word
, EEPROM_NIC_TX_DIVERSITY
, 0);
2343 rt2x00_set_field16(&word
, EEPROM_NIC_RX_FIXED
, 0);
2344 rt2x00_set_field16(&word
, EEPROM_NIC_TX_FIXED
, 0);
2345 rt2x00_set_field16(&word
, EEPROM_NIC_EXTERNAL_LNA_BG
, 0);
2346 rt2x00_set_field16(&word
, EEPROM_NIC_CARDBUS_ACCEL
, 0);
2347 rt2x00_set_field16(&word
, EEPROM_NIC_EXTERNAL_LNA_A
, 0);
2348 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
2349 rt2x00_eeprom_dbg(rt2x00dev
, "NIC: 0x%04x\n", word
);
2352 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_LED
);
2353 if (word
== 0xffff) {
2354 rt2x00_set_field16(&word
, EEPROM_LED_LED_MODE
,
2356 rt2x00_eeprom_write(rt2x00dev
, EEPROM_LED
, word
);
2357 rt2x00_eeprom_dbg(rt2x00dev
, "Led: 0x%04x\n", word
);
2360 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_FREQ
);
2361 if (word
== 0xffff) {
2362 rt2x00_set_field16(&word
, EEPROM_FREQ_OFFSET
, 0);
2363 rt2x00_set_field16(&word
, EEPROM_FREQ_SEQ
, 0);
2364 rt2x00_eeprom_write(rt2x00dev
, EEPROM_FREQ
, word
);
2365 rt2x00_eeprom_dbg(rt2x00dev
, "Freq: 0x%04x\n", word
);
2368 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
);
2369 if (word
== 0xffff) {
2370 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_1
, 0);
2371 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_2
, 0);
2372 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, word
);
2373 rt2x00_eeprom_dbg(rt2x00dev
, "RSSI OFFSET BG: 0x%04x\n", word
);
2375 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_BG_1
);
2376 if (value
< -10 || value
> 10)
2377 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_1
, 0);
2378 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_BG_2
);
2379 if (value
< -10 || value
> 10)
2380 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_BG_2
, 0);
2381 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_BG
, word
);
2384 word
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_RSSI_OFFSET_A
);
2385 if (word
== 0xffff) {
2386 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_1
, 0);
2387 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_2
, 0);
2388 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, word
);
2389 rt2x00_eeprom_dbg(rt2x00dev
, "RSSI OFFSET A: 0x%04x\n", word
);
2391 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_A_1
);
2392 if (value
< -10 || value
> 10)
2393 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_1
, 0);
2394 value
= rt2x00_get_field16(word
, EEPROM_RSSI_OFFSET_A_2
);
2395 if (value
< -10 || value
> 10)
2396 rt2x00_set_field16(&word
, EEPROM_RSSI_OFFSET_A_2
, 0);
2397 rt2x00_eeprom_write(rt2x00dev
, EEPROM_RSSI_OFFSET_A
, word
);
2403 static int rt61pci_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
2410 * Read EEPROM word for configuration.
2412 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
);
2415 * Identify RF chipset.
2417 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
2418 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR0
);
2419 rt2x00_set_chip(rt2x00dev
, rt2x00_get_field32(reg
, MAC_CSR0_CHIPSET
),
2420 value
, rt2x00_get_field32(reg
, MAC_CSR0_REVISION
));
2422 if (!rt2x00_rf(rt2x00dev
, RF5225
) &&
2423 !rt2x00_rf(rt2x00dev
, RF5325
) &&
2424 !rt2x00_rf(rt2x00dev
, RF2527
) &&
2425 !rt2x00_rf(rt2x00dev
, RF2529
)) {
2426 rt2x00_err(rt2x00dev
, "Invalid RF chipset detected\n");
2431 * Determine number of antennas.
2433 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_NUM
) == 2)
2434 __set_bit(CAPABILITY_DOUBLE_ANTENNA
, &rt2x00dev
->cap_flags
);
2437 * Identify default antenna configuration.
2439 rt2x00dev
->default_ant
.tx
=
2440 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_TX_DEFAULT
);
2441 rt2x00dev
->default_ant
.rx
=
2442 rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RX_DEFAULT
);
2445 * Read the Frame type.
2447 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_FRAME_TYPE
))
2448 __set_bit(CAPABILITY_FRAME_TYPE
, &rt2x00dev
->cap_flags
);
2451 * Detect if this device has a hardware controlled radio.
2453 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_HARDWARE_RADIO
))
2454 __set_bit(CAPABILITY_HW_BUTTON
, &rt2x00dev
->cap_flags
);
2457 * Read frequency offset and RF programming sequence.
2459 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_FREQ
);
2460 if (rt2x00_get_field16(eeprom
, EEPROM_FREQ_SEQ
))
2461 __set_bit(CAPABILITY_RF_SEQUENCE
, &rt2x00dev
->cap_flags
);
2463 rt2x00dev
->freq_offset
= rt2x00_get_field16(eeprom
, EEPROM_FREQ_OFFSET
);
2466 * Read external LNA informations.
2468 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
);
2470 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_EXTERNAL_LNA_A
))
2471 __set_bit(CAPABILITY_EXTERNAL_LNA_A
, &rt2x00dev
->cap_flags
);
2472 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_EXTERNAL_LNA_BG
))
2473 __set_bit(CAPABILITY_EXTERNAL_LNA_BG
, &rt2x00dev
->cap_flags
);
2476 * When working with a RF2529 chip without double antenna,
2477 * the antenna settings should be gathered from the NIC
2480 if (rt2x00_rf(rt2x00dev
, RF2529
) &&
2481 !rt2x00_has_cap_double_antenna(rt2x00dev
)) {
2482 rt2x00dev
->default_ant
.rx
=
2483 ANTENNA_A
+ rt2x00_get_field16(eeprom
, EEPROM_NIC_RX_FIXED
);
2484 rt2x00dev
->default_ant
.tx
=
2485 ANTENNA_B
- rt2x00_get_field16(eeprom
, EEPROM_NIC_TX_FIXED
);
2487 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_TX_DIVERSITY
))
2488 rt2x00dev
->default_ant
.tx
= ANTENNA_SW_DIVERSITY
;
2489 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_ENABLE_DIVERSITY
))
2490 rt2x00dev
->default_ant
.rx
= ANTENNA_SW_DIVERSITY
;
2494 * Store led settings, for correct led behaviour.
2495 * If the eeprom value is invalid,
2496 * switch to default led mode.
2498 #ifdef CONFIG_RT2X00_LIB_LEDS
2499 eeprom
= rt2x00_eeprom_read(rt2x00dev
, EEPROM_LED
);
2500 value
= rt2x00_get_field16(eeprom
, EEPROM_LED_LED_MODE
);
2502 rt61pci_init_led(rt2x00dev
, &rt2x00dev
->led_radio
, LED_TYPE_RADIO
);
2503 rt61pci_init_led(rt2x00dev
, &rt2x00dev
->led_assoc
, LED_TYPE_ASSOC
);
2504 if (value
== LED_MODE_SIGNAL_STRENGTH
)
2505 rt61pci_init_led(rt2x00dev
, &rt2x00dev
->led_qual
,
2508 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_LED_MODE
, value
);
2509 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_0
,
2510 rt2x00_get_field16(eeprom
,
2511 EEPROM_LED_POLARITY_GPIO_0
));
2512 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_1
,
2513 rt2x00_get_field16(eeprom
,
2514 EEPROM_LED_POLARITY_GPIO_1
));
2515 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_2
,
2516 rt2x00_get_field16(eeprom
,
2517 EEPROM_LED_POLARITY_GPIO_2
));
2518 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_3
,
2519 rt2x00_get_field16(eeprom
,
2520 EEPROM_LED_POLARITY_GPIO_3
));
2521 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_GPIO_4
,
2522 rt2x00_get_field16(eeprom
,
2523 EEPROM_LED_POLARITY_GPIO_4
));
2524 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_ACT
,
2525 rt2x00_get_field16(eeprom
, EEPROM_LED_POLARITY_ACT
));
2526 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_READY_BG
,
2527 rt2x00_get_field16(eeprom
,
2528 EEPROM_LED_POLARITY_RDY_G
));
2529 rt2x00_set_field16(&rt2x00dev
->led_mcu_reg
, MCU_LEDCS_POLARITY_READY_A
,
2530 rt2x00_get_field16(eeprom
,
2531 EEPROM_LED_POLARITY_RDY_A
));
2532 #endif /* CONFIG_RT2X00_LIB_LEDS */
2538 * RF value list for RF5225 & RF5325
2539 * Supports: 2.4 GHz & 5.2 GHz, rf_sequence disabled
2541 static const struct rf_channel rf_vals_noseq
[] = {
2542 { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
2543 { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
2544 { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
2545 { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
2546 { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
2547 { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
2548 { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
2549 { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
2550 { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
2551 { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
2552 { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
2553 { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
2554 { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
2555 { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
2557 /* 802.11 UNI / HyperLan 2 */
2558 { 36, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa23 },
2559 { 40, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa03 },
2560 { 44, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa0b },
2561 { 48, 0x00002ccc, 0x000049aa, 0x0009be55, 0x000ffa13 },
2562 { 52, 0x00002ccc, 0x000049ae, 0x0009ae55, 0x000ffa1b },
2563 { 56, 0x00002ccc, 0x000049b2, 0x0009ae55, 0x000ffa23 },
2564 { 60, 0x00002ccc, 0x000049ba, 0x0009ae55, 0x000ffa03 },
2565 { 64, 0x00002ccc, 0x000049be, 0x0009ae55, 0x000ffa0b },
2567 /* 802.11 HyperLan 2 */
2568 { 100, 0x00002ccc, 0x00004a2a, 0x000bae55, 0x000ffa03 },
2569 { 104, 0x00002ccc, 0x00004a2e, 0x000bae55, 0x000ffa0b },
2570 { 108, 0x00002ccc, 0x00004a32, 0x000bae55, 0x000ffa13 },
2571 { 112, 0x00002ccc, 0x00004a36, 0x000bae55, 0x000ffa1b },
2572 { 116, 0x00002ccc, 0x00004a3a, 0x000bbe55, 0x000ffa23 },
2573 { 120, 0x00002ccc, 0x00004a82, 0x000bbe55, 0x000ffa03 },
2574 { 124, 0x00002ccc, 0x00004a86, 0x000bbe55, 0x000ffa0b },
2575 { 128, 0x00002ccc, 0x00004a8a, 0x000bbe55, 0x000ffa13 },
2576 { 132, 0x00002ccc, 0x00004a8e, 0x000bbe55, 0x000ffa1b },
2577 { 136, 0x00002ccc, 0x00004a92, 0x000bbe55, 0x000ffa23 },
2580 { 140, 0x00002ccc, 0x00004a9a, 0x000bbe55, 0x000ffa03 },
2581 { 149, 0x00002ccc, 0x00004aa2, 0x000bbe55, 0x000ffa1f },
2582 { 153, 0x00002ccc, 0x00004aa6, 0x000bbe55, 0x000ffa27 },
2583 { 157, 0x00002ccc, 0x00004aae, 0x000bbe55, 0x000ffa07 },
2584 { 161, 0x00002ccc, 0x00004ab2, 0x000bbe55, 0x000ffa0f },
2585 { 165, 0x00002ccc, 0x00004ab6, 0x000bbe55, 0x000ffa17 },
2587 /* MMAC(Japan)J52 ch 34,38,42,46 */
2588 { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000ffa0b },
2589 { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000ffa13 },
2590 { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000ffa1b },
2591 { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000ffa23 },
2595 * RF value list for RF5225 & RF5325
2596 * Supports: 2.4 GHz & 5.2 GHz, rf_sequence enabled
2598 static const struct rf_channel rf_vals_seq
[] = {
2599 { 1, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa0b },
2600 { 2, 0x00002ccc, 0x00004786, 0x00068455, 0x000ffa1f },
2601 { 3, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa0b },
2602 { 4, 0x00002ccc, 0x0000478a, 0x00068455, 0x000ffa1f },
2603 { 5, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa0b },
2604 { 6, 0x00002ccc, 0x0000478e, 0x00068455, 0x000ffa1f },
2605 { 7, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa0b },
2606 { 8, 0x00002ccc, 0x00004792, 0x00068455, 0x000ffa1f },
2607 { 9, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa0b },
2608 { 10, 0x00002ccc, 0x00004796, 0x00068455, 0x000ffa1f },
2609 { 11, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa0b },
2610 { 12, 0x00002ccc, 0x0000479a, 0x00068455, 0x000ffa1f },
2611 { 13, 0x00002ccc, 0x0000479e, 0x00068455, 0x000ffa0b },
2612 { 14, 0x00002ccc, 0x000047a2, 0x00068455, 0x000ffa13 },
2614 /* 802.11 UNI / HyperLan 2 */
2615 { 36, 0x00002cd4, 0x0004481a, 0x00098455, 0x000c0a03 },
2616 { 40, 0x00002cd0, 0x00044682, 0x00098455, 0x000c0a03 },
2617 { 44, 0x00002cd0, 0x00044686, 0x00098455, 0x000c0a1b },
2618 { 48, 0x00002cd0, 0x0004468e, 0x00098655, 0x000c0a0b },
2619 { 52, 0x00002cd0, 0x00044692, 0x00098855, 0x000c0a23 },
2620 { 56, 0x00002cd0, 0x0004469a, 0x00098c55, 0x000c0a13 },
2621 { 60, 0x00002cd0, 0x000446a2, 0x00098e55, 0x000c0a03 },
2622 { 64, 0x00002cd0, 0x000446a6, 0x00099255, 0x000c0a1b },
2624 /* 802.11 HyperLan 2 */
2625 { 100, 0x00002cd4, 0x0004489a, 0x000b9855, 0x000c0a03 },
2626 { 104, 0x00002cd4, 0x000448a2, 0x000b9855, 0x000c0a03 },
2627 { 108, 0x00002cd4, 0x000448aa, 0x000b9855, 0x000c0a03 },
2628 { 112, 0x00002cd4, 0x000448b2, 0x000b9a55, 0x000c0a03 },
2629 { 116, 0x00002cd4, 0x000448ba, 0x000b9a55, 0x000c0a03 },
2630 { 120, 0x00002cd0, 0x00044702, 0x000b9a55, 0x000c0a03 },
2631 { 124, 0x00002cd0, 0x00044706, 0x000b9a55, 0x000c0a1b },
2632 { 128, 0x00002cd0, 0x0004470e, 0x000b9c55, 0x000c0a0b },
2633 { 132, 0x00002cd0, 0x00044712, 0x000b9c55, 0x000c0a23 },
2634 { 136, 0x00002cd0, 0x0004471a, 0x000b9e55, 0x000c0a13 },
2637 { 140, 0x00002cd0, 0x00044722, 0x000b9e55, 0x000c0a03 },
2638 { 149, 0x00002cd0, 0x0004472e, 0x000ba255, 0x000c0a1b },
2639 { 153, 0x00002cd0, 0x00044736, 0x000ba255, 0x000c0a0b },
2640 { 157, 0x00002cd4, 0x0004490a, 0x000ba255, 0x000c0a17 },
2641 { 161, 0x00002cd4, 0x00044912, 0x000ba255, 0x000c0a17 },
2642 { 165, 0x00002cd4, 0x0004491a, 0x000ba255, 0x000c0a17 },
2644 /* MMAC(Japan)J52 ch 34,38,42,46 */
2645 { 34, 0x00002ccc, 0x0000499a, 0x0009be55, 0x000c0a0b },
2646 { 38, 0x00002ccc, 0x0000499e, 0x0009be55, 0x000c0a13 },
2647 { 42, 0x00002ccc, 0x000049a2, 0x0009be55, 0x000c0a1b },
2648 { 46, 0x00002ccc, 0x000049a6, 0x0009be55, 0x000c0a23 },
2651 static int rt61pci_probe_hw_mode(struct rt2x00_dev
*rt2x00dev
)
2653 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
2654 struct channel_info
*info
;
2659 * Disable powersaving as default.
2661 rt2x00dev
->hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
2664 * Initialize all hw fields.
2666 ieee80211_hw_set(rt2x00dev
->hw
, PS_NULLFUNC_STACK
);
2667 ieee80211_hw_set(rt2x00dev
->hw
, SUPPORTS_PS
);
2668 ieee80211_hw_set(rt2x00dev
->hw
, HOST_BROADCAST_PS_BUFFERING
);
2669 ieee80211_hw_set(rt2x00dev
->hw
, SIGNAL_DBM
);
2671 SET_IEEE80211_DEV(rt2x00dev
->hw
, rt2x00dev
->dev
);
2672 SET_IEEE80211_PERM_ADDR(rt2x00dev
->hw
,
2673 rt2x00_eeprom_addr(rt2x00dev
,
2674 EEPROM_MAC_ADDR_0
));
2677 * As rt61 has a global fallback table we cannot specify
2678 * more then one tx rate per frame but since the hw will
2679 * try several rates (based on the fallback table) we should
2680 * initialize max_report_rates to the maximum number of rates
2681 * we are going to try. Otherwise mac80211 will truncate our
2682 * reported tx rates and the rc algortihm will end up with
2685 rt2x00dev
->hw
->max_rates
= 1;
2686 rt2x00dev
->hw
->max_report_rates
= 7;
2687 rt2x00dev
->hw
->max_rate_tries
= 1;
2690 * Initialize hw_mode information.
2692 spec
->supported_bands
= SUPPORT_BAND_2GHZ
;
2693 spec
->supported_rates
= SUPPORT_RATE_CCK
| SUPPORT_RATE_OFDM
;
2695 if (!rt2x00_has_cap_rf_sequence(rt2x00dev
)) {
2696 spec
->num_channels
= 14;
2697 spec
->channels
= rf_vals_noseq
;
2699 spec
->num_channels
= 14;
2700 spec
->channels
= rf_vals_seq
;
2703 if (rt2x00_rf(rt2x00dev
, RF5225
) || rt2x00_rf(rt2x00dev
, RF5325
)) {
2704 spec
->supported_bands
|= SUPPORT_BAND_5GHZ
;
2705 spec
->num_channels
= ARRAY_SIZE(rf_vals_seq
);
2709 * Create channel information array
2711 info
= kcalloc(spec
->num_channels
, sizeof(*info
), GFP_KERNEL
);
2715 spec
->channels_info
= info
;
2717 tx_power
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_G_START
);
2718 for (i
= 0; i
< 14; i
++) {
2719 info
[i
].max_power
= MAX_TXPOWER
;
2720 info
[i
].default_power1
= TXPOWER_FROM_DEV(tx_power
[i
]);
2723 if (spec
->num_channels
> 14) {
2724 tx_power
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_A_START
);
2725 for (i
= 14; i
< spec
->num_channels
; i
++) {
2726 info
[i
].max_power
= MAX_TXPOWER
;
2727 info
[i
].default_power1
=
2728 TXPOWER_FROM_DEV(tx_power
[i
- 14]);
2735 static int rt61pci_probe_hw(struct rt2x00_dev
*rt2x00dev
)
2741 * Disable power saving.
2743 rt2x00mmio_register_write(rt2x00dev
, SOFT_RESET_CSR
, 0x00000007);
2746 * Allocate eeprom data.
2748 retval
= rt61pci_validate_eeprom(rt2x00dev
);
2752 retval
= rt61pci_init_eeprom(rt2x00dev
);
2757 * Enable rfkill polling by setting GPIO direction of the
2758 * rfkill switch GPIO pin correctly.
2760 reg
= rt2x00mmio_register_read(rt2x00dev
, MAC_CSR13
);
2761 rt2x00_set_field32(®
, MAC_CSR13_DIR5
, 1);
2762 rt2x00mmio_register_write(rt2x00dev
, MAC_CSR13
, reg
);
2765 * Initialize hw specifications.
2767 retval
= rt61pci_probe_hw_mode(rt2x00dev
);
2772 * This device has multiple filters for control frames,
2773 * but has no a separate filter for PS Poll frames.
2775 __set_bit(CAPABILITY_CONTROL_FILTERS
, &rt2x00dev
->cap_flags
);
2778 * This device requires firmware and DMA mapped skbs.
2780 __set_bit(REQUIRE_FIRMWARE
, &rt2x00dev
->cap_flags
);
2781 __set_bit(REQUIRE_DMA
, &rt2x00dev
->cap_flags
);
2782 if (!modparam_nohwcrypt
)
2783 __set_bit(CAPABILITY_HW_CRYPTO
, &rt2x00dev
->cap_flags
);
2784 __set_bit(CAPABILITY_LINK_TUNING
, &rt2x00dev
->cap_flags
);
2787 * Set the rssi offset.
2789 rt2x00dev
->rssi_offset
= DEFAULT_RSSI_OFFSET
;
2795 * IEEE80211 stack callback functions.
2797 static int rt61pci_conf_tx(struct ieee80211_hw
*hw
,
2798 struct ieee80211_vif
*vif
, u16 queue_idx
,
2799 const struct ieee80211_tx_queue_params
*params
)
2801 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
2802 struct data_queue
*queue
;
2803 struct rt2x00_field32 field
;
2809 * First pass the configuration through rt2x00lib, that will
2810 * update the queue settings and validate the input. After that
2811 * we are free to update the registers based on the value
2812 * in the queue parameter.
2814 retval
= rt2x00mac_conf_tx(hw
, vif
, queue_idx
, params
);
2819 * We only need to perform additional register initialization
2825 queue
= rt2x00queue_get_tx_queue(rt2x00dev
, queue_idx
);
2827 /* Update WMM TXOP register */
2828 offset
= AC_TXOP_CSR0
+ (sizeof(u32
) * (!!(queue_idx
& 2)));
2829 field
.bit_offset
= (queue_idx
& 1) * 16;
2830 field
.bit_mask
= 0xffff << field
.bit_offset
;
2832 reg
= rt2x00mmio_register_read(rt2x00dev
, offset
);
2833 rt2x00_set_field32(®
, field
, queue
->txop
);
2834 rt2x00mmio_register_write(rt2x00dev
, offset
, reg
);
2836 /* Update WMM registers */
2837 field
.bit_offset
= queue_idx
* 4;
2838 field
.bit_mask
= 0xf << field
.bit_offset
;
2840 reg
= rt2x00mmio_register_read(rt2x00dev
, AIFSN_CSR
);
2841 rt2x00_set_field32(®
, field
, queue
->aifs
);
2842 rt2x00mmio_register_write(rt2x00dev
, AIFSN_CSR
, reg
);
2844 reg
= rt2x00mmio_register_read(rt2x00dev
, CWMIN_CSR
);
2845 rt2x00_set_field32(®
, field
, queue
->cw_min
);
2846 rt2x00mmio_register_write(rt2x00dev
, CWMIN_CSR
, reg
);
2848 reg
= rt2x00mmio_register_read(rt2x00dev
, CWMAX_CSR
);
2849 rt2x00_set_field32(®
, field
, queue
->cw_max
);
2850 rt2x00mmio_register_write(rt2x00dev
, CWMAX_CSR
, reg
);
2855 static u64
rt61pci_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
2857 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
2861 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR13
);
2862 tsf
= (u64
) rt2x00_get_field32(reg
, TXRX_CSR13_HIGH_TSFTIMER
) << 32;
2863 reg
= rt2x00mmio_register_read(rt2x00dev
, TXRX_CSR12
);
2864 tsf
|= rt2x00_get_field32(reg
, TXRX_CSR12_LOW_TSFTIMER
);
2869 static const struct ieee80211_ops rt61pci_mac80211_ops
= {
2871 .start
= rt2x00mac_start
,
2872 .stop
= rt2x00mac_stop
,
2873 .add_interface
= rt2x00mac_add_interface
,
2874 .remove_interface
= rt2x00mac_remove_interface
,
2875 .config
= rt2x00mac_config
,
2876 .configure_filter
= rt2x00mac_configure_filter
,
2877 .set_key
= rt2x00mac_set_key
,
2878 .sw_scan_start
= rt2x00mac_sw_scan_start
,
2879 .sw_scan_complete
= rt2x00mac_sw_scan_complete
,
2880 .get_stats
= rt2x00mac_get_stats
,
2881 .bss_info_changed
= rt2x00mac_bss_info_changed
,
2882 .conf_tx
= rt61pci_conf_tx
,
2883 .get_tsf
= rt61pci_get_tsf
,
2884 .rfkill_poll
= rt2x00mac_rfkill_poll
,
2885 .flush
= rt2x00mac_flush
,
2886 .set_antenna
= rt2x00mac_set_antenna
,
2887 .get_antenna
= rt2x00mac_get_antenna
,
2888 .get_ringparam
= rt2x00mac_get_ringparam
,
2889 .tx_frames_pending
= rt2x00mac_tx_frames_pending
,
2892 static const struct rt2x00lib_ops rt61pci_rt2x00_ops
= {
2893 .irq_handler
= rt61pci_interrupt
,
2894 .txstatus_tasklet
= rt61pci_txstatus_tasklet
,
2895 .tbtt_tasklet
= rt61pci_tbtt_tasklet
,
2896 .rxdone_tasklet
= rt61pci_rxdone_tasklet
,
2897 .autowake_tasklet
= rt61pci_autowake_tasklet
,
2898 .probe_hw
= rt61pci_probe_hw
,
2899 .get_firmware_name
= rt61pci_get_firmware_name
,
2900 .check_firmware
= rt61pci_check_firmware
,
2901 .load_firmware
= rt61pci_load_firmware
,
2902 .initialize
= rt2x00mmio_initialize
,
2903 .uninitialize
= rt2x00mmio_uninitialize
,
2904 .get_entry_state
= rt61pci_get_entry_state
,
2905 .clear_entry
= rt61pci_clear_entry
,
2906 .set_device_state
= rt61pci_set_device_state
,
2907 .rfkill_poll
= rt61pci_rfkill_poll
,
2908 .link_stats
= rt61pci_link_stats
,
2909 .reset_tuner
= rt61pci_reset_tuner
,
2910 .link_tuner
= rt61pci_link_tuner
,
2911 .start_queue
= rt61pci_start_queue
,
2912 .kick_queue
= rt61pci_kick_queue
,
2913 .stop_queue
= rt61pci_stop_queue
,
2914 .flush_queue
= rt2x00mmio_flush_queue
,
2915 .write_tx_desc
= rt61pci_write_tx_desc
,
2916 .write_beacon
= rt61pci_write_beacon
,
2917 .clear_beacon
= rt61pci_clear_beacon
,
2918 .fill_rxdone
= rt61pci_fill_rxdone
,
2919 .config_shared_key
= rt61pci_config_shared_key
,
2920 .config_pairwise_key
= rt61pci_config_pairwise_key
,
2921 .config_filter
= rt61pci_config_filter
,
2922 .config_intf
= rt61pci_config_intf
,
2923 .config_erp
= rt61pci_config_erp
,
2924 .config_ant
= rt61pci_config_ant
,
2925 .config
= rt61pci_config
,
2928 static void rt61pci_queue_init(struct data_queue
*queue
)
2930 switch (queue
->qid
) {
2933 queue
->data_size
= DATA_FRAME_SIZE
;
2934 queue
->desc_size
= RXD_DESC_SIZE
;
2935 queue
->priv_size
= sizeof(struct queue_entry_priv_mmio
);
2943 queue
->data_size
= DATA_FRAME_SIZE
;
2944 queue
->desc_size
= TXD_DESC_SIZE
;
2945 queue
->priv_size
= sizeof(struct queue_entry_priv_mmio
);
2950 queue
->data_size
= 0; /* No DMA required for beacons */
2951 queue
->desc_size
= TXINFO_SIZE
;
2952 queue
->priv_size
= sizeof(struct queue_entry_priv_mmio
);
2963 static const struct rt2x00_ops rt61pci_ops
= {
2964 .name
= KBUILD_MODNAME
,
2966 .eeprom_size
= EEPROM_SIZE
,
2968 .tx_queues
= NUM_TX_QUEUES
,
2969 .queue_init
= rt61pci_queue_init
,
2970 .lib
= &rt61pci_rt2x00_ops
,
2971 .hw
= &rt61pci_mac80211_ops
,
2972 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
2973 .debugfs
= &rt61pci_rt2x00debug
,
2974 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2978 * RT61pci module information.
2980 static const struct pci_device_id rt61pci_device_table
[] = {
2982 { PCI_DEVICE(0x1814, 0x0301) },
2984 { PCI_DEVICE(0x1814, 0x0302) },
2986 { PCI_DEVICE(0x1814, 0x0401) },
2990 MODULE_AUTHOR(DRV_PROJECT
);
2991 MODULE_VERSION(DRV_VERSION
);
2992 MODULE_DESCRIPTION("Ralink RT61 PCI & PCMCIA Wireless LAN driver.");
2993 MODULE_SUPPORTED_DEVICE("Ralink RT2561, RT2561s & RT2661 "
2994 "PCI & PCMCIA chipset based cards");
2995 MODULE_DEVICE_TABLE(pci
, rt61pci_device_table
);
2996 MODULE_FIRMWARE(FIRMWARE_RT2561
);
2997 MODULE_FIRMWARE(FIRMWARE_RT2561s
);
2998 MODULE_FIRMWARE(FIRMWARE_RT2661
);
2999 MODULE_LICENSE("GPL");
3001 static int rt61pci_probe(struct pci_dev
*pci_dev
,
3002 const struct pci_device_id
*id
)
3004 return rt2x00pci_probe(pci_dev
, &rt61pci_ops
);
3007 static struct pci_driver rt61pci_driver
= {
3008 .name
= KBUILD_MODNAME
,
3009 .id_table
= rt61pci_device_table
,
3010 .probe
= rt61pci_probe
,
3011 .remove
= rt2x00pci_remove
,
3012 .suspend
= rt2x00pci_suspend
,
3013 .resume
= rt2x00pci_resume
,
3016 module_pci_driver(rt61pci_driver
);