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: rt2500pci device specific routines.
24 Supported chipsets: RT2560.
28 * Set enviroment defines for rt2x00.h
30 #define DRV_NAME "rt2500pci"
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 "rt2500pci.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
rt2500pci_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 rt2500pci_bbp_write(const struct rt2x00_dev
*rt2x00dev
,
77 const u8 reg_id
, const u8 value
)
82 * Wait until the BBP becomes ready.
84 reg
= rt2500pci_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 rt2500pci_bbp_read(const struct rt2x00_dev
*rt2x00dev
,
103 const u8 reg_id
, u8
*value
)
108 * Wait until the BBP becomes ready.
110 reg
= rt2500pci_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
= rt2500pci_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 rt2500pci_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 rt2500pci_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 rt2500pci_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 rt2500pci_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 rt2500pci_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 rt2500pci_read_eeprom(struct rt2x00_dev
*rt2x00dev
,
215 const unsigned long word
, void *data
)
217 rt2x00_eeprom_read(rt2x00dev
, word
, data
);
220 static void rt2500pci_write_eeprom(struct rt2x00_dev
*rt2x00dev
,
221 const unsigned long word
, void *data
)
223 rt2x00_eeprom_write(rt2x00dev
, word
, *((u16
*)data
));
226 static void rt2500pci_read_bbp(struct rt2x00_dev
*rt2x00dev
,
227 const unsigned long word
, void *data
)
229 rt2500pci_bbp_read(rt2x00dev
, word
, data
);
232 static void rt2500pci_write_bbp(struct rt2x00_dev
*rt2x00dev
,
233 const unsigned long word
, void *data
)
235 rt2500pci_bbp_write(rt2x00dev
, word
, *((u8
*)data
));
238 static const struct rt2x00debug rt2500pci_rt2x00debug
= {
239 .owner
= THIS_MODULE
,
241 .read
= rt2500pci_read_csr
,
242 .write
= rt2500pci_write_csr
,
243 .word_size
= sizeof(u32
),
244 .word_count
= CSR_REG_SIZE
/ sizeof(u32
),
247 .read
= rt2500pci_read_eeprom
,
248 .write
= rt2500pci_write_eeprom
,
249 .word_size
= sizeof(u16
),
250 .word_count
= EEPROM_SIZE
/ sizeof(u16
),
253 .read
= rt2500pci_read_bbp
,
254 .write
= rt2500pci_write_bbp
,
255 .word_size
= sizeof(u8
),
256 .word_count
= BBP_SIZE
/ sizeof(u8
),
259 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
261 #ifdef CONFIG_RT2500PCI_RFKILL
262 static int rt2500pci_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 rt2500pci_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 rt2500pci_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 rt2500pci_config_type(struct rt2x00_dev
*rt2x00dev
,
303 rt2x00pci_register_write(rt2x00dev
, CSR14
, 0);
306 * Apply hardware packet filter.
308 rt2x00pci_register_read(rt2x00dev
, RXCSR0
, ®
);
310 if (!is_monitor_present(&rt2x00dev
->interface
) &&
311 (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_STA
))
312 rt2x00_set_field32(®
, RXCSR0_DROP_TODS
, 1);
314 rt2x00_set_field32(®
, RXCSR0_DROP_TODS
, 0);
316 rt2x00_set_field32(®
, RXCSR0_DROP_CRC
, 1);
317 if (is_monitor_present(&rt2x00dev
->interface
)) {
318 rt2x00_set_field32(®
, RXCSR0_DROP_PHYSICAL
, 0);
319 rt2x00_set_field32(®
, RXCSR0_DROP_CONTROL
, 0);
320 rt2x00_set_field32(®
, RXCSR0_DROP_VERSION_ERROR
, 0);
322 rt2x00_set_field32(®
, RXCSR0_DROP_PHYSICAL
, 1);
323 rt2x00_set_field32(®
, RXCSR0_DROP_CONTROL
, 1);
324 rt2x00_set_field32(®
, RXCSR0_DROP_VERSION_ERROR
, 1);
327 rt2x00_set_field32(®
, RXCSR0_DROP_MCAST
, 0);
328 rt2x00_set_field32(®
, RXCSR0_DROP_BCAST
, 0);
330 rt2x00pci_register_write(rt2x00dev
, RXCSR0
, reg
);
333 * Enable beacon config
335 rt2x00pci_register_read(rt2x00dev
, BCNCSR1
, ®
);
336 rt2x00_set_field32(®
, BCNCSR1_PRELOAD
,
337 PREAMBLE
+ get_duration(IEEE80211_HEADER
, 2));
338 rt2x00_set_field32(®
, BCNCSR1_BEACON_CWMIN
,
339 rt2x00_get_ring(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
)
341 rt2x00pci_register_write(rt2x00dev
, BCNCSR1
, reg
);
344 * Enable synchronisation.
346 rt2x00pci_register_read(rt2x00dev
, CSR14
, ®
);
347 if (is_interface_present(&rt2x00dev
->interface
)) {
348 rt2x00_set_field32(®
, CSR14_TSF_COUNT
, 1);
349 rt2x00_set_field32(®
, CSR14_TBCN
, 1);
352 rt2x00_set_field32(®
, CSR14_BEACON_GEN
, 0);
353 if (type
== IEEE80211_IF_TYPE_IBSS
|| type
== IEEE80211_IF_TYPE_AP
)
354 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 2);
355 else if (type
== IEEE80211_IF_TYPE_STA
)
356 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 1);
357 else if (is_monitor_present(&rt2x00dev
->interface
) &&
358 !is_interface_present(&rt2x00dev
->interface
))
359 rt2x00_set_field32(®
, CSR14_TSF_SYNC
, 0);
361 rt2x00pci_register_write(rt2x00dev
, CSR14
, reg
);
364 static void rt2500pci_config_channel(struct rt2x00_dev
*rt2x00dev
,
365 const int value
, const int channel
, const int txpower
)
367 u32 rf1
= rt2x00dev
->rf1
;
369 u32 rf3
= rt2x00dev
->rf3
;
370 u32 rf4
= rt2x00dev
->rf4
;
372 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525
) ||
373 rt2x00_rf(&rt2x00dev
->chip
, RF2525E
))
376 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) && channel
== 14)
379 if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
383 } else if (channel
== 14) {
386 } else if (channel
< 64) {
389 } else if (channel
< 140) {
392 } else if (channel
< 161) {
401 rt2x00_set_field32(&rf3
, RF3_TXPOWER
, TXPOWER_TO_DEV(txpower
));
404 * Switch on tuning bits.
405 * For RT2523 devices we do not need to update the R1 register.
407 if (!rt2x00_rf(&rt2x00dev
->chip
, RF2523
))
408 rt2x00_set_field32(&rf1
, RF1_TUNER
, 1);
409 rt2x00_set_field32(&rf3
, RF3_TUNER
, 1);
412 * For RT2525 we should first set the channel to half band higher.
414 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525
)) {
415 static const u32 vals
[] = {
416 0x00080cbe, 0x00080d02, 0x00080d06, 0x00080d0a,
417 0x00080d0e, 0x00080d12, 0x00080d16, 0x00080d1a,
418 0x00080d1e, 0x00080d22, 0x00080d26, 0x00080d2a,
419 0x00080d2e, 0x00080d3a
422 rt2500pci_rf_write(rt2x00dev
, rf1
);
423 rt2500pci_rf_write(rt2x00dev
, vals
[channel
- 1]);
424 rt2500pci_rf_write(rt2x00dev
, rf3
);
426 rt2500pci_rf_write(rt2x00dev
, rf4
);
429 rt2500pci_rf_write(rt2x00dev
, rf1
);
430 rt2500pci_rf_write(rt2x00dev
, rf2
);
431 rt2500pci_rf_write(rt2x00dev
, rf3
);
433 rt2500pci_rf_write(rt2x00dev
, rf4
);
436 * Channel 14 requires the Japan filter bit to be set.
438 rt2500pci_bbp_write(rt2x00dev
, 70, (channel
== 14) ? 0x4e : 0x46);
443 * Switch off tuning bits.
444 * For RT2523 devices we do not need to update the R1 register.
446 rt2x00_set_field32(&rf1
, RF1_TUNER
, 0);
447 rt2x00_set_field32(&rf3
, RF3_TUNER
, 0);
450 if (!rt2x00_rf(&rt2x00dev
->chip
, RF2523
))
451 rt2500pci_rf_write(rt2x00dev
, rf1
);
453 rt2500pci_rf_write(rt2x00dev
, rf3
);
458 rt2x00dev
->rf1
= rf1
;
459 rt2x00dev
->rf2
= rf2
;
460 rt2x00dev
->rf3
= rf3
;
461 rt2x00dev
->rf4
= rf4
;
462 rt2x00dev
->tx_power
= txpower
;
465 * Clear false CRC during channel switch.
467 rt2x00pci_register_read(rt2x00dev
, CNT0
, &rf1
);
470 static void rt2500pci_config_txpower(struct rt2x00_dev
*rt2x00dev
,
473 rt2x00_set_field32(&rt2x00dev
->rf3
, RF3_TXPOWER
,
474 TXPOWER_TO_DEV(txpower
));
475 rt2500pci_rf_write(rt2x00dev
, rt2x00dev
->rf3
);
479 static void rt2500pci_config_antenna(struct rt2x00_dev
*rt2x00dev
,
480 const int antenna_tx
, const int antenna_rx
)
486 rt2x00pci_register_read(rt2x00dev
, BBPCSR1
, ®
);
487 rt2500pci_bbp_read(rt2x00dev
, 14, &r14
);
488 rt2500pci_bbp_read(rt2x00dev
, 2, &r2
);
491 * Configure the TX antenna.
493 if (antenna_tx
== ANTENNA_DIVERSITY
) {
494 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 2);
495 rt2x00_set_field32(®
, BBPCSR1_CCK
, 2);
496 rt2x00_set_field32(®
, BBPCSR1_OFDM
, 2);
497 } else if (antenna_tx
== ANTENNA_A
) {
498 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 0);
499 rt2x00_set_field32(®
, BBPCSR1_CCK
, 0);
500 rt2x00_set_field32(®
, BBPCSR1_OFDM
, 0);
501 } else if (antenna_tx
== ANTENNA_B
) {
502 rt2x00_set_field8(&r2
, BBP_R2_TX_ANTENNA
, 2);
503 rt2x00_set_field32(®
, BBPCSR1_CCK
, 2);
504 rt2x00_set_field32(®
, BBPCSR1_OFDM
, 2);
508 * Configure the RX antenna.
510 if (antenna_rx
== ANTENNA_DIVERSITY
)
511 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 2);
512 else if (antenna_rx
== ANTENNA_A
)
513 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 0);
514 else if (antenna_rx
== ANTENNA_B
)
515 rt2x00_set_field8(&r14
, BBP_R14_RX_ANTENNA
, 2);
518 * RT2525E and RT5222 need to flip TX I/Q
520 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) ||
521 rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
522 rt2x00_set_field8(&r2
, BBP_R2_TX_IQ_FLIP
, 1);
523 rt2x00_set_field32(®
, BBPCSR1_CCK_FLIP
, 1);
524 rt2x00_set_field32(®
, BBPCSR1_OFDM_FLIP
, 1);
527 * RT2525E does not need RX I/Q Flip.
529 if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
))
530 rt2x00_set_field8(&r14
, BBP_R14_RX_IQ_FLIP
, 0);
532 rt2x00_set_field32(®
, BBPCSR1_CCK_FLIP
, 0);
533 rt2x00_set_field32(®
, BBPCSR1_OFDM_FLIP
, 0);
536 rt2x00pci_register_write(rt2x00dev
, BBPCSR1
, reg
);
537 rt2500pci_bbp_write(rt2x00dev
, 14, r14
);
538 rt2500pci_bbp_write(rt2x00dev
, 2, r2
);
541 static void rt2500pci_config_duration(struct rt2x00_dev
*rt2x00dev
,
542 const int short_slot_time
, const int beacon_int
)
546 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
547 rt2x00_set_field32(®
, CSR11_SLOT_TIME
,
548 short_slot_time
? SHORT_SLOT_TIME
: SLOT_TIME
);
549 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
551 rt2x00pci_register_read(rt2x00dev
, CSR18
, ®
);
552 rt2x00_set_field32(®
, CSR18_SIFS
, SIFS
);
553 rt2x00_set_field32(®
, CSR18_PIFS
,
554 short_slot_time
? SHORT_PIFS
: PIFS
);
555 rt2x00pci_register_write(rt2x00dev
, CSR18
, reg
);
557 rt2x00pci_register_read(rt2x00dev
, CSR19
, ®
);
558 rt2x00_set_field32(®
, CSR19_DIFS
,
559 short_slot_time
? SHORT_DIFS
: DIFS
);
560 rt2x00_set_field32(®
, CSR19_EIFS
, EIFS
);
561 rt2x00pci_register_write(rt2x00dev
, CSR19
, reg
);
563 rt2x00pci_register_read(rt2x00dev
, TXCSR1
, ®
);
564 rt2x00_set_field32(®
, TXCSR1_TSF_OFFSET
, IEEE80211_HEADER
);
565 rt2x00_set_field32(®
, TXCSR1_AUTORESPONDER
, 1);
566 rt2x00pci_register_write(rt2x00dev
, TXCSR1
, reg
);
568 rt2x00pci_register_read(rt2x00dev
, CSR12
, ®
);
569 rt2x00_set_field32(®
, CSR12_BEACON_INTERVAL
, beacon_int
* 16);
570 rt2x00_set_field32(®
, CSR12_CFP_MAX_DURATION
, beacon_int
* 16);
571 rt2x00pci_register_write(rt2x00dev
, CSR12
, reg
);
574 static void rt2500pci_config_rate(struct rt2x00_dev
*rt2x00dev
, const int rate
)
576 struct ieee80211_conf
*conf
= &rt2x00dev
->hw
->conf
;
581 preamble
= DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
)
582 ? SHORT_PREAMBLE
: PREAMBLE
;
584 reg
= DEVICE_GET_RATE_FIELD(rate
, RATEMASK
) & DEV_BASIC_RATE
;
585 rt2x00pci_register_write(rt2x00dev
, ARCSR1
, reg
);
587 rt2x00pci_register_read(rt2x00dev
, TXCSR1
, ®
);
588 value
= ((conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
) ?
590 PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
591 rt2x00_set_field32(®
, TXCSR1_ACK_TIMEOUT
, value
);
592 value
= SIFS
+ PLCP
+ preamble
+ get_duration(ACK_SIZE
, 10);
593 rt2x00_set_field32(®
, TXCSR1_ACK_CONSUME_TIME
, value
);
594 rt2x00pci_register_write(rt2x00dev
, TXCSR1
, reg
);
596 preamble
= DEVICE_GET_RATE_FIELD(rate
, PREAMBLE
) ? 0x08 : 0x00;
598 rt2x00pci_register_read(rt2x00dev
, ARCSR2
, ®
);
599 rt2x00_set_field32(®
, ARCSR2_SIGNAL
, 0x00 | preamble
);
600 rt2x00_set_field32(®
, ARCSR2_SERVICE
, 0x04);
601 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 10));
602 rt2x00pci_register_write(rt2x00dev
, ARCSR2
, reg
);
604 rt2x00pci_register_read(rt2x00dev
, ARCSR3
, ®
);
605 rt2x00_set_field32(®
, ARCSR3_SIGNAL
, 0x01 | preamble
);
606 rt2x00_set_field32(®
, ARCSR3_SERVICE
, 0x04);
607 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 20));
608 rt2x00pci_register_write(rt2x00dev
, ARCSR3
, reg
);
610 rt2x00pci_register_read(rt2x00dev
, ARCSR4
, ®
);
611 rt2x00_set_field32(®
, ARCSR4_SIGNAL
, 0x02 | preamble
);
612 rt2x00_set_field32(®
, ARCSR4_SERVICE
, 0x04);
613 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 55));
614 rt2x00pci_register_write(rt2x00dev
, ARCSR4
, reg
);
616 rt2x00pci_register_read(rt2x00dev
, ARCSR5
, ®
);
617 rt2x00_set_field32(®
, ARCSR5_SIGNAL
, 0x03 | preamble
);
618 rt2x00_set_field32(®
, ARCSR5_SERVICE
, 0x84);
619 rt2x00_set_field32(®
, ARCSR2_LENGTH
, get_duration(ACK_SIZE
, 110));
620 rt2x00pci_register_write(rt2x00dev
, ARCSR5
, reg
);
623 static void rt2500pci_config_phymode(struct rt2x00_dev
*rt2x00dev
,
626 struct ieee80211_hw_mode
*mode
;
627 struct ieee80211_rate
*rate
;
629 if (phymode
== MODE_IEEE80211A
)
630 rt2x00dev
->curr_hwmode
= HWMODE_A
;
631 else if (phymode
== MODE_IEEE80211B
)
632 rt2x00dev
->curr_hwmode
= HWMODE_B
;
634 rt2x00dev
->curr_hwmode
= HWMODE_G
;
636 mode
= &rt2x00dev
->hwmodes
[rt2x00dev
->curr_hwmode
];
637 rate
= &mode
->rates
[mode
->num_rates
- 1];
639 rt2500pci_config_rate(rt2x00dev
, rate
->val2
);
642 static void rt2500pci_config_mac_addr(struct rt2x00_dev
*rt2x00dev
, u8
*addr
)
646 memset(®
, 0, sizeof(reg
));
647 memcpy(®
, addr
, ETH_ALEN
);
650 * The MAC address is passed to us as an array of bytes,
651 * that array is little endian, so no need for byte ordering.
653 rt2x00pci_register_multiwrite(rt2x00dev
, CSR3
, ®
, sizeof(reg
));
659 static void rt2500pci_enable_led(struct rt2x00_dev
*rt2x00dev
)
663 rt2x00pci_register_read(rt2x00dev
, LEDCSR
, ®
);
665 rt2x00_set_field32(®
, LEDCSR_ON_PERIOD
, 70);
666 rt2x00_set_field32(®
, LEDCSR_OFF_PERIOD
, 30);
668 if (rt2x00dev
->led_mode
== LED_MODE_TXRX_ACTIVITY
) {
669 rt2x00_set_field32(®
, LEDCSR_LINK
, 1);
670 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 0);
671 } else if (rt2x00dev
->led_mode
== LED_MODE_ASUS
) {
672 rt2x00_set_field32(®
, LEDCSR_LINK
, 0);
673 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 1);
675 rt2x00_set_field32(®
, LEDCSR_LINK
, 1);
676 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 1);
679 rt2x00pci_register_write(rt2x00dev
, LEDCSR
, reg
);
682 static void rt2500pci_disable_led(struct rt2x00_dev
*rt2x00dev
)
686 rt2x00pci_register_read(rt2x00dev
, LEDCSR
, ®
);
687 rt2x00_set_field32(®
, LEDCSR_LINK
, 0);
688 rt2x00_set_field32(®
, LEDCSR_ACTIVITY
, 0);
689 rt2x00pci_register_write(rt2x00dev
, LEDCSR
, reg
);
695 static void rt2500pci_link_tuner(struct rt2x00_dev
*rt2x00dev
, int rssi
)
701 * To prevent collisions with MAC ASIC on chipsets
702 * up to version C the link tuning should halt after 20
705 if (rt2x00_rev(&rt2x00dev
->chip
) < RT2560_VERSION_D
&&
706 rt2x00dev
->link
.count
> 20)
709 rt2500pci_bbp_read(rt2x00dev
, 17, &r17
);
712 * Chipset versions C and lower should directly continue
713 * to the dynamic CCA tuning.
715 if (rt2x00_rev(&rt2x00dev
->chip
) < RT2560_VERSION_D
)
716 goto dynamic_cca_tune
;
719 * A too low RSSI will cause too much false CCA which will
720 * then corrupt the R17 tuning. To remidy this the tuning should
721 * be stopped (While making sure the R17 value will not exceed limits)
723 if (rssi
< -80 && rt2x00dev
->link
.count
> 20) {
725 r17
= rt2x00dev
->link
.curr_noise
;
726 rt2500pci_bbp_write(rt2x00dev
, 17, r17
);
732 * Special big-R17 for short distance
736 rt2500pci_bbp_write(rt2x00dev
, 17, 0x50);
741 * Special mid-R17 for middle distance
745 rt2500pci_bbp_write(rt2x00dev
, 17, 0x41);
750 * Leave short or middle distance condition, restore r17
751 * to the dynamic tuning range.
754 rt2500pci_bbp_write(rt2x00dev
, 17, rt2x00dev
->link
.curr_noise
);
761 * R17 is inside the dynamic tuning range,
762 * start tuning the link based on the false cca counter.
764 rt2x00pci_register_read(rt2x00dev
, CNT3
, ®
);
765 rt2x00dev
->link
.false_cca
= rt2x00_get_field32(reg
, CNT3_FALSE_CCA
);
767 if (rt2x00dev
->link
.false_cca
> 512 && r17
< 0x40) {
768 rt2500pci_bbp_write(rt2x00dev
, 17, ++r17
);
769 rt2x00dev
->link
.curr_noise
= r17
;
770 } else if (rt2x00dev
->link
.false_cca
< 100 && r17
> 0x32) {
771 rt2500pci_bbp_write(rt2x00dev
, 17, --r17
);
772 rt2x00dev
->link
.curr_noise
= r17
;
777 * Initialization functions.
779 static void rt2500pci_init_rxring(struct rt2x00_dev
*rt2x00dev
)
781 struct data_desc
*rxd
;
785 memset(rt2x00dev
->rx
->data_addr
, 0x00,
786 rt2x00_get_ring_size(rt2x00dev
->rx
));
788 for (i
= 0; i
< rt2x00dev
->rx
->stats
.limit
; i
++) {
789 rxd
= rt2x00dev
->rx
->entry
[i
].priv
;
791 rt2x00_desc_read(rxd
, 1, &word
);
792 rt2x00_set_field32(&word
, RXD_W1_BUFFER_ADDRESS
,
793 rt2x00dev
->rx
->entry
[i
].data_dma
);
794 rt2x00_desc_write(rxd
, 1, word
);
796 rt2x00_desc_read(rxd
, 0, &word
);
797 rt2x00_set_field32(&word
, RXD_W0_OWNER_NIC
, 1);
798 rt2x00_desc_write(rxd
, 0, word
);
801 rt2x00_ring_index_clear(rt2x00dev
->rx
);
804 static void rt2500pci_init_txring(struct rt2x00_dev
*rt2x00dev
,
807 struct data_ring
*ring
= rt2x00_get_ring(rt2x00dev
, queue
);
808 struct data_desc
*txd
;
812 memset(ring
->data_addr
, 0x00, rt2x00_get_ring_size(ring
));
814 for (i
= 0; i
< ring
->stats
.limit
; i
++) {
815 txd
= ring
->entry
[i
].priv
;
817 rt2x00_desc_read(txd
, 1, &word
);
818 rt2x00_set_field32(&word
, TXD_W1_BUFFER_ADDRESS
,
819 ring
->entry
[i
].data_dma
);
820 rt2x00_desc_write(txd
, 1, word
);
822 rt2x00_desc_read(txd
, 0, &word
);
823 rt2x00_set_field32(&word
, TXD_W0_VALID
, 0);
824 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 0);
825 rt2x00_desc_write(txd
, 0, word
);
828 rt2x00_ring_index_clear(ring
);
831 static int rt2500pci_init_rings(struct rt2x00_dev
*rt2x00dev
)
838 rt2500pci_init_rxring(rt2x00dev
);
839 rt2500pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_DATA0
);
840 rt2500pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_DATA1
);
841 rt2500pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_AFTER_BEACON
);
842 rt2500pci_init_txring(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
845 * Initialize registers.
847 rt2x00pci_register_read(rt2x00dev
, TXCSR2
, ®
);
848 rt2x00_set_field32(®
, TXCSR2_TXD_SIZE
,
849 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].desc_size
);
850 rt2x00_set_field32(®
, TXCSR2_NUM_TXD
,
851 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA1
].stats
.limit
);
852 rt2x00_set_field32(®
, TXCSR2_NUM_ATIM
,
853 rt2x00dev
->bcn
[1].stats
.limit
);
854 rt2x00_set_field32(®
, TXCSR2_NUM_PRIO
,
855 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].stats
.limit
);
856 rt2x00pci_register_write(rt2x00dev
, TXCSR2
, reg
);
858 rt2x00pci_register_read(rt2x00dev
, TXCSR3
, ®
);
859 rt2x00_set_field32(®
, TXCSR3_TX_RING_REGISTER
,
860 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA1
].data_dma
);
861 rt2x00pci_register_write(rt2x00dev
, TXCSR3
, reg
);
863 rt2x00pci_register_read(rt2x00dev
, TXCSR5
, ®
);
864 rt2x00_set_field32(®
, TXCSR5_PRIO_RING_REGISTER
,
865 rt2x00dev
->tx
[IEEE80211_TX_QUEUE_DATA0
].data_dma
);
866 rt2x00pci_register_write(rt2x00dev
, TXCSR5
, reg
);
868 rt2x00pci_register_read(rt2x00dev
, TXCSR4
, ®
);
869 rt2x00_set_field32(®
, TXCSR4_ATIM_RING_REGISTER
,
870 rt2x00dev
->bcn
[1].data_dma
);
871 rt2x00pci_register_write(rt2x00dev
, TXCSR4
, reg
);
873 rt2x00pci_register_read(rt2x00dev
, TXCSR6
, ®
);
874 rt2x00_set_field32(®
, TXCSR6_BEACON_RING_REGISTER
,
875 rt2x00dev
->bcn
[0].data_dma
);
876 rt2x00pci_register_write(rt2x00dev
, TXCSR6
, reg
);
878 rt2x00pci_register_read(rt2x00dev
, RXCSR1
, ®
);
879 rt2x00_set_field32(®
, RXCSR1_RXD_SIZE
,
880 rt2x00dev
->rx
->desc_size
);
881 rt2x00_set_field32(®
, RXCSR1_NUM_RXD
,
882 rt2x00dev
->rx
->stats
.limit
);
883 rt2x00pci_register_write(rt2x00dev
, RXCSR1
, reg
);
885 rt2x00pci_register_read(rt2x00dev
, RXCSR2
, ®
);
886 rt2x00_set_field32(®
, RXCSR2_RX_RING_REGISTER
,
887 rt2x00dev
->rx
->data_dma
);
888 rt2x00pci_register_write(rt2x00dev
, RXCSR2
, reg
);
893 static int rt2500pci_init_registers(struct rt2x00_dev
*rt2x00dev
)
897 if (rt2x00dev
->ops
->lib
->set_device_state(rt2x00dev
, STATE_AWAKE
))
900 rt2x00pci_register_write(rt2x00dev
, PWRCSR0
, 0x3f3b3100);
901 rt2x00pci_register_write(rt2x00dev
, PCICSR
, 0x000003b8);
903 rt2x00pci_register_write(rt2x00dev
, PSCSR0
, 0x00020002);
904 rt2x00pci_register_write(rt2x00dev
, PSCSR1
, 0x00000002);
905 rt2x00pci_register_write(rt2x00dev
, PSCSR2
, 0x00020002);
906 rt2x00pci_register_write(rt2x00dev
, PSCSR3
, 0x00000002);
908 rt2x00pci_register_read(rt2x00dev
, TIMECSR
, ®
);
909 rt2x00_set_field32(®
, TIMECSR_US_COUNT
, 33);
910 rt2x00_set_field32(®
, TIMECSR_US_64_COUNT
, 63);
911 rt2x00_set_field32(®
, TIMECSR_BEACON_EXPECT
, 0);
912 rt2x00pci_register_write(rt2x00dev
, TIMECSR
, reg
);
914 rt2x00pci_register_read(rt2x00dev
, CSR9
, ®
);
915 rt2x00_set_field32(®
, CSR9_MAX_FRAME_UNIT
,
916 rt2x00dev
->rx
->data_size
/ 128);
917 rt2x00pci_register_write(rt2x00dev
, CSR9
, reg
);
919 rt2x00pci_register_write(rt2x00dev
, CNT3
, 0);
921 rt2x00pci_register_write(rt2x00dev
, GPIOCSR
, 0x0000ff00);
922 rt2x00pci_register_write(rt2x00dev
, TESTCSR
, 0x000000f0);
924 rt2x00pci_register_write(rt2x00dev
, MACCSR0
, 0x00213223);
925 rt2x00pci_register_write(rt2x00dev
, MACCSR1
, 0x00235518);
927 rt2x00pci_register_read(rt2x00dev
, MACCSR2
, ®
);
928 rt2x00_set_field32(®
, MACCSR2_DELAY
, 64);
929 rt2x00pci_register_write(rt2x00dev
, MACCSR2
, reg
);
932 * Always use CWmin and CWmax set in descriptor.
934 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
935 rt2x00_set_field32(®
, CSR11_CW_SELECT
, 0);
936 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
938 rt2x00pci_register_read(rt2x00dev
, RXCSR3
, ®
);
942 rt2x00_set_field32(®
, RXCSR3_BBP_ID0
, 47);
943 rt2x00_set_field32(®
, RXCSR3_BBP_ID0_VALID
, 1);
947 rt2x00_set_field32(®
, RXCSR3_BBP_ID1
, 51);
948 rt2x00_set_field32(®
, RXCSR3_BBP_ID1_VALID
, 1);
952 rt2x00_set_field32(®
, RXCSR3_BBP_ID2
, 42);
953 rt2x00_set_field32(®
, RXCSR3_BBP_ID2_VALID
, 1);
957 rt2x00_set_field32(®
, RXCSR3_BBP_ID3
, 51);
958 rt2x00_set_field32(®
, RXCSR3_BBP_ID3_VALID
, 1);
959 rt2x00pci_register_write(rt2x00dev
, RXCSR3
, reg
);
961 rt2x00pci_register_read(rt2x00dev
, RALINKCSR
, ®
);
962 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_DATA0
, 17);
963 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_ID0
, 26);
964 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_VALID0
, 1);
965 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_DATA1
, 0);
966 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_ID1
, 26);
967 rt2x00_set_field32(®
, RALINKCSR_AR_BBP_VALID1
, 1);
968 rt2x00pci_register_write(rt2x00dev
, RALINKCSR
, reg
);
970 rt2x00pci_register_write(rt2x00dev
, BBPCSR1
, 0x82188200);
972 rt2x00pci_register_write(rt2x00dev
, TXACKCSR0
, 0x00000020);
974 rt2x00pci_register_write(rt2x00dev
, ARTCSR0
, 0x7038140a);
975 rt2x00pci_register_write(rt2x00dev
, ARTCSR1
, 0x1d21252d);
976 rt2x00pci_register_write(rt2x00dev
, ARTCSR2
, 0x1919191d);
978 rt2x00pci_register_read(rt2x00dev
, CSR1
, ®
);
979 rt2x00_set_field32(®
, CSR1_SOFT_RESET
, 1);
980 rt2x00_set_field32(®
, CSR1_BBP_RESET
, 0);
981 rt2x00_set_field32(®
, CSR1_HOST_READY
, 0);
982 rt2x00pci_register_write(rt2x00dev
, CSR1
, reg
);
984 rt2x00pci_register_read(rt2x00dev
, CSR1
, ®
);
985 rt2x00_set_field32(®
, CSR1_SOFT_RESET
, 0);
986 rt2x00_set_field32(®
, CSR1_HOST_READY
, 1);
987 rt2x00pci_register_write(rt2x00dev
, CSR1
, reg
);
990 * We must clear the FCS and FIFO error count.
991 * These registers are cleared on read,
992 * so we may pass a useless variable to store the value.
994 rt2x00pci_register_read(rt2x00dev
, CNT0
, ®
);
995 rt2x00pci_register_read(rt2x00dev
, CNT4
, ®
);
1000 static int rt2500pci_init_bbp(struct rt2x00_dev
*rt2x00dev
)
1007 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1008 rt2500pci_bbp_read(rt2x00dev
, 0, &value
);
1009 if ((value
!= 0xff) && (value
!= 0x00))
1010 goto continue_csr_init
;
1011 NOTICE(rt2x00dev
, "Waiting for BBP register.\n");
1012 udelay(REGISTER_BUSY_DELAY
);
1015 ERROR(rt2x00dev
, "BBP register access failed, aborting.\n");
1019 rt2500pci_bbp_write(rt2x00dev
, 3, 0x02);
1020 rt2500pci_bbp_write(rt2x00dev
, 4, 0x19);
1021 rt2500pci_bbp_write(rt2x00dev
, 14, 0x1c);
1022 rt2500pci_bbp_write(rt2x00dev
, 15, 0x30);
1023 rt2500pci_bbp_write(rt2x00dev
, 16, 0xac);
1024 rt2500pci_bbp_write(rt2x00dev
, 17, 0x48);
1025 rt2500pci_bbp_write(rt2x00dev
, 18, 0x18);
1026 rt2500pci_bbp_write(rt2x00dev
, 19, 0xff);
1027 rt2500pci_bbp_write(rt2x00dev
, 20, 0x1e);
1028 rt2500pci_bbp_write(rt2x00dev
, 21, 0x08);
1029 rt2500pci_bbp_write(rt2x00dev
, 22, 0x08);
1030 rt2500pci_bbp_write(rt2x00dev
, 23, 0x08);
1031 rt2500pci_bbp_write(rt2x00dev
, 24, 0x70);
1032 rt2500pci_bbp_write(rt2x00dev
, 25, 0x40);
1033 rt2500pci_bbp_write(rt2x00dev
, 26, 0x08);
1034 rt2500pci_bbp_write(rt2x00dev
, 27, 0x23);
1035 rt2500pci_bbp_write(rt2x00dev
, 30, 0x10);
1036 rt2500pci_bbp_write(rt2x00dev
, 31, 0x2b);
1037 rt2500pci_bbp_write(rt2x00dev
, 32, 0xb9);
1038 rt2500pci_bbp_write(rt2x00dev
, 34, 0x12);
1039 rt2500pci_bbp_write(rt2x00dev
, 35, 0x50);
1040 rt2500pci_bbp_write(rt2x00dev
, 39, 0xc4);
1041 rt2500pci_bbp_write(rt2x00dev
, 40, 0x02);
1042 rt2500pci_bbp_write(rt2x00dev
, 41, 0x60);
1043 rt2500pci_bbp_write(rt2x00dev
, 53, 0x10);
1044 rt2500pci_bbp_write(rt2x00dev
, 54, 0x18);
1045 rt2500pci_bbp_write(rt2x00dev
, 56, 0x08);
1046 rt2500pci_bbp_write(rt2x00dev
, 57, 0x10);
1047 rt2500pci_bbp_write(rt2x00dev
, 58, 0x08);
1048 rt2500pci_bbp_write(rt2x00dev
, 61, 0x6d);
1049 rt2500pci_bbp_write(rt2x00dev
, 62, 0x10);
1051 DEBUG(rt2x00dev
, "Start initialization from EEPROM...\n");
1052 for (i
= 0; i
< EEPROM_BBP_SIZE
; i
++) {
1053 rt2x00_eeprom_read(rt2x00dev
, EEPROM_BBP_START
+ i
, &eeprom
);
1055 if (eeprom
!= 0xffff && eeprom
!= 0x0000) {
1056 reg_id
= rt2x00_get_field16(eeprom
, EEPROM_BBP_REG_ID
);
1057 value
= rt2x00_get_field16(eeprom
, EEPROM_BBP_VALUE
);
1058 DEBUG(rt2x00dev
, "BBP: 0x%02x, value: 0x%02x.\n",
1060 rt2500pci_bbp_write(rt2x00dev
, reg_id
, value
);
1063 DEBUG(rt2x00dev
, "...End initialization from EEPROM.\n");
1069 * Device state switch handlers.
1071 static void rt2500pci_toggle_rx(struct rt2x00_dev
*rt2x00dev
,
1072 enum dev_state state
)
1076 rt2x00pci_register_read(rt2x00dev
, RXCSR0
, ®
);
1077 rt2x00_set_field32(®
, RXCSR0_DISABLE_RX
,
1078 state
== STATE_RADIO_RX_OFF
);
1079 rt2x00pci_register_write(rt2x00dev
, RXCSR0
, reg
);
1082 static int rt2500pci_enable_radio(struct rt2x00_dev
*rt2x00dev
)
1087 * Initialize all registers.
1089 if (rt2500pci_init_rings(rt2x00dev
) ||
1090 rt2500pci_init_registers(rt2x00dev
) ||
1091 rt2500pci_init_bbp(rt2x00dev
)) {
1092 ERROR(rt2x00dev
, "Register initialization failed.\n");
1099 rt2x00pci_register_read(rt2x00dev
, CSR7
, ®
);
1100 rt2x00pci_register_write(rt2x00dev
, CSR7
, reg
);
1103 * Enable interrupts.
1105 rt2x00pci_register_read(rt2x00dev
, CSR8
, ®
);
1106 rt2x00_set_field32(®
, CSR8_TBCN_EXPIRE
, 0);
1107 rt2x00_set_field32(®
, CSR8_TXDONE_TXRING
, 0);
1108 rt2x00_set_field32(®
, CSR8_TXDONE_ATIMRING
, 0);
1109 rt2x00_set_field32(®
, CSR8_TXDONE_PRIORING
, 0);
1110 rt2x00_set_field32(®
, CSR8_RXDONE
, 0);
1111 rt2x00pci_register_write(rt2x00dev
, CSR8
, reg
);
1116 rt2500pci_enable_led(rt2x00dev
);
1121 static void rt2500pci_disable_radio(struct rt2x00_dev
*rt2x00dev
)
1128 rt2500pci_disable_led(rt2x00dev
);
1130 rt2x00pci_register_write(rt2x00dev
, PWRCSR0
, 0);
1133 * Disable synchronisation.
1135 rt2x00pci_register_write(rt2x00dev
, CSR14
, 0);
1140 rt2x00pci_register_read(rt2x00dev
, TXCSR0
, ®
);
1141 rt2x00_set_field32(®
, TXCSR0_ABORT
, 1);
1142 rt2x00pci_register_write(rt2x00dev
, TXCSR0
, reg
);
1145 * Disable interrupts.
1147 rt2x00pci_register_read(rt2x00dev
, CSR8
, ®
);
1148 rt2x00_set_field32(®
, CSR8_TBCN_EXPIRE
, 1);
1149 rt2x00_set_field32(®
, CSR8_TXDONE_TXRING
, 1);
1150 rt2x00_set_field32(®
, CSR8_TXDONE_ATIMRING
, 1);
1151 rt2x00_set_field32(®
, CSR8_TXDONE_PRIORING
, 1);
1152 rt2x00_set_field32(®
, CSR8_RXDONE
, 1);
1153 rt2x00pci_register_write(rt2x00dev
, CSR8
, reg
);
1156 static int rt2500pci_set_state(struct rt2x00_dev
*rt2x00dev
,
1157 enum dev_state state
)
1165 put_to_sleep
= (state
!= STATE_AWAKE
);
1167 rt2x00pci_register_read(rt2x00dev
, PWRCSR1
, ®
);
1168 rt2x00_set_field32(®
, PWRCSR1_SET_STATE
, 1);
1169 rt2x00_set_field32(®
, PWRCSR1_BBP_DESIRE_STATE
, state
);
1170 rt2x00_set_field32(®
, PWRCSR1_RF_DESIRE_STATE
, state
);
1171 rt2x00_set_field32(®
, PWRCSR1_PUT_TO_SLEEP
, put_to_sleep
);
1172 rt2x00pci_register_write(rt2x00dev
, PWRCSR1
, reg
);
1175 * Device is not guaranteed to be in the requested state yet.
1176 * We must wait until the register indicates that the
1177 * device has entered the correct state.
1179 for (i
= 0; i
< REGISTER_BUSY_COUNT
; i
++) {
1180 rt2x00pci_register_read(rt2x00dev
, PWRCSR1
, ®
);
1181 bbp_state
= rt2x00_get_field32(reg
, PWRCSR1_BBP_CURR_STATE
);
1182 rf_state
= rt2x00_get_field32(reg
, PWRCSR1_RF_CURR_STATE
);
1183 if (bbp_state
== state
&& rf_state
== state
)
1188 NOTICE(rt2x00dev
, "Device failed to enter state %d, "
1189 "current device state: bbp %d and rf %d.\n",
1190 state
, bbp_state
, rf_state
);
1195 static int rt2500pci_set_device_state(struct rt2x00_dev
*rt2x00dev
,
1196 enum dev_state state
)
1201 case STATE_RADIO_ON
:
1202 retval
= rt2500pci_enable_radio(rt2x00dev
);
1204 case STATE_RADIO_OFF
:
1205 rt2500pci_disable_radio(rt2x00dev
);
1207 case STATE_RADIO_RX_ON
:
1208 case STATE_RADIO_RX_OFF
:
1209 rt2500pci_toggle_rx(rt2x00dev
, state
);
1211 case STATE_DEEP_SLEEP
:
1215 retval
= rt2500pci_set_state(rt2x00dev
, state
);
1226 * TX descriptor initialization
1228 static void rt2500pci_write_tx_desc(struct rt2x00_dev
*rt2x00dev
,
1229 struct data_entry
*entry
, struct data_desc
*txd
,
1230 struct data_entry_desc
*desc
, struct ieee80211_hdr
*ieee80211hdr
,
1231 unsigned int length
, struct ieee80211_tx_control
*control
)
1236 * Start writing the descriptor words.
1238 rt2x00_desc_read(txd
, 2, &word
);
1239 rt2x00_set_field32(&word
, TXD_W2_IV_OFFSET
, IEEE80211_HEADER
);
1240 rt2x00_set_field32(&word
, TXD_W2_AIFS
, entry
->ring
->tx_params
.aifs
);
1241 rt2x00_set_field32(&word
, TXD_W2_CWMIN
, entry
->ring
->tx_params
.cw_min
);
1242 rt2x00_set_field32(&word
, TXD_W2_CWMAX
, entry
->ring
->tx_params
.cw_max
);
1243 rt2x00_desc_write(txd
, 2, word
);
1245 rt2x00_desc_read(txd
, 3, &word
);
1246 rt2x00_set_field32(&word
, TXD_W3_PLCP_SIGNAL
, desc
->signal
);
1247 rt2x00_set_field32(&word
, TXD_W3_PLCP_SERVICE
, desc
->service
);
1248 rt2x00_set_field32(&word
, TXD_W3_PLCP_LENGTH_LOW
, desc
->length_low
);
1249 rt2x00_set_field32(&word
, TXD_W3_PLCP_LENGTH_HIGH
, desc
->length_high
);
1250 rt2x00_desc_write(txd
, 3, word
);
1252 rt2x00_desc_read(txd
, 10, &word
);
1253 rt2x00_set_field32(&word
, TXD_W10_RTS
,
1254 test_bit(ENTRY_TXD_RTS_FRAME
, &entry
->flags
));
1255 rt2x00_desc_write(txd
, 10, word
);
1257 rt2x00_desc_read(txd
, 0, &word
);
1258 rt2x00_set_field32(&word
, TXD_W0_OWNER_NIC
, 1);
1259 rt2x00_set_field32(&word
, TXD_W0_VALID
, 1);
1260 rt2x00_set_field32(&word
, TXD_W0_MORE_FRAG
,
1261 test_bit(ENTRY_TXD_MORE_FRAG
, &entry
->flags
));
1262 rt2x00_set_field32(&word
, TXD_W0_ACK
,
1263 test_bit(ENTRY_TXD_REQ_ACK
, &entry
->flags
));
1264 rt2x00_set_field32(&word
, TXD_W0_TIMESTAMP
,
1265 test_bit(ENTRY_TXD_REQ_TIMESTAMP
, &entry
->flags
));
1266 rt2x00_set_field32(&word
, TXD_W0_OFDM
,
1267 test_bit(ENTRY_TXD_OFDM_RATE
, &entry
->flags
));
1268 rt2x00_set_field32(&word
, TXD_W0_CIPHER_OWNER
, 1);
1269 rt2x00_set_field32(&word
, TXD_W0_IFS
, desc
->ifs
);
1270 rt2x00_set_field32(&word
, TXD_W0_RETRY_MODE
, 0);
1271 rt2x00_set_field32(&word
, TXD_W0_DATABYTE_COUNT
, length
);
1272 rt2x00_set_field32(&word
, TXD_W0_CIPHER_ALG
, CIPHER_NONE
);
1273 rt2x00_desc_write(txd
, 0, word
);
1277 * TX data initialization
1279 static void rt2500pci_kick_tx_queue(struct rt2x00_dev
*rt2x00dev
, int queue
)
1283 if (queue
== IEEE80211_TX_QUEUE_BEACON
) {
1284 rt2x00pci_register_read(rt2x00dev
, CSR14
, ®
);
1285 if (!rt2x00_get_field32(reg
, CSR14_BEACON_GEN
)) {
1286 rt2x00_set_field32(®
, CSR14_BEACON_GEN
, 1);
1287 rt2x00pci_register_write(rt2x00dev
, CSR14
, reg
);
1292 rt2x00pci_register_read(rt2x00dev
, TXCSR0
, ®
);
1293 if (queue
== IEEE80211_TX_QUEUE_DATA0
)
1294 rt2x00_set_field32(®
, TXCSR0_KICK_PRIO
, 1);
1295 else if (queue
== IEEE80211_TX_QUEUE_DATA1
)
1296 rt2x00_set_field32(®
, TXCSR0_KICK_TX
, 1);
1297 else if (queue
== IEEE80211_TX_QUEUE_AFTER_BEACON
)
1298 rt2x00_set_field32(®
, TXCSR0_KICK_ATIM
, 1);
1299 rt2x00pci_register_write(rt2x00dev
, TXCSR0
, reg
);
1303 * Interrupt functions.
1305 static void rt2500pci_rxdone(struct rt2x00_dev
*rt2x00dev
)
1307 struct data_ring
*ring
= rt2x00dev
->rx
;
1308 struct data_entry
*entry
;
1309 struct data_desc
*rxd
;
1318 entry
= rt2x00_get_data_entry(ring
);
1320 rt2x00_desc_read(rxd
, 0, &word0
);
1321 rt2x00_desc_read(rxd
, 2, &word2
);
1323 if (rt2x00_get_field32(word0
, RXD_W0_OWNER_NIC
))
1327 * TODO: Don't we need to keep statistics
1328 * updated about events like CRC and physical errors?
1330 if (rt2x00_get_field32(word0
, RXD_W0_CRC
) ||
1331 rt2x00_get_field32(word0
, RXD_W0_PHYSICAL_ERROR
))
1335 * Obtain the status about this packet.
1337 size
= rt2x00_get_field32(word0
, RXD_W0_DATABYTE_COUNT
);
1338 signal
= rt2x00_get_field32(word2
, RXD_W2_SIGNAL
);
1339 rssi
= rt2x00_get_field32(word2
, RXD_W2_RSSI
);
1340 ofdm
= rt2x00_get_field32(word0
, RXD_W0_OFDM
);
1343 * Send the packet to upper layer.
1345 rt2x00lib_rxdone(entry
, entry
->data_addr
, size
,
1346 signal
, rssi
, ofdm
);
1349 if (test_bit(DEVICE_ENABLED_RADIO
, &ring
->rt2x00dev
->flags
)) {
1350 rt2x00_set_field32(&word0
, RXD_W0_OWNER_NIC
, 1);
1351 rt2x00_desc_write(rxd
, 0, word0
);
1354 rt2x00_ring_index_inc(ring
);
1358 static void rt2500pci_txdone(struct rt2x00_dev
*rt2x00dev
, const int queue
)
1360 struct data_ring
*ring
= rt2x00_get_ring(rt2x00dev
, queue
);
1361 struct data_entry
*entry
;
1362 struct data_desc
*txd
;
1367 while (!rt2x00_ring_empty(ring
)) {
1368 entry
= rt2x00_get_data_entry_done(ring
);
1370 rt2x00_desc_read(txd
, 0, &word
);
1372 if (rt2x00_get_field32(word
, TXD_W0_OWNER_NIC
) ||
1373 !rt2x00_get_field32(word
, TXD_W0_VALID
))
1377 * Obtain the status about this packet.
1379 tx_status
= rt2x00_get_field32(word
, TXD_W0_RESULT
);
1380 retry
= rt2x00_get_field32(word
, TXD_W0_RETRY_COUNT
);
1382 rt2x00lib_txdone(entry
, tx_status
, retry
);
1385 * Make this entry available for reuse.
1388 rt2x00_set_field32(&word
, TXD_W0_VALID
, 0);
1389 rt2x00_desc_write(txd
, 0, word
);
1390 rt2x00_ring_index_done_inc(ring
);
1394 * If the data ring was full before the txdone handler
1395 * we must make sure the packet queue in the mac80211 stack
1396 * is reenabled when the txdone handler has finished.
1398 entry
= ring
->entry
;
1399 if (!rt2x00_ring_full(ring
))
1400 ieee80211_wake_queue(rt2x00dev
->hw
,
1401 entry
->tx_status
.control
.queue
);
1404 static irqreturn_t
rt2500pci_interrupt(int irq
, void *dev_instance
)
1406 struct rt2x00_dev
*rt2x00dev
= dev_instance
;
1410 * Get the interrupt sources & saved to local variable.
1411 * Write register value back to clear pending interrupts.
1413 rt2x00pci_register_read(rt2x00dev
, CSR7
, ®
);
1414 rt2x00pci_register_write(rt2x00dev
, CSR7
, reg
);
1419 if (!test_bit(DEVICE_ENABLED_RADIO
, &rt2x00dev
->flags
))
1423 * Handle interrupts, walk through all bits
1424 * and run the tasks, the bits are checked in order of
1429 * 1 - Beacon timer expired interrupt.
1431 if (rt2x00_get_field32(reg
, CSR7_TBCN_EXPIRE
))
1432 rt2x00pci_beacondone(rt2x00dev
, IEEE80211_TX_QUEUE_BEACON
);
1435 * 2 - Rx ring done interrupt.
1437 if (rt2x00_get_field32(reg
, CSR7_RXDONE
))
1438 rt2500pci_rxdone(rt2x00dev
);
1441 * 3 - Atim ring transmit done interrupt.
1443 if (rt2x00_get_field32(reg
, CSR7_TXDONE_ATIMRING
))
1444 rt2500pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_AFTER_BEACON
);
1447 * 4 - Priority ring transmit done interrupt.
1449 if (rt2x00_get_field32(reg
, CSR7_TXDONE_PRIORING
))
1450 rt2500pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_DATA0
);
1453 * 5 - Tx ring transmit done interrupt.
1455 if (rt2x00_get_field32(reg
, CSR7_TXDONE_TXRING
))
1456 rt2500pci_txdone(rt2x00dev
, IEEE80211_TX_QUEUE_DATA1
);
1462 * Device initialization functions.
1464 static int rt2500pci_alloc_eeprom(struct rt2x00_dev
*rt2x00dev
)
1466 struct eeprom_93cx6 eeprom
;
1471 * Allocate the eeprom memory, check the eeprom width
1472 * and copy the entire eeprom into this allocated memory.
1474 rt2x00dev
->eeprom
= kzalloc(EEPROM_SIZE
, GFP_KERNEL
);
1475 if (!rt2x00dev
->eeprom
)
1478 rt2x00pci_register_read(rt2x00dev
, CSR21
, ®
);
1480 eeprom
.data
= rt2x00dev
;
1481 eeprom
.register_read
= rt2500pci_eepromregister_read
;
1482 eeprom
.register_write
= rt2500pci_eepromregister_write
;
1483 eeprom
.width
= rt2x00_get_field32(reg
, CSR21_TYPE_93C46
) ?
1484 PCI_EEPROM_WIDTH_93C46
: PCI_EEPROM_WIDTH_93C66
;
1485 eeprom
.reg_data_in
= 0;
1486 eeprom
.reg_data_out
= 0;
1487 eeprom
.reg_data_clock
= 0;
1488 eeprom
.reg_chip_select
= 0;
1490 eeprom_93cx6_multiread(&eeprom
, EEPROM_BASE
, rt2x00dev
->eeprom
,
1491 EEPROM_SIZE
/ sizeof(u16
));
1494 * Start validation of the data that has been read.
1496 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &word
);
1497 if (word
== 0xffff) {
1498 rt2x00_set_field16(&word
, EEPROM_ANTENNA_NUM
, 2);
1499 rt2x00_set_field16(&word
, EEPROM_ANTENNA_TX_DEFAULT
, 0);
1500 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RX_DEFAULT
, 0);
1501 rt2x00_set_field16(&word
, EEPROM_ANTENNA_LED_MODE
, 0);
1502 rt2x00_set_field16(&word
, EEPROM_ANTENNA_DYN_TXAGC
, 0);
1503 rt2x00_set_field16(&word
, EEPROM_ANTENNA_HARDWARE_RADIO
, 0);
1504 rt2x00_set_field16(&word
, EEPROM_ANTENNA_RF_TYPE
, RF2522
);
1505 rt2x00_eeprom_write(rt2x00dev
, EEPROM_ANTENNA
, word
);
1506 EEPROM(rt2x00dev
, "Antenna: 0x%04x\n", word
);
1509 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &word
);
1510 if (word
== 0xffff) {
1511 rt2x00_set_field16(&word
, EEPROM_NIC_CARDBUS_ACCEL
, 0);
1512 rt2x00_set_field16(&word
, EEPROM_NIC_DYN_BBP_TUNE
, 0);
1513 rt2x00_set_field16(&word
, EEPROM_NIC_CCK_TX_POWER
, 0);
1514 rt2x00_eeprom_write(rt2x00dev
, EEPROM_NIC
, word
);
1515 EEPROM(rt2x00dev
, "NIC: 0x%04x\n", word
);
1518 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &word
);
1519 if (word
== 0xffff) {
1520 rt2x00_set_field16(&word
, EEPROM_CALIBRATE_OFFSET_RSSI
,
1522 rt2x00_eeprom_write(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, word
);
1523 EEPROM(rt2x00dev
, "Calibrate offset: 0x%04x\n", word
);
1529 static int rt2500pci_init_eeprom(struct rt2x00_dev
*rt2x00dev
)
1536 * Read EEPROM word for configuration.
1538 rt2x00_eeprom_read(rt2x00dev
, EEPROM_ANTENNA
, &eeprom
);
1541 * Identify RF chipset.
1543 value
= rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_RF_TYPE
);
1544 rt2x00pci_register_read(rt2x00dev
, CSR0
, ®
);
1545 rt2x00_set_chip(rt2x00dev
, RT2560
, value
, reg
);
1547 if (!rt2x00_rf(&rt2x00dev
->chip
, RF2522
) &&
1548 !rt2x00_rf(&rt2x00dev
->chip
, RF2523
) &&
1549 !rt2x00_rf(&rt2x00dev
->chip
, RF2524
) &&
1550 !rt2x00_rf(&rt2x00dev
->chip
, RF2525
) &&
1551 !rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) &&
1552 !rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
1553 ERROR(rt2x00dev
, "Invalid RF chipset detected.\n");
1558 * Identify default antenna configuration.
1560 rt2x00dev
->hw
->conf
.antenna_sel_tx
= rt2x00_get_field16(eeprom
,
1561 EEPROM_ANTENNA_TX_DEFAULT
);
1562 rt2x00dev
->hw
->conf
.antenna_sel_rx
= rt2x00_get_field16(eeprom
,
1563 EEPROM_ANTENNA_RX_DEFAULT
);
1566 * Store led mode, for correct led behaviour.
1568 rt2x00dev
->led_mode
= rt2x00_get_field16(eeprom
,
1569 EEPROM_ANTENNA_LED_MODE
);
1572 * Detect if this device has an hardware controlled radio.
1574 if (rt2x00_get_field16(eeprom
, EEPROM_ANTENNA_HARDWARE_RADIO
))
1575 __set_bit(DEVICE_SUPPORT_HW_BUTTON
, &rt2x00dev
->flags
);
1578 * Check if the BBP tuning should be enabled.
1580 rt2x00_eeprom_read(rt2x00dev
, EEPROM_NIC
, &eeprom
);
1582 if (rt2x00_get_field16(eeprom
, EEPROM_NIC_DYN_BBP_TUNE
))
1583 __set_bit(CONFIG_DISABLE_LINK_TUNING
, &rt2x00dev
->flags
);
1586 * Read the RSSI <-> dBm offset information.
1588 rt2x00_eeprom_read(rt2x00dev
, EEPROM_CALIBRATE_OFFSET
, &eeprom
);
1589 rt2x00dev
->hw
->max_rssi
=
1590 rt2x00_get_field16(eeprom
, EEPROM_CALIBRATE_OFFSET_RSSI
);
1595 static const struct {
1599 { RF2522
, { 0x00002050, 0x00000101, 0x00000000 } },
1600 { RF2523
, { 0x00022010, 0x000e0111, 0x00000a1b } },
1601 { RF2524
, { 0x00032020, 0x00000101, 0x00000a1b } },
1602 { RF2525
, { 0x00022020, 0x00060111, 0x00000a1b } },
1603 { RF2525E
, { 0x00022020, 0x00060111, 0x00000a0b } },
1604 { RF5222
, { 0x00000000, 0x00000101, 0x00000000 } },
1608 * RF value list for RF2522
1611 static const u32 rf_vals_bg_2522
[] = {
1612 0x000c1fda, 0x000c1fee, 0x000c2002, 0x000c2016, 0x000c202a,
1613 0x000c203e, 0x000c2052, 0x000c2066, 0x000c207a, 0x000c208e,
1614 0x000c20a2, 0x000c20b6, 0x000c20ca, 0x000c20fa
1618 * RF value list for RF2523, RF2524 & RF2525
1621 static const u32 rf_vals_bg_252x
[] = {
1622 0x00000c9e, 0x00000ca2, 0x00000ca6, 0x00000caa, 0x00000cae,
1623 0x00000cb2, 0x00000cb6, 0x00000cba, 0x00000cbe, 0x00000d02,
1624 0x00000d06, 0x00000d0a, 0x00000d0e, 0x00000d1a
1628 * RF value list for RF2525E & RF5222
1631 static const u32 rf_vals_bg_5x
[] = {
1632 0x00001136, 0x0000113a, 0x0000113e, 0x00001182, 0x00001186,
1633 0x0000118a, 0x0000118e, 0x00001192, 0x00001196, 0x0000119a,
1634 0x0000119e, 0x000011a2, 0x000011a6, 0x000011ae
1638 * RF value list for RF5222 (supplement to rf_vals_bg_5x)
1641 static const u32 rf_vals_a_5x
[] = {
1642 0x00018896, 0x0001889a, 0x0001889e, 0x000188a2, 0x000188a6,
1643 0x000188aa, 0x000188ae, 0x000188b2, 0x00008802, 0x00008806,
1644 0x0000880a, 0x0000880e, 0x00008812, 0x00008816, 0x0000881a,
1645 0x0000881e, 0x00008822, 0x00008826, 0x0000882a, 0x000090a6,
1646 0x000090ae, 0x000090b6, 0x000090be
1649 static void rt2500pci_init_hw_mode(struct rt2x00_dev
*rt2x00dev
)
1651 struct hw_mode_spec
*spec
= &rt2x00dev
->spec
;
1656 * Initialize all hw fields.
1658 rt2x00dev
->hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON
|
1659 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING
|
1660 IEEE80211_HW_WEP_INCLUDE_IV
|
1661 IEEE80211_HW_DATA_NULLFUNC_ACK
|
1662 IEEE80211_HW_NO_TKIP_WMM_HWACCEL
|
1663 IEEE80211_HW_MONITOR_DURING_OPER
;
1664 rt2x00dev
->hw
->extra_tx_headroom
= 0;
1665 rt2x00dev
->hw
->max_rssi
= MAX_RX_SSI
;
1666 rt2x00dev
->hw
->max_noise
= MAX_RX_NOISE
;
1667 rt2x00dev
->hw
->queues
= 2;
1670 * This device supports ATIM
1672 __set_bit(DEVICE_SUPPORT_ATIM
, &rt2x00dev
->flags
);
1675 * Set device specific, but channel independent RF values.
1677 for (i
= 0; i
< ARRAY_SIZE(rf_vals
); i
++) {
1678 if (rt2x00_rf(&rt2x00dev
->chip
, rf_vals
[i
].chip
)) {
1679 rt2x00dev
->rf1
= rf_vals
[i
].val
[0];
1680 rt2x00dev
->rf3
= rf_vals
[i
].val
[1];
1681 rt2x00dev
->rf4
= rf_vals
[i
].val
[2];
1686 * Convert tx_power array in eeprom.
1688 txpower
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_TXPOWER_START
);
1689 for (i
= 0; i
< 14; i
++)
1690 txpower
[i
] = TXPOWER_FROM_DEV(txpower
[i
]);
1693 * Initialize hw_mode information.
1695 spec
->mac_addr
= rt2x00_eeprom_addr(rt2x00dev
, EEPROM_MAC_ADDR_0
);
1696 spec
->num_modes
= 2;
1697 spec
->num_rates
= 12;
1698 spec
->num_channels
= 14;
1699 spec
->tx_power_a
= NULL
;
1700 spec
->tx_power_bg
= txpower
;
1701 spec
->tx_power_default
= DEFAULT_TXPOWER
;
1702 spec
->chan_val_a
= NULL
;
1704 if (rt2x00_rf(&rt2x00dev
->chip
, RF2522
))
1705 spec
->chan_val_bg
= rf_vals_bg_2522
;
1706 else if (rt2x00_rf(&rt2x00dev
->chip
, RF2523
) ||
1707 rt2x00_rf(&rt2x00dev
->chip
, RF2524
) ||
1708 rt2x00_rf(&rt2x00dev
->chip
, RF2525
))
1709 spec
->chan_val_bg
= rf_vals_bg_252x
;
1710 else if (rt2x00_rf(&rt2x00dev
->chip
, RF2525E
) ||
1711 rt2x00_rf(&rt2x00dev
->chip
, RF5222
))
1712 spec
->chan_val_bg
= rf_vals_bg_5x
;
1714 if (rt2x00_rf(&rt2x00dev
->chip
, RF5222
)) {
1715 spec
->num_modes
= 3;
1716 spec
->num_channels
+= 23;
1717 spec
->chan_val_a
= rf_vals_a_5x
;
1721 static int rt2500pci_init_hw(struct rt2x00_dev
*rt2x00dev
)
1726 * Allocate eeprom data.
1728 retval
= rt2500pci_alloc_eeprom(rt2x00dev
);
1732 retval
= rt2500pci_init_eeprom(rt2x00dev
);
1737 * Initialize hw specifications.
1739 rt2500pci_init_hw_mode(rt2x00dev
);
1745 * IEEE80211 stack callback functions.
1747 static int rt2500pci_get_stats(struct ieee80211_hw
*hw
,
1748 struct ieee80211_low_level_stats
*stats
)
1750 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1754 * Update FCS error count from register.
1755 * The dot11ACKFailureCount, dot11RTSFailureCount and
1756 * dot11RTSSuccessCount are updated in interrupt time.
1758 rt2x00pci_register_read(rt2x00dev
, CNT0
, ®
);
1759 rt2x00dev
->low_level_stats
.dot11FCSErrorCount
+=
1760 rt2x00_get_field32(reg
, CNT0_FCS_ERROR
);
1762 memcpy(stats
, &rt2x00dev
->low_level_stats
, sizeof(*stats
));
1767 static int rt2500pci_set_retry_limit(struct ieee80211_hw
*hw
,
1768 u32 short_retry
, u32 long_retry
)
1770 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1773 rt2x00pci_register_read(rt2x00dev
, CSR11
, ®
);
1774 rt2x00_set_field32(®
, CSR11_LONG_RETRY
, long_retry
);
1775 rt2x00_set_field32(®
, CSR11_SHORT_RETRY
, short_retry
);
1776 rt2x00pci_register_write(rt2x00dev
, CSR11
, reg
);
1781 static u64
rt2500pci_get_tsf(struct ieee80211_hw
*hw
)
1783 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1787 rt2x00pci_register_read(rt2x00dev
, CSR17
, ®
);
1788 tsf
= (u64
)rt2x00_get_field32(reg
, CSR17_HIGH_TSFTIMER
) << 32;
1789 rt2x00pci_register_read(rt2x00dev
, CSR16
, ®
);
1790 tsf
|= rt2x00_get_field32(reg
, CSR16_LOW_TSFTIMER
);
1795 static void rt2500pci_reset_tsf(struct ieee80211_hw
*hw
)
1797 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1799 rt2x00pci_register_write(rt2x00dev
, CSR16
, 0);
1800 rt2x00pci_register_write(rt2x00dev
, CSR17
, 0);
1803 static int rt2500pci_tx_last_beacon(struct ieee80211_hw
*hw
)
1805 struct rt2x00_dev
*rt2x00dev
= hw
->priv
;
1808 rt2x00pci_register_read(rt2x00dev
, CSR15
, ®
);
1809 return rt2x00_get_field32(reg
, CSR15_BEACON_SENT
);
1812 static const struct ieee80211_ops rt2500pci_mac80211_ops
= {
1814 .reset
= rt2x00lib_reset
,
1815 .open
= rt2x00lib_open
,
1816 .stop
= rt2x00lib_stop
,
1817 .add_interface
= rt2x00lib_add_interface
,
1818 .remove_interface
= rt2x00lib_remove_interface
,
1819 .config
= rt2x00lib_config
,
1820 .config_interface
= rt2x00lib_config_interface
,
1821 .set_multicast_list
= rt2x00lib_set_multicast_list
,
1822 .get_stats
= rt2500pci_get_stats
,
1823 .set_retry_limit
= rt2500pci_set_retry_limit
,
1824 .conf_tx
= rt2x00lib_conf_tx
,
1825 .get_tx_stats
= rt2x00lib_get_tx_stats
,
1826 .get_tsf
= rt2500pci_get_tsf
,
1827 .reset_tsf
= rt2500pci_reset_tsf
,
1828 .beacon_update
= rt2x00pci_beacon_update
,
1829 .tx_last_beacon
= rt2500pci_tx_last_beacon
,
1832 static const struct rt2x00lib_ops rt2500pci_rt2x00_ops
= {
1833 .irq_handler
= rt2500pci_interrupt
,
1834 .init_hw
= rt2500pci_init_hw
,
1835 .initialize
= rt2x00pci_initialize
,
1836 .uninitialize
= rt2x00pci_uninitialize
,
1837 .set_device_state
= rt2500pci_set_device_state
,
1838 #ifdef CONFIG_RT2500PCI_RFKILL
1839 .rfkill_poll
= rt2500pci_rfkill_poll
,
1840 #endif /* CONFIG_RT2500PCI_RFKILL */
1841 .link_tuner
= rt2500pci_link_tuner
,
1842 .write_tx_desc
= rt2500pci_write_tx_desc
,
1843 .write_tx_data
= rt2x00pci_write_tx_data
,
1844 .kick_tx_queue
= rt2500pci_kick_tx_queue
,
1845 .config_type
= rt2500pci_config_type
,
1846 .config_phymode
= rt2500pci_config_phymode
,
1847 .config_channel
= rt2500pci_config_channel
,
1848 .config_mac_addr
= rt2500pci_config_mac_addr
,
1849 .config_bssid
= rt2500pci_config_bssid
,
1850 .config_promisc
= rt2500pci_config_promisc
,
1851 .config_txpower
= rt2500pci_config_txpower
,
1852 .config_antenna
= rt2500pci_config_antenna
,
1853 .config_duration
= rt2500pci_config_duration
,
1856 static const struct rt2x00_ops rt2500pci_ops
= {
1858 .rxd_size
= RXD_DESC_SIZE
,
1859 .txd_size
= TXD_DESC_SIZE
,
1860 .lib
= &rt2500pci_rt2x00_ops
,
1861 .hw
= &rt2500pci_mac80211_ops
,
1862 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
1863 .debugfs
= &rt2500pci_rt2x00debug
,
1864 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
1868 * RT2500pci module information.
1870 static struct pci_device_id rt2500pci_device_table
[] = {
1871 { PCI_DEVICE(0x1814, 0x0201), PCI_DEVICE_DATA(&rt2500pci_ops
) },
1875 MODULE_AUTHOR(DRV_PROJECT
);
1876 MODULE_VERSION(DRV_VERSION
);
1877 MODULE_DESCRIPTION("Ralink RT2500 PCI & PCMCIA Wireless LAN driver.");
1878 MODULE_SUPPORTED_DEVICE("Ralink RT2560 PCI & PCMCIA chipset based cards");
1879 MODULE_DEVICE_TABLE(pci
, rt2500pci_device_table
);
1880 MODULE_LICENSE("GPL");
1882 static struct pci_driver rt2500pci_driver
= {
1884 .id_table
= rt2500pci_device_table
,
1885 .probe
= rt2x00pci_probe
,
1886 .remove
= __devexit_p(rt2x00pci_remove
),
1888 .suspend
= rt2x00pci_suspend
,
1889 .resume
= rt2x00pci_resume
,
1890 #endif /* CONFIG_PM */
1893 static int __init
rt2500pci_init(void)
1895 printk(KERN_INFO
"Loading module: %s - %s by %s.\n",
1896 DRV_NAME
, DRV_VERSION
, DRV_PROJECT
);
1897 return pci_register_driver(&rt2500pci_driver
);
1900 static void __exit
rt2500pci_exit(void)
1902 printk(KERN_INFO
"Unloading module: %s.\n", DRV_NAME
);
1903 pci_unregister_driver(&rt2500pci_driver
);
1906 module_init(rt2500pci_init
);
1907 module_exit(rt2500pci_exit
);