2008-10-29 12:46:30 +08:00
|
|
|
/*
|
2011-05-17 16:06:18 +08:00
|
|
|
* Copyright (c) 2008-2011 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.
|
|
|
|
*/
|
|
|
|
|
2010-09-09 05:25:42 +08:00
|
|
|
#include <linux/kernel.h>
|
2011-05-28 04:14:23 +08:00
|
|
|
#include <linux/export.h>
|
2009-09-14 14:39:31 +08:00
|
|
|
#include "hw.h"
|
2010-04-16 05:38:39 +08:00
|
|
|
#include "hw-ops.h"
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2010-06-12 12:33:45 +08:00
|
|
|
struct ani_ofdm_level_entry {
|
|
|
|
int spur_immunity_level;
|
|
|
|
int fir_step_level;
|
|
|
|
int ofdm_weak_signal_on;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* values here are relative to the INI */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Legend:
|
|
|
|
*
|
|
|
|
* SI: Spur immunity
|
|
|
|
* FS: FIR Step
|
|
|
|
* WS: OFDM / CCK Weak Signal detection
|
|
|
|
* MRC-CCK: Maximal Ratio Combining for CCK
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct ani_ofdm_level_entry ofdm_level_table[] = {
|
|
|
|
/* SI FS WS */
|
|
|
|
{ 0, 0, 1 }, /* lvl 0 */
|
|
|
|
{ 1, 1, 1 }, /* lvl 1 */
|
|
|
|
{ 2, 2, 1 }, /* lvl 2 */
|
|
|
|
{ 3, 2, 1 }, /* lvl 3 (default) */
|
|
|
|
{ 4, 3, 1 }, /* lvl 4 */
|
|
|
|
{ 5, 4, 1 }, /* lvl 5 */
|
|
|
|
{ 6, 5, 1 }, /* lvl 6 */
|
|
|
|
{ 7, 6, 1 }, /* lvl 7 */
|
2012-03-15 08:04:26 +08:00
|
|
|
{ 7, 6, 0 }, /* lvl 8 */
|
|
|
|
{ 7, 7, 0 } /* lvl 9 */
|
2010-06-12 12:33:45 +08:00
|
|
|
};
|
|
|
|
#define ATH9K_ANI_OFDM_NUM_LEVEL \
|
2010-09-09 05:25:42 +08:00
|
|
|
ARRAY_SIZE(ofdm_level_table)
|
2010-06-12 12:33:45 +08:00
|
|
|
#define ATH9K_ANI_OFDM_MAX_LEVEL \
|
|
|
|
(ATH9K_ANI_OFDM_NUM_LEVEL-1)
|
|
|
|
#define ATH9K_ANI_OFDM_DEF_LEVEL \
|
|
|
|
3 /* default level - matches the INI settings */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MRC (Maximal Ratio Combining) has always been used with multi-antenna ofdm.
|
|
|
|
* With OFDM for single stream you just add up all antenna inputs, you're
|
|
|
|
* only interested in what you get after FFT. Signal aligment is also not
|
|
|
|
* required for OFDM because any phase difference adds up in the frequency
|
|
|
|
* domain.
|
|
|
|
*
|
|
|
|
* MRC requires extra work for use with CCK. You need to align the antenna
|
|
|
|
* signals from the different antenna before you can add the signals together.
|
|
|
|
* You need aligment of signals as CCK is in time domain, so addition can cancel
|
|
|
|
* your signal completely if phase is 180 degrees (think of adding sine waves).
|
|
|
|
* You also need to remove noise before the addition and this is where ANI
|
|
|
|
* MRC CCK comes into play. One of the antenna inputs may be stronger but
|
|
|
|
* lower SNR, so just adding after alignment can be dangerous.
|
|
|
|
*
|
|
|
|
* Regardless of alignment in time, the antenna signals add constructively after
|
|
|
|
* FFT and improve your reception. For more information:
|
|
|
|
*
|
|
|
|
* http://en.wikipedia.org/wiki/Maximal-ratio_combining
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ani_cck_level_entry {
|
|
|
|
int fir_step_level;
|
|
|
|
int mrc_cck_on;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ani_cck_level_entry cck_level_table[] = {
|
|
|
|
/* FS MRC-CCK */
|
|
|
|
{ 0, 1 }, /* lvl 0 */
|
|
|
|
{ 1, 1 }, /* lvl 1 */
|
|
|
|
{ 2, 1 }, /* lvl 2 (default) */
|
|
|
|
{ 3, 1 }, /* lvl 3 */
|
|
|
|
{ 4, 0 }, /* lvl 4 */
|
|
|
|
{ 5, 0 }, /* lvl 5 */
|
|
|
|
{ 6, 0 }, /* lvl 6 */
|
2012-03-15 08:04:26 +08:00
|
|
|
{ 6, 0 }, /* lvl 7 (only for high rssi) */
|
|
|
|
{ 7, 0 } /* lvl 8 (only for high rssi) */
|
2010-06-12 12:33:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ATH9K_ANI_CCK_NUM_LEVEL \
|
2010-09-09 05:25:42 +08:00
|
|
|
ARRAY_SIZE(cck_level_table)
|
2010-06-12 12:33:45 +08:00
|
|
|
#define ATH9K_ANI_CCK_MAX_LEVEL \
|
|
|
|
(ATH9K_ANI_CCK_NUM_LEVEL-1)
|
|
|
|
#define ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI \
|
|
|
|
(ATH9K_ANI_CCK_NUM_LEVEL-3)
|
|
|
|
#define ATH9K_ANI_CCK_DEF_LEVEL \
|
|
|
|
2 /* default level - matches the INI settings */
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
static void ath9k_ani_restart(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
|
2013-06-03 11:49:26 +08:00
|
|
|
if (!ah->curchan)
|
2008-10-29 12:46:30 +08:00
|
|
|
return;
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
aniState = &ah->curchan->ani;
|
2008-10-29 12:46:30 +08:00
|
|
|
aniState->listenTime = 0;
|
2009-08-13 12:04:25 +08:00
|
|
|
|
2010-06-12 12:33:45 +08:00
|
|
|
ENABLE_REGWRITE_BUFFER(ah);
|
|
|
|
|
2012-06-15 21:25:24 +08:00
|
|
|
REG_WRITE(ah, AR_PHY_ERR_1, 0);
|
|
|
|
REG_WRITE(ah, AR_PHY_ERR_2, 0);
|
2010-06-12 12:33:45 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
REGWRITE_BUFFER_FLUSH(ah);
|
|
|
|
|
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
|
|
|
|
|
|
|
aniState->ofdmPhyErrCount = 0;
|
|
|
|
aniState->cckPhyErrCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the OFDM Noise Immunity Level */
|
2012-06-27 20:58:19 +08:00
|
|
|
static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel,
|
|
|
|
bool scan)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
2010-10-05 02:09:47 +08:00
|
|
|
struct ar5416AniState *aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
|
|
|
const struct ani_ofdm_level_entry *entry_ofdm;
|
|
|
|
const struct ani_cck_level_entry *entry_cck;
|
2012-06-15 21:25:20 +08:00
|
|
|
bool weak_sig;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI, "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
|
2010-12-03 11:12:37 +08:00
|
|
|
aniState->ofdmNoiseImmunityLevel,
|
2012-06-15 21:25:19 +08:00
|
|
|
immunityLevel, BEACON_RSSI(ah),
|
2013-01-21 01:51:58 +08:00
|
|
|
ATH9K_ANI_RSSI_THR_LOW,
|
|
|
|
ATH9K_ANI_RSSI_THR_HIGH);
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2012-06-27 20:58:19 +08:00
|
|
|
if (!scan)
|
2012-06-15 21:25:26 +08:00
|
|
|
aniState->ofdmNoiseImmunityLevel = immunityLevel;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
|
|
|
|
entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
|
|
|
|
|
|
|
|
if (aniState->spurImmunityLevel != entry_ofdm->spur_immunity_level)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
|
|
|
|
entry_ofdm->spur_immunity_level);
|
|
|
|
|
|
|
|
if (aniState->firstepLevel != entry_ofdm->fir_step_level &&
|
|
|
|
entry_ofdm->fir_step_level >= entry_cck->fir_step_level)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
entry_ofdm->fir_step_level);
|
|
|
|
|
2012-06-15 21:25:20 +08:00
|
|
|
weak_sig = entry_ofdm->ofdm_weak_signal_on;
|
|
|
|
if (ah->opmode == NL80211_IFTYPE_STATION &&
|
2013-01-21 01:51:58 +08:00
|
|
|
BEACON_RSSI(ah) <= ATH9K_ANI_RSSI_THR_HIGH)
|
2012-06-15 21:25:20 +08:00
|
|
|
weak_sig = true;
|
|
|
|
|
2012-06-15 21:25:21 +08:00
|
|
|
if (aniState->ofdmWeakSigDetect != weak_sig)
|
2010-06-12 12:33:45 +08:00
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
|
|
|
|
entry_ofdm->ofdm_weak_signal_on);
|
2012-06-15 21:25:27 +08:00
|
|
|
|
|
|
|
if (aniState->ofdmNoiseImmunityLevel >= ATH9K_ANI_OFDM_DEF_LEVEL) {
|
|
|
|
ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
|
|
|
|
ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI;
|
|
|
|
} else {
|
|
|
|
ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI;
|
|
|
|
ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
|
|
|
|
}
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
|
2010-10-05 02:09:49 +08:00
|
|
|
static void ath9k_hw_ani_ofdm_err_trigger(struct ath_hw *ah)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
|
2013-06-03 11:49:26 +08:00
|
|
|
if (!ah->curchan)
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
|
2012-06-27 20:58:19 +08:00
|
|
|
ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel + 1, false);
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the ANI settings to match an CCK level.
|
|
|
|
*/
|
2012-06-27 20:58:19 +08:00
|
|
|
static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel,
|
|
|
|
bool scan)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
2010-10-05 02:09:47 +08:00
|
|
|
struct ar5416AniState *aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
|
|
|
const struct ani_ofdm_level_entry *entry_ofdm;
|
|
|
|
const struct ani_cck_level_entry *entry_cck;
|
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI, "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
|
2010-12-03 11:12:37 +08:00
|
|
|
aniState->cckNoiseImmunityLevel, immunityLevel,
|
2013-01-21 01:51:58 +08:00
|
|
|
BEACON_RSSI(ah), ATH9K_ANI_RSSI_THR_LOW,
|
|
|
|
ATH9K_ANI_RSSI_THR_HIGH);
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2012-06-15 21:25:22 +08:00
|
|
|
if (ah->opmode == NL80211_IFTYPE_STATION &&
|
2013-01-21 01:51:58 +08:00
|
|
|
BEACON_RSSI(ah) <= ATH9K_ANI_RSSI_THR_LOW &&
|
2010-06-12 12:33:45 +08:00
|
|
|
immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
|
|
|
|
immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
|
|
|
|
|
2012-06-27 20:58:19 +08:00
|
|
|
if (!scan)
|
2012-06-15 21:25:26 +08:00
|
|
|
aniState->cckNoiseImmunityLevel = immunityLevel;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
|
|
|
|
entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
|
|
|
|
|
|
|
|
if (aniState->firstepLevel != entry_cck->fir_step_level &&
|
|
|
|
entry_cck->fir_step_level >= entry_ofdm->fir_step_level)
|
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL,
|
|
|
|
entry_cck->fir_step_level);
|
|
|
|
|
|
|
|
/* Skip MRC CCK for pre AR9003 families */
|
2012-09-10 11:50:03 +08:00
|
|
|
if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
|
2012-06-21 23:03:59 +08:00
|
|
|
if (aniState->mrcCCK != entry_cck->mrc_cck_on)
|
2010-06-12 12:33:45 +08:00
|
|
|
ath9k_hw_ani_control(ah,
|
|
|
|
ATH9K_ANI_MRC_CCK,
|
|
|
|
entry_cck->mrc_cck_on);
|
|
|
|
}
|
|
|
|
|
2010-10-05 02:09:49 +08:00
|
|
|
static void ath9k_hw_ani_cck_err_trigger(struct ath_hw *ah)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
|
2013-06-03 11:49:26 +08:00
|
|
|
if (!ah->curchan)
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
|
2012-06-27 20:58:19 +08:00
|
|
|
ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1,
|
|
|
|
false);
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only lower either OFDM or CCK errors per turn
|
|
|
|
* we lower the other one next time
|
|
|
|
*/
|
2010-10-05 02:09:49 +08:00
|
|
|
static void ath9k_hw_ani_lower_immunity(struct ath_hw *ah)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
/* lower OFDM noise immunity */
|
|
|
|
if (aniState->ofdmNoiseImmunityLevel > 0 &&
|
|
|
|
(aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
|
2012-06-27 20:58:19 +08:00
|
|
|
ath9k_hw_set_ofdm_nil(ah, aniState->ofdmNoiseImmunityLevel - 1,
|
|
|
|
false);
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lower CCK noise immunity */
|
|
|
|
if (aniState->cckNoiseImmunityLevel > 0)
|
2012-06-27 20:58:19 +08:00
|
|
|
ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1,
|
|
|
|
false);
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the ANI parameters in the HAL and reset the statistics.
|
|
|
|
* This routine should be called for every hardware reset and for
|
|
|
|
* every channel change.
|
|
|
|
*/
|
2010-10-05 02:09:49 +08:00
|
|
|
void ath9k_ani_reset(struct ath_hw *ah, bool is_scanning)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
2010-10-05 02:09:47 +08:00
|
|
|
struct ar5416AniState *aniState = &ah->curchan->ani;
|
2010-06-12 12:33:45 +08:00
|
|
|
struct ath9k_channel *chan = ah->curchan;
|
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
2012-06-15 21:25:26 +08:00
|
|
|
int ofdm_nil, cck_nil;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2013-06-03 11:49:26 +08:00
|
|
|
if (!ah->curchan)
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
BUG_ON(aniState == NULL);
|
|
|
|
ah->stats.ast_ani_reset++;
|
|
|
|
|
|
|
|
/* only allow a subset of functions in AP mode */
|
|
|
|
if (ah->opmode == NL80211_IFTYPE_AP) {
|
|
|
|
if (IS_CHAN_2GHZ(chan)) {
|
|
|
|
ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
|
|
|
|
ATH9K_ANI_FIRSTEP_LEVEL);
|
|
|
|
if (AR_SREV_9300_20_OR_LATER(ah))
|
|
|
|
ah->ani_function |= ATH9K_ANI_MRC_CCK;
|
|
|
|
} else
|
|
|
|
ah->ani_function = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always allow mode (on/off) to be controlled */
|
|
|
|
ah->ani_function |= ATH9K_ANI_MODE;
|
|
|
|
|
2012-06-15 21:25:26 +08:00
|
|
|
ofdm_nil = max_t(int, ATH9K_ANI_OFDM_DEF_LEVEL,
|
|
|
|
aniState->ofdmNoiseImmunityLevel);
|
|
|
|
cck_nil = max_t(int, ATH9K_ANI_CCK_DEF_LEVEL,
|
|
|
|
aniState->cckNoiseImmunityLevel);
|
|
|
|
|
2010-06-12 12:33:45 +08:00
|
|
|
if (is_scanning ||
|
|
|
|
(ah->opmode != NL80211_IFTYPE_STATION &&
|
|
|
|
ah->opmode != NL80211_IFTYPE_ADHOC)) {
|
|
|
|
/*
|
|
|
|
* If we're scanning or in AP mode, the defaults (ini)
|
|
|
|
* should be in place. For an AP we assume the historical
|
|
|
|
* levels for this channel are probably outdated so start
|
|
|
|
* from defaults instead.
|
|
|
|
*/
|
|
|
|
if (aniState->ofdmNoiseImmunityLevel !=
|
|
|
|
ATH9K_ANI_OFDM_DEF_LEVEL ||
|
|
|
|
aniState->cckNoiseImmunityLevel !=
|
|
|
|
ATH9K_ANI_CCK_DEF_LEVEL) {
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI,
|
2010-12-03 11:12:37 +08:00
|
|
|
"Restore defaults: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
|
|
|
|
ah->opmode,
|
|
|
|
chan->channel,
|
|
|
|
chan->channelFlags,
|
|
|
|
is_scanning,
|
|
|
|
aniState->ofdmNoiseImmunityLevel,
|
|
|
|
aniState->cckNoiseImmunityLevel);
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2012-06-15 21:25:26 +08:00
|
|
|
ofdm_nil = ATH9K_ANI_OFDM_DEF_LEVEL;
|
|
|
|
cck_nil = ATH9K_ANI_CCK_DEF_LEVEL;
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* restore historical levels for this channel
|
|
|
|
*/
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI,
|
2010-12-03 11:12:37 +08:00
|
|
|
"Restore history: opmode %u chan %d Mhz/0x%x is_scanning=%d ofdm:%d cck:%d\n",
|
|
|
|
ah->opmode,
|
|
|
|
chan->channel,
|
|
|
|
chan->channelFlags,
|
|
|
|
is_scanning,
|
|
|
|
aniState->ofdmNoiseImmunityLevel,
|
|
|
|
aniState->cckNoiseImmunityLevel);
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
2012-06-27 20:58:19 +08:00
|
|
|
ath9k_hw_set_ofdm_nil(ah, ofdm_nil, is_scanning);
|
|
|
|
ath9k_hw_set_cck_nil(ah, cck_nil, is_scanning);
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* enable phy counters if hw supports or if not, enable phy
|
|
|
|
* interrupts (so we can count each one)
|
|
|
|
*/
|
2010-10-05 02:09:47 +08:00
|
|
|
ath9k_ani_restart(ah);
|
2010-04-16 14:23:57 +08:00
|
|
|
|
|
|
|
ENABLE_REGWRITE_BUFFER(ah);
|
|
|
|
|
2009-08-13 12:04:25 +08:00
|
|
|
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);
|
2010-04-16 14:23:57 +08:00
|
|
|
|
|
|
|
REGWRITE_BUFFER_FLUSH(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
|
2010-10-12 22:08:01 +08:00
|
|
|
static bool ath9k_hw_ani_read_counters(struct ath_hw *ah)
|
2008-10-29 12:46:30 +08:00
|
|
|
{
|
2009-09-13 17:42:02 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
2010-10-05 02:09:48 +08:00
|
|
|
struct ar5416AniState *aniState = &ah->curchan->ani;
|
|
|
|
u32 phyCnt1, phyCnt2;
|
|
|
|
int32_t listenTime;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2010-10-09 04:13:53 +08:00
|
|
|
ath_hw_cycle_counters_update(common);
|
|
|
|
listenTime = ath_hw_get_listen_time(common);
|
|
|
|
|
2010-10-12 22:08:01 +08:00
|
|
|
if (listenTime <= 0) {
|
2011-08-26 13:49:57 +08:00
|
|
|
ah->stats.ast_ani_lneg_or_lzero++;
|
2010-10-05 02:09:47 +08:00
|
|
|
ath9k_ani_restart(ah);
|
2010-10-12 22:08:01 +08:00
|
|
|
return false;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-06-15 21:25:24 +08:00
|
|
|
ah->stats.ast_ani_ofdmerrs += phyCnt1 - aniState->ofdmPhyErrCount;
|
|
|
|
aniState->ofdmPhyErrCount = phyCnt1;
|
|
|
|
|
|
|
|
ah->stats.ast_ani_cckerrs += phyCnt2 - aniState->cckPhyErrCount;
|
|
|
|
aniState->cckPhyErrCount = phyCnt2;
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2010-10-12 22:08:01 +08:00
|
|
|
return true;
|
2010-10-05 02:09:48 +08:00
|
|
|
}
|
|
|
|
|
2010-10-05 02:09:50 +08:00
|
|
|
void ath9k_hw_ani_monitor(struct ath_hw *ah, struct ath9k_channel *chan)
|
2010-06-12 12:33:45 +08:00
|
|
|
{
|
|
|
|
struct ar5416AniState *aniState;
|
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
|
|
|
u32 ofdmPhyErrRate, cckPhyErrRate;
|
|
|
|
|
2013-06-03 11:49:26 +08:00
|
|
|
if (!ah->curchan)
|
2010-06-12 12:33:45 +08:00
|
|
|
return;
|
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
aniState = &ah->curchan->ani;
|
2010-10-12 22:08:01 +08:00
|
|
|
if (!ath9k_hw_ani_read_counters(ah))
|
|
|
|
return;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
|
|
|
ofdmPhyErrRate = aniState->ofdmPhyErrCount * 1000 /
|
|
|
|
aniState->listenTime;
|
|
|
|
cckPhyErrRate = aniState->cckPhyErrCount * 1000 /
|
|
|
|
aniState->listenTime;
|
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI,
|
2010-12-03 11:12:37 +08:00
|
|
|
"listenTime=%d OFDM:%d errs=%d/s CCK:%d errs=%d/s ofdm_turn=%d\n",
|
|
|
|
aniState->listenTime,
|
|
|
|
aniState->ofdmNoiseImmunityLevel,
|
|
|
|
ofdmPhyErrRate, aniState->cckNoiseImmunityLevel,
|
|
|
|
cckPhyErrRate, aniState->ofdmsTurn);
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2012-03-15 08:04:26 +08:00
|
|
|
if (aniState->listenTime > ah->aniperiod) {
|
|
|
|
if (cckPhyErrRate < ah->config.cck_trig_low &&
|
2012-06-15 21:25:27 +08:00
|
|
|
ofdmPhyErrRate < ah->config.ofdm_trig_low) {
|
2010-06-12 12:33:45 +08:00
|
|
|
ath9k_hw_ani_lower_immunity(ah);
|
|
|
|
aniState->ofdmsTurn = !aniState->ofdmsTurn;
|
2012-06-15 21:25:27 +08:00
|
|
|
} else if (ofdmPhyErrRate > ah->config.ofdm_trig_high) {
|
2010-10-05 02:09:49 +08:00
|
|
|
ath9k_hw_ani_ofdm_err_trigger(ah);
|
2010-06-12 12:33:45 +08:00
|
|
|
aniState->ofdmsTurn = false;
|
2010-10-05 02:09:47 +08:00
|
|
|
} else if (cckPhyErrRate > ah->config.cck_trig_high) {
|
2010-10-05 02:09:49 +08:00
|
|
|
ath9k_hw_ani_cck_err_trigger(ah);
|
2010-06-12 12:33:45 +08:00
|
|
|
aniState->ofdmsTurn = true;
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
2012-03-15 08:04:26 +08:00
|
|
|
ath9k_ani_restart(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
}
|
2010-10-05 02:09:50 +08:00
|
|
|
EXPORT_SYMBOL(ath9k_hw_ani_monitor);
|
2008-10-29 12:46:30 +08:00
|
|
|
|
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
|
|
|
{
|
2009-09-13 17:42:02 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI, "Enable MIB counters\n");
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2009-02-09 15:57:12 +08:00
|
|
|
ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
|
2008-10-29 12:46:30 +08:00
|
|
|
|
2010-04-16 14:23:57 +08:00
|
|
|
ENABLE_REGWRITE_BUFFER(ah);
|
|
|
|
|
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);
|
2010-04-16 14:23:57 +08:00
|
|
|
|
|
|
|
REGWRITE_BUFFER_FLUSH(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-09-13 17:42:02 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI, "Disable MIB counters\n");
|
2009-09-13 17:42:02 +08:00
|
|
|
|
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);
|
|
|
|
}
|
2010-06-01 17:44:18 +08:00
|
|
|
EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
|
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
|
|
|
{
|
2009-09-13 17:42:02 +08:00
|
|
|
struct ath_common *common = ath9k_hw_common(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
int i;
|
|
|
|
|
2011-12-16 06:55:53 +08:00
|
|
|
ath_dbg(common, ANI, "Initialize ANI\n");
|
2009-02-09 15:57:26 +08:00
|
|
|
|
2012-06-15 21:25:24 +08:00
|
|
|
ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
|
|
|
|
ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2012-06-15 21:25:24 +08:00
|
|
|
ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH;
|
|
|
|
ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW;
|
2010-06-12 12:33:45 +08:00
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ah->channels); i++) {
|
|
|
|
struct ath9k_channel *chan = &ah->channels[i];
|
|
|
|
struct ar5416AniState *ani = &chan->ani;
|
|
|
|
|
2012-06-15 21:25:24 +08:00
|
|
|
ani->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
|
|
|
|
ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
|
2012-06-21 23:03:59 +08:00
|
|
|
ani->mrcCCK = AR_SREV_9300_20_OR_LATER(ah) ? true : false;
|
2012-06-15 21:25:23 +08:00
|
|
|
ani->ofdmsTurn = true;
|
2013-06-03 11:49:27 +08:00
|
|
|
ani->ofdmWeakSigDetect = true;
|
2010-10-05 02:09:47 +08:00
|
|
|
ani->cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
|
2011-09-19 22:45:48 +08:00
|
|
|
ani->ofdmNoiseImmunityLevel = ATH9K_ANI_OFDM_DEF_LEVEL;
|
2010-06-12 12:33:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* since we expect some ongoing maintenance on the tables, let's sanity
|
|
|
|
* check here default level should not modify INI setting.
|
|
|
|
*/
|
2012-06-15 21:25:24 +08:00
|
|
|
ah->aniperiod = ATH9K_ANI_PERIOD;
|
|
|
|
ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL;
|
2009-08-13 12:04:25 +08:00
|
|
|
|
2010-10-05 02:09:47 +08:00
|
|
|
ath9k_ani_restart(ah);
|
|
|
|
ath9k_enable_mib_counters(ah);
|
2008-10-29 12:46:30 +08:00
|
|
|
}
|