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