Date:2010-07-31 00:18:57 (13 years 7 months ago)
Author:nbd
Commit:b00a170db9d65ade8c080fca8c49ac5ff671ec4c
Message:mac80211: update to 2010-07-29, add pending patches to fix further issues with calibration

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@22419 3c298f89-4303-0410-b956-a3cf2f4a3e73
Files: package/mac80211/Makefile (1 diff)
package/mac80211/patches/130-printk_debug_revert.patch (1 diff)
package/mac80211/patches/520-mac80211_offchannel_conf.patch (1 diff)
package/mac80211/patches/520-pending_work.patch (1 diff)
package/mac80211/patches/521-ath9k_no_offchannel_cal.patch (1 diff)
package/mac80211/patches/522-ath9k_cleanup_cal_data.patch (1 diff)
package/mac80211/patches/523-ath9k_nfcal_timeout_handling.patch (1 diff)

Change Details

package/mac80211/Makefile
1010
1111PKG_NAME:=mac80211
1212
13PKG_VERSION:=2010-07-26
13PKG_VERSION:=2010-07-29
1414PKG_RELEASE:=1
1515PKG_SOURCE_URL:=http://mirror2.openwrt.org/sources
1616# http://www.orbit-lab.org/kernel/compat-wireless-2.6/2010/11 \
1717# http://wireless.kernel.org/download/compat-wireless-2.6
18PKG_MD5SUM:=4388547c8cf60a895d9ee64420df2f25
18PKG_MD5SUM:=fcfb757939c4718efbf9c87ca59c6932
1919
2020PKG_SOURCE:=compat-wireless-$(PKG_VERSION).tar.bz2
2121PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/compat-wireless-$(PKG_VERSION)
package/mac80211/patches/130-printk_debug_revert.patch
1--- a/include/net/cfg80211.h
2@@ -2443,9 +2443,8 @@ void cfg80211_cqm_rssi_notify(struct net
3     wiphy_printk(KERN_NOTICE, wiphy, format, ##args)
4 #define wiphy_info(wiphy, format, args...) \
5     wiphy_printk(KERN_INFO, wiphy, format, ##args)
6-
7-int wiphy_debug(const struct wiphy *wiphy, const char *format, ...)
8- __attribute__ ((format (printf, 2, 3)));
9+#define wiphy_debug(wiphy, format, args...) \
10+ wiphy_printk(KERN_DEBUG, wiphy, format, ##args)
11
12 #if defined(DEBUG)
13 #define wiphy_dbg(wiphy, format, args...) \
14--- a/net/wireless/core.c
15@@ -921,52 +921,3 @@ static void __exit cfg80211_exit(void)
16     destroy_workqueue(cfg80211_wq);
17 }
18 module_exit(cfg80211_exit);
19-
20-static int ___wiphy_printk(const char *level, const struct wiphy *wiphy,
21- struct va_format *vaf)
22-{
23- if (!wiphy)
24- return printk("%s(NULL wiphy *): %pV", level, vaf);
25-
26- return printk("%s%s: %pV", level, wiphy_name(wiphy), vaf);
27-}
28-
29-int __wiphy_printk(const char *level, const struct wiphy *wiphy,
30- const char *fmt, ...)
31-{
32- struct va_format vaf;
33- va_list args;
34- int r;
35-
36- va_start(args, fmt);
37-
38- vaf.fmt = fmt;
39- vaf.va = &args;
40-
41- r = ___wiphy_printk(level, wiphy, &vaf);
42- va_end(args);
43-
44- return r;
45-}
46-EXPORT_SYMBOL(__wiphy_printk);
47-
48-#define define_wiphy_printk_level(func, kern_level) \
49-int func(const struct wiphy *wiphy, const char *fmt, ...) \
50-{ \
51- struct va_format vaf; \
52- va_list args; \
53- int r; \
54- \
55- va_start(args, fmt); \
56- \
57- vaf.fmt = fmt; \
58- vaf.va = &args; \
59- \
60- r = ___wiphy_printk(kern_level, wiphy, &vaf); \
61- va_end(args); \
62- \
63- return r; \
64-} \
65-EXPORT_SYMBOL(func);
66-
67-define_wiphy_printk_level(wiphy_debug, KERN_DEBUG);
package/mac80211/patches/520-mac80211_offchannel_conf.patch
1+++ b/include/net/mac80211.h
2@@ -625,11 +625,14 @@ struct ieee80211_rx_status {
3  * may turn the device off as much as possible. Typically, this flag will
4  * be set when an interface is set UP but not associated or scanning, but
5  * it can also be unset in that case when monitor interfaces are active.
6+ * @IEEE80211_CONF_OFFCHANNEL: The device is currently not on its main
7+ * operating channel.
8  */
9 enum ieee80211_conf_flags {
10     IEEE80211_CONF_MONITOR = (1<<0),
11     IEEE80211_CONF_PS = (1<<1),
12     IEEE80211_CONF_IDLE = (1<<2),
13+ IEEE80211_CONF_OFFCHANNEL = (1<<3),
14 };
15
16
17+++ b/net/mac80211/main.c
18@@ -111,12 +111,15 @@ int ieee80211_hw_config(struct ieee80211
19     if (scan_chan) {
20         chan = scan_chan;
21         channel_type = NL80211_CHAN_NO_HT;
22+ local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
23     } else if (local->tmp_channel) {
24         chan = scan_chan = local->tmp_channel;
25         channel_type = local->tmp_channel_type;
26+ local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
27     } else {
28         chan = local->oper_channel;
29         channel_type = local->_oper_channel_type;
30+ local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
31     }
32
33     if (chan != local->hw.conf.channel ||
package/mac80211/patches/520-pending_work.patch
1--- a/net/mac80211/main.c
2@@ -103,11 +103,13 @@ int ieee80211_hw_config(struct ieee80211
3     int ret = 0;
4     int power;
5     enum nl80211_channel_type channel_type;
6+ u32 offchannel_flag;
7
8     might_sleep();
9
10     scan_chan = local->scan_channel;
11
12+ offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
13     if (scan_chan) {
14         chan = scan_chan;
15         channel_type = NL80211_CHAN_NO_HT;
16@@ -121,8 +123,9 @@ int ieee80211_hw_config(struct ieee80211
17         channel_type = local->_oper_channel_type;
18         local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
19     }
20+ offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
21
22- if (chan != local->hw.conf.channel ||
23+ if (offchannel_flag || chan != local->hw.conf.channel ||
24         channel_type != local->hw.conf.channel_type) {
25         local->hw.conf.channel = chan;
26         local->hw.conf.channel_type = channel_type;
27--- a/drivers/net/wireless/ath/ath9k/ar9002_calib.c
28@@ -63,6 +63,7 @@ static bool ar9002_hw_per_calibration(st
29                       u8 rxchainmask,
30                       struct ath9k_cal_list *currCal)
31 {
32+ struct ath9k_hw_cal_data *caldata = ah->caldata;
33     bool iscaldone = false;
34
35     if (currCal->calState == CAL_RUNNING) {
36@@ -81,14 +82,14 @@ static bool ar9002_hw_per_calibration(st
37                 }
38
39                 currCal->calData->calPostProc(ah, numChains);
40- ichan->CalValid |= currCal->calData->calType;
41+ caldata->CalValid |= currCal->calData->calType;
42                 currCal->calState = CAL_DONE;
43                 iscaldone = true;
44             } else {
45                 ar9002_hw_setup_calibration(ah, currCal);
46             }
47         }
48- } else if (!(ichan->CalValid & currCal->calData->calType)) {
49+ } else if (!(caldata->CalValid & currCal->calData->calType)) {
50         ath9k_hw_reset_calibration(ah, currCal);
51     }
52
53@@ -686,8 +687,13 @@ static bool ar9002_hw_calibrate(struct a
54 {
55     bool iscaldone = true;
56     struct ath9k_cal_list *currCal = ah->cal_list_curr;
57+ bool nfcal, nfcal_pending = false;
58
59- if (currCal &&
60+ nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
61+ if (ah->caldata)
62+ nfcal_pending = ah->caldata->nfcal_pending;
63+
64+ if (currCal && !nfcal &&
65         (currCal->calState == CAL_RUNNING ||
66          currCal->calState == CAL_WAITING)) {
67         iscaldone = ar9002_hw_per_calibration(ah, chan,
68@@ -703,7 +709,7 @@ static bool ar9002_hw_calibrate(struct a
69     }
70
71     /* Do NF cal only at longer intervals */
72- if (longcal) {
73+ if (longcal || nfcal_pending) {
74         /* Do periodic PAOffset Cal */
75         ar9002_hw_pa_cal(ah, false);
76         ar9002_hw_olc_temp_compensation(ah);
77@@ -712,16 +718,18 @@ static bool ar9002_hw_calibrate(struct a
78          * Get the value from the previous NF cal and update
79          * history buffer.
80          */
81- ath9k_hw_getnf(ah, chan);
82-
83- /*
84- * Load the NF from history buffer of the current channel.
85- * NF is slow time-variant, so it is OK to use a historical
86- * value.
87- */
88- ath9k_hw_loadnf(ah, ah->curchan);
89+ if (ath9k_hw_getnf(ah, chan)) {
90+ /*
91+ * Load the NF from history buffer of the current
92+ * channel.
93+ * NF is slow time-variant, so it is OK to use a
94+ * historical value.
95+ */
96+ ath9k_hw_loadnf(ah, ah->curchan);
97+ }
98
99- ath9k_hw_start_nfcal(ah);
100+ if (longcal)
101+ ath9k_hw_start_nfcal(ah, false);
102     }
103
104     return iscaldone;
105@@ -869,8 +877,10 @@ static bool ar9002_hw_init_cal(struct at
106     ar9002_hw_pa_cal(ah, true);
107
108     /* Do NF Calibration after DC offset and other calibrations */
109- REG_WRITE(ah, AR_PHY_AGC_CONTROL,
110- REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF);
111+ ath9k_hw_start_nfcal(ah, true);
112+
113+ if (ah->caldata)
114+ ah->caldata->nfcal_pending = true;
115
116     ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
117
118@@ -901,7 +911,8 @@ static bool ar9002_hw_init_cal(struct at
119             ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
120     }
121
122- chan->CalValid = 0;
123+ if (ah->caldata)
124+ ah->caldata->CalValid = 0;
125
126     return true;
127 }
128--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
129@@ -68,6 +68,7 @@ static bool ar9003_hw_per_calibration(st
130                       u8 rxchainmask,
131                       struct ath9k_cal_list *currCal)
132 {
133+ struct ath9k_hw_cal_data *caldata = ah->caldata;
134     /* Cal is assumed not done until explicitly set below */
135     bool iscaldone = false;
136
137@@ -95,7 +96,7 @@ static bool ar9003_hw_per_calibration(st
138                 currCal->calData->calPostProc(ah, numChains);
139
140                 /* Calibration has finished. */
141- ichan->CalValid |= currCal->calData->calType;
142+ caldata->CalValid |= currCal->calData->calType;
143                 currCal->calState = CAL_DONE;
144                 iscaldone = true;
145             } else {
146@@ -106,7 +107,7 @@ static bool ar9003_hw_per_calibration(st
147             ar9003_hw_setup_calibration(ah, currCal);
148             }
149         }
150- } else if (!(ichan->CalValid & currCal->calData->calType)) {
151+ } else if (!(caldata->CalValid & currCal->calData->calType)) {
152         /* If current cal is marked invalid in channel, kick it off */
153         ath9k_hw_reset_calibration(ah, currCal);
154     }
155@@ -149,6 +150,12 @@ static bool ar9003_hw_calibrate(struct a
156     /* Do NF cal only at longer intervals */
157     if (longcal) {
158         /*
159+ * Get the value from the previous NF cal and update
160+ * history buffer.
161+ */
162+ ath9k_hw_getnf(ah, chan);
163+
164+ /*
165          * Load the NF from history buffer of the current channel.
166          * NF is slow time-variant, so it is OK to use a historical
167          * value.
168@@ -156,7 +163,7 @@ static bool ar9003_hw_calibrate(struct a
169         ath9k_hw_loadnf(ah, ah->curchan);
170
171         /* start NF calibration, without updating BB NF register */
172- ath9k_hw_start_nfcal(ah);
173+ ath9k_hw_start_nfcal(ah, false);
174     }
175
176     return iscaldone;
177@@ -762,6 +769,8 @@ static bool ar9003_hw_init_cal(struct at
178     /* Revert chainmasks to their original values before NF cal */
179     ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
180
181+ ath9k_hw_start_nfcal(ah, true);
182+
183     /* Initialize list pointers */
184     ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
185
186@@ -785,7 +794,8 @@ static bool ar9003_hw_init_cal(struct at
187     if (ah->cal_list_curr)
188         ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
189
190- chan->CalValid = 0;
191+ if (ah->caldata)
192+ ah->caldata->CalValid = 0;
193
194     return true;
195 }
196--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
197@@ -542,7 +542,11 @@ static void ar9003_hw_prog_ini(struct at
198         u32 reg = INI_RA(iniArr, i, 0);
199         u32 val = INI_RA(iniArr, i, column);
200
201- REG_WRITE(ah, reg, val);
202+ if (reg >= 0x16000 && reg < 0x17000)
203+ ath9k_hw_analog_shift_regwrite(ah, reg, val);
204+ else
205+ REG_WRITE(ah, reg, val);
206+
207         DO_DELAY(regWrites);
208     }
209 }
210--- a/drivers/net/wireless/ath/ath9k/calib.c
211@@ -22,23 +22,6 @@
212 /* We can tune this as we go by monitoring really low values */
213 #define ATH9K_NF_TOO_LOW -60
214
215-/* AR5416 may return very high value (like -31 dBm), in those cases the nf
216- * is incorrect and we should use the static NF value. Later we can try to
217- * find out why they are reporting these values */
218-
219-static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf)
220-{
221- if (nf > ATH9K_NF_TOO_LOW) {
222- ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
223- "noise floor value detected (%d) is "
224- "lower than what we think is a "
225- "reasonable value (%d)\n",
226- nf, ATH9K_NF_TOO_LOW);
227- return false;
228- }
229- return true;
230-}
231-
232 static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
233 {
234     int16_t nfval;
235@@ -121,6 +104,19 @@ void ath9k_hw_reset_calibration(struct a
236     ah->cal_samples = 0;
237 }
238
239+static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
240+ struct ath9k_channel *chan)
241+{
242+ struct ath_nf_limits *limit;
243+
244+ if (!chan || IS_CHAN_2GHZ(chan))
245+ limit = &ah->nf_2g;
246+ else
247+ limit = &ah->nf_5g;
248+
249+ return limit->nominal;
250+}
251+
252 /* This is done for the currently configured channel */
253 bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
254 {
255@@ -128,7 +124,7 @@ bool ath9k_hw_reset_calvalid(struct ath_
256     struct ieee80211_conf *conf = &common->hw->conf;
257     struct ath9k_cal_list *currCal = ah->cal_list_curr;
258
259- if (!ah->curchan)
260+ if (!ah->caldata)
261         return true;
262
263     if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
264@@ -151,37 +147,55 @@ bool ath9k_hw_reset_calvalid(struct ath_
265           "Resetting Cal %d state for channel %u\n",
266           currCal->calData->calType, conf->channel->center_freq);
267
268- ah->curchan->CalValid &= ~currCal->calData->calType;
269+ ah->caldata->CalValid &= ~currCal->calData->calType;
270     currCal->calState = CAL_WAITING;
271
272     return false;
273 }
274 EXPORT_SYMBOL(ath9k_hw_reset_calvalid);
275
276-void ath9k_hw_start_nfcal(struct ath_hw *ah)
277+void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update)
278 {
279+ if (ah->caldata)
280+ ah->caldata->nfcal_pending = true;
281+
282     REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
283             AR_PHY_AGC_CONTROL_ENABLE_NF);
284- REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
285+
286+ if (update)
287+ REG_CLR_BIT(ah, AR_PHY_AGC_CONTROL,
288+ AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
289+ else
290+ REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
291             AR_PHY_AGC_CONTROL_NO_UPDATE_NF);
292+
293     REG_SET_BIT(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_NF);
294 }
295
296 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
297 {
298- struct ath9k_nfcal_hist *h;
299+ struct ath9k_nfcal_hist *h = NULL;
300     unsigned i, j;
301     int32_t val;
302     u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
303     struct ath_common *common = ath9k_hw_common(ah);
304+ s16 default_nf = ath9k_hw_get_default_nf(ah, chan);
305
306- h = ah->nfCalHist;
307+ if (ah->caldata)
308+ h = ah->caldata->nfCalHist;
309
310     for (i = 0; i < NUM_NF_READINGS; i++) {
311         if (chainmask & (1 << i)) {
312+ s16 nfval;
313+
314+ if (h)
315+ nfval = h[i].privNF;
316+ else
317+ nfval = default_nf;
318+
319             val = REG_READ(ah, ah->nf_regs[i]);
320             val &= 0xFFFFFE00;
321- val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
322+ val |= (((u32) nfval << 1) & 0x1ff);
323             REG_WRITE(ah, ah->nf_regs[i], val);
324         }
325     }
326@@ -277,22 +291,25 @@ static void ath9k_hw_nf_sanitize(struct
327     }
328 }
329
330-int16_t ath9k_hw_getnf(struct ath_hw *ah,
331- struct ath9k_channel *chan)
332+bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
333 {
334     struct ath_common *common = ath9k_hw_common(ah);
335     int16_t nf, nfThresh;
336     int16_t nfarray[NUM_NF_READINGS] = { 0 };
337     struct ath9k_nfcal_hist *h;
338     struct ieee80211_channel *c = chan->chan;
339+ struct ath9k_hw_cal_data *caldata = ah->caldata;
340+
341+ if (!caldata)
342+ return false;
343
344     chan->channelFlags &= (~CHANNEL_CW_INT);
345     if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
346         ath_print(common, ATH_DBG_CALIBRATE,
347               "NF did not complete in calibration window\n");
348         nf = 0;
349- chan->rawNoiseFloor = nf;
350- return chan->rawNoiseFloor;
351+ caldata->rawNoiseFloor = nf;
352+ return false;
353     } else {
354         ath9k_hw_do_getnf(ah, nfarray);
355         ath9k_hw_nf_sanitize(ah, nfarray);
356@@ -307,47 +324,40 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
357         }
358     }
359
360- h = ah->nfCalHist;
361-
362+ h = caldata->nfCalHist;
363+ caldata->nfcal_pending = false;
364     ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
365- chan->rawNoiseFloor = h[0].privNF;
366-
367- return chan->rawNoiseFloor;
368+ caldata->rawNoiseFloor = h[0].privNF;
369+ return true;
370 }
371
372-void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah)
373+void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
374+ struct ath9k_channel *chan)
375 {
376- struct ath_nf_limits *limit;
377+ struct ath9k_nfcal_hist *h;
378+ s16 default_nf;
379     int i, j;
380
381- if (!ah->curchan || IS_CHAN_2GHZ(ah->curchan))
382- limit = &ah->nf_2g;
383- else
384- limit = &ah->nf_5g;
385+ if (!ah->caldata)
386+ return;
387
388+ h = ah->caldata->nfCalHist;
389+ default_nf = ath9k_hw_get_default_nf(ah, chan);
390     for (i = 0; i < NUM_NF_READINGS; i++) {
391- ah->nfCalHist[i].currIndex = 0;
392- ah->nfCalHist[i].privNF = limit->nominal;
393- ah->nfCalHist[i].invalidNFcount =
394- AR_PHY_CCA_FILTERWINDOW_LENGTH;
395+ h[i].currIndex = 0;
396+ h[i].privNF = default_nf;
397+ h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH;
398         for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
399- ah->nfCalHist[i].nfCalBuffer[j] = limit->nominal;
400+ h[i].nfCalBuffer[j] = default_nf;
401         }
402     }
403 }
404
405 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
406 {
407- s16 nf;
408-
409- if (chan->rawNoiseFloor == 0)
410- nf = -96;
411- else
412- nf = chan->rawNoiseFloor;
413-
414- if (!ath9k_hw_nf_in_range(ah, nf))
415- nf = ATH_DEFAULT_NOISE_FLOOR;
416+ if (!ah->caldata || !ah->caldata->rawNoiseFloor)
417+ return ath9k_hw_get_default_nf(ah, chan);
418
419- return nf;
420+ return ah->caldata->rawNoiseFloor;
421 }
422 EXPORT_SYMBOL(ath9k_hw_getchan_noise);
423--- a/drivers/net/wireless/ath/ath9k/calib.h
424@@ -108,11 +108,11 @@ struct ath9k_pacal_info{
425 };
426
427 bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
428-void ath9k_hw_start_nfcal(struct ath_hw *ah);
429+void ath9k_hw_start_nfcal(struct ath_hw *ah, bool update);
430 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
431-int16_t ath9k_hw_getnf(struct ath_hw *ah,
432- struct ath9k_channel *chan);
433-void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
434+bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
435+void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
436+ struct ath9k_channel *chan);
437 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
438 void ath9k_hw_reset_calibration(struct ath_hw *ah,
439                 struct ath9k_cal_list *currCal);
440--- a/drivers/net/wireless/ath/ath9k/hw.c
441@@ -622,7 +622,6 @@ static int __ath9k_hw_init(struct ath_hw
442     else
443         ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
444
445- ath9k_init_nfcal_hist_buffer(ah);
446     ah->bb_watchdog_timeout_ms = 25;
447
448     common->state = ATH_HW_INITIALIZED;
449@@ -1195,9 +1194,6 @@ static bool ath9k_hw_channel_change(stru
450
451     ath9k_hw_spur_mitigate_freq(ah, chan);
452
453- if (!chan->oneTimeCalsDone)
454- chan->oneTimeCalsDone = true;
455-
456     return true;
457 }
458
459@@ -1230,7 +1226,7 @@ bool ath9k_hw_check_alive(struct ath_hw
460 EXPORT_SYMBOL(ath9k_hw_check_alive);
461
462 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
463- bool bChannelChange)
464+ struct ath9k_hw_cal_data *caldata, bool bChannelChange)
465 {
466     struct ath_common *common = ath9k_hw_common(ah);
467     u32 saveLedState;
468@@ -1255,9 +1251,19 @@ int ath9k_hw_reset(struct ath_hw *ah, st
469     if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
470         return -EIO;
471
472- if (curchan && !ah->chip_fullsleep)
473+ if (curchan && !ah->chip_fullsleep && ah->caldata)
474         ath9k_hw_getnf(ah, curchan);
475
476+ ah->caldata = caldata;
477+ if (caldata &&
478+ (chan->channel != caldata->channel ||
479+ (chan->channelFlags & ~CHANNEL_CW_INT) !=
480+ (caldata->channelFlags & ~CHANNEL_CW_INT))) {
481+ /* Operating channel changed, reset channel calibration data */
482+ memset(caldata, 0, sizeof(*caldata));
483+ ath9k_init_nfcal_hist_buffer(ah, chan);
484+ }
485+
486     if (bChannelChange &&
487         (ah->chip_fullsleep != true) &&
488         (ah->curchan != NULL) &&
489@@ -1268,7 +1274,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
490
491         if (ath9k_hw_channel_change(ah, chan)) {
492             ath9k_hw_loadnf(ah, ah->curchan);
493- ath9k_hw_start_nfcal(ah);
494+ ath9k_hw_start_nfcal(ah, true);
495             return 0;
496         }
497     }
498@@ -1473,11 +1479,8 @@ int ath9k_hw_reset(struct ath_hw *ah, st
499     if (ah->btcoex_hw.enabled)
500         ath9k_hw_btcoex_enable(ah);
501
502- if (AR_SREV_9300_20_OR_LATER(ah)) {
503- ath9k_hw_loadnf(ah, curchan);
504- ath9k_hw_start_nfcal(ah);
505+ if (AR_SREV_9300_20_OR_LATER(ah))
506         ar9003_hw_bb_watchdog_config(ah);
507- }
508
509     return 0;
510 }
511--- a/drivers/net/wireless/ath/ath9k/main.c
512@@ -155,6 +155,27 @@ void ath9k_ps_restore(struct ath_softc *
513     spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
514 }
515
516+static void ath_start_ani(struct ath_common *common)
517+{
518+ struct ath_hw *ah = common->ah;
519+ unsigned long timestamp = jiffies_to_msecs(jiffies);
520+ struct ath_softc *sc = (struct ath_softc *) common->priv;
521+
522+ if (!(sc->sc_flags & SC_OP_ANI_RUN))
523+ return;
524+
525+ if (sc->sc_flags & SC_OP_OFFCHANNEL)
526+ return;
527+
528+ common->ani.longcal_timer = timestamp;
529+ common->ani.shortcal_timer = timestamp;
530+ common->ani.checkani_timer = timestamp;
531+
532+ mod_timer(&common->ani.timer,
533+ jiffies +
534+ msecs_to_jiffies((u32)ah->config.ani_poll_interval));
535+}
536+
537 /*
538  * Set/change channels. If the channel is really being changed, it's done
539  * by reseting the chip. To accomplish this we must first cleanup any pending
540@@ -163,16 +184,23 @@ void ath9k_ps_restore(struct ath_softc *
541 int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
542             struct ath9k_channel *hchan)
543 {
544+ struct ath_wiphy *aphy = hw->priv;
545     struct ath_hw *ah = sc->sc_ah;
546     struct ath_common *common = ath9k_hw_common(ah);
547     struct ieee80211_conf *conf = &common->hw->conf;
548     bool fastcc = true, stopped;
549     struct ieee80211_channel *channel = hw->conf.channel;
550+ struct ath9k_hw_cal_data *caldata = NULL;
551     int r;
552
553     if (sc->sc_flags & SC_OP_INVALID)
554         return -EIO;
555
556+ del_timer_sync(&common->ani.timer);
557+ cancel_work_sync(&sc->paprd_work);
558+ cancel_work_sync(&sc->hw_check_work);
559+ cancel_delayed_work_sync(&sc->tx_complete_work);
560+
561     ath9k_ps_wakeup(sc);
562
563     /*
564@@ -192,9 +220,12 @@ int ath_set_channel(struct ath_softc *sc
565      * to flush data frames already in queue because of
566      * changing channel. */
567
568- if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
569+ if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
570         fastcc = false;
571
572+ if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
573+ caldata = &aphy->caldata;
574+
575     ath_print(common, ATH_DBG_CONFIG,
576           "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
577           sc->sc_ah->curchan->channel,
578@@ -202,7 +233,7 @@ int ath_set_channel(struct ath_softc *sc
579
580     spin_lock_bh(&sc->sc_resetlock);
581
582- r = ath9k_hw_reset(ah, hchan, fastcc);
583+ r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
584     if (r) {
585         ath_print(common, ATH_DBG_FATAL,
586               "Unable to reset channel (%u MHz), "
587@@ -213,8 +244,6 @@ int ath_set_channel(struct ath_softc *sc
588     }
589     spin_unlock_bh(&sc->sc_resetlock);
590
591- sc->sc_flags &= ~SC_OP_FULL_RESET;
592-
593     if (ath_startrecv(sc) != 0) {
594         ath_print(common, ATH_DBG_FATAL,
595               "Unable to restart recv logic\n");
596@@ -226,6 +255,12 @@ int ath_set_channel(struct ath_softc *sc
597     ath_update_txpow(sc);
598     ath9k_hw_set_interrupts(ah, ah->imask);
599
600+ if (!(sc->sc_flags & (SC_OP_OFFCHANNEL | SC_OP_SCANNING))) {
601+ ath_start_ani(common);
602+ ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
603+ ath_beacon_config(sc, NULL);
604+ }
605+
606  ps_restore:
607     ath9k_ps_restore(sc);
608     return r;
609@@ -234,17 +269,19 @@ int ath_set_channel(struct ath_softc *sc
610 static void ath_paprd_activate(struct ath_softc *sc)
611 {
612     struct ath_hw *ah = sc->sc_ah;
613+ struct ath9k_hw_cal_data *caldata = ah->caldata;
614     int chain;
615
616- if (!ah->curchan->paprd_done)
617+ if (!caldata || !caldata->paprd_done)
618         return;
619
620     ath9k_ps_wakeup(sc);
621+ ar9003_paprd_enable(ah, false);
622     for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
623         if (!(ah->caps.tx_chainmask & BIT(chain)))
624             continue;
625
626- ar9003_paprd_populate_single_table(ah, ah->curchan, chain);
627+ ar9003_paprd_populate_single_table(ah, caldata, chain);
628     }
629
630     ar9003_paprd_enable(ah, true);
631@@ -262,6 +299,7 @@ void ath_paprd_calibrate(struct work_str
632     int band = hw->conf.channel->band;
633     struct ieee80211_supported_band *sband = &sc->sbands[band];
634     struct ath_tx_control txctl;
635+ struct ath9k_hw_cal_data *caldata = ah->caldata;
636     int qnum, ftype;
637     int chain_ok = 0;
638     int chain;
639@@ -269,6 +307,9 @@ void ath_paprd_calibrate(struct work_str
640     int time_left;
641     int i;
642
643+ if (!caldata)
644+ return;
645+
646     skb = alloc_skb(len, GFP_KERNEL);
647     if (!skb)
648         return;
649@@ -323,7 +364,7 @@ void ath_paprd_calibrate(struct work_str
650         if (!ar9003_paprd_is_done(ah))
651             break;
652
653- if (ar9003_paprd_create_curve(ah, ah->curchan, chain) != 0)
654+ if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
655             break;
656
657         chain_ok = 1;
658@@ -331,7 +372,7 @@ void ath_paprd_calibrate(struct work_str
659     kfree_skb(skb);
660
661     if (chain_ok) {
662- ah->curchan->paprd_done = true;
663+ caldata->paprd_done = true;
664         ath_paprd_activate(sc);
665     }
666
667@@ -440,33 +481,14 @@ set_timer:
668         cal_interval = min(cal_interval, (u32)short_cal_interval);
669
670     mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
671- if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) &&
672- !(sc->sc_flags & SC_OP_SCANNING)) {
673- if (!sc->sc_ah->curchan->paprd_done)
674+ if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
675+ if (!ah->caldata->paprd_done)
676             ieee80211_queue_work(sc->hw, &sc->paprd_work);
677         else
678             ath_paprd_activate(sc);
679     }
680 }
681
682-static void ath_start_ani(struct ath_common *common)
683-{
684- struct ath_hw *ah = common->ah;
685- unsigned long timestamp = jiffies_to_msecs(jiffies);
686- struct ath_softc *sc = (struct ath_softc *) common->priv;
687-
688- if (!(sc->sc_flags & SC_OP_ANI_RUN))
689- return;
690-
691- common->ani.longcal_timer = timestamp;
692- common->ani.shortcal_timer = timestamp;
693- common->ani.checkani_timer = timestamp;
694-
695- mod_timer(&common->ani.timer,
696- jiffies +
697- msecs_to_jiffies((u32)ah->config.ani_poll_interval));
698-}
699-
700 /*
701  * Update tx/rx chainmask. For legacy association,
702  * hard code chainmask to 1x1, for 11n association, use
703@@ -478,7 +500,7 @@ void ath_update_chainmask(struct ath_sof
704     struct ath_hw *ah = sc->sc_ah;
705     struct ath_common *common = ath9k_hw_common(ah);
706
707- if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
708+ if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
709         (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
710         common->tx_chainmask = ah->caps.tx_chainmask;
711         common->rx_chainmask = ah->caps.rx_chainmask;
712@@ -818,7 +840,7 @@ void ath_radio_enable(struct ath_softc *
713         ah->curchan = ath_get_curchannel(sc, sc->hw);
714
715     spin_lock_bh(&sc->sc_resetlock);
716- r = ath9k_hw_reset(ah, ah->curchan, false);
717+ r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
718     if (r) {
719         ath_print(common, ATH_DBG_FATAL,
720               "Unable to reset channel (%u MHz), "
721@@ -878,7 +900,7 @@ void ath_radio_disable(struct ath_softc
722         ah->curchan = ath_get_curchannel(sc, hw);
723
724     spin_lock_bh(&sc->sc_resetlock);
725- r = ath9k_hw_reset(ah, ah->curchan, false);
726+ r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
727     if (r) {
728         ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
729               "Unable to reset channel (%u MHz), "
730@@ -911,7 +933,7 @@ int ath_reset(struct ath_softc *sc, bool
731     ath_flushrecv(sc);
732
733     spin_lock_bh(&sc->sc_resetlock);
734- r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
735+ r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
736     if (r)
737         ath_print(common, ATH_DBG_FATAL,
738               "Unable to reset hardware; reset status %d\n", r);
739@@ -1086,7 +1108,7 @@ static int ath9k_start(struct ieee80211_
740      * and then setup of the interrupt mask.
741      */
742     spin_lock_bh(&sc->sc_resetlock);
743- r = ath9k_hw_reset(ah, init_channel, false);
744+ r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
745     if (r) {
746         ath_print(common, ATH_DBG_FATAL,
747               "Unable to reset hardware; reset status %d "
748@@ -1580,6 +1602,10 @@ static int ath9k_config(struct ieee80211
749
750         aphy->chan_idx = pos;
751         aphy->chan_is_ht = conf_is_ht(conf);
752+ if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
753+ sc->sc_flags |= SC_OP_OFFCHANNEL;
754+ else
755+ sc->sc_flags &= ~SC_OP_OFFCHANNEL;
756
757         if (aphy->state == ATH_WIPHY_SCAN ||
758             aphy->state == ATH_WIPHY_ACTIVE)
759@@ -1991,7 +2017,6 @@ static void ath9k_sw_scan_start(struct i
760 {
761     struct ath_wiphy *aphy = hw->priv;
762     struct ath_softc *sc = aphy->sc;
763- struct ath_common *common = ath9k_hw_common(sc->sc_ah);
764
765     mutex_lock(&sc->mutex);
766     if (ath9k_wiphy_scanning(sc)) {
767@@ -2009,10 +2034,6 @@ static void ath9k_sw_scan_start(struct i
768     aphy->state = ATH_WIPHY_SCAN;
769     ath9k_wiphy_pause_all_forced(sc, aphy);
770     sc->sc_flags |= SC_OP_SCANNING;
771- del_timer_sync(&common->ani.timer);
772- cancel_work_sync(&sc->paprd_work);
773- cancel_work_sync(&sc->hw_check_work);
774- cancel_delayed_work_sync(&sc->tx_complete_work);
775     mutex_unlock(&sc->mutex);
776 }
777
778@@ -2024,15 +2045,10 @@ static void ath9k_sw_scan_complete(struc
779 {
780     struct ath_wiphy *aphy = hw->priv;
781     struct ath_softc *sc = aphy->sc;
782- struct ath_common *common = ath9k_hw_common(sc->sc_ah);
783
784     mutex_lock(&sc->mutex);
785     aphy->state = ATH_WIPHY_ACTIVE;
786     sc->sc_flags &= ~SC_OP_SCANNING;
787- sc->sc_flags |= SC_OP_FULL_RESET;
788- ath_start_ani(common);
789- ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
790- ath_beacon_config(sc, NULL);
791     mutex_unlock(&sc->mutex);
792 }
793
794--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
795@@ -577,10 +577,11 @@ static bool create_pa_curve(u32 *data_L,
796 }
797
798 void ar9003_paprd_populate_single_table(struct ath_hw *ah,
799- struct ath9k_channel *chan, int chain)
800+ struct ath9k_hw_cal_data *caldata,
801+ int chain)
802 {
803- u32 *paprd_table_val = chan->pa_table[chain];
804- u32 small_signal_gain = chan->small_signal_gain[chain];
805+ u32 *paprd_table_val = caldata->pa_table[chain];
806+ u32 small_signal_gain = caldata->small_signal_gain[chain];
807     u32 training_power;
808     u32 reg = 0;
809     int i;
810@@ -654,17 +655,17 @@ int ar9003_paprd_setup_gain_table(struct
811 }
812 EXPORT_SYMBOL(ar9003_paprd_setup_gain_table);
813
814-int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan,
815- int chain)
816+int ar9003_paprd_create_curve(struct ath_hw *ah,
817+ struct ath9k_hw_cal_data *caldata, int chain)
818 {
819- u16 *small_signal_gain = &chan->small_signal_gain[chain];
820- u32 *pa_table = chan->pa_table[chain];
821+ u16 *small_signal_gain = &caldata->small_signal_gain[chain];
822+ u32 *pa_table = caldata->pa_table[chain];
823     u32 *data_L, *data_U;
824     int i, status = 0;
825     u32 *buf;
826     u32 reg;
827
828- memset(chan->pa_table[chain], 0, sizeof(chan->pa_table[chain]));
829+ memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain]));
830
831     buf = kmalloc(2 * 48 * sizeof(u32), GFP_ATOMIC);
832     if (!buf)
833--- a/drivers/net/wireless/ath/ath9k/ath9k.h
834@@ -511,7 +511,7 @@ void ath_deinit_leds(struct ath_softc *s
835 #define SC_OP_BEACONS BIT(1)
836 #define SC_OP_RXAGGR BIT(2)
837 #define SC_OP_TXAGGR BIT(3)
838-#define SC_OP_FULL_RESET BIT(4)
839+#define SC_OP_OFFCHANNEL BIT(4)
840 #define SC_OP_PREAMBLE_SHORT BIT(5)
841 #define SC_OP_PROTECT_ENABLE BIT(6)
842 #define SC_OP_RXFLUSH BIT(7)
843@@ -612,6 +612,7 @@ struct ath_softc {
844 struct ath_wiphy {
845     struct ath_softc *sc; /* shared for all virtual wiphys */
846     struct ieee80211_hw *hw;
847+ struct ath9k_hw_cal_data caldata;
848     enum ath_wiphy_state {
849         ATH_WIPHY_INACTIVE,
850         ATH_WIPHY_ACTIVE,
851--- a/drivers/net/wireless/ath/ath9k/htc.h
852@@ -353,6 +353,8 @@ struct ath9k_htc_priv {
853     u16 seq_no;
854     u32 bmiss_cnt;
855
856+ struct ath9k_hw_cal_data caldata[38];
857+
858     spinlock_t beacon_lock;
859
860     bool tx_queues_stop;
861--- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
862@@ -125,6 +125,7 @@ static int ath9k_htc_set_channel(struct
863     struct ieee80211_conf *conf = &common->hw->conf;
864     bool fastcc = true;
865     struct ieee80211_channel *channel = hw->conf.channel;
866+ struct ath9k_hw_cal_data *caldata;
867     enum htc_phymode mode;
868     __be16 htc_mode;
869     u8 cmd_rsp;
870@@ -149,7 +150,8 @@ static int ath9k_htc_set_channel(struct
871           priv->ah->curchan->channel,
872           channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
873
874- ret = ath9k_hw_reset(ah, hchan, fastcc);
875+ caldata = &priv->caldata[channel->hw_value];
876+ ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
877     if (ret) {
878         ath_print(common, ATH_DBG_FATAL,
879               "Unable to reset channel (%u Mhz) "
880@@ -1028,7 +1030,7 @@ static void ath9k_htc_radio_enable(struc
881         ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
882
883     /* Reset the HW */
884- ret = ath9k_hw_reset(ah, ah->curchan, false);
885+ ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
886     if (ret) {
887         ath_print(common, ATH_DBG_FATAL,
888               "Unable to reset hardware; reset status %d "
889@@ -1091,7 +1093,7 @@ static void ath9k_htc_radio_disable(stru
890         ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
891
892     /* Reset the HW */
893- ret = ath9k_hw_reset(ah, ah->curchan, false);
894+ ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
895     if (ret) {
896         ath_print(common, ATH_DBG_FATAL,
897               "Unable to reset hardware; reset status %d "
898@@ -1179,7 +1181,7 @@ static int ath9k_htc_start(struct ieee80
899     ath9k_hw_configpcipowersave(ah, 0, 0);
900
901     ath9k_hw_htc_resetinit(ah);
902- ret = ath9k_hw_reset(ah, init_channel, false);
903+ ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
904     if (ret) {
905         ath_print(common, ATH_DBG_FATAL,
906               "Unable to reset hardware; reset status %d "
907--- a/drivers/net/wireless/ath/ath9k/hw.h
908@@ -346,19 +346,25 @@ enum ath9k_int {
909      CHANNEL_HT40PLUS | \
910      CHANNEL_HT40MINUS)
911
912-struct ath9k_channel {
913- struct ieee80211_channel *chan;
914+struct ath9k_hw_cal_data {
915     u16 channel;
916     u32 channelFlags;
917- u32 chanmode;
918     int32_t CalValid;
919- bool oneTimeCalsDone;
920     int8_t iCoff;
921     int8_t qCoff;
922     int16_t rawNoiseFloor;
923     bool paprd_done;
924+ bool nfcal_pending;
925     u16 small_signal_gain[AR9300_MAX_CHAINS];
926     u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
927+ struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
928+};
929+
930+struct ath9k_channel {
931+ struct ieee80211_channel *chan;
932+ u16 channel;
933+ u32 channelFlags;
934+ u32 chanmode;
935 };
936
937 #define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \
938@@ -669,7 +675,7 @@ struct ath_hw {
939     enum nl80211_iftype opmode;
940     enum ath9k_power_mode power_mode;
941
942- struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
943+ struct ath9k_hw_cal_data *caldata;
944     struct ath9k_pacal_info pacal_info;
945     struct ar5416Stats stats;
946     struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES];
947@@ -863,7 +869,7 @@ const char *ath9k_hw_probe(u16 vendorid,
948 void ath9k_hw_deinit(struct ath_hw *ah);
949 int ath9k_hw_init(struct ath_hw *ah);
950 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
951- bool bChannelChange);
952+ struct ath9k_hw_cal_data *caldata, bool bChannelChange);
953 int ath9k_hw_fill_cap_info(struct ath_hw *ah);
954 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan);
955
956@@ -958,9 +964,10 @@ void ar9003_hw_bb_watchdog_read(struct a
957 void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah);
958 void ar9003_paprd_enable(struct ath_hw *ah, bool val);
959 void ar9003_paprd_populate_single_table(struct ath_hw *ah,
960- struct ath9k_channel *chan, int chain);
961-int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan,
962- int chain);
963+ struct ath9k_hw_cal_data *caldata,
964+ int chain);
965+int ar9003_paprd_create_curve(struct ath_hw *ah,
966+ struct ath9k_hw_cal_data *caldata, int chain);
967 int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain);
968 int ar9003_paprd_init_table(struct ath_hw *ah);
969 bool ar9003_paprd_is_done(struct ath_hw *ah);
970--- a/drivers/net/wireless/ath/ath9k/xmit.c
971@@ -1181,7 +1181,7 @@ void ath_drain_all_txq(struct ath_softc
972               "Failed to stop TX DMA. Resetting hardware!\n");
973
974         spin_lock_bh(&sc->sc_resetlock);
975- r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
976+ r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
977         if (r)
978             ath_print(common, ATH_DBG_FATAL,
979                   "Unable to reset hardware; reset status %d\n",
package/mac80211/patches/521-ath9k_no_offchannel_cal.patch
1+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
2@@ -511,13 +511,12 @@ void ath_deinit_leds(struct ath_softc *s
3 #define SC_OP_BEACONS BIT(1)
4 #define SC_OP_RXAGGR BIT(2)
5 #define SC_OP_TXAGGR BIT(3)
6-#define SC_OP_FULL_RESET BIT(4)
7 #define SC_OP_PREAMBLE_SHORT BIT(5)
8 #define SC_OP_PROTECT_ENABLE BIT(6)
9 #define SC_OP_RXFLUSH BIT(7)
10 #define SC_OP_LED_ASSOCIATED BIT(8)
11 #define SC_OP_LED_ON BIT(9)
12-#define SC_OP_SCANNING BIT(10)
13+#define SC_OP_OFFCHANNEL BIT(10)
14 #define SC_OP_TSF_RESET BIT(11)
15 #define SC_OP_BT_PRIORITY_DETECTED BIT(12)
16 #define SC_OP_BT_SCAN BIT(13)
17+++ b/drivers/net/wireless/ath/ath9k/main.c
18@@ -155,6 +155,27 @@ void ath9k_ps_restore(struct ath_softc *
19     spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
20 }
21
22+static void ath_start_ani(struct ath_common *common)
23+{
24+ struct ath_hw *ah = common->ah;
25+ unsigned long timestamp = jiffies_to_msecs(jiffies);
26+ struct ath_softc *sc = (struct ath_softc *) common->priv;
27+
28+ if (!(sc->sc_flags & SC_OP_ANI_RUN))
29+ return;
30+
31+ if (sc->sc_flags & SC_OP_OFFCHANNEL)
32+ return;
33+
34+ common->ani.longcal_timer = timestamp;
35+ common->ani.shortcal_timer = timestamp;
36+ common->ani.checkani_timer = timestamp;
37+
38+ mod_timer(&common->ani.timer,
39+ jiffies +
40+ msecs_to_jiffies((u32)ah->config.ani_poll_interval));
41+}
42+
43 /*
44  * Set/change channels. If the channel is really being changed, it's done
45  * by reseting the chip. To accomplish this we must first cleanup any pending
46@@ -173,6 +194,11 @@ int ath_set_channel(struct ath_softc *sc
47     if (sc->sc_flags & SC_OP_INVALID)
48         return -EIO;
49
50+ del_timer_sync(&common->ani.timer);
51+ cancel_work_sync(&sc->paprd_work);
52+ cancel_work_sync(&sc->hw_check_work);
53+ cancel_delayed_work_sync(&sc->tx_complete_work);
54+
55     ath9k_ps_wakeup(sc);
56
57     /*
58@@ -192,7 +218,7 @@ int ath_set_channel(struct ath_softc *sc
59      * to flush data frames already in queue because of
60      * changing channel. */
61
62- if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
63+ if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
64         fastcc = false;
65
66     ath_print(common, ATH_DBG_CONFIG,
67@@ -213,8 +239,6 @@ int ath_set_channel(struct ath_softc *sc
68     }
69     spin_unlock_bh(&sc->sc_resetlock);
70
71- sc->sc_flags &= ~SC_OP_FULL_RESET;
72-
73     if (ath_startrecv(sc) != 0) {
74         ath_print(common, ATH_DBG_FATAL,
75               "Unable to restart recv logic\n");
76@@ -226,6 +250,12 @@ int ath_set_channel(struct ath_softc *sc
77     ath_update_txpow(sc);
78     ath9k_hw_set_interrupts(ah, ah->imask);
79
80+ if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) {
81+ ath_start_ani(common);
82+ ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
83+ ath_beacon_config(sc, NULL);
84+ }
85+
86  ps_restore:
87     ath9k_ps_restore(sc);
88     return r;
89@@ -440,8 +470,7 @@ set_timer:
90         cal_interval = min(cal_interval, (u32)short_cal_interval);
91
92     mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
93- if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) &&
94- !(sc->sc_flags & SC_OP_SCANNING)) {
95+ if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) {
96         if (!sc->sc_ah->curchan->paprd_done)
97             ieee80211_queue_work(sc->hw, &sc->paprd_work);
98         else
99@@ -449,24 +478,6 @@ set_timer:
100     }
101 }
102
103-static void ath_start_ani(struct ath_common *common)
104-{
105- struct ath_hw *ah = common->ah;
106- unsigned long timestamp = jiffies_to_msecs(jiffies);
107- struct ath_softc *sc = (struct ath_softc *) common->priv;
108-
109- if (!(sc->sc_flags & SC_OP_ANI_RUN))
110- return;
111-
112- common->ani.longcal_timer = timestamp;
113- common->ani.shortcal_timer = timestamp;
114- common->ani.checkani_timer = timestamp;
115-
116- mod_timer(&common->ani.timer,
117- jiffies +
118- msecs_to_jiffies((u32)ah->config.ani_poll_interval));
119-}
120-
121 /*
122  * Update tx/rx chainmask. For legacy association,
123  * hard code chainmask to 1x1, for 11n association, use
124@@ -478,7 +489,7 @@ void ath_update_chainmask(struct ath_sof
125     struct ath_hw *ah = sc->sc_ah;
126     struct ath_common *common = ath9k_hw_common(ah);
127
128- if ((sc->sc_flags & SC_OP_SCANNING) || is_ht ||
129+ if ((sc->sc_flags & SC_OP_OFFCHANNEL) || is_ht ||
130         (ah->btcoex_hw.scheme != ATH_BTCOEX_CFG_NONE)) {
131         common->tx_chainmask = ah->caps.tx_chainmask;
132         common->rx_chainmask = ah->caps.rx_chainmask;
133@@ -1580,6 +1591,10 @@ static int ath9k_config(struct ieee80211
134
135         aphy->chan_idx = pos;
136         aphy->chan_is_ht = conf_is_ht(conf);
137+ if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
138+ sc->sc_flags |= SC_OP_OFFCHANNEL;
139+ else
140+ sc->sc_flags &= ~SC_OP_OFFCHANNEL;
141
142         if (aphy->state == ATH_WIPHY_SCAN ||
143             aphy->state == ATH_WIPHY_ACTIVE)
144@@ -1991,7 +2006,6 @@ static void ath9k_sw_scan_start(struct i
145 {
146     struct ath_wiphy *aphy = hw->priv;
147     struct ath_softc *sc = aphy->sc;
148- struct ath_common *common = ath9k_hw_common(sc->sc_ah);
149
150     mutex_lock(&sc->mutex);
151     if (ath9k_wiphy_scanning(sc)) {
152@@ -2007,11 +2021,6 @@ static void ath9k_sw_scan_start(struct i
153
154     aphy->state = ATH_WIPHY_SCAN;
155     ath9k_wiphy_pause_all_forced(sc, aphy);
156- sc->sc_flags |= SC_OP_SCANNING;
157- del_timer_sync(&common->ani.timer);
158- cancel_work_sync(&sc->paprd_work);
159- cancel_work_sync(&sc->hw_check_work);
160- cancel_delayed_work_sync(&sc->tx_complete_work);
161     mutex_unlock(&sc->mutex);
162 }
163
164@@ -2019,15 +2028,9 @@ static void ath9k_sw_scan_complete(struc
165 {
166     struct ath_wiphy *aphy = hw->priv;
167     struct ath_softc *sc = aphy->sc;
168- struct ath_common *common = ath9k_hw_common(sc->sc_ah);
169
170     mutex_lock(&sc->mutex);
171     aphy->state = ATH_WIPHY_ACTIVE;
172- sc->sc_flags &= ~SC_OP_SCANNING;
173- sc->sc_flags |= SC_OP_FULL_RESET;
174- ath_start_ani(common);
175- ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
176- ath_beacon_config(sc, NULL);
177     mutex_unlock(&sc->mutex);
178 }
179
180+++ b/drivers/net/wireless/ath/ath9k/recv.c
181@@ -292,7 +292,7 @@ static void ath_edma_start_recv(struct a
182
183     ath_opmode_init(sc);
184
185- ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_SCANNING));
186+ ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
187 }
188
189 static void ath_edma_stop_recv(struct ath_softc *sc)
190@@ -498,7 +498,7 @@ int ath_startrecv(struct ath_softc *sc)
191 start_recv:
192     spin_unlock_bh(&sc->rx.rxbuflock);
193     ath_opmode_init(sc);
194- ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_SCANNING));
195+ ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL));
196
197     return 0;
198 }
package/mac80211/patches/522-ath9k_cleanup_cal_data.patch
1+++ b/drivers/net/wireless/ath/ath9k/hw.h
2@@ -346,19 +346,24 @@ enum ath9k_int {
3      CHANNEL_HT40PLUS | \
4      CHANNEL_HT40MINUS)
5
6-struct ath9k_channel {
7- struct ieee80211_channel *chan;
8+struct ath9k_hw_cal_data {
9     u16 channel;
10     u32 channelFlags;
11- u32 chanmode;
12     int32_t CalValid;
13- bool oneTimeCalsDone;
14     int8_t iCoff;
15     int8_t qCoff;
16     int16_t rawNoiseFloor;
17     bool paprd_done;
18     u16 small_signal_gain[AR9300_MAX_CHAINS];
19     u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
20+ struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
21+};
22+
23+struct ath9k_channel {
24+ struct ieee80211_channel *chan;
25+ u16 channel;
26+ u32 channelFlags;
27+ u32 chanmode;
28 };
29
30 #define IS_CHAN_G(_c) ((((_c)->channelFlags & (CHANNEL_G)) == CHANNEL_G) || \
31@@ -669,7 +674,7 @@ struct ath_hw {
32     enum nl80211_iftype opmode;
33     enum ath9k_power_mode power_mode;
34
35- struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
36+ struct ath9k_hw_cal_data *caldata;
37     struct ath9k_pacal_info pacal_info;
38     struct ar5416Stats stats;
39     struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES];
40@@ -863,7 +868,7 @@ const char *ath9k_hw_probe(u16 vendorid,
41 void ath9k_hw_deinit(struct ath_hw *ah);
42 int ath9k_hw_init(struct ath_hw *ah);
43 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
44- bool bChannelChange);
45+ struct ath9k_hw_cal_data *caldata, bool bChannelChange);
46 int ath9k_hw_fill_cap_info(struct ath_hw *ah);
47 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan);
48
49@@ -958,9 +963,10 @@ void ar9003_hw_bb_watchdog_read(struct a
50 void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah);
51 void ar9003_paprd_enable(struct ath_hw *ah, bool val);
52 void ar9003_paprd_populate_single_table(struct ath_hw *ah,
53- struct ath9k_channel *chan, int chain);
54-int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan,
55- int chain);
56+ struct ath9k_hw_cal_data *caldata,
57+ int chain);
58+int ar9003_paprd_create_curve(struct ath_hw *ah,
59+ struct ath9k_hw_cal_data *caldata, int chain);
60 int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain);
61 int ar9003_paprd_init_table(struct ath_hw *ah);
62 bool ar9003_paprd_is_done(struct ath_hw *ah);
63+++ b/drivers/net/wireless/ath/ath9k/calib.c
64@@ -22,23 +22,6 @@
65 /* We can tune this as we go by monitoring really low values */
66 #define ATH9K_NF_TOO_LOW -60
67
68-/* AR5416 may return very high value (like -31 dBm), in those cases the nf
69- * is incorrect and we should use the static NF value. Later we can try to
70- * find out why they are reporting these values */
71-
72-static bool ath9k_hw_nf_in_range(struct ath_hw *ah, s16 nf)
73-{
74- if (nf > ATH9K_NF_TOO_LOW) {
75- ath_print(ath9k_hw_common(ah), ATH_DBG_CALIBRATE,
76- "noise floor value detected (%d) is "
77- "lower than what we think is a "
78- "reasonable value (%d)\n",
79- nf, ATH9K_NF_TOO_LOW);
80- return false;
81- }
82- return true;
83-}
84-
85 static int16_t ath9k_hw_get_nf_hist_mid(int16_t *nfCalBuffer)
86 {
87     int16_t nfval;
88@@ -121,6 +104,19 @@ void ath9k_hw_reset_calibration(struct a
89     ah->cal_samples = 0;
90 }
91
92+static s16 ath9k_hw_get_default_nf(struct ath_hw *ah,
93+ struct ath9k_channel *chan)
94+{
95+ struct ath_nf_limits *limit;
96+
97+ if (!chan || IS_CHAN_2GHZ(chan))
98+ limit = &ah->nf_2g;
99+ else
100+ limit = &ah->nf_5g;
101+
102+ return limit->nominal;
103+}
104+
105 /* This is done for the currently configured channel */
106 bool ath9k_hw_reset_calvalid(struct ath_hw *ah)
107 {
108@@ -128,7 +124,7 @@ bool ath9k_hw_reset_calvalid(struct ath_
109     struct ieee80211_conf *conf = &common->hw->conf;
110     struct ath9k_cal_list *currCal = ah->cal_list_curr;
111
112- if (!ah->curchan)
113+ if (!ah->caldata)
114         return true;
115
116     if (!AR_SREV_9100(ah) && !AR_SREV_9160_10_OR_LATER(ah))
117@@ -151,7 +147,7 @@ bool ath9k_hw_reset_calvalid(struct ath_
118           "Resetting Cal %d state for channel %u\n",
119           currCal->calData->calType, conf->channel->center_freq);
120
121- ah->curchan->CalValid &= ~currCal->calData->calType;
122+ ah->caldata->CalValid &= ~currCal->calData->calType;
123     currCal->calState = CAL_WAITING;
124
125     return false;
126@@ -169,19 +165,28 @@ void ath9k_hw_start_nfcal(struct ath_hw
127
128 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan)
129 {
130- struct ath9k_nfcal_hist *h;
131+ struct ath9k_nfcal_hist *h = NULL;
132     unsigned i, j;
133     int32_t val;
134     u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
135     struct ath_common *common = ath9k_hw_common(ah);
136+ s16 default_nf = ath9k_hw_get_default_nf(ah, chan);
137
138- h = ah->nfCalHist;
139+ if (ah->caldata)
140+ h = ah->caldata->nfCalHist;
141
142     for (i = 0; i < NUM_NF_READINGS; i++) {
143         if (chainmask & (1 << i)) {
144+ s16 nfval;
145+
146+ if (h)
147+ nfval = h[i].privNF;
148+ else
149+ nfval = default_nf;
150+
151             val = REG_READ(ah, ah->nf_regs[i]);
152             val &= 0xFFFFFE00;
153- val |= (((u32) (h[i].privNF) << 1) & 0x1ff);
154+ val |= (((u32) nfval << 1) & 0x1ff);
155             REG_WRITE(ah, ah->nf_regs[i], val);
156         }
157     }
158@@ -285,14 +290,18 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
159     int16_t nfarray[NUM_NF_READINGS] = { 0 };
160     struct ath9k_nfcal_hist *h;
161     struct ieee80211_channel *c = chan->chan;
162+ struct ath9k_hw_cal_data *caldata = ah->caldata;
163+
164+ if (!caldata)
165+ return ath9k_hw_get_default_nf(ah, chan);
166
167     chan->channelFlags &= (~CHANNEL_CW_INT);
168     if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
169         ath_print(common, ATH_DBG_CALIBRATE,
170               "NF did not complete in calibration window\n");
171         nf = 0;
172- chan->rawNoiseFloor = nf;
173- return chan->rawNoiseFloor;
174+ caldata->rawNoiseFloor = nf;
175+ return caldata->rawNoiseFloor;
176     } else {
177         ath9k_hw_do_getnf(ah, nfarray);
178         ath9k_hw_nf_sanitize(ah, nfarray);
179@@ -307,47 +316,41 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
180         }
181     }
182
183- h = ah->nfCalHist;
184+ h = caldata->nfCalHist;
185
186     ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
187- chan->rawNoiseFloor = h[0].privNF;
188+ caldata->rawNoiseFloor = h[0].privNF;
189
190- return chan->rawNoiseFloor;
191+ return ah->caldata->rawNoiseFloor;
192 }
193
194-void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah)
195+void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
196+ struct ath9k_channel *chan)
197 {
198- struct ath_nf_limits *limit;
199+ struct ath9k_nfcal_hist *h;
200+ s16 default_nf;
201     int i, j;
202
203- if (!ah->curchan || IS_CHAN_2GHZ(ah->curchan))
204- limit = &ah->nf_2g;
205- else
206- limit = &ah->nf_5g;
207+ if (!ah->caldata)
208+ return;
209
210+ h = ah->caldata->nfCalHist;
211+ default_nf = ath9k_hw_get_default_nf(ah, chan);
212     for (i = 0; i < NUM_NF_READINGS; i++) {
213- ah->nfCalHist[i].currIndex = 0;
214- ah->nfCalHist[i].privNF = limit->nominal;
215- ah->nfCalHist[i].invalidNFcount =
216- AR_PHY_CCA_FILTERWINDOW_LENGTH;
217+ h[i].currIndex = 0;
218+ h[i].privNF = default_nf;
219+ h[i].invalidNFcount = AR_PHY_CCA_FILTERWINDOW_LENGTH;
220         for (j = 0; j < ATH9K_NF_CAL_HIST_MAX; j++) {
221- ah->nfCalHist[i].nfCalBuffer[j] = limit->nominal;
222+ h[i].nfCalBuffer[j] = default_nf;
223         }
224     }
225 }
226
227 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan)
228 {
229- s16 nf;
230-
231- if (chan->rawNoiseFloor == 0)
232- nf = -96;
233- else
234- nf = chan->rawNoiseFloor;
235-
236- if (!ath9k_hw_nf_in_range(ah, nf))
237- nf = ATH_DEFAULT_NOISE_FLOOR;
238+ if (!ah->caldata || !ah->caldata->rawNoiseFloor)
239+ return ath9k_hw_get_default_nf(ah, chan);
240
241- return nf;
242+ return ah->caldata->rawNoiseFloor;
243 }
244 EXPORT_SYMBOL(ath9k_hw_getchan_noise);
245+++ b/drivers/net/wireless/ath/ath9k/main.c
246@@ -184,11 +184,13 @@ static void ath_start_ani(struct ath_com
247 int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
248             struct ath9k_channel *hchan)
249 {
250+ struct ath_wiphy *aphy = hw->priv;
251     struct ath_hw *ah = sc->sc_ah;
252     struct ath_common *common = ath9k_hw_common(ah);
253     struct ieee80211_conf *conf = &common->hw->conf;
254     bool fastcc = true, stopped;
255     struct ieee80211_channel *channel = hw->conf.channel;
256+ struct ath9k_hw_cal_data *caldata = NULL;
257     int r;
258
259     if (sc->sc_flags & SC_OP_INVALID)
260@@ -221,6 +223,9 @@ int ath_set_channel(struct ath_softc *sc
261     if (!stopped || !(sc->sc_flags & SC_OP_OFFCHANNEL))
262         fastcc = false;
263
264+ if (!(sc->sc_flags & SC_OP_OFFCHANNEL))
265+ caldata = &aphy->caldata;
266+
267     ath_print(common, ATH_DBG_CONFIG,
268           "(%u MHz) -> (%u MHz), conf_is_ht40: %d\n",
269           sc->sc_ah->curchan->channel,
270@@ -228,7 +233,7 @@ int ath_set_channel(struct ath_softc *sc
271
272     spin_lock_bh(&sc->sc_resetlock);
273
274- r = ath9k_hw_reset(ah, hchan, fastcc);
275+ r = ath9k_hw_reset(ah, hchan, caldata, fastcc);
276     if (r) {
277         ath_print(common, ATH_DBG_FATAL,
278               "Unable to reset channel (%u MHz), "
279@@ -264,9 +269,10 @@ int ath_set_channel(struct ath_softc *sc
280 static void ath_paprd_activate(struct ath_softc *sc)
281 {
282     struct ath_hw *ah = sc->sc_ah;
283+ struct ath9k_hw_cal_data *caldata = ah->caldata;
284     int chain;
285
286- if (!ah->curchan->paprd_done)
287+ if (!caldata || !caldata->paprd_done)
288         return;
289
290     ath9k_ps_wakeup(sc);
291@@ -274,7 +280,7 @@ static void ath_paprd_activate(struct at
292         if (!(ah->caps.tx_chainmask & BIT(chain)))
293             continue;
294
295- ar9003_paprd_populate_single_table(ah, ah->curchan, chain);
296+ ar9003_paprd_populate_single_table(ah, caldata, chain);
297     }
298
299     ar9003_paprd_enable(ah, true);
300@@ -292,6 +298,7 @@ void ath_paprd_calibrate(struct work_str
301     int band = hw->conf.channel->band;
302     struct ieee80211_supported_band *sband = &sc->sbands[band];
303     struct ath_tx_control txctl;
304+ struct ath9k_hw_cal_data *caldata = ah->caldata;
305     int qnum, ftype;
306     int chain_ok = 0;
307     int chain;
308@@ -299,6 +306,9 @@ void ath_paprd_calibrate(struct work_str
309     int time_left;
310     int i;
311
312+ if (!caldata)
313+ return;
314+
315     skb = alloc_skb(len, GFP_KERNEL);
316     if (!skb)
317         return;
318@@ -353,7 +363,7 @@ void ath_paprd_calibrate(struct work_str
319         if (!ar9003_paprd_is_done(ah))
320             break;
321
322- if (ar9003_paprd_create_curve(ah, ah->curchan, chain) != 0)
323+ if (ar9003_paprd_create_curve(ah, caldata, chain) != 0)
324             break;
325
326         chain_ok = 1;
327@@ -361,7 +371,7 @@ void ath_paprd_calibrate(struct work_str
328     kfree_skb(skb);
329
330     if (chain_ok) {
331- ah->curchan->paprd_done = true;
332+ caldata->paprd_done = true;
333         ath_paprd_activate(sc);
334     }
335
336@@ -470,8 +480,8 @@ set_timer:
337         cal_interval = min(cal_interval, (u32)short_cal_interval);
338
339     mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
340- if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) {
341- if (!sc->sc_ah->curchan->paprd_done)
342+ if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
343+ if (!ah->caldata->paprd_done)
344             ieee80211_queue_work(sc->hw, &sc->paprd_work);
345         else
346             ath_paprd_activate(sc);
347@@ -829,7 +839,7 @@ void ath_radio_enable(struct ath_softc *
348         ah->curchan = ath_get_curchannel(sc, sc->hw);
349
350     spin_lock_bh(&sc->sc_resetlock);
351- r = ath9k_hw_reset(ah, ah->curchan, false);
352+ r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
353     if (r) {
354         ath_print(common, ATH_DBG_FATAL,
355               "Unable to reset channel (%u MHz), "
356@@ -889,7 +899,7 @@ void ath_radio_disable(struct ath_softc
357         ah->curchan = ath_get_curchannel(sc, hw);
358
359     spin_lock_bh(&sc->sc_resetlock);
360- r = ath9k_hw_reset(ah, ah->curchan, false);
361+ r = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
362     if (r) {
363         ath_print(ath9k_hw_common(sc->sc_ah), ATH_DBG_FATAL,
364               "Unable to reset channel (%u MHz), "
365@@ -922,7 +932,7 @@ int ath_reset(struct ath_softc *sc, bool
366     ath_flushrecv(sc);
367
368     spin_lock_bh(&sc->sc_resetlock);
369- r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
370+ r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
371     if (r)
372         ath_print(common, ATH_DBG_FATAL,
373               "Unable to reset hardware; reset status %d\n", r);
374@@ -1097,7 +1107,7 @@ static int ath9k_start(struct ieee80211_
375      * and then setup of the interrupt mask.
376      */
377     spin_lock_bh(&sc->sc_resetlock);
378- r = ath9k_hw_reset(ah, init_channel, false);
379+ r = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
380     if (r) {
381         ath_print(common, ATH_DBG_FATAL,
382               "Unable to reset hardware; reset status %d "
383+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
384@@ -577,10 +577,11 @@ static bool create_pa_curve(u32 *data_L,
385 }
386
387 void ar9003_paprd_populate_single_table(struct ath_hw *ah,
388- struct ath9k_channel *chan, int chain)
389+ struct ath9k_hw_cal_data *caldata,
390+ int chain)
391 {
392- u32 *paprd_table_val = chan->pa_table[chain];
393- u32 small_signal_gain = chan->small_signal_gain[chain];
394+ u32 *paprd_table_val = caldata->pa_table[chain];
395+ u32 small_signal_gain = caldata->small_signal_gain[chain];
396     u32 training_power;
397     u32 reg = 0;
398     int i;
399@@ -654,17 +655,17 @@ int ar9003_paprd_setup_gain_table(struct
400 }
401 EXPORT_SYMBOL(ar9003_paprd_setup_gain_table);
402
403-int ar9003_paprd_create_curve(struct ath_hw *ah, struct ath9k_channel *chan,
404- int chain)
405+int ar9003_paprd_create_curve(struct ath_hw *ah,
406+ struct ath9k_hw_cal_data *caldata, int chain)
407 {
408- u16 *small_signal_gain = &chan->small_signal_gain[chain];
409- u32 *pa_table = chan->pa_table[chain];
410+ u16 *small_signal_gain = &caldata->small_signal_gain[chain];
411+ u32 *pa_table = caldata->pa_table[chain];
412     u32 *data_L, *data_U;
413     int i, status = 0;
414     u32 *buf;
415     u32 reg;
416
417- memset(chan->pa_table[chain], 0, sizeof(chan->pa_table[chain]));
418+ memset(caldata->pa_table[chain], 0, sizeof(caldata->pa_table[chain]));
419
420     buf = kmalloc(2 * 48 * sizeof(u32), GFP_ATOMIC);
421     if (!buf)
422+++ b/drivers/net/wireless/ath/ath9k/hw.c
423@@ -621,7 +621,6 @@ static int __ath9k_hw_init(struct ath_hw
424     else
425         ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
426
427- ath9k_init_nfcal_hist_buffer(ah);
428     ah->bb_watchdog_timeout_ms = 25;
429
430     common->state = ATH_HW_INITIALIZED;
431@@ -1194,9 +1193,6 @@ static bool ath9k_hw_channel_change(stru
432
433     ath9k_hw_spur_mitigate_freq(ah, chan);
434
435- if (!chan->oneTimeCalsDone)
436- chan->oneTimeCalsDone = true;
437-
438     return true;
439 }
440
441@@ -1229,7 +1225,7 @@ bool ath9k_hw_check_alive(struct ath_hw
442 EXPORT_SYMBOL(ath9k_hw_check_alive);
443
444 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
445- bool bChannelChange)
446+ struct ath9k_hw_cal_data *caldata, bool bChannelChange)
447 {
448     struct ath_common *common = ath9k_hw_common(ah);
449     u32 saveLedState;
450@@ -1254,9 +1250,19 @@ int ath9k_hw_reset(struct ath_hw *ah, st
451     if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
452         return -EIO;
453
454- if (curchan && !ah->chip_fullsleep)
455+ if (curchan && !ah->chip_fullsleep && ah->caldata)
456         ath9k_hw_getnf(ah, curchan);
457
458+ ah->caldata = caldata;
459+ if (caldata &&
460+ (chan->channel != caldata->channel ||
461+ (chan->channelFlags & ~CHANNEL_CW_INT) !=
462+ (caldata->channelFlags & ~CHANNEL_CW_INT))) {
463+ /* Operating channel changed, reset channel calibration data */
464+ memset(caldata, 0, sizeof(*caldata));
465+ ath9k_init_nfcal_hist_buffer(ah, chan);
466+ }
467+
468     if (bChannelChange &&
469         (ah->chip_fullsleep != true) &&
470         (ah->curchan != NULL) &&
471+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
472@@ -63,6 +63,7 @@ static bool ar9002_hw_per_calibration(st
473                       u8 rxchainmask,
474                       struct ath9k_cal_list *currCal)
475 {
476+ struct ath9k_hw_cal_data *caldata = ah->caldata;
477     bool iscaldone = false;
478
479     if (currCal->calState == CAL_RUNNING) {
480@@ -81,14 +82,14 @@ static bool ar9002_hw_per_calibration(st
481                 }
482
483                 currCal->calData->calPostProc(ah, numChains);
484- ichan->CalValid |= currCal->calData->calType;
485+ caldata->CalValid |= currCal->calData->calType;
486                 currCal->calState = CAL_DONE;
487                 iscaldone = true;
488             } else {
489                 ar9002_hw_setup_calibration(ah, currCal);
490             }
491         }
492- } else if (!(ichan->CalValid & currCal->calData->calType)) {
493+ } else if (!(caldata->CalValid & currCal->calData->calType)) {
494         ath9k_hw_reset_calibration(ah, currCal);
495     }
496
497@@ -901,7 +902,8 @@ static bool ar9002_hw_init_cal(struct at
498             ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
499     }
500
501- chan->CalValid = 0;
502+ if (ah->caldata)
503+ ah->caldata->CalValid = 0;
504
505     return true;
506 }
507+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
508@@ -68,6 +68,7 @@ static bool ar9003_hw_per_calibration(st
509                       u8 rxchainmask,
510                       struct ath9k_cal_list *currCal)
511 {
512+ struct ath9k_hw_cal_data *caldata = ah->caldata;
513     /* Cal is assumed not done until explicitly set below */
514     bool iscaldone = false;
515
516@@ -95,7 +96,7 @@ static bool ar9003_hw_per_calibration(st
517                 currCal->calData->calPostProc(ah, numChains);
518
519                 /* Calibration has finished. */
520- ichan->CalValid |= currCal->calData->calType;
521+ caldata->CalValid |= currCal->calData->calType;
522                 currCal->calState = CAL_DONE;
523                 iscaldone = true;
524             } else {
525@@ -106,7 +107,7 @@ static bool ar9003_hw_per_calibration(st
526             ar9003_hw_setup_calibration(ah, currCal);
527             }
528         }
529- } else if (!(ichan->CalValid & currCal->calData->calType)) {
530+ } else if (!(caldata->CalValid & currCal->calData->calType)) {
531         /* If current cal is marked invalid in channel, kick it off */
532         ath9k_hw_reset_calibration(ah, currCal);
533     }
534@@ -785,7 +786,8 @@ static bool ar9003_hw_init_cal(struct at
535     if (ah->cal_list_curr)
536         ath9k_hw_reset_calibration(ah, ah->cal_list_curr);
537
538- chan->CalValid = 0;
539+ if (ah->caldata)
540+ ah->caldata->CalValid = 0;
541
542     return true;
543 }
544+++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
545@@ -125,6 +125,7 @@ static int ath9k_htc_set_channel(struct
546     struct ieee80211_conf *conf = &common->hw->conf;
547     bool fastcc = true;
548     struct ieee80211_channel *channel = hw->conf.channel;
549+ struct ath9k_hw_cal_data *caldata;
550     enum htc_phymode mode;
551     __be16 htc_mode;
552     u8 cmd_rsp;
553@@ -149,7 +150,8 @@ static int ath9k_htc_set_channel(struct
554           priv->ah->curchan->channel,
555           channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
556
557- ret = ath9k_hw_reset(ah, hchan, fastcc);
558+ caldata = &priv->caldata[channel->hw_value];
559+ ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
560     if (ret) {
561         ath_print(common, ATH_DBG_FATAL,
562               "Unable to reset channel (%u Mhz) "
563@@ -1028,7 +1030,7 @@ static void ath9k_htc_radio_enable(struc
564         ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
565
566     /* Reset the HW */
567- ret = ath9k_hw_reset(ah, ah->curchan, false);
568+ ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
569     if (ret) {
570         ath_print(common, ATH_DBG_FATAL,
571               "Unable to reset hardware; reset status %d "
572@@ -1091,7 +1093,7 @@ static void ath9k_htc_radio_disable(stru
573         ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
574
575     /* Reset the HW */
576- ret = ath9k_hw_reset(ah, ah->curchan, false);
577+ ret = ath9k_hw_reset(ah, ah->curchan, ah->caldata, false);
578     if (ret) {
579         ath_print(common, ATH_DBG_FATAL,
580               "Unable to reset hardware; reset status %d "
581@@ -1179,7 +1181,7 @@ static int ath9k_htc_start(struct ieee80
582     ath9k_hw_configpcipowersave(ah, 0, 0);
583
584     ath9k_hw_htc_resetinit(ah);
585- ret = ath9k_hw_reset(ah, init_channel, false);
586+ ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
587     if (ret) {
588         ath_print(common, ATH_DBG_FATAL,
589               "Unable to reset hardware; reset status %d "
590+++ b/drivers/net/wireless/ath/ath9k/xmit.c
591@@ -1181,7 +1181,7 @@ void ath_drain_all_txq(struct ath_softc
592               "Failed to stop TX DMA. Resetting hardware!\n");
593
594         spin_lock_bh(&sc->sc_resetlock);
595- r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
596+ r = ath9k_hw_reset(ah, sc->sc_ah->curchan, ah->caldata, false);
597         if (r)
598             ath_print(common, ATH_DBG_FATAL,
599                   "Unable to reset hardware; reset status %d\n",
600+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
601@@ -611,6 +611,7 @@ struct ath_softc {
602 struct ath_wiphy {
603     struct ath_softc *sc; /* shared for all virtual wiphys */
604     struct ieee80211_hw *hw;
605+ struct ath9k_hw_cal_data caldata;
606     enum ath_wiphy_state {
607         ATH_WIPHY_INACTIVE,
608         ATH_WIPHY_ACTIVE,
609+++ b/drivers/net/wireless/ath/ath9k/calib.h
610@@ -112,7 +112,8 @@ void ath9k_hw_start_nfcal(struct ath_hw
611 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
612 int16_t ath9k_hw_getnf(struct ath_hw *ah,
613                struct ath9k_channel *chan);
614-void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah);
615+void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
616+ struct ath9k_channel *chan);
617 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);
618 void ath9k_hw_reset_calibration(struct ath_hw *ah,
619                 struct ath9k_cal_list *currCal);
620+++ b/drivers/net/wireless/ath/ath9k/htc.h
621@@ -353,6 +353,8 @@ struct ath9k_htc_priv {
622     u16 seq_no;
623     u32 bmiss_cnt;
624
625+ struct ath9k_hw_cal_data caldata[38];
626+
627     spinlock_t beacon_lock;
628
629     bool tx_queues_stop;
package/mac80211/patches/523-ath9k_nfcal_timeout_handling.patch
1+++ b/drivers/net/wireless/ath/ath9k/hw.h
2@@ -354,6 +354,7 @@ struct ath9k_hw_cal_data {
3     int8_t qCoff;
4     int16_t rawNoiseFloor;
5     bool paprd_done;
6+ bool nfcal_pending;
7     u16 small_signal_gain[AR9300_MAX_CHAINS];
8     u32 pa_table[AR9300_MAX_CHAINS][PAPRD_TABLE_SZ];
9     struct ath9k_nfcal_hist nfCalHist[NUM_NF_READINGS];
10+++ b/drivers/net/wireless/ath/ath9k/calib.c
11@@ -156,6 +156,9 @@ EXPORT_SYMBOL(ath9k_hw_reset_calvalid);
12
13 void ath9k_hw_start_nfcal(struct ath_hw *ah)
14 {
15+ if (ah->caldata)
16+ ah->caldata->nfcal_pending = true;
17+
18     REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
19             AR_PHY_AGC_CONTROL_ENABLE_NF);
20     REG_SET_BIT(ah, AR_PHY_AGC_CONTROL,
21@@ -282,8 +285,7 @@ static void ath9k_hw_nf_sanitize(struct
22     }
23 }
24
25-int16_t ath9k_hw_getnf(struct ath_hw *ah,
26- struct ath9k_channel *chan)
27+bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan)
28 {
29     struct ath_common *common = ath9k_hw_common(ah);
30     int16_t nf, nfThresh;
31@@ -293,7 +295,7 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
32     struct ath9k_hw_cal_data *caldata = ah->caldata;
33
34     if (!caldata)
35- return ath9k_hw_get_default_nf(ah, chan);
36+ return false;
37
38     chan->channelFlags &= (~CHANNEL_CW_INT);
39     if (REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) {
40@@ -301,7 +303,7 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
41               "NF did not complete in calibration window\n");
42         nf = 0;
43         caldata->rawNoiseFloor = nf;
44- return caldata->rawNoiseFloor;
45+ return false;
46     } else {
47         ath9k_hw_do_getnf(ah, nfarray);
48         ath9k_hw_nf_sanitize(ah, nfarray);
49@@ -317,11 +319,10 @@ int16_t ath9k_hw_getnf(struct ath_hw *ah
50     }
51
52     h = caldata->nfCalHist;
53-
54+ caldata->nfcal_pending = false;
55     ath9k_hw_update_nfcal_hist_buffer(h, nfarray);
56     caldata->rawNoiseFloor = h[0].privNF;
57-
58- return ah->caldata->rawNoiseFloor;
59+ return true;
60 }
61
62 void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
63+++ b/drivers/net/wireless/ath/ath9k/ar9002_calib.c
64@@ -687,8 +687,13 @@ static bool ar9002_hw_calibrate(struct a
65 {
66     bool iscaldone = true;
67     struct ath9k_cal_list *currCal = ah->cal_list_curr;
68+ bool nfcal, nfcal_pending = false;
69
70- if (currCal &&
71+ nfcal = !!(REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF);
72+ if (ah->caldata)
73+ nfcal_pending = ah->caldata->nfcal_pending;
74+
75+ if (currCal && !nfcal &&
76         (currCal->calState == CAL_RUNNING ||
77          currCal->calState == CAL_WAITING)) {
78         iscaldone = ar9002_hw_per_calibration(ah, chan,
79@@ -704,7 +709,7 @@ static bool ar9002_hw_calibrate(struct a
80     }
81
82     /* Do NF cal only at longer intervals */
83- if (longcal) {
84+ if (longcal || nfcal_pending) {
85         /* Do periodic PAOffset Cal */
86         ar9002_hw_pa_cal(ah, false);
87         ar9002_hw_olc_temp_compensation(ah);
88@@ -713,16 +718,18 @@ static bool ar9002_hw_calibrate(struct a
89          * Get the value from the previous NF cal and update
90          * history buffer.
91          */
92- ath9k_hw_getnf(ah, chan);
93-
94- /*
95- * Load the NF from history buffer of the current channel.
96- * NF is slow time-variant, so it is OK to use a historical
97- * value.
98- */
99- ath9k_hw_loadnf(ah, ah->curchan);
100+ if (ath9k_hw_getnf(ah, chan)) {
101+ /*
102+ * Load the NF from history buffer of the current
103+ * channel.
104+ * NF is slow time-variant, so it is OK to use a
105+ * historical value.
106+ */
107+ ath9k_hw_loadnf(ah, ah->curchan);
108+ }
109
110- ath9k_hw_start_nfcal(ah);
111+ if (longcal)
112+ ath9k_hw_start_nfcal(ah);
113     }
114
115     return iscaldone;
116@@ -873,6 +880,9 @@ static bool ar9002_hw_init_cal(struct at
117     REG_WRITE(ah, AR_PHY_AGC_CONTROL,
118           REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF);
119
120+ if (ah->caldata)
121+ ah->caldata->nfcal_pending = true;
122+
123     ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL;
124
125     /* Enable IQ, ADC Gain and ADC DC offset CALs */
126+++ b/drivers/net/wireless/ath/ath9k/calib.h
127@@ -110,8 +110,7 @@ struct ath9k_pacal_info{
128 bool ath9k_hw_reset_calvalid(struct ath_hw *ah);
129 void ath9k_hw_start_nfcal(struct ath_hw *ah);
130 void ath9k_hw_loadnf(struct ath_hw *ah, struct ath9k_channel *chan);
131-int16_t ath9k_hw_getnf(struct ath_hw *ah,
132- struct ath9k_channel *chan);
133+bool ath9k_hw_getnf(struct ath_hw *ah, struct ath9k_channel *chan);
134 void ath9k_init_nfcal_hist_buffer(struct ath_hw *ah,
135                   struct ath9k_channel *chan);
136 s16 ath9k_hw_getchan_noise(struct ath_hw *ah, struct ath9k_channel *chan);

Archive Download the corresponding diff file



interactive