2 * Copyright (c) 2007-2008 Atheros Communications Inc.
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.
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.
16 #include "../80211core/cprecomp.h"
21 extern u16_t zfDelayWriteInternalReg(zdev_t* dev, u32_t addr, u32_t val);
22 extern u16_t zfFlushDelayWrite(zdev_t* dev);
25 * Anti noise immunity support. We track phy errors and react
26 * to excessive errors by adjusting the noise immunity parameters.
29 /******************************************************************************
31 * New Ani Algorithm for Station side only
33 *****************************************************************************/
35 #define ZM_HAL_NOISE_IMMUNE_MAX 4 /* Max noise immunity level */
36 #define ZM_HAL_SPUR_IMMUNE_MAX 7 /* Max spur immunity level */
37 #define ZM_HAL_FIRST_STEP_MAX 2 /* Max first step level */
39 #define ZM_HAL_ANI_OFDM_TRIG_HIGH 500
40 #define ZM_HAL_ANI_OFDM_TRIG_LOW 200
41 #define ZM_HAL_ANI_CCK_TRIG_HIGH 200
42 #define ZM_HAL_ANI_CCK_TRIG_LOW 100
43 #define ZM_HAL_ANI_NOISE_IMMUNE_LVL 4
44 #define ZM_HAL_ANI_USE_OFDM_WEAK_SIG TRUE
45 #define ZM_HAL_ANI_CCK_WEAK_SIG_THR FALSE
46 #define ZM_HAL_ANI_SPUR_IMMUNE_LVL 7
47 #define ZM_HAL_ANI_FIRSTEP_LVL 0
48 #define ZM_HAL_ANI_RSSI_THR_HIGH 40
49 #define ZM_HAL_ANI_RSSI_THR_LOW 7
50 #define ZM_HAL_ANI_PERIOD 100
52 #define ZM_HAL_EP_RND(x, mul) \
53 ((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
55 s32_t BEACON_RSSI(zdev_t* dev)
59 zmw_get_wlan_dev(dev);
61 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
63 rssi = ZM_HAL_EP_RND(HpPriv->stats.ast_nodestats.ns_avgbrssi, ZM_HAL_RSSI_EP_MULTIPLIER);
69 * Setup ANI handling. Sets all thresholds and levels to default level AND
70 * resets the channel statistics
73 void zfHpAniAttach(zdev_t* dev)
75 #define N(a) (sizeof(a) / sizeof(a[0]))
78 zmw_get_wlan_dev(dev);
80 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
82 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
83 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
84 const int coarseLow[] = { -64, -64, -64, -64, -70 };
85 const int firpwr[] = { -78, -78, -78, -78, -80 };
87 for (i = 0; i < 5; i++)
89 HpPriv->totalSizeDesired[i] = totalSizeDesired[i];
90 HpPriv->coarseHigh[i] = coarseHigh[i];
91 HpPriv->coarseLow[i] = coarseLow[i];
92 HpPriv->firpwr[i] = firpwr[i];
95 /* owl has phy counters */
96 HpPriv->hasHwPhyCounters = 1;
98 memset((char *)&HpPriv->ani, 0, sizeof(HpPriv->ani));
99 for (i = 0; i < N(wd->regulationTable.allowChannel); i++)
102 HpPriv->ani[i].ofdmTrigHigh = ZM_HAL_ANI_OFDM_TRIG_HIGH;
103 HpPriv->ani[i].ofdmTrigLow = ZM_HAL_ANI_OFDM_TRIG_LOW;
104 HpPriv->ani[i].cckTrigHigh = ZM_HAL_ANI_CCK_TRIG_HIGH;
105 HpPriv->ani[i].cckTrigLow = ZM_HAL_ANI_CCK_TRIG_LOW;
106 HpPriv->ani[i].rssiThrHigh = ZM_HAL_ANI_RSSI_THR_HIGH;
107 HpPriv->ani[i].rssiThrLow = ZM_HAL_ANI_RSSI_THR_LOW;
108 HpPriv->ani[i].ofdmWeakSigDetectOff = !ZM_HAL_ANI_USE_OFDM_WEAK_SIG;
109 HpPriv->ani[i].cckWeakSigThreshold = ZM_HAL_ANI_CCK_WEAK_SIG_THR;
110 HpPriv->ani[i].spurImmunityLevel = ZM_HAL_ANI_SPUR_IMMUNE_LVL;
111 HpPriv->ani[i].firstepLevel = ZM_HAL_ANI_FIRSTEP_LVL;
112 if (HpPriv->hasHwPhyCounters)
114 HpPriv->ani[i].ofdmPhyErrBase = 0;//AR_PHY_COUNTMAX - ZM_HAL_ANI_OFDM_TRIG_HIGH;
115 HpPriv->ani[i].cckPhyErrBase = 0;//AR_PHY_COUNTMAX - ZM_HAL_ANI_CCK_TRIG_HIGH;
118 if (HpPriv->hasHwPhyCounters)
120 //zm_debug_msg2("Setting OfdmErrBase = 0x", HpPriv->ani[0].ofdmPhyErrBase);
121 //zm_debug_msg2("Setting cckErrBase = 0x", HpPriv->ani[0].cckPhyErrBase);
122 //OS_REG_WRITE(ah, AR_PHY_ERR_1, HpPriv->ani[0].ofdmPhyErrBase);
123 //OS_REG_WRITE(ah, AR_PHY_ERR_2, HpPriv->ani[0].cckPhyErrBase);
125 HpPriv->aniPeriod = ZM_HAL_ANI_PERIOD;
126 //if (ath_hal_enableANI)
127 HpPriv->procPhyErr |= ZM_HAL_PROCESS_ANI;
129 HpPriv->stats.ast_nodestats.ns_avgbrssi = ZM_RSSI_DUMMY_MARKER;
130 HpPriv->stats.ast_nodestats.ns_avgrssi = ZM_RSSI_DUMMY_MARKER;
131 HpPriv->stats.ast_nodestats.ns_avgtxrssi = ZM_RSSI_DUMMY_MARKER;
136 * Control Adaptive Noise Immunity Parameters
138 u8_t zfHpAniControl(zdev_t* dev, ZM_HAL_ANI_CMD cmd, int param)
140 #define N(a) (sizeof(a)/sizeof(a[0]))
141 typedef s32_t TABLE[];
143 zmw_get_wlan_dev(dev);
145 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
147 struct zsAniState *aniState = HpPriv->curani;
151 case ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL:
155 if (level >= N(HpPriv->totalSizeDesired))
157 zm_debug_msg1("level out of range, desired level : ", level);
158 zm_debug_msg1("max level : ", N(HpPriv->totalSizeDesired));
162 zfDelayWriteInternalReg(dev, AR_PHY_DESIRED_SZ,
163 (HpPriv->regPHYDesiredSZ & ~AR_PHY_DESIRED_SZ_TOT_DES)
164 | ((HpPriv->totalSizeDesired[level] << AR_PHY_DESIRED_SZ_TOT_DES_S)
165 & AR_PHY_DESIRED_SZ_TOT_DES));
166 zfDelayWriteInternalReg(dev, AR_PHY_AGC_CTL1,
167 (HpPriv->regPHYAgcCtl1 & ~AR_PHY_AGC_CTL1_COARSE_LOW)
168 | ((HpPriv->coarseLow[level] << AR_PHY_AGC_CTL1_COARSE_LOW_S)
169 & AR_PHY_AGC_CTL1_COARSE_LOW));
170 zfDelayWriteInternalReg(dev, AR_PHY_AGC_CTL1,
171 (HpPriv->regPHYAgcCtl1 & ~AR_PHY_AGC_CTL1_COARSE_HIGH)
172 | ((HpPriv->coarseHigh[level] << AR_PHY_AGC_CTL1_COARSE_HIGH_S)
173 & AR_PHY_AGC_CTL1_COARSE_HIGH));
174 zfDelayWriteInternalReg(dev, AR_PHY_FIND_SIG,
175 (HpPriv->regPHYFindSig & ~AR_PHY_FIND_SIG_FIRPWR)
176 | ((HpPriv->firpwr[level] << AR_PHY_FIND_SIG_FIRPWR_S)
177 & AR_PHY_FIND_SIG_FIRPWR));
178 zfFlushDelayWrite(dev);
180 if (level > aniState->noiseImmunityLevel)
181 HpPriv->stats.ast_ani_niup++;
182 else if (level < aniState->noiseImmunityLevel)
183 HpPriv->stats.ast_ani_nidown++;
184 aniState->noiseImmunityLevel = (u8_t)level;
187 case ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION:
189 const TABLE m1ThreshLow = { 127, 50 };
190 const TABLE m2ThreshLow = { 127, 40 };
191 const TABLE m1Thresh = { 127, 0x4d };
192 const TABLE m2Thresh = { 127, 0x40 };
193 const TABLE m2CountThr = { 31, 16 };
194 const TABLE m2CountThrLow = { 63, 48 };
195 u32_t on = param ? 1 : 0;
197 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
198 (HpPriv->regPHYSfcorrLow & ~AR_PHY_SFCORR_LOW_M1_THRESH_LOW)
199 | ((m1ThreshLow[on] << AR_PHY_SFCORR_LOW_M1_THRESH_LOW_S)
200 & AR_PHY_SFCORR_LOW_M1_THRESH_LOW));
201 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
202 (HpPriv->regPHYSfcorrLow & ~AR_PHY_SFCORR_LOW_M2_THRESH_LOW)
203 | ((m2ThreshLow[on] << AR_PHY_SFCORR_LOW_M2_THRESH_LOW_S)
204 & AR_PHY_SFCORR_LOW_M2_THRESH_LOW));
205 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR,
206 (HpPriv->regPHYSfcorr & ~AR_PHY_SFCORR_M1_THRESH)
207 | ((m1Thresh[on] << AR_PHY_SFCORR_M1_THRESH_S)
208 & AR_PHY_SFCORR_M1_THRESH));
209 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR,
210 (HpPriv->regPHYSfcorr & ~AR_PHY_SFCORR_M2_THRESH)
211 | ((m2Thresh[on] << AR_PHY_SFCORR_M2_THRESH_S)
212 & AR_PHY_SFCORR_M2_THRESH));
213 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR,
214 (HpPriv->regPHYSfcorr & ~AR_PHY_SFCORR_M2COUNT_THR)
215 | ((m2CountThr[on] << AR_PHY_SFCORR_M2COUNT_THR_S)
216 & AR_PHY_SFCORR_M2COUNT_THR));
217 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
218 (HpPriv->regPHYSfcorrLow & ~AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW)
219 | ((m2CountThrLow[on] << AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW_S)
220 & AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW));
224 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
225 HpPriv->regPHYSfcorrLow | AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
229 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
230 HpPriv->regPHYSfcorrLow & ~AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
232 zfFlushDelayWrite(dev);
233 if (!on != aniState->ofdmWeakSigDetectOff)
236 HpPriv->stats.ast_ani_ofdmon++;
238 HpPriv->stats.ast_ani_ofdmoff++;
239 aniState->ofdmWeakSigDetectOff = !on;
243 case ZM_HAL_ANI_CCK_WEAK_SIGNAL_THR:
245 const TABLE weakSigThrCck = { 8, 6 };
246 u32_t high = param ? 1 : 0;
248 zfDelayWriteInternalReg(dev, AR_PHY_CCK_DETECT,
249 (HpPriv->regPHYCckDetect & ~AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK)
250 | ((weakSigThrCck[high] << AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK_S)
251 & AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK));
252 zfFlushDelayWrite(dev);
253 if (high != aniState->cckWeakSigThreshold)
256 HpPriv->stats.ast_ani_cckhigh++;
258 HpPriv->stats.ast_ani_ccklow++;
259 aniState->cckWeakSigThreshold = (u8_t)high;
263 case ZM_HAL_ANI_FIRSTEP_LEVEL:
265 const TABLE firstep = { 0, 4, 8 };
268 if (level >= N(firstep))
270 zm_debug_msg1("level out of range, desired level : ", level);
271 zm_debug_msg1("max level : ", N(firstep));
274 zfDelayWriteInternalReg(dev, AR_PHY_FIND_SIG,
275 (HpPriv->regPHYFindSig & ~AR_PHY_FIND_SIG_FIRSTEP)
276 | ((firstep[level] << AR_PHY_FIND_SIG_FIRSTEP_S)
277 & AR_PHY_FIND_SIG_FIRSTEP));
278 zfFlushDelayWrite(dev);
279 if (level > aniState->firstepLevel)
280 HpPriv->stats.ast_ani_stepup++;
281 else if (level < aniState->firstepLevel)
282 HpPriv->stats.ast_ani_stepdown++;
283 aniState->firstepLevel = (u8_t)level;
286 case ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL:
288 const TABLE cycpwrThr1 = { 2, 4, 6, 8, 10, 12, 14, 16 };
291 if (level >= N(cycpwrThr1))
293 zm_debug_msg1("level out of range, desired level : ", level);
294 zm_debug_msg1("max level : ", N(cycpwrThr1));
297 zfDelayWriteInternalReg(dev, AR_PHY_TIMING5,
298 (HpPriv->regPHYTiming5 & ~AR_PHY_TIMING5_CYCPWR_THR1)
299 | ((cycpwrThr1[level] << AR_PHY_TIMING5_CYCPWR_THR1_S)
300 & AR_PHY_TIMING5_CYCPWR_THR1));
301 zfFlushDelayWrite(dev);
302 if (level > aniState->spurImmunityLevel)
303 HpPriv->stats.ast_ani_spurup++;
304 else if (level < aniState->spurImmunityLevel)
305 HpPriv->stats.ast_ani_spurdown++;
306 aniState->spurImmunityLevel = (u8_t)level;
309 case ZM_HAL_ANI_PRESENT:
311 #ifdef AH_PRIVATE_DIAG
312 case ZM_HAL_ANI_MODE:
315 HpPriv->procPhyErr &= ~ZM_HAL_PROCESS_ANI;
316 /* Turn off HW counters if we have them */
318 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) &~ HAL_RX_FILTER_PHYERR);
321 { /* normal/auto mode */
322 HpPriv->procPhyErr |= ZM_HAL_PROCESS_ANI;
323 if (HpPriv->hasHwPhyCounters)
325 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) &~ HAL_RX_FILTER_PHYERR);
329 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) | HAL_RX_FILTER_PHYERR);
333 case ZM_HAL_ANI_PHYERR_RESET:
334 HpPriv->stats.ast_ani_ofdmerrs = 0;
335 HpPriv->stats.ast_ani_cckerrs = 0;
337 #endif /* AH_PRIVATE_DIAG */
339 zm_debug_msg1("invalid cmd ", cmd);
346 void zfHpAniRestart(zdev_t* dev)
348 struct zsAniState *aniState;
350 zmw_get_wlan_dev(dev);
352 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
354 aniState = HpPriv->curani;
356 aniState->listenTime = 0;
357 if (HpPriv->hasHwPhyCounters)
359 //if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX)
361 // aniState->ofdmPhyErrBase = 0;
362 // zm_debug_msg0("OFDM Trigger is too high for hw counters");
365 // aniState->ofdmPhyErrBase = AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
366 //if (aniState->cckTrigHigh > AR_PHY_COUNTMAX)
368 // aniState->cckPhyErrBase = 0;
369 // zm_debug_msg0("CCK Trigger is too high for hw counters");
372 // aniState->cckPhyErrBase = AR_PHY_COUNTMAX - aniState->cckTrigHigh;
373 //zm_debug_msg2("Writing ofdmbase = 0x", aniState->ofdmPhyErrBase);
374 //zm_debug_msg2("Writing cckbase = 0x", aniState->cckPhyErrBase);
375 //OS_REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
376 //OS_REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
377 //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
378 //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
379 aniState->ofdmPhyErrBase = 0;
380 aniState->cckPhyErrBase = 0;
382 aniState->ofdmPhyErrCount = 0;
383 aniState->cckPhyErrCount = 0;
386 void zfHpAniOfdmErrTrigger(zdev_t* dev)
388 struct zsAniState *aniState;
391 zmw_get_wlan_dev(dev);
393 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
395 //HALASSERT(chan != NULL);
397 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
400 aniState = HpPriv->curani;
401 /* First, raise noise immunity level, up to max */
402 if (aniState->noiseImmunityLevel < ZM_HAL_NOISE_IMMUNE_MAX)
404 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL, aniState->noiseImmunityLevel + 1);
407 /* then, raise spur immunity level, up to max */
408 if (aniState->spurImmunityLevel < ZM_HAL_SPUR_IMMUNE_MAX)
410 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, aniState->spurImmunityLevel + 1);
413 rssi = BEACON_RSSI(dev);
414 if (rssi > aniState->rssiThrHigh)
417 * Beacon rssi is high, can turn off ofdm weak sig detect.
419 if (!aniState->ofdmWeakSigDetectOff)
421 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, FALSE);
422 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, 0);
426 * If weak sig detect is already off, as last resort, raise
429 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
431 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
435 else if (rssi > aniState->rssiThrLow)
438 * Beacon rssi in mid range, need ofdm weak signal detect,
439 * but we can raise firststepLevel
441 if (aniState->ofdmWeakSigDetectOff)
442 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, TRUE);
443 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
444 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
450 * Beacon rssi is low, if in 11b/g mode, turn off ofdm
451 * weak sign detction and zero firstepLevel to maximize
454 if (wd->frequency < 3000)
456 if (!aniState->ofdmWeakSigDetectOff)
457 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, FALSE);
458 if (aniState->firstepLevel > 0)
459 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, 0);
465 void zfHpAniCckErrTrigger(zdev_t* dev)
467 struct zsAniState *aniState;
470 zmw_get_wlan_dev(dev);
472 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
474 //HALASSERT(chan != NULL);
476 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
479 /* first, raise noise immunity level, up to max */
480 aniState = HpPriv->curani;
481 if (aniState->noiseImmunityLevel < ZM_HAL_NOISE_IMMUNE_MAX)
483 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL,
484 aniState->noiseImmunityLevel + 1);
487 rssi = BEACON_RSSI(dev);
488 if (rssi > aniState->rssiThrLow)
491 * Beacon signal in mid and high range, raise firsteplevel.
493 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
494 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
499 * Beacon rssi is low, zero firstepLevel to maximize
502 if (wd->frequency < 3000)
504 if (aniState->firstepLevel > 0)
505 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, 0);
510 void zfHpAniLowerImmunity(zdev_t* dev)
512 struct zsAniState *aniState;
515 zmw_get_wlan_dev(dev);
517 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
519 aniState = HpPriv->curani;
521 rssi = BEACON_RSSI(dev);
522 if (rssi > aniState->rssiThrHigh)
525 * Beacon signal is high, leave ofdm weak signal detection off
526 * or it may oscillate. Let it fall through.
529 else if (rssi > aniState->rssiThrLow)
532 * Beacon rssi in mid range, turn on ofdm weak signal
533 * detection or lower first step level.
535 if (aniState->ofdmWeakSigDetectOff)
537 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, TRUE);
540 if (aniState->firstepLevel > 0)
542 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel - 1);
549 * Beacon rssi is low, reduce first step level.
551 if (aniState->firstepLevel > 0)
553 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel - 1);
557 /* then lower spur immunity level, down to zero */
558 if (aniState->spurImmunityLevel > 0)
560 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, aniState->spurImmunityLevel - 1);
564 * if all else fails, lower noise immunity level down to a min value
567 if (aniState->noiseImmunityLevel > 0)
569 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL, aniState->noiseImmunityLevel - 1);
574 #define CLOCK_RATE 44000 /* XXX use mac_usec or similar */
575 /* convert HW counter values to ms using 11g clock rate, goo9d enough
579 * Return an approximation of the time spent ``listening'' by
580 * deducting the cycles spent tx'ing and rx'ing from the total
581 * cycle count since our last call. A return value <0 indicates
582 * an invalid/inconsistent time.
584 s32_t zfHpAniGetListenTime(zdev_t* dev)
586 struct zsAniState *aniState;
587 u32_t txFrameCount, rxFrameCount, cycleCount;
590 zmw_get_wlan_dev(dev);
592 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
594 txFrameCount = 0;//OS_REG_READ(ah, AR_TFCNT);
595 rxFrameCount = 0;//OS_REG_READ(ah, AR_RFCNT);
596 cycleCount = 0;//OS_REG_READ(ah, AR_CCCNT);
598 aniState = HpPriv->curani;
599 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount)
602 * Cycle counter wrap (or initial call); it's not possible
603 * to accurately calculate a value because the registers
604 * right shift rather than wrap--so punt and return 0.
607 HpPriv->stats.ast_ani_lzero++;
611 s32_t ccdelta = cycleCount - aniState->cycleCount;
612 s32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
613 s32_t tfdelta = txFrameCount - aniState->txFrameCount;
614 listenTime = (ccdelta - rfdelta - tfdelta) / CLOCK_RATE;
616 aniState->cycleCount = cycleCount;
617 aniState->txFrameCount = txFrameCount;
618 aniState->rxFrameCount = rxFrameCount;
623 * Do periodic processing. This routine is called from the
624 * driver's rx interrupt handler after processing frames.
626 void zfHpAniArPoll(zdev_t* dev, u32_t listenTime, u32_t phyCnt1, u32_t phyCnt2)
628 struct zsAniState *aniState;
631 zmw_get_wlan_dev(dev);
633 struct zsHpPriv *HpPriv = (struct zsHpPriv*)wd->hpPrivate;
636 * Since we're called from end of rx tasklet, we also check for
640 aniState = HpPriv->curani;
641 //HpPriv->stats.ast_nodestats = *stats; /* XXX optimize? */
643 //listenTime = zfHpAniGetListenTime(dev);
644 //if (listenTime < 0)
646 // HpPriv->stats.ast_ani_lneg++;
647 // /* restart ANI period if listenTime is invalid */
648 // zfHpAniRestart(dev);
651 /* XXX beware of overflow? */
652 aniState->listenTime += listenTime;
654 if (HpPriv->hasHwPhyCounters)
656 //u32_t phyCnt1, phyCnt2;
657 u32_t ofdmPhyErrCnt, cckPhyErrCnt;
659 /* NB: these are not reset-on-read */
660 //phyCnt1 = 0;//OS_REG_READ(ah, AR_PHY_ERR_1);
661 //phyCnt2 = 0;//OS_REG_READ(ah, AR_PHY_ERR_2);
662 /* XXX sometimes zero, why? */
663 //if (phyCnt1 < aniState->ofdmPhyErrBase ||
664 // phyCnt2 < aniState->cckPhyErrBase)
666 // if (phyCnt1 < aniState->ofdmPhyErrBase)
668 // zm_debug_msg2("phyCnt1 = 0x", phyCnt1);
669 // zm_debug_msg2("resetting counter value to 0x", aniState->ofdmPhyErrBase);
670 // //OS_REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
671 // //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
673 // if (phyCnt2 < aniState->cckPhyErrBase)
675 // zm_debug_msg2("phyCnt2 = 0x", phyCnt2);
676 // zm_debug_msg2("resetting counter value to 0x", aniState->cckPhyErrBase);
677 // //OS_REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
678 // //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
682 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
683 //ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
684 //HpPriv->stats.ast_ani_ofdmerrs += ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
685 //aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
686 ofdmPhyErrCnt = phyCnt1;
687 HpPriv->stats.ast_ani_ofdmerrs += ofdmPhyErrCnt;
688 aniState->ofdmPhyErrCount += ofdmPhyErrCnt;
690 //cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
691 //HpPriv->stats.ast_ani_cckerrs += cckPhyErrCnt - aniState->cckPhyErrCount;
692 //aniState->cckPhyErrCount = cckPhyErrCnt;
693 cckPhyErrCnt = phyCnt2;
694 HpPriv->stats.ast_ani_cckerrs += cckPhyErrCnt;
695 aniState->cckPhyErrCount += cckPhyErrCnt;
698 * If ani is not enabled, return after we've collected
701 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
703 if (aniState->listenTime > 5 * HpPriv->aniPeriod)
706 * Check to see if need to lower immunity if
707 * 5 aniPeriods have passed
709 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
710 aniState->ofdmTrigLow/1000 &&
711 aniState->cckPhyErrCount <= aniState->listenTime *
712 aniState->cckTrigLow/1000)
713 zfHpAniLowerImmunity(dev);
716 else if (aniState->listenTime > HpPriv->aniPeriod)
718 /* check to see if need to raise immunity */
719 if (aniState->ofdmPhyErrCount > aniState->listenTime *
720 aniState->ofdmTrigHigh / 1000)
722 zfHpAniOfdmErrTrigger(dev);
725 else if (aniState->cckPhyErrCount > aniState->listenTime *
726 aniState->cckTrigHigh / 1000)
728 zfHpAniCckErrTrigger(dev);