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 */
7 + struct ieee80211_tx_rate rates[4];
8 struct ath_buf_state bf_state;
11 @@ -253,6 +254,7 @@ struct ath_atx_tid {
19 @@ -350,7 +352,8 @@ void ath_tx_tasklet(struct ath_softc *sc
20 void ath_tx_edma_tasklet(struct ath_softc *sc);
21 int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
23 -void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
24 +bool ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid,
26 void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid);
28 void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
29 @@ -658,11 +661,10 @@ enum sc_op_flags {
30 struct ath_rate_table;
32 struct ath9k_vif_iter_data {
33 - const u8 *hw_macaddr; /* phy's hardware address, set
34 - * before starting iteration for
37 + u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
38 u8 mask[ETH_ALEN]; /* bssid mask */
39 + bool has_hw_macaddr;
41 int naps; /* number of AP vifs */
42 int nmeshes; /* number of mesh vifs */
43 int nstations; /* number of station vifs */
44 --- a/drivers/net/wireless/ath/ath9k/hw.c
45 +++ b/drivers/net/wireless/ath/ath9k/hw.c
46 @@ -1366,7 +1366,10 @@ static bool ath9k_hw_set_reset(struct at
48 REGWRITE_BUFFER_FLUSH(ah);
51 + if (AR_SREV_9100(ah))
56 REG_WRITE(ah, AR_RTC_RC, 0);
57 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
58 @@ -1377,8 +1380,12 @@ static bool ath9k_hw_set_reset(struct at
59 if (!AR_SREV_9100(ah))
60 REG_WRITE(ah, AR_RC, 0);
62 - if (AR_SREV_9100(ah))
63 + if (AR_SREV_9100(ah) && type != ATH9K_RESET_WARM) {
64 + if (ah->external_reset)
65 + ah->external_reset();
72 @@ -1464,7 +1471,8 @@ static bool ath9k_hw_chip_reset(struct a
73 reset_type = ATH9K_RESET_POWER_ON;
75 reset_type = ATH9K_RESET_COLD;
76 - } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
77 + } else if (ah->chip_fullsleep ||
78 + REG_READ(ah, AR_Q_TXE) ||
79 (REG_READ(ah, AR_CR) & AR_CR_RXE))
80 reset_type = ATH9K_RESET_COLD;
82 @@ -1698,12 +1706,11 @@ static void ath9k_hw_reset_opmode(struct
84 ENABLE_REGWRITE_BUFFER(ah);
86 - REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
87 - REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
89 + REG_RMW(ah, AR_STA_ID1, macStaId1
90 | AR_STA_ID1_RTS_USE_DEF
91 | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
92 - | ah->sta_id1_defaults);
93 + | ah->sta_id1_defaults,
94 + ~AR_STA_ID1_SADH_MASK);
95 ath_hw_setbssidmask(common);
96 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
97 ath9k_hw_write_associd(ah);
98 --- a/drivers/net/wireless/ath/ath9k/main.c
99 +++ b/drivers/net/wireless/ath/ath9k/main.c
100 @@ -839,10 +839,14 @@ static void ath9k_vif_iter(void *data, u
101 struct ath9k_vif_iter_data *iter_data = data;
104 - if (iter_data->hw_macaddr)
105 + if (iter_data->has_hw_macaddr) {
106 for (i = 0; i < ETH_ALEN; i++)
107 iter_data->mask[i] &=
108 ~(iter_data->hw_macaddr[i] ^ mac[i]);
110 + memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
111 + iter_data->has_hw_macaddr = true;
115 case NL80211_IFTYPE_AP:
116 @@ -891,7 +895,6 @@ void ath9k_calculate_iter_data(struct ie
117 * together with the BSSID mask when matching addresses.
119 memset(iter_data, 0, sizeof(*iter_data));
120 - iter_data->hw_macaddr = common->macaddr;
121 memset(&iter_data->mask, 0xff, ETH_ALEN);
124 @@ -901,6 +904,8 @@ void ath9k_calculate_iter_data(struct ie
125 ieee80211_iterate_active_interfaces_atomic(
126 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
127 ath9k_vif_iter, iter_data);
129 + memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
132 /* Called with sc->mutex held. */
133 @@ -1327,6 +1332,7 @@ static int ath9k_sta_add(struct ieee8021
134 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
135 struct ath_node *an = (struct ath_node *) sta->drv_priv;
136 struct ieee80211_key_conf ps_key = { };
139 ath_node_attach(sc, sta, vif);
141 @@ -1334,7 +1340,9 @@ static int ath9k_sta_add(struct ieee8021
142 vif->type != NL80211_IFTYPE_AP_VLAN)
145 - an->ps_key = ath_key_config(common, vif, sta, &ps_key);
146 + key = ath_key_config(common, vif, sta, &ps_key);
152 @@ -1351,6 +1359,7 @@ static void ath9k_del_ps_key(struct ath_
155 ath_key_delete(common, &ps_key);
159 static int ath9k_sta_remove(struct ieee80211_hw *hw,
160 @@ -1678,6 +1687,7 @@ static int ath9k_ampdu_action(struct iee
161 u16 tid, u16 *ssn, u8 buf_size)
163 struct ath_softc *sc = hw->priv;
164 + bool flush = false, cb;
168 @@ -1694,12 +1704,14 @@ static int ath9k_ampdu_action(struct iee
169 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
170 ath9k_ps_restore(sc);
172 - case IEEE80211_AMPDU_TX_STOP_CONT:
173 case IEEE80211_AMPDU_TX_STOP_FLUSH:
174 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
176 + case IEEE80211_AMPDU_TX_STOP_CONT:
178 - ath_tx_aggr_stop(sc, sta, tid);
179 - ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
180 + cb = ath_tx_aggr_stop(sc, sta, tid, flush);
182 + ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
183 ath9k_ps_restore(sc);
185 case IEEE80211_AMPDU_TX_OPERATIONAL:
186 --- a/drivers/net/wireless/ath/ath9k/reg.h
187 +++ b/drivers/net/wireless/ath/ath9k/reg.h
188 @@ -1493,9 +1493,6 @@ enum {
189 #define AR9271_RADIO_RF_RST 0x20
190 #define AR9271_GATE_MAC_CTL 0x4000
192 -#define AR_STA_ID0 0x8000
193 -#define AR_STA_ID1 0x8004
194 -#define AR_STA_ID1_SADH_MASK 0x0000FFFF
195 #define AR_STA_ID1_STA_AP 0x00010000
196 #define AR_STA_ID1_ADHOC 0x00020000
197 #define AR_STA_ID1_PWR_SAV 0x00040000
198 --- a/drivers/net/wireless/ath/hw.c
199 +++ b/drivers/net/wireless/ath/hw.c
201 void ath_hw_setbssidmask(struct ath_common *common)
203 void *ah = common->ah;
206 + REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
207 + id1 = REG_READ(ah, AR_STA_ID1) & ~AR_STA_ID1_SADH_MASK;
208 + id1 |= get_unaligned_le16(common->macaddr + 4);
209 + REG_WRITE(ah, AR_STA_ID1, id1);
211 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
212 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
213 --- a/drivers/net/wireless/ath/reg.h
214 +++ b/drivers/net/wireless/ath/reg.h
216 #define AR_MIBC_CMC 0x00000004
217 #define AR_MIBC_MCS 0x00000008
219 +#define AR_STA_ID0 0x8000
220 +#define AR_STA_ID1 0x8004
221 +#define AR_STA_ID1_SADH_MASK 0x0000ffff
224 * BSSID mask registers. See ath_hw_set_bssid_mask()
225 * for detailed documentation about these registers.
226 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
227 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
228 @@ -6059,7 +6059,7 @@ il4965_mac_channel_switch(struct ieee802
229 struct il_priv *il = hw->priv;
230 const struct il_channel_info *ch_info;
231 struct ieee80211_conf *conf = &hw->conf;
232 - struct ieee80211_channel *channel = ch_switch->channel;
233 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
234 struct il_ht_config *ht_conf = &il->current_ht_config;
237 @@ -6096,23 +6096,21 @@ il4965_mac_channel_switch(struct ieee802
238 il->current_ht_config.smps = conf->smps_mode;
240 /* Configure HT40 channels */
241 - il->ht.enabled = conf_is_ht(conf);
242 - if (il->ht.enabled) {
243 - if (conf_is_ht40_minus(conf)) {
244 - il->ht.extension_chan_offset =
245 - IEEE80211_HT_PARAM_CHA_SEC_BELOW;
246 - il->ht.is_40mhz = true;
247 - } else if (conf_is_ht40_plus(conf)) {
248 - il->ht.extension_chan_offset =
249 - IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
250 - il->ht.is_40mhz = true;
252 - il->ht.extension_chan_offset =
253 - IEEE80211_HT_PARAM_CHA_SEC_NONE;
254 - il->ht.is_40mhz = false;
257 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
258 + case NL80211_CHAN_NO_HT:
259 + case NL80211_CHAN_HT20:
260 il->ht.is_40mhz = false;
261 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
263 + case NL80211_CHAN_HT40MINUS:
264 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
265 + il->ht.is_40mhz = true;
267 + case NL80211_CHAN_HT40PLUS:
268 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
269 + il->ht.is_40mhz = true;
273 if ((le16_to_cpu(il->staging.channel) != ch))
274 il->staging.flags = 0;
275 --- a/drivers/net/wireless/iwlegacy/4965.c
276 +++ b/drivers/net/wireless/iwlegacy/4965.c
277 @@ -1493,7 +1493,7 @@ il4965_hw_channel_switch(struct il_priv
280 cmd.expect_beacon = 0;
281 - ch = ch_switch->channel->hw_value;
282 + ch = ch_switch->chandef.chan->hw_value;
283 cmd.channel = cpu_to_le16(ch);
284 cmd.rxon_flags = il->staging.flags;
285 cmd.rxon_filter_flags = il->staging.filter_flags;
286 --- a/drivers/net/wireless/iwlwifi/dvm/devices.c
287 +++ b/drivers/net/wireless/iwlwifi/dvm/devices.c
288 @@ -379,7 +379,7 @@ static int iwl5000_hw_channel_switch(str
291 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
292 - ch = ch_switch->channel->hw_value;
293 + ch = ch_switch->chandef.chan->hw_value;
294 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
295 ctx->active.channel, ch);
296 cmd.channel = cpu_to_le16(ch);
297 @@ -414,7 +414,8 @@ static int iwl5000_hw_channel_switch(str
299 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
301 - cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
302 + cmd.expect_beacon =
303 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
305 return iwl_dvm_send_cmd(priv, &hcmd);
307 @@ -540,7 +541,7 @@ static int iwl6000_hw_channel_switch(str
310 cmd->band = priv->band == IEEE80211_BAND_2GHZ;
311 - ch = ch_switch->channel->hw_value;
312 + ch = ch_switch->chandef.chan->hw_value;
313 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
314 ctx->active.channel, ch);
315 cmd->channel = cpu_to_le16(ch);
316 @@ -575,7 +576,8 @@ static int iwl6000_hw_channel_switch(str
318 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
320 - cmd->expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
321 + cmd->expect_beacon =
322 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
324 err = iwl_dvm_send_cmd(priv, &hcmd);
326 --- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
327 +++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
328 @@ -970,7 +970,7 @@ static void iwlagn_mac_channel_switch(st
330 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
331 struct ieee80211_conf *conf = &hw->conf;
332 - struct ieee80211_channel *channel = ch_switch->channel;
333 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
334 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
337 @@ -1008,11 +1008,21 @@ static void iwlagn_mac_channel_switch(st
338 priv->current_ht_config.smps = conf->smps_mode;
340 /* Configure HT40 channels */
341 - ctx->ht.enabled = conf_is_ht(conf);
342 - if (ctx->ht.enabled)
343 - iwlagn_config_ht40(conf, ctx);
345 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
346 + case NL80211_CHAN_NO_HT:
347 + case NL80211_CHAN_HT20:
348 ctx->ht.is_40mhz = false;
349 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
351 + case NL80211_CHAN_HT40MINUS:
352 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
353 + ctx->ht.is_40mhz = true;
355 + case NL80211_CHAN_HT40PLUS:
356 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
357 + ctx->ht.is_40mhz = true;
361 if ((le16_to_cpu(ctx->staging.channel) != ch))
362 ctx->staging.flags = 0;
363 --- a/drivers/net/wireless/iwlwifi/dvm/rxon.c
364 +++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c
365 @@ -1160,7 +1160,7 @@ int iwlagn_commit_rxon(struct iwl_priv *
368 void iwlagn_config_ht40(struct ieee80211_conf *conf,
369 - struct iwl_rxon_context *ctx)
370 + struct iwl_rxon_context *ctx)
372 if (conf_is_ht40_minus(conf)) {
373 ctx->ht.extension_chan_offset =
374 --- a/drivers/net/wireless/mac80211_hwsim.c
375 +++ b/drivers/net/wireless/mac80211_hwsim.c
377 #include <linux/if_arp.h>
378 #include <linux/rtnetlink.h>
379 #include <linux/etherdevice.h>
380 +#include <linux/platform_device.h>
381 #include <linux/debugfs.h>
382 #include <linux/module.h>
383 #include <linux/ktime.h>
384 @@ -717,9 +718,17 @@ static bool mac80211_hwsim_tx_frame_no_n
385 rx_status.flag |= RX_FLAG_MACTIME_START;
386 rx_status.freq = chan->center_freq;
387 rx_status.band = chan->band;
388 - rx_status.rate_idx = info->control.rates[0].idx;
389 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
390 - rx_status.flag |= RX_FLAG_HT;
391 + if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
392 + rx_status.rate_idx =
393 + ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
394 + rx_status.vht_nss =
395 + ieee80211_rate_get_vht_nss(&info->control.rates[0]);
396 + rx_status.flag |= RX_FLAG_VHT;
398 + rx_status.rate_idx = info->control.rates[0].idx;
399 + if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
400 + rx_status.flag |= RX_FLAG_HT;
402 if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
403 rx_status.flag |= RX_FLAG_40MHZ;
404 if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
405 @@ -1687,6 +1696,7 @@ static void mac80211_hwsim_free(void)
406 debugfs_remove(data->debugfs_ps);
407 debugfs_remove(data->debugfs);
408 ieee80211_unregister_hw(data->hw);
409 + device_release_driver(data->dev);
410 device_unregister(data->dev);
411 ieee80211_free_hw(data->hw);
413 @@ -1695,7 +1705,9 @@ static void mac80211_hwsim_free(void)
416 static struct device_driver mac80211_hwsim_driver = {
417 - .name = "mac80211_hwsim"
418 + .name = "mac80211_hwsim",
419 + .bus = &platform_bus_type,
420 + .owner = THIS_MODULE,
423 static const struct net_device_ops hwsim_netdev_ops = {
424 @@ -2187,9 +2199,15 @@ static int __init init_mac80211_hwsim(vo
425 spin_lock_init(&hwsim_radio_lock);
426 INIT_LIST_HEAD(&hwsim_radios);
428 + err = driver_register(&mac80211_hwsim_driver);
432 hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
433 - if (IS_ERR(hwsim_class))
434 - return PTR_ERR(hwsim_class);
435 + if (IS_ERR(hwsim_class)) {
436 + err = PTR_ERR(hwsim_class);
437 + goto failed_unregister_driver;
440 memset(addr, 0, ETH_ALEN);
442 @@ -2211,12 +2229,20 @@ static int __init init_mac80211_hwsim(vo
444 if (IS_ERR(data->dev)) {
446 - "mac80211_hwsim: device_create "
447 - "failed (%ld)\n", PTR_ERR(data->dev));
448 + "mac80211_hwsim: device_create failed (%ld)\n",
449 + PTR_ERR(data->dev));
453 data->dev->driver = &mac80211_hwsim_driver;
454 + err = device_bind_driver(data->dev);
457 + "mac80211_hwsim: device_bind_driver failed (%d)\n",
462 skb_queue_head_init(&data->pending);
464 SET_IEEE80211_DEV(hw, data->dev);
465 @@ -2515,6 +2541,8 @@ failed_drvdata:
466 ieee80211_free_hw(hw);
468 mac80211_hwsim_free();
469 +failed_unregister_driver:
470 + driver_unregister(&mac80211_hwsim_driver);
473 module_init(init_mac80211_hwsim);
474 @@ -2527,5 +2555,6 @@ static void __exit exit_mac80211_hwsim(v
476 mac80211_hwsim_free();
477 unregister_netdev(hwsim_mon);
478 + driver_unregister(&mac80211_hwsim_driver);
480 module_exit(exit_mac80211_hwsim);
481 --- a/drivers/net/wireless/ti/wl12xx/cmd.c
482 +++ b/drivers/net/wireless/ti/wl12xx/cmd.c
483 @@ -301,7 +301,7 @@ int wl12xx_cmd_channel_switch(struct wl1
486 cmd->role_id = wlvif->role_id;
487 - cmd->channel = ch_switch->channel->hw_value;
488 + cmd->channel = ch_switch->chandef.chan->hw_value;
489 cmd->switch_time = ch_switch->count;
490 cmd->stop_tx = ch_switch->block_tx;
492 --- a/drivers/net/wireless/ti/wl18xx/cmd.c
493 +++ b/drivers/net/wireless/ti/wl18xx/cmd.c
494 @@ -42,11 +42,11 @@ int wl18xx_cmd_channel_switch(struct wl1
497 cmd->role_id = wlvif->role_id;
498 - cmd->channel = ch_switch->channel->hw_value;
499 + cmd->channel = ch_switch->chandef.chan->hw_value;
500 cmd->switch_time = ch_switch->count;
501 cmd->stop_tx = ch_switch->block_tx;
503 - switch (ch_switch->channel->band) {
504 + switch (ch_switch->chandef.chan->band) {
505 case IEEE80211_BAND_2GHZ:
506 cmd->band = WLCORE_BAND_2_4GHZ;
508 @@ -55,7 +55,7 @@ int wl18xx_cmd_channel_switch(struct wl1
511 wl1271_error("invalid channel switch band: %d",
512 - ch_switch->channel->band);
513 + ch_switch->chandef.chan->band);
517 --- a/include/linux/ieee80211.h
518 +++ b/include/linux/ieee80211.h
519 @@ -673,6 +673,36 @@ struct ieee80211_channel_sw_ie {
523 + * struct ieee80211_ext_chansw_ie
525 + * This structure represents the "Extended Channel Switch Announcement element"
527 +struct ieee80211_ext_chansw_ie {
529 + u8 new_operating_class;
535 + * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
536 + * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
538 + * This structure represents the "Secondary Channel Offset element"
540 +struct ieee80211_sec_chan_offs_ie {
545 + * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
547 +struct ieee80211_wide_bw_chansw_ie {
548 + u8 new_channel_width;
549 + u8 new_center_freq_seg0, new_center_freq_seg1;
553 * struct ieee80211_tim
555 * This structure refers to "Traffic Indication Map information element"
556 @@ -840,12 +870,15 @@ struct ieee80211_mgmt {
557 } __packed wme_action;
562 - struct ieee80211_channel_sw_ie sw_elem;
564 } __packed chan_switch;
567 + struct ieee80211_ext_chansw_ie data;
569 + } __packed ext_chan_switch;
575 @@ -1638,6 +1671,7 @@ enum ieee80211_eid {
577 WLAN_EID_HT_CAPABILITY = 45,
578 WLAN_EID_HT_OPERATION = 61,
579 + WLAN_EID_SECONDARY_CHANNEL_OFFSET = 62,
583 @@ -1672,6 +1706,8 @@ enum ieee80211_eid {
584 WLAN_EID_VHT_CAPABILITY = 191,
585 WLAN_EID_VHT_OPERATION = 192,
586 WLAN_EID_OPMODE_NOTIF = 199,
587 + WLAN_EID_WIDE_BW_CHANNEL_SWITCH = 194,
588 + WLAN_EID_CHANNEL_SWITCH_WRAPPER = 196,
591 WLAN_EID_NON_TX_BSSID_CAP = 83,
592 @@ -1795,6 +1831,7 @@ enum ieee80211_key_len {
594 /* Public action codes */
595 enum ieee80211_pub_actioncode {
596 + WLAN_PUB_ACTION_EXT_CHANSW_ANN = 4,
597 WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
600 --- a/include/net/cfg80211.h
601 +++ b/include/net/cfg80211.h
602 @@ -753,6 +753,8 @@ int cfg80211_check_station_change(struct
603 * @STATION_INFO_LOCAL_PM: @local_pm filled
604 * @STATION_INFO_PEER_PM: @peer_pm filled
605 * @STATION_INFO_NONPEER_PM: @nonpeer_pm filled
606 + * @STATION_INFO_CHAIN_SIGNAL: @chain_signal filled
607 + * @STATION_INFO_CHAIN_SIGNAL_AVG: @chain_signal_avg filled
609 enum station_info_flags {
610 STATION_INFO_INACTIVE_TIME = 1<<0,
611 @@ -781,6 +783,8 @@ enum station_info_flags {
612 STATION_INFO_NONPEER_PM = 1<<23,
613 STATION_INFO_RX_BYTES64 = 1<<24,
614 STATION_INFO_TX_BYTES64 = 1<<25,
615 + STATION_INFO_CHAIN_SIGNAL = 1<<26,
616 + STATION_INFO_CHAIN_SIGNAL_AVG = 1<<27,
620 @@ -857,6 +861,8 @@ struct sta_bss_parameters {
624 +#define IEEE80211_MAX_CHAINS 4
627 * struct station_info - station information
629 @@ -874,6 +880,9 @@ struct sta_bss_parameters {
630 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
631 * @signal_avg: Average signal strength, type depends on the wiphy's signal_type.
632 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
633 + * @chains: bitmask for filled values in @chain_signal, @chain_signal_avg
634 + * @chain_signal: per-chain signal strength of last received packet in dBm
635 + * @chain_signal_avg: per-chain signal strength average in dBm
636 * @txrate: current unicast bitrate from this station
637 * @rxrate: current unicast bitrate to this station
638 * @rx_packets: packets received from this station
639 @@ -909,6 +918,11 @@ struct station_info {
645 + s8 chain_signal[IEEE80211_MAX_CHAINS];
646 + s8 chain_signal_avg[IEEE80211_MAX_CHAINS];
648 struct rate_info txrate;
649 struct rate_info rxrate;
651 @@ -4027,6 +4041,17 @@ bool cfg80211_reg_can_beacon(struct wiph
652 void cfg80211_ch_switch_notify(struct net_device *dev,
653 struct cfg80211_chan_def *chandef);
656 + * ieee80211_operating_class_to_band - convert operating class to band
658 + * @operating_class: the operating class to convert
659 + * @band: band pointer to fill
661 + * Returns %true if the conversion was successful, %false otherwise.
663 +bool ieee80211_operating_class_to_band(u8 operating_class,
664 + enum ieee80211_band *band);
667 * cfg80211_tdls_oper_request - request userspace to perform TDLS operation
668 * @dev: the device on which the operation is requested
669 --- a/include/net/mac80211.h
670 +++ b/include/net/mac80211.h
671 @@ -210,7 +210,7 @@ struct ieee80211_chanctx_conf {
672 * @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
673 * that it is only ever disabled for station mode.
674 * @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
675 - * @BSS_CHANGED_SSID: SSID changed for this BSS (AP mode)
676 + * @BSS_CHANGED_SSID: SSID changed for this BSS (AP and IBSS mode)
677 * @BSS_CHANGED_AP_PROBE_RESP: Probe Response changed for this BSS (AP mode)
678 * @BSS_CHANGED_PS: PS changed for this BSS (STA mode)
679 * @BSS_CHANGED_TXPOWER: TX power setting changed for this interface
680 @@ -327,7 +327,7 @@ enum ieee80211_rssi_event {
681 * your driver/device needs to do.
682 * @ps: power-save mode (STA only). This flag is NOT affected by
683 * offchannel/dynamic_ps operations.
684 - * @ssid: The SSID of the current vif. Only valid in AP-mode.
685 + * @ssid: The SSID of the current vif. Valid in AP and IBSS mode.
686 * @ssid_len: Length of SSID given in @ssid.
687 * @hidden_ssid: The SSID of the current vif is hidden. Only valid in AP-mode.
688 * @txpower: TX power in dBm
689 @@ -562,6 +562,9 @@ enum mac80211_rate_control_flags {
690 /* maximum number of rate stages */
691 #define IEEE80211_TX_MAX_RATES 4
693 +/* maximum number of rate table entries */
694 +#define IEEE80211_TX_RATE_TABLE_SIZE 4
697 * struct ieee80211_tx_rate - rate selection/status
699 @@ -602,8 +605,8 @@ static inline void ieee80211_rate_set_vh
703 - WARN_ON(nss & ~0x7);
704 - rate->idx = (nss << 4) | mcs;
705 + WARN_ON((nss - 1) & ~0x7);
706 + rate->idx = ((nss - 1) << 4) | mcs;
710 @@ -615,7 +618,7 @@ ieee80211_rate_get_vht_mcs(const struct
712 ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate)
714 - return rate->idx >> 4;
715 + return (rate->idx >> 4) + 1;
719 @@ -656,7 +659,11 @@ struct ieee80211_tx_info {
720 struct ieee80211_tx_rate rates[
721 IEEE80211_TX_MAX_RATES];
726 + u8 short_preamble:1;
730 /* only needed before rate control */
731 unsigned long jiffies;
732 @@ -677,6 +684,8 @@ struct ieee80211_tx_info {
734 struct ieee80211_tx_rate driver_rates[
735 IEEE80211_TX_MAX_RATES];
738 void *rate_driver_data[
739 IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE / sizeof(void *)];
741 @@ -840,6 +849,9 @@ enum mac80211_rx_flags {
742 * @signal: signal strength when receiving this frame, either in dBm, in dB or
743 * unspecified depending on the hardware capabilities flags
744 * @IEEE80211_HW_SIGNAL_*
745 + * @chains: bitmask of receive chains for which separate signal strength
746 + * values were filled.
747 + * @chain_signal: per-chain signal strength, same format as @signal
748 * @antenna: antenna used
749 * @rate_idx: index of data rate into band's supported rates or MCS index if
750 * HT or VHT is used (%RX_FLAG_HT/%RX_FLAG_VHT)
751 @@ -871,6 +883,8 @@ struct ieee80211_rx_status {
756 + s8 chain_signal[IEEE80211_MAX_CHAINS];
757 u8 ampdu_delimiter_crc;
758 u8 vendor_radiotap_align;
759 u8 vendor_radiotap_oui[3];
760 @@ -1018,13 +1032,13 @@ struct ieee80211_conf {
761 * the driver passed into mac80211.
762 * @block_tx: Indicates whether transmission must be blocked before the
763 * scheduled channel switch, as indicated by the AP.
764 - * @channel: the new channel to switch to
765 + * @chandef: the new channel to switch to
766 * @count: the number of TBTT's until the channel switch event
768 struct ieee80211_channel_switch {
771 - struct ieee80211_channel *channel;
772 + struct cfg80211_chan_def chandef;
776 @@ -1222,6 +1236,24 @@ enum ieee80211_sta_rx_bandwidth {
780 + * struct ieee80211_sta_rates - station rate selection table
782 + * @rcu_head: RCU head used for freeing the table on update
783 + * @rates: transmit rates/flags to be used by default.
784 + * Overriding entries per-packet is possible by using cb tx control.
786 +struct ieee80211_sta_rates {
787 + struct rcu_head rcu_head;
794 + } rate[IEEE80211_TX_RATE_TABLE_SIZE];
798 * struct ieee80211_sta - station table entry
800 * A station table entry represents a station we are possibly
801 @@ -1248,6 +1280,7 @@ enum ieee80211_sta_rx_bandwidth {
802 * notifications and capabilities. The value is only valid after
803 * the station moves to associated state.
804 * @smps_mode: current SMPS mode (off, static or dynamic)
805 + * @tx_rates: rate control selection table
807 struct ieee80211_sta {
808 u32 supp_rates[IEEE80211_NUM_BANDS];
809 @@ -1261,6 +1294,7 @@ struct ieee80211_sta {
811 enum ieee80211_sta_rx_bandwidth bandwidth;
812 enum ieee80211_smps_mode smps_mode;
813 + struct ieee80211_sta_rates __rcu *rates;
816 u8 drv_priv[0] __aligned(sizeof(void *));
817 @@ -1416,6 +1450,9 @@ struct ieee80211_tx_control {
818 * for different virtual interfaces. See the doc section on HW queue
819 * control for more details.
821 + * @IEEE80211_HW_SUPPORTS_RC_TABLE: The driver supports using a rate
822 + * selection table provided by the rate control algorithm.
824 * @IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF: Use the P2P Device address for any
825 * P2P Interface. This will be honoured even if more than one interface
827 @@ -1448,6 +1485,7 @@ enum ieee80211_hw_flags {
828 IEEE80211_HW_SUPPORTS_PER_STA_GTK = 1<<21,
829 IEEE80211_HW_AP_LINK_PS = 1<<22,
830 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW = 1<<23,
831 + IEEE80211_HW_SUPPORTS_RC_TABLE = 1<<24,
832 IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF = 1<<25,
833 IEEE80211_HW_TIMING_BEACON_ONLY = 1<<26,
835 @@ -3144,6 +3182,25 @@ void ieee80211_sta_set_buffered(struct i
836 u8 tid, bool buffered);
839 + * ieee80211_get_tx_rates - get the selected transmit rates for a packet
841 + * Call this function in a driver with per-packet rate selection support
842 + * to combine the rate info in the packet tx info with the most recent
843 + * rate selection table for the station entry.
845 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
846 + * @sta: the receiver station to which this packet is sent.
847 + * @skb: the frame to be transmitted.
848 + * @dest: buffer for extracted rate/retry information
849 + * @max_rates: maximum number of rates to fetch
851 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
852 + struct ieee80211_sta *sta,
853 + struct sk_buff *skb,
854 + struct ieee80211_tx_rate *dest,
858 * ieee80211_tx_status - transmit status callback
860 * Call this function for all transmitted frames after they have been
861 @@ -4118,7 +4175,7 @@ void ieee80211_send_bar(struct ieee80211
862 * (deprecated; this will be removed once drivers get updated to use
864 * @rate_idx_mask: user-requested (legacy) rate mask
865 - * @rate_idx_mcs_mask: user-requested MCS rate mask
866 + * @rate_idx_mcs_mask: user-requested MCS rate mask (NULL if not in use)
867 * @bss: whether this frame is sent out in AP or IBSS mode
869 struct ieee80211_tx_rate_control {
870 @@ -4130,7 +4187,7 @@ struct ieee80211_tx_rate_control {
871 bool rts, short_preamble;
874 - u8 rate_idx_mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
875 + u8 *rate_idx_mcs_mask;
879 @@ -4219,6 +4276,22 @@ bool rate_usable_index_exists(struct iee
884 + * rate_control_set_rates - pass the sta rate selection to mac80211/driver
886 + * When not doing a rate control probe to test rates, rate control should pass
887 + * its rate selection to mac80211. If the driver supports receiving a station
888 + * rate table, it will use it to ensure that frames are always sent based on
889 + * the most recent rate control module decision.
891 + * @hw: pointer as obtained from ieee80211_alloc_hw()
892 + * @pubsta: &struct ieee80211_sta pointer to the target destination.
893 + * @rates: new tx rate set to be used for this station.
895 +int rate_control_set_rates(struct ieee80211_hw *hw,
896 + struct ieee80211_sta *pubsta,
897 + struct ieee80211_sta_rates *rates);
899 int ieee80211_rate_control_register(struct rate_control_ops *ops);
900 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
902 --- a/net/mac80211/agg-rx.c
903 +++ b/net/mac80211/agg-rx.c
904 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
905 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
906 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
907 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
908 + else if (sdata->vif.type == NL80211_IFTYPE_WDS)
909 + memcpy(mgmt->bssid, da, ETH_ALEN);
911 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
912 IEEE80211_STYPE_ACTION);
913 --- a/net/mac80211/agg-tx.c
914 +++ b/net/mac80211/agg-tx.c
915 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
916 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
917 if (sdata->vif.type == NL80211_IFTYPE_AP ||
918 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
919 - sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
920 + sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
921 + sdata->vif.type == NL80211_IFTYPE_WDS)
922 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
923 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
924 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
925 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
926 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
927 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
928 sdata->vif.type != NL80211_IFTYPE_AP &&
929 + sdata->vif.type != NL80211_IFTYPE_WDS &&
930 sdata->vif.type != NL80211_IFTYPE_ADHOC)
933 --- a/net/mac80211/cfg.c
934 +++ b/net/mac80211/cfg.c
935 @@ -444,7 +444,7 @@ static void sta_set_sinfo(struct sta_inf
936 struct ieee80211_local *local = sdata->local;
937 struct timespec uptime;
942 sinfo->generation = sdata->local->sta_generation;
944 @@ -488,6 +488,17 @@ static void sta_set_sinfo(struct sta_inf
945 sinfo->signal = (s8)sta->last_signal;
946 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
949 + sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
950 + STATION_INFO_CHAIN_SIGNAL_AVG;
952 + sinfo->chains = sta->chains;
953 + for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
954 + sinfo->chain_signal[i] = sta->chain_signal_last[i];
955 + sinfo->chain_signal_avg[i] =
956 + (s8) -ewma_read(&sta->chain_signal_avg[i]);
960 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
961 sta_set_rate_info_rx(sta, &sinfo->rxrate);
962 @@ -1052,6 +1063,7 @@ static int ieee80211_stop_ap(struct wiph
963 ieee80211_free_keys(sdata);
965 sdata->vif.bss_conf.enable_beacon = false;
966 + sdata->vif.bss_conf.ssid_len = 0;
967 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
968 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
970 @@ -2416,9 +2428,22 @@ static int ieee80211_set_bitrate_mask(st
973 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
974 + struct ieee80211_supported_band *sband = wiphy->bands[i];
977 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
978 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
979 sizeof(mask->control[i].mcs));
981 + sdata->rc_has_mcs_mask[i] = false;
985 + for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
986 + if (~sdata->rc_rateidx_mcs_mask[i][j]) {
987 + sdata->rc_has_mcs_mask[i] = true;
993 --- a/net/mac80211/chan.c
994 +++ b/net/mac80211/chan.c
995 @@ -57,6 +57,22 @@ ieee80211_find_chanctx(struct ieee80211_
999 +static bool ieee80211_is_radar_required(struct ieee80211_local *local)
1001 + struct ieee80211_sub_if_data *sdata;
1004 + list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1005 + if (sdata->radar_required) {
1006 + rcu_read_unlock();
1010 + rcu_read_unlock();
1015 static struct ieee80211_chanctx *
1016 ieee80211_new_chanctx(struct ieee80211_local *local,
1017 const struct cfg80211_chan_def *chandef,
1018 @@ -76,6 +92,9 @@ ieee80211_new_chanctx(struct ieee80211_l
1019 ctx->conf.rx_chains_static = 1;
1020 ctx->conf.rx_chains_dynamic = 1;
1022 + ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
1023 + if (!local->use_chanctx)
1024 + local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
1026 /* acquire mutex to prevent idle from changing */
1027 mutex_lock(&local->mtx);
1028 @@ -110,6 +129,7 @@ ieee80211_new_chanctx(struct ieee80211_l
1029 static void ieee80211_free_chanctx(struct ieee80211_local *local,
1030 struct ieee80211_chanctx *ctx)
1032 + bool check_single_channel = false;
1033 lockdep_assert_held(&local->chanctx_mtx);
1035 WARN_ON_ONCE(ctx->refcount != 0);
1036 @@ -119,6 +139,14 @@ static void ieee80211_free_chanctx(struc
1037 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1038 chandef->center_freq1 = chandef->chan->center_freq;
1039 chandef->center_freq2 = 0;
1041 + /* NOTE: Disabling radar is only valid here for
1042 + * single channel context. To be sure, check it ...
1044 + if (local->hw.conf.radar_enabled)
1045 + check_single_channel = true;
1046 + local->hw.conf.radar_enabled = false;
1048 ieee80211_hw_config(local, 0);
1050 drv_remove_chanctx(local, ctx);
1051 @@ -127,6 +155,9 @@ static void ieee80211_free_chanctx(struc
1052 list_del_rcu(&ctx->list);
1053 kfree_rcu(ctx, rcu_head);
1055 + /* throw a warning if this wasn't the only channel context. */
1056 + WARN_ON(check_single_channel && !list_empty(&local->chanctx_list));
1058 mutex_lock(&local->mtx);
1059 ieee80211_recalc_idle(local);
1060 mutex_unlock(&local->mtx);
1061 @@ -238,19 +269,11 @@ static void __ieee80211_vif_release_chan
1062 void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
1063 struct ieee80211_chanctx *chanctx)
1065 - struct ieee80211_sub_if_data *sdata;
1066 - bool radar_enabled = false;
1067 + bool radar_enabled;
1069 lockdep_assert_held(&local->chanctx_mtx);
1072 - list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1073 - if (sdata->radar_required) {
1074 - radar_enabled = true;
1078 - rcu_read_unlock();
1079 + radar_enabled = ieee80211_is_radar_required(local);
1081 if (radar_enabled == chanctx->conf.radar_enabled)
1083 --- a/net/mac80211/debugfs_sta.c
1084 +++ b/net/mac80211/debugfs_sta.c
1085 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
1086 test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
1088 int res = scnprintf(buf, sizeof(buf),
1089 - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1090 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1091 TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
1092 TEST(PS_DRIVER), TEST(AUTHORIZED),
1093 TEST(SHORT_PREAMBLE),
1094 - TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
1095 + TEST(WME), TEST(CLEAR_PS_FILT),
1096 TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
1097 TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
1098 TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
1099 --- a/net/mac80211/ibss.c
1100 +++ b/net/mac80211/ibss.c
1101 @@ -209,6 +209,8 @@ static void __ieee80211_sta_join_ibss(st
1102 sdata->vif.bss_conf.enable_beacon = true;
1103 sdata->vif.bss_conf.beacon_int = beacon_int;
1104 sdata->vif.bss_conf.basic_rates = basic_rates;
1105 + sdata->vif.bss_conf.ssid_len = ifibss->ssid_len;
1106 + memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len);
1107 bss_change = BSS_CHANGED_BEACON_INT;
1108 bss_change |= ieee80211_reset_erp_info(sdata);
1109 bss_change |= BSS_CHANGED_BSSID;
1110 @@ -217,6 +219,7 @@ static void __ieee80211_sta_join_ibss(st
1111 bss_change |= BSS_CHANGED_BASIC_RATES;
1112 bss_change |= BSS_CHANGED_HT;
1113 bss_change |= BSS_CHANGED_IBSS;
1114 + bss_change |= BSS_CHANGED_SSID;
1117 * In 5 GHz/802.11a, we can always use short slot time.
1118 @@ -911,7 +914,7 @@ void ieee80211_rx_mgmt_probe_beacon(stru
1121 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1125 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1127 @@ -1159,6 +1162,7 @@ int ieee80211_ibss_leave(struct ieee8021
1128 sdata->vif.bss_conf.ibss_joined = false;
1129 sdata->vif.bss_conf.ibss_creator = false;
1130 sdata->vif.bss_conf.enable_beacon = false;
1131 + sdata->vif.bss_conf.ssid_len = 0;
1132 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1133 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1135 --- a/net/mac80211/ieee80211_i.h
1136 +++ b/net/mac80211/ieee80211_i.h
1137 @@ -156,6 +156,7 @@ struct ieee80211_tx_data {
1138 struct ieee80211_sub_if_data *sdata;
1139 struct sta_info *sta;
1140 struct ieee80211_key *key;
1141 + struct ieee80211_tx_rate rate;
1145 @@ -740,6 +741,8 @@ struct ieee80211_sub_if_data {
1147 /* bitmap of allowed (non-MCS) rate indexes for rate control */
1148 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
1150 + bool rc_has_mcs_mask[IEEE80211_NUM_BANDS];
1151 u8 rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN];
1154 @@ -1025,7 +1028,7 @@ struct ieee80211_local {
1155 enum mac80211_scan_state next_scan_state;
1156 struct delayed_work scan_work;
1157 struct ieee80211_sub_if_data __rcu *scan_sdata;
1158 - struct ieee80211_channel *csa_channel;
1159 + struct cfg80211_chan_def csa_chandef;
1160 /* For backward compatibility only -- do not use */
1161 struct cfg80211_chan_def _oper_chandef;
1163 @@ -1184,10 +1187,13 @@ struct ieee802_11_elems {
1165 const struct ieee80211_rann_ie *rann;
1166 const struct ieee80211_channel_sw_ie *ch_switch_ie;
1167 + const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1168 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1169 const u8 *country_elem;
1170 const u8 *pwr_constr_elem;
1171 const struct ieee80211_timeout_interval_ie *timeout_int;
1172 const u8 *opmode_notif;
1173 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1175 /* length of them, respectively */
1177 @@ -1258,10 +1264,6 @@ void ieee80211_recalc_ps_vif(struct ieee
1178 int ieee80211_max_network_latency(struct notifier_block *nb,
1179 unsigned long data, void *dummy);
1180 int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1182 -ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1183 - const struct ieee80211_channel_sw_ie *sw_elem,
1184 - struct ieee80211_bss *bss, u64 timestamp);
1185 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1186 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1187 struct sk_buff *skb);
1188 @@ -1499,13 +1501,13 @@ static inline void ieee80211_tx_skb(stru
1189 ieee80211_tx_skb_tid(sdata, skb, 7);
1192 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1193 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
1194 struct ieee802_11_elems *elems,
1195 u64 filter, u32 crc);
1196 -static inline void ieee802_11_parse_elems(u8 *start, size_t len,
1197 +static inline void ieee802_11_parse_elems(u8 *start, size_t len, bool action,
1198 struct ieee802_11_elems *elems)
1200 - ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
1201 + ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0);
1204 u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1205 --- a/net/mac80211/iface.c
1206 +++ b/net/mac80211/iface.c
1207 @@ -450,7 +450,6 @@ int ieee80211_do_open(struct wireless_de
1208 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1209 struct net_device *dev = wdev->netdev;
1210 struct ieee80211_local *local = sdata->local;
1211 - struct sta_info *sta;
1214 u32 hw_reconf_flags = 0;
1215 @@ -609,30 +608,8 @@ int ieee80211_do_open(struct wireless_de
1217 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1219 - if (sdata->vif.type == NL80211_IFTYPE_WDS) {
1220 - /* Create STA entry for the WDS peer */
1221 - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1225 - goto err_del_interface;
1228 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1229 - sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1230 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1232 - res = sta_info_insert(sta);
1234 - /* STA has been freed */
1235 - goto err_del_interface;
1238 - rate_control_rate_init(sta);
1239 - netif_carrier_on(dev);
1240 - } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
1241 + if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
1242 rcu_assign_pointer(local->p2p_sdata, sdata);
1246 * set_multicast_list will be invoked by the networking core
1247 @@ -1092,6 +1069,74 @@ static void ieee80211_if_setup(struct ne
1248 dev->destructor = free_netdev;
1251 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1252 + struct sk_buff *skb)
1254 + struct ieee80211_local *local = sdata->local;
1255 + struct ieee80211_rx_status *rx_status;
1256 + struct ieee802_11_elems elems;
1257 + struct ieee80211_mgmt *mgmt;
1258 + struct sta_info *sta;
1263 + enum ieee80211_band band;
1264 + struct ieee80211_supported_band *sband;
1266 + rx_status = IEEE80211_SKB_RXCB(skb);
1267 + band = rx_status->band;
1268 + sband = local->hw.wiphy->bands[band];
1269 + mgmt = (struct ieee80211_mgmt *) skb->data;
1270 + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1272 + if (stype != IEEE80211_STYPE_BEACON)
1275 + baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1276 + if (baselen > skb->len)
1279 + ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1280 + skb->len - baselen, false, &elems);
1282 + rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
1286 + sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
1289 + rcu_read_unlock();
1290 + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1298 + sta->last_rx = jiffies;
1299 + sta->sta.supp_rates[band] = rates;
1301 + if (elems.ht_cap_elem)
1302 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1303 + elems.ht_cap_elem, sta);
1305 + if (elems.wmm_param)
1306 + set_sta_flag(sta, WLAN_STA_WME);
1309 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1310 + sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1311 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1312 + rate_control_rate_init(sta);
1313 + sta_info_insert_rcu(sta);
1316 + rcu_read_unlock();
1319 static void ieee80211_iface_work(struct work_struct *work)
1321 struct ieee80211_sub_if_data *sdata =
1322 @@ -1196,6 +1241,9 @@ static void ieee80211_iface_work(struct
1324 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1326 + case NL80211_IFTYPE_WDS:
1327 + ieee80211_wds_rx_queued_mgmt(sdata, skb);
1330 WARN(1, "frame for unexpected interface type");
1332 --- a/net/mac80211/main.c
1333 +++ b/net/mac80211/main.c
1334 @@ -674,6 +674,7 @@ int ieee80211_register_hw(struct ieee802
1335 int channels, max_bitrates;
1336 bool supp_ht, supp_vht;
1337 netdev_features_t feature_whitelist;
1338 + struct cfg80211_chan_def dflt_chandef = {};
1339 static const u32 cipher_suites[] = {
1340 /* keep WEP first, it may be removed below */
1341 WLAN_CIPHER_SUITE_WEP40,
1342 @@ -751,19 +752,19 @@ int ieee80211_register_hw(struct ieee802
1343 sband = local->hw.wiphy->bands[band];
1346 - if (!local->use_chanctx && !local->_oper_chandef.chan) {
1348 + if (!dflt_chandef.chan) {
1349 + cfg80211_chandef_create(&dflt_chandef,
1350 + &sband->channels[0],
1351 + NL80211_CHAN_NO_HT);
1352 /* init channel we're on */
1353 - struct cfg80211_chan_def chandef = {
1354 - .chan = &sband->channels[0],
1355 - .width = NL80211_CHAN_NO_HT,
1356 - .center_freq1 = sband->channels[0].center_freq,
1359 - local->hw.conf.chandef = local->_oper_chandef = chandef;
1360 + if (!local->use_chanctx && !local->_oper_chandef.chan) {
1361 + local->hw.conf.chandef = dflt_chandef;
1362 + local->_oper_chandef = dflt_chandef;
1364 + local->monitor_chandef = dflt_chandef;
1366 - cfg80211_chandef_create(&local->monitor_chandef,
1367 - &sband->channels[0],
1368 - NL80211_CHAN_NO_HT);
1370 channels += sband->n_channels;
1372 if (max_bitrates < sband->n_bitrates)
1373 --- a/net/mac80211/mesh.c
1374 +++ b/net/mac80211/mesh.c
1375 @@ -838,7 +838,7 @@ ieee80211_mesh_rx_probe_req(struct ieee8
1379 - ieee802_11_parse_elems(pos, len - baselen, &elems);
1380 + ieee802_11_parse_elems(pos, len - baselen, false, &elems);
1382 /* 802.11-2012 10.1.4.3.2 */
1383 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
1384 @@ -899,7 +899,7 @@ static void ieee80211_mesh_rx_bcn_presp(
1387 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1391 /* ignore non-mesh or secure / unsecure mismatch */
1392 if ((!elems.mesh_id || !elems.mesh_config) ||
1393 --- a/net/mac80211/mesh_hwmp.c
1394 +++ b/net/mac80211/mesh_hwmp.c
1395 @@ -880,7 +880,7 @@ void mesh_rx_path_sel_frame(struct ieee8
1397 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
1398 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
1399 - len - baselen, &elems);
1400 + len - baselen, false, &elems);
1403 if (elems.preq_len != 37)
1404 --- a/net/mac80211/mesh_plink.c
1405 +++ b/net/mac80211/mesh_plink.c
1406 @@ -544,8 +544,8 @@ static void mesh_plink_timer(unsigned lo
1410 - "Mesh plink timer for %pM fired on state %d\n",
1411 - sta->sta.addr, sta->plink_state);
1412 + "Mesh plink timer for %pM fired on state %s\n",
1413 + sta->sta.addr, mplstates[sta->plink_state]);
1417 @@ -687,7 +687,7 @@ void mesh_rx_plink_frame(struct ieee8021
1421 - ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
1422 + ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1424 if (!elems.peering) {
1426 --- a/net/mac80211/mlme.c
1427 +++ b/net/mac80211/mlme.c
1428 @@ -289,6 +289,8 @@ ieee80211_determine_chantype(struct ieee
1430 /* 40 MHz (and 80 MHz) must be supported for VHT */
1431 ret = IEEE80211_STA_DISABLE_VHT;
1432 + /* also mark 40 MHz disabled */
1433 + ret |= IEEE80211_STA_DISABLE_40MHZ;
1437 @@ -303,12 +305,6 @@ ieee80211_determine_chantype(struct ieee
1439 vht_chandef.center_freq2 = 0;
1441 - if (vht_oper->center_freq_seg2_idx)
1442 - vht_chandef.center_freq2 =
1443 - ieee80211_channel_to_frequency(
1444 - vht_oper->center_freq_seg2_idx,
1447 switch (vht_oper->chan_width) {
1448 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1449 vht_chandef.width = chandef->width;
1450 @@ -321,6 +317,10 @@ ieee80211_determine_chantype(struct ieee
1452 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1453 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1454 + vht_chandef.center_freq2 =
1455 + ieee80211_channel_to_frequency(
1456 + vht_oper->center_freq_seg2_idx,
1461 @@ -604,7 +604,6 @@ static void ieee80211_add_vht_ie(struct
1464 struct ieee80211_sta_vht_cap vht_cap;
1467 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
1469 @@ -632,37 +631,6 @@ static void ieee80211_add_vht_ie(struct
1470 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
1471 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1473 - if (!(ap_vht_cap->vht_cap_info &
1474 - cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
1475 - cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
1476 - IEEE80211_VHT_CAP_RXSTBC_3 |
1477 - IEEE80211_VHT_CAP_RXSTBC_4);
1479 - for (i = 0; i < 8; i++) {
1480 - int shift = i * 2;
1481 - u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
1482 - u16 ap_mcs, our_mcs;
1484 - ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
1486 - our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
1489 - if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
1494 - if (our_mcs <= ap_mcs)
1496 - /* fall through */
1497 - case IEEE80211_VHT_MCS_NOT_SUPPORTED:
1498 - vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
1499 - vht_cap.vht_mcs.rx_mcs_map |=
1500 - cpu_to_le16(ap_mcs << shift);
1504 /* reserve and fill IE */
1505 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
1506 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
1507 @@ -998,16 +966,7 @@ static void ieee80211_chswitch_work(stru
1508 if (!ifmgd->associated)
1512 - * FIXME: Here we are downgrading to NL80211_CHAN_WIDTH_20_NOHT
1513 - * and don't adjust our ht/vht settings
1514 - * This is wrong - we should behave according to the CSA params
1516 - local->_oper_chandef.chan = local->csa_channel;
1517 - local->_oper_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
1518 - local->_oper_chandef.center_freq1 =
1519 - local->_oper_chandef.chan->center_freq;
1520 - local->_oper_chandef.center_freq2 = 0;
1521 + local->_oper_chandef = local->csa_chandef;
1523 if (!local->ops->channel_switch) {
1524 /* call "hw_config" only if doing sw channel switch */
1525 @@ -1054,56 +1013,208 @@ static void ieee80211_chswitch_timer(uns
1526 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1531 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1532 - const struct ieee80211_channel_sw_ie *sw_elem,
1533 - struct ieee80211_bss *bss, u64 timestamp)
1534 + u64 timestamp, struct ieee802_11_elems *elems,
1537 - struct cfg80211_bss *cbss =
1538 - container_of((void *)bss, struct cfg80211_bss, priv);
1539 - struct ieee80211_channel *new_ch;
1540 + struct ieee80211_local *local = sdata->local;
1541 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1542 - int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
1543 - cbss->channel->band);
1544 + struct cfg80211_bss *cbss = ifmgd->associated;
1545 + struct ieee80211_bss *bss;
1546 struct ieee80211_chanctx *chanctx;
1547 + enum ieee80211_band new_band;
1552 + struct ieee80211_channel *new_chan;
1553 + struct cfg80211_chan_def new_chandef = {};
1554 + struct cfg80211_chan_def new_vht_chandef = {};
1555 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1556 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1557 + const struct ieee80211_ht_operation *ht_oper;
1558 + int secondary_channel_offset = -1;
1560 ASSERT_MGD_MTX(ifmgd);
1562 - if (!ifmgd->associated)
1566 + if (local->scanning)
1569 - if (sdata->local->scanning)
1570 + /* disregard subsequent announcements if we are already processing */
1571 + if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1574 - /* Disregard subsequent beacons if we are already running a timer
1575 - processing a CSA */
1576 + sec_chan_offs = elems->sec_chan_offs;
1577 + wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
1578 + ht_oper = elems->ht_operation;
1580 + if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1581 + IEEE80211_STA_DISABLE_40MHZ)) {
1582 + sec_chan_offs = NULL;
1583 + wide_bw_chansw_ie = NULL;
1584 + /* only used for bandwidth here */
1588 - if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1589 + if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1590 + wide_bw_chansw_ie = NULL;
1592 + if (elems->ext_chansw_ie) {
1593 + if (!ieee80211_operating_class_to_band(
1594 + elems->ext_chansw_ie->new_operating_class,
1597 + "cannot understand ECSA IE operating class %d, disconnecting\n",
1598 + elems->ext_chansw_ie->new_operating_class);
1599 + ieee80211_queue_work(&local->hw,
1600 + &ifmgd->csa_connection_drop_work);
1602 + new_chan_no = elems->ext_chansw_ie->new_ch_num;
1603 + count = elems->ext_chansw_ie->count;
1604 + mode = elems->ext_chansw_ie->mode;
1605 + } else if (elems->ch_switch_ie) {
1606 + new_band = cbss->channel->band;
1607 + new_chan_no = elems->ch_switch_ie->new_ch_num;
1608 + count = elems->ch_switch_ie->count;
1609 + mode = elems->ch_switch_ie->mode;
1611 + /* nothing here we understand */
1615 + bss = (void *)cbss->priv;
1617 - new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1618 - if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
1619 + new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
1620 + new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1621 + if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
1623 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1624 ifmgd->associated->bssid, new_freq);
1625 - ieee80211_queue_work(&sdata->local->hw,
1626 + ieee80211_queue_work(&local->hw,
1627 + &ifmgd->csa_connection_drop_work);
1631 + if (!beacon && sec_chan_offs) {
1632 + secondary_channel_offset = sec_chan_offs->sec_chan_offs;
1633 + } else if (beacon && ht_oper) {
1634 + secondary_channel_offset =
1635 + ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
1636 + } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
1638 + * If it's not a beacon, HT is enabled and the IE not present,
1639 + * it's 20 MHz, 802.11-2012 8.5.2.6:
1640 + * This element [the Secondary Channel Offset Element] is
1641 + * present when switching to a 40 MHz channel. It may be
1642 + * present when switching to a 20 MHz channel (in which
1643 + * case the secondary channel offset is set to SCN).
1645 + secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1648 + switch (secondary_channel_offset) {
1650 + /* secondary_channel_offset was present but is invalid */
1651 + case IEEE80211_HT_PARAM_CHA_SEC_NONE:
1652 + cfg80211_chandef_create(&new_chandef, new_chan,
1653 + NL80211_CHAN_HT20);
1655 + case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1656 + cfg80211_chandef_create(&new_chandef, new_chan,
1657 + NL80211_CHAN_HT40PLUS);
1659 + case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1660 + cfg80211_chandef_create(&new_chandef, new_chan,
1661 + NL80211_CHAN_HT40MINUS);
1664 + cfg80211_chandef_create(&new_chandef, new_chan,
1665 + NL80211_CHAN_NO_HT);
1669 + if (wide_bw_chansw_ie) {
1670 + new_vht_chandef.chan = new_chan;
1671 + new_vht_chandef.center_freq1 =
1672 + ieee80211_channel_to_frequency(
1673 + wide_bw_chansw_ie->new_center_freq_seg0,
1676 + switch (wide_bw_chansw_ie->new_channel_width) {
1678 + /* hmmm, ignore VHT and use HT if present */
1679 + case IEEE80211_VHT_CHANWIDTH_USE_HT:
1680 + new_vht_chandef.chan = NULL;
1682 + case IEEE80211_VHT_CHANWIDTH_80MHZ:
1683 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1685 + case IEEE80211_VHT_CHANWIDTH_160MHZ:
1686 + new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1688 + case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1689 + /* field is otherwise reserved */
1690 + new_vht_chandef.center_freq2 =
1691 + ieee80211_channel_to_frequency(
1692 + wide_bw_chansw_ie->new_center_freq_seg1,
1694 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1697 + if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1698 + new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1699 + chandef_downgrade(&new_vht_chandef);
1700 + if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1701 + new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1702 + chandef_downgrade(&new_vht_chandef);
1703 + if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1704 + new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1705 + chandef_downgrade(&new_vht_chandef);
1708 + /* if VHT data is there validate & use it */
1709 + if (new_vht_chandef.chan) {
1710 + if (!cfg80211_chandef_compatible(&new_vht_chandef,
1713 + "AP %pM CSA has inconsistent channel data, disconnecting\n",
1714 + ifmgd->associated->bssid);
1715 + ieee80211_queue_work(&local->hw,
1716 + &ifmgd->csa_connection_drop_work);
1719 + new_chandef = new_vht_chandef;
1722 + if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1723 + IEEE80211_CHAN_DISABLED)) {
1725 + "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1726 + ifmgd->associated->bssid, new_freq,
1727 + new_chandef.width, new_chandef.center_freq1,
1728 + new_chandef.center_freq2);
1729 + ieee80211_queue_work(&local->hw,
1730 &ifmgd->csa_connection_drop_work);
1734 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
1736 - if (sdata->local->use_chanctx) {
1737 + if (local->use_chanctx) {
1739 "not handling channel switch with channel contexts\n");
1740 - ieee80211_queue_work(&sdata->local->hw,
1741 + ieee80211_queue_work(&local->hw,
1742 &ifmgd->csa_connection_drop_work);
1746 - mutex_lock(&sdata->local->chanctx_mtx);
1747 + mutex_lock(&local->chanctx_mtx);
1748 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
1749 - mutex_unlock(&sdata->local->chanctx_mtx);
1750 + mutex_unlock(&local->chanctx_mtx);
1753 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
1754 @@ -1111,40 +1222,39 @@ ieee80211_sta_process_chanswitch(struct
1755 if (chanctx->refcount > 1) {
1757 "channel switch with multiple interfaces on the same channel, disconnecting\n");
1758 - ieee80211_queue_work(&sdata->local->hw,
1759 + ieee80211_queue_work(&local->hw,
1760 &ifmgd->csa_connection_drop_work);
1761 - mutex_unlock(&sdata->local->chanctx_mtx);
1762 + mutex_unlock(&local->chanctx_mtx);
1765 - mutex_unlock(&sdata->local->chanctx_mtx);
1766 + mutex_unlock(&local->chanctx_mtx);
1768 - sdata->local->csa_channel = new_ch;
1769 + local->csa_chandef = new_chandef;
1771 - if (sw_elem->mode)
1772 - ieee80211_stop_queues_by_reason(&sdata->local->hw,
1774 + ieee80211_stop_queues_by_reason(&local->hw,
1775 IEEE80211_MAX_QUEUE_MAP,
1776 IEEE80211_QUEUE_STOP_REASON_CSA);
1778 - if (sdata->local->ops->channel_switch) {
1779 + if (local->ops->channel_switch) {
1780 /* use driver's channel switch callback */
1781 struct ieee80211_channel_switch ch_switch = {
1782 .timestamp = timestamp,
1783 - .block_tx = sw_elem->mode,
1784 - .channel = new_ch,
1785 - .count = sw_elem->count,
1787 + .chandef = new_chandef,
1791 - drv_channel_switch(sdata->local, &ch_switch);
1792 + drv_channel_switch(local, &ch_switch);
1796 /* channel switch handled in software */
1797 - if (sw_elem->count <= 1)
1798 - ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
1800 + ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1802 mod_timer(&ifmgd->chswitch_timer,
1803 - TU_TO_EXP_TIME(sw_elem->count *
1804 - cbss->beacon_interval));
1805 + TU_TO_EXP_TIME(count * cbss->beacon_interval));
1808 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1809 @@ -2120,7 +2230,6 @@ void ieee80211_beacon_loss(struct ieee80
1811 trace_api_beacon_loss(sdata);
1813 - WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1814 sdata->u.mgd.connection_loss = false;
1815 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1817 @@ -2170,7 +2279,7 @@ static void ieee80211_auth_challenge(str
1820 pos = mgmt->u.auth.variable;
1821 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1822 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
1823 if (!elems.challenge)
1825 auth_data->expected_transaction = 4;
1826 @@ -2435,7 +2544,7 @@ static bool ieee80211_assoc_success(stru
1829 pos = mgmt->u.assoc_resp.variable;
1830 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1831 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
1833 if (!elems.supp_rates) {
1834 sdata_info(sdata, "no SuppRates element in AssocResp\n");
1835 @@ -2604,7 +2713,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
1836 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
1838 pos = mgmt->u.assoc_resp.variable;
1839 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1840 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
1842 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
1843 elems.timeout_int &&
1844 @@ -2659,6 +2768,8 @@ static void ieee80211_rx_bss_info(struct
1845 struct ieee80211_channel *channel;
1846 bool need_ps = false;
1848 + lockdep_assert_held(&sdata->u.mgd.mtx);
1850 if ((sdata->u.mgd.associated &&
1851 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
1852 (sdata->u.mgd.assoc_data &&
1853 @@ -2689,7 +2800,8 @@ static void ieee80211_rx_bss_info(struct
1855 ieee80211_rx_bss_put(local, bss);
1857 - if (!sdata->u.mgd.associated)
1858 + if (!sdata->u.mgd.associated ||
1859 + !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
1863 @@ -2698,10 +2810,9 @@ static void ieee80211_rx_bss_info(struct
1864 mutex_unlock(&local->iflist_mtx);
1867 - if (elems->ch_switch_ie &&
1868 - memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
1869 - ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
1870 - bss, rx_status->mactime);
1871 + ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
1877 @@ -2726,7 +2837,7 @@ static void ieee80211_rx_mgmt_probe_resp
1880 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1884 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1886 @@ -2809,7 +2920,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
1887 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
1888 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
1889 ieee802_11_parse_elems(mgmt->u.beacon.variable,
1890 - len - baselen, &elems);
1891 + len - baselen, false, &elems);
1893 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1894 ifmgd->assoc_data->have_beacon = true;
1895 @@ -2919,7 +3030,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
1897 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1898 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1899 - len - baselen, &elems,
1900 + len - baselen, false, &elems,
1901 care_about_ies, ncrc);
1903 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1904 @@ -3066,6 +3177,8 @@ void ieee80211_sta_rx_queued_mgmt(struct
1905 enum rx_mgmt_action rma = RX_MGMT_NONE;
1906 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
1908 + struct ieee802_11_elems elems;
1911 rx_status = (struct ieee80211_rx_status *) skb->cb;
1912 mgmt = (struct ieee80211_mgmt *) skb->data;
1913 @@ -3095,14 +3208,48 @@ void ieee80211_sta_rx_queued_mgmt(struct
1914 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
1916 case IEEE80211_STYPE_ACTION:
1917 - switch (mgmt->u.action.category) {
1918 - case WLAN_CATEGORY_SPECTRUM_MGMT:
1919 + if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
1920 + ies_len = skb->len -
1921 + offsetof(struct ieee80211_mgmt,
1922 + u.action.u.chan_switch.variable);
1927 + ieee802_11_parse_elems(
1928 + mgmt->u.action.u.chan_switch.variable,
1929 + ies_len, true, &elems);
1931 + if (elems.parse_error)
1934 ieee80211_sta_process_chanswitch(sdata,
1935 - &mgmt->u.action.u.chan_switch.sw_elem,
1936 - (void *)ifmgd->associated->priv,
1937 - rx_status->mactime);
1939 + rx_status->mactime,
1941 + } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
1942 + ies_len = skb->len -
1943 + offsetof(struct ieee80211_mgmt,
1944 + u.action.u.ext_chan_switch.variable);
1949 + ieee802_11_parse_elems(
1950 + mgmt->u.action.u.ext_chan_switch.variable,
1951 + ies_len, true, &elems);
1953 + if (elems.parse_error)
1956 + /* for the handling code pretend this was also an IE */
1957 + elems.ext_chansw_ie =
1958 + &mgmt->u.action.u.ext_chan_switch.data;
1960 + ieee80211_sta_process_chanswitch(sdata,
1961 + rx_status->mactime,
1966 mutex_unlock(&ifmgd->mtx);
1968 @@ -4197,7 +4344,7 @@ int ieee80211_mgd_deauth(struct ieee8021
1969 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1970 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
1971 bool tx = !req->local_state_change;
1972 - bool sent_frame = false;
1973 + bool report_frame = false;
1975 mutex_lock(&ifmgd->mtx);
1977 @@ -4214,7 +4361,7 @@ int ieee80211_mgd_deauth(struct ieee8021
1978 ieee80211_destroy_auth_data(sdata, false);
1979 mutex_unlock(&ifmgd->mtx);
1982 + report_frame = true;
1986 @@ -4222,12 +4369,12 @@ int ieee80211_mgd_deauth(struct ieee8021
1987 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
1988 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
1989 req->reason_code, tx, frame_buf);
1991 + report_frame = true;
1993 mutex_unlock(&ifmgd->mtx);
1998 __cfg80211_send_deauth(sdata->dev, frame_buf,
1999 IEEE80211_DEAUTH_FRAME_LEN);
2001 --- a/net/mac80211/pm.c
2002 +++ b/net/mac80211/pm.c
2003 @@ -38,8 +38,8 @@ int __ieee80211_suspend(struct ieee80211
2004 IEEE80211_MAX_QUEUE_MAP,
2005 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
2007 - /* flush out all packets */
2008 - synchronize_net();
2009 + /* flush out all packets and station cleanup call_rcu()s */
2012 ieee80211_flush_queues(local, NULL);
2014 --- a/net/mac80211/rate.c
2015 +++ b/net/mac80211/rate.c
2016 @@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee802
2020 +static void __rate_control_send_low(struct ieee80211_hw *hw,
2021 + struct ieee80211_supported_band *sband,
2022 + struct ieee80211_sta *sta,
2023 + struct ieee80211_tx_info *info)
2025 + if ((sband->band != IEEE80211_BAND_2GHZ) ||
2026 + !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2027 + info->control.rates[0].idx = rate_lowest_index(sband, sta);
2029 + info->control.rates[0].idx =
2030 + rate_lowest_non_cck_index(sband, sta);
2032 + info->control.rates[0].count =
2033 + (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2034 + 1 : hw->max_rate_tries;
2036 + info->control.skip_table = 1;
2040 bool rate_control_send_low(struct ieee80211_sta *sta,
2042 @@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80
2045 if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
2046 - if ((sband->band != IEEE80211_BAND_2GHZ) ||
2047 - !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2048 - info->control.rates[0].idx =
2049 - rate_lowest_index(txrc->sband, sta);
2051 - info->control.rates[0].idx =
2052 - rate_lowest_non_cck_index(txrc->sband, sta);
2053 - info->control.rates[0].count =
2054 - (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2055 - 1 : txrc->hw->max_rate_tries;
2056 + __rate_control_send_low(txrc->hw, sband, sta, info);
2058 if (!sta && txrc->bss) {
2059 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
2060 if (mcast_rate > 0) {
2061 @@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(stru
2064 static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
2065 - struct ieee80211_tx_rate_control *txrc,
2066 + struct ieee80211_supported_band *sband,
2067 + enum nl80211_chan_width chan_width,
2069 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2071 @@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct i
2072 IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
2073 alt_rate.count = rate->count;
2074 if (rate_idx_match_legacy_mask(&alt_rate,
2075 - txrc->sband->n_bitrates,
2077 + sband->n_bitrates, mask)) {
2082 - struct sk_buff *skb = txrc->skb;
2083 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2086 /* handle legacy rates */
2087 - if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates,
2089 + if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask))
2092 /* if HT BSS, and we handle a data frame, also try HT rates */
2093 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2096 - fc = hdr->frame_control;
2097 - if (!ieee80211_is_data(fc))
2098 + if (chan_width == NL80211_CHAN_WIDTH_20_NOHT)
2102 @@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct i
2104 alt_rate.flags |= IEEE80211_TX_RC_MCS;
2106 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40)
2107 + if (chan_width == NL80211_CHAN_WIDTH_40)
2108 alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2110 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) {
2111 @@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct i
2115 +static void rate_fixup_ratelist(struct ieee80211_vif *vif,
2116 + struct ieee80211_supported_band *sband,
2117 + struct ieee80211_tx_info *info,
2118 + struct ieee80211_tx_rate *rates,
2121 + struct ieee80211_rate *rate;
2122 + bool inval = false;
2126 + * Set up the RTS/CTS rate as the fastest basic rate
2127 + * that is not faster than the data rate unless there
2128 + * is no basic rate slower than the data rate, in which
2129 + * case we pick the slowest basic rate
2131 + * XXX: Should this check all retry rates?
2133 + if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
2134 + u32 basic_rates = vif->bss_conf.basic_rates;
2135 + s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
2137 + rate = &sband->bitrates[rates[0].idx];
2139 + for (i = 0; i < sband->n_bitrates; i++) {
2140 + /* must be a basic rate */
2141 + if (!(basic_rates & BIT(i)))
2143 + /* must not be faster than the data rate */
2144 + if (sband->bitrates[i].bitrate > rate->bitrate)
2147 + if (sband->bitrates[baserate].bitrate <
2148 + sband->bitrates[i].bitrate)
2152 + info->control.rts_cts_rate_idx = baserate;
2155 + for (i = 0; i < max_rates; i++) {
2157 + * make sure there's no valid rate following
2158 + * an invalid one, just in case drivers don't
2159 + * take the API seriously to stop at -1.
2162 + rates[i].idx = -1;
2165 + if (rates[i].idx < 0) {
2171 + * For now assume MCS is already set up correctly, this
2172 + * needs to be fixed.
2174 + if (rates[i].flags & IEEE80211_TX_RC_MCS) {
2175 + WARN_ON(rates[i].idx > 76);
2177 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2178 + info->control.use_cts_prot)
2180 + IEEE80211_TX_RC_USE_CTS_PROTECT;
2184 + if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) {
2185 + WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9);
2189 + /* set up RTS protection if desired */
2190 + if (info->control.use_rts) {
2191 + rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2192 + info->control.use_cts_prot = false;
2195 + /* RC is busted */
2196 + if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) {
2197 + rates[i].idx = -1;
2201 + rate = &sband->bitrates[rates[i].idx];
2203 + /* set up short preamble */
2204 + if (info->control.short_preamble &&
2205 + rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2206 + rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
2208 + /* set up G protection */
2209 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2210 + info->control.use_cts_prot &&
2211 + rate->flags & IEEE80211_RATE_ERP_G)
2212 + rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
2217 +static void rate_control_fill_sta_table(struct ieee80211_sta *sta,
2218 + struct ieee80211_tx_info *info,
2219 + struct ieee80211_tx_rate *rates,
2222 + struct ieee80211_sta_rates *ratetbl = NULL;
2225 + if (sta && !info->control.skip_table)
2226 + ratetbl = rcu_dereference(sta->rates);
2228 + /* Fill remaining rate slots with data from the sta rate table. */
2229 + max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE);
2230 + for (i = 0; i < max_rates; i++) {
2231 + if (i < ARRAY_SIZE(info->control.rates) &&
2232 + info->control.rates[i].idx >= 0 &&
2233 + info->control.rates[i].count) {
2234 + if (rates != info->control.rates)
2235 + rates[i] = info->control.rates[i];
2236 + } else if (ratetbl) {
2237 + rates[i].idx = ratetbl->rate[i].idx;
2238 + rates[i].flags = ratetbl->rate[i].flags;
2239 + if (info->control.use_rts)
2240 + rates[i].count = ratetbl->rate[i].count_rts;
2241 + else if (info->control.use_cts_prot)
2242 + rates[i].count = ratetbl->rate[i].count_cts;
2244 + rates[i].count = ratetbl->rate[i].count;
2246 + rates[i].idx = -1;
2247 + rates[i].count = 0;
2250 + if (rates[i].idx < 0 || !rates[i].count)
2255 +static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
2256 + struct ieee80211_sta *sta,
2257 + struct ieee80211_supported_band *sband,
2258 + struct ieee80211_tx_info *info,
2259 + struct ieee80211_tx_rate *rates,
2262 + enum nl80211_chan_width chan_width;
2263 + u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2264 + bool has_mcs_mask;
2269 + * Try to enforce the rateidx mask the user wanted. skip this if the
2270 + * default mask (allow all rates) is used to save some processing for
2271 + * the common case.
2273 + mask = sdata->rc_rateidx_mask[info->band];
2274 + has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
2275 + if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
2279 + memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2280 + sizeof(mcs_mask));
2282 + memset(mcs_mask, 0xff, sizeof(mcs_mask));
2285 + /* Filter out rates that the STA does not support */
2286 + mask &= sta->supp_rates[info->band];
2287 + for (i = 0; i < sizeof(mcs_mask); i++)
2288 + mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i];
2292 + * Make sure the rate index selected for each TX rate is
2293 + * included in the configured mask and change the rate indexes
2296 + chan_width = sdata->vif.bss_conf.chandef.width;
2297 + for (i = 0; i < max_rates; i++) {
2298 + /* Skip invalid rates */
2299 + if (rates[i].idx < 0)
2302 + rate_idx_match_mask(&rates[i], sband, chan_width, mask,
2307 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
2308 + struct ieee80211_sta *sta,
2309 + struct sk_buff *skb,
2310 + struct ieee80211_tx_rate *dest,
2313 + struct ieee80211_sub_if_data *sdata;
2314 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2315 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2316 + struct ieee80211_supported_band *sband;
2318 + rate_control_fill_sta_table(sta, info, dest, max_rates);
2323 + sdata = vif_to_sdata(vif);
2324 + sband = sdata->local->hw.wiphy->bands[info->band];
2326 + if (ieee80211_is_data(hdr->frame_control))
2327 + rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates);
2329 + if (dest[0].idx < 0)
2330 + __rate_control_send_low(&sdata->local->hw, sband, sta, info);
2333 + rate_fixup_ratelist(vif, sband, info, dest, max_rates);
2335 +EXPORT_SYMBOL(ieee80211_get_tx_rates);
2337 void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
2338 struct sta_info *sta,
2339 struct ieee80211_tx_rate_control *txrc)
2340 @@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80
2341 struct ieee80211_sta *ista = NULL;
2342 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
2345 - u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2347 if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) {
2349 @@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80
2351 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
2354 - * Try to enforce the rateidx mask the user wanted. skip this if the
2355 - * default mask (allow all rates) is used to save some processing for
2356 - * the common case.
2358 - mask = sdata->rc_rateidx_mask[info->band];
2359 - memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2360 - sizeof(mcs_mask));
2361 - if (mask != (1 << txrc->sband->n_bitrates) - 1) {
2363 - /* Filter out rates that the STA does not support */
2364 - mask &= sta->sta.supp_rates[info->band];
2365 - for (i = 0; i < sizeof(mcs_mask); i++)
2366 - mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i];
2369 - * Make sure the rate index selected for each TX rate is
2370 - * included in the configured mask and change the rate indexes
2373 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2374 - /* Skip invalid rates */
2375 - if (info->control.rates[i].idx < 0)
2377 - rate_idx_match_mask(&info->control.rates[i], txrc,
2381 + if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE)
2384 - BUG_ON(info->control.rates[0].idx < 0);
2385 + ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb,
2386 + info->control.rates,
2387 + ARRAY_SIZE(info->control.rates));
2390 +int rate_control_set_rates(struct ieee80211_hw *hw,
2391 + struct ieee80211_sta *pubsta,
2392 + struct ieee80211_sta_rates *rates)
2394 + struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates);
2396 + rcu_assign_pointer(pubsta->rates, rates);
2398 + kfree_rcu(old, rcu_head);
2402 +EXPORT_SYMBOL(rate_control_set_rates);
2404 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
2406 --- a/net/mac80211/rc80211_minstrel.c
2407 +++ b/net/mac80211/rc80211_minstrel.c
2408 @@ -84,6 +84,50 @@ minstrel_sort_best_tp_rates(struct minst
2412 +minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
2413 + int offset, int idx)
2415 + struct minstrel_rate *r = &mi->r[idx];
2417 + ratetbl->rate[offset].idx = r->rix;
2418 + ratetbl->rate[offset].count = r->adjusted_retry_count;
2419 + ratetbl->rate[offset].count_cts = r->retry_count_cts;
2420 + ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
2424 +minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2426 + struct ieee80211_sta_rates *ratetbl;
2429 + ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
2433 + /* Start with max_tp_rate */
2434 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
2436 + if (mp->hw->max_rates >= 3) {
2437 + /* At least 3 tx rates supported, use max_tp_rate2 next */
2438 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
2441 + if (mp->hw->max_rates >= 2) {
2442 + /* At least 2 tx rates supported, use max_prob_rate next */
2443 + minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
2446 + /* Use lowest rate last */
2447 + ratetbl->rate[i].idx = mi->lowest_rix;
2448 + ratetbl->rate[i].count = mp->max_retry;
2449 + ratetbl->rate[i].count_cts = mp->max_retry;
2450 + ratetbl->rate[i].count_rts = mp->max_retry;
2452 + rate_control_set_rates(mp->hw, mi->sta, ratetbl);
2456 minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2458 u8 tmp_tp_rate[MAX_THR_RATES];
2459 @@ -161,6 +205,8 @@ minstrel_update_stats(struct minstrel_pr
2461 /* Reset update timer */
2462 mi->stats_update = jiffies;
2464 + minstrel_update_rates(mp, mi);
2468 @@ -209,9 +255,9 @@ minstrel_get_retry_count(struct minstrel
2470 unsigned int retry = mr->adjusted_retry_count;
2472 - if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
2473 + if (info->control.use_rts)
2474 retry = max(2U, min(mr->retry_count_rtscts, retry));
2475 - else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
2476 + else if (info->control.use_cts_prot)
2477 retry = max(2U, min(mr->retry_count_cts, retry));
2480 @@ -240,13 +286,12 @@ minstrel_get_rate(void *priv, struct iee
2481 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2482 struct minstrel_sta_info *mi = priv_sta;
2483 struct minstrel_priv *mp = priv;
2484 - struct ieee80211_tx_rate *ar = info->control.rates;
2485 - unsigned int ndx, sample_ndx = 0;
2486 + struct ieee80211_tx_rate *rate = &info->control.rates[0];
2487 + struct minstrel_rate *msr, *mr;
2490 - bool indirect_rate_sampling = false;
2491 - bool rate_sampling = false;
2494 + bool prev_sample = mi->prev_sample;
2498 /* management/no-ack frames do not use rate control */
2499 @@ -262,107 +307,75 @@ minstrel_get_rate(void *priv, struct iee
2501 sampling_ratio = mp->lookaround_rate;
2503 - /* init rateindex [ndx] with max throughput rate */
2504 - ndx = mi->max_tp_rate[0];
2506 /* increase sum packet counter */
2509 delta = (mi->packet_count * sampling_ratio / 100) -
2510 (mi->sample_count + mi->sample_deferred / 2);
2512 - /* delta > 0: sampling required */
2513 - if ((delta > 0) && (mrr_capable || !mi->prev_sample)) {
2514 - struct minstrel_rate *msr;
2515 - if (mi->packet_count >= 10000) {
2516 - mi->sample_deferred = 0;
2517 - mi->sample_count = 0;
2518 - mi->packet_count = 0;
2519 - } else if (delta > mi->n_rates * 2) {
2520 - /* With multi-rate retry, not every planned sample
2521 - * attempt actually gets used, due to the way the retry
2522 - * chain is set up - [max_tp,sample,prob,lowest] for
2523 - * sample_rate < max_tp.
2525 - * If there's too much sampling backlog and the link
2526 - * starts getting worse, minstrel would start bursting
2527 - * out lots of sampling frames, which would result
2528 - * in a large throughput loss. */
2529 - mi->sample_count += (delta - mi->n_rates * 2);
2531 + /* delta < 0: no sampling required */
2532 + mi->prev_sample = false;
2533 + if (delta < 0 || (!mrr_capable && prev_sample))
2536 - /* get next random rate sample */
2537 - sample_ndx = minstrel_get_next_sample(mi);
2538 - msr = &mi->r[sample_ndx];
2539 - rate_sampling = true;
2541 - /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2542 - * rate sampling method should be used.
2543 - * Respect such rates that are not sampled for 20 interations.
2545 - if (mrr_capable &&
2546 - msr->perfect_tx_time > mi->r[ndx].perfect_tx_time &&
2547 - msr->sample_skipped < 20)
2548 - indirect_rate_sampling = true;
2550 - if (!indirect_rate_sampling) {
2551 - if (msr->sample_limit != 0) {
2553 - mi->sample_count++;
2554 - if (msr->sample_limit > 0)
2555 - msr->sample_limit--;
2557 - rate_sampling = false;
2559 - /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2560 - * packets that have the sampling rate deferred to the
2561 - * second MRR stage. Increase the sample counter only
2562 - * if the deferred sample rate was actually used.
2563 - * Use the sample_deferred counter to make sure that
2564 - * the sampling is not done in large bursts */
2565 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2566 - mi->sample_deferred++;
2568 + if (mi->packet_count >= 10000) {
2569 + mi->sample_deferred = 0;
2570 + mi->sample_count = 0;
2571 + mi->packet_count = 0;
2572 + } else if (delta > mi->n_rates * 2) {
2573 + /* With multi-rate retry, not every planned sample
2574 + * attempt actually gets used, due to the way the retry
2575 + * chain is set up - [max_tp,sample,prob,lowest] for
2576 + * sample_rate < max_tp.
2578 + * If there's too much sampling backlog and the link
2579 + * starts getting worse, minstrel would start bursting
2580 + * out lots of sampling frames, which would result
2581 + * in a large throughput loss. */
2582 + mi->sample_count += (delta - mi->n_rates * 2);
2585 + /* get next random rate sample */
2586 + ndx = minstrel_get_next_sample(mi);
2587 + msr = &mi->r[ndx];
2588 + mr = &mi->r[mi->max_tp_rate[0]];
2590 + /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2591 + * rate sampling method should be used.
2592 + * Respect such rates that are not sampled for 20 interations.
2594 + if (mrr_capable &&
2595 + msr->perfect_tx_time > mr->perfect_tx_time &&
2596 + msr->sample_skipped < 20) {
2597 + /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2598 + * packets that have the sampling rate deferred to the
2599 + * second MRR stage. Increase the sample counter only
2600 + * if the deferred sample rate was actually used.
2601 + * Use the sample_deferred counter to make sure that
2602 + * the sampling is not done in large bursts */
2603 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2605 + mi->sample_deferred++;
2607 + if (!msr->sample_limit != 0)
2610 + mi->sample_count++;
2611 + if (msr->sample_limit > 0)
2612 + msr->sample_limit--;
2614 - mi->prev_sample = rate_sampling;
2616 /* If we're not using MRR and the sampling rate already
2617 * has a probability of >95%, we shouldn't be attempting
2618 * to use it, as this only wastes precious airtime */
2619 - if (!mrr_capable && rate_sampling &&
2620 + if (!mrr_capable &&
2621 (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
2622 - ndx = mi->max_tp_rate[0];
2624 - /* mrr setup for 1st stage */
2625 - ar[0].idx = mi->r[ndx].rix;
2626 - ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
2628 - /* non mrr setup for 2nd stage */
2629 - if (!mrr_capable) {
2630 - if (!rate_sampling)
2631 - ar[0].count = mp->max_retry;
2632 - ar[1].idx = mi->lowest_rix;
2633 - ar[1].count = mp->max_retry;
2637 - /* mrr setup for 2nd stage */
2638 - if (rate_sampling) {
2639 - if (indirect_rate_sampling)
2640 - mrr_ndx[0] = sample_ndx;
2642 - mrr_ndx[0] = mi->max_tp_rate[0];
2644 - mrr_ndx[0] = mi->max_tp_rate[1];
2646 + mi->prev_sample = true;
2648 - /* mrr setup for 3rd & 4th stage */
2649 - mrr_ndx[1] = mi->max_prob_rate;
2651 - for (i = 1; i < 4; i++) {
2652 - ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
2653 - ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
2655 + rate->idx = mi->r[ndx].rix;
2656 + rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
2660 @@ -412,12 +425,16 @@ minstrel_rate_init(void *priv, struct ie
2661 unsigned int i, n = 0;
2662 unsigned int t_slot = 9; /* FIXME: get real slot time */
2665 mi->lowest_rix = rate_lowest_index(sband, sta);
2666 ctl_rate = &sband->bitrates[mi->lowest_rix];
2667 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
2669 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
2671 + memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
2672 + mi->max_prob_rate = 0;
2674 for (i = 0; i < sband->n_bitrates; i++) {
2675 struct minstrel_rate *mr = &mi->r[n];
2676 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
2677 @@ -460,6 +477,8 @@ minstrel_rate_init(void *priv, struct ie
2678 } while ((tx_time < mp->segment_size) &&
2679 (++mr->retry_count < mp->max_retry));
2680 mr->adjusted_retry_count = mr->retry_count;
2681 + if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
2682 + mr->retry_count_cts = mr->retry_count;
2685 for (i = n; i < sband->n_bitrates; i++) {
2686 @@ -471,6 +490,7 @@ minstrel_rate_init(void *priv, struct ie
2687 mi->stats_update = jiffies;
2689 init_sample_table(mi);
2690 + minstrel_update_rates(mp, mi);
2694 --- a/net/mac80211/rc80211_minstrel.h
2695 +++ b/net/mac80211/rc80211_minstrel.h
2697 #ifndef __RC_MINSTREL_H
2698 #define __RC_MINSTREL_H
2700 -#define EWMA_LEVEL 75 /* ewma weighting factor [%] */
2701 +#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
2702 +#define EWMA_DIV 128
2703 #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
2708 minstrel_ewma(int old, int new, int weight)
2710 - return (new * (100 - weight) + old * weight) / 100;
2711 + return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
2715 @@ -62,6 +63,8 @@ struct minstrel_rate {
2718 struct minstrel_sta_info {
2719 + struct ieee80211_sta *sta;
2721 unsigned long stats_update;
2722 unsigned int sp_ack_dur;
2723 unsigned int rate_avg;
2724 --- a/net/mac80211/rc80211_minstrel_debugfs.c
2725 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
2726 @@ -68,7 +68,7 @@ minstrel_stats_open(struct inode *inode,
2728 file->private_data = ms;
2730 - p += sprintf(p, "rate throughput ewma prob this prob "
2731 + p += sprintf(p, "rate throughput ewma prob this prob "
2732 "this succ/attempt success attempts\n");
2733 for (i = 0; i < mi->n_rates; i++) {
2734 struct minstrel_rate *mr = &mi->r[i];
2735 @@ -86,7 +86,7 @@ minstrel_stats_open(struct inode *inode,
2736 eprob = MINSTREL_TRUNC(mr->probability * 1000);
2738 p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
2739 - "%3u(%3u) %8llu %8llu\n",
2740 + " %3u(%3u) %8llu %8llu\n",
2742 eprob / 10, eprob % 10,
2743 prob / 10, prob % 10,
2744 --- a/net/mac80211/rc80211_minstrel_ht.c
2745 +++ b/net/mac80211/rc80211_minstrel_ht.c
2746 @@ -126,6 +126,9 @@ const struct mcs_group minstrel_mcs_grou
2748 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES];
2751 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
2754 * Look up an MCS group index based on mac80211 rate information
2756 @@ -244,6 +247,7 @@ minstrel_ht_update_stats(struct minstrel
2757 struct minstrel_rate_stats *mr;
2758 int cur_prob, cur_prob_tp, cur_tp, cur_tp2;
2759 int group, i, index;
2760 + bool mi_rates_valid = false;
2762 if (mi->ampdu_packets > 0) {
2763 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
2764 @@ -254,11 +258,10 @@ minstrel_ht_update_stats(struct minstrel
2766 mi->sample_slow = 0;
2767 mi->sample_count = 0;
2768 - mi->max_tp_rate = 0;
2769 - mi->max_tp_rate2 = 0;
2770 - mi->max_prob_rate = 0;
2772 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
2773 + bool mg_rates_valid = false;
2778 @@ -268,15 +271,24 @@ minstrel_ht_update_stats(struct minstrel
2782 - mg->max_tp_rate = 0;
2783 - mg->max_tp_rate2 = 0;
2784 - mg->max_prob_rate = 0;
2787 for (i = 0; i < MCS_GROUP_RATES; i++) {
2788 if (!(mg->supported & BIT(i)))
2791 + /* initialize rates selections starting indexes */
2792 + if (!mg_rates_valid) {
2793 + mg->max_tp_rate = mg->max_tp_rate2 =
2794 + mg->max_prob_rate = i;
2795 + if (!mi_rates_valid) {
2796 + mi->max_tp_rate = mi->max_tp_rate2 =
2797 + mi->max_prob_rate = i;
2798 + mi_rates_valid = true;
2800 + mg_rates_valid = true;
2804 mr->retry_updated = false;
2805 index = MCS_GROUP_RATES * group + i;
2806 @@ -456,7 +468,7 @@ minstrel_ht_tx_status(void *priv, struct
2807 struct ieee80211_tx_rate *ar = info->status.rates;
2808 struct minstrel_rate_stats *rate, *rate2;
2809 struct minstrel_priv *mp = priv;
2811 + bool last, update = false;
2815 @@ -505,21 +517,29 @@ minstrel_ht_tx_status(void *priv, struct
2816 rate = minstrel_get_ratestats(mi, mi->max_tp_rate);
2817 if (rate->attempts > 30 &&
2818 MINSTREL_FRAC(rate->success, rate->attempts) <
2819 - MINSTREL_FRAC(20, 100))
2820 + MINSTREL_FRAC(20, 100)) {
2821 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true);
2825 rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2);
2826 if (rate2->attempts > 30 &&
2827 MINSTREL_FRAC(rate2->success, rate2->attempts) <
2828 - MINSTREL_FRAC(20, 100))
2829 + MINSTREL_FRAC(20, 100)) {
2830 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false);
2834 if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) {
2836 minstrel_ht_update_stats(mp, mi);
2837 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
2838 mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
2839 minstrel_aggr_check(sta, skb);
2843 + minstrel_ht_update_rates(mp, mi);
2847 @@ -580,39 +600,73 @@ minstrel_calc_retransmit(struct minstrel
2848 (++mr->retry_count < mp->max_retry));
2853 minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
2854 - struct ieee80211_tx_rate *rate, int index,
2855 - bool sample, bool rtscts)
2856 + struct ieee80211_sta_rates *ratetbl, int offset, int index)
2858 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
2859 struct minstrel_rate_stats *mr;
2863 mr = minstrel_get_ratestats(mi, index);
2864 if (!mr->retry_updated)
2865 minstrel_calc_retransmit(mp, mi, index);
2869 - else if (mr->probability < MINSTREL_FRAC(20, 100))
2872 - rate->count = mr->retry_count_rtscts;
2874 - rate->count = mr->retry_count;
2878 - rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2879 + if (mr->probability < MINSTREL_FRAC(20, 100) || !mr->retry_count) {
2880 + ratetbl->rate[offset].count = 2;
2881 + ratetbl->rate[offset].count_rts = 2;
2882 + ratetbl->rate[offset].count_cts = 2;
2884 + ratetbl->rate[offset].count = mr->retry_count;
2885 + ratetbl->rate[offset].count_cts = mr->retry_count;
2886 + ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
2889 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
2890 - rate->idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
2891 + idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
2894 + idx = index % MCS_GROUP_RATES +
2895 + (group->streams - 1) * MCS_GROUP_RATES;
2896 + flags = IEEE80211_TX_RC_MCS | group->flags;
2900 + ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
2901 + flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2904 + ratetbl->rate[offset].idx = idx;
2905 + ratetbl->rate[offset].flags = flags;
2909 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
2911 + struct ieee80211_sta_rates *rates;
2914 + rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
2918 + /* Start with max_tp_rate */
2919 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate);
2921 + if (mp->hw->max_rates >= 3) {
2922 + /* At least 3 tx rates supported, use max_tp_rate2 next */
2923 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate2);
2926 + if (mp->hw->max_rates >= 2) {
2928 + * At least 2 tx rates supported, use max_prob_rate next */
2929 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
2932 - rate->flags |= IEEE80211_TX_RC_MCS | group->flags;
2933 - rate->idx = index % MCS_GROUP_RATES + (group->streams - 1) * MCS_GROUP_RATES;
2934 + rates->rate[i].idx = -1;
2935 + rate_control_set_rates(mp->hw, mi->sta, rates);
2939 @@ -702,13 +756,13 @@ static void
2940 minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
2941 struct ieee80211_tx_rate_control *txrc)
2943 + const struct mcs_group *sample_group;
2944 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
2945 - struct ieee80211_tx_rate *ar = info->status.rates;
2946 + struct ieee80211_tx_rate *rate = &info->status.rates[0];
2947 struct minstrel_ht_sta_priv *msp = priv_sta;
2948 struct minstrel_ht_sta *mi = &msp->ht;
2949 struct minstrel_priv *mp = priv;
2951 - bool sample = false;
2953 if (rate_control_send_low(sta, priv_sta, txrc))
2955 @@ -736,51 +790,6 @@ minstrel_ht_get_rate(void *priv, struct
2959 - if (sample_idx >= 0) {
2961 - minstrel_ht_set_rate(mp, mi, &ar[0], sample_idx,
2963 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2965 - minstrel_ht_set_rate(mp, mi, &ar[0], mi->max_tp_rate,
2969 - if (mp->hw->max_rates >= 3) {
2971 - * At least 3 tx rates supported, use
2972 - * sample_rate -> max_tp_rate -> max_prob_rate for sampling and
2973 - * max_tp_rate -> max_tp_rate2 -> max_prob_rate by default.
2975 - if (sample_idx >= 0)
2976 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate,
2979 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate2,
2982 - minstrel_ht_set_rate(mp, mi, &ar[2], mi->max_prob_rate,
2987 - } else if (mp->hw->max_rates == 2) {
2989 - * Only 2 tx rates supported, use
2990 - * sample_rate -> max_prob_rate for sampling and
2991 - * max_tp_rate -> max_prob_rate by default.
2993 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_prob_rate,
2999 - /* Not using MRR, only use the first rate */
3004 mi->total_packets++;
3007 @@ -788,6 +797,16 @@ minstrel_ht_get_rate(void *priv, struct
3008 mi->total_packets = 0;
3009 mi->sample_packets = 0;
3012 + if (sample_idx < 0)
3015 + sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
3016 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3017 + rate->idx = sample_idx % MCS_GROUP_RATES +
3018 + (sample_group->streams - 1) * MCS_GROUP_RATES;
3019 + rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
3024 @@ -837,6 +856,8 @@ minstrel_ht_update_caps(void *priv, stru
3027 memset(mi, 0, sizeof(*mi));
3030 mi->stats_update = jiffies;
3032 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
3033 @@ -898,6 +919,9 @@ minstrel_ht_update_caps(void *priv, stru
3037 + minstrel_ht_update_stats(mp, mi);
3038 + minstrel_ht_update_rates(mp, mi);
3043 --- a/net/mac80211/rc80211_minstrel_ht.h
3044 +++ b/net/mac80211/rc80211_minstrel_ht.h
3045 @@ -65,6 +65,8 @@ struct minstrel_mcs_group_data {
3048 struct minstrel_ht_sta {
3049 + struct ieee80211_sta *sta;
3051 /* ampdu length (average, per sampling interval) */
3052 unsigned int ampdu_len;
3053 unsigned int ampdu_packets;
3054 --- a/net/mac80211/rx.c
3055 +++ b/net/mac80211/rx.c
3056 @@ -1372,6 +1372,7 @@ ieee80211_rx_h_sta_process(struct ieee80
3057 struct sk_buff *skb = rx->skb;
3058 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3059 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3064 @@ -1422,6 +1423,19 @@ ieee80211_rx_h_sta_process(struct ieee80
3065 ewma_add(&sta->avg_signal, -status->signal);
3068 + if (status->chains) {
3069 + sta->chains = status->chains;
3070 + for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
3071 + int signal = status->chain_signal[i];
3073 + if (!(status->chains & BIT(i)))
3076 + sta->chain_signal_last[i] = signal;
3077 + ewma_add(&sta->chain_signal_avg[i], -signal);
3082 * Change STA power saving mode only at the end of a frame
3083 * exchange sequence.
3084 @@ -2085,6 +2099,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
3087 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
3088 + fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
3089 info = IEEE80211_SKB_CB(fwd_skb);
3090 memset(info, 0, sizeof(*info));
3091 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
3092 @@ -2356,6 +2371,7 @@ ieee80211_rx_h_action(struct ieee80211_r
3093 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3094 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3095 sdata->vif.type != NL80211_IFTYPE_AP &&
3096 + sdata->vif.type != NL80211_IFTYPE_WDS &&
3097 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3100 @@ -2423,6 +2439,22 @@ ieee80211_rx_h_action(struct ieee80211_r
3104 + case WLAN_CATEGORY_PUBLIC:
3105 + if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3107 + if (sdata->vif.type != NL80211_IFTYPE_STATION)
3111 + if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3113 + if (mgmt->u.action.u.ext_chan_switch.action_code !=
3114 + WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3116 + if (len < offsetof(struct ieee80211_mgmt,
3117 + u.action.u.ext_chan_switch.variable))
3120 case WLAN_CATEGORY_VHT:
3121 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3122 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3123 @@ -2506,10 +2538,6 @@ ieee80211_rx_h_action(struct ieee80211_r
3124 ieee80211_process_measurement_req(sdata, mgmt, len);
3126 case WLAN_ACTION_SPCT_CHL_SWITCH:
3127 - if (len < (IEEE80211_MIN_ACTION_SIZE +
3128 - sizeof(mgmt->u.action.u.chan_switch)))
3131 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3134 @@ -2695,14 +2723,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
3136 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3137 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3138 - sdata->vif.type != NL80211_IFTYPE_STATION)
3139 + sdata->vif.type != NL80211_IFTYPE_STATION &&
3140 + sdata->vif.type != NL80211_IFTYPE_WDS)
3141 return RX_DROP_MONITOR;
3144 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3145 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3146 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3147 - /* process for all: mesh, mlme, ibss */
3148 + /* process for all: mesh, mlme, ibss, wds */
3150 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3151 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3152 @@ -3023,6 +3052,9 @@ static int prepare_for_handlers(struct i
3153 * and location updates. Note that mac80211
3154 * itself never looks at these frames.
3157 + !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3159 if (ieee80211_is_public_action(hdr, skb->len))
3161 if (!ieee80211_is_beacon(hdr->frame_control))
3162 @@ -3031,10 +3063,16 @@ static int prepare_for_handlers(struct i
3165 case NL80211_IFTYPE_WDS:
3166 - if (bssid || !ieee80211_is_data(hdr->frame_control))
3168 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
3171 + if (ieee80211_is_data(hdr->frame_control) ||
3172 + ieee80211_is_action(hdr->frame_control)) {
3173 + if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
3175 + } else if (!ieee80211_is_beacon(hdr->frame_control))
3179 case NL80211_IFTYPE_P2P_DEVICE:
3180 if (!ieee80211_is_public_action(hdr, skb->len) &&
3181 --- a/net/mac80211/scan.c
3182 +++ b/net/mac80211/scan.c
3183 @@ -181,7 +181,7 @@ void ieee80211_scan_rx(struct ieee80211_
3184 if (baselen > skb->len)
3187 - ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
3188 + ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
3190 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3192 --- a/net/mac80211/sta_info.h
3193 +++ b/net/mac80211/sta_info.h
3195 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
3197 * @WLAN_STA_WME: Station is a QoS-STA.
3198 - * @WLAN_STA_WDS: Station is one of our WDS peers.
3199 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
3200 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
3201 * frame to this station is transmitted.
3202 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
3203 WLAN_STA_AUTHORIZED,
3204 WLAN_STA_SHORT_PREAMBLE,
3207 WLAN_STA_CLEAR_PS_FILT,
3210 @@ -344,6 +342,11 @@ struct sta_info {
3212 struct ewma avg_signal;
3213 int last_ack_signal;
3216 + s8 chain_signal_last[IEEE80211_MAX_CHAINS];
3217 + struct ewma chain_signal_avg[IEEE80211_MAX_CHAINS];
3219 /* Plus 1 for non-QoS frames */
3220 __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
3222 --- a/net/mac80211/trace.h
3223 +++ b/net/mac80211/trace.h
3224 @@ -990,23 +990,23 @@ TRACE_EVENT(drv_channel_switch,
3229 __field(u64, timestamp)
3230 __field(bool, block_tx)
3231 - __field(u16, freq)
3237 + CHANDEF_ASSIGN(&ch_switch->chandef)
3238 __entry->timestamp = ch_switch->timestamp;
3239 __entry->block_tx = ch_switch->block_tx;
3240 - __entry->freq = ch_switch->channel->center_freq;
3241 __entry->count = ch_switch->count;
3245 - LOCAL_PR_FMT " new freq:%u count:%d",
3246 - LOCAL_PR_ARG, __entry->freq, __entry->count
3247 + LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
3248 + LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count
3252 --- a/net/mac80211/tx.c
3253 +++ b/net/mac80211/tx.c
3254 @@ -48,15 +48,15 @@ static __le16 ieee80211_duration(struct
3255 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3257 /* assume HW handles this */
3258 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
3259 + if (tx->rate.flags & IEEE80211_TX_RC_MCS)
3263 - if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
3264 + if (WARN_ON_ONCE(tx->rate.idx < 0))
3267 sband = local->hw.wiphy->bands[info->band];
3268 - txrate = &sband->bitrates[info->control.rates[0].idx];
3269 + txrate = &sband->bitrates[tx->rate.idx];
3271 erp = txrate->flags & IEEE80211_RATE_ERP_G;
3273 @@ -617,11 +617,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3274 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
3275 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
3276 struct ieee80211_supported_band *sband;
3277 - struct ieee80211_rate *rate;
3280 - bool inval = false, rts = false, short_preamble = false;
3281 struct ieee80211_tx_rate_control txrc;
3282 + struct ieee80211_sta_rates *ratetbl = NULL;
3285 memset(&txrc, 0, sizeof(txrc));
3286 @@ -642,18 +640,23 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3287 txrc.max_rate_idx = -1;
3289 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3290 - memcpy(txrc.rate_idx_mcs_mask,
3291 - tx->sdata->rc_rateidx_mcs_mask[info->band],
3292 - sizeof(txrc.rate_idx_mcs_mask));
3294 + if (tx->sdata->rc_has_mcs_mask[info->band])
3295 + txrc.rate_idx_mcs_mask =
3296 + tx->sdata->rc_rateidx_mcs_mask[info->band];
3298 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
3299 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
3300 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
3302 /* set up RTS protection if desired */
3303 if (len > tx->local->hw.wiphy->rts_threshold) {
3304 - txrc.rts = rts = true;
3308 + info->control.use_rts = txrc.rts;
3309 + info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
3312 * Use short preamble if the BSS can handle it, but not for
3313 * management frames unless we know the receiver can handle
3314 @@ -663,7 +666,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3315 if (tx->sdata->vif.bss_conf.use_short_preamble &&
3316 (ieee80211_is_data(hdr->frame_control) ||
3317 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
3318 - txrc.short_preamble = short_preamble = true;
3319 + txrc.short_preamble = true;
3321 + info->control.short_preamble = txrc.short_preamble;
3324 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
3325 @@ -687,16 +692,38 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3327 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
3329 - if (unlikely(info->control.rates[0].idx < 0))
3331 + if (tx->sta && !info->control.skip_table)
3332 + ratetbl = rcu_dereference(tx->sta->sta.rates);
3334 + if (unlikely(info->control.rates[0].idx < 0)) {
3336 + struct ieee80211_tx_rate rate = {
3337 + .idx = ratetbl->rate[0].idx,
3338 + .flags = ratetbl->rate[0].flags,
3339 + .count = ratetbl->rate[0].count
3342 + if (ratetbl->rate[0].idx < 0)
3350 + tx->rate = info->control.rates[0];
3353 if (txrc.reported_rate.idx < 0) {
3354 - txrc.reported_rate = info->control.rates[0];
3355 + txrc.reported_rate = tx->rate;
3356 if (tx->sta && ieee80211_is_data(hdr->frame_control))
3357 tx->sta->last_tx_rate = txrc.reported_rate;
3359 tx->sta->last_tx_rate = txrc.reported_rate;
3362 + return TX_CONTINUE;
3364 if (unlikely(!info->control.rates[0].count))
3365 info->control.rates[0].count = 1;
3367 @@ -704,91 +731,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3368 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
3369 info->control.rates[0].count = 1;
3371 - if (is_multicast_ether_addr(hdr->addr1)) {
3373 - * XXX: verify the rate is in the basic rateset
3375 - return TX_CONTINUE;
3379 - * set up the RTS/CTS rate as the fastest basic rate
3380 - * that is not faster than the data rate
3382 - * XXX: Should this check all retry rates?
3384 - if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
3387 - rate = &sband->bitrates[info->control.rates[0].idx];
3389 - for (i = 0; i < sband->n_bitrates; i++) {
3390 - /* must be a basic rate */
3391 - if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
3393 - /* must not be faster than the data rate */
3394 - if (sband->bitrates[i].bitrate > rate->bitrate)
3397 - if (sband->bitrates[baserate].bitrate <
3398 - sband->bitrates[i].bitrate)
3402 - info->control.rts_cts_rate_idx = baserate;
3405 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
3407 - * make sure there's no valid rate following
3408 - * an invalid one, just in case drivers don't
3409 - * take the API seriously to stop at -1.
3412 - info->control.rates[i].idx = -1;
3415 - if (info->control.rates[i].idx < 0) {
3421 - * For now assume MCS is already set up correctly, this
3422 - * needs to be fixed.
3424 - if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
3425 - WARN_ON(info->control.rates[i].idx > 76);
3429 - /* set up RTS protection if desired */
3431 - info->control.rates[i].flags |=
3432 - IEEE80211_TX_RC_USE_RTS_CTS;
3434 - /* RC is busted */
3435 - if (WARN_ON_ONCE(info->control.rates[i].idx >=
3436 - sband->n_bitrates)) {
3437 - info->control.rates[i].idx = -1;
3441 - rate = &sband->bitrates[info->control.rates[i].idx];
3443 - /* set up short preamble */
3444 - if (short_preamble &&
3445 - rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
3446 - info->control.rates[i].flags |=
3447 - IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
3449 - /* set up G protection */
3450 - if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
3451 - rate->flags & IEEE80211_RATE_ERP_G)
3452 - info->control.rates[i].flags |=
3453 - IEEE80211_TX_RC_USE_CTS_PROTECT;
3459 @@ -2508,8 +2450,6 @@ struct sk_buff *ieee80211_beacon_get_tim
3460 txrc.max_rate_idx = -1;
3462 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3463 - memcpy(txrc.rate_idx_mcs_mask, sdata->rc_rateidx_mcs_mask[band],
3464 - sizeof(txrc.rate_idx_mcs_mask));
3466 rate_control_get_rate(sdata, NULL, &txrc);
3468 --- a/net/mac80211/util.c
3469 +++ b/net/mac80211/util.c
3470 @@ -485,7 +485,8 @@ int ieee80211_queue_stopped(struct ieee8
3473 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3474 - ret = !!local->queue_stop_reasons[queue];
3475 + ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
3476 + &local->queue_stop_reasons[queue]);
3477 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3480 @@ -660,7 +661,7 @@ void ieee80211_queue_delayed_work(struct
3482 EXPORT_SYMBOL(ieee80211_queue_delayed_work);
3484 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
3485 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
3486 struct ieee802_11_elems *elems,
3487 u64 filter, u32 crc)
3489 @@ -668,6 +669,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3491 bool calc_crc = filter != 0;
3492 DECLARE_BITMAP(seen_elems, 256);
3495 bitmap_zero(seen_elems, 256);
3496 memset(elems, 0, sizeof(*elems));
3497 @@ -715,6 +717,12 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3498 case WLAN_EID_COUNTRY:
3499 case WLAN_EID_PWR_CONSTRAINT:
3500 case WLAN_EID_TIMEOUT_INTERVAL:
3501 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3502 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3504 + * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
3505 + * that if the content gets bigger it might be needed more than once
3507 if (test_bit(id, seen_elems)) {
3508 elems->parse_error = true;
3510 @@ -862,6 +870,48 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3512 elems->ch_switch_ie = (void *)pos;
3514 + case WLAN_EID_EXT_CHANSWITCH_ANN:
3515 + if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
3516 + elem_parse_failed = true;
3519 + elems->ext_chansw_ie = (void *)pos;
3521 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3522 + if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
3523 + elem_parse_failed = true;
3526 + elems->sec_chan_offs = (void *)pos;
3528 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3530 + elen != sizeof(*elems->wide_bw_chansw_ie)) {
3531 + elem_parse_failed = true;
3534 + elems->wide_bw_chansw_ie = (void *)pos;
3536 + case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
3538 + elem_parse_failed = true;
3542 + * This is a bit tricky, but as we only care about
3543 + * the wide bandwidth channel switch element, so
3544 + * just parse it out manually.
3546 + ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
3549 + if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
3550 + elems->wide_bw_chansw_ie =
3553 + elem_parse_failed = true;
3556 case WLAN_EID_COUNTRY:
3557 elems->country_elem = pos;
3558 elems->country_elem_len = elen;
3559 --- a/net/wireless/reg.c
3560 +++ b/net/wireless/reg.c
3561 @@ -857,7 +857,7 @@ static void handle_channel(struct wiphy
3564 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
3565 - chan->flags = IEEE80211_CHAN_DISABLED;
3566 + chan->flags |= IEEE80211_CHAN_DISABLED;
3570 --- a/net/wireless/util.c
3571 +++ b/net/wireless/util.c
3572 @@ -1156,6 +1156,26 @@ int cfg80211_get_p2p_attr(const u8 *ies,
3574 EXPORT_SYMBOL(cfg80211_get_p2p_attr);
3576 +bool ieee80211_operating_class_to_band(u8 operating_class,
3577 + enum ieee80211_band *band)
3579 + switch (operating_class) {
3582 + *band = IEEE80211_BAND_5GHZ;
3588 + *band = IEEE80211_BAND_2GHZ;
3594 +EXPORT_SYMBOL(ieee80211_operating_class_to_band);
3596 int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
3599 --- a/include/uapi/linux/nl80211.h
3600 +++ b/include/uapi/linux/nl80211.h
3601 @@ -1973,6 +1973,10 @@ enum nl80211_sta_bss_param {
3602 * @NL80211_STA_INFO_PEER_PM: peer mesh STA link-specific power mode
3603 * @NL80211_STA_INFO_NONPEER_PM: neighbor mesh STA power save mode towards
3605 + * @NL80211_STA_INFO_CHAIN_SIGNAL: per-chain signal strength of last PPDU
3606 + * Contains a nested array of signal strength attributes (u8, dBm)
3607 + * @NL80211_STA_INFO_CHAIN_SIGNAL_AVG: per-chain signal strength average
3608 + * Same format as NL80211_STA_INFO_CHAIN_SIGNAL.
3609 * @__NL80211_STA_INFO_AFTER_LAST: internal
3610 * @NL80211_STA_INFO_MAX: highest possible station info attribute
3612 @@ -2002,6 +2006,8 @@ enum nl80211_sta_info {
3613 NL80211_STA_INFO_NONPEER_PM,
3614 NL80211_STA_INFO_RX_BYTES64,
3615 NL80211_STA_INFO_TX_BYTES64,
3616 + NL80211_STA_INFO_CHAIN_SIGNAL,
3617 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
3620 __NL80211_STA_INFO_AFTER_LAST,
3621 --- a/net/mac80211/sta_info.c
3622 +++ b/net/mac80211/sta_info.c
3623 @@ -358,6 +358,8 @@ struct sta_info *sta_info_alloc(struct i
3624 do_posix_clock_monotonic_gettime(&uptime);
3625 sta->last_connected = uptime.tv_sec;
3626 ewma_init(&sta->avg_signal, 1024, 8);
3627 + for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
3628 + ewma_init(&sta->chain_signal_avg[i], 1024, 8);
3630 if (sta_prepare_rate_control(local, sta, gfp)) {
3632 --- a/net/wireless/nl80211.c
3633 +++ b/net/wireless/nl80211.c
3634 @@ -3367,6 +3367,32 @@ static bool nl80211_put_sta_rate(struct
3638 +static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3647 + attr = nla_nest_start(msg, id);
3651 + for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3652 + if (!(mask & BIT(i)))
3655 + if (nla_put_u8(msg, i, signal[i]))
3659 + nla_nest_end(msg, attr);
3664 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
3666 struct cfg80211_registered_device *rdev,
3667 @@ -3438,6 +3464,18 @@ static int nl80211_send_station(struct s
3671 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3672 + if (!nl80211_put_signal(msg, sinfo->chains,
3673 + sinfo->chain_signal,
3674 + NL80211_STA_INFO_CHAIN_SIGNAL))
3675 + goto nla_put_failure;
3677 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3678 + if (!nl80211_put_signal(msg, sinfo->chains,
3679 + sinfo->chain_signal_avg,
3680 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3681 + goto nla_put_failure;
3683 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
3684 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3685 NL80211_STA_INFO_TX_BITRATE))
3686 --- a/drivers/net/wireless/ath/ath9k/init.c
3687 +++ b/drivers/net/wireless/ath/ath9k/init.c
3688 @@ -768,7 +768,8 @@ void ath9k_set_hw_capab(struct ath_softc
3689 IEEE80211_HW_SUPPORTS_PS |
3690 IEEE80211_HW_PS_NULLFUNC_STACK |
3691 IEEE80211_HW_SPECTRUM_MGMT |
3692 - IEEE80211_HW_REPORTS_TX_ACK_STATUS;
3693 + IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3694 + IEEE80211_HW_SUPPORTS_RC_TABLE;
3696 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
3697 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
3698 --- a/drivers/net/wireless/ath/ath9k/xmit.c
3699 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
3700 @@ -157,7 +157,27 @@ static void ath_send_bar(struct ath_atx_
3701 seqno << IEEE80211_SEQ_SEQ_SHIFT);
3704 -static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
3705 +static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3706 + struct ath_buf *bf)
3708 + ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
3709 + ARRAY_SIZE(bf->rates));
3712 +static void ath_tx_clear_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
3714 + tid->state &= ~AGGR_ADDBA_COMPLETE;
3715 + tid->state &= ~AGGR_CLEANUP;
3716 + if (!tid->stop_cb)
3719 + ieee80211_start_tx_ba_cb_irqsafe(tid->an->vif, tid->an->sta->addr,
3721 + tid->stop_cb = false;
3724 +static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid,
3725 + bool flush_packets)
3727 struct ath_txq *txq = tid->ac->txq;
3728 struct sk_buff *skb;
3729 @@ -174,31 +194,29 @@ static void ath_tx_flush_tid(struct ath_
3730 while ((skb = __skb_dequeue(&tid->buf_q))) {
3731 fi = get_frame_info(skb);
3733 + if (!bf && !flush_packets)
3734 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
3737 - bf = ath_tx_setup_buffer(sc, txq, tid, skb);
3739 - ieee80211_free_txskb(sc->hw, skb);
3742 + ieee80211_free_txskb(sc->hw, skb);
3746 - if (fi->retries) {
3747 + if (fi->retries || flush_packets) {
3748 list_add_tail(&bf->list, &bf_head);
3749 ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
3750 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
3753 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
3754 ath_tx_send_normal(sc, txq, NULL, skb);
3758 - if (tid->baw_head == tid->baw_tail) {
3759 - tid->state &= ~AGGR_ADDBA_COMPLETE;
3760 - tid->state &= ~AGGR_CLEANUP;
3762 + if (tid->baw_head == tid->baw_tail)
3763 + ath_tx_clear_tid(sc, tid);
3766 + if (sendbar && !flush_packets) {
3767 ath_txq_unlock(sc, txq);
3768 ath_send_bar(tid, tid->seq_start);
3769 ath_txq_lock(sc, txq);
3770 @@ -269,9 +287,7 @@ static void ath_tid_drain(struct ath_sof
3772 list_add_tail(&bf->list, &bf_head);
3775 - ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
3777 + ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
3778 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
3781 @@ -407,7 +423,7 @@ static void ath_tx_complete_aggr(struct
3783 tx_info = IEEE80211_SKB_CB(skb);
3785 - memcpy(rates, tx_info->control.rates, sizeof(rates));
3786 + memcpy(rates, bf->rates, sizeof(rates));
3788 retries = ts->ts_longretry + 1;
3789 for (i = 0; i < ts->ts_rateindex; i++)
3790 @@ -594,7 +610,7 @@ static void ath_tx_complete_aggr(struct
3793 if (tid->state & AGGR_CLEANUP)
3794 - ath_tx_flush_tid(sc, tid);
3795 + ath_tx_flush_tid(sc, tid, false);
3799 @@ -612,6 +628,7 @@ static void ath_tx_process_buffer(struct
3800 struct ath_tx_status *ts, struct ath_buf *bf,
3801 struct list_head *bf_head)
3803 + struct ieee80211_tx_info *info;
3806 txok = !(ts->ts_status & ATH9K_TXERR_MASK);
3807 @@ -623,8 +640,12 @@ static void ath_tx_process_buffer(struct
3808 txq->axq_ampdu_depth--;
3810 if (!bf_isampdu(bf)) {
3813 + info = IEEE80211_SKB_CB(bf->bf_mpdu);
3814 + memcpy(info->control.rates, bf->rates,
3815 + sizeof(info->control.rates));
3816 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
3818 ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok);
3820 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
3821 @@ -668,7 +689,7 @@ static u32 ath_lookup_rate(struct ath_so
3824 tx_info = IEEE80211_SKB_CB(skb);
3825 - rates = tx_info->control.rates;
3826 + rates = bf->rates;
3829 * Find the lowest frame length among the rate series that will have a
3830 @@ -736,8 +757,6 @@ static int ath_compute_num_delims(struct
3833 #define FIRST_DESC_NDELIMS 60
3834 - struct sk_buff *skb = bf->bf_mpdu;
3835 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
3836 u32 nsymbits, nsymbols;
3839 @@ -778,8 +797,8 @@ static int ath_compute_num_delims(struct
3840 if (tid->an->mpdudensity == 0)
3843 - rix = tx_info->control.rates[0].idx;
3844 - flags = tx_info->control.rates[0].flags;
3845 + rix = bf->rates[0].idx;
3846 + flags = bf->rates[0].flags;
3847 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
3848 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
3850 @@ -858,6 +877,7 @@ static enum ATH_AGGR_STATUS ath_tx_form_
3854 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
3855 aggr_limit = ath_lookup_rate(sc, bf, tid);
3858 @@ -998,14 +1018,14 @@ static void ath_buf_set_rate(struct ath_
3861 tx_info = IEEE80211_SKB_CB(skb);
3862 - rates = tx_info->control.rates;
3863 + rates = bf->rates;
3864 hdr = (struct ieee80211_hdr *)skb->data;
3866 /* set dur_update_en for l-sig computation except for PS-Poll frames */
3867 info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
3868 info->rtscts_rate = fi->rtscts_rate;
3870 - for (i = 0; i < 4; i++) {
3871 + for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
3872 bool is_40, is_sgi, is_sp;
3875 @@ -1249,18 +1269,23 @@ int ath_tx_aggr_start(struct ath_softc *
3879 -void ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
3880 +bool ath_tx_aggr_stop(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid,
3883 struct ath_node *an = (struct ath_node *)sta->drv_priv;
3884 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
3885 struct ath_txq *txq = txtid->ac->txq;
3886 + bool ret = !flush;
3889 + txtid->stop_cb = false;
3891 if (txtid->state & AGGR_CLEANUP)
3895 if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
3896 txtid->state &= ~AGGR_ADDBA_PROGRESS;
3901 ath_txq_lock(sc, txq);
3902 @@ -1272,13 +1297,17 @@ void ath_tx_aggr_stop(struct ath_softc *
3903 * TID can only be reused after all in-progress subframes have been
3906 - if (txtid->baw_head != txtid->baw_tail)
3907 + if (txtid->baw_head != txtid->baw_tail) {
3908 txtid->state |= AGGR_CLEANUP;
3911 + txtid->stop_cb = !flush;
3913 txtid->state &= ~AGGR_ADDBA_COMPLETE;
3916 - ath_tx_flush_tid(sc, txtid);
3917 + ath_tx_flush_tid(sc, txtid, flush);
3918 ath_txq_unlock_complete(sc, txq);
3922 void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
3923 @@ -1743,6 +1772,7 @@ static void ath_tx_send_ampdu(struct ath
3927 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
3928 bf->bf_state.bf_type = BUF_AMPDU;
3929 INIT_LIST_HEAD(&bf_head);
3930 list_add(&bf->list, &bf_head);
3931 @@ -1892,49 +1922,6 @@ static struct ath_buf *ath_tx_setup_buff
3935 -/* FIXME: tx power */
3936 -static void ath_tx_start_dma(struct ath_softc *sc, struct sk_buff *skb,
3937 - struct ath_tx_control *txctl)
3939 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
3940 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3941 - struct ath_atx_tid *tid = NULL;
3942 - struct ath_buf *bf;
3945 - if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
3946 - tidno = ieee80211_get_qos_ctl(hdr)[0] &
3947 - IEEE80211_QOS_CTL_TID_MASK;
3948 - tid = ATH_AN_2_TID(txctl->an, tidno);
3950 - WARN_ON(tid->ac->txq != txctl->txq);
3953 - if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
3955 - * Try aggregation if it's a unicast data frame
3956 - * and the destination is HT capable.
3958 - ath_tx_send_ampdu(sc, tid, skb, txctl);
3960 - bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
3963 - dev_kfree_skb_any(skb);
3965 - ieee80211_free_txskb(sc->hw, skb);
3969 - bf->bf_state.bfs_paprd = txctl->paprd;
3972 - bf->bf_state.bfs_paprd_timestamp = jiffies;
3974 - ath_tx_send_normal(sc, txctl->txq, tid, skb);
3978 /* Upon failure caller should free skb */
3979 int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
3980 struct ath_tx_control *txctl)
3981 @@ -1945,8 +1932,11 @@ int ath_tx_start(struct ieee80211_hw *hw
3982 struct ieee80211_vif *vif = info->control.vif;
3983 struct ath_softc *sc = hw->priv;
3984 struct ath_txq *txq = txctl->txq;
3985 + struct ath_atx_tid *tid = NULL;
3986 + struct ath_buf *bf;
3987 int padpos, padsize;
3988 int frmlen = skb->len + FCS_LEN;
3992 /* NOTE: sta can be NULL according to net/mac80211.h */
3993 @@ -2002,8 +1992,41 @@ int ath_tx_start(struct ieee80211_hw *hw
3994 txq->stopped = true;
3997 - ath_tx_start_dma(sc, skb, txctl);
3998 + if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
3999 + tidno = ieee80211_get_qos_ctl(hdr)[0] &
4000 + IEEE80211_QOS_CTL_TID_MASK;
4001 + tid = ATH_AN_2_TID(txctl->an, tidno);
4003 + WARN_ON(tid->ac->txq != txctl->txq);
4006 + if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4008 + * Try aggregation if it's a unicast data frame
4009 + * and the destination is HT capable.
4011 + ath_tx_send_ampdu(sc, tid, skb, txctl);
4015 + bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4018 + dev_kfree_skb_any(skb);
4020 + ieee80211_free_txskb(sc->hw, skb);
4024 + bf->bf_state.bfs_paprd = txctl->paprd;
4027 + bf->bf_state.bfs_paprd_timestamp = jiffies;
4029 + ath_set_rates(vif, sta, bf);
4030 + ath_tx_send_normal(sc, txctl->txq, tid, skb);
4033 ath_txq_unlock(sc, txq);
4036 @@ -2414,6 +2437,7 @@ void ath_tx_node_init(struct ath_softc *
4037 tid->ac = &an->ac[acno];
4038 tid->state &= ~AGGR_ADDBA_COMPLETE;
4039 tid->state &= ~AGGR_ADDBA_PROGRESS;
4040 + tid->stop_cb = false;
4043 for (acno = 0, ac = &an->ac[acno];
4044 @@ -2450,8 +2474,7 @@ void ath_tx_node_cleanup(struct ath_soft
4047 ath_tid_drain(sc, txq, tid);
4048 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4049 - tid->state &= ~AGGR_CLEANUP;
4050 + ath_tx_clear_tid(sc, tid);
4052 ath_txq_unlock(sc, txq);
4054 --- a/drivers/net/wireless/ath/ath9k/recv.c
4055 +++ b/drivers/net/wireless/ath/ath9k/recv.c
4056 @@ -124,7 +124,7 @@ static bool ath_rx_edma_buf_link(struct
4058 SKB_CB_ATHBUF(skb) = bf;
4059 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
4060 - skb_queue_tail(&rx_edma->rx_fifo, skb);
4061 + __skb_queue_tail(&rx_edma->rx_fifo, skb);
4065 @@ -155,7 +155,7 @@ static void ath_rx_remove_buffer(struct
4067 rx_edma = &sc->rx.rx_edma[qtype];
4069 - while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4070 + while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4071 bf = SKB_CB_ATHBUF(skb);
4073 list_add_tail(&bf->list, &sc->rx.rxbuf);
4074 @@ -1287,13 +1287,13 @@ int ath_rx_tasklet(struct ath_softc *sc,
4075 goto requeue_drop_frag;
4078 - bf->bf_mpdu = requeue_skb;
4079 - bf->bf_buf_addr = new_buf_addr;
4081 /* Unmap the frame */
4082 dma_unmap_single(sc->dev, bf->bf_buf_addr,
4083 common->rx_bufsize, dma_type);
4085 + bf->bf_mpdu = requeue_skb;
4086 + bf->bf_buf_addr = new_buf_addr;
4088 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
4089 if (ah->caps.rx_status_len)
4090 skb_pull(skb, ah->caps.rx_status_len);
4091 --- a/net/wireless/core.c
4092 +++ b/net/wireless/core.c
4093 @@ -885,7 +885,6 @@ void cfg80211_leave(struct cfg80211_regi
4095 __cfg80211_disconnect(rdev, dev,
4096 WLAN_REASON_DEAUTH_LEAVING, true);
4097 - cfg80211_mlme_down(rdev, dev);
4100 case NL80211_IFTYPE_MESH_POINT:
4101 --- a/net/wireless/sme.c
4102 +++ b/net/wireless/sme.c
4103 @@ -961,7 +961,7 @@ int __cfg80211_disconnect(struct cfg8021
4104 /* was it connected by userspace SME? */
4106 cfg80211_mlme_down(rdev, dev);
4111 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
4112 @@ -987,6 +987,7 @@ int __cfg80211_disconnect(struct cfg8021
4117 if (wdev->sme_state == CFG80211_SME_CONNECTED)
4118 __cfg80211_disconnected(dev, NULL, 0, 0, false);
4119 else if (wdev->sme_state == CFG80211_SME_CONNECTING)