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