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