17 #include <linux/kernel.h>
18 #include <linux/export.h>
52 #define ATH9K_ANI_OFDM_NUM_LEVEL \
53 ARRAY_SIZE(ofdm_level_table)
54 #define ATH9K_ANI_OFDM_MAX_LEVEL \
55 (ATH9K_ANI_OFDM_NUM_LEVEL-1)
56 #define ATH9K_ANI_OFDM_DEF_LEVEL \
98 #define ATH9K_ANI_CCK_NUM_LEVEL \
99 ARRAY_SIZE(cck_level_table)
100 #define ATH9K_ANI_CCK_MAX_LEVEL \
101 (ATH9K_ANI_CCK_NUM_LEVEL-1)
102 #define ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI \
103 (ATH9K_ANI_CCK_NUM_LEVEL-3)
104 #define ATH9K_ANI_CCK_DEF_LEVEL \
107 static void ath9k_hw_update_mibstats(
struct ath_hw *
ah,
117 static void ath9k_ani_restart(
struct ath_hw *
ah)
136 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
143 static void ath9k_hw_set_ofdm_nil(
struct ath_hw *ah,
u8 immunityLevel,
152 ath_dbg(common, ANI,
"**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
164 ath9k_hw_ani_control(ah,
170 ath9k_hw_ani_control(ah,
180 ath9k_hw_ani_control(ah,
193 static void ath9k_hw_ani_ofdm_err_trigger(
struct ath_hw *ah)
209 static void ath9k_hw_set_cck_nil(
struct ath_hw *ah,
u_int8_t immunityLevel,
213 struct ath_common *common = ath9k_hw_common(ah);
217 ath_dbg(common, ANI,
"**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
235 ath9k_hw_ani_control(ah,
244 ath9k_hw_ani_control(ah,
249 static void ath9k_hw_ani_cck_err_trigger(
struct ath_hw *ah)
267 static void ath9k_hw_ani_lower_immunity(
struct ath_hw *ah)
296 struct ath_common *common = ath9k_hw_common(ah);
297 int ofdm_nil, cck_nil;
303 ah->
stats.ast_ani_reset++;
338 "Restore defaults: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
354 "Restore history: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
362 ath9k_hw_set_ofdm_nil(ah, ofdm_nil, is_scanning);
363 ath9k_hw_set_cck_nil(ah, cck_nil, is_scanning);
369 ath9k_ani_restart(ah);
379 static bool ath9k_hw_ani_read_counters(
struct ath_hw *ah)
381 struct ath_common *common = ath9k_hw_common(ah);
383 u32 phyCnt1, phyCnt2;
389 if (listenTime <= 0) {
390 ah->
stats.ast_ani_lneg_or_lzero++;
391 ath9k_ani_restart(ah);
397 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
414 struct ath_common *common = ath9k_hw_common(ah);
415 u32 ofdmPhyErrRate, cckPhyErrRate;
424 if (!ath9k_hw_ani_read_counters(ah))
433 "listenTime=%d OFDM:%d errs=%d/s CCK:%d errs=%d/s ofdm_turn=%d\n",
440 if (cckPhyErrRate < ah->
config.cck_trig_low &&
441 ofdmPhyErrRate < ah->
config.ofdm_trig_low) {
442 ath9k_hw_ani_lower_immunity(ah);
444 }
else if (ofdmPhyErrRate > ah->
config.ofdm_trig_high) {
445 ath9k_hw_ani_ofdm_err_trigger(ah);
447 }
else if (cckPhyErrRate > ah->
config.cck_trig_high) {
448 ath9k_hw_ani_cck_err_trigger(ah);
451 ath9k_ani_restart(ah);
458 struct ath_common *common = ath9k_hw_common(ah);
460 ath_dbg(common, ANI,
"Enable MIB counters\n");
462 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
480 struct ath_common *common = ath9k_hw_common(ah);
482 ath_dbg(common, ANI,
"Disable MIB counters\n");
485 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
496 static const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
497 static const int coarseHigh[] = { -14, -14, -14, -14, -12 };
498 static const int coarseLow[] = { -64, -64, -64, -64, -70 };
499 static const int firpwr[] = { -78, -78, -78, -78, -80 };
501 for (i = 0; i < 5; i++) {
511 struct ath_common *common = ath9k_hw_common(ah);
514 ath_dbg(common, ANI,
"Initialize ANI\n");
548 if (ah->
config.enable_ani)
551 ath9k_ani_restart(ah);