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