ar71xx: refresh patches
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 542-ath9k_bstuck_nf_calibrate.patch
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",
6 sc->beacon.bmisscnt);
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
14
15
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,
19 int16_t *nfarray)
20 {
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;
25 int i;
26
27 + h = cal->nfCalHist;
28 limit = ath9k_hw_get_nf_limits(ah, ah->curchan);
29
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);
33 }
34
35 - if (h[i].privNF > limit->max)
36 - h[i].privNF = limit->max;
37 + if (!h[i].privNF)
38 + continue;
39 +
40 + if (h[i].privNF > limit->max) {
41 + high_nf_mid = true;
42 +
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"));
49 +
50 + /*
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.
56 + */
57 + if (!cal->nfcal_interference)
58 + h[i].privNF = limit->max;
59 + }
60 }
61 +
62 + /*
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.
66 + */
67 + if (!high_nf_mid)
68 + cal->nfcal_interference = false;
69 }
70
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
73
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;
79 return true;
80 }
81 @@ -374,3 +407,28 @@ s16 ath9k_hw_getchan_noise(struct ath_hw
82 return ah->caldata->rawNoiseFloor;
83 }
84 EXPORT_SYMBOL(ath9k_hw_getchan_noise);
85 +
86 +void ath9k_hw_bstuck_nfcal(struct ath_hw *ah)
87 +{
88 + struct ath9k_hw_cal_data *caldata = ah->caldata;
89 +
90 + if (unlikely(!caldata))
91 + return;
92 +
93 + /*
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.
100 + */
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);
105 +
106 + caldata->nfcal_interference = true;
107 +}
108 +EXPORT_SYMBOL(ath9k_hw_bstuck_nfcal);
109 +
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;
124 bool paprd_done;
125 bool nfcal_pending;
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];