ath9k: improve multicast buffering handling, take care of the MORE_DATA flag properly
[openwrt/svn-archive/archive.git] / package / mac80211 / patches / 300-pending_work.patch
1 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
2 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3 @@ -234,6 +234,7 @@ struct ath_buf {
4 dma_addr_t bf_daddr; /* physical addr of desc */
5 dma_addr_t bf_buf_addr; /* physical addr of data buffer, for DMA */
6 bool bf_stale;
7 + struct ieee80211_tx_rate rates[4];
8 struct ath_buf_state bf_state;
9 };
10
11 @@ -250,9 +251,9 @@ struct ath_atx_tid {
12 int tidno;
13 int baw_head; /* first un-acked tx buffer */
14 int baw_tail; /* next unused tx buffer slot */
15 - int sched;
16 - int paused;
17 - u8 state;
18 + bool sched;
19 + bool paused;
20 + bool active;
21 };
22
23 struct ath_node {
24 @@ -273,10 +274,6 @@ struct ath_node {
25 #endif
26 };
27
28 -#define AGGR_CLEANUP BIT(1)
29 -#define AGGR_ADDBA_COMPLETE BIT(2)
30 -#define AGGR_ADDBA_PROGRESS BIT(3)
31 -
32 struct ath_tx_control {
33 struct ath_txq *txq;
34 struct ath_node *an;
35 @@ -299,6 +296,7 @@ struct ath_tx {
36 struct ath_txq txq[ATH9K_NUM_TX_QUEUES];
37 struct ath_descdma txdma;
38 struct ath_txq *txq_map[IEEE80211_NUM_ACS];
39 + struct ath_txq *uapsdq;
40 u32 txq_max_pending[IEEE80211_NUM_ACS];
41 u16 max_aggr_framelen[IEEE80211_NUM_ACS][4][32];
42 };
43 @@ -346,6 +344,8 @@ int ath_txq_update(struct ath_softc *sc,
44 void ath_update_max_aggr_framelen(struct ath_softc *sc, int queue, int txop);
45 int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
46 struct ath_tx_control *txctl);
47 +void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
48 + struct sk_buff *skb);
49 void ath_tx_tasklet(struct ath_softc *sc);
50 void ath_tx_edma_tasklet(struct ath_softc *sc);
51 int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
52 @@ -356,6 +356,11 @@ void ath_tx_aggr_resume(struct ath_softc
53 void ath_tx_aggr_wakeup(struct ath_softc *sc, struct ath_node *an);
54 void ath_tx_aggr_sleep(struct ieee80211_sta *sta, struct ath_softc *sc,
55 struct ath_node *an);
56 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
57 + struct ieee80211_sta *sta,
58 + u16 tids, int nframes,
59 + enum ieee80211_frame_release_type reason,
60 + bool more_data);
61
62 /********/
63 /* VIFs */
64 @@ -658,11 +663,10 @@ enum sc_op_flags {
65 struct ath_rate_table;
66
67 struct ath9k_vif_iter_data {
68 - const u8 *hw_macaddr; /* phy's hardware address, set
69 - * before starting iteration for
70 - * valid bssid mask.
71 - */
72 + u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */
73 u8 mask[ETH_ALEN]; /* bssid mask */
74 + bool has_hw_macaddr;
75 +
76 int naps; /* number of AP vifs */
77 int nmeshes; /* number of mesh vifs */
78 int nstations; /* number of station vifs */
79 --- a/drivers/net/wireless/ath/ath9k/hw.c
80 +++ b/drivers/net/wireless/ath/ath9k/hw.c
81 @@ -1171,6 +1171,7 @@ u32 ath9k_regd_get_ctl(struct ath_regula
82 static inline void ath9k_hw_set_dma(struct ath_hw *ah)
83 {
84 struct ath_common *common = ath9k_hw_common(ah);
85 + int txbuf_size;
86
87 ENABLE_REGWRITE_BUFFER(ah);
88
89 @@ -1224,13 +1225,17 @@ static inline void ath9k_hw_set_dma(stru
90 * So set the usable tx buf size also to half to
91 * avoid data/delimiter underruns
92 */
93 - REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
94 - AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
95 - } else if (!AR_SREV_9271(ah)) {
96 - REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
97 - AR_PCU_TXBUF_CTRL_USABLE_SIZE);
98 + txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
99 + } else if (AR_SREV_9340_13_OR_LATER(ah)) {
100 + /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
101 + txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
102 + } else {
103 + txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
104 }
105
106 + if (!AR_SREV_9271(ah))
107 + REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
108 +
109 REGWRITE_BUFFER_FLUSH(ah);
110
111 if (AR_SREV_9300_20_OR_LATER(ah))
112 @@ -1305,9 +1310,13 @@ static bool ath9k_hw_set_reset(struct at
113 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
114 } else {
115 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
116 - if (tmpReg &
117 - (AR_INTR_SYNC_LOCAL_TIMEOUT |
118 - AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
119 + if (AR_SREV_9340(ah))
120 + tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
121 + else
122 + tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
123 + AR_INTR_SYNC_RADM_CPL_TIMEOUT;
124 +
125 + if (tmpReg) {
126 u32 val;
127 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
128
129 @@ -1366,7 +1375,10 @@ static bool ath9k_hw_set_reset(struct at
130
131 REGWRITE_BUFFER_FLUSH(ah);
132
133 - udelay(50);
134 + if (AR_SREV_9100(ah))
135 + mdelay(10);
136 + else
137 + udelay(50);
138
139 REG_WRITE(ah, AR_RTC_RC, 0);
140 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
141 @@ -1377,8 +1389,12 @@ static bool ath9k_hw_set_reset(struct at
142 if (!AR_SREV_9100(ah))
143 REG_WRITE(ah, AR_RC, 0);
144
145 - if (AR_SREV_9100(ah))
146 + if (AR_SREV_9100(ah) && type != ATH9K_RESET_WARM) {
147 + if (ah->external_reset)
148 + ah->external_reset();
149 +
150 udelay(50);
151 + }
152
153 return true;
154 }
155 @@ -1464,7 +1480,8 @@ static bool ath9k_hw_chip_reset(struct a
156 reset_type = ATH9K_RESET_POWER_ON;
157 else
158 reset_type = ATH9K_RESET_COLD;
159 - } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
160 + } else if (ah->chip_fullsleep ||
161 + REG_READ(ah, AR_Q_TXE) ||
162 (REG_READ(ah, AR_CR) & AR_CR_RXE))
163 reset_type = ATH9K_RESET_COLD;
164
165 @@ -1698,12 +1715,11 @@ static void ath9k_hw_reset_opmode(struct
166
167 ENABLE_REGWRITE_BUFFER(ah);
168
169 - REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
170 - REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
171 - | macStaId1
172 + REG_RMW(ah, AR_STA_ID1, macStaId1
173 | AR_STA_ID1_RTS_USE_DEF
174 | (ah->config.ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
175 - | ah->sta_id1_defaults);
176 + | ah->sta_id1_defaults,
177 + ~AR_STA_ID1_SADH_MASK);
178 ath_hw_setbssidmask(common);
179 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
180 ath9k_hw_write_associd(ah);
181 --- a/drivers/net/wireless/ath/ath9k/main.c
182 +++ b/drivers/net/wireless/ath/ath9k/main.c
183 @@ -839,10 +839,14 @@ static void ath9k_vif_iter(void *data, u
184 struct ath9k_vif_iter_data *iter_data = data;
185 int i;
186
187 - if (iter_data->hw_macaddr)
188 + if (iter_data->has_hw_macaddr) {
189 for (i = 0; i < ETH_ALEN; i++)
190 iter_data->mask[i] &=
191 ~(iter_data->hw_macaddr[i] ^ mac[i]);
192 + } else {
193 + memcpy(iter_data->hw_macaddr, mac, ETH_ALEN);
194 + iter_data->has_hw_macaddr = true;
195 + }
196
197 switch (vif->type) {
198 case NL80211_IFTYPE_AP:
199 @@ -891,7 +895,6 @@ void ath9k_calculate_iter_data(struct ie
200 * together with the BSSID mask when matching addresses.
201 */
202 memset(iter_data, 0, sizeof(*iter_data));
203 - iter_data->hw_macaddr = common->macaddr;
204 memset(&iter_data->mask, 0xff, ETH_ALEN);
205
206 if (vif)
207 @@ -901,6 +904,8 @@ void ath9k_calculate_iter_data(struct ie
208 ieee80211_iterate_active_interfaces_atomic(
209 sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
210 ath9k_vif_iter, iter_data);
211 +
212 + memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN);
213 }
214
215 /* Called with sc->mutex held. */
216 @@ -1327,6 +1332,7 @@ static int ath9k_sta_add(struct ieee8021
217 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
218 struct ath_node *an = (struct ath_node *) sta->drv_priv;
219 struct ieee80211_key_conf ps_key = { };
220 + int key;
221
222 ath_node_attach(sc, sta, vif);
223
224 @@ -1334,7 +1340,9 @@ static int ath9k_sta_add(struct ieee8021
225 vif->type != NL80211_IFTYPE_AP_VLAN)
226 return 0;
227
228 - an->ps_key = ath_key_config(common, vif, sta, &ps_key);
229 + key = ath_key_config(common, vif, sta, &ps_key);
230 + if (key > 0)
231 + an->ps_key = key;
232
233 return 0;
234 }
235 @@ -1351,6 +1359,7 @@ static void ath9k_del_ps_key(struct ath_
236 return;
237
238 ath_key_delete(common, &ps_key);
239 + an->ps_key = 0;
240 }
241
242 static int ath9k_sta_remove(struct ieee80211_hw *hw,
243 @@ -1678,6 +1687,7 @@ static int ath9k_ampdu_action(struct iee
244 u16 tid, u16 *ssn, u8 buf_size)
245 {
246 struct ath_softc *sc = hw->priv;
247 + bool flush = false;
248 int ret = 0;
249
250 local_bh_disable();
251 @@ -1694,12 +1704,14 @@ static int ath9k_ampdu_action(struct iee
252 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
253 ath9k_ps_restore(sc);
254 break;
255 - case IEEE80211_AMPDU_TX_STOP_CONT:
256 case IEEE80211_AMPDU_TX_STOP_FLUSH:
257 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
258 + flush = true;
259 + case IEEE80211_AMPDU_TX_STOP_CONT:
260 ath9k_ps_wakeup(sc);
261 ath_tx_aggr_stop(sc, sta, tid);
262 - ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
263 + if (!flush)
264 + ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
265 ath9k_ps_restore(sc);
266 break;
267 case IEEE80211_AMPDU_TX_OPERATIONAL:
268 @@ -2366,6 +2378,7 @@ struct ieee80211_ops ath9k_ops = {
269 .flush = ath9k_flush,
270 .tx_frames_pending = ath9k_tx_frames_pending,
271 .tx_last_beacon = ath9k_tx_last_beacon,
272 + .release_buffered_frames = ath9k_release_buffered_frames,
273 .get_stats = ath9k_get_stats,
274 .set_antenna = ath9k_set_antenna,
275 .get_antenna = ath9k_get_antenna,
276 --- a/drivers/net/wireless/ath/ath9k/reg.h
277 +++ b/drivers/net/wireless/ath/ath9k/reg.h
278 @@ -798,6 +798,10 @@
279 #define AR_SREV_REVISION_9485_10 0
280 #define AR_SREV_REVISION_9485_11 1
281 #define AR_SREV_VERSION_9340 0x300
282 +#define AR_SREV_REVISION_9340_10 0
283 +#define AR_SREV_REVISION_9340_11 1
284 +#define AR_SREV_REVISION_9340_12 2
285 +#define AR_SREV_REVISION_9340_13 3
286 #define AR_SREV_VERSION_9580 0x1C0
287 #define AR_SREV_REVISION_9580_10 4 /* AR9580 1.0 */
288 #define AR_SREV_VERSION_9462 0x280
289 @@ -897,6 +901,10 @@
290 #define AR_SREV_9340(_ah) \
291 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9340))
292
293 +#define AR_SREV_9340_13_OR_LATER(_ah) \
294 + (AR_SREV_9340((_ah)) && \
295 + ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9340_13))
296 +
297 #define AR_SREV_9285E_20(_ah) \
298 (AR_SREV_9285_12_OR_LATER(_ah) && \
299 ((REG_READ(_ah, AR_AN_SYNTH9) & 0x7) == 0x1))
300 @@ -1007,6 +1015,8 @@ enum {
301 AR_INTR_SYNC_LOCAL_TIMEOUT |
302 AR_INTR_SYNC_MAC_SLEEP_ACCESS),
303
304 + AR9340_INTR_SYNC_LOCAL_TIMEOUT = 0x00000010,
305 +
306 AR_INTR_SYNC_SPURIOUS = 0xFFFFFFFF,
307
308 };
309 @@ -1493,9 +1503,6 @@ enum {
310 #define AR9271_RADIO_RF_RST 0x20
311 #define AR9271_GATE_MAC_CTL 0x4000
312
313 -#define AR_STA_ID0 0x8000
314 -#define AR_STA_ID1 0x8004
315 -#define AR_STA_ID1_SADH_MASK 0x0000FFFF
316 #define AR_STA_ID1_STA_AP 0x00010000
317 #define AR_STA_ID1_ADHOC 0x00020000
318 #define AR_STA_ID1_PWR_SAV 0x00040000
319 @@ -1884,6 +1891,7 @@ enum {
320 #define AR_PCU_TXBUF_CTRL_SIZE_MASK 0x7FF
321 #define AR_PCU_TXBUF_CTRL_USABLE_SIZE 0x700
322 #define AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE 0x380
323 +#define AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE 0x500
324
325 #define AR_PCU_MISC_MODE2 0x8344
326 #define AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE 0x00000002
327 --- a/drivers/net/wireless/ath/hw.c
328 +++ b/drivers/net/wireless/ath/hw.c
329 @@ -118,6 +118,12 @@
330 void ath_hw_setbssidmask(struct ath_common *common)
331 {
332 void *ah = common->ah;
333 + u32 id1;
334 +
335 + REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
336 + id1 = REG_READ(ah, AR_STA_ID1) & ~AR_STA_ID1_SADH_MASK;
337 + id1 |= get_unaligned_le16(common->macaddr + 4);
338 + REG_WRITE(ah, AR_STA_ID1, id1);
339
340 REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask));
341 REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4));
342 --- a/drivers/net/wireless/ath/reg.h
343 +++ b/drivers/net/wireless/ath/reg.h
344 @@ -23,6 +23,10 @@
345 #define AR_MIBC_CMC 0x00000004
346 #define AR_MIBC_MCS 0x00000008
347
348 +#define AR_STA_ID0 0x8000
349 +#define AR_STA_ID1 0x8004
350 +#define AR_STA_ID1_SADH_MASK 0x0000ffff
351 +
352 /*
353 * BSSID mask registers. See ath_hw_set_bssid_mask()
354 * for detailed documentation about these registers.
355 --- a/drivers/net/wireless/iwlegacy/4965-mac.c
356 +++ b/drivers/net/wireless/iwlegacy/4965-mac.c
357 @@ -6059,7 +6059,7 @@ il4965_mac_channel_switch(struct ieee802
358 struct il_priv *il = hw->priv;
359 const struct il_channel_info *ch_info;
360 struct ieee80211_conf *conf = &hw->conf;
361 - struct ieee80211_channel *channel = ch_switch->channel;
362 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
363 struct il_ht_config *ht_conf = &il->current_ht_config;
364 u16 ch;
365
366 @@ -6096,23 +6096,21 @@ il4965_mac_channel_switch(struct ieee802
367 il->current_ht_config.smps = conf->smps_mode;
368
369 /* Configure HT40 channels */
370 - il->ht.enabled = conf_is_ht(conf);
371 - if (il->ht.enabled) {
372 - if (conf_is_ht40_minus(conf)) {
373 - il->ht.extension_chan_offset =
374 - IEEE80211_HT_PARAM_CHA_SEC_BELOW;
375 - il->ht.is_40mhz = true;
376 - } else if (conf_is_ht40_plus(conf)) {
377 - il->ht.extension_chan_offset =
378 - IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
379 - il->ht.is_40mhz = true;
380 - } else {
381 - il->ht.extension_chan_offset =
382 - IEEE80211_HT_PARAM_CHA_SEC_NONE;
383 - il->ht.is_40mhz = false;
384 - }
385 - } else
386 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
387 + case NL80211_CHAN_NO_HT:
388 + case NL80211_CHAN_HT20:
389 il->ht.is_40mhz = false;
390 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
391 + break;
392 + case NL80211_CHAN_HT40MINUS:
393 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
394 + il->ht.is_40mhz = true;
395 + break;
396 + case NL80211_CHAN_HT40PLUS:
397 + il->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
398 + il->ht.is_40mhz = true;
399 + break;
400 + }
401
402 if ((le16_to_cpu(il->staging.channel) != ch))
403 il->staging.flags = 0;
404 --- a/drivers/net/wireless/iwlegacy/4965.c
405 +++ b/drivers/net/wireless/iwlegacy/4965.c
406 @@ -1493,7 +1493,7 @@ il4965_hw_channel_switch(struct il_priv
407
408 cmd.band = band;
409 cmd.expect_beacon = 0;
410 - ch = ch_switch->channel->hw_value;
411 + ch = ch_switch->chandef.chan->hw_value;
412 cmd.channel = cpu_to_le16(ch);
413 cmd.rxon_flags = il->staging.flags;
414 cmd.rxon_filter_flags = il->staging.filter_flags;
415 --- a/drivers/net/wireless/iwlwifi/dvm/devices.c
416 +++ b/drivers/net/wireless/iwlwifi/dvm/devices.c
417 @@ -379,7 +379,7 @@ static int iwl5000_hw_channel_switch(str
418 };
419
420 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
421 - ch = ch_switch->channel->hw_value;
422 + ch = ch_switch->chandef.chan->hw_value;
423 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
424 ctx->active.channel, ch);
425 cmd.channel = cpu_to_le16(ch);
426 @@ -414,7 +414,8 @@ static int iwl5000_hw_channel_switch(str
427 }
428 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
429 cmd.switch_time);
430 - cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
431 + cmd.expect_beacon =
432 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
433
434 return iwl_dvm_send_cmd(priv, &hcmd);
435 }
436 @@ -540,7 +541,7 @@ static int iwl6000_hw_channel_switch(str
437 hcmd.data[0] = cmd;
438
439 cmd->band = priv->band == IEEE80211_BAND_2GHZ;
440 - ch = ch_switch->channel->hw_value;
441 + ch = ch_switch->chandef.chan->hw_value;
442 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
443 ctx->active.channel, ch);
444 cmd->channel = cpu_to_le16(ch);
445 @@ -575,7 +576,8 @@ static int iwl6000_hw_channel_switch(str
446 }
447 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
448 cmd->switch_time);
449 - cmd->expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
450 + cmd->expect_beacon =
451 + ch_switch->chandef.chan->flags & IEEE80211_CHAN_RADAR;
452
453 err = iwl_dvm_send_cmd(priv, &hcmd);
454 kfree(cmd);
455 --- a/drivers/net/wireless/iwlwifi/dvm/mac80211.c
456 +++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
457 @@ -970,7 +970,7 @@ static void iwlagn_mac_channel_switch(st
458 {
459 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
460 struct ieee80211_conf *conf = &hw->conf;
461 - struct ieee80211_channel *channel = ch_switch->channel;
462 + struct ieee80211_channel *channel = ch_switch->chandef.chan;
463 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
464 /*
465 * MULTI-FIXME
466 @@ -1008,11 +1008,21 @@ static void iwlagn_mac_channel_switch(st
467 priv->current_ht_config.smps = conf->smps_mode;
468
469 /* Configure HT40 channels */
470 - ctx->ht.enabled = conf_is_ht(conf);
471 - if (ctx->ht.enabled)
472 - iwlagn_config_ht40(conf, ctx);
473 - else
474 + switch (cfg80211_get_chandef_type(&ch_switch->chandef)) {
475 + case NL80211_CHAN_NO_HT:
476 + case NL80211_CHAN_HT20:
477 ctx->ht.is_40mhz = false;
478 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
479 + break;
480 + case NL80211_CHAN_HT40MINUS:
481 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
482 + ctx->ht.is_40mhz = true;
483 + break;
484 + case NL80211_CHAN_HT40PLUS:
485 + ctx->ht.extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
486 + ctx->ht.is_40mhz = true;
487 + break;
488 + }
489
490 if ((le16_to_cpu(ctx->staging.channel) != ch))
491 ctx->staging.flags = 0;
492 --- a/drivers/net/wireless/iwlwifi/dvm/rxon.c
493 +++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c
494 @@ -1160,7 +1160,7 @@ int iwlagn_commit_rxon(struct iwl_priv *
495 }
496
497 void iwlagn_config_ht40(struct ieee80211_conf *conf,
498 - struct iwl_rxon_context *ctx)
499 + struct iwl_rxon_context *ctx)
500 {
501 if (conf_is_ht40_minus(conf)) {
502 ctx->ht.extension_chan_offset =
503 --- a/drivers/net/wireless/mac80211_hwsim.c
504 +++ b/drivers/net/wireless/mac80211_hwsim.c
505 @@ -25,6 +25,7 @@
506 #include <linux/if_arp.h>
507 #include <linux/rtnetlink.h>
508 #include <linux/etherdevice.h>
509 +#include <linux/platform_device.h>
510 #include <linux/debugfs.h>
511 #include <linux/module.h>
512 #include <linux/ktime.h>
513 @@ -717,9 +718,17 @@ static bool mac80211_hwsim_tx_frame_no_n
514 rx_status.flag |= RX_FLAG_MACTIME_START;
515 rx_status.freq = chan->center_freq;
516 rx_status.band = chan->band;
517 - rx_status.rate_idx = info->control.rates[0].idx;
518 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
519 - rx_status.flag |= RX_FLAG_HT;
520 + if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
521 + rx_status.rate_idx =
522 + ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
523 + rx_status.vht_nss =
524 + ieee80211_rate_get_vht_nss(&info->control.rates[0]);
525 + rx_status.flag |= RX_FLAG_VHT;
526 + } else {
527 + rx_status.rate_idx = info->control.rates[0].idx;
528 + if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
529 + rx_status.flag |= RX_FLAG_HT;
530 + }
531 if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
532 rx_status.flag |= RX_FLAG_40MHZ;
533 if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
534 @@ -1687,6 +1696,7 @@ static void mac80211_hwsim_free(void)
535 debugfs_remove(data->debugfs_ps);
536 debugfs_remove(data->debugfs);
537 ieee80211_unregister_hw(data->hw);
538 + device_release_driver(data->dev);
539 device_unregister(data->dev);
540 ieee80211_free_hw(data->hw);
541 }
542 @@ -1695,7 +1705,9 @@ static void mac80211_hwsim_free(void)
543
544
545 static struct device_driver mac80211_hwsim_driver = {
546 - .name = "mac80211_hwsim"
547 + .name = "mac80211_hwsim",
548 + .bus = &platform_bus_type,
549 + .owner = THIS_MODULE,
550 };
551
552 static const struct net_device_ops hwsim_netdev_ops = {
553 @@ -2187,9 +2199,15 @@ static int __init init_mac80211_hwsim(vo
554 spin_lock_init(&hwsim_radio_lock);
555 INIT_LIST_HEAD(&hwsim_radios);
556
557 + err = driver_register(&mac80211_hwsim_driver);
558 + if (err)
559 + return err;
560 +
561 hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
562 - if (IS_ERR(hwsim_class))
563 - return PTR_ERR(hwsim_class);
564 + if (IS_ERR(hwsim_class)) {
565 + err = PTR_ERR(hwsim_class);
566 + goto failed_unregister_driver;
567 + }
568
569 memset(addr, 0, ETH_ALEN);
570 addr[0] = 0x02;
571 @@ -2211,12 +2229,20 @@ static int __init init_mac80211_hwsim(vo
572 "hwsim%d", i);
573 if (IS_ERR(data->dev)) {
574 printk(KERN_DEBUG
575 - "mac80211_hwsim: device_create "
576 - "failed (%ld)\n", PTR_ERR(data->dev));
577 + "mac80211_hwsim: device_create failed (%ld)\n",
578 + PTR_ERR(data->dev));
579 err = -ENOMEM;
580 goto failed_drvdata;
581 }
582 data->dev->driver = &mac80211_hwsim_driver;
583 + err = device_bind_driver(data->dev);
584 + if (err != 0) {
585 + printk(KERN_DEBUG
586 + "mac80211_hwsim: device_bind_driver failed (%d)\n",
587 + err);
588 + goto failed_hw;
589 + }
590 +
591 skb_queue_head_init(&data->pending);
592
593 SET_IEEE80211_DEV(hw, data->dev);
594 @@ -2515,6 +2541,8 @@ failed_drvdata:
595 ieee80211_free_hw(hw);
596 failed:
597 mac80211_hwsim_free();
598 +failed_unregister_driver:
599 + driver_unregister(&mac80211_hwsim_driver);
600 return err;
601 }
602 module_init(init_mac80211_hwsim);
603 @@ -2527,5 +2555,6 @@ static void __exit exit_mac80211_hwsim(v
604
605 mac80211_hwsim_free();
606 unregister_netdev(hwsim_mon);
607 + driver_unregister(&mac80211_hwsim_driver);
608 }
609 module_exit(exit_mac80211_hwsim);
610 --- a/drivers/net/wireless/ti/wl12xx/cmd.c
611 +++ b/drivers/net/wireless/ti/wl12xx/cmd.c
612 @@ -301,7 +301,7 @@ int wl12xx_cmd_channel_switch(struct wl1
613 }
614
615 cmd->role_id = wlvif->role_id;
616 - cmd->channel = ch_switch->channel->hw_value;
617 + cmd->channel = ch_switch->chandef.chan->hw_value;
618 cmd->switch_time = ch_switch->count;
619 cmd->stop_tx = ch_switch->block_tx;
620
621 --- a/drivers/net/wireless/ti/wl18xx/cmd.c
622 +++ b/drivers/net/wireless/ti/wl18xx/cmd.c
623 @@ -42,11 +42,11 @@ int wl18xx_cmd_channel_switch(struct wl1
624 }
625
626 cmd->role_id = wlvif->role_id;
627 - cmd->channel = ch_switch->channel->hw_value;
628 + cmd->channel = ch_switch->chandef.chan->hw_value;
629 cmd->switch_time = ch_switch->count;
630 cmd->stop_tx = ch_switch->block_tx;
631
632 - switch (ch_switch->channel->band) {
633 + switch (ch_switch->chandef.chan->band) {
634 case IEEE80211_BAND_2GHZ:
635 cmd->band = WLCORE_BAND_2_4GHZ;
636 break;
637 @@ -55,7 +55,7 @@ int wl18xx_cmd_channel_switch(struct wl1
638 break;
639 default:
640 wl1271_error("invalid channel switch band: %d",
641 - ch_switch->channel->band);
642 + ch_switch->chandef.chan->band);
643 ret = -EINVAL;
644 goto out_free;
645 }
646 --- a/include/linux/ieee80211.h
647 +++ b/include/linux/ieee80211.h
648 @@ -673,6 +673,36 @@ struct ieee80211_channel_sw_ie {
649 } __packed;
650
651 /**
652 + * struct ieee80211_ext_chansw_ie
653 + *
654 + * This structure represents the "Extended Channel Switch Announcement element"
655 + */
656 +struct ieee80211_ext_chansw_ie {
657 + u8 mode;
658 + u8 new_operating_class;
659 + u8 new_ch_num;
660 + u8 count;
661 +} __packed;
662 +
663 +/**
664 + * struct ieee80211_sec_chan_offs_ie - secondary channel offset IE
665 + * @sec_chan_offs: secondary channel offset, uses IEEE80211_HT_PARAM_CHA_SEC_*
666 + * values here
667 + * This structure represents the "Secondary Channel Offset element"
668 + */
669 +struct ieee80211_sec_chan_offs_ie {
670 + u8 sec_chan_offs;
671 +} __packed;
672 +
673 +/**
674 + * struct ieee80211_wide_bw_chansw_ie - wide bandwidth channel switch IE
675 + */
676 +struct ieee80211_wide_bw_chansw_ie {
677 + u8 new_channel_width;
678 + u8 new_center_freq_seg0, new_center_freq_seg1;
679 +} __packed;
680 +
681 +/**
682 * struct ieee80211_tim
683 *
684 * This structure refers to "Traffic Indication Map information element"
685 @@ -840,12 +870,15 @@ struct ieee80211_mgmt {
686 } __packed wme_action;
687 struct{
688 u8 action_code;
689 - u8 element_id;
690 - u8 length;
691 - struct ieee80211_channel_sw_ie sw_elem;
692 + u8 variable[0];
693 } __packed chan_switch;
694 struct{
695 u8 action_code;
696 + struct ieee80211_ext_chansw_ie data;
697 + u8 variable[0];
698 + } __packed ext_chan_switch;
699 + struct{
700 + u8 action_code;
701 u8 dialog_token;
702 u8 element_id;
703 u8 length;
704 @@ -1638,6 +1671,7 @@ enum ieee80211_eid {
705
706 WLAN_EID_HT_CAPABILITY = 45,
707 WLAN_EID_HT_OPERATION = 61,
708 + WLAN_EID_SECONDARY_CHANNEL_OFFSET = 62,
709
710 WLAN_EID_RSN = 48,
711 WLAN_EID_MMIE = 76,
712 @@ -1672,6 +1706,8 @@ enum ieee80211_eid {
713 WLAN_EID_VHT_CAPABILITY = 191,
714 WLAN_EID_VHT_OPERATION = 192,
715 WLAN_EID_OPMODE_NOTIF = 199,
716 + WLAN_EID_WIDE_BW_CHANNEL_SWITCH = 194,
717 + WLAN_EID_CHANNEL_SWITCH_WRAPPER = 196,
718
719 /* 802.11ad */
720 WLAN_EID_NON_TX_BSSID_CAP = 83,
721 @@ -1795,6 +1831,7 @@ enum ieee80211_key_len {
722
723 /* Public action codes */
724 enum ieee80211_pub_actioncode {
725 + WLAN_PUB_ACTION_EXT_CHANSW_ANN = 4,
726 WLAN_PUB_ACTION_TDLS_DISCOVER_RES = 14,
727 };
728
729 --- a/include/net/cfg80211.h
730 +++ b/include/net/cfg80211.h
731 @@ -753,6 +753,8 @@ int cfg80211_check_station_change(struct
732 * @STATION_INFO_LOCAL_PM: @local_pm filled
733 * @STATION_INFO_PEER_PM: @peer_pm filled
734 * @STATION_INFO_NONPEER_PM: @nonpeer_pm filled
735 + * @STATION_INFO_CHAIN_SIGNAL: @chain_signal filled
736 + * @STATION_INFO_CHAIN_SIGNAL_AVG: @chain_signal_avg filled
737 */
738 enum station_info_flags {
739 STATION_INFO_INACTIVE_TIME = 1<<0,
740 @@ -781,6 +783,8 @@ enum station_info_flags {
741 STATION_INFO_NONPEER_PM = 1<<23,
742 STATION_INFO_RX_BYTES64 = 1<<24,
743 STATION_INFO_TX_BYTES64 = 1<<25,
744 + STATION_INFO_CHAIN_SIGNAL = 1<<26,
745 + STATION_INFO_CHAIN_SIGNAL_AVG = 1<<27,
746 };
747
748 /**
749 @@ -857,6 +861,8 @@ struct sta_bss_parameters {
750 u16 beacon_interval;
751 };
752
753 +#define IEEE80211_MAX_CHAINS 4
754 +
755 /**
756 * struct station_info - station information
757 *
758 @@ -874,6 +880,9 @@ struct sta_bss_parameters {
759 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
760 * @signal_avg: Average signal strength, type depends on the wiphy's signal_type.
761 * For CFG80211_SIGNAL_TYPE_MBM, value is expressed in _dBm_.
762 + * @chains: bitmask for filled values in @chain_signal, @chain_signal_avg
763 + * @chain_signal: per-chain signal strength of last received packet in dBm
764 + * @chain_signal_avg: per-chain signal strength average in dBm
765 * @txrate: current unicast bitrate from this station
766 * @rxrate: current unicast bitrate to this station
767 * @rx_packets: packets received from this station
768 @@ -909,6 +918,11 @@ struct station_info {
769 u8 plink_state;
770 s8 signal;
771 s8 signal_avg;
772 +
773 + u8 chains;
774 + s8 chain_signal[IEEE80211_MAX_CHAINS];
775 + s8 chain_signal_avg[IEEE80211_MAX_CHAINS];
776 +
777 struct rate_info txrate;
778 struct rate_info rxrate;
779 u32 rx_packets;
780 @@ -954,6 +968,7 @@ enum monitor_flags {
781 MONITOR_FLAG_CONTROL = 1<<NL80211_MNTR_FLAG_CONTROL,
782 MONITOR_FLAG_OTHER_BSS = 1<<NL80211_MNTR_FLAG_OTHER_BSS,
783 MONITOR_FLAG_COOK_FRAMES = 1<<NL80211_MNTR_FLAG_COOK_FRAMES,
784 + MONITOR_FLAG_ACTIVE = 1<<NL80211_MNTR_FLAG_ACTIVE,
785 };
786
787 /**
788 @@ -4027,6 +4042,17 @@ bool cfg80211_reg_can_beacon(struct wiph
789 void cfg80211_ch_switch_notify(struct net_device *dev,
790 struct cfg80211_chan_def *chandef);
791
792 +/**
793 + * ieee80211_operating_class_to_band - convert operating class to band
794 + *
795 + * @operating_class: the operating class to convert
796 + * @band: band pointer to fill
797 + *
798 + * Returns %true if the conversion was successful, %false otherwise.
799 + */
800 +bool ieee80211_operating_class_to_band(u8 operating_class,
801 + enum ieee80211_band *band);
802 +
803 /*
804 * cfg80211_tdls_oper_request - request userspace to perform TDLS operation
805 * @dev: the device on which the operation is requested
806 --- a/include/net/mac80211.h
807 +++ b/include/net/mac80211.h
808 @@ -210,7 +210,7 @@ struct ieee80211_chanctx_conf {
809 * @BSS_CHANGED_QOS: QoS for this association was enabled/disabled. Note
810 * that it is only ever disabled for station mode.
811 * @BSS_CHANGED_IDLE: Idle changed for this BSS/interface.
812 - * @BSS_CHANGED_SSID: SSID changed for this BSS (AP mode)
813 + * @BSS_CHANGED_SSID: SSID changed for this BSS (AP and IBSS mode)
814 * @BSS_CHANGED_AP_PROBE_RESP: Probe Response changed for this BSS (AP mode)
815 * @BSS_CHANGED_PS: PS changed for this BSS (STA mode)
816 * @BSS_CHANGED_TXPOWER: TX power setting changed for this interface
817 @@ -327,7 +327,7 @@ enum ieee80211_rssi_event {
818 * your driver/device needs to do.
819 * @ps: power-save mode (STA only). This flag is NOT affected by
820 * offchannel/dynamic_ps operations.
821 - * @ssid: The SSID of the current vif. Only valid in AP-mode.
822 + * @ssid: The SSID of the current vif. Valid in AP and IBSS mode.
823 * @ssid_len: Length of SSID given in @ssid.
824 * @hidden_ssid: The SSID of the current vif is hidden. Only valid in AP-mode.
825 * @txpower: TX power in dBm
826 @@ -459,6 +459,8 @@ struct ieee80211_bss_conf {
827 * @IEEE80211_TX_CTL_DONTFRAG: Don't fragment this packet even if it
828 * would be fragmented by size (this is optional, only used for
829 * monitor injection).
830 + * @IEEE80211_TX_CTL_PS_RESPONSE: This frame is a response to a poll
831 + * frame (PS-Poll or uAPSD).
832 *
833 * Note: If you have to add new flags to the enumeration, then don't
834 * forget to update %IEEE80211_TX_TEMPORARY_FLAGS when necessary.
835 @@ -494,6 +496,7 @@ enum mac80211_tx_control_flags {
836 IEEE80211_TX_STATUS_EOSP = BIT(28),
837 IEEE80211_TX_CTL_USE_MINRATE = BIT(29),
838 IEEE80211_TX_CTL_DONTFRAG = BIT(30),
839 + IEEE80211_TX_CTL_PS_RESPONSE = BIT(31),
840 };
841
842 #define IEEE80211_TX_CTL_STBC_SHIFT 23
843 @@ -562,6 +565,9 @@ enum mac80211_rate_control_flags {
844 /* maximum number of rate stages */
845 #define IEEE80211_TX_MAX_RATES 4
846
847 +/* maximum number of rate table entries */
848 +#define IEEE80211_TX_RATE_TABLE_SIZE 4
849 +
850 /**
851 * struct ieee80211_tx_rate - rate selection/status
852 *
853 @@ -602,8 +608,8 @@ static inline void ieee80211_rate_set_vh
854 u8 mcs, u8 nss)
855 {
856 WARN_ON(mcs & ~0xF);
857 - WARN_ON(nss & ~0x7);
858 - rate->idx = (nss << 4) | mcs;
859 + WARN_ON((nss - 1) & ~0x7);
860 + rate->idx = ((nss - 1) << 4) | mcs;
861 }
862
863 static inline u8
864 @@ -615,7 +621,7 @@ ieee80211_rate_get_vht_mcs(const struct
865 static inline u8
866 ieee80211_rate_get_vht_nss(const struct ieee80211_tx_rate *rate)
867 {
868 - return rate->idx >> 4;
869 + return (rate->idx >> 4) + 1;
870 }
871
872 /**
873 @@ -656,7 +662,11 @@ struct ieee80211_tx_info {
874 struct ieee80211_tx_rate rates[
875 IEEE80211_TX_MAX_RATES];
876 s8 rts_cts_rate_idx;
877 - /* 3 bytes free */
878 + u8 use_rts:1;
879 + u8 use_cts_prot:1;
880 + u8 short_preamble:1;
881 + u8 skip_table:1;
882 + /* 2 bytes free */
883 };
884 /* only needed before rate control */
885 unsigned long jiffies;
886 @@ -677,6 +687,8 @@ struct ieee80211_tx_info {
887 struct {
888 struct ieee80211_tx_rate driver_rates[
889 IEEE80211_TX_MAX_RATES];
890 + u8 pad[4];
891 +
892 void *rate_driver_data[
893 IEEE80211_TX_INFO_RATE_DRIVER_DATA_SIZE / sizeof(void *)];
894 };
895 @@ -840,6 +852,9 @@ enum mac80211_rx_flags {
896 * @signal: signal strength when receiving this frame, either in dBm, in dB or
897 * unspecified depending on the hardware capabilities flags
898 * @IEEE80211_HW_SIGNAL_*
899 + * @chains: bitmask of receive chains for which separate signal strength
900 + * values were filled.
901 + * @chain_signal: per-chain signal strength, same format as @signal
902 * @antenna: antenna used
903 * @rate_idx: index of data rate into band's supported rates or MCS index if
904 * HT or VHT is used (%RX_FLAG_HT/%RX_FLAG_VHT)
905 @@ -871,6 +886,8 @@ struct ieee80211_rx_status {
906 u8 band;
907 u8 antenna;
908 s8 signal;
909 + u8 chains;
910 + s8 chain_signal[IEEE80211_MAX_CHAINS];
911 u8 ampdu_delimiter_crc;
912 u8 vendor_radiotap_align;
913 u8 vendor_radiotap_oui[3];
914 @@ -1018,13 +1035,13 @@ struct ieee80211_conf {
915 * the driver passed into mac80211.
916 * @block_tx: Indicates whether transmission must be blocked before the
917 * scheduled channel switch, as indicated by the AP.
918 - * @channel: the new channel to switch to
919 + * @chandef: the new channel to switch to
920 * @count: the number of TBTT's until the channel switch event
921 */
922 struct ieee80211_channel_switch {
923 u64 timestamp;
924 bool block_tx;
925 - struct ieee80211_channel *channel;
926 + struct cfg80211_chan_def chandef;
927 u8 count;
928 };
929
930 @@ -1222,6 +1239,24 @@ enum ieee80211_sta_rx_bandwidth {
931 };
932
933 /**
934 + * struct ieee80211_sta_rates - station rate selection table
935 + *
936 + * @rcu_head: RCU head used for freeing the table on update
937 + * @rates: transmit rates/flags to be used by default.
938 + * Overriding entries per-packet is possible by using cb tx control.
939 + */
940 +struct ieee80211_sta_rates {
941 + struct rcu_head rcu_head;
942 + struct {
943 + s8 idx;
944 + u8 count;
945 + u8 count_cts;
946 + u8 count_rts;
947 + u16 flags;
948 + } rate[IEEE80211_TX_RATE_TABLE_SIZE];
949 +};
950 +
951 +/**
952 * struct ieee80211_sta - station table entry
953 *
954 * A station table entry represents a station we are possibly
955 @@ -1248,6 +1283,7 @@ enum ieee80211_sta_rx_bandwidth {
956 * notifications and capabilities. The value is only valid after
957 * the station moves to associated state.
958 * @smps_mode: current SMPS mode (off, static or dynamic)
959 + * @tx_rates: rate control selection table
960 */
961 struct ieee80211_sta {
962 u32 supp_rates[IEEE80211_NUM_BANDS];
963 @@ -1261,6 +1297,7 @@ struct ieee80211_sta {
964 u8 rx_nss;
965 enum ieee80211_sta_rx_bandwidth bandwidth;
966 enum ieee80211_smps_mode smps_mode;
967 + struct ieee80211_sta_rates __rcu *rates;
968
969 /* must be last */
970 u8 drv_priv[0] __aligned(sizeof(void *));
971 @@ -1416,6 +1453,9 @@ struct ieee80211_tx_control {
972 * for different virtual interfaces. See the doc section on HW queue
973 * control for more details.
974 *
975 + * @IEEE80211_HW_SUPPORTS_RC_TABLE: The driver supports using a rate
976 + * selection table provided by the rate control algorithm.
977 + *
978 * @IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF: Use the P2P Device address for any
979 * P2P Interface. This will be honoured even if more than one interface
980 * is supported.
981 @@ -1448,6 +1488,7 @@ enum ieee80211_hw_flags {
982 IEEE80211_HW_SUPPORTS_PER_STA_GTK = 1<<21,
983 IEEE80211_HW_AP_LINK_PS = 1<<22,
984 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW = 1<<23,
985 + IEEE80211_HW_SUPPORTS_RC_TABLE = 1<<24,
986 IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF = 1<<25,
987 IEEE80211_HW_TIMING_BEACON_ONLY = 1<<26,
988 };
989 @@ -3144,6 +3185,25 @@ void ieee80211_sta_set_buffered(struct i
990 u8 tid, bool buffered);
991
992 /**
993 + * ieee80211_get_tx_rates - get the selected transmit rates for a packet
994 + *
995 + * Call this function in a driver with per-packet rate selection support
996 + * to combine the rate info in the packet tx info with the most recent
997 + * rate selection table for the station entry.
998 + *
999 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
1000 + * @sta: the receiver station to which this packet is sent.
1001 + * @skb: the frame to be transmitted.
1002 + * @dest: buffer for extracted rate/retry information
1003 + * @max_rates: maximum number of rates to fetch
1004 + */
1005 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
1006 + struct ieee80211_sta *sta,
1007 + struct sk_buff *skb,
1008 + struct ieee80211_tx_rate *dest,
1009 + int max_rates);
1010 +
1011 +/**
1012 * ieee80211_tx_status - transmit status callback
1013 *
1014 * Call this function for all transmitted frames after they have been
1015 @@ -4118,7 +4178,7 @@ void ieee80211_send_bar(struct ieee80211
1016 * (deprecated; this will be removed once drivers get updated to use
1017 * rate_idx_mask)
1018 * @rate_idx_mask: user-requested (legacy) rate mask
1019 - * @rate_idx_mcs_mask: user-requested MCS rate mask
1020 + * @rate_idx_mcs_mask: user-requested MCS rate mask (NULL if not in use)
1021 * @bss: whether this frame is sent out in AP or IBSS mode
1022 */
1023 struct ieee80211_tx_rate_control {
1024 @@ -4130,7 +4190,7 @@ struct ieee80211_tx_rate_control {
1025 bool rts, short_preamble;
1026 u8 max_rate_idx;
1027 u32 rate_idx_mask;
1028 - u8 rate_idx_mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
1029 + u8 *rate_idx_mcs_mask;
1030 bool bss;
1031 };
1032
1033 @@ -4219,6 +4279,22 @@ bool rate_usable_index_exists(struct iee
1034 return false;
1035 }
1036
1037 +/**
1038 + * rate_control_set_rates - pass the sta rate selection to mac80211/driver
1039 + *
1040 + * When not doing a rate control probe to test rates, rate control should pass
1041 + * its rate selection to mac80211. If the driver supports receiving a station
1042 + * rate table, it will use it to ensure that frames are always sent based on
1043 + * the most recent rate control module decision.
1044 + *
1045 + * @hw: pointer as obtained from ieee80211_alloc_hw()
1046 + * @pubsta: &struct ieee80211_sta pointer to the target destination.
1047 + * @rates: new tx rate set to be used for this station.
1048 + */
1049 +int rate_control_set_rates(struct ieee80211_hw *hw,
1050 + struct ieee80211_sta *pubsta,
1051 + struct ieee80211_sta_rates *rates);
1052 +
1053 int ieee80211_rate_control_register(struct rate_control_ops *ops);
1054 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
1055
1056 --- a/net/mac80211/agg-rx.c
1057 +++ b/net/mac80211/agg-rx.c
1058 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
1059 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1060 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1061 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
1062 + else if (sdata->vif.type == NL80211_IFTYPE_WDS)
1063 + memcpy(mgmt->bssid, da, ETH_ALEN);
1064
1065 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1066 IEEE80211_STYPE_ACTION);
1067 --- a/net/mac80211/agg-tx.c
1068 +++ b/net/mac80211/agg-tx.c
1069 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
1070 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
1071 if (sdata->vif.type == NL80211_IFTYPE_AP ||
1072 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1073 - sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
1074 + sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
1075 + sdata->vif.type == NL80211_IFTYPE_WDS)
1076 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
1077 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
1078 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
1079 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
1080 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1081 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1082 sdata->vif.type != NL80211_IFTYPE_AP &&
1083 + sdata->vif.type != NL80211_IFTYPE_WDS &&
1084 sdata->vif.type != NL80211_IFTYPE_ADHOC)
1085 return -EINVAL;
1086
1087 --- a/net/mac80211/cfg.c
1088 +++ b/net/mac80211/cfg.c
1089 @@ -73,16 +73,19 @@ static int ieee80211_change_iface(struct
1090 struct ieee80211_local *local = sdata->local;
1091
1092 if (ieee80211_sdata_running(sdata)) {
1093 + u32 mask = MONITOR_FLAG_COOK_FRAMES |
1094 + MONITOR_FLAG_ACTIVE;
1095 +
1096 /*
1097 - * Prohibit MONITOR_FLAG_COOK_FRAMES to be
1098 - * changed while the interface is up.
1099 + * Prohibit MONITOR_FLAG_COOK_FRAMES and
1100 + * MONITOR_FLAG_ACTIVE to be changed while the
1101 + * interface is up.
1102 * Else we would need to add a lot of cruft
1103 * to update everything:
1104 * cooked_mntrs, monitor and all fif_* counters
1105 * reconfigure hardware
1106 */
1107 - if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
1108 - (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1109 + if ((*flags & mask) != (sdata->u.mntr_flags & mask))
1110 return -EBUSY;
1111
1112 ieee80211_adjust_monitor_flags(sdata, -1);
1113 @@ -444,7 +447,7 @@ static void sta_set_sinfo(struct sta_inf
1114 struct ieee80211_local *local = sdata->local;
1115 struct timespec uptime;
1116 u64 packets = 0;
1117 - int ac;
1118 + int i, ac;
1119
1120 sinfo->generation = sdata->local->sta_generation;
1121
1122 @@ -488,6 +491,17 @@ static void sta_set_sinfo(struct sta_inf
1123 sinfo->signal = (s8)sta->last_signal;
1124 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
1125 }
1126 + if (sta->chains) {
1127 + sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
1128 + STATION_INFO_CHAIN_SIGNAL_AVG;
1129 +
1130 + sinfo->chains = sta->chains;
1131 + for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
1132 + sinfo->chain_signal[i] = sta->chain_signal_last[i];
1133 + sinfo->chain_signal_avg[i] =
1134 + (s8) -ewma_read(&sta->chain_signal_avg[i]);
1135 + }
1136 + }
1137
1138 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
1139 sta_set_rate_info_rx(sta, &sinfo->rxrate);
1140 @@ -1052,6 +1066,7 @@ static int ieee80211_stop_ap(struct wiph
1141 ieee80211_free_keys(sdata);
1142
1143 sdata->vif.bss_conf.enable_beacon = false;
1144 + sdata->vif.bss_conf.ssid_len = 0;
1145 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1146 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
1147
1148 @@ -2416,9 +2431,22 @@ static int ieee80211_set_bitrate_mask(st
1149 }
1150
1151 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1152 + struct ieee80211_supported_band *sband = wiphy->bands[i];
1153 + int j;
1154 +
1155 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1156 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1157 sizeof(mask->control[i].mcs));
1158 +
1159 + sdata->rc_has_mcs_mask[i] = false;
1160 + if (!sband)
1161 + continue;
1162 +
1163 + for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
1164 + if (~sdata->rc_rateidx_mcs_mask[i][j]) {
1165 + sdata->rc_has_mcs_mask[i] = true;
1166 + break;
1167 + }
1168 }
1169
1170 return 0;
1171 --- a/net/mac80211/chan.c
1172 +++ b/net/mac80211/chan.c
1173 @@ -57,6 +57,22 @@ ieee80211_find_chanctx(struct ieee80211_
1174 return NULL;
1175 }
1176
1177 +static bool ieee80211_is_radar_required(struct ieee80211_local *local)
1178 +{
1179 + struct ieee80211_sub_if_data *sdata;
1180 +
1181 + rcu_read_lock();
1182 + list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1183 + if (sdata->radar_required) {
1184 + rcu_read_unlock();
1185 + return true;
1186 + }
1187 + }
1188 + rcu_read_unlock();
1189 +
1190 + return false;
1191 +}
1192 +
1193 static struct ieee80211_chanctx *
1194 ieee80211_new_chanctx(struct ieee80211_local *local,
1195 const struct cfg80211_chan_def *chandef,
1196 @@ -76,6 +92,9 @@ ieee80211_new_chanctx(struct ieee80211_l
1197 ctx->conf.rx_chains_static = 1;
1198 ctx->conf.rx_chains_dynamic = 1;
1199 ctx->mode = mode;
1200 + ctx->conf.radar_enabled = ieee80211_is_radar_required(local);
1201 + if (!local->use_chanctx)
1202 + local->hw.conf.radar_enabled = ctx->conf.radar_enabled;
1203
1204 /* acquire mutex to prevent idle from changing */
1205 mutex_lock(&local->mtx);
1206 @@ -110,6 +129,7 @@ ieee80211_new_chanctx(struct ieee80211_l
1207 static void ieee80211_free_chanctx(struct ieee80211_local *local,
1208 struct ieee80211_chanctx *ctx)
1209 {
1210 + bool check_single_channel = false;
1211 lockdep_assert_held(&local->chanctx_mtx);
1212
1213 WARN_ON_ONCE(ctx->refcount != 0);
1214 @@ -119,6 +139,14 @@ static void ieee80211_free_chanctx(struc
1215 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1216 chandef->center_freq1 = chandef->chan->center_freq;
1217 chandef->center_freq2 = 0;
1218 +
1219 + /* NOTE: Disabling radar is only valid here for
1220 + * single channel context. To be sure, check it ...
1221 + */
1222 + if (local->hw.conf.radar_enabled)
1223 + check_single_channel = true;
1224 + local->hw.conf.radar_enabled = false;
1225 +
1226 ieee80211_hw_config(local, 0);
1227 } else {
1228 drv_remove_chanctx(local, ctx);
1229 @@ -127,6 +155,9 @@ static void ieee80211_free_chanctx(struc
1230 list_del_rcu(&ctx->list);
1231 kfree_rcu(ctx, rcu_head);
1232
1233 + /* throw a warning if this wasn't the only channel context. */
1234 + WARN_ON(check_single_channel && !list_empty(&local->chanctx_list));
1235 +
1236 mutex_lock(&local->mtx);
1237 ieee80211_recalc_idle(local);
1238 mutex_unlock(&local->mtx);
1239 @@ -238,19 +269,11 @@ static void __ieee80211_vif_release_chan
1240 void ieee80211_recalc_radar_chanctx(struct ieee80211_local *local,
1241 struct ieee80211_chanctx *chanctx)
1242 {
1243 - struct ieee80211_sub_if_data *sdata;
1244 - bool radar_enabled = false;
1245 + bool radar_enabled;
1246
1247 lockdep_assert_held(&local->chanctx_mtx);
1248
1249 - rcu_read_lock();
1250 - list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1251 - if (sdata->radar_required) {
1252 - radar_enabled = true;
1253 - break;
1254 - }
1255 - }
1256 - rcu_read_unlock();
1257 + radar_enabled = ieee80211_is_radar_required(local);
1258
1259 if (radar_enabled == chanctx->conf.radar_enabled)
1260 return;
1261 --- a/net/mac80211/debugfs_sta.c
1262 +++ b/net/mac80211/debugfs_sta.c
1263 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
1264 test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
1265
1266 int res = scnprintf(buf, sizeof(buf),
1267 - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1268 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1269 TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
1270 TEST(PS_DRIVER), TEST(AUTHORIZED),
1271 TEST(SHORT_PREAMBLE),
1272 - TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
1273 + TEST(WME), TEST(CLEAR_PS_FILT),
1274 TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
1275 TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
1276 TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
1277 --- a/net/mac80211/ibss.c
1278 +++ b/net/mac80211/ibss.c
1279 @@ -209,6 +209,8 @@ static void __ieee80211_sta_join_ibss(st
1280 sdata->vif.bss_conf.enable_beacon = true;
1281 sdata->vif.bss_conf.beacon_int = beacon_int;
1282 sdata->vif.bss_conf.basic_rates = basic_rates;
1283 + sdata->vif.bss_conf.ssid_len = ifibss->ssid_len;
1284 + memcpy(sdata->vif.bss_conf.ssid, ifibss->ssid, ifibss->ssid_len);
1285 bss_change = BSS_CHANGED_BEACON_INT;
1286 bss_change |= ieee80211_reset_erp_info(sdata);
1287 bss_change |= BSS_CHANGED_BSSID;
1288 @@ -217,6 +219,7 @@ static void __ieee80211_sta_join_ibss(st
1289 bss_change |= BSS_CHANGED_BASIC_RATES;
1290 bss_change |= BSS_CHANGED_HT;
1291 bss_change |= BSS_CHANGED_IBSS;
1292 + bss_change |= BSS_CHANGED_SSID;
1293
1294 /*
1295 * In 5 GHz/802.11a, we can always use short slot time.
1296 @@ -911,7 +914,7 @@ void ieee80211_rx_mgmt_probe_beacon(stru
1297 return;
1298
1299 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1300 - &elems);
1301 + false, &elems);
1302
1303 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
1304 }
1305 @@ -1159,6 +1162,7 @@ int ieee80211_ibss_leave(struct ieee8021
1306 sdata->vif.bss_conf.ibss_joined = false;
1307 sdata->vif.bss_conf.ibss_creator = false;
1308 sdata->vif.bss_conf.enable_beacon = false;
1309 + sdata->vif.bss_conf.ssid_len = 0;
1310 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
1311 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
1312 BSS_CHANGED_IBSS);
1313 --- a/net/mac80211/ieee80211_i.h
1314 +++ b/net/mac80211/ieee80211_i.h
1315 @@ -156,6 +156,7 @@ struct ieee80211_tx_data {
1316 struct ieee80211_sub_if_data *sdata;
1317 struct sta_info *sta;
1318 struct ieee80211_key *key;
1319 + struct ieee80211_tx_rate rate;
1320
1321 unsigned int flags;
1322 };
1323 @@ -740,6 +741,8 @@ struct ieee80211_sub_if_data {
1324
1325 /* bitmap of allowed (non-MCS) rate indexes for rate control */
1326 u32 rc_rateidx_mask[IEEE80211_NUM_BANDS];
1327 +
1328 + bool rc_has_mcs_mask[IEEE80211_NUM_BANDS];
1329 u8 rc_rateidx_mcs_mask[IEEE80211_NUM_BANDS][IEEE80211_HT_MCS_MASK_LEN];
1330
1331 union {
1332 @@ -1025,7 +1028,7 @@ struct ieee80211_local {
1333 enum mac80211_scan_state next_scan_state;
1334 struct delayed_work scan_work;
1335 struct ieee80211_sub_if_data __rcu *scan_sdata;
1336 - struct ieee80211_channel *csa_channel;
1337 + struct cfg80211_chan_def csa_chandef;
1338 /* For backward compatibility only -- do not use */
1339 struct cfg80211_chan_def _oper_chandef;
1340
1341 @@ -1184,10 +1187,13 @@ struct ieee802_11_elems {
1342 const u8 *perr;
1343 const struct ieee80211_rann_ie *rann;
1344 const struct ieee80211_channel_sw_ie *ch_switch_ie;
1345 + const struct ieee80211_ext_chansw_ie *ext_chansw_ie;
1346 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1347 const u8 *country_elem;
1348 const u8 *pwr_constr_elem;
1349 const struct ieee80211_timeout_interval_ie *timeout_int;
1350 const u8 *opmode_notif;
1351 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1352
1353 /* length of them, respectively */
1354 u8 ssid_len;
1355 @@ -1258,10 +1264,6 @@ void ieee80211_recalc_ps_vif(struct ieee
1356 int ieee80211_max_network_latency(struct notifier_block *nb,
1357 unsigned long data, void *dummy);
1358 int ieee80211_set_arp_filter(struct ieee80211_sub_if_data *sdata);
1359 -void
1360 -ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1361 - const struct ieee80211_channel_sw_ie *sw_elem,
1362 - struct ieee80211_bss *bss, u64 timestamp);
1363 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata);
1364 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1365 struct sk_buff *skb);
1366 @@ -1499,13 +1501,13 @@ static inline void ieee80211_tx_skb(stru
1367 ieee80211_tx_skb_tid(sdata, skb, 7);
1368 }
1369
1370 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1371 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
1372 struct ieee802_11_elems *elems,
1373 u64 filter, u32 crc);
1374 -static inline void ieee802_11_parse_elems(u8 *start, size_t len,
1375 +static inline void ieee802_11_parse_elems(u8 *start, size_t len, bool action,
1376 struct ieee802_11_elems *elems)
1377 {
1378 - ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
1379 + ieee802_11_parse_elems_crc(start, len, action, elems, 0, 0);
1380 }
1381
1382 u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1383 --- a/net/mac80211/iface.c
1384 +++ b/net/mac80211/iface.c
1385 @@ -159,7 +159,8 @@ static int ieee80211_change_mtu(struct n
1386 return 0;
1387 }
1388
1389 -static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr)
1390 +static int ieee80211_verify_mac(struct ieee80211_local *local, u8 *addr,
1391 + bool check_dup)
1392 {
1393 struct ieee80211_sub_if_data *sdata;
1394 u64 new, mask, tmp;
1395 @@ -179,10 +180,13 @@ static int ieee80211_verify_mac(struct i
1396 ((u64)m[2] << 3*8) | ((u64)m[3] << 2*8) |
1397 ((u64)m[4] << 1*8) | ((u64)m[5] << 0*8);
1398
1399 + if (!check_dup)
1400 + return ret;
1401
1402 mutex_lock(&local->iflist_mtx);
1403 list_for_each_entry(sdata, &local->interfaces, list) {
1404 - if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1405 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1406 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1407 continue;
1408
1409 m = sdata->vif.addr;
1410 @@ -204,12 +208,17 @@ static int ieee80211_change_mac(struct n
1411 {
1412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1413 struct sockaddr *sa = addr;
1414 + bool check_dup = true;
1415 int ret;
1416
1417 if (ieee80211_sdata_running(sdata))
1418 return -EBUSY;
1419
1420 - ret = ieee80211_verify_mac(sdata->local, sa->sa_data);
1421 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
1422 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1423 + check_dup = false;
1424 +
1425 + ret = ieee80211_verify_mac(sdata->local, sa->sa_data, check_dup);
1426 if (ret)
1427 return ret;
1428
1429 @@ -450,7 +459,6 @@ int ieee80211_do_open(struct wireless_de
1430 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
1431 struct net_device *dev = wdev->netdev;
1432 struct ieee80211_local *local = sdata->local;
1433 - struct sta_info *sta;
1434 u32 changed = 0;
1435 int res;
1436 u32 hw_reconf_flags = 0;
1437 @@ -474,6 +482,9 @@ int ieee80211_do_open(struct wireless_de
1438 master->control_port_protocol;
1439 sdata->control_port_no_encrypt =
1440 master->control_port_no_encrypt;
1441 + sdata->vif.cab_queue = master->vif.cab_queue;
1442 + memcpy(sdata->vif.hw_queue, master->vif.hw_queue,
1443 + sizeof(sdata->vif.hw_queue));
1444 break;
1445 }
1446 case NL80211_IFTYPE_AP:
1447 @@ -538,7 +549,11 @@ int ieee80211_do_open(struct wireless_de
1448 break;
1449 }
1450
1451 - if (local->monitors == 0 && local->open_count == 0) {
1452 + if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
1453 + res = drv_add_interface(local, sdata);
1454 + if (res)
1455 + goto err_stop;
1456 + } else if (local->monitors == 0 && local->open_count == 0) {
1457 res = ieee80211_add_virtual_monitor(local);
1458 if (res)
1459 goto err_stop;
1460 @@ -609,30 +624,8 @@ int ieee80211_do_open(struct wireless_de
1461
1462 set_bit(SDATA_STATE_RUNNING, &sdata->state);
1463
1464 - if (sdata->vif.type == NL80211_IFTYPE_WDS) {
1465 - /* Create STA entry for the WDS peer */
1466 - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1467 - GFP_KERNEL);
1468 - if (!sta) {
1469 - res = -ENOMEM;
1470 - goto err_del_interface;
1471 - }
1472 -
1473 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1474 - sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1475 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1476 -
1477 - res = sta_info_insert(sta);
1478 - if (res) {
1479 - /* STA has been freed */
1480 - goto err_del_interface;
1481 - }
1482 -
1483 - rate_control_rate_init(sta);
1484 - netif_carrier_on(dev);
1485 - } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
1486 + if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
1487 rcu_assign_pointer(local->p2p_sdata, sdata);
1488 - }
1489
1490 /*
1491 * set_multicast_list will be invoked by the networking core
1492 @@ -653,7 +646,11 @@ int ieee80211_do_open(struct wireless_de
1493
1494 ieee80211_recalc_ps(local, -1);
1495
1496 - if (dev) {
1497 + if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1498 + sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1499 + /* XXX: for AP_VLAN, actually track AP queues */
1500 + netif_tx_start_all_queues(dev);
1501 + } else if (dev) {
1502 unsigned long flags;
1503 int n_acs = IEEE80211_NUM_ACS;
1504 int ac;
1505 @@ -916,7 +913,11 @@ static void ieee80211_do_stop(struct iee
1506 mutex_lock(&local->mtx);
1507 ieee80211_recalc_idle(local);
1508 mutex_unlock(&local->mtx);
1509 - break;
1510 +
1511 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
1512 + break;
1513 +
1514 + /* fall through */
1515 default:
1516 if (going_down)
1517 drv_remove_interface(local, sdata);
1518 @@ -1075,7 +1076,7 @@ static const struct net_device_ops ieee8
1519 .ndo_start_xmit = ieee80211_monitor_start_xmit,
1520 .ndo_set_rx_mode = ieee80211_set_multicast_list,
1521 .ndo_change_mtu = ieee80211_change_mtu,
1522 - .ndo_set_mac_address = eth_mac_addr,
1523 + .ndo_set_mac_address = ieee80211_change_mac,
1524 .ndo_select_queue = ieee80211_monitor_select_queue,
1525 };
1526
1527 @@ -1092,6 +1093,74 @@ static void ieee80211_if_setup(struct ne
1528 dev->destructor = free_netdev;
1529 }
1530
1531 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1532 + struct sk_buff *skb)
1533 +{
1534 + struct ieee80211_local *local = sdata->local;
1535 + struct ieee80211_rx_status *rx_status;
1536 + struct ieee802_11_elems elems;
1537 + struct ieee80211_mgmt *mgmt;
1538 + struct sta_info *sta;
1539 + size_t baselen;
1540 + u32 rates = 0;
1541 + u16 stype;
1542 + bool new = false;
1543 + enum ieee80211_band band;
1544 + struct ieee80211_supported_band *sband;
1545 +
1546 + rx_status = IEEE80211_SKB_RXCB(skb);
1547 + band = rx_status->band;
1548 + sband = local->hw.wiphy->bands[band];
1549 + mgmt = (struct ieee80211_mgmt *) skb->data;
1550 + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
1551 +
1552 + if (stype != IEEE80211_STYPE_BEACON)
1553 + return;
1554 +
1555 + baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1556 + if (baselen > skb->len)
1557 + return;
1558 +
1559 + ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
1560 + skb->len - baselen, false, &elems);
1561 +
1562 + rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
1563 +
1564 + rcu_read_lock();
1565 +
1566 + sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
1567 +
1568 + if (!sta) {
1569 + rcu_read_unlock();
1570 + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
1571 + GFP_KERNEL);
1572 + if (!sta)
1573 + return;
1574 +
1575 + new = true;
1576 + }
1577 +
1578 + sta->last_rx = jiffies;
1579 + sta->sta.supp_rates[band] = rates;
1580 +
1581 + if (elems.ht_cap_elem)
1582 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
1583 + elems.ht_cap_elem, sta);
1584 +
1585 + if (elems.wmm_param)
1586 + set_sta_flag(sta, WLAN_STA_WME);
1587 +
1588 + if (new) {
1589 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1590 + sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1591 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
1592 + rate_control_rate_init(sta);
1593 + sta_info_insert_rcu(sta);
1594 + }
1595 +
1596 + rcu_read_unlock();
1597 +}
1598 +
1599 static void ieee80211_iface_work(struct work_struct *work)
1600 {
1601 struct ieee80211_sub_if_data *sdata =
1602 @@ -1196,6 +1265,9 @@ static void ieee80211_iface_work(struct
1603 break;
1604 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
1605 break;
1606 + case NL80211_IFTYPE_WDS:
1607 + ieee80211_wds_rx_queued_mgmt(sdata, skb);
1608 + break;
1609 default:
1610 WARN(1, "frame for unexpected interface type");
1611 break;
1612 @@ -1718,6 +1790,15 @@ void ieee80211_remove_interfaces(struct
1613
1614 ASSERT_RTNL();
1615
1616 + /*
1617 + * Close all AP_VLAN interfaces first, as otherwise they
1618 + * might be closed while the AP interface they belong to
1619 + * is closed, causing unregister_netdevice_many() to crash.
1620 + */
1621 + list_for_each_entry(sdata, &local->interfaces, list)
1622 + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1623 + dev_close(sdata->dev);
1624 +
1625 mutex_lock(&local->iflist_mtx);
1626 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1627 list_del(&sdata->list);
1628 --- a/net/mac80211/main.c
1629 +++ b/net/mac80211/main.c
1630 @@ -674,6 +674,7 @@ int ieee80211_register_hw(struct ieee802
1631 int channels, max_bitrates;
1632 bool supp_ht, supp_vht;
1633 netdev_features_t feature_whitelist;
1634 + struct cfg80211_chan_def dflt_chandef = {};
1635 static const u32 cipher_suites[] = {
1636 /* keep WEP first, it may be removed below */
1637 WLAN_CIPHER_SUITE_WEP40,
1638 @@ -751,19 +752,19 @@ int ieee80211_register_hw(struct ieee802
1639 sband = local->hw.wiphy->bands[band];
1640 if (!sband)
1641 continue;
1642 - if (!local->use_chanctx && !local->_oper_chandef.chan) {
1643 +
1644 + if (!dflt_chandef.chan) {
1645 + cfg80211_chandef_create(&dflt_chandef,
1646 + &sband->channels[0],
1647 + NL80211_CHAN_NO_HT);
1648 /* init channel we're on */
1649 - struct cfg80211_chan_def chandef = {
1650 - .chan = &sband->channels[0],
1651 - .width = NL80211_CHAN_NO_HT,
1652 - .center_freq1 = sband->channels[0].center_freq,
1653 - .center_freq2 = 0
1654 - };
1655 - local->hw.conf.chandef = local->_oper_chandef = chandef;
1656 + if (!local->use_chanctx && !local->_oper_chandef.chan) {
1657 + local->hw.conf.chandef = dflt_chandef;
1658 + local->_oper_chandef = dflt_chandef;
1659 + }
1660 + local->monitor_chandef = dflt_chandef;
1661 }
1662 - cfg80211_chandef_create(&local->monitor_chandef,
1663 - &sband->channels[0],
1664 - NL80211_CHAN_NO_HT);
1665 +
1666 channels += sband->n_channels;
1667
1668 if (max_bitrates < sband->n_bitrates)
1669 --- a/net/mac80211/mesh.c
1670 +++ b/net/mac80211/mesh.c
1671 @@ -838,7 +838,7 @@ ieee80211_mesh_rx_probe_req(struct ieee8
1672 if (baselen > len)
1673 return;
1674
1675 - ieee802_11_parse_elems(pos, len - baselen, &elems);
1676 + ieee802_11_parse_elems(pos, len - baselen, false, &elems);
1677
1678 /* 802.11-2012 10.1.4.3.2 */
1679 if ((!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
1680 @@ -899,7 +899,7 @@ static void ieee80211_mesh_rx_bcn_presp(
1681 return;
1682
1683 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1684 - &elems);
1685 + false, &elems);
1686
1687 /* ignore non-mesh or secure / unsecure mismatch */
1688 if ((!elems.mesh_id || !elems.mesh_config) ||
1689 --- a/net/mac80211/mesh_hwmp.c
1690 +++ b/net/mac80211/mesh_hwmp.c
1691 @@ -880,7 +880,7 @@ void mesh_rx_path_sel_frame(struct ieee8
1692
1693 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
1694 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
1695 - len - baselen, &elems);
1696 + len - baselen, false, &elems);
1697
1698 if (elems.preq) {
1699 if (elems.preq_len != 37)
1700 --- a/net/mac80211/mesh_plink.c
1701 +++ b/net/mac80211/mesh_plink.c
1702 @@ -544,8 +544,8 @@ static void mesh_plink_timer(unsigned lo
1703 return;
1704 }
1705 mpl_dbg(sta->sdata,
1706 - "Mesh plink timer for %pM fired on state %d\n",
1707 - sta->sta.addr, sta->plink_state);
1708 + "Mesh plink timer for %pM fired on state %s\n",
1709 + sta->sta.addr, mplstates[sta->plink_state]);
1710 reason = 0;
1711 llid = sta->llid;
1712 plid = sta->plid;
1713 @@ -687,7 +687,7 @@ void mesh_rx_plink_frame(struct ieee8021
1714 baseaddr += 4;
1715 baselen += 4;
1716 }
1717 - ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
1718 + ieee802_11_parse_elems(baseaddr, len - baselen, true, &elems);
1719
1720 if (!elems.peering) {
1721 mpl_dbg(sdata,
1722 --- a/net/mac80211/mlme.c
1723 +++ b/net/mac80211/mlme.c
1724 @@ -289,6 +289,8 @@ ieee80211_determine_chantype(struct ieee
1725 } else {
1726 /* 40 MHz (and 80 MHz) must be supported for VHT */
1727 ret = IEEE80211_STA_DISABLE_VHT;
1728 + /* also mark 40 MHz disabled */
1729 + ret |= IEEE80211_STA_DISABLE_40MHZ;
1730 goto out;
1731 }
1732
1733 @@ -303,12 +305,6 @@ ieee80211_determine_chantype(struct ieee
1734 channel->band);
1735 vht_chandef.center_freq2 = 0;
1736
1737 - if (vht_oper->center_freq_seg2_idx)
1738 - vht_chandef.center_freq2 =
1739 - ieee80211_channel_to_frequency(
1740 - vht_oper->center_freq_seg2_idx,
1741 - channel->band);
1742 -
1743 switch (vht_oper->chan_width) {
1744 case IEEE80211_VHT_CHANWIDTH_USE_HT:
1745 vht_chandef.width = chandef->width;
1746 @@ -321,6 +317,10 @@ ieee80211_determine_chantype(struct ieee
1747 break;
1748 case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1749 vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1750 + vht_chandef.center_freq2 =
1751 + ieee80211_channel_to_frequency(
1752 + vht_oper->center_freq_seg2_idx,
1753 + channel->band);
1754 break;
1755 default:
1756 if (verbose)
1757 @@ -604,7 +604,6 @@ static void ieee80211_add_vht_ie(struct
1758 u8 *pos;
1759 u32 cap;
1760 struct ieee80211_sta_vht_cap vht_cap;
1761 - int i;
1762
1763 BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
1764
1765 @@ -632,37 +631,6 @@ static void ieee80211_add_vht_ie(struct
1766 cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
1767 cap &= ~IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE;
1768
1769 - if (!(ap_vht_cap->vht_cap_info &
1770 - cpu_to_le32(IEEE80211_VHT_CAP_TXSTBC)))
1771 - cap &= ~(IEEE80211_VHT_CAP_RXSTBC_1 |
1772 - IEEE80211_VHT_CAP_RXSTBC_3 |
1773 - IEEE80211_VHT_CAP_RXSTBC_4);
1774 -
1775 - for (i = 0; i < 8; i++) {
1776 - int shift = i * 2;
1777 - u16 mask = IEEE80211_VHT_MCS_NOT_SUPPORTED << shift;
1778 - u16 ap_mcs, our_mcs;
1779 -
1780 - ap_mcs = (le16_to_cpu(ap_vht_cap->supp_mcs.tx_mcs_map) &
1781 - mask) >> shift;
1782 - our_mcs = (le16_to_cpu(vht_cap.vht_mcs.rx_mcs_map) &
1783 - mask) >> shift;
1784 -
1785 - if (our_mcs == IEEE80211_VHT_MCS_NOT_SUPPORTED)
1786 - continue;
1787 -
1788 - switch (ap_mcs) {
1789 - default:
1790 - if (our_mcs <= ap_mcs)
1791 - break;
1792 - /* fall through */
1793 - case IEEE80211_VHT_MCS_NOT_SUPPORTED:
1794 - vht_cap.vht_mcs.rx_mcs_map &= cpu_to_le16(~mask);
1795 - vht_cap.vht_mcs.rx_mcs_map |=
1796 - cpu_to_le16(ap_mcs << shift);
1797 - }
1798 - }
1799 -
1800 /* reserve and fill IE */
1801 pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
1802 ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
1803 @@ -998,16 +966,7 @@ static void ieee80211_chswitch_work(stru
1804 if (!ifmgd->associated)
1805 goto out;
1806
1807 - /*
1808 - * FIXME: Here we are downgrading to NL80211_CHAN_WIDTH_20_NOHT
1809 - * and don't adjust our ht/vht settings
1810 - * This is wrong - we should behave according to the CSA params
1811 - */
1812 - local->_oper_chandef.chan = local->csa_channel;
1813 - local->_oper_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
1814 - local->_oper_chandef.center_freq1 =
1815 - local->_oper_chandef.chan->center_freq;
1816 - local->_oper_chandef.center_freq2 = 0;
1817 + local->_oper_chandef = local->csa_chandef;
1818
1819 if (!local->ops->channel_switch) {
1820 /* call "hw_config" only if doing sw channel switch */
1821 @@ -1054,56 +1013,208 @@ static void ieee80211_chswitch_timer(uns
1822 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
1823 }
1824
1825 -void
1826 +static void
1827 ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1828 - const struct ieee80211_channel_sw_ie *sw_elem,
1829 - struct ieee80211_bss *bss, u64 timestamp)
1830 + u64 timestamp, struct ieee802_11_elems *elems,
1831 + bool beacon)
1832 {
1833 - struct cfg80211_bss *cbss =
1834 - container_of((void *)bss, struct cfg80211_bss, priv);
1835 - struct ieee80211_channel *new_ch;
1836 + struct ieee80211_local *local = sdata->local;
1837 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1838 - int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
1839 - cbss->channel->band);
1840 + struct cfg80211_bss *cbss = ifmgd->associated;
1841 + struct ieee80211_bss *bss;
1842 struct ieee80211_chanctx *chanctx;
1843 + enum ieee80211_band new_band;
1844 + int new_freq;
1845 + u8 new_chan_no;
1846 + u8 count;
1847 + u8 mode;
1848 + struct ieee80211_channel *new_chan;
1849 + struct cfg80211_chan_def new_chandef = {};
1850 + struct cfg80211_chan_def new_vht_chandef = {};
1851 + const struct ieee80211_sec_chan_offs_ie *sec_chan_offs;
1852 + const struct ieee80211_wide_bw_chansw_ie *wide_bw_chansw_ie;
1853 + const struct ieee80211_ht_operation *ht_oper;
1854 + int secondary_channel_offset = -1;
1855
1856 ASSERT_MGD_MTX(ifmgd);
1857
1858 - if (!ifmgd->associated)
1859 + if (!cbss)
1860 + return;
1861 +
1862 + if (local->scanning)
1863 return;
1864
1865 - if (sdata->local->scanning)
1866 + /* disregard subsequent announcements if we are already processing */
1867 + if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1868 return;
1869
1870 - /* Disregard subsequent beacons if we are already running a timer
1871 - processing a CSA */
1872 + sec_chan_offs = elems->sec_chan_offs;
1873 + wide_bw_chansw_ie = elems->wide_bw_chansw_ie;
1874 + ht_oper = elems->ht_operation;
1875 +
1876 + if (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
1877 + IEEE80211_STA_DISABLE_40MHZ)) {
1878 + sec_chan_offs = NULL;
1879 + wide_bw_chansw_ie = NULL;
1880 + /* only used for bandwidth here */
1881 + ht_oper = NULL;
1882 + }
1883
1884 - if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
1885 + if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
1886 + wide_bw_chansw_ie = NULL;
1887 +
1888 + if (elems->ext_chansw_ie) {
1889 + if (!ieee80211_operating_class_to_band(
1890 + elems->ext_chansw_ie->new_operating_class,
1891 + &new_band)) {
1892 + sdata_info(sdata,
1893 + "cannot understand ECSA IE operating class %d, disconnecting\n",
1894 + elems->ext_chansw_ie->new_operating_class);
1895 + ieee80211_queue_work(&local->hw,
1896 + &ifmgd->csa_connection_drop_work);
1897 + }
1898 + new_chan_no = elems->ext_chansw_ie->new_ch_num;
1899 + count = elems->ext_chansw_ie->count;
1900 + mode = elems->ext_chansw_ie->mode;
1901 + } else if (elems->ch_switch_ie) {
1902 + new_band = cbss->channel->band;
1903 + new_chan_no = elems->ch_switch_ie->new_ch_num;
1904 + count = elems->ch_switch_ie->count;
1905 + mode = elems->ch_switch_ie->mode;
1906 + } else {
1907 + /* nothing here we understand */
1908 return;
1909 + }
1910 +
1911 + bss = (void *)cbss->priv;
1912
1913 - new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1914 - if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) {
1915 + new_freq = ieee80211_channel_to_frequency(new_chan_no, new_band);
1916 + new_chan = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
1917 + if (!new_chan || new_chan->flags & IEEE80211_CHAN_DISABLED) {
1918 sdata_info(sdata,
1919 "AP %pM switches to unsupported channel (%d MHz), disconnecting\n",
1920 ifmgd->associated->bssid, new_freq);
1921 - ieee80211_queue_work(&sdata->local->hw,
1922 + ieee80211_queue_work(&local->hw,
1923 + &ifmgd->csa_connection_drop_work);
1924 + return;
1925 + }
1926 +
1927 + if (!beacon && sec_chan_offs) {
1928 + secondary_channel_offset = sec_chan_offs->sec_chan_offs;
1929 + } else if (beacon && ht_oper) {
1930 + secondary_channel_offset =
1931 + ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
1932 + } else if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
1933 + /*
1934 + * If it's not a beacon, HT is enabled and the IE not present,
1935 + * it's 20 MHz, 802.11-2012 8.5.2.6:
1936 + * This element [the Secondary Channel Offset Element] is
1937 + * present when switching to a 40 MHz channel. It may be
1938 + * present when switching to a 20 MHz channel (in which
1939 + * case the secondary channel offset is set to SCN).
1940 + */
1941 + secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
1942 + }
1943 +
1944 + switch (secondary_channel_offset) {
1945 + default:
1946 + /* secondary_channel_offset was present but is invalid */
1947 + case IEEE80211_HT_PARAM_CHA_SEC_NONE:
1948 + cfg80211_chandef_create(&new_chandef, new_chan,
1949 + NL80211_CHAN_HT20);
1950 + break;
1951 + case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
1952 + cfg80211_chandef_create(&new_chandef, new_chan,
1953 + NL80211_CHAN_HT40PLUS);
1954 + break;
1955 + case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
1956 + cfg80211_chandef_create(&new_chandef, new_chan,
1957 + NL80211_CHAN_HT40MINUS);
1958 + break;
1959 + case -1:
1960 + cfg80211_chandef_create(&new_chandef, new_chan,
1961 + NL80211_CHAN_NO_HT);
1962 + break;
1963 + }
1964 +
1965 + if (wide_bw_chansw_ie) {
1966 + new_vht_chandef.chan = new_chan;
1967 + new_vht_chandef.center_freq1 =
1968 + ieee80211_channel_to_frequency(
1969 + wide_bw_chansw_ie->new_center_freq_seg0,
1970 + new_band);
1971 +
1972 + switch (wide_bw_chansw_ie->new_channel_width) {
1973 + default:
1974 + /* hmmm, ignore VHT and use HT if present */
1975 + case IEEE80211_VHT_CHANWIDTH_USE_HT:
1976 + new_vht_chandef.chan = NULL;
1977 + break;
1978 + case IEEE80211_VHT_CHANWIDTH_80MHZ:
1979 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80;
1980 + break;
1981 + case IEEE80211_VHT_CHANWIDTH_160MHZ:
1982 + new_vht_chandef.width = NL80211_CHAN_WIDTH_160;
1983 + break;
1984 + case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
1985 + /* field is otherwise reserved */
1986 + new_vht_chandef.center_freq2 =
1987 + ieee80211_channel_to_frequency(
1988 + wide_bw_chansw_ie->new_center_freq_seg1,
1989 + new_band);
1990 + new_vht_chandef.width = NL80211_CHAN_WIDTH_80P80;
1991 + break;
1992 + }
1993 + if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
1994 + new_vht_chandef.width == NL80211_CHAN_WIDTH_80P80)
1995 + chandef_downgrade(&new_vht_chandef);
1996 + if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
1997 + new_vht_chandef.width == NL80211_CHAN_WIDTH_160)
1998 + chandef_downgrade(&new_vht_chandef);
1999 + if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
2000 + new_vht_chandef.width > NL80211_CHAN_WIDTH_20)
2001 + chandef_downgrade(&new_vht_chandef);
2002 + }
2003 +
2004 + /* if VHT data is there validate & use it */
2005 + if (new_vht_chandef.chan) {
2006 + if (!cfg80211_chandef_compatible(&new_vht_chandef,
2007 + &new_chandef)) {
2008 + sdata_info(sdata,
2009 + "AP %pM CSA has inconsistent channel data, disconnecting\n",
2010 + ifmgd->associated->bssid);
2011 + ieee80211_queue_work(&local->hw,
2012 + &ifmgd->csa_connection_drop_work);
2013 + return;
2014 + }
2015 + new_chandef = new_vht_chandef;
2016 + }
2017 +
2018 + if (!cfg80211_chandef_usable(local->hw.wiphy, &new_chandef,
2019 + IEEE80211_CHAN_DISABLED)) {
2020 + sdata_info(sdata,
2021 + "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
2022 + ifmgd->associated->bssid, new_freq,
2023 + new_chandef.width, new_chandef.center_freq1,
2024 + new_chandef.center_freq2);
2025 + ieee80211_queue_work(&local->hw,
2026 &ifmgd->csa_connection_drop_work);
2027 return;
2028 }
2029
2030 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
2031
2032 - if (sdata->local->use_chanctx) {
2033 + if (local->use_chanctx) {
2034 sdata_info(sdata,
2035 "not handling channel switch with channel contexts\n");
2036 - ieee80211_queue_work(&sdata->local->hw,
2037 + ieee80211_queue_work(&local->hw,
2038 &ifmgd->csa_connection_drop_work);
2039 return;
2040 }
2041
2042 - mutex_lock(&sdata->local->chanctx_mtx);
2043 + mutex_lock(&local->chanctx_mtx);
2044 if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) {
2045 - mutex_unlock(&sdata->local->chanctx_mtx);
2046 + mutex_unlock(&local->chanctx_mtx);
2047 return;
2048 }
2049 chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf),
2050 @@ -1111,40 +1222,39 @@ ieee80211_sta_process_chanswitch(struct
2051 if (chanctx->refcount > 1) {
2052 sdata_info(sdata,
2053 "channel switch with multiple interfaces on the same channel, disconnecting\n");
2054 - ieee80211_queue_work(&sdata->local->hw,
2055 + ieee80211_queue_work(&local->hw,
2056 &ifmgd->csa_connection_drop_work);
2057 - mutex_unlock(&sdata->local->chanctx_mtx);
2058 + mutex_unlock(&local->chanctx_mtx);
2059 return;
2060 }
2061 - mutex_unlock(&sdata->local->chanctx_mtx);
2062 + mutex_unlock(&local->chanctx_mtx);
2063
2064 - sdata->local->csa_channel = new_ch;
2065 + local->csa_chandef = new_chandef;
2066
2067 - if (sw_elem->mode)
2068 - ieee80211_stop_queues_by_reason(&sdata->local->hw,
2069 + if (mode)
2070 + ieee80211_stop_queues_by_reason(&local->hw,
2071 IEEE80211_MAX_QUEUE_MAP,
2072 IEEE80211_QUEUE_STOP_REASON_CSA);
2073
2074 - if (sdata->local->ops->channel_switch) {
2075 + if (local->ops->channel_switch) {
2076 /* use driver's channel switch callback */
2077 struct ieee80211_channel_switch ch_switch = {
2078 .timestamp = timestamp,
2079 - .block_tx = sw_elem->mode,
2080 - .channel = new_ch,
2081 - .count = sw_elem->count,
2082 + .block_tx = mode,
2083 + .chandef = new_chandef,
2084 + .count = count,
2085 };
2086
2087 - drv_channel_switch(sdata->local, &ch_switch);
2088 + drv_channel_switch(local, &ch_switch);
2089 return;
2090 }
2091
2092 /* channel switch handled in software */
2093 - if (sw_elem->count <= 1)
2094 - ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
2095 + if (count <= 1)
2096 + ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
2097 else
2098 mod_timer(&ifmgd->chswitch_timer,
2099 - TU_TO_EXP_TIME(sw_elem->count *
2100 - cbss->beacon_interval));
2101 + TU_TO_EXP_TIME(count * cbss->beacon_interval));
2102 }
2103
2104 static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
2105 @@ -2120,7 +2230,6 @@ void ieee80211_beacon_loss(struct ieee80
2106
2107 trace_api_beacon_loss(sdata);
2108
2109 - WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
2110 sdata->u.mgd.connection_loss = false;
2111 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
2112 }
2113 @@ -2170,7 +2279,7 @@ static void ieee80211_auth_challenge(str
2114 u32 tx_flags = 0;
2115
2116 pos = mgmt->u.auth.variable;
2117 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2118 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2119 if (!elems.challenge)
2120 return;
2121 auth_data->expected_transaction = 4;
2122 @@ -2435,7 +2544,7 @@ static bool ieee80211_assoc_success(stru
2123 }
2124
2125 pos = mgmt->u.assoc_resp.variable;
2126 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2127 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2128
2129 if (!elems.supp_rates) {
2130 sdata_info(sdata, "no SuppRates element in AssocResp\n");
2131 @@ -2604,7 +2713,7 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee
2132 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2133
2134 pos = mgmt->u.assoc_resp.variable;
2135 - ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2136 + ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
2137
2138 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
2139 elems.timeout_int &&
2140 @@ -2659,6 +2768,8 @@ static void ieee80211_rx_bss_info(struct
2141 struct ieee80211_channel *channel;
2142 bool need_ps = false;
2143
2144 + lockdep_assert_held(&sdata->u.mgd.mtx);
2145 +
2146 if ((sdata->u.mgd.associated &&
2147 ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) ||
2148 (sdata->u.mgd.assoc_data &&
2149 @@ -2689,7 +2800,8 @@ static void ieee80211_rx_bss_info(struct
2150 if (bss)
2151 ieee80211_rx_bss_put(local, bss);
2152
2153 - if (!sdata->u.mgd.associated)
2154 + if (!sdata->u.mgd.associated ||
2155 + !ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid))
2156 return;
2157
2158 if (need_ps) {
2159 @@ -2698,10 +2810,9 @@ static void ieee80211_rx_bss_info(struct
2160 mutex_unlock(&local->iflist_mtx);
2161 }
2162
2163 - if (elems->ch_switch_ie &&
2164 - memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0)
2165 - ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie,
2166 - bss, rx_status->mactime);
2167 + ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
2168 + elems, true);
2169 +
2170 }
2171
2172
2173 @@ -2726,7 +2837,7 @@ static void ieee80211_rx_mgmt_probe_resp
2174 return;
2175
2176 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
2177 - &elems);
2178 + false, &elems);
2179
2180 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2181
2182 @@ -2809,7 +2920,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2183 if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
2184 ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
2185 ieee802_11_parse_elems(mgmt->u.beacon.variable,
2186 - len - baselen, &elems);
2187 + len - baselen, false, &elems);
2188
2189 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
2190 ifmgd->assoc_data->have_beacon = true;
2191 @@ -2919,7 +3030,7 @@ ieee80211_rx_mgmt_beacon(struct ieee8021
2192
2193 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
2194 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
2195 - len - baselen, &elems,
2196 + len - baselen, false, &elems,
2197 care_about_ies, ncrc);
2198
2199 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
2200 @@ -3066,6 +3177,8 @@ void ieee80211_sta_rx_queued_mgmt(struct
2201 enum rx_mgmt_action rma = RX_MGMT_NONE;
2202 u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
2203 u16 fc;
2204 + struct ieee802_11_elems elems;
2205 + int ies_len;
2206
2207 rx_status = (struct ieee80211_rx_status *) skb->cb;
2208 mgmt = (struct ieee80211_mgmt *) skb->data;
2209 @@ -3095,14 +3208,48 @@ void ieee80211_sta_rx_queued_mgmt(struct
2210 rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss);
2211 break;
2212 case IEEE80211_STYPE_ACTION:
2213 - switch (mgmt->u.action.category) {
2214 - case WLAN_CATEGORY_SPECTRUM_MGMT:
2215 + if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
2216 + ies_len = skb->len -
2217 + offsetof(struct ieee80211_mgmt,
2218 + u.action.u.chan_switch.variable);
2219 +
2220 + if (ies_len < 0)
2221 + break;
2222 +
2223 + ieee802_11_parse_elems(
2224 + mgmt->u.action.u.chan_switch.variable,
2225 + ies_len, true, &elems);
2226 +
2227 + if (elems.parse_error)
2228 + break;
2229 +
2230 ieee80211_sta_process_chanswitch(sdata,
2231 - &mgmt->u.action.u.chan_switch.sw_elem,
2232 - (void *)ifmgd->associated->priv,
2233 - rx_status->mactime);
2234 - break;
2235 + rx_status->mactime,
2236 + &elems, false);
2237 + } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
2238 + ies_len = skb->len -
2239 + offsetof(struct ieee80211_mgmt,
2240 + u.action.u.ext_chan_switch.variable);
2241 +
2242 + if (ies_len < 0)
2243 + break;
2244 +
2245 + ieee802_11_parse_elems(
2246 + mgmt->u.action.u.ext_chan_switch.variable,
2247 + ies_len, true, &elems);
2248 +
2249 + if (elems.parse_error)
2250 + break;
2251 +
2252 + /* for the handling code pretend this was also an IE */
2253 + elems.ext_chansw_ie =
2254 + &mgmt->u.action.u.ext_chan_switch.data;
2255 +
2256 + ieee80211_sta_process_chanswitch(sdata,
2257 + rx_status->mactime,
2258 + &elems, false);
2259 }
2260 + break;
2261 }
2262 mutex_unlock(&ifmgd->mtx);
2263
2264 @@ -4197,7 +4344,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2265 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2266 u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
2267 bool tx = !req->local_state_change;
2268 - bool sent_frame = false;
2269 + bool report_frame = false;
2270
2271 mutex_lock(&ifmgd->mtx);
2272
2273 @@ -4214,7 +4361,7 @@ int ieee80211_mgd_deauth(struct ieee8021
2274 ieee80211_destroy_auth_data(sdata, false);
2275 mutex_unlock(&ifmgd->mtx);
2276
2277 - sent_frame = tx;
2278 + report_frame = true;
2279 goto out;
2280 }
2281
2282 @@ -4222,12 +4369,12 @@ int ieee80211_mgd_deauth(struct ieee8021
2283 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
2284 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
2285 req->reason_code, tx, frame_buf);
2286 - sent_frame = tx;
2287 + report_frame = true;
2288 }
2289 mutex_unlock(&ifmgd->mtx);
2290
2291 out:
2292 - if (sent_frame)
2293 + if (report_frame)
2294 __cfg80211_send_deauth(sdata->dev, frame_buf,
2295 IEEE80211_DEAUTH_FRAME_LEN);
2296
2297 --- a/net/mac80211/pm.c
2298 +++ b/net/mac80211/pm.c
2299 @@ -38,8 +38,8 @@ int __ieee80211_suspend(struct ieee80211
2300 IEEE80211_MAX_QUEUE_MAP,
2301 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
2302
2303 - /* flush out all packets */
2304 - synchronize_net();
2305 + /* flush out all packets and station cleanup call_rcu()s */
2306 + rcu_barrier();
2307
2308 ieee80211_flush_queues(local, NULL);
2309
2310 --- a/net/mac80211/rate.c
2311 +++ b/net/mac80211/rate.c
2312 @@ -252,6 +252,25 @@ rate_lowest_non_cck_index(struct ieee802
2313 return 0;
2314 }
2315
2316 +static void __rate_control_send_low(struct ieee80211_hw *hw,
2317 + struct ieee80211_supported_band *sband,
2318 + struct ieee80211_sta *sta,
2319 + struct ieee80211_tx_info *info)
2320 +{
2321 + if ((sband->band != IEEE80211_BAND_2GHZ) ||
2322 + !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2323 + info->control.rates[0].idx = rate_lowest_index(sband, sta);
2324 + else
2325 + info->control.rates[0].idx =
2326 + rate_lowest_non_cck_index(sband, sta);
2327 +
2328 + info->control.rates[0].count =
2329 + (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2330 + 1 : hw->max_rate_tries;
2331 +
2332 + info->control.skip_table = 1;
2333 +}
2334 +
2335
2336 bool rate_control_send_low(struct ieee80211_sta *sta,
2337 void *priv_sta,
2338 @@ -262,16 +281,8 @@ bool rate_control_send_low(struct ieee80
2339 int mcast_rate;
2340
2341 if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
2342 - if ((sband->band != IEEE80211_BAND_2GHZ) ||
2343 - !(info->flags & IEEE80211_TX_CTL_NO_CCK_RATE))
2344 - info->control.rates[0].idx =
2345 - rate_lowest_index(txrc->sband, sta);
2346 - else
2347 - info->control.rates[0].idx =
2348 - rate_lowest_non_cck_index(txrc->sband, sta);
2349 - info->control.rates[0].count =
2350 - (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
2351 - 1 : txrc->hw->max_rate_tries;
2352 + __rate_control_send_low(txrc->hw, sband, sta, info);
2353 +
2354 if (!sta && txrc->bss) {
2355 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
2356 if (mcast_rate > 0) {
2357 @@ -355,7 +366,8 @@ static bool rate_idx_match_mcs_mask(stru
2358
2359
2360 static void rate_idx_match_mask(struct ieee80211_tx_rate *rate,
2361 - struct ieee80211_tx_rate_control *txrc,
2362 + struct ieee80211_supported_band *sband,
2363 + enum nl80211_chan_width chan_width,
2364 u32 mask,
2365 u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
2366 {
2367 @@ -375,27 +387,17 @@ static void rate_idx_match_mask(struct i
2368 IEEE80211_TX_RC_USE_SHORT_PREAMBLE);
2369 alt_rate.count = rate->count;
2370 if (rate_idx_match_legacy_mask(&alt_rate,
2371 - txrc->sband->n_bitrates,
2372 - mask)) {
2373 + sband->n_bitrates, mask)) {
2374 *rate = alt_rate;
2375 return;
2376 }
2377 } else {
2378 - struct sk_buff *skb = txrc->skb;
2379 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2380 - __le16 fc;
2381 -
2382 /* handle legacy rates */
2383 - if (rate_idx_match_legacy_mask(rate, txrc->sband->n_bitrates,
2384 - mask))
2385 + if (rate_idx_match_legacy_mask(rate, sband->n_bitrates, mask))
2386 return;
2387
2388 /* if HT BSS, and we handle a data frame, also try HT rates */
2389 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2390 - return;
2391 -
2392 - fc = hdr->frame_control;
2393 - if (!ieee80211_is_data(fc))
2394 + if (chan_width == NL80211_CHAN_WIDTH_20_NOHT)
2395 return;
2396
2397 alt_rate.idx = 0;
2398 @@ -408,7 +410,7 @@ static void rate_idx_match_mask(struct i
2399
2400 alt_rate.flags |= IEEE80211_TX_RC_MCS;
2401
2402 - if (txrc->bss_conf->chandef.width == NL80211_CHAN_WIDTH_40)
2403 + if (chan_width == NL80211_CHAN_WIDTH_40)
2404 alt_rate.flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
2405
2406 if (rate_idx_match_mcs_mask(&alt_rate, mcs_mask)) {
2407 @@ -426,6 +428,228 @@ static void rate_idx_match_mask(struct i
2408 */
2409 }
2410
2411 +static void rate_fixup_ratelist(struct ieee80211_vif *vif,
2412 + struct ieee80211_supported_band *sband,
2413 + struct ieee80211_tx_info *info,
2414 + struct ieee80211_tx_rate *rates,
2415 + int max_rates)
2416 +{
2417 + struct ieee80211_rate *rate;
2418 + bool inval = false;
2419 + int i;
2420 +
2421 + /*
2422 + * Set up the RTS/CTS rate as the fastest basic rate
2423 + * that is not faster than the data rate unless there
2424 + * is no basic rate slower than the data rate, in which
2425 + * case we pick the slowest basic rate
2426 + *
2427 + * XXX: Should this check all retry rates?
2428 + */
2429 + if (!(rates[0].flags & IEEE80211_TX_RC_MCS)) {
2430 + u32 basic_rates = vif->bss_conf.basic_rates;
2431 + s8 baserate = basic_rates ? ffs(basic_rates - 1) : 0;
2432 +
2433 + rate = &sband->bitrates[rates[0].idx];
2434 +
2435 + for (i = 0; i < sband->n_bitrates; i++) {
2436 + /* must be a basic rate */
2437 + if (!(basic_rates & BIT(i)))
2438 + continue;
2439 + /* must not be faster than the data rate */
2440 + if (sband->bitrates[i].bitrate > rate->bitrate)
2441 + continue;
2442 + /* maximum */
2443 + if (sband->bitrates[baserate].bitrate <
2444 + sband->bitrates[i].bitrate)
2445 + baserate = i;
2446 + }
2447 +
2448 + info->control.rts_cts_rate_idx = baserate;
2449 + }
2450 +
2451 + for (i = 0; i < max_rates; i++) {
2452 + /*
2453 + * make sure there's no valid rate following
2454 + * an invalid one, just in case drivers don't
2455 + * take the API seriously to stop at -1.
2456 + */
2457 + if (inval) {
2458 + rates[i].idx = -1;
2459 + continue;
2460 + }
2461 + if (rates[i].idx < 0) {
2462 + inval = true;
2463 + continue;
2464 + }
2465 +
2466 + /*
2467 + * For now assume MCS is already set up correctly, this
2468 + * needs to be fixed.
2469 + */
2470 + if (rates[i].flags & IEEE80211_TX_RC_MCS) {
2471 + WARN_ON(rates[i].idx > 76);
2472 +
2473 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2474 + info->control.use_cts_prot)
2475 + rates[i].flags |=
2476 + IEEE80211_TX_RC_USE_CTS_PROTECT;
2477 + continue;
2478 + }
2479 +
2480 + if (rates[i].flags & IEEE80211_TX_RC_VHT_MCS) {
2481 + WARN_ON(ieee80211_rate_get_vht_mcs(&rates[i]) > 9);
2482 + continue;
2483 + }
2484 +
2485 + /* set up RTS protection if desired */
2486 + if (info->control.use_rts) {
2487 + rates[i].flags |= IEEE80211_TX_RC_USE_RTS_CTS;
2488 + info->control.use_cts_prot = false;
2489 + }
2490 +
2491 + /* RC is busted */
2492 + if (WARN_ON_ONCE(rates[i].idx >= sband->n_bitrates)) {
2493 + rates[i].idx = -1;
2494 + continue;
2495 + }
2496 +
2497 + rate = &sband->bitrates[rates[i].idx];
2498 +
2499 + /* set up short preamble */
2500 + if (info->control.short_preamble &&
2501 + rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2502 + rates[i].flags |= IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
2503 +
2504 + /* set up G protection */
2505 + if (!(rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) &&
2506 + info->control.use_cts_prot &&
2507 + rate->flags & IEEE80211_RATE_ERP_G)
2508 + rates[i].flags |= IEEE80211_TX_RC_USE_CTS_PROTECT;
2509 + }
2510 +}
2511 +
2512 +
2513 +static void rate_control_fill_sta_table(struct ieee80211_sta *sta,
2514 + struct ieee80211_tx_info *info,
2515 + struct ieee80211_tx_rate *rates,
2516 + int max_rates)
2517 +{
2518 + struct ieee80211_sta_rates *ratetbl = NULL;
2519 + int i;
2520 +
2521 + if (sta && !info->control.skip_table)
2522 + ratetbl = rcu_dereference(sta->rates);
2523 +
2524 + /* Fill remaining rate slots with data from the sta rate table. */
2525 + max_rates = min_t(int, max_rates, IEEE80211_TX_RATE_TABLE_SIZE);
2526 + for (i = 0; i < max_rates; i++) {
2527 + if (i < ARRAY_SIZE(info->control.rates) &&
2528 + info->control.rates[i].idx >= 0 &&
2529 + info->control.rates[i].count) {
2530 + if (rates != info->control.rates)
2531 + rates[i] = info->control.rates[i];
2532 + } else if (ratetbl) {
2533 + rates[i].idx = ratetbl->rate[i].idx;
2534 + rates[i].flags = ratetbl->rate[i].flags;
2535 + if (info->control.use_rts)
2536 + rates[i].count = ratetbl->rate[i].count_rts;
2537 + else if (info->control.use_cts_prot)
2538 + rates[i].count = ratetbl->rate[i].count_cts;
2539 + else
2540 + rates[i].count = ratetbl->rate[i].count;
2541 + } else {
2542 + rates[i].idx = -1;
2543 + rates[i].count = 0;
2544 + }
2545 +
2546 + if (rates[i].idx < 0 || !rates[i].count)
2547 + break;
2548 + }
2549 +}
2550 +
2551 +static void rate_control_apply_mask(struct ieee80211_sub_if_data *sdata,
2552 + struct ieee80211_sta *sta,
2553 + struct ieee80211_supported_band *sband,
2554 + struct ieee80211_tx_info *info,
2555 + struct ieee80211_tx_rate *rates,
2556 + int max_rates)
2557 +{
2558 + enum nl80211_chan_width chan_width;
2559 + u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2560 + bool has_mcs_mask;
2561 + u32 mask;
2562 + int i;
2563 +
2564 + /*
2565 + * Try to enforce the rateidx mask the user wanted. skip this if the
2566 + * default mask (allow all rates) is used to save some processing for
2567 + * the common case.
2568 + */
2569 + mask = sdata->rc_rateidx_mask[info->band];
2570 + has_mcs_mask = sdata->rc_has_mcs_mask[info->band];
2571 + if (mask == (1 << sband->n_bitrates) - 1 && !has_mcs_mask)
2572 + return;
2573 +
2574 + if (has_mcs_mask)
2575 + memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2576 + sizeof(mcs_mask));
2577 + else
2578 + memset(mcs_mask, 0xff, sizeof(mcs_mask));
2579 +
2580 + if (sta) {
2581 + /* Filter out rates that the STA does not support */
2582 + mask &= sta->supp_rates[info->band];
2583 + for (i = 0; i < sizeof(mcs_mask); i++)
2584 + mcs_mask[i] &= sta->ht_cap.mcs.rx_mask[i];
2585 + }
2586 +
2587 + /*
2588 + * Make sure the rate index selected for each TX rate is
2589 + * included in the configured mask and change the rate indexes
2590 + * if needed.
2591 + */
2592 + chan_width = sdata->vif.bss_conf.chandef.width;
2593 + for (i = 0; i < max_rates; i++) {
2594 + /* Skip invalid rates */
2595 + if (rates[i].idx < 0)
2596 + break;
2597 +
2598 + rate_idx_match_mask(&rates[i], sband, chan_width, mask,
2599 + mcs_mask);
2600 + }
2601 +}
2602 +
2603 +void ieee80211_get_tx_rates(struct ieee80211_vif *vif,
2604 + struct ieee80211_sta *sta,
2605 + struct sk_buff *skb,
2606 + struct ieee80211_tx_rate *dest,
2607 + int max_rates)
2608 +{
2609 + struct ieee80211_sub_if_data *sdata;
2610 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
2611 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2612 + struct ieee80211_supported_band *sband;
2613 +
2614 + rate_control_fill_sta_table(sta, info, dest, max_rates);
2615 +
2616 + if (!vif)
2617 + return;
2618 +
2619 + sdata = vif_to_sdata(vif);
2620 + sband = sdata->local->hw.wiphy->bands[info->band];
2621 +
2622 + if (ieee80211_is_data(hdr->frame_control))
2623 + rate_control_apply_mask(sdata, sta, sband, info, dest, max_rates);
2624 +
2625 + if (dest[0].idx < 0)
2626 + __rate_control_send_low(&sdata->local->hw, sband, sta, info);
2627 +
2628 + if (sta)
2629 + rate_fixup_ratelist(vif, sband, info, dest, max_rates);
2630 +}
2631 +EXPORT_SYMBOL(ieee80211_get_tx_rates);
2632 +
2633 void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
2634 struct sta_info *sta,
2635 struct ieee80211_tx_rate_control *txrc)
2636 @@ -435,8 +659,6 @@ void rate_control_get_rate(struct ieee80
2637 struct ieee80211_sta *ista = NULL;
2638 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
2639 int i;
2640 - u32 mask;
2641 - u8 mcs_mask[IEEE80211_HT_MCS_MASK_LEN];
2642
2643 if (sta && test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) {
2644 ista = &sta->sta;
2645 @@ -454,37 +676,27 @@ void rate_control_get_rate(struct ieee80
2646
2647 ref->ops->get_rate(ref->priv, ista, priv_sta, txrc);
2648
2649 - /*
2650 - * Try to enforce the rateidx mask the user wanted. skip this if the
2651 - * default mask (allow all rates) is used to save some processing for
2652 - * the common case.
2653 - */
2654 - mask = sdata->rc_rateidx_mask[info->band];
2655 - memcpy(mcs_mask, sdata->rc_rateidx_mcs_mask[info->band],
2656 - sizeof(mcs_mask));
2657 - if (mask != (1 << txrc->sband->n_bitrates) - 1) {
2658 - if (sta) {
2659 - /* Filter out rates that the STA does not support */
2660 - mask &= sta->sta.supp_rates[info->band];
2661 - for (i = 0; i < sizeof(mcs_mask); i++)
2662 - mcs_mask[i] &= sta->sta.ht_cap.mcs.rx_mask[i];
2663 - }
2664 - /*
2665 - * Make sure the rate index selected for each TX rate is
2666 - * included in the configured mask and change the rate indexes
2667 - * if needed.
2668 - */
2669 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
2670 - /* Skip invalid rates */
2671 - if (info->control.rates[i].idx < 0)
2672 - break;
2673 - rate_idx_match_mask(&info->control.rates[i], txrc,
2674 - mask, mcs_mask);
2675 - }
2676 - }
2677 + if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_RC_TABLE)
2678 + return;
2679
2680 - BUG_ON(info->control.rates[0].idx < 0);
2681 + ieee80211_get_tx_rates(&sdata->vif, ista, txrc->skb,
2682 + info->control.rates,
2683 + ARRAY_SIZE(info->control.rates));
2684 +}
2685 +
2686 +int rate_control_set_rates(struct ieee80211_hw *hw,
2687 + struct ieee80211_sta *pubsta,
2688 + struct ieee80211_sta_rates *rates)
2689 +{
2690 + struct ieee80211_sta_rates *old = rcu_dereference(pubsta->rates);
2691 +
2692 + rcu_assign_pointer(pubsta->rates, rates);
2693 + if (old)
2694 + kfree_rcu(old, rcu_head);
2695 +
2696 + return 0;
2697 }
2698 +EXPORT_SYMBOL(rate_control_set_rates);
2699
2700 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
2701 const char *name)
2702 --- a/net/mac80211/rc80211_minstrel.c
2703 +++ b/net/mac80211/rc80211_minstrel.c
2704 @@ -84,6 +84,50 @@ minstrel_sort_best_tp_rates(struct minst
2705 }
2706
2707 static void
2708 +minstrel_set_rate(struct minstrel_sta_info *mi, struct ieee80211_sta_rates *ratetbl,
2709 + int offset, int idx)
2710 +{
2711 + struct minstrel_rate *r = &mi->r[idx];
2712 +
2713 + ratetbl->rate[offset].idx = r->rix;
2714 + ratetbl->rate[offset].count = r->adjusted_retry_count;
2715 + ratetbl->rate[offset].count_cts = r->retry_count_cts;
2716 + ratetbl->rate[offset].count_rts = r->retry_count_rtscts;
2717 +}
2718 +
2719 +static void
2720 +minstrel_update_rates(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2721 +{
2722 + struct ieee80211_sta_rates *ratetbl;
2723 + int i = 0;
2724 +
2725 + ratetbl = kzalloc(sizeof(*ratetbl), GFP_ATOMIC);
2726 + if (!ratetbl)
2727 + return;
2728 +
2729 + /* Start with max_tp_rate */
2730 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[0]);
2731 +
2732 + if (mp->hw->max_rates >= 3) {
2733 + /* At least 3 tx rates supported, use max_tp_rate2 next */
2734 + minstrel_set_rate(mi, ratetbl, i++, mi->max_tp_rate[1]);
2735 + }
2736 +
2737 + if (mp->hw->max_rates >= 2) {
2738 + /* At least 2 tx rates supported, use max_prob_rate next */
2739 + minstrel_set_rate(mi, ratetbl, i++, mi->max_prob_rate);
2740 + }
2741 +
2742 + /* Use lowest rate last */
2743 + ratetbl->rate[i].idx = mi->lowest_rix;
2744 + ratetbl->rate[i].count = mp->max_retry;
2745 + ratetbl->rate[i].count_cts = mp->max_retry;
2746 + ratetbl->rate[i].count_rts = mp->max_retry;
2747 +
2748 + rate_control_set_rates(mp->hw, mi->sta, ratetbl);
2749 +}
2750 +
2751 +static void
2752 minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
2753 {
2754 u8 tmp_tp_rate[MAX_THR_RATES];
2755 @@ -161,6 +205,8 @@ minstrel_update_stats(struct minstrel_pr
2756
2757 /* Reset update timer */
2758 mi->stats_update = jiffies;
2759 +
2760 + minstrel_update_rates(mp, mi);
2761 }
2762
2763 static void
2764 @@ -209,9 +255,9 @@ minstrel_get_retry_count(struct minstrel
2765 {
2766 unsigned int retry = mr->adjusted_retry_count;
2767
2768 - if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS)
2769 + if (info->control.use_rts)
2770 retry = max(2U, min(mr->retry_count_rtscts, retry));
2771 - else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
2772 + else if (info->control.use_cts_prot)
2773 retry = max(2U, min(mr->retry_count_cts, retry));
2774 return retry;
2775 }
2776 @@ -240,13 +286,12 @@ minstrel_get_rate(void *priv, struct iee
2777 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2778 struct minstrel_sta_info *mi = priv_sta;
2779 struct minstrel_priv *mp = priv;
2780 - struct ieee80211_tx_rate *ar = info->control.rates;
2781 - unsigned int ndx, sample_ndx = 0;
2782 + struct ieee80211_tx_rate *rate = &info->control.rates[0];
2783 + struct minstrel_rate *msr, *mr;
2784 + unsigned int ndx;
2785 bool mrr_capable;
2786 - bool indirect_rate_sampling = false;
2787 - bool rate_sampling = false;
2788 - int i, delta;
2789 - int mrr_ndx[3];
2790 + bool prev_sample = mi->prev_sample;
2791 + int delta;
2792 int sampling_ratio;
2793
2794 /* management/no-ack frames do not use rate control */
2795 @@ -262,107 +307,75 @@ minstrel_get_rate(void *priv, struct iee
2796 else
2797 sampling_ratio = mp->lookaround_rate;
2798
2799 - /* init rateindex [ndx] with max throughput rate */
2800 - ndx = mi->max_tp_rate[0];
2801 -
2802 /* increase sum packet counter */
2803 mi->packet_count++;
2804
2805 delta = (mi->packet_count * sampling_ratio / 100) -
2806 (mi->sample_count + mi->sample_deferred / 2);
2807
2808 - /* delta > 0: sampling required */
2809 - if ((delta > 0) && (mrr_capable || !mi->prev_sample)) {
2810 - struct minstrel_rate *msr;
2811 - if (mi->packet_count >= 10000) {
2812 - mi->sample_deferred = 0;
2813 - mi->sample_count = 0;
2814 - mi->packet_count = 0;
2815 - } else if (delta > mi->n_rates * 2) {
2816 - /* With multi-rate retry, not every planned sample
2817 - * attempt actually gets used, due to the way the retry
2818 - * chain is set up - [max_tp,sample,prob,lowest] for
2819 - * sample_rate < max_tp.
2820 - *
2821 - * If there's too much sampling backlog and the link
2822 - * starts getting worse, minstrel would start bursting
2823 - * out lots of sampling frames, which would result
2824 - * in a large throughput loss. */
2825 - mi->sample_count += (delta - mi->n_rates * 2);
2826 - }
2827 + /* delta < 0: no sampling required */
2828 + mi->prev_sample = false;
2829 + if (delta < 0 || (!mrr_capable && prev_sample))
2830 + return;
2831
2832 - /* get next random rate sample */
2833 - sample_ndx = minstrel_get_next_sample(mi);
2834 - msr = &mi->r[sample_ndx];
2835 - rate_sampling = true;
2836 -
2837 - /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2838 - * rate sampling method should be used.
2839 - * Respect such rates that are not sampled for 20 interations.
2840 - */
2841 - if (mrr_capable &&
2842 - msr->perfect_tx_time > mi->r[ndx].perfect_tx_time &&
2843 - msr->sample_skipped < 20)
2844 - indirect_rate_sampling = true;
2845 -
2846 - if (!indirect_rate_sampling) {
2847 - if (msr->sample_limit != 0) {
2848 - ndx = sample_ndx;
2849 - mi->sample_count++;
2850 - if (msr->sample_limit > 0)
2851 - msr->sample_limit--;
2852 - } else
2853 - rate_sampling = false;
2854 - } else {
2855 - /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2856 - * packets that have the sampling rate deferred to the
2857 - * second MRR stage. Increase the sample counter only
2858 - * if the deferred sample rate was actually used.
2859 - * Use the sample_deferred counter to make sure that
2860 - * the sampling is not done in large bursts */
2861 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2862 - mi->sample_deferred++;
2863 - }
2864 + if (mi->packet_count >= 10000) {
2865 + mi->sample_deferred = 0;
2866 + mi->sample_count = 0;
2867 + mi->packet_count = 0;
2868 + } else if (delta > mi->n_rates * 2) {
2869 + /* With multi-rate retry, not every planned sample
2870 + * attempt actually gets used, due to the way the retry
2871 + * chain is set up - [max_tp,sample,prob,lowest] for
2872 + * sample_rate < max_tp.
2873 + *
2874 + * If there's too much sampling backlog and the link
2875 + * starts getting worse, minstrel would start bursting
2876 + * out lots of sampling frames, which would result
2877 + * in a large throughput loss. */
2878 + mi->sample_count += (delta - mi->n_rates * 2);
2879 + }
2880 +
2881 + /* get next random rate sample */
2882 + ndx = minstrel_get_next_sample(mi);
2883 + msr = &mi->r[ndx];
2884 + mr = &mi->r[mi->max_tp_rate[0]];
2885 +
2886 + /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage)
2887 + * rate sampling method should be used.
2888 + * Respect such rates that are not sampled for 20 interations.
2889 + */
2890 + if (mrr_capable &&
2891 + msr->perfect_tx_time > mr->perfect_tx_time &&
2892 + msr->sample_skipped < 20) {
2893 + /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark
2894 + * packets that have the sampling rate deferred to the
2895 + * second MRR stage. Increase the sample counter only
2896 + * if the deferred sample rate was actually used.
2897 + * Use the sample_deferred counter to make sure that
2898 + * the sampling is not done in large bursts */
2899 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
2900 + rate++;
2901 + mi->sample_deferred++;
2902 + } else {
2903 + if (!msr->sample_limit != 0)
2904 + return;
2905 +
2906 + mi->sample_count++;
2907 + if (msr->sample_limit > 0)
2908 + msr->sample_limit--;
2909 }
2910 - mi->prev_sample = rate_sampling;
2911
2912 /* If we're not using MRR and the sampling rate already
2913 * has a probability of >95%, we shouldn't be attempting
2914 * to use it, as this only wastes precious airtime */
2915 - if (!mrr_capable && rate_sampling &&
2916 + if (!mrr_capable &&
2917 (mi->r[ndx].probability > MINSTREL_FRAC(95, 100)))
2918 - ndx = mi->max_tp_rate[0];
2919 -
2920 - /* mrr setup for 1st stage */
2921 - ar[0].idx = mi->r[ndx].rix;
2922 - ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info);
2923 -
2924 - /* non mrr setup for 2nd stage */
2925 - if (!mrr_capable) {
2926 - if (!rate_sampling)
2927 - ar[0].count = mp->max_retry;
2928 - ar[1].idx = mi->lowest_rix;
2929 - ar[1].count = mp->max_retry;
2930 return;
2931 - }
2932
2933 - /* mrr setup for 2nd stage */
2934 - if (rate_sampling) {
2935 - if (indirect_rate_sampling)
2936 - mrr_ndx[0] = sample_ndx;
2937 - else
2938 - mrr_ndx[0] = mi->max_tp_rate[0];
2939 - } else {
2940 - mrr_ndx[0] = mi->max_tp_rate[1];
2941 - }
2942 + mi->prev_sample = true;
2943
2944 - /* mrr setup for 3rd & 4th stage */
2945 - mrr_ndx[1] = mi->max_prob_rate;
2946 - mrr_ndx[2] = 0;
2947 - for (i = 1; i < 4; i++) {
2948 - ar[i].idx = mi->r[mrr_ndx[i - 1]].rix;
2949 - ar[i].count = mi->r[mrr_ndx[i - 1]].adjusted_retry_count;
2950 - }
2951 + rate->idx = mi->r[ndx].rix;
2952 + rate->count = minstrel_get_retry_count(&mi->r[ndx], info);
2953 }
2954
2955
2956 @@ -412,12 +425,16 @@ minstrel_rate_init(void *priv, struct ie
2957 unsigned int i, n = 0;
2958 unsigned int t_slot = 9; /* FIXME: get real slot time */
2959
2960 + mi->sta = sta;
2961 mi->lowest_rix = rate_lowest_index(sband, sta);
2962 ctl_rate = &sband->bitrates[mi->lowest_rix];
2963 mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
2964 ctl_rate->bitrate,
2965 !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
2966
2967 + memset(mi->max_tp_rate, 0, sizeof(mi->max_tp_rate));
2968 + mi->max_prob_rate = 0;
2969 +
2970 for (i = 0; i < sband->n_bitrates; i++) {
2971 struct minstrel_rate *mr = &mi->r[n];
2972 unsigned int tx_time = 0, tx_time_cts = 0, tx_time_rtscts = 0;
2973 @@ -460,6 +477,8 @@ minstrel_rate_init(void *priv, struct ie
2974 } while ((tx_time < mp->segment_size) &&
2975 (++mr->retry_count < mp->max_retry));
2976 mr->adjusted_retry_count = mr->retry_count;
2977 + if (!(sband->bitrates[i].flags & IEEE80211_RATE_ERP_G))
2978 + mr->retry_count_cts = mr->retry_count;
2979 }
2980
2981 for (i = n; i < sband->n_bitrates; i++) {
2982 @@ -471,6 +490,7 @@ minstrel_rate_init(void *priv, struct ie
2983 mi->stats_update = jiffies;
2984
2985 init_sample_table(mi);
2986 + minstrel_update_rates(mp, mi);
2987 }
2988
2989 static void *
2990 --- a/net/mac80211/rc80211_minstrel.h
2991 +++ b/net/mac80211/rc80211_minstrel.h
2992 @@ -9,7 +9,8 @@
2993 #ifndef __RC_MINSTREL_H
2994 #define __RC_MINSTREL_H
2995
2996 -#define EWMA_LEVEL 75 /* ewma weighting factor [%] */
2997 +#define EWMA_LEVEL 96 /* ewma weighting factor [/EWMA_DIV] */
2998 +#define EWMA_DIV 128
2999 #define SAMPLE_COLUMNS 10 /* number of columns in sample table */
3000
3001
3002 @@ -27,7 +28,7 @@
3003 static inline int
3004 minstrel_ewma(int old, int new, int weight)
3005 {
3006 - return (new * (100 - weight) + old * weight) / 100;
3007 + return (new * (EWMA_DIV - weight) + old * weight) / EWMA_DIV;
3008 }
3009
3010
3011 @@ -62,6 +63,8 @@ struct minstrel_rate {
3012 };
3013
3014 struct minstrel_sta_info {
3015 + struct ieee80211_sta *sta;
3016 +
3017 unsigned long stats_update;
3018 unsigned int sp_ack_dur;
3019 unsigned int rate_avg;
3020 --- a/net/mac80211/rc80211_minstrel_debugfs.c
3021 +++ b/net/mac80211/rc80211_minstrel_debugfs.c
3022 @@ -68,7 +68,7 @@ minstrel_stats_open(struct inode *inode,
3023
3024 file->private_data = ms;
3025 p = ms->buf;
3026 - p += sprintf(p, "rate throughput ewma prob this prob "
3027 + p += sprintf(p, "rate throughput ewma prob this prob "
3028 "this succ/attempt success attempts\n");
3029 for (i = 0; i < mi->n_rates; i++) {
3030 struct minstrel_rate *mr = &mi->r[i];
3031 @@ -86,7 +86,7 @@ minstrel_stats_open(struct inode *inode,
3032 eprob = MINSTREL_TRUNC(mr->probability * 1000);
3033
3034 p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u "
3035 - "%3u(%3u) %8llu %8llu\n",
3036 + " %3u(%3u) %8llu %8llu\n",
3037 tp / 10, tp % 10,
3038 eprob / 10, eprob % 10,
3039 prob / 10, prob % 10,
3040 --- a/net/mac80211/rc80211_minstrel_ht.c
3041 +++ b/net/mac80211/rc80211_minstrel_ht.c
3042 @@ -126,6 +126,9 @@ const struct mcs_group minstrel_mcs_grou
3043
3044 static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES];
3045
3046 +static void
3047 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi);
3048 +
3049 /*
3050 * Look up an MCS group index based on mac80211 rate information
3051 */
3052 @@ -244,6 +247,7 @@ minstrel_ht_update_stats(struct minstrel
3053 struct minstrel_rate_stats *mr;
3054 int cur_prob, cur_prob_tp, cur_tp, cur_tp2;
3055 int group, i, index;
3056 + bool mi_rates_valid = false;
3057
3058 if (mi->ampdu_packets > 0) {
3059 mi->avg_ampdu_len = minstrel_ewma(mi->avg_ampdu_len,
3060 @@ -254,11 +258,10 @@ minstrel_ht_update_stats(struct minstrel
3061
3062 mi->sample_slow = 0;
3063 mi->sample_count = 0;
3064 - mi->max_tp_rate = 0;
3065 - mi->max_tp_rate2 = 0;
3066 - mi->max_prob_rate = 0;
3067
3068 for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) {
3069 + bool mg_rates_valid = false;
3070 +
3071 cur_prob = 0;
3072 cur_prob_tp = 0;
3073 cur_tp = 0;
3074 @@ -268,15 +271,24 @@ minstrel_ht_update_stats(struct minstrel
3075 if (!mg->supported)
3076 continue;
3077
3078 - mg->max_tp_rate = 0;
3079 - mg->max_tp_rate2 = 0;
3080 - mg->max_prob_rate = 0;
3081 mi->sample_count++;
3082
3083 for (i = 0; i < MCS_GROUP_RATES; i++) {
3084 if (!(mg->supported & BIT(i)))
3085 continue;
3086
3087 + /* initialize rates selections starting indexes */
3088 + if (!mg_rates_valid) {
3089 + mg->max_tp_rate = mg->max_tp_rate2 =
3090 + mg->max_prob_rate = i;
3091 + if (!mi_rates_valid) {
3092 + mi->max_tp_rate = mi->max_tp_rate2 =
3093 + mi->max_prob_rate = i;
3094 + mi_rates_valid = true;
3095 + }
3096 + mg_rates_valid = true;
3097 + }
3098 +
3099 mr = &mg->rates[i];
3100 mr->retry_updated = false;
3101 index = MCS_GROUP_RATES * group + i;
3102 @@ -456,7 +468,7 @@ minstrel_ht_tx_status(void *priv, struct
3103 struct ieee80211_tx_rate *ar = info->status.rates;
3104 struct minstrel_rate_stats *rate, *rate2;
3105 struct minstrel_priv *mp = priv;
3106 - bool last;
3107 + bool last, update = false;
3108 int i;
3109
3110 if (!msp->is_ht)
3111 @@ -505,21 +517,29 @@ minstrel_ht_tx_status(void *priv, struct
3112 rate = minstrel_get_ratestats(mi, mi->max_tp_rate);
3113 if (rate->attempts > 30 &&
3114 MINSTREL_FRAC(rate->success, rate->attempts) <
3115 - MINSTREL_FRAC(20, 100))
3116 + MINSTREL_FRAC(20, 100)) {
3117 minstrel_downgrade_rate(mi, &mi->max_tp_rate, true);
3118 + update = true;
3119 + }
3120
3121 rate2 = minstrel_get_ratestats(mi, mi->max_tp_rate2);
3122 if (rate2->attempts > 30 &&
3123 MINSTREL_FRAC(rate2->success, rate2->attempts) <
3124 - MINSTREL_FRAC(20, 100))
3125 + MINSTREL_FRAC(20, 100)) {
3126 minstrel_downgrade_rate(mi, &mi->max_tp_rate2, false);
3127 + update = true;
3128 + }
3129
3130 if (time_after(jiffies, mi->stats_update + (mp->update_interval / 2 * HZ) / 1000)) {
3131 + update = true;
3132 minstrel_ht_update_stats(mp, mi);
3133 if (!(info->flags & IEEE80211_TX_CTL_AMPDU) &&
3134 mi->max_prob_rate / MCS_GROUP_RATES != MINSTREL_CCK_GROUP)
3135 minstrel_aggr_check(sta, skb);
3136 }
3137 +
3138 + if (update)
3139 + minstrel_ht_update_rates(mp, mi);
3140 }
3141
3142 static void
3143 @@ -580,39 +600,73 @@ minstrel_calc_retransmit(struct minstrel
3144 (++mr->retry_count < mp->max_retry));
3145 }
3146
3147 -
3148 static void
3149 minstrel_ht_set_rate(struct minstrel_priv *mp, struct minstrel_ht_sta *mi,
3150 - struct ieee80211_tx_rate *rate, int index,
3151 - bool sample, bool rtscts)
3152 + struct ieee80211_sta_rates *ratetbl, int offset, int index)
3153 {
3154 const struct mcs_group *group = &minstrel_mcs_groups[index / MCS_GROUP_RATES];
3155 struct minstrel_rate_stats *mr;
3156 + u8 idx;
3157 + u16 flags;
3158
3159 mr = minstrel_get_ratestats(mi, index);
3160 if (!mr->retry_updated)
3161 minstrel_calc_retransmit(mp, mi, index);
3162
3163 - if (sample)
3164 - rate->count = 1;
3165 - else if (mr->probability < MINSTREL_FRAC(20, 100))
3166 - rate->count = 2;
3167 - else if (rtscts)
3168 - rate->count = mr->retry_count_rtscts;
3169 - else
3170 - rate->count = mr->retry_count;
3171 -
3172 - rate->flags = 0;
3173 - if (rtscts)
3174 - rate->flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3175 + if (mr->probability < MINSTREL_FRAC(20, 100) || !mr->retry_count) {
3176 + ratetbl->rate[offset].count = 2;
3177 + ratetbl->rate[offset].count_rts = 2;
3178 + ratetbl->rate[offset].count_cts = 2;
3179 + } else {
3180 + ratetbl->rate[offset].count = mr->retry_count;
3181 + ratetbl->rate[offset].count_cts = mr->retry_count;
3182 + ratetbl->rate[offset].count_rts = mr->retry_count_rtscts;
3183 + }
3184
3185 if (index / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
3186 - rate->idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3187 + idx = mp->cck_rates[index % ARRAY_SIZE(mp->cck_rates)];
3188 + flags = 0;
3189 + } else {
3190 + idx = index % MCS_GROUP_RATES +
3191 + (group->streams - 1) * MCS_GROUP_RATES;
3192 + flags = IEEE80211_TX_RC_MCS | group->flags;
3193 + }
3194 +
3195 + if (offset > 0) {
3196 + ratetbl->rate[offset].count = ratetbl->rate[offset].count_rts;
3197 + flags |= IEEE80211_TX_RC_USE_RTS_CTS;
3198 + }
3199 +
3200 + ratetbl->rate[offset].idx = idx;
3201 + ratetbl->rate[offset].flags = flags;
3202 +}
3203 +
3204 +static void
3205 +minstrel_ht_update_rates(struct minstrel_priv *mp, struct minstrel_ht_sta *mi)
3206 +{
3207 + struct ieee80211_sta_rates *rates;
3208 + int i = 0;
3209 +
3210 + rates = kzalloc(sizeof(*rates), GFP_ATOMIC);
3211 + if (!rates)
3212 return;
3213 +
3214 + /* Start with max_tp_rate */
3215 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate);
3216 +
3217 + if (mp->hw->max_rates >= 3) {
3218 + /* At least 3 tx rates supported, use max_tp_rate2 next */
3219 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_tp_rate2);
3220 + }
3221 +
3222 + if (mp->hw->max_rates >= 2) {
3223 + /*
3224 + * At least 2 tx rates supported, use max_prob_rate next */
3225 + minstrel_ht_set_rate(mp, mi, rates, i++, mi->max_prob_rate);
3226 }
3227
3228 - rate->flags |= IEEE80211_TX_RC_MCS | group->flags;
3229 - rate->idx = index % MCS_GROUP_RATES + (group->streams - 1) * MCS_GROUP_RATES;
3230 + rates->rate[i].idx = -1;
3231 + rate_control_set_rates(mp->hw, mi->sta, rates);
3232 }
3233
3234 static inline int
3235 @@ -702,13 +756,13 @@ static void
3236 minstrel_ht_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
3237 struct ieee80211_tx_rate_control *txrc)
3238 {
3239 + const struct mcs_group *sample_group;
3240 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
3241 - struct ieee80211_tx_rate *ar = info->status.rates;
3242 + struct ieee80211_tx_rate *rate = &info->status.rates[0];
3243 struct minstrel_ht_sta_priv *msp = priv_sta;
3244 struct minstrel_ht_sta *mi = &msp->ht;
3245 struct minstrel_priv *mp = priv;
3246 int sample_idx;
3247 - bool sample = false;
3248
3249 if (rate_control_send_low(sta, priv_sta, txrc))
3250 return;
3251 @@ -736,51 +790,6 @@ minstrel_ht_get_rate(void *priv, struct
3252 }
3253 #endif
3254
3255 - if (sample_idx >= 0) {
3256 - sample = true;
3257 - minstrel_ht_set_rate(mp, mi, &ar[0], sample_idx,
3258 - true, false);
3259 - info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3260 - } else {
3261 - minstrel_ht_set_rate(mp, mi, &ar[0], mi->max_tp_rate,
3262 - false, false);
3263 - }
3264 -
3265 - if (mp->hw->max_rates >= 3) {
3266 - /*
3267 - * At least 3 tx rates supported, use
3268 - * sample_rate -> max_tp_rate -> max_prob_rate for sampling and
3269 - * max_tp_rate -> max_tp_rate2 -> max_prob_rate by default.
3270 - */
3271 - if (sample_idx >= 0)
3272 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate,
3273 - false, false);
3274 - else
3275 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_tp_rate2,
3276 - false, true);
3277 -
3278 - minstrel_ht_set_rate(mp, mi, &ar[2], mi->max_prob_rate,
3279 - false, !sample);
3280 -
3281 - ar[3].count = 0;
3282 - ar[3].idx = -1;
3283 - } else if (mp->hw->max_rates == 2) {
3284 - /*
3285 - * Only 2 tx rates supported, use
3286 - * sample_rate -> max_prob_rate for sampling and
3287 - * max_tp_rate -> max_prob_rate by default.
3288 - */
3289 - minstrel_ht_set_rate(mp, mi, &ar[1], mi->max_prob_rate,
3290 - false, !sample);
3291 -
3292 - ar[2].count = 0;
3293 - ar[2].idx = -1;
3294 - } else {
3295 - /* Not using MRR, only use the first rate */
3296 - ar[1].count = 0;
3297 - ar[1].idx = -1;
3298 - }
3299 -
3300 mi->total_packets++;
3301
3302 /* wraparound */
3303 @@ -788,6 +797,16 @@ minstrel_ht_get_rate(void *priv, struct
3304 mi->total_packets = 0;
3305 mi->sample_packets = 0;
3306 }
3307 +
3308 + if (sample_idx < 0)
3309 + return;
3310 +
3311 + sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
3312 + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
3313 + rate->idx = sample_idx % MCS_GROUP_RATES +
3314 + (sample_group->streams - 1) * MCS_GROUP_RATES;
3315 + rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
3316 + rate->count = 1;
3317 }
3318
3319 static void
3320 @@ -837,6 +856,8 @@ minstrel_ht_update_caps(void *priv, stru
3321
3322 msp->is_ht = true;
3323 memset(mi, 0, sizeof(*mi));
3324 +
3325 + mi->sta = sta;
3326 mi->stats_update = jiffies;
3327
3328 ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
3329 @@ -898,6 +919,9 @@ minstrel_ht_update_caps(void *priv, stru
3330 if (!n_supported)
3331 goto use_legacy;
3332
3333 + minstrel_ht_update_stats(mp, mi);
3334 + minstrel_ht_update_rates(mp, mi);
3335 +
3336 return;
3337
3338 use_legacy:
3339 --- a/net/mac80211/rc80211_minstrel_ht.h
3340 +++ b/net/mac80211/rc80211_minstrel_ht.h
3341 @@ -65,6 +65,8 @@ struct minstrel_mcs_group_data {
3342 };
3343
3344 struct minstrel_ht_sta {
3345 + struct ieee80211_sta *sta;
3346 +
3347 /* ampdu length (average, per sampling interval) */
3348 unsigned int ampdu_len;
3349 unsigned int ampdu_packets;
3350 --- a/net/mac80211/rx.c
3351 +++ b/net/mac80211/rx.c
3352 @@ -1372,6 +1372,7 @@ ieee80211_rx_h_sta_process(struct ieee80
3353 struct sk_buff *skb = rx->skb;
3354 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
3355 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3356 + int i;
3357
3358 if (!sta)
3359 return RX_CONTINUE;
3360 @@ -1422,6 +1423,19 @@ ieee80211_rx_h_sta_process(struct ieee80
3361 ewma_add(&sta->avg_signal, -status->signal);
3362 }
3363
3364 + if (status->chains) {
3365 + sta->chains = status->chains;
3366 + for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
3367 + int signal = status->chain_signal[i];
3368 +
3369 + if (!(status->chains & BIT(i)))
3370 + continue;
3371 +
3372 + sta->chain_signal_last[i] = signal;
3373 + ewma_add(&sta->chain_signal_avg[i], -signal);
3374 + }
3375 + }
3376 +
3377 /*
3378 * Change STA power saving mode only at the end of a frame
3379 * exchange sequence.
3380 @@ -2085,6 +2099,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
3381 }
3382
3383 fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
3384 + fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
3385 info = IEEE80211_SKB_CB(fwd_skb);
3386 memset(info, 0, sizeof(*info));
3387 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
3388 @@ -2356,6 +2371,7 @@ ieee80211_rx_h_action(struct ieee80211_r
3389 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3390 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
3391 sdata->vif.type != NL80211_IFTYPE_AP &&
3392 + sdata->vif.type != NL80211_IFTYPE_WDS &&
3393 sdata->vif.type != NL80211_IFTYPE_ADHOC)
3394 break;
3395
3396 @@ -2423,6 +2439,22 @@ ieee80211_rx_h_action(struct ieee80211_r
3397 }
3398
3399 break;
3400 + case WLAN_CATEGORY_PUBLIC:
3401 + if (len < IEEE80211_MIN_ACTION_SIZE + 1)
3402 + goto invalid;
3403 + if (sdata->vif.type != NL80211_IFTYPE_STATION)
3404 + break;
3405 + if (!rx->sta)
3406 + break;
3407 + if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
3408 + break;
3409 + if (mgmt->u.action.u.ext_chan_switch.action_code !=
3410 + WLAN_PUB_ACTION_EXT_CHANSW_ANN)
3411 + break;
3412 + if (len < offsetof(struct ieee80211_mgmt,
3413 + u.action.u.ext_chan_switch.variable))
3414 + goto invalid;
3415 + goto queue;
3416 case WLAN_CATEGORY_VHT:
3417 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
3418 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
3419 @@ -2506,10 +2538,6 @@ ieee80211_rx_h_action(struct ieee80211_r
3420 ieee80211_process_measurement_req(sdata, mgmt, len);
3421 goto handled;
3422 case WLAN_ACTION_SPCT_CHL_SWITCH:
3423 - if (len < (IEEE80211_MIN_ACTION_SIZE +
3424 - sizeof(mgmt->u.action.u.chan_switch)))
3425 - break;
3426 -
3427 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3428 break;
3429
3430 @@ -2695,14 +2723,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
3431
3432 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
3433 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3434 - sdata->vif.type != NL80211_IFTYPE_STATION)
3435 + sdata->vif.type != NL80211_IFTYPE_STATION &&
3436 + sdata->vif.type != NL80211_IFTYPE_WDS)
3437 return RX_DROP_MONITOR;
3438
3439 switch (stype) {
3440 case cpu_to_le16(IEEE80211_STYPE_AUTH):
3441 case cpu_to_le16(IEEE80211_STYPE_BEACON):
3442 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
3443 - /* process for all: mesh, mlme, ibss */
3444 + /* process for all: mesh, mlme, ibss, wds */
3445 break;
3446 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
3447 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
3448 @@ -3023,6 +3052,9 @@ static int prepare_for_handlers(struct i
3449 * and location updates. Note that mac80211
3450 * itself never looks at these frames.
3451 */
3452 + if (!multicast &&
3453 + !ether_addr_equal(sdata->vif.addr, hdr->addr1))
3454 + return 0;
3455 if (ieee80211_is_public_action(hdr, skb->len))
3456 return 1;
3457 if (!ieee80211_is_beacon(hdr->frame_control))
3458 @@ -3031,10 +3063,16 @@ static int prepare_for_handlers(struct i
3459 }
3460 break;
3461 case NL80211_IFTYPE_WDS:
3462 - if (bssid || !ieee80211_is_data(hdr->frame_control))
3463 - return 0;
3464 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
3465 return 0;
3466 +
3467 + if (ieee80211_is_data(hdr->frame_control) ||
3468 + ieee80211_is_action(hdr->frame_control)) {
3469 + if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
3470 + return 0;
3471 + } else if (!ieee80211_is_beacon(hdr->frame_control))
3472 + return 0;
3473 +
3474 break;
3475 case NL80211_IFTYPE_P2P_DEVICE:
3476 if (!ieee80211_is_public_action(hdr, skb->len) &&
3477 --- a/net/mac80211/scan.c
3478 +++ b/net/mac80211/scan.c
3479 @@ -181,7 +181,7 @@ void ieee80211_scan_rx(struct ieee80211_
3480 if (baselen > skb->len)
3481 return;
3482
3483 - ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
3484 + ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
3485
3486 channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
3487
3488 --- a/net/mac80211/sta_info.h
3489 +++ b/net/mac80211/sta_info.h
3490 @@ -32,7 +32,6 @@
3491 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
3492 * frames.
3493 * @WLAN_STA_WME: Station is a QoS-STA.
3494 - * @WLAN_STA_WDS: Station is one of our WDS peers.
3495 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
3496 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
3497 * frame to this station is transmitted.
3498 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
3499 WLAN_STA_AUTHORIZED,
3500 WLAN_STA_SHORT_PREAMBLE,
3501 WLAN_STA_WME,
3502 - WLAN_STA_WDS,
3503 WLAN_STA_CLEAR_PS_FILT,
3504 WLAN_STA_MFP,
3505 WLAN_STA_BLOCK_BA,
3506 @@ -344,6 +342,11 @@ struct sta_info {
3507 int last_signal;
3508 struct ewma avg_signal;
3509 int last_ack_signal;
3510 +
3511 + u8 chains;
3512 + s8 chain_signal_last[IEEE80211_MAX_CHAINS];
3513 + struct ewma chain_signal_avg[IEEE80211_MAX_CHAINS];
3514 +
3515 /* Plus 1 for non-QoS frames */
3516 __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
3517
3518 --- a/net/mac80211/trace.h
3519 +++ b/net/mac80211/trace.h
3520 @@ -990,23 +990,23 @@ TRACE_EVENT(drv_channel_switch,
3521
3522 TP_STRUCT__entry(
3523 LOCAL_ENTRY
3524 + CHANDEF_ENTRY
3525 __field(u64, timestamp)
3526 __field(bool, block_tx)
3527 - __field(u16, freq)
3528 __field(u8, count)
3529 ),
3530
3531 TP_fast_assign(
3532 LOCAL_ASSIGN;
3533 + CHANDEF_ASSIGN(&ch_switch->chandef)
3534 __entry->timestamp = ch_switch->timestamp;
3535 __entry->block_tx = ch_switch->block_tx;
3536 - __entry->freq = ch_switch->channel->center_freq;
3537 __entry->count = ch_switch->count;
3538 ),
3539
3540 TP_printk(
3541 - LOCAL_PR_FMT " new freq:%u count:%d",
3542 - LOCAL_PR_ARG, __entry->freq, __entry->count
3543 + LOCAL_PR_FMT " new " CHANDEF_PR_FMT " count:%d",
3544 + LOCAL_PR_ARG, CHANDEF_PR_ARG, __entry->count
3545 )
3546 );
3547
3548 --- a/net/mac80211/tx.c
3549 +++ b/net/mac80211/tx.c
3550 @@ -48,15 +48,15 @@ static __le16 ieee80211_duration(struct
3551 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
3552
3553 /* assume HW handles this */
3554 - if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
3555 + if (tx->rate.flags & IEEE80211_TX_RC_MCS)
3556 return 0;
3557
3558 /* uh huh? */
3559 - if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
3560 + if (WARN_ON_ONCE(tx->rate.idx < 0))
3561 return 0;
3562
3563 sband = local->hw.wiphy->bands[info->band];
3564 - txrate = &sband->bitrates[info->control.rates[0].idx];
3565 + txrate = &sband->bitrates[tx->rate.idx];
3566
3567 erp = txrate->flags & IEEE80211_RATE_ERP_G;
3568
3569 @@ -617,11 +617,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3570 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
3571 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
3572 struct ieee80211_supported_band *sband;
3573 - struct ieee80211_rate *rate;
3574 - int i;
3575 u32 len;
3576 - bool inval = false, rts = false, short_preamble = false;
3577 struct ieee80211_tx_rate_control txrc;
3578 + struct ieee80211_sta_rates *ratetbl = NULL;
3579 bool assoc = false;
3580
3581 memset(&txrc, 0, sizeof(txrc));
3582 @@ -642,18 +640,23 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3583 txrc.max_rate_idx = -1;
3584 else
3585 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3586 - memcpy(txrc.rate_idx_mcs_mask,
3587 - tx->sdata->rc_rateidx_mcs_mask[info->band],
3588 - sizeof(txrc.rate_idx_mcs_mask));
3589 +
3590 + if (tx->sdata->rc_has_mcs_mask[info->band])
3591 + txrc.rate_idx_mcs_mask =
3592 + tx->sdata->rc_rateidx_mcs_mask[info->band];
3593 +
3594 txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
3595 tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
3596 tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
3597
3598 /* set up RTS protection if desired */
3599 if (len > tx->local->hw.wiphy->rts_threshold) {
3600 - txrc.rts = rts = true;
3601 + txrc.rts = true;
3602 }
3603
3604 + info->control.use_rts = txrc.rts;
3605 + info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
3606 +
3607 /*
3608 * Use short preamble if the BSS can handle it, but not for
3609 * management frames unless we know the receiver can handle
3610 @@ -663,7 +666,9 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3611 if (tx->sdata->vif.bss_conf.use_short_preamble &&
3612 (ieee80211_is_data(hdr->frame_control) ||
3613 (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
3614 - txrc.short_preamble = short_preamble = true;
3615 + txrc.short_preamble = true;
3616 +
3617 + info->control.short_preamble = txrc.short_preamble;
3618
3619 if (tx->sta)
3620 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
3621 @@ -687,16 +692,38 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3622 */
3623 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
3624
3625 - if (unlikely(info->control.rates[0].idx < 0))
3626 - return TX_DROP;
3627 + if (tx->sta && !info->control.skip_table)
3628 + ratetbl = rcu_dereference(tx->sta->sta.rates);
3629 +
3630 + if (unlikely(info->control.rates[0].idx < 0)) {
3631 + if (ratetbl) {
3632 + struct ieee80211_tx_rate rate = {
3633 + .idx = ratetbl->rate[0].idx,
3634 + .flags = ratetbl->rate[0].flags,
3635 + .count = ratetbl->rate[0].count
3636 + };
3637 +
3638 + if (ratetbl->rate[0].idx < 0)
3639 + return TX_DROP;
3640 +
3641 + tx->rate = rate;
3642 + } else {
3643 + return TX_DROP;
3644 + }
3645 + } else {
3646 + tx->rate = info->control.rates[0];
3647 + }
3648
3649 if (txrc.reported_rate.idx < 0) {
3650 - txrc.reported_rate = info->control.rates[0];
3651 + txrc.reported_rate = tx->rate;
3652 if (tx->sta && ieee80211_is_data(hdr->frame_control))
3653 tx->sta->last_tx_rate = txrc.reported_rate;
3654 } else if (tx->sta)
3655 tx->sta->last_tx_rate = txrc.reported_rate;
3656
3657 + if (ratetbl)
3658 + return TX_CONTINUE;
3659 +
3660 if (unlikely(!info->control.rates[0].count))
3661 info->control.rates[0].count = 1;
3662
3663 @@ -704,91 +731,6 @@ ieee80211_tx_h_rate_ctrl(struct ieee8021
3664 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
3665 info->control.rates[0].count = 1;
3666
3667 - if (is_multicast_ether_addr(hdr->addr1)) {
3668 - /*
3669 - * XXX: verify the rate is in the basic rateset
3670 - */
3671 - return TX_CONTINUE;
3672 - }
3673 -
3674 - /*
3675 - * set up the RTS/CTS rate as the fastest basic rate
3676 - * that is not faster than the data rate
3677 - *
3678 - * XXX: Should this check all retry rates?
3679 - */
3680 - if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
3681 - s8 baserate = 0;
3682 -
3683 - rate = &sband->bitrates[info->control.rates[0].idx];
3684 -
3685 - for (i = 0; i < sband->n_bitrates; i++) {
3686 - /* must be a basic rate */
3687 - if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
3688 - continue;
3689 - /* must not be faster than the data rate */
3690 - if (sband->bitrates[i].bitrate > rate->bitrate)
3691 - continue;
3692 - /* maximum */
3693 - if (sband->bitrates[baserate].bitrate <
3694 - sband->bitrates[i].bitrate)
3695 - baserate = i;
3696 - }
3697 -
3698 - info->control.rts_cts_rate_idx = baserate;
3699 - }
3700 -
3701 - for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
3702 - /*
3703 - * make sure there's no valid rate following
3704 - * an invalid one, just in case drivers don't
3705 - * take the API seriously to stop at -1.
3706 - */
3707 - if (inval) {
3708 - info->control.rates[i].idx = -1;
3709 - continue;
3710 - }
3711 - if (info->control.rates[i].idx < 0) {
3712 - inval = true;
3713 - continue;
3714 - }
3715 -
3716 - /*
3717 - * For now assume MCS is already set up correctly, this
3718 - * needs to be fixed.
3719 - */
3720 - if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
3721 - WARN_ON(info->control.rates[i].idx > 76);
3722 - continue;
3723 - }
3724 -
3725 - /* set up RTS protection if desired */
3726 - if (rts)
3727 - info->control.rates[i].flags |=
3728 - IEEE80211_TX_RC_USE_RTS_CTS;
3729 -
3730 - /* RC is busted */
3731 - if (WARN_ON_ONCE(info->control.rates[i].idx >=
3732 - sband->n_bitrates)) {
3733 - info->control.rates[i].idx = -1;
3734 - continue;
3735 - }
3736 -
3737 - rate = &sband->bitrates[info->control.rates[i].idx];
3738 -
3739 - /* set up short preamble */
3740 - if (short_preamble &&
3741 - rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
3742 - info->control.rates[i].flags |=
3743 - IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
3744 -
3745 - /* set up G protection */
3746 - if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
3747 - rate->flags & IEEE80211_RATE_ERP_G)
3748 - info->control.rates[i].flags |=
3749 - IEEE80211_TX_RC_USE_CTS_PROTECT;
3750 - }
3751 -
3752 return TX_CONTINUE;
3753 }
3754
3755 @@ -2508,8 +2450,6 @@ struct sk_buff *ieee80211_beacon_get_tim
3756 txrc.max_rate_idx = -1;
3757 else
3758 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
3759 - memcpy(txrc.rate_idx_mcs_mask, sdata->rc_rateidx_mcs_mask[band],
3760 - sizeof(txrc.rate_idx_mcs_mask));
3761 txrc.bss = true;
3762 rate_control_get_rate(sdata, NULL, &txrc);
3763
3764 --- a/net/mac80211/util.c
3765 +++ b/net/mac80211/util.c
3766 @@ -485,7 +485,8 @@ int ieee80211_queue_stopped(struct ieee8
3767 return true;
3768
3769 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
3770 - ret = !!local->queue_stop_reasons[queue];
3771 + ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
3772 + &local->queue_stop_reasons[queue]);
3773 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
3774 return ret;
3775 }
3776 @@ -559,6 +560,9 @@ void ieee80211_iterate_active_interfaces
3777 list_for_each_entry(sdata, &local->interfaces, list) {
3778 switch (sdata->vif.type) {
3779 case NL80211_IFTYPE_MONITOR:
3780 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3781 + continue;
3782 + break;
3783 case NL80211_IFTYPE_AP_VLAN:
3784 continue;
3785 default:
3786 @@ -597,6 +601,9 @@ void ieee80211_iterate_active_interfaces
3787 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
3788 switch (sdata->vif.type) {
3789 case NL80211_IFTYPE_MONITOR:
3790 + if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
3791 + continue;
3792 + break;
3793 case NL80211_IFTYPE_AP_VLAN:
3794 continue;
3795 default:
3796 @@ -660,7 +667,7 @@ void ieee80211_queue_delayed_work(struct
3797 }
3798 EXPORT_SYMBOL(ieee80211_queue_delayed_work);
3799
3800 -u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
3801 +u32 ieee802_11_parse_elems_crc(u8 *start, size_t len, bool action,
3802 struct ieee802_11_elems *elems,
3803 u64 filter, u32 crc)
3804 {
3805 @@ -668,6 +675,7 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3806 u8 *pos = start;
3807 bool calc_crc = filter != 0;
3808 DECLARE_BITMAP(seen_elems, 256);
3809 + const u8 *ie;
3810
3811 bitmap_zero(seen_elems, 256);
3812 memset(elems, 0, sizeof(*elems));
3813 @@ -715,6 +723,12 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3814 case WLAN_EID_COUNTRY:
3815 case WLAN_EID_PWR_CONSTRAINT:
3816 case WLAN_EID_TIMEOUT_INTERVAL:
3817 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3818 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3819 + /*
3820 + * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
3821 + * that if the content gets bigger it might be needed more than once
3822 + */
3823 if (test_bit(id, seen_elems)) {
3824 elems->parse_error = true;
3825 left -= elen;
3826 @@ -862,6 +876,48 @@ u32 ieee802_11_parse_elems_crc(u8 *start
3827 }
3828 elems->ch_switch_ie = (void *)pos;
3829 break;
3830 + case WLAN_EID_EXT_CHANSWITCH_ANN:
3831 + if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
3832 + elem_parse_failed = true;
3833 + break;
3834 + }
3835 + elems->ext_chansw_ie = (void *)pos;
3836 + break;
3837 + case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
3838 + if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
3839 + elem_parse_failed = true;
3840 + break;
3841 + }
3842 + elems->sec_chan_offs = (void *)pos;
3843 + break;
3844 + case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
3845 + if (!action ||
3846 + elen != sizeof(*elems->wide_bw_chansw_ie)) {
3847 + elem_parse_failed = true;
3848 + break;
3849 + }
3850 + elems->wide_bw_chansw_ie = (void *)pos;
3851 + break;
3852 + case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
3853 + if (action) {
3854 + elem_parse_failed = true;
3855 + break;
3856 + }
3857 + /*
3858 + * This is a bit tricky, but as we only care about
3859 + * the wide bandwidth channel switch element, so
3860 + * just parse it out manually.
3861 + */
3862 + ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
3863 + pos, elen);
3864 + if (ie) {
3865 + if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
3866 + elems->wide_bw_chansw_ie =
3867 + (void *)(ie + 2);
3868 + else
3869 + elem_parse_failed = true;
3870 + }
3871 + break;
3872 case WLAN_EID_COUNTRY:
3873 elems->country_elem = pos;
3874 elems->country_elem_len = elen;
3875 --- a/net/wireless/reg.c
3876 +++ b/net/wireless/reg.c
3877 @@ -857,7 +857,7 @@ static void handle_channel(struct wiphy
3878 return;
3879
3880 REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
3881 - chan->flags = IEEE80211_CHAN_DISABLED;
3882 + chan->flags |= IEEE80211_CHAN_DISABLED;
3883 return;
3884 }
3885
3886 --- a/net/wireless/util.c
3887 +++ b/net/wireless/util.c
3888 @@ -1156,6 +1156,26 @@ int cfg80211_get_p2p_attr(const u8 *ies,
3889 }
3890 EXPORT_SYMBOL(cfg80211_get_p2p_attr);
3891
3892 +bool ieee80211_operating_class_to_band(u8 operating_class,
3893 + enum ieee80211_band *band)
3894 +{
3895 + switch (operating_class) {
3896 + case 112:
3897 + case 115 ... 127:
3898 + *band = IEEE80211_BAND_5GHZ;
3899 + return true;
3900 + case 81:
3901 + case 82:
3902 + case 83:
3903 + case 84:
3904 + *band = IEEE80211_BAND_2GHZ;
3905 + return true;
3906 + }
3907 +
3908 + return false;
3909 +}
3910 +EXPORT_SYMBOL(ieee80211_operating_class_to_band);
3911 +
3912 int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
3913 u32 beacon_int)
3914 {
3915 --- a/include/uapi/linux/nl80211.h
3916 +++ b/include/uapi/linux/nl80211.h
3917 @@ -1973,6 +1973,10 @@ enum nl80211_sta_bss_param {
3918 * @NL80211_STA_INFO_PEER_PM: peer mesh STA link-specific power mode
3919 * @NL80211_STA_INFO_NONPEER_PM: neighbor mesh STA power save mode towards
3920 * non-peer STA
3921 + * @NL80211_STA_INFO_CHAIN_SIGNAL: per-chain signal strength of last PPDU
3922 + * Contains a nested array of signal strength attributes (u8, dBm)
3923 + * @NL80211_STA_INFO_CHAIN_SIGNAL_AVG: per-chain signal strength average
3924 + * Same format as NL80211_STA_INFO_CHAIN_SIGNAL.
3925 * @__NL80211_STA_INFO_AFTER_LAST: internal
3926 * @NL80211_STA_INFO_MAX: highest possible station info attribute
3927 */
3928 @@ -2002,6 +2006,8 @@ enum nl80211_sta_info {
3929 NL80211_STA_INFO_NONPEER_PM,
3930 NL80211_STA_INFO_RX_BYTES64,
3931 NL80211_STA_INFO_TX_BYTES64,
3932 + NL80211_STA_INFO_CHAIN_SIGNAL,
3933 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG,
3934
3935 /* keep last */
3936 __NL80211_STA_INFO_AFTER_LAST,
3937 @@ -2395,6 +2401,8 @@ enum nl80211_survey_info {
3938 * @NL80211_MNTR_FLAG_OTHER_BSS: disable BSSID filtering
3939 * @NL80211_MNTR_FLAG_COOK_FRAMES: report frames after processing.
3940 * overrides all other flags.
3941 + * @NL80211_MNTR_FLAG_ACTIVE: use the configured MAC address
3942 + * and ACK incoming unicast packets.
3943 *
3944 * @__NL80211_MNTR_FLAG_AFTER_LAST: internal use
3945 * @NL80211_MNTR_FLAG_MAX: highest possible monitor flag
3946 @@ -2406,6 +2414,7 @@ enum nl80211_mntr_flags {
3947 NL80211_MNTR_FLAG_CONTROL,
3948 NL80211_MNTR_FLAG_OTHER_BSS,
3949 NL80211_MNTR_FLAG_COOK_FRAMES,
3950 + NL80211_MNTR_FLAG_ACTIVE,
3951
3952 /* keep last */
3953 __NL80211_MNTR_FLAG_AFTER_LAST,
3954 @@ -3557,6 +3566,7 @@ enum nl80211_feature_flags {
3955 NL80211_FEATURE_ADVERTISE_CHAN_LIMITS = 1 << 14,
3956 NL80211_FEATURE_FULL_AP_CLIENT_STATE = 1 << 15,
3957 NL80211_FEATURE_USERSPACE_MPM = 1 << 16,
3958 + NL80211_FEATURE_ACTIVE_MONITOR = 1 << 17,
3959 };
3960
3961 /**
3962 --- a/net/mac80211/sta_info.c
3963 +++ b/net/mac80211/sta_info.c
3964 @@ -358,6 +358,8 @@ struct sta_info *sta_info_alloc(struct i
3965 do_posix_clock_monotonic_gettime(&uptime);
3966 sta->last_connected = uptime.tv_sec;
3967 ewma_init(&sta->avg_signal, 1024, 8);
3968 + for (i = 0; i < ARRAY_SIZE(sta->chain_signal_avg); i++)
3969 + ewma_init(&sta->chain_signal_avg[i], 1024, 8);
3970
3971 if (sta_prepare_rate_control(local, sta, gfp)) {
3972 kfree(sta);
3973 @@ -1130,6 +1132,7 @@ static void ieee80211_send_null_response
3974 * ends the poll/service period.
3975 */
3976 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
3977 + IEEE80211_TX_CTL_PS_RESPONSE |
3978 IEEE80211_TX_STATUS_EOSP |
3979 IEEE80211_TX_CTL_REQ_TX_STATUS;
3980
3981 @@ -1267,7 +1270,8 @@ ieee80211_sta_ps_deliver_response(struct
3982 * STA may still remain is PS mode after this frame
3983 * exchange.
3984 */
3985 - info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
3986 + info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
3987 + IEEE80211_TX_CTL_PS_RESPONSE;
3988
3989 /*
3990 * Use MoreData flag to indicate whether there are
3991 --- a/net/wireless/nl80211.c
3992 +++ b/net/wireless/nl80211.c
3993 @@ -2270,6 +2270,7 @@ static const struct nla_policy mntr_flag
3994 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3995 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3996 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
3997 + [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
3998 };
3999
4000 static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
4001 @@ -2381,6 +2382,10 @@ static int nl80211_set_interface(struct
4002 change = true;
4003 }
4004
4005 + if (flags && (*flags & NL80211_MNTR_FLAG_ACTIVE) &&
4006 + !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
4007 + return -EOPNOTSUPP;
4008 +
4009 if (change)
4010 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
4011 else
4012 @@ -2438,6 +2443,11 @@ static int nl80211_new_interface(struct
4013 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
4014 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
4015 &flags);
4016 +
4017 + if (!err && (flags & NL80211_MNTR_FLAG_ACTIVE) &&
4018 + !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
4019 + return -EOPNOTSUPP;
4020 +
4021 wdev = rdev_add_virtual_intf(rdev,
4022 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
4023 type, err ? NULL : &flags, &params);
4024 @@ -3367,6 +3377,32 @@ static bool nl80211_put_sta_rate(struct
4025 return true;
4026 }
4027
4028 +static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
4029 + int id)
4030 +{
4031 + void *attr;
4032 + int i = 0;
4033 +
4034 + if (!mask)
4035 + return true;
4036 +
4037 + attr = nla_nest_start(msg, id);
4038 + if (!attr)
4039 + return false;
4040 +
4041 + for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
4042 + if (!(mask & BIT(i)))
4043 + continue;
4044 +
4045 + if (nla_put_u8(msg, i, signal[i]))
4046 + return false;
4047 + }
4048 +
4049 + nla_nest_end(msg, attr);
4050 +
4051 + return true;
4052 +}
4053 +
4054 static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
4055 int flags,
4056 struct cfg80211_registered_device *rdev,
4057 @@ -3402,7 +3438,7 @@ static int nl80211_send_station(struct s
4058 (u32)sinfo->rx_bytes))
4059 goto nla_put_failure;
4060 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
4061 - NL80211_STA_INFO_TX_BYTES64)) &&
4062 + STATION_INFO_TX_BYTES64)) &&
4063 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
4064 (u32)sinfo->tx_bytes))
4065 goto nla_put_failure;
4066 @@ -3438,6 +3474,18 @@ static int nl80211_send_station(struct s
4067 default:
4068 break;
4069 }
4070 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
4071 + if (!nl80211_put_signal(msg, sinfo->chains,
4072 + sinfo->chain_signal,
4073 + NL80211_STA_INFO_CHAIN_SIGNAL))
4074 + goto nla_put_failure;
4075 + }
4076 + if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
4077 + if (!nl80211_put_signal(msg, sinfo->chains,
4078 + sinfo->chain_signal_avg,
4079 + NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
4080 + goto nla_put_failure;
4081 + }
4082 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
4083 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
4084 NL80211_STA_INFO_TX_BITRATE))
4085 --- a/drivers/net/wireless/ath/ath9k/init.c
4086 +++ b/drivers/net/wireless/ath/ath9k/init.c
4087 @@ -433,6 +433,8 @@ static int ath9k_init_queues(struct ath_
4088 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
4089 ath_cabq_update(sc);
4090
4091 + sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
4092 +
4093 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
4094 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
4095 sc->tx.txq_map[i]->mac80211_qnum = i;
4096 @@ -768,7 +770,8 @@ void ath9k_set_hw_capab(struct ath_softc
4097 IEEE80211_HW_SUPPORTS_PS |
4098 IEEE80211_HW_PS_NULLFUNC_STACK |
4099 IEEE80211_HW_SPECTRUM_MGMT |
4100 - IEEE80211_HW_REPORTS_TX_ACK_STATUS;
4101 + IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4102 + IEEE80211_HW_SUPPORTS_RC_TABLE;
4103
4104 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
4105 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4106 @@ -776,6 +779,8 @@ void ath9k_set_hw_capab(struct ath_softc
4107 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
4108 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
4109
4110 + hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
4111 +
4112 hw->wiphy->interface_modes =
4113 BIT(NL80211_IFTYPE_P2P_GO) |
4114 BIT(NL80211_IFTYPE_P2P_CLIENT) |
4115 --- a/drivers/net/wireless/ath/ath9k/xmit.c
4116 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
4117 @@ -125,24 +125,6 @@ static void ath_tx_queue_tid(struct ath_
4118 list_add_tail(&ac->list, &txq->axq_acq);
4119 }
4120
4121 -static void ath_tx_resume_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4122 -{
4123 - struct ath_txq *txq = tid->ac->txq;
4124 -
4125 - WARN_ON(!tid->paused);
4126 -
4127 - ath_txq_lock(sc, txq);
4128 - tid->paused = false;
4129 -
4130 - if (skb_queue_empty(&tid->buf_q))
4131 - goto unlock;
4132 -
4133 - ath_tx_queue_tid(txq, tid);
4134 - ath_txq_schedule(sc, txq);
4135 -unlock:
4136 - ath_txq_unlock_complete(sc, txq);
4137 -}
4138 -
4139 static struct ath_frame_info *get_frame_info(struct sk_buff *skb)
4140 {
4141 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4142 @@ -157,6 +139,13 @@ static void ath_send_bar(struct ath_atx_
4143 seqno << IEEE80211_SEQ_SEQ_SHIFT);
4144 }
4145
4146 +static void ath_set_rates(struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4147 + struct ath_buf *bf)
4148 +{
4149 + ieee80211_get_tx_rates(vif, sta, bf->bf_mpdu, bf->rates,
4150 + ARRAY_SIZE(bf->rates));
4151 +}
4152 +
4153 static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
4154 {
4155 struct ath_txq *txq = tid->ac->txq;
4156 @@ -189,15 +178,11 @@ static void ath_tx_flush_tid(struct ath_
4157 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4158 sendbar = true;
4159 } else {
4160 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4161 ath_tx_send_normal(sc, txq, NULL, skb);
4162 }
4163 }
4164
4165 - if (tid->baw_head == tid->baw_tail) {
4166 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4167 - tid->state &= ~AGGR_CLEANUP;
4168 - }
4169 -
4170 if (sendbar) {
4171 ath_txq_unlock(sc, txq);
4172 ath_send_bar(tid, tid->seq_start);
4173 @@ -269,9 +254,7 @@ static void ath_tid_drain(struct ath_sof
4174
4175 list_add_tail(&bf->list, &bf_head);
4176
4177 - if (fi->retries)
4178 - ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4179 -
4180 + ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
4181 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
4182 }
4183
4184 @@ -407,7 +390,7 @@ static void ath_tx_complete_aggr(struct
4185
4186 tx_info = IEEE80211_SKB_CB(skb);
4187
4188 - memcpy(rates, tx_info->control.rates, sizeof(rates));
4189 + memcpy(rates, bf->rates, sizeof(rates));
4190
4191 retries = ts->ts_longretry + 1;
4192 for (i = 0; i < ts->ts_rateindex; i++)
4193 @@ -483,19 +466,19 @@ static void ath_tx_complete_aggr(struct
4194 tx_info = IEEE80211_SKB_CB(skb);
4195 fi = get_frame_info(skb);
4196
4197 - if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4198 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4199 + /*
4200 + * Outside of the current BlockAck window,
4201 + * maybe part of a previous session
4202 + */
4203 + txfail = 1;
4204 + } else if (ATH_BA_ISSET(ba, ATH_BA_INDEX(seq_st, seqno))) {
4205 /* transmit completion, subframe is
4206 * acked by block ack */
4207 acked_cnt++;
4208 } else if (!isaggr && txok) {
4209 /* transmit completion */
4210 acked_cnt++;
4211 - } else if (tid->state & AGGR_CLEANUP) {
4212 - /*
4213 - * cleanup in progress, just fail
4214 - * the un-acked sub-frames
4215 - */
4216 - txfail = 1;
4217 } else if (flush) {
4218 txpending = 1;
4219 } else if (fi->retries < ATH_MAX_SW_RETRIES) {
4220 @@ -519,7 +502,7 @@ static void ath_tx_complete_aggr(struct
4221 if (bf_next != NULL || !bf_last->bf_stale)
4222 list_move_tail(&bf->list, &bf_head);
4223
4224 - if (!txpending || (tid->state & AGGR_CLEANUP)) {
4225 + if (!txpending) {
4226 /*
4227 * complete the acked-ones/xretried ones; update
4228 * block-ack window
4229 @@ -535,6 +518,10 @@ static void ath_tx_complete_aggr(struct
4230 ath_tx_complete_buf(sc, bf, txq, &bf_head, ts,
4231 !txfail);
4232 } else {
4233 + if (tx_info->flags & IEEE80211_TX_STATUS_EOSP) {
4234 + tx_info->flags &= ~IEEE80211_TX_STATUS_EOSP;
4235 + ieee80211_sta_eosp(sta);
4236 + }
4237 /* retry the un-acked ones */
4238 if (bf->bf_next == NULL && bf_last->bf_stale) {
4239 struct ath_buf *tbf;
4240 @@ -593,9 +580,6 @@ static void ath_tx_complete_aggr(struct
4241 ath_txq_lock(sc, txq);
4242 }
4243
4244 - if (tid->state & AGGR_CLEANUP)
4245 - ath_tx_flush_tid(sc, tid);
4246 -
4247 rcu_read_unlock();
4248
4249 if (needreset)
4250 @@ -612,6 +596,7 @@ static void ath_tx_process_buffer(struct
4251 struct ath_tx_status *ts, struct ath_buf *bf,
4252 struct list_head *bf_head)
4253 {
4254 + struct ieee80211_tx_info *info;
4255 bool txok, flush;
4256
4257 txok = !(ts->ts_status & ATH9K_TXERR_MASK);
4258 @@ -623,8 +608,12 @@ static void ath_tx_process_buffer(struct
4259 txq->axq_ampdu_depth--;
4260
4261 if (!bf_isampdu(bf)) {
4262 - if (!flush)
4263 + if (!flush) {
4264 + info = IEEE80211_SKB_CB(bf->bf_mpdu);
4265 + memcpy(info->control.rates, bf->rates,
4266 + sizeof(info->control.rates));
4267 ath_tx_rc_status(sc, bf, ts, 1, txok ? 0 : 1, txok);
4268 + }
4269 ath_tx_complete_buf(sc, bf, txq, bf_head, ts, txok);
4270 } else
4271 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
4272 @@ -668,7 +657,7 @@ static u32 ath_lookup_rate(struct ath_so
4273
4274 skb = bf->bf_mpdu;
4275 tx_info = IEEE80211_SKB_CB(skb);
4276 - rates = tx_info->control.rates;
4277 + rates = bf->rates;
4278
4279 /*
4280 * Find the lowest frame length among the rate series that will have a
4281 @@ -736,8 +725,6 @@ static int ath_compute_num_delims(struct
4282 bool first_subfrm)
4283 {
4284 #define FIRST_DESC_NDELIMS 60
4285 - struct sk_buff *skb = bf->bf_mpdu;
4286 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4287 u32 nsymbits, nsymbols;
4288 u16 minlen;
4289 u8 flags, rix;
4290 @@ -778,8 +765,8 @@ static int ath_compute_num_delims(struct
4291 if (tid->an->mpdudensity == 0)
4292 return ndelim;
4293
4294 - rix = tx_info->control.rates[0].idx;
4295 - flags = tx_info->control.rates[0].flags;
4296 + rix = bf->rates[0].idx;
4297 + flags = bf->rates[0].flags;
4298 width = (flags & IEEE80211_TX_RC_40_MHZ_WIDTH) ? 1 : 0;
4299 half_gi = (flags & IEEE80211_TX_RC_SHORT_GI) ? 1 : 0;
4300
4301 @@ -803,25 +790,20 @@ static int ath_compute_num_delims(struct
4302 return ndelim;
4303 }
4304
4305 -static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4306 - struct ath_txq *txq,
4307 - struct ath_atx_tid *tid,
4308 - struct list_head *bf_q,
4309 - int *aggr_len)
4310 +static struct ath_buf *
4311 +ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
4312 + struct ath_atx_tid *tid)
4313 {
4314 -#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4315 - struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4316 - int rl = 0, nframes = 0, ndelim, prev_al = 0;
4317 - u16 aggr_limit = 0, al = 0, bpad = 0,
4318 - al_delta, h_baw = tid->baw_size / 2;
4319 - enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4320 - struct ieee80211_tx_info *tx_info;
4321 struct ath_frame_info *fi;
4322 struct sk_buff *skb;
4323 + struct ath_buf *bf;
4324 u16 seqno;
4325
4326 - do {
4327 + while (1) {
4328 skb = skb_peek(&tid->buf_q);
4329 + if (!skb)
4330 + break;
4331 +
4332 fi = get_frame_info(skb);
4333 bf = fi->bf;
4334 if (!fi->bf)
4335 @@ -837,10 +819,8 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4336 seqno = bf->bf_state.seqno;
4337
4338 /* do not step over block-ack window */
4339 - if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
4340 - status = ATH_AGGR_BAW_CLOSED;
4341 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno))
4342 break;
4343 - }
4344
4345 if (tid->bar_index > ATH_BA_INDEX(tid->seq_start, seqno)) {
4346 struct ath_tx_status ts = {};
4347 @@ -854,10 +834,45 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4348 continue;
4349 }
4350
4351 + bf->bf_next = NULL;
4352 + bf->bf_lastbf = bf;
4353 + return bf;
4354 + }
4355 +
4356 + return NULL;
4357 +}
4358 +
4359 +static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
4360 + struct ath_txq *txq,
4361 + struct ath_atx_tid *tid,
4362 + struct list_head *bf_q,
4363 + int *aggr_len)
4364 +{
4365 +#define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
4366 + struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
4367 + int rl = 0, nframes = 0, ndelim, prev_al = 0;
4368 + u16 aggr_limit = 0, al = 0, bpad = 0,
4369 + al_delta, h_baw = tid->baw_size / 2;
4370 + enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
4371 + struct ieee80211_tx_info *tx_info;
4372 + struct ath_frame_info *fi;
4373 + struct sk_buff *skb;
4374 +
4375 + do {
4376 + bf = ath_tx_get_tid_subframe(sc, txq, tid);
4377 + if (!bf) {
4378 + status = ATH_AGGR_BAW_CLOSED;
4379 + break;
4380 + }
4381 +
4382 + skb = bf->bf_mpdu;
4383 + fi = get_frame_info(skb);
4384 +
4385 if (!bf_first)
4386 bf_first = bf;
4387
4388 if (!rl) {
4389 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4390 aggr_limit = ath_lookup_rate(sc, bf, tid);
4391 rl = 1;
4392 }
4393 @@ -898,7 +913,7 @@ static enum ATH_AGGR_STATUS ath_tx_form_
4394
4395 /* link buffers of this frame to the aggregate */
4396 if (!fi->retries)
4397 - ath_tx_addto_baw(sc, tid, seqno);
4398 + ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4399 bf->bf_state.ndelim = ndelim;
4400
4401 __skb_unlink(skb, &tid->buf_q);
4402 @@ -998,14 +1013,14 @@ static void ath_buf_set_rate(struct ath_
4403
4404 skb = bf->bf_mpdu;
4405 tx_info = IEEE80211_SKB_CB(skb);
4406 - rates = tx_info->control.rates;
4407 + rates = bf->rates;
4408 hdr = (struct ieee80211_hdr *)skb->data;
4409
4410 /* set dur_update_en for l-sig computation except for PS-Poll frames */
4411 info->dur_update = !ieee80211_is_pspoll(hdr->frame_control);
4412 info->rtscts_rate = fi->rtscts_rate;
4413
4414 - for (i = 0; i < 4; i++) {
4415 + for (i = 0; i < ARRAY_SIZE(bf->rates); i++) {
4416 bool is_40, is_sgi, is_sp;
4417 int phy;
4418
4419 @@ -1106,10 +1121,8 @@ static void ath_tx_fill_desc(struct ath_
4420 struct ath_txq *txq, int len)
4421 {
4422 struct ath_hw *ah = sc->sc_ah;
4423 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
4424 - struct ath_buf *bf_first = bf;
4425 + struct ath_buf *bf_first = NULL;
4426 struct ath_tx_info info;
4427 - bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4428
4429 memset(&info, 0, sizeof(info));
4430 info.is_first = true;
4431 @@ -1117,24 +1130,14 @@ static void ath_tx_fill_desc(struct ath_
4432 info.txpower = MAX_RATE_POWER;
4433 info.qcu = txq->axq_qnum;
4434
4435 - info.flags = ATH9K_TXDESC_INTREQ;
4436 - if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4437 - info.flags |= ATH9K_TXDESC_NOACK;
4438 - if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4439 - info.flags |= ATH9K_TXDESC_LDPC;
4440 -
4441 - ath_buf_set_rate(sc, bf, &info, len);
4442 -
4443 - if (tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
4444 - info.flags |= ATH9K_TXDESC_CLRDMASK;
4445 -
4446 if (bf->bf_state.bfs_paprd)
4447 info.flags |= (u32) bf->bf_state.bfs_paprd << ATH9K_TXDESC_PAPRD_S;
4448
4449 -
4450 while (bf) {
4451 struct sk_buff *skb = bf->bf_mpdu;
4452 + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4453 struct ath_frame_info *fi = get_frame_info(skb);
4454 + bool aggr = !!(bf->bf_state.bf_type & BUF_AGGR);
4455
4456 info.type = get_hw_packet_type(skb);
4457 if (bf->bf_next)
4458 @@ -1142,6 +1145,22 @@ static void ath_tx_fill_desc(struct ath_
4459 else
4460 info.link = 0;
4461
4462 + if (!bf_first) {
4463 + bf_first = bf;
4464 +
4465 + info.flags = ATH9K_TXDESC_INTREQ;
4466 + if ((tx_info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) ||
4467 + txq == sc->tx.uapsdq)
4468 + info.flags |= ATH9K_TXDESC_CLRDMASK;
4469 +
4470 + if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK)
4471 + info.flags |= ATH9K_TXDESC_NOACK;
4472 + if (tx_info->flags & IEEE80211_TX_CTL_LDPC)
4473 + info.flags |= ATH9K_TXDESC_LDPC;
4474 +
4475 + ath_buf_set_rate(sc, bf, &info, len);
4476 + }
4477 +
4478 info.buf_addr[0] = bf->bf_buf_addr;
4479 info.buf_len[0] = skb->len;
4480 info.pkt_len = fi->framelen;
4481 @@ -1151,7 +1170,7 @@ static void ath_tx_fill_desc(struct ath_
4482 if (aggr) {
4483 if (bf == bf_first)
4484 info.aggr = AGGR_BUF_FIRST;
4485 - else if (!bf->bf_next)
4486 + else if (bf == bf_first->bf_lastbf)
4487 info.aggr = AGGR_BUF_LAST;
4488 else
4489 info.aggr = AGGR_BUF_MIDDLE;
4490 @@ -1160,6 +1179,9 @@ static void ath_tx_fill_desc(struct ath_
4491 info.aggr_len = len;
4492 }
4493
4494 + if (bf == bf_first->bf_lastbf)
4495 + bf_first = NULL;
4496 +
4497 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
4498 bf = bf->bf_next;
4499 }
4500 @@ -1224,9 +1246,6 @@ int ath_tx_aggr_start(struct ath_softc *
4501 an = (struct ath_node *)sta->drv_priv;
4502 txtid = ATH_AN_2_TID(an, tid);
4503
4504 - if (txtid->state & (AGGR_CLEANUP | AGGR_ADDBA_COMPLETE))
4505 - return -EAGAIN;
4506 -
4507 /* update ampdu factor/density, they may have changed. This may happen
4508 * in HT IBSS when a beacon with HT-info is received after the station
4509 * has already been added.
4510 @@ -1238,7 +1257,7 @@ int ath_tx_aggr_start(struct ath_softc *
4511 an->mpdudensity = density;
4512 }
4513
4514 - txtid->state |= AGGR_ADDBA_PROGRESS;
4515 + txtid->active = true;
4516 txtid->paused = true;
4517 *ssn = txtid->seq_start = txtid->seq_next;
4518 txtid->bar_index = -1;
4519 @@ -1255,28 +1274,9 @@ void ath_tx_aggr_stop(struct ath_softc *
4520 struct ath_atx_tid *txtid = ATH_AN_2_TID(an, tid);
4521 struct ath_txq *txq = txtid->ac->txq;
4522
4523 - if (txtid->state & AGGR_CLEANUP)
4524 - return;
4525 -
4526 - if (!(txtid->state & AGGR_ADDBA_COMPLETE)) {
4527 - txtid->state &= ~AGGR_ADDBA_PROGRESS;
4528 - return;
4529 - }
4530 -
4531 ath_txq_lock(sc, txq);
4532 + txtid->active = false;
4533 txtid->paused = true;
4534 -
4535 - /*
4536 - * If frames are still being transmitted for this TID, they will be
4537 - * cleaned up during tx completion. To prevent race conditions, this
4538 - * TID can only be reused after all in-progress subframes have been
4539 - * completed.
4540 - */
4541 - if (txtid->baw_head != txtid->baw_tail)
4542 - txtid->state |= AGGR_CLEANUP;
4543 - else
4544 - txtid->state &= ~AGGR_ADDBA_COMPLETE;
4545 -
4546 ath_tx_flush_tid(sc, txtid);
4547 ath_txq_unlock_complete(sc, txq);
4548 }
4549 @@ -1342,18 +1342,92 @@ void ath_tx_aggr_wakeup(struct ath_softc
4550 }
4551 }
4552
4553 -void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta, u16 tid)
4554 +void ath_tx_aggr_resume(struct ath_softc *sc, struct ieee80211_sta *sta,
4555 + u16 tidno)
4556 {
4557 - struct ath_atx_tid *txtid;
4558 + struct ath_atx_tid *tid;
4559 struct ath_node *an;
4560 + struct ath_txq *txq;
4561
4562 an = (struct ath_node *)sta->drv_priv;
4563 + tid = ATH_AN_2_TID(an, tidno);
4564 + txq = tid->ac->txq;
4565
4566 - txtid = ATH_AN_2_TID(an, tid);
4567 - txtid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4568 - txtid->state |= AGGR_ADDBA_COMPLETE;
4569 - txtid->state &= ~AGGR_ADDBA_PROGRESS;
4570 - ath_tx_resume_tid(sc, txtid);
4571 + ath_txq_lock(sc, txq);
4572 +
4573 + tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
4574 + tid->paused = false;
4575 +
4576 + if (!skb_queue_empty(&tid->buf_q)) {
4577 + ath_tx_queue_tid(txq, tid);
4578 + ath_txq_schedule(sc, txq);
4579 + }
4580 +
4581 + ath_txq_unlock_complete(sc, txq);
4582 +}
4583 +
4584 +void ath9k_release_buffered_frames(struct ieee80211_hw *hw,
4585 + struct ieee80211_sta *sta,
4586 + u16 tids, int nframes,
4587 + enum ieee80211_frame_release_type reason,
4588 + bool more_data)
4589 +{
4590 + struct ath_softc *sc = hw->priv;
4591 + struct ath_node *an = (struct ath_node *)sta->drv_priv;
4592 + struct ath_txq *txq = sc->tx.uapsdq;
4593 + struct ieee80211_tx_info *info;
4594 + struct list_head bf_q;
4595 + struct ath_buf *bf_tail = NULL, *bf;
4596 + int sent = 0;
4597 + int i;
4598 +
4599 + INIT_LIST_HEAD(&bf_q);
4600 + for (i = 0; tids && nframes; i++, tids >>= 1) {
4601 + struct ath_atx_tid *tid;
4602 +
4603 + if (!(tids & 1))
4604 + continue;
4605 +
4606 + tid = ATH_AN_2_TID(an, i);
4607 + if (tid->paused)
4608 + continue;
4609 +
4610 + ath_txq_lock(sc, tid->ac->txq);
4611 + while (!skb_queue_empty(&tid->buf_q) && nframes > 0) {
4612 + bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
4613 + if (!bf)
4614 + break;
4615 +
4616 + __skb_unlink(bf->bf_mpdu, &tid->buf_q);
4617 + list_add_tail(&bf->list, &bf_q);
4618 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4619 + ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4620 + bf->bf_state.bf_type &= ~BUF_AGGR;
4621 + if (bf_tail)
4622 + bf_tail->bf_next = bf;
4623 +
4624 + bf_tail = bf;
4625 + nframes--;
4626 + sent++;
4627 + TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4628 +
4629 + if (skb_queue_empty(&tid->buf_q))
4630 + ieee80211_sta_set_buffered(an->sta, i, false);
4631 + }
4632 + ath_txq_unlock_complete(sc, tid->ac->txq);
4633 + }
4634 +
4635 + if (list_empty(&bf_q))
4636 + return;
4637 +
4638 + info = IEEE80211_SKB_CB(bf_tail->bf_mpdu);
4639 + info->flags |= IEEE80211_TX_STATUS_EOSP;
4640 +
4641 + bf = list_first_entry(&bf_q, struct ath_buf, list);
4642 + ath_txq_lock(sc, txq);
4643 + ath_tx_fill_desc(sc, bf, txq, 0);
4644 + ath_tx_txqaddbuf(sc, txq, &bf_q, false);
4645 + ath_txq_unlock(sc, txq);
4646 }
4647
4648 /********************/
4649 @@ -1709,8 +1783,9 @@ static void ath_tx_txqaddbuf(struct ath_
4650 }
4651 }
4652
4653 -static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_atx_tid *tid,
4654 - struct sk_buff *skb, struct ath_tx_control *txctl)
4655 +static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_txq *txq,
4656 + struct ath_atx_tid *tid, struct sk_buff *skb,
4657 + struct ath_tx_control *txctl)
4658 {
4659 struct ath_frame_info *fi = get_frame_info(skb);
4660 struct list_head bf_head;
4661 @@ -1723,26 +1798,28 @@ static void ath_tx_send_ampdu(struct ath
4662 * - seqno is not within block-ack window
4663 * - h/w queue depth exceeds low water mark
4664 */
4665 - if (!skb_queue_empty(&tid->buf_q) || tid->paused ||
4666 - !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4667 - txctl->txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) {
4668 + if ((!skb_queue_empty(&tid->buf_q) || tid->paused ||
4669 + !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
4670 + txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
4671 + txq != sc->tx.uapsdq) {
4672 /*
4673 * Add this frame to software queue for scheduling later
4674 * for aggregation.
4675 */
4676 - TX_STAT_INC(txctl->txq->axq_qnum, a_queued_sw);
4677 + TX_STAT_INC(txq->axq_qnum, a_queued_sw);
4678 __skb_queue_tail(&tid->buf_q, skb);
4679 if (!txctl->an || !txctl->an->sleeping)
4680 - ath_tx_queue_tid(txctl->txq, tid);
4681 + ath_tx_queue_tid(txq, tid);
4682 return;
4683 }
4684
4685 - bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4686 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4687 if (!bf) {
4688 ieee80211_free_txskb(sc->hw, skb);
4689 return;
4690 }
4691
4692 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
4693 bf->bf_state.bf_type = BUF_AMPDU;
4694 INIT_LIST_HEAD(&bf_head);
4695 list_add(&bf->list, &bf_head);
4696 @@ -1751,10 +1828,10 @@ static void ath_tx_send_ampdu(struct ath
4697 ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
4698
4699 /* Queue to h/w without aggregation */
4700 - TX_STAT_INC(txctl->txq->axq_qnum, a_queued_hw);
4701 + TX_STAT_INC(txq->axq_qnum, a_queued_hw);
4702 bf->bf_lastbf = bf;
4703 - ath_tx_fill_desc(sc, bf, txctl->txq, fi->framelen);
4704 - ath_tx_txqaddbuf(sc, txctl->txq, &bf_head, false);
4705 + ath_tx_fill_desc(sc, bf, txq, fi->framelen);
4706 + ath_tx_txqaddbuf(sc, txq, &bf_head, false);
4707 }
4708
4709 static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
4710 @@ -1892,62 +1969,16 @@ static struct ath_buf *ath_tx_setup_buff
4711 return bf;
4712 }
4713
4714 -/* FIXME: tx power */
4715 -static void ath_tx_start_dma(struct ath_softc *sc, struct sk_buff *skb,
4716 - struct ath_tx_control *txctl)
4717 -{
4718 - struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
4719 - struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4720 - struct ath_atx_tid *tid = NULL;
4721 - struct ath_buf *bf;
4722 - u8 tidno;
4723 -
4724 - if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4725 - tidno = ieee80211_get_qos_ctl(hdr)[0] &
4726 - IEEE80211_QOS_CTL_TID_MASK;
4727 - tid = ATH_AN_2_TID(txctl->an, tidno);
4728 -
4729 - WARN_ON(tid->ac->txq != txctl->txq);
4730 - }
4731 -
4732 - if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4733 - /*
4734 - * Try aggregation if it's a unicast data frame
4735 - * and the destination is HT capable.
4736 - */
4737 - ath_tx_send_ampdu(sc, tid, skb, txctl);
4738 - } else {
4739 - bf = ath_tx_setup_buffer(sc, txctl->txq, tid, skb);
4740 - if (!bf) {
4741 - if (txctl->paprd)
4742 - dev_kfree_skb_any(skb);
4743 - else
4744 - ieee80211_free_txskb(sc->hw, skb);
4745 - return;
4746 - }
4747 -
4748 - bf->bf_state.bfs_paprd = txctl->paprd;
4749 -
4750 - if (txctl->paprd)
4751 - bf->bf_state.bfs_paprd_timestamp = jiffies;
4752 -
4753 - ath_tx_send_normal(sc, txctl->txq, tid, skb);
4754 - }
4755 -}
4756 -
4757 -/* Upon failure caller should free skb */
4758 -int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
4759 - struct ath_tx_control *txctl)
4760 +static int ath_tx_prepare(struct ieee80211_hw *hw, struct sk_buff *skb,
4761 + struct ath_tx_control *txctl)
4762 {
4763 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
4764 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4765 struct ieee80211_sta *sta = txctl->sta;
4766 struct ieee80211_vif *vif = info->control.vif;
4767 struct ath_softc *sc = hw->priv;
4768 - struct ath_txq *txq = txctl->txq;
4769 - int padpos, padsize;
4770 int frmlen = skb->len + FCS_LEN;
4771 - int q;
4772 + int padpos, padsize;
4773
4774 /* NOTE: sta can be NULL according to net/mac80211.h */
4775 if (sta)
4776 @@ -1968,6 +1999,11 @@ int ath_tx_start(struct ieee80211_hw *hw
4777 hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
4778 }
4779
4780 + if ((vif && vif->type != NL80211_IFTYPE_AP &&
4781 + vif->type != NL80211_IFTYPE_AP_VLAN) ||
4782 + !ieee80211_is_data(hdr->frame_control))
4783 + info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
4784 +
4785 /* Add the padding after the header if this is not already done */
4786 padpos = ieee80211_hdrlen(hdr->frame_control);
4787 padsize = padpos & 3;
4788 @@ -1977,16 +2013,34 @@ int ath_tx_start(struct ieee80211_hw *hw
4789
4790 skb_push(skb, padsize);
4791 memmove(skb->data, skb->data + padsize, padpos);
4792 - hdr = (struct ieee80211_hdr *) skb->data;
4793 }
4794
4795 - if ((vif && vif->type != NL80211_IFTYPE_AP &&
4796 - vif->type != NL80211_IFTYPE_AP_VLAN) ||
4797 - !ieee80211_is_data(hdr->frame_control))
4798 - info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
4799 -
4800 setup_frame_info(hw, sta, skb, frmlen);
4801 + return 0;
4802 +}
4803 +
4804 +
4805 +/* Upon failure caller should free skb */
4806 +int ath_tx_start(struct ieee80211_hw *hw, struct sk_buff *skb,
4807 + struct ath_tx_control *txctl)
4808 +{
4809 + struct ieee80211_hdr *hdr;
4810 + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4811 + struct ieee80211_sta *sta = txctl->sta;
4812 + struct ieee80211_vif *vif = info->control.vif;
4813 + struct ath_softc *sc = hw->priv;
4814 + struct ath_txq *txq = txctl->txq;
4815 + struct ath_atx_tid *tid = NULL;
4816 + struct ath_buf *bf;
4817 + u8 tidno;
4818 + int q;
4819 + int ret;
4820 +
4821 + ret = ath_tx_prepare(hw, skb, txctl);
4822 + if (ret)
4823 + return ret;
4824
4825 + hdr = (struct ieee80211_hdr *) skb->data;
4826 /*
4827 * At this point, the vif, hw_key and sta pointers in the tx control
4828 * info are no longer valid (overwritten by the ath_frame_info data.
4829 @@ -2002,13 +2056,120 @@ int ath_tx_start(struct ieee80211_hw *hw
4830 txq->stopped = true;
4831 }
4832
4833 - ath_tx_start_dma(sc, skb, txctl);
4834 + if (info->flags & IEEE80211_TX_CTL_PS_RESPONSE) {
4835 + ath_txq_unlock(sc, txq);
4836 + txq = sc->tx.uapsdq;
4837 + ath_txq_lock(sc, txq);
4838 + }
4839 +
4840 + if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
4841 + tidno = ieee80211_get_qos_ctl(hdr)[0] &
4842 + IEEE80211_QOS_CTL_TID_MASK;
4843 + tid = ATH_AN_2_TID(txctl->an, tidno);
4844 +
4845 + WARN_ON(tid->ac->txq != txctl->txq);
4846 + }
4847 +
4848 + if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
4849 + /*
4850 + * Try aggregation if it's a unicast data frame
4851 + * and the destination is HT capable.
4852 + */
4853 + ath_tx_send_ampdu(sc, txq, tid, skb, txctl);
4854 + goto out;
4855 + }
4856 +
4857 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
4858 + if (!bf) {
4859 + if (txctl->paprd)
4860 + dev_kfree_skb_any(skb);
4861 + else
4862 + ieee80211_free_txskb(sc->hw, skb);
4863 + goto out;
4864 + }
4865 +
4866 + bf->bf_state.bfs_paprd = txctl->paprd;
4867
4868 + if (txctl->paprd)
4869 + bf->bf_state.bfs_paprd_timestamp = jiffies;
4870 +
4871 + ath_set_rates(vif, sta, bf);
4872 + ath_tx_send_normal(sc, txq, tid, skb);
4873 +
4874 +out:
4875 ath_txq_unlock(sc, txq);
4876
4877 return 0;
4878 }
4879
4880 +void ath_tx_cabq(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4881 + struct sk_buff *skb)
4882 +{
4883 + struct ath_softc *sc = hw->priv;
4884 + struct ath_tx_control txctl = {
4885 + .txq = sc->beacon.cabq
4886 + };
4887 + struct ath_tx_info info = {};
4888 + struct ieee80211_hdr *hdr;
4889 + struct ath_buf *bf_tail = NULL;
4890 + struct ath_buf *bf;
4891 + LIST_HEAD(bf_q);
4892 + int duration = 0;
4893 + int max_duration;
4894 +
4895 + max_duration =
4896 + sc->cur_beacon_conf.beacon_interval * 1000 *
4897 + sc->cur_beacon_conf.dtim_period / ATH_BCBUF;
4898 +
4899 + do {
4900 + struct ath_frame_info *fi = get_frame_info(skb);
4901 +
4902 + if (ath_tx_prepare(hw, skb, &txctl))
4903 + break;
4904 +
4905 + bf = ath_tx_setup_buffer(sc, txctl.txq, NULL, skb);
4906 + if (!bf)
4907 + break;
4908 +
4909 + bf->bf_lastbf = bf;
4910 + ath_set_rates(vif, NULL, bf);
4911 + ath_buf_set_rate(sc, bf, &info, fi->framelen);
4912 + duration += info.rates[0].PktDuration;
4913 + if (bf_tail)
4914 + bf_tail->bf_next = bf;
4915 +
4916 + list_add_tail(&bf->list, &bf_q);
4917 + bf_tail = bf;
4918 + skb = NULL;
4919 +
4920 + if (duration > max_duration)
4921 + break;
4922 +
4923 + skb = ieee80211_get_buffered_bc(hw, vif);
4924 + } while(skb);
4925 +
4926 + if (skb)
4927 + ieee80211_free_txskb(hw, skb);
4928 +
4929 + if (list_empty(&bf_q))
4930 + return;
4931 +
4932 + bf = list_first_entry(&bf_q, struct ath_buf, list);
4933 + hdr = (struct ieee80211_hdr *) bf->bf_mpdu->data;
4934 +
4935 + if (hdr->frame_control & IEEE80211_FCTL_MOREDATA) {
4936 + hdr->frame_control &= ~IEEE80211_FCTL_MOREDATA;
4937 + dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
4938 + sizeof(*hdr), DMA_TO_DEVICE);
4939 + }
4940 +
4941 + ath_txq_lock(sc, txctl.txq);
4942 + ath_tx_fill_desc(sc, bf, txctl.txq, 0);
4943 + ath_tx_txqaddbuf(sc, txctl.txq, &bf_q, false);
4944 + TX_STAT_INC(txctl.txq->axq_qnum, queued);
4945 + ath_txq_unlock(sc, txctl.txq);
4946 +}
4947 +
4948 /*****************/
4949 /* TX Completion */
4950 /*****************/
4951 @@ -2054,7 +2215,12 @@ static void ath_tx_complete(struct ath_s
4952 }
4953 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
4954
4955 + __skb_queue_tail(&txq->complete_q, skb);
4956 +
4957 q = skb_get_queue_mapping(skb);
4958 + if (txq == sc->tx.uapsdq)
4959 + txq = sc->tx.txq_map[q];
4960 +
4961 if (txq == sc->tx.txq_map[q]) {
4962 if (WARN_ON(--txq->pending_frames < 0))
4963 txq->pending_frames = 0;
4964 @@ -2065,8 +2231,6 @@ static void ath_tx_complete(struct ath_s
4965 txq->stopped = false;
4966 }
4967 }
4968 -
4969 - __skb_queue_tail(&txq->complete_q, skb);
4970 }
4971
4972 static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
4973 @@ -2408,12 +2572,10 @@ void ath_tx_node_init(struct ath_softc *
4974 tid->baw_head = tid->baw_tail = 0;
4975 tid->sched = false;
4976 tid->paused = false;
4977 - tid->state &= ~AGGR_CLEANUP;
4978 + tid->active = false;
4979 __skb_queue_head_init(&tid->buf_q);
4980 acno = TID_TO_WME_AC(tidno);
4981 tid->ac = &an->ac[acno];
4982 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4983 - tid->state &= ~AGGR_ADDBA_PROGRESS;
4984 }
4985
4986 for (acno = 0, ac = &an->ac[acno];
4987 @@ -2450,9 +2612,9 @@ void ath_tx_node_cleanup(struct ath_soft
4988 }
4989
4990 ath_tid_drain(sc, txq, tid);
4991 - tid->state &= ~AGGR_ADDBA_COMPLETE;
4992 - tid->state &= ~AGGR_CLEANUP;
4993 + tid->active = false;
4994
4995 ath_txq_unlock(sc, txq);
4996 }
4997 }
4998 +
4999 --- a/drivers/net/wireless/ath/ath9k/recv.c
5000 +++ b/drivers/net/wireless/ath/ath9k/recv.c
5001 @@ -124,7 +124,7 @@ static bool ath_rx_edma_buf_link(struct
5002
5003 SKB_CB_ATHBUF(skb) = bf;
5004 ath9k_hw_addrxbuf_edma(ah, bf->bf_buf_addr, qtype);
5005 - skb_queue_tail(&rx_edma->rx_fifo, skb);
5006 + __skb_queue_tail(&rx_edma->rx_fifo, skb);
5007
5008 return true;
5009 }
5010 @@ -155,7 +155,7 @@ static void ath_rx_remove_buffer(struct
5011
5012 rx_edma = &sc->rx.rx_edma[qtype];
5013
5014 - while ((skb = skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
5015 + while ((skb = __skb_dequeue(&rx_edma->rx_fifo)) != NULL) {
5016 bf = SKB_CB_ATHBUF(skb);
5017 BUG_ON(!bf);
5018 list_add_tail(&bf->list, &sc->rx.rxbuf);
5019 @@ -1287,13 +1287,13 @@ int ath_rx_tasklet(struct ath_softc *sc,
5020 goto requeue_drop_frag;
5021 }
5022
5023 - bf->bf_mpdu = requeue_skb;
5024 - bf->bf_buf_addr = new_buf_addr;
5025 -
5026 /* Unmap the frame */
5027 dma_unmap_single(sc->dev, bf->bf_buf_addr,
5028 common->rx_bufsize, dma_type);
5029
5030 + bf->bf_mpdu = requeue_skb;
5031 + bf->bf_buf_addr = new_buf_addr;
5032 +
5033 skb_put(skb, rs.rs_datalen + ah->caps.rx_status_len);
5034 if (ah->caps.rx_status_len)
5035 skb_pull(skb, ah->caps.rx_status_len);
5036 --- a/net/wireless/core.c
5037 +++ b/net/wireless/core.c
5038 @@ -885,7 +885,6 @@ void cfg80211_leave(struct cfg80211_regi
5039 #endif
5040 __cfg80211_disconnect(rdev, dev,
5041 WLAN_REASON_DEAUTH_LEAVING, true);
5042 - cfg80211_mlme_down(rdev, dev);
5043 wdev_unlock(wdev);
5044 break;
5045 case NL80211_IFTYPE_MESH_POINT:
5046 --- a/net/wireless/sme.c
5047 +++ b/net/wireless/sme.c
5048 @@ -961,7 +961,7 @@ int __cfg80211_disconnect(struct cfg8021
5049 /* was it connected by userspace SME? */
5050 if (!wdev->conn) {
5051 cfg80211_mlme_down(rdev, dev);
5052 - return 0;
5053 + goto disconnect;
5054 }
5055
5056 if (wdev->sme_state == CFG80211_SME_CONNECTING &&
5057 @@ -987,6 +987,7 @@ int __cfg80211_disconnect(struct cfg8021
5058 return err;
5059 }
5060
5061 + disconnect:
5062 if (wdev->sme_state == CFG80211_SME_CONNECTED)
5063 __cfg80211_disconnected(dev, NULL, 0, 0, false);
5064 else if (wdev->sme_state == CFG80211_SME_CONNECTING)
5065 --- a/drivers/net/wireless/ath/ath9k/rc.c
5066 +++ b/drivers/net/wireless/ath/ath9k/rc.c
5067 @@ -1227,10 +1227,7 @@ static bool ath_tx_aggr_check(struct ath
5068 return false;
5069
5070 txtid = ATH_AN_2_TID(an, tidno);
5071 -
5072 - if (!(txtid->state & (AGGR_ADDBA_COMPLETE | AGGR_ADDBA_PROGRESS)))
5073 - return true;
5074 - return false;
5075 + return !txtid->active;
5076 }
5077
5078
5079 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
5080 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
5081 @@ -334,7 +334,8 @@ static void ar9003_hw_spur_ofdm(struct a
5082 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
5083 AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
5084
5085 - if (REG_READ_FIELD(ah, AR_PHY_MODE,
5086 + if (!AR_SREV_9340(ah) &&
5087 + REG_READ_FIELD(ah, AR_PHY_MODE,
5088 AR_PHY_MODE_DYNAMIC) == 0x1)
5089 REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
5090 AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
5091 --- a/drivers/net/wireless/ath/ath9k/mac.c
5092 +++ b/drivers/net/wireless/ath/ath9k/mac.c
5093 @@ -410,7 +410,7 @@ bool ath9k_hw_resettxqueue(struct ath_hw
5094
5095 REG_WRITE(ah, AR_QMISC(q), AR_Q_MISC_DCU_EARLY_TERM_REQ);
5096
5097 - if (AR_SREV_9340(ah))
5098 + if (AR_SREV_9340(ah) && !AR_SREV_9340_13_OR_LATER(ah))
5099 REG_WRITE(ah, AR_DMISC(q),
5100 AR_D_MISC_CW_BKOFF_EN | AR_D_MISC_FRAG_WAIT_EN | 0x1);
5101 else
5102 --- a/net/mac80211/driver-ops.h
5103 +++ b/net/mac80211/driver-ops.h
5104 @@ -146,7 +146,8 @@ static inline int drv_add_interface(stru
5105
5106 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
5107 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
5108 - !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF))))
5109 + !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF) &&
5110 + !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
5111 return -EINVAL;
5112
5113 trace_drv_add_interface(local, sdata);
5114 --- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
5115 +++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
5116 @@ -454,6 +454,8 @@ static bool create_pa_curve(u32 *data_L,
5117 if (accum_cnt <= thresh_accum_cnt)
5118 continue;
5119
5120 + max_index++;
5121 +
5122 /* sum(tx amplitude) */
5123 accum_tx = ((data_L[i] >> 16) & 0xffff) |
5124 ((data_U[i] & 0x7ff) << 16);
5125 @@ -468,20 +470,21 @@ static bool create_pa_curve(u32 *data_L,
5126
5127 accum_tx <<= scale_factor;
5128 accum_rx <<= scale_factor;
5129 - x_est[i + 1] = (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
5130 - scale_factor;
5131 + x_est[max_index] =
5132 + (((accum_tx + accum_cnt) / accum_cnt) + 32) >>
5133 + scale_factor;
5134
5135 - Y[i + 1] = ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
5136 + Y[max_index] =
5137 + ((((accum_rx + accum_cnt) / accum_cnt) + 32) >>
5138 scale_factor) +
5139 - (1 << scale_factor) * max_index + 16;
5140 + (1 << scale_factor) * i + 16;
5141
5142 if (accum_ang >= (1 << 26))
5143 accum_ang -= 1 << 27;
5144
5145 - theta[i + 1] = ((accum_ang * (1 << scale_factor)) + accum_cnt) /
5146 - accum_cnt;
5147 -
5148 - max_index++;
5149 + theta[max_index] =
5150 + ((accum_ang * (1 << scale_factor)) + accum_cnt) /
5151 + accum_cnt;
5152 }
5153
5154 /*
5155 --- a/drivers/net/wireless/ath/ath9k/beacon.c
5156 +++ b/drivers/net/wireless/ath/ath9k/beacon.c
5157 @@ -107,23 +107,6 @@ static void ath9k_beacon_setup(struct at
5158 ath9k_hw_set_txdesc(ah, bf->bf_desc, &info);
5159 }
5160
5161 -static void ath9k_tx_cabq(struct ieee80211_hw *hw, struct sk_buff *skb)
5162 -{
5163 - struct ath_softc *sc = hw->priv;
5164 - struct ath_common *common = ath9k_hw_common(sc->sc_ah);
5165 - struct ath_tx_control txctl;
5166 -
5167 - memset(&txctl, 0, sizeof(struct ath_tx_control));
5168 - txctl.txq = sc->beacon.cabq;
5169 -
5170 - ath_dbg(common, XMIT, "transmitting CABQ packet, skb: %p\n", skb);
5171 -
5172 - if (ath_tx_start(hw, skb, &txctl) != 0) {
5173 - ath_dbg(common, XMIT, "CABQ TX failed\n");
5174 - ieee80211_free_txskb(hw, skb);
5175 - }
5176 -}
5177 -
5178 static struct ath_buf *ath9k_beacon_generate(struct ieee80211_hw *hw,
5179 struct ieee80211_vif *vif)
5180 {
5181 @@ -205,10 +188,8 @@ static struct ath_buf *ath9k_beacon_gene
5182
5183 ath9k_beacon_setup(sc, vif, bf, info->control.rates[0].idx);
5184
5185 - while (skb) {
5186 - ath9k_tx_cabq(hw, skb);
5187 - skb = ieee80211_get_buffered_bc(hw, vif);
5188 - }
5189 + if (skb)
5190 + ath_tx_cabq(hw, vif, skb);
5191
5192 return bf;
5193 }
5194 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
5195 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
5196 @@ -68,13 +68,16 @@
5197 #define AR9300_BASE_ADDR 0x3ff
5198 #define AR9300_BASE_ADDR_512 0x1ff
5199
5200 -#define AR9300_OTP_BASE (AR_SREV_9340(ah) ? 0x30000 : 0x14000)
5201 -#define AR9300_OTP_STATUS (AR_SREV_9340(ah) ? 0x30018 : 0x15f18)
5202 +#define AR9300_OTP_BASE \
5203 + ((AR_SREV_9340(ah) || AR_SREV_9550(ah)) ? 0x30000 : 0x14000)
5204 +#define AR9300_OTP_STATUS \
5205 + ((AR_SREV_9340(ah) || AR_SREV_9550(ah)) ? 0x30018 : 0x15f18)
5206 #define AR9300_OTP_STATUS_TYPE 0x7
5207 #define AR9300_OTP_STATUS_VALID 0x4
5208 #define AR9300_OTP_STATUS_ACCESS_BUSY 0x2
5209 #define AR9300_OTP_STATUS_SM_BUSY 0x1
5210 -#define AR9300_OTP_READ_DATA (AR_SREV_9340(ah) ? 0x3001c : 0x15f1c)
5211 +#define AR9300_OTP_READ_DATA \
5212 + ((AR_SREV_9340(ah) || AR_SREV_9550(ah)) ? 0x3001c : 0x15f1c)
5213
5214 enum targetPowerHTRates {
5215 HT_TARGET_RATE_0_8_16,