2 Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2400pci device specific routines.
24 Supported chipsets: RT2460.
28 * Set enviroment defines for rt2x00.h
30 #define DRV_NAME "rt2400pci"
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/version.h>
35 #include <linux/init.h>
36 #include <linux/pci.h>
37 #include <linux/dma-mapping.h>
38 #include <linux/delay.h>
39 #include <linux/etherdevice.h>
40 #include <linux/eeprom_93cx6.h>
45 #include "rt2x00pci.h"
46 #include "rt2400pci.h"
50 * All access to the CSR registers will go through the methods
51 * rt2x00pci_register_read and rt2x00pci_register_write.
52 * BBP and RF register require indirect register access,
53 * and use the CSR registers BBPCSR and RFCSR to achieve this.
54 * These indirect registers work with busy bits,
55 * and we will try maximal REGISTER_BUSY_COUNT times to access
56 * the register while taking a REGISTER_BUSY_DELAY us delay
57 * between each attampt. When the busy bit is still set at that time,
58 * the access attempt is considered to have failed,
59 * and we will print an error.
61 static u32
rt2400pci_bbp_check(const struct rt2x00_dev
*rt2x00dev
)
66 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
67 rt2x00pci_register_read(rt2x00dev
, BBPCSR
, ®
);
68 if (!rt2x00_get_field32(reg
, BBPCSR_BUSY
))
70 udelay(REGISTER_BUSY_DELAY
);
76 static void rt2400pci_bbp_write(const struct rt2x00_dev
*rt2x00dev
,
77 const u8 reg_id
, const u8 value
)
82 * Wait until the BBP becomes ready.
84 reg
= rt2400pci_bbp_check(rt2x00dev
);
85 if (rt2x00_get_field32(reg
, BBPCSR_BUSY
)) {
86 ERROR(rt2x00dev
, "BBPCSR register busy. Write failed.\n");
91 * Write the data into the BBP.
94 rt2x00_set_field32(®
, BBPCSR_VALUE
, value
);
95 rt2x00_set_field32(®
, BBPCSR_REGNUM
, reg_id
);
96 rt2x00_set_field32(®
, BBPCSR_BUSY
, 1);
97 rt2x00_set_field32(®
, BBPCSR_WRITE_CONTROL
, 1);
99 rt2x00pci_register_write(rt2x00dev
, BBPCSR
, reg
);
102 static void rt2400pci_bbp_read(const struct rt2x00_dev
*rt2x00dev
,
103 const u8 reg_id
, u8
*value
)
108 * Wait until the BBP becomes ready.
110 reg
= rt2400pci_bbp_check(rt2x00dev
);
111 if (rt2x00_get_field32(reg
, BBPCSR_BUSY
)) {
112 ERROR(rt2x00dev
, "BBPCSR register busy. Read failed.\n");
117 * Write the request into the BBP.
120 rt2x00_set_field32(®
, BBPCSR_REGNUM
, reg_id
);
121 rt2x00_set_field32(®
, BBPCSR_BUSY
, 1);
122 rt2x00_set_field32(®
, BBPCSR_WRITE_CONTROL
, 0);
124 rt2x00pci_register_write(rt2x00dev
, BBPCSR
, reg
);
127 * Wait until the BBP becomes ready.
129 reg
= rt2400pci_bbp_check(rt2x00dev
);
130 if (rt2x00_get_field32(reg
, BBPCSR_BUSY
)) {
131 ERROR(rt2x00dev
, "BBPCSR register busy. Read failed.\n");
136 *value
= rt2x00_get_field32(reg
, BBPCSR_VALUE
);
139 static void rt2400pci_rf_write(const struct rt2x00_dev
*rt2x00dev
,
145 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
146 rt2x00pci_register_read(rt2x00dev
, RFCSR
, ®
);
147 if (!rt2x00_get_field32(reg
, RFCSR_BUSY
))
149 udelay(REGISTER_BUSY_DELAY
);
152 ERROR(rt2x00dev
, "RFCSR register busy. Write failed.\n");
157 rt2x00_set_field32(®
, RFCSR_VALUE
, value
);
158 rt2x00_set_field32(®
, RFCSR_NUMBER_OF_BITS
, 20);
159 rt2x00_set_field32(®
, RFCSR_IF_SELECT
, 0);
160 rt2x00_set_field32(®
, RFCSR_BUSY
, 1);
162 rt2x00pci_register_write(rt2x00dev
, RFCSR
, reg
);
165 static void rt2400pci_eepromregister_read(struct eeprom_93cx6
*eeprom
)
167 struct rt2x00_dev
*rt2x00dev
= eeprom
->data
;
170 rt2x00pci_register_read(rt2x00dev
, CSR21
, ®
);
172 eeprom
->reg_data_in
= !!rt2x00_get_field32(reg
,
173 CSR21_EEPROM_DATA_IN
);
174 eeprom
->reg_data_out
= !!rt2x00_get_field32(reg
,
175 CSR21_EEPROM_DATA_OUT
);
176 eeprom
->reg_data_clock
= !!rt2x00_get_field32(reg
,
177 CSR21_EEPROM_DATA_CLOCK
);
178 eeprom
->reg_chip_select
= !!rt2x00_get_field32(reg
,
179 CSR21_EEPROM_CHIP_SELECT
);
182 static void rt2400pci_eepromregister_write(struct eeprom_93cx6
*eeprom
)
184 struct rt2x00_dev
*rt2x00dev
= eeprom
->data
;
187 rt2x00_set_field32(®
, CSR21_EEPROM_DATA_IN
,
188 !!eeprom
->reg_data_in
);
189 rt2x00_set_field32(®
, CSR21_EEPROM_DATA_OUT
,
190 !!eeprom
->reg_data_out
);
191 rt2x00_set_field32(®
, CSR21_EEPROM_DATA_CLOCK
,
192 !!eeprom
->reg_data_clock
);
193 rt2x00_set_field32(®
, CSR21_EEPROM_CHIP_SELECT
,
194 !!eeprom
->reg_chip_select
);
196 rt2x00pci_register_write(rt2x00dev
, CSR21
, reg
);
199 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
200 #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u32)) )
202 static void rt2400pci_read_csr(struct rt2x00_dev
*rt2x00dev
,
203 const unsigned long word
, void *data
)
205 rt2x00pci_register_read(rt2x00dev
, CSR_OFFSET(word
), data
);
208 static void rt2400pci_write_csr(struct rt2x00_dev
*rt2x00dev
,
209 const unsigned long word
, void *data
)
211 rt2x00pci_register_write(rt2x00dev
, CSR_OFFSET(word
), *((u32
*)data
));
214 static void rt2400pci_read_eeprom(struct rt2x00_dev
*rt2x00dev
,
215 const unsigned long word
, void *data
)
217 rt2x00_eeprom_read(rt2x00dev
, word
, data
);
220 static void rt2400pci_write_eeprom(struct rt2x00_dev
*rt2x00dev
,
221 const unsigned long word
, void *data
)
223 rt2x00_eeprom_write(rt2x00dev
, word
, *((u16
*)data
));
226 static void rt2400pci_read_bbp(struct rt2x00_dev
*rt2x00dev
,
227 const unsigned long word
, void *data
)
229 rt2400pci_bbp_read(rt2x00dev
, word
, data
);
232 static void rt2400pci_write_bbp(struct rt2x00_dev
*rt2x00dev
,
233 const unsigned long word
, void *data
)
235 rt2400pci_bbp_write(rt2x00dev
, word
, *((u8
*)data
));
238 static const struct rt2x00debug rt2400pci_rt2x00debug
= {
239 .owner
= THIS_MODULE
,
241 .read
= rt2400pci_read_csr
,
242 .write
= rt2400pci_write_csr
,
243 .word_size
= sizeof(u32
),
244 .word_count
= CSR_REG_SIZE
/ sizeof(u32
),
247 .read
= rt2400pci_read_eeprom
,
248 .write
= rt2400pci_write_eeprom
,
249 .word_size
= sizeof(u16
),
250 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
253 .read
= rt2400pci_read_bbp
,
254 .write
= rt2400pci_write_bbp
,
255 .word_size
= sizeof(u8
),
256 .word_count
= BBP_SIZE
/ sizeof(u8
),
259 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
261 #ifdef CONFIG_RT2400PCI_RFKILL
262 static int rt2400pci_rfkill_poll(struct rt2x00_dev
*rt2x00dev
)
266 rt2x00pci_register_read(rt2x00dev
, GPIOCSR
, ®
);
267 return rt2x00_get_field32(reg
, GPIOCSR_BIT0
);
269 #endif /* CONFIG_RT2400PCI_RFKILL */
272 * Configuration handlers.
274 static void rt2400pci_config_bssid(struct rt2x00_dev
*rt2x00dev
, u8
*bssid
)
278 memset(®
, 0, sizeof(reg
));
279 memcpy(®
, bssid
, ETH_ALEN
);
282 * The BSSID is passed to us as an array of bytes,
283 * that array is little endian, so no need for byte ordering.
285 rt2x00pci_register_multiwrite(rt2x00dev
, CSR5
, ®
, sizeof(reg
));
288 static void rt2400pci_config_promisc(struct rt2x00_dev
*rt2x00dev
,
293 rt2x00pci_register_read(rt2x00dev
, RXCSR0
, ®
);
294 rt2x00_set_field32(®
, RXCSR0_DROP_NOT_TO_ME
, !promisc
);
295 rt2x00pci_register_write(rt2x00dev
, RXCSR0
, reg
);
298 static void rt2400pci_config_type(struct rt2x00_dev
*rt2x00dev
, int type
)
302 rt2x00pci_register_write(rt2x00dev
, CSR14
, 0);
305 * Apply hardware packet filter.
307 rt2x00pci_register_read(rt2x00dev
, RXCSR0
, ®
);
309 if (!is_monitor_present(&rt2x00dev
->interface
) &&
310 (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_STA
))
311 rt2x00_set_field32(®
, RXCSR0_DROP_TODS
, 1);
313 rt2x00_set_field32(®
, RXCSR0_DROP_TODS
, 0);
315 rt2x00_set_field32(®
, RXCSR0_DROP_CRC
, 1);
316 if (is_monitor_present(&rt2x00dev
->interface
)) {
317 rt2x00_set_field32(®
, RXCSR0_DROP_PHYSICAL
, 0);
318 rt2x00_set_field32(®
, RXCSR0_DROP_CONTROL
, 0);
319 rt2x00_set_field32(®
, RXCSR0_DROP_VERSION_ERROR
, 0);
321 rt2x00_set_field32(®
, RXCSR0_DROP_PHYSICAL
, 1);
322 rt2x00_set_field32(®
, RXCSR0_DROP_CONTROL
, 1);
323 rt2x00_set_field32(®
, RXCSR0_DROP_VERSION_ERROR
, 1);
326 rt2x00pci_register_write(rt2x00dev
, RXCSR0
, reg
);
329 * Enable beacon config
331 rt2x00pci_register_read(rt2x00dev
, BCNCSR1
, ®
);
332 rt2x00_set_field32(®
, BCNCSR1_PRELOAD
,
333 PREAMBLE
+ get_duration(IEEE80211_HEADER
, 2));
334 rt2x00pci_register_write(rt2x00dev
, BCNCSR1
, reg
);
337 * Enable synchronisation.
339 rt2x00pci_register_read(rt2x00dev
, CSR14
, ®
);
340 if (is_interface_present(&rt2x00dev
->interface
)) {
341 rt2x00_set_field32(®
, CSR14_TSF_COUNT
, 1);
342 rt2x00_set_field32(®
, CSR14_TBCN
, 1);
345 rt2x00_set_field32(®
, CSR14_BEACON_GEN
, 0);
346 if (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_AP
)
347 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 2);
348 else if (type
== IEEE80211_IF_TYPE_STA
)
349 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 1);
350 else if (is_monitor_present(&rt2x00dev
->interface
) &&
351 !is_interface_present(&rt2x00dev
->interface
))
352 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 0);
354 rt2x00pci_register_write(rt2x00dev
, CSR14
, reg
);
357 static void rt2400pci_config_channel(struct rt2x00_dev
*rt2x00dev
,
358 const int value
, const int channel
, const int txpower
)
360 u32 rf1
= rt2x00dev
->rf1
;
362 u32 rf3
= rt2x00dev
->rf3
;
365 * Switch on tuning bits.
367 rt2x00_set_field32(&rf1
, RF1_TUNER
, 1);
368 rt2x00_set_field32(&rf3
, RF3_TUNER
, 1);
370 rt2400pci_rf_write(rt2x00dev
, rf1
);
371 rt2400pci_rf_write(rt2x00dev
, rf2
);
372 rt2400pci_rf_write(rt2x00dev
, rf3
);
375 * RF2420 chipset don't need any additional actions.
377 if (rt2x00_rf(&rt2x00dev
->chip
, RF2420
))
381 * For the RT2421 chipsets we need to write an invalid
382 * reference clock rate to activate auto_tune.
383 * After that we set the value back to the correct channel.
385 rt2400pci_rf_write(rt2x00dev
, rf1
);
386 rt2400pci_rf_write(rt2x00dev
, 0x000c2a32);
387 rt2400pci_rf_write(rt2x00dev
, rf3
);
391 rt2400pci_rf_write(rt2x00dev
, rf1
);
392 rt2400pci_rf_write(rt2x00dev
, rf2
);
393 rt2400pci_rf_write(rt2x00dev
, rf3
);
398 * Switch off tuning bits.
400 rt2x00_set_field32(&rf1
, RF1_TUNER
, 0);
401 rt2x00_set_field32(&rf3
, RF3_TUNER
, 0);
403 rt2400pci_rf_write(rt2x00dev
, rf1
);
404 rt2400pci_rf_write(rt2x00dev
, rf3
);
409 rt2x00dev
->rf1
= rf1
;
410 rt2x00dev
->rf2
= rf2
;
411 rt2x00dev
->rf3
= rf3
;
414 * Clear false CRC during channel switch.
416 rt2x00pci_register_read(rt2x00dev
, CNT0
, &rf1
);
419 static void rt2400pci_config_txpower(struct rt2x00_dev
*rt2x00dev
, int txpower
)
421 rt2400pci_bbp_write(rt2x00dev
, 3, TXPOWER_TO_DEV(txpower
));
424 static void rt2400pci_config_antenna(struct rt2x00_dev
*rt2x00dev
,
425 int antenna_tx
, int antenna_rx
)
430 rt2400pci_bbp_read(rt2x00dev
, 4, &r4
);
431 rt2400pci_bbp_read(rt2x00dev
, 1, &r1
);
434 * Configure the TX antenna.
436 if (antenna_tx
== ANTENNA_DIVERSITY
)
437 rt2x00_set_field8(&r1
, BBP_R1_TX_ANTENNA
, 1);
438 else if (antenna_tx
== ANTENNA_A
)
439 rt2x00_set_field8(&r1
, BBP_R1_TX_ANTENNA
, 0);
440 else if (antenna_tx
== ANTENNA_B
)
441 rt2x00_set_field8(&r1
, BBP_R1_TX_ANTENNA
, 2);
444 * Configure the RX antenna.
446 if (antenna_rx
== ANTENNA_DIVERSITY
)
447 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA
, 1);
448 else if (antenna_rx
== ANTENNA_A
)
449 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA
, 0);
450 else if (antenna_rx
== ANTENNA_B
)
451 rt2x00_set_field8(&r4
, BBP_R4_RX_ANTENNA
, 2);
453 rt2400pci_bbp_write(rt2x00dev
, 4, r4
);
454 rt2400pci_bbp_write(rt2x00dev
, 1, r1
);
457 static void rt2400pci_config_cw(struct rt2x00_dev
*rt2x00dev
,
458 struct ieee80211_tx_queue_params
*params
)
462 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
463 rt2x00_set_field32(®
, CSR11_CWMIN
, params
->cw_min
);
464 rt2x00_set_field32(®
, CSR11_CWMAX
, params
->cw_max
);
465 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
468 static void rt2400pci_config_duration(struct rt2x00_dev
*rt2x00dev
,
469 int short_slot_time
, int beacon_int
)
473 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
474 rt2x00_set_field32(®
, CSR11_SLOT_TIME
,
475 short_slot_time
? SHORT_SLOT_TIME
: SLOT_TIME
);
476 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
478 rt2x00pci_register_read(rt2x00dev
, CSR18
, ®
);
479 rt2x00_set_field32(®
, CSR18_SIFS
, SIFS
);
480 rt2x00_set_field32(®
, CSR18_PIFS
,
481 short_slot_time
? SHORT_PIFS
: PIFS
);
482 rt2x00pci_register_write(rt2x00dev
, CSR18
, reg
);
484 rt2x00pci_register_read(rt2x00dev
, CSR19
, ®
);
485 rt2x00_set_field32(®
, CSR19_DIFS
,
486 short_slot_time
? SHORT_DIFS
: DIFS
);
487 rt2x00_set_field32(®
, CSR19_EIFS
, EIFS
);
488 rt2x00pci_register_write(rt2x00dev
, CSR19
, reg
);
490 rt2x00pci_register_read(rt2x00dev
, TXCSR1
, ®
);
491 rt2x00_set_field32(®
, TXCSR1_TSF_OFFSET
, IEEE80211_HEADER
);
492 rt2x00_set_field32(®
, TXCSR1_AUTORESPONDER
, 1);
493 rt2x00pci_register_write(rt2x00dev
, TXCSR1
, reg
);
495 rt2x00pci_register_read(rt2x00dev
, CSR12
, ®
);
496 rt2x00_set_field32(®
, CSR12_BEACON_INTERVAL
, beacon_int
* 16);
497 rt2x00_set_field32(®
, CSR12_CFP_MAX_DURATION
, beacon_int
* 16);
498 rt2x00pci_register_write(rt2x00dev
, CSR12
, reg
);
501 static void rt2400pci_config_rate(struct rt2x00_dev
*rt2x00dev
, const int rate
)
503 struct ieee80211_conf
*conf
= &rt2x00dev
->hw
->conf
;
508 preamble
= DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
)
509 ? SHORT_PREAMBLE
: PREAMBLE
;
511 reg
= DEVICE_GET_RATE_FIELD(rate
, RATEMASK
) & DEV_BASIC_RATE
;
512 rt2x00pci_register_write(rt2x00dev
, ARCSR1
, reg
);
514 rt2x00pci_register_read(rt2x00dev
, TXCSR1
, ®
);
515 value
= ((conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
) ?
517 PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
518 rt2x00_set_field32(®
, TXCSR1_ACK_TIMEOUT
, value
);
519 value
= SIFS
+ PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
520 rt2x00_set_field32(®
, TXCSR1_ACK_CONSUME_TIME
, value
);
521 rt2x00pci_register_write(rt2x00dev
, TXCSR1
, reg
);
523 preamble
= DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
) ? 0x08 : 0x00;
525 rt2x00pci_register_read(rt2x00dev
, ARCSR2
, ®
);
526 rt2x00_set_field32(®
, ARCSR2_SIGNAL
, 0x00 | preamble
);
527 rt2x00_set_field32(®
, ARCSR2_SERVICE
, 0x04);
528 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 10));
529 rt2x00pci_register_write(rt2x00dev
, ARCSR2
, reg
);
531 rt2x00pci_register_read(rt2x00dev
, ARCSR3
, ®
);
532 rt2x00_set_field32(®
, ARCSR3_SIGNAL
, 0x01 | preamble
);
533 rt2x00_set_field32(®
, ARCSR3_SERVICE
, 0x04);
534 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 20));
535 rt2x00pci_register_write(rt2x00dev
, ARCSR3
, reg
);
537 rt2x00pci_register_read(rt2x00dev
, ARCSR4
, ®
);
538 rt2x00_set_field32(®
, ARCSR4_SIGNAL
, 0x02 | preamble
);
539 rt2x00_set_field32(®
, ARCSR4_SERVICE
, 0x04);
540 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 55));
541 rt2x00pci_register_write(rt2x00dev
, ARCSR4
, reg
);
543 rt2x00pci_register_read(rt2x00dev
, ARCSR5
, ®
);
544 rt2x00_set_field32(®
, ARCSR5_SIGNAL
, 0x03 | preamble
);
545 rt2x00_set_field32(®
, ARCSR5_SERVICE
, 0x84);
546 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 110));
547 rt2x00pci_register_write(rt2x00dev
, ARCSR5
, reg
);
550 static void rt2400pci_config_phymode(struct rt2x00_dev
*rt2x00dev
,
553 struct ieee80211_hw_mode
*mode
;
554 struct ieee80211_rate
*rate
;
556 rt2x00dev
->curr_hwmode
= HWMODE_B
;
558 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
559 rate
= &mode
->rates
[mode
->num_rates
- 1];
561 rt2400pci_config_rate(rt2x00dev
, rate
->val2
);
564 static void rt2400pci_config_mac_addr(struct rt2x00_dev
*rt2x00dev
, u8
*addr
)
568 memset(®
, 0, sizeof(reg
));
569 memcpy(®
, addr
, ETH_ALEN
);
572 * The MAC address is passed to us as an array of bytes,
573 * that array is little endian, so no need for byte ordering.
575 rt2x00pci_register_multiwrite(rt2x00dev
, CSR3
, ®
, sizeof(reg
));
581 static void rt2400pci_enable_led(struct rt2x00_dev
*rt2x00dev
)
585 rt2x00pci_register_read(rt2x00dev
, LEDCSR
, ®
);
587 rt2x00_set_field32(®
, LEDCSR_ON_PERIOD
, 70);
588 rt2x00_set_field32(®
, LEDCSR_OFF_PERIOD
, 30);
590 if (rt2x00dev
->led_mode
== LED_MODE_TXRX_ACTIVITY
) {
591 rt2x00_set_field32(®
, LEDCSR_LINK
, 1);
592 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 0);
593 } else if (rt2x00dev
->led_mode
== LED_MODE_ASUS
) {
594 rt2x00_set_field32(®
, LEDCSR_LINK
, 0);
595 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 1);
597 rt2x00_set_field32(®
, LEDCSR_LINK
, 1);
598 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 1);
601 rt2x00pci_register_write(rt2x00dev
, LEDCSR
, reg
);
604 static void rt2400pci_disable_led(struct rt2x00_dev
*rt2x00dev
)
608 rt2x00pci_register_read(rt2x00dev
, LEDCSR
, ®
);
609 rt2x00_set_field32(®
, LEDCSR_LINK
, 0);
610 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 0);
611 rt2x00pci_register_write(rt2x00dev
, LEDCSR
, reg
);
617 static void rt2400pci_link_tuner(struct rt2x00_dev
*rt2x00dev
, int rssi
)
620 char false_cca_delta
;
623 * The link tuner should not run longer then 60 seconds,
624 * and should run once every 2 seconds.
626 if (rt2x00dev
->link
.count
> 60 || !(rt2x00dev
->link
.count
% 1))
630 * Read false CCA counter.
632 rt2400pci_bbp_read(rt2x00dev
, 39, ®
);
635 * Determine difference with previous CCA counter.
637 false_cca_delta
= reg
- rt2x00dev
->link
.false_cca
;
638 rt2x00dev
->link
.false_cca
= reg
;
641 * Check if the difference is higher than the
642 * threshold and if so, tune the link.
644 if (false_cca_delta
>= 8) {
646 * Read and update RX AGC VGC.
648 rt2400pci_bbp_read(rt2x00dev
, 13, ®
);
651 rt2400pci_bbp_write(rt2x00dev
, 13, reg
);
656 * Initialization functions.
658 static void rt2400pci_init_rxring(struct rt2x00_dev
*rt2x00dev
)
660 struct data_desc
*rxd
;
664 memset(rt2x00dev
->rx
->data_addr
, 0x00,
665 rt2x00_get_ring_size(rt2x00dev
->rx
));
667 for (i
= 0; i
< rt2x00dev
->rx
->stats
.limit
; i
++) {
668 rxd
= rt2x00dev
->rx
->entry
[i
].priv
;
670 rt2x00_desc_read(rxd
, 2, &word
);
671 rt2x00_set_field32(&word
, RXD_W2_BUFFER_LENGTH
,
672 rt2x00dev
->rx
->data_size
);
673 rt2x00_desc_write(rxd
, 2, word
);
675 rt2x00_desc_read(rxd
, 1, &word
);
676 rt2x00_set_field32(&word
, RXD_W1_BUFFER_ADDRESS
,
677 rt2x00dev
->rx
->entry
[i
].data_dma
);
678 rt2x00_desc_write(rxd
, 1, word
);
680 rt2x00_desc_read(rxd
, 0, &word
);
681 rt2x00_set_field32(&word
, RXD_W0_OWNER_NIC
, 1);
682 rt2x00_desc_write(rxd
, 0, word
);
685 rt2x00_ring_index_clear(rt2x00dev
->rx
);
688 static void rt2400pci_init_txring(struct rt2x00_dev
*rt2x00dev
,
691 struct data_ring
*ring
= rt2x00_get_ring(rt2x00dev
, queue
);
692 struct data_desc
*txd
;
696 memset(ring
->data_addr
, 0x00, rt2x00_get_ring_size(ring
));
698 for (i
= 0; i
< ring
->stats
.limit
; i
++) {
699 txd
= ring
->entry
[i
].priv
;
701 rt2x00_desc_read(txd
, 1, &word
);
702 rt2x00_set_field32(&word
, TXD_W1_BUFFER_ADDRESS
,
703 ring
->entry
[i
].data_dma
);
704 rt2x00_desc_write(txd
, 1, word
);
706 rt2x00_desc_read(txd
, 2, &word
);
707 rt2x00_set_field32(&word
, TXD_W2_BUFFER_LENGTH
,
709 rt2x00_desc_write(txd
, 2, word
);
711 rt2x00_desc_read(txd
, 0, &word
);
712 rt2x00_set_field32(&word
, TXD_W0_VALID
, 0);
713 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 0);
714 rt2x00_desc_write(txd
, 0, word
);
717 rt2x00_ring_index_clear(ring
);
720 static int rt2400pci_init_rings(struct rt2x00_dev
*rt2x00dev
)
727 rt2400pci_init_rxring(rt2x00dev
);
728 rt2400pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_DATA0
);
729 rt2400pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_DATA1
);
730 rt2400pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_AFTER_BEACON
);
731 rt2400pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
734 * Initialize registers.
736 rt2x00pci_register_read(rt2x00dev
, TXCSR2
, ®
);
737 rt2x00_set_field32(®
, TXCSR2_TXD_SIZE
,
738 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].desc_size
);
739 rt2x00_set_field32(®
, TXCSR2_NUM_TXD
,
740 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA1
].stats
.limit
);
741 rt2x00_set_field32(®
, TXCSR2_NUM_ATIM
,
742 rt2x00dev
->bcn
[1].stats
.limit
);
743 rt2x00_set_field32(®
, TXCSR2_NUM_PRIO
,
744 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].stats
.limit
);
745 rt2x00pci_register_write(rt2x00dev
, TXCSR2
, reg
);
747 rt2x00pci_register_read(rt2x00dev
, TXCSR3
, ®
);
748 rt2x00_set_field32(®
, TXCSR3_TX_RING_REGISTER
,
749 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA1
].data_dma
);
750 rt2x00pci_register_write(rt2x00dev
, TXCSR3
, reg
);
752 rt2x00pci_register_read(rt2x00dev
, TXCSR5
, ®
);
753 rt2x00_set_field32(®
, TXCSR5_PRIO_RING_REGISTER
,
754 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].data_dma
);
755 rt2x00pci_register_write(rt2x00dev
, TXCSR5
, reg
);
757 rt2x00pci_register_read(rt2x00dev
, TXCSR4
, ®
);
758 rt2x00_set_field32(®
, TXCSR4_ATIM_RING_REGISTER
,
759 rt2x00dev
->bcn
[1].data_dma
);
760 rt2x00pci_register_write(rt2x00dev
, TXCSR4
, reg
);
762 rt2x00pci_register_read(rt2x00dev
, TXCSR6
, ®
);
763 rt2x00_set_field32(®
, TXCSR6_BEACON_RING_REGISTER
,
764 rt2x00dev
->bcn
[0].data_dma
);
765 rt2x00pci_register_write(rt2x00dev
, TXCSR6
, reg
);
767 rt2x00pci_register_read(rt2x00dev
, RXCSR1
, ®
);
768 rt2x00_set_field32(®
, RXCSR1_RXD_SIZE
,
769 rt2x00dev
->rx
->desc_size
);
770 rt2x00_set_field32(®
, RXCSR1_NUM_RXD
,
771 rt2x00dev
->rx
->stats
.limit
);
772 rt2x00pci_register_write(rt2x00dev
, RXCSR1
, reg
);
774 rt2x00pci_register_read(rt2x00dev
, RXCSR2
, ®
);
775 rt2x00_set_field32(®
, RXCSR2_RX_RING_REGISTER
,
776 rt2x00dev
->rx
->data_dma
);
777 rt2x00pci_register_write(rt2x00dev
, RXCSR2
, reg
);
782 static int rt2400pci_init_registers(struct rt2x00_dev
*rt2x00dev
)
786 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
789 rt2x00pci_register_write(rt2x00dev
, PWRCSR0
, 0x3f3b3100);
791 rt2x00pci_register_write(rt2x00dev
, PSCSR0
, 0x00020002);
792 rt2x00pci_register_write(rt2x00dev
, PSCSR1
, 0x00000002);
793 rt2x00pci_register_write(rt2x00dev
, PSCSR2
, 0x00020002);
794 rt2x00pci_register_write(rt2x00dev
, PSCSR3
, 0x00000002);
796 rt2x00pci_register_read(rt2x00dev
, TIMECSR
, ®
);
797 rt2x00_set_field32(®
, TIMECSR_US_COUNT
, 33);
798 rt2x00_set_field32(®
, TIMECSR_US_64_COUNT
, 63);
799 rt2x00_set_field32(®
, TIMECSR_BEACON_EXPECT
, 0);
800 rt2x00pci_register_write(rt2x00dev
, TIMECSR
, reg
);
802 rt2x00pci_register_read(rt2x00dev
, CSR9
, ®
);
803 rt2x00_set_field32(®
, CSR9_MAX_FRAME_UNIT
,
804 (rt2x00dev
->rx
->data_size
/ 128));
805 rt2x00pci_register_write(rt2x00dev
, CSR9
, reg
);
807 rt2x00pci_register_write(rt2x00dev
, CNT3
, 0x3f080000);
809 rt2x00pci_register_write(rt2x00dev
, MACCSR0
, 0x00217223);
810 rt2x00pci_register_write(rt2x00dev
, MACCSR1
, 0x00235518);
812 rt2x00pci_register_read(rt2x00dev
, MACCSR2
, ®
);
813 rt2x00_set_field32(®
, MACCSR2_DELAY
, 64);
814 rt2x00pci_register_write(rt2x00dev
, MACCSR2
, reg
);
816 rt2x00pci_register_read(rt2x00dev
, RXCSR3
, ®
);
820 rt2x00_set_field32(®
, RXCSR3_BBP_ID0
, 3);
821 rt2x00_set_field32(®
, RXCSR3_BBP_ID0_VALID
, 1);
825 rt2x00_set_field32(®
, RXCSR3_BBP_ID1
, 32);
826 rt2x00_set_field32(®
, RXCSR3_BBP_ID1_VALID
, 1);
830 rt2x00_set_field32(®
, RXCSR3_BBP_ID2
, 36);
831 rt2x00_set_field32(®
, RXCSR3_BBP_ID2_VALID
, 1);
832 rt2x00pci_register_write(rt2x00dev
, RXCSR3
, reg
);
834 rt2x00pci_register_read(rt2x00dev
, RALINKCSR
, ®
);
835 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_DATA0
, 17);
836 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_ID0
, 154);
837 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_DATA1
, 0);
838 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_ID1
, 154);
839 rt2x00pci_register_write(rt2x00dev
, RALINKCSR
, reg
);
841 rt2x00pci_register_read(rt2x00dev
, CSR1
, ®
);
842 rt2x00_set_field32(®
, CSR1_SOFT_RESET
, 1);
843 rt2x00_set_field32(®
, CSR1_BBP_RESET
, 0);
844 rt2x00_set_field32(®
, CSR1_HOST_READY
, 0);
845 rt2x00pci_register_write(rt2x00dev
, CSR1
, reg
);
847 rt2x00pci_register_read(rt2x00dev
, CSR1
, ®
);
848 rt2x00_set_field32(®
, CSR1_SOFT_RESET
, 0);
849 rt2x00_set_field32(®
, CSR1_HOST_READY
, 1);
850 rt2x00pci_register_write(rt2x00dev
, CSR1
, reg
);
853 * We must clear the FCS and FIFO error count.
854 * These registers are cleared on read,
855 * so we may pass a useless variable to store the value.
857 rt2x00pci_register_read(rt2x00dev
, CNT0
, ®
);
858 rt2x00pci_register_read(rt2x00dev
, CNT4
, ®
);
863 static int rt2400pci_init_bbp(struct rt2x00_dev
*rt2x00dev
)
870 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
871 rt2400pci_bbp_read(rt2x00dev
, 0, &value
);
872 if ((value
!= 0xff) && (value
!= 0x00))
873 goto continue_csr_init
;
874 NOTICE(rt2x00dev
, "Waiting for BBP register.\n");
875 udelay(REGISTER_BUSY_DELAY
);
878 ERROR(rt2x00dev
, "BBP register access failed, aborting.\n");
882 rt2400pci_bbp_write(rt2x00dev
, 1, 0x00);
883 rt2400pci_bbp_write(rt2x00dev
, 3, 0x27);
884 rt2400pci_bbp_write(rt2x00dev
, 4, 0x08);
885 rt2400pci_bbp_write(rt2x00dev
, 10, 0x0f);
886 rt2400pci_bbp_write(rt2x00dev
, 13, 0x08);
887 rt2400pci_bbp_write(rt2x00dev
, 15, 0x72);
888 rt2400pci_bbp_write(rt2x00dev
, 16, 0x74);
889 rt2400pci_bbp_write(rt2x00dev
, 17, 0x20);
890 rt2400pci_bbp_write(rt2x00dev
, 18, 0x72);
891 rt2400pci_bbp_write(rt2x00dev
, 19, 0x0b);
892 rt2400pci_bbp_write(rt2x00dev
, 20, 0x00);
893 rt2400pci_bbp_write(rt2x00dev
, 28, 0x11);
894 rt2400pci_bbp_write(rt2x00dev
, 29, 0x04);
895 rt2400pci_bbp_write(rt2x00dev
, 30, 0x21);
896 rt2400pci_bbp_write(rt2x00dev
, 31, 0x00);
898 DEBUG(rt2x00dev
, "Start initialization from EEPROM...\n");
899 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
900 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
902 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
903 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
904 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
905 DEBUG(rt2x00dev
, "BBP: 0x%02x, value: 0x%02x.\n",
907 rt2400pci_bbp_write(rt2x00dev
, reg_id
, value
);
910 DEBUG(rt2x00dev
, "...End initialization from EEPROM.\n");
916 * Device state switch handlers.
918 static void rt2400pci_toggle_rx(struct rt2x00_dev
*rt2x00dev
,
919 enum dev_state state
)
923 rt2x00pci_register_read(rt2x00dev
, RXCSR0
, ®
);
924 rt2x00_set_field32(®
, RXCSR0_DISABLE_RX
,
925 state
== STATE_RADIO_RX_OFF
);
926 rt2x00pci_register_write(rt2x00dev
, RXCSR0
, reg
);
929 static int rt2400pci_enable_radio(struct rt2x00_dev
*rt2x00dev
)
934 * Initialize all registers.
936 if (rt2400pci_init_rings(rt2x00dev
) ||
937 rt2400pci_init_registers(rt2x00dev
) ||
938 rt2400pci_init_bbp(rt2x00dev
)) {
939 ERROR(rt2x00dev
, "Register initialization failed.\n");
946 rt2x00pci_register_read(rt2x00dev
, CSR7
, ®
);
947 rt2x00pci_register_write(rt2x00dev
, CSR7
, reg
);
952 rt2x00pci_register_read(rt2x00dev
, CSR8
, ®
);
953 rt2x00_set_field32(®
, CSR8_TBCN_EXPIRE
, 0);
954 rt2x00_set_field32(®
, CSR8_TXDONE_TXRING
, 0);
955 rt2x00_set_field32(®
, CSR8_TXDONE_ATIMRING
, 0);
956 rt2x00_set_field32(®
, CSR8_TXDONE_PRIORING
, 0);
957 rt2x00_set_field32(®
, CSR8_RXDONE
, 0);
958 rt2x00pci_register_write(rt2x00dev
, CSR8
, reg
);
963 rt2400pci_enable_led(rt2x00dev
);
968 static void rt2400pci_disable_radio(struct rt2x00_dev
*rt2x00dev
)
975 rt2400pci_disable_led(rt2x00dev
);
977 rt2x00pci_register_write(rt2x00dev
, PWRCSR0
, 0);
980 * Disable synchronisation.
982 rt2x00pci_register_write(rt2x00dev
, CSR14
, 0);
987 rt2x00pci_register_read(rt2x00dev
, TXCSR0
, ®
);
988 rt2x00_set_field32(®
, TXCSR0_ABORT
, 1);
989 rt2x00pci_register_write(rt2x00dev
, TXCSR0
, reg
);
992 * Disable interrupts.
994 rt2x00pci_register_read(rt2x00dev
, CSR8
, ®
);
995 rt2x00_set_field32(®
, CSR8_TBCN_EXPIRE
, 1);
996 rt2x00_set_field32(®
, CSR8_TXDONE_TXRING
, 1);
997 rt2x00_set_field32(®
, CSR8_TXDONE_ATIMRING
, 1);
998 rt2x00_set_field32(®
, CSR8_TXDONE_PRIORING
, 1);
999 rt2x00_set_field32(®
, CSR8_RXDONE
, 1);
1000 rt2x00pci_register_write(rt2x00dev
, CSR8
, reg
);
1003 static int rt2400pci_set_state(struct rt2x00_dev
*rt2x00dev
,
1004 enum dev_state state
)
1012 put_to_sleep
= (state
!= STATE_AWAKE
);
1014 rt2x00pci_register_read(rt2x00dev
, PWRCSR1
, ®
);
1015 rt2x00_set_field32(®
, PWRCSR1_SET_STATE
, 1);
1016 rt2x00_set_field32(®
, PWRCSR1_BBP_DESIRE_STATE
, state
);
1017 rt2x00_set_field32(®
, PWRCSR1_RF_DESIRE_STATE
, state
);
1018 rt2x00_set_field32(®
, PWRCSR1_PUT_TO_SLEEP
, put_to_sleep
);
1019 rt2x00pci_register_write(rt2x00dev
, PWRCSR1
, reg
);
1022 * Device is not guaranteed to be in the requested state yet.
1023 * We must wait until the register indicates that the
1024 * device has entered the correct state.
1026 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1027 rt2x00pci_register_read(rt2x00dev
, PWRCSR1
, ®
);
1028 bbp_state
= rt2x00_get_field32(reg
, PWRCSR1_BBP_CURR_STATE
);
1029 rf_state
= rt2x00_get_field32(reg
, PWRCSR1_RF_CURR_STATE
);
1030 if (bbp_state
== state
&& rf_state
== state
)
1035 NOTICE(rt2x00dev
, "Device failed to enter state %d, "
1036 "current device state: bbp %d and rf %d.\n",
1037 state
, bbp_state
, rf_state
);
1042 static int rt2400pci_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1043 enum dev_state state
)
1048 case STATE_RADIO_ON
:
1049 retval
= rt2400pci_enable_radio(rt2x00dev
);
1051 case STATE_RADIO_OFF
:
1052 rt2400pci_disable_radio(rt2x00dev
);
1054 case STATE_RADIO_RX_ON
:
1055 case STATE_RADIO_RX_OFF
:
1056 rt2400pci_toggle_rx(rt2x00dev
, state
);
1058 case STATE_DEEP_SLEEP
:
1062 retval
= rt2400pci_set_state(rt2x00dev
, state
);
1073 * TX descriptor initialization
1075 static void rt2400pci_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
1076 struct data_entry
*entry
, struct data_desc
*txd
,
1077 struct data_entry_desc
*desc
, struct ieee80211_hdr
*ieee80211hdr
,
1078 unsigned int length
, struct ieee80211_tx_control
*control
)
1083 u32 length_high
= 0;
1087 * The PLCP values should be treated as if they
1090 rt2x00_set_field32(&signal
, BBPCSR_VALUE
, desc
->signal
);
1091 rt2x00_set_field32(&signal
, BBPCSR_REGNUM
, 5);
1092 rt2x00_set_field32(&signal
, BBPCSR_BUSY
, 1);
1094 rt2x00_set_field32(&service
, BBPCSR_VALUE
, desc
->service
);
1095 rt2x00_set_field32(&service
, BBPCSR_REGNUM
, 6);
1096 rt2x00_set_field32(&service
, BBPCSR_BUSY
, 1);
1098 rt2x00_set_field32(&length_high
, BBPCSR_VALUE
, desc
->length_high
);
1099 rt2x00_set_field32(&length_high
, BBPCSR_REGNUM
, 7);
1100 rt2x00_set_field32(&length_high
, BBPCSR_BUSY
, 1);
1102 rt2x00_set_field32(&length_low
, BBPCSR_VALUE
, desc
->length_low
);
1103 rt2x00_set_field32(&length_low
, BBPCSR_REGNUM
, 8);
1104 rt2x00_set_field32(&length_low
, BBPCSR_BUSY
, 1);
1107 * Start writing the descriptor words.
1109 rt2x00_desc_read(txd
, 2, &word
);
1110 rt2x00_set_field32(&word
, TXD_W2_DATABYTE_COUNT
, length
);
1111 rt2x00_desc_write(txd
, 2, word
);
1113 rt2x00_desc_read(txd
, 3, &word
);
1114 rt2x00_set_field32(&word
, TXD_W3_PLCP_SIGNAL
, signal
);
1115 rt2x00_set_field32(&word
, TXD_W3_PLCP_SERVICE
, service
);
1116 rt2x00_desc_write(txd
, 3, word
);
1118 rt2x00_desc_read(txd
, 4, &word
);
1119 rt2x00_set_field32(&word
, TXD_W4_PLCP_LENGTH_LOW
, length_low
);
1120 rt2x00_set_field32(&word
, TXD_W4_PLCP_LENGTH_HIGH
, length_high
);
1121 rt2x00_desc_write(txd
, 4, word
);
1123 rt2x00_desc_read(txd
, 0, &word
);
1124 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 1);
1125 rt2x00_set_field32(&word
, TXD_W0_VALID
, 1);
1126 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1127 test_bit(ENTRY_TXD_MORE_FRAG
, &entry
->flags
));
1128 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1129 test_bit(ENTRY_TXD_REQ_ACK
, &entry
->flags
));
1130 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1131 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &entry
->flags
));
1132 rt2x00_set_field32(&word
, TXD_W0_RTS
,
1133 test_bit(ENTRY_TXD_RTS_FRAME
, &entry
->flags
));
1134 rt2x00_set_field32(&word
, TXD_W0_IFS
, desc
->ifs
);
1135 rt2x00_set_field32(&word
, TXD_W0_RETRY_MODE
, 0);
1136 rt2x00_desc_write(txd
, 0, word
);
1140 * TX data initialization
1142 static void rt2400pci_kick_tx_queue(struct rt2x00_dev
*rt2x00dev
, int queue
)
1146 if (queue
== IEEE80211_TX_QUEUE_BEACON
) {
1147 rt2x00pci_register_read(rt2x00dev
, CSR14
, ®
);
1148 if (!rt2x00_get_field32(reg
, CSR14_BEACON_GEN
)) {
1149 rt2x00_set_field32(®
, CSR14_BEACON_GEN
, 1);
1150 rt2x00pci_register_write(rt2x00dev
, CSR14
, reg
);
1155 rt2x00pci_register_read(rt2x00dev
, TXCSR0
, ®
);
1156 if (queue
== IEEE80211_TX_QUEUE_DATA0
)
1157 rt2x00_set_field32(®
, TXCSR0_KICK_PRIO
, 1);
1158 else if (queue
== IEEE80211_TX_QUEUE_DATA1
)
1159 rt2x00_set_field32(®
, TXCSR0_KICK_TX
, 1);
1160 else if (queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
)
1161 rt2x00_set_field32(®
, TXCSR0_KICK_ATIM
, 1);
1162 rt2x00pci_register_write(rt2x00dev
, TXCSR0
, reg
);
1166 * Interrupt functions.
1168 static void rt2400pci_rxdone(struct rt2x00_dev
*rt2x00dev
)
1170 struct data_ring
*ring
= rt2x00dev
->rx
;
1171 struct data_entry
*entry
;
1172 struct data_desc
*rxd
;
1180 entry
= rt2x00_get_data_entry(ring
);
1182 rt2x00_desc_read(rxd
, 0, &word0
);
1183 rt2x00_desc_read(rxd
, 2, &word2
);
1185 if (rt2x00_get_field32(word0
, RXD_W0_OWNER_NIC
))
1189 * TODO: Don't we need to keep statistics
1190 * updated about events like CRC and physical errors?
1192 if (rt2x00_get_field32(word0
, RXD_W0_CRC
) ||
1193 rt2x00_get_field32(word0
, RXD_W0_PHYSICAL_ERROR
))
1197 * Obtain the status about this packet.
1199 size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
1200 signal
= rt2x00_get_field32(word2
, RXD_W2_SIGNAL
);
1201 rssi
= rt2x00_get_field32(word2
, RXD_W2_RSSI
);
1204 * Send the packet to upper layer.
1206 rt2x00lib_rxdone(entry
, entry
->data_addr
, size
,
1210 if (test_bit(DEVICE_ENABLED_RADIO
, &ring
->rt2x00dev
->flags
)) {
1211 rt2x00_set_field32(&word0
, RXD_W0_OWNER_NIC
, 1);
1212 rt2x00_desc_write(rxd
, 0, word0
);
1215 rt2x00_ring_index_inc(ring
);
1219 static void rt2400pci_txdone(struct rt2x00_dev
*rt2x00dev
, const int queue
)
1221 struct data_ring
*ring
= rt2x00_get_ring(rt2x00dev
, queue
);
1222 struct data_entry
*entry
;
1223 struct data_desc
*txd
;
1228 while (!rt2x00_ring_empty(ring
)) {
1229 entry
= rt2x00_get_data_entry_done(ring
);
1231 rt2x00_desc_read(txd
, 0, &word
);
1233 if (rt2x00_get_field32(word
, TXD_W0_OWNER_NIC
) ||
1234 !rt2x00_get_field32(word
, TXD_W0_VALID
))
1238 * Obtain the status about this packet.
1240 tx_status
= rt2x00_get_field32(word
, TXD_W0_RESULT
);
1241 retry
= rt2x00_get_field32(word
, TXD_W0_RETRY_COUNT
);
1243 rt2x00lib_txdone(entry
, tx_status
, retry
);
1246 * Make this entry available for reuse.
1249 rt2x00_set_field32(&word
, TXD_W0_VALID
, 0);
1250 rt2x00_desc_write(txd
, 0, word
);
1251 rt2x00_ring_index_done_inc(ring
);
1255 * If the data ring was full before the txdone handler
1256 * we must make sure the packet queue in the mac80211 stack
1257 * is reenabled when the txdone handler has finished.
1259 entry
= ring
->entry
;
1260 if (!rt2x00_ring_full(ring
))
1261 ieee80211_wake_queue(rt2x00dev
->hw
,
1262 entry
->tx_status
.control
.queue
);
1265 static irqreturn_t
rt2400pci_interrupt(int irq
, void *dev_instance
)
1267 struct rt2x00_dev
*rt2x00dev
= dev_instance
;
1271 * Get the interrupt sources & saved to local variable.
1272 * Write register value back to clear pending interrupts.
1274 rt2x00pci_register_read(rt2x00dev
, CSR7
, ®
);
1275 rt2x00pci_register_write(rt2x00dev
, CSR7
, reg
);
1280 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
1284 * Handle interrupts, walk through all bits
1285 * and run the tasks, the bits are checked in order of
1290 * 1 - Beacon timer expired interrupt.
1292 if (rt2x00_get_field32(reg
, CSR7_TBCN_EXPIRE
))
1293 rt2x00pci_beacondone(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
1296 * 2 - Rx ring done interrupt.
1298 if (rt2x00_get_field32(reg
, CSR7_RXDONE
))
1299 rt2400pci_rxdone(rt2x00dev
);
1302 * 3 - Atim ring transmit done interrupt.
1304 if (rt2x00_get_field32(reg
, CSR7_TXDONE_ATIMRING
))
1305 rt2400pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_AFTER_BEACON
);
1308 * 4 - Priority ring transmit done interrupt.
1310 if (rt2x00_get_field32(reg
, CSR7_TXDONE_PRIORING
))
1311 rt2400pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_DATA0
);
1314 * 5 - Tx ring transmit done interrupt.
1316 if (rt2x00_get_field32(reg
, CSR7_TXDONE_TXRING
))
1317 rt2400pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_DATA1
);
1323 * Device initialization functions.
1325 static int rt2400pci_alloc_eeprom(struct rt2x00_dev
*rt2x00dev
)
1327 struct eeprom_93cx6 eeprom
;
1332 * Allocate the eeprom memory, check the eeprom width
1333 * and copy the entire eeprom into this allocated memory.
1335 rt2x00dev
->eeprom
= kzalloc(EEPROM_SIZE
, GFP_KERNEL
);
1336 if (!rt2x00dev
->eeprom
)
1339 rt2x00pci_register_read(rt2x00dev
, CSR21
, ®
);
1341 eeprom
.data
= rt2x00dev
;
1342 eeprom
.register_read
= rt2400pci_eepromregister_read
;
1343 eeprom
.register_write
= rt2400pci_eepromregister_write
;
1344 eeprom
.width
= rt2x00_get_field32(reg
, CSR21_TYPE_93C46
) ?
1345 PCI_EEPROM_WIDTH_93C46
: PCI_EEPROM_WIDTH_93C66
;
1346 eeprom
.reg_data_in
= 0;
1347 eeprom
.reg_data_out
= 0;
1348 eeprom
.reg_data_clock
= 0;
1349 eeprom
.reg_chip_select
= 0;
1351 eeprom_93cx6_multiread(&eeprom
, EEPROM_BASE
, rt2x00dev
->eeprom
,
1352 EEPROM_SIZE
/ sizeof(u16
));
1355 * Start validation of the data that has been read.
1357 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1358 if (word
== 0xffff) {
1359 ERROR(rt2x00dev
, "Invalid EEPROM data detected.\n");
1366 static int rt2400pci_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1373 * Read EEPROM word for configuration.
1375 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1378 * Identify RF chipset.
1380 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1381 rt2x00pci_register_read(rt2x00dev
, CSR0
, ®
);
1382 rt2x00_set_chip(rt2x00dev
, RT2460
, value
, reg
);
1384 if (!rt2x00_rf(&rt2x00dev
->chip
, RF2420
) &&
1385 !rt2x00_rf(&rt2x00dev
->chip
, RF2421
)) {
1386 ERROR(rt2x00dev
, "Invalid RF chipset detected.\n");
1391 * Identify default antenna configuration.
1393 rt2x00dev
->hw
->conf
.antenna_sel_tx
= rt2x00_get_field16(eeprom
,
1394 EEPROM_ANTENNA_TX_DEFAULT
);
1395 rt2x00dev
->hw
->conf
.antenna_sel_rx
= rt2x00_get_field16(eeprom
,
1396 EEPROM_ANTENNA_RX_DEFAULT
);
1399 * Store led mode, for correct led behaviour.
1401 rt2x00dev
->led_mode
= rt2x00_get_field16(eeprom
,
1402 EEPROM_ANTENNA_LED_MODE
);
1405 * Detect if this device has an hardware controlled radio.
1407 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_HARDWARE_RADIO
))
1408 __set_bit(DEVICE_SUPPORT_HW_BUTTON
, &rt2x00dev
->flags
);
1411 * Check if the BBP tuning should be enabled.
1413 if (!rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RX_AGCVGC_TUNING
))
1414 __set_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
);
1420 * RF value list for RF2420 & RF2421
1423 static const u32 rf_vals_bg
[] = {
1424 0x000c1fda, 0x000c1fee, 0x000c2002, 0x000c2016, 0x000c202a,
1425 0x000c203e, 0x000c2052, 0x000c2066, 0x000c207a, 0x000c208e,
1426 0x000c20a2, 0x000c20b6, 0x000c20ca, 0x000c20fa
1429 static void rt2400pci_init_hw_mode(struct rt2x00_dev
*rt2x00dev
)
1431 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1436 * Initialize all hw fields.
1438 rt2x00dev
->hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON
|
1439 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
1440 IEEE80211_HW_WEP_INCLUDE_IV
|
1441 IEEE80211_HW_DATA_NULLFUNC_ACK
|
1442 IEEE80211_HW_NO_TKIP_WMM_HWACCEL
|
1443 IEEE80211_HW_MONITOR_DURING_OPER
;
1444 rt2x00dev
->hw
->extra_tx_headroom
= 0;
1445 rt2x00dev
->hw
->max_rssi
= MAX_RX_SSI
;
1446 rt2x00dev
->hw
->max_noise
= MAX_RX_NOISE
;
1447 rt2x00dev
->hw
->queues
= 2;
1450 * This device supports ATIM
1452 __set_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
1455 * Set device specific, but channel independent RF values.
1457 rt2x00dev
->rf1
= 0x00022058;
1458 if (rt2x00_rf(&rt2x00dev
->chip
, RF2420
))
1459 rt2x00dev
->rf3
= 0x00000111;
1461 rt2x00dev
->rf3
= 0x00000101;
1464 * Convert tx_power array in eeprom.
1466 txpower
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_START
);
1467 for (i
= 0; i
< 14; i
++)
1468 txpower
[i
] = TXPOWER_FROM_DEV(txpower
[i
]);
1471 * Initialize hw_mode information.
1473 spec
->mac_addr
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1474 spec
->num_modes
= 1;
1475 spec
->num_rates
= 4;
1476 spec
->num_channels
= 14;
1477 spec
->tx_power_a
= NULL
;
1478 spec
->tx_power_bg
= txpower
;
1479 spec
->tx_power_default
= DEFAULT_TXPOWER
;
1480 spec
->chan_val_a
= NULL
;
1481 spec
->chan_val_bg
= rf_vals_bg
;
1484 static int rt2400pci_init_hw(struct rt2x00_dev
*rt2x00dev
)
1489 * Allocate eeprom data.
1491 retval
= rt2400pci_alloc_eeprom(rt2x00dev
);
1495 retval
= rt2400pci_init_eeprom(rt2x00dev
);
1500 * Initialize hw specifications.
1502 rt2400pci_init_hw_mode(rt2x00dev
);
1508 * IEEE80211 stack callback functions.
1510 static int rt2400pci_get_stats(struct ieee80211_hw
*hw
,
1511 struct ieee80211_low_level_stats
*stats
)
1513 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1517 * Update FCS error count from register.
1518 * The dot11ACKFailureCount, dot11RTSFailureCount and
1519 * dot11RTSSuccessCount are updated in interrupt time.
1521 rt2x00pci_register_read(rt2x00dev
, CNT0
, ®
);
1522 rt2x00dev
->low_level_stats
.dot11FCSErrorCount
+=
1523 rt2x00_get_field32(reg
, CNT0_FCS_ERROR
);
1525 memcpy(stats
, &rt2x00dev
->low_level_stats
, sizeof(*stats
));
1530 static int rt2400pci_set_retry_limit(struct ieee80211_hw
*hw
,
1531 u32 short_retry
, u32 long_retry
)
1533 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1536 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
1537 rt2x00_set_field32(®
, CSR11_LONG_RETRY
, long_retry
);
1538 rt2x00_set_field32(®
, CSR11_SHORT_RETRY
, short_retry
);
1539 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
1544 static int rt2400pci_conf_tx(struct ieee80211_hw
*hw
,
1545 int queue
, const struct ieee80211_tx_queue_params
*params
)
1547 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1550 * We don't support variating cw_min and cw_max variables
1551 * per queue. So by default we only configure the TX queue,
1552 * and ignore all other configurations.
1554 if (queue
!= IEEE80211_TX_QUEUE_DATA0
)
1557 if (rt2x00lib_conf_tx(hw
, queue
, params
))
1561 * Write configuration to register.
1563 rt2400pci_config_cw(rt2x00dev
, &rt2x00dev
->tx
->tx_params
);
1568 static u64
rt2400pci_get_tsf(struct ieee80211_hw
*hw
)
1570 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1574 rt2x00pci_register_read(rt2x00dev
, CSR17
, ®
);
1575 tsf
= (u64
)rt2x00_get_field32(reg
, CSR17_HIGH_TSFTIMER
) << 32;
1576 rt2x00pci_register_read(rt2x00dev
, CSR16
, ®
);
1577 tsf
|= rt2x00_get_field32(reg
, CSR16_LOW_TSFTIMER
);
1582 static void rt2400pci_reset_tsf(struct ieee80211_hw
*hw
)
1584 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1586 rt2x00pci_register_write(rt2x00dev
, CSR16
, 0);
1587 rt2x00pci_register_write(rt2x00dev
, CSR17
, 0);
1590 static int rt2400pci_tx_last_beacon(struct ieee80211_hw
*hw
)
1592 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1595 rt2x00pci_register_read(rt2x00dev
, CSR15
, ®
);
1596 return rt2x00_get_field32(reg
, CSR15_BEACON_SENT
);
1599 static const struct ieee80211_ops rt2400pci_mac80211_ops
= {
1601 .reset
= rt2x00lib_reset
,
1602 .open
= rt2x00lib_open
,
1603 .stop
= rt2x00lib_stop
,
1604 .add_interface
= rt2x00lib_add_interface
,
1605 .remove_interface
= rt2x00lib_remove_interface
,
1606 .config
= rt2x00lib_config
,
1607 .config_interface
= rt2x00lib_config_interface
,
1608 .set_multicast_list
= rt2x00lib_set_multicast_list
,
1609 .get_stats
= rt2400pci_get_stats
,
1610 .set_retry_limit
= rt2400pci_set_retry_limit
,
1611 .conf_tx
= rt2400pci_conf_tx
,
1612 .get_tx_stats
= rt2x00lib_get_tx_stats
,
1613 .get_tsf
= rt2400pci_get_tsf
,
1614 .reset_tsf
= rt2400pci_reset_tsf
,
1615 .beacon_update
= rt2x00pci_beacon_update
,
1616 .tx_last_beacon
= rt2400pci_tx_last_beacon
,
1619 static const struct rt2x00lib_ops rt2400pci_rt2x00_ops
= {
1620 .irq_handler
= rt2400pci_interrupt
,
1621 .init_hw
= rt2400pci_init_hw
,
1622 .initialize
= rt2x00pci_initialize
,
1623 .uninitialize
= rt2x00pci_uninitialize
,
1624 .set_device_state
= rt2400pci_set_device_state
,
1625 #ifdef CONFIG_RT2400PCI_RFKILL
1626 .rfkill_poll
= rt2400pci_rfkill_poll
,
1627 #endif /* CONFIG_RT2400PCI_RFKILL */
1628 .link_tuner
= rt2400pci_link_tuner
,
1629 .write_tx_desc
= rt2400pci_write_tx_desc
,
1630 .write_tx_data
= rt2x00pci_write_tx_data
,
1631 .kick_tx_queue
= rt2400pci_kick_tx_queue
,
1632 .config_type
= rt2400pci_config_type
,
1633 .config_phymode
= rt2400pci_config_phymode
,
1634 .config_channel
= rt2400pci_config_channel
,
1635 .config_mac_addr
= rt2400pci_config_mac_addr
,
1636 .config_bssid
= rt2400pci_config_bssid
,
1637 .config_promisc
= rt2400pci_config_promisc
,
1638 .config_txpower
= rt2400pci_config_txpower
,
1639 .config_antenna
= rt2400pci_config_antenna
,
1640 .config_duration
= rt2400pci_config_duration
,
1643 static const struct rt2x00_ops rt2400pci_ops
= {
1645 .rxd_size
= RXD_DESC_SIZE
,
1646 .txd_size
= TXD_DESC_SIZE
,
1647 .lib
= &rt2400pci_rt2x00_ops
,
1648 .hw
= &rt2400pci_mac80211_ops
,
1649 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1650 .debugfs
= &rt2400pci_rt2x00debug
,
1651 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1655 * RT2400pci module information.
1657 static struct pci_device_id rt2400pci_device_table
[] = {
1658 { PCI_DEVICE(0x1814, 0x0101), PCI_DEVICE_DATA(&rt2400pci_ops
) },
1662 MODULE_AUTHOR(DRV_PROJECT
);
1663 MODULE_VERSION(DRV_VERSION
);
1664 MODULE_DESCRIPTION("Ralink RT2400 PCI & PCMCIA Wireless LAN driver.");
1665 MODULE_SUPPORTED_DEVICE("Ralink RT2460 PCI & PCMCIA chipset based cards");
1666 MODULE_DEVICE_TABLE(pci
, rt2400pci_device_table
);
1667 MODULE_LICENSE("GPL");
1669 static struct pci_driver rt2400pci_driver
= {
1671 .id_table
= rt2400pci_device_table
,
1672 .probe
= rt2x00pci_probe
,
1673 .remove
= __devexit_p(rt2x00pci_remove
),
1675 .suspend
= rt2x00pci_suspend
,
1676 .resume
= rt2x00pci_resume
,
1677 #endif /* CONFIG_PM */
1680 static int __init
rt2400pci_init(void)
1682 printk(KERN_INFO
"Loading module: %s - %s by %s.\n",
1683 DRV_NAME
, DRV_VERSION
, DRV_PROJECT
);
1684 return pci_register_driver(&rt2400pci_driver
);
1687 static void __exit
rt2400pci_exit(void)
1689 printk(KERN_INFO
"Unloading module: %s.\n", DRV_NAME
);
1690 pci_unregister_driver(&rt2400pci_driver
);
1693 module_init(rt2400pci_init
);
1694 module_exit(rt2400pci_exit
);