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