Full support for Ginger Console
[linux-ginger.git] / drivers / staging / otus / hal / hpani.c
blob0afecd8c2de4e1ff509988eca98ae0f32fe4b06b
1 /*
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"
17 #include "hpani.h"
18 #include "hpusb.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)
57 s32_t rssi;
58 struct zsHpPriv *HpPriv;
60 zmw_get_wlan_dev(dev);
61 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
63 rssi = ZM_HAL_EP_RND(HpPriv->stats.ast_nodestats.ns_avgbrssi, ZM_HAL_RSSI_EP_MULTIPLIER);
65 return rssi;
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]))
76 u32_t i;
77 struct zsHpPriv *HpPriv;
79 const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
80 const int coarseHigh[] = { -14, -14, -14, -14, -12 };
81 const int coarseLow[] = { -64, -64, -64, -64, -70 };
82 const int firpwr[] = { -78, -78, -78, -78, -80 };
84 zmw_get_wlan_dev(dev);
85 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
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++)
101 /* New ANI stuff */
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;
132 #undef N
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[];
142 struct zsHpPriv *HpPriv;
143 struct zsAniState *aniState;
145 zmw_get_wlan_dev(dev);
146 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
147 aniState = HpPriv->curani;
149 switch (cmd)
151 case ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL:
153 u32_t level = param;
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));
159 return FALSE;
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;
185 break;
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));
222 if (on)
224 zfDelayWriteInternalReg(dev, AR_PHY_SFCORR_LOW,
225 HpPriv->regPHYSfcorrLow | AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
227 else
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)
235 if (on)
236 HpPriv->stats.ast_ani_ofdmon++;
237 else
238 HpPriv->stats.ast_ani_ofdmoff++;
239 aniState->ofdmWeakSigDetectOff = !on;
241 break;
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)
255 if (high)
256 HpPriv->stats.ast_ani_cckhigh++;
257 else
258 HpPriv->stats.ast_ani_ccklow++;
259 aniState->cckWeakSigThreshold = (u8_t)high;
261 break;
263 case ZM_HAL_ANI_FIRSTEP_LEVEL:
265 const TABLE firstep = { 0, 4, 8 };
266 u32_t level = param;
268 if (level >= N(firstep))
270 zm_debug_msg1("level out of range, desired level : ", level);
271 zm_debug_msg1("max level : ", N(firstep));
272 return FALSE;
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;
284 break;
286 case ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL:
288 const TABLE cycpwrThr1 = { 2, 4, 6, 8, 10, 12, 14, 16 };
289 u32_t level = param;
291 if (level >= N(cycpwrThr1))
293 zm_debug_msg1("level out of range, desired level : ", level);
294 zm_debug_msg1("max level : ", N(cycpwrThr1));
295 return FALSE;
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;
307 break;
309 case ZM_HAL_ANI_PRESENT:
310 break;
311 #ifdef AH_PRIVATE_DIAG
312 case ZM_HAL_ANI_MODE:
313 if (param == 0)
315 HpPriv->procPhyErr &= ~ZM_HAL_PROCESS_ANI;
316 /* Turn off HW counters if we have them */
317 zfHpAniDetach(dev);
318 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) &~ HAL_RX_FILTER_PHYERR);
320 else
321 { /* normal/auto mode */
322 HpPriv->procPhyErr |= ZM_HAL_PROCESS_ANI;
323 if (HpPriv->hasHwPhyCounters)
325 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) &~ HAL_RX_FILTER_PHYERR);
327 else
329 //zfHpSetRxFilter(dev, zfHpGetRxFilter(dev) | HAL_RX_FILTER_PHYERR);
332 break;
333 case ZM_HAL_ANI_PHYERR_RESET:
334 HpPriv->stats.ast_ani_ofdmerrs = 0;
335 HpPriv->stats.ast_ani_cckerrs = 0;
336 break;
337 #endif /* AH_PRIVATE_DIAG */
338 default:
339 zm_debug_msg1("invalid cmd ", cmd);
340 return FALSE;
342 return TRUE;
343 #undef N
346 void zfHpAniRestart(zdev_t* dev)
348 struct zsAniState *aniState;
349 struct zsHpPriv *HpPriv;
351 zmw_get_wlan_dev(dev);
352 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
353 aniState = HpPriv->curani;
355 aniState->listenTime = 0;
356 if (HpPriv->hasHwPhyCounters)
358 //if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX)
360 // aniState->ofdmPhyErrBase = 0;
361 // zm_debug_msg0("OFDM Trigger is too high for hw counters");
363 //else
364 // aniState->ofdmPhyErrBase = AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
365 //if (aniState->cckTrigHigh > AR_PHY_COUNTMAX)
367 // aniState->cckPhyErrBase = 0;
368 // zm_debug_msg0("CCK Trigger is too high for hw counters");
370 //else
371 // aniState->cckPhyErrBase = AR_PHY_COUNTMAX - aniState->cckTrigHigh;
372 //zm_debug_msg2("Writing ofdmbase = 0x", aniState->ofdmPhyErrBase);
373 //zm_debug_msg2("Writing cckbase = 0x", aniState->cckPhyErrBase);
374 //OS_REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
375 //OS_REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
376 //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
377 //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
378 aniState->ofdmPhyErrBase = 0;
379 aniState->cckPhyErrBase = 0;
381 aniState->ofdmPhyErrCount = 0;
382 aniState->cckPhyErrCount = 0;
385 void zfHpAniOfdmErrTrigger(zdev_t* dev)
387 struct zsAniState *aniState;
388 s32_t rssi;
389 struct zsHpPriv *HpPriv;
391 zmw_get_wlan_dev(dev);
392 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
394 //HALASSERT(chan != NULL);
396 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
397 return;
399 aniState = HpPriv->curani;
400 /* First, raise noise immunity level, up to max */
401 if (aniState->noiseImmunityLevel < ZM_HAL_NOISE_IMMUNE_MAX)
403 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL, aniState->noiseImmunityLevel + 1);
404 return;
406 /* then, raise spur immunity level, up to max */
407 if (aniState->spurImmunityLevel < ZM_HAL_SPUR_IMMUNE_MAX)
409 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, aniState->spurImmunityLevel + 1);
410 return;
412 rssi = BEACON_RSSI(dev);
413 if (rssi > aniState->rssiThrHigh)
416 * Beacon rssi is high, can turn off ofdm weak sig detect.
418 if (!aniState->ofdmWeakSigDetectOff)
420 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, FALSE);
421 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, 0);
422 return;
425 * If weak sig detect is already off, as last resort, raise
426 * first step level
428 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
430 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
431 return;
434 else if (rssi > aniState->rssiThrLow)
437 * Beacon rssi in mid range, need ofdm weak signal detect,
438 * but we can raise firststepLevel
440 if (aniState->ofdmWeakSigDetectOff)
441 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, TRUE);
442 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
443 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
444 return;
446 else
449 * Beacon rssi is low, if in 11b/g mode, turn off ofdm
450 * weak sign detction and zero firstepLevel to maximize
451 * CCK sensitivity
453 if (wd->frequency < 3000)
455 if (!aniState->ofdmWeakSigDetectOff)
456 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, FALSE);
457 if (aniState->firstepLevel > 0)
458 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, 0);
459 return;
464 void zfHpAniCckErrTrigger(zdev_t* dev)
466 struct zsAniState *aniState;
467 s32_t rssi;
468 struct zsHpPriv *HpPriv;
470 zmw_get_wlan_dev(dev);
471 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
473 //HALASSERT(chan != NULL);
475 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
476 return;
478 /* first, raise noise immunity level, up to max */
479 aniState = HpPriv->curani;
480 if (aniState->noiseImmunityLevel < ZM_HAL_NOISE_IMMUNE_MAX)
482 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL,
483 aniState->noiseImmunityLevel + 1);
484 return;
486 rssi = BEACON_RSSI(dev);
487 if (rssi > aniState->rssiThrLow)
490 * Beacon signal in mid and high range, raise firsteplevel.
492 if (aniState->firstepLevel < ZM_HAL_FIRST_STEP_MAX)
493 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel + 1);
495 else
498 * Beacon rssi is low, zero firstepLevel to maximize
499 * CCK sensitivity.
501 if (wd->frequency < 3000)
503 if (aniState->firstepLevel > 0)
504 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, 0);
509 void zfHpAniLowerImmunity(zdev_t* dev)
511 struct zsAniState *aniState;
512 s32_t rssi;
513 struct zsHpPriv *HpPriv;
515 zmw_get_wlan_dev(dev);
516 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
517 aniState = HpPriv->curani;
519 rssi = BEACON_RSSI(dev);
520 if (rssi > aniState->rssiThrHigh)
523 * Beacon signal is high, leave ofdm weak signal detection off
524 * or it may oscillate. Let it fall through.
527 else if (rssi > aniState->rssiThrLow)
530 * Beacon rssi in mid range, turn on ofdm weak signal
531 * detection or lower first step level.
533 if (aniState->ofdmWeakSigDetectOff)
535 zfHpAniControl(dev, ZM_HAL_ANI_OFDM_WEAK_SIGNAL_DETECTION, TRUE);
536 return;
538 if (aniState->firstepLevel > 0)
540 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel - 1);
541 return;
544 else
547 * Beacon rssi is low, reduce first step level.
549 if (aniState->firstepLevel > 0)
551 zfHpAniControl(dev, ZM_HAL_ANI_FIRSTEP_LEVEL, aniState->firstepLevel - 1);
552 return;
555 /* then lower spur immunity level, down to zero */
556 if (aniState->spurImmunityLevel > 0)
558 zfHpAniControl(dev, ZM_HAL_ANI_SPUR_IMMUNITY_LEVEL, aniState->spurImmunityLevel - 1);
559 return;
562 * if all else fails, lower noise immunity level down to a min value
563 * zero for now
565 if (aniState->noiseImmunityLevel > 0)
567 zfHpAniControl(dev, ZM_HAL_ANI_NOISE_IMMUNITY_LEVEL, aniState->noiseImmunityLevel - 1);
568 return;
572 #define CLOCK_RATE 44000 /* XXX use mac_usec or similar */
573 /* convert HW counter values to ms using 11g clock rate, goo9d enough
574 for 11a and Turbo */
577 * Return an approximation of the time spent ``listening'' by
578 * deducting the cycles spent tx'ing and rx'ing from the total
579 * cycle count since our last call. A return value <0 indicates
580 * an invalid/inconsistent time.
582 s32_t zfHpAniGetListenTime(zdev_t* dev)
584 struct zsAniState *aniState;
585 u32_t txFrameCount, rxFrameCount, cycleCount;
586 s32_t listenTime;
587 struct zsHpPriv *HpPriv;
589 zmw_get_wlan_dev(dev);
590 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
592 txFrameCount = 0;//OS_REG_READ(ah, AR_TFCNT);
593 rxFrameCount = 0;//OS_REG_READ(ah, AR_RFCNT);
594 cycleCount = 0;//OS_REG_READ(ah, AR_CCCNT);
596 aniState = HpPriv->curani;
597 if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount)
600 * Cycle counter wrap (or initial call); it's not possible
601 * to accurately calculate a value because the registers
602 * right shift rather than wrap--so punt and return 0.
604 listenTime = 0;
605 HpPriv->stats.ast_ani_lzero++;
607 else
609 s32_t ccdelta = cycleCount - aniState->cycleCount;
610 s32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
611 s32_t tfdelta = txFrameCount - aniState->txFrameCount;
612 listenTime = (ccdelta - rfdelta - tfdelta) / CLOCK_RATE;
614 aniState->cycleCount = cycleCount;
615 aniState->txFrameCount = txFrameCount;
616 aniState->rxFrameCount = rxFrameCount;
617 return listenTime;
621 * Do periodic processing. This routine is called from the
622 * driver's rx interrupt handler after processing frames.
624 void zfHpAniArPoll(zdev_t* dev, u32_t listenTime, u32_t phyCnt1, u32_t phyCnt2)
626 struct zsAniState *aniState;
627 //s32_t listenTime;
628 struct zsHpPriv *HpPriv;
630 zmw_get_wlan_dev(dev);
631 HpPriv = (struct zsHpPriv*)wd->hpPrivate;
634 * Since we're called from end of rx tasklet, we also check for
635 * AR processing now
638 aniState = HpPriv->curani;
639 //HpPriv->stats.ast_nodestats = *stats; /* XXX optimize? */
641 //listenTime = zfHpAniGetListenTime(dev);
642 //if (listenTime < 0)
644 // HpPriv->stats.ast_ani_lneg++;
645 // /* restart ANI period if listenTime is invalid */
646 // zfHpAniRestart(dev);
647 // return;
649 /* XXX beware of overflow? */
650 aniState->listenTime += listenTime;
652 if (HpPriv->hasHwPhyCounters)
654 //u32_t phyCnt1, phyCnt2;
655 u32_t ofdmPhyErrCnt, cckPhyErrCnt;
657 /* NB: these are not reset-on-read */
658 //phyCnt1 = 0;//OS_REG_READ(ah, AR_PHY_ERR_1);
659 //phyCnt2 = 0;//OS_REG_READ(ah, AR_PHY_ERR_2);
660 /* XXX sometimes zero, why? */
661 //if (phyCnt1 < aniState->ofdmPhyErrBase ||
662 // phyCnt2 < aniState->cckPhyErrBase)
664 // if (phyCnt1 < aniState->ofdmPhyErrBase)
665 // {
666 // zm_debug_msg2("phyCnt1 = 0x", phyCnt1);
667 // zm_debug_msg2("resetting counter value to 0x", aniState->ofdmPhyErrBase);
668 // //OS_REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
669 // //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
670 // }
671 // if (phyCnt2 < aniState->cckPhyErrBase)
672 // {
673 // zm_debug_msg2("phyCnt2 = 0x", phyCnt2);
674 // zm_debug_msg2("resetting counter value to 0x", aniState->cckPhyErrBase);
675 // //OS_REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
676 // //OS_REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
677 // }
678 // return; /* XXX */
680 /* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
681 //ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
682 //HpPriv->stats.ast_ani_ofdmerrs += ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
683 //aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
684 ofdmPhyErrCnt = phyCnt1;
685 HpPriv->stats.ast_ani_ofdmerrs += ofdmPhyErrCnt;
686 aniState->ofdmPhyErrCount += ofdmPhyErrCnt;
688 //cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
689 //HpPriv->stats.ast_ani_cckerrs += cckPhyErrCnt - aniState->cckPhyErrCount;
690 //aniState->cckPhyErrCount = cckPhyErrCnt;
691 cckPhyErrCnt = phyCnt2;
692 HpPriv->stats.ast_ani_cckerrs += cckPhyErrCnt;
693 aniState->cckPhyErrCount += cckPhyErrCnt;
696 * If ani is not enabled, return after we've collected
697 * statistics
699 if ((HpPriv->procPhyErr & ZM_HAL_PROCESS_ANI) == 0)
700 return;
701 if (aniState->listenTime > 5 * HpPriv->aniPeriod)
704 * Check to see if need to lower immunity if
705 * 5 aniPeriods have passed
707 if (aniState->ofdmPhyErrCount <= aniState->listenTime *
708 aniState->ofdmTrigLow/1000 &&
709 aniState->cckPhyErrCount <= aniState->listenTime *
710 aniState->cckTrigLow/1000)
711 zfHpAniLowerImmunity(dev);
712 zfHpAniRestart(dev);
714 else if (aniState->listenTime > HpPriv->aniPeriod)
716 /* check to see if need to raise immunity */
717 if (aniState->ofdmPhyErrCount > aniState->listenTime *
718 aniState->ofdmTrigHigh / 1000)
720 zfHpAniOfdmErrTrigger(dev);
721 zfHpAniRestart(dev);
723 else if (aniState->cckPhyErrCount > aniState->listenTime *
724 aniState->cckTrigHigh / 1000)
726 zfHpAniCckErrTrigger(dev);
727 zfHpAniRestart(dev);