2 * Copyright (c) 2008-2009 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <asm/unaligned.h>
24 #define ATH9K_CLOCK_RATE_CCK 22
25 #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
26 #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
28 static bool ath9k_hw_set_reset_reg(struct ath_hw
*ah
, u32 type
);
29 static void ath9k_hw_set_regs(struct ath_hw
*ah
, struct ath9k_channel
*chan
);
30 static u32
ath9k_hw_ini_fixup(struct ath_hw
*ah
,
31 struct ar5416_eeprom_def
*pEepData
,
33 static void ath9k_hw_9280_spur_mitigate(struct ath_hw
*ah
, struct ath9k_channel
*chan
);
34 static void ath9k_hw_spur_mitigate(struct ath_hw
*ah
, struct ath9k_channel
*chan
);
36 MODULE_AUTHOR("Atheros Communications");
37 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
38 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
39 MODULE_LICENSE("Dual BSD/GPL");
41 static int __init
ath9k_init(void)
45 module_init(ath9k_init
);
47 static void __exit
ath9k_exit(void)
51 module_exit(ath9k_exit
);
53 /********************/
54 /* Helper Functions */
55 /********************/
57 static u32
ath9k_hw_mac_usec(struct ath_hw
*ah
, u32 clks
)
59 struct ieee80211_conf
*conf
= &ath9k_hw_common(ah
)->hw
->conf
;
61 if (!ah
->curchan
) /* should really check for CCK instead */
62 return clks
/ ATH9K_CLOCK_RATE_CCK
;
63 if (conf
->channel
->band
== IEEE80211_BAND_2GHZ
)
64 return clks
/ ATH9K_CLOCK_RATE_2GHZ_OFDM
;
66 return clks
/ ATH9K_CLOCK_RATE_5GHZ_OFDM
;
69 static u32
ath9k_hw_mac_to_usec(struct ath_hw
*ah
, u32 clks
)
71 struct ieee80211_conf
*conf
= &ath9k_hw_common(ah
)->hw
->conf
;
73 if (conf_is_ht40(conf
))
74 return ath9k_hw_mac_usec(ah
, clks
) / 2;
76 return ath9k_hw_mac_usec(ah
, clks
);
79 static u32
ath9k_hw_mac_clks(struct ath_hw
*ah
, u32 usecs
)
81 struct ieee80211_conf
*conf
= &ath9k_hw_common(ah
)->hw
->conf
;
83 if (!ah
->curchan
) /* should really check for CCK instead */
84 return usecs
*ATH9K_CLOCK_RATE_CCK
;
85 if (conf
->channel
->band
== IEEE80211_BAND_2GHZ
)
86 return usecs
*ATH9K_CLOCK_RATE_2GHZ_OFDM
;
87 return usecs
*ATH9K_CLOCK_RATE_5GHZ_OFDM
;
90 static u32
ath9k_hw_mac_to_clks(struct ath_hw
*ah
, u32 usecs
)
92 struct ieee80211_conf
*conf
= &ath9k_hw_common(ah
)->hw
->conf
;
94 if (conf_is_ht40(conf
))
95 return ath9k_hw_mac_clks(ah
, usecs
) * 2;
97 return ath9k_hw_mac_clks(ah
, usecs
);
100 bool ath9k_hw_wait(struct ath_hw
*ah
, u32 reg
, u32 mask
, u32 val
, u32 timeout
)
104 BUG_ON(timeout
< AH_TIME_QUANTUM
);
106 for (i
= 0; i
< (timeout
/ AH_TIME_QUANTUM
); i
++) {
107 if ((REG_READ(ah
, reg
) & mask
) == val
)
110 udelay(AH_TIME_QUANTUM
);
113 ath_print(ath9k_hw_common(ah
), ATH_DBG_ANY
,
114 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
115 timeout
, reg
, REG_READ(ah
, reg
), mask
, val
);
119 EXPORT_SYMBOL(ath9k_hw_wait
);
121 u32
ath9k_hw_reverse_bits(u32 val
, u32 n
)
126 for (i
= 0, retval
= 0; i
< n
; i
++) {
127 retval
= (retval
<< 1) | (val
& 1);
133 bool ath9k_get_channel_edges(struct ath_hw
*ah
,
137 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
139 if (flags
& CHANNEL_5GHZ
) {
140 *low
= pCap
->low_5ghz_chan
;
141 *high
= pCap
->high_5ghz_chan
;
144 if ((flags
& CHANNEL_2GHZ
)) {
145 *low
= pCap
->low_2ghz_chan
;
146 *high
= pCap
->high_2ghz_chan
;
152 u16
ath9k_hw_computetxtime(struct ath_hw
*ah
,
153 const struct ath_rate_table
*rates
,
154 u32 frameLen
, u16 rateix
,
157 u32 bitsPerSymbol
, numBits
, numSymbols
, phyTime
, txTime
;
160 kbps
= rates
->info
[rateix
].ratekbps
;
165 switch (rates
->info
[rateix
].phy
) {
166 case WLAN_RC_PHY_CCK
:
167 phyTime
= CCK_PREAMBLE_BITS
+ CCK_PLCP_BITS
;
168 if (shortPreamble
&& rates
->info
[rateix
].short_preamble
)
170 numBits
= frameLen
<< 3;
171 txTime
= CCK_SIFS_TIME
+ phyTime
+ ((numBits
* 1000) / kbps
);
173 case WLAN_RC_PHY_OFDM
:
174 if (ah
->curchan
&& IS_CHAN_QUARTER_RATE(ah
->curchan
)) {
175 bitsPerSymbol
= (kbps
* OFDM_SYMBOL_TIME_QUARTER
) / 1000;
176 numBits
= OFDM_PLCP_BITS
+ (frameLen
<< 3);
177 numSymbols
= DIV_ROUND_UP(numBits
, bitsPerSymbol
);
178 txTime
= OFDM_SIFS_TIME_QUARTER
179 + OFDM_PREAMBLE_TIME_QUARTER
180 + (numSymbols
* OFDM_SYMBOL_TIME_QUARTER
);
181 } else if (ah
->curchan
&&
182 IS_CHAN_HALF_RATE(ah
->curchan
)) {
183 bitsPerSymbol
= (kbps
* OFDM_SYMBOL_TIME_HALF
) / 1000;
184 numBits
= OFDM_PLCP_BITS
+ (frameLen
<< 3);
185 numSymbols
= DIV_ROUND_UP(numBits
, bitsPerSymbol
);
186 txTime
= OFDM_SIFS_TIME_HALF
+
187 OFDM_PREAMBLE_TIME_HALF
188 + (numSymbols
* OFDM_SYMBOL_TIME_HALF
);
190 bitsPerSymbol
= (kbps
* OFDM_SYMBOL_TIME
) / 1000;
191 numBits
= OFDM_PLCP_BITS
+ (frameLen
<< 3);
192 numSymbols
= DIV_ROUND_UP(numBits
, bitsPerSymbol
);
193 txTime
= OFDM_SIFS_TIME
+ OFDM_PREAMBLE_TIME
194 + (numSymbols
* OFDM_SYMBOL_TIME
);
198 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
199 "Unknown phy %u (rate ix %u)\n",
200 rates
->info
[rateix
].phy
, rateix
);
207 EXPORT_SYMBOL(ath9k_hw_computetxtime
);
209 void ath9k_hw_get_channel_centers(struct ath_hw
*ah
,
210 struct ath9k_channel
*chan
,
211 struct chan_centers
*centers
)
215 if (!IS_CHAN_HT40(chan
)) {
216 centers
->ctl_center
= centers
->ext_center
=
217 centers
->synth_center
= chan
->channel
;
221 if ((chan
->chanmode
== CHANNEL_A_HT40PLUS
) ||
222 (chan
->chanmode
== CHANNEL_G_HT40PLUS
)) {
223 centers
->synth_center
=
224 chan
->channel
+ HT40_CHANNEL_CENTER_SHIFT
;
227 centers
->synth_center
=
228 chan
->channel
- HT40_CHANNEL_CENTER_SHIFT
;
232 centers
->ctl_center
=
233 centers
->synth_center
- (extoff
* HT40_CHANNEL_CENTER_SHIFT
);
234 /* 25 MHz spacing is supported by hw but not on upper layers */
235 centers
->ext_center
=
236 centers
->synth_center
+ (extoff
* HT40_CHANNEL_CENTER_SHIFT
);
243 static void ath9k_hw_read_revisions(struct ath_hw
*ah
)
247 val
= REG_READ(ah
, AR_SREV
) & AR_SREV_ID
;
250 val
= REG_READ(ah
, AR_SREV
);
251 ah
->hw_version
.macVersion
=
252 (val
& AR_SREV_VERSION2
) >> AR_SREV_TYPE2_S
;
253 ah
->hw_version
.macRev
= MS(val
, AR_SREV_REVISION2
);
254 ah
->is_pciexpress
= (val
& AR_SREV_TYPE2_HOST_MODE
) ? 0 : 1;
256 if (!AR_SREV_9100(ah
))
257 ah
->hw_version
.macVersion
= MS(val
, AR_SREV_VERSION
);
259 ah
->hw_version
.macRev
= val
& AR_SREV_REVISION
;
261 if (ah
->hw_version
.macVersion
== AR_SREV_VERSION_5416_PCIE
)
262 ah
->is_pciexpress
= true;
266 static int ath9k_hw_get_radiorev(struct ath_hw
*ah
)
271 REG_WRITE(ah
, AR_PHY(0x36), 0x00007058);
273 for (i
= 0; i
< 8; i
++)
274 REG_WRITE(ah
, AR_PHY(0x20), 0x00010000);
275 val
= (REG_READ(ah
, AR_PHY(256)) >> 24) & 0xff;
276 val
= ((val
& 0xf0) >> 4) | ((val
& 0x0f) << 4);
278 return ath9k_hw_reverse_bits(val
, 8);
281 /************************************/
282 /* HW Attach, Detach, Init Routines */
283 /************************************/
285 static void ath9k_hw_disablepcie(struct ath_hw
*ah
)
287 if (AR_SREV_9100(ah
))
290 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x9248fc00);
291 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x24924924);
292 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x28000029);
293 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x57160824);
294 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x25980579);
295 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x00000000);
296 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x1aaabe40);
297 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xbe105554);
298 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x000e1007);
300 REG_WRITE(ah
, AR_PCIE_SERDES2
, 0x00000000);
303 static bool ath9k_hw_chip_test(struct ath_hw
*ah
)
305 struct ath_common
*common
= ath9k_hw_common(ah
);
306 u32 regAddr
[2] = { AR_STA_ID0
, AR_PHY_BASE
+ (8 << 2) };
308 u32 patternData
[4] = { 0x55555555,
314 for (i
= 0; i
< 2; i
++) {
315 u32 addr
= regAddr
[i
];
318 regHold
[i
] = REG_READ(ah
, addr
);
319 for (j
= 0; j
< 0x100; j
++) {
320 wrData
= (j
<< 16) | j
;
321 REG_WRITE(ah
, addr
, wrData
);
322 rdData
= REG_READ(ah
, addr
);
323 if (rdData
!= wrData
) {
324 ath_print(common
, ATH_DBG_FATAL
,
325 "address test failed "
326 "addr: 0x%08x - wr:0x%08x != "
328 addr
, wrData
, rdData
);
332 for (j
= 0; j
< 4; j
++) {
333 wrData
= patternData
[j
];
334 REG_WRITE(ah
, addr
, wrData
);
335 rdData
= REG_READ(ah
, addr
);
336 if (wrData
!= rdData
) {
337 ath_print(common
, ATH_DBG_FATAL
,
338 "address test failed "
339 "addr: 0x%08x - wr:0x%08x != "
341 addr
, wrData
, rdData
);
345 REG_WRITE(ah
, regAddr
[i
], regHold
[i
]);
352 static const char *ath9k_hw_devname(u16 devid
)
355 case AR5416_DEVID_PCI
:
356 return "Atheros 5416";
357 case AR5416_DEVID_PCIE
:
358 return "Atheros 5418";
359 case AR9160_DEVID_PCI
:
360 return "Atheros 9160";
361 case AR5416_AR9100_DEVID
:
362 return "Atheros 9100";
363 case AR9280_DEVID_PCI
:
364 case AR9280_DEVID_PCIE
:
365 return "Atheros 9280";
366 case AR9285_DEVID_PCIE
:
367 return "Atheros 9285";
368 case AR5416_DEVID_AR9287_PCI
:
369 case AR5416_DEVID_AR9287_PCIE
:
370 return "Atheros 9287";
376 static void ath9k_hw_init_config(struct ath_hw
*ah
)
380 ah
->config
.dma_beacon_response_time
= 2;
381 ah
->config
.sw_beacon_response_time
= 10;
382 ah
->config
.additional_swba_backoff
= 0;
383 ah
->config
.ack_6mb
= 0x0;
384 ah
->config
.cwm_ignore_extcca
= 0;
385 ah
->config
.pcie_powersave_enable
= 0;
386 ah
->config
.pcie_clock_req
= 0;
387 ah
->config
.pcie_waen
= 0;
388 ah
->config
.analog_shiftreg
= 1;
389 ah
->config
.ht_enable
= 1;
390 ah
->config
.ofdm_trig_low
= 200;
391 ah
->config
.ofdm_trig_high
= 500;
392 ah
->config
.cck_trig_high
= 200;
393 ah
->config
.cck_trig_low
= 100;
394 ah
->config
.enable_ani
= 1;
395 ah
->config
.diversity_control
= ATH9K_ANT_VARIABLE
;
396 ah
->config
.antenna_switch_swap
= 0;
398 for (i
= 0; i
< AR_EEPROM_MODAL_SPURS
; i
++) {
399 ah
->config
.spurchans
[i
][0] = AR_NO_SPUR
;
400 ah
->config
.spurchans
[i
][1] = AR_NO_SPUR
;
403 ah
->config
.intr_mitigation
= true;
406 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
407 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
408 * This means we use it for all AR5416 devices, and the few
409 * minor PCI AR9280 devices out there.
411 * Serialization is required because these devices do not handle
412 * well the case of two concurrent reads/writes due to the latency
413 * involved. During one read/write another read/write can be issued
414 * on another CPU while the previous read/write may still be working
415 * on our hardware, if we hit this case the hardware poops in a loop.
416 * We prevent this by serializing reads and writes.
418 * This issue is not present on PCI-Express devices or pre-AR5416
419 * devices (legacy, 802.11abg).
421 if (num_possible_cpus() > 1)
422 ah
->config
.serialize_regmode
= SER_REG_MODE_AUTO
;
424 EXPORT_SYMBOL(ath9k_hw_init
);
426 static void ath9k_hw_init_defaults(struct ath_hw
*ah
)
428 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
430 regulatory
->country_code
= CTRY_DEFAULT
;
431 regulatory
->power_limit
= MAX_RATE_POWER
;
432 regulatory
->tp_scale
= ATH9K_TP_SCALE_MAX
;
434 ah
->hw_version
.magic
= AR5416_MAGIC
;
435 ah
->hw_version
.subvendorid
= 0;
438 if (ah
->hw_version
.devid
== AR5416_AR9100_DEVID
)
439 ah
->hw_version
.macVersion
= AR_SREV_VERSION_9100
;
440 if (!AR_SREV_9100(ah
))
441 ah
->ah_flags
= AH_USE_EEPROM
;
444 ah
->sta_id1_defaults
= AR_STA_ID1_CRPT_MIC_ENABLE
;
445 ah
->beacon_interval
= 100;
446 ah
->enable_32kHz_clock
= DONT_USE_32KHZ
;
447 ah
->slottime
= (u32
) -1;
448 ah
->acktimeout
= (u32
) -1;
449 ah
->ctstimeout
= (u32
) -1;
450 ah
->globaltxtimeout
= (u32
) -1;
452 ah
->gbeacon_rate
= 0;
454 ah
->power_mode
= ATH9K_PM_UNDEFINED
;
457 static int ath9k_hw_rfattach(struct ath_hw
*ah
)
459 bool rfStatus
= false;
462 rfStatus
= ath9k_hw_init_rf(ah
, &ecode
);
464 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
465 "RF setup failed, status: %u\n", ecode
);
472 static int ath9k_hw_rf_claim(struct ath_hw
*ah
)
476 REG_WRITE(ah
, AR_PHY(0), 0x00000007);
478 val
= ath9k_hw_get_radiorev(ah
);
479 switch (val
& AR_RADIO_SREV_MAJOR
) {
481 val
= AR_RAD5133_SREV_MAJOR
;
483 case AR_RAD5133_SREV_MAJOR
:
484 case AR_RAD5122_SREV_MAJOR
:
485 case AR_RAD2133_SREV_MAJOR
:
486 case AR_RAD2122_SREV_MAJOR
:
489 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
490 "Radio Chip Rev 0x%02X not supported\n",
491 val
& AR_RADIO_SREV_MAJOR
);
495 ah
->hw_version
.analog5GhzRev
= val
;
500 static int ath9k_hw_init_macaddr(struct ath_hw
*ah
)
502 struct ath_common
*common
= ath9k_hw_common(ah
);
508 for (i
= 0; i
< 3; i
++) {
509 eeval
= ah
->eep_ops
->get_eeprom(ah
, AR_EEPROM_MAC(i
));
511 common
->macaddr
[2 * i
] = eeval
>> 8;
512 common
->macaddr
[2 * i
+ 1] = eeval
& 0xff;
514 if (sum
== 0 || sum
== 0xffff * 3)
515 return -EADDRNOTAVAIL
;
520 static void ath9k_hw_init_rxgain_ini(struct ath_hw
*ah
)
524 if (ah
->eep_ops
->get_eeprom(ah
, EEP_MINOR_REV
) >= AR5416_EEP_MINOR_VER_17
) {
525 rxgain_type
= ah
->eep_ops
->get_eeprom(ah
, EEP_RXGAIN_TYPE
);
527 if (rxgain_type
== AR5416_EEP_RXGAIN_13DB_BACKOFF
)
528 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
529 ar9280Modes_backoff_13db_rxgain_9280_2
,
530 ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2
), 6);
531 else if (rxgain_type
== AR5416_EEP_RXGAIN_23DB_BACKOFF
)
532 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
533 ar9280Modes_backoff_23db_rxgain_9280_2
,
534 ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2
), 6);
536 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
537 ar9280Modes_original_rxgain_9280_2
,
538 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2
), 6);
540 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
541 ar9280Modes_original_rxgain_9280_2
,
542 ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2
), 6);
546 static void ath9k_hw_init_txgain_ini(struct ath_hw
*ah
)
550 if (ah
->eep_ops
->get_eeprom(ah
, EEP_MINOR_REV
) >= AR5416_EEP_MINOR_VER_19
) {
551 txgain_type
= ah
->eep_ops
->get_eeprom(ah
, EEP_TXGAIN_TYPE
);
553 if (txgain_type
== AR5416_EEP_TXGAIN_HIGH_POWER
)
554 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
555 ar9280Modes_high_power_tx_gain_9280_2
,
556 ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2
), 6);
558 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
559 ar9280Modes_original_tx_gain_9280_2
,
560 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2
), 6);
562 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
563 ar9280Modes_original_tx_gain_9280_2
,
564 ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2
), 6);
568 static int ath9k_hw_post_init(struct ath_hw
*ah
)
572 if (!ath9k_hw_chip_test(ah
))
575 ecode
= ath9k_hw_rf_claim(ah
);
579 ecode
= ath9k_hw_eeprom_init(ah
);
583 ath_print(ath9k_hw_common(ah
), ATH_DBG_CONFIG
,
584 "Eeprom VER: %d, REV: %d\n",
585 ah
->eep_ops
->get_eeprom_ver(ah
),
586 ah
->eep_ops
->get_eeprom_rev(ah
));
588 ecode
= ath9k_hw_rfattach(ah
);
592 if (!AR_SREV_9100(ah
)) {
593 ath9k_hw_ani_setup(ah
);
594 ath9k_hw_ani_init(ah
);
600 static bool ath9k_hw_devid_supported(u16 devid
)
603 case AR5416_DEVID_PCI
:
604 case AR5416_DEVID_PCIE
:
605 case AR5416_AR9100_DEVID
:
606 case AR9160_DEVID_PCI
:
607 case AR9280_DEVID_PCI
:
608 case AR9280_DEVID_PCIE
:
609 case AR9285_DEVID_PCIE
:
610 case AR5416_DEVID_AR9287_PCI
:
611 case AR5416_DEVID_AR9287_PCIE
:
620 static bool ath9k_hw_macversion_supported(u32 macversion
)
622 switch (macversion
) {
623 case AR_SREV_VERSION_5416_PCI
:
624 case AR_SREV_VERSION_5416_PCIE
:
625 case AR_SREV_VERSION_9160
:
626 case AR_SREV_VERSION_9100
:
627 case AR_SREV_VERSION_9280
:
628 case AR_SREV_VERSION_9285
:
629 case AR_SREV_VERSION_9287
:
630 case AR_SREV_VERSION_9271
:
638 static void ath9k_hw_init_cal_settings(struct ath_hw
*ah
)
640 if (AR_SREV_9160_10_OR_LATER(ah
)) {
641 if (AR_SREV_9280_10_OR_LATER(ah
)) {
642 ah
->iq_caldata
.calData
= &iq_cal_single_sample
;
643 ah
->adcgain_caldata
.calData
=
644 &adc_gain_cal_single_sample
;
645 ah
->adcdc_caldata
.calData
=
646 &adc_dc_cal_single_sample
;
647 ah
->adcdc_calinitdata
.calData
=
650 ah
->iq_caldata
.calData
= &iq_cal_multi_sample
;
651 ah
->adcgain_caldata
.calData
=
652 &adc_gain_cal_multi_sample
;
653 ah
->adcdc_caldata
.calData
=
654 &adc_dc_cal_multi_sample
;
655 ah
->adcdc_calinitdata
.calData
=
658 ah
->supp_cals
= ADC_GAIN_CAL
| ADC_DC_CAL
| IQ_MISMATCH_CAL
;
662 static void ath9k_hw_init_mode_regs(struct ath_hw
*ah
)
664 if (AR_SREV_9271(ah
)) {
665 INIT_INI_ARRAY(&ah
->iniModes
, ar9271Modes_9271_1_0
,
666 ARRAY_SIZE(ar9271Modes_9271_1_0
), 6);
667 INIT_INI_ARRAY(&ah
->iniCommon
, ar9271Common_9271_1_0
,
668 ARRAY_SIZE(ar9271Common_9271_1_0
), 2);
672 if (AR_SREV_9287_11_OR_LATER(ah
)) {
673 INIT_INI_ARRAY(&ah
->iniModes
, ar9287Modes_9287_1_1
,
674 ARRAY_SIZE(ar9287Modes_9287_1_1
), 6);
675 INIT_INI_ARRAY(&ah
->iniCommon
, ar9287Common_9287_1_1
,
676 ARRAY_SIZE(ar9287Common_9287_1_1
), 2);
677 if (ah
->config
.pcie_clock_req
)
678 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
679 ar9287PciePhy_clkreq_off_L1_9287_1_1
,
680 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1
), 2);
682 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
683 ar9287PciePhy_clkreq_always_on_L1_9287_1_1
,
684 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1
),
686 } else if (AR_SREV_9287_10_OR_LATER(ah
)) {
687 INIT_INI_ARRAY(&ah
->iniModes
, ar9287Modes_9287_1_0
,
688 ARRAY_SIZE(ar9287Modes_9287_1_0
), 6);
689 INIT_INI_ARRAY(&ah
->iniCommon
, ar9287Common_9287_1_0
,
690 ARRAY_SIZE(ar9287Common_9287_1_0
), 2);
692 if (ah
->config
.pcie_clock_req
)
693 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
694 ar9287PciePhy_clkreq_off_L1_9287_1_0
,
695 ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0
), 2);
697 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
698 ar9287PciePhy_clkreq_always_on_L1_9287_1_0
,
699 ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0
),
701 } else if (AR_SREV_9285_12_OR_LATER(ah
)) {
704 INIT_INI_ARRAY(&ah
->iniModes
, ar9285Modes_9285_1_2
,
705 ARRAY_SIZE(ar9285Modes_9285_1_2
), 6);
706 INIT_INI_ARRAY(&ah
->iniCommon
, ar9285Common_9285_1_2
,
707 ARRAY_SIZE(ar9285Common_9285_1_2
), 2);
709 if (ah
->config
.pcie_clock_req
) {
710 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
711 ar9285PciePhy_clkreq_off_L1_9285_1_2
,
712 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2
), 2);
714 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
715 ar9285PciePhy_clkreq_always_on_L1_9285_1_2
,
716 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2
),
719 } else if (AR_SREV_9285_10_OR_LATER(ah
)) {
720 INIT_INI_ARRAY(&ah
->iniModes
, ar9285Modes_9285
,
721 ARRAY_SIZE(ar9285Modes_9285
), 6);
722 INIT_INI_ARRAY(&ah
->iniCommon
, ar9285Common_9285
,
723 ARRAY_SIZE(ar9285Common_9285
), 2);
725 if (ah
->config
.pcie_clock_req
) {
726 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
727 ar9285PciePhy_clkreq_off_L1_9285
,
728 ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285
), 2);
730 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
731 ar9285PciePhy_clkreq_always_on_L1_9285
,
732 ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285
), 2);
734 } else if (AR_SREV_9280_20_OR_LATER(ah
)) {
735 INIT_INI_ARRAY(&ah
->iniModes
, ar9280Modes_9280_2
,
736 ARRAY_SIZE(ar9280Modes_9280_2
), 6);
737 INIT_INI_ARRAY(&ah
->iniCommon
, ar9280Common_9280_2
,
738 ARRAY_SIZE(ar9280Common_9280_2
), 2);
740 if (ah
->config
.pcie_clock_req
) {
741 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
742 ar9280PciePhy_clkreq_off_L1_9280
,
743 ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280
),2);
745 INIT_INI_ARRAY(&ah
->iniPcieSerdes
,
746 ar9280PciePhy_clkreq_always_on_L1_9280
,
747 ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280
), 2);
749 INIT_INI_ARRAY(&ah
->iniModesAdditional
,
750 ar9280Modes_fast_clock_9280_2
,
751 ARRAY_SIZE(ar9280Modes_fast_clock_9280_2
), 3);
752 } else if (AR_SREV_9280_10_OR_LATER(ah
)) {
753 INIT_INI_ARRAY(&ah
->iniModes
, ar9280Modes_9280
,
754 ARRAY_SIZE(ar9280Modes_9280
), 6);
755 INIT_INI_ARRAY(&ah
->iniCommon
, ar9280Common_9280
,
756 ARRAY_SIZE(ar9280Common_9280
), 2);
757 } else if (AR_SREV_9160_10_OR_LATER(ah
)) {
758 INIT_INI_ARRAY(&ah
->iniModes
, ar5416Modes_9160
,
759 ARRAY_SIZE(ar5416Modes_9160
), 6);
760 INIT_INI_ARRAY(&ah
->iniCommon
, ar5416Common_9160
,
761 ARRAY_SIZE(ar5416Common_9160
), 2);
762 INIT_INI_ARRAY(&ah
->iniBank0
, ar5416Bank0_9160
,
763 ARRAY_SIZE(ar5416Bank0_9160
), 2);
764 INIT_INI_ARRAY(&ah
->iniBB_RfGain
, ar5416BB_RfGain_9160
,
765 ARRAY_SIZE(ar5416BB_RfGain_9160
), 3);
766 INIT_INI_ARRAY(&ah
->iniBank1
, ar5416Bank1_9160
,
767 ARRAY_SIZE(ar5416Bank1_9160
), 2);
768 INIT_INI_ARRAY(&ah
->iniBank2
, ar5416Bank2_9160
,
769 ARRAY_SIZE(ar5416Bank2_9160
), 2);
770 INIT_INI_ARRAY(&ah
->iniBank3
, ar5416Bank3_9160
,
771 ARRAY_SIZE(ar5416Bank3_9160
), 3);
772 INIT_INI_ARRAY(&ah
->iniBank6
, ar5416Bank6_9160
,
773 ARRAY_SIZE(ar5416Bank6_9160
), 3);
774 INIT_INI_ARRAY(&ah
->iniBank6TPC
, ar5416Bank6TPC_9160
,
775 ARRAY_SIZE(ar5416Bank6TPC_9160
), 3);
776 INIT_INI_ARRAY(&ah
->iniBank7
, ar5416Bank7_9160
,
777 ARRAY_SIZE(ar5416Bank7_9160
), 2);
778 if (AR_SREV_9160_11(ah
)) {
779 INIT_INI_ARRAY(&ah
->iniAddac
,
781 ARRAY_SIZE(ar5416Addac_91601_1
), 2);
783 INIT_INI_ARRAY(&ah
->iniAddac
, ar5416Addac_9160
,
784 ARRAY_SIZE(ar5416Addac_9160
), 2);
786 } else if (AR_SREV_9100_OR_LATER(ah
)) {
787 INIT_INI_ARRAY(&ah
->iniModes
, ar5416Modes_9100
,
788 ARRAY_SIZE(ar5416Modes_9100
), 6);
789 INIT_INI_ARRAY(&ah
->iniCommon
, ar5416Common_9100
,
790 ARRAY_SIZE(ar5416Common_9100
), 2);
791 INIT_INI_ARRAY(&ah
->iniBank0
, ar5416Bank0_9100
,
792 ARRAY_SIZE(ar5416Bank0_9100
), 2);
793 INIT_INI_ARRAY(&ah
->iniBB_RfGain
, ar5416BB_RfGain_9100
,
794 ARRAY_SIZE(ar5416BB_RfGain_9100
), 3);
795 INIT_INI_ARRAY(&ah
->iniBank1
, ar5416Bank1_9100
,
796 ARRAY_SIZE(ar5416Bank1_9100
), 2);
797 INIT_INI_ARRAY(&ah
->iniBank2
, ar5416Bank2_9100
,
798 ARRAY_SIZE(ar5416Bank2_9100
), 2);
799 INIT_INI_ARRAY(&ah
->iniBank3
, ar5416Bank3_9100
,
800 ARRAY_SIZE(ar5416Bank3_9100
), 3);
801 INIT_INI_ARRAY(&ah
->iniBank6
, ar5416Bank6_9100
,
802 ARRAY_SIZE(ar5416Bank6_9100
), 3);
803 INIT_INI_ARRAY(&ah
->iniBank6TPC
, ar5416Bank6TPC_9100
,
804 ARRAY_SIZE(ar5416Bank6TPC_9100
), 3);
805 INIT_INI_ARRAY(&ah
->iniBank7
, ar5416Bank7_9100
,
806 ARRAY_SIZE(ar5416Bank7_9100
), 2);
807 INIT_INI_ARRAY(&ah
->iniAddac
, ar5416Addac_9100
,
808 ARRAY_SIZE(ar5416Addac_9100
), 2);
810 INIT_INI_ARRAY(&ah
->iniModes
, ar5416Modes
,
811 ARRAY_SIZE(ar5416Modes
), 6);
812 INIT_INI_ARRAY(&ah
->iniCommon
, ar5416Common
,
813 ARRAY_SIZE(ar5416Common
), 2);
814 INIT_INI_ARRAY(&ah
->iniBank0
, ar5416Bank0
,
815 ARRAY_SIZE(ar5416Bank0
), 2);
816 INIT_INI_ARRAY(&ah
->iniBB_RfGain
, ar5416BB_RfGain
,
817 ARRAY_SIZE(ar5416BB_RfGain
), 3);
818 INIT_INI_ARRAY(&ah
->iniBank1
, ar5416Bank1
,
819 ARRAY_SIZE(ar5416Bank1
), 2);
820 INIT_INI_ARRAY(&ah
->iniBank2
, ar5416Bank2
,
821 ARRAY_SIZE(ar5416Bank2
), 2);
822 INIT_INI_ARRAY(&ah
->iniBank3
, ar5416Bank3
,
823 ARRAY_SIZE(ar5416Bank3
), 3);
824 INIT_INI_ARRAY(&ah
->iniBank6
, ar5416Bank6
,
825 ARRAY_SIZE(ar5416Bank6
), 3);
826 INIT_INI_ARRAY(&ah
->iniBank6TPC
, ar5416Bank6TPC
,
827 ARRAY_SIZE(ar5416Bank6TPC
), 3);
828 INIT_INI_ARRAY(&ah
->iniBank7
, ar5416Bank7
,
829 ARRAY_SIZE(ar5416Bank7
), 2);
830 INIT_INI_ARRAY(&ah
->iniAddac
, ar5416Addac
,
831 ARRAY_SIZE(ar5416Addac
), 2);
835 static void ath9k_hw_init_mode_gain_regs(struct ath_hw
*ah
)
837 if (AR_SREV_9287_11_OR_LATER(ah
))
838 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
839 ar9287Modes_rx_gain_9287_1_1
,
840 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1
), 6);
841 else if (AR_SREV_9287_10(ah
))
842 INIT_INI_ARRAY(&ah
->iniModesRxGain
,
843 ar9287Modes_rx_gain_9287_1_0
,
844 ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0
), 6);
845 else if (AR_SREV_9280_20(ah
))
846 ath9k_hw_init_rxgain_ini(ah
);
848 if (AR_SREV_9287_11_OR_LATER(ah
)) {
849 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
850 ar9287Modes_tx_gain_9287_1_1
,
851 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1
), 6);
852 } else if (AR_SREV_9287_10(ah
)) {
853 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
854 ar9287Modes_tx_gain_9287_1_0
,
855 ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0
), 6);
856 } else if (AR_SREV_9280_20(ah
)) {
857 ath9k_hw_init_txgain_ini(ah
);
858 } else if (AR_SREV_9285_12_OR_LATER(ah
)) {
859 u32 txgain_type
= ah
->eep_ops
->get_eeprom(ah
, EEP_TXGAIN_TYPE
);
862 if (txgain_type
== AR5416_EEP_TXGAIN_HIGH_POWER
) {
863 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
864 ar9285Modes_high_power_tx_gain_9285_1_2
,
865 ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2
), 6);
867 INIT_INI_ARRAY(&ah
->iniModesTxGain
,
868 ar9285Modes_original_tx_gain_9285_1_2
,
869 ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2
), 6);
875 static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw
*ah
)
879 if ((ah
->hw_version
.devid
== AR9280_DEVID_PCI
) &&
880 test_bit(ATH9K_MODE_11A
, ah
->caps
.wireless_modes
)) {
883 for (i
= 0; i
< ah
->iniModes
.ia_rows
; i
++) {
884 u32 reg
= INI_RA(&ah
->iniModes
, i
, 0);
886 for (j
= 1; j
< ah
->iniModes
.ia_columns
; j
++) {
887 u32 val
= INI_RA(&ah
->iniModes
, i
, j
);
889 INI_RA(&ah
->iniModes
, i
, j
) =
890 ath9k_hw_ini_fixup(ah
,
898 int ath9k_hw_init(struct ath_hw
*ah
)
900 struct ath_common
*common
= ath9k_hw_common(ah
);
903 if (!ath9k_hw_devid_supported(ah
->hw_version
.devid
)) {
904 ath_print(common
, ATH_DBG_FATAL
,
905 "Unsupported device ID: 0x%0x\n",
906 ah
->hw_version
.devid
);
910 ath9k_hw_init_defaults(ah
);
911 ath9k_hw_init_config(ah
);
913 if (!ath9k_hw_set_reset_reg(ah
, ATH9K_RESET_POWER_ON
)) {
914 ath_print(common
, ATH_DBG_FATAL
,
915 "Couldn't reset chip\n");
919 if (!ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
)) {
920 ath_print(common
, ATH_DBG_FATAL
, "Couldn't wakeup chip\n");
924 if (ah
->config
.serialize_regmode
== SER_REG_MODE_AUTO
) {
925 if (ah
->hw_version
.macVersion
== AR_SREV_VERSION_5416_PCI
||
926 (AR_SREV_9280(ah
) && !ah
->is_pciexpress
)) {
927 ah
->config
.serialize_regmode
=
930 ah
->config
.serialize_regmode
=
935 ath_print(common
, ATH_DBG_RESET
, "serialize_regmode is %d\n",
936 ah
->config
.serialize_regmode
);
938 if (!ath9k_hw_macversion_supported(ah
->hw_version
.macVersion
)) {
939 ath_print(common
, ATH_DBG_FATAL
,
940 "Mac Chip Rev 0x%02x.%x is not supported by "
941 "this driver\n", ah
->hw_version
.macVersion
,
942 ah
->hw_version
.macRev
);
946 if (AR_SREV_9100(ah
)) {
947 ah
->iq_caldata
.calData
= &iq_cal_multi_sample
;
948 ah
->supp_cals
= IQ_MISMATCH_CAL
;
949 ah
->is_pciexpress
= false;
952 if (AR_SREV_9271(ah
))
953 ah
->is_pciexpress
= false;
955 ah
->hw_version
.phyRev
= REG_READ(ah
, AR_PHY_CHIP_ID
);
957 ath9k_hw_init_cal_settings(ah
);
959 ah
->ani_function
= ATH9K_ANI_ALL
;
960 if (AR_SREV_9280_10_OR_LATER(ah
))
961 ah
->ani_function
&= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL
;
963 ath9k_hw_init_mode_regs(ah
);
965 if (ah
->is_pciexpress
)
966 ath9k_hw_configpcipowersave(ah
, 0, 0);
968 ath9k_hw_disablepcie(ah
);
970 /* Support for Japan ch.14 (2484) spread */
971 if (AR_SREV_9287_11_OR_LATER(ah
)) {
972 INIT_INI_ARRAY(&ah
->iniCckfirNormal
,
973 ar9287Common_normal_cck_fir_coeff_92871_1
,
974 ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1
), 2);
975 INIT_INI_ARRAY(&ah
->iniCckfirJapan2484
,
976 ar9287Common_japan_2484_cck_fir_coeff_92871_1
,
977 ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1
), 2);
980 r
= ath9k_hw_post_init(ah
);
984 ath9k_hw_init_mode_gain_regs(ah
);
985 ath9k_hw_fill_cap_info(ah
);
986 ath9k_hw_init_11a_eeprom_fix(ah
);
988 r
= ath9k_hw_init_macaddr(ah
);
990 ath_print(common
, ATH_DBG_FATAL
,
991 "Failed to initialize MAC address\n");
995 if (AR_SREV_9285(ah
) || AR_SREV_9271(ah
))
996 ah
->tx_trig_level
= (AR_FTRIG_256B
>> AR_FTRIG_S
);
998 ah
->tx_trig_level
= (AR_FTRIG_512B
>> AR_FTRIG_S
);
1000 ath9k_init_nfcal_hist_buffer(ah
);
1002 common
->state
= ATH_HW_INITIALIZED
;
1007 static void ath9k_hw_init_bb(struct ath_hw
*ah
,
1008 struct ath9k_channel
*chan
)
1012 synthDelay
= REG_READ(ah
, AR_PHY_RX_DELAY
) & AR_PHY_RX_DELAY_DELAY
;
1013 if (IS_CHAN_B(chan
))
1014 synthDelay
= (4 * synthDelay
) / 22;
1018 REG_WRITE(ah
, AR_PHY_ACTIVE
, AR_PHY_ACTIVE_EN
);
1020 udelay(synthDelay
+ BASE_ACTIVATE_DELAY
);
1023 static void ath9k_hw_init_qos(struct ath_hw
*ah
)
1025 REG_WRITE(ah
, AR_MIC_QOS_CONTROL
, 0x100aa);
1026 REG_WRITE(ah
, AR_MIC_QOS_SELECT
, 0x3210);
1028 REG_WRITE(ah
, AR_QOS_NO_ACK
,
1029 SM(2, AR_QOS_NO_ACK_TWO_BIT
) |
1030 SM(5, AR_QOS_NO_ACK_BIT_OFF
) |
1031 SM(0, AR_QOS_NO_ACK_BYTE_OFF
));
1033 REG_WRITE(ah
, AR_TXOP_X
, AR_TXOP_X_VAL
);
1034 REG_WRITE(ah
, AR_TXOP_0_3
, 0xFFFFFFFF);
1035 REG_WRITE(ah
, AR_TXOP_4_7
, 0xFFFFFFFF);
1036 REG_WRITE(ah
, AR_TXOP_8_11
, 0xFFFFFFFF);
1037 REG_WRITE(ah
, AR_TXOP_12_15
, 0xFFFFFFFF);
1040 static void ath9k_hw_init_pll(struct ath_hw
*ah
,
1041 struct ath9k_channel
*chan
)
1045 if (AR_SREV_9100(ah
)) {
1046 if (chan
&& IS_CHAN_5GHZ(chan
))
1051 if (AR_SREV_9280_10_OR_LATER(ah
)) {
1052 pll
= SM(0x5, AR_RTC_9160_PLL_REFDIV
);
1054 if (chan
&& IS_CHAN_HALF_RATE(chan
))
1055 pll
|= SM(0x1, AR_RTC_9160_PLL_CLKSEL
);
1056 else if (chan
&& IS_CHAN_QUARTER_RATE(chan
))
1057 pll
|= SM(0x2, AR_RTC_9160_PLL_CLKSEL
);
1059 if (chan
&& IS_CHAN_5GHZ(chan
)) {
1060 pll
|= SM(0x28, AR_RTC_9160_PLL_DIV
);
1063 if (AR_SREV_9280_20(ah
)) {
1064 if (((chan
->channel
% 20) == 0)
1065 || ((chan
->channel
% 10) == 0))
1071 pll
|= SM(0x2c, AR_RTC_9160_PLL_DIV
);
1074 } else if (AR_SREV_9160_10_OR_LATER(ah
)) {
1076 pll
= SM(0x5, AR_RTC_9160_PLL_REFDIV
);
1078 if (chan
&& IS_CHAN_HALF_RATE(chan
))
1079 pll
|= SM(0x1, AR_RTC_9160_PLL_CLKSEL
);
1080 else if (chan
&& IS_CHAN_QUARTER_RATE(chan
))
1081 pll
|= SM(0x2, AR_RTC_9160_PLL_CLKSEL
);
1083 if (chan
&& IS_CHAN_5GHZ(chan
))
1084 pll
|= SM(0x50, AR_RTC_9160_PLL_DIV
);
1086 pll
|= SM(0x58, AR_RTC_9160_PLL_DIV
);
1088 pll
= AR_RTC_PLL_REFDIV_5
| AR_RTC_PLL_DIV2
;
1090 if (chan
&& IS_CHAN_HALF_RATE(chan
))
1091 pll
|= SM(0x1, AR_RTC_PLL_CLKSEL
);
1092 else if (chan
&& IS_CHAN_QUARTER_RATE(chan
))
1093 pll
|= SM(0x2, AR_RTC_PLL_CLKSEL
);
1095 if (chan
&& IS_CHAN_5GHZ(chan
))
1096 pll
|= SM(0xa, AR_RTC_PLL_DIV
);
1098 pll
|= SM(0xb, AR_RTC_PLL_DIV
);
1101 REG_WRITE(ah
, AR_RTC_PLL_CONTROL
, pll
);
1103 udelay(RTC_PLL_SETTLE_DELAY
);
1105 REG_WRITE(ah
, AR_RTC_SLEEP_CLK
, AR_RTC_FORCE_DERIVED_CLK
);
1108 static void ath9k_hw_init_chain_masks(struct ath_hw
*ah
)
1110 int rx_chainmask
, tx_chainmask
;
1112 rx_chainmask
= ah
->rxchainmask
;
1113 tx_chainmask
= ah
->txchainmask
;
1115 switch (rx_chainmask
) {
1117 REG_SET_BIT(ah
, AR_PHY_ANALOG_SWAP
,
1118 AR_PHY_SWAP_ALT_CHAIN
);
1120 if (((ah
)->hw_version
.macVersion
<= AR_SREV_VERSION_9160
)) {
1121 REG_WRITE(ah
, AR_PHY_RX_CHAINMASK
, 0x7);
1122 REG_WRITE(ah
, AR_PHY_CAL_CHAINMASK
, 0x7);
1128 REG_WRITE(ah
, AR_PHY_RX_CHAINMASK
, rx_chainmask
);
1129 REG_WRITE(ah
, AR_PHY_CAL_CHAINMASK
, rx_chainmask
);
1135 REG_WRITE(ah
, AR_SELFGEN_MASK
, tx_chainmask
);
1136 if (tx_chainmask
== 0x5) {
1137 REG_SET_BIT(ah
, AR_PHY_ANALOG_SWAP
,
1138 AR_PHY_SWAP_ALT_CHAIN
);
1140 if (AR_SREV_9100(ah
))
1141 REG_WRITE(ah
, AR_PHY_ANALOG_SWAP
,
1142 REG_READ(ah
, AR_PHY_ANALOG_SWAP
) | 0x00000001);
1145 static void ath9k_hw_init_interrupt_masks(struct ath_hw
*ah
,
1146 enum nl80211_iftype opmode
)
1148 ah
->mask_reg
= AR_IMR_TXERR
|
1154 if (ah
->config
.intr_mitigation
)
1155 ah
->mask_reg
|= AR_IMR_RXINTM
| AR_IMR_RXMINTR
;
1157 ah
->mask_reg
|= AR_IMR_RXOK
;
1159 ah
->mask_reg
|= AR_IMR_TXOK
;
1161 if (opmode
== NL80211_IFTYPE_AP
)
1162 ah
->mask_reg
|= AR_IMR_MIB
;
1164 REG_WRITE(ah
, AR_IMR
, ah
->mask_reg
);
1165 REG_WRITE(ah
, AR_IMR_S2
, REG_READ(ah
, AR_IMR_S2
) | AR_IMR_S2_GTT
);
1167 if (!AR_SREV_9100(ah
)) {
1168 REG_WRITE(ah
, AR_INTR_SYNC_CAUSE
, 0xFFFFFFFF);
1169 REG_WRITE(ah
, AR_INTR_SYNC_ENABLE
, AR_INTR_SYNC_DEFAULT
);
1170 REG_WRITE(ah
, AR_INTR_SYNC_MASK
, 0);
1174 static bool ath9k_hw_set_ack_timeout(struct ath_hw
*ah
, u32 us
)
1176 if (us
> ath9k_hw_mac_to_usec(ah
, MS(0xffffffff, AR_TIME_OUT_ACK
))) {
1177 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
1178 "bad ack timeout %u\n", us
);
1179 ah
->acktimeout
= (u32
) -1;
1182 REG_RMW_FIELD(ah
, AR_TIME_OUT
,
1183 AR_TIME_OUT_ACK
, ath9k_hw_mac_to_clks(ah
, us
));
1184 ah
->acktimeout
= us
;
1189 static bool ath9k_hw_set_cts_timeout(struct ath_hw
*ah
, u32 us
)
1191 if (us
> ath9k_hw_mac_to_usec(ah
, MS(0xffffffff, AR_TIME_OUT_CTS
))) {
1192 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
1193 "bad cts timeout %u\n", us
);
1194 ah
->ctstimeout
= (u32
) -1;
1197 REG_RMW_FIELD(ah
, AR_TIME_OUT
,
1198 AR_TIME_OUT_CTS
, ath9k_hw_mac_to_clks(ah
, us
));
1199 ah
->ctstimeout
= us
;
1204 static bool ath9k_hw_set_global_txtimeout(struct ath_hw
*ah
, u32 tu
)
1207 ath_print(ath9k_hw_common(ah
), ATH_DBG_XMIT
,
1208 "bad global tx timeout %u\n", tu
);
1209 ah
->globaltxtimeout
= (u32
) -1;
1212 REG_RMW_FIELD(ah
, AR_GTXTO
, AR_GTXTO_TIMEOUT_LIMIT
, tu
);
1213 ah
->globaltxtimeout
= tu
;
1218 static void ath9k_hw_init_user_settings(struct ath_hw
*ah
)
1220 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
, "ah->misc_mode 0x%x\n",
1223 if (ah
->misc_mode
!= 0)
1224 REG_WRITE(ah
, AR_PCU_MISC
,
1225 REG_READ(ah
, AR_PCU_MISC
) | ah
->misc_mode
);
1226 if (ah
->slottime
!= (u32
) -1)
1227 ath9k_hw_setslottime(ah
, ah
->slottime
);
1228 if (ah
->acktimeout
!= (u32
) -1)
1229 ath9k_hw_set_ack_timeout(ah
, ah
->acktimeout
);
1230 if (ah
->ctstimeout
!= (u32
) -1)
1231 ath9k_hw_set_cts_timeout(ah
, ah
->ctstimeout
);
1232 if (ah
->globaltxtimeout
!= (u32
) -1)
1233 ath9k_hw_set_global_txtimeout(ah
, ah
->globaltxtimeout
);
1236 const char *ath9k_hw_probe(u16 vendorid
, u16 devid
)
1238 return vendorid
== ATHEROS_VENDOR_ID
?
1239 ath9k_hw_devname(devid
) : NULL
;
1242 void ath9k_hw_detach(struct ath_hw
*ah
)
1244 struct ath_common
*common
= ath9k_hw_common(ah
);
1246 if (common
->state
<= ATH_HW_INITIALIZED
)
1249 if (!AR_SREV_9100(ah
))
1250 ath9k_hw_ani_disable(ah
);
1252 ath9k_hw_setpower(ah
, ATH9K_PM_FULL_SLEEP
);
1255 ath9k_hw_rf_free(ah
);
1259 EXPORT_SYMBOL(ath9k_hw_detach
);
1265 static void ath9k_hw_override_ini(struct ath_hw
*ah
,
1266 struct ath9k_channel
*chan
)
1270 if (AR_SREV_9271(ah
)) {
1272 * Enable spectral scan to solution for issues with stuck
1273 * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
1276 if (AR_SREV_9271_10(ah
)) {
1277 val
= REG_READ(ah
, AR_PHY_SPECTRAL_SCAN
) | AR_PHY_SPECTRAL_SCAN_ENABLE
;
1278 REG_WRITE(ah
, AR_PHY_SPECTRAL_SCAN
, val
);
1280 else if (AR_SREV_9271_11(ah
))
1282 * change AR_PHY_RF_CTL3 setting to fix MAC issue
1283 * present on AR9271 1.1
1285 REG_WRITE(ah
, AR_PHY_RF_CTL3
, 0x3a020001);
1290 * Set the RX_ABORT and RX_DIS and clear if off only after
1291 * RXE is set for MAC. This prevents frames with corrupted
1292 * descriptor status.
1294 REG_SET_BIT(ah
, AR_DIAG_SW
, (AR_DIAG_RX_DIS
| AR_DIAG_RX_ABORT
));
1296 if (AR_SREV_9280_10_OR_LATER(ah
)) {
1297 val
= REG_READ(ah
, AR_PCU_MISC_MODE2
) &
1298 (~AR_PCU_MISC_MODE2_HWWAR1
);
1300 if (AR_SREV_9287_10_OR_LATER(ah
))
1301 val
= val
& (~AR_PCU_MISC_MODE2_HWWAR2
);
1303 REG_WRITE(ah
, AR_PCU_MISC_MODE2
, val
);
1306 if (!AR_SREV_5416_20_OR_LATER(ah
) ||
1307 AR_SREV_9280_10_OR_LATER(ah
))
1310 * Disable BB clock gating
1311 * Necessary to avoid issues on AR5416 2.0
1313 REG_WRITE(ah
, 0x9800 + (651 << 2), 0x11);
1316 static u32
ath9k_hw_def_ini_fixup(struct ath_hw
*ah
,
1317 struct ar5416_eeprom_def
*pEepData
,
1320 struct base_eep_header
*pBase
= &(pEepData
->baseEepHeader
);
1321 struct ath_common
*common
= ath9k_hw_common(ah
);
1323 switch (ah
->hw_version
.devid
) {
1324 case AR9280_DEVID_PCI
:
1325 if (reg
== 0x7894) {
1326 ath_print(common
, ATH_DBG_EEPROM
,
1327 "ini VAL: %x EEPROM: %x\n", value
,
1328 (pBase
->version
& 0xff));
1330 if ((pBase
->version
& 0xff) > 0x0a) {
1331 ath_print(common
, ATH_DBG_EEPROM
,
1334 value
&= ~AR_AN_TOP2_PWDCLKIND
;
1335 value
|= AR_AN_TOP2_PWDCLKIND
&
1336 (pBase
->pwdclkind
<< AR_AN_TOP2_PWDCLKIND_S
);
1338 ath_print(common
, ATH_DBG_EEPROM
,
1339 "PWDCLKIND Earlier Rev\n");
1342 ath_print(common
, ATH_DBG_EEPROM
,
1343 "final ini VAL: %x\n", value
);
1351 static u32
ath9k_hw_ini_fixup(struct ath_hw
*ah
,
1352 struct ar5416_eeprom_def
*pEepData
,
1355 if (ah
->eep_map
== EEP_MAP_4KBITS
)
1358 return ath9k_hw_def_ini_fixup(ah
, pEepData
, reg
, value
);
1361 static void ath9k_olc_init(struct ath_hw
*ah
)
1365 if (OLC_FOR_AR9287_10_LATER
) {
1366 REG_SET_BIT(ah
, AR_PHY_TX_PWRCTRL9
,
1367 AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL
);
1368 ath9k_hw_analog_shift_rmw(ah
, AR9287_AN_TXPC0
,
1369 AR9287_AN_TXPC0_TXPCMODE
,
1370 AR9287_AN_TXPC0_TXPCMODE_S
,
1371 AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE
);
1374 for (i
= 0; i
< AR9280_TX_GAIN_TABLE_SIZE
; i
++)
1375 ah
->originalGain
[i
] =
1376 MS(REG_READ(ah
, AR_PHY_TX_GAIN_TBL1
+ i
* 4),
1382 static u32
ath9k_regd_get_ctl(struct ath_regulatory
*reg
,
1383 struct ath9k_channel
*chan
)
1385 u32 ctl
= ath_regd_get_band_ctl(reg
, chan
->chan
->band
);
1387 if (IS_CHAN_B(chan
))
1389 else if (IS_CHAN_G(chan
))
1397 static int ath9k_hw_process_ini(struct ath_hw
*ah
,
1398 struct ath9k_channel
*chan
)
1400 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
1401 int i
, regWrites
= 0;
1402 struct ieee80211_channel
*channel
= chan
->chan
;
1403 u32 modesIndex
, freqIndex
;
1405 switch (chan
->chanmode
) {
1407 case CHANNEL_A_HT20
:
1411 case CHANNEL_A_HT40PLUS
:
1412 case CHANNEL_A_HT40MINUS
:
1417 case CHANNEL_G_HT20
:
1422 case CHANNEL_G_HT40PLUS
:
1423 case CHANNEL_G_HT40MINUS
:
1432 REG_WRITE(ah
, AR_PHY(0), 0x00000007);
1433 REG_WRITE(ah
, AR_PHY_ADC_SERIAL_CTL
, AR_PHY_SEL_EXTERNAL_RADIO
);
1434 ah
->eep_ops
->set_addac(ah
, chan
);
1436 if (AR_SREV_5416_22_OR_LATER(ah
)) {
1437 REG_WRITE_ARRAY(&ah
->iniAddac
, 1, regWrites
);
1439 struct ar5416IniArray temp
;
1441 sizeof(u32
) * ah
->iniAddac
.ia_rows
*
1442 ah
->iniAddac
.ia_columns
;
1444 memcpy(ah
->addac5416_21
,
1445 ah
->iniAddac
.ia_array
, addacSize
);
1447 (ah
->addac5416_21
)[31 * ah
->iniAddac
.ia_columns
+ 1] = 0;
1449 temp
.ia_array
= ah
->addac5416_21
;
1450 temp
.ia_columns
= ah
->iniAddac
.ia_columns
;
1451 temp
.ia_rows
= ah
->iniAddac
.ia_rows
;
1452 REG_WRITE_ARRAY(&temp
, 1, regWrites
);
1455 REG_WRITE(ah
, AR_PHY_ADC_SERIAL_CTL
, AR_PHY_SEL_INTERNAL_ADDAC
);
1457 for (i
= 0; i
< ah
->iniModes
.ia_rows
; i
++) {
1458 u32 reg
= INI_RA(&ah
->iniModes
, i
, 0);
1459 u32 val
= INI_RA(&ah
->iniModes
, i
, modesIndex
);
1461 REG_WRITE(ah
, reg
, val
);
1463 if (reg
>= 0x7800 && reg
< 0x78a0
1464 && ah
->config
.analog_shiftreg
) {
1468 DO_DELAY(regWrites
);
1471 if (AR_SREV_9280(ah
) || AR_SREV_9287_10_OR_LATER(ah
))
1472 REG_WRITE_ARRAY(&ah
->iniModesRxGain
, modesIndex
, regWrites
);
1474 if (AR_SREV_9280(ah
) || AR_SREV_9285_12_OR_LATER(ah
) ||
1475 AR_SREV_9287_10_OR_LATER(ah
))
1476 REG_WRITE_ARRAY(&ah
->iniModesTxGain
, modesIndex
, regWrites
);
1478 for (i
= 0; i
< ah
->iniCommon
.ia_rows
; i
++) {
1479 u32 reg
= INI_RA(&ah
->iniCommon
, i
, 0);
1480 u32 val
= INI_RA(&ah
->iniCommon
, i
, 1);
1482 REG_WRITE(ah
, reg
, val
);
1484 if (reg
>= 0x7800 && reg
< 0x78a0
1485 && ah
->config
.analog_shiftreg
) {
1489 DO_DELAY(regWrites
);
1492 ath9k_hw_write_regs(ah
, modesIndex
, freqIndex
, regWrites
);
1494 if (AR_SREV_9280_20(ah
) && IS_CHAN_A_5MHZ_SPACED(chan
)) {
1495 REG_WRITE_ARRAY(&ah
->iniModesAdditional
, modesIndex
,
1499 ath9k_hw_override_ini(ah
, chan
);
1500 ath9k_hw_set_regs(ah
, chan
);
1501 ath9k_hw_init_chain_masks(ah
);
1503 if (OLC_FOR_AR9280_20_LATER
)
1506 ah
->eep_ops
->set_txpower(ah
, chan
,
1507 ath9k_regd_get_ctl(regulatory
, chan
),
1508 channel
->max_antenna_gain
* 2,
1509 channel
->max_power
* 2,
1510 min((u32
) MAX_RATE_POWER
,
1511 (u32
) regulatory
->power_limit
));
1513 if (!ath9k_hw_set_rf_regs(ah
, chan
, freqIndex
)) {
1514 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
1515 "ar5416SetRfRegs failed\n");
1522 /****************************************/
1523 /* Reset and Channel Switching Routines */
1524 /****************************************/
1526 static void ath9k_hw_set_rfmode(struct ath_hw
*ah
, struct ath9k_channel
*chan
)
1533 rfMode
|= (IS_CHAN_B(chan
) || IS_CHAN_G(chan
))
1534 ? AR_PHY_MODE_DYNAMIC
: AR_PHY_MODE_OFDM
;
1536 if (!AR_SREV_9280_10_OR_LATER(ah
))
1537 rfMode
|= (IS_CHAN_5GHZ(chan
)) ?
1538 AR_PHY_MODE_RF5GHZ
: AR_PHY_MODE_RF2GHZ
;
1540 if (AR_SREV_9280_20(ah
) && IS_CHAN_A_5MHZ_SPACED(chan
))
1541 rfMode
|= (AR_PHY_MODE_DYNAMIC
| AR_PHY_MODE_DYN_CCK_DISABLE
);
1543 REG_WRITE(ah
, AR_PHY_MODE
, rfMode
);
1546 static void ath9k_hw_mark_phy_inactive(struct ath_hw
*ah
)
1548 REG_WRITE(ah
, AR_PHY_ACTIVE
, AR_PHY_ACTIVE_DIS
);
1551 static inline void ath9k_hw_set_dma(struct ath_hw
*ah
)
1556 * set AHB_MODE not to do cacheline prefetches
1558 regval
= REG_READ(ah
, AR_AHB_MODE
);
1559 REG_WRITE(ah
, AR_AHB_MODE
, regval
| AR_AHB_PREFETCH_RD_EN
);
1562 * let mac dma reads be in 128 byte chunks
1564 regval
= REG_READ(ah
, AR_TXCFG
) & ~AR_TXCFG_DMASZ_MASK
;
1565 REG_WRITE(ah
, AR_TXCFG
, regval
| AR_TXCFG_DMASZ_128B
);
1568 * Restore TX Trigger Level to its pre-reset value.
1569 * The initial value depends on whether aggregation is enabled, and is
1570 * adjusted whenever underruns are detected.
1572 REG_RMW_FIELD(ah
, AR_TXCFG
, AR_FTRIG
, ah
->tx_trig_level
);
1575 * let mac dma writes be in 128 byte chunks
1577 regval
= REG_READ(ah
, AR_RXCFG
) & ~AR_RXCFG_DMASZ_MASK
;
1578 REG_WRITE(ah
, AR_RXCFG
, regval
| AR_RXCFG_DMASZ_128B
);
1581 * Setup receive FIFO threshold to hold off TX activities
1583 REG_WRITE(ah
, AR_RXFIFO_CFG
, 0x200);
1586 * reduce the number of usable entries in PCU TXBUF to avoid
1587 * wrap around issues.
1589 if (AR_SREV_9285(ah
)) {
1590 /* For AR9285 the number of Fifos are reduced to half.
1591 * So set the usable tx buf size also to half to
1592 * avoid data/delimiter underruns
1594 REG_WRITE(ah
, AR_PCU_TXBUF_CTRL
,
1595 AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE
);
1596 } else if (!AR_SREV_9271(ah
)) {
1597 REG_WRITE(ah
, AR_PCU_TXBUF_CTRL
,
1598 AR_PCU_TXBUF_CTRL_USABLE_SIZE
);
1602 static void ath9k_hw_set_operating_mode(struct ath_hw
*ah
, int opmode
)
1606 val
= REG_READ(ah
, AR_STA_ID1
);
1607 val
&= ~(AR_STA_ID1_STA_AP
| AR_STA_ID1_ADHOC
);
1609 case NL80211_IFTYPE_AP
:
1610 REG_WRITE(ah
, AR_STA_ID1
, val
| AR_STA_ID1_STA_AP
1611 | AR_STA_ID1_KSRCH_MODE
);
1612 REG_CLR_BIT(ah
, AR_CFG
, AR_CFG_AP_ADHOC_INDICATION
);
1614 case NL80211_IFTYPE_ADHOC
:
1615 case NL80211_IFTYPE_MESH_POINT
:
1616 REG_WRITE(ah
, AR_STA_ID1
, val
| AR_STA_ID1_ADHOC
1617 | AR_STA_ID1_KSRCH_MODE
);
1618 REG_SET_BIT(ah
, AR_CFG
, AR_CFG_AP_ADHOC_INDICATION
);
1620 case NL80211_IFTYPE_STATION
:
1621 case NL80211_IFTYPE_MONITOR
:
1622 REG_WRITE(ah
, AR_STA_ID1
, val
| AR_STA_ID1_KSRCH_MODE
);
1627 static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw
*ah
,
1632 u32 coef_exp
, coef_man
;
1634 for (coef_exp
= 31; coef_exp
> 0; coef_exp
--)
1635 if ((coef_scaled
>> coef_exp
) & 0x1)
1638 coef_exp
= 14 - (coef_exp
- COEF_SCALE_S
);
1640 coef_man
= coef_scaled
+ (1 << (COEF_SCALE_S
- coef_exp
- 1));
1642 *coef_mantissa
= coef_man
>> (COEF_SCALE_S
- coef_exp
);
1643 *coef_exponent
= coef_exp
- 16;
1646 static void ath9k_hw_set_delta_slope(struct ath_hw
*ah
,
1647 struct ath9k_channel
*chan
)
1649 u32 coef_scaled
, ds_coef_exp
, ds_coef_man
;
1650 u32 clockMhzScaled
= 0x64000000;
1651 struct chan_centers centers
;
1653 if (IS_CHAN_HALF_RATE(chan
))
1654 clockMhzScaled
= clockMhzScaled
>> 1;
1655 else if (IS_CHAN_QUARTER_RATE(chan
))
1656 clockMhzScaled
= clockMhzScaled
>> 2;
1658 ath9k_hw_get_channel_centers(ah
, chan
, ¢ers
);
1659 coef_scaled
= clockMhzScaled
/ centers
.synth_center
;
1661 ath9k_hw_get_delta_slope_vals(ah
, coef_scaled
, &ds_coef_man
,
1664 REG_RMW_FIELD(ah
, AR_PHY_TIMING3
,
1665 AR_PHY_TIMING3_DSC_MAN
, ds_coef_man
);
1666 REG_RMW_FIELD(ah
, AR_PHY_TIMING3
,
1667 AR_PHY_TIMING3_DSC_EXP
, ds_coef_exp
);
1669 coef_scaled
= (9 * coef_scaled
) / 10;
1671 ath9k_hw_get_delta_slope_vals(ah
, coef_scaled
, &ds_coef_man
,
1674 REG_RMW_FIELD(ah
, AR_PHY_HALFGI
,
1675 AR_PHY_HALFGI_DSC_MAN
, ds_coef_man
);
1676 REG_RMW_FIELD(ah
, AR_PHY_HALFGI
,
1677 AR_PHY_HALFGI_DSC_EXP
, ds_coef_exp
);
1680 static bool ath9k_hw_set_reset(struct ath_hw
*ah
, int type
)
1685 if (AR_SREV_9100(ah
)) {
1686 u32 val
= REG_READ(ah
, AR_RTC_DERIVED_CLK
);
1687 val
&= ~AR_RTC_DERIVED_CLK_PERIOD
;
1688 val
|= SM(1, AR_RTC_DERIVED_CLK_PERIOD
);
1689 REG_WRITE(ah
, AR_RTC_DERIVED_CLK
, val
);
1690 (void)REG_READ(ah
, AR_RTC_DERIVED_CLK
);
1693 REG_WRITE(ah
, AR_RTC_FORCE_WAKE
, AR_RTC_FORCE_WAKE_EN
|
1694 AR_RTC_FORCE_WAKE_ON_INT
);
1696 if (AR_SREV_9100(ah
)) {
1697 rst_flags
= AR_RTC_RC_MAC_WARM
| AR_RTC_RC_MAC_COLD
|
1698 AR_RTC_RC_COLD_RESET
| AR_RTC_RC_WARM_RESET
;
1700 tmpReg
= REG_READ(ah
, AR_INTR_SYNC_CAUSE
);
1702 (AR_INTR_SYNC_LOCAL_TIMEOUT
|
1703 AR_INTR_SYNC_RADM_CPL_TIMEOUT
)) {
1704 REG_WRITE(ah
, AR_INTR_SYNC_ENABLE
, 0);
1705 REG_WRITE(ah
, AR_RC
, AR_RC_AHB
| AR_RC_HOSTIF
);
1707 REG_WRITE(ah
, AR_RC
, AR_RC_AHB
);
1710 rst_flags
= AR_RTC_RC_MAC_WARM
;
1711 if (type
== ATH9K_RESET_COLD
)
1712 rst_flags
|= AR_RTC_RC_MAC_COLD
;
1715 REG_WRITE(ah
, AR_RTC_RC
, rst_flags
);
1718 REG_WRITE(ah
, AR_RTC_RC
, 0);
1719 if (!ath9k_hw_wait(ah
, AR_RTC_RC
, AR_RTC_RC_M
, 0, AH_WAIT_TIMEOUT
)) {
1720 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
1721 "RTC stuck in MAC reset\n");
1725 if (!AR_SREV_9100(ah
))
1726 REG_WRITE(ah
, AR_RC
, 0);
1728 if (AR_SREV_9100(ah
))
1734 static bool ath9k_hw_set_reset_power_on(struct ath_hw
*ah
)
1736 REG_WRITE(ah
, AR_RTC_FORCE_WAKE
, AR_RTC_FORCE_WAKE_EN
|
1737 AR_RTC_FORCE_WAKE_ON_INT
);
1739 if (!AR_SREV_9100(ah
))
1740 REG_WRITE(ah
, AR_RC
, AR_RC_AHB
);
1742 REG_WRITE(ah
, AR_RTC_RESET
, 0);
1745 if (!AR_SREV_9100(ah
))
1746 REG_WRITE(ah
, AR_RC
, 0);
1748 REG_WRITE(ah
, AR_RTC_RESET
, 1);
1750 if (!ath9k_hw_wait(ah
,
1755 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
1756 "RTC not waking up\n");
1760 ath9k_hw_read_revisions(ah
);
1762 return ath9k_hw_set_reset(ah
, ATH9K_RESET_WARM
);
1765 static bool ath9k_hw_set_reset_reg(struct ath_hw
*ah
, u32 type
)
1767 REG_WRITE(ah
, AR_RTC_FORCE_WAKE
,
1768 AR_RTC_FORCE_WAKE_EN
| AR_RTC_FORCE_WAKE_ON_INT
);
1771 case ATH9K_RESET_POWER_ON
:
1772 return ath9k_hw_set_reset_power_on(ah
);
1773 case ATH9K_RESET_WARM
:
1774 case ATH9K_RESET_COLD
:
1775 return ath9k_hw_set_reset(ah
, type
);
1781 static void ath9k_hw_set_regs(struct ath_hw
*ah
, struct ath9k_channel
*chan
)
1784 u32 enableDacFifo
= 0;
1786 if (AR_SREV_9285_10_OR_LATER(ah
))
1787 enableDacFifo
= (REG_READ(ah
, AR_PHY_TURBO
) &
1788 AR_PHY_FC_ENABLE_DAC_FIFO
);
1790 phymode
= AR_PHY_FC_HT_EN
| AR_PHY_FC_SHORT_GI_40
1791 | AR_PHY_FC_SINGLE_HT_LTF1
| AR_PHY_FC_WALSH
| enableDacFifo
;
1793 if (IS_CHAN_HT40(chan
)) {
1794 phymode
|= AR_PHY_FC_DYN2040_EN
;
1796 if ((chan
->chanmode
== CHANNEL_A_HT40PLUS
) ||
1797 (chan
->chanmode
== CHANNEL_G_HT40PLUS
))
1798 phymode
|= AR_PHY_FC_DYN2040_PRI_CH
;
1801 REG_WRITE(ah
, AR_PHY_TURBO
, phymode
);
1803 ath9k_hw_set11nmac2040(ah
);
1805 REG_WRITE(ah
, AR_GTXTO
, 25 << AR_GTXTO_TIMEOUT_LIMIT_S
);
1806 REG_WRITE(ah
, AR_CST
, 0xF << AR_CST_TIMEOUT_LIMIT_S
);
1809 static bool ath9k_hw_chip_reset(struct ath_hw
*ah
,
1810 struct ath9k_channel
*chan
)
1812 if (AR_SREV_9280(ah
) && ah
->eep_ops
->get_eeprom(ah
, EEP_OL_PWRCTRL
)) {
1813 if (!ath9k_hw_set_reset_reg(ah
, ATH9K_RESET_POWER_ON
))
1815 } else if (!ath9k_hw_set_reset_reg(ah
, ATH9K_RESET_WARM
))
1818 if (!ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
))
1821 ah
->chip_fullsleep
= false;
1822 ath9k_hw_init_pll(ah
, chan
);
1823 ath9k_hw_set_rfmode(ah
, chan
);
1828 static bool ath9k_hw_channel_change(struct ath_hw
*ah
,
1829 struct ath9k_channel
*chan
)
1831 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
1832 struct ath_common
*common
= ath9k_hw_common(ah
);
1833 struct ieee80211_channel
*channel
= chan
->chan
;
1834 u32 synthDelay
, qnum
;
1836 for (qnum
= 0; qnum
< AR_NUM_QCU
; qnum
++) {
1837 if (ath9k_hw_numtxpending(ah
, qnum
)) {
1838 ath_print(common
, ATH_DBG_QUEUE
,
1839 "Transmit frames pending on "
1840 "queue %d\n", qnum
);
1845 REG_WRITE(ah
, AR_PHY_RFBUS_REQ
, AR_PHY_RFBUS_REQ_EN
);
1846 if (!ath9k_hw_wait(ah
, AR_PHY_RFBUS_GRANT
, AR_PHY_RFBUS_GRANT_EN
,
1847 AR_PHY_RFBUS_GRANT_EN
, AH_WAIT_TIMEOUT
)) {
1848 ath_print(common
, ATH_DBG_FATAL
,
1849 "Could not kill baseband RX\n");
1853 ath9k_hw_set_regs(ah
, chan
);
1855 if (AR_SREV_9280_10_OR_LATER(ah
)) {
1856 ath9k_hw_ar9280_set_channel(ah
, chan
);
1858 if (!(ath9k_hw_set_channel(ah
, chan
))) {
1859 ath_print(common
, ATH_DBG_FATAL
,
1860 "Failed to set channel\n");
1865 ah
->eep_ops
->set_txpower(ah
, chan
,
1866 ath9k_regd_get_ctl(regulatory
, chan
),
1867 channel
->max_antenna_gain
* 2,
1868 channel
->max_power
* 2,
1869 min((u32
) MAX_RATE_POWER
,
1870 (u32
) regulatory
->power_limit
));
1872 synthDelay
= REG_READ(ah
, AR_PHY_RX_DELAY
) & AR_PHY_RX_DELAY_DELAY
;
1873 if (IS_CHAN_B(chan
))
1874 synthDelay
= (4 * synthDelay
) / 22;
1878 udelay(synthDelay
+ BASE_ACTIVATE_DELAY
);
1880 REG_WRITE(ah
, AR_PHY_RFBUS_REQ
, 0);
1882 if (IS_CHAN_OFDM(chan
) || IS_CHAN_HT(chan
))
1883 ath9k_hw_set_delta_slope(ah
, chan
);
1885 if (AR_SREV_9280_10_OR_LATER(ah
))
1886 ath9k_hw_9280_spur_mitigate(ah
, chan
);
1888 ath9k_hw_spur_mitigate(ah
, chan
);
1890 if (!chan
->oneTimeCalsDone
)
1891 chan
->oneTimeCalsDone
= true;
1896 static void ath9k_hw_9280_spur_mitigate(struct ath_hw
*ah
, struct ath9k_channel
*chan
)
1898 int bb_spur
= AR_NO_SPUR
;
1901 int bb_spur_off
, spur_subchannel_sd
;
1903 int spur_delta_phase
;
1905 int upper
, lower
, cur_vit_mask
;
1908 int pilot_mask_reg
[4] = { AR_PHY_TIMING7
, AR_PHY_TIMING8
,
1909 AR_PHY_PILOT_MASK_01_30
, AR_PHY_PILOT_MASK_31_60
1911 int chan_mask_reg
[4] = { AR_PHY_TIMING9
, AR_PHY_TIMING10
,
1912 AR_PHY_CHANNEL_MASK_01_30
, AR_PHY_CHANNEL_MASK_31_60
1914 int inc
[4] = { 0, 100, 0, 0 };
1915 struct chan_centers centers
;
1922 bool is2GHz
= IS_CHAN_2GHZ(chan
);
1924 memset(&mask_m
, 0, sizeof(int8_t) * 123);
1925 memset(&mask_p
, 0, sizeof(int8_t) * 123);
1927 ath9k_hw_get_channel_centers(ah
, chan
, ¢ers
);
1928 freq
= centers
.synth_center
;
1930 ah
->config
.spurmode
= SPUR_ENABLE_EEPROM
;
1931 for (i
= 0; i
< AR_EEPROM_MODAL_SPURS
; i
++) {
1932 cur_bb_spur
= ah
->eep_ops
->get_spur_channel(ah
, i
, is2GHz
);
1935 cur_bb_spur
= (cur_bb_spur
/ 10) + AR_BASE_FREQ_2GHZ
;
1937 cur_bb_spur
= (cur_bb_spur
/ 10) + AR_BASE_FREQ_5GHZ
;
1939 if (AR_NO_SPUR
== cur_bb_spur
)
1941 cur_bb_spur
= cur_bb_spur
- freq
;
1943 if (IS_CHAN_HT40(chan
)) {
1944 if ((cur_bb_spur
> -AR_SPUR_FEEQ_BOUND_HT40
) &&
1945 (cur_bb_spur
< AR_SPUR_FEEQ_BOUND_HT40
)) {
1946 bb_spur
= cur_bb_spur
;
1949 } else if ((cur_bb_spur
> -AR_SPUR_FEEQ_BOUND_HT20
) &&
1950 (cur_bb_spur
< AR_SPUR_FEEQ_BOUND_HT20
)) {
1951 bb_spur
= cur_bb_spur
;
1956 if (AR_NO_SPUR
== bb_spur
) {
1957 REG_CLR_BIT(ah
, AR_PHY_FORCE_CLKEN_CCK
,
1958 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX
);
1961 REG_CLR_BIT(ah
, AR_PHY_FORCE_CLKEN_CCK
,
1962 AR_PHY_FORCE_CLKEN_CCK_MRC_MUX
);
1965 bin
= bb_spur
* 320;
1967 tmp
= REG_READ(ah
, AR_PHY_TIMING_CTRL4(0));
1969 newVal
= tmp
| (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI
|
1970 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER
|
1971 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK
|
1972 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK
);
1973 REG_WRITE(ah
, AR_PHY_TIMING_CTRL4(0), newVal
);
1975 newVal
= (AR_PHY_SPUR_REG_MASK_RATE_CNTL
|
1976 AR_PHY_SPUR_REG_ENABLE_MASK_PPM
|
1977 AR_PHY_SPUR_REG_MASK_RATE_SELECT
|
1978 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI
|
1979 SM(SPUR_RSSI_THRESH
, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH
));
1980 REG_WRITE(ah
, AR_PHY_SPUR_REG
, newVal
);
1982 if (IS_CHAN_HT40(chan
)) {
1984 spur_subchannel_sd
= 1;
1985 bb_spur_off
= bb_spur
+ 10;
1987 spur_subchannel_sd
= 0;
1988 bb_spur_off
= bb_spur
- 10;
1991 spur_subchannel_sd
= 0;
1992 bb_spur_off
= bb_spur
;
1995 if (IS_CHAN_HT40(chan
))
1997 ((bb_spur
* 262144) /
1998 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE
;
2001 ((bb_spur
* 524288) /
2002 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE
;
2004 denominator
= IS_CHAN_2GHZ(chan
) ? 44 : 40;
2005 spur_freq_sd
= ((bb_spur_off
* 2048) / denominator
) & 0x3ff;
2007 newVal
= (AR_PHY_TIMING11_USE_SPUR_IN_AGC
|
2008 SM(spur_freq_sd
, AR_PHY_TIMING11_SPUR_FREQ_SD
) |
2009 SM(spur_delta_phase
, AR_PHY_TIMING11_SPUR_DELTA_PHASE
));
2010 REG_WRITE(ah
, AR_PHY_TIMING11
, newVal
);
2012 newVal
= spur_subchannel_sd
<< AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S
;
2013 REG_WRITE(ah
, AR_PHY_SFCORR_EXT
, newVal
);
2019 for (i
= 0; i
< 4; i
++) {
2023 for (bp
= 0; bp
< 30; bp
++) {
2024 if ((cur_bin
> lower
) && (cur_bin
< upper
)) {
2025 pilot_mask
= pilot_mask
| 0x1 << bp
;
2026 chan_mask
= chan_mask
| 0x1 << bp
;
2031 REG_WRITE(ah
, pilot_mask_reg
[i
], pilot_mask
);
2032 REG_WRITE(ah
, chan_mask_reg
[i
], chan_mask
);
2035 cur_vit_mask
= 6100;
2039 for (i
= 0; i
< 123; i
++) {
2040 if ((cur_vit_mask
> lower
) && (cur_vit_mask
< upper
)) {
2042 /* workaround for gcc bug #37014 */
2043 volatile int tmp_v
= abs(cur_vit_mask
- bin
);
2049 if (cur_vit_mask
< 0)
2050 mask_m
[abs(cur_vit_mask
/ 100)] = mask_amt
;
2052 mask_p
[cur_vit_mask
/ 100] = mask_amt
;
2054 cur_vit_mask
-= 100;
2057 tmp_mask
= (mask_m
[46] << 30) | (mask_m
[47] << 28)
2058 | (mask_m
[48] << 26) | (mask_m
[49] << 24)
2059 | (mask_m
[50] << 22) | (mask_m
[51] << 20)
2060 | (mask_m
[52] << 18) | (mask_m
[53] << 16)
2061 | (mask_m
[54] << 14) | (mask_m
[55] << 12)
2062 | (mask_m
[56] << 10) | (mask_m
[57] << 8)
2063 | (mask_m
[58] << 6) | (mask_m
[59] << 4)
2064 | (mask_m
[60] << 2) | (mask_m
[61] << 0);
2065 REG_WRITE(ah
, AR_PHY_BIN_MASK_1
, tmp_mask
);
2066 REG_WRITE(ah
, AR_PHY_VIT_MASK2_M_46_61
, tmp_mask
);
2068 tmp_mask
= (mask_m
[31] << 28)
2069 | (mask_m
[32] << 26) | (mask_m
[33] << 24)
2070 | (mask_m
[34] << 22) | (mask_m
[35] << 20)
2071 | (mask_m
[36] << 18) | (mask_m
[37] << 16)
2072 | (mask_m
[48] << 14) | (mask_m
[39] << 12)
2073 | (mask_m
[40] << 10) | (mask_m
[41] << 8)
2074 | (mask_m
[42] << 6) | (mask_m
[43] << 4)
2075 | (mask_m
[44] << 2) | (mask_m
[45] << 0);
2076 REG_WRITE(ah
, AR_PHY_BIN_MASK_2
, tmp_mask
);
2077 REG_WRITE(ah
, AR_PHY_MASK2_M_31_45
, tmp_mask
);
2079 tmp_mask
= (mask_m
[16] << 30) | (mask_m
[16] << 28)
2080 | (mask_m
[18] << 26) | (mask_m
[18] << 24)
2081 | (mask_m
[20] << 22) | (mask_m
[20] << 20)
2082 | (mask_m
[22] << 18) | (mask_m
[22] << 16)
2083 | (mask_m
[24] << 14) | (mask_m
[24] << 12)
2084 | (mask_m
[25] << 10) | (mask_m
[26] << 8)
2085 | (mask_m
[27] << 6) | (mask_m
[28] << 4)
2086 | (mask_m
[29] << 2) | (mask_m
[30] << 0);
2087 REG_WRITE(ah
, AR_PHY_BIN_MASK_3
, tmp_mask
);
2088 REG_WRITE(ah
, AR_PHY_MASK2_M_16_30
, tmp_mask
);
2090 tmp_mask
= (mask_m
[0] << 30) | (mask_m
[1] << 28)
2091 | (mask_m
[2] << 26) | (mask_m
[3] << 24)
2092 | (mask_m
[4] << 22) | (mask_m
[5] << 20)
2093 | (mask_m
[6] << 18) | (mask_m
[7] << 16)
2094 | (mask_m
[8] << 14) | (mask_m
[9] << 12)
2095 | (mask_m
[10] << 10) | (mask_m
[11] << 8)
2096 | (mask_m
[12] << 6) | (mask_m
[13] << 4)
2097 | (mask_m
[14] << 2) | (mask_m
[15] << 0);
2098 REG_WRITE(ah
, AR_PHY_MASK_CTL
, tmp_mask
);
2099 REG_WRITE(ah
, AR_PHY_MASK2_M_00_15
, tmp_mask
);
2101 tmp_mask
= (mask_p
[15] << 28)
2102 | (mask_p
[14] << 26) | (mask_p
[13] << 24)
2103 | (mask_p
[12] << 22) | (mask_p
[11] << 20)
2104 | (mask_p
[10] << 18) | (mask_p
[9] << 16)
2105 | (mask_p
[8] << 14) | (mask_p
[7] << 12)
2106 | (mask_p
[6] << 10) | (mask_p
[5] << 8)
2107 | (mask_p
[4] << 6) | (mask_p
[3] << 4)
2108 | (mask_p
[2] << 2) | (mask_p
[1] << 0);
2109 REG_WRITE(ah
, AR_PHY_BIN_MASK2_1
, tmp_mask
);
2110 REG_WRITE(ah
, AR_PHY_MASK2_P_15_01
, tmp_mask
);
2112 tmp_mask
= (mask_p
[30] << 28)
2113 | (mask_p
[29] << 26) | (mask_p
[28] << 24)
2114 | (mask_p
[27] << 22) | (mask_p
[26] << 20)
2115 | (mask_p
[25] << 18) | (mask_p
[24] << 16)
2116 | (mask_p
[23] << 14) | (mask_p
[22] << 12)
2117 | (mask_p
[21] << 10) | (mask_p
[20] << 8)
2118 | (mask_p
[19] << 6) | (mask_p
[18] << 4)
2119 | (mask_p
[17] << 2) | (mask_p
[16] << 0);
2120 REG_WRITE(ah
, AR_PHY_BIN_MASK2_2
, tmp_mask
);
2121 REG_WRITE(ah
, AR_PHY_MASK2_P_30_16
, tmp_mask
);
2123 tmp_mask
= (mask_p
[45] << 28)
2124 | (mask_p
[44] << 26) | (mask_p
[43] << 24)
2125 | (mask_p
[42] << 22) | (mask_p
[41] << 20)
2126 | (mask_p
[40] << 18) | (mask_p
[39] << 16)
2127 | (mask_p
[38] << 14) | (mask_p
[37] << 12)
2128 | (mask_p
[36] << 10) | (mask_p
[35] << 8)
2129 | (mask_p
[34] << 6) | (mask_p
[33] << 4)
2130 | (mask_p
[32] << 2) | (mask_p
[31] << 0);
2131 REG_WRITE(ah
, AR_PHY_BIN_MASK2_3
, tmp_mask
);
2132 REG_WRITE(ah
, AR_PHY_MASK2_P_45_31
, tmp_mask
);
2134 tmp_mask
= (mask_p
[61] << 30) | (mask_p
[60] << 28)
2135 | (mask_p
[59] << 26) | (mask_p
[58] << 24)
2136 | (mask_p
[57] << 22) | (mask_p
[56] << 20)
2137 | (mask_p
[55] << 18) | (mask_p
[54] << 16)
2138 | (mask_p
[53] << 14) | (mask_p
[52] << 12)
2139 | (mask_p
[51] << 10) | (mask_p
[50] << 8)
2140 | (mask_p
[49] << 6) | (mask_p
[48] << 4)
2141 | (mask_p
[47] << 2) | (mask_p
[46] << 0);
2142 REG_WRITE(ah
, AR_PHY_BIN_MASK2_4
, tmp_mask
);
2143 REG_WRITE(ah
, AR_PHY_MASK2_P_61_45
, tmp_mask
);
2146 static void ath9k_hw_spur_mitigate(struct ath_hw
*ah
, struct ath9k_channel
*chan
)
2148 int bb_spur
= AR_NO_SPUR
;
2151 int spur_delta_phase
;
2153 int upper
, lower
, cur_vit_mask
;
2156 int pilot_mask_reg
[4] = { AR_PHY_TIMING7
, AR_PHY_TIMING8
,
2157 AR_PHY_PILOT_MASK_01_30
, AR_PHY_PILOT_MASK_31_60
2159 int chan_mask_reg
[4] = { AR_PHY_TIMING9
, AR_PHY_TIMING10
,
2160 AR_PHY_CHANNEL_MASK_01_30
, AR_PHY_CHANNEL_MASK_31_60
2162 int inc
[4] = { 0, 100, 0, 0 };
2169 bool is2GHz
= IS_CHAN_2GHZ(chan
);
2171 memset(&mask_m
, 0, sizeof(int8_t) * 123);
2172 memset(&mask_p
, 0, sizeof(int8_t) * 123);
2174 for (i
= 0; i
< AR_EEPROM_MODAL_SPURS
; i
++) {
2175 cur_bb_spur
= ah
->eep_ops
->get_spur_channel(ah
, i
, is2GHz
);
2176 if (AR_NO_SPUR
== cur_bb_spur
)
2178 cur_bb_spur
= cur_bb_spur
- (chan
->channel
* 10);
2179 if ((cur_bb_spur
> -95) && (cur_bb_spur
< 95)) {
2180 bb_spur
= cur_bb_spur
;
2185 if (AR_NO_SPUR
== bb_spur
)
2190 tmp
= REG_READ(ah
, AR_PHY_TIMING_CTRL4(0));
2191 new = tmp
| (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI
|
2192 AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER
|
2193 AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK
|
2194 AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK
);
2196 REG_WRITE(ah
, AR_PHY_TIMING_CTRL4(0), new);
2198 new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL
|
2199 AR_PHY_SPUR_REG_ENABLE_MASK_PPM
|
2200 AR_PHY_SPUR_REG_MASK_RATE_SELECT
|
2201 AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI
|
2202 SM(SPUR_RSSI_THRESH
, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH
));
2203 REG_WRITE(ah
, AR_PHY_SPUR_REG
, new);
2205 spur_delta_phase
= ((bb_spur
* 524288) / 100) &
2206 AR_PHY_TIMING11_SPUR_DELTA_PHASE
;
2208 denominator
= IS_CHAN_2GHZ(chan
) ? 440 : 400;
2209 spur_freq_sd
= ((bb_spur
* 2048) / denominator
) & 0x3ff;
2211 new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC
|
2212 SM(spur_freq_sd
, AR_PHY_TIMING11_SPUR_FREQ_SD
) |
2213 SM(spur_delta_phase
, AR_PHY_TIMING11_SPUR_DELTA_PHASE
));
2214 REG_WRITE(ah
, AR_PHY_TIMING11
, new);
2220 for (i
= 0; i
< 4; i
++) {
2224 for (bp
= 0; bp
< 30; bp
++) {
2225 if ((cur_bin
> lower
) && (cur_bin
< upper
)) {
2226 pilot_mask
= pilot_mask
| 0x1 << bp
;
2227 chan_mask
= chan_mask
| 0x1 << bp
;
2232 REG_WRITE(ah
, pilot_mask_reg
[i
], pilot_mask
);
2233 REG_WRITE(ah
, chan_mask_reg
[i
], chan_mask
);
2236 cur_vit_mask
= 6100;
2240 for (i
= 0; i
< 123; i
++) {
2241 if ((cur_vit_mask
> lower
) && (cur_vit_mask
< upper
)) {
2243 /* workaround for gcc bug #37014 */
2244 volatile int tmp_v
= abs(cur_vit_mask
- bin
);
2250 if (cur_vit_mask
< 0)
2251 mask_m
[abs(cur_vit_mask
/ 100)] = mask_amt
;
2253 mask_p
[cur_vit_mask
/ 100] = mask_amt
;
2255 cur_vit_mask
-= 100;
2258 tmp_mask
= (mask_m
[46] << 30) | (mask_m
[47] << 28)
2259 | (mask_m
[48] << 26) | (mask_m
[49] << 24)
2260 | (mask_m
[50] << 22) | (mask_m
[51] << 20)
2261 | (mask_m
[52] << 18) | (mask_m
[53] << 16)
2262 | (mask_m
[54] << 14) | (mask_m
[55] << 12)
2263 | (mask_m
[56] << 10) | (mask_m
[57] << 8)
2264 | (mask_m
[58] << 6) | (mask_m
[59] << 4)
2265 | (mask_m
[60] << 2) | (mask_m
[61] << 0);
2266 REG_WRITE(ah
, AR_PHY_BIN_MASK_1
, tmp_mask
);
2267 REG_WRITE(ah
, AR_PHY_VIT_MASK2_M_46_61
, tmp_mask
);
2269 tmp_mask
= (mask_m
[31] << 28)
2270 | (mask_m
[32] << 26) | (mask_m
[33] << 24)
2271 | (mask_m
[34] << 22) | (mask_m
[35] << 20)
2272 | (mask_m
[36] << 18) | (mask_m
[37] << 16)
2273 | (mask_m
[48] << 14) | (mask_m
[39] << 12)
2274 | (mask_m
[40] << 10) | (mask_m
[41] << 8)
2275 | (mask_m
[42] << 6) | (mask_m
[43] << 4)
2276 | (mask_m
[44] << 2) | (mask_m
[45] << 0);
2277 REG_WRITE(ah
, AR_PHY_BIN_MASK_2
, tmp_mask
);
2278 REG_WRITE(ah
, AR_PHY_MASK2_M_31_45
, tmp_mask
);
2280 tmp_mask
= (mask_m
[16] << 30) | (mask_m
[16] << 28)
2281 | (mask_m
[18] << 26) | (mask_m
[18] << 24)
2282 | (mask_m
[20] << 22) | (mask_m
[20] << 20)
2283 | (mask_m
[22] << 18) | (mask_m
[22] << 16)
2284 | (mask_m
[24] << 14) | (mask_m
[24] << 12)
2285 | (mask_m
[25] << 10) | (mask_m
[26] << 8)
2286 | (mask_m
[27] << 6) | (mask_m
[28] << 4)
2287 | (mask_m
[29] << 2) | (mask_m
[30] << 0);
2288 REG_WRITE(ah
, AR_PHY_BIN_MASK_3
, tmp_mask
);
2289 REG_WRITE(ah
, AR_PHY_MASK2_M_16_30
, tmp_mask
);
2291 tmp_mask
= (mask_m
[0] << 30) | (mask_m
[1] << 28)
2292 | (mask_m
[2] << 26) | (mask_m
[3] << 24)
2293 | (mask_m
[4] << 22) | (mask_m
[5] << 20)
2294 | (mask_m
[6] << 18) | (mask_m
[7] << 16)
2295 | (mask_m
[8] << 14) | (mask_m
[9] << 12)
2296 | (mask_m
[10] << 10) | (mask_m
[11] << 8)
2297 | (mask_m
[12] << 6) | (mask_m
[13] << 4)
2298 | (mask_m
[14] << 2) | (mask_m
[15] << 0);
2299 REG_WRITE(ah
, AR_PHY_MASK_CTL
, tmp_mask
);
2300 REG_WRITE(ah
, AR_PHY_MASK2_M_00_15
, tmp_mask
);
2302 tmp_mask
= (mask_p
[15] << 28)
2303 | (mask_p
[14] << 26) | (mask_p
[13] << 24)
2304 | (mask_p
[12] << 22) | (mask_p
[11] << 20)
2305 | (mask_p
[10] << 18) | (mask_p
[9] << 16)
2306 | (mask_p
[8] << 14) | (mask_p
[7] << 12)
2307 | (mask_p
[6] << 10) | (mask_p
[5] << 8)
2308 | (mask_p
[4] << 6) | (mask_p
[3] << 4)
2309 | (mask_p
[2] << 2) | (mask_p
[1] << 0);
2310 REG_WRITE(ah
, AR_PHY_BIN_MASK2_1
, tmp_mask
);
2311 REG_WRITE(ah
, AR_PHY_MASK2_P_15_01
, tmp_mask
);
2313 tmp_mask
= (mask_p
[30] << 28)
2314 | (mask_p
[29] << 26) | (mask_p
[28] << 24)
2315 | (mask_p
[27] << 22) | (mask_p
[26] << 20)
2316 | (mask_p
[25] << 18) | (mask_p
[24] << 16)
2317 | (mask_p
[23] << 14) | (mask_p
[22] << 12)
2318 | (mask_p
[21] << 10) | (mask_p
[20] << 8)
2319 | (mask_p
[19] << 6) | (mask_p
[18] << 4)
2320 | (mask_p
[17] << 2) | (mask_p
[16] << 0);
2321 REG_WRITE(ah
, AR_PHY_BIN_MASK2_2
, tmp_mask
);
2322 REG_WRITE(ah
, AR_PHY_MASK2_P_30_16
, tmp_mask
);
2324 tmp_mask
= (mask_p
[45] << 28)
2325 | (mask_p
[44] << 26) | (mask_p
[43] << 24)
2326 | (mask_p
[42] << 22) | (mask_p
[41] << 20)
2327 | (mask_p
[40] << 18) | (mask_p
[39] << 16)
2328 | (mask_p
[38] << 14) | (mask_p
[37] << 12)
2329 | (mask_p
[36] << 10) | (mask_p
[35] << 8)
2330 | (mask_p
[34] << 6) | (mask_p
[33] << 4)
2331 | (mask_p
[32] << 2) | (mask_p
[31] << 0);
2332 REG_WRITE(ah
, AR_PHY_BIN_MASK2_3
, tmp_mask
);
2333 REG_WRITE(ah
, AR_PHY_MASK2_P_45_31
, tmp_mask
);
2335 tmp_mask
= (mask_p
[61] << 30) | (mask_p
[60] << 28)
2336 | (mask_p
[59] << 26) | (mask_p
[58] << 24)
2337 | (mask_p
[57] << 22) | (mask_p
[56] << 20)
2338 | (mask_p
[55] << 18) | (mask_p
[54] << 16)
2339 | (mask_p
[53] << 14) | (mask_p
[52] << 12)
2340 | (mask_p
[51] << 10) | (mask_p
[50] << 8)
2341 | (mask_p
[49] << 6) | (mask_p
[48] << 4)
2342 | (mask_p
[47] << 2) | (mask_p
[46] << 0);
2343 REG_WRITE(ah
, AR_PHY_BIN_MASK2_4
, tmp_mask
);
2344 REG_WRITE(ah
, AR_PHY_MASK2_P_61_45
, tmp_mask
);
2347 static void ath9k_enable_rfkill(struct ath_hw
*ah
)
2349 REG_SET_BIT(ah
, AR_GPIO_INPUT_EN_VAL
,
2350 AR_GPIO_INPUT_EN_VAL_RFSILENT_BB
);
2352 REG_CLR_BIT(ah
, AR_GPIO_INPUT_MUX2
,
2353 AR_GPIO_INPUT_MUX2_RFSILENT
);
2355 ath9k_hw_cfg_gpio_input(ah
, ah
->rfkill_gpio
);
2356 REG_SET_BIT(ah
, AR_PHY_TEST
, RFSILENT_BB
);
2359 int ath9k_hw_reset(struct ath_hw
*ah
, struct ath9k_channel
*chan
,
2360 bool bChannelChange
)
2362 struct ath_common
*common
= ath9k_hw_common(ah
);
2364 struct ath9k_channel
*curchan
= ah
->curchan
;
2368 int i
, rx_chainmask
, r
;
2370 ah
->txchainmask
= common
->tx_chainmask
;
2371 ah
->rxchainmask
= common
->rx_chainmask
;
2373 if (!ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
))
2376 if (curchan
&& !ah
->chip_fullsleep
)
2377 ath9k_hw_getnf(ah
, curchan
);
2379 if (bChannelChange
&&
2380 (ah
->chip_fullsleep
!= true) &&
2381 (ah
->curchan
!= NULL
) &&
2382 (chan
->channel
!= ah
->curchan
->channel
) &&
2383 ((chan
->channelFlags
& CHANNEL_ALL
) ==
2384 (ah
->curchan
->channelFlags
& CHANNEL_ALL
)) &&
2385 !(AR_SREV_9280(ah
) || IS_CHAN_A_5MHZ_SPACED(chan
) ||
2386 IS_CHAN_A_5MHZ_SPACED(ah
->curchan
))) {
2388 if (ath9k_hw_channel_change(ah
, chan
)) {
2389 ath9k_hw_loadnf(ah
, ah
->curchan
);
2390 ath9k_hw_start_nfcal(ah
);
2395 saveDefAntenna
= REG_READ(ah
, AR_DEF_ANTENNA
);
2396 if (saveDefAntenna
== 0)
2399 macStaId1
= REG_READ(ah
, AR_STA_ID1
) & AR_STA_ID1_BASE_RATE_11B
;
2401 /* For chips on which RTC reset is done, save TSF before it gets cleared */
2402 if (AR_SREV_9280(ah
) && ah
->eep_ops
->get_eeprom(ah
, EEP_OL_PWRCTRL
))
2403 tsf
= ath9k_hw_gettsf64(ah
);
2405 saveLedState
= REG_READ(ah
, AR_CFG_LED
) &
2406 (AR_CFG_LED_ASSOC_CTL
| AR_CFG_LED_MODE_SEL
|
2407 AR_CFG_LED_BLINK_THRESH_SEL
| AR_CFG_LED_BLINK_SLOW
);
2409 ath9k_hw_mark_phy_inactive(ah
);
2411 if (AR_SREV_9271(ah
) && ah
->htc_reset_init
) {
2413 AR9271_RESET_POWER_DOWN_CONTROL
,
2414 AR9271_RADIO_RF_RST
);
2418 if (!ath9k_hw_chip_reset(ah
, chan
)) {
2419 ath_print(common
, ATH_DBG_FATAL
, "Chip reset failed\n");
2423 if (AR_SREV_9271(ah
) && ah
->htc_reset_init
) {
2424 ah
->htc_reset_init
= false;
2426 AR9271_RESET_POWER_DOWN_CONTROL
,
2427 AR9271_GATE_MAC_CTL
);
2432 if (tsf
&& AR_SREV_9280(ah
) && ah
->eep_ops
->get_eeprom(ah
, EEP_OL_PWRCTRL
))
2433 ath9k_hw_settsf64(ah
, tsf
);
2435 if (AR_SREV_9280_10_OR_LATER(ah
))
2436 REG_SET_BIT(ah
, AR_GPIO_INPUT_EN_VAL
, AR_GPIO_JTAG_DISABLE
);
2438 if (AR_SREV_9287_12_OR_LATER(ah
)) {
2439 /* Enable ASYNC FIFO */
2440 REG_SET_BIT(ah
, AR_MAC_PCU_ASYNC_FIFO_REG3
,
2441 AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL
);
2442 REG_SET_BIT(ah
, AR_PHY_MODE
, AR_PHY_MODE_ASYNCFIFO
);
2443 REG_CLR_BIT(ah
, AR_MAC_PCU_ASYNC_FIFO_REG3
,
2444 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET
);
2445 REG_SET_BIT(ah
, AR_MAC_PCU_ASYNC_FIFO_REG3
,
2446 AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET
);
2448 r
= ath9k_hw_process_ini(ah
, chan
);
2452 /* Setup MFP options for CCMP */
2453 if (AR_SREV_9280_20_OR_LATER(ah
)) {
2454 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
2455 * frames when constructing CCMP AAD. */
2456 REG_RMW_FIELD(ah
, AR_AES_MUTE_MASK1
, AR_AES_MUTE_MASK1_FC_MGMT
,
2458 ah
->sw_mgmt_crypto
= false;
2459 } else if (AR_SREV_9160_10_OR_LATER(ah
)) {
2460 /* Disable hardware crypto for management frames */
2461 REG_CLR_BIT(ah
, AR_PCU_MISC_MODE2
,
2462 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE
);
2463 REG_SET_BIT(ah
, AR_PCU_MISC_MODE2
,
2464 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT
);
2465 ah
->sw_mgmt_crypto
= true;
2467 ah
->sw_mgmt_crypto
= true;
2469 if (IS_CHAN_OFDM(chan
) || IS_CHAN_HT(chan
))
2470 ath9k_hw_set_delta_slope(ah
, chan
);
2472 if (AR_SREV_9280_10_OR_LATER(ah
))
2473 ath9k_hw_9280_spur_mitigate(ah
, chan
);
2475 ath9k_hw_spur_mitigate(ah
, chan
);
2477 ah
->eep_ops
->set_board_values(ah
, chan
);
2479 ath9k_hw_decrease_chain_power(ah
, chan
);
2481 REG_WRITE(ah
, AR_STA_ID0
, get_unaligned_le32(common
->macaddr
));
2482 REG_WRITE(ah
, AR_STA_ID1
, get_unaligned_le16(common
->macaddr
+ 4)
2484 | AR_STA_ID1_RTS_USE_DEF
2486 ack_6mb
? AR_STA_ID1_ACKCTS_6MB
: 0)
2487 | ah
->sta_id1_defaults
);
2488 ath9k_hw_set_operating_mode(ah
, ah
->opmode
);
2490 ath_hw_setbssidmask(common
);
2492 REG_WRITE(ah
, AR_DEF_ANTENNA
, saveDefAntenna
);
2494 ath9k_hw_write_associd(ah
);
2496 REG_WRITE(ah
, AR_ISR
, ~0);
2498 REG_WRITE(ah
, AR_RSSI_THR
, INIT_RSSI_THR
);
2500 if (AR_SREV_9280_10_OR_LATER(ah
))
2501 ath9k_hw_ar9280_set_channel(ah
, chan
);
2503 if (!(ath9k_hw_set_channel(ah
, chan
)))
2506 for (i
= 0; i
< AR_NUM_DCU
; i
++)
2507 REG_WRITE(ah
, AR_DQCUMASK(i
), 1 << i
);
2510 for (i
= 0; i
< ah
->caps
.total_queues
; i
++)
2511 ath9k_hw_resettxqueue(ah
, i
);
2513 ath9k_hw_init_interrupt_masks(ah
, ah
->opmode
);
2514 ath9k_hw_init_qos(ah
);
2516 if (ah
->caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
2517 ath9k_enable_rfkill(ah
);
2519 ath9k_hw_init_user_settings(ah
);
2521 if (AR_SREV_9287_12_OR_LATER(ah
)) {
2522 REG_WRITE(ah
, AR_D_GBL_IFS_SIFS
,
2523 AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR
);
2524 REG_WRITE(ah
, AR_D_GBL_IFS_SLOT
,
2525 AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR
);
2526 REG_WRITE(ah
, AR_D_GBL_IFS_EIFS
,
2527 AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR
);
2529 REG_WRITE(ah
, AR_TIME_OUT
, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR
);
2530 REG_WRITE(ah
, AR_USEC
, AR_USEC_ASYNC_FIFO_DUR
);
2532 REG_SET_BIT(ah
, AR_MAC_PCU_LOGIC_ANALYZER
,
2533 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768
);
2534 REG_RMW_FIELD(ah
, AR_AHB_MODE
, AR_AHB_CUSTOM_BURST_EN
,
2535 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL
);
2537 if (AR_SREV_9287_12_OR_LATER(ah
)) {
2538 REG_SET_BIT(ah
, AR_PCU_MISC_MODE2
,
2539 AR_PCU_MISC_MODE2_ENABLE_AGGWEP
);
2542 REG_WRITE(ah
, AR_STA_ID1
,
2543 REG_READ(ah
, AR_STA_ID1
) | AR_STA_ID1_PRESERVE_SEQNUM
);
2545 ath9k_hw_set_dma(ah
);
2547 REG_WRITE(ah
, AR_OBS
, 8);
2549 if (ah
->config
.intr_mitigation
) {
2550 REG_RMW_FIELD(ah
, AR_RIMT
, AR_RIMT_LAST
, 500);
2551 REG_RMW_FIELD(ah
, AR_RIMT
, AR_RIMT_FIRST
, 2000);
2554 ath9k_hw_init_bb(ah
, chan
);
2556 if (!ath9k_hw_init_cal(ah
, chan
))
2559 rx_chainmask
= ah
->rxchainmask
;
2560 if ((rx_chainmask
== 0x5) || (rx_chainmask
== 0x3)) {
2561 REG_WRITE(ah
, AR_PHY_RX_CHAINMASK
, rx_chainmask
);
2562 REG_WRITE(ah
, AR_PHY_CAL_CHAINMASK
, rx_chainmask
);
2565 REG_WRITE(ah
, AR_CFG_LED
, saveLedState
| AR_CFG_SCLK_32KHZ
);
2568 * For big endian systems turn on swapping for descriptors
2570 if (AR_SREV_9100(ah
)) {
2572 mask
= REG_READ(ah
, AR_CFG
);
2573 if (mask
& (AR_CFG_SWRB
| AR_CFG_SWTB
| AR_CFG_SWRG
)) {
2574 ath_print(common
, ATH_DBG_RESET
,
2575 "CFG Byte Swap Set 0x%x\n", mask
);
2578 INIT_CONFIG_STATUS
| AR_CFG_SWRB
| AR_CFG_SWTB
;
2579 REG_WRITE(ah
, AR_CFG
, mask
);
2580 ath_print(common
, ATH_DBG_RESET
,
2581 "Setting CFG 0x%x\n", REG_READ(ah
, AR_CFG
));
2584 /* Configure AR9271 target WLAN */
2585 if (AR_SREV_9271(ah
))
2586 REG_WRITE(ah
, AR_CFG
, AR_CFG_SWRB
| AR_CFG_SWTB
);
2589 REG_WRITE(ah
, AR_CFG
, AR_CFG_SWTD
| AR_CFG_SWRD
);
2593 if (ah
->btcoex_hw
.enabled
)
2594 ath9k_hw_btcoex_enable(ah
);
2598 EXPORT_SYMBOL(ath9k_hw_reset
);
2600 /************************/
2601 /* Key Cache Management */
2602 /************************/
2604 bool ath9k_hw_keyreset(struct ath_hw
*ah
, u16 entry
)
2608 if (entry
>= ah
->caps
.keycache_size
) {
2609 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
2610 "keychache entry %u out of range\n", entry
);
2614 keyType
= REG_READ(ah
, AR_KEYTABLE_TYPE(entry
));
2616 REG_WRITE(ah
, AR_KEYTABLE_KEY0(entry
), 0);
2617 REG_WRITE(ah
, AR_KEYTABLE_KEY1(entry
), 0);
2618 REG_WRITE(ah
, AR_KEYTABLE_KEY2(entry
), 0);
2619 REG_WRITE(ah
, AR_KEYTABLE_KEY3(entry
), 0);
2620 REG_WRITE(ah
, AR_KEYTABLE_KEY4(entry
), 0);
2621 REG_WRITE(ah
, AR_KEYTABLE_TYPE(entry
), AR_KEYTABLE_TYPE_CLR
);
2622 REG_WRITE(ah
, AR_KEYTABLE_MAC0(entry
), 0);
2623 REG_WRITE(ah
, AR_KEYTABLE_MAC1(entry
), 0);
2625 if (keyType
== AR_KEYTABLE_TYPE_TKIP
&& ATH9K_IS_MIC_ENABLED(ah
)) {
2626 u16 micentry
= entry
+ 64;
2628 REG_WRITE(ah
, AR_KEYTABLE_KEY0(micentry
), 0);
2629 REG_WRITE(ah
, AR_KEYTABLE_KEY1(micentry
), 0);
2630 REG_WRITE(ah
, AR_KEYTABLE_KEY2(micentry
), 0);
2631 REG_WRITE(ah
, AR_KEYTABLE_KEY3(micentry
), 0);
2637 EXPORT_SYMBOL(ath9k_hw_keyreset
);
2639 bool ath9k_hw_keysetmac(struct ath_hw
*ah
, u16 entry
, const u8
*mac
)
2643 if (entry
>= ah
->caps
.keycache_size
) {
2644 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
2645 "keychache entry %u out of range\n", entry
);
2650 macHi
= (mac
[5] << 8) | mac
[4];
2651 macLo
= (mac
[3] << 24) |
2656 macLo
|= (macHi
& 1) << 31;
2661 REG_WRITE(ah
, AR_KEYTABLE_MAC0(entry
), macLo
);
2662 REG_WRITE(ah
, AR_KEYTABLE_MAC1(entry
), macHi
| AR_KEYTABLE_VALID
);
2666 EXPORT_SYMBOL(ath9k_hw_keysetmac
);
2668 bool ath9k_hw_set_keycache_entry(struct ath_hw
*ah
, u16 entry
,
2669 const struct ath9k_keyval
*k
,
2672 const struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
2673 struct ath_common
*common
= ath9k_hw_common(ah
);
2674 u32 key0
, key1
, key2
, key3
, key4
;
2677 if (entry
>= pCap
->keycache_size
) {
2678 ath_print(common
, ATH_DBG_FATAL
,
2679 "keycache entry %u out of range\n", entry
);
2683 switch (k
->kv_type
) {
2684 case ATH9K_CIPHER_AES_OCB
:
2685 keyType
= AR_KEYTABLE_TYPE_AES
;
2687 case ATH9K_CIPHER_AES_CCM
:
2688 if (!(pCap
->hw_caps
& ATH9K_HW_CAP_CIPHER_AESCCM
)) {
2689 ath_print(common
, ATH_DBG_ANY
,
2690 "AES-CCM not supported by mac rev 0x%x\n",
2691 ah
->hw_version
.macRev
);
2694 keyType
= AR_KEYTABLE_TYPE_CCM
;
2696 case ATH9K_CIPHER_TKIP
:
2697 keyType
= AR_KEYTABLE_TYPE_TKIP
;
2698 if (ATH9K_IS_MIC_ENABLED(ah
)
2699 && entry
+ 64 >= pCap
->keycache_size
) {
2700 ath_print(common
, ATH_DBG_ANY
,
2701 "entry %u inappropriate for TKIP\n", entry
);
2705 case ATH9K_CIPHER_WEP
:
2706 if (k
->kv_len
< WLAN_KEY_LEN_WEP40
) {
2707 ath_print(common
, ATH_DBG_ANY
,
2708 "WEP key length %u too small\n", k
->kv_len
);
2711 if (k
->kv_len
<= WLAN_KEY_LEN_WEP40
)
2712 keyType
= AR_KEYTABLE_TYPE_40
;
2713 else if (k
->kv_len
<= WLAN_KEY_LEN_WEP104
)
2714 keyType
= AR_KEYTABLE_TYPE_104
;
2716 keyType
= AR_KEYTABLE_TYPE_128
;
2718 case ATH9K_CIPHER_CLR
:
2719 keyType
= AR_KEYTABLE_TYPE_CLR
;
2722 ath_print(common
, ATH_DBG_FATAL
,
2723 "cipher %u not supported\n", k
->kv_type
);
2727 key0
= get_unaligned_le32(k
->kv_val
+ 0);
2728 key1
= get_unaligned_le16(k
->kv_val
+ 4);
2729 key2
= get_unaligned_le32(k
->kv_val
+ 6);
2730 key3
= get_unaligned_le16(k
->kv_val
+ 10);
2731 key4
= get_unaligned_le32(k
->kv_val
+ 12);
2732 if (k
->kv_len
<= WLAN_KEY_LEN_WEP104
)
2736 * Note: Key cache registers access special memory area that requires
2737 * two 32-bit writes to actually update the values in the internal
2738 * memory. Consequently, the exact order and pairs used here must be
2742 if (keyType
== AR_KEYTABLE_TYPE_TKIP
&& ATH9K_IS_MIC_ENABLED(ah
)) {
2743 u16 micentry
= entry
+ 64;
2746 * Write inverted key[47:0] first to avoid Michael MIC errors
2747 * on frames that could be sent or received at the same time.
2748 * The correct key will be written in the end once everything
2751 REG_WRITE(ah
, AR_KEYTABLE_KEY0(entry
), ~key0
);
2752 REG_WRITE(ah
, AR_KEYTABLE_KEY1(entry
), ~key1
);
2754 /* Write key[95:48] */
2755 REG_WRITE(ah
, AR_KEYTABLE_KEY2(entry
), key2
);
2756 REG_WRITE(ah
, AR_KEYTABLE_KEY3(entry
), key3
);
2758 /* Write key[127:96] and key type */
2759 REG_WRITE(ah
, AR_KEYTABLE_KEY4(entry
), key4
);
2760 REG_WRITE(ah
, AR_KEYTABLE_TYPE(entry
), keyType
);
2762 /* Write MAC address for the entry */
2763 (void) ath9k_hw_keysetmac(ah
, entry
, mac
);
2765 if (ah
->misc_mode
& AR_PCU_MIC_NEW_LOC_ENA
) {
2767 * TKIP uses two key cache entries:
2768 * Michael MIC TX/RX keys in the same key cache entry
2769 * (idx = main index + 64):
2770 * key0 [31:0] = RX key [31:0]
2771 * key1 [15:0] = TX key [31:16]
2772 * key1 [31:16] = reserved
2773 * key2 [31:0] = RX key [63:32]
2774 * key3 [15:0] = TX key [15:0]
2775 * key3 [31:16] = reserved
2776 * key4 [31:0] = TX key [63:32]
2778 u32 mic0
, mic1
, mic2
, mic3
, mic4
;
2780 mic0
= get_unaligned_le32(k
->kv_mic
+ 0);
2781 mic2
= get_unaligned_le32(k
->kv_mic
+ 4);
2782 mic1
= get_unaligned_le16(k
->kv_txmic
+ 2) & 0xffff;
2783 mic3
= get_unaligned_le16(k
->kv_txmic
+ 0) & 0xffff;
2784 mic4
= get_unaligned_le32(k
->kv_txmic
+ 4);
2786 /* Write RX[31:0] and TX[31:16] */
2787 REG_WRITE(ah
, AR_KEYTABLE_KEY0(micentry
), mic0
);
2788 REG_WRITE(ah
, AR_KEYTABLE_KEY1(micentry
), mic1
);
2790 /* Write RX[63:32] and TX[15:0] */
2791 REG_WRITE(ah
, AR_KEYTABLE_KEY2(micentry
), mic2
);
2792 REG_WRITE(ah
, AR_KEYTABLE_KEY3(micentry
), mic3
);
2794 /* Write TX[63:32] and keyType(reserved) */
2795 REG_WRITE(ah
, AR_KEYTABLE_KEY4(micentry
), mic4
);
2796 REG_WRITE(ah
, AR_KEYTABLE_TYPE(micentry
),
2797 AR_KEYTABLE_TYPE_CLR
);
2801 * TKIP uses four key cache entries (two for group
2803 * Michael MIC TX/RX keys are in different key cache
2804 * entries (idx = main index + 64 for TX and
2805 * main index + 32 + 96 for RX):
2806 * key0 [31:0] = TX/RX MIC key [31:0]
2807 * key1 [31:0] = reserved
2808 * key2 [31:0] = TX/RX MIC key [63:32]
2809 * key3 [31:0] = reserved
2810 * key4 [31:0] = reserved
2812 * Upper layer code will call this function separately
2813 * for TX and RX keys when these registers offsets are
2818 mic0
= get_unaligned_le32(k
->kv_mic
+ 0);
2819 mic2
= get_unaligned_le32(k
->kv_mic
+ 4);
2821 /* Write MIC key[31:0] */
2822 REG_WRITE(ah
, AR_KEYTABLE_KEY0(micentry
), mic0
);
2823 REG_WRITE(ah
, AR_KEYTABLE_KEY1(micentry
), 0);
2825 /* Write MIC key[63:32] */
2826 REG_WRITE(ah
, AR_KEYTABLE_KEY2(micentry
), mic2
);
2827 REG_WRITE(ah
, AR_KEYTABLE_KEY3(micentry
), 0);
2829 /* Write TX[63:32] and keyType(reserved) */
2830 REG_WRITE(ah
, AR_KEYTABLE_KEY4(micentry
), 0);
2831 REG_WRITE(ah
, AR_KEYTABLE_TYPE(micentry
),
2832 AR_KEYTABLE_TYPE_CLR
);
2835 /* MAC address registers are reserved for the MIC entry */
2836 REG_WRITE(ah
, AR_KEYTABLE_MAC0(micentry
), 0);
2837 REG_WRITE(ah
, AR_KEYTABLE_MAC1(micentry
), 0);
2840 * Write the correct (un-inverted) key[47:0] last to enable
2841 * TKIP now that all other registers are set with correct
2844 REG_WRITE(ah
, AR_KEYTABLE_KEY0(entry
), key0
);
2845 REG_WRITE(ah
, AR_KEYTABLE_KEY1(entry
), key1
);
2847 /* Write key[47:0] */
2848 REG_WRITE(ah
, AR_KEYTABLE_KEY0(entry
), key0
);
2849 REG_WRITE(ah
, AR_KEYTABLE_KEY1(entry
), key1
);
2851 /* Write key[95:48] */
2852 REG_WRITE(ah
, AR_KEYTABLE_KEY2(entry
), key2
);
2853 REG_WRITE(ah
, AR_KEYTABLE_KEY3(entry
), key3
);
2855 /* Write key[127:96] and key type */
2856 REG_WRITE(ah
, AR_KEYTABLE_KEY4(entry
), key4
);
2857 REG_WRITE(ah
, AR_KEYTABLE_TYPE(entry
), keyType
);
2859 /* Write MAC address for the entry */
2860 (void) ath9k_hw_keysetmac(ah
, entry
, mac
);
2865 EXPORT_SYMBOL(ath9k_hw_set_keycache_entry
);
2867 bool ath9k_hw_keyisvalid(struct ath_hw
*ah
, u16 entry
)
2869 if (entry
< ah
->caps
.keycache_size
) {
2870 u32 val
= REG_READ(ah
, AR_KEYTABLE_MAC1(entry
));
2871 if (val
& AR_KEYTABLE_VALID
)
2876 EXPORT_SYMBOL(ath9k_hw_keyisvalid
);
2878 /******************************/
2879 /* Power Management (Chipset) */
2880 /******************************/
2882 static void ath9k_set_power_sleep(struct ath_hw
*ah
, int setChip
)
2884 REG_SET_BIT(ah
, AR_STA_ID1
, AR_STA_ID1_PWR_SAV
);
2886 REG_CLR_BIT(ah
, AR_RTC_FORCE_WAKE
,
2887 AR_RTC_FORCE_WAKE_EN
);
2888 if (!AR_SREV_9100(ah
))
2889 REG_WRITE(ah
, AR_RC
, AR_RC_AHB
| AR_RC_HOSTIF
);
2891 if(!AR_SREV_5416(ah
))
2892 REG_CLR_BIT(ah
, (AR_RTC_RESET
),
2897 static void ath9k_set_power_network_sleep(struct ath_hw
*ah
, int setChip
)
2899 REG_SET_BIT(ah
, AR_STA_ID1
, AR_STA_ID1_PWR_SAV
);
2901 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
2903 if (!(pCap
->hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
2904 REG_WRITE(ah
, AR_RTC_FORCE_WAKE
,
2905 AR_RTC_FORCE_WAKE_ON_INT
);
2907 REG_CLR_BIT(ah
, AR_RTC_FORCE_WAKE
,
2908 AR_RTC_FORCE_WAKE_EN
);
2913 static bool ath9k_hw_set_power_awake(struct ath_hw
*ah
, int setChip
)
2919 if ((REG_READ(ah
, AR_RTC_STATUS
) &
2920 AR_RTC_STATUS_M
) == AR_RTC_STATUS_SHUTDOWN
) {
2921 if (ath9k_hw_set_reset_reg(ah
,
2922 ATH9K_RESET_POWER_ON
) != true) {
2925 ath9k_hw_init_pll(ah
, NULL
);
2927 if (AR_SREV_9100(ah
))
2928 REG_SET_BIT(ah
, AR_RTC_RESET
,
2931 REG_SET_BIT(ah
, AR_RTC_FORCE_WAKE
,
2932 AR_RTC_FORCE_WAKE_EN
);
2935 for (i
= POWER_UP_TIME
/ 50; i
> 0; i
--) {
2936 val
= REG_READ(ah
, AR_RTC_STATUS
) & AR_RTC_STATUS_M
;
2937 if (val
== AR_RTC_STATUS_ON
)
2940 REG_SET_BIT(ah
, AR_RTC_FORCE_WAKE
,
2941 AR_RTC_FORCE_WAKE_EN
);
2944 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
2945 "Failed to wakeup in %uus\n",
2946 POWER_UP_TIME
/ 20);
2951 REG_CLR_BIT(ah
, AR_STA_ID1
, AR_STA_ID1_PWR_SAV
);
2956 bool ath9k_hw_setpower(struct ath_hw
*ah
, enum ath9k_power_mode mode
)
2958 struct ath_common
*common
= ath9k_hw_common(ah
);
2959 int status
= true, setChip
= true;
2960 static const char *modes
[] = {
2967 if (ah
->power_mode
== mode
)
2970 ath_print(common
, ATH_DBG_RESET
, "%s -> %s\n",
2971 modes
[ah
->power_mode
], modes
[mode
]);
2974 case ATH9K_PM_AWAKE
:
2975 status
= ath9k_hw_set_power_awake(ah
, setChip
);
2977 case ATH9K_PM_FULL_SLEEP
:
2978 ath9k_set_power_sleep(ah
, setChip
);
2979 ah
->chip_fullsleep
= true;
2981 case ATH9K_PM_NETWORK_SLEEP
:
2982 ath9k_set_power_network_sleep(ah
, setChip
);
2985 ath_print(common
, ATH_DBG_FATAL
,
2986 "Unknown power mode %u\n", mode
);
2989 ah
->power_mode
= mode
;
2993 EXPORT_SYMBOL(ath9k_hw_setpower
);
2996 * Helper for ASPM support.
2998 * Disable PLL when in L0s as well as receiver clock when in L1.
2999 * This power saving option must be enabled through the SerDes.
3001 * Programming the SerDes must go through the same 288 bit serial shift
3002 * register as the other analog registers. Hence the 9 writes.
3004 void ath9k_hw_configpcipowersave(struct ath_hw
*ah
, int restore
, int power_off
)
3009 if (ah
->is_pciexpress
!= true)
3012 /* Do not touch SerDes registers */
3013 if (ah
->config
.pcie_powersave_enable
== 2)
3016 /* Nothing to do on restore for 11N */
3018 if (AR_SREV_9280_20_OR_LATER(ah
)) {
3020 * AR9280 2.0 or later chips use SerDes values from the
3021 * initvals.h initialized depending on chipset during
3024 for (i
= 0; i
< ah
->iniPcieSerdes
.ia_rows
; i
++) {
3025 REG_WRITE(ah
, INI_RA(&ah
->iniPcieSerdes
, i
, 0),
3026 INI_RA(&ah
->iniPcieSerdes
, i
, 1));
3028 } else if (AR_SREV_9280(ah
) &&
3029 (ah
->hw_version
.macRev
== AR_SREV_REVISION_9280_10
)) {
3030 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x9248fd00);
3031 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x24924924);
3033 /* RX shut off when elecidle is asserted */
3034 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xa8000019);
3035 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x13160820);
3036 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xe5980560);
3038 /* Shut off CLKREQ active in L1 */
3039 if (ah
->config
.pcie_clock_req
)
3040 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x401deffc);
3042 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x401deffd);
3044 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x1aaabe40);
3045 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xbe105554);
3046 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x00043007);
3048 /* Load the new settings */
3049 REG_WRITE(ah
, AR_PCIE_SERDES2
, 0x00000000);
3052 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x9248fc00);
3053 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x24924924);
3055 /* RX shut off when elecidle is asserted */
3056 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x28000039);
3057 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x53160824);
3058 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xe5980579);
3061 * Ignore ah->ah_config.pcie_clock_req setting for
3064 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x001defff);
3066 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x1aaabe40);
3067 REG_WRITE(ah
, AR_PCIE_SERDES
, 0xbe105554);
3068 REG_WRITE(ah
, AR_PCIE_SERDES
, 0x000e3007);
3070 /* Load the new settings */
3071 REG_WRITE(ah
, AR_PCIE_SERDES2
, 0x00000000);
3076 /* set bit 19 to allow forcing of pcie core into L1 state */
3077 REG_SET_BIT(ah
, AR_PCIE_PM_CTRL
, AR_PCIE_PM_CTRL_ENA
);
3079 /* Several PCIe massages to ensure proper behaviour */
3080 if (ah
->config
.pcie_waen
) {
3081 val
= ah
->config
.pcie_waen
;
3083 val
&= (~AR_WA_D3_L1_DISABLE
);
3085 if (AR_SREV_9285(ah
) || AR_SREV_9271(ah
) ||
3087 val
= AR9285_WA_DEFAULT
;
3089 val
&= (~AR_WA_D3_L1_DISABLE
);
3090 } else if (AR_SREV_9280(ah
)) {
3092 * On AR9280 chips bit 22 of 0x4004 needs to be
3093 * set otherwise card may disappear.
3095 val
= AR9280_WA_DEFAULT
;
3097 val
&= (~AR_WA_D3_L1_DISABLE
);
3099 val
= AR_WA_DEFAULT
;
3102 REG_WRITE(ah
, AR_WA
, val
);
3107 * Set PCIe workaround bits
3108 * bit 14 in WA register (disable L1) should only
3109 * be set when device enters D3 and be cleared
3110 * when device comes back to D0.
3112 if (ah
->config
.pcie_waen
) {
3113 if (ah
->config
.pcie_waen
& AR_WA_D3_L1_DISABLE
)
3114 REG_SET_BIT(ah
, AR_WA
, AR_WA_D3_L1_DISABLE
);
3116 if (((AR_SREV_9285(ah
) || AR_SREV_9271(ah
) ||
3117 AR_SREV_9287(ah
)) &&
3118 (AR9285_WA_DEFAULT
& AR_WA_D3_L1_DISABLE
)) ||
3119 (AR_SREV_9280(ah
) &&
3120 (AR9280_WA_DEFAULT
& AR_WA_D3_L1_DISABLE
))) {
3121 REG_SET_BIT(ah
, AR_WA
, AR_WA_D3_L1_DISABLE
);
3126 EXPORT_SYMBOL(ath9k_hw_configpcipowersave
);
3128 /**********************/
3129 /* Interrupt Handling */
3130 /**********************/
3132 bool ath9k_hw_intrpend(struct ath_hw
*ah
)
3136 if (AR_SREV_9100(ah
))
3139 host_isr
= REG_READ(ah
, AR_INTR_ASYNC_CAUSE
);
3140 if ((host_isr
& AR_INTR_MAC_IRQ
) && (host_isr
!= AR_INTR_SPURIOUS
))
3143 host_isr
= REG_READ(ah
, AR_INTR_SYNC_CAUSE
);
3144 if ((host_isr
& AR_INTR_SYNC_DEFAULT
)
3145 && (host_isr
!= AR_INTR_SPURIOUS
))
3150 EXPORT_SYMBOL(ath9k_hw_intrpend
);
3152 bool ath9k_hw_getisr(struct ath_hw
*ah
, enum ath9k_int
*masked
)
3156 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
3158 bool fatal_int
= false;
3159 struct ath_common
*common
= ath9k_hw_common(ah
);
3161 if (!AR_SREV_9100(ah
)) {
3162 if (REG_READ(ah
, AR_INTR_ASYNC_CAUSE
) & AR_INTR_MAC_IRQ
) {
3163 if ((REG_READ(ah
, AR_RTC_STATUS
) & AR_RTC_STATUS_M
)
3164 == AR_RTC_STATUS_ON
) {
3165 isr
= REG_READ(ah
, AR_ISR
);
3169 sync_cause
= REG_READ(ah
, AR_INTR_SYNC_CAUSE
) &
3170 AR_INTR_SYNC_DEFAULT
;
3174 if (!isr
&& !sync_cause
)
3178 isr
= REG_READ(ah
, AR_ISR
);
3182 if (isr
& AR_ISR_BCNMISC
) {
3184 isr2
= REG_READ(ah
, AR_ISR_S2
);
3185 if (isr2
& AR_ISR_S2_TIM
)
3186 mask2
|= ATH9K_INT_TIM
;
3187 if (isr2
& AR_ISR_S2_DTIM
)
3188 mask2
|= ATH9K_INT_DTIM
;
3189 if (isr2
& AR_ISR_S2_DTIMSYNC
)
3190 mask2
|= ATH9K_INT_DTIMSYNC
;
3191 if (isr2
& (AR_ISR_S2_CABEND
))
3192 mask2
|= ATH9K_INT_CABEND
;
3193 if (isr2
& AR_ISR_S2_GTT
)
3194 mask2
|= ATH9K_INT_GTT
;
3195 if (isr2
& AR_ISR_S2_CST
)
3196 mask2
|= ATH9K_INT_CST
;
3197 if (isr2
& AR_ISR_S2_TSFOOR
)
3198 mask2
|= ATH9K_INT_TSFOOR
;
3201 isr
= REG_READ(ah
, AR_ISR_RAC
);
3202 if (isr
== 0xffffffff) {
3207 *masked
= isr
& ATH9K_INT_COMMON
;
3209 if (ah
->config
.intr_mitigation
) {
3210 if (isr
& (AR_ISR_RXMINTR
| AR_ISR_RXINTM
))
3211 *masked
|= ATH9K_INT_RX
;
3214 if (isr
& (AR_ISR_RXOK
| AR_ISR_RXERR
))
3215 *masked
|= ATH9K_INT_RX
;
3217 (AR_ISR_TXOK
| AR_ISR_TXDESC
| AR_ISR_TXERR
|
3221 *masked
|= ATH9K_INT_TX
;
3223 s0_s
= REG_READ(ah
, AR_ISR_S0_S
);
3224 ah
->intr_txqs
|= MS(s0_s
, AR_ISR_S0_QCU_TXOK
);
3225 ah
->intr_txqs
|= MS(s0_s
, AR_ISR_S0_QCU_TXDESC
);
3227 s1_s
= REG_READ(ah
, AR_ISR_S1_S
);
3228 ah
->intr_txqs
|= MS(s1_s
, AR_ISR_S1_QCU_TXERR
);
3229 ah
->intr_txqs
|= MS(s1_s
, AR_ISR_S1_QCU_TXEOL
);
3232 if (isr
& AR_ISR_RXORN
) {
3233 ath_print(common
, ATH_DBG_INTERRUPT
,
3234 "receive FIFO overrun interrupt\n");
3237 if (!AR_SREV_9100(ah
)) {
3238 if (!(pCap
->hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
3239 u32 isr5
= REG_READ(ah
, AR_ISR_S5_S
);
3240 if (isr5
& AR_ISR_S5_TIM_TIMER
)
3241 *masked
|= ATH9K_INT_TIM_TIMER
;
3248 if (AR_SREV_9100(ah
))
3251 if (isr
& AR_ISR_GENTMR
) {
3254 s5_s
= REG_READ(ah
, AR_ISR_S5_S
);
3255 if (isr
& AR_ISR_GENTMR
) {
3256 ah
->intr_gen_timer_trigger
=
3257 MS(s5_s
, AR_ISR_S5_GENTIMER_TRIG
);
3259 ah
->intr_gen_timer_thresh
=
3260 MS(s5_s
, AR_ISR_S5_GENTIMER_THRESH
);
3262 if (ah
->intr_gen_timer_trigger
)
3263 *masked
|= ATH9K_INT_GENTIMER
;
3271 (AR_INTR_SYNC_HOST1_FATAL
| AR_INTR_SYNC_HOST1_PERR
))
3275 if (sync_cause
& AR_INTR_SYNC_HOST1_FATAL
) {
3276 ath_print(common
, ATH_DBG_ANY
,
3277 "received PCI FATAL interrupt\n");
3279 if (sync_cause
& AR_INTR_SYNC_HOST1_PERR
) {
3280 ath_print(common
, ATH_DBG_ANY
,
3281 "received PCI PERR interrupt\n");
3283 *masked
|= ATH9K_INT_FATAL
;
3285 if (sync_cause
& AR_INTR_SYNC_RADM_CPL_TIMEOUT
) {
3286 ath_print(common
, ATH_DBG_INTERRUPT
,
3287 "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
3288 REG_WRITE(ah
, AR_RC
, AR_RC_HOSTIF
);
3289 REG_WRITE(ah
, AR_RC
, 0);
3290 *masked
|= ATH9K_INT_FATAL
;
3292 if (sync_cause
& AR_INTR_SYNC_LOCAL_TIMEOUT
) {
3293 ath_print(common
, ATH_DBG_INTERRUPT
,
3294 "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
3297 REG_WRITE(ah
, AR_INTR_SYNC_CAUSE_CLR
, sync_cause
);
3298 (void) REG_READ(ah
, AR_INTR_SYNC_CAUSE_CLR
);
3303 EXPORT_SYMBOL(ath9k_hw_getisr
);
3305 enum ath9k_int
ath9k_hw_set_interrupts(struct ath_hw
*ah
, enum ath9k_int ints
)
3307 u32 omask
= ah
->mask_reg
;
3309 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
3310 struct ath_common
*common
= ath9k_hw_common(ah
);
3312 ath_print(common
, ATH_DBG_INTERRUPT
, "0x%x => 0x%x\n", omask
, ints
);
3314 if (omask
& ATH9K_INT_GLOBAL
) {
3315 ath_print(common
, ATH_DBG_INTERRUPT
, "disable IER\n");
3316 REG_WRITE(ah
, AR_IER
, AR_IER_DISABLE
);
3317 (void) REG_READ(ah
, AR_IER
);
3318 if (!AR_SREV_9100(ah
)) {
3319 REG_WRITE(ah
, AR_INTR_ASYNC_ENABLE
, 0);
3320 (void) REG_READ(ah
, AR_INTR_ASYNC_ENABLE
);
3322 REG_WRITE(ah
, AR_INTR_SYNC_ENABLE
, 0);
3323 (void) REG_READ(ah
, AR_INTR_SYNC_ENABLE
);
3327 mask
= ints
& ATH9K_INT_COMMON
;
3330 if (ints
& ATH9K_INT_TX
) {
3331 if (ah
->txok_interrupt_mask
)
3332 mask
|= AR_IMR_TXOK
;
3333 if (ah
->txdesc_interrupt_mask
)
3334 mask
|= AR_IMR_TXDESC
;
3335 if (ah
->txerr_interrupt_mask
)
3336 mask
|= AR_IMR_TXERR
;
3337 if (ah
->txeol_interrupt_mask
)
3338 mask
|= AR_IMR_TXEOL
;
3340 if (ints
& ATH9K_INT_RX
) {
3341 mask
|= AR_IMR_RXERR
;
3342 if (ah
->config
.intr_mitigation
)
3343 mask
|= AR_IMR_RXMINTR
| AR_IMR_RXINTM
;
3345 mask
|= AR_IMR_RXOK
| AR_IMR_RXDESC
;
3346 if (!(pCap
->hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
))
3347 mask
|= AR_IMR_GENTMR
;
3350 if (ints
& (ATH9K_INT_BMISC
)) {
3351 mask
|= AR_IMR_BCNMISC
;
3352 if (ints
& ATH9K_INT_TIM
)
3353 mask2
|= AR_IMR_S2_TIM
;
3354 if (ints
& ATH9K_INT_DTIM
)
3355 mask2
|= AR_IMR_S2_DTIM
;
3356 if (ints
& ATH9K_INT_DTIMSYNC
)
3357 mask2
|= AR_IMR_S2_DTIMSYNC
;
3358 if (ints
& ATH9K_INT_CABEND
)
3359 mask2
|= AR_IMR_S2_CABEND
;
3360 if (ints
& ATH9K_INT_TSFOOR
)
3361 mask2
|= AR_IMR_S2_TSFOOR
;
3364 if (ints
& (ATH9K_INT_GTT
| ATH9K_INT_CST
)) {
3365 mask
|= AR_IMR_BCNMISC
;
3366 if (ints
& ATH9K_INT_GTT
)
3367 mask2
|= AR_IMR_S2_GTT
;
3368 if (ints
& ATH9K_INT_CST
)
3369 mask2
|= AR_IMR_S2_CST
;
3372 ath_print(common
, ATH_DBG_INTERRUPT
, "new IMR 0x%x\n", mask
);
3373 REG_WRITE(ah
, AR_IMR
, mask
);
3374 mask
= REG_READ(ah
, AR_IMR_S2
) & ~(AR_IMR_S2_TIM
|
3376 AR_IMR_S2_DTIMSYNC
|
3380 AR_IMR_S2_GTT
| AR_IMR_S2_CST
);
3381 REG_WRITE(ah
, AR_IMR_S2
, mask
| mask2
);
3382 ah
->mask_reg
= ints
;
3384 if (!(pCap
->hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)) {
3385 if (ints
& ATH9K_INT_TIM_TIMER
)
3386 REG_SET_BIT(ah
, AR_IMR_S5
, AR_IMR_S5_TIM_TIMER
);
3388 REG_CLR_BIT(ah
, AR_IMR_S5
, AR_IMR_S5_TIM_TIMER
);
3391 if (ints
& ATH9K_INT_GLOBAL
) {
3392 ath_print(common
, ATH_DBG_INTERRUPT
, "enable IER\n");
3393 REG_WRITE(ah
, AR_IER
, AR_IER_ENABLE
);
3394 if (!AR_SREV_9100(ah
)) {
3395 REG_WRITE(ah
, AR_INTR_ASYNC_ENABLE
,
3397 REG_WRITE(ah
, AR_INTR_ASYNC_MASK
, AR_INTR_MAC_IRQ
);
3400 REG_WRITE(ah
, AR_INTR_SYNC_ENABLE
,
3401 AR_INTR_SYNC_DEFAULT
);
3402 REG_WRITE(ah
, AR_INTR_SYNC_MASK
,
3403 AR_INTR_SYNC_DEFAULT
);
3405 ath_print(common
, ATH_DBG_INTERRUPT
, "AR_IMR 0x%x IER 0x%x\n",
3406 REG_READ(ah
, AR_IMR
), REG_READ(ah
, AR_IER
));
3411 EXPORT_SYMBOL(ath9k_hw_set_interrupts
);
3413 /*******************/
3414 /* Beacon Handling */
3415 /*******************/
3417 void ath9k_hw_beaconinit(struct ath_hw
*ah
, u32 next_beacon
, u32 beacon_period
)
3421 ah
->beacon_interval
= beacon_period
;
3423 switch (ah
->opmode
) {
3424 case NL80211_IFTYPE_STATION
:
3425 case NL80211_IFTYPE_MONITOR
:
3426 REG_WRITE(ah
, AR_NEXT_TBTT_TIMER
, TU_TO_USEC(next_beacon
));
3427 REG_WRITE(ah
, AR_NEXT_DMA_BEACON_ALERT
, 0xffff);
3428 REG_WRITE(ah
, AR_NEXT_SWBA
, 0x7ffff);
3429 flags
|= AR_TBTT_TIMER_EN
;
3431 case NL80211_IFTYPE_ADHOC
:
3432 case NL80211_IFTYPE_MESH_POINT
:
3433 REG_SET_BIT(ah
, AR_TXCFG
,
3434 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY
);
3435 REG_WRITE(ah
, AR_NEXT_NDP_TIMER
,
3436 TU_TO_USEC(next_beacon
+
3437 (ah
->atim_window
? ah
->
3439 flags
|= AR_NDP_TIMER_EN
;
3440 case NL80211_IFTYPE_AP
:
3441 REG_WRITE(ah
, AR_NEXT_TBTT_TIMER
, TU_TO_USEC(next_beacon
));
3442 REG_WRITE(ah
, AR_NEXT_DMA_BEACON_ALERT
,
3443 TU_TO_USEC(next_beacon
-
3445 dma_beacon_response_time
));
3446 REG_WRITE(ah
, AR_NEXT_SWBA
,
3447 TU_TO_USEC(next_beacon
-
3449 sw_beacon_response_time
));
3451 AR_TBTT_TIMER_EN
| AR_DBA_TIMER_EN
| AR_SWBA_TIMER_EN
;
3454 ath_print(ath9k_hw_common(ah
), ATH_DBG_BEACON
,
3455 "%s: unsupported opmode: %d\n",
3456 __func__
, ah
->opmode
);
3461 REG_WRITE(ah
, AR_BEACON_PERIOD
, TU_TO_USEC(beacon_period
));
3462 REG_WRITE(ah
, AR_DMA_BEACON_PERIOD
, TU_TO_USEC(beacon_period
));
3463 REG_WRITE(ah
, AR_SWBA_PERIOD
, TU_TO_USEC(beacon_period
));
3464 REG_WRITE(ah
, AR_NDP_PERIOD
, TU_TO_USEC(beacon_period
));
3466 beacon_period
&= ~ATH9K_BEACON_ENA
;
3467 if (beacon_period
& ATH9K_BEACON_RESET_TSF
) {
3468 ath9k_hw_reset_tsf(ah
);
3471 REG_SET_BIT(ah
, AR_TIMER_MODE
, flags
);
3473 EXPORT_SYMBOL(ath9k_hw_beaconinit
);
3475 void ath9k_hw_set_sta_beacon_timers(struct ath_hw
*ah
,
3476 const struct ath9k_beacon_state
*bs
)
3478 u32 nextTbtt
, beaconintval
, dtimperiod
, beacontimeout
;
3479 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
3480 struct ath_common
*common
= ath9k_hw_common(ah
);
3482 REG_WRITE(ah
, AR_NEXT_TBTT_TIMER
, TU_TO_USEC(bs
->bs_nexttbtt
));
3484 REG_WRITE(ah
, AR_BEACON_PERIOD
,
3485 TU_TO_USEC(bs
->bs_intval
& ATH9K_BEACON_PERIOD
));
3486 REG_WRITE(ah
, AR_DMA_BEACON_PERIOD
,
3487 TU_TO_USEC(bs
->bs_intval
& ATH9K_BEACON_PERIOD
));
3489 REG_RMW_FIELD(ah
, AR_RSSI_THR
,
3490 AR_RSSI_THR_BM_THR
, bs
->bs_bmissthreshold
);
3492 beaconintval
= bs
->bs_intval
& ATH9K_BEACON_PERIOD
;
3494 if (bs
->bs_sleepduration
> beaconintval
)
3495 beaconintval
= bs
->bs_sleepduration
;
3497 dtimperiod
= bs
->bs_dtimperiod
;
3498 if (bs
->bs_sleepduration
> dtimperiod
)
3499 dtimperiod
= bs
->bs_sleepduration
;
3501 if (beaconintval
== dtimperiod
)
3502 nextTbtt
= bs
->bs_nextdtim
;
3504 nextTbtt
= bs
->bs_nexttbtt
;
3506 ath_print(common
, ATH_DBG_BEACON
, "next DTIM %d\n", bs
->bs_nextdtim
);
3507 ath_print(common
, ATH_DBG_BEACON
, "next beacon %d\n", nextTbtt
);
3508 ath_print(common
, ATH_DBG_BEACON
, "beacon period %d\n", beaconintval
);
3509 ath_print(common
, ATH_DBG_BEACON
, "DTIM period %d\n", dtimperiod
);
3511 REG_WRITE(ah
, AR_NEXT_DTIM
,
3512 TU_TO_USEC(bs
->bs_nextdtim
- SLEEP_SLOP
));
3513 REG_WRITE(ah
, AR_NEXT_TIM
, TU_TO_USEC(nextTbtt
- SLEEP_SLOP
));
3515 REG_WRITE(ah
, AR_SLEEP1
,
3516 SM((CAB_TIMEOUT_VAL
<< 3), AR_SLEEP1_CAB_TIMEOUT
)
3517 | AR_SLEEP1_ASSUME_DTIM
);
3519 if (pCap
->hw_caps
& ATH9K_HW_CAP_AUTOSLEEP
)
3520 beacontimeout
= (BEACON_TIMEOUT_VAL
<< 3);
3522 beacontimeout
= MIN_BEACON_TIMEOUT_VAL
;
3524 REG_WRITE(ah
, AR_SLEEP2
,
3525 SM(beacontimeout
, AR_SLEEP2_BEACON_TIMEOUT
));
3527 REG_WRITE(ah
, AR_TIM_PERIOD
, TU_TO_USEC(beaconintval
));
3528 REG_WRITE(ah
, AR_DTIM_PERIOD
, TU_TO_USEC(dtimperiod
));
3530 REG_SET_BIT(ah
, AR_TIMER_MODE
,
3531 AR_TBTT_TIMER_EN
| AR_TIM_TIMER_EN
|
3534 /* TSF Out of Range Threshold */
3535 REG_WRITE(ah
, AR_TSFOOR_THRESHOLD
, bs
->bs_tsfoor_threshold
);
3537 EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers
);
3539 /*******************/
3540 /* HW Capabilities */
3541 /*******************/
3543 void ath9k_hw_fill_cap_info(struct ath_hw
*ah
)
3545 struct ath9k_hw_capabilities
*pCap
= &ah
->caps
;
3546 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
3547 struct ath_common
*common
= ath9k_hw_common(ah
);
3548 struct ath_btcoex_hw
*btcoex_hw
= &ah
->btcoex_hw
;
3550 u16 capField
= 0, eeval
;
3552 eeval
= ah
->eep_ops
->get_eeprom(ah
, EEP_REG_0
);
3553 regulatory
->current_rd
= eeval
;
3555 eeval
= ah
->eep_ops
->get_eeprom(ah
, EEP_REG_1
);
3556 if (AR_SREV_9285_10_OR_LATER(ah
))
3557 eeval
|= AR9285_RDEXT_DEFAULT
;
3558 regulatory
->current_rd_ext
= eeval
;
3560 capField
= ah
->eep_ops
->get_eeprom(ah
, EEP_OP_CAP
);
3562 if (ah
->opmode
!= NL80211_IFTYPE_AP
&&
3563 ah
->hw_version
.subvendorid
== AR_SUBVENDOR_ID_NEW_A
) {
3564 if (regulatory
->current_rd
== 0x64 ||
3565 regulatory
->current_rd
== 0x65)
3566 regulatory
->current_rd
+= 5;
3567 else if (regulatory
->current_rd
== 0x41)
3568 regulatory
->current_rd
= 0x43;
3569 ath_print(common
, ATH_DBG_REGULATORY
,
3570 "regdomain mapped to 0x%x\n", regulatory
->current_rd
);
3573 eeval
= ah
->eep_ops
->get_eeprom(ah
, EEP_OP_MODE
);
3574 bitmap_zero(pCap
->wireless_modes
, ATH9K_MODE_MAX
);
3576 if (eeval
& AR5416_OPFLAGS_11A
) {
3577 set_bit(ATH9K_MODE_11A
, pCap
->wireless_modes
);
3578 if (ah
->config
.ht_enable
) {
3579 if (!(eeval
& AR5416_OPFLAGS_N_5G_HT20
))
3580 set_bit(ATH9K_MODE_11NA_HT20
,
3581 pCap
->wireless_modes
);
3582 if (!(eeval
& AR5416_OPFLAGS_N_5G_HT40
)) {
3583 set_bit(ATH9K_MODE_11NA_HT40PLUS
,
3584 pCap
->wireless_modes
);
3585 set_bit(ATH9K_MODE_11NA_HT40MINUS
,
3586 pCap
->wireless_modes
);
3591 if (eeval
& AR5416_OPFLAGS_11G
) {
3592 set_bit(ATH9K_MODE_11G
, pCap
->wireless_modes
);
3593 if (ah
->config
.ht_enable
) {
3594 if (!(eeval
& AR5416_OPFLAGS_N_2G_HT20
))
3595 set_bit(ATH9K_MODE_11NG_HT20
,
3596 pCap
->wireless_modes
);
3597 if (!(eeval
& AR5416_OPFLAGS_N_2G_HT40
)) {
3598 set_bit(ATH9K_MODE_11NG_HT40PLUS
,
3599 pCap
->wireless_modes
);
3600 set_bit(ATH9K_MODE_11NG_HT40MINUS
,
3601 pCap
->wireless_modes
);
3606 pCap
->tx_chainmask
= ah
->eep_ops
->get_eeprom(ah
, EEP_TX_MASK
);
3608 * For AR9271 we will temporarilly uses the rx chainmax as read from
3611 if ((ah
->hw_version
.devid
== AR5416_DEVID_PCI
) &&
3612 !(eeval
& AR5416_OPFLAGS_11A
) &&
3613 !(AR_SREV_9271(ah
)))
3614 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
3615 pCap
->rx_chainmask
= ath9k_hw_gpio_get(ah
, 0) ? 0x5 : 0x7;
3617 /* Use rx_chainmask from EEPROM. */
3618 pCap
->rx_chainmask
= ah
->eep_ops
->get_eeprom(ah
, EEP_RX_MASK
);
3620 if (!(AR_SREV_9280(ah
) && (ah
->hw_version
.macRev
== 0)))
3621 ah
->misc_mode
|= AR_PCU_MIC_NEW_LOC_ENA
;
3623 pCap
->low_2ghz_chan
= 2312;
3624 pCap
->high_2ghz_chan
= 2732;
3626 pCap
->low_5ghz_chan
= 4920;
3627 pCap
->high_5ghz_chan
= 6100;
3629 pCap
->hw_caps
&= ~ATH9K_HW_CAP_CIPHER_CKIP
;
3630 pCap
->hw_caps
|= ATH9K_HW_CAP_CIPHER_TKIP
;
3631 pCap
->hw_caps
|= ATH9K_HW_CAP_CIPHER_AESCCM
;
3633 pCap
->hw_caps
&= ~ATH9K_HW_CAP_MIC_CKIP
;
3634 pCap
->hw_caps
|= ATH9K_HW_CAP_MIC_TKIP
;
3635 pCap
->hw_caps
|= ATH9K_HW_CAP_MIC_AESCCM
;
3637 if (ah
->config
.ht_enable
)
3638 pCap
->hw_caps
|= ATH9K_HW_CAP_HT
;
3640 pCap
->hw_caps
&= ~ATH9K_HW_CAP_HT
;
3642 pCap
->hw_caps
|= ATH9K_HW_CAP_GTT
;
3643 pCap
->hw_caps
|= ATH9K_HW_CAP_VEOL
;
3644 pCap
->hw_caps
|= ATH9K_HW_CAP_BSSIDMASK
;
3645 pCap
->hw_caps
&= ~ATH9K_HW_CAP_MCAST_KEYSEARCH
;
3647 if (capField
& AR_EEPROM_EEPCAP_MAXQCU
)
3648 pCap
->total_queues
=
3649 MS(capField
, AR_EEPROM_EEPCAP_MAXQCU
);
3651 pCap
->total_queues
= ATH9K_NUM_TX_QUEUES
;
3653 if (capField
& AR_EEPROM_EEPCAP_KC_ENTRIES
)
3654 pCap
->keycache_size
=
3655 1 << MS(capField
, AR_EEPROM_EEPCAP_KC_ENTRIES
);
3657 pCap
->keycache_size
= AR_KEYTABLE_SIZE
;
3659 pCap
->hw_caps
|= ATH9K_HW_CAP_FASTCC
;
3660 pCap
->tx_triglevel_max
= MAX_TX_FIFO_THRESHOLD
;
3662 if (AR_SREV_9285_10_OR_LATER(ah
))
3663 pCap
->num_gpio_pins
= AR9285_NUM_GPIO
;
3664 else if (AR_SREV_9280_10_OR_LATER(ah
))
3665 pCap
->num_gpio_pins
= AR928X_NUM_GPIO
;
3667 pCap
->num_gpio_pins
= AR_NUM_GPIO
;
3669 if (AR_SREV_9160_10_OR_LATER(ah
) || AR_SREV_9100(ah
)) {
3670 pCap
->hw_caps
|= ATH9K_HW_CAP_CST
;
3671 pCap
->rts_aggr_limit
= ATH_AMPDU_LIMIT_MAX
;
3673 pCap
->rts_aggr_limit
= (8 * 1024);
3676 pCap
->hw_caps
|= ATH9K_HW_CAP_ENHANCEDPM
;
3678 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
3679 ah
->rfsilent
= ah
->eep_ops
->get_eeprom(ah
, EEP_RF_SILENT
);
3680 if (ah
->rfsilent
& EEP_RFSILENT_ENABLED
) {
3682 MS(ah
->rfsilent
, EEP_RFSILENT_GPIO_SEL
);
3683 ah
->rfkill_polarity
=
3684 MS(ah
->rfsilent
, EEP_RFSILENT_POLARITY
);
3686 pCap
->hw_caps
|= ATH9K_HW_CAP_RFSILENT
;
3690 pCap
->hw_caps
&= ~ATH9K_HW_CAP_AUTOSLEEP
;
3692 if (AR_SREV_9280(ah
) || AR_SREV_9285(ah
))
3693 pCap
->hw_caps
&= ~ATH9K_HW_CAP_4KB_SPLITTRANS
;
3695 pCap
->hw_caps
|= ATH9K_HW_CAP_4KB_SPLITTRANS
;
3697 if (regulatory
->current_rd_ext
& (1 << REG_EXT_JAPAN_MIDBAND
)) {
3699 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A
|
3700 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN
|
3701 AR_EEPROM_EEREGCAP_EN_KK_U2
|
3702 AR_EEPROM_EEREGCAP_EN_KK_MIDBAND
;
3705 AR_EEPROM_EEREGCAP_EN_KK_NEW_11A
|
3706 AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN
;
3709 /* Advertise midband for AR5416 with FCC midband set in eeprom */
3710 if (regulatory
->current_rd_ext
& (1 << REG_EXT_FCC_MIDBAND
) &&
3712 pCap
->reg_cap
|= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND
;
3714 pCap
->num_antcfg_5ghz
=
3715 ah
->eep_ops
->get_num_ant_config(ah
, ATH9K_HAL_FREQ_BAND_5GHZ
);
3716 pCap
->num_antcfg_2ghz
=
3717 ah
->eep_ops
->get_num_ant_config(ah
, ATH9K_HAL_FREQ_BAND_2GHZ
);
3719 if (AR_SREV_9280_10_OR_LATER(ah
) &&
3720 ath9k_hw_btcoex_supported(ah
)) {
3721 btcoex_hw
->btactive_gpio
= ATH_BTACTIVE_GPIO
;
3722 btcoex_hw
->wlanactive_gpio
= ATH_WLANACTIVE_GPIO
;
3724 if (AR_SREV_9285(ah
)) {
3725 btcoex_hw
->scheme
= ATH_BTCOEX_CFG_3WIRE
;
3726 btcoex_hw
->btpriority_gpio
= ATH_BTPRIORITY_GPIO
;
3728 btcoex_hw
->scheme
= ATH_BTCOEX_CFG_2WIRE
;
3731 btcoex_hw
->scheme
= ATH_BTCOEX_CFG_NONE
;
3735 bool ath9k_hw_getcapability(struct ath_hw
*ah
, enum ath9k_capability_type type
,
3736 u32 capability
, u32
*result
)
3738 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
3740 case ATH9K_CAP_CIPHER
:
3741 switch (capability
) {
3742 case ATH9K_CIPHER_AES_CCM
:
3743 case ATH9K_CIPHER_AES_OCB
:
3744 case ATH9K_CIPHER_TKIP
:
3745 case ATH9K_CIPHER_WEP
:
3746 case ATH9K_CIPHER_MIC
:
3747 case ATH9K_CIPHER_CLR
:
3752 case ATH9K_CAP_TKIP_MIC
:
3753 switch (capability
) {
3757 return (ah
->sta_id1_defaults
&
3758 AR_STA_ID1_CRPT_MIC_ENABLE
) ? true :
3761 case ATH9K_CAP_TKIP_SPLIT
:
3762 return (ah
->misc_mode
& AR_PCU_MIC_NEW_LOC_ENA
) ?
3764 case ATH9K_CAP_DIVERSITY
:
3765 return (REG_READ(ah
, AR_PHY_CCK_DETECT
) &
3766 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
) ?
3768 case ATH9K_CAP_MCAST_KEYSRCH
:
3769 switch (capability
) {
3773 if (REG_READ(ah
, AR_STA_ID1
) & AR_STA_ID1_ADHOC
) {
3776 return (ah
->sta_id1_defaults
&
3777 AR_STA_ID1_MCAST_KSRCH
) ? true :
3782 case ATH9K_CAP_TXPOW
:
3783 switch (capability
) {
3787 *result
= regulatory
->power_limit
;
3790 *result
= regulatory
->max_power_level
;
3793 *result
= regulatory
->tp_scale
;
3798 return (AR_SREV_9280_20_OR_LATER(ah
) &&
3799 (ah
->eep_ops
->get_eeprom(ah
, EEP_RC_CHAIN_MASK
) == 1))
3805 EXPORT_SYMBOL(ath9k_hw_getcapability
);
3807 bool ath9k_hw_setcapability(struct ath_hw
*ah
, enum ath9k_capability_type type
,
3808 u32 capability
, u32 setting
, int *status
)
3813 case ATH9K_CAP_TKIP_MIC
:
3815 ah
->sta_id1_defaults
|=
3816 AR_STA_ID1_CRPT_MIC_ENABLE
;
3818 ah
->sta_id1_defaults
&=
3819 ~AR_STA_ID1_CRPT_MIC_ENABLE
;
3821 case ATH9K_CAP_DIVERSITY
:
3822 v
= REG_READ(ah
, AR_PHY_CCK_DETECT
);
3824 v
|= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
;
3826 v
&= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
;
3827 REG_WRITE(ah
, AR_PHY_CCK_DETECT
, v
);
3829 case ATH9K_CAP_MCAST_KEYSRCH
:
3831 ah
->sta_id1_defaults
|= AR_STA_ID1_MCAST_KSRCH
;
3833 ah
->sta_id1_defaults
&= ~AR_STA_ID1_MCAST_KSRCH
;
3839 EXPORT_SYMBOL(ath9k_hw_setcapability
);
3841 /****************************/
3842 /* GPIO / RFKILL / Antennae */
3843 /****************************/
3845 static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw
*ah
,
3849 u32 gpio_shift
, tmp
;
3852 addr
= AR_GPIO_OUTPUT_MUX3
;
3854 addr
= AR_GPIO_OUTPUT_MUX2
;
3856 addr
= AR_GPIO_OUTPUT_MUX1
;
3858 gpio_shift
= (gpio
% 6) * 5;
3860 if (AR_SREV_9280_20_OR_LATER(ah
)
3861 || (addr
!= AR_GPIO_OUTPUT_MUX1
)) {
3862 REG_RMW(ah
, addr
, (type
<< gpio_shift
),
3863 (0x1f << gpio_shift
));
3865 tmp
= REG_READ(ah
, addr
);
3866 tmp
= ((tmp
& 0x1F0) << 1) | (tmp
& ~0x1F0);
3867 tmp
&= ~(0x1f << gpio_shift
);
3868 tmp
|= (type
<< gpio_shift
);
3869 REG_WRITE(ah
, addr
, tmp
);
3873 void ath9k_hw_cfg_gpio_input(struct ath_hw
*ah
, u32 gpio
)
3877 BUG_ON(gpio
>= ah
->caps
.num_gpio_pins
);
3879 gpio_shift
= gpio
<< 1;
3883 (AR_GPIO_OE_OUT_DRV_NO
<< gpio_shift
),
3884 (AR_GPIO_OE_OUT_DRV
<< gpio_shift
));
3886 EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input
);
3888 u32
ath9k_hw_gpio_get(struct ath_hw
*ah
, u32 gpio
)
3890 #define MS_REG_READ(x, y) \
3891 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
3893 if (gpio
>= ah
->caps
.num_gpio_pins
)
3896 if (AR_SREV_9287_10_OR_LATER(ah
))
3897 return MS_REG_READ(AR9287
, gpio
) != 0;
3898 else if (AR_SREV_9285_10_OR_LATER(ah
))
3899 return MS_REG_READ(AR9285
, gpio
) != 0;
3900 else if (AR_SREV_9280_10_OR_LATER(ah
))
3901 return MS_REG_READ(AR928X
, gpio
) != 0;
3903 return MS_REG_READ(AR
, gpio
) != 0;
3905 EXPORT_SYMBOL(ath9k_hw_gpio_get
);
3907 void ath9k_hw_cfg_output(struct ath_hw
*ah
, u32 gpio
,
3912 ath9k_hw_gpio_cfg_output_mux(ah
, gpio
, ah_signal_type
);
3914 gpio_shift
= 2 * gpio
;
3918 (AR_GPIO_OE_OUT_DRV_ALL
<< gpio_shift
),
3919 (AR_GPIO_OE_OUT_DRV
<< gpio_shift
));
3921 EXPORT_SYMBOL(ath9k_hw_cfg_output
);
3923 void ath9k_hw_set_gpio(struct ath_hw
*ah
, u32 gpio
, u32 val
)
3925 REG_RMW(ah
, AR_GPIO_IN_OUT
, ((val
& 1) << gpio
),
3928 EXPORT_SYMBOL(ath9k_hw_set_gpio
);
3930 u32
ath9k_hw_getdefantenna(struct ath_hw
*ah
)
3932 return REG_READ(ah
, AR_DEF_ANTENNA
) & 0x7;
3934 EXPORT_SYMBOL(ath9k_hw_getdefantenna
);
3936 void ath9k_hw_setantenna(struct ath_hw
*ah
, u32 antenna
)
3938 REG_WRITE(ah
, AR_DEF_ANTENNA
, (antenna
& 0x7));
3940 EXPORT_SYMBOL(ath9k_hw_setantenna
);
3942 bool ath9k_hw_setantennaswitch(struct ath_hw
*ah
,
3943 enum ath9k_ant_setting settings
,
3944 struct ath9k_channel
*chan
,
3949 static u8 tx_chainmask_cfg
, rx_chainmask_cfg
;
3951 if (AR_SREV_9280(ah
)) {
3952 if (!tx_chainmask_cfg
) {
3954 tx_chainmask_cfg
= *tx_chainmask
;
3955 rx_chainmask_cfg
= *rx_chainmask
;
3959 case ATH9K_ANT_FIXED_A
:
3960 *tx_chainmask
= ATH9K_ANTENNA0_CHAINMASK
;
3961 *rx_chainmask
= ATH9K_ANTENNA0_CHAINMASK
;
3962 *antenna_cfgd
= true;
3964 case ATH9K_ANT_FIXED_B
:
3965 if (ah
->caps
.tx_chainmask
>
3966 ATH9K_ANTENNA1_CHAINMASK
) {
3967 *tx_chainmask
= ATH9K_ANTENNA1_CHAINMASK
;
3969 *rx_chainmask
= ATH9K_ANTENNA1_CHAINMASK
;
3970 *antenna_cfgd
= true;
3972 case ATH9K_ANT_VARIABLE
:
3973 *tx_chainmask
= tx_chainmask_cfg
;
3974 *rx_chainmask
= rx_chainmask_cfg
;
3975 *antenna_cfgd
= true;
3981 ah
->config
.diversity_control
= settings
;
3987 /*********************/
3988 /* General Operation */
3989 /*********************/
3991 u32
ath9k_hw_getrxfilter(struct ath_hw
*ah
)
3993 u32 bits
= REG_READ(ah
, AR_RX_FILTER
);
3994 u32 phybits
= REG_READ(ah
, AR_PHY_ERR
);
3996 if (phybits
& AR_PHY_ERR_RADAR
)
3997 bits
|= ATH9K_RX_FILTER_PHYRADAR
;
3998 if (phybits
& (AR_PHY_ERR_OFDM_TIMING
| AR_PHY_ERR_CCK_TIMING
))
3999 bits
|= ATH9K_RX_FILTER_PHYERR
;
4003 EXPORT_SYMBOL(ath9k_hw_getrxfilter
);
4005 void ath9k_hw_setrxfilter(struct ath_hw
*ah
, u32 bits
)
4009 REG_WRITE(ah
, AR_RX_FILTER
, bits
);
4012 if (bits
& ATH9K_RX_FILTER_PHYRADAR
)
4013 phybits
|= AR_PHY_ERR_RADAR
;
4014 if (bits
& ATH9K_RX_FILTER_PHYERR
)
4015 phybits
|= AR_PHY_ERR_OFDM_TIMING
| AR_PHY_ERR_CCK_TIMING
;
4016 REG_WRITE(ah
, AR_PHY_ERR
, phybits
);
4019 REG_WRITE(ah
, AR_RXCFG
,
4020 REG_READ(ah
, AR_RXCFG
) | AR_RXCFG_ZLFDMA
);
4022 REG_WRITE(ah
, AR_RXCFG
,
4023 REG_READ(ah
, AR_RXCFG
) & ~AR_RXCFG_ZLFDMA
);
4025 EXPORT_SYMBOL(ath9k_hw_setrxfilter
);
4027 bool ath9k_hw_phy_disable(struct ath_hw
*ah
)
4029 if (!ath9k_hw_set_reset_reg(ah
, ATH9K_RESET_WARM
))
4032 ath9k_hw_init_pll(ah
, NULL
);
4035 EXPORT_SYMBOL(ath9k_hw_phy_disable
);
4037 bool ath9k_hw_disable(struct ath_hw
*ah
)
4039 if (!ath9k_hw_setpower(ah
, ATH9K_PM_AWAKE
))
4042 if (!ath9k_hw_set_reset_reg(ah
, ATH9K_RESET_COLD
))
4045 ath9k_hw_init_pll(ah
, NULL
);
4048 EXPORT_SYMBOL(ath9k_hw_disable
);
4050 void ath9k_hw_set_txpowerlimit(struct ath_hw
*ah
, u32 limit
)
4052 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
4053 struct ath9k_channel
*chan
= ah
->curchan
;
4054 struct ieee80211_channel
*channel
= chan
->chan
;
4056 regulatory
->power_limit
= min(limit
, (u32
) MAX_RATE_POWER
);
4058 ah
->eep_ops
->set_txpower(ah
, chan
,
4059 ath9k_regd_get_ctl(regulatory
, chan
),
4060 channel
->max_antenna_gain
* 2,
4061 channel
->max_power
* 2,
4062 min((u32
) MAX_RATE_POWER
,
4063 (u32
) regulatory
->power_limit
));
4065 EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit
);
4067 void ath9k_hw_setmac(struct ath_hw
*ah
, const u8
*mac
)
4069 memcpy(ath9k_hw_common(ah
)->macaddr
, mac
, ETH_ALEN
);
4071 EXPORT_SYMBOL(ath9k_hw_setmac
);
4073 void ath9k_hw_setopmode(struct ath_hw
*ah
)
4075 ath9k_hw_set_operating_mode(ah
, ah
->opmode
);
4077 EXPORT_SYMBOL(ath9k_hw_setopmode
);
4079 void ath9k_hw_setmcastfilter(struct ath_hw
*ah
, u32 filter0
, u32 filter1
)
4081 REG_WRITE(ah
, AR_MCAST_FIL0
, filter0
);
4082 REG_WRITE(ah
, AR_MCAST_FIL1
, filter1
);
4084 EXPORT_SYMBOL(ath9k_hw_setmcastfilter
);
4086 void ath9k_hw_write_associd(struct ath_hw
*ah
)
4088 struct ath_common
*common
= ath9k_hw_common(ah
);
4090 REG_WRITE(ah
, AR_BSS_ID0
, get_unaligned_le32(common
->curbssid
));
4091 REG_WRITE(ah
, AR_BSS_ID1
, get_unaligned_le16(common
->curbssid
+ 4) |
4092 ((common
->curaid
& 0x3fff) << AR_BSS_ID1_AID_S
));
4094 EXPORT_SYMBOL(ath9k_hw_write_associd
);
4096 u64
ath9k_hw_gettsf64(struct ath_hw
*ah
)
4100 tsf
= REG_READ(ah
, AR_TSF_U32
);
4101 tsf
= (tsf
<< 32) | REG_READ(ah
, AR_TSF_L32
);
4105 EXPORT_SYMBOL(ath9k_hw_gettsf64
);
4107 void ath9k_hw_settsf64(struct ath_hw
*ah
, u64 tsf64
)
4109 REG_WRITE(ah
, AR_TSF_L32
, tsf64
& 0xffffffff);
4110 REG_WRITE(ah
, AR_TSF_U32
, (tsf64
>> 32) & 0xffffffff);
4112 EXPORT_SYMBOL(ath9k_hw_settsf64
);
4114 void ath9k_hw_reset_tsf(struct ath_hw
*ah
)
4116 if (!ath9k_hw_wait(ah
, AR_SLP32_MODE
, AR_SLP32_TSF_WRITE_STATUS
, 0,
4117 AH_TSF_WRITE_TIMEOUT
))
4118 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
4119 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
4121 REG_WRITE(ah
, AR_RESET_TSF
, AR_RESET_TSF_ONCE
);
4123 EXPORT_SYMBOL(ath9k_hw_reset_tsf
);
4125 void ath9k_hw_set_tsfadjust(struct ath_hw
*ah
, u32 setting
)
4128 ah
->misc_mode
|= AR_PCU_TX_ADD_TSF
;
4130 ah
->misc_mode
&= ~AR_PCU_TX_ADD_TSF
;
4132 EXPORT_SYMBOL(ath9k_hw_set_tsfadjust
);
4134 bool ath9k_hw_setslottime(struct ath_hw
*ah
, u32 us
)
4136 if (us
< ATH9K_SLOT_TIME_9
|| us
> ath9k_hw_mac_to_usec(ah
, 0xffff)) {
4137 ath_print(ath9k_hw_common(ah
), ATH_DBG_RESET
,
4138 "bad slot time %u\n", us
);
4139 ah
->slottime
= (u32
) -1;
4142 REG_WRITE(ah
, AR_D_GBL_IFS_SLOT
, ath9k_hw_mac_to_clks(ah
, us
));
4147 EXPORT_SYMBOL(ath9k_hw_setslottime
);
4149 void ath9k_hw_set11nmac2040(struct ath_hw
*ah
)
4151 struct ieee80211_conf
*conf
= &ath9k_hw_common(ah
)->hw
->conf
;
4154 if (conf_is_ht40(conf
) && !ah
->config
.cwm_ignore_extcca
)
4155 macmode
= AR_2040_JOINED_RX_CLEAR
;
4159 REG_WRITE(ah
, AR_2040_MODE
, macmode
);
4162 /* HW Generic timers configuration */
4164 static const struct ath_gen_timer_configuration gen_tmr_configuration
[] =
4166 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4167 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4168 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4169 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4170 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4171 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4172 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4173 {AR_NEXT_NDP_TIMER
, AR_NDP_PERIOD
, AR_TIMER_MODE
, 0x0080},
4174 {AR_NEXT_NDP2_TIMER
, AR_NDP2_PERIOD
, AR_NDP2_TIMER_MODE
, 0x0001},
4175 {AR_NEXT_NDP2_TIMER
+ 1*4, AR_NDP2_PERIOD
+ 1*4,
4176 AR_NDP2_TIMER_MODE
, 0x0002},
4177 {AR_NEXT_NDP2_TIMER
+ 2*4, AR_NDP2_PERIOD
+ 2*4,
4178 AR_NDP2_TIMER_MODE
, 0x0004},
4179 {AR_NEXT_NDP2_TIMER
+ 3*4, AR_NDP2_PERIOD
+ 3*4,
4180 AR_NDP2_TIMER_MODE
, 0x0008},
4181 {AR_NEXT_NDP2_TIMER
+ 4*4, AR_NDP2_PERIOD
+ 4*4,
4182 AR_NDP2_TIMER_MODE
, 0x0010},
4183 {AR_NEXT_NDP2_TIMER
+ 5*4, AR_NDP2_PERIOD
+ 5*4,
4184 AR_NDP2_TIMER_MODE
, 0x0020},
4185 {AR_NEXT_NDP2_TIMER
+ 6*4, AR_NDP2_PERIOD
+ 6*4,
4186 AR_NDP2_TIMER_MODE
, 0x0040},
4187 {AR_NEXT_NDP2_TIMER
+ 7*4, AR_NDP2_PERIOD
+ 7*4,
4188 AR_NDP2_TIMER_MODE
, 0x0080}
4191 /* HW generic timer primitives */
4193 /* compute and clear index of rightmost 1 */
4194 static u32
rightmost_index(struct ath_gen_timer_table
*timer_table
, u32
*mask
)
4204 return timer_table
->gen_timer_index
[b
];
4207 u32
ath9k_hw_gettsf32(struct ath_hw
*ah
)
4209 return REG_READ(ah
, AR_TSF_L32
);
4211 EXPORT_SYMBOL(ath9k_hw_gettsf32
);
4213 struct ath_gen_timer
*ath_gen_timer_alloc(struct ath_hw
*ah
,
4214 void (*trigger
)(void *),
4215 void (*overflow
)(void *),
4219 struct ath_gen_timer_table
*timer_table
= &ah
->hw_gen_timers
;
4220 struct ath_gen_timer
*timer
;
4222 timer
= kzalloc(sizeof(struct ath_gen_timer
), GFP_KERNEL
);
4224 if (timer
== NULL
) {
4225 ath_print(ath9k_hw_common(ah
), ATH_DBG_FATAL
,
4226 "Failed to allocate memory"
4227 "for hw timer[%d]\n", timer_index
);
4231 /* allocate a hardware generic timer slot */
4232 timer_table
->timers
[timer_index
] = timer
;
4233 timer
->index
= timer_index
;
4234 timer
->trigger
= trigger
;
4235 timer
->overflow
= overflow
;
4240 EXPORT_SYMBOL(ath_gen_timer_alloc
);
4242 void ath9k_hw_gen_timer_start(struct ath_hw
*ah
,
4243 struct ath_gen_timer
*timer
,
4247 struct ath_gen_timer_table
*timer_table
= &ah
->hw_gen_timers
;
4250 BUG_ON(!timer_period
);
4252 set_bit(timer
->index
, &timer_table
->timer_mask
.timer_bits
);
4254 tsf
= ath9k_hw_gettsf32(ah
);
4256 ath_print(ath9k_hw_common(ah
), ATH_DBG_HWTIMER
,
4257 "curent tsf %x period %x"
4258 "timer_next %x\n", tsf
, timer_period
, timer_next
);
4261 * Pull timer_next forward if the current TSF already passed it
4262 * because of software latency
4264 if (timer_next
< tsf
)
4265 timer_next
= tsf
+ timer_period
;
4268 * Program generic timer registers
4270 REG_WRITE(ah
, gen_tmr_configuration
[timer
->index
].next_addr
,
4272 REG_WRITE(ah
, gen_tmr_configuration
[timer
->index
].period_addr
,
4274 REG_SET_BIT(ah
, gen_tmr_configuration
[timer
->index
].mode_addr
,
4275 gen_tmr_configuration
[timer
->index
].mode_mask
);
4277 /* Enable both trigger and thresh interrupt masks */
4278 REG_SET_BIT(ah
, AR_IMR_S5
,
4279 (SM(AR_GENTMR_BIT(timer
->index
), AR_IMR_S5_GENTIMER_THRESH
) |
4280 SM(AR_GENTMR_BIT(timer
->index
), AR_IMR_S5_GENTIMER_TRIG
)));
4282 EXPORT_SYMBOL(ath9k_hw_gen_timer_start
);
4284 void ath9k_hw_gen_timer_stop(struct ath_hw
*ah
, struct ath_gen_timer
*timer
)
4286 struct ath_gen_timer_table
*timer_table
= &ah
->hw_gen_timers
;
4288 if ((timer
->index
< AR_FIRST_NDP_TIMER
) ||
4289 (timer
->index
>= ATH_MAX_GEN_TIMER
)) {
4293 /* Clear generic timer enable bits. */
4294 REG_CLR_BIT(ah
, gen_tmr_configuration
[timer
->index
].mode_addr
,
4295 gen_tmr_configuration
[timer
->index
].mode_mask
);
4297 /* Disable both trigger and thresh interrupt masks */
4298 REG_CLR_BIT(ah
, AR_IMR_S5
,
4299 (SM(AR_GENTMR_BIT(timer
->index
), AR_IMR_S5_GENTIMER_THRESH
) |
4300 SM(AR_GENTMR_BIT(timer
->index
), AR_IMR_S5_GENTIMER_TRIG
)));
4302 clear_bit(timer
->index
, &timer_table
->timer_mask
.timer_bits
);
4304 EXPORT_SYMBOL(ath9k_hw_gen_timer_stop
);
4306 void ath_gen_timer_free(struct ath_hw
*ah
, struct ath_gen_timer
*timer
)
4308 struct ath_gen_timer_table
*timer_table
= &ah
->hw_gen_timers
;
4310 /* free the hardware generic timer slot */
4311 timer_table
->timers
[timer
->index
] = NULL
;
4314 EXPORT_SYMBOL(ath_gen_timer_free
);
4317 * Generic Timer Interrupts handling
4319 void ath_gen_timer_isr(struct ath_hw
*ah
)
4321 struct ath_gen_timer_table
*timer_table
= &ah
->hw_gen_timers
;
4322 struct ath_gen_timer
*timer
;
4323 struct ath_common
*common
= ath9k_hw_common(ah
);
4324 u32 trigger_mask
, thresh_mask
, index
;
4326 /* get hardware generic timer interrupt status */
4327 trigger_mask
= ah
->intr_gen_timer_trigger
;
4328 thresh_mask
= ah
->intr_gen_timer_thresh
;
4329 trigger_mask
&= timer_table
->timer_mask
.val
;
4330 thresh_mask
&= timer_table
->timer_mask
.val
;
4332 trigger_mask
&= ~thresh_mask
;
4334 while (thresh_mask
) {
4335 index
= rightmost_index(timer_table
, &thresh_mask
);
4336 timer
= timer_table
->timers
[index
];
4338 ath_print(common
, ATH_DBG_HWTIMER
,
4339 "TSF overflow for Gen timer %d\n", index
);
4340 timer
->overflow(timer
->arg
);
4343 while (trigger_mask
) {
4344 index
= rightmost_index(timer_table
, &trigger_mask
);
4345 timer
= timer_table
->timers
[index
];
4347 ath_print(common
, ATH_DBG_HWTIMER
,
4348 "Gen timer[%d] trigger\n", index
);
4349 timer
->trigger(timer
->arg
);
4352 EXPORT_SYMBOL(ath_gen_timer_isr
);