ath9k: merge a ar93xx ht40 performance fix
[openwrt.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 @@ -2416,6 +2416,22 @@ ath5k_tx_complete_poll_work(struct work_
4  * Initialization routines *
5  \*************************/
6  
7 +static const struct ieee80211_iface_limit if_limits[] = {
8 +       { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) },
9 +       { .max = 4,     .types =
10 +#ifdef CONFIG_MAC80211_MESH
11 +                                BIT(NL80211_IFTYPE_MESH_POINT) |
12 +#endif
13 +                                BIT(NL80211_IFTYPE_AP) },
14 +};
15 +
16 +static const struct ieee80211_iface_combination if_comb = {
17 +       .limits = if_limits,
18 +       .n_limits = ARRAY_SIZE(if_limits),
19 +       .max_interfaces = 2048,
20 +       .num_different_channels = 1,
21 +};
22 +
23  int __devinit
24  ath5k_init_ah(struct ath5k_hw *ah, const struct ath_bus_ops *bus_ops)
25  {
26 @@ -2437,6 +2453,9 @@ ath5k_init_ah(struct ath5k_hw *ah, const
27                 BIT(NL80211_IFTYPE_ADHOC) |
28                 BIT(NL80211_IFTYPE_MESH_POINT);
29  
30 +       hw->wiphy->iface_combinations = &if_comb;
31 +       hw->wiphy->n_iface_combinations = 1;
32 +
33         /* SW support for IBSS_RSN is provided by mac80211 */
34         hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
35  
36 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
37 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
38 @@ -618,19 +618,10 @@ static void ar5008_hw_init_bb(struct ath
39         u32 synthDelay;
40  
41         synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
42 -       if (IS_CHAN_B(chan))
43 -               synthDelay = (4 * synthDelay) / 22;
44 -       else
45 -               synthDelay /= 10;
46 -
47 -       if (IS_CHAN_HALF_RATE(chan))
48 -               synthDelay *= 2;
49 -       else if (IS_CHAN_QUARTER_RATE(chan))
50 -               synthDelay *= 4;
51  
52         REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
53  
54 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
55 +       ath9k_hw_synth_delay(ah, chan, synthDelay);
56  }
57  
58  static void ar5008_hw_init_chain_masks(struct ath_hw *ah)
59 @@ -868,7 +859,7 @@ static int ar5008_hw_process_ini(struct 
60         ar5008_hw_set_channel_regs(ah, chan);
61         ar5008_hw_init_chain_masks(ah);
62         ath9k_olc_init(ah);
63 -       ath9k_hw_apply_txpower(ah, chan);
64 +       ath9k_hw_apply_txpower(ah, chan, false);
65  
66         /* Write analog registers */
67         if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
68 @@ -948,12 +939,8 @@ static bool ar5008_hw_rfbus_req(struct a
69  static void ar5008_hw_rfbus_done(struct ath_hw *ah)
70  {
71         u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
72 -       if (IS_CHAN_B(ah->curchan))
73 -               synthDelay = (4 * synthDelay) / 22;
74 -       else
75 -               synthDelay /= 10;
76  
77 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
78 +       ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
79  
80         REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
81  }
82 --- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
83 +++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
84 @@ -1000,10 +1000,12 @@ static bool ar9003_hw_init_cal(struct at
85         if (mci && IS_CHAN_2GHZ(chan) && run_agc_cal)
86                 ar9003_mci_init_cal_req(ah, &is_reusable);
87  
88 -       txiqcal_done = ar9003_hw_tx_iq_cal_run(ah);
89 -       REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
90 -       udelay(5);
91 -       REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
92 +       if (!(IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))) {
93 +               txiqcal_done = ar9003_hw_tx_iq_cal_run(ah);
94 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
95 +               udelay(5);
96 +               REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
97 +       }
98  
99  skip_tx_iqcal:
100         if (run_agc_cal || !(ah->ah_flags & AH_FASTCC)) {
101 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
102 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
103 @@ -4281,18 +4281,10 @@ static int ar9003_hw_tx_power_regwrite(s
104  #undef POW_SM
105  }
106  
107 -static void ar9003_hw_set_target_power_eeprom(struct ath_hw *ah, u16 freq,
108 -                                             u8 *targetPowerValT2)
109 +static void ar9003_hw_get_legacy_target_powers(struct ath_hw *ah, u16 freq,
110 +                                              u8 *targetPowerValT2,
111 +                                              bool is2GHz)
112  {
113 -       /* XXX: hard code for now, need to get from eeprom struct */
114 -       u8 ht40PowerIncForPdadc = 0;
115 -       bool is2GHz = false;
116 -       unsigned int i = 0;
117 -       struct ath_common *common = ath9k_hw_common(ah);
118 -
119 -       if (freq < 4000)
120 -               is2GHz = true;
121 -
122         targetPowerValT2[ALL_TARGET_LEGACY_6_24] =
123             ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_6_24, freq,
124                                          is2GHz);
125 @@ -4305,6 +4297,11 @@ static void ar9003_hw_set_target_power_e
126         targetPowerValT2[ALL_TARGET_LEGACY_54] =
127             ar9003_hw_eeprom_get_tgt_pwr(ah, LEGACY_TARGET_RATE_54, freq,
128                                          is2GHz);
129 +}
130 +
131 +static void ar9003_hw_get_cck_target_powers(struct ath_hw *ah, u16 freq,
132 +                                           u8 *targetPowerValT2)
133 +{
134         targetPowerValT2[ALL_TARGET_LEGACY_1L_5L] =
135             ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_1L_5L,
136                                              freq);
137 @@ -4314,6 +4311,11 @@ static void ar9003_hw_set_target_power_e
138             ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11L, freq);
139         targetPowerValT2[ALL_TARGET_LEGACY_11S] =
140             ar9003_hw_eeprom_get_cck_tgt_pwr(ah, LEGACY_TARGET_RATE_11S, freq);
141 +}
142 +
143 +static void ar9003_hw_get_ht20_target_powers(struct ath_hw *ah, u16 freq,
144 +                                            u8 *targetPowerValT2, bool is2GHz)
145 +{
146         targetPowerValT2[ALL_TARGET_HT20_0_8_16] =
147             ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
148                                               is2GHz);
149 @@ -4356,6 +4358,16 @@ static void ar9003_hw_set_target_power_e
150         targetPowerValT2[ALL_TARGET_HT20_23] =
151             ar9003_hw_eeprom_get_ht20_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
152                                               is2GHz);
153 +}
154 +
155 +static void ar9003_hw_get_ht40_target_powers(struct ath_hw *ah,
156 +                                                  u16 freq,
157 +                                                  u8 *targetPowerValT2,
158 +                                                  bool is2GHz)
159 +{
160 +       /* XXX: hard code for now, need to get from eeprom struct */
161 +       u8 ht40PowerIncForPdadc = 0;
162 +
163         targetPowerValT2[ALL_TARGET_HT40_0_8_16] =
164             ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_0_8_16, freq,
165                                               is2GHz) + ht40PowerIncForPdadc;
166 @@ -4399,6 +4411,26 @@ static void ar9003_hw_set_target_power_e
167         targetPowerValT2[ALL_TARGET_HT40_23] =
168             ar9003_hw_eeprom_get_ht40_tgt_pwr(ah, HT_TARGET_RATE_23, freq,
169                                               is2GHz) + ht40PowerIncForPdadc;
170 +}
171 +
172 +static void ar9003_hw_get_target_power_eeprom(struct ath_hw *ah,
173 +                                             struct ath9k_channel *chan,
174 +                                             u8 *targetPowerValT2)
175 +{
176 +       bool is2GHz = IS_CHAN_2GHZ(chan);
177 +       unsigned int i = 0;
178 +       struct ath_common *common = ath9k_hw_common(ah);
179 +       u16 freq = chan->channel;
180 +
181 +       if (is2GHz)
182 +               ar9003_hw_get_cck_target_powers(ah, freq, targetPowerValT2);
183 +
184 +       ar9003_hw_get_legacy_target_powers(ah, freq, targetPowerValT2, is2GHz);
185 +       ar9003_hw_get_ht20_target_powers(ah, freq, targetPowerValT2, is2GHz);
186 +
187 +       if (IS_CHAN_HT40(chan))
188 +               ar9003_hw_get_ht40_target_powers(ah, freq, targetPowerValT2,
189 +                                                is2GHz);
190  
191         for (i = 0; i < ar9300RateSize; i++) {
192                 ath_dbg(common, EEPROM, "TPC[%02d] 0x%08x\n",
193 @@ -4778,9 +4810,6 @@ static void ar9003_hw_set_power_per_rate
194         scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
195                                                 antenna_reduction);
196  
197 -       /*
198 -        * Get target powers from EEPROM - our baseline for TX Power
199 -        */
200         if (is2ghz) {
201                 /* Setup for CTL modes */
202                 /* CTL_11B, CTL_11G, CTL_2GHT20 */
203 @@ -4952,7 +4981,12 @@ static void ath9k_hw_ar9300_set_txpower(
204         unsigned int i = 0, paprd_scale_factor = 0;
205         u8 pwr_idx, min_pwridx = 0;
206  
207 -       ar9003_hw_set_target_power_eeprom(ah, chan->channel, targetPowerValT2);
208 +       memset(targetPowerValT2, 0 , sizeof(targetPowerValT2));
209 +
210 +       /*
211 +        * Get target powers from EEPROM - our baseline for TX Power
212 +        */
213 +       ar9003_hw_get_target_power_eeprom(ah, chan, targetPowerValT2);
214  
215         if (ah->eep_ops->get_eeprom(ah, EEP_PAPRD)) {
216                 if (IS_CHAN_2GHZ(chan))
217 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
218 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
219 @@ -54,7 +54,7 @@ void ar9003_paprd_enable(struct ath_hw *
220  
221         if (val) {
222                 ah->paprd_table_write_done = true;
223 -               ath9k_hw_apply_txpower(ah, chan);
224 +               ath9k_hw_apply_txpower(ah, chan, false);
225         }
226  
227         REG_RMW_FIELD(ah, AR_PHY_PAPRD_CTRL0_B0,
228 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
229 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
230 @@ -373,7 +373,7 @@ static void ar9003_hw_spur_ofdm_work(str
231                         else
232                                 spur_subchannel_sd = 0;
233  
234 -                       spur_freq_sd = (freq_offset << 9) / 11;
235 +                       spur_freq_sd = ((freq_offset + 10) << 9) / 11;
236  
237                 } else {
238                         if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
239 @@ -382,7 +382,7 @@ static void ar9003_hw_spur_ofdm_work(str
240                         else
241                                 spur_subchannel_sd = 1;
242  
243 -                       spur_freq_sd = (freq_offset << 9) / 11;
244 +                       spur_freq_sd = ((freq_offset - 10) << 9) / 11;
245  
246                 }
247  
248 @@ -526,22 +526,10 @@ static void ar9003_hw_init_bb(struct ath
249          * Value is in 100ns increments.
250          */
251         synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
252 -       if (IS_CHAN_B(chan))
253 -               synthDelay = (4 * synthDelay) / 22;
254 -       else
255 -               synthDelay /= 10;
256  
257         /* Activate the PHY (includes baseband activate + synthesizer on) */
258         REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
259 -
260 -       /*
261 -        * There is an issue if the AP starts the calibration before
262 -        * the base band timeout completes.  This could result in the
263 -        * rx_clear false triggering.  As a workaround we add delay an
264 -        * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
265 -        * does not happen.
266 -        */
267 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
268 +       ath9k_hw_synth_delay(ah, chan, synthDelay);
269  }
270  
271  static void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
272 @@ -692,7 +680,7 @@ static int ar9003_hw_process_ini(struct 
273         ar9003_hw_override_ini(ah);
274         ar9003_hw_set_channel_regs(ah, chan);
275         ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
276 -       ath9k_hw_apply_txpower(ah, chan);
277 +       ath9k_hw_apply_txpower(ah, chan, false);
278  
279         if (AR_SREV_9462(ah)) {
280                 if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
281 @@ -723,6 +711,14 @@ static void ar9003_hw_set_rfmode(struct 
282  
283         if (IS_CHAN_A_FAST_CLOCK(ah, chan))
284                 rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
285 +       if (IS_CHAN_QUARTER_RATE(chan))
286 +               rfMode |= AR_PHY_MODE_QUARTER;
287 +       if (IS_CHAN_HALF_RATE(chan))
288 +               rfMode |= AR_PHY_MODE_HALF;
289 +
290 +       if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
291 +               REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
292 +                             AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
293  
294         REG_WRITE(ah, AR_PHY_MODE, rfMode);
295  }
296 @@ -793,12 +789,8 @@ static bool ar9003_hw_rfbus_req(struct a
297  static void ar9003_hw_rfbus_done(struct ath_hw *ah)
298  {
299         u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
300 -       if (IS_CHAN_B(ah->curchan))
301 -               synthDelay = (4 * synthDelay) / 22;
302 -       else
303 -               synthDelay /= 10;
304  
305 -       udelay(synthDelay + BASE_ACTIVATE_DELAY);
306 +       ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
307  
308         REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
309  }
310 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
311 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
312 @@ -468,6 +468,9 @@
313  #define AR_PHY_ADDAC_PARA_CTL    (AR_SM_BASE + 0x150)
314  #define AR_PHY_XPA_CFG           (AR_SM_BASE + 0x158)
315  
316 +#define AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW  3
317 +#define AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW_S    0
318 +
319  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A           0x0001FC00
320  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A_S         10
321  #define AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A                       0x3FF
322 --- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
323 +++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
324 @@ -798,6 +798,8 @@ static void ath9k_hw_ar9287_set_txpower(
325                         regulatory->max_power_level = ratesArray[i];
326         }
327  
328 +       ath9k_hw_update_regulatory_maxpower(ah);
329 +
330         if (test)
331                 return;
332  
333 --- a/drivers/net/wireless/ath/ath9k/hw.c
334 +++ b/drivers/net/wireless/ath/ath9k/hw.c
335 @@ -191,6 +191,22 @@ bool ath9k_hw_wait(struct ath_hw *ah, u3
336  }
337  EXPORT_SYMBOL(ath9k_hw_wait);
338  
339 +void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
340 +                         int hw_delay)
341 +{
342 +       if (IS_CHAN_B(chan))
343 +               hw_delay = (4 * hw_delay) / 22;
344 +       else
345 +               hw_delay /= 10;
346 +
347 +       if (IS_CHAN_HALF_RATE(chan))
348 +               hw_delay *= 2;
349 +       else if (IS_CHAN_QUARTER_RATE(chan))
350 +               hw_delay *= 4;
351 +
352 +       udelay(hw_delay + BASE_ACTIVATE_DELAY);
353 +}
354 +
355  void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
356                           int column, unsigned int *writecnt)
357  {
358 @@ -1020,7 +1036,7 @@ void ath9k_hw_init_global_settings(struc
359         struct ath_common *common = ath9k_hw_common(ah);
360         struct ieee80211_conf *conf = &common->hw->conf;
361         const struct ath9k_channel *chan = ah->curchan;
362 -       int acktimeout, ctstimeout;
363 +       int acktimeout, ctstimeout, ack_offset = 0;
364         int slottime;
365         int sifstime;
366         int rx_lat = 0, tx_lat = 0, eifs = 0;
367 @@ -1041,6 +1057,11 @@ void ath9k_hw_init_global_settings(struc
368                 rx_lat = 37;
369         tx_lat = 54;
370  
371 +       if (IS_CHAN_5GHZ(chan))
372 +               sifstime = 16;
373 +       else
374 +               sifstime = 10;
375 +
376         if (IS_CHAN_HALF_RATE(chan)) {
377                 eifs = 175;
378                 rx_lat *= 2;
379 @@ -1048,8 +1069,9 @@ void ath9k_hw_init_global_settings(struc
380                 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
381                     tx_lat += 11;
382  
383 +               sifstime *= 2;
384 +               ack_offset = 16;
385                 slottime = 13;
386 -               sifstime = 32;
387         } else if (IS_CHAN_QUARTER_RATE(chan)) {
388                 eifs = 340;
389                 rx_lat = (rx_lat * 4) - 1;
390 @@ -1057,8 +1079,9 @@ void ath9k_hw_init_global_settings(struc
391                 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
392                     tx_lat += 22;
393  
394 +               sifstime *= 4;
395 +               ack_offset = 32;
396                 slottime = 21;
397 -               sifstime = 64;
398         } else {
399                 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
400                         eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
401 @@ -1072,14 +1095,10 @@ void ath9k_hw_init_global_settings(struc
402                 tx_lat = MS(reg, AR_USEC_TX_LAT);
403  
404                 slottime = ah->slottime;
405 -               if (IS_CHAN_5GHZ(chan))
406 -                       sifstime = 16;
407 -               else
408 -                       sifstime = 10;
409         }
410  
411         /* As defined by IEEE 802.11-2007 17.3.8.6 */
412 -       acktimeout = slottime + sifstime + 3 * ah->coverage_class;
413 +       acktimeout = slottime + sifstime + 3 * ah->coverage_class + ack_offset;
414         ctstimeout = acktimeout;
415  
416         /*
417 @@ -1089,7 +1108,8 @@ void ath9k_hw_init_global_settings(struc
418          * BA frames in some implementations, but it has been found to fix ACK
419          * timeout issues in other cases as well.
420          */
421 -       if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ) {
422 +       if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ &&
423 +           !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
424                 acktimeout += 64 - sifstime - ah->slottime;
425                 ctstimeout += 48 - sifstime - ah->slottime;
426         }
427 @@ -1469,6 +1489,10 @@ static bool ath9k_hw_channel_change(stru
428                                                     CHANNEL_5GHZ));
429         mode_diff = (chan->chanmode != ah->curchan->chanmode);
430  
431 +       if ((ah->curchan->channelFlags | chan->channelFlags) &
432 +           (CHANNEL_HALF | CHANNEL_QUARTER))
433 +               return false;
434 +
435         for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
436                 if (ath9k_hw_numtxpending(ah, qnum)) {
437                         ath_dbg(common, QUEUE,
438 @@ -1502,7 +1526,7 @@ static bool ath9k_hw_channel_change(stru
439                 return false;
440         }
441         ath9k_hw_set_clockrate(ah);
442 -       ath9k_hw_apply_txpower(ah, chan);
443 +       ath9k_hw_apply_txpower(ah, chan, false);
444         ath9k_hw_rfbus_done(ah);
445  
446         if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
447 @@ -2773,7 +2797,8 @@ static int get_antenna_gain(struct ath_h
448         return ah->eep_ops->get_eeprom(ah, gain_param);
449  }
450  
451 -void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan)
452 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
453 +                           bool test)
454  {
455         struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
456         struct ieee80211_channel *channel;
457 @@ -2794,7 +2819,7 @@ void ath9k_hw_apply_txpower(struct ath_h
458  
459         ah->eep_ops->set_txpower(ah, chan,
460                                  ath9k_regd_get_ctl(reg, chan),
461 -                                ant_reduction, new_pwr, false);
462 +                                ant_reduction, new_pwr, test);
463  }
464  
465  void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
466 @@ -2807,7 +2832,7 @@ void ath9k_hw_set_txpowerlimit(struct at
467         if (test)
468                 channel->max_power = MAX_RATE_POWER / 2;
469  
470 -       ath9k_hw_apply_txpower(ah, chan);
471 +       ath9k_hw_apply_txpower(ah, chan, test);
472  
473         if (test)
474                 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
475 --- a/drivers/net/wireless/ath/ath9k/hw.h
476 +++ b/drivers/net/wireless/ath/ath9k/hw.h
477 @@ -923,6 +923,8 @@ void ath9k_hw_set_gpio(struct ath_hw *ah
478  void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna);
479  
480  /* General Operation */
481 +void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
482 +                         int hw_delay);
483  bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout);
484  void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
485                           int column, unsigned int *writecnt);
486 @@ -982,7 +984,8 @@ void ath9k_hw_name(struct ath_hw *ah, ch
487  /* PHY */
488  void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
489                                    u32 *coef_mantissa, u32 *coef_exponent);
490 -void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan);
491 +void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
492 +                           bool test);
493  
494  /*
495   * Code Specific to AR5008, AR9001 or AR9002,
496 --- a/drivers/net/wireless/ath/ath9k/init.c
497 +++ b/drivers/net/wireless/ath/ath9k/init.c
498 @@ -647,6 +647,24 @@ void ath9k_reload_chainmask_settings(str
499                 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
500  }
501  
502 +static const struct ieee80211_iface_limit if_limits[] = {
503 +       { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) |
504 +                                BIT(NL80211_IFTYPE_P2P_CLIENT) |
505 +                                BIT(NL80211_IFTYPE_WDS) },
506 +       { .max = 8,     .types =
507 +#ifdef CONFIG_MAC80211_MESH
508 +                                BIT(NL80211_IFTYPE_MESH_POINT) |
509 +#endif
510 +                                BIT(NL80211_IFTYPE_AP) |
511 +                                BIT(NL80211_IFTYPE_P2P_GO) },
512 +};
513 +
514 +static const struct ieee80211_iface_combination if_comb = {
515 +       .limits = if_limits,
516 +       .n_limits = ARRAY_SIZE(if_limits),
517 +       .max_interfaces = 2048,
518 +       .num_different_channels = 1,
519 +};
520  
521  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
522  {
523 @@ -676,6 +694,9 @@ void ath9k_set_hw_capab(struct ath_softc
524                 BIT(NL80211_IFTYPE_ADHOC) |
525                 BIT(NL80211_IFTYPE_MESH_POINT);
526  
527 +       hw->wiphy->iface_combinations = &if_comb;
528 +       hw->wiphy->n_iface_combinations = 1;
529 +
530         if (AR_SREV_5416(sc->sc_ah))
531                 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
532  
533 --- a/drivers/net/wireless/ath/ath9k/mac.c
534 +++ b/drivers/net/wireless/ath/ath9k/mac.c
535 @@ -133,8 +133,16 @@ EXPORT_SYMBOL(ath9k_hw_updatetxtriglevel
536  
537  void ath9k_hw_abort_tx_dma(struct ath_hw *ah)
538  {
539 +       int maxdelay = 1000;
540         int i, q;
541  
542 +       if (ah->curchan) {
543 +               if (IS_CHAN_HALF_RATE(ah->curchan))
544 +                       maxdelay *= 2;
545 +               else if (IS_CHAN_QUARTER_RATE(ah->curchan))
546 +                       maxdelay *= 4;
547 +       }
548 +
549         REG_WRITE(ah, AR_Q_TXD, AR_Q_TXD_M);
550  
551         REG_SET_BIT(ah, AR_PCU_MISC, AR_PCU_FORCE_QUIET_COLL | AR_PCU_CLEAR_VMF);
552 @@ -142,7 +150,7 @@ void ath9k_hw_abort_tx_dma(struct ath_hw
553         REG_SET_BIT(ah, AR_D_GBL_IFS_MISC, AR_D_GBL_IFS_MISC_IGNORE_BACKOFF);
554  
555         for (q = 0; q < AR_NUM_QCU; q++) {
556 -               for (i = 0; i < 1000; i++) {
557 +               for (i = 0; i < maxdelay; i++) {
558                         if (i)
559                                 udelay(5);
560  
561 --- a/net/mac80211/agg-rx.c
562 +++ b/net/mac80211/agg-rx.c
563 @@ -200,6 +200,8 @@ static void ieee80211_send_addba_resp(st
564                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
565         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
566                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
567 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
568 +               memcpy(mgmt->bssid, da, ETH_ALEN);
569  
570         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
571                                           IEEE80211_STYPE_ACTION);
572 --- a/net/mac80211/agg-tx.c
573 +++ b/net/mac80211/agg-tx.c
574 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
575         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
576         if (sdata->vif.type == NL80211_IFTYPE_AP ||
577             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
578 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
579 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
580 +           sdata->vif.type == NL80211_IFTYPE_WDS)
581                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
582         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
583                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
584 @@ -484,6 +485,7 @@ int ieee80211_start_tx_ba_session(struct
585             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
586             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
587             sdata->vif.type != NL80211_IFTYPE_AP &&
588 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
589             sdata->vif.type != NL80211_IFTYPE_ADHOC)
590                 return -EINVAL;
591  
592 --- a/net/mac80211/debugfs_sta.c
593 +++ b/net/mac80211/debugfs_sta.c
594 @@ -63,11 +63,11 @@ static ssize_t sta_flags_read(struct fil
595         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
596  
597         int res = scnprintf(buf, sizeof(buf),
598 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
599 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
600                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
601                             TEST(PS_DRIVER), TEST(AUTHORIZED),
602                             TEST(SHORT_PREAMBLE),
603 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
604 +                           TEST(WME), TEST(CLEAR_PS_FILT),
605                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
606                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
607                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
608 --- a/net/mac80211/iface.c
609 +++ b/net/mac80211/iface.c
610 @@ -282,7 +282,6 @@ static int ieee80211_do_open(struct net_
611  {
612         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
613         struct ieee80211_local *local = sdata->local;
614 -       struct sta_info *sta;
615         u32 changed = 0;
616         int res;
617         u32 hw_reconf_flags = 0;
618 @@ -428,28 +427,6 @@ static int ieee80211_do_open(struct net_
619  
620         set_bit(SDATA_STATE_RUNNING, &sdata->state);
621  
622 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
623 -               /* Create STA entry for the WDS peer */
624 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
625 -                                    GFP_KERNEL);
626 -               if (!sta) {
627 -                       res = -ENOMEM;
628 -                       goto err_del_interface;
629 -               }
630 -
631 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
632 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
633 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
634 -
635 -               res = sta_info_insert(sta);
636 -               if (res) {
637 -                       /* STA has been freed */
638 -                       goto err_del_interface;
639 -               }
640 -
641 -               rate_control_rate_init(sta);
642 -       }
643 -
644         /*
645          * set_multicast_list will be invoked by the networking core
646          * which will check whether any increments here were done in
647 @@ -846,6 +823,72 @@ static void ieee80211_if_setup(struct ne
648         dev->destructor = free_netdev;
649  }
650  
651 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
652 +                                        struct sk_buff *skb)
653 +{
654 +       struct ieee80211_local *local = sdata->local;
655 +       struct ieee80211_rx_status *rx_status;
656 +       struct ieee802_11_elems elems;
657 +       struct ieee80211_mgmt *mgmt;
658 +       struct sta_info *sta;
659 +       size_t baselen;
660 +       u32 rates = 0;
661 +       u16 stype;
662 +       bool new = false;
663 +       enum ieee80211_band band = local->hw.conf.channel->band;
664 +       struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band];
665 +
666 +       rx_status = IEEE80211_SKB_RXCB(skb);
667 +       mgmt = (struct ieee80211_mgmt *) skb->data;
668 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
669 +
670 +       if (stype != IEEE80211_STYPE_BEACON)
671 +               return;
672 +
673 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
674 +       if (baselen > skb->len)
675 +               return;
676 +
677 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
678 +                              skb->len - baselen, &elems);
679 +
680 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
681 +
682 +       rcu_read_lock();
683 +
684 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
685 +
686 +       if (!sta) {
687 +               rcu_read_unlock();
688 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
689 +                                    GFP_KERNEL);
690 +               if (!sta)
691 +                       return;
692 +
693 +               new = true;
694 +       }
695 +
696 +       sta->last_rx = jiffies;
697 +       sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
698 +
699 +       if (elems.ht_cap_elem)
700 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
701 +                               elems.ht_cap_elem, &sta->sta.ht_cap);
702 +
703 +       if (elems.wmm_param)
704 +               set_sta_flag(sta, WLAN_STA_WME);
705 +
706 +       if (new) {
707 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
708 +               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
709 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
710 +               rate_control_rate_init(sta);
711 +               sta_info_insert_rcu(sta);
712 +       }
713 +
714 +       rcu_read_unlock();
715 +}
716 +
717  static void ieee80211_iface_work(struct work_struct *work)
718  {
719         struct ieee80211_sub_if_data *sdata =
720 @@ -950,6 +993,9 @@ static void ieee80211_iface_work(struct 
721                                 break;
722                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
723                         break;
724 +               case NL80211_IFTYPE_WDS:
725 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
726 +                       break;
727                 default:
728                         WARN(1, "frame for unexpected interface type");
729                         break;
730 --- a/net/mac80211/rx.c
731 +++ b/net/mac80211/rx.c
732 @@ -2283,6 +2283,7 @@ ieee80211_rx_h_action(struct ieee80211_r
733                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
734                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
735                     sdata->vif.type != NL80211_IFTYPE_AP &&
736 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
737                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
738                         break;
739  
740 @@ -2497,14 +2498,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
741  
742         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
743             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
744 -           sdata->vif.type != NL80211_IFTYPE_STATION)
745 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
746 +           sdata->vif.type != NL80211_IFTYPE_WDS)
747                 return RX_DROP_MONITOR;
748  
749         switch (stype) {
750         case cpu_to_le16(IEEE80211_STYPE_AUTH):
751         case cpu_to_le16(IEEE80211_STYPE_BEACON):
752         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
753 -               /* process for all: mesh, mlme, ibss */
754 +               /* process for all: mesh, mlme, ibss, wds */
755                 break;
756         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
757         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
758 @@ -2838,10 +2840,16 @@ static int prepare_for_handlers(struct i
759                 }
760                 break;
761         case NL80211_IFTYPE_WDS:
762 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
763 -                       return 0;
764                 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
765                         return 0;
766 +
767 +               if (ieee80211_is_data(hdr->frame_control) ||
768 +                   ieee80211_is_action(hdr->frame_control)) {
769 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
770 +                               return 0;
771 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
772 +                       return 0;
773 +
774                 break;
775         default:
776                 /* should never get here */
777 --- a/net/mac80211/sta_info.h
778 +++ b/net/mac80211/sta_info.h
779 @@ -32,7 +32,6 @@
780   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
781   *     frames.
782   * @WLAN_STA_WME: Station is a QoS-STA.
783 - * @WLAN_STA_WDS: Station is one of our WDS peers.
784   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
785   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
786   *     frame to this station is transmitted.
787 @@ -64,7 +63,6 @@ enum ieee80211_sta_info_flags {
788         WLAN_STA_AUTHORIZED,
789         WLAN_STA_SHORT_PREAMBLE,
790         WLAN_STA_WME,
791 -       WLAN_STA_WDS,
792         WLAN_STA_CLEAR_PS_FILT,
793         WLAN_STA_MFP,
794         WLAN_STA_BLOCK_BA,
795 --- a/drivers/net/wireless/iwlwifi/iwl-agn.h
796 +++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
797 @@ -425,6 +425,7 @@ void iwl_testmode_cleanup(struct iwl_pri
798  #ifdef CONFIG_IWLWIFI_DEBUG
799  void iwl_print_rx_config_cmd(struct iwl_priv *priv,
800                              enum iwl_rxon_context_id ctxid);
801 +int iwl_alloc_traffic_mem(struct iwl_priv *priv);
802  #else
803  static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv,
804                                            enum iwl_rxon_context_id ctxid)
805 @@ -510,7 +511,6 @@ void iwl_setup_deferred_work(struct iwl_
806  int iwl_send_wimax_coex(struct iwl_priv *priv);
807  int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
808  void iwl_debug_config(struct iwl_priv *priv);
809 -int iwl_alloc_traffic_mem(struct iwl_priv *priv);
810  void iwl_set_hw_params(struct iwl_priv *priv);
811  void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags);
812  int iwl_init_drv(struct iwl_priv *priv);
813 --- a/drivers/net/wireless/libertas/firmware.c
814 +++ b/drivers/net/wireless/libertas/firmware.c
815 @@ -5,6 +5,7 @@
816  #include <linux/firmware.h>
817  #include <linux/firmware.h>
818  #include <linux/module.h>
819 +#include <linux/sched.h>
820  
821  #include "dev.h"
822  #include "decl.h"
823 --- a/drivers/net/wireless/ath/ath9k/recv.c
824 +++ b/drivers/net/wireless/ath/ath9k/recv.c
825 @@ -812,6 +812,7 @@ static bool ath9k_rx_accept(struct ath_c
826         is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
827                 test_bit(rx_stats->rs_keyix, common->tkip_keymap);
828         strip_mic = is_valid_tkip && ieee80211_is_data(fc) &&
829 +               ieee80211_has_protected(fc) &&
830                 !(rx_stats->rs_status &
831                 (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC |
832                  ATH9K_RXERR_KEYMISS));
833 --- a/net/mac80211/cfg.c
834 +++ b/net/mac80211/cfg.c
835 @@ -1005,6 +1005,9 @@ static int ieee80211_change_station(stru
836         }
837  
838         if (params->vlan && params->vlan != sta->sdata->dev) {
839 +               bool prev_4addr = false;
840 +               bool new_4addr = false;
841 +
842                 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
843  
844                 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
845 @@ -1020,9 +1023,25 @@ static int ieee80211_change_station(stru
846                         }
847  
848                         rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
849 +                       new_4addr = true;
850 +               }
851 +
852 +               if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
853 +                   sta->sdata->u.vlan.sta) {
854 +                       rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
855 +                       prev_4addr = true;
856                 }
857  
858                 sta->sdata = vlansdata;
859 +
860 +               if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
861 +                   prev_4addr != new_4addr) {
862 +                       if (new_4addr)
863 +                               atomic_dec(&sta->sdata->bss->num_mcast_sta);
864 +                       else
865 +                               atomic_inc(&sta->sdata->bss->num_mcast_sta);
866 +               }
867 +
868                 ieee80211_send_layer2_update(sta);
869         }
870  
871 --- a/net/mac80211/debugfs_netdev.c
872 +++ b/net/mac80211/debugfs_netdev.c
873 @@ -394,7 +394,7 @@ static ssize_t ieee80211_if_parse_uapsd_
874  __IEEE80211_IF_FILE_W(uapsd_max_sp_len);
875  
876  /* AP attributes */
877 -IEEE80211_IF_FILE(num_sta_authorized, u.ap.num_sta_authorized, ATOMIC);
878 +IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
879  IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
880  IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
881  
882 @@ -540,7 +540,7 @@ static void add_sta_files(struct ieee802
883  
884  static void add_ap_files(struct ieee80211_sub_if_data *sdata)
885  {
886 -       DEBUGFS_ADD(num_sta_authorized);
887 +       DEBUGFS_ADD(num_mcast_sta);
888         DEBUGFS_ADD(num_sta_ps);
889         DEBUGFS_ADD(dtim_count);
890         DEBUGFS_ADD(num_buffered_multicast);
891 --- a/net/mac80211/ieee80211_i.h
892 +++ b/net/mac80211/ieee80211_i.h
893 @@ -282,7 +282,7 @@ struct ieee80211_if_ap {
894         u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
895         struct sk_buff_head ps_bc_buf;
896         atomic_t num_sta_ps; /* number of stations in PS mode */
897 -       atomic_t num_sta_authorized; /* number of authorized stations */
898 +       atomic_t num_mcast_sta; /* number of stations receiving multicast */
899         int dtim_count;
900         bool dtim_bc_mc;
901  };
902 --- a/net/mac80211/sta_info.c
903 +++ b/net/mac80211/sta_info.c
904 @@ -1417,15 +1417,19 @@ int sta_info_move_state(struct sta_info 
905                 if (sta->sta_state == IEEE80211_STA_AUTH) {
906                         set_bit(WLAN_STA_ASSOC, &sta->_flags);
907                 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
908 -                       if (sta->sdata->vif.type == NL80211_IFTYPE_AP)
909 -                               atomic_dec(&sta->sdata->u.ap.num_sta_authorized);
910 +                       if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
911 +                           (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
912 +                            !sta->sdata->u.vlan.sta))
913 +                               atomic_dec(&sta->sdata->bss->num_mcast_sta);
914                         clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
915                 }
916                 break;
917         case IEEE80211_STA_AUTHORIZED:
918                 if (sta->sta_state == IEEE80211_STA_ASSOC) {
919 -                       if (sta->sdata->vif.type == NL80211_IFTYPE_AP)
920 -                               atomic_inc(&sta->sdata->u.ap.num_sta_authorized);
921 +                       if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
922 +                           (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
923 +                            !sta->sdata->u.vlan.sta))
924 +                               atomic_inc(&sta->sdata->bss->num_mcast_sta);
925                         set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
926                 }
927                 break;
928 --- a/net/mac80211/tx.c
929 +++ b/net/mac80211/tx.c
930 @@ -306,7 +306,7 @@ ieee80211_tx_h_check_assoc(struct ieee80
931                 }
932         } else if (unlikely(tx->sdata->vif.type == NL80211_IFTYPE_AP &&
933                             ieee80211_is_data(hdr->frame_control) &&
934 -                           !atomic_read(&tx->sdata->u.ap.num_sta_authorized))) {
935 +                           !atomic_read(&tx->sdata->u.ap.num_mcast_sta))) {
936                 /*
937                  * No associated STAs - no need to send multicast
938                  * frames.
939 @@ -1159,7 +1159,8 @@ ieee80211_tx_prepare(struct ieee80211_su
940                 tx->sta = rcu_dereference(sdata->u.vlan.sta);
941                 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
942                         return TX_DROP;
943 -       } else if (info->flags & IEEE80211_TX_CTL_INJECTED) {
944 +       } else if (info->flags & IEEE80211_TX_CTL_INJECTED ||
945 +                  tx->sdata->control_port_protocol == tx->skb->protocol) {
946                 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
947         }
948         if (!tx->sta)
949 --- a/net/wireless/scan.c
950 +++ b/net/wireless/scan.c
951 @@ -378,7 +378,11 @@ static int cmp_bss_core(struct cfg80211_
952                                b->len_information_elements);
953         }
954  
955 -       return compare_ether_addr(a->bssid, b->bssid);
956 +       /*
957 +        * we can't use compare_ether_addr here since we need a < > operator.
958 +        * The binary return value of compare_ether_addr isn't enough
959 +        */
960 +       return memcmp(a->bssid, b->bssid, sizeof(a->bssid));
961  }
962  
963  static int cmp_bss(struct cfg80211_bss *a,