ath9k: merge a patch for improving ad-hoc mode performance
[openwrt.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath9k/ani.c
2 +++ b/drivers/net/wireless/ath/ath9k/ani.c
3 @@ -104,11 +104,6 @@ static const struct ani_cck_level_entry 
4  #define ATH9K_ANI_CCK_DEF_LEVEL \
5         2 /* default level - matches the INI settings */
6  
7 -static bool use_new_ani(struct ath_hw *ah)
8 -{
9 -       return AR_SREV_9300_20_OR_LATER(ah) || modparam_force_new_ani;
10 -}
11 -
12  static void ath9k_hw_update_mibstats(struct ath_hw *ah,
13                                      struct ath9k_mib_stats *stats)
14  {
15 @@ -122,8 +117,6 @@ static void ath9k_hw_update_mibstats(str
16  static void ath9k_ani_restart(struct ath_hw *ah)
17  {
18         struct ar5416AniState *aniState;
19 -       struct ath_common *common = ath9k_hw_common(ah);
20 -       u32 ofdm_base = 0, cck_base = 0;
21  
22         if (!DO_ANI(ah))
23                 return;
24 @@ -131,18 +124,10 @@ static void ath9k_ani_restart(struct ath
25         aniState = &ah->curchan->ani;
26         aniState->listenTime = 0;
27  
28 -       if (!use_new_ani(ah)) {
29 -               ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high;
30 -               cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high;
31 -       }
32 -
33 -       ath_dbg(common, ANI, "Writing ofdmbase=%u   cckbase=%u\n",
34 -               ofdm_base, cck_base);
35 -
36         ENABLE_REGWRITE_BUFFER(ah);
37  
38 -       REG_WRITE(ah, AR_PHY_ERR_1, ofdm_base);
39 -       REG_WRITE(ah, AR_PHY_ERR_2, cck_base);
40 +       REG_WRITE(ah, AR_PHY_ERR_1, 0);
41 +       REG_WRITE(ah, AR_PHY_ERR_2, 0);
42         REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
43         REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
44  
45 @@ -154,110 +139,6 @@ static void ath9k_ani_restart(struct ath
46         aniState->cckPhyErrCount = 0;
47  }
48  
49 -static void ath9k_hw_ani_ofdm_err_trigger_old(struct ath_hw *ah)
50 -{
51 -       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
52 -       struct ar5416AniState *aniState;
53 -       int32_t rssi;
54 -
55 -       aniState = &ah->curchan->ani;
56 -
57 -       if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
58 -               if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
59 -                                        aniState->noiseImmunityLevel + 1)) {
60 -                       return;
61 -               }
62 -       }
63 -
64 -       if (aniState->spurImmunityLevel < HAL_SPUR_IMMUNE_MAX) {
65 -               if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
66 -                                        aniState->spurImmunityLevel + 1)) {
67 -                       return;
68 -               }
69 -       }
70 -
71 -       if (ah->opmode == NL80211_IFTYPE_AP) {
72 -               if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
73 -                       ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
74 -                                            aniState->firstepLevel + 1);
75 -               }
76 -               return;
77 -       }
78 -       rssi = BEACON_RSSI(ah);
79 -       if (rssi > aniState->rssiThrHigh) {
80 -               if (!aniState->ofdmWeakSigDetectOff) {
81 -                       if (ath9k_hw_ani_control(ah,
82 -                                        ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
83 -                                        false)) {
84 -                               ath9k_hw_ani_control(ah,
85 -                                       ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
86 -                               return;
87 -                       }
88 -               }
89 -               if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
90 -                       ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
91 -                                            aniState->firstepLevel + 1);
92 -                       return;
93 -               }
94 -       } else if (rssi > aniState->rssiThrLow) {
95 -               if (aniState->ofdmWeakSigDetectOff)
96 -                       ath9k_hw_ani_control(ah,
97 -                                    ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
98 -                                    true);
99 -               if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
100 -                       ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
101 -                                            aniState->firstepLevel + 1);
102 -               return;
103 -       } else {
104 -               if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
105 -                   !conf_is_ht(conf)) {
106 -                       if (!aniState->ofdmWeakSigDetectOff)
107 -                               ath9k_hw_ani_control(ah,
108 -                                    ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
109 -                                    false);
110 -                       if (aniState->firstepLevel > 0)
111 -                               ath9k_hw_ani_control(ah,
112 -                                            ATH9K_ANI_FIRSTEP_LEVEL, 0);
113 -                       return;
114 -               }
115 -       }
116 -}
117 -
118 -static void ath9k_hw_ani_cck_err_trigger_old(struct ath_hw *ah)
119 -{
120 -       struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
121 -       struct ar5416AniState *aniState;
122 -       int32_t rssi;
123 -
124 -       aniState = &ah->curchan->ani;
125 -       if (aniState->noiseImmunityLevel < HAL_NOISE_IMMUNE_MAX) {
126 -               if (ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
127 -                                        aniState->noiseImmunityLevel + 1)) {
128 -                       return;
129 -               }
130 -       }
131 -       if (ah->opmode == NL80211_IFTYPE_AP) {
132 -               if (aniState->firstepLevel < HAL_FIRST_STEP_MAX) {
133 -                       ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
134 -                                            aniState->firstepLevel + 1);
135 -               }
136 -               return;
137 -       }
138 -       rssi = BEACON_RSSI(ah);
139 -       if (rssi > aniState->rssiThrLow) {
140 -               if (aniState->firstepLevel < HAL_FIRST_STEP_MAX)
141 -                       ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
142 -                                            aniState->firstepLevel + 1);
143 -       } else {
144 -               if ((conf->channel->band == IEEE80211_BAND_2GHZ) &&
145 -                   !conf_is_ht(conf)) {
146 -                       if (aniState->firstepLevel > 0)
147 -                               ath9k_hw_ani_control(ah,
148 -                                            ATH9K_ANI_FIRSTEP_LEVEL, 0);
149 -               }
150 -       }
151 -}
152 -
153  /* Adjust the OFDM Noise Immunity Level */
154  static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
155  {
156 @@ -265,18 +146,15 @@ static void ath9k_hw_set_ofdm_nil(struct
157         struct ath_common *common = ath9k_hw_common(ah);
158         const struct ani_ofdm_level_entry *entry_ofdm;
159         const struct ani_cck_level_entry *entry_cck;
160 -
161 -       aniState->noiseFloor = BEACON_RSSI(ah);
162 +       bool weak_sig;
163  
164         ath_dbg(common, ANI, "**** ofdmlevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
165                 aniState->ofdmNoiseImmunityLevel,
166 -               immunityLevel, aniState->noiseFloor,
167 +               immunityLevel, BEACON_RSSI(ah),
168                 aniState->rssiThrLow, aniState->rssiThrHigh);
169  
170         if (aniState->update_ani)
171 -               aniState->ofdmNoiseImmunityLevel =
172 -                       (immunityLevel > ATH9K_ANI_OFDM_DEF_LEVEL) ?
173 -                       immunityLevel : ATH9K_ANI_OFDM_DEF_LEVEL;
174 +               aniState->ofdmNoiseImmunityLevel = immunityLevel;
175  
176         entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
177         entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
178 @@ -292,12 +170,22 @@ static void ath9k_hw_set_ofdm_nil(struct
179                                      ATH9K_ANI_FIRSTEP_LEVEL,
180                                      entry_ofdm->fir_step_level);
181  
182 -       if ((aniState->noiseFloor >= aniState->rssiThrHigh) &&
183 -           (!aniState->ofdmWeakSigDetectOff !=
184 -            entry_ofdm->ofdm_weak_signal_on)) {
185 +       weak_sig = entry_ofdm->ofdm_weak_signal_on;
186 +       if (ah->opmode == NL80211_IFTYPE_STATION &&
187 +           BEACON_RSSI(ah) <= aniState->rssiThrHigh)
188 +               weak_sig = true;
189 +
190 +       if (aniState->ofdmWeakSigDetect != weak_sig)
191                         ath9k_hw_ani_control(ah,
192                                 ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
193                                 entry_ofdm->ofdm_weak_signal_on);
194 +
195 +       if (aniState->ofdmNoiseImmunityLevel >= ATH9K_ANI_OFDM_DEF_LEVEL) {
196 +               ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
197 +               ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI;
198 +       } else {
199 +               ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI;
200 +               ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
201         }
202  }
203  
204 @@ -308,11 +196,6 @@ static void ath9k_hw_ani_ofdm_err_trigge
205         if (!DO_ANI(ah))
206                 return;
207  
208 -       if (!use_new_ani(ah)) {
209 -               ath9k_hw_ani_ofdm_err_trigger_old(ah);
210 -               return;
211 -       }
212 -
213         aniState = &ah->curchan->ani;
214  
215         if (aniState->ofdmNoiseImmunityLevel < ATH9K_ANI_OFDM_MAX_LEVEL)
216 @@ -329,22 +212,18 @@ static void ath9k_hw_set_cck_nil(struct 
217         const struct ani_ofdm_level_entry *entry_ofdm;
218         const struct ani_cck_level_entry *entry_cck;
219  
220 -       aniState->noiseFloor = BEACON_RSSI(ah);
221         ath_dbg(common, ANI, "**** ccklevel %d=>%d, rssi=%d[lo=%d hi=%d]\n",
222                 aniState->cckNoiseImmunityLevel, immunityLevel,
223 -               aniState->noiseFloor, aniState->rssiThrLow,
224 +               BEACON_RSSI(ah), aniState->rssiThrLow,
225                 aniState->rssiThrHigh);
226  
227 -       if ((ah->opmode == NL80211_IFTYPE_STATION ||
228 -            ah->opmode == NL80211_IFTYPE_ADHOC) &&
229 -           aniState->noiseFloor <= aniState->rssiThrLow &&
230 +       if (ah->opmode == NL80211_IFTYPE_STATION &&
231 +           BEACON_RSSI(ah) <= aniState->rssiThrLow &&
232             immunityLevel > ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI)
233                 immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
234  
235         if (aniState->update_ani)
236 -               aniState->cckNoiseImmunityLevel =
237 -                       (immunityLevel > ATH9K_ANI_CCK_DEF_LEVEL) ?
238 -                       immunityLevel : ATH9K_ANI_CCK_DEF_LEVEL;
239 +               aniState->cckNoiseImmunityLevel = immunityLevel;
240  
241         entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
242         entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
243 @@ -372,70 +251,12 @@ static void ath9k_hw_ani_cck_err_trigger
244         if (!DO_ANI(ah))
245                 return;
246  
247 -       if (!use_new_ani(ah)) {
248 -               ath9k_hw_ani_cck_err_trigger_old(ah);
249 -               return;
250 -       }
251 -
252         aniState = &ah->curchan->ani;
253  
254         if (aniState->cckNoiseImmunityLevel < ATH9K_ANI_CCK_MAX_LEVEL)
255                 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel + 1);
256  }
257  
258 -static void ath9k_hw_ani_lower_immunity_old(struct ath_hw *ah)
259 -{
260 -       struct ar5416AniState *aniState;
261 -       int32_t rssi;
262 -
263 -       aniState = &ah->curchan->ani;
264 -
265 -       if (ah->opmode == NL80211_IFTYPE_AP) {
266 -               if (aniState->firstepLevel > 0) {
267 -                       if (ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
268 -                                                aniState->firstepLevel - 1))
269 -                               return;
270 -               }
271 -       } else {
272 -               rssi = BEACON_RSSI(ah);
273 -               if (rssi > aniState->rssiThrHigh) {
274 -                       /* XXX: Handle me */
275 -               } else if (rssi > aniState->rssiThrLow) {
276 -                       if (aniState->ofdmWeakSigDetectOff) {
277 -                               if (ath9k_hw_ani_control(ah,
278 -                                        ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
279 -                                        true))
280 -                                       return;
281 -                       }
282 -                       if (aniState->firstepLevel > 0) {
283 -                               if (ath9k_hw_ani_control(ah,
284 -                                        ATH9K_ANI_FIRSTEP_LEVEL,
285 -                                        aniState->firstepLevel - 1))
286 -                                       return;
287 -                       }
288 -               } else {
289 -                       if (aniState->firstepLevel > 0) {
290 -                               if (ath9k_hw_ani_control(ah,
291 -                                        ATH9K_ANI_FIRSTEP_LEVEL,
292 -                                        aniState->firstepLevel - 1))
293 -                                       return;
294 -                       }
295 -               }
296 -       }
297 -
298 -       if (aniState->spurImmunityLevel > 0) {
299 -               if (ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
300 -                                        aniState->spurImmunityLevel - 1))
301 -                       return;
302 -       }
303 -
304 -       if (aniState->noiseImmunityLevel > 0) {
305 -               ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
306 -                                    aniState->noiseImmunityLevel - 1);
307 -               return;
308 -       }
309 -}
310 -
311  /*
312   * only lower either OFDM or CCK errors per turn
313   * we lower the other one next time
314 @@ -446,11 +267,6 @@ static void ath9k_hw_ani_lower_immunity(
315  
316         aniState = &ah->curchan->ani;
317  
318 -       if (!use_new_ani(ah)) {
319 -               ath9k_hw_ani_lower_immunity_old(ah);
320 -               return;
321 -       }
322 -
323         /* lower OFDM noise immunity */
324         if (aniState->ofdmNoiseImmunityLevel > 0 &&
325             (aniState->ofdmsTurn || aniState->cckNoiseImmunityLevel == 0)) {
326 @@ -463,72 +279,6 @@ static void ath9k_hw_ani_lower_immunity(
327                 ath9k_hw_set_cck_nil(ah, aniState->cckNoiseImmunityLevel - 1);
328  }
329  
330 -static void ath9k_ani_reset_old(struct ath_hw *ah, bool is_scanning)
331 -{
332 -       struct ar5416AniState *aniState;
333 -       struct ath9k_channel *chan = ah->curchan;
334 -       struct ath_common *common = ath9k_hw_common(ah);
335 -
336 -       if (!DO_ANI(ah))
337 -               return;
338 -
339 -       aniState = &ah->curchan->ani;
340 -
341 -       if (ah->opmode != NL80211_IFTYPE_STATION
342 -           && ah->opmode != NL80211_IFTYPE_ADHOC) {
343 -               ath_dbg(common, ANI, "Reset ANI state opmode %u\n", ah->opmode);
344 -               ah->stats.ast_ani_reset++;
345 -
346 -               if (ah->opmode == NL80211_IFTYPE_AP) {
347 -                       /*
348 -                        * ath9k_hw_ani_control() will only process items set on
349 -                        * ah->ani_function
350 -                        */
351 -                       if (IS_CHAN_2GHZ(chan))
352 -                               ah->ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
353 -                                                   ATH9K_ANI_FIRSTEP_LEVEL);
354 -                       else
355 -                               ah->ani_function = 0;
356 -               }
357 -
358 -               ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL, 0);
359 -               ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL, 0);
360 -               ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL, 0);
361 -               ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
362 -                                    !ATH9K_ANI_USE_OFDM_WEAK_SIG);
363 -               ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
364 -                                    ATH9K_ANI_CCK_WEAK_SIG_THR);
365 -
366 -               ath9k_ani_restart(ah);
367 -               return;
368 -       }
369 -
370 -       if (aniState->noiseImmunityLevel != 0)
371 -               ath9k_hw_ani_control(ah, ATH9K_ANI_NOISE_IMMUNITY_LEVEL,
372 -                                    aniState->noiseImmunityLevel);
373 -       if (aniState->spurImmunityLevel != 0)
374 -               ath9k_hw_ani_control(ah, ATH9K_ANI_SPUR_IMMUNITY_LEVEL,
375 -                                    aniState->spurImmunityLevel);
376 -       if (aniState->ofdmWeakSigDetectOff)
377 -               ath9k_hw_ani_control(ah, ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION,
378 -                                    !aniState->ofdmWeakSigDetectOff);
379 -       if (aniState->cckWeakSigThreshold)
380 -               ath9k_hw_ani_control(ah, ATH9K_ANI_CCK_WEAK_SIGNAL_THR,
381 -                                    aniState->cckWeakSigThreshold);
382 -       if (aniState->firstepLevel != 0)
383 -               ath9k_hw_ani_control(ah, ATH9K_ANI_FIRSTEP_LEVEL,
384 -                                    aniState->firstepLevel);
385 -
386 -       ath9k_ani_restart(ah);
387 -
388 -       ENABLE_REGWRITE_BUFFER(ah);
389 -
390 -       REG_WRITE(ah, AR_PHY_ERR_MASK_1, AR_PHY_ERR_OFDM_TIMING);
391 -       REG_WRITE(ah, AR_PHY_ERR_MASK_2, AR_PHY_ERR_CCK_TIMING);
392 -
393 -       REGWRITE_BUFFER_FLUSH(ah);
394 -}
395 -
396  /*
397   * Restore the ANI parameters in the HAL and reset the statistics.
398   * This routine should be called for every hardware reset and for
399 @@ -539,13 +289,11 @@ void ath9k_ani_reset(struct ath_hw *ah, 
400         struct ar5416AniState *aniState = &ah->curchan->ani;
401         struct ath9k_channel *chan = ah->curchan;
402         struct ath_common *common = ath9k_hw_common(ah);
403 +       int ofdm_nil, cck_nil;
404  
405         if (!DO_ANI(ah))
406                 return;
407  
408 -       if (!use_new_ani(ah))
409 -               return ath9k_ani_reset_old(ah, is_scanning);
410 -
411         BUG_ON(aniState == NULL);
412         ah->stats.ast_ani_reset++;
413  
414 @@ -563,6 +311,11 @@ void ath9k_ani_reset(struct ath_hw *ah, 
415         /* always allow mode (on/off) to be controlled */
416         ah->ani_function |= ATH9K_ANI_MODE;
417  
418 +       ofdm_nil = max_t(int, ATH9K_ANI_OFDM_DEF_LEVEL,
419 +                        aniState->ofdmNoiseImmunityLevel);
420 +       cck_nil = max_t(int, ATH9K_ANI_CCK_DEF_LEVEL,
421 +                        aniState->cckNoiseImmunityLevel);
422 +
423         if (is_scanning ||
424             (ah->opmode != NL80211_IFTYPE_STATION &&
425              ah->opmode != NL80211_IFTYPE_ADHOC)) {
426 @@ -586,8 +339,8 @@ void ath9k_ani_reset(struct ath_hw *ah, 
427                                 aniState->cckNoiseImmunityLevel);
428  
429                         aniState->update_ani = false;
430 -                       ath9k_hw_set_ofdm_nil(ah, ATH9K_ANI_OFDM_DEF_LEVEL);
431 -                       ath9k_hw_set_cck_nil(ah, ATH9K_ANI_CCK_DEF_LEVEL);
432 +                       ofdm_nil = ATH9K_ANI_OFDM_DEF_LEVEL;
433 +                       cck_nil = ATH9K_ANI_CCK_DEF_LEVEL;
434                 }
435         } else {
436                 /*
437 @@ -603,11 +356,9 @@ void ath9k_ani_reset(struct ath_hw *ah, 
438                         aniState->cckNoiseImmunityLevel);
439  
440                         aniState->update_ani = true;
441 -                       ath9k_hw_set_ofdm_nil(ah,
442 -                                             aniState->ofdmNoiseImmunityLevel);
443 -                       ath9k_hw_set_cck_nil(ah,
444 -                                            aniState->cckNoiseImmunityLevel);
445         }
446 +       ath9k_hw_set_ofdm_nil(ah, ofdm_nil);
447 +       ath9k_hw_set_cck_nil(ah, cck_nil);
448  
449         /*
450          * enable phy counters if hw supports or if not, enable phy
451 @@ -627,9 +378,6 @@ static bool ath9k_hw_ani_read_counters(s
452  {
453         struct ath_common *common = ath9k_hw_common(ah);
454         struct ar5416AniState *aniState = &ah->curchan->ani;
455 -       u32 ofdm_base = 0;
456 -       u32 cck_base = 0;
457 -       u32 ofdmPhyErrCnt, cckPhyErrCnt;
458         u32 phyCnt1, phyCnt2;
459         int32_t listenTime;
460  
461 @@ -642,11 +390,6 @@ static bool ath9k_hw_ani_read_counters(s
462                 return false;
463         }
464  
465 -       if (!use_new_ani(ah)) {
466 -               ofdm_base = AR_PHY_COUNTMAX - ah->config.ofdm_trig_high;
467 -               cck_base = AR_PHY_COUNTMAX - ah->config.cck_trig_high;
468 -       }
469 -
470         aniState->listenTime += listenTime;
471  
472         ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
473 @@ -654,35 +397,12 @@ static bool ath9k_hw_ani_read_counters(s
474         phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
475         phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
476  
477 -       if (!use_new_ani(ah) && (phyCnt1 < ofdm_base || phyCnt2 < cck_base)) {
478 -               if (phyCnt1 < ofdm_base) {
479 -                       ath_dbg(common, ANI,
480 -                               "phyCnt1 0x%x, resetting counter value to 0x%x\n",
481 -                               phyCnt1, ofdm_base);
482 -                       REG_WRITE(ah, AR_PHY_ERR_1, ofdm_base);
483 -                       REG_WRITE(ah, AR_PHY_ERR_MASK_1,
484 -                                 AR_PHY_ERR_OFDM_TIMING);
485 -               }
486 -               if (phyCnt2 < cck_base) {
487 -                       ath_dbg(common, ANI,
488 -                               "phyCnt2 0x%x, resetting counter value to 0x%x\n",
489 -                               phyCnt2, cck_base);
490 -                       REG_WRITE(ah, AR_PHY_ERR_2, cck_base);
491 -                       REG_WRITE(ah, AR_PHY_ERR_MASK_2,
492 -                                 AR_PHY_ERR_CCK_TIMING);
493 -               }
494 -               return false;
495 -       }
496 +       ah->stats.ast_ani_ofdmerrs += phyCnt1 - aniState->ofdmPhyErrCount;
497 +       aniState->ofdmPhyErrCount = phyCnt1;
498 +
499 +       ah->stats.ast_ani_cckerrs += phyCnt2 - aniState->cckPhyErrCount;
500 +       aniState->cckPhyErrCount = phyCnt2;
501  
502 -       ofdmPhyErrCnt = phyCnt1 - ofdm_base;
503 -       ah->stats.ast_ani_ofdmerrs +=
504 -               ofdmPhyErrCnt - aniState->ofdmPhyErrCount;
505 -       aniState->ofdmPhyErrCount = ofdmPhyErrCnt;
506 -
507 -       cckPhyErrCnt = phyCnt2 - cck_base;
508 -       ah->stats.ast_ani_cckerrs +=
509 -               cckPhyErrCnt - aniState->cckPhyErrCount;
510 -       aniState->cckPhyErrCount = cckPhyErrCnt;
511         return true;
512  }
513  
514 @@ -716,21 +436,10 @@ void ath9k_hw_ani_monitor(struct ath_hw 
515  
516         if (aniState->listenTime > ah->aniperiod) {
517                 if (cckPhyErrRate < ah->config.cck_trig_low &&
518 -                   ((ofdmPhyErrRate < ah->config.ofdm_trig_low &&
519 -                     aniState->ofdmNoiseImmunityLevel <
520 -                     ATH9K_ANI_OFDM_DEF_LEVEL) ||
521 -                    (ofdmPhyErrRate < ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI &&
522 -                     aniState->ofdmNoiseImmunityLevel >=
523 -                     ATH9K_ANI_OFDM_DEF_LEVEL))) {
524 +                   ofdmPhyErrRate < ah->config.ofdm_trig_low) {
525                         ath9k_hw_ani_lower_immunity(ah);
526                         aniState->ofdmsTurn = !aniState->ofdmsTurn;
527 -               } else if ((ofdmPhyErrRate > ah->config.ofdm_trig_high &&
528 -                           aniState->ofdmNoiseImmunityLevel >=
529 -                           ATH9K_ANI_OFDM_DEF_LEVEL) ||
530 -                          (ofdmPhyErrRate >
531 -                           ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI &&
532 -                           aniState->ofdmNoiseImmunityLevel <
533 -                           ATH9K_ANI_OFDM_DEF_LEVEL)) {
534 +               } else if (ofdmPhyErrRate > ah->config.ofdm_trig_high) {
535                         ath9k_hw_ani_ofdm_err_trigger(ah);
536                         aniState->ofdmsTurn = false;
537                 } else if (cckPhyErrRate > ah->config.cck_trig_high) {
538 @@ -778,49 +487,6 @@ void ath9k_hw_disable_mib_counters(struc
539  }
540  EXPORT_SYMBOL(ath9k_hw_disable_mib_counters);
541  
542 -/*
543 - * Process a MIB interrupt.  We may potentially be invoked because
544 - * any of the MIB counters overflow/trigger so don't assume we're
545 - * here because a PHY error counter triggered.
546 - */
547 -void ath9k_hw_proc_mib_event(struct ath_hw *ah)
548 -{
549 -       u32 phyCnt1, phyCnt2;
550 -
551 -       /* Reset these counters regardless */
552 -       REG_WRITE(ah, AR_FILT_OFDM, 0);
553 -       REG_WRITE(ah, AR_FILT_CCK, 0);
554 -       if (!(REG_READ(ah, AR_SLP_MIB_CTRL) & AR_SLP_MIB_PENDING))
555 -               REG_WRITE(ah, AR_SLP_MIB_CTRL, AR_SLP_MIB_CLEAR);
556 -
557 -       /* Clear the mib counters and save them in the stats */
558 -       ath9k_hw_update_mibstats(ah, &ah->ah_mibStats);
559 -
560 -       if (!DO_ANI(ah)) {
561 -               /*
562 -                * We must always clear the interrupt cause by
563 -                * resetting the phy error regs.
564 -                */
565 -               REG_WRITE(ah, AR_PHY_ERR_1, 0);
566 -               REG_WRITE(ah, AR_PHY_ERR_2, 0);
567 -               return;
568 -       }
569 -
570 -       /* NB: these are not reset-on-read */
571 -       phyCnt1 = REG_READ(ah, AR_PHY_ERR_1);
572 -       phyCnt2 = REG_READ(ah, AR_PHY_ERR_2);
573 -       if (((phyCnt1 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK) ||
574 -           ((phyCnt2 & AR_MIBCNT_INTRMASK) == AR_MIBCNT_INTRMASK)) {
575 -
576 -               if (!use_new_ani(ah))
577 -                       ath9k_hw_ani_read_counters(ah);
578 -
579 -               /* NB: always restart to insure the h/w counters are reset */
580 -               ath9k_ani_restart(ah);
581 -       }
582 -}
583 -EXPORT_SYMBOL(ath9k_hw_proc_mib_event);
584 -
585  void ath9k_hw_ani_setup(struct ath_hw *ah)
586  {
587         int i;
588 @@ -845,50 +511,31 @@ void ath9k_hw_ani_init(struct ath_hw *ah
589  
590         ath_dbg(common, ANI, "Initialize ANI\n");
591  
592 -       if (use_new_ani(ah)) {
593 -               ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_NEW;
594 -               ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_NEW;
595 +       ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH;
596 +       ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW;
597  
598 -               ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH_NEW;
599 -               ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW_NEW;
600 -       } else {
601 -               ah->config.ofdm_trig_high = ATH9K_ANI_OFDM_TRIG_HIGH_OLD;
602 -               ah->config.ofdm_trig_low = ATH9K_ANI_OFDM_TRIG_LOW_OLD;
603 -
604 -               ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH_OLD;
605 -               ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW_OLD;
606 -       }
607 +       ah->config.cck_trig_high = ATH9K_ANI_CCK_TRIG_HIGH;
608 +       ah->config.cck_trig_low = ATH9K_ANI_CCK_TRIG_LOW;
609  
610         for (i = 0; i < ARRAY_SIZE(ah->channels); i++) {
611                 struct ath9k_channel *chan = &ah->channels[i];
612                 struct ar5416AniState *ani = &chan->ani;
613  
614 -               if (use_new_ani(ah)) {
615 -                       ani->spurImmunityLevel =
616 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
617 +               ani->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
618  
619 -                       ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
620 +               ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
621  
622 -                       if (AR_SREV_9300_20_OR_LATER(ah))
623 -                               ani->mrcCCKOff =
624 -                                       !ATH9K_ANI_ENABLE_MRC_CCK;
625 -                       else
626 -                               ani->mrcCCKOff = true;
627 -
628 -                       ani->ofdmsTurn = true;
629 -               } else {
630 -                       ani->spurImmunityLevel =
631 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_OLD;
632 -                       ani->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_OLD;
633 +               if (AR_SREV_9300_20_OR_LATER(ah))
634 +                       ani->mrcCCKOff =
635 +                               !ATH9K_ANI_ENABLE_MRC_CCK;
636 +               else
637 +                       ani->mrcCCKOff = true;
638  
639 -                       ani->cckWeakSigThreshold =
640 -                               ATH9K_ANI_CCK_WEAK_SIG_THR;
641 -               }
642 +               ani->ofdmsTurn = true;
643  
644                 ani->rssiThrHigh = ATH9K_ANI_RSSI_THR_HIGH;
645                 ani->rssiThrLow = ATH9K_ANI_RSSI_THR_LOW;
646 -               ani->ofdmWeakSigDetectOff =
647 -                       !ATH9K_ANI_USE_OFDM_WEAK_SIG;
648 +               ani->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
649                 ani->cckNoiseImmunityLevel = ATH9K_ANI_CCK_DEF_LEVEL;
650                 ani->ofdmNoiseImmunityLevel = ATH9K_ANI_OFDM_DEF_LEVEL;
651                 ani->update_ani = false;
652 @@ -898,13 +545,8 @@ void ath9k_hw_ani_init(struct ath_hw *ah
653          * since we expect some ongoing maintenance on the tables, let's sanity
654          * check here default level should not modify INI setting.
655          */
656 -       if (use_new_ani(ah)) {
657 -               ah->aniperiod = ATH9K_ANI_PERIOD_NEW;
658 -               ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_NEW;
659 -       } else {
660 -               ah->aniperiod = ATH9K_ANI_PERIOD_OLD;
661 -               ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL_OLD;
662 -       }
663 +       ah->aniperiod = ATH9K_ANI_PERIOD;
664 +       ah->config.ani_poll_interval = ATH9K_ANI_POLLINTERVAL;
665  
666         if (ah->config.enable_ani)
667                 ah->proc_phyerr |= HAL_PROCESS_ANI;
668 --- a/drivers/net/wireless/ath/ath9k/ani.h
669 +++ b/drivers/net/wireless/ath/ath9k/ani.h
670 @@ -24,42 +24,34 @@
671  #define BEACON_RSSI(ahp) (ahp->stats.avgbrssi)
672  
673  /* units are errors per second */
674 -#define ATH9K_ANI_OFDM_TRIG_HIGH_OLD      500
675 -#define ATH9K_ANI_OFDM_TRIG_HIGH_NEW      3500
676 +#define ATH9K_ANI_OFDM_TRIG_HIGH          3500
677  #define ATH9K_ANI_OFDM_TRIG_HIGH_BELOW_INI 1000
678  
679  /* units are errors per second */
680 -#define ATH9K_ANI_OFDM_TRIG_LOW_OLD       200
681 -#define ATH9K_ANI_OFDM_TRIG_LOW_NEW       400
682 +#define ATH9K_ANI_OFDM_TRIG_LOW           400
683  #define ATH9K_ANI_OFDM_TRIG_LOW_ABOVE_INI 900
684  
685  /* units are errors per second */
686 -#define ATH9K_ANI_CCK_TRIG_HIGH_OLD       200
687 -#define ATH9K_ANI_CCK_TRIG_HIGH_NEW       600
688 +#define ATH9K_ANI_CCK_TRIG_HIGH           600
689  
690  /* units are errors per second */
691 -#define ATH9K_ANI_CCK_TRIG_LOW_OLD        100
692 -#define ATH9K_ANI_CCK_TRIG_LOW_NEW        300
693 +#define ATH9K_ANI_CCK_TRIG_LOW            300
694  
695  #define ATH9K_ANI_NOISE_IMMUNE_LVL        4
696  #define ATH9K_ANI_USE_OFDM_WEAK_SIG       true
697  #define ATH9K_ANI_CCK_WEAK_SIG_THR        false
698  
699 -#define ATH9K_ANI_SPUR_IMMUNE_LVL_OLD     7
700 -#define ATH9K_ANI_SPUR_IMMUNE_LVL_NEW     3
701 +#define ATH9K_ANI_SPUR_IMMUNE_LVL         3
702  
703 -#define ATH9K_ANI_FIRSTEP_LVL_OLD         0
704 -#define ATH9K_ANI_FIRSTEP_LVL_NEW         2
705 +#define ATH9K_ANI_FIRSTEP_LVL             2
706  
707  #define ATH9K_ANI_RSSI_THR_HIGH           40
708  #define ATH9K_ANI_RSSI_THR_LOW            7
709  
710 -#define ATH9K_ANI_PERIOD_OLD              100
711 -#define ATH9K_ANI_PERIOD_NEW              300
712 +#define ATH9K_ANI_PERIOD                  300
713  
714  /* in ms */
715 -#define ATH9K_ANI_POLLINTERVAL_OLD        100
716 -#define ATH9K_ANI_POLLINTERVAL_NEW        1000
717 +#define ATH9K_ANI_POLLINTERVAL            1000
718  
719  #define HAL_NOISE_IMMUNE_MAX              4
720  #define HAL_SPUR_IMMUNE_MAX               7
721 @@ -122,13 +114,12 @@ struct ar5416AniState {
722         u8 mrcCCKOff;
723         u8 spurImmunityLevel;
724         u8 firstepLevel;
725 -       u8 ofdmWeakSigDetectOff;
726 +       u8 ofdmWeakSigDetect;
727         u8 cckWeakSigThreshold;
728         bool update_ani;
729         u32 listenTime;
730         int32_t rssiThrLow;
731         int32_t rssiThrHigh;
732 -       u32 noiseFloor;
733         u32 ofdmPhyErrCount;
734         u32 cckPhyErrCount;
735         int16_t pktRssi[2];
736 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
737 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
738 @@ -995,141 +995,6 @@ static u32 ar5008_hw_compute_pll_control
739         return pll;
740  }
741  
742 -static bool ar5008_hw_ani_control_old(struct ath_hw *ah,
743 -                                     enum ath9k_ani_cmd cmd,
744 -                                     int param)
745 -{
746 -       struct ar5416AniState *aniState = &ah->curchan->ani;
747 -       struct ath_common *common = ath9k_hw_common(ah);
748 -
749 -       switch (cmd & ah->ani_function) {
750 -       case ATH9K_ANI_NOISE_IMMUNITY_LEVEL:{
751 -               u32 level = param;
752 -
753 -               if (level >= ARRAY_SIZE(ah->totalSizeDesired)) {
754 -                       ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
755 -                               level, ARRAY_SIZE(ah->totalSizeDesired));
756 -                       return false;
757 -               }
758 -
759 -               REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
760 -                             AR_PHY_DESIRED_SZ_TOT_DES,
761 -                             ah->totalSizeDesired[level]);
762 -               REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
763 -                             AR_PHY_AGC_CTL1_COARSE_LOW,
764 -                             ah->coarse_low[level]);
765 -               REG_RMW_FIELD(ah, AR_PHY_AGC_CTL1,
766 -                             AR_PHY_AGC_CTL1_COARSE_HIGH,
767 -                             ah->coarse_high[level]);
768 -               REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
769 -                             AR_PHY_FIND_SIG_FIRPWR,
770 -                             ah->firpwr[level]);
771 -
772 -               if (level > aniState->noiseImmunityLevel)
773 -                       ah->stats.ast_ani_niup++;
774 -               else if (level < aniState->noiseImmunityLevel)
775 -                       ah->stats.ast_ani_nidown++;
776 -               aniState->noiseImmunityLevel = level;
777 -               break;
778 -       }
779 -       case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
780 -               u32 on = param ? 1 : 0;
781 -
782 -               if (on)
783 -                       REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
784 -                                   AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
785 -               else
786 -                       REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
787 -                                   AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
788 -
789 -               if (!on != aniState->ofdmWeakSigDetectOff) {
790 -                       if (on)
791 -                               ah->stats.ast_ani_ofdmon++;
792 -                       else
793 -                               ah->stats.ast_ani_ofdmoff++;
794 -                       aniState->ofdmWeakSigDetectOff = !on;
795 -               }
796 -               break;
797 -       }
798 -       case ATH9K_ANI_CCK_WEAK_SIGNAL_THR:{
799 -               static const int weakSigThrCck[] = { 8, 6 };
800 -               u32 high = param ? 1 : 0;
801 -
802 -               REG_RMW_FIELD(ah, AR_PHY_CCK_DETECT,
803 -                             AR_PHY_CCK_DETECT_WEAK_SIG_THR_CCK,
804 -                             weakSigThrCck[high]);
805 -               if (high != aniState->cckWeakSigThreshold) {
806 -                       if (high)
807 -                               ah->stats.ast_ani_cckhigh++;
808 -                       else
809 -                               ah->stats.ast_ani_ccklow++;
810 -                       aniState->cckWeakSigThreshold = high;
811 -               }
812 -               break;
813 -       }
814 -       case ATH9K_ANI_FIRSTEP_LEVEL:{
815 -               static const int firstep[] = { 0, 4, 8 };
816 -               u32 level = param;
817 -
818 -               if (level >= ARRAY_SIZE(firstep)) {
819 -                       ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
820 -                               level, ARRAY_SIZE(firstep));
821 -                       return false;
822 -               }
823 -               REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
824 -                             AR_PHY_FIND_SIG_FIRSTEP,
825 -                             firstep[level]);
826 -               if (level > aniState->firstepLevel)
827 -                       ah->stats.ast_ani_stepup++;
828 -               else if (level < aniState->firstepLevel)
829 -                       ah->stats.ast_ani_stepdown++;
830 -               aniState->firstepLevel = level;
831 -               break;
832 -       }
833 -       case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
834 -               static const int cycpwrThr1[] = { 2, 4, 6, 8, 10, 12, 14, 16 };
835 -               u32 level = param;
836 -
837 -               if (level >= ARRAY_SIZE(cycpwrThr1)) {
838 -                       ath_dbg(common, ANI, "level out of range (%u > %zu)\n",
839 -                               level, ARRAY_SIZE(cycpwrThr1));
840 -                       return false;
841 -               }
842 -               REG_RMW_FIELD(ah, AR_PHY_TIMING5,
843 -                             AR_PHY_TIMING5_CYCPWR_THR1,
844 -                             cycpwrThr1[level]);
845 -               if (level > aniState->spurImmunityLevel)
846 -                       ah->stats.ast_ani_spurup++;
847 -               else if (level < aniState->spurImmunityLevel)
848 -                       ah->stats.ast_ani_spurdown++;
849 -               aniState->spurImmunityLevel = level;
850 -               break;
851 -       }
852 -       case ATH9K_ANI_PRESENT:
853 -               break;
854 -       default:
855 -               ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
856 -               return false;
857 -       }
858 -
859 -       ath_dbg(common, ANI, "ANI parameters:\n");
860 -       ath_dbg(common, ANI,
861 -               "noiseImmunityLevel=%d, spurImmunityLevel=%d, ofdmWeakSigDetectOff=%d\n",
862 -               aniState->noiseImmunityLevel,
863 -               aniState->spurImmunityLevel,
864 -               !aniState->ofdmWeakSigDetectOff);
865 -       ath_dbg(common, ANI,
866 -               "cckWeakSigThreshold=%d, firstepLevel=%d, listenTime=%d\n",
867 -               aniState->cckWeakSigThreshold,
868 -               aniState->firstepLevel,
869 -               aniState->listenTime);
870 -       ath_dbg(common, ANI, "ofdmPhyErrCount=%d, cckPhyErrCount=%d\n\n",
871 -               aniState->ofdmPhyErrCount,
872 -               aniState->cckPhyErrCount);
873 -
874 -       return true;
875 -}
876 -
877  static bool ar5008_hw_ani_control_new(struct ath_hw *ah,
878                                       enum ath9k_ani_cmd cmd,
879                                       int param)
880 @@ -1206,18 +1071,18 @@ static bool ar5008_hw_ani_control_new(st
881                         REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
882                                     AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
883  
884 -               if (!on != aniState->ofdmWeakSigDetectOff) {
885 +               if (on != aniState->ofdmWeakSigDetect) {
886                         ath_dbg(common, ANI,
887                                 "** ch %d: ofdm weak signal: %s=>%s\n",
888                                 chan->channel,
889 -                               !aniState->ofdmWeakSigDetectOff ?
890 +                               aniState->ofdmWeakSigDetect ?
891                                 "on" : "off",
892                                 on ? "on" : "off");
893                         if (on)
894                                 ah->stats.ast_ani_ofdmon++;
895                         else
896                                 ah->stats.ast_ani_ofdmoff++;
897 -                       aniState->ofdmWeakSigDetectOff = !on;
898 +                       aniState->ofdmWeakSigDetect = on;
899                 }
900                 break;
901         }
902 @@ -1236,7 +1101,7 @@ static bool ar5008_hw_ani_control_new(st
903                  * from INI file & cap value
904                  */
905                 value = firstep_table[level] -
906 -                       firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
907 +                       firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
908                         aniState->iniDef.firstep;
909                 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
910                         value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
911 @@ -1251,7 +1116,7 @@ static bool ar5008_hw_ani_control_new(st
912                  * from INI file & cap value
913                  */
914                 value2 = firstep_table[level] -
915 -                        firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
916 +                        firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
917                          aniState->iniDef.firstepLow;
918                 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
919                         value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
920 @@ -1267,7 +1132,7 @@ static bool ar5008_hw_ani_control_new(st
921                                 chan->channel,
922                                 aniState->firstepLevel,
923                                 level,
924 -                               ATH9K_ANI_FIRSTEP_LVL_NEW,
925 +                               ATH9K_ANI_FIRSTEP_LVL,
926                                 value,
927                                 aniState->iniDef.firstep);
928                         ath_dbg(common, ANI,
929 @@ -1275,7 +1140,7 @@ static bool ar5008_hw_ani_control_new(st
930                                 chan->channel,
931                                 aniState->firstepLevel,
932                                 level,
933 -                               ATH9K_ANI_FIRSTEP_LVL_NEW,
934 +                               ATH9K_ANI_FIRSTEP_LVL,
935                                 value2,
936                                 aniState->iniDef.firstepLow);
937                         if (level > aniState->firstepLevel)
938 @@ -1300,7 +1165,7 @@ static bool ar5008_hw_ani_control_new(st
939                  * from INI file & cap value
940                  */
941                 value = cycpwrThr1_table[level] -
942 -                       cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
943 +                       cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
944                         aniState->iniDef.cycpwrThr1;
945                 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
946                         value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
947 @@ -1316,7 +1181,7 @@ static bool ar5008_hw_ani_control_new(st
948                  * from INI file & cap value
949                  */
950                 value2 = cycpwrThr1_table[level] -
951 -                        cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
952 +                        cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
953                          aniState->iniDef.cycpwrThr1Ext;
954                 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
955                         value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
956 @@ -1331,7 +1196,7 @@ static bool ar5008_hw_ani_control_new(st
957                                 chan->channel,
958                                 aniState->spurImmunityLevel,
959                                 level,
960 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
961 +                               ATH9K_ANI_SPUR_IMMUNE_LVL,
962                                 value,
963                                 aniState->iniDef.cycpwrThr1);
964                         ath_dbg(common, ANI,
965 @@ -1339,7 +1204,7 @@ static bool ar5008_hw_ani_control_new(st
966                                 chan->channel,
967                                 aniState->spurImmunityLevel,
968                                 level,
969 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
970 +                               ATH9K_ANI_SPUR_IMMUNE_LVL,
971                                 value2,
972                                 aniState->iniDef.cycpwrThr1Ext);
973                         if (level > aniState->spurImmunityLevel)
974 @@ -1367,7 +1232,7 @@ static bool ar5008_hw_ani_control_new(st
975         ath_dbg(common, ANI,
976                 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
977                 aniState->spurImmunityLevel,
978 -               !aniState->ofdmWeakSigDetectOff ? "on" : "off",
979 +               aniState->ofdmWeakSigDetect ? "on" : "off",
980                 aniState->firstepLevel,
981                 !aniState->mrcCCKOff ? "on" : "off",
982                 aniState->listenTime,
983 @@ -1454,9 +1319,9 @@ static void ar5008_hw_ani_cache_ini_regs
984                                                AR_PHY_EXT_TIMING5_CYCPWR_THR1);
985  
986         /* these levels just got reset to defaults by the INI */
987 -       aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
988 -       aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
989 -       aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
990 +       aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
991 +       aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
992 +       aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
993         aniState->mrcCCKOff = true; /* not available on pre AR9003 */
994  }
995  
996 @@ -1545,11 +1410,8 @@ void ar5008_hw_attach_phy_ops(struct ath
997         priv_ops->do_getnf = ar5008_hw_do_getnf;
998         priv_ops->set_radar_params = ar5008_hw_set_radar_params;
999  
1000 -       if (modparam_force_new_ani) {
1001 -               priv_ops->ani_control = ar5008_hw_ani_control_new;
1002 -               priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
1003 -       } else
1004 -               priv_ops->ani_control = ar5008_hw_ani_control_old;
1005 +       priv_ops->ani_control = ar5008_hw_ani_control_new;
1006 +       priv_ops->ani_cache_ini_regs = ar5008_hw_ani_cache_ini_regs;
1007  
1008         if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
1009                 priv_ops->compute_pll_control = ar9160_hw_compute_pll_control;
1010 --- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
1011 +++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
1012 @@ -21,10 +21,6 @@
1013  #include "ar9002_initvals.h"
1014  #include "ar9002_phy.h"
1015  
1016 -int modparam_force_new_ani;
1017 -module_param_named(force_new_ani, modparam_force_new_ani, int, 0444);
1018 -MODULE_PARM_DESC(force_new_ani, "Force new ANI for AR5008, AR9001, AR9002");
1019 -
1020  /* General hardware code for the A5008/AR9001/AR9002 hadware families */
1021  
1022  static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
1023 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
1024 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
1025 @@ -825,18 +825,18 @@ static bool ar9003_hw_ani_control(struct
1026                         REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
1027                                     AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
1028  
1029 -               if (!on != aniState->ofdmWeakSigDetectOff) {
1030 +               if (on != aniState->ofdmWeakSigDetect) {
1031                         ath_dbg(common, ANI,
1032                                 "** ch %d: ofdm weak signal: %s=>%s\n",
1033                                 chan->channel,
1034 -                               !aniState->ofdmWeakSigDetectOff ?
1035 +                               aniState->ofdmWeakSigDetect ?
1036                                 "on" : "off",
1037                                 on ? "on" : "off");
1038                         if (on)
1039                                 ah->stats.ast_ani_ofdmon++;
1040                         else
1041                                 ah->stats.ast_ani_ofdmoff++;
1042 -                       aniState->ofdmWeakSigDetectOff = !on;
1043 +                       aniState->ofdmWeakSigDetect = on;
1044                 }
1045                 break;
1046         }
1047 @@ -855,7 +855,7 @@ static bool ar9003_hw_ani_control(struct
1048                  * from INI file & cap value
1049                  */
1050                 value = firstep_table[level] -
1051 -                       firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
1052 +                       firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
1053                         aniState->iniDef.firstep;
1054                 if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1055                         value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1056 @@ -870,7 +870,7 @@ static bool ar9003_hw_ani_control(struct
1057                  * from INI file & cap value
1058                  */
1059                 value2 = firstep_table[level] -
1060 -                        firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
1061 +                        firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
1062                          aniState->iniDef.firstepLow;
1063                 if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
1064                         value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
1065 @@ -886,7 +886,7 @@ static bool ar9003_hw_ani_control(struct
1066                                 chan->channel,
1067                                 aniState->firstepLevel,
1068                                 level,
1069 -                               ATH9K_ANI_FIRSTEP_LVL_NEW,
1070 +                               ATH9K_ANI_FIRSTEP_LVL,
1071                                 value,
1072                                 aniState->iniDef.firstep);
1073                         ath_dbg(common, ANI,
1074 @@ -894,7 +894,7 @@ static bool ar9003_hw_ani_control(struct
1075                                 chan->channel,
1076                                 aniState->firstepLevel,
1077                                 level,
1078 -                               ATH9K_ANI_FIRSTEP_LVL_NEW,
1079 +                               ATH9K_ANI_FIRSTEP_LVL,
1080                                 value2,
1081                                 aniState->iniDef.firstepLow);
1082                         if (level > aniState->firstepLevel)
1083 @@ -919,7 +919,7 @@ static bool ar9003_hw_ani_control(struct
1084                  * from INI file & cap value
1085                  */
1086                 value = cycpwrThr1_table[level] -
1087 -                       cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
1088 +                       cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
1089                         aniState->iniDef.cycpwrThr1;
1090                 if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1091                         value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1092 @@ -935,7 +935,7 @@ static bool ar9003_hw_ani_control(struct
1093                  * from INI file & cap value
1094                  */
1095                 value2 = cycpwrThr1_table[level] -
1096 -                        cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
1097 +                        cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
1098                          aniState->iniDef.cycpwrThr1Ext;
1099                 if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
1100                         value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
1101 @@ -950,7 +950,7 @@ static bool ar9003_hw_ani_control(struct
1102                                 chan->channel,
1103                                 aniState->spurImmunityLevel,
1104                                 level,
1105 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1106 +                               ATH9K_ANI_SPUR_IMMUNE_LVL,
1107                                 value,
1108                                 aniState->iniDef.cycpwrThr1);
1109                         ath_dbg(common, ANI,
1110 @@ -958,7 +958,7 @@ static bool ar9003_hw_ani_control(struct
1111                                 chan->channel,
1112                                 aniState->spurImmunityLevel,
1113                                 level,
1114 -                               ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
1115 +                               ATH9K_ANI_SPUR_IMMUNE_LVL,
1116                                 value2,
1117                                 aniState->iniDef.cycpwrThr1Ext);
1118                         if (level > aniState->spurImmunityLevel)
1119 @@ -1002,7 +1002,7 @@ static bool ar9003_hw_ani_control(struct
1120         ath_dbg(common, ANI,
1121                 "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
1122                 aniState->spurImmunityLevel,
1123 -               !aniState->ofdmWeakSigDetectOff ? "on" : "off",
1124 +               aniState->ofdmWeakSigDetect ? "on" : "off",
1125                 aniState->firstepLevel,
1126                 !aniState->mrcCCKOff ? "on" : "off",
1127                 aniState->listenTime,
1128 @@ -1111,9 +1111,9 @@ static void ar9003_hw_ani_cache_ini_regs
1129                                                AR_PHY_EXT_CYCPWR_THR1);
1130  
1131         /* these levels just got reset to defaults by the INI */
1132 -       aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
1133 -       aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
1134 -       aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
1135 +       aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
1136 +       aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
1137 +       aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
1138         aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
1139  }
1140  
1141 --- a/drivers/net/wireless/ath/ath9k/debug.c
1142 +++ b/drivers/net/wireless/ath/ath9k/debug.c
1143 @@ -348,8 +348,6 @@ void ath_debug_stat_interrupt(struct ath
1144                 sc->debug.stats.istats.txok++;
1145         if (status & ATH9K_INT_TXURN)
1146                 sc->debug.stats.istats.txurn++;
1147 -       if (status & ATH9K_INT_MIB)
1148 -               sc->debug.stats.istats.mib++;
1149         if (status & ATH9K_INT_RXPHY)
1150                 sc->debug.stats.istats.rxphyerr++;
1151         if (status & ATH9K_INT_RXKCM)
1152 --- a/drivers/net/wireless/ath/ath9k/hw.h
1153 +++ b/drivers/net/wireless/ath/ath9k/hw.h
1154 @@ -1019,16 +1019,8 @@ void ar9002_hw_attach_ops(struct ath_hw 
1155  void ar9003_hw_attach_ops(struct ath_hw *ah);
1156  
1157  void ar9002_hw_load_ani_reg(struct ath_hw *ah, struct ath9k_channel *chan);
1158 -/*
1159 - * ANI work can be shared between all families but a next
1160 - * generation implementation of ANI will be used only for AR9003 only
1161 - * for now as the other families still need to be tested with the same
1162 - * next generation ANI. Feel free to start testing it though for the
1163 - * older families (AR5008, AR9001, AR9002) by using modparam_force_new_ani.
1164 - */
1165 -extern int modparam_force_new_ani;
1166 +
1167  void ath9k_ani_reset(struct ath_hw *ah, bool is_scanning);
1168 -void ath9k_hw_proc_mib_event(struct ath_hw *ah);
1169  void ath9k_hw_ani_monitor(struct ath_hw *ah, struct ath9k_channel *chan);
1170  
1171  #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
1172 --- a/drivers/net/wireless/ath/ath9k/main.c
1173 +++ b/drivers/net/wireless/ath/ath9k/main.c
1174 @@ -19,7 +19,7 @@
1175  #include "ath9k.h"
1176  #include "btcoex.h"
1177  
1178 -static u8 parse_mpdudensity(u8 mpdudensity)
1179 +u8 ath9k_parse_mpdudensity(u8 mpdudensity)
1180  {
1181         /*
1182          * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
1183 @@ -320,6 +320,7 @@ static void ath_node_attach(struct ath_s
1184                             struct ieee80211_vif *vif)
1185  {
1186         struct ath_node *an;
1187 +       u8 density;
1188         an = (struct ath_node *)sta->drv_priv;
1189  
1190  #ifdef CONFIG_ATH9K_DEBUGFS
1191 @@ -334,7 +335,8 @@ static void ath_node_attach(struct ath_s
1192                 ath_tx_node_init(sc, an);
1193                 an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1194                                      sta->ht_cap.ampdu_factor);
1195 -               an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
1196 +               density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
1197 +               an->mpdudensity = density;
1198         }
1199  }
1200  
1201 @@ -516,24 +518,6 @@ irqreturn_t ath_isr(int irq, void *dev)
1202                 ath9k_hw_set_interrupts(ah);
1203         }
1204  
1205 -       if (status & ATH9K_INT_MIB) {
1206 -               /*
1207 -                * Disable interrupts until we service the MIB
1208 -                * interrupt; otherwise it will continue to
1209 -                * fire.
1210 -                */
1211 -               ath9k_hw_disable_interrupts(ah);
1212 -               /*
1213 -                * Let the hal handle the event. We assume
1214 -                * it will clear whatever condition caused
1215 -                * the interrupt.
1216 -                */
1217 -               spin_lock(&common->cc_lock);
1218 -               ath9k_hw_proc_mib_event(ah);
1219 -               spin_unlock(&common->cc_lock);
1220 -               ath9k_hw_enable_interrupts(ah);
1221 -       }
1222 -
1223         if (!(ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1224                 if (status & ATH9K_INT_TIM_TIMER) {
1225                         if (ATH_DBG_WARN_ON_ONCE(sc->ps_idle))
1226 @@ -959,14 +943,10 @@ static void ath9k_calculate_summary_stat
1227         /*
1228          * Enable MIB interrupts when there are hardware phy counters.
1229          */
1230 -       if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0) {
1231 -               if (ah->config.enable_ani)
1232 -                       ah->imask |= ATH9K_INT_MIB;
1233 +       if ((iter_data.nstations + iter_data.nadhocs + iter_data.nmeshes) > 0)
1234                 ah->imask |= ATH9K_INT_TSFOOR;
1235 -       } else {
1236 -               ah->imask &= ~ATH9K_INT_MIB;
1237 +       else
1238                 ah->imask &= ~ATH9K_INT_TSFOOR;
1239 -       }
1240  
1241         ath9k_hw_set_interrupts(ah);
1242  
1243 --- a/net/mac80211/agg-rx.c
1244 +++ b/net/mac80211/agg-rx.c
1245 @@ -201,6 +201,8 @@ static void ieee80211_send_addba_resp(st
1246                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1247         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1248                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
1249 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
1250 +               memcpy(mgmt->bssid, da, ETH_ALEN);
1251  
1252         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1253                                           IEEE80211_STYPE_ACTION);
1254 --- a/net/mac80211/agg-tx.c
1255 +++ b/net/mac80211/agg-tx.c
1256 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
1257         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1258         if (sdata->vif.type == NL80211_IFTYPE_AP ||
1259             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1260 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
1261 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
1262 +           sdata->vif.type == NL80211_IFTYPE_WDS)
1263                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
1264         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
1265                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1266 @@ -456,6 +457,7 @@ int ieee80211_start_tx_ba_session(struct
1267             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1268             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1269             sdata->vif.type != NL80211_IFTYPE_AP &&
1270 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
1271             sdata->vif.type != NL80211_IFTYPE_ADHOC)
1272                 return -EINVAL;
1273  
1274 --- a/net/mac80211/debugfs_sta.c
1275 +++ b/net/mac80211/debugfs_sta.c
1276 @@ -63,11 +63,11 @@ static ssize_t sta_flags_read(struct fil
1277         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
1278  
1279         int res = scnprintf(buf, sizeof(buf),
1280 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1281 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1282                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
1283                             TEST(PS_DRIVER), TEST(AUTHORIZED),
1284                             TEST(SHORT_PREAMBLE),
1285 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
1286 +                           TEST(WME), TEST(CLEAR_PS_FILT),
1287                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
1288                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
1289                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
1290 --- a/net/mac80211/iface.c
1291 +++ b/net/mac80211/iface.c
1292 @@ -284,7 +284,6 @@ static int ieee80211_do_open(struct net_
1293  {
1294         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1295         struct ieee80211_local *local = sdata->local;
1296 -       struct sta_info *sta;
1297         u32 changed = 0;
1298         int res;
1299         u32 hw_reconf_flags = 0;
1300 @@ -430,28 +429,6 @@ static int ieee80211_do_open(struct net_
1301  
1302         set_bit(SDATA_STATE_RUNNING, &sdata->state);
1303  
1304 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
1305 -               /* Create STA entry for the WDS peer */
1306 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1307 -                                    GFP_KERNEL);
1308 -               if (!sta) {
1309 -                       res = -ENOMEM;
1310 -                       goto err_del_interface;
1311 -               }
1312 -
1313 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1314 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1315 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1316 -
1317 -               res = sta_info_insert(sta);
1318 -               if (res) {
1319 -                       /* STA has been freed */
1320 -                       goto err_del_interface;
1321 -               }
1322 -
1323 -               rate_control_rate_init(sta);
1324 -       }
1325 -
1326         /*
1327          * set_multicast_list will be invoked by the networking core
1328          * which will check whether any increments here were done in
1329 @@ -639,6 +616,8 @@ static void ieee80211_do_stop(struct iee
1330                 ieee80211_configure_filter(local);
1331                 break;
1332         default:
1333 +               flush_work(&local->hw_roc_start);
1334 +               flush_work(&local->hw_roc_done);
1335                 flush_work(&sdata->work);
1336                 /*
1337                  * When we get here, the interface is marked down.
1338 @@ -845,6 +824,72 @@ static void ieee80211_if_setup(struct ne
1339         dev->destructor = free_netdev;
1340  }
1341  
1342 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1343 +                                        struct sk_buff *skb)
1344 +{
1345 +       struct ieee80211_local *local = sdata->local;
1346 +       struct ieee80211_rx_status *rx_status;
1347 +       struct ieee802_11_elems elems;
1348 +       struct ieee80211_mgmt *mgmt;
1349 +       struct sta_info *sta;
1350 +       size_t baselen;
1351 +       u32 rates = 0;
1352 +       u16 stype;
1353 +       bool new = false;
1354 +       enum ieee80211_band band = local->hw.conf.channel->band;
1355 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
1356 +
1357 +       rx_status = IEEE80211_SKB_RXCB(skb);
1358 +       mgmt = (struct ieee80211_mgmt *) skb->data;
1359 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1360 +
1361 +       if (stype != IEEE80211_STYPE_BEACON)
1362 +               return;
1363 +
1364 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1365 +       if (baselen > skb->len)
1366 +               return;
1367 +
1368 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1369 +                              skb->len - baselen, &elems);
1370 +
1371 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
1372 +
1373 +       rcu_read_lock();
1374 +
1375 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
1376 +
1377 +       if (!sta) {
1378 +               rcu_read_unlock();
1379 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1380 +                                    GFP_KERNEL);
1381 +               if (!sta)
1382 +                       return;
1383 +
1384 +               new = true;
1385 +       }
1386 +
1387 +       sta->last_rx = jiffies;
1388 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
1389 +
1390 +       if (elems.ht_cap_elem)
1391 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1392 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
1393 +
1394 +       if (elems.wmm_param)
1395 +               set_sta_flag(sta, WLAN_STA_WME);
1396 +
1397 +       if (new) {
1398 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1399 +               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1400 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1401 +               rate_control_rate_init(sta);
1402 +               sta_info_insert_rcu(sta);
1403 +       }
1404 +
1405 +       rcu_read_unlock();
1406 +}
1407 +
1408  static void ieee80211_iface_work(struct work_struct *work)
1409  {
1410         struct ieee80211_sub_if_data *sdata =
1411 @@ -949,6 +994,9 @@ static void ieee80211_iface_work(struct 
1412                                 break;
1413                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1414                         break;
1415 +               case NL80211_IFTYPE_WDS:
1416 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
1417 +                       break;
1418                 default:
1419                         WARN(1, "frame for unexpected interface type");
1420                         break;
1421 --- a/net/mac80211/rx.c
1422 +++ b/net/mac80211/rx.c
1423 @@ -2281,6 +2281,7 @@ ieee80211_rx_h_action(struct ieee80211_r
1424                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1425                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1426                     sdata->vif.type != NL80211_IFTYPE_AP &&
1427 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
1428                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
1429                         break;
1430  
1431 @@ -2495,14 +2496,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
1432  
1433         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1434             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1435 -           sdata->vif.type != NL80211_IFTYPE_STATION)
1436 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
1437 +           sdata->vif.type != NL80211_IFTYPE_WDS)
1438                 return RX_DROP_MONITOR;
1439  
1440         switch (stype) {
1441         case cpu_to_le16(IEEE80211_STYPE_AUTH):
1442         case cpu_to_le16(IEEE80211_STYPE_BEACON):
1443         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
1444 -               /* process for all: mesh, mlme, ibss */
1445 +               /* process for all: mesh, mlme, ibss, wds */
1446                 break;
1447         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
1448         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
1449 @@ -2833,10 +2835,16 @@ static int prepare_for_handlers(struct i
1450                 }
1451                 break;
1452         case NL80211_IFTYPE_WDS:
1453 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
1454 -                       return 0;
1455                 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
1456                         return 0;
1457 +
1458 +               if (ieee80211_is_data(hdr->frame_control) ||
1459 +                   ieee80211_is_action(hdr->frame_control)) {
1460 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
1461 +                               return 0;
1462 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
1463 +                       return 0;
1464 +
1465                 break;
1466         default:
1467                 /* should never get here */
1468 --- a/net/mac80211/sta_info.h
1469 +++ b/net/mac80211/sta_info.h
1470 @@ -32,7 +32,6 @@
1471   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
1472   *     frames.
1473   * @WLAN_STA_WME: Station is a QoS-STA.
1474 - * @WLAN_STA_WDS: Station is one of our WDS peers.
1475   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
1476   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
1477   *     frame to this station is transmitted.
1478 @@ -64,7 +63,6 @@ enum ieee80211_sta_info_flags {
1479         WLAN_STA_AUTHORIZED,
1480         WLAN_STA_SHORT_PREAMBLE,
1481         WLAN_STA_WME,
1482 -       WLAN_STA_WDS,
1483         WLAN_STA_CLEAR_PS_FILT,
1484         WLAN_STA_MFP,
1485         WLAN_STA_BLOCK_BA,
1486 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
1487 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
1488 @@ -214,6 +214,7 @@ struct ath_frame_info {
1489         enum ath9k_key_type keytype;
1490         u8 keyix;
1491         u8 retries;
1492 +       u8 rtscts_rate;
1493  };
1494  
1495  struct ath_buf_state {
1496 @@ -721,6 +722,7 @@ extern int ath9k_modparam_nohwcrypt;
1497  extern int led_blink;
1498  extern bool is_ath9k_unloaded;
1499  
1500 +u8 ath9k_parse_mpdudensity(u8 mpdudensity);
1501  irqreturn_t ath_isr(int irq, void *dev);
1502  int ath9k_init_device(u16 devid, struct ath_softc *sc,
1503                     const struct ath_bus_ops *bus_ops);
1504 --- a/drivers/net/wireless/ath/ath9k/xmit.c
1505 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
1506 @@ -938,6 +938,7 @@ static void ath_buf_set_rate(struct ath_
1507         struct ieee80211_tx_rate *rates;
1508         const struct ieee80211_rate *rate;
1509         struct ieee80211_hdr *hdr;
1510 +       struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
1511         int i;
1512         u8 rix = 0;
1513  
1514 @@ -948,18 +949,7 @@ static void ath_buf_set_rate(struct ath_
1515  
1516         /* set dur_update_en for l-sig computation except for PS-Poll frames */
1517         info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
1518 -
1519 -       /*
1520 -        * We check if Short Preamble is needed for the CTS rate by
1521 -        * checking the BSS's global flag.
1522 -        * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
1523 -        */
1524 -       rate = ieee80211_get_rts_cts_rate(sc->hw, tx_info);
1525 -       info->rtscts_rate = rate->hw_value;
1526 -
1527 -       if (tx_info->control.vif &&
1528 -           tx_info->control.vif->bss_conf.use_short_preamble)
1529 -               info->rtscts_rate |= rate->hw_value_short;
1530 +       info->rtscts_rate = fi->rtscts_rate;
1531  
1532         for (i = 0; i < 4; i++) {
1533                 bool is_40, is_sgi, is_sp;
1534 @@ -1001,13 +991,13 @@ static void ath_buf_set_rate(struct ath_
1535                 }
1536  
1537                 /* legacy rates */
1538 +               rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx];
1539                 if ((tx_info->band == IEEE80211_BAND_2GHZ) &&
1540                     !(rate->flags & IEEE80211_RATE_ERP_G))
1541                         phy = WLAN_RC_PHY_CCK;
1542                 else
1543                         phy = WLAN_RC_PHY_OFDM;
1544  
1545 -               rate = &sc->sbands[tx_info->band].bitrates[rates[i].idx];
1546                 info->rates[i].Rate = rate->hw_value;
1547                 if (rate->hw_value_short) {
1548                         if (rates[i].flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1549 @@ -1175,6 +1165,7 @@ int ath_tx_aggr_start(struct ath_softc *
1550  {
1551         struct ath_atx_tid *txtid;
1552         struct ath_node *an;
1553 +       u8 density;
1554  
1555         an = (struct ath_node *)sta->drv_priv;
1556         txtid = ATH_AN_2_TID(an, tid);
1557 @@ -1182,6 +1173,17 @@ int ath_tx_aggr_start(struct ath_softc *
1558         if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE))
1559                 return -EAGAIN;
1560  
1561 +       /* update ampdu factor/density, they may have changed. This may happen
1562 +        * in HT IBSS when a beacon with HT-info is received after the station
1563 +        * has already been added.
1564 +        */
1565 +       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
1566 +               an->maxampdu = 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1567 +                                    sta->ht_cap.ampdu_factor);
1568 +               density = ath9k_parse_mpdudensity(sta->ht_cap.ampdu_density);
1569 +               an->mpdudensity = density;
1570 +       }
1571 +
1572         txtid->state |= AGGR_ADDBA_PROGRESS;
1573         txtid->paused = true;
1574         *ssn = txtid->seq_start = txtid->seq_next;
1575 @@ -1776,10 +1778,22 @@ static void setup_frame_info(struct ieee
1576         struct ieee80211_sta *sta = tx_info->control.sta;
1577         struct ieee80211_key_conf *hw_key = tx_info->control.hw_key;
1578         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1579 +       const struct ieee80211_rate *rate;
1580         struct ath_frame_info *fi = get_frame_info(skb);
1581         struct ath_node *an = NULL;
1582         enum ath9k_key_type keytype;
1583 +       bool short_preamble = false;
1584 +
1585 +       /*
1586 +        * We check if Short Preamble is needed for the CTS rate by
1587 +        * checking the BSS's global flag.
1588 +        * But for the rate series, IEEE80211_TX_RC_USE_SHORT_PREAMBLE is used.
1589 +        */
1590 +       if (tx_info->control.vif &&
1591 +           tx_info->control.vif->bss_conf.use_short_preamble)
1592 +               short_preamble = true;
1593  
1594 +       rate = ieee80211_get_rts_cts_rate(hw, tx_info);
1595         keytype = ath9k_cmn_get_hw_crypto_keytype(skb);
1596  
1597         if (sta)
1598 @@ -1794,6 +1808,9 @@ static void setup_frame_info(struct ieee
1599                 fi->keyix = ATH9K_TXKEYIX_INVALID;
1600         fi->keytype = keytype;
1601         fi->framelen = framelen;
1602 +       fi->rtscts_rate = rate->hw_value;
1603 +       if (short_preamble)
1604 +               fi->rtscts_rate |= rate->hw_value_short;
1605  }
1606  
1607  u8 ath_txchainmask_reduction(struct ath_softc *sc, u8 chainmask, u32 rate)
1608 --- a/net/wireless/nl80211.c
1609 +++ b/net/wireless/nl80211.c
1610 @@ -2246,6 +2246,33 @@ static int nl80211_parse_beacon(struct g
1611         return 0;
1612  }
1613  
1614 +static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
1615 +                                  struct cfg80211_ap_settings *params)
1616 +{
1617 +       struct wireless_dev *wdev;
1618 +       bool ret = false;
1619 +
1620 +       mutex_lock(&rdev->devlist_mtx);
1621 +
1622 +       list_for_each_entry(wdev, &rdev->netdev_list, list) {
1623 +               if (wdev->iftype != NL80211_IFTYPE_AP &&
1624 +                   wdev->iftype != NL80211_IFTYPE_P2P_GO)
1625 +                       continue;
1626 +
1627 +               if (!wdev->preset_chan)
1628 +                       continue;
1629 +
1630 +               params->channel = wdev->preset_chan;
1631 +               params->channel_type = wdev->preset_chantype;
1632 +               ret = true;
1633 +               break;
1634 +       }
1635 +
1636 +       mutex_unlock(&rdev->devlist_mtx);
1637 +
1638 +       return ret;
1639 +}
1640 +
1641  static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
1642  {
1643         struct cfg80211_registered_device *rdev = info->user_ptr[0];
1644 @@ -2348,7 +2375,7 @@ static int nl80211_start_ap(struct sk_bu
1645         } else if (wdev->preset_chan) {
1646                 params.channel = wdev->preset_chan;
1647                 params.channel_type = wdev->preset_chantype;
1648 -       } else
1649 +       } else if (!nl80211_get_ap_channel(rdev, &params))
1650                 return -EINVAL;
1651  
1652         if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
1653 @@ -2356,8 +2383,11 @@ static int nl80211_start_ap(struct sk_bu
1654                 return -EINVAL;
1655  
1656         err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
1657 -       if (!err)
1658 +       if (!err) {
1659 +               wdev->preset_chan = params.channel;
1660 +               wdev->preset_chantype = params.channel_type;
1661                 wdev->beacon_interval = params.beacon_interval;
1662 +       }
1663         return err;
1664  }
1665  
1666 --- a/drivers/net/wireless/ath/ath9k/link.c
1667 +++ b/drivers/net/wireless/ath/ath9k/link.c
1668 @@ -407,6 +407,7 @@ void ath_ani_calibrate(unsigned long dat
1669                 longcal ? "long" : "", shortcal ? "short" : "",
1670                 aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
1671  
1672 +       ath9k_debug_samp_bb_mac(sc);
1673         ath9k_ps_restore(sc);
1674  
1675  set_timer:
1676 @@ -415,7 +416,6 @@ set_timer:
1677         * The interval must be the shortest necessary to satisfy ANI,
1678         * short calibration and long calibration.
1679         */
1680 -       ath9k_debug_samp_bb_mac(sc);
1681         cal_interval = ATH_LONG_CALINTERVAL;
1682         if (sc->sc_ah->config.enable_ani)
1683                 cal_interval = min(cal_interval,