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