2 * Copyright (c) 2008-2010 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.
17 #include <linux/kernel.h>
21 struct ani_ofdm_level_entry {
22 int spur_immunity_level;
24 int ofdm_weak_signal_on;
27 /* values here are relative to the INI */
34 * WS: OFDM / CCK Weak Signal detection
35 * MRC-CCK: Maximal Ratio Combining for CCK
38 static const struct ani_ofdm_level_entry ofdm_level_table[] = {
40 { 0, 0, 1 }, /* lvl 0 */
41 { 1, 1, 1 }, /* lvl 1 */
42 { 2, 2, 1 }, /* lvl 2 */
43 { 3, 2, 1 }, /* lvl 3 (default) */
44 { 4, 3, 1 }, /* lvl 4 */
45 { 5, 4, 1 }, /* lvl 5 */
46 { 6, 5, 1 }, /* lvl 6 */
47 { 7, 6, 1 }, /* lvl 7 */
48 { 7, 7, 1 }, /* lvl 8 */
49 { 7, 8, 0 } /* lvl 9 */
51 #define ATH9K_ANI_OFDM_NUM_LEVEL \
52 ARRAY_SIZE(ofdm_level_table)
53 #define ATH9K_ANI_OFDM_MAX_LEVEL \
54 (ATH9K_ANI_OFDM_NUM_LEVEL-1)
55 #define ATH9K_ANI_OFDM_DEF_LEVEL \
56 3 /* default level - matches the INI settings */
59 * MRC (Maximal Ratio Combining) has always been used with multi-antenna ofdm.
60 * With OFDM for single stream you just add up all antenna inputs, you're
61 * only interested in what you get after FFT. Signal aligment is also not
62 * required for OFDM because any phase difference adds up in the frequency
65 * MRC requires extra work for use with CCK. You need to align the antenna
66 * signals from the different antenna before you can add the signals together.
67 * You need aligment of signals as CCK is in time domain, so addition can cancel
68 * your signal completely if phase is 180 degrees (think of adding sine waves).
69 * You also need to remove noise before the addition and this is where ANI
70 * MRC CCK comes into play. One of the antenna inputs may be stronger but
71 * lower SNR, so just adding after alignment can be dangerous.
73 * Regardless of alignment in time, the antenna signals add constructively after
74 * FFT and improve your reception. For more information:
76 * http://en.wikipedia.org/wiki/Maximal-ratio_combining
79 struct ani_cck_level_entry {
84 static const struct ani_cck_level_entry cck_level_table[] = {
88 { 2, 1 }, /* lvl 2 (default) */
93 { 7, 0 }, /* lvl 7 (only for high rssi) */
94 { 8, 0 } /* lvl 8 (only for high rssi) */
97 #define ATH9K_ANI_CCK_NUM_LEVEL \
98 ARRAY_SIZE(cck_level_table)
99 #define ATH9K_ANI_CCK_MAX_LEVEL \
100 (ATH9K_ANI_CCK_NUM_LEVEL-1)
101 #define ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI \
102 (ATH9K_ANI_CCK_NUM_LEVEL-3)
103 #define ATH9K_ANI_CCK_DEF_LEVEL \
104 2 /* default level - matches the INI settings */
106 /* Private to ani.c */
107 static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
109 ath9k_hw_private_ops(ah)->ani_lower_immunity(ah);
112 int ath9k_hw_get_ani_channel_idx(struct ath_hw *ah,
113 struct ath9k_channel *chan)
117 for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
119 ah->ani[i].c->channel == chan->channel)
121 if (ah->ani[i].c == NULL) {
127 ath_print(ath9k_hw_common(ah), ATH_DBG_ANI,
128 "No more channel states left. Using channel 0\n");
133 static void ath9k_hw_update_mibstats(struct ath_hw *ah,
134 struct ath9k_mib_stats *stats)
136 stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
137 stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
138 stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
139 stats->rts_good += REG_READ(ah, AR_RTS_OK);
140 stats->beacons += REG_READ(ah, AR_BEACON_CNT);
143 static void ath9k_ani_restart_old(struct ath_hw *ah)
145 struct ar5416AniState *aniState;
146 struct ath_common *common = ath9k_hw_common(ah);
151 aniState = ah->curani;
152 aniState->listenTime = 0;
154 if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
155 aniState->ofdmPhyErrBase = 0;
156 ath_print(common, ATH_DBG_ANI,
157 "OFDM Trigger is too high for hw counters\n");
159 aniState->ofdmPhyErrBase =
160 AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
162 if (aniState->cckTrigHigh > AR_PHY_COUNTMAX) {
163 aniState->cckPhyErrBase = 0;
164 ath_print(common, ATH_DBG_ANI,
165 "CCK Trigger is too high for hw counters\n");
167 aniState->cckPhyErrBase =
168 AR_PHY_COUNTMAX - aniState->cckTrigHigh;
170 ath_print(common, ATH_DBG_ANI,
171 "Writing ofdmbase=%u cckbase=%u\n",
172 aniState->ofdmPhyErrBase,
173 aniState->cckPhyErrBase);
175 ENABLE_REGWRITE_BUFFER(ah);
177 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
178 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
179 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
180 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
182 REGWRITE_BUFFER_FLUSH(ah);
183 DISABLE_REGWRITE_BUFFER(ah);
185 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
187 aniState->ofdmPhyErrCount = 0;
188 aniState->cckPhyErrCount = 0;
191 static void ath9k_ani_restart_new(struct ath_hw *ah)
193 struct ar5416AniState *aniState;
194 struct ath_common *common = ath9k_hw_common(ah);
199 aniState = ah->curani;
200 aniState->listenTime = 0;
202 aniState->ofdmPhyErrBase = 0;
203 aniState->cckPhyErrBase = 0;
205 ath_print(common, ATH_DBG_ANI,
206 "Writing ofdmbase=%08x cckbase=%08x\n",
207 aniState->ofdmPhyErrBase,
208 aniState->cckPhyErrBase);
210 ENABLE_REGWRITE_BUFFER(ah);
212 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
213 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
214 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
215 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
217 REGWRITE_BUFFER_FLUSH(ah);
218 DISABLE_REGWRITE_BUFFER(ah);
220 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
222 aniState->ofdmPhyErrCount = 0;
223 aniState->cckPhyErrCount = 0;
226 static void ath9k_hw_ani_ofdm_err_trigger_old(struct ath_hw *ah)
228 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
229 struct ar5416AniState *aniState;
235 aniState = ah->curani;
237 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
238 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
239 aniState->noiseImmunityLevel + 1)) {
244 if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
245 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
246 aniState->spurImmunityLevel + 1)) {
251 if (ah->opmode == NL80211_IFTYPE_AP) {
252 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
253 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
254 aniState->firstepLevel + 1);
258 rssi = BEACON_RSSI(ah);
259 if (rssi > aniState->rssiThrHigh) {
260 if (!aniState->ofdmWeakSigDetectOff) {
261 if (ath9k_hw_ani_control(ah,
262 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
264 ath9k_hw_ani_control(ah,
265 ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
269 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
270 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
271 aniState->firstepLevel + 1);
274 } else if (rssi > aniState->rssiThrLow) {
275 if (aniState->ofdmWeakSigDetectOff)
276 ath9k_hw_ani_control(ah,
277 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
279 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
280 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
281 aniState->firstepLevel + 1);
284 if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
286 if (!aniState->ofdmWeakSigDetectOff)
287 ath9k_hw_ani_control(ah,
288 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
290 if (aniState->firstepLevel > 0)
291 ath9k_hw_ani_control(ah,
292 ATH9K_ANI_FIRSTEP_LEVEL, 0);
298 static void ath9k_hw_ani_cck_err_trigger_old(struct ath_hw *ah)
300 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
301 struct ar5416AniState *aniState;
307 aniState = ah->curani;
308 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
309 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
310 aniState->noiseImmunityLevel + 1)) {
314 if (ah->opmode == NL80211_IFTYPE_AP) {
315 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
316 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
317 aniState->firstepLevel + 1);
321 rssi = BEACON_RSSI(ah);
322 if (rssi > aniState->rssiThrLow) {
323 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
324 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
325 aniState->firstepLevel + 1);
327 if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
329 if (aniState->firstepLevel > 0)
330 ath9k_hw_ani_control(ah,
331 ATH9K_ANI_FIRSTEP_LEVEL, 0);
336 /* Adjust the OFDM Noise Immunity Level */
337 static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
339 struct ar5416AniState *aniState = ah->curani;
340 struct ath_common *common = ath9k_hw_common(ah);
341 const struct ani_ofdm_level_entry *entry_ofdm;
342 const struct ani_cck_level_entry *entry_cck;
344 aniState->noiseFloor = BEACON_RSSI(ah);
346 ath_print(common, ATH_DBG_ANI,
347 "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
348 aniState->ofdmNoiseImmunityLevel,
349 immunityLevel, aniState->noiseFloor,
350 aniState->rssiThrLow, aniState->rssiThrHigh);
352 aniState->ofdmNoiseImmunityLevel = immunityLevel;
354 entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
355 entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
357 if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level)
358 ath9k_hw_ani_control(ah,
359 ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
360 entry_ofdm->spur_immunity_level);
362 if (aniState->firstepLevel != entry_ofdm->fir_step_level &&
363 entry_ofdm->fir_step_level >= entry_cck->fir_step_level)
364 ath9k_hw_ani_control(ah,
365 ATH9K_ANI_FIRSTEP_LEVEL,
366 entry_ofdm->fir_step_level);
368 if ((ah->opmode != NL80211_IFTYPE_STATION &&
369 ah->opmode != NL80211_IFTYPE_ADHOC) ||
370 aniState->noiseFloor <= aniState->rssiThrHigh) {
371 if (aniState->ofdmWeakSigDetectOff)
372 /* force on ofdm weak sig detect */
373 ath9k_hw_ani_control(ah,
374 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
376 else if (aniState->ofdmWeakSigDetectOff ==
377 entry_ofdm->ofdm_weak_signal_on)
378 ath9k_hw_ani_control(ah,
379 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
380 entry_ofdm->ofdm_weak_signal_on);
384 static void ath9k_hw_ani_ofdm_err_trigger_new(struct ath_hw *ah)
386 struct ar5416AniState *aniState;
391 aniState = ah->curani;
393 if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
394 ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1);
398 * Set the ANI settings to match an CCK level.
400 static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel)
402 struct ar5416AniState *aniState = ah->curani;
403 struct ath_common *common = ath9k_hw_common(ah);
404 const struct ani_ofdm_level_entry *entry_ofdm;
405 const struct ani_cck_level_entry *entry_cck;
407 aniState->noiseFloor = BEACON_RSSI(ah);
408 ath_print(common, ATH_DBG_ANI,
409 "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
410 aniState->cckNoiseImmunityLevel, immunityLevel,
411 aniState->noiseFloor, aniState->rssiThrLow,
412 aniState->rssiThrHigh);
414 if ((ah->opmode == NL80211_IFTYPE_STATION ||
415 ah->opmode == NL80211_IFTYPE_ADHOC) &&
416 aniState->noiseFloor <= aniState->rssiThrLow &&
417 immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
418 immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
420 aniState->cckNoiseImmunityLevel = immunityLevel;
422 entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
423 entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
425 if (aniState->firstepLevel != entry_cck->fir_step_level &&
426 entry_cck->fir_step_level >= entry_ofdm->fir_step_level)
427 ath9k_hw_ani_control(ah,
428 ATH9K_ANI_FIRSTEP_LEVEL,
429 entry_cck->fir_step_level);
431 /* Skip MRC CCK for pre AR9003 families */
432 if (!AR_SREV_9300_20_OR_LATER(ah))
435 if (aniState->mrcCCKOff == entry_cck->mrc_cck_on)
436 ath9k_hw_ani_control(ah,
438 entry_cck->mrc_cck_on);
441 static void ath9k_hw_ani_cck_err_trigger_new(struct ath_hw *ah)
443 struct ar5416AniState *aniState;
448 aniState = ah->curani;
450 if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
451 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1);
454 static void ath9k_hw_ani_lower_immunity_old(struct ath_hw *ah)
456 struct ar5416AniState *aniState;
459 aniState = ah->curani;
461 if (ah->opmode == NL80211_IFTYPE_AP) {
462 if (aniState->firstepLevel > 0) {
463 if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
464 aniState->firstepLevel - 1))
468 rssi = BEACON_RSSI(ah);
469 if (rssi > aniState->rssiThrHigh) {
471 } else if (rssi > aniState->rssiThrLow) {
472 if (aniState->ofdmWeakSigDetectOff) {
473 if (ath9k_hw_ani_control(ah,
474 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
478 if (aniState->firstepLevel > 0) {
479 if (ath9k_hw_ani_control(ah,
480 ATH9K_ANI_FIRSTEP_LEVEL,
481 aniState->firstepLevel - 1) == true)
485 if (aniState->firstepLevel > 0) {
486 if (ath9k_hw_ani_control(ah,
487 ATH9K_ANI_FIRSTEP_LEVEL,
488 aniState->firstepLevel - 1) == true)
494 if (aniState->spurImmunityLevel > 0) {
495 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
496 aniState->spurImmunityLevel - 1))
500 if (aniState->noiseImmunityLevel > 0) {
501 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
502 aniState->noiseImmunityLevel - 1);
508 * only lower either OFDM or CCK errors per turn
509 * we lower the other one next time
511 static void ath9k_hw_ani_lower_immunity_new(struct ath_hw *ah)
513 struct ar5416AniState *aniState;
515 aniState = ah->curani;
517 /* lower OFDM noise immunity */
518 if (aniState->ofdmNoiseImmunityLevel > 0 &&
519 (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
520 ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1);
524 /* lower CCK noise immunity */
525 if (aniState->cckNoiseImmunityLevel > 0)
526 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
529 static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah)
531 struct ath9k_channel *chan = ah->curchan;
532 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
533 u8 clockrate; /* in MHz */
535 if (!ah->curchan) /* should really check for CCK instead */
536 clockrate = ATH9K_CLOCK_RATE_CCK;
537 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
538 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
539 else if (IS_CHAN_A_FAST_CLOCK(ah, chan))
540 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
542 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
544 if (conf_is_ht40(conf))
545 return clockrate * 2;
550 static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
552 struct ar5416AniState *aniState;
553 struct ath_common *common = ath9k_hw_common(ah);
554 u32 txFrameCount, rxFrameCount, cycleCount;
557 txFrameCount = REG_READ(ah, AR_TFCNT);
558 rxFrameCount = REG_READ(ah, AR_RFCNT);
559 cycleCount = REG_READ(ah, AR_CCCNT);
561 aniState = ah->curani;
562 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
564 ah->stats.ast_ani_lzero++;
565 ath_print(common, ATH_DBG_ANI,
566 "1st call: aniState->cycleCount=%d\n",
567 aniState->cycleCount);
569 int32_t ccdelta = cycleCount - aniState->cycleCount;
570 int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
571 int32_t tfdelta = txFrameCount - aniState->txFrameCount;
575 * convert HW counter values to ms using mode
576 * specifix clock rate
578 clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000;;
580 listenTime = (ccdelta - rfdelta - tfdelta) / clock_rate;
582 ath_print(common, ATH_DBG_ANI,
583 "cyclecount=%d, rfcount=%d, "
584 "tfcount=%d, listenTime=%d CLOCK_RATE=%d\n",
585 ccdelta, rfdelta, tfdelta, listenTime, clock_rate);
588 aniState->cycleCount = cycleCount;
589 aniState->txFrameCount = txFrameCount;
590 aniState->rxFrameCount = rxFrameCount;
595 static void ath9k_ani_reset_old(struct ath_hw *ah, bool is_scanning)
597 struct ar5416AniState *aniState;
598 struct ath9k_channel *chan = ah->curchan;
599 struct ath_common *common = ath9k_hw_common(ah);
605 index = ath9k_hw_get_ani_channel_idx(ah, chan);
606 aniState = &ah->ani[index];
607 ah->curani = aniState;
609 if (DO_ANI(ah) && ah->opmode != NL80211_IFTYPE_STATION
610 && ah->opmode != NL80211_IFTYPE_ADHOC) {
611 ath_print(common, ATH_DBG_ANI,
612 "Reset ANI state opmode %u\n", ah->opmode);
613 ah->stats.ast_ani_reset++;
615 if (ah->opmode == NL80211_IFTYPE_AP) {
617 * ath9k_hw_ani_control() will only process items set on
620 if (IS_CHAN_2GHZ(chan))
621 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
622 ATH9K_ANI_FIRSTEP_LEVEL);
624 ah->ani_function = 0;
627 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
628 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
629 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
630 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
631 !ATH9K_ANI_USE_OFDM_WEAK_SIG);
632 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
633 ATH9K_ANI_CCK_WEAK_SIG_THR);
635 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
636 ATH9K_RX_FILTER_PHYERR);
638 if (ah->opmode == NL80211_IFTYPE_AP) {
639 ah->curani->ofdmTrigHigh =
640 ah->config.ofdm_trig_high;
641 ah->curani->ofdmTrigLow =
642 ah->config.ofdm_trig_low;
643 ah->curani->cckTrigHigh =
644 ah->config.cck_trig_high;
645 ah->curani->cckTrigLow =
646 ah->config.cck_trig_low;
648 ath9k_ani_restart_old(ah);
652 if (aniState->noiseImmunityLevel != 0)
653 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
654 aniState->noiseImmunityLevel);
655 if (aniState->spurImmunityLevel != 0)
656 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
657 aniState->spurImmunityLevel);
658 if (aniState->ofdmWeakSigDetectOff)
659 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
660 !aniState->ofdmWeakSigDetectOff);
661 if (aniState->cckWeakSigThreshold)
662 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
663 aniState->cckWeakSigThreshold);
664 if (aniState->firstepLevel != 0)
665 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
666 aniState->firstepLevel);
668 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) &
669 ~ATH9K_RX_FILTER_PHYERR);
670 ath9k_ani_restart_old(ah);
672 ENABLE_REGWRITE_BUFFER(ah);
674 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
675 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
677 REGWRITE_BUFFER_FLUSH(ah);
678 DISABLE_REGWRITE_BUFFER(ah);
682 * Restore the ANI parameters in the HAL and reset the statistics.
683 * This routine should be called for every hardware reset and for
684 * every channel change.
686 static void ath9k_ani_reset_new(struct ath_hw *ah, bool is_scanning)
688 struct ar5416AniState *aniState = ah->curani;
689 struct ath9k_channel *chan = ah->curchan;
690 struct ath_common *common = ath9k_hw_common(ah);
695 BUG_ON(aniState == NULL);
696 ah->stats.ast_ani_reset++;
698 /* only allow a subset of functions in AP mode */
699 if (ah->opmode == NL80211_IFTYPE_AP) {
700 if (IS_CHAN_2GHZ(chan)) {
701 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
702 ATH9K_ANI_FIRSTEP_LEVEL);
703 if (AR_SREV_9300_20_OR_LATER(ah))
704 ah->ani_function |= ATH9K_ANI_MRC_CCK;
706 ah->ani_function = 0;
709 /* always allow mode (on/off) to be controlled */
710 ah->ani_function |= ATH9K_ANI_MODE;
713 (ah->opmode != NL80211_IFTYPE_STATION &&
714 ah->opmode != NL80211_IFTYPE_ADHOC)) {
716 * If we're scanning or in AP mode, the defaults (ini)
717 * should be in place. For an AP we assume the historical
718 * levels for this channel are probably outdated so start
719 * from defaults instead.
721 if (aniState->ofdmNoiseImmunityLevel !=
722 ATH9K_ANI_OFDM_DEF_LEVEL ||
723 aniState->cckNoiseImmunityLevel !=
724 ATH9K_ANI_CCK_DEF_LEVEL) {
725 ath_print(common, ATH_DBG_ANI,
726 "Restore defaults: opmode %u "
727 "chan %d Mhz/0x%x is_scanning=%d "
733 aniState->ofdmNoiseImmunityLevel,
734 aniState->cckNoiseImmunityLevel);
736 ath9k_hw_set_ofdm_nil(ah, ATH9K_ANI_OFDM_DEF_LEVEL);
737 ath9k_hw_set_cck_nil(ah, ATH9K_ANI_CCK_DEF_LEVEL);
741 * restore historical levels for this channel
743 ath_print(common, ATH_DBG_ANI,
744 "Restore history: opmode %u "
745 "chan %d Mhz/0x%x is_scanning=%d "
751 aniState->ofdmNoiseImmunityLevel,
752 aniState->cckNoiseImmunityLevel);
754 ath9k_hw_set_ofdm_nil(ah,
755 aniState->ofdmNoiseImmunityLevel);
756 ath9k_hw_set_cck_nil(ah,
757 aniState->cckNoiseImmunityLevel);
761 * enable phy counters if hw supports or if not, enable phy
762 * interrupts (so we can count each one)
764 ath9k_ani_restart_new(ah);
766 ENABLE_REGWRITE_BUFFER(ah);
768 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
769 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
771 REGWRITE_BUFFER_FLUSH(ah);
772 DISABLE_REGWRITE_BUFFER(ah);
775 static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
776 struct ath9k_channel *chan)
778 struct ar5416AniState *aniState;
779 struct ath_common *common = ath9k_hw_common(ah);
781 u32 phyCnt1, phyCnt2;
782 u32 ofdmPhyErrCnt, cckPhyErrCnt;
787 aniState = ah->curani;
789 listenTime = ath9k_hw_ani_get_listen_time(ah);
790 if (listenTime < 0) {
791 ah->stats.ast_ani_lneg++;
792 ath9k_ani_restart_old(ah);
796 aniState->listenTime += listenTime;
798 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
800 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
801 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
803 if (phyCnt1 < aniState->ofdmPhyErrBase ||
804 phyCnt2 < aniState->cckPhyErrBase) {
805 if (phyCnt1 < aniState->ofdmPhyErrBase) {
806 ath_print(common, ATH_DBG_ANI,
807 "phyCnt1 0x%x, resetting "
808 "counter value to 0x%x\n",
810 aniState->ofdmPhyErrBase);
811 REG_WRITE(ah, AR_PHY_ERR_1,
812 aniState->ofdmPhyErrBase);
813 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
814 AR_PHY_ERR_OFDM_TIMING);
816 if (phyCnt2 < aniState->cckPhyErrBase) {
817 ath_print(common, ATH_DBG_ANI,
818 "phyCnt2 0x%x, resetting "
819 "counter value to 0x%x\n",
821 aniState->cckPhyErrBase);
822 REG_WRITE(ah, AR_PHY_ERR_2,
823 aniState->cckPhyErrBase);
824 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
825 AR_PHY_ERR_CCK_TIMING);
830 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
831 ah->stats.ast_ani_ofdmerrs +=
832 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
833 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
835 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
836 ah->stats.ast_ani_cckerrs +=
837 cckPhyErrCnt - aniState->cckPhyErrCount;
838 aniState->cckPhyErrCount = cckPhyErrCnt;
840 if (aniState->listenTime > 5 * ah->aniperiod) {
841 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
842 aniState->ofdmTrigLow / 1000 &&
843 aniState->cckPhyErrCount <= aniState->listenTime *
844 aniState->cckTrigLow / 1000)
845 ath9k_hw_ani_lower_immunity(ah);
846 ath9k_ani_restart_old(ah);
847 } else if (aniState->listenTime > ah->aniperiod) {
848 if (aniState->ofdmPhyErrCount > aniState->listenTime *
849 aniState->ofdmTrigHigh / 1000) {
850 ath9k_hw_ani_ofdm_err_trigger_old(ah);
851 ath9k_ani_restart_old(ah);
852 } else if (aniState->cckPhyErrCount >
853 aniState->listenTime * aniState->cckTrigHigh /
855 ath9k_hw_ani_cck_err_trigger_old(ah);
856 ath9k_ani_restart_old(ah);
861 static void ath9k_hw_ani_monitor_new(struct ath_hw *ah,
862 struct ath9k_channel *chan)
864 struct ar5416AniState *aniState;
865 struct ath_common *common = ath9k_hw_common(ah);
867 u32 phyCnt1, phyCnt2;
868 u32 ofdmPhyErrCnt, cckPhyErrCnt;
869 u32 ofdmPhyErrRate, cckPhyErrRate;
874 aniState = ah->curani;
875 if (WARN_ON(!aniState))
878 listenTime = ath9k_hw_ani_get_listen_time(ah);
879 if (listenTime <= 0) {
880 ah->stats.ast_ani_lneg++;
881 /* restart ANI period if listenTime is invalid */
882 ath_print(common, ATH_DBG_ANI,
883 "listenTime=%d - on new ani monitor\n",
885 ath9k_ani_restart_new(ah);
889 aniState->listenTime += listenTime;
891 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
893 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
894 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
896 if (phyCnt1 < aniState->ofdmPhyErrBase ||
897 phyCnt2 < aniState->cckPhyErrBase) {
898 if (phyCnt1 < aniState->ofdmPhyErrBase) {
899 ath_print(common, ATH_DBG_ANI,
900 "phyCnt1 0x%x, resetting "
901 "counter value to 0x%x\n",
903 aniState->ofdmPhyErrBase);
904 REG_WRITE(ah, AR_PHY_ERR_1,
905 aniState->ofdmPhyErrBase);
906 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
907 AR_PHY_ERR_OFDM_TIMING);
909 if (phyCnt2 < aniState->cckPhyErrBase) {
910 ath_print(common, ATH_DBG_ANI,
911 "phyCnt2 0x%x, resetting "
912 "counter value to 0x%x\n",
914 aniState->cckPhyErrBase);
915 REG_WRITE(ah, AR_PHY_ERR_2,
916 aniState->cckPhyErrBase);
917 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
918 AR_PHY_ERR_CCK_TIMING);
923 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
924 ah->stats.ast_ani_ofdmerrs +=
925 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
926 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
928 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
929 ah->stats.ast_ani_cckerrs +=
930 cckPhyErrCnt - aniState->cckPhyErrCount;
931 aniState->cckPhyErrCount = cckPhyErrCnt;
933 ath_print(common, ATH_DBG_ANI,
934 "Errors: OFDM=0x%08x-0x%08x=%d "
935 "CCK=0x%08x-0x%08x=%d\n",
937 aniState->ofdmPhyErrBase,
940 aniState->cckPhyErrBase,
943 ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
944 aniState->listenTime;
945 cckPhyErrRate = aniState->cckPhyErrCount * 1000 /
946 aniState->listenTime;
948 ath_print(common, ATH_DBG_ANI,
949 "listenTime=%d OFDM:%d errs=%d/s CCK:%d "
950 "errs=%d/s ofdm_turn=%d\n",
951 listenTime, aniState->ofdmNoiseImmunityLevel,
952 ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
953 cckPhyErrRate, aniState->ofdmsTurn);
955 if (aniState->listenTime > 5 * ah->aniperiod) {
956 if (ofdmPhyErrRate <= aniState->ofdmTrigLow &&
957 cckPhyErrRate <= aniState->cckTrigLow) {
958 ath_print(common, ATH_DBG_ANI,
959 "1. listenTime=%d OFDM:%d errs=%d/s(<%d) "
960 "CCK:%d errs=%d/s(<%d) -> "
961 "ath9k_hw_ani_lower_immunity()\n",
962 aniState->listenTime,
963 aniState->ofdmNoiseImmunityLevel,
965 aniState->ofdmTrigLow,
966 aniState->cckNoiseImmunityLevel,
968 aniState->cckTrigLow);
969 ath9k_hw_ani_lower_immunity(ah);
970 aniState->ofdmsTurn = !aniState->ofdmsTurn;
972 ath_print(common, ATH_DBG_ANI,
973 "1 listenTime=%d ofdm=%d/s cck=%d/s - "
974 "calling ath9k_ani_restart_new()\n",
975 aniState->listenTime, ofdmPhyErrRate, cckPhyErrRate);
976 ath9k_ani_restart_new(ah);
977 } else if (aniState->listenTime > ah->aniperiod) {
978 /* check to see if need to raise immunity */
979 if (ofdmPhyErrRate > aniState->ofdmTrigHigh &&
980 (cckPhyErrRate <= aniState->cckTrigHigh ||
981 aniState->ofdmsTurn)) {
982 ath_print(common, ATH_DBG_ANI,
983 "2 listenTime=%d OFDM:%d errs=%d/s(>%d) -> "
984 "ath9k_hw_ani_ofdm_err_trigger_new()\n",
985 aniState->listenTime,
986 aniState->ofdmNoiseImmunityLevel,
988 aniState->ofdmTrigHigh);
989 ath9k_hw_ani_ofdm_err_trigger_new(ah);
990 ath9k_ani_restart_new(ah);
991 aniState->ofdmsTurn = false;
992 } else if (cckPhyErrRate > aniState->cckTrigHigh) {
993 ath_print(common, ATH_DBG_ANI,
994 "3 listenTime=%d CCK:%d errs=%d/s(>%d) -> "
995 "ath9k_hw_ani_cck_err_trigger_new()\n",
996 aniState->listenTime,
997 aniState->cckNoiseImmunityLevel,
999 aniState->cckTrigHigh);
1000 ath9k_hw_ani_cck_err_trigger_new(ah);
1001 ath9k_ani_restart_new(ah);
1002 aniState->ofdmsTurn = true;
1007 void ath9k_enable_mib_counters(struct ath_hw *ah)
1009 struct ath_common *common = ath9k_hw_common(ah);
1011 ath_print(common, ATH_DBG_ANI, "Enable MIB counters\n");
1013 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1015 ENABLE_REGWRITE_BUFFER(ah);
1017 REG_WRITE(ah, AR_FILT_OFDM, 0);
1018 REG_WRITE(ah, AR_FILT_CCK, 0);
1019 REG_WRITE(ah, AR_MIBC,
1020 ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
1022 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
1023 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
1025 REGWRITE_BUFFER_FLUSH(ah);
1026 DISABLE_REGWRITE_BUFFER(ah);
1029 /* Freeze the MIB counters, get the stats and then clear them */
1030 void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
1032 struct ath_common *common = ath9k_hw_common(ah);
1034 ath_print(common, ATH_DBG_ANI, "Disable MIB counters\n");
1036 REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
1037 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1038 REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
1039 REG_WRITE(ah, AR_FILT_OFDM, 0);
1040 REG_WRITE(ah, AR_FILT_CCK, 0);
1042 EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
1044 u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
1049 struct ath_common *common = ath9k_hw_common(ah);
1050 static u32 cycles, rx_clear, rx_frame, tx_frame;
1053 u32 rc = REG_READ(ah, AR_RCCNT);
1054 u32 rf = REG_READ(ah, AR_RFCNT);
1055 u32 tf = REG_READ(ah, AR_TFCNT);
1056 u32 cc = REG_READ(ah, AR_CCCNT);
1058 if (cycles == 0 || cycles > cc) {
1059 ath_print(common, ATH_DBG_ANI,
1060 "cycle counter wrap. ExtBusy = 0\n");
1063 u32 cc_d = cc - cycles;
1064 u32 rc_d = rc - rx_clear;
1065 u32 rf_d = rf - rx_frame;
1066 u32 tf_d = tf - tx_frame;
1069 *rxc_pcnt = rc_d * 100 / cc_d;
1070 *rxf_pcnt = rf_d * 100 / cc_d;
1071 *txf_pcnt = tf_d * 100 / cc_d;
1086 * Process a MIB interrupt. We may potentially be invoked because
1087 * any of the MIB counters overflow/trigger so don't assume we're
1088 * here because a PHY error counter triggered.
1090 static void ath9k_hw_proc_mib_event_old(struct ath_hw *ah)
1092 u32 phyCnt1, phyCnt2;
1094 /* Reset these counters regardless */
1095 REG_WRITE(ah, AR_FILT_OFDM, 0);
1096 REG_WRITE(ah, AR_FILT_CCK, 0);
1097 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
1098 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
1100 /* Clear the mib counters and save them in the stats */
1101 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1105 * We must always clear the interrupt cause by
1106 * resetting the phy error regs.
1108 REG_WRITE(ah, AR_PHY_ERR_1, 0);
1109 REG_WRITE(ah, AR_PHY_ERR_2, 0);
1113 /* NB: these are not reset-on-read */
1114 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
1115 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
1116 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
1117 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
1118 struct ar5416AniState *aniState = ah->curani;
1119 u32 ofdmPhyErrCnt, cckPhyErrCnt;
1121 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
1122 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
1123 ah->stats.ast_ani_ofdmerrs +=
1124 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
1125 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
1127 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
1128 ah->stats.ast_ani_cckerrs +=
1129 cckPhyErrCnt - aniState->cckPhyErrCount;
1130 aniState->cckPhyErrCount = cckPhyErrCnt;
1133 * NB: figure out which counter triggered. If both
1134 * trigger we'll only deal with one as the processing
1135 * clobbers the error counter so the trigger threshold
1136 * check will never be true.
1138 if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
1139 ath9k_hw_ani_ofdm_err_trigger_new(ah);
1140 if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
1141 ath9k_hw_ani_cck_err_trigger_old(ah);
1142 /* NB: always restart to insure the h/w counters are reset */
1143 ath9k_ani_restart_old(ah);
1148 * Process a MIB interrupt. We may potentially be invoked because
1149 * any of the MIB counters overflow/trigger so don't assume we're
1150 * here because a PHY error counter triggered.
1152 static void ath9k_hw_proc_mib_event_new(struct ath_hw *ah)
1154 u32 phyCnt1, phyCnt2;
1156 /* Reset these counters regardless */
1157 REG_WRITE(ah, AR_FILT_OFDM, 0);
1158 REG_WRITE(ah, AR_FILT_CCK, 0);
1159 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
1160 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
1162 /* Clear the mib counters and save them in the stats */
1163 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1167 * We must always clear the interrupt cause by
1168 * resetting the phy error regs.
1170 REG_WRITE(ah, AR_PHY_ERR_1, 0);
1171 REG_WRITE(ah, AR_PHY_ERR_2, 0);
1175 /* NB: these are not reset-on-read */
1176 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
1177 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
1179 /* NB: always restart to insure the h/w counters are reset */
1180 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
1181 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK))
1182 ath9k_ani_restart_new(ah);
1185 void ath9k_hw_ani_setup(struct ath_hw *ah)
1189 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
1190 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
1191 const int coarseLow[] = { -64, -64, -64, -64, -70 };
1192 const int firpwr[] = { -78, -78, -78, -78, -80 };
1194 for (i = 0; i < 5; i++) {
1195 ah->totalSizeDesired[i] = totalSizeDesired[i];
1196 ah->coarse_high[i] = coarseHigh[i];
1197 ah->coarse_low[i] = coarseLow[i];
1198 ah->firpwr[i] = firpwr[i];
1202 void ath9k_hw_ani_init(struct ath_hw *ah)
1204 struct ath_common *common = ath9k_hw_common(ah);
1207 ath_print(common, ATH_DBG_ANI, "Initialize ANI\n");
1209 memset(ah->ani, 0, sizeof(ah->ani));
1210 for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
1211 if (AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani) {
1212 ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH_NEW;
1213 ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW_NEW;
1215 ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH_NEW;
1216 ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW_NEW;
1218 ah->ani[i].spurImmunityLevel =
1219 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1221 ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1223 ah->ani[i].ofdmPhyErrBase = 0;
1224 ah->ani[i].cckPhyErrBase = 0;
1226 if (AR_SREV_9300_20_OR_LATER(ah))
1227 ah->ani[i].mrcCCKOff =
1228 !ATH9K_ANI_ENABLE_MRC_CCK;
1230 ah->ani[i].mrcCCKOff = true;
1232 ah->ani[i].ofdmsTurn = true;
1234 ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH_OLD;
1235 ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW_OLD;
1237 ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH_OLD;
1238 ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW_OLD;
1240 ah->ani[i].spurImmunityLevel =
1241 ATH9K_ANI_SPUR_IMMUNE_LVL_OLD;
1242 ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL_OLD;
1244 ah->ani[i].ofdmPhyErrBase =
1245 AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH_OLD;
1246 ah->ani[i].cckPhyErrBase =
1247 AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH_OLD;
1248 ah->ani[i].cckWeakSigThreshold =
1249 ATH9K_ANI_CCK_WEAK_SIG_THR;
1252 ah->ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
1253 ah->ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
1254 ah->ani[i].ofdmWeakSigDetectOff =
1255 !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1256 ah->ani[i].cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
1260 * since we expect some ongoing maintenance on the tables, let's sanity
1261 * check here default level should not modify INI setting.
1263 if (AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani) {
1264 const struct ani_ofdm_level_entry *entry_ofdm;
1265 const struct ani_cck_level_entry *entry_cck;
1267 entry_ofdm = &ofdm_level_table[ATH9K_ANI_OFDM_DEF_LEVEL];
1268 entry_cck = &cck_level_table[ATH9K_ANI_CCK_DEF_LEVEL];
1270 ah->aniperiod = ATH9K_ANI_PERIOD_NEW;
1271 ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_NEW;
1273 ah->aniperiod = ATH9K_ANI_PERIOD_OLD;
1274 ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_OLD;
1277 ath_print(common, ATH_DBG_ANI,
1278 "Setting OfdmErrBase = 0x%08x\n",
1279 ah->ani[0].ofdmPhyErrBase);
1280 ath_print(common, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
1281 ah->ani[0].cckPhyErrBase);
1283 ENABLE_REGWRITE_BUFFER(ah);
1285 REG_WRITE(ah, AR_PHY_ERR_1, ah->ani[0].ofdmPhyErrBase);
1286 REG_WRITE(ah, AR_PHY_ERR_2, ah->ani[0].cckPhyErrBase);
1288 REGWRITE_BUFFER_FLUSH(ah);
1289 DISABLE_REGWRITE_BUFFER(ah);
1291 ath9k_enable_mib_counters(ah);
1293 if (ah->config.enable_ani)
1294 ah->proc_phyerr |= HAL_PROCESS_ANI;
1297 void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah)
1299 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
1300 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
1302 priv_ops->ani_reset = ath9k_ani_reset_old;
1303 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_old;
1305 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_old;
1306 ops->ani_monitor = ath9k_hw_ani_monitor_old;
1308 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v1\n");
1311 void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah)
1313 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
1314 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
1316 priv_ops->ani_reset = ath9k_ani_reset_new;
1317 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_new;
1319 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_new;
1320 ops->ani_monitor = ath9k_hw_ani_monitor_new;
1322 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v2\n");