ath9k: fix a null pointer deref issue in the powersave fixes
[openwrt.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -234,6 +234,7 @@ struct ath_buf {
4         dma_addr_t bf_daddr;            /* physical addr of desc */
5         dma_addr_t bf_buf_addr; /* physical addr of data buffer, for DMA */
6         bool bf_stale;
7 +       struct ieee80211_tx_rate rates[4];
8         struct ath_buf_state bf_state;
9  };
10  
11 @@ -250,9 +251,9 @@ struct ath_atx_tid {
12         int tidno;
13         int baw_head;   /* first un-acked tx buffer */
14         int baw_tail;   /* next unused tx buffer slot */
15 -       int sched;
16 -       int paused;
17 -       u8 state;
18 +       bool sched;
19 +       bool paused;
20 +       bool active;
21  };
22  
23  struct ath_node {
24 @@ -273,10 +274,6 @@ struct ath_node {
25  #endif
26  };
27  
28 -#define AGGR_CLEANUP         BIT(1)
29 -#define AGGR_ADDBA_COMPLETE  BIT(2)
30 -#define AGGR_ADDBA_PROGRESS  BIT(3)
31 -
32  struct ath_tx_control {
33         struct ath_txq *txq;
34         struct ath_node *an;
35 @@ -299,6 +296,7 @@ struct ath_tx {
36         struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
37         struct ath_descdma txdma;
38         struct ath_txq *txq_map[IEEE80211_NUM_ACS];
39 +       struct ath_txq *uapsdq;
40         u32 txq_max_pending[IEEE80211_NUM_ACS];
41         u16 max_aggr_framelen[IEEE80211_NUM_ACS][4][32];
42  };
43 @@ -356,6 +354,11 @@ void ath_tx_aggr_resume(struct ath_softc
44  void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
45  void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
46                        struct ath_node *an);
47 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
48 +                                  struct ieee80211_sta *sta,
49 +                                  u16 tids, int nframes,
50 +                                  enum ieee80211_frame_release_type reason,
51 +                                  bool more_data);
52  
53  /********/
54  /* VIFs */
55 @@ -410,6 +413,7 @@ struct ath_beacon {
56         struct ath_descdma bdma;
57         struct ath_txq *cabq;
58         struct list_head bbuf;
59 +       int cabq_dur;
60  
61         bool tx_processed;
62         bool tx_last;
63 @@ -658,11 +662,10 @@ enum sc_op_flags {
64  struct ath_rate_table;
65  
66  struct ath9k_vif_iter_data {
67 -       const u8 *hw_macaddr; /* phy's hardware address, set
68 -                              * before starting iteration for
69 -                              * valid bssid mask.
70 -                              */
71 +       u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
72         u8 mask[ETH_ALEN]; /* bssid mask */
73 +       bool has_hw_macaddr;
74 +
75         int naps;      /* number of AP vifs */
76         int nmeshes;   /* number of mesh vifs */
77         int nstations; /* number of station vifs */
78 --- a/drivers/net/wireless/ath/ath9k/hw.c
79 +++ b/drivers/net/wireless/ath/ath9k/hw.c
80 @@ -1171,6 +1171,7 @@ u32 ath9k_regd_get_ctl(struct ath_regula
81  static inline void ath9k_hw_set_dma(struct ath_hw *ah)
82  {
83         struct ath_common *common = ath9k_hw_common(ah);
84 +       int txbuf_size;
85  
86         ENABLE_REGWRITE_BUFFER(ah);
87  
88 @@ -1224,13 +1225,17 @@ static inline void ath9k_hw_set_dma(stru
89                  * So set the usable tx buf size also to half to
90                  * avoid data/delimiter underruns
91                  */
92 -               REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
93 -                         AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
94 -       } else if (!AR_SREV_9271(ah)) {
95 -               REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
96 -                         AR_PCU_TXBUF_CTRL_USABLE_SIZE);
97 +               txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
98 +       } else if (AR_SREV_9340_13_OR_LATER(ah)) {
99 +               /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
100 +               txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
101 +       } else {
102 +               txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
103         }
104  
105 +       if (!AR_SREV_9271(ah))
106 +               REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
107 +
108         REGWRITE_BUFFER_FLUSH(ah);
109  
110         if (AR_SREV_9300_20_OR_LATER(ah))
111 @@ -1305,9 +1310,13 @@ static bool ath9k_hw_set_reset(struct at
112                         AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
113         } else {
114                 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
115 -               if (tmpReg &
116 -                   (AR_INTR_SYNC_LOCAL_TIMEOUT |
117 -                    AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
118 +               if (AR_SREV_9340(ah))
119 +                       tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
120 +               else
121 +                       tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
122 +                                 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
123 +
124 +               if (tmpReg) {
125                         u32 val;
126                         REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
127  
128 @@ -1366,7 +1375,10 @@ static bool ath9k_hw_set_reset(struct at
129  
130         REGWRITE_BUFFER_FLUSH(ah);
131  
132 -       udelay(50);
133 +       if (AR_SREV_9100(ah))
134 +               mdelay(10);
135 +       else
136 +               udelay(50);
137  
138         REG_WRITE(ah, AR_RTC_RC, 0);
139         if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
140 @@ -1377,8 +1389,12 @@ static bool ath9k_hw_set_reset(struct at
141         if (!AR_SREV_9100(ah))
142                 REG_WRITE(ah, AR_RC, 0);
143  
144 -       if (AR_SREV_9100(ah))
145 +       if (AR_SREV_9100(ah) && type != ATH9K_RESET_WARM) {
146 +               if (ah->external_reset)
147 +                       ah->external_reset();
148 +
149                 udelay(50);
150 +       }
151  
152         return true;
153  }
154 @@ -1464,7 +1480,8 @@ static bool ath9k_hw_chip_reset(struct a
155                         reset_type = ATH9K_RESET_POWER_ON;
156                 else
157                         reset_type = ATH9K_RESET_COLD;
158 -       } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
159 +       } else if (ah->chip_fullsleep ||
160 +                  REG_READ(ah, AR_Q_TXE) ||
161                    (REG_READ(ah, AR_CR) & AR_CR_RXE))
162                 reset_type = ATH9K_RESET_COLD;
163  
164 @@ -1698,12 +1715,11 @@ static void ath9k_hw_reset_opmode(struct
165  
166         ENABLE_REGWRITE_BUFFER(ah);
167  
168 -       REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
169 -       REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
170 -                 | macStaId1
171 +       REG_RMW(ah, AR_STA_ID1, macStaId1
172                   | AR_STA_ID1_RTS_USE_DEF
173                   | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
174 -                 | ah->sta_id1_defaults);
175 +                 | ah->sta_id1_defaults,
176 +                 ~AR_STA_ID1_SADH_MASK);
177         ath_hw_setbssidmask(common);
178         REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
179         ath9k_hw_write_associd(ah);
180 --- a/drivers/net/wireless/ath/ath9k/main.c
181 +++ b/drivers/net/wireless/ath/ath9k/main.c
182 @@ -839,10 +839,14 @@ static void ath9k_vif_iter(void *data, u
183         struct ath9k_vif_iter_data *iter_data = data;
184         int i;
185  
186 -       if (iter_data->hw_macaddr)
187 +       if (iter_data->has_hw_macaddr) {
188                 for (i = 0; i < ETH_ALEN; i++)
189                         iter_data->mask[i] &=
190                                 ~(iter_data->hw_macaddr[i] ^ mac[i]);
191 +       } else {
192 +               memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
193 +               iter_data->has_hw_macaddr = true;
194 +       }
195  
196         switch (vif->type) {
197         case NL80211_IFTYPE_AP:
198 @@ -891,7 +895,6 @@ void ath9k_calculate_iter_data(struct ie
199          * together with the BSSID mask when matching addresses.
200          */
201         memset(iter_data, 0, sizeof(*iter_data));
202 -       iter_data->hw_macaddr = common->macaddr;
203         memset(&iter_data->mask, 0xff, ETH_ALEN);
204  
205         if (vif)
206 @@ -901,6 +904,8 @@ void ath9k_calculate_iter_data(struct ie
207         ieee80211_iterate_active_interfaces_atomic(
208                 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
209                 ath9k_vif_iter, iter_data);
210 +
211 +       memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
212  }
213  
214  /* Called with sc->mutex held. */
215 @@ -1327,6 +1332,7 @@ static int ath9k_sta_add(struct ieee8021
216         struct ath_common *common = ath9k_hw_common(sc->sc_ah);
217         struct ath_node *an = (struct ath_node *) sta->drv_priv;
218         struct ieee80211_key_conf ps_key = { };
219 +       int key;
220  
221         ath_node_attach(sc, sta, vif);
222  
223 @@ -1334,7 +1340,9 @@ static int ath9k_sta_add(struct ieee8021
224             vif->type != NL80211_IFTYPE_AP_VLAN)
225                 return 0;
226  
227 -       an->ps_key = ath_key_config(common, vif, sta, &ps_key);
228 +       key = ath_key_config(common, vif, sta, &ps_key);
229 +       if (key > 0)
230 +               an->ps_key = key;
231  
232         return 0;
233  }
234 @@ -1351,6 +1359,7 @@ static void ath9k_del_ps_key(struct ath_
235             return;
236  
237         ath_key_delete(common, &ps_key);
238 +       an->ps_key = 0;
239  }
240  
241  static int ath9k_sta_remove(struct ieee80211_hw *hw,
242 @@ -1678,6 +1687,7 @@ static int ath9k_ampdu_action(struct iee
243                               u16 tid, u16 *ssn, u8 buf_size)
244  {
245         struct ath_softc *sc = hw->priv;
246 +       bool flush = false;
247         int ret = 0;
248  
249         local_bh_disable();
250 @@ -1694,12 +1704,14 @@ static int ath9k_ampdu_action(struct iee
251                         ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
252                 ath9k_ps_restore(sc);
253                 break;
254 -       case IEEE80211_AMPDU_TX_STOP_CONT:
255         case IEEE80211_AMPDU_TX_STOP_FLUSH:
256         case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
257 +               flush = true;
258 +       case IEEE80211_AMPDU_TX_STOP_CONT:
259                 ath9k_ps_wakeup(sc);
260                 ath_tx_aggr_stop(sc, sta, tid);
261 -               ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
262 +               if (!flush)
263 +                       ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
264                 ath9k_ps_restore(sc);
265                 break;
266         case IEEE80211_AMPDU_TX_OPERATIONAL:
267 @@ -2366,6 +2378,7 @@ struct ieee80211_ops ath9k_ops = {
268         .flush              = ath9k_flush,
269         .tx_frames_pending  = ath9k_tx_frames_pending,
270         .tx_last_beacon     = ath9k_tx_last_beacon,
271 +       .release_buffered_frames = ath9k_release_buffered_frames,
272         .get_stats          = ath9k_get_stats,
273         .set_antenna        = ath9k_set_antenna,
274         .get_antenna        = ath9k_get_antenna,
275 --- a/drivers/net/wireless/ath/ath9k/reg.h
276 +++ b/drivers/net/wireless/ath/ath9k/reg.h
277 @@ -798,6 +798,10 @@
278  #define AR_SREV_REVISION_9485_10       0
279  #define AR_SREV_REVISION_9485_11        1
280  #define AR_SREV_VERSION_9340           0x300
281 +#define AR_SREV_REVISION_9340_10       0
282 +#define AR_SREV_REVISION_9340_11       1
283 +#define AR_SREV_REVISION_9340_12       2
284 +#define AR_SREV_REVISION_9340_13       3
285  #define AR_SREV_VERSION_9580           0x1C0
286  #define AR_SREV_REVISION_9580_10       4 /* AR9580 1.0 */
287  #define AR_SREV_VERSION_9462           0x280
288 @@ -897,6 +901,10 @@
289  #define AR_SREV_9340(_ah) \
290         (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
291  
292 +#define AR_SREV_9340_13_OR_LATER(_ah) \
293 +       (AR_SREV_9340((_ah)) && \
294 +        ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))
295 +
296  #define AR_SREV_9285E_20(_ah) \
297      (AR_SREV_9285_12_OR_LATER(_ah) && \
298       ((REG_READ(_ah, AR_AN_SYNTH9) & 0x7) == 0x1))
299 @@ -1007,6 +1015,8 @@ enum {
300                                 AR_INTR_SYNC_LOCAL_TIMEOUT |
301                                 AR_INTR_SYNC_MAC_SLEEP_ACCESS),
302  
303 +       AR9340_INTR_SYNC_LOCAL_TIMEOUT = 0x00000010,
304 +
305         AR_INTR_SYNC_SPURIOUS = 0xFFFFFFFF,
306  
307  };
308 @@ -1493,9 +1503,6 @@ enum {
309  #define AR9271_RADIO_RF_RST                    0x20
310  #define AR9271_GATE_MAC_CTL                    0x4000
311  
312 -#define AR_STA_ID0                 0x8000
313 -#define AR_STA_ID1                 0x8004
314 -#define AR_STA_ID1_SADH_MASK       0x0000FFFF
315  #define AR_STA_ID1_STA_AP          0x00010000
316  #define AR_STA_ID1_ADHOC           0x00020000
317  #define AR_STA_ID1_PWR_SAV         0x00040000
318 @@ -1884,6 +1891,7 @@ enum {
319  #define AR_PCU_TXBUF_CTRL_SIZE_MASK     0x7FF
320  #define AR_PCU_TXBUF_CTRL_USABLE_SIZE   0x700
321  #define AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE   0x380
322 +#define AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE   0x500
323  
324  #define AR_PCU_MISC_MODE2               0x8344
325  #define AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE           0x00000002
326 --- a/drivers/net/wireless/ath/hw.c
327 +++ b/drivers/net/wireless/ath/hw.c
328 @@ -118,6 +118,12 @@
329  void ath_hw_setbssidmask(struct ath_common *common)
330  {
331         void *ah = common->ah;
332 +       u32 id1;
333 +
334 +       REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
335 +       id1 = REG_READ(ah, AR_STA_ID1) & ~AR_STA_ID1_SADH_MASK;
336 +       id1 |= get_unaligned_le16(common->macaddr + 4);
337 +       REG_WRITE(ah, AR_STA_ID1, id1);
338  
339         REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
340         REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
341 --- a/drivers/net/wireless/ath/reg.h
342 +++ b/drivers/net/wireless/ath/reg.h
343 @@ -23,6 +23,10 @@
344  #define AR_MIBC_CMC            0x00000004
345  #define AR_MIBC_MCS            0x00000008
346  
347 +#define AR_STA_ID0             0x8000
348 +#define AR_STA_ID1             0x8004
349 +#define AR_STA_ID1_SADH_MASK   0x0000ffff
350 +
351  /*
352   * BSSID mask registers. See ath_hw_set_bssid_mask()
353   * for detailed documentation about these registers.
354 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
355 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
356 @@ -6059,7 +6059,7 @@ il4965_mac_channel_switch(struct ieee802
357         struct il_priv *il = hw->priv;
358         const struct il_channel_info *ch_info;
359         struct ieee80211_conf *conf = &hw->conf;
360 -       struct ieee80211_channel *channel = ch_switch->channel;
361 +       struct ieee80211_channel *channel = ch_switch->chandef.chan;
362         struct il_ht_config *ht_conf = &il->current_ht_config;
363         u16 ch;
364  
365 @@ -6096,23 +6096,21 @@ il4965_mac_channel_switch(struct ieee802
366         il->current_ht_config.smps = conf->smps_mode;
367  
368         /* Configure HT40 channels */
369 -       il->ht.enabled = conf_is_ht(conf);
370 -       if (il->ht.enabled) {
371 -               if (conf_is_ht40_minus(conf)) {
372 -                       il->ht.extension_chan_offset =
373 -                           IEEE80211_HT_PARAM_CHA_SEC_BELOW;
374 -                       il->ht.is_40mhz = true;
375 -               } else if (conf_is_ht40_plus(conf)) {
376 -                       il->ht.extension_chan_offset =
377 -                           IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
378 -                       il->ht.is_40mhz = true;
379 -               } else {
380 -                       il->ht.extension_chan_offset =
381 -                           IEEE80211_HT_PARAM_CHA_SEC_NONE;
382 -                       il->ht.is_40mhz = false;
383 -               }
384 -       } else
385 +       switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
386 +       case NL80211_CHAN_NO_HT:
387 +       case NL80211_CHAN_HT20:
388                 il->ht.is_40mhz = false;
389 +               il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
390 +               break;
391 +       case NL80211_CHAN_HT40MINUS:
392 +               il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
393 +               il->ht.is_40mhz = true;
394 +               break;
395 +       case NL80211_CHAN_HT40PLUS:
396 +               il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
397 +               il->ht.is_40mhz = true;
398 +               break;
399 +       }
400  
401         if ((le16_to_cpu(il->staging.channel) != ch))
402                 il->staging.flags = 0;
403 --- a/drivers/net/wireless/iwlegacy/4965.c
404 +++ b/drivers/net/wireless/iwlegacy/4965.c
405 @@ -1493,7 +1493,7 @@ il4965_hw_channel_switch(struct il_priv 
406  
407         cmd.band = band;
408         cmd.expect_beacon = 0;
409 -       ch = ch_switch->channel->hw_value;
410 +       ch = ch_switch->chandef.chan->hw_value;
411         cmd.channel = cpu_to_le16(ch);
412         cmd.rxon_flags = il->staging.flags;
413         cmd.rxon_filter_flags = il->staging.filter_flags;
414 --- a/drivers/net/wireless/iwlwifi/dvm/devices.c
415 +++ b/drivers/net/wireless/iwlwifi/dvm/devices.c
416 @@ -379,7 +379,7 @@ static int iwl5000_hw_channel_switch(str
417         };
418  
419         cmd.band = priv->band == IEEE80211_BAND_2GHZ;
420 -       ch = ch_switch->channel->hw_value;
421 +       ch = ch_switch->chandef.chan->hw_value;
422         IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
423                       ctx->active.channel, ch);
424         cmd.channel = cpu_to_le16(ch);
425 @@ -414,7 +414,8 @@ static int iwl5000_hw_channel_switch(str
426         }
427         IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
428                       cmd.switch_time);
429 -       cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
430 +       cmd.expect_beacon =
431 +               ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
432  
433         return iwl_dvm_send_cmd(priv, &hcmd);
434  }
435 @@ -540,7 +541,7 @@ static int iwl6000_hw_channel_switch(str
436         hcmd.data[0] = cmd;
437  
438         cmd->band = priv->band == IEEE80211_BAND_2GHZ;
439 -       ch = ch_switch->channel->hw_value;
440 +       ch = ch_switch->chandef.chan->hw_value;
441         IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
442                       ctx->active.channel, ch);
443         cmd->channel = cpu_to_le16(ch);
444 @@ -575,7 +576,8 @@ static int iwl6000_hw_channel_switch(str
445         }
446         IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
447                       cmd->switch_time);
448 -       cmd->expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
449 +       cmd->expect_beacon =
450 +               ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
451  
452         err = iwl_dvm_send_cmd(priv, &hcmd);
453         kfree(cmd);
454 --- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
455 +++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
456 @@ -970,7 +970,7 @@ static void iwlagn_mac_channel_switch(st
457  {
458         struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
459         struct ieee80211_conf *conf = &hw->conf;
460 -       struct ieee80211_channel *channel = ch_switch->channel;
461 +       struct ieee80211_channel *channel = ch_switch->chandef.chan;
462         struct iwl_ht_config *ht_conf = &priv->current_ht_config;
463         /*
464          * MULTI-FIXME
465 @@ -1008,11 +1008,21 @@ static void iwlagn_mac_channel_switch(st
466         priv->current_ht_config.smps = conf->smps_mode;
467  
468         /* Configure HT40 channels */
469 -       ctx->ht.enabled = conf_is_ht(conf);
470 -       if (ctx->ht.enabled)
471 -               iwlagn_config_ht40(conf, ctx);
472 -       else
473 +       switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
474 +       case NL80211_CHAN_NO_HT:
475 +       case NL80211_CHAN_HT20:
476                 ctx->ht.is_40mhz = false;
477 +               ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
478 +               break;
479 +       case NL80211_CHAN_HT40MINUS:
480 +               ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
481 +               ctx->ht.is_40mhz = true;
482 +               break;
483 +       case NL80211_CHAN_HT40PLUS:
484 +               ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
485 +               ctx->ht.is_40mhz = true;
486 +               break;
487 +       }
488  
489         if ((le16_to_cpu(ctx->staging.channel) != ch))
490                 ctx->staging.flags = 0;
491 --- a/drivers/net/wireless/iwlwifi/dvm/rxon.c
492 +++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c
493 @@ -1160,7 +1160,7 @@ int iwlagn_commit_rxon(struct iwl_priv *
494  }
495  
496  void iwlagn_config_ht40(struct ieee80211_conf *conf,
497 -       struct iwl_rxon_context *ctx)
498 +                       struct iwl_rxon_context *ctx)
499  {
500         if (conf_is_ht40_minus(conf)) {
501                 ctx->ht.extension_chan_offset =
502 --- a/drivers/net/wireless/mac80211_hwsim.c
503 +++ b/drivers/net/wireless/mac80211_hwsim.c
504 @@ -25,6 +25,7 @@
505  #include <linux/if_arp.h>
506  #include <linux/rtnetlink.h>
507  #include <linux/etherdevice.h>
508 +#include <linux/platform_device.h>
509  #include <linux/debugfs.h>
510  #include <linux/module.h>
511  #include <linux/ktime.h>
512 @@ -717,9 +718,17 @@ static bool mac80211_hwsim_tx_frame_no_n
513         rx_status.flag |= RX_FLAG_MACTIME_START;
514         rx_status.freq = chan->center_freq;
515         rx_status.band = chan->band;
516 -       rx_status.rate_idx = info->control.rates[0].idx;
517 -       if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
518 -               rx_status.flag |= RX_FLAG_HT;
519 +       if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
520 +               rx_status.rate_idx =
521 +                       ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
522 +               rx_status.vht_nss =
523 +                       ieee80211_rate_get_vht_nss(&info->control.rates[0]);
524 +               rx_status.flag |= RX_FLAG_VHT;
525 +       } else {
526 +               rx_status.rate_idx = info->control.rates[0].idx;
527 +               if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
528 +                       rx_status.flag |= RX_FLAG_HT;
529 +       }
530         if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
531                 rx_status.flag |= RX_FLAG_40MHZ;
532         if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
533 @@ -1687,6 +1696,7 @@ static void mac80211_hwsim_free(void)
534                 debugfs_remove(data->debugfs_ps);
535                 debugfs_remove(data->debugfs);
536                 ieee80211_unregister_hw(data->hw);
537 +               device_release_driver(data->dev);
538                 device_unregister(data->dev);
539                 ieee80211_free_hw(data->hw);
540         }
541 @@ -1695,7 +1705,9 @@ static void mac80211_hwsim_free(void)
542  
543  
544  static struct device_driver mac80211_hwsim_driver = {
545 -       .name = "mac80211_hwsim"
546 +       .name = "mac80211_hwsim",
547 +       .bus = &platform_bus_type,
548 +       .owner = THIS_MODULE,
549  };
550  
551  static const struct net_device_ops hwsim_netdev_ops = {
552 @@ -2187,9 +2199,15 @@ static int __init init_mac80211_hwsim(vo
553         spin_lock_init(&hwsim_radio_lock);
554         INIT_LIST_HEAD(&hwsim_radios);
555  
556 +       err = driver_register(&mac80211_hwsim_driver);
557 +       if (err)
558 +               return err;
559 +
560         hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
561 -       if (IS_ERR(hwsim_class))
562 -               return PTR_ERR(hwsim_class);
563 +       if (IS_ERR(hwsim_class)) {
564 +               err = PTR_ERR(hwsim_class);
565 +               goto failed_unregister_driver;
566 +       }
567  
568         memset(addr, 0, ETH_ALEN);
569         addr[0] = 0x02;
570 @@ -2211,12 +2229,20 @@ static int __init init_mac80211_hwsim(vo
571                                           "hwsim%d", i);
572                 if (IS_ERR(data->dev)) {
573                         printk(KERN_DEBUG
574 -                              "mac80211_hwsim: device_create "
575 -                              "failed (%ld)\n", PTR_ERR(data->dev));
576 +                              "mac80211_hwsim: device_create failed (%ld)\n",
577 +                              PTR_ERR(data->dev));
578                         err = -ENOMEM;
579                         goto failed_drvdata;
580                 }
581                 data->dev->driver = &mac80211_hwsim_driver;
582 +               err = device_bind_driver(data->dev);
583 +               if (err != 0) {
584 +                       printk(KERN_DEBUG
585 +                              "mac80211_hwsim: device_bind_driver failed (%d)\n",
586 +                              err);
587 +                       goto failed_hw;
588 +               }
589 +
590                 skb_queue_head_init(&data->pending);
591  
592                 SET_IEEE80211_DEV(hw, data->dev);
593 @@ -2515,6 +2541,8 @@ failed_drvdata:
594         ieee80211_free_hw(hw);
595  failed:
596         mac80211_hwsim_free();
597 +failed_unregister_driver:
598 +       driver_unregister(&mac80211_hwsim_driver);
599         return err;
600  }
601  module_init(init_mac80211_hwsim);
602 @@ -2527,5 +2555,6 @@ static void __exit exit_mac80211_hwsim(v
603  
604         mac80211_hwsim_free();
605         unregister_netdev(hwsim_mon);
606 +       driver_unregister(&mac80211_hwsim_driver);
607  }
608  module_exit(exit_mac80211_hwsim);
609 --- a/drivers/net/wireless/ti/wl12xx/cmd.c
610 +++ b/drivers/net/wireless/ti/wl12xx/cmd.c
611 @@ -301,7 +301,7 @@ int wl12xx_cmd_channel_switch(struct wl1
612         }
613  
614         cmd->role_id = wlvif->role_id;
615 -       cmd->channel = ch_switch->channel->hw_value;
616 +       cmd->channel = ch_switch->chandef.chan->hw_value;
617         cmd->switch_time = ch_switch->count;
618         cmd->stop_tx = ch_switch->block_tx;
619  
620 --- a/drivers/net/wireless/ti/wl18xx/cmd.c
621 +++ b/drivers/net/wireless/ti/wl18xx/cmd.c
622 @@ -42,11 +42,11 @@ int wl18xx_cmd_channel_switch(struct wl1
623         }
624  
625         cmd->role_id = wlvif->role_id;
626 -       cmd->channel = ch_switch->channel->hw_value;
627 +       cmd->channel = ch_switch->chandef.chan->hw_value;
628         cmd->switch_time = ch_switch->count;
629         cmd->stop_tx = ch_switch->block_tx;
630  
631 -       switch (ch_switch->channel->band) {
632 +       switch (ch_switch->chandef.chan->band) {
633         case IEEE80211_BAND_2GHZ:
634                 cmd->band = WLCORE_BAND_2_4GHZ;
635                 break;
636 @@ -55,7 +55,7 @@ int wl18xx_cmd_channel_switch(struct wl1
637                 break;
638         default:
639                 wl1271_error("invalid channel switch band: %d",
640 -                            ch_switch->channel->band);
641 +                            ch_switch->chandef.chan->band);
642                 ret = -EINVAL;
643                 goto out_free;
644         }
645 --- a/include/linux/ieee80211.h
646 +++ b/include/linux/ieee80211.h
647 @@ -673,6 +673,36 @@ struct ieee80211_channel_sw_ie {
648  } __packed;
649  
650  /**
651 + * struct ieee80211_ext_chansw_ie
652 + *
653 + * This structure represents the "Extended Channel Switch Announcement element"
654 + */
655 +struct ieee80211_ext_chansw_ie {
656 +       u8 mode;
657 +       u8 new_operating_class;
658 +       u8 new_ch_num;
659 +       u8 count;
660 +} __packed;
661 +
662 +/**
663 + * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
664 + * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
665 + *     values here
666 + * This structure represents the "Secondary Channel Offset element"
667 + */
668 +struct ieee80211_sec_chan_offs_ie {
669 +       u8 sec_chan_offs;
670 +} __packed;
671 +
672 +/**
673 + * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
674 + */
675 +struct ieee80211_wide_bw_chansw_ie {
676 +       u8 new_channel_width;
677 +       u8 new_center_freq_seg0, new_center_freq_seg1;
678 +} __packed;
679 +
680 +/**
681   * struct ieee80211_tim
682   *
683   * This structure refers to "Traffic Indication Map information element"
684 @@ -840,12 +870,15 @@ struct ieee80211_mgmt {
685                                 } __packed wme_action;
686                                 struct{
687                                         u8 action_code;
688 -                                       u8 element_id;
689 -                                       u8 length;
690 -                                       struct ieee80211_channel_sw_ie sw_elem;
691 +                                       u8 variable[0];
692                                 } __packed chan_switch;
693                                 struct{
694                                         u8 action_code;
695 +                                       struct ieee80211_ext_chansw_ie data;
696 +                                       u8 variable[0];
697 +                               } __packed ext_chan_switch;
698 +                               struct{
699 +                                       u8 action_code;
700                                         u8 dialog_token;
701                                         u8 element_id;
702                                         u8 length;
703 @@ -1638,6 +1671,7 @@ enum ieee80211_eid {
704  
705         WLAN_EID_HT_CAPABILITY = 45,
706         WLAN_EID_HT_OPERATION = 61,
707 +       WLAN_EID_SECONDARY_CHANNEL_OFFSET = 62,
708  
709         WLAN_EID_RSN = 48,
710         WLAN_EID_MMIE = 76,
711 @@ -1672,6 +1706,8 @@ enum ieee80211_eid {
712         WLAN_EID_VHT_CAPABILITY = 191,
713         WLAN_EID_VHT_OPERATION = 192,
714         WLAN_EID_OPMODE_NOTIF = 199,
715 +       WLAN_EID_WIDE_BW_CHANNEL_SWITCH = 194,
716 +       WLAN_EID_CHANNEL_SWITCH_WRAPPER = 196,
717  
718         /* 802.11ad */
719         WLAN_EID_NON_TX_BSSID_CAP =  83,
720 @@ -1795,6 +1831,7 @@ enum ieee80211_key_len {
721  
722  /* Public action codes */
723  enum ieee80211_pub_actioncode {
724 +       WLAN_PUB_ACTION_EXT_CHANSW_ANN = 4,
725         WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
726  };
727  
728 --- a/include/net/cfg80211.h
729 +++ b/include/net/cfg80211.h
730 @@ -753,6 +753,8 @@ int cfg80211_check_station_change(struct
731   * @STATION_INFO_LOCAL_PM: @local_pm filled
732   * @STATION_INFO_PEER_PM: @peer_pm filled
733   * @STATION_INFO_NONPEER_PM: @nonpeer_pm filled
734 + * @STATION_INFO_CHAIN_SIGNAL: @chain_signal filled
735 + * @STATION_INFO_CHAIN_SIGNAL_AVG: @chain_signal_avg filled
736   */
737  enum station_info_flags {
738         STATION_INFO_INACTIVE_TIME      = 1<<0,
739 @@ -781,6 +783,8 @@ enum station_info_flags {
740         STATION_INFO_NONPEER_PM         = 1<<23,
741         STATION_INFO_RX_BYTES64         = 1<<24,
742         STATION_INFO_TX_BYTES64         = 1<<25,
743 +       STATION_INFO_CHAIN_SIGNAL       = 1<<26,
744 +       STATION_INFO_CHAIN_SIGNAL_AVG   = 1<<27,
745  };
746  
747  /**
748 @@ -857,6 +861,8 @@ struct sta_bss_parameters {
749         u16 beacon_interval;
750  };
751  
752 +#define IEEE80211_MAX_CHAINS   4
753 +
754  /**
755   * struct station_info - station information
756   *
757 @@ -874,6 +880,9 @@ struct sta_bss_parameters {
758   *     For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
759   * @signal_avg: Average signal strength, type depends on the wiphy's signal_type.
760   *     For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
761 + * @chains: bitmask for filled values in @chain_signal, @chain_signal_avg
762 + * @chain_signal: per-chain signal strength of last received packet in dBm
763 + * @chain_signal_avg: per-chain signal strength average in dBm
764   * @txrate: current unicast bitrate from this station
765   * @rxrate: current unicast bitrate to this station
766   * @rx_packets: packets received from this station
767 @@ -909,6 +918,11 @@ struct station_info {
768         u8 plink_state;
769         s8 signal;
770         s8 signal_avg;
771 +
772 +       u8 chains;
773 +       s8 chain_signal[IEEE80211_MAX_CHAINS];
774 +       s8 chain_signal_avg[IEEE80211_MAX_CHAINS];
775 +
776         struct rate_info txrate;
777         struct rate_info rxrate;
778         u32 rx_packets;
779 @@ -954,6 +968,7 @@ enum monitor_flags {
780         MONITOR_FLAG_CONTROL            = 1<<NL80211_MNTR_FLAG_CONTROL,
781         MONITOR_FLAG_OTHER_BSS          = 1<<NL80211_MNTR_FLAG_OTHER_BSS,
782         MONITOR_FLAG_COOK_FRAMES        = 1<<NL80211_MNTR_FLAG_COOK_FRAMES,
783 +       MONITOR_FLAG_ACTIVE             = 1<<NL80211_MNTR_FLAG_ACTIVE,
784  };
785  
786  /**
787 @@ -4027,6 +4042,17 @@ bool cfg80211_reg_can_beacon(struct wiph
788  void cfg80211_ch_switch_notify(struct net_device *dev,
789                                struct cfg80211_chan_def *chandef);
790  
791 +/**
792 + * ieee80211_operating_class_to_band - convert operating class to band
793 + *
794 + * @operating_class: the operating class to convert
795 + * @band: band pointer to fill
796 + *
797 + * Returns %true if the conversion was successful, %false otherwise.
798 + */
799 +bool ieee80211_operating_class_to_band(u8 operating_class,
800 +                                      enum ieee80211_band *band);
801 +
802  /*
803   * cfg80211_tdls_oper_request - request userspace to perform TDLS operation
804   * @dev: the device on which the operation is requested
805 --- a/include/net/mac80211.h
806 +++ b/include/net/mac80211.h
807 @@ -210,7 +210,7 @@ struct ieee80211_chanctx_conf {
808   * @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
809   *     that it is only ever disabled for station mode.
810   * @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
811 - * @BSS_CHANGED_SSID: SSID changed for this BSS (AP mode)
812 + * @BSS_CHANGED_SSID: SSID changed for this BSS (AP and IBSS mode)
813   * @BSS_CHANGED_AP_PROBE_RESP: Probe Response changed for this BSS (AP mode)
814   * @BSS_CHANGED_PS: PS changed for this BSS (STA mode)
815   * @BSS_CHANGED_TXPOWER: TX power setting changed for this interface
816 @@ -327,7 +327,7 @@ enum ieee80211_rssi_event {
817   *     your driver/device needs to do.
818   * @ps: power-save mode (STA only). This flag is NOT affected by
819   *     offchannel/dynamic_ps operations.
820 - * @ssid: The SSID of the current vif. Only valid in AP-mode.
821 + * @ssid: The SSID of the current vif. Valid in AP and IBSS mode.
822   * @ssid_len: Length of SSID given in @ssid.
823   * @hidden_ssid: The SSID of the current vif is hidden. Only valid in AP-mode.
824   * @txpower: TX power in dBm
825 @@ -562,6 +562,9 @@ enum mac80211_rate_control_flags {
826  /* maximum number of rate stages */
827  #define IEEE80211_TX_MAX_RATES 4
828  
829 +/* maximum number of rate table entries */
830 +#define IEEE80211_TX_RATE_TABLE_SIZE   4
831 +
832  /**
833   * struct ieee80211_tx_rate - rate selection/status
834   *
835 @@ -602,8 +605,8 @@ static inline void ieee80211_rate_set_vh
836                                           u8 mcs, u8 nss)
837  {
838         WARN_ON(mcs & ~0xF);
839 -       WARN_ON(nss & ~0x7);
840 -       rate->idx = (nss << 4) | mcs;
841 +       WARN_ON((nss - 1) & ~0x7);
842 +       rate->idx = ((nss - 1) << 4) | mcs;
843  }
844  
845  static inline u8
846 @@ -615,7 +618,7 @@ ieee80211_rate_get_vht_mcs(const struct 
847  static inline u8
848  ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate)
849  {
850 -       return rate->idx >> 4;
851 +       return (rate->idx >> 4) + 1;
852  }
853  
854  /**
855 @@ -656,7 +659,11 @@ struct ieee80211_tx_info {
856                                         struct ieee80211_tx_rate rates[
857                                                 IEEE80211_TX_MAX_RATES];
858                                         s8 rts_cts_rate_idx;
859 -                                       /* 3 bytes free */
860 +                                       u8 use_rts:1;
861 +                                       u8 use_cts_prot:1;
862 +                                       u8 short_preamble:1;
863 +                                       u8 skip_table:1;
864 +                                       /* 2 bytes free */
865                                 };
866                                 /* only needed before rate control */
867                                 unsigned long jiffies;
868 @@ -677,6 +684,8 @@ struct ieee80211_tx_info {
869                 struct {
870                         struct ieee80211_tx_rate driver_rates[
871                                 IEEE80211_TX_MAX_RATES];
872 +                       u8 pad[4];
873 +
874                         void *rate_driver_data[
875                                 IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE / sizeof(void *)];
876                 };
877 @@ -840,6 +849,9 @@ enum mac80211_rx_flags {
878   * @signal: signal strength when receiving this frame, either in dBm, in dB or
879   *     unspecified depending on the hardware capabilities flags
880   *     @IEEE80211_HW_SIGNAL_*
881 + * @chains: bitmask of receive chains for which separate signal strength
882 + *     values were filled.
883 + * @chain_signal: per-chain signal strength, same format as @signal
884   * @antenna: antenna used
885   * @rate_idx: index of data rate into band's supported rates or MCS index if
886   *     HT or VHT is used (%RX_FLAG_HT/%RX_FLAG_VHT)
887 @@ -871,6 +883,8 @@ struct ieee80211_rx_status {
888         u8 band;
889         u8 antenna;
890         s8 signal;
891 +       u8 chains;
892 +       s8 chain_signal[IEEE80211_MAX_CHAINS];
893         u8 ampdu_delimiter_crc;
894         u8 vendor_radiotap_align;
895         u8 vendor_radiotap_oui[3];
896 @@ -1018,13 +1032,13 @@ struct ieee80211_conf {
897   *     the driver passed into mac80211.
898   * @block_tx: Indicates whether transmission must be blocked before the
899   *     scheduled channel switch, as indicated by the AP.
900 - * @channel: the new channel to switch to
901 + * @chandef: the new channel to switch to
902   * @count: the number of TBTT's until the channel switch event
903   */
904  struct ieee80211_channel_switch {
905         u64 timestamp;
906         bool block_tx;
907 -       struct ieee80211_channel *channel;
908 +       struct cfg80211_chan_def chandef;
909         u8 count;
910  };
911  
912 @@ -1222,6 +1236,24 @@ enum ieee80211_sta_rx_bandwidth {
913  };
914  
915  /**
916 + * struct ieee80211_sta_rates - station rate selection table
917 + *
918 + * @rcu_head: RCU head used for freeing the table on update
919 + * @rates: transmit rates/flags to be used by default.
920 + *     Overriding entries per-packet is possible by using cb tx control.
921 + */
922 +struct ieee80211_sta_rates {
923 +       struct rcu_head rcu_head;
924 +       struct {
925 +               s8 idx;
926 +               u8 count;
927 +               u8 count_cts;
928 +               u8 count_rts;
929 +               u16 flags;
930 +       } rate[IEEE80211_TX_RATE_TABLE_SIZE];
931 +};
932 +
933 +/**
934   * struct ieee80211_sta - station table entry
935   *
936   * A station table entry represents a station we are possibly
937 @@ -1248,6 +1280,7 @@ enum ieee80211_sta_rx_bandwidth {
938   *     notifications and capabilities. The value is only valid after
939   *     the station moves to associated state.
940   * @smps_mode: current SMPS mode (off, static or dynamic)
941 + * @tx_rates: rate control selection table
942   */
943  struct ieee80211_sta {
944         u32 supp_rates[IEEE80211_NUM_BANDS];
945 @@ -1261,6 +1294,7 @@ struct ieee80211_sta {
946         u8 rx_nss;
947         enum ieee80211_sta_rx_bandwidth bandwidth;
948         enum ieee80211_smps_mode smps_mode;
949 +       struct ieee80211_sta_rates __rcu *rates;
950  
951         /* must be last */
952         u8 drv_priv[0] __aligned(sizeof(void *));
953 @@ -1416,6 +1450,9 @@ struct ieee80211_tx_control {
954   *     for different virtual interfaces. See the doc section on HW queue
955   *     control for more details.
956   *
957 + * @IEEE80211_HW_SUPPORTS_RC_TABLE: The driver supports using a rate
958 + *     selection table provided by the rate control algorithm.
959 + *
960   * @IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF: Use the P2P Device address for any
961   *     P2P Interface. This will be honoured even if more than one interface
962   *     is supported.
963 @@ -1448,6 +1485,7 @@ enum ieee80211_hw_flags {
964         IEEE80211_HW_SUPPORTS_PER_STA_GTK               = 1<<21,
965         IEEE80211_HW_AP_LINK_PS                         = 1<<22,
966         IEEE80211_HW_TX_AMPDU_SETUP_IN_HW               = 1<<23,
967 +       IEEE80211_HW_SUPPORTS_RC_TABLE                  = 1<<24,
968         IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF              = 1<<25,
969         IEEE80211_HW_TIMING_BEACON_ONLY                 = 1<<26,
970  };
971 @@ -3144,6 +3182,25 @@ void ieee80211_sta_set_buffered(struct i
972                                 u8 tid, bool buffered);
973  
974  /**
975 + * ieee80211_get_tx_rates - get the selected transmit rates for a packet
976 + *
977 + * Call this function in a driver with per-packet rate selection support
978 + * to combine the rate info in the packet tx info with the most recent
979 + * rate selection table for the station entry.
980 + *
981 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
982 + * @sta: the receiver station to which this packet is sent.
983 + * @skb: the frame to be transmitted.
984 + * @dest: buffer for extracted rate/retry information
985 + * @max_rates: maximum number of rates to fetch
986 + */
987 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
988 +                           struct ieee80211_sta *sta,
989 +                           struct sk_buff *skb,
990 +                           struct ieee80211_tx_rate *dest,
991 +                           int max_rates);
992 +
993 +/**
994   * ieee80211_tx_status - transmit status callback
995   *
996   * Call this function for all transmitted frames after they have been
997 @@ -4118,7 +4175,7 @@ void ieee80211_send_bar(struct ieee80211
998   *     (deprecated; this will be removed once drivers get updated to use
999   *     rate_idx_mask)
1000   * @rate_idx_mask: user-requested (legacy) rate mask
1001 - * @rate_idx_mcs_mask: user-requested MCS rate mask
1002 + * @rate_idx_mcs_mask: user-requested MCS rate mask (NULL if not in use)
1003   * @bss: whether this frame is sent out in AP or IBSS mode
1004   */
1005  struct ieee80211_tx_rate_control {
1006 @@ -4130,7 +4187,7 @@ struct ieee80211_tx_rate_control {
1007         bool rts, short_preamble;
1008         u8 max_rate_idx;
1009         u32 rate_idx_mask;
1010 -       u8 rate_idx_mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
1011 +       u8 *rate_idx_mcs_mask;
1012         bool bss;
1013  };
1014  
1015 @@ -4219,6 +4276,22 @@ bool rate_usable_index_exists(struct iee
1016         return false;
1017  }
1018  
1019 +/**
1020 + * rate_control_set_rates - pass the sta rate selection to mac80211/driver
1021 + *
1022 + * When not doing a rate control probe to test rates, rate control should pass
1023 + * its rate selection to mac80211. If the driver supports receiving a station
1024 + * rate table, it will use it to ensure that frames are always sent based on
1025 + * the most recent rate control module decision.
1026 + *
1027 + * @hw: pointer as obtained from ieee80211_alloc_hw()
1028 + * @pubsta: &struct ieee80211_sta pointer to the target destination.
1029 + * @rates: new tx rate set to be used for this station.
1030 + */
1031 +int rate_control_set_rates(struct ieee80211_hw *hw,
1032 +                          struct ieee80211_sta *pubsta,
1033 +                          struct ieee80211_sta_rates *rates);
1034 +
1035  int ieee80211_rate_control_register(struct rate_control_ops *ops);
1036  void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
1037  
1038 --- a/net/mac80211/agg-rx.c
1039 +++ b/net/mac80211/agg-rx.c
1040 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
1041                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1042         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1043                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
1044 +       else if (sdata->vif.type == NL80211_IFTYPE_WDS)
1045 +               memcpy(mgmt->bssid, da, ETH_ALEN);
1046  
1047         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1048                                           IEEE80211_STYPE_ACTION);
1049 --- a/net/mac80211/agg-tx.c
1050 +++ b/net/mac80211/agg-tx.c
1051 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
1052         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1053         if (sdata->vif.type == NL80211_IFTYPE_AP ||
1054             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1055 -           sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
1056 +           sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
1057 +           sdata->vif.type == NL80211_IFTYPE_WDS)
1058                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
1059         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
1060                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1061 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
1062             sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1063             sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1064             sdata->vif.type != NL80211_IFTYPE_AP &&
1065 +           sdata->vif.type != NL80211_IFTYPE_WDS &&
1066             sdata->vif.type != NL80211_IFTYPE_ADHOC)
1067                 return -EINVAL;
1068  
1069 --- a/net/mac80211/cfg.c
1070 +++ b/net/mac80211/cfg.c
1071 @@ -73,16 +73,19 @@ static int ieee80211_change_iface(struct
1072                 struct ieee80211_local *local = sdata->local;
1073  
1074                 if (ieee80211_sdata_running(sdata)) {
1075 +                       u32 mask = MONITOR_FLAG_COOK_FRAMES |
1076 +                                  MONITOR_FLAG_ACTIVE;
1077 +
1078                         /*
1079 -                        * Prohibit MONITOR_FLAG_COOK_FRAMES to be
1080 -                        * changed while the interface is up.
1081 +                        * Prohibit MONITOR_FLAG_COOK_FRAMES and
1082 +                        * MONITOR_FLAG_ACTIVE to be changed while the
1083 +                        * interface is up.
1084                          * Else we would need to add a lot of cruft
1085                          * to update everything:
1086                          *      cooked_mntrs, monitor and all fif_* counters
1087                          *      reconfigure hardware
1088                          */
1089 -                       if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
1090 -                           (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1091 +                       if ((*flags & mask) != (sdata->u.mntr_flags & mask))
1092                                 return -EBUSY;
1093  
1094                         ieee80211_adjust_monitor_flags(sdata, -1);
1095 @@ -444,7 +447,7 @@ static void sta_set_sinfo(struct sta_inf
1096         struct ieee80211_local *local = sdata->local;
1097         struct timespec uptime;
1098         u64 packets = 0;
1099 -       int ac;
1100 +       int i, ac;
1101  
1102         sinfo->generation = sdata->local->sta_generation;
1103  
1104 @@ -488,6 +491,17 @@ static void sta_set_sinfo(struct sta_inf
1105                         sinfo->signal = (s8)sta->last_signal;
1106                 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
1107         }
1108 +       if (sta->chains) {
1109 +               sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
1110 +                                STATION_INFO_CHAIN_SIGNAL_AVG;
1111 +
1112 +               sinfo->chains = sta->chains;
1113 +               for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1114 +                       sinfo->chain_signal[i] = sta->chain_signal_last[i];
1115 +                       sinfo->chain_signal_avg[i] =
1116 +                               (s8) -ewma_read(&sta->chain_signal_avg[i]);
1117 +               }
1118 +       }
1119  
1120         sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
1121         sta_set_rate_info_rx(sta, &sinfo->rxrate);
1122 @@ -1052,6 +1066,7 @@ static int ieee80211_stop_ap(struct wiph
1123         ieee80211_free_keys(sdata);
1124  
1125         sdata->vif.bss_conf.enable_beacon = false;
1126 +       sdata->vif.bss_conf.ssid_len = 0;
1127         clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1128         ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1129  
1130 @@ -2416,9 +2431,22 @@ static int ieee80211_set_bitrate_mask(st
1131         }
1132  
1133         for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1134 +               struct ieee80211_supported_band *sband = wiphy->bands[i];
1135 +               int j;
1136 +
1137                 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1138                 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1139                        sizeof(mask->control[i].mcs));
1140 +
1141 +               sdata->rc_has_mcs_mask[i] = false;
1142 +               if (!sband)
1143 +                       continue;
1144 +
1145 +               for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
1146 +                       if (~sdata->rc_rateidx_mcs_mask[i][j]) {
1147 +                               sdata->rc_has_mcs_mask[i] = true;
1148 +                               break;
1149 +                       }
1150         }
1151  
1152         return 0;
1153 --- a/net/mac80211/chan.c
1154 +++ b/net/mac80211/chan.c
1155 @@ -57,6 +57,22 @@ ieee80211_find_chanctx(struct ieee80211_
1156         return NULL;
1157  }
1158  
1159 +static bool ieee80211_is_radar_required(struct ieee80211_local *local)
1160 +{
1161 +       struct ieee80211_sub_if_data *sdata;
1162 +
1163 +       rcu_read_lock();
1164 +       list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1165 +               if (sdata->radar_required) {
1166 +                       rcu_read_unlock();
1167 +                       return true;
1168 +               }
1169 +       }
1170 +       rcu_read_unlock();
1171 +
1172 +       return false;
1173 +}
1174 +
1175  static struct ieee80211_chanctx *
1176  ieee80211_new_chanctx(struct ieee80211_local *local,
1177                       const struct cfg80211_chan_def *chandef,
1178 @@ -76,6 +92,9 @@ ieee80211_new_chanctx(struct ieee80211_l
1179         ctx->conf.rx_chains_static = 1;
1180         ctx->conf.rx_chains_dynamic = 1;
1181         ctx->mode = mode;
1182 +       ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
1183 +       if (!local->use_chanctx)
1184 +               local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
1185  
1186         /* acquire mutex to prevent idle from changing */
1187         mutex_lock(&local->mtx);
1188 @@ -110,6 +129,7 @@ ieee80211_new_chanctx(struct ieee80211_l
1189  static void ieee80211_free_chanctx(struct ieee80211_local *local,
1190                                    struct ieee80211_chanctx *ctx)
1191  {
1192 +       bool check_single_channel = false;
1193         lockdep_assert_held(&local->chanctx_mtx);
1194  
1195         WARN_ON_ONCE(ctx->refcount != 0);
1196 @@ -119,6 +139,14 @@ static void ieee80211_free_chanctx(struc
1197                 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1198                 chandef->center_freq1 = chandef->chan->center_freq;
1199                 chandef->center_freq2 = 0;
1200 +
1201 +               /* NOTE: Disabling radar is only valid here for
1202 +                * single channel context. To be sure, check it ...
1203 +                */
1204 +               if (local->hw.conf.radar_enabled)
1205 +                       check_single_channel = true;
1206 +               local->hw.conf.radar_enabled = false;
1207 +
1208                 ieee80211_hw_config(local, 0);
1209         } else {
1210                 drv_remove_chanctx(local, ctx);
1211 @@ -127,6 +155,9 @@ static void ieee80211_free_chanctx(struc
1212         list_del_rcu(&ctx->list);
1213         kfree_rcu(ctx, rcu_head);
1214  
1215 +       /* throw a warning if this wasn't the only channel context. */
1216 +       WARN_ON(check_single_channel && !list_empty(&local->chanctx_list));
1217 +
1218         mutex_lock(&local->mtx);
1219         ieee80211_recalc_idle(local);
1220         mutex_unlock(&local->mtx);
1221 @@ -238,19 +269,11 @@ static void __ieee80211_vif_release_chan
1222  void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
1223                                     struct ieee80211_chanctx *chanctx)
1224  {
1225 -       struct ieee80211_sub_if_data *sdata;
1226 -       bool radar_enabled = false;
1227 +       bool radar_enabled;
1228  
1229         lockdep_assert_held(&local->chanctx_mtx);
1230  
1231 -       rcu_read_lock();
1232 -       list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1233 -               if (sdata->radar_required) {
1234 -                       radar_enabled = true;
1235 -                       break;
1236 -               }
1237 -       }
1238 -       rcu_read_unlock();
1239 +       radar_enabled = ieee80211_is_radar_required(local);
1240  
1241         if (radar_enabled == chanctx->conf.radar_enabled)
1242                 return;
1243 --- a/net/mac80211/debugfs_sta.c
1244 +++ b/net/mac80211/debugfs_sta.c
1245 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
1246         test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
1247  
1248         int res = scnprintf(buf, sizeof(buf),
1249 -                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1250 +                           "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1251                             TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
1252                             TEST(PS_DRIVER), TEST(AUTHORIZED),
1253                             TEST(SHORT_PREAMBLE),
1254 -                           TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
1255 +                           TEST(WME), TEST(CLEAR_PS_FILT),
1256                             TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
1257                             TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
1258                             TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
1259 --- a/net/mac80211/ibss.c
1260 +++ b/net/mac80211/ibss.c
1261 @@ -209,6 +209,8 @@ static void __ieee80211_sta_join_ibss(st
1262         sdata->vif.bss_conf.enable_beacon = true;
1263         sdata->vif.bss_conf.beacon_int = beacon_int;
1264         sdata->vif.bss_conf.basic_rates = basic_rates;
1265 +       sdata->vif.bss_conf.ssid_len = ifibss->ssid_len;
1266 +       memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len);
1267         bss_change = BSS_CHANGED_BEACON_INT;
1268         bss_change |= ieee80211_reset_erp_info(sdata);
1269         bss_change |= BSS_CHANGED_BSSID;
1270 @@ -217,6 +219,7 @@ static void __ieee80211_sta_join_ibss(st
1271         bss_change |= BSS_CHANGED_BASIC_RATES;
1272         bss_change |= BSS_CHANGED_HT;
1273         bss_change |= BSS_CHANGED_IBSS;
1274 +       bss_change |= BSS_CHANGED_SSID;
1275  
1276         /*
1277          * In 5 GHz/802.11a, we can always use short slot time.
1278 @@ -911,7 +914,7 @@ void ieee80211_rx_mgmt_probe_beacon(stru
1279                 return;
1280  
1281         ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1282 -                               &elems);
1283 +                              false, &elems);
1284  
1285         ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1286  }
1287 @@ -1159,6 +1162,7 @@ int ieee80211_ibss_leave(struct ieee8021
1288         sdata->vif.bss_conf.ibss_joined = false;
1289         sdata->vif.bss_conf.ibss_creator = false;
1290         sdata->vif.bss_conf.enable_beacon = false;
1291 +       sdata->vif.bss_conf.ssid_len = 0;
1292         clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1293         ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1294                                                 BSS_CHANGED_IBSS);
1295 --- a/net/mac80211/ieee80211_i.h
1296 +++ b/net/mac80211/ieee80211_i.h
1297 @@ -156,6 +156,7 @@ struct ieee80211_tx_data {
1298         struct ieee80211_sub_if_data *sdata;
1299         struct sta_info *sta;
1300         struct ieee80211_key *key;
1301 +       struct ieee80211_tx_rate rate;
1302  
1303         unsigned int flags;
1304  };
1305 @@ -740,6 +741,8 @@ struct ieee80211_sub_if_data {
1306  
1307         /* bitmap of allowed (non-MCS) rate indexes for rate control */
1308         u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
1309 +
1310 +       bool rc_has_mcs_mask[IEEE80211_NUM_BANDS];
1311         u8  rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN];
1312  
1313         union {
1314 @@ -1025,7 +1028,7 @@ struct ieee80211_local {
1315         enum mac80211_scan_state next_scan_state;
1316         struct delayed_work scan_work;
1317         struct ieee80211_sub_if_data __rcu *scan_sdata;
1318 -       struct ieee80211_channel *csa_channel;
1319 +       struct cfg80211_chan_def csa_chandef;
1320         /* For backward compatibility only -- do not use */
1321         struct cfg80211_chan_def _oper_chandef;
1322  
1323 @@ -1184,10 +1187,13 @@ struct ieee802_11_elems {
1324         const u8 *perr;
1325         const struct ieee80211_rann_ie *rann;
1326         const struct ieee80211_channel_sw_ie *ch_switch_ie;
1327 +       const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1328 +       const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1329         const u8 *country_elem;
1330         const u8 *pwr_constr_elem;
1331         const struct ieee80211_timeout_interval_ie *timeout_int;
1332         const u8 *opmode_notif;
1333 +       const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1334  
1335         /* length of them, respectively */
1336         u8 ssid_len;
1337 @@ -1258,10 +1264,6 @@ void ieee80211_recalc_ps_vif(struct ieee
1338  int ieee80211_max_network_latency(struct notifier_block *nb,
1339                                   unsigned long data, void *dummy);
1340  int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1341 -void
1342 -ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1343 -                                const struct ieee80211_channel_sw_ie *sw_elem,
1344 -                                struct ieee80211_bss *bss, u64 timestamp);
1345  void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1346  void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1347                                   struct sk_buff *skb);
1348 @@ -1499,13 +1501,13 @@ static inline void ieee80211_tx_skb(stru
1349         ieee80211_tx_skb_tid(sdata, skb, 7);
1350  }
1351  
1352 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1353 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
1354                                struct ieee802_11_elems *elems,
1355                                u64 filter, u32 crc);
1356 -static inline void ieee802_11_parse_elems(u8 *start, size_t len,
1357 +static inline void ieee802_11_parse_elems(u8 *start, size_t len, bool action,
1358                                           struct ieee802_11_elems *elems)
1359  {
1360 -       ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
1361 +       ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0);
1362  }
1363  
1364  u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1365 --- a/net/mac80211/iface.c
1366 +++ b/net/mac80211/iface.c
1367 @@ -159,7 +159,8 @@ static int ieee80211_change_mtu(struct n
1368         return 0;
1369  }
1370  
1371 -static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)
1372 +static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr,
1373 +                               bool check_dup)
1374  {
1375         struct ieee80211_sub_if_data *sdata;
1376         u64 new, mask, tmp;
1377 @@ -179,10 +180,13 @@ static int ieee80211_verify_mac(struct i
1378                 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
1379                 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
1380  
1381 +       if (!check_dup)
1382 +               return ret;
1383  
1384         mutex_lock(&local->iflist_mtx);
1385         list_for_each_entry(sdata, &local->interfaces, list) {
1386 -               if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1387 +               if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1388 +                   !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1389                         continue;
1390  
1391                 m = sdata->vif.addr;
1392 @@ -204,12 +208,17 @@ static int ieee80211_change_mac(struct n
1393  {
1394         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1395         struct sockaddr *sa = addr;
1396 +       bool check_dup = true;
1397         int ret;
1398  
1399         if (ieee80211_sdata_running(sdata))
1400                 return -EBUSY;
1401  
1402 -       ret = ieee80211_verify_mac(sdata->local, sa->sa_data);
1403 +       if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1404 +           !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1405 +               check_dup = false;
1406 +
1407 +       ret = ieee80211_verify_mac(sdata->local, sa->sa_data, check_dup);
1408         if (ret)
1409                 return ret;
1410  
1411 @@ -450,7 +459,6 @@ int ieee80211_do_open(struct wireless_de
1412         struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1413         struct net_device *dev = wdev->netdev;
1414         struct ieee80211_local *local = sdata->local;
1415 -       struct sta_info *sta;
1416         u32 changed = 0;
1417         int res;
1418         u32 hw_reconf_flags = 0;
1419 @@ -474,6 +482,9 @@ int ieee80211_do_open(struct wireless_de
1420                         master->control_port_protocol;
1421                 sdata->control_port_no_encrypt =
1422                         master->control_port_no_encrypt;
1423 +               sdata->vif.cab_queue = master->vif.cab_queue;
1424 +               memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
1425 +                      sizeof(sdata->vif.hw_queue));
1426                 break;
1427                 }
1428         case NL80211_IFTYPE_AP:
1429 @@ -538,7 +549,11 @@ int ieee80211_do_open(struct wireless_de
1430                         break;
1431                 }
1432  
1433 -               if (local->monitors == 0 && local->open_count == 0) {
1434 +               if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
1435 +                       res = drv_add_interface(local, sdata);
1436 +                       if (res)
1437 +                               goto err_stop;
1438 +               } else if (local->monitors == 0 && local->open_count == 0) {
1439                         res = ieee80211_add_virtual_monitor(local);
1440                         if (res)
1441                                 goto err_stop;
1442 @@ -609,30 +624,8 @@ int ieee80211_do_open(struct wireless_de
1443  
1444         set_bit(SDATA_STATE_RUNNING, &sdata->state);
1445  
1446 -       if (sdata->vif.type == NL80211_IFTYPE_WDS) {
1447 -               /* Create STA entry for the WDS peer */
1448 -               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1449 -                                    GFP_KERNEL);
1450 -               if (!sta) {
1451 -                       res = -ENOMEM;
1452 -                       goto err_del_interface;
1453 -               }
1454 -
1455 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1456 -               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1457 -               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1458 -
1459 -               res = sta_info_insert(sta);
1460 -               if (res) {
1461 -                       /* STA has been freed */
1462 -                       goto err_del_interface;
1463 -               }
1464 -
1465 -               rate_control_rate_init(sta);
1466 -               netif_carrier_on(dev);
1467 -       } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
1468 +       if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
1469                 rcu_assign_pointer(local->p2p_sdata, sdata);
1470 -       }
1471  
1472         /*
1473          * set_multicast_list will be invoked by the networking core
1474 @@ -653,7 +646,11 @@ int ieee80211_do_open(struct wireless_de
1475  
1476         ieee80211_recalc_ps(local, -1);
1477  
1478 -       if (dev) {
1479 +       if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1480 +           sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1481 +               /* XXX: for AP_VLAN, actually track AP queues */
1482 +               netif_tx_start_all_queues(dev);
1483 +       } else if (dev) {
1484                 unsigned long flags;
1485                 int n_acs = IEEE80211_NUM_ACS;
1486                 int ac;
1487 @@ -916,7 +913,11 @@ static void ieee80211_do_stop(struct iee
1488                 mutex_lock(&local->mtx);
1489                 ieee80211_recalc_idle(local);
1490                 mutex_unlock(&local->mtx);
1491 -               break;
1492 +
1493 +               if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1494 +                       break;
1495 +
1496 +               /* fall through */
1497         default:
1498                 if (going_down)
1499                         drv_remove_interface(local, sdata);
1500 @@ -1075,7 +1076,7 @@ static const struct net_device_ops ieee8
1501         .ndo_start_xmit         = ieee80211_monitor_start_xmit,
1502         .ndo_set_rx_mode        = ieee80211_set_multicast_list,
1503         .ndo_change_mtu         = ieee80211_change_mtu,
1504 -       .ndo_set_mac_address    = eth_mac_addr,
1505 +       .ndo_set_mac_address    = ieee80211_change_mac,
1506         .ndo_select_queue       = ieee80211_monitor_select_queue,
1507  };
1508  
1509 @@ -1092,6 +1093,74 @@ static void ieee80211_if_setup(struct ne
1510         dev->destructor = free_netdev;
1511  }
1512  
1513 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1514 +                                        struct sk_buff *skb)
1515 +{
1516 +       struct ieee80211_local *local = sdata->local;
1517 +       struct ieee80211_rx_status *rx_status;
1518 +       struct ieee802_11_elems elems;
1519 +       struct ieee80211_mgmt *mgmt;
1520 +       struct sta_info *sta;
1521 +       size_t baselen;
1522 +       u32 rates = 0;
1523 +       u16 stype;
1524 +       bool new = false;
1525 +       enum ieee80211_band band;
1526 +       struct ieee80211_supported_band *sband;
1527 +
1528 +       rx_status = IEEE80211_SKB_RXCB(skb);
1529 +       band = rx_status->band;
1530 +       sband = local->hw.wiphy->bands[band];
1531 +       mgmt = (struct ieee80211_mgmt *) skb->data;
1532 +       stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1533 +
1534 +       if (stype != IEEE80211_STYPE_BEACON)
1535 +               return;
1536 +
1537 +       baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1538 +       if (baselen > skb->len)
1539 +               return;
1540 +
1541 +       ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1542 +                              skb->len - baselen, false, &elems);
1543 +
1544 +       rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
1545 +
1546 +       rcu_read_lock();
1547 +
1548 +       sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
1549 +
1550 +       if (!sta) {
1551 +               rcu_read_unlock();
1552 +               sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1553 +                                    GFP_KERNEL);
1554 +               if (!sta)
1555 +                       return;
1556 +
1557 +               new = true;
1558 +       }
1559 +
1560 +       sta->last_rx = jiffies;
1561 +       sta->sta.supp_rates[band] = rates;
1562 +
1563 +       if (elems.ht_cap_elem)
1564 +               ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1565 +                               elems.ht_cap_elem, sta);
1566 +
1567 +       if (elems.wmm_param)
1568 +               set_sta_flag(sta, WLAN_STA_WME);
1569 +
1570 +       if (new) {
1571 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1572 +               sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1573 +               sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1574 +               rate_control_rate_init(sta);
1575 +               sta_info_insert_rcu(sta);
1576 +       }
1577 +
1578 +       rcu_read_unlock();
1579 +}
1580 +
1581  static void ieee80211_iface_work(struct work_struct *work)
1582  {
1583         struct ieee80211_sub_if_data *sdata =
1584 @@ -1196,6 +1265,9 @@ static void ieee80211_iface_work(struct 
1585                                 break;
1586                         ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1587                         break;
1588 +               case NL80211_IFTYPE_WDS:
1589 +                       ieee80211_wds_rx_queued_mgmt(sdata, skb);
1590 +                       break;
1591                 default:
1592                         WARN(1, "frame for unexpected interface type");
1593                         break;
1594 @@ -1718,6 +1790,15 @@ void ieee80211_remove_interfaces(struct 
1595  
1596         ASSERT_RTNL();
1597  
1598 +       /*
1599 +        * Close all AP_VLAN interfaces first, as otherwise they
1600 +        * might be closed while the AP interface they belong to
1601 +        * is closed, causing unregister_netdevice_many() to crash.
1602 +        */
1603 +       list_for_each_entry(sdata, &local->interfaces, list)
1604 +               if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1605 +                       dev_close(sdata->dev);
1606 +
1607         mutex_lock(&local->iflist_mtx);
1608         list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1609                 list_del(&sdata->list);
1610 --- a/net/mac80211/main.c
1611 +++ b/net/mac80211/main.c
1612 @@ -674,6 +674,7 @@ int ieee80211_register_hw(struct ieee802
1613         int channels, max_bitrates;
1614         bool supp_ht, supp_vht;
1615         netdev_features_t feature_whitelist;
1616 +       struct cfg80211_chan_def dflt_chandef = {};
1617         static const u32 cipher_suites[] = {
1618                 /* keep WEP first, it may be removed below */
1619                 WLAN_CIPHER_SUITE_WEP40,
1620 @@ -751,19 +752,19 @@ int ieee80211_register_hw(struct ieee802
1621                 sband = local->hw.wiphy->bands[band];
1622                 if (!sband)
1623                         continue;
1624 -               if (!local->use_chanctx && !local->_oper_chandef.chan) {
1625 +
1626 +               if (!dflt_chandef.chan) {
1627 +                       cfg80211_chandef_create(&dflt_chandef,
1628 +                                               &sband->channels[0],
1629 +                                               NL80211_CHAN_NO_HT);
1630                         /* init channel we're on */
1631 -                       struct cfg80211_chan_def chandef = {
1632 -                               .chan = &sband->channels[0],
1633 -                               .width = NL80211_CHAN_NO_HT,
1634 -                               .center_freq1 = sband->channels[0].center_freq,
1635 -                               .center_freq2 = 0
1636 -                       };
1637 -                       local->hw.conf.chandef = local->_oper_chandef = chandef;
1638 +                       if (!local->use_chanctx && !local->_oper_chandef.chan) {
1639 +                               local->hw.conf.chandef = dflt_chandef;
1640 +                               local->_oper_chandef = dflt_chandef;
1641 +                       }
1642 +                       local->monitor_chandef = dflt_chandef;
1643                 }
1644 -               cfg80211_chandef_create(&local->monitor_chandef,
1645 -                                       &sband->channels[0],
1646 -                                       NL80211_CHAN_NO_HT);
1647 +
1648                 channels += sband->n_channels;
1649  
1650                 if (max_bitrates < sband->n_bitrates)
1651 --- a/net/mac80211/mesh.c
1652 +++ b/net/mac80211/mesh.c
1653 @@ -838,7 +838,7 @@ ieee80211_mesh_rx_probe_req(struct ieee8
1654         if (baselen > len)
1655                 return;
1656  
1657 -       ieee802_11_parse_elems(pos, len - baselen, &elems);
1658 +       ieee802_11_parse_elems(pos, len - baselen, false, &elems);
1659  
1660         /* 802.11-2012 10.1.4.3.2 */
1661         if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
1662 @@ -899,7 +899,7 @@ static void ieee80211_mesh_rx_bcn_presp(
1663                 return;
1664  
1665         ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1666 -                              &elems);
1667 +                              false, &elems);
1668  
1669         /* ignore non-mesh or secure / unsecure mismatch */
1670         if ((!elems.mesh_id || !elems.mesh_config) ||
1671 --- a/net/mac80211/mesh_hwmp.c
1672 +++ b/net/mac80211/mesh_hwmp.c
1673 @@ -880,7 +880,7 @@ void mesh_rx_path_sel_frame(struct ieee8
1674  
1675         baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
1676         ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
1677 -                       len - baselen, &elems);
1678 +                              len - baselen, false, &elems);
1679  
1680         if (elems.preq) {
1681                 if (elems.preq_len != 37)
1682 --- a/net/mac80211/mesh_plink.c
1683 +++ b/net/mac80211/mesh_plink.c
1684 @@ -544,8 +544,8 @@ static void mesh_plink_timer(unsigned lo
1685                 return;
1686         }
1687         mpl_dbg(sta->sdata,
1688 -               "Mesh plink timer for %pM fired on state %d\n",
1689 -               sta->sta.addr, sta->plink_state);
1690 +               "Mesh plink timer for %pM fired on state %s\n",
1691 +               sta->sta.addr, mplstates[sta->plink_state]);
1692         reason = 0;
1693         llid = sta->llid;
1694         plid = sta->plid;
1695 @@ -687,7 +687,7 @@ void mesh_rx_plink_frame(struct ieee8021
1696                 baseaddr += 4;
1697                 baselen += 4;
1698         }
1699 -       ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
1700 +       ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1701  
1702         if (!elems.peering) {
1703                 mpl_dbg(sdata,
1704 --- a/net/mac80211/mlme.c
1705 +++ b/net/mac80211/mlme.c
1706 @@ -289,6 +289,8 @@ ieee80211_determine_chantype(struct ieee
1707         } else {
1708                 /* 40 MHz (and 80 MHz) must be supported for VHT */
1709                 ret = IEEE80211_STA_DISABLE_VHT;
1710 +               /* also mark 40 MHz disabled */
1711 +               ret |= IEEE80211_STA_DISABLE_40MHZ;
1712                 goto out;
1713         }
1714  
1715 @@ -303,12 +305,6 @@ ieee80211_determine_chantype(struct ieee
1716                                                channel->band);
1717         vht_chandef.center_freq2 = 0;
1718  
1719 -       if (vht_oper->center_freq_seg2_idx)
1720 -               vht_chandef.center_freq2 =
1721 -                       ieee80211_channel_to_frequency(
1722 -                               vht_oper->center_freq_seg2_idx,
1723 -                               channel->band);
1724 -
1725         switch (vht_oper->chan_width) {
1726         case IEEE80211_VHT_CHANWIDTH_USE_HT:
1727                 vht_chandef.width = chandef->width;
1728 @@ -321,6 +317,10 @@ ieee80211_determine_chantype(struct ieee
1729                 break;
1730         case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1731                 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1732 +               vht_chandef.center_freq2 =
1733 +                       ieee80211_channel_to_frequency(
1734 +                               vht_oper->center_freq_seg2_idx,
1735 +                               channel->band);
1736                 break;
1737         default:
1738                 if (verbose)
1739 @@ -604,7 +604,6 @@ static void ieee80211_add_vht_ie(struct 
1740         u8 *pos;
1741         u32 cap;
1742         struct ieee80211_sta_vht_cap vht_cap;
1743 -       int i;
1744  
1745         BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
1746  
1747 @@ -632,37 +631,6 @@ static void ieee80211_add_vht_ie(struct 
1748                         cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
1749                 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1750  
1751 -       if (!(ap_vht_cap->vht_cap_info &
1752 -                       cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
1753 -               cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
1754 -                        IEEE80211_VHT_CAP_RXSTBC_3 |
1755 -                        IEEE80211_VHT_CAP_RXSTBC_4);
1756 -
1757 -       for (i = 0; i < 8; i++) {
1758 -               int shift = i * 2;
1759 -               u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
1760 -               u16 ap_mcs, our_mcs;
1761 -
1762 -               ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
1763 -                                                               mask) >> shift;
1764 -               our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
1765 -                                                               mask) >> shift;
1766 -
1767 -               if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
1768 -                       continue;
1769 -
1770 -               switch (ap_mcs) {
1771 -               default:
1772 -                       if (our_mcs <= ap_mcs)
1773 -                               break;
1774 -                       /* fall through */
1775 -               case IEEE80211_VHT_MCS_NOT_SUPPORTED:
1776 -                       vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
1777 -                       vht_cap.vht_mcs.rx_mcs_map |=
1778 -                               cpu_to_le16(ap_mcs << shift);
1779 -               }
1780 -       }
1781 -
1782         /* reserve and fill IE */
1783         pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
1784         ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
1785 @@ -998,16 +966,7 @@ static void ieee80211_chswitch_work(stru
1786         if (!ifmgd->associated)
1787                 goto out;
1788  
1789 -       /*
1790 -        * FIXME: Here we are downgrading to NL80211_CHAN_WIDTH_20_NOHT
1791 -        * and don't adjust our ht/vht settings
1792 -        * This is wrong - we should behave according to the CSA params
1793 -        */
1794 -       local->_oper_chandef.chan = local->csa_channel;
1795 -       local->_oper_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
1796 -       local->_oper_chandef.center_freq1 =
1797 -               local->_oper_chandef.chan->center_freq;
1798 -       local->_oper_chandef.center_freq2 = 0;
1799 +       local->_oper_chandef = local->csa_chandef;
1800  
1801         if (!local->ops->channel_switch) {
1802                 /* call "hw_config" only if doing sw channel switch */
1803 @@ -1054,56 +1013,208 @@ static void ieee80211_chswitch_timer(uns
1804         ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1805  }
1806  
1807 -void
1808 +static void
1809  ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1810 -                                const struct ieee80211_channel_sw_ie *sw_elem,
1811 -                                struct ieee80211_bss *bss, u64 timestamp)
1812 +                                u64 timestamp, struct ieee802_11_elems *elems,
1813 +                                bool beacon)
1814  {
1815 -       struct cfg80211_bss *cbss =
1816 -               container_of((void *)bss, struct cfg80211_bss, priv);
1817 -       struct ieee80211_channel *new_ch;
1818 +       struct ieee80211_local *local = sdata->local;
1819         struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1820 -       int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
1821 -                                                     cbss->channel->band);
1822 +       struct cfg80211_bss *cbss = ifmgd->associated;
1823 +       struct ieee80211_bss *bss;
1824         struct ieee80211_chanctx *chanctx;
1825 +       enum ieee80211_band new_band;
1826 +       int new_freq;
1827 +       u8 new_chan_no;
1828 +       u8 count;
1829 +       u8 mode;
1830 +       struct ieee80211_channel *new_chan;
1831 +       struct cfg80211_chan_def new_chandef = {};
1832 +       struct cfg80211_chan_def new_vht_chandef = {};
1833 +       const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1834 +       const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1835 +       const struct ieee80211_ht_operation *ht_oper;
1836 +       int secondary_channel_offset = -1;
1837  
1838         ASSERT_MGD_MTX(ifmgd);
1839  
1840 -       if (!ifmgd->associated)
1841 +       if (!cbss)
1842 +               return;
1843 +
1844 +       if (local->scanning)
1845                 return;
1846  
1847 -       if (sdata->local->scanning)
1848 +       /* disregard subsequent announcements if we are already processing */
1849 +       if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1850                 return;
1851  
1852 -       /* Disregard subsequent beacons if we are already running a timer
1853 -          processing a CSA */
1854 +       sec_chan_offs = elems->sec_chan_offs;
1855 +       wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
1856 +       ht_oper = elems->ht_operation;
1857 +
1858 +       if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1859 +                           IEEE80211_STA_DISABLE_40MHZ)) {
1860 +               sec_chan_offs = NULL;
1861 +               wide_bw_chansw_ie = NULL;
1862 +               /* only used for bandwidth here */
1863 +               ht_oper = NULL;
1864 +       }
1865  
1866 -       if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1867 +       if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1868 +               wide_bw_chansw_ie = NULL;
1869 +
1870 +       if (elems->ext_chansw_ie) {
1871 +               if (!ieee80211_operating_class_to_band(
1872 +                               elems->ext_chansw_ie->new_operating_class,
1873 +                               &new_band)) {
1874 +                       sdata_info(sdata,
1875 +                                  "cannot understand ECSA IE operating class %d, disconnecting\n",
1876 +                                  elems->ext_chansw_ie->new_operating_class);
1877 +                       ieee80211_queue_work(&local->hw,
1878 +                                            &ifmgd->csa_connection_drop_work);
1879 +               }
1880 +               new_chan_no = elems->ext_chansw_ie->new_ch_num;
1881 +               count = elems->ext_chansw_ie->count;
1882 +               mode = elems->ext_chansw_ie->mode;
1883 +       } else if (elems->ch_switch_ie) {
1884 +               new_band = cbss->channel->band;
1885 +               new_chan_no = elems->ch_switch_ie->new_ch_num;
1886 +               count = elems->ch_switch_ie->count;
1887 +               mode = elems->ch_switch_ie->mode;
1888 +       } else {
1889 +               /* nothing here we understand */
1890                 return;
1891 +       }
1892 +
1893 +       bss = (void *)cbss->priv;
1894  
1895 -       new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1896 -       if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
1897 +       new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
1898 +       new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1899 +       if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
1900                 sdata_info(sdata,
1901                            "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1902                            ifmgd->associated->bssid, new_freq);
1903 -               ieee80211_queue_work(&sdata->local->hw,
1904 +               ieee80211_queue_work(&local->hw,
1905 +                                    &ifmgd->csa_connection_drop_work);
1906 +               return;
1907 +       }
1908 +
1909 +       if (!beacon && sec_chan_offs) {
1910 +               secondary_channel_offset = sec_chan_offs->sec_chan_offs;
1911 +       } else if (beacon && ht_oper) {
1912 +               secondary_channel_offset =
1913 +                       ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
1914 +       } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
1915 +               /*
1916 +                * If it's not a beacon, HT is enabled and the IE not present,
1917 +                * it's 20 MHz, 802.11-2012 8.5.2.6:
1918 +                *      This element [the Secondary Channel Offset Element] is
1919 +                *      present when switching to a 40 MHz channel. It may be
1920 +                *      present when switching to a 20 MHz channel (in which
1921 +                *      case the secondary channel offset is set to SCN).
1922 +                */
1923 +               secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1924 +       }
1925 +
1926 +       switch (secondary_channel_offset) {
1927 +       default:
1928 +               /* secondary_channel_offset was present but is invalid */
1929 +       case IEEE80211_HT_PARAM_CHA_SEC_NONE:
1930 +               cfg80211_chandef_create(&new_chandef, new_chan,
1931 +                                       NL80211_CHAN_HT20);
1932 +               break;
1933 +       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1934 +               cfg80211_chandef_create(&new_chandef, new_chan,
1935 +                                       NL80211_CHAN_HT40PLUS);
1936 +               break;
1937 +       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1938 +               cfg80211_chandef_create(&new_chandef, new_chan,
1939 +                                       NL80211_CHAN_HT40MINUS);
1940 +               break;
1941 +       case -1:
1942 +               cfg80211_chandef_create(&new_chandef, new_chan,
1943 +                                       NL80211_CHAN_NO_HT);
1944 +               break;
1945 +       }
1946 +
1947 +       if (wide_bw_chansw_ie) {
1948 +               new_vht_chandef.chan = new_chan;
1949 +               new_vht_chandef.center_freq1 =
1950 +                       ieee80211_channel_to_frequency(
1951 +                               wide_bw_chansw_ie->new_center_freq_seg0,
1952 +                               new_band);
1953 +
1954 +               switch (wide_bw_chansw_ie->new_channel_width) {
1955 +               default:
1956 +                       /* hmmm, ignore VHT and use HT if present */
1957 +               case IEEE80211_VHT_CHANWIDTH_USE_HT:
1958 +                       new_vht_chandef.chan = NULL;
1959 +                       break;
1960 +               case IEEE80211_VHT_CHANWIDTH_80MHZ:
1961 +                       new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1962 +                       break;
1963 +               case IEEE80211_VHT_CHANWIDTH_160MHZ:
1964 +                       new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1965 +                       break;
1966 +               case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1967 +                       /* field is otherwise reserved */
1968 +                       new_vht_chandef.center_freq2 =
1969 +                               ieee80211_channel_to_frequency(
1970 +                                       wide_bw_chansw_ie->new_center_freq_seg1,
1971 +                                       new_band);
1972 +                       new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1973 +                       break;
1974 +               }
1975 +               if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1976 +                   new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1977 +                       chandef_downgrade(&new_vht_chandef);
1978 +               if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1979 +                   new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1980 +                       chandef_downgrade(&new_vht_chandef);
1981 +               if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1982 +                   new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1983 +                       chandef_downgrade(&new_vht_chandef);
1984 +       }
1985 +
1986 +       /* if VHT data is there validate & use it */
1987 +       if (new_vht_chandef.chan) {
1988 +               if (!cfg80211_chandef_compatible(&new_vht_chandef,
1989 +                                                &new_chandef)) {
1990 +                       sdata_info(sdata,
1991 +                                  "AP %pM CSA has inconsistent channel data, disconnecting\n",
1992 +                                  ifmgd->associated->bssid);
1993 +                       ieee80211_queue_work(&local->hw,
1994 +                                            &ifmgd->csa_connection_drop_work);
1995 +                       return;
1996 +               }
1997 +               new_chandef = new_vht_chandef;
1998 +       }
1999 +
2000 +       if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
2001 +                                    IEEE80211_CHAN_DISABLED)) {
2002 +               sdata_info(sdata,
2003 +                          "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
2004 +                          ifmgd->associated->bssid, new_freq,
2005 +                          new_chandef.width, new_chandef.center_freq1,
2006 +                          new_chandef.center_freq2);
2007 +               ieee80211_queue_work(&local->hw,
2008                                      &ifmgd->csa_connection_drop_work);
2009                 return;
2010         }
2011  
2012         ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
2013  
2014 -       if (sdata->local->use_chanctx) {
2015 +       if (local->use_chanctx) {
2016                 sdata_info(sdata,
2017                            "not handling channel switch with channel contexts\n");
2018 -               ieee80211_queue_work(&sdata->local->hw,
2019 +               ieee80211_queue_work(&local->hw,
2020                                      &ifmgd->csa_connection_drop_work);
2021                 return;
2022         }
2023  
2024 -       mutex_lock(&sdata->local->chanctx_mtx);
2025 +       mutex_lock(&local->chanctx_mtx);
2026         if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
2027 -               mutex_unlock(&sdata->local->chanctx_mtx);
2028 +               mutex_unlock(&local->chanctx_mtx);
2029                 return;
2030         }
2031         chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
2032 @@ -1111,40 +1222,39 @@ ieee80211_sta_process_chanswitch(struct 
2033         if (chanctx->refcount > 1) {
2034                 sdata_info(sdata,
2035                            "channel switch with multiple interfaces on the same channel, disconnecting\n");
2036 -               ieee80211_queue_work(&sdata->local->hw,
2037 +               ieee80211_queue_work(&local->hw,
2038                                      &ifmgd->csa_connection_drop_work);
2039 -               mutex_unlock(&sdata->local->chanctx_mtx);
2040 +               mutex_unlock(&local->chanctx_mtx);
2041                 return;
2042         }
2043 -       mutex_unlock(&sdata->local->chanctx_mtx);
2044 +       mutex_unlock(&local->chanctx_mtx);
2045  
2046 -       sdata->local->csa_channel = new_ch;
2047 +       local->csa_chandef = new_chandef;
2048  
2049 -       if (sw_elem->mode)
2050 -               ieee80211_stop_queues_by_reason(&sdata->local->hw,
2051 +       if (mode)
2052 +               ieee80211_stop_queues_by_reason(&local->hw,
2053                                 IEEE80211_MAX_QUEUE_MAP,
2054                                 IEEE80211_QUEUE_STOP_REASON_CSA);
2055  
2056 -       if (sdata->local->ops->channel_switch) {
2057 +       if (local->ops->channel_switch) {
2058                 /* use driver's channel switch callback */
2059                 struct ieee80211_channel_switch ch_switch = {
2060                         .timestamp = timestamp,
2061 -                       .block_tx = sw_elem->mode,
2062 -                       .channel = new_ch,
2063 -                       .count = sw_elem->count,
2064 +                       .block_tx = mode,
2065 +                       .chandef = new_chandef,
2066 +                       .count = count,
2067                 };
2068  
2069 -               drv_channel_switch(sdata->local, &ch_switch);
2070 +               drv_channel_switch(local, &ch_switch);
2071                 return;
2072         }
2073  
2074         /* channel switch handled in software */
2075 -       if (sw_elem->count <= 1)
2076 -               ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
2077 +       if (count <= 1)
2078 +               ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
2079         else
2080                 mod_timer(&ifmgd->chswitch_timer,
2081 -                         TU_TO_EXP_TIME(sw_elem->count *
2082 -                                        cbss->beacon_interval));
2083 +                         TU_TO_EXP_TIME(count * cbss->beacon_interval));
2084  }
2085  
2086  static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
2087 @@ -2120,7 +2230,6 @@ void ieee80211_beacon_loss(struct ieee80
2088  
2089         trace_api_beacon_loss(sdata);
2090  
2091 -       WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
2092         sdata->u.mgd.connection_loss = false;
2093         ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2094  }
2095 @@ -2170,7 +2279,7 @@ static void ieee80211_auth_challenge(str
2096         u32 tx_flags = 0;
2097  
2098         pos = mgmt->u.auth.variable;
2099 -       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2100 +       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2101         if (!elems.challenge)
2102                 return;
2103         auth_data->expected_transaction = 4;
2104 @@ -2435,7 +2544,7 @@ static bool ieee80211_assoc_success(stru
2105         }
2106  
2107         pos = mgmt->u.assoc_resp.variable;
2108 -       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2109 +       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2110  
2111         if (!elems.supp_rates) {
2112                 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2113 @@ -2604,7 +2713,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
2114                    capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2115  
2116         pos = mgmt->u.assoc_resp.variable;
2117 -       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2118 +       ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2119  
2120         if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2121             elems.timeout_int &&
2122 @@ -2659,6 +2768,8 @@ static void ieee80211_rx_bss_info(struct
2123         struct ieee80211_channel *channel;
2124         bool need_ps = false;
2125  
2126 +       lockdep_assert_held(&sdata->u.mgd.mtx);
2127 +
2128         if ((sdata->u.mgd.associated &&
2129              ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2130             (sdata->u.mgd.assoc_data &&
2131 @@ -2689,7 +2800,8 @@ static void ieee80211_rx_bss_info(struct
2132         if (bss)
2133                 ieee80211_rx_bss_put(local, bss);
2134  
2135 -       if (!sdata->u.mgd.associated)
2136 +       if (!sdata->u.mgd.associated ||
2137 +           !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
2138                 return;
2139  
2140         if (need_ps) {
2141 @@ -2698,10 +2810,9 @@ static void ieee80211_rx_bss_info(struct
2142                 mutex_unlock(&local->iflist_mtx);
2143         }
2144  
2145 -       if (elems->ch_switch_ie &&
2146 -           memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2147 -               ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
2148 -                                                bss, rx_status->mactime);
2149 +       ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2150 +                                        elems, true);
2151 +
2152  }
2153  
2154  
2155 @@ -2726,7 +2837,7 @@ static void ieee80211_rx_mgmt_probe_resp
2156                 return;
2157  
2158         ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2159 -                               &elems);
2160 +                              false, &elems);
2161  
2162         ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2163  
2164 @@ -2809,7 +2920,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2165         if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
2166             ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2167                 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2168 -                                      len - baselen, &elems);
2169 +                                      len - baselen, false, &elems);
2170  
2171                 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2172                 ifmgd->assoc_data->have_beacon = true;
2173 @@ -2919,7 +3030,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2174  
2175         ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2176         ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2177 -                                         len - baselen, &elems,
2178 +                                         len - baselen, false, &elems,
2179                                           care_about_ies, ncrc);
2180  
2181         if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
2182 @@ -3066,6 +3177,8 @@ void ieee80211_sta_rx_queued_mgmt(struct
2183         enum rx_mgmt_action rma = RX_MGMT_NONE;
2184         u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
2185         u16 fc;
2186 +       struct ieee802_11_elems elems;
2187 +       int ies_len;
2188  
2189         rx_status = (struct ieee80211_rx_status *) skb->cb;
2190         mgmt = (struct ieee80211_mgmt *) skb->data;
2191 @@ -3095,14 +3208,48 @@ void ieee80211_sta_rx_queued_mgmt(struct
2192                 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2193                 break;
2194         case IEEE80211_STYPE_ACTION:
2195 -               switch (mgmt->u.action.category) {
2196 -               case WLAN_CATEGORY_SPECTRUM_MGMT:
2197 +               if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
2198 +                       ies_len = skb->len -
2199 +                                 offsetof(struct ieee80211_mgmt,
2200 +                                          u.action.u.chan_switch.variable);
2201 +
2202 +                       if (ies_len < 0)
2203 +                               break;
2204 +
2205 +                       ieee802_11_parse_elems(
2206 +                               mgmt->u.action.u.chan_switch.variable,
2207 +                               ies_len, true, &elems);
2208 +
2209 +                       if (elems.parse_error)
2210 +                               break;
2211 +
2212                         ieee80211_sta_process_chanswitch(sdata,
2213 -                                       &mgmt->u.action.u.chan_switch.sw_elem,
2214 -                                       (void *)ifmgd->associated->priv,
2215 -                                       rx_status->mactime);
2216 -                       break;
2217 +                                                        rx_status->mactime,
2218 +                                                        &elems, false);
2219 +               } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
2220 +                       ies_len = skb->len -
2221 +                                 offsetof(struct ieee80211_mgmt,
2222 +                                          u.action.u.ext_chan_switch.variable);
2223 +
2224 +                       if (ies_len < 0)
2225 +                               break;
2226 +
2227 +                       ieee802_11_parse_elems(
2228 +                               mgmt->u.action.u.ext_chan_switch.variable,
2229 +                               ies_len, true, &elems);
2230 +
2231 +                       if (elems.parse_error)
2232 +                               break;
2233 +
2234 +                       /* for the handling code pretend this was also an IE */
2235 +                       elems.ext_chansw_ie =
2236 +                               &mgmt->u.action.u.ext_chan_switch.data;
2237 +
2238 +                       ieee80211_sta_process_chanswitch(sdata,
2239 +                                                        rx_status->mactime,
2240 +                                                        &elems, false);
2241                 }
2242 +               break;
2243         }
2244         mutex_unlock(&ifmgd->mtx);
2245  
2246 @@ -4197,7 +4344,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2247         struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2248         u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2249         bool tx = !req->local_state_change;
2250 -       bool sent_frame = false;
2251 +       bool report_frame = false;
2252  
2253         mutex_lock(&ifmgd->mtx);
2254  
2255 @@ -4214,7 +4361,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2256                 ieee80211_destroy_auth_data(sdata, false);
2257                 mutex_unlock(&ifmgd->mtx);
2258  
2259 -               sent_frame = tx;
2260 +               report_frame = true;
2261                 goto out;
2262         }
2263  
2264 @@ -4222,12 +4369,12 @@ int ieee80211_mgd_deauth(struct ieee8021
2265             ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
2266                 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2267                                        req->reason_code, tx, frame_buf);
2268 -               sent_frame = tx;
2269 +               report_frame = true;
2270         }
2271         mutex_unlock(&ifmgd->mtx);
2272  
2273   out:
2274 -       if (sent_frame)
2275 +       if (report_frame)
2276                 __cfg80211_send_deauth(sdata->dev, frame_buf,
2277                                        IEEE80211_DEAUTH_FRAME_LEN);
2278  
2279 --- a/net/mac80211/pm.c
2280 +++ b/net/mac80211/pm.c
2281 @@ -38,8 +38,8 @@ int __ieee80211_suspend(struct ieee80211
2282                                         IEEE80211_MAX_QUEUE_MAP,
2283                                         IEEE80211_QUEUE_STOP_REASON_SUSPEND);
2284  
2285 -       /* flush out all packets */
2286 -       synchronize_net();
2287 +       /* flush out all packets and station cleanup call_rcu()s */
2288 +       rcu_barrier();
2289  
2290         ieee80211_flush_queues(local, NULL);
2291  
2292 --- a/net/mac80211/rate.c
2293 +++ b/net/mac80211/rate.c
2294 @@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee802
2295         return 0;
2296  }
2297  
2298 +static void __rate_control_send_low(struct ieee80211_hw *hw,
2299 +                                   struct ieee80211_supported_band *sband,
2300 +                                   struct ieee80211_sta *sta,
2301 +                                   struct ieee80211_tx_info *info)
2302 +{
2303 +       if ((sband->band != IEEE80211_BAND_2GHZ) ||
2304 +           !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2305 +               info->control.rates[0].idx = rate_lowest_index(sband, sta);
2306 +       else
2307 +               info->control.rates[0].idx =
2308 +                       rate_lowest_non_cck_index(sband, sta);
2309 +
2310 +       info->control.rates[0].count =
2311 +               (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2312 +               1 : hw->max_rate_tries;
2313 +
2314 +       info->control.skip_table = 1;
2315 +}
2316 +
2317  
2318  bool rate_control_send_low(struct ieee80211_sta *sta,
2319                            void *priv_sta,
2320 @@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80
2321         int mcast_rate;
2322  
2323         if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
2324 -               if ((sband->band != IEEE80211_BAND_2GHZ) ||
2325 -                   !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2326 -                       info->control.rates[0].idx =
2327 -                               rate_lowest_index(txrc->sband, sta);
2328 -               else
2329 -                       info->control.rates[0].idx =
2330 -                               rate_lowest_non_cck_index(txrc->sband, sta);
2331 -               info->control.rates[0].count =
2332 -                       (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2333 -                       1 : txrc->hw->max_rate_tries;
2334 +               __rate_control_send_low(txrc->hw, sband, sta, info);
2335 +
2336                 if (!sta && txrc->bss) {
2337                         mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
2338                         if (mcast_rate > 0) {
2339 @@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(stru
2340  
2341  
2342  static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
2343 -                               struct ieee80211_tx_rate_control *txrc,
2344 +                               struct ieee80211_supported_band *sband,
2345 +                               enum nl80211_chan_width chan_width,
2346                                 u32 mask,
2347                                 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2348  {
2349 @@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct i
2350                                   IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
2351                 alt_rate.count = rate->count;
2352                 if (rate_idx_match_legacy_mask(&alt_rate,
2353 -                                              txrc->sband->n_bitrates,
2354 -                                              mask)) {
2355 +                                              sband->n_bitrates, mask)) {
2356                         *rate = alt_rate;
2357                         return;
2358                 }
2359         } else {
2360 -               struct sk_buff *skb = txrc->skb;
2361 -               struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2362 -               __le16 fc;
2363 -
2364                 /* handle legacy rates */
2365 -               if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates,
2366 -                                              mask))
2367 +               if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask))
2368                         return;
2369  
2370                 /* if HT BSS, and we handle a data frame, also try HT rates */
2371 -               if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2372 -                       return;
2373 -
2374 -               fc = hdr->frame_control;
2375 -               if (!ieee80211_is_data(fc))
2376 +               if (chan_width == NL80211_CHAN_WIDTH_20_NOHT)
2377                         return;
2378  
2379                 alt_rate.idx = 0;
2380 @@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct i
2381  
2382                 alt_rate.flags |= IEEE80211_TX_RC_MCS;
2383  
2384 -               if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40)
2385 +               if (chan_width == NL80211_CHAN_WIDTH_40)
2386                         alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2387  
2388                 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) {
2389 @@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct i
2390          */
2391  }
2392  
2393 +static void rate_fixup_ratelist(struct ieee80211_vif *vif,
2394 +                               struct ieee80211_supported_band *sband,
2395 +                               struct ieee80211_tx_info *info,
2396 +                               struct ieee80211_tx_rate *rates,
2397 +                               int max_rates)
2398 +{
2399 +       struct ieee80211_rate *rate;
2400 +       bool inval = false;
2401 +       int i;
2402 +
2403 +       /*
2404 +        * Set up the RTS/CTS rate as the fastest basic rate
2405 +        * that is not faster than the data rate unless there
2406 +        * is no basic rate slower than the data rate, in which
2407 +        * case we pick the slowest basic rate
2408 +        *
2409 +        * XXX: Should this check all retry rates?
2410 +        */
2411 +       if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
2412 +               u32 basic_rates = vif->bss_conf.basic_rates;
2413 +               s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
2414 +
2415 +               rate = &sband->bitrates[rates[0].idx];
2416 +
2417 +               for (i = 0; i < sband->n_bitrates; i++) {
2418 +                       /* must be a basic rate */
2419 +                       if (!(basic_rates & BIT(i)))
2420 +                               continue;
2421 +                       /* must not be faster than the data rate */
2422 +                       if (sband->bitrates[i].bitrate > rate->bitrate)
2423 +                               continue;
2424 +                       /* maximum */
2425 +                       if (sband->bitrates[baserate].bitrate <
2426 +                            sband->bitrates[i].bitrate)
2427 +                               baserate = i;
2428 +               }
2429 +
2430 +               info->control.rts_cts_rate_idx = baserate;
2431 +       }
2432 +
2433 +       for (i = 0; i < max_rates; i++) {
2434 +               /*
2435 +                * make sure there's no valid rate following
2436 +                * an invalid one, just in case drivers don't
2437 +                * take the API seriously to stop at -1.
2438 +                */
2439 +               if (inval) {
2440 +                       rates[i].idx = -1;
2441 +                       continue;
2442 +               }
2443 +               if (rates[i].idx < 0) {
2444 +                       inval = true;
2445 +                       continue;
2446 +               }
2447 +
2448 +               /*
2449 +                * For now assume MCS is already set up correctly, this
2450 +                * needs to be fixed.
2451 +                */
2452 +               if (rates[i].flags & IEEE80211_TX_RC_MCS) {
2453 +                       WARN_ON(rates[i].idx > 76);
2454 +
2455 +                       if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2456 +                           info->control.use_cts_prot)
2457 +                               rates[i].flags |=
2458 +                                       IEEE80211_TX_RC_USE_CTS_PROTECT;
2459 +                       continue;
2460 +               }
2461 +
2462 +               if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) {
2463 +                       WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9);
2464 +                       continue;
2465 +               }
2466 +
2467 +               /* set up RTS protection if desired */
2468 +               if (info->control.use_rts) {
2469 +                       rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2470 +                       info->control.use_cts_prot = false;
2471 +               }
2472 +
2473 +               /* RC is busted */
2474 +               if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) {
2475 +                       rates[i].idx = -1;
2476 +                       continue;
2477 +               }
2478 +
2479 +               rate = &sband->bitrates[rates[i].idx];
2480 +
2481 +               /* set up short preamble */
2482 +               if (info->control.short_preamble &&
2483 +                   rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2484 +                       rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
2485 +
2486 +               /* set up G protection */
2487 +               if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2488 +                   info->control.use_cts_prot &&
2489 +                   rate->flags & IEEE80211_RATE_ERP_G)
2490 +                       rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
2491 +       }
2492 +}
2493 +
2494 +
2495 +static void rate_control_fill_sta_table(struct ieee80211_sta *sta,
2496 +                                       struct ieee80211_tx_info *info,
2497 +                                       struct ieee80211_tx_rate *rates,
2498 +                                       int max_rates)
2499 +{
2500 +       struct ieee80211_sta_rates *ratetbl = NULL;
2501 +       int i;
2502 +
2503 +       if (sta && !info->control.skip_table)
2504 +               ratetbl = rcu_dereference(sta->rates);
2505 +
2506 +       /* Fill remaining rate slots with data from the sta rate table. */
2507 +       max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE);
2508 +       for (i = 0; i < max_rates; i++) {
2509 +               if (i < ARRAY_SIZE(info->control.rates) &&
2510 +                   info->control.rates[i].idx >= 0 &&
2511 +                   info->control.rates[i].count) {
2512 +                       if (rates != info->control.rates)
2513 +                               rates[i] = info->control.rates[i];
2514 +               } else if (ratetbl) {
2515 +                       rates[i].idx = ratetbl->rate[i].idx;
2516 +                       rates[i].flags = ratetbl->rate[i].flags;
2517 +                       if (info->control.use_rts)
2518 +                               rates[i].count = ratetbl->rate[i].count_rts;
2519 +                       else if (info->control.use_cts_prot)
2520 +                               rates[i].count = ratetbl->rate[i].count_cts;
2521 +                       else
2522 +                               rates[i].count = ratetbl->rate[i].count;
2523 +               } else {
2524 +                       rates[i].idx = -1;
2525 +                       rates[i].count = 0;
2526 +               }
2527 +
2528 +               if (rates[i].idx < 0 || !rates[i].count)
2529 +                       break;
2530 +       }
2531 +}
2532 +
2533 +static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
2534 +                                   struct ieee80211_sta *sta,
2535 +                                   struct ieee80211_supported_band *sband,
2536 +                                   struct ieee80211_tx_info *info,
2537 +                                   struct ieee80211_tx_rate *rates,
2538 +                                   int max_rates)
2539 +{
2540 +       enum nl80211_chan_width chan_width;
2541 +       u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2542 +       bool has_mcs_mask;
2543 +       u32 mask;
2544 +       int i;
2545 +
2546 +       /*
2547 +        * Try to enforce the rateidx mask the user wanted. skip this if the
2548 +        * default mask (allow all rates) is used to save some processing for
2549 +        * the common case.
2550 +        */
2551 +       mask = sdata->rc_rateidx_mask[info->band];
2552 +       has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
2553 +       if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
2554 +               return;
2555 +
2556 +       if (has_mcs_mask)
2557 +               memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2558 +                      sizeof(mcs_mask));
2559 +       else
2560 +               memset(mcs_mask, 0xff, sizeof(mcs_mask));
2561 +
2562 +       if (sta) {
2563 +               /* Filter out rates that the STA does not support */
2564 +               mask &= sta->supp_rates[info->band];
2565 +               for (i = 0; i < sizeof(mcs_mask); i++)
2566 +                       mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i];
2567 +       }
2568 +
2569 +       /*
2570 +        * Make sure the rate index selected for each TX rate is
2571 +        * included in the configured mask and change the rate indexes
2572 +        * if needed.
2573 +        */
2574 +       chan_width = sdata->vif.bss_conf.chandef.width;
2575 +       for (i = 0; i < max_rates; i++) {
2576 +               /* Skip invalid rates */
2577 +               if (rates[i].idx < 0)
2578 +                       break;
2579 +
2580 +               rate_idx_match_mask(&rates[i], sband, chan_width, mask,
2581 +                                   mcs_mask);
2582 +       }
2583 +}
2584 +
2585 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
2586 +                           struct ieee80211_sta *sta,
2587 +                           struct sk_buff *skb,
2588 +                           struct ieee80211_tx_rate *dest,
2589 +                           int max_rates)
2590 +{
2591 +       struct ieee80211_sub_if_data *sdata;
2592 +       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2593 +       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2594 +       struct ieee80211_supported_band *sband;
2595 +
2596 +       rate_control_fill_sta_table(sta, info, dest, max_rates);
2597 +
2598 +       if (!vif)
2599 +               return;
2600 +
2601 +       sdata = vif_to_sdata(vif);
2602 +       sband = sdata->local->hw.wiphy->bands[info->band];
2603 +
2604 +       if (ieee80211_is_data(hdr->frame_control))
2605 +               rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates);
2606 +
2607 +       if (dest[0].idx < 0)
2608 +               __rate_control_send_low(&sdata->local->hw, sband, sta, info);
2609 +
2610 +       if (sta)
2611 +               rate_fixup_ratelist(vif, sband, info, dest, max_rates);
2612 +}
2613 +EXPORT_SYMBOL(ieee80211_get_tx_rates);
2614 +
2615  void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
2616                            struct sta_info *sta,
2617                            struct ieee80211_tx_rate_control *txrc)
2618 @@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80
2619         struct ieee80211_sta *ista = NULL;
2620         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
2621         int i;
2622 -       u32 mask;
2623 -       u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2624  
2625         if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) {
2626                 ista = &sta->sta;
2627 @@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80
2628  
2629         ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
2630  
2631 -       /*
2632 -        * Try to enforce the rateidx mask the user wanted. skip this if the
2633 -        * default mask (allow all rates) is used to save some processing for
2634 -        * the common case.
2635 -        */
2636 -       mask = sdata->rc_rateidx_mask[info->band];
2637 -       memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2638 -              sizeof(mcs_mask));
2639 -       if (mask != (1 << txrc->sband->n_bitrates) - 1) {
2640 -               if (sta) {
2641 -                       /* Filter out rates that the STA does not support */
2642 -                       mask &= sta->sta.supp_rates[info->band];
2643 -                       for (i = 0; i < sizeof(mcs_mask); i++)
2644 -                               mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i];
2645 -               }
2646 -               /*
2647 -                * Make sure the rate index selected for each TX rate is
2648 -                * included in the configured mask and change the rate indexes
2649 -                * if needed.
2650 -                */
2651 -               for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2652 -                       /* Skip invalid rates */
2653 -                       if (info->control.rates[i].idx < 0)
2654 -                               break;
2655 -                       rate_idx_match_mask(&info->control.rates[i], txrc,
2656 -                                           mask, mcs_mask);
2657 -               }
2658 -       }
2659 +       if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE)
2660 +               return;
2661  
2662 -       BUG_ON(info->control.rates[0].idx < 0);
2663 +       ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb,
2664 +                              info->control.rates,
2665 +                              ARRAY_SIZE(info->control.rates));
2666 +}
2667 +
2668 +int rate_control_set_rates(struct ieee80211_hw *hw,
2669 +                          struct ieee80211_sta *pubsta,
2670 +                          struct ieee80211_sta_rates *rates)
2671 +{
2672 +       struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates);
2673 +
2674 +       rcu_assign_pointer(pubsta->rates, rates);
2675 +       if (old)
2676 +               kfree_rcu(old, rcu_head);
2677 +
2678 +       return 0;
2679  }
2680 +EXPORT_SYMBOL(rate_control_set_rates);
2681  
2682  int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
2683                                  const char *name)
2684 --- a/net/mac80211/rc80211_minstrel.c
2685 +++ b/net/mac80211/rc80211_minstrel.c
2686 @@ -84,6 +84,50 @@ minstrel_sort_best_tp_rates(struct minst
2687  }
2688  
2689  static void
2690 +minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
2691 +                 int offset, int idx)
2692 +{
2693 +       struct minstrel_rate *r = &mi->r[idx];
2694 +
2695 +       ratetbl->rate[offset].idx = r->rix;
2696 +       ratetbl->rate[offset].count = r->adjusted_retry_count;
2697 +       ratetbl->rate[offset].count_cts = r->retry_count_cts;
2698 +       ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
2699 +}
2700 +
2701 +static void
2702 +minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2703 +{
2704 +       struct ieee80211_sta_rates *ratetbl;
2705 +       int i = 0;
2706 +
2707 +       ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
2708 +       if (!ratetbl)
2709 +               return;
2710 +
2711 +       /* Start with max_tp_rate */
2712 +       minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
2713 +
2714 +       if (mp->hw->max_rates >= 3) {
2715 +               /* At least 3 tx rates supported, use max_tp_rate2 next */
2716 +               minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
2717 +       }
2718 +
2719 +       if (mp->hw->max_rates >= 2) {
2720 +               /* At least 2 tx rates supported, use max_prob_rate next */
2721 +               minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
2722 +       }
2723 +
2724 +       /* Use lowest rate last */
2725 +       ratetbl->rate[i].idx = mi->lowest_rix;
2726 +       ratetbl->rate[i].count = mp->max_retry;
2727 +       ratetbl->rate[i].count_cts = mp->max_retry;
2728 +       ratetbl->rate[i].count_rts = mp->max_retry;
2729 +
2730 +       rate_control_set_rates(mp->hw, mi->sta, ratetbl);
2731 +}
2732 +
2733 +static void
2734  minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2735  {
2736         u8 tmp_tp_rate[MAX_THR_RATES];
2737 @@ -161,6 +205,8 @@ minstrel_update_stats(struct minstrel_pr
2738  
2739         /* Reset update timer */
2740         mi->stats_update = jiffies;
2741 +
2742 +       minstrel_update_rates(mp, mi);
2743  }
2744  
2745  static void
2746 @@ -209,9 +255,9 @@ minstrel_get_retry_count(struct minstrel
2747  {
2748         unsigned int retry = mr->adjusted_retry_count;
2749  
2750 -       if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
2751 +       if (info->control.use_rts)
2752                 retry = max(2U, min(mr->retry_count_rtscts, retry));
2753 -       else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
2754 +       else if (info->control.use_cts_prot)
2755                 retry = max(2U, min(mr->retry_count_cts, retry));
2756         return retry;
2757  }
2758 @@ -240,13 +286,12 @@ minstrel_get_rate(void *priv, struct iee
2759         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2760         struct minstrel_sta_info *mi = priv_sta;
2761         struct minstrel_priv *mp = priv;
2762 -       struct ieee80211_tx_rate *ar = info->control.rates;
2763 -       unsigned int ndx, sample_ndx = 0;
2764 +       struct ieee80211_tx_rate *rate = &info->control.rates[0];
2765 +       struct minstrel_rate *msr, *mr;
2766 +       unsigned int ndx;
2767         bool mrr_capable;
2768 -       bool indirect_rate_sampling = false;
2769 -       bool rate_sampling = false;
2770 -       int i, delta;
2771 -       int mrr_ndx[3];
2772 +       bool prev_sample = mi->prev_sample;
2773 +       int delta;
2774         int sampling_ratio;
2775  
2776         /* management/no-ack frames do not use rate control */
2777 @@ -262,107 +307,75 @@ minstrel_get_rate(void *priv, struct iee
2778         else
2779                 sampling_ratio = mp->lookaround_rate;
2780  
2781 -       /* init rateindex [ndx] with max throughput rate */
2782 -       ndx = mi->max_tp_rate[0];
2783 -
2784         /* increase sum packet counter */
2785         mi->packet_count++;
2786  
2787         delta = (mi->packet_count * sampling_ratio / 100) -
2788                         (mi->sample_count + mi->sample_deferred / 2);
2789  
2790 -       /* delta > 0: sampling required */
2791 -       if ((delta > 0) && (mrr_capable || !mi->prev_sample)) {
2792 -               struct minstrel_rate *msr;
2793 -               if (mi->packet_count >= 10000) {
2794 -                       mi->sample_deferred = 0;
2795 -                       mi->sample_count = 0;
2796 -                       mi->packet_count = 0;
2797 -               } else if (delta > mi->n_rates * 2) {
2798 -                       /* With multi-rate retry, not every planned sample
2799 -                        * attempt actually gets used, due to the way the retry
2800 -                        * chain is set up - [max_tp,sample,prob,lowest] for
2801 -                        * sample_rate < max_tp.
2802 -                        *
2803 -                        * If there's too much sampling backlog and the link
2804 -                        * starts getting worse, minstrel would start bursting
2805 -                        * out lots of sampling frames, which would result
2806 -                        * in a large throughput loss. */
2807 -                       mi->sample_count += (delta - mi->n_rates * 2);
2808 -               }
2809 +       /* delta < 0: no sampling required */
2810 +       mi->prev_sample = false;
2811 +       if (delta < 0 || (!mrr_capable && prev_sample))
2812 +               return;
2813  
2814 -               /* get next random rate sample */
2815 -               sample_ndx = minstrel_get_next_sample(mi);
2816 -               msr = &mi->r[sample_ndx];
2817 -               rate_sampling = true;
2818 -
2819 -               /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2820 -                * rate sampling method should be used.
2821 -                * Respect such rates that are not sampled for 20 interations.
2822 -                */
2823 -               if (mrr_capable &&
2824 -                   msr->perfect_tx_time > mi->r[ndx].perfect_tx_time &&
2825 -                   msr->sample_skipped < 20)
2826 -                               indirect_rate_sampling = true;
2827 -
2828 -               if (!indirect_rate_sampling) {
2829 -                       if (msr->sample_limit != 0) {
2830 -                               ndx = sample_ndx;
2831 -                               mi->sample_count++;
2832 -                               if (msr->sample_limit > 0)
2833 -                                       msr->sample_limit--;
2834 -                       } else
2835 -                               rate_sampling = false;
2836 -               } else {
2837 -                       /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2838 -                        * packets that have the sampling rate deferred to the
2839 -                        * second MRR stage. Increase the sample counter only
2840 -                        * if the deferred sample rate was actually used.
2841 -                        * Use the sample_deferred counter to make sure that
2842 -                        * the sampling is not done in large bursts */
2843 -                       info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2844 -                       mi->sample_deferred++;
2845 -               }
2846 +       if (mi->packet_count >= 10000) {
2847 +               mi->sample_deferred = 0;
2848 +               mi->sample_count = 0;
2849 +               mi->packet_count = 0;
2850 +       } else if (delta > mi->n_rates * 2) {
2851 +               /* With multi-rate retry, not every planned sample
2852 +                * attempt actually gets used, due to the way the retry
2853 +                * chain is set up - [max_tp,sample,prob,lowest] for
2854 +                * sample_rate < max_tp.
2855 +                *
2856 +                * If there's too much sampling backlog and the link
2857 +                * starts getting worse, minstrel would start bursting
2858 +                * out lots of sampling frames, which would result
2859 +                * in a large throughput loss. */
2860 +               mi->sample_count += (delta - mi->n_rates * 2);
2861 +       }
2862 +
2863 +       /* get next random rate sample */
2864 +       ndx = minstrel_get_next_sample(mi);
2865 +       msr = &mi->r[ndx];
2866 +       mr = &mi->r[mi->max_tp_rate[0]];
2867 +
2868 +       /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2869 +        * rate sampling method should be used.
2870 +        * Respect such rates that are not sampled for 20 interations.
2871 +        */
2872 +       if (mrr_capable &&
2873 +           msr->perfect_tx_time > mr->perfect_tx_time &&
2874 +           msr->sample_skipped < 20) {
2875 +               /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2876 +                * packets that have the sampling rate deferred to the
2877 +                * second MRR stage. Increase the sample counter only
2878 +                * if the deferred sample rate was actually used.
2879 +                * Use the sample_deferred counter to make sure that
2880 +                * the sampling is not done in large bursts */
2881 +               info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2882 +               rate++;
2883 +               mi->sample_deferred++;
2884 +       } else {
2885 +               if (!msr->sample_limit != 0)
2886 +                       return;
2887 +
2888 +               mi->sample_count++;
2889 +               if (msr->sample_limit > 0)
2890 +                       msr->sample_limit--;
2891         }
2892 -       mi->prev_sample = rate_sampling;
2893  
2894         /* If we're not using MRR and the sampling rate already
2895          * has a probability of >95%, we shouldn't be attempting
2896          * to use it, as this only wastes precious airtime */
2897 -       if (!mrr_capable && rate_sampling &&
2898 +       if (!mrr_capable &&
2899            (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
2900 -               ndx = mi->max_tp_rate[0];
2901 -
2902 -       /* mrr setup for 1st stage */
2903 -       ar[0].idx = mi->r[ndx].rix;
2904 -       ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
2905 -
2906 -       /* non mrr setup for 2nd stage */
2907 -       if (!mrr_capable) {
2908 -               if (!rate_sampling)
2909 -                       ar[0].count = mp->max_retry;
2910 -               ar[1].idx = mi->lowest_rix;
2911 -               ar[1].count = mp->max_retry;
2912                 return;
2913 -       }
2914  
2915 -       /* mrr setup for 2nd stage */
2916 -       if (rate_sampling) {
2917 -               if (indirect_rate_sampling)
2918 -                       mrr_ndx[0] = sample_ndx;
2919 -               else
2920 -                       mrr_ndx[0] = mi->max_tp_rate[0];
2921 -       } else {
2922 -               mrr_ndx[0] = mi->max_tp_rate[1];
2923 -       }
2924 +       mi->prev_sample = true;
2925  
2926 -       /* mrr setup for 3rd & 4th stage */
2927 -       mrr_ndx[1] = mi->max_prob_rate;
2928 -       mrr_ndx[2] = 0;
2929 -       for (i = 1; i < 4; i++) {
2930 -               ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
2931 -               ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
2932 -       }
2933 +       rate->idx = mi->r[ndx].rix;
2934 +       rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
2935  }
2936  
2937  
2938 @@ -412,12 +425,16 @@ minstrel_rate_init(void *priv, struct ie
2939         unsigned int i, n = 0;
2940         unsigned int t_slot = 9; /* FIXME: get real slot time */
2941  
2942 +       mi->sta = sta;
2943         mi->lowest_rix = rate_lowest_index(sband, sta);
2944         ctl_rate = &sband->bitrates[mi->lowest_rix];
2945         mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
2946                                 ctl_rate->bitrate,
2947                                 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
2948  
2949 +       memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
2950 +       mi->max_prob_rate = 0;
2951 +
2952         for (i = 0; i < sband->n_bitrates; i++) {
2953                 struct minstrel_rate *mr = &mi->r[n];
2954                 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
2955 @@ -460,6 +477,8 @@ minstrel_rate_init(void *priv, struct ie
2956                 } while ((tx_time < mp->segment_size) &&
2957                                 (++mr->retry_count < mp->max_retry));
2958                 mr->adjusted_retry_count = mr->retry_count;
2959 +               if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
2960 +                       mr->retry_count_cts = mr->retry_count;
2961         }
2962  
2963         for (i = n; i < sband->n_bitrates; i++) {
2964 @@ -471,6 +490,7 @@ minstrel_rate_init(void *priv, struct ie
2965         mi->stats_update = jiffies;
2966  
2967         init_sample_table(mi);
2968 +       minstrel_update_rates(mp, mi);
2969  }
2970  
2971  static void *
2972 --- a/net/mac80211/rc80211_minstrel.h
2973 +++ b/net/mac80211/rc80211_minstrel.h
2974 @@ -9,7 +9,8 @@
2975  #ifndef __RC_MINSTREL_H
2976  #define __RC_MINSTREL_H
2977  
2978 -#define EWMA_LEVEL     75      /* ewma weighting factor [%] */
2979 +#define EWMA_LEVEL     96      /* ewma weighting factor [/EWMA_DIV] */
2980 +#define EWMA_DIV       128
2981  #define SAMPLE_COLUMNS 10      /* number of columns in sample table */
2982  
2983  
2984 @@ -27,7 +28,7 @@
2985  static inline int
2986  minstrel_ewma(int old, int new, int weight)
2987  {
2988 -       return (new * (100 - weight) + old * weight) / 100;
2989 +       return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
2990  }
2991  
2992  
2993 @@ -62,6 +63,8 @@ struct minstrel_rate {
2994  };
2995  
2996  struct minstrel_sta_info {
2997 +       struct ieee80211_sta *sta;
2998 +
2999         unsigned long stats_update;
3000         unsigned int sp_ack_dur;
3001         unsigned int rate_avg;
3002 --- a/net/mac80211/rc80211_minstrel_debugfs.c
3003 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
3004 @@ -68,7 +68,7 @@ minstrel_stats_open(struct inode *inode,
3005  
3006         file->private_data = ms;
3007         p = ms->buf;
3008 -       p += sprintf(p, "rate     throughput  ewma prob   this prob  "
3009 +       p += sprintf(p, "rate      throughput  ewma prob  this prob  "
3010                         "this succ/attempt   success    attempts\n");
3011         for (i = 0; i < mi->n_rates; i++) {
3012                 struct minstrel_rate *mr = &mi->r[i];
3013 @@ -86,7 +86,7 @@ minstrel_stats_open(struct inode *inode,
3014                 eprob = MINSTREL_TRUNC(mr->probability * 1000);
3015  
3016                 p += sprintf(p, "  %6u.%1u   %6u.%1u   %6u.%1u        "
3017 -                               "%3u(%3u)   %8llu    %8llu\n",
3018 +                               "   %3u(%3u)  %8llu    %8llu\n",
3019                                 tp / 10, tp % 10,
3020                                 eprob / 10, eprob % 10,
3021                                 prob / 10, prob % 10,
3022 --- a/net/mac80211/rc80211_minstrel_ht.c
3023 +++ b/net/mac80211/rc80211_minstrel_ht.c
3024 @@ -126,6 +126,9 @@ const struct mcs_group minstrel_mcs_grou
3025  
3026  static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES];
3027  
3028 +static void
3029 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
3030 +
3031  /*
3032   * Look up an MCS group index based on mac80211 rate information
3033   */
3034 @@ -244,6 +247,7 @@ minstrel_ht_update_stats(struct minstrel
3035         struct minstrel_rate_stats *mr;
3036         int cur_prob, cur_prob_tp, cur_tp, cur_tp2;
3037         int group, i, index;
3038 +       bool mi_rates_valid = false;
3039  
3040         if (mi->ampdu_packets > 0) {
3041                 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
3042 @@ -254,11 +258,10 @@ minstrel_ht_update_stats(struct minstrel
3043  
3044         mi->sample_slow = 0;
3045         mi->sample_count = 0;
3046 -       mi->max_tp_rate = 0;
3047 -       mi->max_tp_rate2 = 0;
3048 -       mi->max_prob_rate = 0;
3049  
3050         for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
3051 +               bool mg_rates_valid = false;
3052 +
3053                 cur_prob = 0;
3054                 cur_prob_tp = 0;
3055                 cur_tp = 0;
3056 @@ -268,15 +271,24 @@ minstrel_ht_update_stats(struct minstrel
3057                 if (!mg->supported)
3058                         continue;
3059  
3060 -               mg->max_tp_rate = 0;
3061 -               mg->max_tp_rate2 = 0;
3062 -               mg->max_prob_rate = 0;
3063                 mi->sample_count++;
3064  
3065                 for (i = 0; i < MCS_GROUP_RATES; i++) {
3066                         if (!(mg->supported & BIT(i)))
3067                                 continue;
3068  
3069 +                       /* initialize rates selections starting indexes */
3070 +                       if (!mg_rates_valid) {
3071 +                               mg->max_tp_rate = mg->max_tp_rate2 =
3072 +                                       mg->max_prob_rate = i;
3073 +                               if (!mi_rates_valid) {
3074 +                                       mi->max_tp_rate = mi->max_tp_rate2 =
3075 +                                               mi->max_prob_rate = i;
3076 +                                       mi_rates_valid = true;
3077 +                               }
3078 +                               mg_rates_valid = true;
3079 +                       }
3080 +
3081                         mr = &mg->rates[i];
3082                         mr->retry_updated = false;
3083                         index = MCS_GROUP_RATES * group + i;
3084 @@ -456,7 +468,7 @@ minstrel_ht_tx_status(void *priv, struct
3085         struct ieee80211_tx_rate *ar = info->status.rates;
3086         struct minstrel_rate_stats *rate, *rate2;
3087         struct minstrel_priv *mp = priv;
3088 -       bool last;
3089 +       bool last, update = false;
3090         int i;
3091  
3092         if (!msp->is_ht)
3093 @@ -505,21 +517,29 @@ minstrel_ht_tx_status(void *priv, struct
3094         rate = minstrel_get_ratestats(mi, mi->max_tp_rate);
3095         if (rate->attempts > 30 &&
3096             MINSTREL_FRAC(rate->success, rate->attempts) <
3097 -           MINSTREL_FRAC(20, 100))
3098 +           MINSTREL_FRAC(20, 100)) {
3099                 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true);
3100 +               update = true;
3101 +       }
3102  
3103         rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2);
3104         if (rate2->attempts > 30 &&
3105             MINSTREL_FRAC(rate2->success, rate2->attempts) <
3106 -           MINSTREL_FRAC(20, 100))
3107 +           MINSTREL_FRAC(20, 100)) {
3108                 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false);
3109 +               update = true;
3110 +       }
3111  
3112         if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) {
3113 +               update = true;
3114                 minstrel_ht_update_stats(mp, mi);
3115                 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
3116                     mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
3117                         minstrel_aggr_check(sta, skb);
3118         }
3119 +
3120 +       if (update)
3121 +               minstrel_ht_update_rates(mp, mi);
3122  }
3123  
3124  static void
3125 @@ -580,39 +600,73 @@ minstrel_calc_retransmit(struct minstrel
3126                  (++mr->retry_count < mp->max_retry));
3127  }
3128  
3129 -
3130  static void
3131  minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
3132 -                     struct ieee80211_tx_rate *rate, int index,
3133 -                     bool sample, bool rtscts)
3134 +                     struct ieee80211_sta_rates *ratetbl, int offset, int index)
3135  {
3136         const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
3137         struct minstrel_rate_stats *mr;
3138 +       u8 idx;
3139 +       u16 flags;
3140  
3141         mr = minstrel_get_ratestats(mi, index);
3142         if (!mr->retry_updated)
3143                 minstrel_calc_retransmit(mp, mi, index);
3144  
3145 -       if (sample)
3146 -               rate->count = 1;
3147 -       else if (mr->probability < MINSTREL_FRAC(20, 100))
3148 -               rate->count = 2;
3149 -       else if (rtscts)
3150 -               rate->count = mr->retry_count_rtscts;
3151 -       else
3152 -               rate->count = mr->retry_count;
3153 -
3154 -       rate->flags = 0;
3155 -       if (rtscts)
3156 -               rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3157 +       if (mr->probability < MINSTREL_FRAC(20, 100) || !mr->retry_count) {
3158 +               ratetbl->rate[offset].count = 2;
3159 +               ratetbl->rate[offset].count_rts = 2;
3160 +               ratetbl->rate[offset].count_cts = 2;
3161 +       } else {
3162 +               ratetbl->rate[offset].count = mr->retry_count;
3163 +               ratetbl->rate[offset].count_cts = mr->retry_count;
3164 +               ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
3165 +       }
3166  
3167         if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
3168 -               rate->idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3169 +               idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3170 +               flags = 0;
3171 +       } else {
3172 +               idx = index % MCS_GROUP_RATES +
3173 +                     (group->streams - 1) * MCS_GROUP_RATES;
3174 +               flags = IEEE80211_TX_RC_MCS | group->flags;
3175 +       }
3176 +
3177 +       if (offset > 0) {
3178 +               ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
3179 +               flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3180 +       }
3181 +
3182 +       ratetbl->rate[offset].idx = idx;
3183 +       ratetbl->rate[offset].flags = flags;
3184 +}
3185 +
3186 +static void
3187 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
3188 +{
3189 +       struct ieee80211_sta_rates *rates;
3190 +       int i = 0;
3191 +
3192 +       rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
3193 +       if (!rates)
3194                 return;
3195 +
3196 +       /* Start with max_tp_rate */
3197 +       minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate);
3198 +
3199 +       if (mp->hw->max_rates >= 3) {
3200 +               /* At least 3 tx rates supported, use max_tp_rate2 next */
3201 +               minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate2);
3202 +       }
3203 +
3204 +       if (mp->hw->max_rates >= 2) {
3205 +               /*
3206 +                * At least 2 tx rates supported, use max_prob_rate next */
3207 +               minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
3208         }
3209  
3210 -       rate->flags |= IEEE80211_TX_RC_MCS | group->flags;
3211 -       rate->idx = index % MCS_GROUP_RATES + (group->streams - 1) * MCS_GROUP_RATES;
3212 +       rates->rate[i].idx = -1;
3213 +       rate_control_set_rates(mp->hw, mi->sta, rates);
3214  }
3215  
3216  static inline int
3217 @@ -702,13 +756,13 @@ static void
3218  minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
3219                       struct ieee80211_tx_rate_control *txrc)
3220  {
3221 +       const struct mcs_group *sample_group;
3222         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
3223 -       struct ieee80211_tx_rate *ar = info->status.rates;
3224 +       struct ieee80211_tx_rate *rate = &info->status.rates[0];
3225         struct minstrel_ht_sta_priv *msp = priv_sta;
3226         struct minstrel_ht_sta *mi = &msp->ht;
3227         struct minstrel_priv *mp = priv;
3228         int sample_idx;
3229 -       bool sample = false;
3230  
3231         if (rate_control_send_low(sta, priv_sta, txrc))
3232                 return;
3233 @@ -736,51 +790,6 @@ minstrel_ht_get_rate(void *priv, struct 
3234         }
3235  #endif
3236  
3237 -       if (sample_idx >= 0) {
3238 -               sample = true;
3239 -               minstrel_ht_set_rate(mp, mi, &ar[0], sample_idx,
3240 -                       true, false);
3241 -               info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3242 -       } else {
3243 -               minstrel_ht_set_rate(mp, mi, &ar[0], mi->max_tp_rate,
3244 -                       false, false);
3245 -       }
3246 -
3247 -       if (mp->hw->max_rates >= 3) {
3248 -               /*
3249 -                * At least 3 tx rates supported, use
3250 -                * sample_rate -> max_tp_rate -> max_prob_rate for sampling and
3251 -                * max_tp_rate -> max_tp_rate2 -> max_prob_rate by default.
3252 -                */
3253 -               if (sample_idx >= 0)
3254 -                       minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate,
3255 -                               false, false);
3256 -               else
3257 -                       minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate2,
3258 -                               false, true);
3259 -
3260 -               minstrel_ht_set_rate(mp, mi, &ar[2], mi->max_prob_rate,
3261 -                                    false, !sample);
3262 -
3263 -               ar[3].count = 0;
3264 -               ar[3].idx = -1;
3265 -       } else if (mp->hw->max_rates == 2) {
3266 -               /*
3267 -                * Only 2 tx rates supported, use
3268 -                * sample_rate -> max_prob_rate for sampling and
3269 -                * max_tp_rate -> max_prob_rate by default.
3270 -                */
3271 -               minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_prob_rate,
3272 -                                    false, !sample);
3273 -
3274 -               ar[2].count = 0;
3275 -               ar[2].idx = -1;
3276 -       } else {
3277 -               /* Not using MRR, only use the first rate */
3278 -               ar[1].count = 0;
3279 -               ar[1].idx = -1;
3280 -       }
3281 -
3282         mi->total_packets++;
3283  
3284         /* wraparound */
3285 @@ -788,6 +797,16 @@ minstrel_ht_get_rate(void *priv, struct 
3286                 mi->total_packets = 0;
3287                 mi->sample_packets = 0;
3288         }
3289 +
3290 +       if (sample_idx < 0)
3291 +               return;
3292 +
3293 +       sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
3294 +       info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3295 +       rate->idx = sample_idx % MCS_GROUP_RATES +
3296 +                   (sample_group->streams - 1) * MCS_GROUP_RATES;
3297 +       rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
3298 +       rate->count = 1;
3299  }
3300  
3301  static void
3302 @@ -837,6 +856,8 @@ minstrel_ht_update_caps(void *priv, stru
3303  
3304         msp->is_ht = true;
3305         memset(mi, 0, sizeof(*mi));
3306 +
3307 +       mi->sta = sta;
3308         mi->stats_update = jiffies;
3309  
3310         ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
3311 @@ -898,6 +919,9 @@ minstrel_ht_update_caps(void *priv, stru
3312         if (!n_supported)
3313                 goto use_legacy;
3314  
3315 +       minstrel_ht_update_stats(mp, mi);
3316 +       minstrel_ht_update_rates(mp, mi);
3317 +
3318         return;
3319  
3320  use_legacy:
3321 --- a/net/mac80211/rc80211_minstrel_ht.h
3322 +++ b/net/mac80211/rc80211_minstrel_ht.h
3323 @@ -65,6 +65,8 @@ struct minstrel_mcs_group_data {
3324  };
3325  
3326  struct minstrel_ht_sta {
3327 +       struct ieee80211_sta *sta;
3328 +
3329         /* ampdu length (average, per sampling interval) */
3330         unsigned int ampdu_len;
3331         unsigned int ampdu_packets;
3332 --- a/net/mac80211/rx.c
3333 +++ b/net/mac80211/rx.c
3334 @@ -1372,6 +1372,7 @@ ieee80211_rx_h_sta_process(struct ieee80
3335         struct sk_buff *skb = rx->skb;
3336         struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3337         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3338 +       int i;
3339  
3340         if (!sta)
3341                 return RX_CONTINUE;
3342 @@ -1422,6 +1423,19 @@ ieee80211_rx_h_sta_process(struct ieee80
3343                 ewma_add(&sta->avg_signal, -status->signal);
3344         }
3345  
3346 +       if (status->chains) {
3347 +               sta->chains = status->chains;
3348 +               for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
3349 +                       int signal = status->chain_signal[i];
3350 +
3351 +                       if (!(status->chains & BIT(i)))
3352 +                               continue;
3353 +
3354 +                       sta->chain_signal_last[i] = signal;
3355 +                       ewma_add(&sta->chain_signal_avg[i], -signal);
3356 +               }
3357 +       }
3358 +
3359         /*
3360          * Change STA power saving mode only at the end of a frame
3361          * exchange sequence.
3362 @@ -2085,6 +2099,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
3363         }
3364  
3365         fwd_hdr =  (struct ieee80211_hdr *) fwd_skb->data;
3366 +       fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
3367         info = IEEE80211_SKB_CB(fwd_skb);
3368         memset(info, 0, sizeof(*info));
3369         info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
3370 @@ -2356,6 +2371,7 @@ ieee80211_rx_h_action(struct ieee80211_r
3371                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3372                     sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3373                     sdata->vif.type != NL80211_IFTYPE_AP &&
3374 +                   sdata->vif.type != NL80211_IFTYPE_WDS &&
3375                     sdata->vif.type != NL80211_IFTYPE_ADHOC)
3376                         break;
3377  
3378 @@ -2423,6 +2439,22 @@ ieee80211_rx_h_action(struct ieee80211_r
3379                 }
3380  
3381                 break;
3382 +       case WLAN_CATEGORY_PUBLIC:
3383 +               if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3384 +                       goto invalid;
3385 +               if (sdata->vif.type != NL80211_IFTYPE_STATION)
3386 +                       break;
3387 +               if (!rx->sta)
3388 +                       break;
3389 +               if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3390 +                       break;
3391 +               if (mgmt->u.action.u.ext_chan_switch.action_code !=
3392 +                               WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3393 +                       break;
3394 +               if (len < offsetof(struct ieee80211_mgmt,
3395 +                                  u.action.u.ext_chan_switch.variable))
3396 +                       goto invalid;
3397 +               goto queue;
3398         case WLAN_CATEGORY_VHT:
3399                 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3400                     sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3401 @@ -2506,10 +2538,6 @@ ieee80211_rx_h_action(struct ieee80211_r
3402                         ieee80211_process_measurement_req(sdata, mgmt, len);
3403                         goto handled;
3404                 case WLAN_ACTION_SPCT_CHL_SWITCH:
3405 -                       if (len < (IEEE80211_MIN_ACTION_SIZE +
3406 -                                  sizeof(mgmt->u.action.u.chan_switch)))
3407 -                               break;
3408 -
3409                         if (sdata->vif.type != NL80211_IFTYPE_STATION)
3410                                 break;
3411  
3412 @@ -2695,14 +2723,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
3413  
3414         if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3415             sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3416 -           sdata->vif.type != NL80211_IFTYPE_STATION)
3417 +           sdata->vif.type != NL80211_IFTYPE_STATION &&
3418 +           sdata->vif.type != NL80211_IFTYPE_WDS)
3419                 return RX_DROP_MONITOR;
3420  
3421         switch (stype) {
3422         case cpu_to_le16(IEEE80211_STYPE_AUTH):
3423         case cpu_to_le16(IEEE80211_STYPE_BEACON):
3424         case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3425 -               /* process for all: mesh, mlme, ibss */
3426 +               /* process for all: mesh, mlme, ibss, wds */
3427                 break;
3428         case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3429         case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3430 @@ -3023,6 +3052,9 @@ static int prepare_for_handlers(struct i
3431                          * and location updates. Note that mac80211
3432                          * itself never looks at these frames.
3433                          */
3434 +                       if (!multicast &&
3435 +                           !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3436 +                               return 0;
3437                         if (ieee80211_is_public_action(hdr, skb->len))
3438                                 return 1;
3439                         if (!ieee80211_is_beacon(hdr->frame_control))
3440 @@ -3031,10 +3063,16 @@ static int prepare_for_handlers(struct i
3441                 }
3442                 break;
3443         case NL80211_IFTYPE_WDS:
3444 -               if (bssid || !ieee80211_is_data(hdr->frame_control))
3445 -                       return 0;
3446                 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
3447                         return 0;
3448 +
3449 +               if (ieee80211_is_data(hdr->frame_control) ||
3450 +                   ieee80211_is_action(hdr->frame_control)) {
3451 +                       if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
3452 +                               return 0;
3453 +               } else if (!ieee80211_is_beacon(hdr->frame_control))
3454 +                       return 0;
3455 +
3456                 break;
3457         case NL80211_IFTYPE_P2P_DEVICE:
3458                 if (!ieee80211_is_public_action(hdr, skb->len) &&
3459 --- a/net/mac80211/scan.c
3460 +++ b/net/mac80211/scan.c
3461 @@ -181,7 +181,7 @@ void ieee80211_scan_rx(struct ieee80211_
3462         if (baselen > skb->len)
3463                 return;
3464  
3465 -       ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
3466 +       ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
3467  
3468         channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3469  
3470 --- a/net/mac80211/sta_info.h
3471 +++ b/net/mac80211/sta_info.h
3472 @@ -32,7 +32,6 @@
3473   * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
3474   *     frames.
3475   * @WLAN_STA_WME: Station is a QoS-STA.
3476 - * @WLAN_STA_WDS: Station is one of our WDS peers.
3477   * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
3478   *     IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
3479   *     frame to this station is transmitted.
3480 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
3481         WLAN_STA_AUTHORIZED,
3482         WLAN_STA_SHORT_PREAMBLE,
3483         WLAN_STA_WME,
3484 -       WLAN_STA_WDS,
3485         WLAN_STA_CLEAR_PS_FILT,
3486         WLAN_STA_MFP,
3487         WLAN_STA_BLOCK_BA,
3488 @@ -344,6 +342,11 @@ struct sta_info {
3489         int last_signal;
3490         struct ewma avg_signal;
3491         int last_ack_signal;
3492 +
3493 +       u8 chains;
3494 +       s8 chain_signal_last[IEEE80211_MAX_CHAINS];
3495 +       struct ewma chain_signal_avg[IEEE80211_MAX_CHAINS];
3496 +
3497         /* Plus 1 for non-QoS frames */
3498         __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
3499  
3500 --- a/net/mac80211/trace.h
3501 +++ b/net/mac80211/trace.h
3502 @@ -990,23 +990,23 @@ TRACE_EVENT(drv_channel_switch,
3503  
3504         TP_STRUCT__entry(
3505                 LOCAL_ENTRY
3506 +               CHANDEF_ENTRY
3507                 __field(u64, timestamp)
3508                 __field(bool, block_tx)
3509 -               __field(u16, freq)
3510                 __field(u8, count)
3511         ),
3512  
3513         TP_fast_assign(
3514                 LOCAL_ASSIGN;
3515 +               CHANDEF_ASSIGN(&ch_switch->chandef)
3516                 __entry->timestamp = ch_switch->timestamp;
3517                 __entry->block_tx = ch_switch->block_tx;
3518 -               __entry->freq = ch_switch->channel->center_freq;
3519                 __entry->count = ch_switch->count;
3520         ),
3521  
3522         TP_printk(
3523 -               LOCAL_PR_FMT " new freq:%u count:%d",
3524 -               LOCAL_PR_ARG, __entry->freq, __entry->count
3525 +               LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
3526 +               LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count
3527         )
3528  );
3529  
3530 --- a/net/mac80211/tx.c
3531 +++ b/net/mac80211/tx.c
3532 @@ -48,15 +48,15 @@ static __le16 ieee80211_duration(struct 
3533         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3534  
3535         /* assume HW handles this */
3536 -       if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
3537 +       if (tx->rate.flags & IEEE80211_TX_RC_MCS)
3538                 return 0;
3539  
3540         /* uh huh? */
3541 -       if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
3542 +       if (WARN_ON_ONCE(tx->rate.idx < 0))
3543                 return 0;
3544  
3545         sband = local->hw.wiphy->bands[info->band];
3546 -       txrate = &sband->bitrates[info->control.rates[0].idx];
3547 +       txrate = &sband->bitrates[tx->rate.idx];
3548  
3549         erp = txrate->flags & IEEE80211_RATE_ERP_G;
3550  
3551 @@ -617,11 +617,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3552         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
3553         struct ieee80211_hdr *hdr = (void *)tx->skb->data;
3554         struct ieee80211_supported_band *sband;
3555 -       struct ieee80211_rate *rate;
3556 -       int i;
3557         u32 len;
3558 -       bool inval = false, rts = false, short_preamble = false;
3559         struct ieee80211_tx_rate_control txrc;
3560 +       struct ieee80211_sta_rates *ratetbl = NULL;
3561         bool assoc = false;
3562  
3563         memset(&txrc, 0, sizeof(txrc));
3564 @@ -642,18 +640,23 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3565                 txrc.max_rate_idx = -1;
3566         else
3567                 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3568 -       memcpy(txrc.rate_idx_mcs_mask,
3569 -              tx->sdata->rc_rateidx_mcs_mask[info->band],
3570 -              sizeof(txrc.rate_idx_mcs_mask));
3571 +
3572 +       if (tx->sdata->rc_has_mcs_mask[info->band])
3573 +               txrc.rate_idx_mcs_mask =
3574 +                       tx->sdata->rc_rateidx_mcs_mask[info->band];
3575 +
3576         txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
3577                     tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
3578                     tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
3579  
3580         /* set up RTS protection if desired */
3581         if (len > tx->local->hw.wiphy->rts_threshold) {
3582 -               txrc.rts = rts = true;
3583 +               txrc.rts = true;
3584         }
3585  
3586 +       info->control.use_rts = txrc.rts;
3587 +       info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
3588 +
3589         /*
3590          * Use short preamble if the BSS can handle it, but not for
3591          * management frames unless we know the receiver can handle
3592 @@ -663,7 +666,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3593         if (tx->sdata->vif.bss_conf.use_short_preamble &&
3594             (ieee80211_is_data(hdr->frame_control) ||
3595              (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
3596 -               txrc.short_preamble = short_preamble = true;
3597 +               txrc.short_preamble = true;
3598 +
3599 +       info->control.short_preamble = txrc.short_preamble;
3600  
3601         if (tx->sta)
3602                 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
3603 @@ -687,16 +692,38 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3604          */
3605         rate_control_get_rate(tx->sdata, tx->sta, &txrc);
3606  
3607 -       if (unlikely(info->control.rates[0].idx < 0))
3608 -               return TX_DROP;
3609 +       if (tx->sta && !info->control.skip_table)
3610 +               ratetbl = rcu_dereference(tx->sta->sta.rates);
3611 +
3612 +       if (unlikely(info->control.rates[0].idx < 0)) {
3613 +               if (ratetbl) {
3614 +                       struct ieee80211_tx_rate rate = {
3615 +                               .idx = ratetbl->rate[0].idx,
3616 +                               .flags = ratetbl->rate[0].flags,
3617 +                               .count = ratetbl->rate[0].count
3618 +                       };
3619 +
3620 +                       if (ratetbl->rate[0].idx < 0)
3621 +                               return TX_DROP;
3622 +
3623 +                       tx->rate = rate;
3624 +               } else {
3625 +                       return TX_DROP;
3626 +               }
3627 +       } else {
3628 +               tx->rate = info->control.rates[0];
3629 +       }
3630  
3631         if (txrc.reported_rate.idx < 0) {
3632 -               txrc.reported_rate = info->control.rates[0];
3633 +               txrc.reported_rate = tx->rate;
3634                 if (tx->sta && ieee80211_is_data(hdr->frame_control))
3635                         tx->sta->last_tx_rate = txrc.reported_rate;
3636         } else if (tx->sta)
3637                 tx->sta->last_tx_rate = txrc.reported_rate;
3638  
3639 +       if (ratetbl)
3640 +               return TX_CONTINUE;
3641 +
3642         if (unlikely(!info->control.rates[0].count))
3643                 info->control.rates[0].count = 1;
3644  
3645 @@ -704,91 +731,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3646                          (info->flags & IEEE80211_TX_CTL_NO_ACK)))
3647                 info->control.rates[0].count = 1;
3648  
3649 -       if (is_multicast_ether_addr(hdr->addr1)) {
3650 -               /*
3651 -                * XXX: verify the rate is in the basic rateset
3652 -                */
3653 -               return TX_CONTINUE;
3654 -       }
3655 -
3656 -       /*
3657 -        * set up the RTS/CTS rate as the fastest basic rate
3658 -        * that is not faster than the data rate
3659 -        *
3660 -        * XXX: Should this check all retry rates?
3661 -        */
3662 -       if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
3663 -               s8 baserate = 0;
3664 -
3665 -               rate = &sband->bitrates[info->control.rates[0].idx];
3666 -
3667 -               for (i = 0; i < sband->n_bitrates; i++) {
3668 -                       /* must be a basic rate */
3669 -                       if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
3670 -                               continue;
3671 -                       /* must not be faster than the data rate */
3672 -                       if (sband->bitrates[i].bitrate > rate->bitrate)
3673 -                               continue;
3674 -                       /* maximum */
3675 -                       if (sband->bitrates[baserate].bitrate <
3676 -                            sband->bitrates[i].bitrate)
3677 -                               baserate = i;
3678 -               }
3679 -
3680 -               info->control.rts_cts_rate_idx = baserate;
3681 -       }
3682 -
3683 -       for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
3684 -               /*
3685 -                * make sure there's no valid rate following
3686 -                * an invalid one, just in case drivers don't
3687 -                * take the API seriously to stop at -1.
3688 -                */
3689 -               if (inval) {
3690 -                       info->control.rates[i].idx = -1;
3691 -                       continue;
3692 -               }
3693 -               if (info->control.rates[i].idx < 0) {
3694 -                       inval = true;
3695 -                       continue;
3696 -               }
3697 -
3698 -               /*
3699 -                * For now assume MCS is already set up correctly, this
3700 -                * needs to be fixed.
3701 -                */
3702 -               if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
3703 -                       WARN_ON(info->control.rates[i].idx > 76);
3704 -                       continue;
3705 -               }
3706 -
3707 -               /* set up RTS protection if desired */
3708 -               if (rts)
3709 -                       info->control.rates[i].flags |=
3710 -                               IEEE80211_TX_RC_USE_RTS_CTS;
3711 -
3712 -               /* RC is busted */
3713 -               if (WARN_ON_ONCE(info->control.rates[i].idx >=
3714 -                                sband->n_bitrates)) {
3715 -                       info->control.rates[i].idx = -1;
3716 -                       continue;
3717 -               }
3718 -
3719 -               rate = &sband->bitrates[info->control.rates[i].idx];
3720 -
3721 -               /* set up short preamble */
3722 -               if (short_preamble &&
3723 -                   rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
3724 -                       info->control.rates[i].flags |=
3725 -                               IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
3726 -
3727 -               /* set up G protection */
3728 -               if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
3729 -                   rate->flags & IEEE80211_RATE_ERP_G)
3730 -                       info->control.rates[i].flags |=
3731 -                               IEEE80211_TX_RC_USE_CTS_PROTECT;
3732 -       }
3733 -
3734         return TX_CONTINUE;
3735  }
3736  
3737 @@ -2508,8 +2450,6 @@ struct sk_buff *ieee80211_beacon_get_tim
3738                 txrc.max_rate_idx = -1;
3739         else
3740                 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3741 -       memcpy(txrc.rate_idx_mcs_mask, sdata->rc_rateidx_mcs_mask[band],
3742 -              sizeof(txrc.rate_idx_mcs_mask));
3743         txrc.bss = true;
3744         rate_control_get_rate(sdata, NULL, &txrc);
3745  
3746 --- a/net/mac80211/util.c
3747 +++ b/net/mac80211/util.c
3748 @@ -485,7 +485,8 @@ int ieee80211_queue_stopped(struct ieee8
3749                 return true;
3750  
3751         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3752 -       ret = !!local->queue_stop_reasons[queue];
3753 +       ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
3754 +                      &local->queue_stop_reasons[queue]);
3755         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3756         return ret;
3757  }
3758 @@ -559,6 +560,9 @@ void ieee80211_iterate_active_interfaces
3759         list_for_each_entry(sdata, &local->interfaces, list) {
3760                 switch (sdata->vif.type) {
3761                 case NL80211_IFTYPE_MONITOR:
3762 +                       if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3763 +                               continue;
3764 +                       break;
3765                 case NL80211_IFTYPE_AP_VLAN:
3766                         continue;
3767                 default:
3768 @@ -597,6 +601,9 @@ void ieee80211_iterate_active_interfaces
3769         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3770                 switch (sdata->vif.type) {
3771                 case NL80211_IFTYPE_MONITOR:
3772 +                       if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3773 +                               continue;
3774 +                       break;
3775                 case NL80211_IFTYPE_AP_VLAN:
3776                         continue;
3777                 default:
3778 @@ -660,7 +667,7 @@ void ieee80211_queue_delayed_work(struct
3779  }
3780  EXPORT_SYMBOL(ieee80211_queue_delayed_work);
3781  
3782 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
3783 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
3784                                struct ieee802_11_elems *elems,
3785                                u64 filter, u32 crc)
3786  {
3787 @@ -668,6 +675,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3788         u8 *pos = start;
3789         bool calc_crc = filter != 0;
3790         DECLARE_BITMAP(seen_elems, 256);
3791 +       const u8 *ie;
3792  
3793         bitmap_zero(seen_elems, 256);
3794         memset(elems, 0, sizeof(*elems));
3795 @@ -715,6 +723,12 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3796                 case WLAN_EID_COUNTRY:
3797                 case WLAN_EID_PWR_CONSTRAINT:
3798                 case WLAN_EID_TIMEOUT_INTERVAL:
3799 +               case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3800 +               case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3801 +               /*
3802 +                * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
3803 +                * that if the content gets bigger it might be needed more than once
3804 +                */
3805                         if (test_bit(id, seen_elems)) {
3806                                 elems->parse_error = true;
3807                                 left -= elen;
3808 @@ -862,6 +876,48 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3809                         }
3810                         elems->ch_switch_ie = (void *)pos;
3811                         break;
3812 +               case WLAN_EID_EXT_CHANSWITCH_ANN:
3813 +                       if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
3814 +                               elem_parse_failed = true;
3815 +                               break;
3816 +                       }
3817 +                       elems->ext_chansw_ie = (void *)pos;
3818 +                       break;
3819 +               case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3820 +                       if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
3821 +                               elem_parse_failed = true;
3822 +                               break;
3823 +                       }
3824 +                       elems->sec_chan_offs = (void *)pos;
3825 +                       break;
3826 +               case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3827 +                       if (!action ||
3828 +                           elen != sizeof(*elems->wide_bw_chansw_ie)) {
3829 +                               elem_parse_failed = true;
3830 +                               break;
3831 +                       }
3832 +                       elems->wide_bw_chansw_ie = (void *)pos;
3833 +                       break;
3834 +               case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
3835 +                       if (action) {
3836 +                               elem_parse_failed = true;
3837 +                               break;
3838 +                       }
3839 +                       /*
3840 +                        * This is a bit tricky, but as we only care about
3841 +                        * the wide bandwidth channel switch element, so
3842 +                        * just parse it out manually.
3843 +                        */
3844 +                       ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
3845 +                                             pos, elen);
3846 +                       if (ie) {
3847 +                               if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
3848 +                                       elems->wide_bw_chansw_ie =
3849 +                                               (void *)(ie + 2);
3850 +                               else
3851 +                                       elem_parse_failed = true;
3852 +                       }
3853 +                       break;
3854                 case WLAN_EID_COUNTRY:
3855                         elems->country_elem = pos;
3856                         elems->country_elem_len = elen;
3857 --- a/net/wireless/reg.c
3858 +++ b/net/wireless/reg.c
3859 @@ -857,7 +857,7 @@ static void handle_channel(struct wiphy 
3860                         return;
3861  
3862                 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
3863 -               chan->flags = IEEE80211_CHAN_DISABLED;
3864 +               chan->flags |= IEEE80211_CHAN_DISABLED;
3865                 return;
3866         }
3867  
3868 --- a/net/wireless/util.c
3869 +++ b/net/wireless/util.c
3870 @@ -1156,6 +1156,26 @@ int cfg80211_get_p2p_attr(const u8 *ies,
3871  }
3872  EXPORT_SYMBOL(cfg80211_get_p2p_attr);
3873  
3874 +bool ieee80211_operating_class_to_band(u8 operating_class,
3875 +                                      enum ieee80211_band *band)
3876 +{
3877 +       switch (operating_class) {
3878 +       case 112:
3879 +       case 115 ... 127:
3880 +               *band = IEEE80211_BAND_5GHZ;
3881 +               return true;
3882 +       case 81:
3883 +       case 82:
3884 +       case 83:
3885 +       case 84:
3886 +               *band = IEEE80211_BAND_2GHZ;
3887 +               return true;
3888 +       }
3889 +
3890 +       return false;
3891 +}
3892 +EXPORT_SYMBOL(ieee80211_operating_class_to_band);
3893 +
3894  int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
3895                                  u32 beacon_int)
3896  {
3897 --- a/include/uapi/linux/nl80211.h
3898 +++ b/include/uapi/linux/nl80211.h
3899 @@ -1973,6 +1973,10 @@ enum nl80211_sta_bss_param {
3900   * @NL80211_STA_INFO_PEER_PM: peer mesh STA link-specific power mode
3901   * @NL80211_STA_INFO_NONPEER_PM: neighbor mesh STA power save mode towards
3902   *     non-peer STA
3903 + * @NL80211_STA_INFO_CHAIN_SIGNAL: per-chain signal strength of last PPDU
3904 + *     Contains a nested array of signal strength attributes (u8, dBm)
3905 + * @NL80211_STA_INFO_CHAIN_SIGNAL_AVG: per-chain signal strength average
3906 + *     Same format as NL80211_STA_INFO_CHAIN_SIGNAL.
3907   * @__NL80211_STA_INFO_AFTER_LAST: internal
3908   * @NL80211_STA_INFO_MAX: highest possible station info attribute
3909   */
3910 @@ -2002,6 +2006,8 @@ enum nl80211_sta_info {
3911         NL80211_STA_INFO_NONPEER_PM,
3912         NL80211_STA_INFO_RX_BYTES64,
3913         NL80211_STA_INFO_TX_BYTES64,
3914 +       NL80211_STA_INFO_CHAIN_SIGNAL,
3915 +       NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
3916  
3917         /* keep last */
3918         __NL80211_STA_INFO_AFTER_LAST,
3919 @@ -2395,6 +2401,8 @@ enum nl80211_survey_info {
3920   * @NL80211_MNTR_FLAG_OTHER_BSS: disable BSSID filtering
3921   * @NL80211_MNTR_FLAG_COOK_FRAMES: report frames after processing.
3922   *     overrides all other flags.
3923 + * @NL80211_MNTR_FLAG_ACTIVE: use the configured MAC address
3924 + *     and ACK incoming unicast packets.
3925   *
3926   * @__NL80211_MNTR_FLAG_AFTER_LAST: internal use
3927   * @NL80211_MNTR_FLAG_MAX: highest possible monitor flag
3928 @@ -2406,6 +2414,7 @@ enum nl80211_mntr_flags {
3929         NL80211_MNTR_FLAG_CONTROL,
3930         NL80211_MNTR_FLAG_OTHER_BSS,
3931         NL80211_MNTR_FLAG_COOK_FRAMES,
3932 +       NL80211_MNTR_FLAG_ACTIVE,
3933  
3934         /* keep last */
3935         __NL80211_MNTR_FLAG_AFTER_LAST,
3936 @@ -3557,6 +3566,7 @@ enum nl80211_feature_flags {
3937         NL80211_FEATURE_ADVERTISE_CHAN_LIMITS           = 1 << 14,
3938         NL80211_FEATURE_FULL_AP_CLIENT_STATE            = 1 << 15,
3939         NL80211_FEATURE_USERSPACE_MPM                   = 1 << 16,
3940 +       NL80211_FEATURE_ACTIVE_MONITOR                  = 1 << 17,
3941  };
3942  
3943  /**
3944 --- a/net/mac80211/sta_info.c
3945 +++ b/net/mac80211/sta_info.c
3946 @@ -358,6 +358,8 @@ struct sta_info *sta_info_alloc(struct i
3947         do_posix_clock_monotonic_gettime(&uptime);
3948         sta->last_connected = uptime.tv_sec;
3949         ewma_init(&sta->avg_signal, 1024, 8);
3950 +       for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
3951 +               ewma_init(&sta->chain_signal_avg[i], 1024, 8);
3952  
3953         if (sta_prepare_rate_control(local, sta, gfp)) {
3954                 kfree(sta);
3955 --- a/net/wireless/nl80211.c
3956 +++ b/net/wireless/nl80211.c
3957 @@ -2270,6 +2270,7 @@ static const struct nla_policy mntr_flag
3958         [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3959         [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3960         [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3961 +       [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3962  };
3963  
3964  static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3965 @@ -2381,6 +2382,10 @@ static int nl80211_set_interface(struct 
3966                 change = true;
3967         }
3968  
3969 +       if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
3970 +           !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3971 +               return -EOPNOTSUPP;
3972 +
3973         if (change)
3974                 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
3975         else
3976 @@ -2438,6 +2443,11 @@ static int nl80211_new_interface(struct 
3977         err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
3978                                   info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
3979                                   &flags);
3980 +
3981 +       if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
3982 +           !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3983 +               return -EOPNOTSUPP;
3984 +
3985         wdev = rdev_add_virtual_intf(rdev,
3986                                 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
3987                                 type, err ? NULL : &flags, &params);
3988 @@ -3367,6 +3377,32 @@ static bool nl80211_put_sta_rate(struct 
3989         return true;
3990  }
3991  
3992 +static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3993 +                              int id)
3994 +{
3995 +       void *attr;
3996 +       int i = 0;
3997 +
3998 +       if (!mask)
3999 +               return true;
4000 +
4001 +       attr = nla_nest_start(msg, id);
4002 +       if (!attr)
4003 +               return false;
4004 +
4005 +       for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4006 +               if (!(mask & BIT(i)))
4007 +                       continue;
4008 +
4009 +               if (nla_put_u8(msg, i, signal[i]))
4010 +                       return false;
4011 +       }
4012 +
4013 +       nla_nest_end(msg, attr);
4014 +
4015 +       return true;
4016 +}
4017 +
4018  static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
4019                                 int flags,
4020                                 struct cfg80211_registered_device *rdev,
4021 @@ -3402,7 +3438,7 @@ static int nl80211_send_station(struct s
4022                         (u32)sinfo->rx_bytes))
4023                 goto nla_put_failure;
4024         if ((sinfo->filled & (STATION_INFO_TX_BYTES |
4025 -                             NL80211_STA_INFO_TX_BYTES64)) &&
4026 +                             STATION_INFO_TX_BYTES64)) &&
4027             nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4028                         (u32)sinfo->tx_bytes))
4029                 goto nla_put_failure;
4030 @@ -3438,6 +3474,18 @@ static int nl80211_send_station(struct s
4031         default:
4032                 break;
4033         }
4034 +       if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
4035 +               if (!nl80211_put_signal(msg, sinfo->chains,
4036 +                                       sinfo->chain_signal,
4037 +                                       NL80211_STA_INFO_CHAIN_SIGNAL))
4038 +                       goto nla_put_failure;
4039 +       }
4040 +       if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
4041 +               if (!nl80211_put_signal(msg, sinfo->chains,
4042 +                                       sinfo->chain_signal_avg,
4043 +                                       NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4044 +                       goto nla_put_failure;
4045 +       }
4046         if (sinfo->filled & STATION_INFO_TX_BITRATE) {
4047                 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4048                                           NL80211_STA_INFO_TX_BITRATE))
4049 --- a/drivers/net/wireless/ath/ath9k/init.c
4050 +++ b/drivers/net/wireless/ath/ath9k/init.c
4051 @@ -433,6 +433,8 @@ static int ath9k_init_queues(struct ath_
4052         sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
4053         ath_cabq_update(sc);
4054  
4055 +       sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
4056 +
4057         for (i = 0; i < IEEE80211_NUM_ACS; i++) {
4058                 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
4059                 sc->tx.txq_map[i]->mac80211_qnum = i;
4060 @@ -768,7 +770,8 @@ void ath9k_set_hw_capab(struct ath_softc
4061                 IEEE80211_HW_SUPPORTS_PS |
4062                 IEEE80211_HW_PS_NULLFUNC_STACK |
4063                 IEEE80211_HW_SPECTRUM_MGMT |
4064 -               IEEE80211_HW_REPORTS_TX_ACK_STATUS;
4065 +               IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4066 +               IEEE80211_HW_SUPPORTS_RC_TABLE;
4067  
4068         if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
4069                  hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4070 @@ -776,6 +779,8 @@ void ath9k_set_hw_capab(struct ath_softc
4071         if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
4072                 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
4073  
4074 +       hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
4075 +
4076         hw->wiphy->interface_modes =
4077                 BIT(NL80211_IFTYPE_P2P_GO) |
4078                 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4079 --- a/drivers/net/wireless/ath/ath9k/xmit.c
4080 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
4081 @@ -125,24 +125,6 @@ static void ath_tx_queue_tid(struct ath_
4082         list_add_tail(&ac->list, &txq->axq_acq);
4083  }
4084  
4085 -static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4086 -{
4087 -       struct ath_txq *txq = tid->ac->txq;
4088 -
4089 -       WARN_ON(!tid->paused);
4090 -
4091 -       ath_txq_lock(sc, txq);
4092 -       tid->paused = false;
4093 -
4094 -       if (skb_queue_empty(&tid->buf_q))
4095 -               goto unlock;
4096 -
4097 -       ath_tx_queue_tid(txq, tid);
4098 -       ath_txq_schedule(sc, txq);
4099 -unlock:
4100 -       ath_txq_unlock_complete(sc, txq);
4101 -}
4102 -
4103  static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
4104  {
4105         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4106 @@ -157,6 +139,13 @@ static void ath_send_bar(struct ath_atx_
4107                            seqno << IEEE80211_SEQ_SEQ_SHIFT);
4108  }
4109  
4110 +static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4111 +                         struct ath_buf *bf)
4112 +{
4113 +       ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
4114 +                              ARRAY_SIZE(bf->rates));
4115 +}
4116 +
4117  static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4118  {
4119         struct ath_txq *txq = tid->ac->txq;
4120 @@ -189,15 +178,11 @@ static void ath_tx_flush_tid(struct ath_
4121                         ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4122                         sendbar = true;
4123                 } else {
4124 +                       ath_set_rates(tid->an->vif, tid->an->sta, bf);
4125                         ath_tx_send_normal(sc, txq, NULL, skb);
4126                 }
4127         }
4128  
4129 -       if (tid->baw_head == tid->baw_tail) {
4130 -               tid->state &= ~AGGR_ADDBA_COMPLETE;
4131 -               tid->state &= ~AGGR_CLEANUP;
4132 -       }
4133 -
4134         if (sendbar) {
4135                 ath_txq_unlock(sc, txq);
4136                 ath_send_bar(tid, tid->seq_start);
4137 @@ -269,9 +254,7 @@ static void ath_tid_drain(struct ath_sof
4138  
4139                 list_add_tail(&bf->list, &bf_head);
4140  
4141 -               if (fi->retries)
4142 -                       ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4143 -
4144 +               ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4145                 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4146         }
4147  
4148 @@ -407,7 +390,7 @@ static void ath_tx_complete_aggr(struct 
4149  
4150         tx_info = IEEE80211_SKB_CB(skb);
4151  
4152 -       memcpy(rates, tx_info->control.rates, sizeof(rates));
4153 +       memcpy(rates, bf->rates, sizeof(rates));
4154  
4155         retries = ts->ts_longretry + 1;
4156         for (i = 0; i < ts->ts_rateindex; i++)
4157 @@ -483,19 +466,19 @@ static void ath_tx_complete_aggr(struct 
4158                 tx_info = IEEE80211_SKB_CB(skb);
4159                 fi = get_frame_info(skb);
4160  
4161 -               if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4162 +               if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4163 +                       /*
4164 +                        * Outside of the current BlockAck window,
4165 +                        * maybe part of a previous session
4166 +                        */
4167 +                       txfail = 1;
4168 +               } else if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4169                         /* transmit completion, subframe is
4170                          * acked by block ack */
4171                         acked_cnt++;
4172                 } else if (!isaggr && txok) {
4173                         /* transmit completion */
4174                         acked_cnt++;
4175 -               } else if (tid->state & AGGR_CLEANUP) {
4176 -                       /*
4177 -                        * cleanup in progress, just fail
4178 -                        * the un-acked sub-frames
4179 -                        */
4180 -                       txfail = 1;
4181                 } else if (flush) {
4182                         txpending = 1;
4183                 } else if (fi->retries < ATH_MAX_SW_RETRIES) {
4184 @@ -519,7 +502,7 @@ static void ath_tx_complete_aggr(struct 
4185                 if (bf_next != NULL || !bf_last->bf_stale)
4186                         list_move_tail(&bf->list, &bf_head);
4187  
4188 -               if (!txpending || (tid->state & AGGR_CLEANUP)) {
4189 +               if (!txpending) {
4190                         /*
4191                          * complete the acked-ones/xretried ones; update
4192                          * block-ack window
4193 @@ -535,6 +518,10 @@ static void ath_tx_complete_aggr(struct 
4194                         ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
4195                                 !txfail);
4196                 } else {
4197 +                       if (tx_info->flags & IEEE80211_TX_STATUS_EOSP) {
4198 +                               tx_info->flags &= ~IEEE80211_TX_STATUS_EOSP;
4199 +                               ieee80211_sta_eosp(sta);
4200 +                       }
4201                         /* retry the un-acked ones */
4202                         if (bf->bf_next == NULL && bf_last->bf_stale) {
4203                                 struct ath_buf *tbf;
4204 @@ -593,9 +580,6 @@ static void ath_tx_complete_aggr(struct 
4205                 ath_txq_lock(sc, txq);
4206         }
4207  
4208 -       if (tid->state & AGGR_CLEANUP)
4209 -               ath_tx_flush_tid(sc, tid);
4210 -
4211         rcu_read_unlock();
4212  
4213         if (needreset)
4214 @@ -612,6 +596,7 @@ static void ath_tx_process_buffer(struct
4215                                   struct ath_tx_status *ts, struct ath_buf *bf,
4216                                   struct list_head *bf_head)
4217  {
4218 +       struct ieee80211_tx_info *info;
4219         bool txok, flush;
4220  
4221         txok = !(ts->ts_status & ATH9K_TXERR_MASK);
4222 @@ -623,8 +608,12 @@ static void ath_tx_process_buffer(struct
4223                 txq->axq_ampdu_depth--;
4224  
4225         if (!bf_isampdu(bf)) {
4226 -               if (!flush)
4227 +               if (!flush) {
4228 +                       info = IEEE80211_SKB_CB(bf->bf_mpdu);
4229 +                       memcpy(info->control.rates, bf->rates,
4230 +                              sizeof(info->control.rates));
4231                         ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
4232 +               }
4233                 ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok);
4234         } else
4235                 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
4236 @@ -668,7 +657,7 @@ static u32 ath_lookup_rate(struct ath_so
4237  
4238         skb = bf->bf_mpdu;
4239         tx_info = IEEE80211_SKB_CB(skb);
4240 -       rates = tx_info->control.rates;
4241 +       rates = bf->rates;
4242  
4243         /*
4244          * Find the lowest frame length among the rate series that will have a
4245 @@ -736,8 +725,6 @@ static int ath_compute_num_delims(struct
4246                                   bool first_subfrm)
4247  {
4248  #define FIRST_DESC_NDELIMS 60
4249 -       struct sk_buff *skb = bf->bf_mpdu;
4250 -       struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4251         u32 nsymbits, nsymbols;
4252         u16 minlen;
4253         u8 flags, rix;
4254 @@ -778,8 +765,8 @@ static int ath_compute_num_delims(struct
4255         if (tid->an->mpdudensity == 0)
4256                 return ndelim;
4257  
4258 -       rix = tx_info->control.rates[0].idx;
4259 -       flags = tx_info->control.rates[0].flags;
4260 +       rix = bf->rates[0].idx;
4261 +       flags = bf->rates[0].flags;
4262         width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
4263         half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
4264  
4265 @@ -803,25 +790,20 @@ static int ath_compute_num_delims(struct
4266         return ndelim;
4267  }
4268  
4269 -static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4270 -                                            struct ath_txq *txq,
4271 -                                            struct ath_atx_tid *tid,
4272 -                                            struct list_head *bf_q,
4273 -                                            int *aggr_len)
4274 +static struct ath_buf *
4275 +ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
4276 +                       struct ath_atx_tid *tid)
4277  {
4278 -#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4279 -       struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4280 -       int rl = 0, nframes = 0, ndelim, prev_al = 0;
4281 -       u16 aggr_limit = 0, al = 0, bpad = 0,
4282 -               al_delta, h_baw = tid->baw_size / 2;
4283 -       enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4284 -       struct ieee80211_tx_info *tx_info;
4285         struct ath_frame_info *fi;
4286         struct sk_buff *skb;
4287 +       struct ath_buf *bf;
4288         u16 seqno;
4289  
4290 -       do {
4291 +       while (1) {
4292                 skb = skb_peek(&tid->buf_q);
4293 +               if (!skb)
4294 +                       break;
4295 +
4296                 fi = get_frame_info(skb);
4297                 bf = fi->bf;
4298                 if (!fi->bf)
4299 @@ -837,10 +819,8 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4300                 seqno = bf->bf_state.seqno;
4301  
4302                 /* do not step over block-ack window */
4303 -               if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4304 -                       status = ATH_AGGR_BAW_CLOSED;
4305 +               if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno))
4306                         break;
4307 -               }
4308  
4309                 if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) {
4310                         struct ath_tx_status ts = {};
4311 @@ -854,10 +834,45 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4312                         continue;
4313                 }
4314  
4315 +               bf->bf_next = NULL;
4316 +               bf->bf_lastbf = bf;
4317 +               return bf;
4318 +       }
4319 +
4320 +       return NULL;
4321 +}
4322 +
4323 +static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4324 +                                            struct ath_txq *txq,
4325 +                                            struct ath_atx_tid *tid,
4326 +                                            struct list_head *bf_q,
4327 +                                            int *aggr_len)
4328 +{
4329 +#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4330 +       struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4331 +       int rl = 0, nframes = 0, ndelim, prev_al = 0;
4332 +       u16 aggr_limit = 0, al = 0, bpad = 0,
4333 +               al_delta, h_baw = tid->baw_size / 2;
4334 +       enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4335 +       struct ieee80211_tx_info *tx_info;
4336 +       struct ath_frame_info *fi;
4337 +       struct sk_buff *skb;
4338 +
4339 +       do {
4340 +               bf = ath_tx_get_tid_subframe(sc, txq, tid);
4341 +               if (!bf) {
4342 +                       status = ATH_AGGR_BAW_CLOSED;
4343 +                       break;
4344 +               }
4345 +
4346 +               skb = bf->bf_mpdu;
4347 +               fi = get_frame_info(skb);
4348 +
4349                 if (!bf_first)
4350                         bf_first = bf;
4351  
4352                 if (!rl) {
4353 +                       ath_set_rates(tid->an->vif, tid->an->sta, bf);
4354                         aggr_limit = ath_lookup_rate(sc, bf, tid);
4355                         rl = 1;
4356                 }
4357 @@ -898,7 +913,7 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4358  
4359                 /* link buffers of this frame to the aggregate */
4360                 if (!fi->retries)
4361 -                       ath_tx_addto_baw(sc, tid, seqno);
4362 +                       ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4363                 bf->bf_state.ndelim = ndelim;
4364  
4365                 __skb_unlink(skb, &tid->buf_q);
4366 @@ -998,14 +1013,14 @@ static void ath_buf_set_rate(struct ath_
4367  
4368         skb = bf->bf_mpdu;
4369         tx_info = IEEE80211_SKB_CB(skb);
4370 -       rates = tx_info->control.rates;
4371 +       rates = bf->rates;
4372         hdr = (struct ieee80211_hdr *)skb->data;
4373  
4374         /* set dur_update_en for l-sig computation except for PS-Poll frames */
4375         info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
4376         info->rtscts_rate = fi->rtscts_rate;
4377  
4378 -       for (i = 0; i < 4; i++) {
4379 +       for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
4380                 bool is_40, is_sgi, is_sp;
4381                 int phy;
4382  
4383 @@ -1107,9 +1122,8 @@ static void ath_tx_fill_desc(struct ath_
4384  {
4385         struct ath_hw *ah = sc->sc_ah;
4386         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
4387 -       struct ath_buf *bf_first = bf;
4388 +       struct ath_buf *bf_first = NULL;
4389         struct ath_tx_info info;
4390 -       bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4391  
4392         memset(&info, 0, sizeof(info));
4393         info.is_first = true;
4394 @@ -1117,24 +1131,17 @@ static void ath_tx_fill_desc(struct ath_
4395         info.txpower = MAX_RATE_POWER;
4396         info.qcu = txq->axq_qnum;
4397  
4398 -       info.flags = ATH9K_TXDESC_INTREQ;
4399 -       if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4400 -               info.flags |= ATH9K_TXDESC_NOACK;
4401 -       if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4402 -               info.flags |= ATH9K_TXDESC_LDPC;
4403 -
4404 -       ath_buf_set_rate(sc, bf, &info, len);
4405 -
4406 -       if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
4407 +       if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
4408 +           txq == sc->tx.uapsdq)
4409                 info.flags |= ATH9K_TXDESC_CLRDMASK;
4410  
4411         if (bf->bf_state.bfs_paprd)
4412                 info.flags |= (u32) bf->bf_state.bfs_paprd << ATH9K_TXDESC_PAPRD_S;
4413  
4414 -
4415         while (bf) {
4416                 struct sk_buff *skb = bf->bf_mpdu;
4417                 struct ath_frame_info *fi = get_frame_info(skb);
4418 +               bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4419  
4420                 info.type = get_hw_packet_type(skb);
4421                 if (bf->bf_next)
4422 @@ -1142,6 +1149,21 @@ static void ath_tx_fill_desc(struct ath_
4423                 else
4424                         info.link = 0;
4425  
4426 +               if (!bf_first) {
4427 +                       bf_first = bf;
4428 +
4429 +                       info.flags = ATH9K_TXDESC_INTREQ;
4430 +                       if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4431 +                               info.flags |= ATH9K_TXDESC_NOACK;
4432 +                       if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4433 +                               info.flags |= ATH9K_TXDESC_LDPC;
4434 +
4435 +                       ath_buf_set_rate(sc, bf, &info, len);
4436 +
4437 +                       if (txq == sc->beacon.cabq)
4438 +                               sc->beacon.cabq_dur += info.rates[0].PktDuration;
4439 +               }
4440 +
4441                 info.buf_addr[0] = bf->bf_buf_addr;
4442                 info.buf_len[0] = skb->len;
4443                 info.pkt_len = fi->framelen;
4444 @@ -1151,7 +1173,7 @@ static void ath_tx_fill_desc(struct ath_
4445                 if (aggr) {
4446                         if (bf == bf_first)
4447                                 info.aggr = AGGR_BUF_FIRST;
4448 -                       else if (!bf->bf_next)
4449 +                       else if (bf == bf_first->bf_lastbf)
4450                                 info.aggr = AGGR_BUF_LAST;
4451                         else
4452                                 info.aggr = AGGR_BUF_MIDDLE;
4453 @@ -1160,6 +1182,9 @@ static void ath_tx_fill_desc(struct ath_
4454                         info.aggr_len = len;
4455                 }
4456  
4457 +               if (bf == bf_first->bf_lastbf)
4458 +                       bf_first = NULL;
4459 +
4460                 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
4461                 bf = bf->bf_next;
4462         }
4463 @@ -1224,9 +1249,6 @@ int ath_tx_aggr_start(struct ath_softc *
4464         an = (struct ath_node *)sta->drv_priv;
4465         txtid = ATH_AN_2_TID(an, tid);
4466  
4467 -       if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE))
4468 -               return -EAGAIN;
4469 -
4470         /* update ampdu factor/density, they may have changed. This may happen
4471          * in HT IBSS when a beacon with HT-info is received after the station
4472          * has already been added.
4473 @@ -1238,7 +1260,7 @@ int ath_tx_aggr_start(struct ath_softc *
4474                 an->mpdudensity = density;
4475         }
4476  
4477 -       txtid->state |= AGGR_ADDBA_PROGRESS;
4478 +       txtid->active = true;
4479         txtid->paused = true;
4480         *ssn = txtid->seq_start = txtid->seq_next;
4481         txtid->bar_index = -1;
4482 @@ -1255,28 +1277,9 @@ void ath_tx_aggr_stop(struct ath_softc *
4483         struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
4484         struct ath_txq *txq = txtid->ac->txq;
4485  
4486 -       if (txtid->state & AGGR_CLEANUP)
4487 -               return;
4488 -
4489 -       if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
4490 -               txtid->state &= ~AGGR_ADDBA_PROGRESS;
4491 -               return;
4492 -       }
4493 -
4494         ath_txq_lock(sc, txq);
4495 +       txtid->active = false;
4496         txtid->paused = true;
4497 -
4498 -       /*
4499 -        * If frames are still being transmitted for this TID, they will be
4500 -        * cleaned up during tx completion. To prevent race conditions, this
4501 -        * TID can only be reused after all in-progress subframes have been
4502 -        * completed.
4503 -        */
4504 -       if (txtid->baw_head != txtid->baw_tail)
4505 -               txtid->state |= AGGR_CLEANUP;
4506 -       else
4507 -               txtid->state &= ~AGGR_ADDBA_COMPLETE;
4508 -
4509         ath_tx_flush_tid(sc, txtid);
4510         ath_txq_unlock_complete(sc, txq);
4511  }
4512 @@ -1342,18 +1345,92 @@ void ath_tx_aggr_wakeup(struct ath_softc
4513         }
4514  }
4515  
4516 -void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
4517 +void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta,
4518 +                       u16 tidno)
4519  {
4520 -       struct ath_atx_tid *txtid;
4521 +       struct ath_atx_tid *tid;
4522         struct ath_node *an;
4523 +       struct ath_txq *txq;
4524  
4525         an = (struct ath_node *)sta->drv_priv;
4526 +       tid = ATH_AN_2_TID(an, tidno);
4527 +       txq = tid->ac->txq;
4528  
4529 -       txtid = ATH_AN_2_TID(an, tid);
4530 -       txtid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4531 -       txtid->state |= AGGR_ADDBA_COMPLETE;
4532 -       txtid->state &= ~AGGR_ADDBA_PROGRESS;
4533 -       ath_tx_resume_tid(sc, txtid);
4534 +       ath_txq_lock(sc, txq);
4535 +
4536 +       tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4537 +       tid->paused = false;
4538 +
4539 +       if (!skb_queue_empty(&tid->buf_q)) {
4540 +               ath_tx_queue_tid(txq, tid);
4541 +               ath_txq_schedule(sc, txq);
4542 +       }
4543 +
4544 +       ath_txq_unlock_complete(sc, txq);
4545 +}
4546 +
4547 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
4548 +                                  struct ieee80211_sta *sta,
4549 +                                  u16 tids, int nframes,
4550 +                                  enum ieee80211_frame_release_type reason,
4551 +                                  bool more_data)
4552 +{
4553 +       struct ath_softc *sc = hw->priv;
4554 +       struct ath_node *an = (struct ath_node *)sta->drv_priv;
4555 +       struct ath_txq *txq = sc->tx.uapsdq;
4556 +       struct ieee80211_tx_info *info;
4557 +       struct list_head bf_q;
4558 +       struct ath_buf *bf_tail = NULL, *bf;
4559 +       int sent = 0;
4560 +       int i;
4561 +
4562 +       INIT_LIST_HEAD(&bf_q);
4563 +       for (i = 0; tids && nframes; i++, tids >>= 1) {
4564 +               struct ath_atx_tid *tid;
4565 +
4566 +               if (!(tids & 1))
4567 +                       continue;
4568 +
4569 +               tid = ATH_AN_2_TID(an, i);
4570 +               if (tid->paused)
4571 +                       continue;
4572 +
4573 +               ath_txq_lock(sc, tid->ac->txq);
4574 +               while (!skb_queue_empty(&tid->buf_q) && nframes > 0) {
4575 +                       bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
4576 +                       if (!bf)
4577 +                               break;
4578 +
4579 +                       __skb_unlink(bf->bf_mpdu, &tid->buf_q);
4580 +                       list_add_tail(&bf->list, &bf_q);
4581 +                       ath_set_rates(tid->an->vif, tid->an->sta, bf);
4582 +                       ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4583 +                       bf->bf_state.bf_type &= ~BUF_AGGR;
4584 +                       if (bf_tail)
4585 +                               bf_tail->bf_next = bf;
4586 +
4587 +                       bf_tail = bf;
4588 +                       nframes--;
4589 +                       sent++;
4590 +                       TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4591 +
4592 +                       if (skb_queue_empty(&tid->buf_q))
4593 +                               ieee80211_sta_set_buffered(an->sta, i, false);
4594 +               }
4595 +               ath_txq_unlock_complete(sc, tid->ac->txq);
4596 +       }
4597 +
4598 +       if (list_empty(&bf_q))
4599 +               return;
4600 +
4601 +       info = IEEE80211_SKB_CB(bf_tail->bf_mpdu);
4602 +       info->flags |= IEEE80211_TX_STATUS_EOSP;
4603 +
4604 +       bf = list_first_entry(&bf_q, struct ath_buf, list);
4605 +       ath_txq_lock(sc, txq);
4606 +       ath_tx_fill_desc(sc, bf, txq, 0);
4607 +       ath_tx_txqaddbuf(sc, txq, &bf_q, false);
4608 +       ath_txq_unlock(sc, txq);
4609  }
4610  
4611  /********************/
4612 @@ -1709,8 +1786,9 @@ static void ath_tx_txqaddbuf(struct ath_
4613         }
4614  }
4615  
4616 -static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
4617 -                             struct sk_buff *skb, struct ath_tx_control *txctl)
4618 +static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_txq *txq,
4619 +                             struct ath_atx_tid *tid, struct sk_buff *skb,
4620 +                             struct ath_tx_control *txctl)
4621  {
4622         struct ath_frame_info *fi = get_frame_info(skb);
4623         struct list_head bf_head;
4624 @@ -1723,26 +1801,28 @@ static void ath_tx_send_ampdu(struct ath
4625          * - seqno is not within block-ack window
4626          * - h/w queue depth exceeds low water mark
4627          */
4628 -       if (!skb_queue_empty(&tid->buf_q) || tid->paused ||
4629 -           !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4630 -           txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) {
4631 +       if ((!skb_queue_empty(&tid->buf_q) || tid->paused ||
4632 +            !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4633 +            txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
4634 +           txq != sc->tx.uapsdq) {
4635                 /*
4636                  * Add this frame to software queue for scheduling later
4637                  * for aggregation.
4638                  */
4639 -               TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw);
4640 +               TX_STAT_INC(txq->axq_qnum, a_queued_sw);
4641                 __skb_queue_tail(&tid->buf_q, skb);
4642                 if (!txctl->an || !txctl->an->sleeping)
4643 -                       ath_tx_queue_tid(txctl->txq, tid);
4644 +                       ath_tx_queue_tid(txq, tid);
4645                 return;
4646         }
4647  
4648 -       bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4649 +       bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4650         if (!bf) {
4651                 ieee80211_free_txskb(sc->hw, skb);
4652                 return;
4653         }
4654  
4655 +       ath_set_rates(tid->an->vif, tid->an->sta, bf);
4656         bf->bf_state.bf_type = BUF_AMPDU;
4657         INIT_LIST_HEAD(&bf_head);
4658         list_add(&bf->list, &bf_head);
4659 @@ -1751,10 +1831,10 @@ static void ath_tx_send_ampdu(struct ath
4660         ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4661  
4662         /* Queue to h/w without aggregation */
4663 -       TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw);
4664 +       TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4665         bf->bf_lastbf = bf;
4666 -       ath_tx_fill_desc(sc, bf, txctl->txq, fi->framelen);
4667 -       ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false);
4668 +       ath_tx_fill_desc(sc, bf, txq, fi->framelen);
4669 +       ath_tx_txqaddbuf(sc, txq, &bf_head, false);
4670  }
4671  
4672  static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
4673 @@ -1892,49 +1972,6 @@ static struct ath_buf *ath_tx_setup_buff
4674         return bf;
4675  }
4676  
4677 -/* FIXME: tx power */
4678 -static void ath_tx_start_dma(struct ath_softc *sc, struct sk_buff *skb,
4679 -                            struct ath_tx_control *txctl)
4680 -{
4681 -       struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4682 -       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4683 -       struct ath_atx_tid *tid = NULL;
4684 -       struct ath_buf *bf;
4685 -       u8 tidno;
4686 -
4687 -       if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4688 -               tidno = ieee80211_get_qos_ctl(hdr)[0] &
4689 -                       IEEE80211_QOS_CTL_TID_MASK;
4690 -               tid = ATH_AN_2_TID(txctl->an, tidno);
4691 -
4692 -               WARN_ON(tid->ac->txq != txctl->txq);
4693 -       }
4694 -
4695 -       if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4696 -               /*
4697 -                * Try aggregation if it's a unicast data frame
4698 -                * and the destination is HT capable.
4699 -                */
4700 -               ath_tx_send_ampdu(sc, tid, skb, txctl);
4701 -       } else {
4702 -               bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4703 -               if (!bf) {
4704 -                       if (txctl->paprd)
4705 -                               dev_kfree_skb_any(skb);
4706 -                       else
4707 -                               ieee80211_free_txskb(sc->hw, skb);
4708 -                       return;
4709 -               }
4710 -
4711 -               bf->bf_state.bfs_paprd = txctl->paprd;
4712 -
4713 -               if (txctl->paprd)
4714 -                       bf->bf_state.bfs_paprd_timestamp = jiffies;
4715 -
4716 -               ath_tx_send_normal(sc, txctl->txq, tid, skb);
4717 -       }
4718 -}
4719 -
4720  /* Upon failure caller should free skb */
4721  int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
4722                  struct ath_tx_control *txctl)
4723 @@ -1945,8 +1982,11 @@ int ath_tx_start(struct ieee80211_hw *hw
4724         struct ieee80211_vif *vif = info->control.vif;
4725         struct ath_softc *sc = hw->priv;
4726         struct ath_txq *txq = txctl->txq;
4727 +       struct ath_atx_tid *tid = NULL;
4728 +       struct ath_buf *bf;
4729         int padpos, padsize;
4730         int frmlen = skb->len + FCS_LEN;
4731 +       u8 tidno;
4732         int q;
4733  
4734         /* NOTE:  sta can be NULL according to net/mac80211.h */
4735 @@ -2002,8 +2042,47 @@ int ath_tx_start(struct ieee80211_hw *hw
4736                 txq->stopped = true;
4737         }
4738  
4739 -       ath_tx_start_dma(sc, skb, txctl);
4740 +       if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
4741 +               ath_txq_unlock(sc, txq);
4742 +               txq = sc->tx.uapsdq;
4743 +               ath_txq_lock(sc, txq);
4744 +       }
4745 +
4746 +       if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4747 +               tidno = ieee80211_get_qos_ctl(hdr)[0] &
4748 +                       IEEE80211_QOS_CTL_TID_MASK;
4749 +               tid = ATH_AN_2_TID(txctl->an, tidno);
4750 +
4751 +               WARN_ON(tid->ac->txq != txctl->txq);
4752 +       }
4753 +
4754 +       if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4755 +               /*
4756 +                * Try aggregation if it's a unicast data frame
4757 +                * and the destination is HT capable.
4758 +                */
4759 +               ath_tx_send_ampdu(sc, txq, tid, skb, txctl);
4760 +               goto out;
4761 +       }
4762 +
4763 +       bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4764 +       if (!bf) {
4765 +               if (txctl->paprd)
4766 +                       dev_kfree_skb_any(skb);
4767 +               else
4768 +                       ieee80211_free_txskb(sc->hw, skb);
4769 +               goto out;
4770 +       }
4771 +
4772 +       bf->bf_state.bfs_paprd = txctl->paprd;
4773 +
4774 +       if (txctl->paprd)
4775 +               bf->bf_state.bfs_paprd_timestamp = jiffies;
4776 +
4777 +       ath_set_rates(vif, sta, bf);
4778 +       ath_tx_send_normal(sc, txq, tid, skb);
4779  
4780 +out:
4781         ath_txq_unlock(sc, txq);
4782  
4783         return 0;
4784 @@ -2054,7 +2133,12 @@ static void ath_tx_complete(struct ath_s
4785         }
4786         spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
4787  
4788 +       __skb_queue_tail(&txq->complete_q, skb);
4789 +
4790         q = skb_get_queue_mapping(skb);
4791 +       if (txq == sc->tx.uapsdq)
4792 +               txq = sc->tx.txq_map[q];
4793 +
4794         if (txq == sc->tx.txq_map[q]) {
4795                 if (WARN_ON(--txq->pending_frames < 0))
4796                         txq->pending_frames = 0;
4797 @@ -2065,8 +2149,6 @@ static void ath_tx_complete(struct ath_s
4798                         txq->stopped = false;
4799                 }
4800         }
4801 -
4802 -       __skb_queue_tail(&txq->complete_q, skb);
4803  }
4804  
4805  static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
4806 @@ -2408,12 +2490,10 @@ void ath_tx_node_init(struct ath_softc *
4807                 tid->baw_head  = tid->baw_tail = 0;
4808                 tid->sched     = false;
4809                 tid->paused    = false;
4810 -               tid->state &= ~AGGR_CLEANUP;
4811 +               tid->active        = false;
4812                 __skb_queue_head_init(&tid->buf_q);
4813                 acno = TID_TO_WME_AC(tidno);
4814                 tid->ac = &an->ac[acno];
4815 -               tid->state &= ~AGGR_ADDBA_COMPLETE;
4816 -               tid->state &= ~AGGR_ADDBA_PROGRESS;
4817         }
4818  
4819         for (acno = 0, ac = &an->ac[acno];
4820 @@ -2450,9 +2530,9 @@ void ath_tx_node_cleanup(struct ath_soft
4821                 }
4822  
4823                 ath_tid_drain(sc, txq, tid);
4824 -               tid->state &= ~AGGR_ADDBA_COMPLETE;
4825 -               tid->state &= ~AGGR_CLEANUP;
4826 +               tid->active = false;
4827  
4828                 ath_txq_unlock(sc, txq);
4829         }
4830  }
4831 +
4832 --- a/drivers/net/wireless/ath/ath9k/recv.c
4833 +++ b/drivers/net/wireless/ath/ath9k/recv.c
4834 @@ -124,7 +124,7 @@ static bool ath_rx_edma_buf_link(struct 
4835  
4836         SKB_CB_ATHBUF(skb) = bf;
4837         ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
4838 -       skb_queue_tail(&rx_edma->rx_fifo, skb);
4839 +       __skb_queue_tail(&rx_edma->rx_fifo, skb);
4840  
4841         return true;
4842  }
4843 @@ -155,7 +155,7 @@ static void ath_rx_remove_buffer(struct 
4844  
4845         rx_edma = &sc->rx.rx_edma[qtype];
4846  
4847 -       while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4848 +       while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4849                 bf = SKB_CB_ATHBUF(skb);
4850                 BUG_ON(!bf);
4851                 list_add_tail(&bf->list, &sc->rx.rxbuf);
4852 @@ -1287,13 +1287,13 @@ int ath_rx_tasklet(struct ath_softc *sc,
4853                         goto requeue_drop_frag;
4854                 }
4855  
4856 -               bf->bf_mpdu = requeue_skb;
4857 -               bf->bf_buf_addr = new_buf_addr;
4858 -
4859                 /* Unmap the frame */
4860                 dma_unmap_single(sc->dev, bf->bf_buf_addr,
4861                                  common->rx_bufsize, dma_type);
4862  
4863 +               bf->bf_mpdu = requeue_skb;
4864 +               bf->bf_buf_addr = new_buf_addr;
4865 +
4866                 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
4867                 if (ah->caps.rx_status_len)
4868                         skb_pull(skb, ah->caps.rx_status_len);
4869 --- a/net/wireless/core.c
4870 +++ b/net/wireless/core.c
4871 @@ -885,7 +885,6 @@ void cfg80211_leave(struct cfg80211_regi
4872  #endif
4873                 __cfg80211_disconnect(rdev, dev,
4874                                       WLAN_REASON_DEAUTH_LEAVING, true);
4875 -               cfg80211_mlme_down(rdev, dev);
4876                 wdev_unlock(wdev);
4877                 break;
4878         case NL80211_IFTYPE_MESH_POINT:
4879 --- a/net/wireless/sme.c
4880 +++ b/net/wireless/sme.c
4881 @@ -961,7 +961,7 @@ int __cfg80211_disconnect(struct cfg8021
4882                 /* was it connected by userspace SME? */
4883                 if (!wdev->conn) {
4884                         cfg80211_mlme_down(rdev, dev);
4885 -                       return 0;
4886 +                       goto disconnect;
4887                 }
4888  
4889                 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
4890 @@ -987,6 +987,7 @@ int __cfg80211_disconnect(struct cfg8021
4891                         return err;
4892         }
4893  
4894 + disconnect:
4895         if (wdev->sme_state == CFG80211_SME_CONNECTED)
4896                 __cfg80211_disconnected(dev, NULL, 0, 0, false);
4897         else if (wdev->sme_state == CFG80211_SME_CONNECTING)
4898 --- a/drivers/net/wireless/ath/ath9k/rc.c
4899 +++ b/drivers/net/wireless/ath/ath9k/rc.c
4900 @@ -1227,10 +1227,7 @@ static bool ath_tx_aggr_check(struct ath
4901                 return false;
4902  
4903         txtid = ATH_AN_2_TID(an, tidno);
4904 -
4905 -       if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
4906 -                       return true;
4907 -       return false;
4908 +       return !txtid->active;
4909  }
4910  
4911  
4912 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4913 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4914 @@ -334,7 +334,8 @@ static void ar9003_hw_spur_ofdm(struct a
4915         REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
4916                       AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
4917  
4918 -       if (REG_READ_FIELD(ah, AR_PHY_MODE,
4919 +       if (!AR_SREV_9340(ah) &&
4920 +           REG_READ_FIELD(ah, AR_PHY_MODE,
4921                            AR_PHY_MODE_DYNAMIC) == 0x1)
4922                 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
4923                               AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
4924 --- a/drivers/net/wireless/ath/ath9k/mac.c
4925 +++ b/drivers/net/wireless/ath/ath9k/mac.c
4926 @@ -410,7 +410,7 @@ bool ath9k_hw_resettxqueue(struct ath_hw
4927  
4928         REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
4929  
4930 -       if (AR_SREV_9340(ah))
4931 +       if (AR_SREV_9340(ah) && !AR_SREV_9340_13_OR_LATER(ah))
4932                 REG_WRITE(ah, AR_DMISC(q),
4933                           AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
4934         else
4935 --- a/net/mac80211/driver-ops.h
4936 +++ b/net/mac80211/driver-ops.h
4937 @@ -146,7 +146,8 @@ static inline int drv_add_interface(stru
4938  
4939         if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
4940                     (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
4941 -                    !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))))
4942 +                    !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF) &&
4943 +                    !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
4944                 return -EINVAL;
4945  
4946         trace_drv_add_interface(local, sdata);
4947 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
4948 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
4949 @@ -454,6 +454,8 @@ static bool create_pa_curve(u32 *data_L,
4950                 if (accum_cnt <= thresh_accum_cnt)
4951                         continue;
4952  
4953 +               max_index++;
4954 +
4955                 /* sum(tx amplitude) */
4956                 accum_tx = ((data_L[i] >> 16) & 0xffff) |
4957                     ((data_U[i] & 0x7ff) << 16);
4958 @@ -468,20 +470,21 @@ static bool create_pa_curve(u32 *data_L,
4959  
4960                 accum_tx <<= scale_factor;
4961                 accum_rx <<= scale_factor;
4962 -               x_est[i + 1] = (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
4963 -                   scale_factor;
4964 +               x_est[max_index] =
4965 +                       (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
4966 +                       scale_factor;
4967  
4968 -               Y[i + 1] = ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
4969 +               Y[max_index] =
4970 +                       ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
4971                             scale_factor) +
4972 -                           (1 << scale_factor) * max_index + 16;
4973 +                       (1 << scale_factor) * i + 16;
4974  
4975                 if (accum_ang >= (1 << 26))
4976                         accum_ang -= 1 << 27;
4977  
4978 -               theta[i + 1] = ((accum_ang * (1 << scale_factor)) + accum_cnt) /
4979 -                   accum_cnt;
4980 -
4981 -               max_index++;
4982 +               theta[max_index] =
4983 +                       ((accum_ang * (1 << scale_factor)) + accum_cnt) /
4984 +                       accum_cnt;
4985         }
4986  
4987         /*
4988 --- a/drivers/net/wireless/ath/ath9k/beacon.c
4989 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
4990 @@ -204,9 +204,15 @@ static struct ath_buf *ath9k_beacon_gene
4991         }
4992  
4993         ath9k_beacon_setup(sc, vif, bf, info->control.rates[0].idx);
4994 +       sc->beacon.cabq_dur = 0;
4995  
4996         while (skb) {
4997                 ath9k_tx_cabq(hw, skb);
4998 +
4999 +               if (sc->beacon.cabq_dur / 1000 - 1 >
5000 +                   sc->cur_beacon_conf.beacon_interval / ATH_BCBUF)
5001 +                       break;
5002 +
5003                 skb = ieee80211_get_buffered_bc(hw, vif);
5004         }
5005