2008-10-29 12:46:30 +08:00
|
|
|
/*
|
2009-03-13 11:37:23 +08:00
|
|
|
* Copyright (c) 2008-2009 Atheros Communications Inc.
|
2008-10-29 12:46:30 +08:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2009-02-09 15:56:54 +08:00
|
|
|
#include "ath9k.h"
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static int ath9k_hw_get_ani_channel_idx(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
struct ath9k_channel *chan)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
|
|
|
|
if (ah->ani[i].c &&
|
|
|
|
ah->ani[i].c->channel == chan->channel)
|
2008-10-29 12:46:30 +08:00
|
|
|
return i;
|
2009-02-09 15:57:26 +08:00
|
|
|
if (ah->ani[i].c == NULL) {
|
|
|
|
ah->ani[i].c = chan;
|
2008-10-29 12:46:30 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"No more channel states left. Using channel 0\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static bool ath9k_hw_ani_control(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
enum ath9k_ani_cmd cmd, int param)
|
|
|
|
{
|
2009-02-09 15:57:26 +08:00
|
|
|
struct ar5416AniState *aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
switch (cmd & ah->ani_function) {
|
2008-10-29 12:46:30 +08:00
|
|
|
case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
|
|
|
|
u32 level = param;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
|
2008-10-29 12:46:30 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2008-11-29 00:48:05 +08:00
|
|
|
"level out of range (%u > %u)\n",
|
|
|
|
level,
|
2009-02-09 15:57:26 +08:00
|
|
|
(unsigned)ARRAY_SIZE(ah->totalSizeDesired));
|
2008-10-29 12:46:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
|
|
|
|
AR_PHY_DESIRED_SZ_TOT_DES,
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->totalSizeDesired[level]);
|
2008-10-29 12:46:30 +08:00
|
|
|
REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
|
|
|
|
AR_PHY_AGC_CTL1_COARSE_LOW,
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->coarse_low[level]);
|
2008-10-29 12:46:30 +08:00
|
|
|
REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
|
|
|
|
AR_PHY_AGC_CTL1_COARSE_HIGH,
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->coarse_high[level]);
|
2008-10-29 12:46:30 +08:00
|
|
|
REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
|
|
|
|
AR_PHY_FIND_SIG_FIRPWR,
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->firpwr[level]);
|
2008-10-29 12:46:30 +08:00
|
|
|
|
|
|
|
if (level > aniState->noiseImmunityLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_niup++;
|
2008-10-29 12:46:30 +08:00
|
|
|
else if (level < aniState->noiseImmunityLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_nidown++;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->noiseImmunityLevel = level;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
|
|
|
|
const int m1ThreshLow[] = { 127, 50 };
|
|
|
|
const int m2ThreshLow[] = { 127, 40 };
|
|
|
|
const int m1Thresh[] = { 127, 0x4d };
|
|
|
|
const int m2Thresh[] = { 127, 0x40 };
|
|
|
|
const int m2CountThr[] = { 31, 16 };
|
|
|
|
const int m2CountThrLow[] = { 63, 48 };
|
|
|
|
u32 on = param ? 1 : 0;
|
|
|
|
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
|
|
|
|
AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
|
|
|
|
m1ThreshLow[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
|
|
|
|
AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
|
|
|
|
m2ThreshLow[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR,
|
|
|
|
AR_PHY_SFCORR_M1_THRESH,
|
|
|
|
m1Thresh[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR,
|
|
|
|
AR_PHY_SFCORR_M2_THRESH,
|
|
|
|
m2Thresh[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR,
|
|
|
|
AR_PHY_SFCORR_M2COUNT_THR,
|
|
|
|
m2CountThr[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
|
|
|
|
AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
|
|
|
|
m2CountThrLow[on]);
|
|
|
|
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
|
|
|
|
AR_PHY_SFCORR_EXT_M1_THRESH_LOW,
|
|
|
|
m1ThreshLow[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
|
|
|
|
AR_PHY_SFCORR_EXT_M2_THRESH_LOW,
|
|
|
|
m2ThreshLow[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
|
|
|
|
AR_PHY_SFCORR_EXT_M1_THRESH,
|
|
|
|
m1Thresh[on]);
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
|
|
|
|
AR_PHY_SFCORR_EXT_M2_THRESH,
|
|
|
|
m2Thresh[on]);
|
|
|
|
|
|
|
|
if (on)
|
|
|
|
REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
|
|
|
|
AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
|
|
|
|
else
|
|
|
|
REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
|
|
|
|
AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
|
|
|
|
|
|
|
|
if (!on != aniState->ofdmWeakSigDetectOff) {
|
|
|
|
if (on)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_ofdmon++;
|
2008-10-29 12:46:30 +08:00
|
|
|
else
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_ofdmoff++;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->ofdmWeakSigDetectOff = !on;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
|
|
|
|
const int weakSigThrCck[] = { 8, 6 };
|
|
|
|
u32 high = param ? 1 : 0;
|
|
|
|
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
|
|
|
|
AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
|
|
|
|
weakSigThrCck[high]);
|
|
|
|
if (high != aniState->cckWeakSigThreshold) {
|
|
|
|
if (high)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_cckhigh++;
|
2008-10-29 12:46:30 +08:00
|
|
|
else
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_ccklow++;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->cckWeakSigThreshold = high;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ATH9K_ANI_FIRSTEP_LEVEL:{
|
|
|
|
const int firstep[] = { 0, 4, 8 };
|
|
|
|
u32 level = param;
|
|
|
|
|
|
|
|
if (level >= ARRAY_SIZE(firstep)) {
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2008-11-29 00:48:05 +08:00
|
|
|
"level out of range (%u > %u)\n",
|
|
|
|
level,
|
2008-10-29 12:46:30 +08:00
|
|
|
(unsigned) ARRAY_SIZE(firstep));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
|
|
|
|
AR_PHY_FIND_SIG_FIRSTEP,
|
|
|
|
firstep[level]);
|
|
|
|
if (level > aniState->firstepLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_stepup++;
|
2008-10-29 12:46:30 +08:00
|
|
|
else if (level < aniState->firstepLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_stepdown++;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->firstepLevel = level;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
|
|
|
|
const int cycpwrThr1[] =
|
|
|
|
{ 2, 4, 6, 8, 10, 12, 14, 16 };
|
|
|
|
u32 level = param;
|
|
|
|
|
|
|
|
if (level >= ARRAY_SIZE(cycpwrThr1)) {
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2008-11-29 00:48:05 +08:00
|
|
|
"level out of range (%u > %u)\n",
|
|
|
|
level,
|
2008-10-29 12:46:30 +08:00
|
|
|
(unsigned)
|
|
|
|
ARRAY_SIZE(cycpwrThr1));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
REG_RMW_FIELD(ah, AR_PHY_TIMING5,
|
|
|
|
AR_PHY_TIMING5_CYCPWR_THR1,
|
|
|
|
cycpwrThr1[level]);
|
|
|
|
if (level > aniState->spurImmunityLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_spurup++;
|
2008-10-29 12:46:30 +08:00
|
|
|
else if (level < aniState->spurImmunityLevel)
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_spurdown++;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->spurImmunityLevel = level;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ATH9K_ANI_PRESENT:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2008-11-29 00:48:05 +08:00
|
|
|
"invalid cmd %u\n", cmd);
|
2008-10-29 12:46:30 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-11-29 00:48:05 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "ANI parameters:\n");
|
2008-10-29 12:46:30 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"noiseImmunityLevel=%d, spurImmunityLevel=%d, "
|
|
|
|
"ofdmWeakSigDetectOff=%d\n",
|
|
|
|
aniState->noiseImmunityLevel, aniState->spurImmunityLevel,
|
|
|
|
!aniState->ofdmWeakSigDetectOff);
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"cckWeakSigThreshold=%d, "
|
|
|
|
"firstepLevel=%d, listenTime=%d\n",
|
|
|
|
aniState->cckWeakSigThreshold, aniState->firstepLevel,
|
|
|
|
aniState->listenTime);
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"cycleCount=%d, ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
|
|
|
|
aniState->cycleCount, aniState->ofdmPhyErrCount,
|
|
|
|
aniState->cckPhyErrCount);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static void ath9k_hw_update_mibstats(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
struct ath9k_mib_stats *stats)
|
|
|
|
{
|
|
|
|
stats->ackrcv_bad += REG_READ(ah, AR_ACK_FAIL);
|
|
|
|
stats->rts_bad += REG_READ(ah, AR_RTS_FAIL);
|
|
|
|
stats->fcs_bad += REG_READ(ah, AR_FCS_FAIL);
|
|
|
|
stats->rts_good += REG_READ(ah, AR_RTS_OK);
|
|
|
|
stats->beacons += REG_READ(ah, AR_BEACON_CNT);
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static void ath9k_ani_restart(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
|
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->listenTime = 0;
|
2009-08-13 12:04:25 +08:00
|
|
|
|
|
|
|
if (aniState->ofdmTrigHigh > AR_PHY_COUNTMAX) {
|
|
|
|
aniState->ofdmPhyErrBase = 0;
|
2008-10-29 12:46:30 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2009-08-13 12:04:25 +08:00
|
|
|
"OFDM Trigger is too high for hw counters\n");
|
|
|
|
} else {
|
|
|
|
aniState->ofdmPhyErrBase =
|
|
|
|
AR_PHY_COUNTMAX - aniState->ofdmTrigHigh;
|
|
|
|
}
|
|
|
|
if (aniState->cckTrigHigh > AR_PHY_COUNTMAX) {
|
|
|
|
aniState->cckPhyErrBase = 0;
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"CCK Trigger is too high for hw counters\n");
|
|
|
|
} else {
|
|
|
|
aniState->cckPhyErrBase =
|
|
|
|
AR_PHY_COUNTMAX - aniState->cckTrigHigh;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
2009-08-13 12:04:25 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"Writing ofdmbase=%u cckbase=%u\n",
|
|
|
|
aniState->ofdmPhyErrBase,
|
|
|
|
aniState->cckPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_1, aniState->ofdmPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_2, aniState->cckPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
|
|
|
|
|
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
|
|
|
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->ofdmPhyErrCount = 0;
|
|
|
|
aniState->cckPhyErrCount = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
2008-12-24 07:58:46 +08:00
|
|
|
struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
|
2008-10-29 12:46:30 +08:00
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
int32_t rssi;
|
|
|
|
|
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
|
|
|
if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
|
|
|
|
if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
|
|
|
|
aniState->noiseImmunityLevel + 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
|
|
|
|
if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
|
|
|
|
aniState->spurImmunityLevel + 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel + 1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-02-09 15:57:12 +08:00
|
|
|
rssi = BEACON_RSSI(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
if (rssi > aniState->rssiThrHigh) {
|
|
|
|
if (!aniState->ofdmWeakSigDetectOff) {
|
|
|
|
if (ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
false)) {
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (rssi > aniState->rssiThrLow) {
|
|
|
|
if (aniState->ofdmWeakSigDetectOff)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
true);
|
|
|
|
if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel + 1);
|
|
|
|
return;
|
|
|
|
} else {
|
2008-12-24 07:58:46 +08:00
|
|
|
if (conf->channel->band == IEEE80211_BAND_2GHZ) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (!aniState->ofdmWeakSigDetectOff)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
false);
|
|
|
|
if (aniState->firstepLevel > 0)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
2008-12-24 07:58:46 +08:00
|
|
|
struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
|
2008-10-29 12:46:30 +08:00
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
int32_t rssi;
|
|
|
|
|
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
|
|
|
|
if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
|
|
|
|
aniState->noiseImmunityLevel + 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 15:57:26 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel + 1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-02-09 15:57:12 +08:00
|
|
|
rssi = BEACON_RSSI(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
if (rssi > aniState->rssiThrLow) {
|
|
|
|
if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel + 1);
|
|
|
|
} else {
|
2008-12-24 07:58:46 +08:00
|
|
|
if (conf->channel->band == IEEE80211_BAND_2GHZ) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->firstepLevel > 0)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
int32_t rssi;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->firstepLevel > 0) {
|
|
|
|
if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel - 1))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2009-02-09 15:57:12 +08:00
|
|
|
rssi = BEACON_RSSI(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
if (rssi > aniState->rssiThrHigh) {
|
|
|
|
/* XXX: Handle me */
|
|
|
|
} else if (rssi > aniState->rssiThrLow) {
|
|
|
|
if (aniState->ofdmWeakSigDetectOff) {
|
|
|
|
if (ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
true) == true)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aniState->firstepLevel > 0) {
|
|
|
|
if (ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel - 1) == true)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aniState->firstepLevel > 0) {
|
|
|
|
if (ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel - 1) == true)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aniState->spurImmunityLevel > 0) {
|
|
|
|
if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
|
|
|
|
aniState->spurImmunityLevel - 1))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aniState->noiseImmunityLevel > 0) {
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
|
|
|
|
aniState->noiseImmunityLevel - 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
u32 txFrameCount, rxFrameCount, cycleCount;
|
|
|
|
int32_t listenTime;
|
|
|
|
|
|
|
|
txFrameCount = REG_READ(ah, AR_TFCNT);
|
|
|
|
rxFrameCount = REG_READ(ah, AR_RFCNT);
|
|
|
|
cycleCount = REG_READ(ah, AR_CCCNT);
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->cycleCount == 0 || aniState->cycleCount > cycleCount) {
|
|
|
|
|
|
|
|
listenTime = 0;
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_lzero++;
|
2008-10-29 12:46:30 +08:00
|
|
|
} else {
|
|
|
|
int32_t ccdelta = cycleCount - aniState->cycleCount;
|
|
|
|
int32_t rfdelta = rxFrameCount - aniState->rxFrameCount;
|
|
|
|
int32_t tfdelta = txFrameCount - aniState->txFrameCount;
|
|
|
|
listenTime = (ccdelta - rfdelta - tfdelta) / 44000;
|
|
|
|
}
|
|
|
|
aniState->cycleCount = cycleCount;
|
|
|
|
aniState->txFrameCount = txFrameCount;
|
|
|
|
aniState->rxFrameCount = rxFrameCount;
|
|
|
|
|
|
|
|
return listenTime;
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_ani_reset(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
2009-02-09 15:57:26 +08:00
|
|
|
struct ath9k_channel *chan = ah->curchan;
|
2008-10-29 12:46:30 +08:00
|
|
|
int index;
|
|
|
|
|
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
|
|
|
index = ath9k_hw_get_ani_channel_idx(ah, chan);
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = &ah->ani[index];
|
|
|
|
ah->curani = aniState;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (DO_ANI(ah) && ah->opmode != NL80211_IFTYPE_STATION
|
|
|
|
&& ah->opmode != NL80211_IFTYPE_ADHOC) {
|
2008-10-29 12:46:30 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2009-02-09 15:57:26 +08:00
|
|
|
"Reset ANI state opmode %u\n", ah->opmode);
|
|
|
|
ah->stats.ast_ani_reset++;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-07-17 01:17:35 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
|
|
|
/*
|
|
|
|
* ath9k_hw_ani_control() will only process items set on
|
|
|
|
* ah->ani_function
|
|
|
|
*/
|
|
|
|
if (IS_CHAN_2GHZ(chan))
|
|
|
|
ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL);
|
|
|
|
else
|
|
|
|
ah->ani_function = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-29 12:46:30 +08:00
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
!ATH9K_ANI_USE_OFDM_WEAK_SIG);
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
|
|
|
|
ATH9K_ANI_CCK_WEAK_SIG_THR);
|
|
|
|
|
|
|
|
ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) |
|
|
|
|
ATH9K_RX_FILTER_PHYERR);
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
|
|
|
ah->curani->ofdmTrigHigh =
|
|
|
|
ah->config.ofdm_trig_high;
|
|
|
|
ah->curani->ofdmTrigLow =
|
|
|
|
ah->config.ofdm_trig_low;
|
|
|
|
ah->curani->cckTrigHigh =
|
|
|
|
ah->config.cck_trig_high;
|
|
|
|
ah->curani->cckTrigLow =
|
|
|
|
ah->config.cck_trig_low;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aniState->noiseImmunityLevel != 0)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
|
|
|
|
aniState->noiseImmunityLevel);
|
|
|
|
if (aniState->spurImmunityLevel != 0)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
|
|
|
|
aniState->spurImmunityLevel);
|
|
|
|
if (aniState->ofdmWeakSigDetectOff)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
!aniState->ofdmWeakSigDetectOff);
|
|
|
|
if (aniState->cckWeakSigThreshold)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
|
|
|
|
aniState->cckWeakSigThreshold);
|
|
|
|
if (aniState->firstepLevel != 0)
|
|
|
|
ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
aniState->firstepLevel);
|
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
ath9k_hw_setrxfilter(ah, ath9k_hw_getrxfilter(ah) &
|
|
|
|
~ATH9K_RX_FILTER_PHYERR);
|
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_hw_ani_monitor(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
const struct ath9k_node_stats *stats,
|
|
|
|
struct ath9k_channel *chan)
|
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
int32_t listenTime;
|
2009-08-13 12:04:25 +08:00
|
|
|
u32 phyCnt1, phyCnt2;
|
|
|
|
u32 ofdmPhyErrCnt, cckPhyErrCnt;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-01-15 03:17:11 +08:00
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
aniState = ah->curani;
|
|
|
|
ah->stats.ast_nodestats = *stats;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
|
|
|
listenTime = ath9k_hw_ani_get_listen_time(ah);
|
|
|
|
if (listenTime < 0) {
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_lneg++;
|
2008-10-29 12:46:30 +08:00
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aniState->listenTime += listenTime;
|
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
|
|
|
|
phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
|
|
|
|
|
|
|
|
if (phyCnt1 < aniState->ofdmPhyErrBase ||
|
|
|
|
phyCnt2 < aniState->cckPhyErrBase) {
|
|
|
|
if (phyCnt1 < aniState->ofdmPhyErrBase) {
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"phyCnt1 0x%x, resetting "
|
|
|
|
"counter value to 0x%x\n",
|
|
|
|
phyCnt1, aniState->ofdmPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_1,
|
|
|
|
aniState->ofdmPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_1,
|
|
|
|
AR_PHY_ERR_OFDM_TIMING);
|
|
|
|
}
|
|
|
|
if (phyCnt2 < aniState->cckPhyErrBase) {
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"phyCnt2 0x%x, resetting "
|
|
|
|
"counter value to 0x%x\n",
|
|
|
|
phyCnt2, aniState->cckPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_2,
|
|
|
|
aniState->cckPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_2,
|
|
|
|
AR_PHY_ERR_CCK_TIMING);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
2009-08-13 12:04:25 +08:00
|
|
|
return;
|
|
|
|
}
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
|
|
|
|
ah->stats.ast_ani_ofdmerrs +=
|
|
|
|
ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
|
|
|
|
aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
|
|
|
|
ah->stats.ast_ani_cckerrs +=
|
|
|
|
cckPhyErrCnt - aniState->cckPhyErrCount;
|
|
|
|
aniState->cckPhyErrCount = cckPhyErrCnt;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
if (aniState->listenTime > 5 * ah->aniperiod) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->ofdmPhyErrCount <= aniState->listenTime *
|
|
|
|
aniState->ofdmTrigLow / 1000 &&
|
|
|
|
aniState->cckPhyErrCount <= aniState->listenTime *
|
|
|
|
aniState->cckTrigLow / 1000)
|
|
|
|
ath9k_hw_ani_lower_immunity(ah);
|
|
|
|
ath9k_ani_restart(ah);
|
2009-02-09 15:57:26 +08:00
|
|
|
} else if (aniState->listenTime > ah->aniperiod) {
|
2008-10-29 12:46:30 +08:00
|
|
|
if (aniState->ofdmPhyErrCount > aniState->listenTime *
|
|
|
|
aniState->ofdmTrigHigh / 1000) {
|
|
|
|
ath9k_hw_ani_ofdm_err_trigger(ah);
|
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
} else if (aniState->cckPhyErrCount >
|
|
|
|
aniState->listenTime * aniState->cckTrigHigh /
|
|
|
|
1000) {
|
|
|
|
ath9k_hw_ani_cck_err_trigger(ah);
|
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_enable_mib_counters(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Enable MIB counters\n");
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
2008-10-29 12:46:30 +08:00
|
|
|
|
|
|
|
REG_WRITE(ah, AR_FILT_OFDM, 0);
|
|
|
|
REG_WRITE(ah, AR_FILT_CCK, 0);
|
|
|
|
REG_WRITE(ah, AR_MIBC,
|
|
|
|
~(AR_MIBC_COW | AR_MIBC_FMC | AR_MIBC_CMC | AR_MIBC_MCS)
|
|
|
|
& 0x0f);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
|
|
|
|
}
|
|
|
|
|
2009-02-12 12:36:51 +08:00
|
|
|
/* Freeze the MIB counters, get the stats and then clear them */
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_hw_disable_mib_counters(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Disable MIB counters\n");
|
2009-02-12 12:36:51 +08:00
|
|
|
REG_WRITE(ah, AR_MIBC, AR_MIBC_FMC);
|
2009-02-09 15:57:12 +08:00
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
2009-02-12 12:36:51 +08:00
|
|
|
REG_WRITE(ah, AR_MIBC, AR_MIBC_CMC);
|
2008-10-29 12:46:30 +08:00
|
|
|
REG_WRITE(ah, AR_FILT_OFDM, 0);
|
|
|
|
REG_WRITE(ah, AR_FILT_CCK, 0);
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
u32 ath9k_hw_GetMibCycleCountsPct(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
u32 *rxc_pcnt,
|
|
|
|
u32 *rxf_pcnt,
|
|
|
|
u32 *txf_pcnt)
|
|
|
|
{
|
|
|
|
static u32 cycles, rx_clear, rx_frame, tx_frame;
|
|
|
|
u32 good = 1;
|
|
|
|
|
|
|
|
u32 rc = REG_READ(ah, AR_RCCNT);
|
|
|
|
u32 rf = REG_READ(ah, AR_RFCNT);
|
|
|
|
u32 tf = REG_READ(ah, AR_TFCNT);
|
|
|
|
u32 cc = REG_READ(ah, AR_CCCNT);
|
|
|
|
|
|
|
|
if (cycles == 0 || cycles > cc) {
|
2009-03-30 17:58:25 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
2008-11-29 00:48:05 +08:00
|
|
|
"cycle counter wrap. ExtBusy = 0\n");
|
2008-10-29 12:46:30 +08:00
|
|
|
good = 0;
|
|
|
|
} else {
|
|
|
|
u32 cc_d = cc - cycles;
|
|
|
|
u32 rc_d = rc - rx_clear;
|
|
|
|
u32 rf_d = rf - rx_frame;
|
|
|
|
u32 tf_d = tf - tx_frame;
|
|
|
|
|
|
|
|
if (cc_d != 0) {
|
|
|
|
*rxc_pcnt = rc_d * 100 / cc_d;
|
|
|
|
*rxf_pcnt = rf_d * 100 / cc_d;
|
|
|
|
*txf_pcnt = tf_d * 100 / cc_d;
|
|
|
|
} else {
|
|
|
|
good = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cycles = cc;
|
|
|
|
rx_frame = rf;
|
|
|
|
rx_clear = rc;
|
|
|
|
tx_frame = tf;
|
|
|
|
|
|
|
|
return good;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a MIB interrupt. We may potentially be invoked because
|
|
|
|
* any of the MIB counters overflow/trigger so don't assume we're
|
|
|
|
* here because a PHY error counter triggered.
|
|
|
|
*/
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_hw_procmibevent(struct ath_hw *ah,
|
2008-10-29 12:46:30 +08:00
|
|
|
const struct ath9k_node_stats *stats)
|
|
|
|
{
|
|
|
|
u32 phyCnt1, phyCnt2;
|
|
|
|
|
|
|
|
/* Reset these counters regardless */
|
|
|
|
REG_WRITE(ah, AR_FILT_OFDM, 0);
|
|
|
|
REG_WRITE(ah, AR_FILT_CCK, 0);
|
|
|
|
if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
|
|
|
|
REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
|
|
|
|
|
|
|
|
/* Clear the mib counters and save them in the stats */
|
2009-02-09 15:57:12 +08:00
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_nodestats = *stats;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
|
|
|
if (!DO_ANI(ah))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* NB: these are not reset-on-read */
|
|
|
|
phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
|
|
|
|
phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
|
|
|
|
if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
|
|
|
|
((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
|
2009-02-09 15:57:26 +08:00
|
|
|
struct ar5416AniState *aniState = ah->curani;
|
2008-10-29 12:46:30 +08:00
|
|
|
u32 ofdmPhyErrCnt, cckPhyErrCnt;
|
|
|
|
|
|
|
|
/* NB: only use ast_ani_*errs with AH_PRIVATE_DIAG */
|
|
|
|
ofdmPhyErrCnt = phyCnt1 - aniState->ofdmPhyErrBase;
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_ofdmerrs +=
|
2008-10-29 12:46:30 +08:00
|
|
|
ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
|
|
|
|
aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
|
|
|
|
|
|
|
|
cckPhyErrCnt = phyCnt2 - aniState->cckPhyErrBase;
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->stats.ast_ani_cckerrs +=
|
2008-10-29 12:46:30 +08:00
|
|
|
cckPhyErrCnt - aniState->cckPhyErrCount;
|
|
|
|
aniState->cckPhyErrCount = cckPhyErrCnt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NB: figure out which counter triggered. If both
|
|
|
|
* trigger we'll only deal with one as the processing
|
|
|
|
* clobbers the error counter so the trigger threshold
|
|
|
|
* check will never be true.
|
|
|
|
*/
|
|
|
|
if (aniState->ofdmPhyErrCount > aniState->ofdmTrigHigh)
|
|
|
|
ath9k_hw_ani_ofdm_err_trigger(ah);
|
|
|
|
if (aniState->cckPhyErrCount > aniState->cckTrigHigh)
|
|
|
|
ath9k_hw_ani_cck_err_trigger(ah);
|
|
|
|
/* NB: always restart to insure the h/w counters are reset */
|
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
void ath9k_hw_ani_setup(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
const int totalSizeDesired[] = { -55, -55, -55, -55, -62 };
|
|
|
|
const int coarseHigh[] = { -14, -14, -14, -14, -12 };
|
|
|
|
const int coarseLow[] = { -64, -64, -64, -64, -70 };
|
|
|
|
const int firpwr[] = { -78, -78, -78, -78, -80 };
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->totalSizeDesired[i] = totalSizeDesired[i];
|
|
|
|
ah->coarse_high[i] = coarseHigh[i];
|
|
|
|
ah->coarse_low[i] = coarseLow[i];
|
|
|
|
ah->firpwr[i] = firpwr[i];
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-04 03:24:46 +08:00
|
|
|
void ath9k_hw_ani_init(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Initialize ANI\n");
|
2009-02-09 15:57:26 +08:00
|
|
|
|
|
|
|
memset(ah->ani, 0, sizeof(ah->ani));
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ah->ani); i++) {
|
|
|
|
ah->ani[i].ofdmTrigHigh = ATH9K_ANI_OFDM_TRIG_HIGH;
|
|
|
|
ah->ani[i].ofdmTrigLow = ATH9K_ANI_OFDM_TRIG_LOW;
|
|
|
|
ah->ani[i].cckTrigHigh = ATH9K_ANI_CCK_TRIG_HIGH;
|
|
|
|
ah->ani[i].cckTrigLow = ATH9K_ANI_CCK_TRIG_LOW;
|
|
|
|
ah->ani[i].rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
|
|
|
|
ah->ani[i].rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
|
|
|
|
ah->ani[i].ofdmWeakSigDetectOff =
|
2008-10-29 12:46:30 +08:00
|
|
|
!ATH9K_ANI_USE_OFDM_WEAK_SIG;
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->ani[i].cckWeakSigThreshold =
|
2008-10-29 12:46:30 +08:00
|
|
|
ATH9K_ANI_CCK_WEAK_SIG_THR;
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->ani[i].spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
|
|
|
|
ah->ani[i].firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
|
2009-08-13 12:04:25 +08:00
|
|
|
ah->ani[i].ofdmPhyErrBase =
|
|
|
|
AR_PHY_COUNTMAX - ATH9K_ANI_OFDM_TRIG_HIGH;
|
|
|
|
ah->ani[i].cckPhyErrBase =
|
|
|
|
AR_PHY_COUNTMAX - ATH9K_ANI_CCK_TRIG_HIGH;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
2009-08-13 12:04:25 +08:00
|
|
|
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI,
|
|
|
|
"Setting OfdmErrBase = 0x%08x\n",
|
|
|
|
ah->ani[0].ofdmPhyErrBase);
|
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Setting cckErrBase = 0x%08x\n",
|
|
|
|
ah->ani[0].cckPhyErrBase);
|
|
|
|
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_1, ah->ani[0].ofdmPhyErrBase);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_2, ah->ani[0].cckPhyErrBase);
|
|
|
|
ath9k_enable_mib_counters(ah);
|
|
|
|
|
2009-02-09 15:57:26 +08:00
|
|
|
ah->aniperiod = ATH9K_ANI_PERIOD;
|
|
|
|
if (ah->config.enable_ani)
|
|
|
|
ah->proc_phyerr |= HAL_PROCESS_ANI;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
|
2009-08-04 03:24:51 +08:00
|
|
|
void ath9k_hw_ani_disable(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
2009-08-04 03:24:51 +08:00
|
|
|
DPRINTF(ah->ah_sc, ATH_DBG_ANI, "Disabling ANI\n");
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
ath9k_hw_disable_mib_counters(ah);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_1, 0);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_2, 0);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|