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