ath9k/ath5k: fix driver load issues with mesh support compiled out
[librecmc/librecmc.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath5k/base.c
2 +++ b/drivers/net/wireless/ath/ath5k/base.c
3 @@ -1171,7 +1171,7 @@ ath5k_check_ibss_tsf(struct ath5k_hw *ah
4  
5         if (ieee80211_is_beacon(mgmt->frame_control) &&
6             le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS &&
7 -           memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) == 0) {
8 +           compare_ether_addr(mgmt->bssid, common->curbssid) == 0) {
9                 /*
10                  * Received an IBSS beacon with the same BSSID. Hardware *must*
11                  * have updated the local TSF. We have to work around various
12 @@ -1235,7 +1235,7 @@ ath5k_update_beacon_rssi(struct ath5k_hw
13  
14         /* only beacons from our BSSID */
15         if (!ieee80211_is_beacon(mgmt->frame_control) ||
16 -           memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) != 0)
17 +           compare_ether_addr(mgmt->bssid, common->curbssid) != 0)
18                 return;
19  
20         ewma_add(&ah->ah_beacon_rssi_avg, rssi);
21 @@ -2416,6 +2416,22 @@ ath5k_tx_complete_poll_work(struct work_
22  * Initialization routines *
23  \*************************/
24  
25 +static const struct ieee80211_iface_limit if_limits[] = {
26 +       { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) },
27 +       { .max = 4,     .types =
28 +#ifdef CONFIG_MAC80211_MESH
29 +                                BIT(NL80211_IFTYPE_MESH_POINT) |
30 +#endif
31 +                                BIT(NL80211_IFTYPE_AP) },
32 +};
33 +
34 +static const struct ieee80211_iface_combination if_comb = {
35 +       .limits = if_limits,
36 +       .n_limits = ARRAY_SIZE(if_limits),
37 +       .max_interfaces = 2048,
38 +       .num_different_channels = 1,
39 +};
40 +
41  int __devinit
42  ath5k_init_ah(struct ath5k_hw *ah, const struct ath_bus_ops *bus_ops)
43  {
44 @@ -2437,6 +2453,9 @@ ath5k_init_ah(struct ath5k_hw *ah, const
45                 BIT(NL80211_IFTYPE_ADHOC) |
46                 BIT(NL80211_IFTYPE_MESH_POINT);
47  
48 +       hw->wiphy->iface_combinations = &if_comb;
49 +       hw->wiphy->n_iface_combinations = 1;
50 +
51         /* SW support for IBSS_RSN is provided by mac80211 */
52         hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
53  
54 --- a/drivers/net/wireless/ath/ath9k/ani.c
55 +++ b/drivers/net/wireless/ath/ath9k/ani.c
56 @@ -274,7 +274,9 @@ static void ath9k_hw_set_ofdm_nil(struct
57                 aniState->rssiThrLow, aniState->rssiThrHigh);
58  
59         if (aniState->update_ani)
60 -               aniState->ofdmNoiseImmunityLevel = immunityLevel;
61 +               aniState->ofdmNoiseImmunityLevel =
62 +                       (immunityLevel > ATH9K_ANI_OFDM_DEF_LEVEL) ?
63 +                       immunityLevel : ATH9K_ANI_OFDM_DEF_LEVEL;
64  
65         entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
66         entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
67 @@ -340,7 +342,9 @@ static void ath9k_hw_set_cck_nil(struct 
68                 immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
69  
70         if (aniState->update_ani)
71 -               aniState->cckNoiseImmunityLevel = immunityLevel;
72 +               aniState->cckNoiseImmunityLevel =
73 +                       (immunityLevel > ATH9K_ANI_CCK_DEF_LEVEL) ?
74 +                       immunityLevel : ATH9K_ANI_CCK_DEF_LEVEL;
75  
76         entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
77         entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
78 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
79 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
80 @@ -618,19 +618,10 @@ static void ar5008_hw_init_bb(struct ath
81         u32 synthDelay;
82  
83         synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
84 -       if (IS_CHAN_B(chan))
85 -               synthDelay = (4 * synthDelay) / 22;
86 -       else
87 -               synthDelay /= 10;
88 -
89 -       if (IS_CHAN_HALF_RATE(chan))
90 -               synthDelay *= 2;
91 -       else if (IS_CHAN_QUARTER_RATE(chan))
92 -               synthDelay *= 4;
93  
94         REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
95  
96 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
97 +       ath9k_hw_synth_delay(ah, chan, synthDelay);
98  }
99  
100  static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
101 @@ -868,7 +859,7 @@ static int ar5008_hw_process_ini(struct 
102         ar5008_hw_set_channel_regs(ah, chan);
103         ar5008_hw_init_chain_masks(ah);
104         ath9k_olc_init(ah);
105 -       ath9k_hw_apply_txpower(ah, chan);
106 +       ath9k_hw_apply_txpower(ah, chan, false);
107  
108         /* Write analog registers */
109         if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
110 @@ -948,12 +939,8 @@ static bool ar5008_hw_rfbus_req(struct a
111  static void ar5008_hw_rfbus_done(struct ath_hw *ah)
112  {
113         u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
114 -       if (IS_CHAN_B(ah->curchan))
115 -               synthDelay = (4 * synthDelay) / 22;
116 -       else
117 -               synthDelay /= 10;
118  
119 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
120 +       ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
121  
122         REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
123  }
124 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
125 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
126 @@ -1000,10 +1000,12 @@ static bool ar9003_hw_init_cal(struct at
127         if (mci && IS_CHAN_2GHZ(chan) && run_agc_cal)
128                 ar9003_mci_init_cal_req(ah, &is_reusable);
129  
130 -       txiqcal_done = ar9003_hw_tx_iq_cal_run(ah);
131 -       REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
132 -       udelay(5);
133 -       REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
134 +       if (!(IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))) {
135 +               txiqcal_done = ar9003_hw_tx_iq_cal_run(ah);
136 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
137 +               udelay(5);
138 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
139 +       }
140  
141  skip_tx_iqcal:
142         if (run_agc_cal || !(ah->ah_flags & AH_FASTCC)) {
143 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
144 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
145 @@ -54,7 +54,7 @@ void ar9003_paprd_enable(struct ath_hw *
146  
147         if (val) {
148                 ah->paprd_table_write_done = true;
149 -               ath9k_hw_apply_txpower(ah, chan);
150 +               ath9k_hw_apply_txpower(ah, chan, false);
151         }
152  
153         REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0,
154 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
155 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
156 @@ -524,22 +524,10 @@ static void ar9003_hw_init_bb(struct ath
157          * Value is in 100ns increments.
158          */
159         synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
160 -       if (IS_CHAN_B(chan))
161 -               synthDelay = (4 * synthDelay) / 22;
162 -       else
163 -               synthDelay /= 10;
164  
165         /* Activate the PHY (includes baseband activate + synthesizer on) */
166         REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
167 -
168 -       /*
169 -        * There is an issue if the AP starts the calibration before
170 -        * the base band timeout completes.  This could result in the
171 -        * rx_clear false triggering.  As a workaround we add delay an
172 -        * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
173 -        * does not happen.
174 -        */
175 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
176 +       ath9k_hw_synth_delay(ah, chan, synthDelay);
177  }
178  
179  static void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
180 @@ -690,7 +678,7 @@ static int ar9003_hw_process_ini(struct 
181         ar9003_hw_override_ini(ah);
182         ar9003_hw_set_channel_regs(ah, chan);
183         ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
184 -       ath9k_hw_apply_txpower(ah, chan);
185 +       ath9k_hw_apply_txpower(ah, chan, false);
186  
187         if (AR_SREV_9462(ah)) {
188                 if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
189 @@ -721,6 +709,14 @@ static void ar9003_hw_set_rfmode(struct 
190  
191         if (IS_CHAN_A_FAST_CLOCK(ah, chan))
192                 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
193 +       if (IS_CHAN_QUARTER_RATE(chan))
194 +               rfMode |= AR_PHY_MODE_QUARTER;
195 +       if (IS_CHAN_HALF_RATE(chan))
196 +               rfMode |= AR_PHY_MODE_HALF;
197 +
198 +       if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
199 +               REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
200 +                             AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
201  
202         REG_WRITE(ah, AR_PHY_MODE, rfMode);
203  }
204 @@ -791,12 +787,8 @@ static bool ar9003_hw_rfbus_req(struct a
205  static void ar9003_hw_rfbus_done(struct ath_hw *ah)
206  {
207         u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
208 -       if (IS_CHAN_B(ah->curchan))
209 -               synthDelay = (4 * synthDelay) / 22;
210 -       else
211 -               synthDelay /= 10;
212  
213 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
214 +       ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
215  
216         REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
217  }
218 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
219 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
220 @@ -468,6 +468,9 @@
221  #define AR_PHY_ADDAC_PARA_CTL    (AR_SM_BASE + 0x150)
222  #define AR_PHY_XPA_CFG           (AR_SM_BASE + 0x158)
223  
224 +#define AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW  3
225 +#define AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW_S    0
226 +
227  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A           0x0001FC00
228  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A_S         10
229  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A                       0x3FF
230 --- a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
231 +++ b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
232 @@ -1115,9 +1115,9 @@ static const u32 ar9462_2p0_mac_core[][2
233         {0x000081f8, 0x00000000},
234         {0x000081fc, 0x00000000},
235         {0x00008240, 0x00100000},
236 -       {0x00008244, 0x0010f400},
237 +       {0x00008244, 0x0010f424},
238         {0x00008248, 0x00000800},
239 -       {0x0000824c, 0x0001e800},
240 +       {0x0000824c, 0x0001e848},
241         {0x00008250, 0x00000000},
242         {0x00008254, 0x00000000},
243         {0x00008258, 0x00000000},
244 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
245 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
246 @@ -370,7 +370,7 @@ struct ath_vif {
247   * number of beacon intervals, the game's up.
248   */
249  #define BSTUCK_THRESH                  9
250 -#define        ATH_BCBUF                       4
251 +#define        ATH_BCBUF                       8
252  #define ATH_DEFAULT_BINTVAL            100 /* TU */
253  #define ATH_DEFAULT_BMISS_LIMIT        10
254  #define IEEE80211_MS_TO_TU(x)           (((x) * 1000) / 1024)
255 --- a/drivers/net/wireless/ath/ath9k/beacon.c
256 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
257 @@ -91,7 +91,7 @@ static void ath_beacon_setup(struct ath_
258         info.txpower = MAX_RATE_POWER;
259         info.keyix = ATH9K_TXKEYIX_INVALID;
260         info.keytype = ATH9K_KEY_TYPE_CLEAR;
261 -       info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_INTREQ;
262 +       info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_CLRDMASK;
263  
264         info.buf_addr[0] = bf->bf_buf_addr;
265         info.buf_len[0] = roundup(skb->len, 4);
266 @@ -359,6 +359,11 @@ void ath_beacon_tasklet(unsigned long da
267         int slot;
268         u32 bfaddr, bc = 0;
269  
270 +       if (work_pending(&sc->hw_reset_work)) {
271 +               ath_dbg(common, RESET,
272 +                       "reset work is pending, skip beaconing now\n");
273 +               return;
274 +       }
275         /*
276          * Check if the previous beacon has gone out.  If
277          * not don't try to post another, skip this period
278 @@ -369,6 +374,9 @@ void ath_beacon_tasklet(unsigned long da
279         if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
280                 sc->beacon.bmisscnt++;
281  
282 +               if (!ath9k_hw_check_alive(ah))
283 +                       ieee80211_queue_work(sc->hw, &sc->hw_check_work);
284 +
285                 if (sc->beacon.bmisscnt < BSTUCK_THRESH * sc->nbcnvifs) {
286                         ath_dbg(common, BSTUCK,
287                                 "missed %u consecutive beacons\n",
288 @@ -378,6 +386,7 @@ void ath_beacon_tasklet(unsigned long da
289                                 ath9k_hw_bstuck_nfcal(ah);
290                 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
291                         ath_dbg(common, BSTUCK, "beacon is officially stuck\n");
292 +                       sc->beacon.bmisscnt = 0;
293                         sc->sc_flags |= SC_OP_TSF_RESET;
294                         ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
295                 }
296 @@ -650,6 +659,8 @@ static void ath_beacon_config_adhoc(stru
297         u32 tsf, intval, nexttbtt;
298  
299         ath9k_reset_beacon_status(sc);
300 +       if (!(sc->sc_flags & SC_OP_BEACONS))
301 +               ath9k_hw_settsf64(ah, sc->beacon.bc_tstamp);
302  
303         intval = TU_TO_USEC(conf->beacon_interval);
304         tsf = roundup(ath9k_hw_gettsf32(ah) + TU_TO_USEC(FUDGE), intval);
305 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
306 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
307 @@ -824,6 +824,8 @@ static void ath9k_hw_ar9287_set_txpower(
308                         regulatory->max_power_level = ratesArray[i];
309         }
310  
311 +       ath9k_hw_update_regulatory_maxpower(ah);
312 +
313         if (test)
314                 return;
315  
316 --- a/drivers/net/wireless/ath/ath9k/gpio.c
317 +++ b/drivers/net/wireless/ath/ath9k/gpio.c
318 @@ -41,6 +41,9 @@ void ath_init_leds(struct ath_softc *sc)
319  {
320         int ret;
321  
322 +       if (AR_SREV_9100(sc->sc_ah))
323 +               return;
324 +
325         if (sc->sc_ah->led_pin < 0) {
326                 if (AR_SREV_9287(sc->sc_ah))
327                         sc->sc_ah->led_pin = ATH_LED_PIN_9287;
328 --- a/drivers/net/wireless/ath/ath9k/hw.c
329 +++ b/drivers/net/wireless/ath/ath9k/hw.c
330 @@ -142,6 +142,22 @@ bool ath9k_hw_wait(struct ath_hw *ah, u3
331  }
332  EXPORT_SYMBOL(ath9k_hw_wait);
333  
334 +void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
335 +                         int hw_delay)
336 +{
337 +       if (IS_CHAN_B(chan))
338 +               hw_delay = (4 * hw_delay) / 22;
339 +       else
340 +               hw_delay /= 10;
341 +
342 +       if (IS_CHAN_HALF_RATE(chan))
343 +               hw_delay *= 2;
344 +       else if (IS_CHAN_QUARTER_RATE(chan))
345 +               hw_delay *= 4;
346 +
347 +       udelay(hw_delay + BASE_ACTIVATE_DELAY);
348 +}
349 +
350  void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
351                           int column, unsigned int *writecnt)
352  {
353 @@ -388,8 +404,8 @@ static void ath9k_hw_init_config(struct 
354  {
355         int i;
356  
357 -       ah->config.dma_beacon_response_time = 2;
358 -       ah->config.sw_beacon_response_time = 10;
359 +       ah->config.dma_beacon_response_time = 1;
360 +       ah->config.sw_beacon_response_time = 6;
361         ah->config.additional_swba_backoff = 0;
362         ah->config.ack_6mb = 0x0;
363         ah->config.cwm_ignore_extcca = 0;
364 @@ -971,7 +987,7 @@ void ath9k_hw_init_global_settings(struc
365         struct ath_common *common = ath9k_hw_common(ah);
366         struct ieee80211_conf *conf = &common->hw->conf;
367         const struct ath9k_channel *chan = ah->curchan;
368 -       int acktimeout, ctstimeout;
369 +       int acktimeout, ctstimeout, ack_offset = 0;
370         int slottime;
371         int sifstime;
372         int rx_lat = 0, tx_lat = 0, eifs = 0;
373 @@ -992,6 +1008,11 @@ void ath9k_hw_init_global_settings(struc
374                 rx_lat = 37;
375         tx_lat = 54;
376  
377 +       if (IS_CHAN_5GHZ(chan))
378 +               sifstime = 16;
379 +       else
380 +               sifstime = 10;
381 +
382         if (IS_CHAN_HALF_RATE(chan)) {
383                 eifs = 175;
384                 rx_lat *= 2;
385 @@ -999,8 +1020,9 @@ void ath9k_hw_init_global_settings(struc
386                 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
387                     tx_lat += 11;
388  
389 +               sifstime *= 2;
390 +               ack_offset = 16;
391                 slottime = 13;
392 -               sifstime = 32;
393         } else if (IS_CHAN_QUARTER_RATE(chan)) {
394                 eifs = 340;
395                 rx_lat = (rx_lat * 4) - 1;
396 @@ -1008,8 +1030,9 @@ void ath9k_hw_init_global_settings(struc
397                 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
398                     tx_lat += 22;
399  
400 +               sifstime *= 4;
401 +               ack_offset = 32;
402                 slottime = 21;
403 -               sifstime = 64;
404         } else {
405                 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
406                         eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
407 @@ -1023,14 +1046,10 @@ void ath9k_hw_init_global_settings(struc
408                 tx_lat = MS(reg, AR_USEC_TX_LAT);
409  
410                 slottime = ah->slottime;
411 -               if (IS_CHAN_5GHZ(chan))
412 -                       sifstime = 16;
413 -               else
414 -                       sifstime = 10;
415         }
416  
417         /* As defined by IEEE 802.11-2007 17.3.8.6 */
418 -       acktimeout = slottime + sifstime + 3 * ah->coverage_class;
419 +       acktimeout = slottime + sifstime + 3 * ah->coverage_class + ack_offset;
420         ctstimeout = acktimeout;
421  
422         /*
423 @@ -1040,7 +1059,8 @@ void ath9k_hw_init_global_settings(struc
424          * BA frames in some implementations, but it has been found to fix ACK
425          * timeout issues in other cases as well.
426          */
427 -       if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) {
428 +       if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ &&
429 +           !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
430                 acktimeout += 64 - sifstime - ah->slottime;
431                 ctstimeout += 48 - sifstime - ah->slottime;
432         }
433 @@ -1420,6 +1440,10 @@ static bool ath9k_hw_channel_change(stru
434                                                     CHANNEL_5GHZ));
435         mode_diff = (chan->chanmode != ah->curchan->chanmode);
436  
437 +       if ((ah->curchan->channelFlags | chan->channelFlags) &
438 +           (CHANNEL_HALF | CHANNEL_QUARTER))
439 +               return false;
440 +
441         for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
442                 if (ath9k_hw_numtxpending(ah, qnum)) {
443                         ath_dbg(common, QUEUE,
444 @@ -1453,7 +1477,7 @@ static bool ath9k_hw_channel_change(stru
445                 return false;
446         }
447         ath9k_hw_set_clockrate(ah);
448 -       ath9k_hw_apply_txpower(ah, chan);
449 +       ath9k_hw_apply_txpower(ah, chan, false);
450         ath9k_hw_rfbus_done(ah);
451  
452         if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
453 @@ -2724,7 +2748,8 @@ static int get_antenna_gain(struct ath_h
454         return ah->eep_ops->get_eeprom(ah, gain_param);
455  }
456  
457 -void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
458 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
459 +                           bool test)
460  {
461         struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
462         struct ieee80211_channel *channel;
463 @@ -2745,7 +2770,7 @@ void ath9k_hw_apply_txpower(struct ath_h
464  
465         ah->eep_ops->set_txpower(ah, chan,
466                                  ath9k_regd_get_ctl(reg, chan),
467 -                                ant_reduction, new_pwr, false);
468 +                                ant_reduction, new_pwr, test);
469  }
470  
471  void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
472 @@ -2758,7 +2783,7 @@ void ath9k_hw_set_txpowerlimit(struct at
473         if (test)
474                 channel->max_power = MAX_RATE_POWER / 2;
475  
476 -       ath9k_hw_apply_txpower(ah, chan);
477 +       ath9k_hw_apply_txpower(ah, chan, test);
478  
479         if (test)
480                 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
481 --- a/drivers/net/wireless/ath/ath9k/hw.h
482 +++ b/drivers/net/wireless/ath/ath9k/hw.h
483 @@ -923,6 +923,8 @@ void ath9k_hw_set_gpio(struct ath_hw *ah
484  void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna);
485  
486  /* General Operation */
487 +void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
488 +                         int hw_delay);
489  bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout);
490  void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
491                           int column, unsigned int *writecnt);
492 @@ -976,7 +978,8 @@ void ath9k_hw_name(struct ath_hw *ah, ch
493  /* PHY */
494  void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
495                                    u32 *coef_mantissa, u32 *coef_exponent);
496 -void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan);
497 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
498 +                           bool test);
499  
500  /*
501   * Code Specific to AR5008, AR9001 or AR9002,
502 --- a/drivers/net/wireless/ath/ath9k/mac.c
503 +++ b/drivers/net/wireless/ath/ath9k/mac.c
504 @@ -133,8 +133,16 @@ EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel
505  
506  void ath9k_hw_abort_tx_dma(struct ath_hw *ah)
507  {
508 +       int maxdelay = 1000;
509         int i, q;
510  
511 +       if (ah->curchan) {
512 +               if (IS_CHAN_HALF_RATE(ah->curchan))
513 +                       maxdelay *= 2;
514 +               else if (IS_CHAN_QUARTER_RATE(ah->curchan))
515 +                       maxdelay *= 4;
516 +       }
517 +
518         REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
519  
520         REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
521 @@ -142,7 +150,7 @@ void ath9k_hw_abort_tx_dma(struct ath_hw
522         REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
523  
524         for (q = 0; q < AR_NUM_QCU; q++) {
525 -               for (i = 0; i < 1000; i++) {
526 +               for (i = 0; i < maxdelay; i++) {
527                         if (i)
528                                 udelay(5);
529  
530 --- a/drivers/net/wireless/ath/ath9k/main.c
531 +++ b/drivers/net/wireless/ath/ath9k/main.c
532 @@ -692,17 +692,6 @@ void ath9k_tasklet(unsigned long data)
533                 goto out;
534         }
535  
536 -       /*
537 -        * Only run the baseband hang check if beacons stop working in AP or
538 -        * IBSS mode, because it has a high false positive rate. For station
539 -        * mode it should not be necessary, since the upper layers will detect
540 -        * this through a beacon miss automatically and the following channel
541 -        * change will trigger a hardware reset anyway
542 -        */
543 -       if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0 &&
544 -           !ath9k_hw_check_alive(ah))
545 -               ieee80211_queue_work(sc->hw, &sc->hw_check_work);
546 -
547         if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
548                 /*
549                  * TSF sync does not look correct; remain awake to sync with
550 --- a/net/mac80211/agg-rx.c
551 +++ b/net/mac80211/agg-rx.c
552 @@ -200,6 +200,8 @@ static void ieee80211_send_addba_resp(st
553                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
554         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
555                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
556 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
557 +               memcpy(mgmt->bssid, da, ETH_ALEN);
558  
559         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
560                                           IEEE80211_STYPE_ACTION);
561 --- a/net/mac80211/agg-tx.c
562 +++ b/net/mac80211/agg-tx.c
563 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
564         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
565         if (sdata->vif.type == NL80211_IFTYPE_AP ||
566             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
567 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
568 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
569 +           sdata->vif.type == NL80211_IFTYPE_WDS)
570                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
571         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
572                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
573 @@ -484,6 +485,7 @@ int ieee80211_start_tx_ba_session(struct
574             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
575             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
576             sdata->vif.type != NL80211_IFTYPE_AP &&
577 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
578             sdata->vif.type != NL80211_IFTYPE_ADHOC)
579                 return -EINVAL;
580  
581 --- a/net/mac80211/debugfs_sta.c
582 +++ b/net/mac80211/debugfs_sta.c
583 @@ -63,11 +63,11 @@ static ssize_t sta_flags_read(struct fil
584         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
585  
586         int res = scnprintf(buf, sizeof(buf),
587 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
588 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
589                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
590                             TEST(PS_DRIVER), TEST(AUTHORIZED),
591                             TEST(SHORT_PREAMBLE),
592 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
593 +                           TEST(WME), TEST(CLEAR_PS_FILT),
594                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
595                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
596                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
597 --- a/net/mac80211/iface.c
598 +++ b/net/mac80211/iface.c
599 @@ -163,7 +163,8 @@ static int ieee80211_check_queues(struct
600                         return -EINVAL;
601         }
602  
603 -       if (sdata->vif.type != NL80211_IFTYPE_AP) {
604 +       if ((sdata->vif.type != NL80211_IFTYPE_AP) ||
605 +           !(sdata->local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)) {
606                 sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
607                 return 0;
608         }
609 @@ -281,7 +282,6 @@ static int ieee80211_do_open(struct net_
610  {
611         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
612         struct ieee80211_local *local = sdata->local;
613 -       struct sta_info *sta;
614         u32 changed = 0;
615         int res;
616         u32 hw_reconf_flags = 0;
617 @@ -427,28 +427,6 @@ static int ieee80211_do_open(struct net_
618  
619         set_bit(SDATA_STATE_RUNNING, &sdata->state);
620  
621 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
622 -               /* Create STA entry for the WDS peer */
623 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
624 -                                    GFP_KERNEL);
625 -               if (!sta) {
626 -                       res = -ENOMEM;
627 -                       goto err_del_interface;
628 -               }
629 -
630 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
631 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
632 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
633 -
634 -               res = sta_info_insert(sta);
635 -               if (res) {
636 -                       /* STA has been freed */
637 -                       goto err_del_interface;
638 -               }
639 -
640 -               rate_control_rate_init(sta);
641 -       }
642 -
643         /*
644          * set_multicast_list will be invoked by the networking core
645          * which will check whether any increments here were done in
646 @@ -845,6 +823,70 @@ static void ieee80211_if_setup(struct ne
647         dev->destructor = free_netdev;
648  }
649  
650 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
651 +                                        struct sk_buff *skb)
652 +{
653 +       struct ieee80211_local *local = sdata->local;
654 +       struct ieee80211_rx_status *rx_status;
655 +       struct ieee802_11_elems elems;
656 +       struct ieee80211_mgmt *mgmt;
657 +       struct sta_info *sta;
658 +       size_t baselen;
659 +       u32 rates = 0;
660 +       u16 stype;
661 +       bool new = false;
662 +       enum ieee80211_band band = local->hw.conf.channel->band;
663 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
664 +
665 +       rx_status = IEEE80211_SKB_RXCB(skb);
666 +       mgmt = (struct ieee80211_mgmt *) skb->data;
667 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
668 +
669 +       if (stype != IEEE80211_STYPE_BEACON)
670 +               return;
671 +
672 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
673 +       if (baselen > skb->len)
674 +               return;
675 +
676 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
677 +                              skb->len - baselen, &elems);
678 +
679 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
680 +
681 +       rcu_read_lock();
682 +
683 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
684 +
685 +       if (!sta) {
686 +               rcu_read_unlock();
687 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
688 +                                    GFP_KERNEL);
689 +               if (!sta)
690 +                       return;
691 +
692 +               new = true;
693 +       }
694 +
695 +       sta->last_rx = jiffies;
696 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
697 +
698 +       if (elems.ht_cap_elem)
699 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
700 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
701 +
702 +       if (elems.wmm_param)
703 +               set_sta_flag(sta, WLAN_STA_WME);
704 +
705 +       if (new) {
706 +               set_sta_flag(sta, WLAN_STA_AUTHORIZED);
707 +               rate_control_rate_init(sta);
708 +               sta_info_insert_rcu(sta);
709 +       }
710 +
711 +       rcu_read_unlock();
712 +}
713 +
714  static void ieee80211_iface_work(struct work_struct *work)
715  {
716         struct ieee80211_sub_if_data *sdata =
717 @@ -949,6 +991,9 @@ static void ieee80211_iface_work(struct 
718                                 break;
719                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
720                         break;
721 +               case NL80211_IFTYPE_WDS:
722 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
723 +                       break;
724                 default:
725                         WARN(1, "frame for unexpected interface type");
726                         break;
727 --- a/net/mac80211/rx.c
728 +++ b/net/mac80211/rx.c
729 @@ -103,7 +103,7 @@ static void
730  ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
731                                  struct sk_buff *skb,
732                                  struct ieee80211_rate *rate,
733 -                                int rtap_len)
734 +                                int rtap_len, bool has_fcs)
735  {
736         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
737         struct ieee80211_radiotap_header *rthdr;
738 @@ -134,7 +134,7 @@ ieee80211_add_rx_radiotap_header(struct 
739         }
740  
741         /* IEEE80211_RADIOTAP_FLAGS */
742 -       if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
743 +       if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
744                 *pos |= IEEE80211_RADIOTAP_F_FCS;
745         if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
746                 *pos |= IEEE80211_RADIOTAP_F_BADFCS;
747 @@ -294,7 +294,8 @@ ieee80211_rx_monitor(struct ieee80211_lo
748         }
749  
750         /* prepend radiotap information */
751 -       ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
752 +       ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
753 +                                        true);
754  
755         skb_reset_mac_header(skb);
756         skb->ip_summed = CHECKSUM_UNNECESSARY;
757 @@ -2282,6 +2283,7 @@ ieee80211_rx_h_action(struct ieee80211_r
758                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
759                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
760                     sdata->vif.type != NL80211_IFTYPE_AP &&
761 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
762                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
763                         break;
764  
765 @@ -2496,14 +2498,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
766  
767         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
768             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
769 -           sdata->vif.type != NL80211_IFTYPE_STATION)
770 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
771 +           sdata->vif.type != NL80211_IFTYPE_WDS)
772                 return RX_DROP_MONITOR;
773  
774         switch (stype) {
775         case cpu_to_le16(IEEE80211_STYPE_AUTH):
776         case cpu_to_le16(IEEE80211_STYPE_BEACON):
777         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
778 -               /* process for all: mesh, mlme, ibss */
779 +               /* process for all: mesh, mlme, ibss, wds */
780                 break;
781         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
782         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
783 @@ -2567,7 +2570,8 @@ static void ieee80211_rx_cooked_monitor(
784                 goto out_free_skb;
785  
786         /* prepend radiotap information */
787 -       ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom);
788 +       ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
789 +                                        false);
790  
791         skb_set_mac_header(skb, 0);
792         skb->ip_summed = CHECKSUM_UNNECESSARY;
793 @@ -2836,10 +2840,16 @@ static int prepare_for_handlers(struct i
794                 }
795                 break;
796         case NL80211_IFTYPE_WDS:
797 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
798 -                       return 0;
799                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
800                         return 0;
801 +
802 +               if (ieee80211_is_data(hdr->frame_control) ||
803 +                   ieee80211_is_action(hdr->frame_control)) {
804 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
805 +                               return 0;
806 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
807 +                       return 0;
808 +
809                 break;
810         default:
811                 /* should never get here */
812 --- a/net/mac80211/sta_info.h
813 +++ b/net/mac80211/sta_info.h
814 @@ -32,7 +32,6 @@
815   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
816   *     frames.
817   * @WLAN_STA_WME: Station is a QoS-STA.
818 - * @WLAN_STA_WDS: Station is one of our WDS peers.
819   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
820   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
821   *     frame to this station is transmitted.
822 @@ -64,7 +63,6 @@ enum ieee80211_sta_info_flags {
823         WLAN_STA_AUTHORIZED,
824         WLAN_STA_SHORT_PREAMBLE,
825         WLAN_STA_WME,
826 -       WLAN_STA_WDS,
827         WLAN_STA_CLEAR_PS_FILT,
828         WLAN_STA_MFP,
829         WLAN_STA_BLOCK_BA,
830 --- a/drivers/net/wireless/ath/ath9k/init.c
831 +++ b/drivers/net/wireless/ath/ath9k/init.c
832 @@ -647,6 +647,24 @@ void ath9k_reload_chainmask_settings(str
833                 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
834  }
835  
836 +static const struct ieee80211_iface_limit if_limits[] = {
837 +       { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) |
838 +                                BIT(NL80211_IFTYPE_P2P_CLIENT) |
839 +                                BIT(NL80211_IFTYPE_WDS) },
840 +       { .max = 8,     .types =
841 +#ifdef CONFIG_MAC80211_MESH
842 +                                BIT(NL80211_IFTYPE_MESH_POINT) |
843 +#endif
844 +                                BIT(NL80211_IFTYPE_AP) |
845 +                                BIT(NL80211_IFTYPE_P2P_GO) },
846 +};
847 +
848 +static const struct ieee80211_iface_combination if_comb = {
849 +       .limits = if_limits,
850 +       .n_limits = ARRAY_SIZE(if_limits),
851 +       .max_interfaces = 2048,
852 +       .num_different_channels = 1,
853 +};
854  
855  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
856  {
857 @@ -676,6 +694,9 @@ void ath9k_set_hw_capab(struct ath_softc
858                 BIT(NL80211_IFTYPE_ADHOC) |
859                 BIT(NL80211_IFTYPE_MESH_POINT);
860  
861 +       hw->wiphy->iface_combinations = &if_comb;
862 +       hw->wiphy->n_iface_combinations = 1;
863 +
864         if (AR_SREV_5416(sc->sc_ah))
865                 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
866  
867 --- a/net/mac80211/ibss.c
868 +++ b/net/mac80211/ibss.c
869 @@ -455,8 +455,8 @@ static void ieee80211_rx_bss_info(struct
870                          * fall back to HT20 if we don't use or use
871                          * the other extension channel
872                          */
873 -                       if ((channel_type == NL80211_CHAN_HT40MINUS ||
874 -                            channel_type == NL80211_CHAN_HT40PLUS) &&
875 +                       if (!(channel_type == NL80211_CHAN_HT40MINUS ||
876 +                             channel_type == NL80211_CHAN_HT40PLUS) ||
877                             channel_type != sdata->u.ibss.channel_type)
878                                 sta_ht_cap_new.cap &=
879                                         ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;