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 @@ -250,9 +251,9 @@ struct ath_atx_tid {
13 int baw_head; /* first un-acked tx buffer */
14 int baw_tail; /* next unused tx buffer slot */
24 @@ -273,10 +274,6 @@ struct ath_node {
28 -#define AGGR_CLEANUP BIT(1)
29 -#define AGGR_ADDBA_COMPLETE BIT(2)
30 -#define AGGR_ADDBA_PROGRESS BIT(3)
32 struct ath_tx_control {
35 @@ -299,6 +296,7 @@ struct ath_tx {
36 struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
37 struct ath_descdma txdma;
38 struct ath_txq *txq_map[IEEE80211_NUM_ACS];
39 + struct ath_txq *uapsdq;
40 u32 txq_max_pending[IEEE80211_NUM_ACS];
41 u16 max_aggr_framelen[IEEE80211_NUM_ACS][4][32];
43 @@ -356,6 +354,11 @@ void ath_tx_aggr_resume(struct ath_softc
44 void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
45 void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
47 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
48 + struct ieee80211_sta *sta,
49 + u16 tids, int nframes,
50 + enum ieee80211_frame_release_type reason,
55 @@ -658,11 +661,10 @@ enum sc_op_flags {
56 struct ath_rate_table;
58 struct ath9k_vif_iter_data {
59 - const u8 *hw_macaddr; /* phy's hardware address, set
60 - * before starting iteration for
63 + u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
64 u8 mask[ETH_ALEN]; /* bssid mask */
65 + bool has_hw_macaddr;
67 int naps; /* number of AP vifs */
68 int nmeshes; /* number of mesh vifs */
69 int nstations; /* number of station vifs */
70 --- a/drivers/net/wireless/ath/ath9k/hw.c
71 +++ b/drivers/net/wireless/ath/ath9k/hw.c
72 @@ -1171,6 +1171,7 @@ u32 ath9k_regd_get_ctl(struct ath_regula
73 static inline void ath9k_hw_set_dma(struct ath_hw *ah)
75 struct ath_common *common = ath9k_hw_common(ah);
78 ENABLE_REGWRITE_BUFFER(ah);
80 @@ -1224,13 +1225,17 @@ static inline void ath9k_hw_set_dma(stru
81 * So set the usable tx buf size also to half to
82 * avoid data/delimiter underruns
84 - REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
85 - AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
86 - } else if (!AR_SREV_9271(ah)) {
87 - REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
88 - AR_PCU_TXBUF_CTRL_USABLE_SIZE);
89 + txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
90 + } else if (AR_SREV_9340_13_OR_LATER(ah)) {
91 + /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
92 + txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
94 + txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
97 + if (!AR_SREV_9271(ah))
98 + REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
100 REGWRITE_BUFFER_FLUSH(ah);
102 if (AR_SREV_9300_20_OR_LATER(ah))
103 @@ -1305,9 +1310,13 @@ static bool ath9k_hw_set_reset(struct at
104 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
106 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
108 - (AR_INTR_SYNC_LOCAL_TIMEOUT |
109 - AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
110 + if (AR_SREV_9340(ah))
111 + tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
113 + tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
114 + AR_INTR_SYNC_RADM_CPL_TIMEOUT;
118 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
120 @@ -1366,7 +1375,10 @@ static bool ath9k_hw_set_reset(struct at
122 REGWRITE_BUFFER_FLUSH(ah);
125 + if (AR_SREV_9100(ah))
130 REG_WRITE(ah, AR_RTC_RC, 0);
131 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
132 @@ -1377,8 +1389,12 @@ static bool ath9k_hw_set_reset(struct at
133 if (!AR_SREV_9100(ah))
134 REG_WRITE(ah, AR_RC, 0);
136 - if (AR_SREV_9100(ah))
137 + if (AR_SREV_9100(ah) && type != ATH9K_RESET_WARM) {
138 + if (ah->external_reset)
139 + ah->external_reset();
146 @@ -1464,7 +1480,8 @@ static bool ath9k_hw_chip_reset(struct a
147 reset_type = ATH9K_RESET_POWER_ON;
149 reset_type = ATH9K_RESET_COLD;
150 - } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
151 + } else if (ah->chip_fullsleep ||
152 + REG_READ(ah, AR_Q_TXE) ||
153 (REG_READ(ah, AR_CR) & AR_CR_RXE))
154 reset_type = ATH9K_RESET_COLD;
156 @@ -1698,12 +1715,11 @@ static void ath9k_hw_reset_opmode(struct
158 ENABLE_REGWRITE_BUFFER(ah);
160 - REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
161 - REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
163 + REG_RMW(ah, AR_STA_ID1, macStaId1
164 | AR_STA_ID1_RTS_USE_DEF
165 | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
166 - | ah->sta_id1_defaults);
167 + | ah->sta_id1_defaults,
168 + ~AR_STA_ID1_SADH_MASK);
169 ath_hw_setbssidmask(common);
170 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
171 ath9k_hw_write_associd(ah);
172 --- a/drivers/net/wireless/ath/ath9k/main.c
173 +++ b/drivers/net/wireless/ath/ath9k/main.c
174 @@ -839,10 +839,14 @@ static void ath9k_vif_iter(void *data, u
175 struct ath9k_vif_iter_data *iter_data = data;
178 - if (iter_data->hw_macaddr)
179 + if (iter_data->has_hw_macaddr) {
180 for (i = 0; i < ETH_ALEN; i++)
181 iter_data->mask[i] &=
182 ~(iter_data->hw_macaddr[i] ^ mac[i]);
184 + memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
185 + iter_data->has_hw_macaddr = true;
189 case NL80211_IFTYPE_AP:
190 @@ -891,7 +895,6 @@ void ath9k_calculate_iter_data(struct ie
191 * together with the BSSID mask when matching addresses.
193 memset(iter_data, 0, sizeof(*iter_data));
194 - iter_data->hw_macaddr = common->macaddr;
195 memset(&iter_data->mask, 0xff, ETH_ALEN);
198 @@ -901,6 +904,8 @@ void ath9k_calculate_iter_data(struct ie
199 ieee80211_iterate_active_interfaces_atomic(
200 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
201 ath9k_vif_iter, iter_data);
203 + memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
206 /* Called with sc->mutex held. */
207 @@ -1327,6 +1332,7 @@ static int ath9k_sta_add(struct ieee8021
208 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
209 struct ath_node *an = (struct ath_node *) sta->drv_priv;
210 struct ieee80211_key_conf ps_key = { };
213 ath_node_attach(sc, sta, vif);
215 @@ -1334,7 +1340,9 @@ static int ath9k_sta_add(struct ieee8021
216 vif->type != NL80211_IFTYPE_AP_VLAN)
219 - an->ps_key = ath_key_config(common, vif, sta, &ps_key);
220 + key = ath_key_config(common, vif, sta, &ps_key);
226 @@ -1351,6 +1359,7 @@ static void ath9k_del_ps_key(struct ath_
229 ath_key_delete(common, &ps_key);
233 static int ath9k_sta_remove(struct ieee80211_hw *hw,
234 @@ -1678,6 +1687,7 @@ static int ath9k_ampdu_action(struct iee
235 u16 tid, u16 *ssn, u8 buf_size)
237 struct ath_softc *sc = hw->priv;
238 + bool flush = false;
242 @@ -1694,12 +1704,14 @@ static int ath9k_ampdu_action(struct iee
243 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
244 ath9k_ps_restore(sc);
246 - case IEEE80211_AMPDU_TX_STOP_CONT:
247 case IEEE80211_AMPDU_TX_STOP_FLUSH:
248 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
250 + case IEEE80211_AMPDU_TX_STOP_CONT:
252 ath_tx_aggr_stop(sc, sta, tid);
253 - ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
255 + ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
256 ath9k_ps_restore(sc);
258 case IEEE80211_AMPDU_TX_OPERATIONAL:
259 @@ -2366,6 +2378,7 @@ struct ieee80211_ops ath9k_ops = {
260 .flush = ath9k_flush,
261 .tx_frames_pending = ath9k_tx_frames_pending,
262 .tx_last_beacon = ath9k_tx_last_beacon,
263 + .release_buffered_frames = ath9k_release_buffered_frames,
264 .get_stats = ath9k_get_stats,
265 .set_antenna = ath9k_set_antenna,
266 .get_antenna = ath9k_get_antenna,
267 --- a/drivers/net/wireless/ath/ath9k/reg.h
268 +++ b/drivers/net/wireless/ath/ath9k/reg.h
270 #define AR_SREV_REVISION_9485_10 0
271 #define AR_SREV_REVISION_9485_11 1
272 #define AR_SREV_VERSION_9340 0x300
273 +#define AR_SREV_REVISION_9340_10 0
274 +#define AR_SREV_REVISION_9340_11 1
275 +#define AR_SREV_REVISION_9340_12 2
276 +#define AR_SREV_REVISION_9340_13 3
277 #define AR_SREV_VERSION_9580 0x1C0
278 #define AR_SREV_REVISION_9580_10 4 /* AR9580 1.0 */
279 #define AR_SREV_VERSION_9462 0x280
281 #define AR_SREV_9340(_ah) \
282 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
284 +#define AR_SREV_9340_13_OR_LATER(_ah) \
285 + (AR_SREV_9340((_ah)) && \
286 + ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))
288 #define AR_SREV_9285E_20(_ah) \
289 (AR_SREV_9285_12_OR_LATER(_ah) && \
290 ((REG_READ(_ah, AR_AN_SYNTH9) & 0x7) == 0x1))
291 @@ -1007,6 +1015,8 @@ enum {
292 AR_INTR_SYNC_LOCAL_TIMEOUT |
293 AR_INTR_SYNC_MAC_SLEEP_ACCESS),
295 + AR9340_INTR_SYNC_LOCAL_TIMEOUT = 0x00000010,
297 AR_INTR_SYNC_SPURIOUS = 0xFFFFFFFF,
300 @@ -1493,9 +1503,6 @@ enum {
301 #define AR9271_RADIO_RF_RST 0x20
302 #define AR9271_GATE_MAC_CTL 0x4000
304 -#define AR_STA_ID0 0x8000
305 -#define AR_STA_ID1 0x8004
306 -#define AR_STA_ID1_SADH_MASK 0x0000FFFF
307 #define AR_STA_ID1_STA_AP 0x00010000
308 #define AR_STA_ID1_ADHOC 0x00020000
309 #define AR_STA_ID1_PWR_SAV 0x00040000
310 @@ -1884,6 +1891,7 @@ enum {
311 #define AR_PCU_TXBUF_CTRL_SIZE_MASK 0x7FF
312 #define AR_PCU_TXBUF_CTRL_USABLE_SIZE 0x700
313 #define AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE 0x380
314 +#define AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE 0x500
316 #define AR_PCU_MISC_MODE2 0x8344
317 #define AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE 0x00000002
318 --- a/drivers/net/wireless/ath/hw.c
319 +++ b/drivers/net/wireless/ath/hw.c
321 void ath_hw_setbssidmask(struct ath_common *common)
323 void *ah = common->ah;
326 + REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
327 + id1 = REG_READ(ah, AR_STA_ID1) & ~AR_STA_ID1_SADH_MASK;
328 + id1 |= get_unaligned_le16(common->macaddr + 4);
329 + REG_WRITE(ah, AR_STA_ID1, id1);
331 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
332 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
333 --- a/drivers/net/wireless/ath/reg.h
334 +++ b/drivers/net/wireless/ath/reg.h
336 #define AR_MIBC_CMC 0x00000004
337 #define AR_MIBC_MCS 0x00000008
339 +#define AR_STA_ID0 0x8000
340 +#define AR_STA_ID1 0x8004
341 +#define AR_STA_ID1_SADH_MASK 0x0000ffff
344 * BSSID mask registers. See ath_hw_set_bssid_mask()
345 * for detailed documentation about these registers.
346 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
347 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
348 @@ -6059,7 +6059,7 @@ il4965_mac_channel_switch(struct ieee802
349 struct il_priv *il = hw->priv;
350 const struct il_channel_info *ch_info;
351 struct ieee80211_conf *conf = &hw->conf;
352 - struct ieee80211_channel *channel = ch_switch->channel;
353 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
354 struct il_ht_config *ht_conf = &il->current_ht_config;
357 @@ -6096,23 +6096,21 @@ il4965_mac_channel_switch(struct ieee802
358 il->current_ht_config.smps = conf->smps_mode;
360 /* Configure HT40 channels */
361 - il->ht.enabled = conf_is_ht(conf);
362 - if (il->ht.enabled) {
363 - if (conf_is_ht40_minus(conf)) {
364 - il->ht.extension_chan_offset =
365 - IEEE80211_HT_PARAM_CHA_SEC_BELOW;
366 - il->ht.is_40mhz = true;
367 - } else if (conf_is_ht40_plus(conf)) {
368 - il->ht.extension_chan_offset =
369 - IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
370 - il->ht.is_40mhz = true;
372 - il->ht.extension_chan_offset =
373 - IEEE80211_HT_PARAM_CHA_SEC_NONE;
374 - il->ht.is_40mhz = false;
377 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
378 + case NL80211_CHAN_NO_HT:
379 + case NL80211_CHAN_HT20:
380 il->ht.is_40mhz = false;
381 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
383 + case NL80211_CHAN_HT40MINUS:
384 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
385 + il->ht.is_40mhz = true;
387 + case NL80211_CHAN_HT40PLUS:
388 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
389 + il->ht.is_40mhz = true;
393 if ((le16_to_cpu(il->staging.channel) != ch))
394 il->staging.flags = 0;
395 --- a/drivers/net/wireless/iwlegacy/4965.c
396 +++ b/drivers/net/wireless/iwlegacy/4965.c
397 @@ -1493,7 +1493,7 @@ il4965_hw_channel_switch(struct il_priv
400 cmd.expect_beacon = 0;
401 - ch = ch_switch->channel->hw_value;
402 + ch = ch_switch->chandef.chan->hw_value;
403 cmd.channel = cpu_to_le16(ch);
404 cmd.rxon_flags = il->staging.flags;
405 cmd.rxon_filter_flags = il->staging.filter_flags;
406 --- a/drivers/net/wireless/iwlwifi/dvm/devices.c
407 +++ b/drivers/net/wireless/iwlwifi/dvm/devices.c
408 @@ -379,7 +379,7 @@ static int iwl5000_hw_channel_switch(str
411 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
412 - ch = ch_switch->channel->hw_value;
413 + ch = ch_switch->chandef.chan->hw_value;
414 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
415 ctx->active.channel, ch);
416 cmd.channel = cpu_to_le16(ch);
417 @@ -414,7 +414,8 @@ static int iwl5000_hw_channel_switch(str
419 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
421 - cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
422 + cmd.expect_beacon =
423 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
425 return iwl_dvm_send_cmd(priv, &hcmd);
427 @@ -540,7 +541,7 @@ static int iwl6000_hw_channel_switch(str
430 cmd->band = priv->band == IEEE80211_BAND_2GHZ;
431 - ch = ch_switch->channel->hw_value;
432 + ch = ch_switch->chandef.chan->hw_value;
433 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
434 ctx->active.channel, ch);
435 cmd->channel = cpu_to_le16(ch);
436 @@ -575,7 +576,8 @@ static int iwl6000_hw_channel_switch(str
438 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
440 - cmd->expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
441 + cmd->expect_beacon =
442 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
444 err = iwl_dvm_send_cmd(priv, &hcmd);
446 --- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
447 +++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
448 @@ -970,7 +970,7 @@ static void iwlagn_mac_channel_switch(st
450 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
451 struct ieee80211_conf *conf = &hw->conf;
452 - struct ieee80211_channel *channel = ch_switch->channel;
453 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
454 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
457 @@ -1008,11 +1008,21 @@ static void iwlagn_mac_channel_switch(st
458 priv->current_ht_config.smps = conf->smps_mode;
460 /* Configure HT40 channels */
461 - ctx->ht.enabled = conf_is_ht(conf);
462 - if (ctx->ht.enabled)
463 - iwlagn_config_ht40(conf, ctx);
465 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
466 + case NL80211_CHAN_NO_HT:
467 + case NL80211_CHAN_HT20:
468 ctx->ht.is_40mhz = false;
469 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
471 + case NL80211_CHAN_HT40MINUS:
472 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
473 + ctx->ht.is_40mhz = true;
475 + case NL80211_CHAN_HT40PLUS:
476 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
477 + ctx->ht.is_40mhz = true;
481 if ((le16_to_cpu(ctx->staging.channel) != ch))
482 ctx->staging.flags = 0;
483 --- a/drivers/net/wireless/iwlwifi/dvm/rxon.c
484 +++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c
485 @@ -1160,7 +1160,7 @@ int iwlagn_commit_rxon(struct iwl_priv *
488 void iwlagn_config_ht40(struct ieee80211_conf *conf,
489 - struct iwl_rxon_context *ctx)
490 + struct iwl_rxon_context *ctx)
492 if (conf_is_ht40_minus(conf)) {
493 ctx->ht.extension_chan_offset =
494 --- a/drivers/net/wireless/mac80211_hwsim.c
495 +++ b/drivers/net/wireless/mac80211_hwsim.c
497 #include <linux/if_arp.h>
498 #include <linux/rtnetlink.h>
499 #include <linux/etherdevice.h>
500 +#include <linux/platform_device.h>
501 #include <linux/debugfs.h>
502 #include <linux/module.h>
503 #include <linux/ktime.h>
504 @@ -717,9 +718,17 @@ static bool mac80211_hwsim_tx_frame_no_n
505 rx_status.flag |= RX_FLAG_MACTIME_START;
506 rx_status.freq = chan->center_freq;
507 rx_status.band = chan->band;
508 - rx_status.rate_idx = info->control.rates[0].idx;
509 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
510 - rx_status.flag |= RX_FLAG_HT;
511 + if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
512 + rx_status.rate_idx =
513 + ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
514 + rx_status.vht_nss =
515 + ieee80211_rate_get_vht_nss(&info->control.rates[0]);
516 + rx_status.flag |= RX_FLAG_VHT;
518 + rx_status.rate_idx = info->control.rates[0].idx;
519 + if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
520 + rx_status.flag |= RX_FLAG_HT;
522 if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
523 rx_status.flag |= RX_FLAG_40MHZ;
524 if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
525 @@ -1687,6 +1696,7 @@ static void mac80211_hwsim_free(void)
526 debugfs_remove(data->debugfs_ps);
527 debugfs_remove(data->debugfs);
528 ieee80211_unregister_hw(data->hw);
529 + device_release_driver(data->dev);
530 device_unregister(data->dev);
531 ieee80211_free_hw(data->hw);
533 @@ -1695,7 +1705,9 @@ static void mac80211_hwsim_free(void)
536 static struct device_driver mac80211_hwsim_driver = {
537 - .name = "mac80211_hwsim"
538 + .name = "mac80211_hwsim",
539 + .bus = &platform_bus_type,
540 + .owner = THIS_MODULE,
543 static const struct net_device_ops hwsim_netdev_ops = {
544 @@ -2187,9 +2199,15 @@ static int __init init_mac80211_hwsim(vo
545 spin_lock_init(&hwsim_radio_lock);
546 INIT_LIST_HEAD(&hwsim_radios);
548 + err = driver_register(&mac80211_hwsim_driver);
552 hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
553 - if (IS_ERR(hwsim_class))
554 - return PTR_ERR(hwsim_class);
555 + if (IS_ERR(hwsim_class)) {
556 + err = PTR_ERR(hwsim_class);
557 + goto failed_unregister_driver;
560 memset(addr, 0, ETH_ALEN);
562 @@ -2211,12 +2229,20 @@ static int __init init_mac80211_hwsim(vo
564 if (IS_ERR(data->dev)) {
566 - "mac80211_hwsim: device_create "
567 - "failed (%ld)\n", PTR_ERR(data->dev));
568 + "mac80211_hwsim: device_create failed (%ld)\n",
569 + PTR_ERR(data->dev));
573 data->dev->driver = &mac80211_hwsim_driver;
574 + err = device_bind_driver(data->dev);
577 + "mac80211_hwsim: device_bind_driver failed (%d)\n",
582 skb_queue_head_init(&data->pending);
584 SET_IEEE80211_DEV(hw, data->dev);
585 @@ -2515,6 +2541,8 @@ failed_drvdata:
586 ieee80211_free_hw(hw);
588 mac80211_hwsim_free();
589 +failed_unregister_driver:
590 + driver_unregister(&mac80211_hwsim_driver);
593 module_init(init_mac80211_hwsim);
594 @@ -2527,5 +2555,6 @@ static void __exit exit_mac80211_hwsim(v
596 mac80211_hwsim_free();
597 unregister_netdev(hwsim_mon);
598 + driver_unregister(&mac80211_hwsim_driver);
600 module_exit(exit_mac80211_hwsim);
601 --- a/drivers/net/wireless/ti/wl12xx/cmd.c
602 +++ b/drivers/net/wireless/ti/wl12xx/cmd.c
603 @@ -301,7 +301,7 @@ int wl12xx_cmd_channel_switch(struct wl1
606 cmd->role_id = wlvif->role_id;
607 - cmd->channel = ch_switch->channel->hw_value;
608 + cmd->channel = ch_switch->chandef.chan->hw_value;
609 cmd->switch_time = ch_switch->count;
610 cmd->stop_tx = ch_switch->block_tx;
612 --- a/drivers/net/wireless/ti/wl18xx/cmd.c
613 +++ b/drivers/net/wireless/ti/wl18xx/cmd.c
614 @@ -42,11 +42,11 @@ int wl18xx_cmd_channel_switch(struct wl1
617 cmd->role_id = wlvif->role_id;
618 - cmd->channel = ch_switch->channel->hw_value;
619 + cmd->channel = ch_switch->chandef.chan->hw_value;
620 cmd->switch_time = ch_switch->count;
621 cmd->stop_tx = ch_switch->block_tx;
623 - switch (ch_switch->channel->band) {
624 + switch (ch_switch->chandef.chan->band) {
625 case IEEE80211_BAND_2GHZ:
626 cmd->band = WLCORE_BAND_2_4GHZ;
628 @@ -55,7 +55,7 @@ int wl18xx_cmd_channel_switch(struct wl1
631 wl1271_error("invalid channel switch band: %d",
632 - ch_switch->channel->band);
633 + ch_switch->chandef.chan->band);
637 --- a/include/linux/ieee80211.h
638 +++ b/include/linux/ieee80211.h
639 @@ -673,6 +673,36 @@ struct ieee80211_channel_sw_ie {
643 + * struct ieee80211_ext_chansw_ie
645 + * This structure represents the "Extended Channel Switch Announcement element"
647 +struct ieee80211_ext_chansw_ie {
649 + u8 new_operating_class;
655 + * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
656 + * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
658 + * This structure represents the "Secondary Channel Offset element"
660 +struct ieee80211_sec_chan_offs_ie {
665 + * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
667 +struct ieee80211_wide_bw_chansw_ie {
668 + u8 new_channel_width;
669 + u8 new_center_freq_seg0, new_center_freq_seg1;
673 * struct ieee80211_tim
675 * This structure refers to "Traffic Indication Map information element"
676 @@ -840,12 +870,15 @@ struct ieee80211_mgmt {
677 } __packed wme_action;
682 - struct ieee80211_channel_sw_ie sw_elem;
684 } __packed chan_switch;
687 + struct ieee80211_ext_chansw_ie data;
689 + } __packed ext_chan_switch;
695 @@ -1638,6 +1671,7 @@ enum ieee80211_eid {
697 WLAN_EID_HT_CAPABILITY = 45,
698 WLAN_EID_HT_OPERATION = 61,
699 + WLAN_EID_SECONDARY_CHANNEL_OFFSET = 62,
703 @@ -1672,6 +1706,8 @@ enum ieee80211_eid {
704 WLAN_EID_VHT_CAPABILITY = 191,
705 WLAN_EID_VHT_OPERATION = 192,
706 WLAN_EID_OPMODE_NOTIF = 199,
707 + WLAN_EID_WIDE_BW_CHANNEL_SWITCH = 194,
708 + WLAN_EID_CHANNEL_SWITCH_WRAPPER = 196,
711 WLAN_EID_NON_TX_BSSID_CAP = 83,
712 @@ -1795,6 +1831,7 @@ enum ieee80211_key_len {
714 /* Public action codes */
715 enum ieee80211_pub_actioncode {
716 + WLAN_PUB_ACTION_EXT_CHANSW_ANN = 4,
717 WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
720 --- a/include/net/cfg80211.h
721 +++ b/include/net/cfg80211.h
722 @@ -753,6 +753,8 @@ int cfg80211_check_station_change(struct
723 * @STATION_INFO_LOCAL_PM: @local_pm filled
724 * @STATION_INFO_PEER_PM: @peer_pm filled
725 * @STATION_INFO_NONPEER_PM: @nonpeer_pm filled
726 + * @STATION_INFO_CHAIN_SIGNAL: @chain_signal filled
727 + * @STATION_INFO_CHAIN_SIGNAL_AVG: @chain_signal_avg filled
729 enum station_info_flags {
730 STATION_INFO_INACTIVE_TIME = 1<<0,
731 @@ -781,6 +783,8 @@ enum station_info_flags {
732 STATION_INFO_NONPEER_PM = 1<<23,
733 STATION_INFO_RX_BYTES64 = 1<<24,
734 STATION_INFO_TX_BYTES64 = 1<<25,
735 + STATION_INFO_CHAIN_SIGNAL = 1<<26,
736 + STATION_INFO_CHAIN_SIGNAL_AVG = 1<<27,
740 @@ -857,6 +861,8 @@ struct sta_bss_parameters {
744 +#define IEEE80211_MAX_CHAINS 4
747 * struct station_info - station information
749 @@ -874,6 +880,9 @@ struct sta_bss_parameters {
750 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
751 * @signal_avg: Average signal strength, type depends on the wiphy's signal_type.
752 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
753 + * @chains: bitmask for filled values in @chain_signal, @chain_signal_avg
754 + * @chain_signal: per-chain signal strength of last received packet in dBm
755 + * @chain_signal_avg: per-chain signal strength average in dBm
756 * @txrate: current unicast bitrate from this station
757 * @rxrate: current unicast bitrate to this station
758 * @rx_packets: packets received from this station
759 @@ -909,6 +918,11 @@ struct station_info {
765 + s8 chain_signal[IEEE80211_MAX_CHAINS];
766 + s8 chain_signal_avg[IEEE80211_MAX_CHAINS];
768 struct rate_info txrate;
769 struct rate_info rxrate;
771 @@ -954,6 +968,7 @@ enum monitor_flags {
772 MONITOR_FLAG_CONTROL = 1<<NL80211_MNTR_FLAG_CONTROL,
773 MONITOR_FLAG_OTHER_BSS = 1<<NL80211_MNTR_FLAG_OTHER_BSS,
774 MONITOR_FLAG_COOK_FRAMES = 1<<NL80211_MNTR_FLAG_COOK_FRAMES,
775 + MONITOR_FLAG_ACTIVE = 1<<NL80211_MNTR_FLAG_ACTIVE,
779 @@ -4027,6 +4042,17 @@ bool cfg80211_reg_can_beacon(struct wiph
780 void cfg80211_ch_switch_notify(struct net_device *dev,
781 struct cfg80211_chan_def *chandef);
784 + * ieee80211_operating_class_to_band - convert operating class to band
786 + * @operating_class: the operating class to convert
787 + * @band: band pointer to fill
789 + * Returns %true if the conversion was successful, %false otherwise.
791 +bool ieee80211_operating_class_to_band(u8 operating_class,
792 + enum ieee80211_band *band);
795 * cfg80211_tdls_oper_request - request userspace to perform TDLS operation
796 * @dev: the device on which the operation is requested
797 --- a/include/net/mac80211.h
798 +++ b/include/net/mac80211.h
799 @@ -210,7 +210,7 @@ struct ieee80211_chanctx_conf {
800 * @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
801 * that it is only ever disabled for station mode.
802 * @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
803 - * @BSS_CHANGED_SSID: SSID changed for this BSS (AP mode)
804 + * @BSS_CHANGED_SSID: SSID changed for this BSS (AP and IBSS mode)
805 * @BSS_CHANGED_AP_PROBE_RESP: Probe Response changed for this BSS (AP mode)
806 * @BSS_CHANGED_PS: PS changed for this BSS (STA mode)
807 * @BSS_CHANGED_TXPOWER: TX power setting changed for this interface
808 @@ -327,7 +327,7 @@ enum ieee80211_rssi_event {
809 * your driver/device needs to do.
810 * @ps: power-save mode (STA only). This flag is NOT affected by
811 * offchannel/dynamic_ps operations.
812 - * @ssid: The SSID of the current vif. Only valid in AP-mode.
813 + * @ssid: The SSID of the current vif. Valid in AP and IBSS mode.
814 * @ssid_len: Length of SSID given in @ssid.
815 * @hidden_ssid: The SSID of the current vif is hidden. Only valid in AP-mode.
816 * @txpower: TX power in dBm
817 @@ -562,6 +562,9 @@ enum mac80211_rate_control_flags {
818 /* maximum number of rate stages */
819 #define IEEE80211_TX_MAX_RATES 4
821 +/* maximum number of rate table entries */
822 +#define IEEE80211_TX_RATE_TABLE_SIZE 4
825 * struct ieee80211_tx_rate - rate selection/status
827 @@ -602,8 +605,8 @@ static inline void ieee80211_rate_set_vh
831 - WARN_ON(nss & ~0x7);
832 - rate->idx = (nss << 4) | mcs;
833 + WARN_ON((nss - 1) & ~0x7);
834 + rate->idx = ((nss - 1) << 4) | mcs;
838 @@ -615,7 +618,7 @@ ieee80211_rate_get_vht_mcs(const struct
840 ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate)
842 - return rate->idx >> 4;
843 + return (rate->idx >> 4) + 1;
847 @@ -656,7 +659,11 @@ struct ieee80211_tx_info {
848 struct ieee80211_tx_rate rates[
849 IEEE80211_TX_MAX_RATES];
854 + u8 short_preamble:1;
858 /* only needed before rate control */
859 unsigned long jiffies;
860 @@ -677,6 +684,8 @@ struct ieee80211_tx_info {
862 struct ieee80211_tx_rate driver_rates[
863 IEEE80211_TX_MAX_RATES];
866 void *rate_driver_data[
867 IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE / sizeof(void *)];
869 @@ -840,6 +849,9 @@ enum mac80211_rx_flags {
870 * @signal: signal strength when receiving this frame, either in dBm, in dB or
871 * unspecified depending on the hardware capabilities flags
872 * @IEEE80211_HW_SIGNAL_*
873 + * @chains: bitmask of receive chains for which separate signal strength
874 + * values were filled.
875 + * @chain_signal: per-chain signal strength, same format as @signal
876 * @antenna: antenna used
877 * @rate_idx: index of data rate into band's supported rates or MCS index if
878 * HT or VHT is used (%RX_FLAG_HT/%RX_FLAG_VHT)
879 @@ -871,6 +883,8 @@ struct ieee80211_rx_status {
884 + s8 chain_signal[IEEE80211_MAX_CHAINS];
885 u8 ampdu_delimiter_crc;
886 u8 vendor_radiotap_align;
887 u8 vendor_radiotap_oui[3];
888 @@ -1018,13 +1032,13 @@ struct ieee80211_conf {
889 * the driver passed into mac80211.
890 * @block_tx: Indicates whether transmission must be blocked before the
891 * scheduled channel switch, as indicated by the AP.
892 - * @channel: the new channel to switch to
893 + * @chandef: the new channel to switch to
894 * @count: the number of TBTT's until the channel switch event
896 struct ieee80211_channel_switch {
899 - struct ieee80211_channel *channel;
900 + struct cfg80211_chan_def chandef;
904 @@ -1222,6 +1236,24 @@ enum ieee80211_sta_rx_bandwidth {
908 + * struct ieee80211_sta_rates - station rate selection table
910 + * @rcu_head: RCU head used for freeing the table on update
911 + * @rates: transmit rates/flags to be used by default.
912 + * Overriding entries per-packet is possible by using cb tx control.
914 +struct ieee80211_sta_rates {
915 + struct rcu_head rcu_head;
922 + } rate[IEEE80211_TX_RATE_TABLE_SIZE];
926 * struct ieee80211_sta - station table entry
928 * A station table entry represents a station we are possibly
929 @@ -1248,6 +1280,7 @@ enum ieee80211_sta_rx_bandwidth {
930 * notifications and capabilities. The value is only valid after
931 * the station moves to associated state.
932 * @smps_mode: current SMPS mode (off, static or dynamic)
933 + * @tx_rates: rate control selection table
935 struct ieee80211_sta {
936 u32 supp_rates[IEEE80211_NUM_BANDS];
937 @@ -1261,6 +1294,7 @@ struct ieee80211_sta {
939 enum ieee80211_sta_rx_bandwidth bandwidth;
940 enum ieee80211_smps_mode smps_mode;
941 + struct ieee80211_sta_rates __rcu *rates;
944 u8 drv_priv[0] __aligned(sizeof(void *));
945 @@ -1416,6 +1450,9 @@ struct ieee80211_tx_control {
946 * for different virtual interfaces. See the doc section on HW queue
947 * control for more details.
949 + * @IEEE80211_HW_SUPPORTS_RC_TABLE: The driver supports using a rate
950 + * selection table provided by the rate control algorithm.
952 * @IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF: Use the P2P Device address for any
953 * P2P Interface. This will be honoured even if more than one interface
955 @@ -1448,6 +1485,7 @@ enum ieee80211_hw_flags {
956 IEEE80211_HW_SUPPORTS_PER_STA_GTK = 1<<21,
957 IEEE80211_HW_AP_LINK_PS = 1<<22,
958 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW = 1<<23,
959 + IEEE80211_HW_SUPPORTS_RC_TABLE = 1<<24,
960 IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF = 1<<25,
961 IEEE80211_HW_TIMING_BEACON_ONLY = 1<<26,
963 @@ -3144,6 +3182,25 @@ void ieee80211_sta_set_buffered(struct i
964 u8 tid, bool buffered);
967 + * ieee80211_get_tx_rates - get the selected transmit rates for a packet
969 + * Call this function in a driver with per-packet rate selection support
970 + * to combine the rate info in the packet tx info with the most recent
971 + * rate selection table for the station entry.
973 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
974 + * @sta: the receiver station to which this packet is sent.
975 + * @skb: the frame to be transmitted.
976 + * @dest: buffer for extracted rate/retry information
977 + * @max_rates: maximum number of rates to fetch
979 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
980 + struct ieee80211_sta *sta,
981 + struct sk_buff *skb,
982 + struct ieee80211_tx_rate *dest,
986 * ieee80211_tx_status - transmit status callback
988 * Call this function for all transmitted frames after they have been
989 @@ -4118,7 +4175,7 @@ void ieee80211_send_bar(struct ieee80211
990 * (deprecated; this will be removed once drivers get updated to use
992 * @rate_idx_mask: user-requested (legacy) rate mask
993 - * @rate_idx_mcs_mask: user-requested MCS rate mask
994 + * @rate_idx_mcs_mask: user-requested MCS rate mask (NULL if not in use)
995 * @bss: whether this frame is sent out in AP or IBSS mode
997 struct ieee80211_tx_rate_control {
998 @@ -4130,7 +4187,7 @@ struct ieee80211_tx_rate_control {
999 bool rts, short_preamble;
1002 - u8 rate_idx_mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
1003 + u8 *rate_idx_mcs_mask;
1007 @@ -4219,6 +4276,22 @@ bool rate_usable_index_exists(struct iee
1012 + * rate_control_set_rates - pass the sta rate selection to mac80211/driver
1014 + * When not doing a rate control probe to test rates, rate control should pass
1015 + * its rate selection to mac80211. If the driver supports receiving a station
1016 + * rate table, it will use it to ensure that frames are always sent based on
1017 + * the most recent rate control module decision.
1019 + * @hw: pointer as obtained from ieee80211_alloc_hw()
1020 + * @pubsta: &struct ieee80211_sta pointer to the target destination.
1021 + * @rates: new tx rate set to be used for this station.
1023 +int rate_control_set_rates(struct ieee80211_hw *hw,
1024 + struct ieee80211_sta *pubsta,
1025 + struct ieee80211_sta_rates *rates);
1027 int ieee80211_rate_control_register(struct rate_control_ops *ops);
1028 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
1030 --- a/net/mac80211/agg-rx.c
1031 +++ b/net/mac80211/agg-rx.c
1032 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
1033 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1034 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1035 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
1036 + else if (sdata->vif.type == NL80211_IFTYPE_WDS)
1037 + memcpy(mgmt->bssid, da, ETH_ALEN);
1039 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1040 IEEE80211_STYPE_ACTION);
1041 --- a/net/mac80211/agg-tx.c
1042 +++ b/net/mac80211/agg-tx.c
1043 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
1044 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1045 if (sdata->vif.type == NL80211_IFTYPE_AP ||
1046 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1047 - sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
1048 + sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
1049 + sdata->vif.type == NL80211_IFTYPE_WDS)
1050 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
1051 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
1052 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1053 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
1054 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1055 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1056 sdata->vif.type != NL80211_IFTYPE_AP &&
1057 + sdata->vif.type != NL80211_IFTYPE_WDS &&
1058 sdata->vif.type != NL80211_IFTYPE_ADHOC)
1061 --- a/net/mac80211/cfg.c
1062 +++ b/net/mac80211/cfg.c
1063 @@ -73,16 +73,19 @@ static int ieee80211_change_iface(struct
1064 struct ieee80211_local *local = sdata->local;
1066 if (ieee80211_sdata_running(sdata)) {
1067 + u32 mask = MONITOR_FLAG_COOK_FRAMES |
1068 + MONITOR_FLAG_ACTIVE;
1071 - * Prohibit MONITOR_FLAG_COOK_FRAMES to be
1072 - * changed while the interface is up.
1073 + * Prohibit MONITOR_FLAG_COOK_FRAMES and
1074 + * MONITOR_FLAG_ACTIVE to be changed while the
1075 + * interface is up.
1076 * Else we would need to add a lot of cruft
1077 * to update everything:
1078 * cooked_mntrs, monitor and all fif_* counters
1079 * reconfigure hardware
1081 - if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
1082 - (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1083 + if ((*flags & mask) != (sdata->u.mntr_flags & mask))
1086 ieee80211_adjust_monitor_flags(sdata, -1);
1087 @@ -444,7 +447,7 @@ static void sta_set_sinfo(struct sta_inf
1088 struct ieee80211_local *local = sdata->local;
1089 struct timespec uptime;
1094 sinfo->generation = sdata->local->sta_generation;
1096 @@ -488,6 +491,17 @@ static void sta_set_sinfo(struct sta_inf
1097 sinfo->signal = (s8)sta->last_signal;
1098 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
1100 + if (sta->chains) {
1101 + sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
1102 + STATION_INFO_CHAIN_SIGNAL_AVG;
1104 + sinfo->chains = sta->chains;
1105 + for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1106 + sinfo->chain_signal[i] = sta->chain_signal_last[i];
1107 + sinfo->chain_signal_avg[i] =
1108 + (s8) -ewma_read(&sta->chain_signal_avg[i]);
1112 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
1113 sta_set_rate_info_rx(sta, &sinfo->rxrate);
1114 @@ -1052,6 +1066,7 @@ static int ieee80211_stop_ap(struct wiph
1115 ieee80211_free_keys(sdata);
1117 sdata->vif.bss_conf.enable_beacon = false;
1118 + sdata->vif.bss_conf.ssid_len = 0;
1119 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1120 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1122 @@ -2416,9 +2431,22 @@ static int ieee80211_set_bitrate_mask(st
1125 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1126 + struct ieee80211_supported_band *sband = wiphy->bands[i];
1129 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1130 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1131 sizeof(mask->control[i].mcs));
1133 + sdata->rc_has_mcs_mask[i] = false;
1137 + for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
1138 + if (~sdata->rc_rateidx_mcs_mask[i][j]) {
1139 + sdata->rc_has_mcs_mask[i] = true;
1145 --- a/net/mac80211/chan.c
1146 +++ b/net/mac80211/chan.c
1147 @@ -57,6 +57,22 @@ ieee80211_find_chanctx(struct ieee80211_
1151 +static bool ieee80211_is_radar_required(struct ieee80211_local *local)
1153 + struct ieee80211_sub_if_data *sdata;
1156 + list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1157 + if (sdata->radar_required) {
1158 + rcu_read_unlock();
1162 + rcu_read_unlock();
1167 static struct ieee80211_chanctx *
1168 ieee80211_new_chanctx(struct ieee80211_local *local,
1169 const struct cfg80211_chan_def *chandef,
1170 @@ -76,6 +92,9 @@ ieee80211_new_chanctx(struct ieee80211_l
1171 ctx->conf.rx_chains_static = 1;
1172 ctx->conf.rx_chains_dynamic = 1;
1174 + ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
1175 + if (!local->use_chanctx)
1176 + local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
1178 /* acquire mutex to prevent idle from changing */
1179 mutex_lock(&local->mtx);
1180 @@ -110,6 +129,7 @@ ieee80211_new_chanctx(struct ieee80211_l
1181 static void ieee80211_free_chanctx(struct ieee80211_local *local,
1182 struct ieee80211_chanctx *ctx)
1184 + bool check_single_channel = false;
1185 lockdep_assert_held(&local->chanctx_mtx);
1187 WARN_ON_ONCE(ctx->refcount != 0);
1188 @@ -119,6 +139,14 @@ static void ieee80211_free_chanctx(struc
1189 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1190 chandef->center_freq1 = chandef->chan->center_freq;
1191 chandef->center_freq2 = 0;
1193 + /* NOTE: Disabling radar is only valid here for
1194 + * single channel context. To be sure, check it ...
1196 + if (local->hw.conf.radar_enabled)
1197 + check_single_channel = true;
1198 + local->hw.conf.radar_enabled = false;
1200 ieee80211_hw_config(local, 0);
1202 drv_remove_chanctx(local, ctx);
1203 @@ -127,6 +155,9 @@ static void ieee80211_free_chanctx(struc
1204 list_del_rcu(&ctx->list);
1205 kfree_rcu(ctx, rcu_head);
1207 + /* throw a warning if this wasn't the only channel context. */
1208 + WARN_ON(check_single_channel && !list_empty(&local->chanctx_list));
1210 mutex_lock(&local->mtx);
1211 ieee80211_recalc_idle(local);
1212 mutex_unlock(&local->mtx);
1213 @@ -238,19 +269,11 @@ static void __ieee80211_vif_release_chan
1214 void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
1215 struct ieee80211_chanctx *chanctx)
1217 - struct ieee80211_sub_if_data *sdata;
1218 - bool radar_enabled = false;
1219 + bool radar_enabled;
1221 lockdep_assert_held(&local->chanctx_mtx);
1224 - list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1225 - if (sdata->radar_required) {
1226 - radar_enabled = true;
1230 - rcu_read_unlock();
1231 + radar_enabled = ieee80211_is_radar_required(local);
1233 if (radar_enabled == chanctx->conf.radar_enabled)
1235 --- a/net/mac80211/debugfs_sta.c
1236 +++ b/net/mac80211/debugfs_sta.c
1237 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
1238 test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
1240 int res = scnprintf(buf, sizeof(buf),
1241 - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1242 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1243 TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
1244 TEST(PS_DRIVER), TEST(AUTHORIZED),
1245 TEST(SHORT_PREAMBLE),
1246 - TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
1247 + TEST(WME), TEST(CLEAR_PS_FILT),
1248 TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
1249 TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
1250 TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
1251 --- a/net/mac80211/ibss.c
1252 +++ b/net/mac80211/ibss.c
1253 @@ -209,6 +209,8 @@ static void __ieee80211_sta_join_ibss(st
1254 sdata->vif.bss_conf.enable_beacon = true;
1255 sdata->vif.bss_conf.beacon_int = beacon_int;
1256 sdata->vif.bss_conf.basic_rates = basic_rates;
1257 + sdata->vif.bss_conf.ssid_len = ifibss->ssid_len;
1258 + memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len);
1259 bss_change = BSS_CHANGED_BEACON_INT;
1260 bss_change |= ieee80211_reset_erp_info(sdata);
1261 bss_change |= BSS_CHANGED_BSSID;
1262 @@ -217,6 +219,7 @@ static void __ieee80211_sta_join_ibss(st
1263 bss_change |= BSS_CHANGED_BASIC_RATES;
1264 bss_change |= BSS_CHANGED_HT;
1265 bss_change |= BSS_CHANGED_IBSS;
1266 + bss_change |= BSS_CHANGED_SSID;
1269 * In 5 GHz/802.11a, we can always use short slot time.
1270 @@ -911,7 +914,7 @@ void ieee80211_rx_mgmt_probe_beacon(stru
1273 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1277 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1279 @@ -1159,6 +1162,7 @@ int ieee80211_ibss_leave(struct ieee8021
1280 sdata->vif.bss_conf.ibss_joined = false;
1281 sdata->vif.bss_conf.ibss_creator = false;
1282 sdata->vif.bss_conf.enable_beacon = false;
1283 + sdata->vif.bss_conf.ssid_len = 0;
1284 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1285 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1287 --- a/net/mac80211/ieee80211_i.h
1288 +++ b/net/mac80211/ieee80211_i.h
1289 @@ -156,6 +156,7 @@ struct ieee80211_tx_data {
1290 struct ieee80211_sub_if_data *sdata;
1291 struct sta_info *sta;
1292 struct ieee80211_key *key;
1293 + struct ieee80211_tx_rate rate;
1297 @@ -740,6 +741,8 @@ struct ieee80211_sub_if_data {
1299 /* bitmap of allowed (non-MCS) rate indexes for rate control */
1300 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
1302 + bool rc_has_mcs_mask[IEEE80211_NUM_BANDS];
1303 u8 rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN];
1306 @@ -1025,7 +1028,7 @@ struct ieee80211_local {
1307 enum mac80211_scan_state next_scan_state;
1308 struct delayed_work scan_work;
1309 struct ieee80211_sub_if_data __rcu *scan_sdata;
1310 - struct ieee80211_channel *csa_channel;
1311 + struct cfg80211_chan_def csa_chandef;
1312 /* For backward compatibility only -- do not use */
1313 struct cfg80211_chan_def _oper_chandef;
1315 @@ -1184,10 +1187,13 @@ struct ieee802_11_elems {
1317 const struct ieee80211_rann_ie *rann;
1318 const struct ieee80211_channel_sw_ie *ch_switch_ie;
1319 + const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1320 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1321 const u8 *country_elem;
1322 const u8 *pwr_constr_elem;
1323 const struct ieee80211_timeout_interval_ie *timeout_int;
1324 const u8 *opmode_notif;
1325 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1327 /* length of them, respectively */
1329 @@ -1258,10 +1264,6 @@ void ieee80211_recalc_ps_vif(struct ieee
1330 int ieee80211_max_network_latency(struct notifier_block *nb,
1331 unsigned long data, void *dummy);
1332 int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1334 -ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1335 - const struct ieee80211_channel_sw_ie *sw_elem,
1336 - struct ieee80211_bss *bss, u64 timestamp);
1337 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1338 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1339 struct sk_buff *skb);
1340 @@ -1499,13 +1501,13 @@ static inline void ieee80211_tx_skb(stru
1341 ieee80211_tx_skb_tid(sdata, skb, 7);
1344 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1345 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
1346 struct ieee802_11_elems *elems,
1347 u64 filter, u32 crc);
1348 -static inline void ieee802_11_parse_elems(u8 *start, size_t len,
1349 +static inline void ieee802_11_parse_elems(u8 *start, size_t len, bool action,
1350 struct ieee802_11_elems *elems)
1352 - ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
1353 + ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0);
1356 u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1357 --- a/net/mac80211/iface.c
1358 +++ b/net/mac80211/iface.c
1359 @@ -159,7 +159,8 @@ static int ieee80211_change_mtu(struct n
1363 -static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)
1364 +static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr,
1367 struct ieee80211_sub_if_data *sdata;
1369 @@ -179,10 +180,13 @@ static int ieee80211_verify_mac(struct i
1370 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
1371 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
1376 mutex_lock(&local->iflist_mtx);
1377 list_for_each_entry(sdata, &local->interfaces, list) {
1378 - if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1379 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1380 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1383 m = sdata->vif.addr;
1384 @@ -204,12 +208,17 @@ static int ieee80211_change_mac(struct n
1386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1387 struct sockaddr *sa = addr;
1388 + bool check_dup = true;
1391 if (ieee80211_sdata_running(sdata))
1394 - ret = ieee80211_verify_mac(sdata->local, sa->sa_data);
1395 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1396 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1397 + check_dup = false;
1399 + ret = ieee80211_verify_mac(sdata->local, sa->sa_data, check_dup);
1403 @@ -450,7 +459,6 @@ int ieee80211_do_open(struct wireless_de
1404 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1405 struct net_device *dev = wdev->netdev;
1406 struct ieee80211_local *local = sdata->local;
1407 - struct sta_info *sta;
1410 u32 hw_reconf_flags = 0;
1411 @@ -474,6 +482,9 @@ int ieee80211_do_open(struct wireless_de
1412 master->control_port_protocol;
1413 sdata->control_port_no_encrypt =
1414 master->control_port_no_encrypt;
1415 + sdata->vif.cab_queue = master->vif.cab_queue;
1416 + memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
1417 + sizeof(sdata->vif.hw_queue));
1420 case NL80211_IFTYPE_AP:
1421 @@ -538,7 +549,11 @@ int ieee80211_do_open(struct wireless_de
1425 - if (local->monitors == 0 && local->open_count == 0) {
1426 + if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
1427 + res = drv_add_interface(local, sdata);
1430 + } else if (local->monitors == 0 && local->open_count == 0) {
1431 res = ieee80211_add_virtual_monitor(local);
1434 @@ -609,30 +624,8 @@ int ieee80211_do_open(struct wireless_de
1436 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1438 - if (sdata->vif.type == NL80211_IFTYPE_WDS) {
1439 - /* Create STA entry for the WDS peer */
1440 - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1444 - goto err_del_interface;
1447 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1448 - sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1449 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1451 - res = sta_info_insert(sta);
1453 - /* STA has been freed */
1454 - goto err_del_interface;
1457 - rate_control_rate_init(sta);
1458 - netif_carrier_on(dev);
1459 - } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
1460 + if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
1461 rcu_assign_pointer(local->p2p_sdata, sdata);
1465 * set_multicast_list will be invoked by the networking core
1466 @@ -653,7 +646,11 @@ int ieee80211_do_open(struct wireless_de
1468 ieee80211_recalc_ps(local, -1);
1471 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1472 + sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1473 + /* XXX: for AP_VLAN, actually track AP queues */
1474 + netif_tx_start_all_queues(dev);
1476 unsigned long flags;
1477 int n_acs = IEEE80211_NUM_ACS;
1479 @@ -916,7 +913,11 @@ static void ieee80211_do_stop(struct iee
1480 mutex_lock(&local->mtx);
1481 ieee80211_recalc_idle(local);
1482 mutex_unlock(&local->mtx);
1485 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1488 + /* fall through */
1491 drv_remove_interface(local, sdata);
1492 @@ -1075,7 +1076,7 @@ static const struct net_device_ops ieee8
1493 .ndo_start_xmit = ieee80211_monitor_start_xmit,
1494 .ndo_set_rx_mode = ieee80211_set_multicast_list,
1495 .ndo_change_mtu = ieee80211_change_mtu,
1496 - .ndo_set_mac_address = eth_mac_addr,
1497 + .ndo_set_mac_address = ieee80211_change_mac,
1498 .ndo_select_queue = ieee80211_monitor_select_queue,
1501 @@ -1092,6 +1093,74 @@ static void ieee80211_if_setup(struct ne
1502 dev->destructor = free_netdev;
1505 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1506 + struct sk_buff *skb)
1508 + struct ieee80211_local *local = sdata->local;
1509 + struct ieee80211_rx_status *rx_status;
1510 + struct ieee802_11_elems elems;
1511 + struct ieee80211_mgmt *mgmt;
1512 + struct sta_info *sta;
1517 + enum ieee80211_band band;
1518 + struct ieee80211_supported_band *sband;
1520 + rx_status = IEEE80211_SKB_RXCB(skb);
1521 + band = rx_status->band;
1522 + sband = local->hw.wiphy->bands[band];
1523 + mgmt = (struct ieee80211_mgmt *) skb->data;
1524 + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1526 + if (stype != IEEE80211_STYPE_BEACON)
1529 + baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1530 + if (baselen > skb->len)
1533 + ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1534 + skb->len - baselen, false, &elems);
1536 + rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
1540 + sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
1543 + rcu_read_unlock();
1544 + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1552 + sta->last_rx = jiffies;
1553 + sta->sta.supp_rates[band] = rates;
1555 + if (elems.ht_cap_elem)
1556 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1557 + elems.ht_cap_elem, sta);
1559 + if (elems.wmm_param)
1560 + set_sta_flag(sta, WLAN_STA_WME);
1563 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1564 + sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1565 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1566 + rate_control_rate_init(sta);
1567 + sta_info_insert_rcu(sta);
1570 + rcu_read_unlock();
1573 static void ieee80211_iface_work(struct work_struct *work)
1575 struct ieee80211_sub_if_data *sdata =
1576 @@ -1196,6 +1265,9 @@ static void ieee80211_iface_work(struct
1578 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1580 + case NL80211_IFTYPE_WDS:
1581 + ieee80211_wds_rx_queued_mgmt(sdata, skb);
1584 WARN(1, "frame for unexpected interface type");
1586 @@ -1718,6 +1790,15 @@ void ieee80211_remove_interfaces(struct
1591 + * Close all AP_VLAN interfaces first, as otherwise they
1592 + * might be closed while the AP interface they belong to
1593 + * is closed, causing unregister_netdevice_many() to crash.
1595 + list_for_each_entry(sdata, &local->interfaces, list)
1596 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1597 + dev_close(sdata->dev);
1599 mutex_lock(&local->iflist_mtx);
1600 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1601 list_del(&sdata->list);
1602 --- a/net/mac80211/main.c
1603 +++ b/net/mac80211/main.c
1604 @@ -674,6 +674,7 @@ int ieee80211_register_hw(struct ieee802
1605 int channels, max_bitrates;
1606 bool supp_ht, supp_vht;
1607 netdev_features_t feature_whitelist;
1608 + struct cfg80211_chan_def dflt_chandef = {};
1609 static const u32 cipher_suites[] = {
1610 /* keep WEP first, it may be removed below */
1611 WLAN_CIPHER_SUITE_WEP40,
1612 @@ -751,19 +752,19 @@ int ieee80211_register_hw(struct ieee802
1613 sband = local->hw.wiphy->bands[band];
1616 - if (!local->use_chanctx && !local->_oper_chandef.chan) {
1618 + if (!dflt_chandef.chan) {
1619 + cfg80211_chandef_create(&dflt_chandef,
1620 + &sband->channels[0],
1621 + NL80211_CHAN_NO_HT);
1622 /* init channel we're on */
1623 - struct cfg80211_chan_def chandef = {
1624 - .chan = &sband->channels[0],
1625 - .width = NL80211_CHAN_NO_HT,
1626 - .center_freq1 = sband->channels[0].center_freq,
1629 - local->hw.conf.chandef = local->_oper_chandef = chandef;
1630 + if (!local->use_chanctx && !local->_oper_chandef.chan) {
1631 + local->hw.conf.chandef = dflt_chandef;
1632 + local->_oper_chandef = dflt_chandef;
1634 + local->monitor_chandef = dflt_chandef;
1636 - cfg80211_chandef_create(&local->monitor_chandef,
1637 - &sband->channels[0],
1638 - NL80211_CHAN_NO_HT);
1640 channels += sband->n_channels;
1642 if (max_bitrates < sband->n_bitrates)
1643 --- a/net/mac80211/mesh.c
1644 +++ b/net/mac80211/mesh.c
1645 @@ -838,7 +838,7 @@ ieee80211_mesh_rx_probe_req(struct ieee8
1649 - ieee802_11_parse_elems(pos, len - baselen, &elems);
1650 + ieee802_11_parse_elems(pos, len - baselen, false, &elems);
1652 /* 802.11-2012 10.1.4.3.2 */
1653 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
1654 @@ -899,7 +899,7 @@ static void ieee80211_mesh_rx_bcn_presp(
1657 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1661 /* ignore non-mesh or secure / unsecure mismatch */
1662 if ((!elems.mesh_id || !elems.mesh_config) ||
1663 --- a/net/mac80211/mesh_hwmp.c
1664 +++ b/net/mac80211/mesh_hwmp.c
1665 @@ -880,7 +880,7 @@ void mesh_rx_path_sel_frame(struct ieee8
1667 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
1668 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
1669 - len - baselen, &elems);
1670 + len - baselen, false, &elems);
1673 if (elems.preq_len != 37)
1674 --- a/net/mac80211/mesh_plink.c
1675 +++ b/net/mac80211/mesh_plink.c
1676 @@ -544,8 +544,8 @@ static void mesh_plink_timer(unsigned lo
1680 - "Mesh plink timer for %pM fired on state %d\n",
1681 - sta->sta.addr, sta->plink_state);
1682 + "Mesh plink timer for %pM fired on state %s\n",
1683 + sta->sta.addr, mplstates[sta->plink_state]);
1687 @@ -687,7 +687,7 @@ void mesh_rx_plink_frame(struct ieee8021
1691 - ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
1692 + ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1694 if (!elems.peering) {
1696 --- a/net/mac80211/mlme.c
1697 +++ b/net/mac80211/mlme.c
1698 @@ -289,6 +289,8 @@ ieee80211_determine_chantype(struct ieee
1700 /* 40 MHz (and 80 MHz) must be supported for VHT */
1701 ret = IEEE80211_STA_DISABLE_VHT;
1702 + /* also mark 40 MHz disabled */
1703 + ret |= IEEE80211_STA_DISABLE_40MHZ;
1707 @@ -303,12 +305,6 @@ ieee80211_determine_chantype(struct ieee
1709 vht_chandef.center_freq2 = 0;
1711 - if (vht_oper->center_freq_seg2_idx)
1712 - vht_chandef.center_freq2 =
1713 - ieee80211_channel_to_frequency(
1714 - vht_oper->center_freq_seg2_idx,
1717 switch (vht_oper->chan_width) {
1718 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1719 vht_chandef.width = chandef->width;
1720 @@ -321,6 +317,10 @@ ieee80211_determine_chantype(struct ieee
1722 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1723 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1724 + vht_chandef.center_freq2 =
1725 + ieee80211_channel_to_frequency(
1726 + vht_oper->center_freq_seg2_idx,
1731 @@ -604,7 +604,6 @@ static void ieee80211_add_vht_ie(struct
1734 struct ieee80211_sta_vht_cap vht_cap;
1737 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
1739 @@ -632,37 +631,6 @@ static void ieee80211_add_vht_ie(struct
1740 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
1741 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1743 - if (!(ap_vht_cap->vht_cap_info &
1744 - cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
1745 - cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
1746 - IEEE80211_VHT_CAP_RXSTBC_3 |
1747 - IEEE80211_VHT_CAP_RXSTBC_4);
1749 - for (i = 0; i < 8; i++) {
1750 - int shift = i * 2;
1751 - u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
1752 - u16 ap_mcs, our_mcs;
1754 - ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
1756 - our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
1759 - if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
1764 - if (our_mcs <= ap_mcs)
1766 - /* fall through */
1767 - case IEEE80211_VHT_MCS_NOT_SUPPORTED:
1768 - vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
1769 - vht_cap.vht_mcs.rx_mcs_map |=
1770 - cpu_to_le16(ap_mcs << shift);
1774 /* reserve and fill IE */
1775 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
1776 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
1777 @@ -998,16 +966,7 @@ static void ieee80211_chswitch_work(stru
1778 if (!ifmgd->associated)
1782 - * FIXME: Here we are downgrading to NL80211_CHAN_WIDTH_20_NOHT
1783 - * and don't adjust our ht/vht settings
1784 - * This is wrong - we should behave according to the CSA params
1786 - local->_oper_chandef.chan = local->csa_channel;
1787 - local->_oper_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
1788 - local->_oper_chandef.center_freq1 =
1789 - local->_oper_chandef.chan->center_freq;
1790 - local->_oper_chandef.center_freq2 = 0;
1791 + local->_oper_chandef = local->csa_chandef;
1793 if (!local->ops->channel_switch) {
1794 /* call "hw_config" only if doing sw channel switch */
1795 @@ -1054,56 +1013,208 @@ static void ieee80211_chswitch_timer(uns
1796 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1801 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1802 - const struct ieee80211_channel_sw_ie *sw_elem,
1803 - struct ieee80211_bss *bss, u64 timestamp)
1804 + u64 timestamp, struct ieee802_11_elems *elems,
1807 - struct cfg80211_bss *cbss =
1808 - container_of((void *)bss, struct cfg80211_bss, priv);
1809 - struct ieee80211_channel *new_ch;
1810 + struct ieee80211_local *local = sdata->local;
1811 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1812 - int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
1813 - cbss->channel->band);
1814 + struct cfg80211_bss *cbss = ifmgd->associated;
1815 + struct ieee80211_bss *bss;
1816 struct ieee80211_chanctx *chanctx;
1817 + enum ieee80211_band new_band;
1822 + struct ieee80211_channel *new_chan;
1823 + struct cfg80211_chan_def new_chandef = {};
1824 + struct cfg80211_chan_def new_vht_chandef = {};
1825 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1826 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1827 + const struct ieee80211_ht_operation *ht_oper;
1828 + int secondary_channel_offset = -1;
1830 ASSERT_MGD_MTX(ifmgd);
1832 - if (!ifmgd->associated)
1836 + if (local->scanning)
1839 - if (sdata->local->scanning)
1840 + /* disregard subsequent announcements if we are already processing */
1841 + if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1844 - /* Disregard subsequent beacons if we are already running a timer
1845 - processing a CSA */
1846 + sec_chan_offs = elems->sec_chan_offs;
1847 + wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
1848 + ht_oper = elems->ht_operation;
1850 + if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1851 + IEEE80211_STA_DISABLE_40MHZ)) {
1852 + sec_chan_offs = NULL;
1853 + wide_bw_chansw_ie = NULL;
1854 + /* only used for bandwidth here */
1858 - if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1859 + if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1860 + wide_bw_chansw_ie = NULL;
1862 + if (elems->ext_chansw_ie) {
1863 + if (!ieee80211_operating_class_to_band(
1864 + elems->ext_chansw_ie->new_operating_class,
1867 + "cannot understand ECSA IE operating class %d, disconnecting\n",
1868 + elems->ext_chansw_ie->new_operating_class);
1869 + ieee80211_queue_work(&local->hw,
1870 + &ifmgd->csa_connection_drop_work);
1872 + new_chan_no = elems->ext_chansw_ie->new_ch_num;
1873 + count = elems->ext_chansw_ie->count;
1874 + mode = elems->ext_chansw_ie->mode;
1875 + } else if (elems->ch_switch_ie) {
1876 + new_band = cbss->channel->band;
1877 + new_chan_no = elems->ch_switch_ie->new_ch_num;
1878 + count = elems->ch_switch_ie->count;
1879 + mode = elems->ch_switch_ie->mode;
1881 + /* nothing here we understand */
1885 + bss = (void *)cbss->priv;
1887 - new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1888 - if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
1889 + new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
1890 + new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1891 + if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
1893 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1894 ifmgd->associated->bssid, new_freq);
1895 - ieee80211_queue_work(&sdata->local->hw,
1896 + ieee80211_queue_work(&local->hw,
1897 + &ifmgd->csa_connection_drop_work);
1901 + if (!beacon && sec_chan_offs) {
1902 + secondary_channel_offset = sec_chan_offs->sec_chan_offs;
1903 + } else if (beacon && ht_oper) {
1904 + secondary_channel_offset =
1905 + ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
1906 + } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
1908 + * If it's not a beacon, HT is enabled and the IE not present,
1909 + * it's 20 MHz, 802.11-2012 8.5.2.6:
1910 + * This element [the Secondary Channel Offset Element] is
1911 + * present when switching to a 40 MHz channel. It may be
1912 + * present when switching to a 20 MHz channel (in which
1913 + * case the secondary channel offset is set to SCN).
1915 + secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1918 + switch (secondary_channel_offset) {
1920 + /* secondary_channel_offset was present but is invalid */
1921 + case IEEE80211_HT_PARAM_CHA_SEC_NONE:
1922 + cfg80211_chandef_create(&new_chandef, new_chan,
1923 + NL80211_CHAN_HT20);
1925 + case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1926 + cfg80211_chandef_create(&new_chandef, new_chan,
1927 + NL80211_CHAN_HT40PLUS);
1929 + case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1930 + cfg80211_chandef_create(&new_chandef, new_chan,
1931 + NL80211_CHAN_HT40MINUS);
1934 + cfg80211_chandef_create(&new_chandef, new_chan,
1935 + NL80211_CHAN_NO_HT);
1939 + if (wide_bw_chansw_ie) {
1940 + new_vht_chandef.chan = new_chan;
1941 + new_vht_chandef.center_freq1 =
1942 + ieee80211_channel_to_frequency(
1943 + wide_bw_chansw_ie->new_center_freq_seg0,
1946 + switch (wide_bw_chansw_ie->new_channel_width) {
1948 + /* hmmm, ignore VHT and use HT if present */
1949 + case IEEE80211_VHT_CHANWIDTH_USE_HT:
1950 + new_vht_chandef.chan = NULL;
1952 + case IEEE80211_VHT_CHANWIDTH_80MHZ:
1953 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1955 + case IEEE80211_VHT_CHANWIDTH_160MHZ:
1956 + new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1958 + case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1959 + /* field is otherwise reserved */
1960 + new_vht_chandef.center_freq2 =
1961 + ieee80211_channel_to_frequency(
1962 + wide_bw_chansw_ie->new_center_freq_seg1,
1964 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1967 + if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1968 + new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1969 + chandef_downgrade(&new_vht_chandef);
1970 + if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1971 + new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1972 + chandef_downgrade(&new_vht_chandef);
1973 + if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
1974 + new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
1975 + chandef_downgrade(&new_vht_chandef);
1978 + /* if VHT data is there validate & use it */
1979 + if (new_vht_chandef.chan) {
1980 + if (!cfg80211_chandef_compatible(&new_vht_chandef,
1983 + "AP %pM CSA has inconsistent channel data, disconnecting\n",
1984 + ifmgd->associated->bssid);
1985 + ieee80211_queue_work(&local->hw,
1986 + &ifmgd->csa_connection_drop_work);
1989 + new_chandef = new_vht_chandef;
1992 + if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
1993 + IEEE80211_CHAN_DISABLED)) {
1995 + "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
1996 + ifmgd->associated->bssid, new_freq,
1997 + new_chandef.width, new_chandef.center_freq1,
1998 + new_chandef.center_freq2);
1999 + ieee80211_queue_work(&local->hw,
2000 &ifmgd->csa_connection_drop_work);
2004 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
2006 - if (sdata->local->use_chanctx) {
2007 + if (local->use_chanctx) {
2009 "not handling channel switch with channel contexts\n");
2010 - ieee80211_queue_work(&sdata->local->hw,
2011 + ieee80211_queue_work(&local->hw,
2012 &ifmgd->csa_connection_drop_work);
2016 - mutex_lock(&sdata->local->chanctx_mtx);
2017 + mutex_lock(&local->chanctx_mtx);
2018 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
2019 - mutex_unlock(&sdata->local->chanctx_mtx);
2020 + mutex_unlock(&local->chanctx_mtx);
2023 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
2024 @@ -1111,40 +1222,39 @@ ieee80211_sta_process_chanswitch(struct
2025 if (chanctx->refcount > 1) {
2027 "channel switch with multiple interfaces on the same channel, disconnecting\n");
2028 - ieee80211_queue_work(&sdata->local->hw,
2029 + ieee80211_queue_work(&local->hw,
2030 &ifmgd->csa_connection_drop_work);
2031 - mutex_unlock(&sdata->local->chanctx_mtx);
2032 + mutex_unlock(&local->chanctx_mtx);
2035 - mutex_unlock(&sdata->local->chanctx_mtx);
2036 + mutex_unlock(&local->chanctx_mtx);
2038 - sdata->local->csa_channel = new_ch;
2039 + local->csa_chandef = new_chandef;
2041 - if (sw_elem->mode)
2042 - ieee80211_stop_queues_by_reason(&sdata->local->hw,
2044 + ieee80211_stop_queues_by_reason(&local->hw,
2045 IEEE80211_MAX_QUEUE_MAP,
2046 IEEE80211_QUEUE_STOP_REASON_CSA);
2048 - if (sdata->local->ops->channel_switch) {
2049 + if (local->ops->channel_switch) {
2050 /* use driver's channel switch callback */
2051 struct ieee80211_channel_switch ch_switch = {
2052 .timestamp = timestamp,
2053 - .block_tx = sw_elem->mode,
2054 - .channel = new_ch,
2055 - .count = sw_elem->count,
2057 + .chandef = new_chandef,
2061 - drv_channel_switch(sdata->local, &ch_switch);
2062 + drv_channel_switch(local, &ch_switch);
2066 /* channel switch handled in software */
2067 - if (sw_elem->count <= 1)
2068 - ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
2070 + ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
2072 mod_timer(&ifmgd->chswitch_timer,
2073 - TU_TO_EXP_TIME(sw_elem->count *
2074 - cbss->beacon_interval));
2075 + TU_TO_EXP_TIME(count * cbss->beacon_interval));
2078 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
2079 @@ -2120,7 +2230,6 @@ void ieee80211_beacon_loss(struct ieee80
2081 trace_api_beacon_loss(sdata);
2083 - WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
2084 sdata->u.mgd.connection_loss = false;
2085 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2087 @@ -2170,7 +2279,7 @@ static void ieee80211_auth_challenge(str
2090 pos = mgmt->u.auth.variable;
2091 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2092 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2093 if (!elems.challenge)
2095 auth_data->expected_transaction = 4;
2096 @@ -2435,7 +2544,7 @@ static bool ieee80211_assoc_success(stru
2099 pos = mgmt->u.assoc_resp.variable;
2100 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2101 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2103 if (!elems.supp_rates) {
2104 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2105 @@ -2604,7 +2713,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
2106 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2108 pos = mgmt->u.assoc_resp.variable;
2109 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2110 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2112 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2113 elems.timeout_int &&
2114 @@ -2659,6 +2768,8 @@ static void ieee80211_rx_bss_info(struct
2115 struct ieee80211_channel *channel;
2116 bool need_ps = false;
2118 + lockdep_assert_held(&sdata->u.mgd.mtx);
2120 if ((sdata->u.mgd.associated &&
2121 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2122 (sdata->u.mgd.assoc_data &&
2123 @@ -2689,7 +2800,8 @@ static void ieee80211_rx_bss_info(struct
2125 ieee80211_rx_bss_put(local, bss);
2127 - if (!sdata->u.mgd.associated)
2128 + if (!sdata->u.mgd.associated ||
2129 + !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
2133 @@ -2698,10 +2810,9 @@ static void ieee80211_rx_bss_info(struct
2134 mutex_unlock(&local->iflist_mtx);
2137 - if (elems->ch_switch_ie &&
2138 - memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2139 - ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
2140 - bss, rx_status->mactime);
2141 + ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2147 @@ -2726,7 +2837,7 @@ static void ieee80211_rx_mgmt_probe_resp
2150 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2154 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2156 @@ -2809,7 +2920,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2157 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
2158 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2159 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2160 - len - baselen, &elems);
2161 + len - baselen, false, &elems);
2163 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2164 ifmgd->assoc_data->have_beacon = true;
2165 @@ -2919,7 +3030,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2167 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2168 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2169 - len - baselen, &elems,
2170 + len - baselen, false, &elems,
2171 care_about_ies, ncrc);
2173 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
2174 @@ -3066,6 +3177,8 @@ void ieee80211_sta_rx_queued_mgmt(struct
2175 enum rx_mgmt_action rma = RX_MGMT_NONE;
2176 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
2178 + struct ieee802_11_elems elems;
2181 rx_status = (struct ieee80211_rx_status *) skb->cb;
2182 mgmt = (struct ieee80211_mgmt *) skb->data;
2183 @@ -3095,14 +3208,48 @@ void ieee80211_sta_rx_queued_mgmt(struct
2184 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2186 case IEEE80211_STYPE_ACTION:
2187 - switch (mgmt->u.action.category) {
2188 - case WLAN_CATEGORY_SPECTRUM_MGMT:
2189 + if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
2190 + ies_len = skb->len -
2191 + offsetof(struct ieee80211_mgmt,
2192 + u.action.u.chan_switch.variable);
2197 + ieee802_11_parse_elems(
2198 + mgmt->u.action.u.chan_switch.variable,
2199 + ies_len, true, &elems);
2201 + if (elems.parse_error)
2204 ieee80211_sta_process_chanswitch(sdata,
2205 - &mgmt->u.action.u.chan_switch.sw_elem,
2206 - (void *)ifmgd->associated->priv,
2207 - rx_status->mactime);
2209 + rx_status->mactime,
2211 + } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
2212 + ies_len = skb->len -
2213 + offsetof(struct ieee80211_mgmt,
2214 + u.action.u.ext_chan_switch.variable);
2219 + ieee802_11_parse_elems(
2220 + mgmt->u.action.u.ext_chan_switch.variable,
2221 + ies_len, true, &elems);
2223 + if (elems.parse_error)
2226 + /* for the handling code pretend this was also an IE */
2227 + elems.ext_chansw_ie =
2228 + &mgmt->u.action.u.ext_chan_switch.data;
2230 + ieee80211_sta_process_chanswitch(sdata,
2231 + rx_status->mactime,
2236 mutex_unlock(&ifmgd->mtx);
2238 @@ -4197,7 +4344,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2239 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2240 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2241 bool tx = !req->local_state_change;
2242 - bool sent_frame = false;
2243 + bool report_frame = false;
2245 mutex_lock(&ifmgd->mtx);
2247 @@ -4214,7 +4361,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2248 ieee80211_destroy_auth_data(sdata, false);
2249 mutex_unlock(&ifmgd->mtx);
2252 + report_frame = true;
2256 @@ -4222,12 +4369,12 @@ int ieee80211_mgd_deauth(struct ieee8021
2257 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
2258 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2259 req->reason_code, tx, frame_buf);
2261 + report_frame = true;
2263 mutex_unlock(&ifmgd->mtx);
2268 __cfg80211_send_deauth(sdata->dev, frame_buf,
2269 IEEE80211_DEAUTH_FRAME_LEN);
2271 --- a/net/mac80211/pm.c
2272 +++ b/net/mac80211/pm.c
2273 @@ -38,8 +38,8 @@ int __ieee80211_suspend(struct ieee80211
2274 IEEE80211_MAX_QUEUE_MAP,
2275 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
2277 - /* flush out all packets */
2278 - synchronize_net();
2279 + /* flush out all packets and station cleanup call_rcu()s */
2282 ieee80211_flush_queues(local, NULL);
2284 --- a/net/mac80211/rate.c
2285 +++ b/net/mac80211/rate.c
2286 @@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee802
2290 +static void __rate_control_send_low(struct ieee80211_hw *hw,
2291 + struct ieee80211_supported_band *sband,
2292 + struct ieee80211_sta *sta,
2293 + struct ieee80211_tx_info *info)
2295 + if ((sband->band != IEEE80211_BAND_2GHZ) ||
2296 + !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2297 + info->control.rates[0].idx = rate_lowest_index(sband, sta);
2299 + info->control.rates[0].idx =
2300 + rate_lowest_non_cck_index(sband, sta);
2302 + info->control.rates[0].count =
2303 + (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2304 + 1 : hw->max_rate_tries;
2306 + info->control.skip_table = 1;
2310 bool rate_control_send_low(struct ieee80211_sta *sta,
2312 @@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80
2315 if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
2316 - if ((sband->band != IEEE80211_BAND_2GHZ) ||
2317 - !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2318 - info->control.rates[0].idx =
2319 - rate_lowest_index(txrc->sband, sta);
2321 - info->control.rates[0].idx =
2322 - rate_lowest_non_cck_index(txrc->sband, sta);
2323 - info->control.rates[0].count =
2324 - (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2325 - 1 : txrc->hw->max_rate_tries;
2326 + __rate_control_send_low(txrc->hw, sband, sta, info);
2328 if (!sta && txrc->bss) {
2329 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
2330 if (mcast_rate > 0) {
2331 @@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(stru
2334 static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
2335 - struct ieee80211_tx_rate_control *txrc,
2336 + struct ieee80211_supported_band *sband,
2337 + enum nl80211_chan_width chan_width,
2339 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2341 @@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct i
2342 IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
2343 alt_rate.count = rate->count;
2344 if (rate_idx_match_legacy_mask(&alt_rate,
2345 - txrc->sband->n_bitrates,
2347 + sband->n_bitrates, mask)) {
2352 - struct sk_buff *skb = txrc->skb;
2353 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2356 /* handle legacy rates */
2357 - if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates,
2359 + if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask))
2362 /* if HT BSS, and we handle a data frame, also try HT rates */
2363 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2366 - fc = hdr->frame_control;
2367 - if (!ieee80211_is_data(fc))
2368 + if (chan_width == NL80211_CHAN_WIDTH_20_NOHT)
2372 @@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct i
2374 alt_rate.flags |= IEEE80211_TX_RC_MCS;
2376 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40)
2377 + if (chan_width == NL80211_CHAN_WIDTH_40)
2378 alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2380 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) {
2381 @@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct i
2385 +static void rate_fixup_ratelist(struct ieee80211_vif *vif,
2386 + struct ieee80211_supported_band *sband,
2387 + struct ieee80211_tx_info *info,
2388 + struct ieee80211_tx_rate *rates,
2391 + struct ieee80211_rate *rate;
2392 + bool inval = false;
2396 + * Set up the RTS/CTS rate as the fastest basic rate
2397 + * that is not faster than the data rate unless there
2398 + * is no basic rate slower than the data rate, in which
2399 + * case we pick the slowest basic rate
2401 + * XXX: Should this check all retry rates?
2403 + if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
2404 + u32 basic_rates = vif->bss_conf.basic_rates;
2405 + s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
2407 + rate = &sband->bitrates[rates[0].idx];
2409 + for (i = 0; i < sband->n_bitrates; i++) {
2410 + /* must be a basic rate */
2411 + if (!(basic_rates & BIT(i)))
2413 + /* must not be faster than the data rate */
2414 + if (sband->bitrates[i].bitrate > rate->bitrate)
2417 + if (sband->bitrates[baserate].bitrate <
2418 + sband->bitrates[i].bitrate)
2422 + info->control.rts_cts_rate_idx = baserate;
2425 + for (i = 0; i < max_rates; i++) {
2427 + * make sure there's no valid rate following
2428 + * an invalid one, just in case drivers don't
2429 + * take the API seriously to stop at -1.
2432 + rates[i].idx = -1;
2435 + if (rates[i].idx < 0) {
2441 + * For now assume MCS is already set up correctly, this
2442 + * needs to be fixed.
2444 + if (rates[i].flags & IEEE80211_TX_RC_MCS) {
2445 + WARN_ON(rates[i].idx > 76);
2447 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2448 + info->control.use_cts_prot)
2450 + IEEE80211_TX_RC_USE_CTS_PROTECT;
2454 + if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) {
2455 + WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9);
2459 + /* set up RTS protection if desired */
2460 + if (info->control.use_rts) {
2461 + rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2462 + info->control.use_cts_prot = false;
2465 + /* RC is busted */
2466 + if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) {
2467 + rates[i].idx = -1;
2471 + rate = &sband->bitrates[rates[i].idx];
2473 + /* set up short preamble */
2474 + if (info->control.short_preamble &&
2475 + rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2476 + rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
2478 + /* set up G protection */
2479 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2480 + info->control.use_cts_prot &&
2481 + rate->flags & IEEE80211_RATE_ERP_G)
2482 + rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
2487 +static void rate_control_fill_sta_table(struct ieee80211_sta *sta,
2488 + struct ieee80211_tx_info *info,
2489 + struct ieee80211_tx_rate *rates,
2492 + struct ieee80211_sta_rates *ratetbl = NULL;
2495 + if (sta && !info->control.skip_table)
2496 + ratetbl = rcu_dereference(sta->rates);
2498 + /* Fill remaining rate slots with data from the sta rate table. */
2499 + max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE);
2500 + for (i = 0; i < max_rates; i++) {
2501 + if (i < ARRAY_SIZE(info->control.rates) &&
2502 + info->control.rates[i].idx >= 0 &&
2503 + info->control.rates[i].count) {
2504 + if (rates != info->control.rates)
2505 + rates[i] = info->control.rates[i];
2506 + } else if (ratetbl) {
2507 + rates[i].idx = ratetbl->rate[i].idx;
2508 + rates[i].flags = ratetbl->rate[i].flags;
2509 + if (info->control.use_rts)
2510 + rates[i].count = ratetbl->rate[i].count_rts;
2511 + else if (info->control.use_cts_prot)
2512 + rates[i].count = ratetbl->rate[i].count_cts;
2514 + rates[i].count = ratetbl->rate[i].count;
2516 + rates[i].idx = -1;
2517 + rates[i].count = 0;
2520 + if (rates[i].idx < 0 || !rates[i].count)
2525 +static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
2526 + struct ieee80211_sta *sta,
2527 + struct ieee80211_supported_band *sband,
2528 + struct ieee80211_tx_info *info,
2529 + struct ieee80211_tx_rate *rates,
2532 + enum nl80211_chan_width chan_width;
2533 + u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2534 + bool has_mcs_mask;
2539 + * Try to enforce the rateidx mask the user wanted. skip this if the
2540 + * default mask (allow all rates) is used to save some processing for
2541 + * the common case.
2543 + mask = sdata->rc_rateidx_mask[info->band];
2544 + has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
2545 + if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
2549 + memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2550 + sizeof(mcs_mask));
2552 + memset(mcs_mask, 0xff, sizeof(mcs_mask));
2555 + /* Filter out rates that the STA does not support */
2556 + mask &= sta->supp_rates[info->band];
2557 + for (i = 0; i < sizeof(mcs_mask); i++)
2558 + mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i];
2562 + * Make sure the rate index selected for each TX rate is
2563 + * included in the configured mask and change the rate indexes
2566 + chan_width = sdata->vif.bss_conf.chandef.width;
2567 + for (i = 0; i < max_rates; i++) {
2568 + /* Skip invalid rates */
2569 + if (rates[i].idx < 0)
2572 + rate_idx_match_mask(&rates[i], sband, chan_width, mask,
2577 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
2578 + struct ieee80211_sta *sta,
2579 + struct sk_buff *skb,
2580 + struct ieee80211_tx_rate *dest,
2583 + struct ieee80211_sub_if_data *sdata;
2584 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2585 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2586 + struct ieee80211_supported_band *sband;
2588 + rate_control_fill_sta_table(sta, info, dest, max_rates);
2593 + sdata = vif_to_sdata(vif);
2594 + sband = sdata->local->hw.wiphy->bands[info->band];
2596 + if (ieee80211_is_data(hdr->frame_control))
2597 + rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates);
2599 + if (dest[0].idx < 0)
2600 + __rate_control_send_low(&sdata->local->hw, sband, sta, info);
2603 + rate_fixup_ratelist(vif, sband, info, dest, max_rates);
2605 +EXPORT_SYMBOL(ieee80211_get_tx_rates);
2607 void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
2608 struct sta_info *sta,
2609 struct ieee80211_tx_rate_control *txrc)
2610 @@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80
2611 struct ieee80211_sta *ista = NULL;
2612 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
2615 - u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2617 if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) {
2619 @@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80
2621 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
2624 - * Try to enforce the rateidx mask the user wanted. skip this if the
2625 - * default mask (allow all rates) is used to save some processing for
2626 - * the common case.
2628 - mask = sdata->rc_rateidx_mask[info->band];
2629 - memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2630 - sizeof(mcs_mask));
2631 - if (mask != (1 << txrc->sband->n_bitrates) - 1) {
2633 - /* Filter out rates that the STA does not support */
2634 - mask &= sta->sta.supp_rates[info->band];
2635 - for (i = 0; i < sizeof(mcs_mask); i++)
2636 - mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i];
2639 - * Make sure the rate index selected for each TX rate is
2640 - * included in the configured mask and change the rate indexes
2643 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2644 - /* Skip invalid rates */
2645 - if (info->control.rates[i].idx < 0)
2647 - rate_idx_match_mask(&info->control.rates[i], txrc,
2651 + if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE)
2654 - BUG_ON(info->control.rates[0].idx < 0);
2655 + ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb,
2656 + info->control.rates,
2657 + ARRAY_SIZE(info->control.rates));
2660 +int rate_control_set_rates(struct ieee80211_hw *hw,
2661 + struct ieee80211_sta *pubsta,
2662 + struct ieee80211_sta_rates *rates)
2664 + struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates);
2666 + rcu_assign_pointer(pubsta->rates, rates);
2668 + kfree_rcu(old, rcu_head);
2672 +EXPORT_SYMBOL(rate_control_set_rates);
2674 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
2676 --- a/net/mac80211/rc80211_minstrel.c
2677 +++ b/net/mac80211/rc80211_minstrel.c
2678 @@ -84,6 +84,50 @@ minstrel_sort_best_tp_rates(struct minst
2682 +minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
2683 + int offset, int idx)
2685 + struct minstrel_rate *r = &mi->r[idx];
2687 + ratetbl->rate[offset].idx = r->rix;
2688 + ratetbl->rate[offset].count = r->adjusted_retry_count;
2689 + ratetbl->rate[offset].count_cts = r->retry_count_cts;
2690 + ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
2694 +minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2696 + struct ieee80211_sta_rates *ratetbl;
2699 + ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
2703 + /* Start with max_tp_rate */
2704 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
2706 + if (mp->hw->max_rates >= 3) {
2707 + /* At least 3 tx rates supported, use max_tp_rate2 next */
2708 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
2711 + if (mp->hw->max_rates >= 2) {
2712 + /* At least 2 tx rates supported, use max_prob_rate next */
2713 + minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
2716 + /* Use lowest rate last */
2717 + ratetbl->rate[i].idx = mi->lowest_rix;
2718 + ratetbl->rate[i].count = mp->max_retry;
2719 + ratetbl->rate[i].count_cts = mp->max_retry;
2720 + ratetbl->rate[i].count_rts = mp->max_retry;
2722 + rate_control_set_rates(mp->hw, mi->sta, ratetbl);
2726 minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2728 u8 tmp_tp_rate[MAX_THR_RATES];
2729 @@ -161,6 +205,8 @@ minstrel_update_stats(struct minstrel_pr
2731 /* Reset update timer */
2732 mi->stats_update = jiffies;
2734 + minstrel_update_rates(mp, mi);
2738 @@ -209,9 +255,9 @@ minstrel_get_retry_count(struct minstrel
2740 unsigned int retry = mr->adjusted_retry_count;
2742 - if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
2743 + if (info->control.use_rts)
2744 retry = max(2U, min(mr->retry_count_rtscts, retry));
2745 - else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
2746 + else if (info->control.use_cts_prot)
2747 retry = max(2U, min(mr->retry_count_cts, retry));
2750 @@ -240,13 +286,12 @@ minstrel_get_rate(void *priv, struct iee
2751 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2752 struct minstrel_sta_info *mi = priv_sta;
2753 struct minstrel_priv *mp = priv;
2754 - struct ieee80211_tx_rate *ar = info->control.rates;
2755 - unsigned int ndx, sample_ndx = 0;
2756 + struct ieee80211_tx_rate *rate = &info->control.rates[0];
2757 + struct minstrel_rate *msr, *mr;
2760 - bool indirect_rate_sampling = false;
2761 - bool rate_sampling = false;
2764 + bool prev_sample = mi->prev_sample;
2768 /* management/no-ack frames do not use rate control */
2769 @@ -262,107 +307,75 @@ minstrel_get_rate(void *priv, struct iee
2771 sampling_ratio = mp->lookaround_rate;
2773 - /* init rateindex [ndx] with max throughput rate */
2774 - ndx = mi->max_tp_rate[0];
2776 /* increase sum packet counter */
2779 delta = (mi->packet_count * sampling_ratio / 100) -
2780 (mi->sample_count + mi->sample_deferred / 2);
2782 - /* delta > 0: sampling required */
2783 - if ((delta > 0) && (mrr_capable || !mi->prev_sample)) {
2784 - struct minstrel_rate *msr;
2785 - if (mi->packet_count >= 10000) {
2786 - mi->sample_deferred = 0;
2787 - mi->sample_count = 0;
2788 - mi->packet_count = 0;
2789 - } else if (delta > mi->n_rates * 2) {
2790 - /* With multi-rate retry, not every planned sample
2791 - * attempt actually gets used, due to the way the retry
2792 - * chain is set up - [max_tp,sample,prob,lowest] for
2793 - * sample_rate < max_tp.
2795 - * If there's too much sampling backlog and the link
2796 - * starts getting worse, minstrel would start bursting
2797 - * out lots of sampling frames, which would result
2798 - * in a large throughput loss. */
2799 - mi->sample_count += (delta - mi->n_rates * 2);
2801 + /* delta < 0: no sampling required */
2802 + mi->prev_sample = false;
2803 + if (delta < 0 || (!mrr_capable && prev_sample))
2806 - /* get next random rate sample */
2807 - sample_ndx = minstrel_get_next_sample(mi);
2808 - msr = &mi->r[sample_ndx];
2809 - rate_sampling = true;
2811 - /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2812 - * rate sampling method should be used.
2813 - * Respect such rates that are not sampled for 20 interations.
2815 - if (mrr_capable &&
2816 - msr->perfect_tx_time > mi->r[ndx].perfect_tx_time &&
2817 - msr->sample_skipped < 20)
2818 - indirect_rate_sampling = true;
2820 - if (!indirect_rate_sampling) {
2821 - if (msr->sample_limit != 0) {
2823 - mi->sample_count++;
2824 - if (msr->sample_limit > 0)
2825 - msr->sample_limit--;
2827 - rate_sampling = false;
2829 - /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2830 - * packets that have the sampling rate deferred to the
2831 - * second MRR stage. Increase the sample counter only
2832 - * if the deferred sample rate was actually used.
2833 - * Use the sample_deferred counter to make sure that
2834 - * the sampling is not done in large bursts */
2835 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2836 - mi->sample_deferred++;
2838 + if (mi->packet_count >= 10000) {
2839 + mi->sample_deferred = 0;
2840 + mi->sample_count = 0;
2841 + mi->packet_count = 0;
2842 + } else if (delta > mi->n_rates * 2) {
2843 + /* With multi-rate retry, not every planned sample
2844 + * attempt actually gets used, due to the way the retry
2845 + * chain is set up - [max_tp,sample,prob,lowest] for
2846 + * sample_rate < max_tp.
2848 + * If there's too much sampling backlog and the link
2849 + * starts getting worse, minstrel would start bursting
2850 + * out lots of sampling frames, which would result
2851 + * in a large throughput loss. */
2852 + mi->sample_count += (delta - mi->n_rates * 2);
2855 + /* get next random rate sample */
2856 + ndx = minstrel_get_next_sample(mi);
2857 + msr = &mi->r[ndx];
2858 + mr = &mi->r[mi->max_tp_rate[0]];
2860 + /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2861 + * rate sampling method should be used.
2862 + * Respect such rates that are not sampled for 20 interations.
2864 + if (mrr_capable &&
2865 + msr->perfect_tx_time > mr->perfect_tx_time &&
2866 + msr->sample_skipped < 20) {
2867 + /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2868 + * packets that have the sampling rate deferred to the
2869 + * second MRR stage. Increase the sample counter only
2870 + * if the deferred sample rate was actually used.
2871 + * Use the sample_deferred counter to make sure that
2872 + * the sampling is not done in large bursts */
2873 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2875 + mi->sample_deferred++;
2877 + if (!msr->sample_limit != 0)
2880 + mi->sample_count++;
2881 + if (msr->sample_limit > 0)
2882 + msr->sample_limit--;
2884 - mi->prev_sample = rate_sampling;
2886 /* If we're not using MRR and the sampling rate already
2887 * has a probability of >95%, we shouldn't be attempting
2888 * to use it, as this only wastes precious airtime */
2889 - if (!mrr_capable && rate_sampling &&
2890 + if (!mrr_capable &&
2891 (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
2892 - ndx = mi->max_tp_rate[0];
2894 - /* mrr setup for 1st stage */
2895 - ar[0].idx = mi->r[ndx].rix;
2896 - ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
2898 - /* non mrr setup for 2nd stage */
2899 - if (!mrr_capable) {
2900 - if (!rate_sampling)
2901 - ar[0].count = mp->max_retry;
2902 - ar[1].idx = mi->lowest_rix;
2903 - ar[1].count = mp->max_retry;
2907 - /* mrr setup for 2nd stage */
2908 - if (rate_sampling) {
2909 - if (indirect_rate_sampling)
2910 - mrr_ndx[0] = sample_ndx;
2912 - mrr_ndx[0] = mi->max_tp_rate[0];
2914 - mrr_ndx[0] = mi->max_tp_rate[1];
2916 + mi->prev_sample = true;
2918 - /* mrr setup for 3rd & 4th stage */
2919 - mrr_ndx[1] = mi->max_prob_rate;
2921 - for (i = 1; i < 4; i++) {
2922 - ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
2923 - ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
2925 + rate->idx = mi->r[ndx].rix;
2926 + rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
2930 @@ -412,12 +425,16 @@ minstrel_rate_init(void *priv, struct ie
2931 unsigned int i, n = 0;
2932 unsigned int t_slot = 9; /* FIXME: get real slot time */
2935 mi->lowest_rix = rate_lowest_index(sband, sta);
2936 ctl_rate = &sband->bitrates[mi->lowest_rix];
2937 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
2939 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
2941 + memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
2942 + mi->max_prob_rate = 0;
2944 for (i = 0; i < sband->n_bitrates; i++) {
2945 struct minstrel_rate *mr = &mi->r[n];
2946 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
2947 @@ -460,6 +477,8 @@ minstrel_rate_init(void *priv, struct ie
2948 } while ((tx_time < mp->segment_size) &&
2949 (++mr->retry_count < mp->max_retry));
2950 mr->adjusted_retry_count = mr->retry_count;
2951 + if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
2952 + mr->retry_count_cts = mr->retry_count;
2955 for (i = n; i < sband->n_bitrates; i++) {
2956 @@ -471,6 +490,7 @@ minstrel_rate_init(void *priv, struct ie
2957 mi->stats_update = jiffies;
2959 init_sample_table(mi);
2960 + minstrel_update_rates(mp, mi);
2964 --- a/net/mac80211/rc80211_minstrel.h
2965 +++ b/net/mac80211/rc80211_minstrel.h
2967 #ifndef __RC_MINSTREL_H
2968 #define __RC_MINSTREL_H
2970 -#define EWMA_LEVEL 75 /* ewma weighting factor [%] */
2971 +#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
2972 +#define EWMA_DIV 128
2973 #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
2978 minstrel_ewma(int old, int new, int weight)
2980 - return (new * (100 - weight) + old * weight) / 100;
2981 + return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
2985 @@ -62,6 +63,8 @@ struct minstrel_rate {
2988 struct minstrel_sta_info {
2989 + struct ieee80211_sta *sta;
2991 unsigned long stats_update;
2992 unsigned int sp_ack_dur;
2993 unsigned int rate_avg;
2994 --- a/net/mac80211/rc80211_minstrel_debugfs.c
2995 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
2996 @@ -68,7 +68,7 @@ minstrel_stats_open(struct inode *inode,
2998 file->private_data = ms;
3000 - p += sprintf(p, "rate throughput ewma prob this prob "
3001 + p += sprintf(p, "rate throughput ewma prob this prob "
3002 "this succ/attempt success attempts\n");
3003 for (i = 0; i < mi->n_rates; i++) {
3004 struct minstrel_rate *mr = &mi->r[i];
3005 @@ -86,7 +86,7 @@ minstrel_stats_open(struct inode *inode,
3006 eprob = MINSTREL_TRUNC(mr->probability * 1000);
3008 p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
3009 - "%3u(%3u) %8llu %8llu\n",
3010 + " %3u(%3u) %8llu %8llu\n",
3012 eprob / 10, eprob % 10,
3013 prob / 10, prob % 10,
3014 --- a/net/mac80211/rc80211_minstrel_ht.c
3015 +++ b/net/mac80211/rc80211_minstrel_ht.c
3016 @@ -126,6 +126,9 @@ const struct mcs_group minstrel_mcs_grou
3018 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES];
3021 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
3024 * Look up an MCS group index based on mac80211 rate information
3026 @@ -244,6 +247,7 @@ minstrel_ht_update_stats(struct minstrel
3027 struct minstrel_rate_stats *mr;
3028 int cur_prob, cur_prob_tp, cur_tp, cur_tp2;
3029 int group, i, index;
3030 + bool mi_rates_valid = false;
3032 if (mi->ampdu_packets > 0) {
3033 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
3034 @@ -254,11 +258,10 @@ minstrel_ht_update_stats(struct minstrel
3036 mi->sample_slow = 0;
3037 mi->sample_count = 0;
3038 - mi->max_tp_rate = 0;
3039 - mi->max_tp_rate2 = 0;
3040 - mi->max_prob_rate = 0;
3042 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
3043 + bool mg_rates_valid = false;
3048 @@ -268,15 +271,24 @@ minstrel_ht_update_stats(struct minstrel
3052 - mg->max_tp_rate = 0;
3053 - mg->max_tp_rate2 = 0;
3054 - mg->max_prob_rate = 0;
3057 for (i = 0; i < MCS_GROUP_RATES; i++) {
3058 if (!(mg->supported & BIT(i)))
3061 + /* initialize rates selections starting indexes */
3062 + if (!mg_rates_valid) {
3063 + mg->max_tp_rate = mg->max_tp_rate2 =
3064 + mg->max_prob_rate = i;
3065 + if (!mi_rates_valid) {
3066 + mi->max_tp_rate = mi->max_tp_rate2 =
3067 + mi->max_prob_rate = i;
3068 + mi_rates_valid = true;
3070 + mg_rates_valid = true;
3074 mr->retry_updated = false;
3075 index = MCS_GROUP_RATES * group + i;
3076 @@ -456,7 +468,7 @@ minstrel_ht_tx_status(void *priv, struct
3077 struct ieee80211_tx_rate *ar = info->status.rates;
3078 struct minstrel_rate_stats *rate, *rate2;
3079 struct minstrel_priv *mp = priv;
3081 + bool last, update = false;
3085 @@ -505,21 +517,29 @@ minstrel_ht_tx_status(void *priv, struct
3086 rate = minstrel_get_ratestats(mi, mi->max_tp_rate);
3087 if (rate->attempts > 30 &&
3088 MINSTREL_FRAC(rate->success, rate->attempts) <
3089 - MINSTREL_FRAC(20, 100))
3090 + MINSTREL_FRAC(20, 100)) {
3091 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true);
3095 rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2);
3096 if (rate2->attempts > 30 &&
3097 MINSTREL_FRAC(rate2->success, rate2->attempts) <
3098 - MINSTREL_FRAC(20, 100))
3099 + MINSTREL_FRAC(20, 100)) {
3100 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false);
3104 if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) {
3106 minstrel_ht_update_stats(mp, mi);
3107 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
3108 mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
3109 minstrel_aggr_check(sta, skb);
3113 + minstrel_ht_update_rates(mp, mi);
3117 @@ -580,39 +600,73 @@ minstrel_calc_retransmit(struct minstrel
3118 (++mr->retry_count < mp->max_retry));
3123 minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
3124 - struct ieee80211_tx_rate *rate, int index,
3125 - bool sample, bool rtscts)
3126 + struct ieee80211_sta_rates *ratetbl, int offset, int index)
3128 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
3129 struct minstrel_rate_stats *mr;
3133 mr = minstrel_get_ratestats(mi, index);
3134 if (!mr->retry_updated)
3135 minstrel_calc_retransmit(mp, mi, index);
3139 - else if (mr->probability < MINSTREL_FRAC(20, 100))
3142 - rate->count = mr->retry_count_rtscts;
3144 - rate->count = mr->retry_count;
3148 - rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3149 + if (mr->probability < MINSTREL_FRAC(20, 100) || !mr->retry_count) {
3150 + ratetbl->rate[offset].count = 2;
3151 + ratetbl->rate[offset].count_rts = 2;
3152 + ratetbl->rate[offset].count_cts = 2;
3154 + ratetbl->rate[offset].count = mr->retry_count;
3155 + ratetbl->rate[offset].count_cts = mr->retry_count;
3156 + ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
3159 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
3160 - rate->idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3161 + idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3164 + idx = index % MCS_GROUP_RATES +
3165 + (group->streams - 1) * MCS_GROUP_RATES;
3166 + flags = IEEE80211_TX_RC_MCS | group->flags;
3170 + ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
3171 + flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3174 + ratetbl->rate[offset].idx = idx;
3175 + ratetbl->rate[offset].flags = flags;
3179 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
3181 + struct ieee80211_sta_rates *rates;
3184 + rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
3188 + /* Start with max_tp_rate */
3189 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate);
3191 + if (mp->hw->max_rates >= 3) {
3192 + /* At least 3 tx rates supported, use max_tp_rate2 next */
3193 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate2);
3196 + if (mp->hw->max_rates >= 2) {
3198 + * At least 2 tx rates supported, use max_prob_rate next */
3199 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
3202 - rate->flags |= IEEE80211_TX_RC_MCS | group->flags;
3203 - rate->idx = index % MCS_GROUP_RATES + (group->streams - 1) * MCS_GROUP_RATES;
3204 + rates->rate[i].idx = -1;
3205 + rate_control_set_rates(mp->hw, mi->sta, rates);
3209 @@ -702,13 +756,13 @@ static void
3210 minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
3211 struct ieee80211_tx_rate_control *txrc)
3213 + const struct mcs_group *sample_group;
3214 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
3215 - struct ieee80211_tx_rate *ar = info->status.rates;
3216 + struct ieee80211_tx_rate *rate = &info->status.rates[0];
3217 struct minstrel_ht_sta_priv *msp = priv_sta;
3218 struct minstrel_ht_sta *mi = &msp->ht;
3219 struct minstrel_priv *mp = priv;
3221 - bool sample = false;
3223 if (rate_control_send_low(sta, priv_sta, txrc))
3225 @@ -736,51 +790,6 @@ minstrel_ht_get_rate(void *priv, struct
3229 - if (sample_idx >= 0) {
3231 - minstrel_ht_set_rate(mp, mi, &ar[0], sample_idx,
3233 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3235 - minstrel_ht_set_rate(mp, mi, &ar[0], mi->max_tp_rate,
3239 - if (mp->hw->max_rates >= 3) {
3241 - * At least 3 tx rates supported, use
3242 - * sample_rate -> max_tp_rate -> max_prob_rate for sampling and
3243 - * max_tp_rate -> max_tp_rate2 -> max_prob_rate by default.
3245 - if (sample_idx >= 0)
3246 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate,
3249 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate2,
3252 - minstrel_ht_set_rate(mp, mi, &ar[2], mi->max_prob_rate,
3257 - } else if (mp->hw->max_rates == 2) {
3259 - * Only 2 tx rates supported, use
3260 - * sample_rate -> max_prob_rate for sampling and
3261 - * max_tp_rate -> max_prob_rate by default.
3263 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_prob_rate,
3269 - /* Not using MRR, only use the first rate */
3274 mi->total_packets++;
3277 @@ -788,6 +797,16 @@ minstrel_ht_get_rate(void *priv, struct
3278 mi->total_packets = 0;
3279 mi->sample_packets = 0;
3282 + if (sample_idx < 0)
3285 + sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
3286 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3287 + rate->idx = sample_idx % MCS_GROUP_RATES +
3288 + (sample_group->streams - 1) * MCS_GROUP_RATES;
3289 + rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
3294 @@ -837,6 +856,8 @@ minstrel_ht_update_caps(void *priv, stru
3297 memset(mi, 0, sizeof(*mi));
3300 mi->stats_update = jiffies;
3302 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
3303 @@ -898,6 +919,9 @@ minstrel_ht_update_caps(void *priv, stru
3307 + minstrel_ht_update_stats(mp, mi);
3308 + minstrel_ht_update_rates(mp, mi);
3313 --- a/net/mac80211/rc80211_minstrel_ht.h
3314 +++ b/net/mac80211/rc80211_minstrel_ht.h
3315 @@ -65,6 +65,8 @@ struct minstrel_mcs_group_data {
3318 struct minstrel_ht_sta {
3319 + struct ieee80211_sta *sta;
3321 /* ampdu length (average, per sampling interval) */
3322 unsigned int ampdu_len;
3323 unsigned int ampdu_packets;
3324 --- a/net/mac80211/rx.c
3325 +++ b/net/mac80211/rx.c
3326 @@ -1372,6 +1372,7 @@ ieee80211_rx_h_sta_process(struct ieee80
3327 struct sk_buff *skb = rx->skb;
3328 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3329 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3334 @@ -1422,6 +1423,19 @@ ieee80211_rx_h_sta_process(struct ieee80
3335 ewma_add(&sta->avg_signal, -status->signal);
3338 + if (status->chains) {
3339 + sta->chains = status->chains;
3340 + for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
3341 + int signal = status->chain_signal[i];
3343 + if (!(status->chains & BIT(i)))
3346 + sta->chain_signal_last[i] = signal;
3347 + ewma_add(&sta->chain_signal_avg[i], -signal);
3352 * Change STA power saving mode only at the end of a frame
3353 * exchange sequence.
3354 @@ -2085,6 +2099,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
3357 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
3358 + fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
3359 info = IEEE80211_SKB_CB(fwd_skb);
3360 memset(info, 0, sizeof(*info));
3361 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
3362 @@ -2356,6 +2371,7 @@ ieee80211_rx_h_action(struct ieee80211_r
3363 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3364 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3365 sdata->vif.type != NL80211_IFTYPE_AP &&
3366 + sdata->vif.type != NL80211_IFTYPE_WDS &&
3367 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3370 @@ -2423,6 +2439,22 @@ ieee80211_rx_h_action(struct ieee80211_r
3374 + case WLAN_CATEGORY_PUBLIC:
3375 + if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3377 + if (sdata->vif.type != NL80211_IFTYPE_STATION)
3381 + if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3383 + if (mgmt->u.action.u.ext_chan_switch.action_code !=
3384 + WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3386 + if (len < offsetof(struct ieee80211_mgmt,
3387 + u.action.u.ext_chan_switch.variable))
3390 case WLAN_CATEGORY_VHT:
3391 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3392 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3393 @@ -2506,10 +2538,6 @@ ieee80211_rx_h_action(struct ieee80211_r
3394 ieee80211_process_measurement_req(sdata, mgmt, len);
3396 case WLAN_ACTION_SPCT_CHL_SWITCH:
3397 - if (len < (IEEE80211_MIN_ACTION_SIZE +
3398 - sizeof(mgmt->u.action.u.chan_switch)))
3401 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3404 @@ -2695,14 +2723,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
3406 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3407 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3408 - sdata->vif.type != NL80211_IFTYPE_STATION)
3409 + sdata->vif.type != NL80211_IFTYPE_STATION &&
3410 + sdata->vif.type != NL80211_IFTYPE_WDS)
3411 return RX_DROP_MONITOR;
3414 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3415 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3416 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3417 - /* process for all: mesh, mlme, ibss */
3418 + /* process for all: mesh, mlme, ibss, wds */
3420 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3421 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3422 @@ -3023,6 +3052,9 @@ static int prepare_for_handlers(struct i
3423 * and location updates. Note that mac80211
3424 * itself never looks at these frames.
3427 + !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3429 if (ieee80211_is_public_action(hdr, skb->len))
3431 if (!ieee80211_is_beacon(hdr->frame_control))
3432 @@ -3031,10 +3063,16 @@ static int prepare_for_handlers(struct i
3435 case NL80211_IFTYPE_WDS:
3436 - if (bssid || !ieee80211_is_data(hdr->frame_control))
3438 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
3441 + if (ieee80211_is_data(hdr->frame_control) ||
3442 + ieee80211_is_action(hdr->frame_control)) {
3443 + if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
3445 + } else if (!ieee80211_is_beacon(hdr->frame_control))
3449 case NL80211_IFTYPE_P2P_DEVICE:
3450 if (!ieee80211_is_public_action(hdr, skb->len) &&
3451 --- a/net/mac80211/scan.c
3452 +++ b/net/mac80211/scan.c
3453 @@ -181,7 +181,7 @@ void ieee80211_scan_rx(struct ieee80211_
3454 if (baselen > skb->len)
3457 - ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
3458 + ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
3460 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3462 --- a/net/mac80211/sta_info.h
3463 +++ b/net/mac80211/sta_info.h
3465 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
3467 * @WLAN_STA_WME: Station is a QoS-STA.
3468 - * @WLAN_STA_WDS: Station is one of our WDS peers.
3469 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
3470 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
3471 * frame to this station is transmitted.
3472 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
3473 WLAN_STA_AUTHORIZED,
3474 WLAN_STA_SHORT_PREAMBLE,
3477 WLAN_STA_CLEAR_PS_FILT,
3480 @@ -344,6 +342,11 @@ struct sta_info {
3482 struct ewma avg_signal;
3483 int last_ack_signal;
3486 + s8 chain_signal_last[IEEE80211_MAX_CHAINS];
3487 + struct ewma chain_signal_avg[IEEE80211_MAX_CHAINS];
3489 /* Plus 1 for non-QoS frames */
3490 __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
3492 --- a/net/mac80211/trace.h
3493 +++ b/net/mac80211/trace.h
3494 @@ -990,23 +990,23 @@ TRACE_EVENT(drv_channel_switch,
3499 __field(u64, timestamp)
3500 __field(bool, block_tx)
3501 - __field(u16, freq)
3507 + CHANDEF_ASSIGN(&ch_switch->chandef)
3508 __entry->timestamp = ch_switch->timestamp;
3509 __entry->block_tx = ch_switch->block_tx;
3510 - __entry->freq = ch_switch->channel->center_freq;
3511 __entry->count = ch_switch->count;
3515 - LOCAL_PR_FMT " new freq:%u count:%d",
3516 - LOCAL_PR_ARG, __entry->freq, __entry->count
3517 + LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
3518 + LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count
3522 --- a/net/mac80211/tx.c
3523 +++ b/net/mac80211/tx.c
3524 @@ -48,15 +48,15 @@ static __le16 ieee80211_duration(struct
3525 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3527 /* assume HW handles this */
3528 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
3529 + if (tx->rate.flags & IEEE80211_TX_RC_MCS)
3533 - if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
3534 + if (WARN_ON_ONCE(tx->rate.idx < 0))
3537 sband = local->hw.wiphy->bands[info->band];
3538 - txrate = &sband->bitrates[info->control.rates[0].idx];
3539 + txrate = &sband->bitrates[tx->rate.idx];
3541 erp = txrate->flags & IEEE80211_RATE_ERP_G;
3543 @@ -617,11 +617,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3544 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
3545 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
3546 struct ieee80211_supported_band *sband;
3547 - struct ieee80211_rate *rate;
3550 - bool inval = false, rts = false, short_preamble = false;
3551 struct ieee80211_tx_rate_control txrc;
3552 + struct ieee80211_sta_rates *ratetbl = NULL;
3555 memset(&txrc, 0, sizeof(txrc));
3556 @@ -642,18 +640,23 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3557 txrc.max_rate_idx = -1;
3559 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3560 - memcpy(txrc.rate_idx_mcs_mask,
3561 - tx->sdata->rc_rateidx_mcs_mask[info->band],
3562 - sizeof(txrc.rate_idx_mcs_mask));
3564 + if (tx->sdata->rc_has_mcs_mask[info->band])
3565 + txrc.rate_idx_mcs_mask =
3566 + tx->sdata->rc_rateidx_mcs_mask[info->band];
3568 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
3569 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
3570 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
3572 /* set up RTS protection if desired */
3573 if (len > tx->local->hw.wiphy->rts_threshold) {
3574 - txrc.rts = rts = true;
3578 + info->control.use_rts = txrc.rts;
3579 + info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
3582 * Use short preamble if the BSS can handle it, but not for
3583 * management frames unless we know the receiver can handle
3584 @@ -663,7 +666,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3585 if (tx->sdata->vif.bss_conf.use_short_preamble &&
3586 (ieee80211_is_data(hdr->frame_control) ||
3587 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
3588 - txrc.short_preamble = short_preamble = true;
3589 + txrc.short_preamble = true;
3591 + info->control.short_preamble = txrc.short_preamble;
3594 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
3595 @@ -687,16 +692,38 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3597 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
3599 - if (unlikely(info->control.rates[0].idx < 0))
3601 + if (tx->sta && !info->control.skip_table)
3602 + ratetbl = rcu_dereference(tx->sta->sta.rates);
3604 + if (unlikely(info->control.rates[0].idx < 0)) {
3606 + struct ieee80211_tx_rate rate = {
3607 + .idx = ratetbl->rate[0].idx,
3608 + .flags = ratetbl->rate[0].flags,
3609 + .count = ratetbl->rate[0].count
3612 + if (ratetbl->rate[0].idx < 0)
3620 + tx->rate = info->control.rates[0];
3623 if (txrc.reported_rate.idx < 0) {
3624 - txrc.reported_rate = info->control.rates[0];
3625 + txrc.reported_rate = tx->rate;
3626 if (tx->sta && ieee80211_is_data(hdr->frame_control))
3627 tx->sta->last_tx_rate = txrc.reported_rate;
3629 tx->sta->last_tx_rate = txrc.reported_rate;
3632 + return TX_CONTINUE;
3634 if (unlikely(!info->control.rates[0].count))
3635 info->control.rates[0].count = 1;
3637 @@ -704,91 +731,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3638 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
3639 info->control.rates[0].count = 1;
3641 - if (is_multicast_ether_addr(hdr->addr1)) {
3643 - * XXX: verify the rate is in the basic rateset
3645 - return TX_CONTINUE;
3649 - * set up the RTS/CTS rate as the fastest basic rate
3650 - * that is not faster than the data rate
3652 - * XXX: Should this check all retry rates?
3654 - if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
3657 - rate = &sband->bitrates[info->control.rates[0].idx];
3659 - for (i = 0; i < sband->n_bitrates; i++) {
3660 - /* must be a basic rate */
3661 - if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
3663 - /* must not be faster than the data rate */
3664 - if (sband->bitrates[i].bitrate > rate->bitrate)
3667 - if (sband->bitrates[baserate].bitrate <
3668 - sband->bitrates[i].bitrate)
3672 - info->control.rts_cts_rate_idx = baserate;
3675 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
3677 - * make sure there's no valid rate following
3678 - * an invalid one, just in case drivers don't
3679 - * take the API seriously to stop at -1.
3682 - info->control.rates[i].idx = -1;
3685 - if (info->control.rates[i].idx < 0) {
3691 - * For now assume MCS is already set up correctly, this
3692 - * needs to be fixed.
3694 - if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
3695 - WARN_ON(info->control.rates[i].idx > 76);
3699 - /* set up RTS protection if desired */
3701 - info->control.rates[i].flags |=
3702 - IEEE80211_TX_RC_USE_RTS_CTS;
3704 - /* RC is busted */
3705 - if (WARN_ON_ONCE(info->control.rates[i].idx >=
3706 - sband->n_bitrates)) {
3707 - info->control.rates[i].idx = -1;
3711 - rate = &sband->bitrates[info->control.rates[i].idx];
3713 - /* set up short preamble */
3714 - if (short_preamble &&
3715 - rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
3716 - info->control.rates[i].flags |=
3717 - IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
3719 - /* set up G protection */
3720 - if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
3721 - rate->flags & IEEE80211_RATE_ERP_G)
3722 - info->control.rates[i].flags |=
3723 - IEEE80211_TX_RC_USE_CTS_PROTECT;
3729 @@ -2508,8 +2450,6 @@ struct sk_buff *ieee80211_beacon_get_tim
3730 txrc.max_rate_idx = -1;
3732 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3733 - memcpy(txrc.rate_idx_mcs_mask, sdata->rc_rateidx_mcs_mask[band],
3734 - sizeof(txrc.rate_idx_mcs_mask));
3736 rate_control_get_rate(sdata, NULL, &txrc);
3738 --- a/net/mac80211/util.c
3739 +++ b/net/mac80211/util.c
3740 @@ -485,7 +485,8 @@ int ieee80211_queue_stopped(struct ieee8
3743 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3744 - ret = !!local->queue_stop_reasons[queue];
3745 + ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
3746 + &local->queue_stop_reasons[queue]);
3747 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3750 @@ -559,6 +560,9 @@ void ieee80211_iterate_active_interfaces
3751 list_for_each_entry(sdata, &local->interfaces, list) {
3752 switch (sdata->vif.type) {
3753 case NL80211_IFTYPE_MONITOR:
3754 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3757 case NL80211_IFTYPE_AP_VLAN:
3760 @@ -597,6 +601,9 @@ void ieee80211_iterate_active_interfaces
3761 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3762 switch (sdata->vif.type) {
3763 case NL80211_IFTYPE_MONITOR:
3764 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3767 case NL80211_IFTYPE_AP_VLAN:
3770 @@ -660,7 +667,7 @@ void ieee80211_queue_delayed_work(struct
3772 EXPORT_SYMBOL(ieee80211_queue_delayed_work);
3774 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
3775 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
3776 struct ieee802_11_elems *elems,
3777 u64 filter, u32 crc)
3779 @@ -668,6 +675,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3781 bool calc_crc = filter != 0;
3782 DECLARE_BITMAP(seen_elems, 256);
3785 bitmap_zero(seen_elems, 256);
3786 memset(elems, 0, sizeof(*elems));
3787 @@ -715,6 +723,12 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3788 case WLAN_EID_COUNTRY:
3789 case WLAN_EID_PWR_CONSTRAINT:
3790 case WLAN_EID_TIMEOUT_INTERVAL:
3791 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3792 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3794 + * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
3795 + * that if the content gets bigger it might be needed more than once
3797 if (test_bit(id, seen_elems)) {
3798 elems->parse_error = true;
3800 @@ -862,6 +876,48 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3802 elems->ch_switch_ie = (void *)pos;
3804 + case WLAN_EID_EXT_CHANSWITCH_ANN:
3805 + if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
3806 + elem_parse_failed = true;
3809 + elems->ext_chansw_ie = (void *)pos;
3811 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3812 + if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
3813 + elem_parse_failed = true;
3816 + elems->sec_chan_offs = (void *)pos;
3818 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3820 + elen != sizeof(*elems->wide_bw_chansw_ie)) {
3821 + elem_parse_failed = true;
3824 + elems->wide_bw_chansw_ie = (void *)pos;
3826 + case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
3828 + elem_parse_failed = true;
3832 + * This is a bit tricky, but as we only care about
3833 + * the wide bandwidth channel switch element, so
3834 + * just parse it out manually.
3836 + ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
3839 + if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
3840 + elems->wide_bw_chansw_ie =
3843 + elem_parse_failed = true;
3846 case WLAN_EID_COUNTRY:
3847 elems->country_elem = pos;
3848 elems->country_elem_len = elen;
3849 --- a/net/wireless/reg.c
3850 +++ b/net/wireless/reg.c
3851 @@ -857,7 +857,7 @@ static void handle_channel(struct wiphy
3854 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
3855 - chan->flags = IEEE80211_CHAN_DISABLED;
3856 + chan->flags |= IEEE80211_CHAN_DISABLED;
3860 --- a/net/wireless/util.c
3861 +++ b/net/wireless/util.c
3862 @@ -1156,6 +1156,26 @@ int cfg80211_get_p2p_attr(const u8 *ies,
3864 EXPORT_SYMBOL(cfg80211_get_p2p_attr);
3866 +bool ieee80211_operating_class_to_band(u8 operating_class,
3867 + enum ieee80211_band *band)
3869 + switch (operating_class) {
3872 + *band = IEEE80211_BAND_5GHZ;
3878 + *band = IEEE80211_BAND_2GHZ;
3884 +EXPORT_SYMBOL(ieee80211_operating_class_to_band);
3886 int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
3889 --- a/include/uapi/linux/nl80211.h
3890 +++ b/include/uapi/linux/nl80211.h
3891 @@ -1973,6 +1973,10 @@ enum nl80211_sta_bss_param {
3892 * @NL80211_STA_INFO_PEER_PM: peer mesh STA link-specific power mode
3893 * @NL80211_STA_INFO_NONPEER_PM: neighbor mesh STA power save mode towards
3895 + * @NL80211_STA_INFO_CHAIN_SIGNAL: per-chain signal strength of last PPDU
3896 + * Contains a nested array of signal strength attributes (u8, dBm)
3897 + * @NL80211_STA_INFO_CHAIN_SIGNAL_AVG: per-chain signal strength average
3898 + * Same format as NL80211_STA_INFO_CHAIN_SIGNAL.
3899 * @__NL80211_STA_INFO_AFTER_LAST: internal
3900 * @NL80211_STA_INFO_MAX: highest possible station info attribute
3902 @@ -2002,6 +2006,8 @@ enum nl80211_sta_info {
3903 NL80211_STA_INFO_NONPEER_PM,
3904 NL80211_STA_INFO_RX_BYTES64,
3905 NL80211_STA_INFO_TX_BYTES64,
3906 + NL80211_STA_INFO_CHAIN_SIGNAL,
3907 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
3910 __NL80211_STA_INFO_AFTER_LAST,
3911 @@ -2395,6 +2401,8 @@ enum nl80211_survey_info {
3912 * @NL80211_MNTR_FLAG_OTHER_BSS: disable BSSID filtering
3913 * @NL80211_MNTR_FLAG_COOK_FRAMES: report frames after processing.
3914 * overrides all other flags.
3915 + * @NL80211_MNTR_FLAG_ACTIVE: use the configured MAC address
3916 + * and ACK incoming unicast packets.
3918 * @__NL80211_MNTR_FLAG_AFTER_LAST: internal use
3919 * @NL80211_MNTR_FLAG_MAX: highest possible monitor flag
3920 @@ -2406,6 +2414,7 @@ enum nl80211_mntr_flags {
3921 NL80211_MNTR_FLAG_CONTROL,
3922 NL80211_MNTR_FLAG_OTHER_BSS,
3923 NL80211_MNTR_FLAG_COOK_FRAMES,
3924 + NL80211_MNTR_FLAG_ACTIVE,
3927 __NL80211_MNTR_FLAG_AFTER_LAST,
3928 @@ -3557,6 +3566,7 @@ enum nl80211_feature_flags {
3929 NL80211_FEATURE_ADVERTISE_CHAN_LIMITS = 1 << 14,
3930 NL80211_FEATURE_FULL_AP_CLIENT_STATE = 1 << 15,
3931 NL80211_FEATURE_USERSPACE_MPM = 1 << 16,
3932 + NL80211_FEATURE_ACTIVE_MONITOR = 1 << 17,
3936 --- a/net/mac80211/sta_info.c
3937 +++ b/net/mac80211/sta_info.c
3938 @@ -358,6 +358,8 @@ struct sta_info *sta_info_alloc(struct i
3939 do_posix_clock_monotonic_gettime(&uptime);
3940 sta->last_connected = uptime.tv_sec;
3941 ewma_init(&sta->avg_signal, 1024, 8);
3942 + for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
3943 + ewma_init(&sta->chain_signal_avg[i], 1024, 8);
3945 if (sta_prepare_rate_control(local, sta, gfp)) {
3947 --- a/net/wireless/nl80211.c
3948 +++ b/net/wireless/nl80211.c
3949 @@ -2270,6 +2270,7 @@ static const struct nla_policy mntr_flag
3950 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3951 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3952 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3953 + [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3956 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3957 @@ -2381,6 +2382,10 @@ static int nl80211_set_interface(struct
3961 + if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
3962 + !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3963 + return -EOPNOTSUPP;
3966 err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms);
3968 @@ -2438,6 +2443,11 @@ static int nl80211_new_interface(struct
3969 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
3970 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
3973 + if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
3974 + !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3975 + return -EOPNOTSUPP;
3977 wdev = rdev_add_virtual_intf(rdev,
3978 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
3979 type, err ? NULL : &flags, ¶ms);
3980 @@ -3367,6 +3377,32 @@ static bool nl80211_put_sta_rate(struct
3984 +static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3993 + attr = nla_nest_start(msg, id);
3997 + for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3998 + if (!(mask & BIT(i)))
4001 + if (nla_put_u8(msg, i, signal[i]))
4005 + nla_nest_end(msg, attr);
4010 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
4012 struct cfg80211_registered_device *rdev,
4013 @@ -3402,7 +3438,7 @@ static int nl80211_send_station(struct s
4014 (u32)sinfo->rx_bytes))
4015 goto nla_put_failure;
4016 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
4017 - NL80211_STA_INFO_TX_BYTES64)) &&
4018 + STATION_INFO_TX_BYTES64)) &&
4019 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4020 (u32)sinfo->tx_bytes))
4021 goto nla_put_failure;
4022 @@ -3438,6 +3474,18 @@ static int nl80211_send_station(struct s
4026 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
4027 + if (!nl80211_put_signal(msg, sinfo->chains,
4028 + sinfo->chain_signal,
4029 + NL80211_STA_INFO_CHAIN_SIGNAL))
4030 + goto nla_put_failure;
4032 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
4033 + if (!nl80211_put_signal(msg, sinfo->chains,
4034 + sinfo->chain_signal_avg,
4035 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4036 + goto nla_put_failure;
4038 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
4039 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4040 NL80211_STA_INFO_TX_BITRATE))
4041 --- a/drivers/net/wireless/ath/ath9k/init.c
4042 +++ b/drivers/net/wireless/ath/ath9k/init.c
4043 @@ -433,6 +433,8 @@ static int ath9k_init_queues(struct ath_
4044 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
4045 ath_cabq_update(sc);
4047 + sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
4049 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
4050 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
4051 sc->tx.txq_map[i]->mac80211_qnum = i;
4052 @@ -768,7 +770,8 @@ void ath9k_set_hw_capab(struct ath_softc
4053 IEEE80211_HW_SUPPORTS_PS |
4054 IEEE80211_HW_PS_NULLFUNC_STACK |
4055 IEEE80211_HW_SPECTRUM_MGMT |
4056 - IEEE80211_HW_REPORTS_TX_ACK_STATUS;
4057 + IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4058 + IEEE80211_HW_SUPPORTS_RC_TABLE;
4060 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
4061 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4062 @@ -776,6 +779,8 @@ void ath9k_set_hw_capab(struct ath_softc
4063 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
4064 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
4066 + hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
4068 hw->wiphy->interface_modes =
4069 BIT(NL80211_IFTYPE_P2P_GO) |
4070 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4071 --- a/drivers/net/wireless/ath/ath9k/xmit.c
4072 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
4073 @@ -125,24 +125,6 @@ static void ath_tx_queue_tid(struct ath_
4074 list_add_tail(&ac->list, &txq->axq_acq);
4077 -static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4079 - struct ath_txq *txq = tid->ac->txq;
4081 - WARN_ON(!tid->paused);
4083 - ath_txq_lock(sc, txq);
4084 - tid->paused = false;
4086 - if (skb_queue_empty(&tid->buf_q))
4089 - ath_tx_queue_tid(txq, tid);
4090 - ath_txq_schedule(sc, txq);
4092 - ath_txq_unlock_complete(sc, txq);
4095 static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
4097 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4098 @@ -157,6 +139,13 @@ static void ath_send_bar(struct ath_atx_
4099 seqno << IEEE80211_SEQ_SEQ_SHIFT);
4102 +static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4103 + struct ath_buf *bf)
4105 + ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
4106 + ARRAY_SIZE(bf->rates));
4109 static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4111 struct ath_txq *txq = tid->ac->txq;
4112 @@ -189,15 +178,11 @@ static void ath_tx_flush_tid(struct ath_
4113 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4116 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4117 ath_tx_send_normal(sc, txq, NULL, skb);
4121 - if (tid->baw_head == tid->baw_tail) {
4122 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4123 - tid->state &= ~AGGR_CLEANUP;
4127 ath_txq_unlock(sc, txq);
4128 ath_send_bar(tid, tid->seq_start);
4129 @@ -269,9 +254,7 @@ static void ath_tid_drain(struct ath_sof
4131 list_add_tail(&bf->list, &bf_head);
4134 - ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4136 + ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4137 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4140 @@ -407,7 +390,7 @@ static void ath_tx_complete_aggr(struct
4142 tx_info = IEEE80211_SKB_CB(skb);
4144 - memcpy(rates, tx_info->control.rates, sizeof(rates));
4145 + memcpy(rates, bf->rates, sizeof(rates));
4147 retries = ts->ts_longretry + 1;
4148 for (i = 0; i < ts->ts_rateindex; i++)
4149 @@ -483,19 +466,19 @@ static void ath_tx_complete_aggr(struct
4150 tx_info = IEEE80211_SKB_CB(skb);
4151 fi = get_frame_info(skb);
4153 - if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4154 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4156 + * Outside of the current BlockAck window,
4157 + * maybe part of a previous session
4160 + } else if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4161 /* transmit completion, subframe is
4162 * acked by block ack */
4164 } else if (!isaggr && txok) {
4165 /* transmit completion */
4167 - } else if (tid->state & AGGR_CLEANUP) {
4169 - * cleanup in progress, just fail
4170 - * the un-acked sub-frames
4175 } else if (fi->retries < ATH_MAX_SW_RETRIES) {
4176 @@ -519,7 +502,7 @@ static void ath_tx_complete_aggr(struct
4177 if (bf_next != NULL || !bf_last->bf_stale)
4178 list_move_tail(&bf->list, &bf_head);
4180 - if (!txpending || (tid->state & AGGR_CLEANUP)) {
4183 * complete the acked-ones/xretried ones; update
4185 @@ -535,6 +518,10 @@ static void ath_tx_complete_aggr(struct
4186 ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
4189 + if (tx_info->flags & IEEE80211_TX_STATUS_EOSP) {
4190 + tx_info->flags &= ~IEEE80211_TX_STATUS_EOSP;
4191 + ieee80211_sta_eosp(sta);
4193 /* retry the un-acked ones */
4194 if (bf->bf_next == NULL && bf_last->bf_stale) {
4195 struct ath_buf *tbf;
4196 @@ -593,9 +580,6 @@ static void ath_tx_complete_aggr(struct
4197 ath_txq_lock(sc, txq);
4200 - if (tid->state & AGGR_CLEANUP)
4201 - ath_tx_flush_tid(sc, tid);
4206 @@ -612,6 +596,7 @@ static void ath_tx_process_buffer(struct
4207 struct ath_tx_status *ts, struct ath_buf *bf,
4208 struct list_head *bf_head)
4210 + struct ieee80211_tx_info *info;
4213 txok = !(ts->ts_status & ATH9K_TXERR_MASK);
4214 @@ -623,8 +608,12 @@ static void ath_tx_process_buffer(struct
4215 txq->axq_ampdu_depth--;
4217 if (!bf_isampdu(bf)) {
4220 + info = IEEE80211_SKB_CB(bf->bf_mpdu);
4221 + memcpy(info->control.rates, bf->rates,
4222 + sizeof(info->control.rates));
4223 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
4225 ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok);
4227 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
4228 @@ -668,7 +657,7 @@ static u32 ath_lookup_rate(struct ath_so
4231 tx_info = IEEE80211_SKB_CB(skb);
4232 - rates = tx_info->control.rates;
4233 + rates = bf->rates;
4236 * Find the lowest frame length among the rate series that will have a
4237 @@ -736,8 +725,6 @@ static int ath_compute_num_delims(struct
4240 #define FIRST_DESC_NDELIMS 60
4241 - struct sk_buff *skb = bf->bf_mpdu;
4242 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4243 u32 nsymbits, nsymbols;
4246 @@ -778,8 +765,8 @@ static int ath_compute_num_delims(struct
4247 if (tid->an->mpdudensity == 0)
4250 - rix = tx_info->control.rates[0].idx;
4251 - flags = tx_info->control.rates[0].flags;
4252 + rix = bf->rates[0].idx;
4253 + flags = bf->rates[0].flags;
4254 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
4255 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
4257 @@ -803,24 +790,16 @@ static int ath_compute_num_delims(struct
4261 -static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4262 - struct ath_txq *txq,
4263 - struct ath_atx_tid *tid,
4264 - struct list_head *bf_q,
4266 +static struct ath_buf *
4267 +ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
4268 + struct ath_atx_tid *tid)
4270 -#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4271 - struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4272 - int rl = 0, nframes = 0, ndelim, prev_al = 0;
4273 - u16 aggr_limit = 0, al = 0, bpad = 0,
4274 - al_delta, h_baw = tid->baw_size / 2;
4275 - enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4276 - struct ieee80211_tx_info *tx_info;
4277 struct ath_frame_info *fi;
4278 struct sk_buff *skb;
4279 + struct ath_buf *bf;
4284 skb = skb_peek(&tid->buf_q);
4285 fi = get_frame_info(skb);
4287 @@ -837,10 +816,8 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4288 seqno = bf->bf_state.seqno;
4290 /* do not step over block-ack window */
4291 - if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4292 - status = ATH_AGGR_BAW_CLOSED;
4293 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno))
4297 if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) {
4298 struct ath_tx_status ts = {};
4299 @@ -854,10 +831,45 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4303 + bf->bf_next = NULL;
4304 + bf->bf_lastbf = bf;
4311 +static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4312 + struct ath_txq *txq,
4313 + struct ath_atx_tid *tid,
4314 + struct list_head *bf_q,
4317 +#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4318 + struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4319 + int rl = 0, nframes = 0, ndelim, prev_al = 0;
4320 + u16 aggr_limit = 0, al = 0, bpad = 0,
4321 + al_delta, h_baw = tid->baw_size / 2;
4322 + enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4323 + struct ieee80211_tx_info *tx_info;
4324 + struct ath_frame_info *fi;
4325 + struct sk_buff *skb;
4328 + bf = ath_tx_get_tid_subframe(sc, txq, tid);
4330 + status = ATH_AGGR_BAW_CLOSED;
4334 + skb = bf->bf_mpdu;
4335 + fi = get_frame_info(skb);
4341 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4342 aggr_limit = ath_lookup_rate(sc, bf, tid);
4345 @@ -898,7 +910,7 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4347 /* link buffers of this frame to the aggregate */
4349 - ath_tx_addto_baw(sc, tid, seqno);
4350 + ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4351 bf->bf_state.ndelim = ndelim;
4353 __skb_unlink(skb, &tid->buf_q);
4354 @@ -998,14 +1010,14 @@ static void ath_buf_set_rate(struct ath_
4357 tx_info = IEEE80211_SKB_CB(skb);
4358 - rates = tx_info->control.rates;
4359 + rates = bf->rates;
4360 hdr = (struct ieee80211_hdr *)skb->data;
4362 /* set dur_update_en for l-sig computation except for PS-Poll frames */
4363 info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
4364 info->rtscts_rate = fi->rtscts_rate;
4366 - for (i = 0; i < 4; i++) {
4367 + for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
4368 bool is_40, is_sgi, is_sp;
4371 @@ -1107,9 +1119,8 @@ static void ath_tx_fill_desc(struct ath_
4373 struct ath_hw *ah = sc->sc_ah;
4374 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
4375 - struct ath_buf *bf_first = bf;
4376 + struct ath_buf *bf_first = NULL;
4377 struct ath_tx_info info;
4378 - bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4380 memset(&info, 0, sizeof(info));
4381 info.is_first = true;
4382 @@ -1117,24 +1128,17 @@ static void ath_tx_fill_desc(struct ath_
4383 info.txpower = MAX_RATE_POWER;
4384 info.qcu = txq->axq_qnum;
4386 - info.flags = ATH9K_TXDESC_INTREQ;
4387 - if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4388 - info.flags |= ATH9K_TXDESC_NOACK;
4389 - if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4390 - info.flags |= ATH9K_TXDESC_LDPC;
4392 - ath_buf_set_rate(sc, bf, &info, len);
4394 - if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
4395 + if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
4396 + txq == sc->tx.uapsdq)
4397 info.flags |= ATH9K_TXDESC_CLRDMASK;
4399 if (bf->bf_state.bfs_paprd)
4400 info.flags |= (u32) bf->bf_state.bfs_paprd << ATH9K_TXDESC_PAPRD_S;
4404 struct sk_buff *skb = bf->bf_mpdu;
4405 struct ath_frame_info *fi = get_frame_info(skb);
4406 + bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4408 info.type = get_hw_packet_type(skb);
4410 @@ -1142,6 +1146,18 @@ static void ath_tx_fill_desc(struct ath_
4417 + info.flags = ATH9K_TXDESC_INTREQ;
4418 + if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4419 + info.flags |= ATH9K_TXDESC_NOACK;
4420 + if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4421 + info.flags |= ATH9K_TXDESC_LDPC;
4423 + ath_buf_set_rate(sc, bf, &info, len);
4426 info.buf_addr[0] = bf->bf_buf_addr;
4427 info.buf_len[0] = skb->len;
4428 info.pkt_len = fi->framelen;
4429 @@ -1151,7 +1167,7 @@ static void ath_tx_fill_desc(struct ath_
4432 info.aggr = AGGR_BUF_FIRST;
4433 - else if (!bf->bf_next)
4434 + else if (bf == bf_first->bf_lastbf)
4435 info.aggr = AGGR_BUF_LAST;
4437 info.aggr = AGGR_BUF_MIDDLE;
4438 @@ -1160,6 +1176,9 @@ static void ath_tx_fill_desc(struct ath_
4439 info.aggr_len = len;
4442 + if (bf == bf_first->bf_lastbf)
4445 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
4448 @@ -1224,9 +1243,6 @@ int ath_tx_aggr_start(struct ath_softc *
4449 an = (struct ath_node *)sta->drv_priv;
4450 txtid = ATH_AN_2_TID(an, tid);
4452 - if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE))
4455 /* update ampdu factor/density, they may have changed. This may happen
4456 * in HT IBSS when a beacon with HT-info is received after the station
4457 * has already been added.
4458 @@ -1238,7 +1254,7 @@ int ath_tx_aggr_start(struct ath_softc *
4459 an->mpdudensity = density;
4462 - txtid->state |= AGGR_ADDBA_PROGRESS;
4463 + txtid->active = true;
4464 txtid->paused = true;
4465 *ssn = txtid->seq_start = txtid->seq_next;
4466 txtid->bar_index = -1;
4467 @@ -1255,28 +1271,9 @@ void ath_tx_aggr_stop(struct ath_softc *
4468 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
4469 struct ath_txq *txq = txtid->ac->txq;
4471 - if (txtid->state & AGGR_CLEANUP)
4474 - if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
4475 - txtid->state &= ~AGGR_ADDBA_PROGRESS;
4479 ath_txq_lock(sc, txq);
4480 + txtid->active = false;
4481 txtid->paused = true;
4484 - * If frames are still being transmitted for this TID, they will be
4485 - * cleaned up during tx completion. To prevent race conditions, this
4486 - * TID can only be reused after all in-progress subframes have been
4489 - if (txtid->baw_head != txtid->baw_tail)
4490 - txtid->state |= AGGR_CLEANUP;
4492 - txtid->state &= ~AGGR_ADDBA_COMPLETE;
4494 ath_tx_flush_tid(sc, txtid);
4495 ath_txq_unlock_complete(sc, txq);
4497 @@ -1342,18 +1339,92 @@ void ath_tx_aggr_wakeup(struct ath_softc
4501 -void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
4502 +void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta,
4505 - struct ath_atx_tid *txtid;
4506 + struct ath_atx_tid *tid;
4507 struct ath_node *an;
4508 + struct ath_txq *txq;
4510 an = (struct ath_node *)sta->drv_priv;
4511 + tid = ATH_AN_2_TID(an, tidno);
4512 + txq = tid->ac->txq;
4514 - txtid = ATH_AN_2_TID(an, tid);
4515 - txtid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4516 - txtid->state |= AGGR_ADDBA_COMPLETE;
4517 - txtid->state &= ~AGGR_ADDBA_PROGRESS;
4518 - ath_tx_resume_tid(sc, txtid);
4519 + ath_txq_lock(sc, txq);
4521 + tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4522 + tid->paused = false;
4524 + if (!skb_queue_empty(&tid->buf_q)) {
4525 + ath_tx_queue_tid(txq, tid);
4526 + ath_txq_schedule(sc, txq);
4529 + ath_txq_unlock_complete(sc, txq);
4532 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
4533 + struct ieee80211_sta *sta,
4534 + u16 tids, int nframes,
4535 + enum ieee80211_frame_release_type reason,
4538 + struct ath_softc *sc = hw->priv;
4539 + struct ath_node *an = (struct ath_node *)sta->drv_priv;
4540 + struct ath_txq *txq = sc->tx.uapsdq;
4541 + struct ieee80211_tx_info *info;
4542 + struct list_head bf_q;
4543 + struct ath_buf *bf_tail = NULL, *bf;
4547 + INIT_LIST_HEAD(&bf_q);
4548 + for (i = 0; tids && nframes; i++, tids >>= 1) {
4549 + struct ath_atx_tid *tid;
4554 + tid = ATH_AN_2_TID(an, i);
4558 + ath_txq_lock(sc, tid->ac->txq);
4559 + while (!skb_queue_empty(&tid->buf_q) && nframes > 0) {
4560 + bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
4564 + __skb_unlink(bf->bf_mpdu, &tid->buf_q);
4565 + list_add_tail(&bf->list, &bf_q);
4566 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4567 + ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4568 + bf->bf_state.bf_type &= ~BUF_AGGR;
4570 + bf_tail->bf_next = bf;
4575 + TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4577 + if (skb_queue_empty(&tid->buf_q))
4578 + ieee80211_sta_set_buffered(an->sta, i, false);
4580 + ath_txq_unlock_complete(sc, tid->ac->txq);
4583 + if (list_empty(&bf_q))
4586 + info = IEEE80211_SKB_CB(bf_tail->bf_mpdu);
4587 + info->flags |= IEEE80211_TX_STATUS_EOSP;
4589 + bf = list_first_entry(&bf_q, struct ath_buf, list);
4590 + ath_txq_lock(sc, txq);
4591 + ath_tx_fill_desc(sc, bf, txq, 0);
4592 + ath_tx_txqaddbuf(sc, txq, &bf_q, false);
4593 + ath_txq_unlock(sc, txq);
4596 /********************/
4597 @@ -1709,8 +1780,9 @@ static void ath_tx_txqaddbuf(struct ath_
4601 -static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
4602 - struct sk_buff *skb, struct ath_tx_control *txctl)
4603 +static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_txq *txq,
4604 + struct ath_atx_tid *tid, struct sk_buff *skb,
4605 + struct ath_tx_control *txctl)
4607 struct ath_frame_info *fi = get_frame_info(skb);
4608 struct list_head bf_head;
4609 @@ -1723,26 +1795,28 @@ static void ath_tx_send_ampdu(struct ath
4610 * - seqno is not within block-ack window
4611 * - h/w queue depth exceeds low water mark
4613 - if (!skb_queue_empty(&tid->buf_q) || tid->paused ||
4614 - !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4615 - txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) {
4616 + if ((!skb_queue_empty(&tid->buf_q) || tid->paused ||
4617 + !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4618 + txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
4619 + txq != sc->tx.uapsdq) {
4621 * Add this frame to software queue for scheduling later
4624 - TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw);
4625 + TX_STAT_INC(txq->axq_qnum, a_queued_sw);
4626 __skb_queue_tail(&tid->buf_q, skb);
4627 if (!txctl->an || !txctl->an->sleeping)
4628 - ath_tx_queue_tid(txctl->txq, tid);
4629 + ath_tx_queue_tid(txq, tid);
4633 - bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4634 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4636 ieee80211_free_txskb(sc->hw, skb);
4640 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4641 bf->bf_state.bf_type = BUF_AMPDU;
4642 INIT_LIST_HEAD(&bf_head);
4643 list_add(&bf->list, &bf_head);
4644 @@ -1751,10 +1825,10 @@ static void ath_tx_send_ampdu(struct ath
4645 ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4647 /* Queue to h/w without aggregation */
4648 - TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw);
4649 + TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4651 - ath_tx_fill_desc(sc, bf, txctl->txq, fi->framelen);
4652 - ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false);
4653 + ath_tx_fill_desc(sc, bf, txq, fi->framelen);
4654 + ath_tx_txqaddbuf(sc, txq, &bf_head, false);
4657 static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
4658 @@ -1892,49 +1966,6 @@ static struct ath_buf *ath_tx_setup_buff
4662 -/* FIXME: tx power */
4663 -static void ath_tx_start_dma(struct ath_softc *sc, struct sk_buff *skb,
4664 - struct ath_tx_control *txctl)
4666 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4667 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4668 - struct ath_atx_tid *tid = NULL;
4669 - struct ath_buf *bf;
4672 - if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4673 - tidno = ieee80211_get_qos_ctl(hdr)[0] &
4674 - IEEE80211_QOS_CTL_TID_MASK;
4675 - tid = ATH_AN_2_TID(txctl->an, tidno);
4677 - WARN_ON(tid->ac->txq != txctl->txq);
4680 - if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4682 - * Try aggregation if it's a unicast data frame
4683 - * and the destination is HT capable.
4685 - ath_tx_send_ampdu(sc, tid, skb, txctl);
4687 - bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4690 - dev_kfree_skb_any(skb);
4692 - ieee80211_free_txskb(sc->hw, skb);
4696 - bf->bf_state.bfs_paprd = txctl->paprd;
4699 - bf->bf_state.bfs_paprd_timestamp = jiffies;
4701 - ath_tx_send_normal(sc, txctl->txq, tid, skb);
4705 /* Upon failure caller should free skb */
4706 int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
4707 struct ath_tx_control *txctl)
4708 @@ -1945,8 +1976,11 @@ int ath_tx_start(struct ieee80211_hw *hw
4709 struct ieee80211_vif *vif = info->control.vif;
4710 struct ath_softc *sc = hw->priv;
4711 struct ath_txq *txq = txctl->txq;
4712 + struct ath_atx_tid *tid = NULL;
4713 + struct ath_buf *bf;
4714 int padpos, padsize;
4715 int frmlen = skb->len + FCS_LEN;
4719 /* NOTE: sta can be NULL according to net/mac80211.h */
4720 @@ -2002,8 +2036,47 @@ int ath_tx_start(struct ieee80211_hw *hw
4721 txq->stopped = true;
4724 - ath_tx_start_dma(sc, skb, txctl);
4725 + if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) {
4726 + ath_txq_unlock(sc, txq);
4727 + txq = sc->tx.uapsdq;
4728 + ath_txq_lock(sc, txq);
4731 + if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4732 + tidno = ieee80211_get_qos_ctl(hdr)[0] &
4733 + IEEE80211_QOS_CTL_TID_MASK;
4734 + tid = ATH_AN_2_TID(txctl->an, tidno);
4736 + WARN_ON(tid->ac->txq != txctl->txq);
4739 + if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4741 + * Try aggregation if it's a unicast data frame
4742 + * and the destination is HT capable.
4744 + ath_tx_send_ampdu(sc, txq, tid, skb, txctl);
4748 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4751 + dev_kfree_skb_any(skb);
4753 + ieee80211_free_txskb(sc->hw, skb);
4757 + bf->bf_state.bfs_paprd = txctl->paprd;
4760 + bf->bf_state.bfs_paprd_timestamp = jiffies;
4762 + ath_set_rates(vif, sta, bf);
4763 + ath_tx_send_normal(sc, txq, tid, skb);
4766 ath_txq_unlock(sc, txq);
4769 @@ -2054,7 +2127,12 @@ static void ath_tx_complete(struct ath_s
4771 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
4773 + __skb_queue_tail(&txq->complete_q, skb);
4775 q = skb_get_queue_mapping(skb);
4776 + if (txq == sc->tx.uapsdq)
4777 + txq = sc->tx.txq_map[q];
4779 if (txq == sc->tx.txq_map[q]) {
4780 if (WARN_ON(--txq->pending_frames < 0))
4781 txq->pending_frames = 0;
4782 @@ -2065,8 +2143,6 @@ static void ath_tx_complete(struct ath_s
4783 txq->stopped = false;
4787 - __skb_queue_tail(&txq->complete_q, skb);
4790 static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
4791 @@ -2408,12 +2484,10 @@ void ath_tx_node_init(struct ath_softc *
4792 tid->baw_head = tid->baw_tail = 0;
4794 tid->paused = false;
4795 - tid->state &= ~AGGR_CLEANUP;
4796 + tid->active = false;
4797 __skb_queue_head_init(&tid->buf_q);
4798 acno = TID_TO_WME_AC(tidno);
4799 tid->ac = &an->ac[acno];
4800 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4801 - tid->state &= ~AGGR_ADDBA_PROGRESS;
4804 for (acno = 0, ac = &an->ac[acno];
4805 @@ -2450,9 +2524,9 @@ void ath_tx_node_cleanup(struct ath_soft
4808 ath_tid_drain(sc, txq, tid);
4809 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4810 - tid->state &= ~AGGR_CLEANUP;
4811 + tid->active = false;
4813 ath_txq_unlock(sc, txq);
4817 --- a/drivers/net/wireless/ath/ath9k/recv.c
4818 +++ b/drivers/net/wireless/ath/ath9k/recv.c
4819 @@ -124,7 +124,7 @@ static bool ath_rx_edma_buf_link(struct
4821 SKB_CB_ATHBUF(skb) = bf;
4822 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
4823 - skb_queue_tail(&rx_edma->rx_fifo, skb);
4824 + __skb_queue_tail(&rx_edma->rx_fifo, skb);
4828 @@ -155,7 +155,7 @@ static void ath_rx_remove_buffer(struct
4830 rx_edma = &sc->rx.rx_edma[qtype];
4832 - while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4833 + while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
4834 bf = SKB_CB_ATHBUF(skb);
4836 list_add_tail(&bf->list, &sc->rx.rxbuf);
4837 @@ -1287,13 +1287,13 @@ int ath_rx_tasklet(struct ath_softc *sc,
4838 goto requeue_drop_frag;
4841 - bf->bf_mpdu = requeue_skb;
4842 - bf->bf_buf_addr = new_buf_addr;
4844 /* Unmap the frame */
4845 dma_unmap_single(sc->dev, bf->bf_buf_addr,
4846 common->rx_bufsize, dma_type);
4848 + bf->bf_mpdu = requeue_skb;
4849 + bf->bf_buf_addr = new_buf_addr;
4851 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
4852 if (ah->caps.rx_status_len)
4853 skb_pull(skb, ah->caps.rx_status_len);
4854 --- a/net/wireless/core.c
4855 +++ b/net/wireless/core.c
4856 @@ -885,7 +885,6 @@ void cfg80211_leave(struct cfg80211_regi
4858 __cfg80211_disconnect(rdev, dev,
4859 WLAN_REASON_DEAUTH_LEAVING, true);
4860 - cfg80211_mlme_down(rdev, dev);
4863 case NL80211_IFTYPE_MESH_POINT:
4864 --- a/net/wireless/sme.c
4865 +++ b/net/wireless/sme.c
4866 @@ -961,7 +961,7 @@ int __cfg80211_disconnect(struct cfg8021
4867 /* was it connected by userspace SME? */
4869 cfg80211_mlme_down(rdev, dev);
4874 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
4875 @@ -987,6 +987,7 @@ int __cfg80211_disconnect(struct cfg8021
4880 if (wdev->sme_state == CFG80211_SME_CONNECTED)
4881 __cfg80211_disconnected(dev, NULL, 0, 0, false);
4882 else if (wdev->sme_state == CFG80211_SME_CONNECTING)
4883 --- a/drivers/net/wireless/ath/ath9k/rc.c
4884 +++ b/drivers/net/wireless/ath/ath9k/rc.c
4885 @@ -1227,10 +1227,7 @@ static bool ath_tx_aggr_check(struct ath
4888 txtid = ATH_AN_2_TID(an, tidno);
4890 - if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
4893 + return !txtid->active;
4897 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4898 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
4899 @@ -334,7 +334,8 @@ static void ar9003_hw_spur_ofdm(struct a
4900 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
4901 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
4903 - if (REG_READ_FIELD(ah, AR_PHY_MODE,
4904 + if (!AR_SREV_9340(ah) &&
4905 + REG_READ_FIELD(ah, AR_PHY_MODE,
4906 AR_PHY_MODE_DYNAMIC) == 0x1)
4907 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
4908 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
4909 --- a/drivers/net/wireless/ath/ath9k/mac.c
4910 +++ b/drivers/net/wireless/ath/ath9k/mac.c
4911 @@ -410,7 +410,7 @@ bool ath9k_hw_resettxqueue(struct ath_hw
4913 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
4915 - if (AR_SREV_9340(ah))
4916 + if (AR_SREV_9340(ah) && !AR_SREV_9340_13_OR_LATER(ah))
4917 REG_WRITE(ah, AR_DMISC(q),
4918 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
4920 --- a/net/mac80211/driver-ops.h
4921 +++ b/net/mac80211/driver-ops.h
4922 @@ -146,7 +146,8 @@ static inline int drv_add_interface(stru
4924 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
4925 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
4926 - !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))))
4927 + !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF) &&
4928 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
4931 trace_drv_add_interface(local, sdata);
4932 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
4933 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
4934 @@ -454,6 +454,8 @@ static bool create_pa_curve(u32 *data_L,
4935 if (accum_cnt <= thresh_accum_cnt)
4940 /* sum(tx amplitude) */
4941 accum_tx = ((data_L[i] >> 16) & 0xffff) |
4942 ((data_U[i] & 0x7ff) << 16);
4943 @@ -468,20 +470,21 @@ static bool create_pa_curve(u32 *data_L,
4945 accum_tx <<= scale_factor;
4946 accum_rx <<= scale_factor;
4947 - x_est[i + 1] = (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
4949 + x_est[max_index] =
4950 + (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
4953 - Y[i + 1] = ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
4955 + ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
4957 - (1 << scale_factor) * max_index + 16;
4958 + (1 << scale_factor) * i + 16;
4960 if (accum_ang >= (1 << 26))
4961 accum_ang -= 1 << 27;
4963 - theta[i + 1] = ((accum_ang * (1 << scale_factor)) + accum_cnt) /
4967 + theta[max_index] =
4968 + ((accum_ang * (1 << scale_factor)) + accum_cnt) /