Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1 | /* |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 2 | * Copyright (c) 2008-2010 Atheros Communications Inc. |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 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 | |
Nikitas Angelinas | bbce80e | 2010-09-08 22:25:42 +0100 | [diff] [blame] | 17 | #include <linux/kernel.h> |
Luis R. Rodriguez | cfe8cba | 2009-09-13 23:39:31 -0700 | [diff] [blame] | 18 | #include "hw.h" |
Felix Fietkau | c16fcb4 | 2010-04-15 17:38:39 -0400 | [diff] [blame] | 19 | #include "hw-ops.h" |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 20 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 21 | struct ani_ofdm_level_entry { |
| 22 | int spur_immunity_level; |
| 23 | int fir_step_level; |
| 24 | int ofdm_weak_signal_on; |
| 25 | }; |
| 26 | |
| 27 | /* values here are relative to the INI */ |
| 28 | |
| 29 | /* |
| 30 | * Legend: |
| 31 | * |
| 32 | * SI: Spur immunity |
| 33 | * FS: FIR Step |
| 34 | * WS: OFDM / CCK Weak Signal detection |
| 35 | * MRC-CCK: Maximal Ratio Combining for CCK |
| 36 | */ |
| 37 | |
| 38 | static const struct ani_ofdm_level_entry ofdm_level_table[] = { |
| 39 | /* SI FS WS */ |
| 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 */ |
| 50 | }; |
| 51 | #define ATH9K_ANI_OFDM_NUM_LEVEL \ |
Nikitas Angelinas | bbce80e | 2010-09-08 22:25:42 +0100 | [diff] [blame] | 52 | ARRAY_SIZE(ofdm_level_table) |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 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 */ |
| 57 | |
| 58 | /* |
| 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 |
| 63 | * domain. |
| 64 | * |
| 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. |
| 72 | * |
| 73 | * Regardless of alignment in time, the antenna signals add constructively after |
| 74 | * FFT and improve your reception. For more information: |
| 75 | * |
| 76 | * http://en.wikipedia.org/wiki/Maximal-ratio_combining |
| 77 | */ |
| 78 | |
| 79 | struct ani_cck_level_entry { |
| 80 | int fir_step_level; |
| 81 | int mrc_cck_on; |
| 82 | }; |
| 83 | |
| 84 | static const struct ani_cck_level_entry cck_level_table[] = { |
| 85 | /* FS MRC-CCK */ |
| 86 | { 0, 1 }, /* lvl 0 */ |
| 87 | { 1, 1 }, /* lvl 1 */ |
| 88 | { 2, 1 }, /* lvl 2 (default) */ |
| 89 | { 3, 1 }, /* lvl 3 */ |
| 90 | { 4, 0 }, /* lvl 4 */ |
| 91 | { 5, 0 }, /* lvl 5 */ |
| 92 | { 6, 0 }, /* lvl 6 */ |
| 93 | { 7, 0 }, /* lvl 7 (only for high rssi) */ |
| 94 | { 8, 0 } /* lvl 8 (only for high rssi) */ |
| 95 | }; |
| 96 | |
| 97 | #define ATH9K_ANI_CCK_NUM_LEVEL \ |
Nikitas Angelinas | bbce80e | 2010-09-08 22:25:42 +0100 | [diff] [blame] | 98 | ARRAY_SIZE(cck_level_table) |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 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 */ |
| 105 | |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 106 | /* Private to ani.c */ |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 107 | static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah) |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 108 | { |
| 109 | ath9k_hw_private_ops(ah)->ani_lower_immunity(ah); |
| 110 | } |
| 111 | |
Felix Fietkau | 71ea420 | 2010-10-04 20:09:46 +0200 | [diff] [blame] | 112 | static bool use_new_ani(struct ath_hw *ah) |
| 113 | { |
| 114 | return AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani; |
| 115 | } |
| 116 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 117 | static void ath9k_hw_update_mibstats(struct ath_hw *ah, |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 118 | struct ath9k_mib_stats *stats) |
| 119 | { |
| 120 | stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL); |
| 121 | stats->rts_bad += REG_READ(ah, AR_RTS_FAIL); |
| 122 | stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL); |
| 123 | stats->rts_good += REG_READ(ah, AR_RTS_OK); |
| 124 | stats->beacons += REG_READ(ah, AR_BEACON_CNT); |
| 125 | } |
| 126 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 127 | static void ath9k_ani_restart(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 128 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 129 | struct ar5416AniState *aniState; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 130 | struct ath_common *common = ath9k_hw_common(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 131 | u32 ofdm_base = 0, cck_base = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 132 | |
| 133 | if (!DO_ANI(ah)) |
| 134 | return; |
| 135 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 136 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 137 | aniState->listenTime = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 138 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 139 | if (!use_new_ani(ah)) { |
| 140 | ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high; |
| 141 | cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 142 | } |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 143 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 144 | ath_print(common, ATH_DBG_ANI, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 145 | "Writing ofdmbase=%u cckbase=%u\n", ofdm_base, cck_base); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 146 | |
| 147 | ENABLE_REGWRITE_BUFFER(ah); |
| 148 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 149 | REG_WRITE(ah, AR_PHY_ERR_1, ofdm_base); |
| 150 | REG_WRITE(ah, AR_PHY_ERR_2, cck_base); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 151 | REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING); |
| 152 | REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING); |
| 153 | |
| 154 | REGWRITE_BUFFER_FLUSH(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 155 | |
| 156 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
| 157 | |
| 158 | aniState->ofdmPhyErrCount = 0; |
| 159 | aniState->cckPhyErrCount = 0; |
| 160 | } |
| 161 | |
| 162 | static void ath9k_hw_ani_ofdm_err_trigger_old(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 163 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 164 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 165 | struct ar5416AniState *aniState; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 166 | int32_t rssi; |
| 167 | |
| 168 | if (!DO_ANI(ah)) |
| 169 | return; |
| 170 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 171 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 172 | |
| 173 | if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) { |
| 174 | if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, |
| 175 | aniState->noiseImmunityLevel + 1)) { |
| 176 | return; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) { |
| 181 | if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, |
| 182 | aniState->spurImmunityLevel + 1)) { |
| 183 | return; |
| 184 | } |
| 185 | } |
| 186 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 187 | if (ah->opmode == NL80211_IFTYPE_AP) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 188 | if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) { |
| 189 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 190 | aniState->firstepLevel + 1); |
| 191 | } |
| 192 | return; |
| 193 | } |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 194 | rssi = BEACON_RSSI(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 195 | if (rssi > aniState->rssiThrHigh) { |
| 196 | if (!aniState->ofdmWeakSigDetectOff) { |
| 197 | if (ath9k_hw_ani_control(ah, |
| 198 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 199 | false)) { |
| 200 | ath9k_hw_ani_control(ah, |
| 201 | ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0); |
| 202 | return; |
| 203 | } |
| 204 | } |
| 205 | if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) { |
| 206 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 207 | aniState->firstepLevel + 1); |
| 208 | return; |
| 209 | } |
| 210 | } else if (rssi > aniState->rssiThrLow) { |
| 211 | if (aniState->ofdmWeakSigDetectOff) |
| 212 | ath9k_hw_ani_control(ah, |
| 213 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 214 | true); |
| 215 | if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) |
| 216 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 217 | aniState->firstepLevel + 1); |
| 218 | return; |
| 219 | } else { |
Sujith | d37b7da | 2009-09-11 08:30:03 +0530 | [diff] [blame] | 220 | if ((conf->channel->band == IEEE80211_BAND_2GHZ) && |
| 221 | !conf_is_ht(conf)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 222 | if (!aniState->ofdmWeakSigDetectOff) |
| 223 | ath9k_hw_ani_control(ah, |
| 224 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 225 | false); |
| 226 | if (aniState->firstepLevel > 0) |
| 227 | ath9k_hw_ani_control(ah, |
| 228 | ATH9K_ANI_FIRSTEP_LEVEL, 0); |
| 229 | return; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 234 | static void ath9k_hw_ani_cck_err_trigger_old(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 235 | { |
Luis R. Rodriguez | b002a4a | 2009-09-13 00:03:27 -0700 | [diff] [blame] | 236 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 237 | struct ar5416AniState *aniState; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 238 | int32_t rssi; |
| 239 | |
| 240 | if (!DO_ANI(ah)) |
| 241 | return; |
| 242 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 243 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 244 | if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) { |
| 245 | if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, |
| 246 | aniState->noiseImmunityLevel + 1)) { |
| 247 | return; |
| 248 | } |
| 249 | } |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 250 | if (ah->opmode == NL80211_IFTYPE_AP) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 251 | if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) { |
| 252 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 253 | aniState->firstepLevel + 1); |
| 254 | } |
| 255 | return; |
| 256 | } |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 257 | rssi = BEACON_RSSI(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 258 | if (rssi > aniState->rssiThrLow) { |
| 259 | if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) |
| 260 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 261 | aniState->firstepLevel + 1); |
| 262 | } else { |
Sujith | d37b7da | 2009-09-11 08:30:03 +0530 | [diff] [blame] | 263 | if ((conf->channel->band == IEEE80211_BAND_2GHZ) && |
| 264 | !conf_is_ht(conf)) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 265 | if (aniState->firstepLevel > 0) |
| 266 | ath9k_hw_ani_control(ah, |
| 267 | ATH9K_ANI_FIRSTEP_LEVEL, 0); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 272 | /* Adjust the OFDM Noise Immunity Level */ |
| 273 | static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel) |
| 274 | { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 275 | struct ar5416AniState *aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 276 | struct ath_common *common = ath9k_hw_common(ah); |
| 277 | const struct ani_ofdm_level_entry *entry_ofdm; |
| 278 | const struct ani_cck_level_entry *entry_cck; |
| 279 | |
| 280 | aniState->noiseFloor = BEACON_RSSI(ah); |
| 281 | |
| 282 | ath_print(common, ATH_DBG_ANI, |
| 283 | "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n", |
| 284 | aniState->ofdmNoiseImmunityLevel, |
| 285 | immunityLevel, aniState->noiseFloor, |
| 286 | aniState->rssiThrLow, aniState->rssiThrHigh); |
| 287 | |
| 288 | aniState->ofdmNoiseImmunityLevel = immunityLevel; |
| 289 | |
| 290 | entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel]; |
| 291 | entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel]; |
| 292 | |
| 293 | if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level) |
| 294 | ath9k_hw_ani_control(ah, |
| 295 | ATH9K_ANI_SPUR_IMMUNITY_LEVEL, |
| 296 | entry_ofdm->spur_immunity_level); |
| 297 | |
| 298 | if (aniState->firstepLevel != entry_ofdm->fir_step_level && |
| 299 | entry_ofdm->fir_step_level >= entry_cck->fir_step_level) |
| 300 | ath9k_hw_ani_control(ah, |
| 301 | ATH9K_ANI_FIRSTEP_LEVEL, |
| 302 | entry_ofdm->fir_step_level); |
| 303 | |
| 304 | if ((ah->opmode != NL80211_IFTYPE_STATION && |
| 305 | ah->opmode != NL80211_IFTYPE_ADHOC) || |
| 306 | aniState->noiseFloor <= aniState->rssiThrHigh) { |
| 307 | if (aniState->ofdmWeakSigDetectOff) |
| 308 | /* force on ofdm weak sig detect */ |
| 309 | ath9k_hw_ani_control(ah, |
| 310 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 311 | true); |
| 312 | else if (aniState->ofdmWeakSigDetectOff == |
| 313 | entry_ofdm->ofdm_weak_signal_on) |
| 314 | ath9k_hw_ani_control(ah, |
| 315 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 316 | entry_ofdm->ofdm_weak_signal_on); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static void ath9k_hw_ani_ofdm_err_trigger_new(struct ath_hw *ah) |
| 321 | { |
| 322 | struct ar5416AniState *aniState; |
| 323 | |
| 324 | if (!DO_ANI(ah)) |
| 325 | return; |
| 326 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 327 | aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 328 | |
| 329 | if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL) |
| 330 | ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1); |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Set the ANI settings to match an CCK level. |
| 335 | */ |
| 336 | static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel) |
| 337 | { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 338 | struct ar5416AniState *aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 339 | struct ath_common *common = ath9k_hw_common(ah); |
| 340 | const struct ani_ofdm_level_entry *entry_ofdm; |
| 341 | const struct ani_cck_level_entry *entry_cck; |
| 342 | |
| 343 | aniState->noiseFloor = BEACON_RSSI(ah); |
| 344 | ath_print(common, ATH_DBG_ANI, |
| 345 | "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n", |
| 346 | aniState->cckNoiseImmunityLevel, immunityLevel, |
| 347 | aniState->noiseFloor, aniState->rssiThrLow, |
| 348 | aniState->rssiThrHigh); |
| 349 | |
| 350 | if ((ah->opmode == NL80211_IFTYPE_STATION || |
| 351 | ah->opmode == NL80211_IFTYPE_ADHOC) && |
| 352 | aniState->noiseFloor <= aniState->rssiThrLow && |
| 353 | immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI) |
| 354 | immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI; |
| 355 | |
| 356 | aniState->cckNoiseImmunityLevel = immunityLevel; |
| 357 | |
| 358 | entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel]; |
| 359 | entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel]; |
| 360 | |
| 361 | if (aniState->firstepLevel != entry_cck->fir_step_level && |
| 362 | entry_cck->fir_step_level >= entry_ofdm->fir_step_level) |
| 363 | ath9k_hw_ani_control(ah, |
| 364 | ATH9K_ANI_FIRSTEP_LEVEL, |
| 365 | entry_cck->fir_step_level); |
| 366 | |
| 367 | /* Skip MRC CCK for pre AR9003 families */ |
| 368 | if (!AR_SREV_9300_20_OR_LATER(ah)) |
| 369 | return; |
| 370 | |
| 371 | if (aniState->mrcCCKOff == entry_cck->mrc_cck_on) |
| 372 | ath9k_hw_ani_control(ah, |
| 373 | ATH9K_ANI_MRC_CCK, |
| 374 | entry_cck->mrc_cck_on); |
| 375 | } |
| 376 | |
| 377 | static void ath9k_hw_ani_cck_err_trigger_new(struct ath_hw *ah) |
| 378 | { |
| 379 | struct ar5416AniState *aniState; |
| 380 | |
| 381 | if (!DO_ANI(ah)) |
| 382 | return; |
| 383 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 384 | aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 385 | |
| 386 | if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL) |
| 387 | ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1); |
| 388 | } |
| 389 | |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 390 | static void ath9k_hw_ani_lower_immunity_old(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 391 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 392 | struct ar5416AniState *aniState; |
| 393 | int32_t rssi; |
| 394 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 395 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 396 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 397 | if (ah->opmode == NL80211_IFTYPE_AP) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 398 | if (aniState->firstepLevel > 0) { |
| 399 | if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 400 | aniState->firstepLevel - 1)) |
| 401 | return; |
| 402 | } |
| 403 | } else { |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 404 | rssi = BEACON_RSSI(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 405 | if (rssi > aniState->rssiThrHigh) { |
| 406 | /* XXX: Handle me */ |
| 407 | } else if (rssi > aniState->rssiThrLow) { |
| 408 | if (aniState->ofdmWeakSigDetectOff) { |
| 409 | if (ath9k_hw_ani_control(ah, |
| 410 | ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 411 | true) == true) |
| 412 | return; |
| 413 | } |
| 414 | if (aniState->firstepLevel > 0) { |
| 415 | if (ath9k_hw_ani_control(ah, |
| 416 | ATH9K_ANI_FIRSTEP_LEVEL, |
| 417 | aniState->firstepLevel - 1) == true) |
| 418 | return; |
| 419 | } |
| 420 | } else { |
| 421 | if (aniState->firstepLevel > 0) { |
| 422 | if (ath9k_hw_ani_control(ah, |
| 423 | ATH9K_ANI_FIRSTEP_LEVEL, |
| 424 | aniState->firstepLevel - 1) == true) |
| 425 | return; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (aniState->spurImmunityLevel > 0) { |
| 431 | if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, |
| 432 | aniState->spurImmunityLevel - 1)) |
| 433 | return; |
| 434 | } |
| 435 | |
| 436 | if (aniState->noiseImmunityLevel > 0) { |
| 437 | ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, |
| 438 | aniState->noiseImmunityLevel - 1); |
| 439 | return; |
| 440 | } |
| 441 | } |
| 442 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 443 | /* |
| 444 | * only lower either OFDM or CCK errors per turn |
| 445 | * we lower the other one next time |
| 446 | */ |
| 447 | static void ath9k_hw_ani_lower_immunity_new(struct ath_hw *ah) |
| 448 | { |
| 449 | struct ar5416AniState *aniState; |
| 450 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 451 | aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 452 | |
| 453 | /* lower OFDM noise immunity */ |
| 454 | if (aniState->ofdmNoiseImmunityLevel > 0 && |
| 455 | (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) { |
| 456 | ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1); |
| 457 | return; |
| 458 | } |
| 459 | |
| 460 | /* lower CCK noise immunity */ |
| 461 | if (aniState->cckNoiseImmunityLevel > 0) |
| 462 | ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1); |
| 463 | } |
| 464 | |
Luis R. Rodriguez | 37e5bf6 | 2010-06-12 00:33:40 -0400 | [diff] [blame] | 465 | static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah) |
| 466 | { |
| 467 | struct ath9k_channel *chan = ah->curchan; |
| 468 | struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf; |
| 469 | u8 clockrate; /* in MHz */ |
| 470 | |
| 471 | if (!ah->curchan) /* should really check for CCK instead */ |
| 472 | clockrate = ATH9K_CLOCK_RATE_CCK; |
| 473 | else if (conf->channel->band == IEEE80211_BAND_2GHZ) |
| 474 | clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM; |
| 475 | else if (IS_CHAN_A_FAST_CLOCK(ah, chan)) |
| 476 | clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM; |
| 477 | else |
| 478 | clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM; |
| 479 | |
| 480 | if (conf_is_ht40(conf)) |
| 481 | return clockrate * 2; |
| 482 | |
Felix Fietkau | 918df62 | 2010-10-03 19:07:19 +0200 | [diff] [blame] | 483 | return clockrate; |
Luis R. Rodriguez | 37e5bf6 | 2010-06-12 00:33:40 -0400 | [diff] [blame] | 484 | } |
| 485 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 486 | static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 487 | { |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 488 | int32_t listen_time; |
| 489 | int32_t clock_rate; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 490 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 491 | ath9k_hw_update_cycle_counters(ah); |
| 492 | clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000; |
| 493 | listen_time = ah->listen_time / clock_rate; |
| 494 | ah->listen_time = 0; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 495 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 496 | return listen_time; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 497 | } |
| 498 | |
Luis R. Rodriguez | 40346b6 | 2010-06-12 00:33:44 -0400 | [diff] [blame] | 499 | static void ath9k_ani_reset_old(struct ath_hw *ah, bool is_scanning) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 500 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 501 | struct ar5416AniState *aniState; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 502 | struct ath9k_channel *chan = ah->curchan; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 503 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 504 | |
| 505 | if (!DO_ANI(ah)) |
| 506 | return; |
| 507 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 508 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 509 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 510 | if (ah->opmode != NL80211_IFTYPE_STATION |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 511 | && ah->opmode != NL80211_IFTYPE_ADHOC) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 512 | ath_print(common, ATH_DBG_ANI, |
| 513 | "Reset ANI state opmode %u\n", ah->opmode); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 514 | ah->stats.ast_ani_reset++; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 515 | |
Luis R. Rodriguez | c66284f | 2009-07-16 10:17:35 -0700 | [diff] [blame] | 516 | if (ah->opmode == NL80211_IFTYPE_AP) { |
| 517 | /* |
| 518 | * ath9k_hw_ani_control() will only process items set on |
| 519 | * ah->ani_function |
| 520 | */ |
| 521 | if (IS_CHAN_2GHZ(chan)) |
| 522 | ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL | |
| 523 | ATH9K_ANI_FIRSTEP_LEVEL); |
| 524 | else |
| 525 | ah->ani_function = 0; |
| 526 | } |
| 527 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 528 | ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0); |
| 529 | ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0); |
| 530 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0); |
| 531 | ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 532 | !ATH9K_ANI_USE_OFDM_WEAK_SIG); |
| 533 | ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR, |
| 534 | ATH9K_ANI_CCK_WEAK_SIG_THR); |
| 535 | |
| 536 | ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) | |
| 537 | ATH9K_RX_FILTER_PHYERR); |
| 538 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 539 | ath9k_ani_restart(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | |
| 543 | if (aniState->noiseImmunityLevel != 0) |
| 544 | ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, |
| 545 | aniState->noiseImmunityLevel); |
| 546 | if (aniState->spurImmunityLevel != 0) |
| 547 | ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, |
| 548 | aniState->spurImmunityLevel); |
| 549 | if (aniState->ofdmWeakSigDetectOff) |
| 550 | ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION, |
| 551 | !aniState->ofdmWeakSigDetectOff); |
| 552 | if (aniState->cckWeakSigThreshold) |
| 553 | ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR, |
| 554 | aniState->cckWeakSigThreshold); |
| 555 | if (aniState->firstepLevel != 0) |
| 556 | ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, |
| 557 | aniState->firstepLevel); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 558 | |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 559 | ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) & |
| 560 | ~ATH9K_RX_FILTER_PHYERR); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 561 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 562 | |
| 563 | ENABLE_REGWRITE_BUFFER(ah); |
| 564 | |
| 565 | REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING); |
| 566 | REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING); |
| 567 | |
| 568 | REGWRITE_BUFFER_FLUSH(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Restore the ANI parameters in the HAL and reset the statistics. |
| 573 | * This routine should be called for every hardware reset and for |
| 574 | * every channel change. |
| 575 | */ |
| 576 | static void ath9k_ani_reset_new(struct ath_hw *ah, bool is_scanning) |
| 577 | { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 578 | struct ar5416AniState *aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 579 | struct ath9k_channel *chan = ah->curchan; |
| 580 | struct ath_common *common = ath9k_hw_common(ah); |
| 581 | |
| 582 | if (!DO_ANI(ah)) |
| 583 | return; |
| 584 | |
| 585 | BUG_ON(aniState == NULL); |
| 586 | ah->stats.ast_ani_reset++; |
| 587 | |
| 588 | /* only allow a subset of functions in AP mode */ |
| 589 | if (ah->opmode == NL80211_IFTYPE_AP) { |
| 590 | if (IS_CHAN_2GHZ(chan)) { |
| 591 | ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL | |
| 592 | ATH9K_ANI_FIRSTEP_LEVEL); |
| 593 | if (AR_SREV_9300_20_OR_LATER(ah)) |
| 594 | ah->ani_function |= ATH9K_ANI_MRC_CCK; |
| 595 | } else |
| 596 | ah->ani_function = 0; |
| 597 | } |
| 598 | |
| 599 | /* always allow mode (on/off) to be controlled */ |
| 600 | ah->ani_function |= ATH9K_ANI_MODE; |
| 601 | |
| 602 | if (is_scanning || |
| 603 | (ah->opmode != NL80211_IFTYPE_STATION && |
| 604 | ah->opmode != NL80211_IFTYPE_ADHOC)) { |
| 605 | /* |
| 606 | * If we're scanning or in AP mode, the defaults (ini) |
| 607 | * should be in place. For an AP we assume the historical |
| 608 | * levels for this channel are probably outdated so start |
| 609 | * from defaults instead. |
| 610 | */ |
| 611 | if (aniState->ofdmNoiseImmunityLevel != |
| 612 | ATH9K_ANI_OFDM_DEF_LEVEL || |
| 613 | aniState->cckNoiseImmunityLevel != |
| 614 | ATH9K_ANI_CCK_DEF_LEVEL) { |
| 615 | ath_print(common, ATH_DBG_ANI, |
| 616 | "Restore defaults: opmode %u " |
| 617 | "chan %d Mhz/0x%x is_scanning=%d " |
| 618 | "ofdm:%d cck:%d\n", |
| 619 | ah->opmode, |
| 620 | chan->channel, |
| 621 | chan->channelFlags, |
| 622 | is_scanning, |
| 623 | aniState->ofdmNoiseImmunityLevel, |
| 624 | aniState->cckNoiseImmunityLevel); |
| 625 | |
| 626 | ath9k_hw_set_ofdm_nil(ah, ATH9K_ANI_OFDM_DEF_LEVEL); |
| 627 | ath9k_hw_set_cck_nil(ah, ATH9K_ANI_CCK_DEF_LEVEL); |
| 628 | } |
| 629 | } else { |
| 630 | /* |
| 631 | * restore historical levels for this channel |
| 632 | */ |
| 633 | ath_print(common, ATH_DBG_ANI, |
| 634 | "Restore history: opmode %u " |
| 635 | "chan %d Mhz/0x%x is_scanning=%d " |
| 636 | "ofdm:%d cck:%d\n", |
| 637 | ah->opmode, |
| 638 | chan->channel, |
| 639 | chan->channelFlags, |
| 640 | is_scanning, |
| 641 | aniState->ofdmNoiseImmunityLevel, |
| 642 | aniState->cckNoiseImmunityLevel); |
| 643 | |
| 644 | ath9k_hw_set_ofdm_nil(ah, |
| 645 | aniState->ofdmNoiseImmunityLevel); |
| 646 | ath9k_hw_set_cck_nil(ah, |
| 647 | aniState->cckNoiseImmunityLevel); |
| 648 | } |
| 649 | |
| 650 | /* |
| 651 | * enable phy counters if hw supports or if not, enable phy |
| 652 | * interrupts (so we can count each one) |
| 653 | */ |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 654 | ath9k_ani_restart(ah); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 655 | |
| 656 | ENABLE_REGWRITE_BUFFER(ah); |
| 657 | |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 658 | REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING); |
| 659 | REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 660 | |
| 661 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 662 | } |
| 663 | |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 664 | static void ath9k_hw_ani_monitor_old(struct ath_hw *ah, |
| 665 | struct ath9k_channel *chan) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 666 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 667 | struct ar5416AniState *aniState; |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 668 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 669 | int32_t listenTime; |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 670 | u32 phyCnt1, phyCnt2; |
| 671 | u32 ofdmPhyErrCnt, cckPhyErrCnt; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 672 | u32 ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high; |
| 673 | u32 cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 674 | |
Gabor Juhos | 9950688 | 2009-01-14 20:17:11 +0100 | [diff] [blame] | 675 | if (!DO_ANI(ah)) |
| 676 | return; |
| 677 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 678 | aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 679 | |
| 680 | listenTime = ath9k_hw_ani_get_listen_time(ah); |
| 681 | if (listenTime < 0) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 682 | ah->stats.ast_ani_lneg++; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 683 | ath9k_ani_restart(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 684 | return; |
| 685 | } |
| 686 | |
| 687 | aniState->listenTime += listenTime; |
| 688 | |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 689 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 690 | |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 691 | phyCnt1 = REG_READ(ah, AR_PHY_ERR_1); |
| 692 | phyCnt2 = REG_READ(ah, AR_PHY_ERR_2); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 693 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 694 | if (phyCnt1 < ofdm_base || phyCnt2 < cck_base) { |
| 695 | if (phyCnt1 < ofdm_base) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 696 | ath_print(common, ATH_DBG_ANI, |
| 697 | "phyCnt1 0x%x, resetting " |
| 698 | "counter value to 0x%x\n", |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 699 | phyCnt1, ofdm_base); |
| 700 | REG_WRITE(ah, AR_PHY_ERR_1, ofdm_base); |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 701 | REG_WRITE(ah, AR_PHY_ERR_MASK_1, |
| 702 | AR_PHY_ERR_OFDM_TIMING); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 703 | } |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 704 | if (phyCnt2 < cck_base) { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 705 | ath_print(common, ATH_DBG_ANI, |
| 706 | "phyCnt2 0x%x, resetting " |
| 707 | "counter value to 0x%x\n", |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 708 | phyCnt2, cck_base); |
| 709 | REG_WRITE(ah, AR_PHY_ERR_2, cck_base); |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 710 | REG_WRITE(ah, AR_PHY_ERR_MASK_2, |
| 711 | AR_PHY_ERR_CCK_TIMING); |
| 712 | } |
| 713 | return; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 714 | } |
| 715 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 716 | ofdmPhyErrCnt = phyCnt1 - ofdm_base; |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 717 | ah->stats.ast_ani_ofdmerrs += |
| 718 | ofdmPhyErrCnt - aniState->ofdmPhyErrCount; |
| 719 | aniState->ofdmPhyErrCount = ofdmPhyErrCnt; |
| 720 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 721 | cckPhyErrCnt = phyCnt2 - cck_base; |
Sujith | 1aa8e84 | 2009-08-13 09:34:25 +0530 | [diff] [blame] | 722 | ah->stats.ast_ani_cckerrs += |
| 723 | cckPhyErrCnt - aniState->cckPhyErrCount; |
| 724 | aniState->cckPhyErrCount = cckPhyErrCnt; |
| 725 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 726 | if (aniState->listenTime > 5 * ah->aniperiod) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 727 | if (aniState->ofdmPhyErrCount <= aniState->listenTime * |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 728 | ah->config.ofdm_trig_low / 1000 && |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 729 | aniState->cckPhyErrCount <= aniState->listenTime * |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 730 | ah->config.cck_trig_low / 1000) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 731 | ath9k_hw_ani_lower_immunity(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 732 | ath9k_ani_restart(ah); |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 733 | } else if (aniState->listenTime > ah->aniperiod) { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 734 | if (aniState->ofdmPhyErrCount > aniState->listenTime * |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 735 | ah->config.ofdm_trig_high / 1000) { |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 736 | ath9k_hw_ani_ofdm_err_trigger_old(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 737 | ath9k_ani_restart(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 738 | } else if (aniState->cckPhyErrCount > |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 739 | aniState->listenTime * ah->config.cck_trig_high / |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 740 | 1000) { |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 741 | ath9k_hw_ani_cck_err_trigger_old(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 742 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | static void ath9k_hw_ani_monitor_new(struct ath_hw *ah, |
| 748 | struct ath9k_channel *chan) |
| 749 | { |
| 750 | struct ar5416AniState *aniState; |
| 751 | struct ath_common *common = ath9k_hw_common(ah); |
| 752 | int32_t listenTime; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 753 | u32 ofdmPhyErrCnt, cckPhyErrCnt; |
| 754 | u32 ofdmPhyErrRate, cckPhyErrRate; |
| 755 | |
| 756 | if (!DO_ANI(ah)) |
| 757 | return; |
| 758 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 759 | aniState = &ah->curchan->ani; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 760 | if (WARN_ON(!aniState)) |
| 761 | return; |
| 762 | |
| 763 | listenTime = ath9k_hw_ani_get_listen_time(ah); |
| 764 | if (listenTime <= 0) { |
| 765 | ah->stats.ast_ani_lneg++; |
| 766 | /* restart ANI period if listenTime is invalid */ |
| 767 | ath_print(common, ATH_DBG_ANI, |
| 768 | "listenTime=%d - on new ani monitor\n", |
| 769 | listenTime); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 770 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 771 | return; |
| 772 | } |
| 773 | |
| 774 | aniState->listenTime += listenTime; |
| 775 | |
| 776 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
| 777 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 778 | ofdmPhyErrCnt = REG_READ(ah, AR_PHY_ERR_1); |
| 779 | cckPhyErrCnt = REG_READ(ah, AR_PHY_ERR_2); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 780 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 781 | ah->stats.ast_ani_ofdmerrs += |
| 782 | ofdmPhyErrCnt - aniState->ofdmPhyErrCount; |
| 783 | aniState->ofdmPhyErrCount = ofdmPhyErrCnt; |
| 784 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 785 | ah->stats.ast_ani_cckerrs += |
| 786 | cckPhyErrCnt - aniState->cckPhyErrCount; |
| 787 | aniState->cckPhyErrCount = cckPhyErrCnt; |
| 788 | |
| 789 | ath_print(common, ATH_DBG_ANI, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 790 | "Errors: OFDM=%d, CCK=%d\n", |
| 791 | ofdmPhyErrCnt, cckPhyErrCnt); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 792 | |
| 793 | ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 / |
| 794 | aniState->listenTime; |
| 795 | cckPhyErrRate = aniState->cckPhyErrCount * 1000 / |
| 796 | aniState->listenTime; |
| 797 | |
| 798 | ath_print(common, ATH_DBG_ANI, |
| 799 | "listenTime=%d OFDM:%d errs=%d/s CCK:%d " |
| 800 | "errs=%d/s ofdm_turn=%d\n", |
| 801 | listenTime, aniState->ofdmNoiseImmunityLevel, |
| 802 | ofdmPhyErrRate, aniState->cckNoiseImmunityLevel, |
| 803 | cckPhyErrRate, aniState->ofdmsTurn); |
| 804 | |
| 805 | if (aniState->listenTime > 5 * ah->aniperiod) { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 806 | if (ofdmPhyErrRate <= ah->config.ofdm_trig_low && |
| 807 | cckPhyErrRate <= ah->config.cck_trig_low) { |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 808 | ath_print(common, ATH_DBG_ANI, |
| 809 | "1. listenTime=%d OFDM:%d errs=%d/s(<%d) " |
| 810 | "CCK:%d errs=%d/s(<%d) -> " |
| 811 | "ath9k_hw_ani_lower_immunity()\n", |
| 812 | aniState->listenTime, |
| 813 | aniState->ofdmNoiseImmunityLevel, |
| 814 | ofdmPhyErrRate, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 815 | ah->config.ofdm_trig_low, |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 816 | aniState->cckNoiseImmunityLevel, |
| 817 | cckPhyErrRate, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 818 | ah->config.cck_trig_low); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 819 | ath9k_hw_ani_lower_immunity(ah); |
| 820 | aniState->ofdmsTurn = !aniState->ofdmsTurn; |
| 821 | } |
| 822 | ath_print(common, ATH_DBG_ANI, |
| 823 | "1 listenTime=%d ofdm=%d/s cck=%d/s - " |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 824 | "calling ath9k_ani_restart()\n", |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 825 | aniState->listenTime, ofdmPhyErrRate, cckPhyErrRate); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 826 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 827 | } else if (aniState->listenTime > ah->aniperiod) { |
| 828 | /* check to see if need to raise immunity */ |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 829 | if (ofdmPhyErrRate > ah->config.ofdm_trig_high && |
| 830 | (cckPhyErrRate <= ah->config.cck_trig_high || |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 831 | aniState->ofdmsTurn)) { |
| 832 | ath_print(common, ATH_DBG_ANI, |
| 833 | "2 listenTime=%d OFDM:%d errs=%d/s(>%d) -> " |
| 834 | "ath9k_hw_ani_ofdm_err_trigger_new()\n", |
| 835 | aniState->listenTime, |
| 836 | aniState->ofdmNoiseImmunityLevel, |
| 837 | ofdmPhyErrRate, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 838 | ah->config.ofdm_trig_high); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 839 | ath9k_hw_ani_ofdm_err_trigger_new(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 840 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 841 | aniState->ofdmsTurn = false; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 842 | } else if (cckPhyErrRate > ah->config.cck_trig_high) { |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 843 | ath_print(common, ATH_DBG_ANI, |
| 844 | "3 listenTime=%d CCK:%d errs=%d/s(>%d) -> " |
| 845 | "ath9k_hw_ani_cck_err_trigger_new()\n", |
| 846 | aniState->listenTime, |
| 847 | aniState->cckNoiseImmunityLevel, |
| 848 | cckPhyErrRate, |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 849 | ah->config.cck_trig_high); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 850 | ath9k_hw_ani_cck_err_trigger_new(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 851 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 852 | aniState->ofdmsTurn = true; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 853 | } |
| 854 | } |
| 855 | } |
| 856 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 857 | void ath9k_enable_mib_counters(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 858 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 859 | struct ath_common *common = ath9k_hw_common(ah); |
| 860 | |
| 861 | ath_print(common, ATH_DBG_ANI, "Enable MIB counters\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 862 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 863 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 864 | |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 865 | ENABLE_REGWRITE_BUFFER(ah); |
| 866 | |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 867 | REG_WRITE(ah, AR_FILT_OFDM, 0); |
| 868 | REG_WRITE(ah, AR_FILT_CCK, 0); |
| 869 | REG_WRITE(ah, AR_MIBC, |
| 870 | ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS) |
| 871 | & 0x0f); |
| 872 | REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING); |
| 873 | REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING); |
Sujith | 7d0d0df | 2010-04-16 11:53:57 +0530 | [diff] [blame] | 874 | |
| 875 | REGWRITE_BUFFER_FLUSH(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 876 | } |
| 877 | |
Sujith | 0fd06c9 | 2009-02-12 10:06:51 +0530 | [diff] [blame] | 878 | /* Freeze the MIB counters, get the stats and then clear them */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 879 | void ath9k_hw_disable_mib_counters(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 880 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 881 | struct ath_common *common = ath9k_hw_common(ah); |
| 882 | |
| 883 | ath_print(common, ATH_DBG_ANI, "Disable MIB counters\n"); |
| 884 | |
Sujith | 0fd06c9 | 2009-02-12 10:06:51 +0530 | [diff] [blame] | 885 | REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC); |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 886 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
Sujith | 0fd06c9 | 2009-02-12 10:06:51 +0530 | [diff] [blame] | 887 | REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 888 | REG_WRITE(ah, AR_FILT_OFDM, 0); |
| 889 | REG_WRITE(ah, AR_FILT_CCK, 0); |
| 890 | } |
Sujith | 21d5130 | 2010-06-01 15:14:18 +0530 | [diff] [blame] | 891 | EXPORT_SYMBOL(ath9k_hw_disable_mib_counters); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 892 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 893 | void ath9k_hw_update_cycle_counters(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 894 | { |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 895 | struct ath_cycle_counters cc; |
| 896 | bool clear; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 897 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 898 | memcpy(&cc, &ah->cc, sizeof(cc)); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 899 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 900 | /* freeze counters */ |
| 901 | REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 902 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 903 | ah->cc.cycles = REG_READ(ah, AR_CCCNT); |
| 904 | if (ah->cc.cycles < cc.cycles) { |
| 905 | clear = true; |
| 906 | goto skip; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 907 | } |
| 908 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 909 | ah->cc.rx_clear = REG_READ(ah, AR_RCCNT); |
| 910 | ah->cc.rx_frame = REG_READ(ah, AR_RFCNT); |
| 911 | ah->cc.tx_frame = REG_READ(ah, AR_TFCNT); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 912 | |
Felix Fietkau | 9dbebc7 | 2010-10-03 19:07:17 +0200 | [diff] [blame] | 913 | /* prevent wraparound */ |
| 914 | if (ah->cc.cycles & BIT(31)) |
| 915 | clear = true; |
| 916 | |
| 917 | #define CC_DELTA(_field, _reg) ah->cc_delta._field += ah->cc._field - cc._field |
| 918 | CC_DELTA(cycles, AR_CCCNT); |
| 919 | CC_DELTA(rx_frame, AR_RFCNT); |
| 920 | CC_DELTA(rx_clear, AR_RCCNT); |
| 921 | CC_DELTA(tx_frame, AR_TFCNT); |
| 922 | #undef CC_DELTA |
| 923 | |
| 924 | ah->listen_time += (ah->cc.cycles - cc.cycles) - |
| 925 | ((ah->cc.rx_frame - cc.rx_frame) + |
| 926 | (ah->cc.tx_frame - cc.tx_frame)); |
| 927 | |
| 928 | skip: |
| 929 | if (clear) { |
| 930 | REG_WRITE(ah, AR_CCCNT, 0); |
| 931 | REG_WRITE(ah, AR_RFCNT, 0); |
| 932 | REG_WRITE(ah, AR_RCCNT, 0); |
| 933 | REG_WRITE(ah, AR_TFCNT, 0); |
| 934 | memset(&ah->cc, 0, sizeof(ah->cc)); |
| 935 | } |
| 936 | |
| 937 | /* unfreeze counters */ |
| 938 | REG_WRITE(ah, AR_MIBC, 0); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* |
| 942 | * Process a MIB interrupt. We may potentially be invoked because |
| 943 | * any of the MIB counters overflow/trigger so don't assume we're |
| 944 | * here because a PHY error counter triggered. |
| 945 | */ |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 946 | static void ath9k_hw_proc_mib_event_old(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 947 | { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 948 | u32 ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high; |
| 949 | u32 cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 950 | u32 phyCnt1, phyCnt2; |
| 951 | |
| 952 | /* Reset these counters regardless */ |
| 953 | REG_WRITE(ah, AR_FILT_OFDM, 0); |
| 954 | REG_WRITE(ah, AR_FILT_CCK, 0); |
| 955 | if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING)) |
| 956 | REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR); |
| 957 | |
| 958 | /* Clear the mib counters and save them in the stats */ |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 959 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 960 | |
Luis R. Rodriguez | 6e97f0f | 2010-06-12 00:33:41 -0400 | [diff] [blame] | 961 | if (!DO_ANI(ah)) { |
| 962 | /* |
| 963 | * We must always clear the interrupt cause by |
| 964 | * resetting the phy error regs. |
| 965 | */ |
| 966 | REG_WRITE(ah, AR_PHY_ERR_1, 0); |
| 967 | REG_WRITE(ah, AR_PHY_ERR_2, 0); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 968 | return; |
Luis R. Rodriguez | 6e97f0f | 2010-06-12 00:33:41 -0400 | [diff] [blame] | 969 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 970 | |
| 971 | /* NB: these are not reset-on-read */ |
| 972 | phyCnt1 = REG_READ(ah, AR_PHY_ERR_1); |
| 973 | phyCnt2 = REG_READ(ah, AR_PHY_ERR_2); |
| 974 | if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) || |
| 975 | ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 976 | struct ar5416AniState *aniState = &ah->curchan->ani; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 977 | u32 ofdmPhyErrCnt, cckPhyErrCnt; |
| 978 | |
| 979 | /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */ |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 980 | ofdmPhyErrCnt = phyCnt1 - ofdm_base; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 981 | ah->stats.ast_ani_ofdmerrs += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 982 | ofdmPhyErrCnt - aniState->ofdmPhyErrCount; |
| 983 | aniState->ofdmPhyErrCount = ofdmPhyErrCnt; |
| 984 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 985 | cckPhyErrCnt = phyCnt2 - cck_base; |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 986 | ah->stats.ast_ani_cckerrs += |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 987 | cckPhyErrCnt - aniState->cckPhyErrCount; |
| 988 | aniState->cckPhyErrCount = cckPhyErrCnt; |
| 989 | |
| 990 | /* |
| 991 | * NB: figure out which counter triggered. If both |
| 992 | * trigger we'll only deal with one as the processing |
| 993 | * clobbers the error counter so the trigger threshold |
| 994 | * check will never be true. |
| 995 | */ |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 996 | if (aniState->ofdmPhyErrCount > ah->config.ofdm_trig_high) |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 997 | ath9k_hw_ani_ofdm_err_trigger_new(ah); |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 998 | if (aniState->cckPhyErrCount > ah->config.cck_trig_high) |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 999 | ath9k_hw_ani_cck_err_trigger_old(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1000 | /* NB: always restart to insure the h/w counters are reset */ |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1001 | ath9k_ani_restart(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1005 | /* |
| 1006 | * Process a MIB interrupt. We may potentially be invoked because |
| 1007 | * any of the MIB counters overflow/trigger so don't assume we're |
| 1008 | * here because a PHY error counter triggered. |
| 1009 | */ |
| 1010 | static void ath9k_hw_proc_mib_event_new(struct ath_hw *ah) |
| 1011 | { |
| 1012 | u32 phyCnt1, phyCnt2; |
| 1013 | |
| 1014 | /* Reset these counters regardless */ |
| 1015 | REG_WRITE(ah, AR_FILT_OFDM, 0); |
| 1016 | REG_WRITE(ah, AR_FILT_CCK, 0); |
| 1017 | if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING)) |
| 1018 | REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR); |
| 1019 | |
| 1020 | /* Clear the mib counters and save them in the stats */ |
| 1021 | ath9k_hw_update_mibstats(ah, &ah->ah_mibStats); |
| 1022 | |
| 1023 | if (!DO_ANI(ah)) { |
| 1024 | /* |
| 1025 | * We must always clear the interrupt cause by |
| 1026 | * resetting the phy error regs. |
| 1027 | */ |
| 1028 | REG_WRITE(ah, AR_PHY_ERR_1, 0); |
| 1029 | REG_WRITE(ah, AR_PHY_ERR_2, 0); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | /* NB: these are not reset-on-read */ |
| 1034 | phyCnt1 = REG_READ(ah, AR_PHY_ERR_1); |
| 1035 | phyCnt2 = REG_READ(ah, AR_PHY_ERR_2); |
| 1036 | |
| 1037 | /* NB: always restart to insure the h/w counters are reset */ |
| 1038 | if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) || |
| 1039 | ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1040 | ath9k_ani_restart(ah); |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1041 | } |
| 1042 | |
Sujith | cbe61d8 | 2009-02-09 13:27:12 +0530 | [diff] [blame] | 1043 | void ath9k_hw_ani_setup(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1044 | { |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1045 | int i; |
| 1046 | |
| 1047 | const int totalSizeDesired[] = { -55, -55, -55, -55, -62 }; |
| 1048 | const int coarseHigh[] = { -14, -14, -14, -14, -12 }; |
| 1049 | const int coarseLow[] = { -64, -64, -64, -64, -70 }; |
| 1050 | const int firpwr[] = { -78, -78, -78, -78, -80 }; |
| 1051 | |
| 1052 | for (i = 0; i < 5; i++) { |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1053 | ah->totalSizeDesired[i] = totalSizeDesired[i]; |
| 1054 | ah->coarse_high[i] = coarseHigh[i]; |
| 1055 | ah->coarse_low[i] = coarseLow[i]; |
| 1056 | ah->firpwr[i] = firpwr[i]; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
Luis R. Rodriguez | f637cfd | 2009-08-03 12:24:46 -0700 | [diff] [blame] | 1060 | void ath9k_hw_ani_init(struct ath_hw *ah) |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1061 | { |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1062 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1063 | int i; |
| 1064 | |
Luis R. Rodriguez | c46917b | 2009-09-13 02:42:02 -0700 | [diff] [blame] | 1065 | ath_print(common, ATH_DBG_ANI, "Initialize ANI\n"); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1066 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1067 | if (use_new_ani(ah)) { |
| 1068 | ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_NEW; |
| 1069 | ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_NEW; |
| 1070 | |
| 1071 | ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH_NEW; |
| 1072 | ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW_NEW; |
| 1073 | } else { |
| 1074 | ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_OLD; |
| 1075 | ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_OLD; |
| 1076 | |
| 1077 | ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH_OLD; |
| 1078 | ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW_OLD; |
| 1079 | } |
| 1080 | |
| 1081 | for (i = 0; i < ARRAY_SIZE(ah->channels); i++) { |
| 1082 | struct ath9k_channel *chan = &ah->channels[i]; |
| 1083 | struct ar5416AniState *ani = &chan->ani; |
| 1084 | |
Felix Fietkau | 71ea420 | 2010-10-04 20:09:46 +0200 | [diff] [blame] | 1085 | if (use_new_ani(ah)) { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1086 | ani->spurImmunityLevel = |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1087 | ATH9K_ANI_SPUR_IMMUNE_LVL_NEW; |
| 1088 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1089 | ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1090 | |
| 1091 | if (AR_SREV_9300_20_OR_LATER(ah)) |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1092 | ani->mrcCCKOff = |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1093 | !ATH9K_ANI_ENABLE_MRC_CCK; |
| 1094 | else |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1095 | ani->mrcCCKOff = true; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1096 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1097 | ani->ofdmsTurn = true; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1098 | } else { |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1099 | ani->spurImmunityLevel = |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1100 | ATH9K_ANI_SPUR_IMMUNE_LVL_OLD; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1101 | ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_OLD; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1102 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1103 | ani->cckWeakSigThreshold = |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1104 | ATH9K_ANI_CCK_WEAK_SIG_THR; |
| 1105 | } |
| 1106 | |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1107 | ani->rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH; |
| 1108 | ani->rssiThrLow = ATH9K_ANI_RSSI_THR_LOW; |
| 1109 | ani->ofdmWeakSigDetectOff = |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1110 | !ATH9K_ANI_USE_OFDM_WEAK_SIG; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1111 | ani->cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /* |
| 1115 | * since we expect some ongoing maintenance on the tables, let's sanity |
| 1116 | * check here default level should not modify INI setting. |
| 1117 | */ |
Felix Fietkau | 71ea420 | 2010-10-04 20:09:46 +0200 | [diff] [blame] | 1118 | if (use_new_ani(ah)) { |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1119 | const struct ani_ofdm_level_entry *entry_ofdm; |
| 1120 | const struct ani_cck_level_entry *entry_cck; |
| 1121 | |
| 1122 | entry_ofdm = &ofdm_level_table[ATH9K_ANI_OFDM_DEF_LEVEL]; |
| 1123 | entry_cck = &cck_level_table[ATH9K_ANI_CCK_DEF_LEVEL]; |
| 1124 | |
| 1125 | ah->aniperiod = ATH9K_ANI_PERIOD_NEW; |
| 1126 | ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_NEW; |
| 1127 | } else { |
| 1128 | ah->aniperiod = ATH9K_ANI_PERIOD_OLD; |
| 1129 | ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_OLD; |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1130 | } |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1131 | |
Sujith | 2660b81 | 2009-02-09 13:27:26 +0530 | [diff] [blame] | 1132 | if (ah->config.enable_ani) |
| 1133 | ah->proc_phyerr |= HAL_PROCESS_ANI; |
Felix Fietkau | 093115b | 2010-10-04 20:09:47 +0200 | [diff] [blame^] | 1134 | |
| 1135 | ath9k_ani_restart(ah); |
| 1136 | ath9k_enable_mib_counters(ah); |
Sujith | f1dc560 | 2008-10-29 10:16:30 +0530 | [diff] [blame] | 1137 | } |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 1138 | |
| 1139 | void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah) |
| 1140 | { |
| 1141 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); |
| 1142 | struct ath_hw_ops *ops = ath9k_hw_ops(ah); |
| 1143 | |
| 1144 | priv_ops->ani_reset = ath9k_ani_reset_old; |
| 1145 | priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_old; |
| 1146 | |
| 1147 | ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_old; |
| 1148 | ops->ani_monitor = ath9k_hw_ani_monitor_old; |
Luis R. Rodriguez | e36b27a | 2010-06-12 00:33:45 -0400 | [diff] [blame] | 1149 | |
| 1150 | ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v1\n"); |
| 1151 | } |
| 1152 | |
| 1153 | void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah) |
| 1154 | { |
| 1155 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); |
| 1156 | struct ath_hw_ops *ops = ath9k_hw_ops(ah); |
| 1157 | |
| 1158 | priv_ops->ani_reset = ath9k_ani_reset_new; |
| 1159 | priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_new; |
| 1160 | |
| 1161 | ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_new; |
| 1162 | ops->ani_monitor = ath9k_hw_ani_monitor_new; |
| 1163 | |
| 1164 | ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v2\n"); |
Luis R. Rodriguez | ac0bb76 | 2010-06-12 00:33:42 -0400 | [diff] [blame] | 1165 | } |