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