1 --- a/drivers/net/wireless/ath/ath9k/beacon.c
2 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
3 @@ -362,6 +362,7 @@ void ath_beacon_tasklet(unsigned long da
4 ath_print(common, ATH_DBG_BSTUCK,
5 "missed %u consecutive beacons\n",
7 + ath9k_hw_bstuck_nfcal(ah);
8 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
9 ath_print(common, ATH_DBG_BSTUCK,
10 "beacon is officially stuck\n");
11 --- a/drivers/net/wireless/ath/ath9k/calib.c
12 +++ b/drivers/net/wireless/ath/ath9k/calib.c
13 @@ -65,12 +65,16 @@ static s16 ath9k_hw_get_default_nf(struc
16 static void ath9k_hw_update_nfcal_hist_buffer(struct ath_hw *ah,
17 - struct ath9k_nfcal_hist *h,
18 + struct ath9k_hw_cal_data *cal,
21 + struct ath_common *common = ath9k_hw_common(ah);
22 struct ath_nf_limits *limit;
23 + struct ath9k_nfcal_hist *h;
24 + bool high_nf_mid = false;
28 limit = ath9k_hw_get_nf_limits(ah, ah->curchan);
30 for (i = 0; i < NUM_NF_READINGS; i++) {
31 @@ -87,9 +91,38 @@ static void ath9k_hw_update_nfcal_hist_b
32 ath9k_hw_get_nf_hist_mid(h[i].nfCalBuffer);
35 - if (h[i].privNF > limit->max)
36 - h[i].privNF = limit->max;
40 + if (h[i].privNF > limit->max) {
43 + ath_print(common, ATH_DBG_CALIBRATE,
44 + "NFmid[%d] (%d) > MAX (%d), %s\n",
45 + i, h[i].privNF, limit->max,
46 + (cal->nfcal_interference ?
47 + "not corrected (due to interference)" :
48 + "correcting to MAX"));
51 + * Normally we limit the average noise floor by the
52 + * hardware specific maximum here. However if we have
53 + * encountered stuck beacons because of interference,
54 + * we bypass this limit here in order to better deal
55 + * with our environment.
57 + if (!cal->nfcal_interference)
58 + h[i].privNF = limit->max;
63 + * If the noise floor seems normal for all chains, assume that
64 + * there is no significant interference in the environment anymore.
65 + * Re-enable the enforcement of the NF maximum again.
68 + cal->nfcal_interference = false;
71 static bool ath9k_hw_get_nf_thresh(struct ath_hw *ah,
72 @@ -339,7 +372,7 @@ bool ath9k_hw_getnf(struct ath_hw *ah, s
74 h = caldata->nfCalHist;
75 caldata->nfcal_pending = false;
76 - ath9k_hw_update_nfcal_hist_buffer(ah, h, nfarray);
77 + ath9k_hw_update_nfcal_hist_buffer(ah, caldata, nfarray);
78 caldata->rawNoiseFloor = h[0].privNF;
81 @@ -374,3 +407,28 @@ s16 ath9k_hw_getchan_noise(struct ath_hw
82 return ah->caldata->rawNoiseFloor;
84 EXPORT_SYMBOL(ath9k_hw_getchan_noise);
86 +void ath9k_hw_bstuck_nfcal(struct ath_hw *ah)
88 + struct ath9k_hw_cal_data *caldata = ah->caldata;
90 + if (unlikely(!caldata))
94 + * If beacons are stuck, the most likely cause is interference.
95 + * Triggering a noise floor calibration at this point helps the
96 + * hardware adapt to a noisy environment much faster.
97 + * To ensure that we recover from stuck beacons quickly, let
98 + * the baseband update the internal NF value itself, similar to
99 + * what is being done after a full reset.
101 + if (!caldata->nfcal_pending)
102 + ath9k_hw_start_nfcal(ah, true);
103 + else if (!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF))
104 + ath9k_hw_getnf(ah, ah->curchan);
106 + caldata->nfcal_interference = true;
108 +EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal);
110 --- a/drivers/net/wireless/ath/ath9k/calib.h
111 +++ b/drivers/net/wireless/ath/ath9k/calib.h
112 @@ -113,6 +113,7 @@ void ath9k_hw_loadnf(struct ath_hw *ah,
113 bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
114 void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
115 struct ath9k_channel *chan);
116 +void ath9k_hw_bstuck_nfcal(struct ath_hw *ah);
117 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
118 void ath9k_hw_reset_calibration(struct ath_hw *ah,
119 struct ath9k_cal_list *currCal);
120 --- a/drivers/net/wireless/ath/ath9k/hw.h
121 +++ b/drivers/net/wireless/ath/ath9k/hw.h
122 @@ -355,6 +355,7 @@ struct ath9k_hw_cal_data {
123 int16_t rawNoiseFloor;
126 + bool nfcal_interference;
127 u16 small_signal_gain[AR9300_MAX_CHAINS];
128 u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
129 struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];