blob: 0496f965314fa8417ba79d30d161a221e16ad630 [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04002 * Copyright (c) 2008-2010 Atheros Communications Inc.
Sujithf1dc5602008-10-29 10:16:30 +05303 *
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 Angelinasbbce80e2010-09-08 22:25:42 +010017#include <linux/kernel.h>
Luis R. Rodriguezcfe8cba2009-09-13 23:39:31 -070018#include "hw.h"
Felix Fietkauc16fcb42010-04-15 17:38:39 -040019#include "hw-ops.h"
Sujithf1dc5602008-10-29 10:16:30 +053020
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040021struct 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
38static 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 Angelinasbbce80e2010-09-08 22:25:42 +010052 ARRAY_SIZE(ofdm_level_table)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040053#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
79struct ani_cck_level_entry {
80 int fir_step_level;
81 int mrc_cck_on;
82};
83
84static 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 Angelinasbbce80e2010-09-08 22:25:42 +010098 ARRAY_SIZE(cck_level_table)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -040099#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. Rodriguezac0bb762010-06-12 00:33:42 -0400106/* Private to ani.c */
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400107static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -0400108{
109 ath9k_hw_private_ops(ah)->ani_lower_immunity(ah);
110}
111
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400112int ath9k_hw_get_ani_channel_idx(struct ath_hw *ah,
113 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +0530114{
Sujithf1dc5602008-10-29 10:16:30 +0530115 int i;
116
Sujith2660b812009-02-09 13:27:26 +0530117 for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
118 if (ah->ani[i].c &&
119 ah->ani[i].c->channel == chan->channel)
Sujithf1dc5602008-10-29 10:16:30 +0530120 return i;
Sujith2660b812009-02-09 13:27:26 +0530121 if (ah->ani[i].c == NULL) {
122 ah->ani[i].c = chan;
Sujithf1dc5602008-10-29 10:16:30 +0530123 return i;
124 }
125 }
126
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700127 ath_print(ath9k_hw_common(ah), ATH_DBG_ANI,
128 "No more channel states left. Using channel 0\n");
Sujithf1dc5602008-10-29 10:16:30 +0530129
130 return 0;
131}
132
Sujithcbe61d82009-02-09 13:27:12 +0530133static void ath9k_hw_update_mibstats(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +0530134 struct ath9k_mib_stats *stats)
135{
136 stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
137 stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
138 stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
139 stats->rts_good += REG_READ(ah, AR_RTS_OK);
140 stats->beacons += REG_READ(ah, AR_BEACON_CNT);
141}
142
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400143static void ath9k_ani_restart_old(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530144{
Sujithf1dc5602008-10-29 10:16:30 +0530145 struct ar5416AniState *aniState;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700146 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530147
148 if (!DO_ANI(ah))
149 return;
150
Sujith2660b812009-02-09 13:27:26 +0530151 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530152 aniState->listenTime = 0;
Sujithf1dc5602008-10-29 10:16:30 +0530153
Sujith1aa8e842009-08-13 09:34:25 +0530154 if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
155 aniState->ofdmPhyErrBase = 0;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700156 ath_print(common, ATH_DBG_ANI,
157 "OFDM Trigger is too high for hw counters\n");
Sujith1aa8e842009-08-13 09:34:25 +0530158 } else {
159 aniState->ofdmPhyErrBase =
160 AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
Sujithf1dc5602008-10-29 10:16:30 +0530161 }
Sujith1aa8e842009-08-13 09:34:25 +0530162 if (aniState->cckTrigHigh > AR_PHY_COUNTMAX) {
163 aniState->cckPhyErrBase = 0;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700164 ath_print(common, ATH_DBG_ANI,
165 "CCK Trigger is too high for hw counters\n");
Sujith1aa8e842009-08-13 09:34:25 +0530166 } else {
167 aniState->cckPhyErrBase =
168 AR_PHY_COUNTMAX - aniState->cckTrigHigh;
169 }
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700170 ath_print(common, ATH_DBG_ANI,
171 "Writing ofdmbase=%u cckbase=%u\n",
172 aniState->ofdmPhyErrBase,
173 aniState->cckPhyErrBase);
Sujith7d0d0df2010-04-16 11:53:57 +0530174
175 ENABLE_REGWRITE_BUFFER(ah);
176
Sujith1aa8e842009-08-13 09:34:25 +0530177 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
178 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
179 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
180 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
181
Sujith7d0d0df2010-04-16 11:53:57 +0530182 REGWRITE_BUFFER_FLUSH(ah);
183 DISABLE_REGWRITE_BUFFER(ah);
184
Sujith1aa8e842009-08-13 09:34:25 +0530185 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
186
Sujithf1dc5602008-10-29 10:16:30 +0530187 aniState->ofdmPhyErrCount = 0;
188 aniState->cckPhyErrCount = 0;
189}
190
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400191static void ath9k_ani_restart_new(struct ath_hw *ah)
192{
193 struct ar5416AniState *aniState;
194 struct ath_common *common = ath9k_hw_common(ah);
195
196 if (!DO_ANI(ah))
197 return;
198
199 aniState = ah->curani;
200 aniState->listenTime = 0;
201
202 aniState->ofdmPhyErrBase = 0;
203 aniState->cckPhyErrBase = 0;
204
205 ath_print(common, ATH_DBG_ANI,
206 "Writing ofdmbase=%08x cckbase=%08x\n",
207 aniState->ofdmPhyErrBase,
208 aniState->cckPhyErrBase);
209
210 ENABLE_REGWRITE_BUFFER(ah);
211
212 REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
213 REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
214 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
215 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
216
217 REGWRITE_BUFFER_FLUSH(ah);
218 DISABLE_REGWRITE_BUFFER(ah);
219
220 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
221
222 aniState->ofdmPhyErrCount = 0;
223 aniState->cckPhyErrCount = 0;
224}
225
226static void ath9k_hw_ani_ofdm_err_trigger_old(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530227{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700228 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530229 struct ar5416AniState *aniState;
Sujithf1dc5602008-10-29 10:16:30 +0530230 int32_t rssi;
231
232 if (!DO_ANI(ah))
233 return;
234
Sujith2660b812009-02-09 13:27:26 +0530235 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530236
237 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
238 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
239 aniState->noiseImmunityLevel + 1)) {
240 return;
241 }
242 }
243
244 if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
245 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
246 aniState->spurImmunityLevel + 1)) {
247 return;
248 }
249 }
250
Sujith2660b812009-02-09 13:27:26 +0530251 if (ah->opmode == NL80211_IFTYPE_AP) {
Sujithf1dc5602008-10-29 10:16:30 +0530252 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
253 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
254 aniState->firstepLevel + 1);
255 }
256 return;
257 }
Sujithcbe61d82009-02-09 13:27:12 +0530258 rssi = BEACON_RSSI(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530259 if (rssi > aniState->rssiThrHigh) {
260 if (!aniState->ofdmWeakSigDetectOff) {
261 if (ath9k_hw_ani_control(ah,
262 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
263 false)) {
264 ath9k_hw_ani_control(ah,
265 ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
266 return;
267 }
268 }
269 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
270 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
271 aniState->firstepLevel + 1);
272 return;
273 }
274 } else if (rssi > aniState->rssiThrLow) {
275 if (aniState->ofdmWeakSigDetectOff)
276 ath9k_hw_ani_control(ah,
277 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
278 true);
279 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
280 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
281 aniState->firstepLevel + 1);
282 return;
283 } else {
Sujithd37b7da2009-09-11 08:30:03 +0530284 if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
285 !conf_is_ht(conf)) {
Sujithf1dc5602008-10-29 10:16:30 +0530286 if (!aniState->ofdmWeakSigDetectOff)
287 ath9k_hw_ani_control(ah,
288 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
289 false);
290 if (aniState->firstepLevel > 0)
291 ath9k_hw_ani_control(ah,
292 ATH9K_ANI_FIRSTEP_LEVEL, 0);
293 return;
294 }
295 }
296}
297
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400298static void ath9k_hw_ani_cck_err_trigger_old(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530299{
Luis R. Rodriguezb002a4a2009-09-13 00:03:27 -0700300 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
Sujithf1dc5602008-10-29 10:16:30 +0530301 struct ar5416AniState *aniState;
Sujithf1dc5602008-10-29 10:16:30 +0530302 int32_t rssi;
303
304 if (!DO_ANI(ah))
305 return;
306
Sujith2660b812009-02-09 13:27:26 +0530307 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530308 if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
309 if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
310 aniState->noiseImmunityLevel + 1)) {
311 return;
312 }
313 }
Sujith2660b812009-02-09 13:27:26 +0530314 if (ah->opmode == NL80211_IFTYPE_AP) {
Sujithf1dc5602008-10-29 10:16:30 +0530315 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
316 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
317 aniState->firstepLevel + 1);
318 }
319 return;
320 }
Sujithcbe61d82009-02-09 13:27:12 +0530321 rssi = BEACON_RSSI(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530322 if (rssi > aniState->rssiThrLow) {
323 if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
324 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
325 aniState->firstepLevel + 1);
326 } else {
Sujithd37b7da2009-09-11 08:30:03 +0530327 if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
328 !conf_is_ht(conf)) {
Sujithf1dc5602008-10-29 10:16:30 +0530329 if (aniState->firstepLevel > 0)
330 ath9k_hw_ani_control(ah,
331 ATH9K_ANI_FIRSTEP_LEVEL, 0);
332 }
333 }
334}
335
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400336/* Adjust the OFDM Noise Immunity Level */
337static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
338{
339 struct ar5416AniState *aniState = ah->curani;
340 struct ath_common *common = ath9k_hw_common(ah);
341 const struct ani_ofdm_level_entry *entry_ofdm;
342 const struct ani_cck_level_entry *entry_cck;
343
344 aniState->noiseFloor = BEACON_RSSI(ah);
345
346 ath_print(common, ATH_DBG_ANI,
347 "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
348 aniState->ofdmNoiseImmunityLevel,
349 immunityLevel, aniState->noiseFloor,
350 aniState->rssiThrLow, aniState->rssiThrHigh);
351
352 aniState->ofdmNoiseImmunityLevel = immunityLevel;
353
354 entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
355 entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
356
357 if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level)
358 ath9k_hw_ani_control(ah,
359 ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
360 entry_ofdm->spur_immunity_level);
361
362 if (aniState->firstepLevel != entry_ofdm->fir_step_level &&
363 entry_ofdm->fir_step_level >= entry_cck->fir_step_level)
364 ath9k_hw_ani_control(ah,
365 ATH9K_ANI_FIRSTEP_LEVEL,
366 entry_ofdm->fir_step_level);
367
368 if ((ah->opmode != NL80211_IFTYPE_STATION &&
369 ah->opmode != NL80211_IFTYPE_ADHOC) ||
370 aniState->noiseFloor <= aniState->rssiThrHigh) {
371 if (aniState->ofdmWeakSigDetectOff)
372 /* force on ofdm weak sig detect */
373 ath9k_hw_ani_control(ah,
374 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
375 true);
376 else if (aniState->ofdmWeakSigDetectOff ==
377 entry_ofdm->ofdm_weak_signal_on)
378 ath9k_hw_ani_control(ah,
379 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
380 entry_ofdm->ofdm_weak_signal_on);
381 }
382}
383
384static void ath9k_hw_ani_ofdm_err_trigger_new(struct ath_hw *ah)
385{
386 struct ar5416AniState *aniState;
387
388 if (!DO_ANI(ah))
389 return;
390
391 aniState = ah->curani;
392
393 if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
394 ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1);
395}
396
397/*
398 * Set the ANI settings to match an CCK level.
399 */
400static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel)
401{
402 struct ar5416AniState *aniState = ah->curani;
403 struct ath_common *common = ath9k_hw_common(ah);
404 const struct ani_ofdm_level_entry *entry_ofdm;
405 const struct ani_cck_level_entry *entry_cck;
406
407 aniState->noiseFloor = BEACON_RSSI(ah);
408 ath_print(common, ATH_DBG_ANI,
409 "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
410 aniState->cckNoiseImmunityLevel, immunityLevel,
411 aniState->noiseFloor, aniState->rssiThrLow,
412 aniState->rssiThrHigh);
413
414 if ((ah->opmode == NL80211_IFTYPE_STATION ||
415 ah->opmode == NL80211_IFTYPE_ADHOC) &&
416 aniState->noiseFloor <= aniState->rssiThrLow &&
417 immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
418 immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
419
420 aniState->cckNoiseImmunityLevel = immunityLevel;
421
422 entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
423 entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
424
425 if (aniState->firstepLevel != entry_cck->fir_step_level &&
426 entry_cck->fir_step_level >= entry_ofdm->fir_step_level)
427 ath9k_hw_ani_control(ah,
428 ATH9K_ANI_FIRSTEP_LEVEL,
429 entry_cck->fir_step_level);
430
431 /* Skip MRC CCK for pre AR9003 families */
432 if (!AR_SREV_9300_20_OR_LATER(ah))
433 return;
434
435 if (aniState->mrcCCKOff == entry_cck->mrc_cck_on)
436 ath9k_hw_ani_control(ah,
437 ATH9K_ANI_MRC_CCK,
438 entry_cck->mrc_cck_on);
439}
440
441static void ath9k_hw_ani_cck_err_trigger_new(struct ath_hw *ah)
442{
443 struct ar5416AniState *aniState;
444
445 if (!DO_ANI(ah))
446 return;
447
448 aniState = ah->curani;
449
450 if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
451 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1);
452}
453
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -0400454static void ath9k_hw_ani_lower_immunity_old(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530455{
Sujithf1dc5602008-10-29 10:16:30 +0530456 struct ar5416AniState *aniState;
457 int32_t rssi;
458
Sujith2660b812009-02-09 13:27:26 +0530459 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530460
Sujith2660b812009-02-09 13:27:26 +0530461 if (ah->opmode == NL80211_IFTYPE_AP) {
Sujithf1dc5602008-10-29 10:16:30 +0530462 if (aniState->firstepLevel > 0) {
463 if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
464 aniState->firstepLevel - 1))
465 return;
466 }
467 } else {
Sujithcbe61d82009-02-09 13:27:12 +0530468 rssi = BEACON_RSSI(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530469 if (rssi > aniState->rssiThrHigh) {
470 /* XXX: Handle me */
471 } else if (rssi > aniState->rssiThrLow) {
472 if (aniState->ofdmWeakSigDetectOff) {
473 if (ath9k_hw_ani_control(ah,
474 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
475 true) == true)
476 return;
477 }
478 if (aniState->firstepLevel > 0) {
479 if (ath9k_hw_ani_control(ah,
480 ATH9K_ANI_FIRSTEP_LEVEL,
481 aniState->firstepLevel - 1) == true)
482 return;
483 }
484 } else {
485 if (aniState->firstepLevel > 0) {
486 if (ath9k_hw_ani_control(ah,
487 ATH9K_ANI_FIRSTEP_LEVEL,
488 aniState->firstepLevel - 1) == true)
489 return;
490 }
491 }
492 }
493
494 if (aniState->spurImmunityLevel > 0) {
495 if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
496 aniState->spurImmunityLevel - 1))
497 return;
498 }
499
500 if (aniState->noiseImmunityLevel > 0) {
501 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
502 aniState->noiseImmunityLevel - 1);
503 return;
504 }
505}
506
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400507/*
508 * only lower either OFDM or CCK errors per turn
509 * we lower the other one next time
510 */
511static void ath9k_hw_ani_lower_immunity_new(struct ath_hw *ah)
512{
513 struct ar5416AniState *aniState;
514
515 aniState = ah->curani;
516
517 /* lower OFDM noise immunity */
518 if (aniState->ofdmNoiseImmunityLevel > 0 &&
519 (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
520 ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1);
521 return;
522 }
523
524 /* lower CCK noise immunity */
525 if (aniState->cckNoiseImmunityLevel > 0)
526 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
527}
528
Luis R. Rodriguez37e5bf62010-06-12 00:33:40 -0400529static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah)
530{
531 struct ath9k_channel *chan = ah->curchan;
532 struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
533 u8 clockrate; /* in MHz */
534
535 if (!ah->curchan) /* should really check for CCK instead */
536 clockrate = ATH9K_CLOCK_RATE_CCK;
537 else if (conf->channel->band == IEEE80211_BAND_2GHZ)
538 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
539 else if (IS_CHAN_A_FAST_CLOCK(ah, chan))
540 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
541 else
542 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
543
544 if (conf_is_ht40(conf))
545 return clockrate * 2;
546
547 return clockrate * 2;
548}
549
Sujithcbe61d82009-02-09 13:27:12 +0530550static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530551{
Sujithf1dc5602008-10-29 10:16:30 +0530552 struct ar5416AniState *aniState;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400553 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530554 u32 txFrameCount, rxFrameCount, cycleCount;
555 int32_t listenTime;
556
557 txFrameCount = REG_READ(ah, AR_TFCNT);
558 rxFrameCount = REG_READ(ah, AR_RFCNT);
559 cycleCount = REG_READ(ah, AR_CCCNT);
560
Sujith2660b812009-02-09 13:27:26 +0530561 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530562 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
Sujithf1dc5602008-10-29 10:16:30 +0530563 listenTime = 0;
Sujith2660b812009-02-09 13:27:26 +0530564 ah->stats.ast_ani_lzero++;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400565 ath_print(common, ATH_DBG_ANI,
566 "1st call: aniState->cycleCount=%d\n",
567 aniState->cycleCount);
Sujithf1dc5602008-10-29 10:16:30 +0530568 } else {
569 int32_t ccdelta = cycleCount - aniState->cycleCount;
570 int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
571 int32_t tfdelta = txFrameCount - aniState->txFrameCount;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400572 int32_t clock_rate;
Luis R. Rodriguez37e5bf62010-06-12 00:33:40 -0400573
574 /*
575 * convert HW counter values to ms using mode
576 * specifix clock rate
577 */
578 clock_rate = ath9k_hw_chan_2_clockrate_mhz(ah) * 1000;;
579
580 listenTime = (ccdelta - rfdelta - tfdelta) / clock_rate;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400581
582 ath_print(common, ATH_DBG_ANI,
583 "cyclecount=%d, rfcount=%d, "
584 "tfcount=%d, listenTime=%d CLOCK_RATE=%d\n",
585 ccdelta, rfdelta, tfdelta, listenTime, clock_rate);
Sujithf1dc5602008-10-29 10:16:30 +0530586 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400587
Sujithf1dc5602008-10-29 10:16:30 +0530588 aniState->cycleCount = cycleCount;
589 aniState->txFrameCount = txFrameCount;
590 aniState->rxFrameCount = rxFrameCount;
591
592 return listenTime;
593}
594
Luis R. Rodriguez40346b62010-06-12 00:33:44 -0400595static void ath9k_ani_reset_old(struct ath_hw *ah, bool is_scanning)
Sujithf1dc5602008-10-29 10:16:30 +0530596{
Sujithf1dc5602008-10-29 10:16:30 +0530597 struct ar5416AniState *aniState;
Sujith2660b812009-02-09 13:27:26 +0530598 struct ath9k_channel *chan = ah->curchan;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700599 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530600 int index;
601
602 if (!DO_ANI(ah))
603 return;
604
605 index = ath9k_hw_get_ani_channel_idx(ah, chan);
Sujith2660b812009-02-09 13:27:26 +0530606 aniState = &ah->ani[index];
607 ah->curani = aniState;
Sujithf1dc5602008-10-29 10:16:30 +0530608
Sujith2660b812009-02-09 13:27:26 +0530609 if (DO_ANI(ah) && ah->opmode != NL80211_IFTYPE_STATION
610 && ah->opmode != NL80211_IFTYPE_ADHOC) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700611 ath_print(common, ATH_DBG_ANI,
612 "Reset ANI state opmode %u\n", ah->opmode);
Sujith2660b812009-02-09 13:27:26 +0530613 ah->stats.ast_ani_reset++;
Sujithf1dc5602008-10-29 10:16:30 +0530614
Luis R. Rodriguezc66284f2009-07-16 10:17:35 -0700615 if (ah->opmode == NL80211_IFTYPE_AP) {
616 /*
617 * ath9k_hw_ani_control() will only process items set on
618 * ah->ani_function
619 */
620 if (IS_CHAN_2GHZ(chan))
621 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
622 ATH9K_ANI_FIRSTEP_LEVEL);
623 else
624 ah->ani_function = 0;
625 }
626
Sujithf1dc5602008-10-29 10:16:30 +0530627 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
628 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
629 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
630 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
631 !ATH9K_ANI_USE_OFDM_WEAK_SIG);
632 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
633 ATH9K_ANI_CCK_WEAK_SIG_THR);
634
635 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
636 ATH9K_RX_FILTER_PHYERR);
637
Sujith2660b812009-02-09 13:27:26 +0530638 if (ah->opmode == NL80211_IFTYPE_AP) {
639 ah->curani->ofdmTrigHigh =
640 ah->config.ofdm_trig_high;
641 ah->curani->ofdmTrigLow =
642 ah->config.ofdm_trig_low;
643 ah->curani->cckTrigHigh =
644 ah->config.cck_trig_high;
645 ah->curani->cckTrigLow =
646 ah->config.cck_trig_low;
Sujithf1dc5602008-10-29 10:16:30 +0530647 }
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400648 ath9k_ani_restart_old(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530649 return;
650 }
651
652 if (aniState->noiseImmunityLevel != 0)
653 ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
654 aniState->noiseImmunityLevel);
655 if (aniState->spurImmunityLevel != 0)
656 ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
657 aniState->spurImmunityLevel);
658 if (aniState->ofdmWeakSigDetectOff)
659 ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
660 !aniState->ofdmWeakSigDetectOff);
661 if (aniState->cckWeakSigThreshold)
662 ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
663 aniState->cckWeakSigThreshold);
664 if (aniState->firstepLevel != 0)
665 ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
666 aniState->firstepLevel);
Sujithf1dc5602008-10-29 10:16:30 +0530667
Sujith1aa8e842009-08-13 09:34:25 +0530668 ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) &
669 ~ATH9K_RX_FILTER_PHYERR);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400670 ath9k_ani_restart_old(ah);
671
672 ENABLE_REGWRITE_BUFFER(ah);
673
674 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
675 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
676
677 REGWRITE_BUFFER_FLUSH(ah);
678 DISABLE_REGWRITE_BUFFER(ah);
679}
680
681/*
682 * Restore the ANI parameters in the HAL and reset the statistics.
683 * This routine should be called for every hardware reset and for
684 * every channel change.
685 */
686static void ath9k_ani_reset_new(struct ath_hw *ah, bool is_scanning)
687{
688 struct ar5416AniState *aniState = ah->curani;
689 struct ath9k_channel *chan = ah->curchan;
690 struct ath_common *common = ath9k_hw_common(ah);
691
692 if (!DO_ANI(ah))
693 return;
694
695 BUG_ON(aniState == NULL);
696 ah->stats.ast_ani_reset++;
697
698 /* only allow a subset of functions in AP mode */
699 if (ah->opmode == NL80211_IFTYPE_AP) {
700 if (IS_CHAN_2GHZ(chan)) {
701 ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
702 ATH9K_ANI_FIRSTEP_LEVEL);
703 if (AR_SREV_9300_20_OR_LATER(ah))
704 ah->ani_function |= ATH9K_ANI_MRC_CCK;
705 } else
706 ah->ani_function = 0;
707 }
708
709 /* always allow mode (on/off) to be controlled */
710 ah->ani_function |= ATH9K_ANI_MODE;
711
712 if (is_scanning ||
713 (ah->opmode != NL80211_IFTYPE_STATION &&
714 ah->opmode != NL80211_IFTYPE_ADHOC)) {
715 /*
716 * If we're scanning or in AP mode, the defaults (ini)
717 * should be in place. For an AP we assume the historical
718 * levels for this channel are probably outdated so start
719 * from defaults instead.
720 */
721 if (aniState->ofdmNoiseImmunityLevel !=
722 ATH9K_ANI_OFDM_DEF_LEVEL ||
723 aniState->cckNoiseImmunityLevel !=
724 ATH9K_ANI_CCK_DEF_LEVEL) {
725 ath_print(common, ATH_DBG_ANI,
726 "Restore defaults: opmode %u "
727 "chan %d Mhz/0x%x is_scanning=%d "
728 "ofdm:%d cck:%d\n",
729 ah->opmode,
730 chan->channel,
731 chan->channelFlags,
732 is_scanning,
733 aniState->ofdmNoiseImmunityLevel,
734 aniState->cckNoiseImmunityLevel);
735
736 ath9k_hw_set_ofdm_nil(ah, ATH9K_ANI_OFDM_DEF_LEVEL);
737 ath9k_hw_set_cck_nil(ah, ATH9K_ANI_CCK_DEF_LEVEL);
738 }
739 } else {
740 /*
741 * restore historical levels for this channel
742 */
743 ath_print(common, ATH_DBG_ANI,
744 "Restore history: opmode %u "
745 "chan %d Mhz/0x%x is_scanning=%d "
746 "ofdm:%d cck:%d\n",
747 ah->opmode,
748 chan->channel,
749 chan->channelFlags,
750 is_scanning,
751 aniState->ofdmNoiseImmunityLevel,
752 aniState->cckNoiseImmunityLevel);
753
754 ath9k_hw_set_ofdm_nil(ah,
755 aniState->ofdmNoiseImmunityLevel);
756 ath9k_hw_set_cck_nil(ah,
757 aniState->cckNoiseImmunityLevel);
758 }
759
760 /*
761 * enable phy counters if hw supports or if not, enable phy
762 * interrupts (so we can count each one)
763 */
764 ath9k_ani_restart_new(ah);
Sujith7d0d0df2010-04-16 11:53:57 +0530765
766 ENABLE_REGWRITE_BUFFER(ah);
767
Sujith1aa8e842009-08-13 09:34:25 +0530768 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
769 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
Sujith7d0d0df2010-04-16 11:53:57 +0530770
771 REGWRITE_BUFFER_FLUSH(ah);
772 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530773}
774
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -0400775static void ath9k_hw_ani_monitor_old(struct ath_hw *ah,
776 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +0530777{
Sujithf1dc5602008-10-29 10:16:30 +0530778 struct ar5416AniState *aniState;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700779 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530780 int32_t listenTime;
Sujith1aa8e842009-08-13 09:34:25 +0530781 u32 phyCnt1, phyCnt2;
782 u32 ofdmPhyErrCnt, cckPhyErrCnt;
Sujithf1dc5602008-10-29 10:16:30 +0530783
Gabor Juhos99506882009-01-14 20:17:11 +0100784 if (!DO_ANI(ah))
785 return;
786
Sujith2660b812009-02-09 13:27:26 +0530787 aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +0530788
789 listenTime = ath9k_hw_ani_get_listen_time(ah);
790 if (listenTime < 0) {
Sujith2660b812009-02-09 13:27:26 +0530791 ah->stats.ast_ani_lneg++;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400792 ath9k_ani_restart_old(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530793 return;
794 }
795
796 aniState->listenTime += listenTime;
797
Sujith1aa8e842009-08-13 09:34:25 +0530798 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
Sujithf1dc5602008-10-29 10:16:30 +0530799
Sujith1aa8e842009-08-13 09:34:25 +0530800 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
801 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
Sujithf1dc5602008-10-29 10:16:30 +0530802
Sujith1aa8e842009-08-13 09:34:25 +0530803 if (phyCnt1 < aniState->ofdmPhyErrBase ||
804 phyCnt2 < aniState->cckPhyErrBase) {
805 if (phyCnt1 < aniState->ofdmPhyErrBase) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700806 ath_print(common, ATH_DBG_ANI,
807 "phyCnt1 0x%x, resetting "
808 "counter value to 0x%x\n",
809 phyCnt1,
810 aniState->ofdmPhyErrBase);
Sujith1aa8e842009-08-13 09:34:25 +0530811 REG_WRITE(ah, AR_PHY_ERR_1,
812 aniState->ofdmPhyErrBase);
813 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
814 AR_PHY_ERR_OFDM_TIMING);
Sujithf1dc5602008-10-29 10:16:30 +0530815 }
Sujith1aa8e842009-08-13 09:34:25 +0530816 if (phyCnt2 < aniState->cckPhyErrBase) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700817 ath_print(common, ATH_DBG_ANI,
818 "phyCnt2 0x%x, resetting "
819 "counter value to 0x%x\n",
820 phyCnt2,
821 aniState->cckPhyErrBase);
Sujith1aa8e842009-08-13 09:34:25 +0530822 REG_WRITE(ah, AR_PHY_ERR_2,
823 aniState->cckPhyErrBase);
824 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
825 AR_PHY_ERR_CCK_TIMING);
826 }
827 return;
Sujithf1dc5602008-10-29 10:16:30 +0530828 }
829
Sujith1aa8e842009-08-13 09:34:25 +0530830 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
831 ah->stats.ast_ani_ofdmerrs +=
832 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
833 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
834
835 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
836 ah->stats.ast_ani_cckerrs +=
837 cckPhyErrCnt - aniState->cckPhyErrCount;
838 aniState->cckPhyErrCount = cckPhyErrCnt;
839
Sujith2660b812009-02-09 13:27:26 +0530840 if (aniState->listenTime > 5 * ah->aniperiod) {
Sujithf1dc5602008-10-29 10:16:30 +0530841 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
842 aniState->ofdmTrigLow / 1000 &&
843 aniState->cckPhyErrCount <= aniState->listenTime *
844 aniState->cckTrigLow / 1000)
845 ath9k_hw_ani_lower_immunity(ah);
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400846 ath9k_ani_restart_old(ah);
Sujith2660b812009-02-09 13:27:26 +0530847 } else if (aniState->listenTime > ah->aniperiod) {
Sujithf1dc5602008-10-29 10:16:30 +0530848 if (aniState->ofdmPhyErrCount > aniState->listenTime *
849 aniState->ofdmTrigHigh / 1000) {
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400850 ath9k_hw_ani_ofdm_err_trigger_old(ah);
851 ath9k_ani_restart_old(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530852 } else if (aniState->cckPhyErrCount >
853 aniState->listenTime * aniState->cckTrigHigh /
854 1000) {
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -0400855 ath9k_hw_ani_cck_err_trigger_old(ah);
856 ath9k_ani_restart_old(ah);
857 }
858 }
859}
860
861static void ath9k_hw_ani_monitor_new(struct ath_hw *ah,
862 struct ath9k_channel *chan)
863{
864 struct ar5416AniState *aniState;
865 struct ath_common *common = ath9k_hw_common(ah);
866 int32_t listenTime;
867 u32 phyCnt1, phyCnt2;
868 u32 ofdmPhyErrCnt, cckPhyErrCnt;
869 u32 ofdmPhyErrRate, cckPhyErrRate;
870
871 if (!DO_ANI(ah))
872 return;
873
874 aniState = ah->curani;
875 if (WARN_ON(!aniState))
876 return;
877
878 listenTime = ath9k_hw_ani_get_listen_time(ah);
879 if (listenTime <= 0) {
880 ah->stats.ast_ani_lneg++;
881 /* restart ANI period if listenTime is invalid */
882 ath_print(common, ATH_DBG_ANI,
883 "listenTime=%d - on new ani monitor\n",
884 listenTime);
885 ath9k_ani_restart_new(ah);
886 return;
887 }
888
889 aniState->listenTime += listenTime;
890
891 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
892
893 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
894 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
895
896 if (phyCnt1 < aniState->ofdmPhyErrBase ||
897 phyCnt2 < aniState->cckPhyErrBase) {
898 if (phyCnt1 < aniState->ofdmPhyErrBase) {
899 ath_print(common, ATH_DBG_ANI,
900 "phyCnt1 0x%x, resetting "
901 "counter value to 0x%x\n",
902 phyCnt1,
903 aniState->ofdmPhyErrBase);
904 REG_WRITE(ah, AR_PHY_ERR_1,
905 aniState->ofdmPhyErrBase);
906 REG_WRITE(ah, AR_PHY_ERR_MASK_1,
907 AR_PHY_ERR_OFDM_TIMING);
908 }
909 if (phyCnt2 < aniState->cckPhyErrBase) {
910 ath_print(common, ATH_DBG_ANI,
911 "phyCnt2 0x%x, resetting "
912 "counter value to 0x%x\n",
913 phyCnt2,
914 aniState->cckPhyErrBase);
915 REG_WRITE(ah, AR_PHY_ERR_2,
916 aniState->cckPhyErrBase);
917 REG_WRITE(ah, AR_PHY_ERR_MASK_2,
918 AR_PHY_ERR_CCK_TIMING);
919 }
920 return;
921 }
922
923 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
924 ah->stats.ast_ani_ofdmerrs +=
925 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
926 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
927
928 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
929 ah->stats.ast_ani_cckerrs +=
930 cckPhyErrCnt - aniState->cckPhyErrCount;
931 aniState->cckPhyErrCount = cckPhyErrCnt;
932
933 ath_print(common, ATH_DBG_ANI,
934 "Errors: OFDM=0x%08x-0x%08x=%d "
935 "CCK=0x%08x-0x%08x=%d\n",
936 phyCnt1,
937 aniState->ofdmPhyErrBase,
938 ofdmPhyErrCnt,
939 phyCnt2,
940 aniState->cckPhyErrBase,
941 cckPhyErrCnt);
942
943 ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
944 aniState->listenTime;
945 cckPhyErrRate = aniState->cckPhyErrCount * 1000 /
946 aniState->listenTime;
947
948 ath_print(common, ATH_DBG_ANI,
949 "listenTime=%d OFDM:%d errs=%d/s CCK:%d "
950 "errs=%d/s ofdm_turn=%d\n",
951 listenTime, aniState->ofdmNoiseImmunityLevel,
952 ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
953 cckPhyErrRate, aniState->ofdmsTurn);
954
955 if (aniState->listenTime > 5 * ah->aniperiod) {
956 if (ofdmPhyErrRate <= aniState->ofdmTrigLow &&
957 cckPhyErrRate <= aniState->cckTrigLow) {
958 ath_print(common, ATH_DBG_ANI,
959 "1. listenTime=%d OFDM:%d errs=%d/s(<%d) "
960 "CCK:%d errs=%d/s(<%d) -> "
961 "ath9k_hw_ani_lower_immunity()\n",
962 aniState->listenTime,
963 aniState->ofdmNoiseImmunityLevel,
964 ofdmPhyErrRate,
965 aniState->ofdmTrigLow,
966 aniState->cckNoiseImmunityLevel,
967 cckPhyErrRate,
968 aniState->cckTrigLow);
969 ath9k_hw_ani_lower_immunity(ah);
970 aniState->ofdmsTurn = !aniState->ofdmsTurn;
971 }
972 ath_print(common, ATH_DBG_ANI,
973 "1 listenTime=%d ofdm=%d/s cck=%d/s - "
974 "calling ath9k_ani_restart_new()\n",
975 aniState->listenTime, ofdmPhyErrRate, cckPhyErrRate);
976 ath9k_ani_restart_new(ah);
977 } else if (aniState->listenTime > ah->aniperiod) {
978 /* check to see if need to raise immunity */
979 if (ofdmPhyErrRate > aniState->ofdmTrigHigh &&
980 (cckPhyErrRate <= aniState->cckTrigHigh ||
981 aniState->ofdmsTurn)) {
982 ath_print(common, ATH_DBG_ANI,
983 "2 listenTime=%d OFDM:%d errs=%d/s(>%d) -> "
984 "ath9k_hw_ani_ofdm_err_trigger_new()\n",
985 aniState->listenTime,
986 aniState->ofdmNoiseImmunityLevel,
987 ofdmPhyErrRate,
988 aniState->ofdmTrigHigh);
989 ath9k_hw_ani_ofdm_err_trigger_new(ah);
990 ath9k_ani_restart_new(ah);
991 aniState->ofdmsTurn = false;
992 } else if (cckPhyErrRate > aniState->cckTrigHigh) {
993 ath_print(common, ATH_DBG_ANI,
994 "3 listenTime=%d CCK:%d errs=%d/s(>%d) -> "
995 "ath9k_hw_ani_cck_err_trigger_new()\n",
996 aniState->listenTime,
997 aniState->cckNoiseImmunityLevel,
998 cckPhyErrRate,
999 aniState->cckTrigHigh);
1000 ath9k_hw_ani_cck_err_trigger_new(ah);
1001 ath9k_ani_restart_new(ah);
1002 aniState->ofdmsTurn = true;
Sujithf1dc5602008-10-29 10:16:30 +05301003 }
1004 }
1005}
1006
Sujithcbe61d82009-02-09 13:27:12 +05301007void ath9k_enable_mib_counters(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301008{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001009 struct ath_common *common = ath9k_hw_common(ah);
1010
1011 ath_print(common, ATH_DBG_ANI, "Enable MIB counters\n");
Sujithf1dc5602008-10-29 10:16:30 +05301012
Sujithcbe61d82009-02-09 13:27:12 +05301013 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
Sujithf1dc5602008-10-29 10:16:30 +05301014
Sujith7d0d0df2010-04-16 11:53:57 +05301015 ENABLE_REGWRITE_BUFFER(ah);
1016
Sujithf1dc5602008-10-29 10:16:30 +05301017 REG_WRITE(ah, AR_FILT_OFDM, 0);
1018 REG_WRITE(ah, AR_FILT_CCK, 0);
1019 REG_WRITE(ah, AR_MIBC,
1020 ~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
1021 & 0x0f);
1022 REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
1023 REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
Sujith7d0d0df2010-04-16 11:53:57 +05301024
1025 REGWRITE_BUFFER_FLUSH(ah);
1026 DISABLE_REGWRITE_BUFFER(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301027}
1028
Sujith0fd06c92009-02-12 10:06:51 +05301029/* Freeze the MIB counters, get the stats and then clear them */
Sujithcbe61d82009-02-09 13:27:12 +05301030void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301031{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001032 struct ath_common *common = ath9k_hw_common(ah);
1033
1034 ath_print(common, ATH_DBG_ANI, "Disable MIB counters\n");
1035
Sujith0fd06c92009-02-12 10:06:51 +05301036 REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
Sujithcbe61d82009-02-09 13:27:12 +05301037 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
Sujith0fd06c92009-02-12 10:06:51 +05301038 REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
Sujithf1dc5602008-10-29 10:16:30 +05301039 REG_WRITE(ah, AR_FILT_OFDM, 0);
1040 REG_WRITE(ah, AR_FILT_CCK, 0);
1041}
Sujith21d51302010-06-01 15:14:18 +05301042EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
Sujithf1dc5602008-10-29 10:16:30 +05301043
Sujithcbe61d82009-02-09 13:27:12 +05301044u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +05301045 u32 *rxc_pcnt,
1046 u32 *rxf_pcnt,
1047 u32 *txf_pcnt)
1048{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001049 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301050 static u32 cycles, rx_clear, rx_frame, tx_frame;
1051 u32 good = 1;
1052
1053 u32 rc = REG_READ(ah, AR_RCCNT);
1054 u32 rf = REG_READ(ah, AR_RFCNT);
1055 u32 tf = REG_READ(ah, AR_TFCNT);
1056 u32 cc = REG_READ(ah, AR_CCCNT);
1057
1058 if (cycles == 0 || cycles > cc) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001059 ath_print(common, ATH_DBG_ANI,
1060 "cycle counter wrap. ExtBusy = 0\n");
Sujithf1dc5602008-10-29 10:16:30 +05301061 good = 0;
1062 } else {
1063 u32 cc_d = cc - cycles;
1064 u32 rc_d = rc - rx_clear;
1065 u32 rf_d = rf - rx_frame;
1066 u32 tf_d = tf - tx_frame;
1067
1068 if (cc_d != 0) {
1069 *rxc_pcnt = rc_d * 100 / cc_d;
1070 *rxf_pcnt = rf_d * 100 / cc_d;
1071 *txf_pcnt = tf_d * 100 / cc_d;
1072 } else {
1073 good = 0;
1074 }
1075 }
1076
1077 cycles = cc;
1078 rx_frame = rf;
1079 rx_clear = rc;
1080 tx_frame = tf;
1081
1082 return good;
1083}
1084
1085/*
1086 * Process a MIB interrupt. We may potentially be invoked because
1087 * any of the MIB counters overflow/trigger so don't assume we're
1088 * here because a PHY error counter triggered.
1089 */
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -04001090static void ath9k_hw_proc_mib_event_old(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301091{
Sujithf1dc5602008-10-29 10:16:30 +05301092 u32 phyCnt1, phyCnt2;
1093
1094 /* Reset these counters regardless */
1095 REG_WRITE(ah, AR_FILT_OFDM, 0);
1096 REG_WRITE(ah, AR_FILT_CCK, 0);
1097 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
1098 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
1099
1100 /* Clear the mib counters and save them in the stats */
Sujithcbe61d82009-02-09 13:27:12 +05301101 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
Sujithf1dc5602008-10-29 10:16:30 +05301102
Luis R. Rodriguez6e97f0f2010-06-12 00:33:41 -04001103 if (!DO_ANI(ah)) {
1104 /*
1105 * We must always clear the interrupt cause by
1106 * resetting the phy error regs.
1107 */
1108 REG_WRITE(ah, AR_PHY_ERR_1, 0);
1109 REG_WRITE(ah, AR_PHY_ERR_2, 0);
Sujithf1dc5602008-10-29 10:16:30 +05301110 return;
Luis R. Rodriguez6e97f0f2010-06-12 00:33:41 -04001111 }
Sujithf1dc5602008-10-29 10:16:30 +05301112
1113 /* NB: these are not reset-on-read */
1114 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
1115 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
1116 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
1117 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
Sujith2660b812009-02-09 13:27:26 +05301118 struct ar5416AniState *aniState = ah->curani;
Sujithf1dc5602008-10-29 10:16:30 +05301119 u32 ofdmPhyErrCnt, cckPhyErrCnt;
1120
1121 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
1122 ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
Sujith2660b812009-02-09 13:27:26 +05301123 ah->stats.ast_ani_ofdmerrs +=
Sujithf1dc5602008-10-29 10:16:30 +05301124 ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
1125 aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
1126
1127 cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
Sujith2660b812009-02-09 13:27:26 +05301128 ah->stats.ast_ani_cckerrs +=
Sujithf1dc5602008-10-29 10:16:30 +05301129 cckPhyErrCnt - aniState->cckPhyErrCount;
1130 aniState->cckPhyErrCount = cckPhyErrCnt;
1131
1132 /*
1133 * NB: figure out which counter triggered. If both
1134 * trigger we'll only deal with one as the processing
1135 * clobbers the error counter so the trigger threshold
1136 * check will never be true.
1137 */
1138 if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001139 ath9k_hw_ani_ofdm_err_trigger_new(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301140 if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001141 ath9k_hw_ani_cck_err_trigger_old(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301142 /* NB: always restart to insure the h/w counters are reset */
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001143 ath9k_ani_restart_old(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301144 }
1145}
1146
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001147/*
1148 * Process a MIB interrupt. We may potentially be invoked because
1149 * any of the MIB counters overflow/trigger so don't assume we're
1150 * here because a PHY error counter triggered.
1151 */
1152static void ath9k_hw_proc_mib_event_new(struct ath_hw *ah)
1153{
1154 u32 phyCnt1, phyCnt2;
1155
1156 /* Reset these counters regardless */
1157 REG_WRITE(ah, AR_FILT_OFDM, 0);
1158 REG_WRITE(ah, AR_FILT_CCK, 0);
1159 if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
1160 REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
1161
1162 /* Clear the mib counters and save them in the stats */
1163 ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
1164
1165 if (!DO_ANI(ah)) {
1166 /*
1167 * We must always clear the interrupt cause by
1168 * resetting the phy error regs.
1169 */
1170 REG_WRITE(ah, AR_PHY_ERR_1, 0);
1171 REG_WRITE(ah, AR_PHY_ERR_2, 0);
1172 return;
1173 }
1174
1175 /* NB: these are not reset-on-read */
1176 phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
1177 phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
1178
1179 /* NB: always restart to insure the h/w counters are reset */
1180 if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
1181 ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK))
1182 ath9k_ani_restart_new(ah);
1183}
1184
Sujithcbe61d82009-02-09 13:27:12 +05301185void ath9k_hw_ani_setup(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301186{
Sujithf1dc5602008-10-29 10:16:30 +05301187 int i;
1188
1189 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
1190 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
1191 const int coarseLow[] = { -64, -64, -64, -64, -70 };
1192 const int firpwr[] = { -78, -78, -78, -78, -80 };
1193
1194 for (i = 0; i < 5; i++) {
Sujith2660b812009-02-09 13:27:26 +05301195 ah->totalSizeDesired[i] = totalSizeDesired[i];
1196 ah->coarse_high[i] = coarseHigh[i];
1197 ah->coarse_low[i] = coarseLow[i];
1198 ah->firpwr[i] = firpwr[i];
Sujithf1dc5602008-10-29 10:16:30 +05301199 }
1200}
1201
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -07001202void ath9k_hw_ani_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05301203{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001204 struct ath_common *common = ath9k_hw_common(ah);
Sujithf1dc5602008-10-29 10:16:30 +05301205 int i;
1206
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001207 ath_print(common, ATH_DBG_ANI, "Initialize ANI\n");
Sujithf1dc5602008-10-29 10:16:30 +05301208
Sujith2660b812009-02-09 13:27:26 +05301209 memset(ah->ani, 0, sizeof(ah->ani));
1210 for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001211 if (AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani) {
1212 ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH_NEW;
1213 ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW_NEW;
1214
1215 ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH_NEW;
1216 ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW_NEW;
1217
1218 ah->ani[i].spurImmunityLevel =
1219 ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1220
1221 ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1222
1223 ah->ani[i].ofdmPhyErrBase = 0;
1224 ah->ani[i].cckPhyErrBase = 0;
1225
1226 if (AR_SREV_9300_20_OR_LATER(ah))
1227 ah->ani[i].mrcCCKOff =
1228 !ATH9K_ANI_ENABLE_MRC_CCK;
1229 else
1230 ah->ani[i].mrcCCKOff = true;
1231
1232 ah->ani[i].ofdmsTurn = true;
1233 } else {
1234 ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH_OLD;
1235 ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW_OLD;
1236
1237 ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH_OLD;
1238 ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW_OLD;
1239
1240 ah->ani[i].spurImmunityLevel =
1241 ATH9K_ANI_SPUR_IMMUNE_LVL_OLD;
1242 ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL_OLD;
1243
1244 ah->ani[i].ofdmPhyErrBase =
1245 AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH_OLD;
1246 ah->ani[i].cckPhyErrBase =
1247 AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH_OLD;
1248 ah->ani[i].cckWeakSigThreshold =
1249 ATH9K_ANI_CCK_WEAK_SIG_THR;
1250 }
1251
Sujith2660b812009-02-09 13:27:26 +05301252 ah->ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
1253 ah->ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
1254 ah->ani[i].ofdmWeakSigDetectOff =
Sujithf1dc5602008-10-29 10:16:30 +05301255 !ATH9K_ANI_USE_OFDM_WEAK_SIG;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001256 ah->ani[i].cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
1257 }
1258
1259 /*
1260 * since we expect some ongoing maintenance on the tables, let's sanity
1261 * check here default level should not modify INI setting.
1262 */
1263 if (AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani) {
1264 const struct ani_ofdm_level_entry *entry_ofdm;
1265 const struct ani_cck_level_entry *entry_cck;
1266
1267 entry_ofdm = &ofdm_level_table[ATH9K_ANI_OFDM_DEF_LEVEL];
1268 entry_cck = &cck_level_table[ATH9K_ANI_CCK_DEF_LEVEL];
1269
1270 ah->aniperiod = ATH9K_ANI_PERIOD_NEW;
1271 ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_NEW;
1272 } else {
1273 ah->aniperiod = ATH9K_ANI_PERIOD_OLD;
1274 ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_OLD;
Sujithf1dc5602008-10-29 10:16:30 +05301275 }
Sujithf1dc5602008-10-29 10:16:30 +05301276
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001277 ath_print(common, ATH_DBG_ANI,
1278 "Setting OfdmErrBase = 0x%08x\n",
1279 ah->ani[0].ofdmPhyErrBase);
1280 ath_print(common, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
1281 ah->ani[0].cckPhyErrBase);
Sujith1aa8e842009-08-13 09:34:25 +05301282
Sujith7d0d0df2010-04-16 11:53:57 +05301283 ENABLE_REGWRITE_BUFFER(ah);
1284
Sujith1aa8e842009-08-13 09:34:25 +05301285 REG_WRITE(ah, AR_PHY_ERR_1, ah->ani[0].ofdmPhyErrBase);
1286 REG_WRITE(ah, AR_PHY_ERR_2, ah->ani[0].cckPhyErrBase);
Sujith7d0d0df2010-04-16 11:53:57 +05301287
1288 REGWRITE_BUFFER_FLUSH(ah);
1289 DISABLE_REGWRITE_BUFFER(ah);
1290
Sujith1aa8e842009-08-13 09:34:25 +05301291 ath9k_enable_mib_counters(ah);
1292
Sujith2660b812009-02-09 13:27:26 +05301293 if (ah->config.enable_ani)
1294 ah->proc_phyerr |= HAL_PROCESS_ANI;
Sujithf1dc5602008-10-29 10:16:30 +05301295}
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -04001296
1297void ath9k_hw_attach_ani_ops_old(struct ath_hw *ah)
1298{
1299 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
1300 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
1301
1302 priv_ops->ani_reset = ath9k_ani_reset_old;
1303 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_old;
1304
1305 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_old;
1306 ops->ani_monitor = ath9k_hw_ani_monitor_old;
Luis R. Rodrigueze36b27a2010-06-12 00:33:45 -04001307
1308 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v1\n");
1309}
1310
1311void ath9k_hw_attach_ani_ops_new(struct ath_hw *ah)
1312{
1313 struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
1314 struct ath_hw_ops *ops = ath9k_hw_ops(ah);
1315
1316 priv_ops->ani_reset = ath9k_ani_reset_new;
1317 priv_ops->ani_lower_immunity = ath9k_hw_ani_lower_immunity_new;
1318
1319 ops->ani_proc_mib_event = ath9k_hw_proc_mib_event_new;
1320 ops->ani_monitor = ath9k_hw_ani_monitor_new;
1321
1322 ath_print(ath9k_hw_common(ah), ATH_DBG_ANY, "Using ANI v2\n");
Luis R. Rodriguezac0bb762010-06-12 00:33:42 -04001323}