ani.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  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.
  7. *
  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.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/export.h>
  18. #include "hw.h"
  19. #include "hw-ops.h"
  20. struct ani_ofdm_level_entry {
  21. int spur_immunity_level;
  22. int fir_step_level;
  23. int ofdm_weak_signal_on;
  24. };
  25. /* values here are relative to the INI */
  26. /*
  27. * Legend:
  28. *
  29. * SI: Spur immunity
  30. * FS: FIR Step
  31. * WS: OFDM / CCK Weak Signal detection
  32. * MRC-CCK: Maximal Ratio Combining for CCK
  33. */
  34. static const struct ani_ofdm_level_entry ofdm_level_table[] = {
  35. /* SI FS WS */
  36. { 0, 0, 1 }, /* lvl 0 */
  37. { 1, 1, 1 }, /* lvl 1 */
  38. { 2, 2, 1 }, /* lvl 2 */
  39. { 3, 2, 1 }, /* lvl 3 (default) */
  40. { 4, 3, 1 }, /* lvl 4 */
  41. { 5, 4, 1 }, /* lvl 5 */
  42. { 6, 5, 1 }, /* lvl 6 */
  43. { 7, 6, 1 }, /* lvl 7 */
  44. { 7, 6, 0 }, /* lvl 8 */
  45. { 7, 7, 0 } /* lvl 9 */
  46. };
  47. #define ATH9K_ANI_OFDM_NUM_LEVEL \
  48. ARRAY_SIZE(ofdm_level_table)
  49. #define ATH9K_ANI_OFDM_MAX_LEVEL \
  50. (ATH9K_ANI_OFDM_NUM_LEVEL-1)
  51. #define ATH9K_ANI_OFDM_DEF_LEVEL \
  52. 3 /* default level - matches the INI settings */
  53. /*
  54. * MRC (Maximal Ratio Combining) has always been used with multi-antenna ofdm.
  55. * With OFDM for single stream you just add up all antenna inputs, you're
  56. * only interested in what you get after FFT. Signal aligment is also not
  57. * required for OFDM because any phase difference adds up in the frequency
  58. * domain.
  59. *
  60. * MRC requires extra work for use with CCK. You need to align the antenna
  61. * signals from the different antenna before you can add the signals together.
  62. * You need aligment of signals as CCK is in time domain, so addition can cancel
  63. * your signal completely if phase is 180 degrees (think of adding sine waves).
  64. * You also need to remove noise before the addition and this is where ANI
  65. * MRC CCK comes into play. One of the antenna inputs may be stronger but
  66. * lower SNR, so just adding after alignment can be dangerous.
  67. *
  68. * Regardless of alignment in time, the antenna signals add constructively after
  69. * FFT and improve your reception. For more information:
  70. *
  71. * http://en.wikipedia.org/wiki/Maximal-ratio_combining
  72. */
  73. struct ani_cck_level_entry {
  74. int fir_step_level;
  75. int mrc_cck_on;
  76. };
  77. static const struct ani_cck_level_entry cck_level_table[] = {
  78. /* FS MRC-CCK */
  79. { 0, 1 }, /* lvl 0 */
  80. { 1, 1 }, /* lvl 1 */
  81. { 2, 1 }, /* lvl 2 (default) */
  82. { 3, 1 }, /* lvl 3 */
  83. { 4, 0 }, /* lvl 4 */
  84. { 5, 0 }, /* lvl 5 */
  85. { 6, 0 }, /* lvl 6 */
  86. { 6, 0 }, /* lvl 7 (only for high rssi) */
  87. { 7, 0 } /* lvl 8 (only for high rssi) */
  88. };
  89. #define ATH9K_ANI_CCK_NUM_LEVEL \
  90. ARRAY_SIZE(cck_level_table)
  91. #define ATH9K_ANI_CCK_MAX_LEVEL \
  92. (ATH9K_ANI_CCK_NUM_LEVEL-1)
  93. #define ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI \
  94. (ATH9K_ANI_CCK_NUM_LEVEL-3)
  95. #define ATH9K_ANI_CCK_DEF_LEVEL \
  96. 2 /* default level - matches the INI settings */
  97. static void ath9k_hw_update_mibstats(struct ath_hw *ah,
  98. struct ath9k_mib_stats *stats)
  99. {
  100. stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
  101. stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
  102. stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
  103. stats->rts_good += REG_READ(ah, AR_RTS_OK);
  104. stats->beacons += REG_READ(ah, AR_BEACON_CNT);
  105. }
  106. static void ath9k_ani_restart(struct ath_hw *ah)
  107. {
  108. struct ar5416AniState *aniState;
  109. if (!DO_ANI(ah))
  110. return;
  111. aniState = &ah->curchan->ani;
  112. aniState->listenTime = 0;
  113. ENABLE_REGWRITE_BUFFER(ah);
  114. REG_WRITE(ah, AR_PHY_ERR_1, 0);
  115. REG_WRITE(ah, AR_PHY_ERR_2, 0);
  116. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  117. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  118. REGWRITE_BUFFER_FLUSH(ah);
  119. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  120. aniState->ofdmPhyErrCount = 0;
  121. aniState->cckPhyErrCount = 0;
  122. }
  123. /* Adjust the OFDM Noise Immunity Level */
  124. static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
  125. {
  126. struct ar5416AniState *aniState = &ah->curchan->ani;
  127. struct ath_common *common = ath9k_hw_common(ah);
  128. const struct ani_ofdm_level_entry *entry_ofdm;
  129. const struct ani_cck_level_entry *entry_cck;
  130. bool weak_sig;
  131. ath_dbg(common, ANI, "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
  132. aniState->ofdmNoiseImmunityLevel,
  133. immunityLevel, BEACON_RSSI(ah),
  134. aniState->rssiThrLow, aniState->rssiThrHigh);
  135. if (aniState->update_ani)
  136. aniState->ofdmNoiseImmunityLevel = immunityLevel;
  137. entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
  138. entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
  139. if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level)
  140. ath9k_hw_ani_control(ah,
  141. ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
  142. entry_ofdm->spur_immunity_level);
  143. if (aniState->firstepLevel != entry_ofdm->fir_step_level &&
  144. entry_ofdm->fir_step_level >= entry_cck->fir_step_level)
  145. ath9k_hw_ani_control(ah,
  146. ATH9K_ANI_FIRSTEP_LEVEL,
  147. entry_ofdm->fir_step_level);
  148. weak_sig = entry_ofdm->ofdm_weak_signal_on;
  149. if (ah->opmode == NL80211_IFTYPE_STATION &&
  150. BEACON_RSSI(ah) <= aniState->rssiThrHigh)
  151. weak_sig = true;
  152. if (aniState->ofdmWeakSigDetect != weak_sig)
  153. ath9k_hw_ani_control(ah,
  154. ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
  155. entry_ofdm->ofdm_weak_signal_on);
  156. if (aniState->ofdmNoiseImmunityLevel >= ATH9K_ANI_OFDM_DEF_LEVEL) {
  157. ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
  158. ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI;
  159. } else {
  160. ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI;
  161. ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
  162. }
  163. }
  164. static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
  165. {
  166. struct ar5416AniState *aniState;
  167. if (!DO_ANI(ah))
  168. return;
  169. aniState = &ah->curchan->ani;
  170. if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
  171. ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1);
  172. }
  173. /*
  174. * Set the ANI settings to match an CCK level.
  175. */
  176. static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel)
  177. {
  178. struct ar5416AniState *aniState = &ah->curchan->ani;
  179. struct ath_common *common = ath9k_hw_common(ah);
  180. const struct ani_ofdm_level_entry *entry_ofdm;
  181. const struct ani_cck_level_entry *entry_cck;
  182. ath_dbg(common, ANI, "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
  183. aniState->cckNoiseImmunityLevel, immunityLevel,
  184. BEACON_RSSI(ah), aniState->rssiThrLow,
  185. aniState->rssiThrHigh);
  186. if (ah->opmode == NL80211_IFTYPE_STATION &&
  187. BEACON_RSSI(ah) <= aniState->rssiThrLow &&
  188. immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
  189. immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
  190. if (aniState->update_ani)
  191. aniState->cckNoiseImmunityLevel = immunityLevel;
  192. entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
  193. entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
  194. if (aniState->firstepLevel != entry_cck->fir_step_level &&
  195. entry_cck->fir_step_level >= entry_ofdm->fir_step_level)
  196. ath9k_hw_ani_control(ah,
  197. ATH9K_ANI_FIRSTEP_LEVEL,
  198. entry_cck->fir_step_level);
  199. /* Skip MRC CCK for pre AR9003 families */
  200. if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9485(ah))
  201. return;
  202. if (aniState->mrcCCK != entry_cck->mrc_cck_on)
  203. ath9k_hw_ani_control(ah,
  204. ATH9K_ANI_MRC_CCK,
  205. entry_cck->mrc_cck_on);
  206. }
  207. static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
  208. {
  209. struct ar5416AniState *aniState;
  210. if (!DO_ANI(ah))
  211. return;
  212. aniState = &ah->curchan->ani;
  213. if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
  214. ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1);
  215. }
  216. /*
  217. * only lower either OFDM or CCK errors per turn
  218. * we lower the other one next time
  219. */
  220. static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
  221. {
  222. struct ar5416AniState *aniState;
  223. aniState = &ah->curchan->ani;
  224. /* lower OFDM noise immunity */
  225. if (aniState->ofdmNoiseImmunityLevel > 0 &&
  226. (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
  227. ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1);
  228. return;
  229. }
  230. /* lower CCK noise immunity */
  231. if (aniState->cckNoiseImmunityLevel > 0)
  232. ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
  233. }
  234. /*
  235. * Restore the ANI parameters in the HAL and reset the statistics.
  236. * This routine should be called for every hardware reset and for
  237. * every channel change.
  238. */
  239. void ath9k_ani_reset(struct ath_hw *ah, bool is_scanning)
  240. {
  241. struct ar5416AniState *aniState = &ah->curchan->ani;
  242. struct ath9k_channel *chan = ah->curchan;
  243. struct ath_common *common = ath9k_hw_common(ah);
  244. int ofdm_nil, cck_nil;
  245. if (!DO_ANI(ah))
  246. return;
  247. BUG_ON(aniState == NULL);
  248. ah->stats.ast_ani_reset++;
  249. /* only allow a subset of functions in AP mode */
  250. if (ah->opmode == NL80211_IFTYPE_AP) {
  251. if (IS_CHAN_2GHZ(chan)) {
  252. ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
  253. ATH9K_ANI_FIRSTEP_LEVEL);
  254. if (AR_SREV_9300_20_OR_LATER(ah))
  255. ah->ani_function |= ATH9K_ANI_MRC_CCK;
  256. } else
  257. ah->ani_function = 0;
  258. }
  259. /* always allow mode (on/off) to be controlled */
  260. ah->ani_function |= ATH9K_ANI_MODE;
  261. ofdm_nil = max_t(int, ATH9K_ANI_OFDM_DEF_LEVEL,
  262. aniState->ofdmNoiseImmunityLevel);
  263. cck_nil = max_t(int, ATH9K_ANI_CCK_DEF_LEVEL,
  264. aniState->cckNoiseImmunityLevel);
  265. if (is_scanning ||
  266. (ah->opmode != NL80211_IFTYPE_STATION &&
  267. ah->opmode != NL80211_IFTYPE_ADHOC)) {
  268. /*
  269. * If we're scanning or in AP mode, the defaults (ini)
  270. * should be in place. For an AP we assume the historical
  271. * levels for this channel are probably outdated so start
  272. * from defaults instead.
  273. */
  274. if (aniState->ofdmNoiseImmunityLevel !=
  275. ATH9K_ANI_OFDM_DEF_LEVEL ||
  276. aniState->cckNoiseImmunityLevel !=
  277. ATH9K_ANI_CCK_DEF_LEVEL) {
  278. ath_dbg(common, ANI,
  279. "Restore defaults: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
  280. ah->opmode,
  281. chan->channel,
  282. chan->channelFlags,
  283. is_scanning,
  284. aniState->ofdmNoiseImmunityLevel,
  285. aniState->cckNoiseImmunityLevel);
  286. aniState->update_ani = false;
  287. ofdm_nil = ATH9K_ANI_OFDM_DEF_LEVEL;
  288. cck_nil = ATH9K_ANI_CCK_DEF_LEVEL;
  289. }
  290. } else {
  291. /*
  292. * restore historical levels for this channel
  293. */
  294. ath_dbg(common, ANI,
  295. "Restore history: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
  296. ah->opmode,
  297. chan->channel,
  298. chan->channelFlags,
  299. is_scanning,
  300. aniState->ofdmNoiseImmunityLevel,
  301. aniState->cckNoiseImmunityLevel);
  302. aniState->update_ani = true;
  303. }
  304. ath9k_hw_set_ofdm_nil(ah, ofdm_nil);
  305. ath9k_hw_set_cck_nil(ah, cck_nil);
  306. /*
  307. * enable phy counters if hw supports or if not, enable phy
  308. * interrupts (so we can count each one)
  309. */
  310. ath9k_ani_restart(ah);
  311. ENABLE_REGWRITE_BUFFER(ah);
  312. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  313. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  314. REGWRITE_BUFFER_FLUSH(ah);
  315. }
  316. static bool ath9k_hw_ani_read_counters(struct ath_hw *ah)
  317. {
  318. struct ath_common *common = ath9k_hw_common(ah);
  319. struct ar5416AniState *aniState = &ah->curchan->ani;
  320. u32 phyCnt1, phyCnt2;
  321. int32_t listenTime;
  322. ath_hw_cycle_counters_update(common);
  323. listenTime = ath_hw_get_listen_time(common);
  324. if (listenTime <= 0) {
  325. ah->stats.ast_ani_lneg_or_lzero++;
  326. ath9k_ani_restart(ah);
  327. return false;
  328. }
  329. aniState->listenTime += listenTime;
  330. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  331. phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
  332. phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
  333. ah->stats.ast_ani_ofdmerrs += phyCnt1 - aniState->ofdmPhyErrCount;
  334. aniState->ofdmPhyErrCount = phyCnt1;
  335. ah->stats.ast_ani_cckerrs += phyCnt2 - aniState->cckPhyErrCount;
  336. aniState->cckPhyErrCount = phyCnt2;
  337. return true;
  338. }
  339. void ath9k_hw_ani_monitor(struct ath_hw *ah, struct ath9k_channel *chan)
  340. {
  341. struct ar5416AniState *aniState;
  342. struct ath_common *common = ath9k_hw_common(ah);
  343. u32 ofdmPhyErrRate, cckPhyErrRate;
  344. if (!DO_ANI(ah))
  345. return;
  346. aniState = &ah->curchan->ani;
  347. if (WARN_ON(!aniState))
  348. return;
  349. if (!ath9k_hw_ani_read_counters(ah))
  350. return;
  351. ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
  352. aniState->listenTime;
  353. cckPhyErrRate = aniState->cckPhyErrCount * 1000 /
  354. aniState->listenTime;
  355. ath_dbg(common, ANI,
  356. "listenTime=%d OFDM:%d errs=%d/s CCK:%d errs=%d/s ofdm_turn=%d\n",
  357. aniState->listenTime,
  358. aniState->ofdmNoiseImmunityLevel,
  359. ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
  360. cckPhyErrRate, aniState->ofdmsTurn);
  361. if (aniState->listenTime > ah->aniperiod) {
  362. if (cckPhyErrRate < ah->config.cck_trig_low &&
  363. ofdmPhyErrRate < ah->config.ofdm_trig_low) {
  364. ath9k_hw_ani_lower_immunity(ah);
  365. aniState->ofdmsTurn = !aniState->ofdmsTurn;
  366. } else if (ofdmPhyErrRate > ah->config.ofdm_trig_high) {
  367. ath9k_hw_ani_ofdm_err_trigger(ah);
  368. aniState->ofdmsTurn = false;
  369. } else if (cckPhyErrRate > ah->config.cck_trig_high) {
  370. ath9k_hw_ani_cck_err_trigger(ah);
  371. aniState->ofdmsTurn = true;
  372. }
  373. ath9k_ani_restart(ah);
  374. }
  375. }
  376. EXPORT_SYMBOL(ath9k_hw_ani_monitor);
  377. void ath9k_enable_mib_counters(struct ath_hw *ah)
  378. {
  379. struct ath_common *common = ath9k_hw_common(ah);
  380. ath_dbg(common, ANI, "Enable MIB counters\n");
  381. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  382. ENABLE_REGWRITE_BUFFER(ah);
  383. REG_WRITE(ah, AR_FILT_OFDM, 0);
  384. REG_WRITE(ah, AR_FILT_CCK, 0);
  385. REG_WRITE(ah, AR_MIBC,
  386. ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
  387. & 0x0f);
  388. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  389. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  390. REGWRITE_BUFFER_FLUSH(ah);
  391. }
  392. /* Freeze the MIB counters, get the stats and then clear them */
  393. void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
  394. {
  395. struct ath_common *common = ath9k_hw_common(ah);
  396. ath_dbg(common, ANI, "Disable MIB counters\n");
  397. REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
  398. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  399. REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
  400. REG_WRITE(ah, AR_FILT_OFDM, 0);
  401. REG_WRITE(ah, AR_FILT_CCK, 0);
  402. }
  403. EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
  404. void ath9k_hw_ani_setup(struct ath_hw *ah)
  405. {
  406. int i;
  407. static const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
  408. static const int coarseHigh[] = { -14, -14, -14, -14, -12 };
  409. static const int coarseLow[] = { -64, -64, -64, -64, -70 };
  410. static const int firpwr[] = { -78, -78, -78, -78, -80 };
  411. for (i = 0; i < 5; i++) {
  412. ah->totalSizeDesired[i] = totalSizeDesired[i];
  413. ah->coarse_high[i] = coarseHigh[i];
  414. ah->coarse_low[i] = coarseLow[i];
  415. ah->firpwr[i] = firpwr[i];
  416. }
  417. }
  418. void ath9k_hw_ani_init(struct ath_hw *ah)
  419. {
  420. struct ath_common *common = ath9k_hw_common(ah);
  421. int i;
  422. ath_dbg(common, ANI, "Initialize ANI\n");
  423. ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
  424. ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
  425. ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH;
  426. ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW;
  427. for (i = 0; i < ARRAY_SIZE(ah->channels); i++) {
  428. struct ath9k_channel *chan = &ah->channels[i];
  429. struct ar5416AniState *ani = &chan->ani;
  430. ani->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  431. ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  432. ani->mrcCCK = AR_SREV_9300_20_OR_LATER(ah) ? true : false;
  433. ani->ofdmsTurn = true;
  434. ani->rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
  435. ani->rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
  436. ani->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  437. ani->cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
  438. ani->ofdmNoiseImmunityLevel = ATH9K_ANI_OFDM_DEF_LEVEL;
  439. ani->update_ani = false;
  440. }
  441. /*
  442. * since we expect some ongoing maintenance on the tables, let's sanity
  443. * check here default level should not modify INI setting.
  444. */
  445. ah->aniperiod = ATH9K_ANI_PERIOD;
  446. ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL;
  447. if (ah->config.enable_ani)
  448. ah->proc_phyerr |= HAL_PROCESS_ANI;
  449. ath9k_ani_restart(ah);
  450. ath9k_enable_mib_counters(ah);
  451. }