ani.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. struct ath_common *common = ath9k_hw_common(ah);
  110. u32 ofdm_base = 0, cck_base = 0;
  111. if (!DO_ANI(ah))
  112. return;
  113. aniState = &ah->curchan->ani;
  114. aniState->listenTime = 0;
  115. ath_dbg(common, ANI, "Writing ofdmbase=%u cckbase=%u\n",
  116. ofdm_base, cck_base);
  117. ENABLE_REGWRITE_BUFFER(ah);
  118. REG_WRITE(ah, AR_PHY_ERR_1, ofdm_base);
  119. REG_WRITE(ah, AR_PHY_ERR_2, cck_base);
  120. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  121. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  122. REGWRITE_BUFFER_FLUSH(ah);
  123. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  124. aniState->ofdmPhyErrCount = 0;
  125. aniState->cckPhyErrCount = 0;
  126. }
  127. /* Adjust the OFDM Noise Immunity Level */
  128. static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
  129. {
  130. struct ar5416AniState *aniState = &ah->curchan->ani;
  131. struct ath_common *common = ath9k_hw_common(ah);
  132. const struct ani_ofdm_level_entry *entry_ofdm;
  133. const struct ani_cck_level_entry *entry_cck;
  134. bool weak_sig;
  135. ath_dbg(common, ANI, "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
  136. aniState->ofdmNoiseImmunityLevel,
  137. immunityLevel, BEACON_RSSI(ah),
  138. aniState->rssiThrLow, aniState->rssiThrHigh);
  139. if (aniState->update_ani)
  140. aniState->ofdmNoiseImmunityLevel =
  141. (immunityLevel > ATH9K_ANI_OFDM_DEF_LEVEL) ?
  142. immunityLevel : ATH9K_ANI_OFDM_DEF_LEVEL;
  143. entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
  144. entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
  145. if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level)
  146. ath9k_hw_ani_control(ah,
  147. ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
  148. entry_ofdm->spur_immunity_level);
  149. if (aniState->firstepLevel != entry_ofdm->fir_step_level &&
  150. entry_ofdm->fir_step_level >= entry_cck->fir_step_level)
  151. ath9k_hw_ani_control(ah,
  152. ATH9K_ANI_FIRSTEP_LEVEL,
  153. entry_ofdm->fir_step_level);
  154. weak_sig = entry_ofdm->ofdm_weak_signal_on;
  155. if (ah->opmode == NL80211_IFTYPE_STATION &&
  156. BEACON_RSSI(ah) <= aniState->rssiThrHigh)
  157. weak_sig = true;
  158. if (aniState->ofdmWeakSigDetect != weak_sig)
  159. ath9k_hw_ani_control(ah,
  160. ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
  161. entry_ofdm->ofdm_weak_signal_on);
  162. }
  163. static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
  164. {
  165. struct ar5416AniState *aniState;
  166. if (!DO_ANI(ah))
  167. return;
  168. aniState = &ah->curchan->ani;
  169. if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
  170. ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1);
  171. }
  172. /*
  173. * Set the ANI settings to match an CCK level.
  174. */
  175. static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel)
  176. {
  177. struct ar5416AniState *aniState = &ah->curchan->ani;
  178. struct ath_common *common = ath9k_hw_common(ah);
  179. const struct ani_ofdm_level_entry *entry_ofdm;
  180. const struct ani_cck_level_entry *entry_cck;
  181. ath_dbg(common, ANI, "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
  182. aniState->cckNoiseImmunityLevel, immunityLevel,
  183. BEACON_RSSI(ah), aniState->rssiThrLow,
  184. aniState->rssiThrHigh);
  185. if (ah->opmode == NL80211_IFTYPE_STATION &&
  186. BEACON_RSSI(ah) <= aniState->rssiThrLow &&
  187. immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
  188. immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
  189. if (aniState->update_ani)
  190. aniState->cckNoiseImmunityLevel =
  191. (immunityLevel > ATH9K_ANI_CCK_DEF_LEVEL) ?
  192. immunityLevel : ATH9K_ANI_CCK_DEF_LEVEL;
  193. entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
  194. entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
  195. if (aniState->firstepLevel != entry_cck->fir_step_level &&
  196. entry_cck->fir_step_level >= entry_ofdm->fir_step_level)
  197. ath9k_hw_ani_control(ah,
  198. ATH9K_ANI_FIRSTEP_LEVEL,
  199. entry_cck->fir_step_level);
  200. /* Skip MRC CCK for pre AR9003 families */
  201. if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9485(ah))
  202. return;
  203. if (aniState->mrcCCKOff == entry_cck->mrc_cck_on)
  204. ath9k_hw_ani_control(ah,
  205. ATH9K_ANI_MRC_CCK,
  206. entry_cck->mrc_cck_on);
  207. }
  208. static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
  209. {
  210. struct ar5416AniState *aniState;
  211. if (!DO_ANI(ah))
  212. return;
  213. aniState = &ah->curchan->ani;
  214. if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
  215. ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1);
  216. }
  217. /*
  218. * only lower either OFDM or CCK errors per turn
  219. * we lower the other one next time
  220. */
  221. static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
  222. {
  223. struct ar5416AniState *aniState;
  224. aniState = &ah->curchan->ani;
  225. /* lower OFDM noise immunity */
  226. if (aniState->ofdmNoiseImmunityLevel > 0 &&
  227. (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
  228. ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1);
  229. return;
  230. }
  231. /* lower CCK noise immunity */
  232. if (aniState->cckNoiseImmunityLevel > 0)
  233. ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
  234. }
  235. /*
  236. * Restore the ANI parameters in the HAL and reset the statistics.
  237. * This routine should be called for every hardware reset and for
  238. * every channel change.
  239. */
  240. void ath9k_ani_reset(struct ath_hw *ah, bool is_scanning)
  241. {
  242. struct ar5416AniState *aniState = &ah->curchan->ani;
  243. struct ath9k_channel *chan = ah->curchan;
  244. struct ath_common *common = ath9k_hw_common(ah);
  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. if (is_scanning ||
  262. (ah->opmode != NL80211_IFTYPE_STATION &&
  263. ah->opmode != NL80211_IFTYPE_ADHOC)) {
  264. /*
  265. * If we're scanning or in AP mode, the defaults (ini)
  266. * should be in place. For an AP we assume the historical
  267. * levels for this channel are probably outdated so start
  268. * from defaults instead.
  269. */
  270. if (aniState->ofdmNoiseImmunityLevel !=
  271. ATH9K_ANI_OFDM_DEF_LEVEL ||
  272. aniState->cckNoiseImmunityLevel !=
  273. ATH9K_ANI_CCK_DEF_LEVEL) {
  274. ath_dbg(common, ANI,
  275. "Restore defaults: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
  276. ah->opmode,
  277. chan->channel,
  278. chan->channelFlags,
  279. is_scanning,
  280. aniState->ofdmNoiseImmunityLevel,
  281. aniState->cckNoiseImmunityLevel);
  282. aniState->update_ani = false;
  283. ath9k_hw_set_ofdm_nil(ah, ATH9K_ANI_OFDM_DEF_LEVEL);
  284. ath9k_hw_set_cck_nil(ah, ATH9K_ANI_CCK_DEF_LEVEL);
  285. }
  286. } else {
  287. /*
  288. * restore historical levels for this channel
  289. */
  290. ath_dbg(common, ANI,
  291. "Restore history: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
  292. ah->opmode,
  293. chan->channel,
  294. chan->channelFlags,
  295. is_scanning,
  296. aniState->ofdmNoiseImmunityLevel,
  297. aniState->cckNoiseImmunityLevel);
  298. aniState->update_ani = true;
  299. ath9k_hw_set_ofdm_nil(ah,
  300. aniState->ofdmNoiseImmunityLevel);
  301. ath9k_hw_set_cck_nil(ah,
  302. aniState->cckNoiseImmunityLevel);
  303. }
  304. /*
  305. * enable phy counters if hw supports or if not, enable phy
  306. * interrupts (so we can count each one)
  307. */
  308. ath9k_ani_restart(ah);
  309. ENABLE_REGWRITE_BUFFER(ah);
  310. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  311. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  312. REGWRITE_BUFFER_FLUSH(ah);
  313. }
  314. static bool ath9k_hw_ani_read_counters(struct ath_hw *ah)
  315. {
  316. struct ath_common *common = ath9k_hw_common(ah);
  317. struct ar5416AniState *aniState = &ah->curchan->ani;
  318. u32 ofdm_base = 0;
  319. u32 cck_base = 0;
  320. u32 ofdmPhyErrCnt, cckPhyErrCnt;
  321. u32 phyCnt1, phyCnt2;
  322. int32_t listenTime;
  323. ath_hw_cycle_counters_update(common);
  324. listenTime = ath_hw_get_listen_time(common);
  325. if (listenTime <= 0) {
  326. ah->stats.ast_ani_lneg_or_lzero++;
  327. ath9k_ani_restart(ah);
  328. return false;
  329. }
  330. aniState->listenTime += listenTime;
  331. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  332. phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
  333. phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
  334. ofdmPhyErrCnt = phyCnt1 - ofdm_base;
  335. ah->stats.ast_ani_ofdmerrs +=
  336. ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
  337. aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
  338. cckPhyErrCnt = phyCnt2 - cck_base;
  339. ah->stats.ast_ani_cckerrs +=
  340. cckPhyErrCnt - aniState->cckPhyErrCount;
  341. aniState->cckPhyErrCount = cckPhyErrCnt;
  342. return true;
  343. }
  344. void ath9k_hw_ani_monitor(struct ath_hw *ah, struct ath9k_channel *chan)
  345. {
  346. struct ar5416AniState *aniState;
  347. struct ath_common *common = ath9k_hw_common(ah);
  348. u32 ofdmPhyErrRate, cckPhyErrRate;
  349. if (!DO_ANI(ah))
  350. return;
  351. aniState = &ah->curchan->ani;
  352. if (WARN_ON(!aniState))
  353. return;
  354. if (!ath9k_hw_ani_read_counters(ah))
  355. return;
  356. ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
  357. aniState->listenTime;
  358. cckPhyErrRate = aniState->cckPhyErrCount * 1000 /
  359. aniState->listenTime;
  360. ath_dbg(common, ANI,
  361. "listenTime=%d OFDM:%d errs=%d/s CCK:%d errs=%d/s ofdm_turn=%d\n",
  362. aniState->listenTime,
  363. aniState->ofdmNoiseImmunityLevel,
  364. ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
  365. cckPhyErrRate, aniState->ofdmsTurn);
  366. if (aniState->listenTime > ah->aniperiod) {
  367. if (cckPhyErrRate < ah->config.cck_trig_low &&
  368. ((ofdmPhyErrRate < ah->config.ofdm_trig_low &&
  369. aniState->ofdmNoiseImmunityLevel <
  370. ATH9K_ANI_OFDM_DEF_LEVEL) ||
  371. (ofdmPhyErrRate < ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI &&
  372. aniState->ofdmNoiseImmunityLevel >=
  373. ATH9K_ANI_OFDM_DEF_LEVEL))) {
  374. ath9k_hw_ani_lower_immunity(ah);
  375. aniState->ofdmsTurn = !aniState->ofdmsTurn;
  376. } else if ((ofdmPhyErrRate > ah->config.ofdm_trig_high &&
  377. aniState->ofdmNoiseImmunityLevel >=
  378. ATH9K_ANI_OFDM_DEF_LEVEL) ||
  379. (ofdmPhyErrRate >
  380. ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI &&
  381. aniState->ofdmNoiseImmunityLevel <
  382. ATH9K_ANI_OFDM_DEF_LEVEL)) {
  383. ath9k_hw_ani_ofdm_err_trigger(ah);
  384. aniState->ofdmsTurn = false;
  385. } else if (cckPhyErrRate > ah->config.cck_trig_high) {
  386. ath9k_hw_ani_cck_err_trigger(ah);
  387. aniState->ofdmsTurn = true;
  388. }
  389. ath9k_ani_restart(ah);
  390. }
  391. }
  392. EXPORT_SYMBOL(ath9k_hw_ani_monitor);
  393. void ath9k_enable_mib_counters(struct ath_hw *ah)
  394. {
  395. struct ath_common *common = ath9k_hw_common(ah);
  396. ath_dbg(common, ANI, "Enable MIB counters\n");
  397. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  398. ENABLE_REGWRITE_BUFFER(ah);
  399. REG_WRITE(ah, AR_FILT_OFDM, 0);
  400. REG_WRITE(ah, AR_FILT_CCK, 0);
  401. REG_WRITE(ah, AR_MIBC,
  402. ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
  403. & 0x0f);
  404. REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
  405. REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
  406. REGWRITE_BUFFER_FLUSH(ah);
  407. }
  408. /* Freeze the MIB counters, get the stats and then clear them */
  409. void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
  410. {
  411. struct ath_common *common = ath9k_hw_common(ah);
  412. ath_dbg(common, ANI, "Disable MIB counters\n");
  413. REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
  414. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  415. REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
  416. REG_WRITE(ah, AR_FILT_OFDM, 0);
  417. REG_WRITE(ah, AR_FILT_CCK, 0);
  418. }
  419. EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
  420. /*
  421. * Process a MIB interrupt. We may potentially be invoked because
  422. * any of the MIB counters overflow/trigger so don't assume we're
  423. * here because a PHY error counter triggered.
  424. */
  425. void ath9k_hw_proc_mib_event(struct ath_hw *ah)
  426. {
  427. u32 phyCnt1, phyCnt2;
  428. /* Reset these counters regardless */
  429. REG_WRITE(ah, AR_FILT_OFDM, 0);
  430. REG_WRITE(ah, AR_FILT_CCK, 0);
  431. if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
  432. REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
  433. /* Clear the mib counters and save them in the stats */
  434. ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
  435. if (!DO_ANI(ah)) {
  436. /*
  437. * We must always clear the interrupt cause by
  438. * resetting the phy error regs.
  439. */
  440. REG_WRITE(ah, AR_PHY_ERR_1, 0);
  441. REG_WRITE(ah, AR_PHY_ERR_2, 0);
  442. return;
  443. }
  444. /* NB: these are not reset-on-read */
  445. phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
  446. phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
  447. if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
  448. ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
  449. /* NB: always restart to insure the h/w counters are reset */
  450. ath9k_ani_restart(ah);
  451. }
  452. }
  453. EXPORT_SYMBOL(ath9k_hw_proc_mib_event);
  454. void ath9k_hw_ani_setup(struct ath_hw *ah)
  455. {
  456. int i;
  457. static const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
  458. static const int coarseHigh[] = { -14, -14, -14, -14, -12 };
  459. static const int coarseLow[] = { -64, -64, -64, -64, -70 };
  460. static const int firpwr[] = { -78, -78, -78, -78, -80 };
  461. for (i = 0; i < 5; i++) {
  462. ah->totalSizeDesired[i] = totalSizeDesired[i];
  463. ah->coarse_high[i] = coarseHigh[i];
  464. ah->coarse_low[i] = coarseLow[i];
  465. ah->firpwr[i] = firpwr[i];
  466. }
  467. }
  468. void ath9k_hw_ani_init(struct ath_hw *ah)
  469. {
  470. struct ath_common *common = ath9k_hw_common(ah);
  471. int i;
  472. ath_dbg(common, ANI, "Initialize ANI\n");
  473. ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_NEW;
  474. ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_NEW;
  475. ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH_NEW;
  476. ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW_NEW;
  477. for (i = 0; i < ARRAY_SIZE(ah->channels); i++) {
  478. struct ath9k_channel *chan = &ah->channels[i];
  479. struct ar5416AniState *ani = &chan->ani;
  480. ani->spurImmunityLevel =
  481. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  482. ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  483. if (AR_SREV_9300_20_OR_LATER(ah))
  484. ani->mrcCCKOff =
  485. !ATH9K_ANI_ENABLE_MRC_CCK;
  486. else
  487. ani->mrcCCKOff = true;
  488. ani->ofdmsTurn = true;
  489. ani->rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
  490. ani->rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
  491. ani->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  492. ani->cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
  493. ani->ofdmNoiseImmunityLevel = ATH9K_ANI_OFDM_DEF_LEVEL;
  494. ani->update_ani = false;
  495. }
  496. /*
  497. * since we expect some ongoing maintenance on the tables, let's sanity
  498. * check here default level should not modify INI setting.
  499. */
  500. ah->aniperiod = ATH9K_ANI_PERIOD_NEW;
  501. ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_NEW;
  502. if (ah->config.enable_ani)
  503. ah->proc_phyerr |= HAL_PROCESS_ANI;
  504. ath9k_ani_restart(ah);
  505. ath9k_enable_mib_counters(ah);
  506. }