mac80211: Fix the size used for building probe request
[linux-block.git] / net / mac80211 / sta_info.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
f0706e82
JB
2/*
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
d98ad83e 5 * Copyright 2013-2014 Intel Mobile Communications GmbH
dcba665b 6 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
3a11ce08 7 * Copyright (C) 2018-2021 Intel Corporation
f0706e82
JB
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
888d04df 12#include <linux/etherdevice.h>
f0706e82
JB
13#include <linux/netdevice.h>
14#include <linux/types.h>
15#include <linux/slab.h>
16#include <linux/skbuff.h>
17#include <linux/if_arp.h>
0d174406 18#include <linux/timer.h>
d0709a65 19#include <linux/rtnetlink.h>
f0706e82 20
484a54c2 21#include <net/codel.h>
f0706e82
JB
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
24487981 24#include "driver-ops.h"
2c8dccc7 25#include "rate.h"
f0706e82 26#include "sta_info.h"
e9f207f0 27#include "debugfs_sta.h"
ee385855 28#include "mesh.h"
ce662b44 29#include "wme.h"
f0706e82 30
d0709a65
JB
31/**
32 * DOC: STA information lifetime rules
33 *
34 * STA info structures (&struct sta_info) are managed in a hash table
35 * for faster lookup and a list for iteration. They are managed using
36 * RCU, i.e. access to the list and hash table is protected by RCU.
37 *
34e89507
JB
38 * Upon allocating a STA info structure with sta_info_alloc(), the caller
39 * owns that structure. It must then insert it into the hash table using
40 * either sta_info_insert() or sta_info_insert_rcu(); only in the latter
41 * case (which acquires an rcu read section but must not be called from
42 * within one) will the pointer still be valid after the call. Note that
43 * the caller may not do much with the STA info before inserting it, in
44 * particular, it may not start any mesh peer link management or add
45 * encryption keys.
93e5deb1
JB
46 *
47 * When the insertion fails (sta_info_insert()) returns non-zero), the
48 * structure will have been freed by sta_info_insert()!
d0709a65 49 *
34e89507 50 * Station entries are added by mac80211 when you establish a link with a
7e189a12
LR
51 * peer. This means different things for the different type of interfaces
52 * we support. For a regular station this mean we add the AP sta when we
25985edc 53 * receive an association response from the AP. For IBSS this occurs when
34e89507 54 * get to know about a peer on the same IBSS. For WDS we add the sta for
25985edc 55 * the peer immediately upon device open. When using AP mode we add stations
34e89507 56 * for each respective station upon request from userspace through nl80211.
7e189a12 57 *
34e89507
JB
58 * In order to remove a STA info structure, various sta_info_destroy_*()
59 * calls are available.
d0709a65 60 *
34e89507
JB
61 * There is no concept of ownership on a STA entry, each structure is
62 * owned by the global hash table/list until it is removed. All users of
63 * the structure need to be RCU protected so that the structure won't be
64 * freed before they are done using it.
d0709a65 65 */
f0706e82 66
7bedd0cf
JB
67static const struct rhashtable_params sta_rht_params = {
68 .nelem_hint = 3, /* start small */
caf22d31 69 .automatic_shrinking = true,
7bedd0cf 70 .head_offset = offsetof(struct sta_info, hash_node),
ac100ce5 71 .key_offset = offsetof(struct sta_info, addr),
7bedd0cf 72 .key_len = ETH_ALEN,
ebd82b39 73 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
7bedd0cf
JB
74};
75
4d33960b 76/* Caller must hold local->sta_mtx */
be8755e1
MW
77static int sta_info_hash_del(struct ieee80211_local *local,
78 struct sta_info *sta)
f0706e82 79{
83e7e4ce
HX
80 return rhltable_remove(&local->sta_hash, &sta->hash_node,
81 sta_rht_params);
f0706e82
JB
82}
83
5108ca82 84static void __cleanup_single_sta(struct sta_info *sta)
b22cfcfc 85{
b22cfcfc
EP
86 int ac, i;
87 struct tid_ampdu_tx *tid_tx;
88 struct ieee80211_sub_if_data *sdata = sta->sdata;
89 struct ieee80211_local *local = sdata->local;
d012a605 90 struct ps_data *ps;
b22cfcfc 91
e3685e03 92 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
5ac2e350
JB
93 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
94 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
d012a605
MP
95 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
96 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
97 ps = &sdata->bss->ps;
3f52b7e3
MP
98 else if (ieee80211_vif_is_mesh(&sdata->vif))
99 ps = &sdata->u.mesh.ps;
d012a605
MP
100 else
101 return;
b22cfcfc
EP
102
103 clear_sta_flag(sta, WLAN_STA_PS_STA);
e3685e03 104 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
5ac2e350 105 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
b22cfcfc 106
d012a605 107 atomic_dec(&ps->num_sta_ps);
b22cfcfc
EP
108 }
109
ba8c3d6f
FF
110 if (sta->sta.txq[0]) {
111 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
adf8ed01
JB
112 struct txq_info *txqi;
113
114 if (!sta->sta.txq[i])
115 continue;
116
117 txqi = to_txq_info(sta->sta.txq[i]);
ba8c3d6f 118
fa962b92 119 ieee80211_txq_purge(local, txqi);
ba8c3d6f
FF
120 }
121 }
122
b22cfcfc
EP
123 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
124 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
1f98ab7f
FF
125 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
126 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
b22cfcfc
EP
127 }
128
45b5028e
TP
129 if (ieee80211_vif_is_mesh(&sdata->vif))
130 mesh_sta_cleanup(sta);
b22cfcfc 131
5ac2e350 132 cancel_work_sync(&sta->drv_deliver_wk);
b22cfcfc
EP
133
134 /*
135 * Destroy aggregation state here. It would be nice to wait for the
136 * driver to finish aggregation stop and then clean up, but for now
137 * drivers have to handle aggregation stop being requested, followed
138 * directly by station destruction.
139 */
5a306f58 140 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
661eb381 141 kfree(sta->ampdu_mlme.tid_start_tx[i]);
b22cfcfc
EP
142 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
143 if (!tid_tx)
144 continue;
1f98ab7f 145 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
b22cfcfc
EP
146 kfree(tid_tx);
147 }
5108ca82 148}
b22cfcfc 149
5108ca82
JB
150static void cleanup_single_sta(struct sta_info *sta)
151{
152 struct ieee80211_sub_if_data *sdata = sta->sdata;
153 struct ieee80211_local *local = sdata->local;
154
155 __cleanup_single_sta(sta);
b22cfcfc
EP
156 sta_info_free(local, sta);
157}
158
83e7e4ce
HX
159struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
160 const u8 *addr)
161{
162 return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
163}
164
d0709a65 165/* protected by RCU */
abe60632
JB
166struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
167 const u8 *addr)
f0706e82 168{
abe60632 169 struct ieee80211_local *local = sdata->local;
83e7e4ce 170 struct rhlist_head *tmp;
60f4b626 171 struct sta_info *sta;
f0706e82 172
60f4b626 173 rcu_read_lock();
83e7e4ce 174 for_each_sta_info(local, addr, sta, tmp) {
60f4b626
JB
175 if (sta->sdata == sdata) {
176 rcu_read_unlock();
177 /* this is safe as the caller must already hold
178 * another rcu read section or the mutex
179 */
180 return sta;
181 }
182 }
183 rcu_read_unlock();
184 return NULL;
43ba7e95
JB
185}
186
0e5ded5a
FF
187/*
188 * Get sta info either from the specified interface
189 * or from one of its vlans
190 */
191struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
192 const u8 *addr)
193{
194 struct ieee80211_local *local = sdata->local;
83e7e4ce 195 struct rhlist_head *tmp;
0e5ded5a
FF
196 struct sta_info *sta;
197
7bedd0cf 198 rcu_read_lock();
83e7e4ce 199 for_each_sta_info(local, addr, sta, tmp) {
7bedd0cf
JB
200 if (sta->sdata == sdata ||
201 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
202 rcu_read_unlock();
203 /* this is safe as the caller must already hold
204 * another rcu read section or the mutex
205 */
206 return sta;
207 }
0e5ded5a 208 }
7bedd0cf
JB
209 rcu_read_unlock();
210 return NULL;
0e5ded5a
FF
211}
212
5072f73c
THJ
213struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
214 const u8 *sta_addr, const u8 *vif_addr)
215{
216 struct rhlist_head *tmp;
217 struct sta_info *sta;
218
219 for_each_sta_info(local, sta_addr, sta, tmp) {
220 if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
221 return sta;
222 }
223
224 return NULL;
225}
226
3b53fde8
JB
227struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
228 int idx)
ee385855 229{
3b53fde8 230 struct ieee80211_local *local = sdata->local;
ee385855
LCC
231 struct sta_info *sta;
232 int i = 0;
233
8ca47eb9
MB
234 list_for_each_entry_rcu(sta, &local->sta_list, list,
235 lockdep_is_held(&local->sta_mtx)) {
3b53fde8 236 if (sdata != sta->sdata)
2a8ca29a 237 continue;
ee385855
LCC
238 if (i < idx) {
239 ++i;
240 continue;
ee385855 241 }
2a8ca29a 242 return sta;
ee385855 243 }
ee385855
LCC
244
245 return NULL;
246}
f0706e82 247
93e5deb1 248/**
d9a7ddb0 249 * sta_info_free - free STA
93e5deb1 250 *
6ef307bc 251 * @local: pointer to the global information
93e5deb1
JB
252 * @sta: STA info to free
253 *
254 * This function must undo everything done by sta_info_alloc()
d9a7ddb0
JB
255 * that may happen before sta_info_insert(). It may only be
256 * called when sta_info_insert() has not been attempted (and
257 * if that fails, the station is freed anyway.)
93e5deb1 258 */
d9a7ddb0 259void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
93e5deb1 260{
dcd479e1
JB
261 /*
262 * If we had used sta_info_pre_move_state() then we might not
263 * have gone through the state transitions down again, so do
264 * it here now (and warn if it's inserted).
265 *
266 * This will clear state such as fast TX/RX that may have been
267 * allocated during state transitions.
268 */
269 while (sta->sta_state > IEEE80211_STA_NONE) {
270 int ret;
271
272 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
273
274 ret = sta_info_move_state(sta, sta->sta_state - 1);
275 if (WARN_ONCE(ret, "sta_info_move_state() returned %d\n", ret))
276 break;
277 }
278
889cbb91 279 if (sta->rate_ctrl)
af65cd96 280 rate_control_free_sta(sta);
93e5deb1 281
bdcbd8e0 282 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
93e5deb1 283
ba8c3d6f
FF
284 if (sta->sta.txq[0])
285 kfree(to_txq_info(sta->sta.txq[0]));
53d04525 286 kfree(rcu_dereference_raw(sta->sta.rates));
433f5bc1
JB
287#ifdef CONFIG_MAC80211_MESH
288 kfree(sta->mesh);
289#endif
c9c5962b 290 free_percpu(sta->pcpu_rx_stats);
93e5deb1
JB
291 kfree(sta);
292}
293
4d33960b 294/* Caller must hold local->sta_mtx */
62b14b24
JB
295static int sta_info_hash_add(struct ieee80211_local *local,
296 struct sta_info *sta)
f0706e82 297{
83e7e4ce
HX
298 return rhltable_insert(&local->sta_hash, &sta->hash_node,
299 sta_rht_params);
f0706e82 300}
f0706e82 301
5ac2e350 302static void sta_deliver_ps_frames(struct work_struct *wk)
af818581
JB
303{
304 struct sta_info *sta;
305
5ac2e350 306 sta = container_of(wk, struct sta_info, drv_deliver_wk);
af818581
JB
307
308 if (sta->dead)
309 return;
310
5ac2e350
JB
311 local_bh_disable();
312 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
af818581 313 ieee80211_sta_ps_deliver_wakeup(sta);
5ac2e350 314 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
af818581 315 ieee80211_sta_ps_deliver_poll_response(sta);
5ac2e350 316 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
47086fc5 317 ieee80211_sta_ps_deliver_uapsd(sta);
5ac2e350 318 local_bh_enable();
af818581
JB
319}
320
af65cd96
JB
321static int sta_prepare_rate_control(struct ieee80211_local *local,
322 struct sta_info *sta, gfp_t gfp)
323{
30686bf7 324 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
af65cd96
JB
325 return 0;
326
889cbb91 327 sta->rate_ctrl = local->rate_ctrl;
af65cd96 328 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
35c347ac 329 sta, gfp);
889cbb91 330 if (!sta->rate_ctrl_priv)
af65cd96 331 return -ENOMEM;
af65cd96
JB
332
333 return 0;
334}
335
73651ee6 336struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
56544160 337 const u8 *addr, gfp_t gfp)
f0706e82 338{
d0709a65 339 struct ieee80211_local *local = sdata->local;
ba8c3d6f 340 struct ieee80211_hw *hw = &local->hw;
f0706e82 341 struct sta_info *sta;
16c5f15c 342 int i;
f0706e82 343
ba8c3d6f 344 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
f0706e82 345 if (!sta)
73651ee6 346 return NULL;
f0706e82 347
c9c5962b
JB
348 if (ieee80211_hw_check(hw, USES_RSS)) {
349 sta->pcpu_rx_stats =
95f3ce6a 350 alloc_percpu_gfp(struct ieee80211_sta_rx_stats, gfp);
c9c5962b
JB
351 if (!sta->pcpu_rx_stats)
352 goto free;
353 }
354
07346f81 355 spin_lock_init(&sta->lock);
1d147bfa 356 spin_lock_init(&sta->ps_lock);
5ac2e350 357 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
67c282c0 358 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
a93e3644 359 mutex_init(&sta->ampdu_mlme.mtx);
87f59c70 360#ifdef CONFIG_MAC80211_MESH
433f5bc1
JB
361 if (ieee80211_vif_is_mesh(&sdata->vif)) {
362 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
363 if (!sta->mesh)
364 goto free;
4c02d62f 365 sta->mesh->plink_sta = sta;
433f5bc1
JB
366 spin_lock_init(&sta->mesh->plink_lock);
367 if (ieee80211_vif_is_mesh(&sdata->vif) &&
368 !sdata->u.mesh.user_mpm)
4c02d62f
KC
369 timer_setup(&sta->mesh->plink_timer, mesh_plink_timer,
370 0);
433f5bc1
JB
371 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
372 }
87f59c70 373#endif
07346f81 374
ac100ce5 375 memcpy(sta->addr, addr, ETH_ALEN);
17741cdc 376 memcpy(sta->sta.addr, addr, ETH_ALEN);
480dd46b
MA
377 sta->sta.max_rx_aggregation_subframes =
378 local->hw.max_rx_aggregation_subframes;
379
96fc6efb
AW
380 /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
381 * The Tx path starts to use a key as soon as the key slot ptk_idx
382 * references to is not NULL. To not use the initial Rx-only key
383 * prematurely for Tx initialize ptk_idx to an impossible PTK keyid
384 * which always will refer to a NULL key.
385 */
386 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
387 sta->ptk_idx = INVALID_PTK_KEYIDX;
388
d0709a65
JB
389 sta->local = local;
390 sta->sdata = sdata;
e5a9f8d0 391 sta->rx_stats.last_rx = jiffies;
f0706e82 392
0f9c5a61
JB
393 u64_stats_init(&sta->rx_stats.syncp);
394
3a11ce08
JB
395 ieee80211_init_frag_cache(&sta->frags);
396
71ec375c
JB
397 sta->sta_state = IEEE80211_STA_NONE;
398
b6da911b
LK
399 /* Mark TID as unreserved */
400 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
401
84b00607 402 sta->last_connected = ktime_get_seconds();
0be6ed13 403 ewma_signal_init(&sta->rx_stats_avg.signal);
cc60dbbf 404 ewma_avg_signal_init(&sta->status_stats.avg_ack_signal);
0be6ed13
JB
405 for (i = 0; i < ARRAY_SIZE(sta->rx_stats_avg.chain_signal); i++)
406 ewma_signal_init(&sta->rx_stats_avg.chain_signal[i]);
541a45a1 407
ba8c3d6f
FF
408 if (local->ops->wake_tx_queue) {
409 void *txq_data;
410 int size = sizeof(struct txq_info) +
411 ALIGN(hw->txq_data_size, sizeof(void *));
412
413 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
414 if (!txq_data)
415 goto free;
416
417 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
418 struct txq_info *txq = txq_data + i * size;
419
adf8ed01 420 /* might not do anything for the bufferable MMPDU TXQ */
fa962b92 421 ieee80211_txq_init(sdata, sta, txq, i);
ba8c3d6f 422 }
abfbc3af 423 }
f0706e82 424
ba8c3d6f
FF
425 if (sta_prepare_rate_control(local, sta, gfp))
426 goto free_txq;
427
b4809e94 428
948d887d
JB
429 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
430 skb_queue_head_init(&sta->ps_tx_buf[i]);
431 skb_queue_head_init(&sta->tx_filtered[i]);
2433647b 432 init_airtime_info(&sta->airtime[i], &local->airtime[i]);
948d887d 433 }
73651ee6 434
5a306f58 435 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
4be929be 436 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
cccaec98 437
bd718fc1
JB
438 for (i = 0; i < NUM_NL80211_BANDS; i++) {
439 u32 mandatory = 0;
440 int r;
441
442 if (!hw->wiphy->bands[i])
443 continue;
444
445 switch (i) {
446 case NL80211_BAND_2GHZ:
63fa0426 447 case NL80211_BAND_LC:
bd718fc1
JB
448 /*
449 * We use both here, even if we cannot really know for
450 * sure the station will support both, but the only use
451 * for this is when we don't know anything yet and send
452 * management frames, and then we'll pick the lowest
453 * possible rate anyway.
454 * If we don't include _G here, we cannot find a rate
455 * in P2P, and thus trigger the WARN_ONCE() in rate.c
456 */
457 mandatory = IEEE80211_RATE_MANDATORY_B |
458 IEEE80211_RATE_MANDATORY_G;
459 break;
460 case NL80211_BAND_5GHZ:
461 mandatory = IEEE80211_RATE_MANDATORY_A;
462 break;
463 case NL80211_BAND_60GHZ:
464 WARN_ON(1);
465 mandatory = 0;
466 break;
467 }
468
469 for (r = 0; r < hw->wiphy->bands[i]->n_bitrates; r++) {
470 struct ieee80211_rate *rate;
471
472 rate = &hw->wiphy->bands[i]->bitrates[r];
473
474 if (!(rate->flags & mandatory))
475 continue;
476 sta->sta.supp_rates[i] |= BIT(r);
477 }
478 }
479
af0ed69b 480 sta->sta.smps_mode = IEEE80211_SMPS_OFF;
687da132
EG
481 if (sdata->vif.type == NL80211_IFTYPE_AP ||
482 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
21a8e9dd
MSS
483 struct ieee80211_supported_band *sband;
484 u8 smps;
485
486 sband = ieee80211_get_sband(sdata);
487 if (!sband)
488 goto free_txq;
489
490 smps = (sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS) >>
491 IEEE80211_HT_CAP_SM_PS_SHIFT;
687da132
EG
492 /*
493 * Assume that hostapd advertises our caps in the beacon and
494 * this is the known_smps_mode for a station that just assciated
495 */
496 switch (smps) {
497 case WLAN_HT_SMPS_CONTROL_DISABLED:
498 sta->known_smps_mode = IEEE80211_SMPS_OFF;
499 break;
500 case WLAN_HT_SMPS_CONTROL_STATIC:
501 sta->known_smps_mode = IEEE80211_SMPS_STATIC;
502 break;
503 case WLAN_HT_SMPS_CONTROL_DYNAMIC:
504 sta->known_smps_mode = IEEE80211_SMPS_DYNAMIC;
505 break;
506 default:
507 WARN_ON(1);
508 }
509 }
af0ed69b 510
6e0456b5
FF
511 sta->sta.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
512
484a54c2
THJ
513 sta->cparams.ce_threshold = CODEL_DISABLED_THRESHOLD;
514 sta->cparams.target = MS2TIME(20);
515 sta->cparams.interval = MS2TIME(100);
516 sta->cparams.ecn = true;
dfcb63ce
THJ
517 sta->cparams.ce_threshold_selector = 0;
518 sta->cparams.ce_threshold_mask = 0;
484a54c2 519
bdcbd8e0 520 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
ef04a297 521
abfbc3af 522 return sta;
ba8c3d6f
FF
523
524free_txq:
525 if (sta->sta.txq[0])
526 kfree(to_txq_info(sta->sta.txq[0]));
527free:
d78d9ee9 528 free_percpu(sta->pcpu_rx_stats);
433f5bc1
JB
529#ifdef CONFIG_MAC80211_MESH
530 kfree(sta->mesh);
531#endif
ba8c3d6f
FF
532 kfree(sta);
533 return NULL;
73651ee6
JB
534}
535
8c71df7a 536static int sta_info_insert_check(struct sta_info *sta)
34e89507 537{
34e89507 538 struct ieee80211_sub_if_data *sdata = sta->sdata;
34e89507 539
03e4497e
JB
540 /*
541 * Can't be a WARN_ON because it can be triggered through a race:
542 * something inserts a STA (on one CPU) without holding the RTNL
543 * and another CPU turns off the net device.
544 */
8c71df7a
GE
545 if (unlikely(!ieee80211_sdata_running(sdata)))
546 return -ENETDOWN;
03e4497e 547
b203ca39 548 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
deebea0a 549 !is_valid_ether_addr(sta->sta.addr)))
8c71df7a
GE
550 return -EINVAL;
551
83e7e4ce
HX
552 /* The RCU read lock is required by rhashtable due to
553 * asynchronous resize/rehash. We also require the mutex
554 * for correctness.
31104891
JB
555 */
556 rcu_read_lock();
557 lockdep_assert_held(&sdata->local->sta_mtx);
558 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
559 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
560 rcu_read_unlock();
561 return -ENOTUNIQ;
562 }
563 rcu_read_unlock();
564
8c71df7a
GE
565 return 0;
566}
567
f09603a2
JB
568static int sta_info_insert_drv_state(struct ieee80211_local *local,
569 struct ieee80211_sub_if_data *sdata,
570 struct sta_info *sta)
571{
572 enum ieee80211_sta_state state;
573 int err = 0;
574
575 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
576 err = drv_sta_state(local, sdata, sta, state, state + 1);
577 if (err)
578 break;
579 }
580
581 if (!err) {
a4ec45a4
JB
582 /*
583 * Drivers using legacy sta_add/sta_remove callbacks only
584 * get uploaded set to true after sta_add is called.
585 */
586 if (!local->ops->sta_add)
587 sta->uploaded = true;
f09603a2
JB
588 return 0;
589 }
590
591 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
bdcbd8e0
JB
592 sdata_info(sdata,
593 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
594 sta->sta.addr, state + 1, err);
f09603a2
JB
595 err = 0;
596 }
597
598 /* unwind on error */
599 for (; state > IEEE80211_STA_NOTEXIST; state--)
600 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
601
602 return err;
603}
604
d405fd8c
GG
605static void
606ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
607{
608 struct ieee80211_local *local = sdata->local;
609 bool allow_p2p_go_ps = sdata->vif.p2p;
610 struct sta_info *sta;
611
612 rcu_read_lock();
613 list_for_each_entry_rcu(sta, &local->sta_list, list) {
614 if (sdata != sta->sdata ||
615 !test_sta_flag(sta, WLAN_STA_ASSOC))
616 continue;
617 if (!sta->sta.support_p2p_ps) {
618 allow_p2p_go_ps = false;
619 break;
620 }
621 }
622 rcu_read_unlock();
623
624 if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
625 sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
626 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_P2P_PS);
627 }
628}
629
8c71df7a
GE
630/*
631 * should be called with sta_mtx locked
632 * this function replaces the mutex lock
633 * with a RCU lock
634 */
4d33960b 635static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
8c71df7a
GE
636{
637 struct ieee80211_local *local = sta->local;
638 struct ieee80211_sub_if_data *sdata = sta->sdata;
0c2e3842 639 struct station_info *sinfo = NULL;
8c71df7a
GE
640 int err = 0;
641
642 lockdep_assert_held(&local->sta_mtx);
34e89507 643
7852e361
JB
644 /* check if STA exists already */
645 if (sta_info_get_bss(sdata, sta->sta.addr)) {
646 err = -EEXIST;
8f9dcc29 647 goto out_cleanup;
4d33960b 648 }
32bfd35d 649
0c2e3842
KV
650 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
651 if (!sinfo) {
652 err = -ENOMEM;
8f9dcc29 653 goto out_cleanup;
0c2e3842
KV
654 }
655
7852e361
JB
656 local->num_sta++;
657 local->sta_generation++;
658 smp_mb();
4d33960b 659
5108ca82
JB
660 /* simplify things and don't accept BA sessions yet */
661 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
662
7852e361 663 /* make the station visible */
62b14b24
JB
664 err = sta_info_hash_add(local, sta);
665 if (err)
666 goto out_drop_sta;
83d5cc01 667
2bad7748 668 list_add_tail_rcu(&sta->list, &local->sta_list);
4d33960b 669
5108ca82
JB
670 /* notify driver */
671 err = sta_info_insert_drv_state(local, sdata, sta);
672 if (err)
673 goto out_remove;
674
7852e361 675 set_sta_flag(sta, WLAN_STA_INSERTED);
d405fd8c
GG
676
677 if (sta->sta_state >= IEEE80211_STA_ASSOC) {
678 ieee80211_recalc_min_chandef(sta->sdata);
679 if (!sta->sta.support_p2p_ps)
680 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
681 }
682
5108ca82
JB
683 /* accept BA sessions now */
684 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
4d33960b 685
7852e361
JB
686 ieee80211_sta_debugfs_add(sta);
687 rate_control_add_sta_debugfs(sta);
4d33960b 688
0ef049dc
AB
689 sinfo->generation = local->sta_generation;
690 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
691 kfree(sinfo);
d0709a65 692
bdcbd8e0 693 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
f0706e82 694
34e89507
JB
695 /* move reference to rcu-protected */
696 rcu_read_lock();
697 mutex_unlock(&local->sta_mtx);
e9f207f0 698
73651ee6
JB
699 if (ieee80211_vif_is_mesh(&sdata->vif))
700 mesh_accept_plinks_update(sdata);
701
8c71df7a 702 return 0;
5108ca82
JB
703 out_remove:
704 sta_info_hash_del(local, sta);
705 list_del_rcu(&sta->list);
62b14b24 706 out_drop_sta:
5108ca82
JB
707 local->num_sta--;
708 synchronize_net();
8f9dcc29 709 out_cleanup:
7bc40aed 710 cleanup_single_sta(sta);
4d33960b 711 mutex_unlock(&local->sta_mtx);
ea32f065 712 kfree(sinfo);
4d33960b
JB
713 rcu_read_lock();
714 return err;
8c71df7a
GE
715}
716
717int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
718{
719 struct ieee80211_local *local = sta->local;
308f7fcf 720 int err;
8c71df7a 721
4d33960b
JB
722 might_sleep();
723
31104891
JB
724 mutex_lock(&local->sta_mtx);
725
8c71df7a
GE
726 err = sta_info_insert_check(sta);
727 if (err) {
7bc40aed 728 sta_info_free(local, sta);
31104891 729 mutex_unlock(&local->sta_mtx);
8c71df7a 730 rcu_read_lock();
7bc40aed 731 return err;
8c71df7a
GE
732 }
733
7bc40aed 734 return sta_info_insert_finish(sta);
f0706e82
JB
735}
736
34e89507
JB
737int sta_info_insert(struct sta_info *sta)
738{
739 int err = sta_info_insert_rcu(sta);
740
741 rcu_read_unlock();
742
743 return err;
744}
745
d012a605 746static inline void __bss_tim_set(u8 *tim, u16 id)
004c872e
JB
747{
748 /*
749 * This format has been mandated by the IEEE specifications,
750 * so this line may not be changed to use the __set_bit() format.
751 */
d012a605 752 tim[id / 8] |= (1 << (id % 8));
004c872e
JB
753}
754
d012a605 755static inline void __bss_tim_clear(u8 *tim, u16 id)
004c872e
JB
756{
757 /*
758 * This format has been mandated by the IEEE specifications,
759 * so this line may not be changed to use the __clear_bit() format.
760 */
d012a605 761 tim[id / 8] &= ~(1 << (id % 8));
004c872e
JB
762}
763
3d5839b6
IP
764static inline bool __bss_tim_get(u8 *tim, u16 id)
765{
766 /*
767 * This format has been mandated by the IEEE specifications,
768 * so this line may not be changed to use the test_bit() format.
769 */
770 return tim[id / 8] & (1 << (id % 8));
771}
772
948d887d 773static unsigned long ieee80211_tids_for_ac(int ac)
004c872e 774{
948d887d
JB
775 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
776 switch (ac) {
777 case IEEE80211_AC_VO:
778 return BIT(6) | BIT(7);
779 case IEEE80211_AC_VI:
780 return BIT(4) | BIT(5);
781 case IEEE80211_AC_BE:
782 return BIT(0) | BIT(3);
783 case IEEE80211_AC_BK:
784 return BIT(1) | BIT(2);
785 default:
786 WARN_ON(1);
787 return 0;
d0709a65 788 }
004c872e
JB
789}
790
9b7a86f3 791static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
004c872e 792{
c868cb35 793 struct ieee80211_local *local = sta->local;
d012a605 794 struct ps_data *ps;
948d887d
JB
795 bool indicate_tim = false;
796 u8 ignore_for_tim = sta->sta.uapsd_queues;
797 int ac;
a69bd8e6 798 u16 id = sta->sta.aid;
d012a605
MP
799
800 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
801 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
802 if (WARN_ON_ONCE(!sta->sdata->bss))
803 return;
004c872e 804
d012a605 805 ps = &sta->sdata->bss->ps;
3f52b7e3
MP
806#ifdef CONFIG_MAC80211_MESH
807 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
808 ps = &sta->sdata->u.mesh.ps;
3f52b7e3 809#endif
d012a605 810 } else {
c868cb35 811 return;
d012a605 812 }
3e122be0 813
c868cb35 814 /* No need to do anything if the driver does all */
d98937f4 815 if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
c868cb35 816 return;
004c872e 817
c868cb35
JB
818 if (sta->dead)
819 goto done;
3e122be0 820
948d887d
JB
821 /*
822 * If all ACs are delivery-enabled then we should build
823 * the TIM bit for all ACs anyway; if only some are then
824 * we ignore those and build the TIM bit using only the
825 * non-enabled ones.
826 */
827 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
828 ignore_for_tim = 0;
829
9b7a86f3
JB
830 if (ignore_pending)
831 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
832
948d887d
JB
833 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
834 unsigned long tids;
3e122be0 835
f438ceb8 836 if (ignore_for_tim & ieee80211_ac_to_qos_mask[ac])
948d887d
JB
837 continue;
838
839 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
840 !skb_queue_empty(&sta->ps_tx_buf[ac]);
841 if (indicate_tim)
842 break;
3e122be0 843
948d887d
JB
844 tids = ieee80211_tids_for_ac(ac);
845
846 indicate_tim |=
847 sta->driver_buffered_tids & tids;
ba8c3d6f
FF
848 indicate_tim |=
849 sta->txq_buffered_tids & tids;
d0709a65 850 }
004c872e 851
c868cb35 852 done:
65f704a5 853 spin_lock_bh(&local->tim_lock);
004c872e 854
3d5839b6
IP
855 if (indicate_tim == __bss_tim_get(ps->tim, id))
856 goto out_unlock;
857
948d887d 858 if (indicate_tim)
d012a605 859 __bss_tim_set(ps->tim, id);
c868cb35 860 else
d012a605 861 __bss_tim_clear(ps->tim, id);
004c872e 862
9b7a86f3 863 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
c868cb35 864 local->tim_in_locked_section = true;
948d887d 865 drv_set_tim(local, &sta->sta, indicate_tim);
c868cb35
JB
866 local->tim_in_locked_section = false;
867 }
3e122be0 868
3d5839b6 869out_unlock:
65f704a5 870 spin_unlock_bh(&local->tim_lock);
004c872e
JB
871}
872
9b7a86f3
JB
873void sta_info_recalc_tim(struct sta_info *sta)
874{
875 __sta_info_recalc_tim(sta, false);
876}
877
cd0b8d89 878static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
f0706e82 879{
e039fa4a 880 struct ieee80211_tx_info *info;
f0706e82
JB
881 int timeout;
882
883 if (!skb)
cd0b8d89 884 return false;
f0706e82 885
e039fa4a 886 info = IEEE80211_SKB_CB(skb);
f0706e82
JB
887
888 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
57c4d7b4
JB
889 timeout = (sta->listen_interval *
890 sta->sdata->vif.bss_conf.beacon_int *
891 32 / 15625) * HZ;
f0706e82
JB
892 if (timeout < STA_TX_BUFFER_EXPIRE)
893 timeout = STA_TX_BUFFER_EXPIRE;
e039fa4a 894 return time_after(jiffies, info->control.jiffies + timeout);
f0706e82
JB
895}
896
897
948d887d
JB
898static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
899 struct sta_info *sta, int ac)
f0706e82
JB
900{
901 unsigned long flags;
902 struct sk_buff *skb;
903
60750397
JB
904 /*
905 * First check for frames that should expire on the filtered
906 * queue. Frames here were rejected by the driver and are on
907 * a separate queue to avoid reordering with normal PS-buffered
908 * frames. They also aren't accounted for right now in the
909 * total_ps_buffered counter.
910 */
911 for (;;) {
948d887d
JB
912 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
913 skb = skb_peek(&sta->tx_filtered[ac]);
60750397 914 if (sta_info_buffer_expired(sta, skb))
948d887d 915 skb = __skb_dequeue(&sta->tx_filtered[ac]);
60750397
JB
916 else
917 skb = NULL;
948d887d 918 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
60750397
JB
919
920 /*
921 * Frames are queued in order, so if this one
922 * hasn't expired yet we can stop testing. If
923 * we actually reached the end of the queue we
924 * also need to stop, of course.
925 */
926 if (!skb)
927 break;
d4fa14cd 928 ieee80211_free_txskb(&local->hw, skb);
60750397
JB
929 }
930
931 /*
932 * Now also check the normal PS-buffered queue, this will
933 * only find something if the filtered queue was emptied
934 * since the filtered frames are all before the normal PS
935 * buffered frames.
936 */
f0706e82 937 for (;;) {
948d887d
JB
938 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
939 skb = skb_peek(&sta->ps_tx_buf[ac]);
57c4d7b4 940 if (sta_info_buffer_expired(sta, skb))
948d887d 941 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
836341a7 942 else
f0706e82 943 skb = NULL;
948d887d 944 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
f0706e82 945
60750397
JB
946 /*
947 * frames are queued in order, so if this one
948 * hasn't expired yet (or we reached the end of
949 * the queue) we can stop testing
950 */
836341a7 951 if (!skb)
f0706e82 952 break;
836341a7 953
836341a7 954 local->total_ps_buffered--;
bdcbd8e0
JB
955 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
956 sta->sta.addr);
d4fa14cd 957 ieee80211_free_txskb(&local->hw, skb);
f0706e82 958 }
3393a608 959
60750397
JB
960 /*
961 * Finally, recalculate the TIM bit for this station -- it might
962 * now be clear because the station was too slow to retrieve its
963 * frames.
964 */
965 sta_info_recalc_tim(sta);
966
967 /*
968 * Return whether there are any frames still buffered, this is
969 * used to check whether the cleanup timer still needs to run,
970 * if there are no frames we don't need to rearm the timer.
971 */
948d887d
JB
972 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
973 skb_queue_empty(&sta->tx_filtered[ac]));
974}
975
976static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
977 struct sta_info *sta)
978{
979 bool have_buffered = false;
980 int ac;
981
3f52b7e3
MP
982 /* This is only necessary for stations on BSS/MBSS interfaces */
983 if (!sta->sdata->bss &&
984 !ieee80211_vif_is_mesh(&sta->sdata->vif))
948d887d
JB
985 return false;
986
987 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
988 have_buffered |=
989 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
990
991 return have_buffered;
f0706e82
JB
992}
993
d778207b 994static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
f0706e82 995{
34e89507
JB
996 struct ieee80211_local *local;
997 struct ieee80211_sub_if_data *sdata;
6d10e46b 998 int ret;
f0706e82 999
34e89507 1000 might_sleep();
f0706e82 1001
34e89507
JB
1002 if (!sta)
1003 return -ENOENT;
5bb644a0 1004
34e89507
JB
1005 local = sta->local;
1006 sdata = sta->sdata;
f0706e82 1007
83d5cc01
JB
1008 lockdep_assert_held(&local->sta_mtx);
1009
098a6070
JB
1010 /*
1011 * Before removing the station from the driver and
1012 * rate control, it might still start new aggregation
1013 * sessions -- block that to make sure the tear-down
1014 * will be sufficient.
1015 */
c2c98fde 1016 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
c82c4a80 1017 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
098a6070 1018
f59374eb
SS
1019 /*
1020 * Before removing the station from the driver there might be pending
1021 * rx frames on RSS queues sent prior to the disassociation - wait for
1022 * all such frames to be processed.
1023 */
1024 drv_sync_rx_queues(local, sta);
1025
34e89507 1026 ret = sta_info_hash_del(local, sta);
b01711be 1027 if (WARN_ON(ret))
34e89507
JB
1028 return ret;
1029
a7a6bdd0
AN
1030 /*
1031 * for TDLS peers, make sure to return to the base channel before
1032 * removal.
1033 */
1034 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
1035 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1036 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1037 }
1038
794454ce 1039 list_del_rcu(&sta->list);
ef044763 1040 sta->removed = true;
4d33960b 1041
6a9d1b91
JB
1042 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1043
a710c816
JB
1044 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1045 rcu_access_pointer(sdata->u.vlan.sta) == sta)
1046 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
1047
d778207b
JB
1048 return 0;
1049}
1050
1051static void __sta_info_destroy_part2(struct sta_info *sta)
1052{
1053 struct ieee80211_local *local = sta->local;
1054 struct ieee80211_sub_if_data *sdata = sta->sdata;
0ef049dc 1055 struct station_info *sinfo;
d778207b
JB
1056 int ret;
1057
1058 /*
1059 * NOTE: This assumes at least synchronize_net() was done
1060 * after _part1 and before _part2!
1061 */
1062
1063 might_sleep();
1064 lockdep_assert_held(&local->sta_mtx);
1065
5981fe5b 1066 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
b16798f5
JB
1067 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1068 WARN_ON_ONCE(ret);
1069 }
1070
c8782078 1071 /* now keys can no longer be reached */
6d10e46b 1072 ieee80211_free_sta_keys(local, sta);
34e89507 1073
9b7a86f3
JB
1074 /* disable TIM bit - last chance to tell driver */
1075 __sta_info_recalc_tim(sta, true);
1076
34e89507
JB
1077 sta->dead = true;
1078
34e89507
JB
1079 local->num_sta--;
1080 local->sta_generation++;
1081
83d5cc01 1082 while (sta->sta_state > IEEE80211_STA_NONE) {
f09603a2
JB
1083 ret = sta_info_move_state(sta, sta->sta_state - 1);
1084 if (ret) {
83d5cc01
JB
1085 WARN_ON_ONCE(1);
1086 break;
1087 }
1088 }
d9a7ddb0 1089
f09603a2 1090 if (sta->uploaded) {
f09603a2
JB
1091 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
1092 IEEE80211_STA_NOTEXIST);
1093 WARN_ON_ONCE(ret != 0);
1094 }
34e89507 1095
bdcbd8e0
JB
1096 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
1097
0ef049dc
AB
1098 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
1099 if (sinfo)
0fdf1493 1100 sta_set_sinfo(sta, sinfo, true);
0ef049dc
AB
1101 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1102 kfree(sinfo);
ec15e68b 1103
34e89507
JB
1104 ieee80211_sta_debugfs_remove(sta);
1105
3a11ce08
JB
1106 ieee80211_destroy_frag_cache(&sta->frags);
1107
d34ba216 1108 cleanup_single_sta(sta);
d778207b
JB
1109}
1110
1111int __must_check __sta_info_destroy(struct sta_info *sta)
1112{
1113 int err = __sta_info_destroy_part1(sta);
1114
1115 if (err)
1116 return err;
1117
1118 synchronize_net();
1119
1120 __sta_info_destroy_part2(sta);
34e89507
JB
1121
1122 return 0;
4d6141c3
JS
1123}
1124
34e89507 1125int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
4d6141c3 1126{
34e89507
JB
1127 struct sta_info *sta;
1128 int ret;
4d6141c3 1129
34e89507 1130 mutex_lock(&sdata->local->sta_mtx);
7852e361 1131 sta = sta_info_get(sdata, addr);
34e89507
JB
1132 ret = __sta_info_destroy(sta);
1133 mutex_unlock(&sdata->local->sta_mtx);
4d6141c3
JS
1134
1135 return ret;
1136}
1137
34e89507
JB
1138int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
1139 const u8 *addr)
e9f207f0 1140{
34e89507
JB
1141 struct sta_info *sta;
1142 int ret;
e9f207f0 1143
34e89507 1144 mutex_lock(&sdata->local->sta_mtx);
7852e361 1145 sta = sta_info_get_bss(sdata, addr);
34e89507
JB
1146 ret = __sta_info_destroy(sta);
1147 mutex_unlock(&sdata->local->sta_mtx);
d0709a65 1148
34e89507
JB
1149 return ret;
1150}
e9f207f0 1151
34f11cd3 1152static void sta_info_cleanup(struct timer_list *t)
34e89507 1153{
34f11cd3 1154 struct ieee80211_local *local = from_timer(local, t, sta_cleanup);
34e89507 1155 struct sta_info *sta;
3393a608 1156 bool timer_needed = false;
34e89507
JB
1157
1158 rcu_read_lock();
1159 list_for_each_entry_rcu(sta, &local->sta_list, list)
3393a608
JO
1160 if (sta_info_cleanup_expire_buffered(local, sta))
1161 timer_needed = true;
34e89507 1162 rcu_read_unlock();
e9f207f0 1163
34e89507
JB
1164 if (local->quiescing)
1165 return;
d0709a65 1166
3393a608
JO
1167 if (!timer_needed)
1168 return;
1169
26d59535
JB
1170 mod_timer(&local->sta_cleanup,
1171 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
e9f207f0 1172}
e9f207f0 1173
7bedd0cf
JB
1174int sta_info_init(struct ieee80211_local *local)
1175{
1176 int err;
1177
83e7e4ce 1178 err = rhltable_init(&local->sta_hash, &sta_rht_params);
7bedd0cf
JB
1179 if (err)
1180 return err;
1181
4d33960b 1182 spin_lock_init(&local->tim_lock);
34e89507 1183 mutex_init(&local->sta_mtx);
f0706e82 1184 INIT_LIST_HEAD(&local->sta_list);
f0706e82 1185
34f11cd3 1186 timer_setup(&local->sta_cleanup, sta_info_cleanup, 0);
7bedd0cf 1187 return 0;
f0706e82
JB
1188}
1189
1190void sta_info_stop(struct ieee80211_local *local)
1191{
a56f992c 1192 del_timer_sync(&local->sta_cleanup);
83e7e4ce 1193 rhltable_destroy(&local->sta_hash);
f0706e82
JB
1194}
1195
051007d9 1196
e716251d 1197int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
f0706e82 1198{
b998e8bb 1199 struct ieee80211_local *local = sdata->local;
f0706e82 1200 struct sta_info *sta, *tmp;
d778207b 1201 LIST_HEAD(free_list);
44213b5e 1202 int ret = 0;
f0706e82 1203
d0709a65 1204 might_sleep();
be8755e1 1205
e716251d
JB
1206 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1207 WARN_ON(vlans && !sdata->bss);
1208
34e89507 1209 mutex_lock(&local->sta_mtx);
d0709a65 1210 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
e716251d
JB
1211 if (sdata == sta->sdata ||
1212 (vlans && sdata->bss == sta->sdata->bss)) {
d778207b
JB
1213 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1214 list_add(&sta->free_list, &free_list);
34316837
JB
1215 ret++;
1216 }
be8755e1 1217 }
d778207b
JB
1218
1219 if (!list_empty(&free_list)) {
1220 synchronize_net();
1221 list_for_each_entry_safe(sta, tmp, &free_list, free_list)
1222 __sta_info_destroy_part2(sta);
1223 }
34e89507 1224 mutex_unlock(&local->sta_mtx);
44213b5e 1225
051007d9
JB
1226 return ret;
1227}
1228
24723d1b
JB
1229void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1230 unsigned long exp_time)
1231{
1232 struct ieee80211_local *local = sdata->local;
1233 struct sta_info *sta, *tmp;
24723d1b 1234
34e89507 1235 mutex_lock(&local->sta_mtx);
e46a2cf9
MSS
1236
1237 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
b8da6b6a
JB
1238 unsigned long last_active = ieee80211_sta_last_active(sta);
1239
ec2b774e
ML
1240 if (sdata != sta->sdata)
1241 continue;
1242
b8da6b6a 1243 if (time_is_before_jiffies(last_active + exp_time)) {
eea57d42
MSS
1244 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1245 sta->sta.addr);
3f52b7e3
MP
1246
1247 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1248 test_sta_flag(sta, WLAN_STA_PS_STA))
1249 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1250
34e89507 1251 WARN_ON(__sta_info_destroy(sta));
24723d1b 1252 }
e46a2cf9
MSS
1253 }
1254
34e89507 1255 mutex_unlock(&local->sta_mtx);
24723d1b 1256}
17741cdc 1257
686b9cb9 1258struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
7bedd0cf
JB
1259 const u8 *addr,
1260 const u8 *localaddr)
17741cdc 1261{
7bedd0cf 1262 struct ieee80211_local *local = hw_to_local(hw);
83e7e4ce 1263 struct rhlist_head *tmp;
7bedd0cf 1264 struct sta_info *sta;
17741cdc 1265
686b9cb9
BG
1266 /*
1267 * Just return a random station if localaddr is NULL
1268 * ... first in list.
1269 */
83e7e4ce 1270 for_each_sta_info(local, addr, sta, tmp) {
686b9cb9 1271 if (localaddr &&
b203ca39 1272 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
686b9cb9 1273 continue;
f7c65594
JB
1274 if (!sta->uploaded)
1275 return NULL;
abe60632 1276 return &sta->sta;
f7c65594
JB
1277 }
1278
abe60632 1279 return NULL;
17741cdc 1280}
686b9cb9 1281EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
5ed176e1
JB
1282
1283struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1284 const u8 *addr)
1285{
f7c65594 1286 struct sta_info *sta;
5ed176e1
JB
1287
1288 if (!vif)
1289 return NULL;
1290
f7c65594
JB
1291 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1292 if (!sta)
1293 return NULL;
1294
1295 if (!sta->uploaded)
1296 return NULL;
5ed176e1 1297
f7c65594 1298 return &sta->sta;
5ed176e1 1299}
17741cdc 1300EXPORT_SYMBOL(ieee80211_find_sta);
af818581 1301
e3685e03
JB
1302/* powersave support code */
1303void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
50a9432d 1304{
608383bf 1305 struct ieee80211_sub_if_data *sdata = sta->sdata;
e3685e03
JB
1306 struct ieee80211_local *local = sdata->local;
1307 struct sk_buff_head pending;
ba8c3d6f 1308 int filtered = 0, buffered = 0, ac, i;
e3685e03 1309 unsigned long flags;
d012a605
MP
1310 struct ps_data *ps;
1311
3918edb0
FF
1312 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1313 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1314 u.ap);
1315
1316 if (sdata->vif.type == NL80211_IFTYPE_AP)
d012a605 1317 ps = &sdata->bss->ps;
3f52b7e3
MP
1318 else if (ieee80211_vif_is_mesh(&sdata->vif))
1319 ps = &sdata->u.mesh.ps;
d012a605
MP
1320 else
1321 return;
50a9432d 1322
c2c98fde 1323 clear_sta_flag(sta, WLAN_STA_SP);
47086fc5 1324
5a306f58 1325 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
948d887d 1326 sta->driver_buffered_tids = 0;
ba8c3d6f 1327 sta->txq_buffered_tids = 0;
af818581 1328
30686bf7 1329 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
d057e5a3 1330 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
af818581 1331
adf8ed01
JB
1332 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1333 if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1334 continue;
ba8c3d6f 1335
18667600 1336 schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
ba8c3d6f
FF
1337 }
1338
948d887d 1339 skb_queue_head_init(&pending);
af818581 1340
1d147bfa
EG
1341 /* sync with ieee80211_tx_h_unicast_ps_buf */
1342 spin_lock(&sta->ps_lock);
af818581 1343 /* Send all buffered frames to the station */
948d887d
JB
1344 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1345 int count = skb_queue_len(&pending), tmp;
1346
987c285c 1347 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
948d887d 1348 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
987c285c 1349 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
948d887d
JB
1350 tmp = skb_queue_len(&pending);
1351 filtered += tmp - count;
1352 count = tmp;
1353
987c285c 1354 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
948d887d 1355 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
987c285c 1356 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
948d887d
JB
1357 tmp = skb_queue_len(&pending);
1358 buffered += tmp - count;
1359 }
1360
e3685e03 1361 ieee80211_add_pending_skbs(local, &pending);
5ac2e350
JB
1362
1363 /* now we're no longer in the deliver code */
1364 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1365
1366 /* The station might have polled and then woken up before we responded,
1367 * so clear these flags now to avoid them sticking around.
1368 */
1369 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1370 clear_sta_flag(sta, WLAN_STA_UAPSD);
1d147bfa 1371 spin_unlock(&sta->ps_lock);
948d887d 1372
e3685e03
JB
1373 atomic_dec(&ps->num_sta_ps);
1374
af818581
JB
1375 local->total_ps_buffered -= buffered;
1376
c868cb35
JB
1377 sta_info_recalc_tim(sta);
1378
bdcbd8e0 1379 ps_dbg(sdata,
2595d259 1380 "STA %pM aid %d sending %d filtered/%d PS frames since STA woke up\n",
bdcbd8e0 1381 sta->sta.addr, sta->sta.aid, filtered, buffered);
17c18bf8
JB
1382
1383 ieee80211_check_fast_xmit(sta);
af818581
JB
1384}
1385
0ead2510 1386static void ieee80211_send_null_response(struct sta_info *sta, int tid,
b77cf4f8 1387 enum ieee80211_frame_release_type reason,
0ead2510 1388 bool call_driver, bool more_data)
af818581 1389{
0ead2510 1390 struct ieee80211_sub_if_data *sdata = sta->sdata;
af818581 1391 struct ieee80211_local *local = sdata->local;
ce662b44 1392 struct ieee80211_qos_hdr *nullfunc;
af818581 1393 struct sk_buff *skb;
ce662b44
JB
1394 int size = sizeof(*nullfunc);
1395 __le16 fc;
a74a8c84 1396 bool qos = sta->sta.wme;
ce662b44 1397 struct ieee80211_tx_info *info;
55de908a 1398 struct ieee80211_chanctx_conf *chanctx_conf;
af818581 1399
ce662b44
JB
1400 if (qos) {
1401 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1402 IEEE80211_STYPE_QOS_NULLFUNC |
1403 IEEE80211_FCTL_FROMDS);
1404 } else {
1405 size -= 2;
1406 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1407 IEEE80211_STYPE_NULLFUNC |
1408 IEEE80211_FCTL_FROMDS);
af818581 1409 }
af818581 1410
ce662b44
JB
1411 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1412 if (!skb)
1413 return;
1414
1415 skb_reserve(skb, local->hw.extra_tx_headroom);
1416
4df864c1 1417 nullfunc = skb_put(skb, size);
ce662b44
JB
1418 nullfunc->frame_control = fc;
1419 nullfunc->duration_id = 0;
1420 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1421 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1422 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
864a6040 1423 nullfunc->seq_ctrl = 0;
ce662b44 1424
59b66255
JB
1425 skb->priority = tid;
1426 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
ce662b44 1427 if (qos) {
ce662b44
JB
1428 nullfunc->qos_ctrl = cpu_to_le16(tid);
1429
0ead2510 1430 if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
ce662b44
JB
1431 nullfunc->qos_ctrl |=
1432 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
0ead2510
EG
1433 if (more_data)
1434 nullfunc->frame_control |=
1435 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1436 }
ce662b44
JB
1437 }
1438
1439 info = IEEE80211_SKB_CB(skb);
1440
1441 /*
1442 * Tell TX path to send this frame even though the
1443 * STA may still remain is PS mode after this frame
deeaee19
JB
1444 * exchange. Also set EOSP to indicate this packet
1445 * ends the poll/service period.
ce662b44 1446 */
02f2f1a9 1447 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
deeaee19
JB
1448 IEEE80211_TX_STATUS_EOSP |
1449 IEEE80211_TX_CTL_REQ_TX_STATUS;
ce662b44 1450
6b127c71
SM
1451 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1452
b77cf4f8
JB
1453 if (call_driver)
1454 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1455 reason, false);
40b96408 1456
89afe614
JB
1457 skb->dev = sdata->dev;
1458
55de908a
JB
1459 rcu_read_lock();
1460 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
1461 if (WARN_ON(!chanctx_conf)) {
1462 rcu_read_unlock();
1463 kfree_skb(skb);
1464 return;
1465 }
1466
73c4e195 1467 info->band = chanctx_conf->def.chan->band;
08aca29a 1468 ieee80211_xmit(sdata, sta, skb);
55de908a 1469 rcu_read_unlock();
ce662b44
JB
1470}
1471
0a1cb809
JB
1472static int find_highest_prio_tid(unsigned long tids)
1473{
1474 /* lower 3 TIDs aren't ordered perfectly */
1475 if (tids & 0xF8)
1476 return fls(tids) - 1;
1477 /* TID 0 is BE just like TID 3 */
1478 if (tids & BIT(0))
1479 return 0;
1480 return fls(tids) - 1;
1481}
1482
0ead2510
EG
1483/* Indicates if the MORE_DATA bit should be set in the last
1484 * frame obtained by ieee80211_sta_ps_get_frames.
1485 * Note that driver_release_tids is relevant only if
1486 * reason = IEEE80211_FRAME_RELEASE_PSPOLL
1487 */
1488static bool
1489ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1490 enum ieee80211_frame_release_type reason,
1491 unsigned long driver_release_tids)
1492{
1493 int ac;
1494
1495 /* If the driver has data on more than one TID then
1496 * certainly there's more data if we release just a
1497 * single frame now (from a single TID). This will
1498 * only happen for PS-Poll.
1499 */
1500 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1501 hweight16(driver_release_tids) > 1)
1502 return true;
1503
1504 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
f438ceb8 1505 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
0ead2510
EG
1506 continue;
1507
1508 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1509 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1510 return true;
1511 }
1512
1513 return false;
1514}
1515
47086fc5 1516static void
0ead2510
EG
1517ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1518 enum ieee80211_frame_release_type reason,
1519 struct sk_buff_head *frames,
1520 unsigned long *driver_release_tids)
af818581
JB
1521{
1522 struct ieee80211_sub_if_data *sdata = sta->sdata;
1523 struct ieee80211_local *local = sdata->local;
948d887d 1524 int ac;
948d887d 1525
f9f760b4 1526 /* Get response frame(s) and more data bit for the last one. */
948d887d 1527 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
4049e09a
JB
1528 unsigned long tids;
1529
f438ceb8 1530 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
948d887d
JB
1531 continue;
1532
4049e09a
JB
1533 tids = ieee80211_tids_for_ac(ac);
1534
f9f760b4
JB
1535 /* if we already have frames from software, then we can't also
1536 * release from hardware queues
1537 */
0ead2510
EG
1538 if (skb_queue_empty(frames)) {
1539 *driver_release_tids |=
1540 sta->driver_buffered_tids & tids;
1541 *driver_release_tids |= sta->txq_buffered_tids & tids;
ba8c3d6f 1542 }
948d887d 1543
0ead2510 1544 if (!*driver_release_tids) {
f9f760b4
JB
1545 struct sk_buff *skb;
1546
1547 while (n_frames > 0) {
1548 skb = skb_dequeue(&sta->tx_filtered[ac]);
1549 if (!skb) {
1550 skb = skb_dequeue(
1551 &sta->ps_tx_buf[ac]);
1552 if (skb)
1553 local->total_ps_buffered--;
1554 }
1555 if (!skb)
1556 break;
1557 n_frames--;
0ead2510 1558 __skb_queue_tail(frames, skb);
f9f760b4 1559 }
4049e09a 1560 }
948d887d 1561
0ead2510
EG
1562 /* If we have more frames buffered on this AC, then abort the
1563 * loop since we can't send more data from other ACs before
1564 * the buffered frames from this.
f9f760b4 1565 */
948d887d 1566 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
0ead2510 1567 !skb_queue_empty(&sta->ps_tx_buf[ac]))
948d887d 1568 break;
af818581 1569 }
0ead2510
EG
1570}
1571
1572static void
1573ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1574 int n_frames, u8 ignored_acs,
1575 enum ieee80211_frame_release_type reason)
1576{
1577 struct ieee80211_sub_if_data *sdata = sta->sdata;
1578 struct ieee80211_local *local = sdata->local;
1579 unsigned long driver_release_tids = 0;
1580 struct sk_buff_head frames;
1581 bool more_data;
1582
1583 /* Service or PS-Poll period starts */
1584 set_sta_flag(sta, WLAN_STA_SP);
1585
1586 __skb_queue_head_init(&frames);
1587
1588 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1589 &frames, &driver_release_tids);
1590
1591 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1592
1a57081a 1593 if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
0ead2510
EG
1594 driver_release_tids =
1595 BIT(find_highest_prio_tid(driver_release_tids));
af818581 1596
f9f760b4 1597 if (skb_queue_empty(&frames) && !driver_release_tids) {
f438ceb8 1598 int tid, ac;
af818581
JB
1599
1600 /*
ce662b44
JB
1601 * For PS-Poll, this can only happen due to a race condition
1602 * when we set the TIM bit and the station notices it, but
1603 * before it can poll for the frame we expire it.
1604 *
1605 * For uAPSD, this is said in the standard (11.2.1.5 h):
1606 * At each unscheduled SP for a non-AP STA, the AP shall
1607 * attempt to transmit at least one MSDU or MMPDU, but no
1608 * more than the value specified in the Max SP Length field
1609 * in the QoS Capability element from delivery-enabled ACs,
1610 * that are destined for the non-AP STA.
1611 *
1612 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
af818581 1613 */
af818581 1614
ce662b44 1615 /* This will evaluate to 1, 3, 5 or 7. */
f438ceb8 1616 for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++)
d7f84244
EG
1617 if (!(ignored_acs & ieee80211_ac_to_qos_mask[ac]))
1618 break;
f438ceb8 1619 tid = 7 - 2 * ac;
af818581 1620
0ead2510 1621 ieee80211_send_null_response(sta, tid, reason, true, false);
f9f760b4 1622 } else if (!driver_release_tids) {
47086fc5
JB
1623 struct sk_buff_head pending;
1624 struct sk_buff *skb;
40b96408
JB
1625 int num = 0;
1626 u16 tids = 0;
b77cf4f8 1627 bool need_null = false;
af818581 1628
47086fc5 1629 skb_queue_head_init(&pending);
af818581 1630
47086fc5
JB
1631 while ((skb = __skb_dequeue(&frames))) {
1632 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1633 struct ieee80211_hdr *hdr = (void *) skb->data;
40b96408
JB
1634 u8 *qoshdr = NULL;
1635
1636 num++;
af818581 1637
47086fc5
JB
1638 /*
1639 * Tell TX path to send this frame even though the
1640 * STA may still remain is PS mode after this frame
1641 * exchange.
1642 */
6b127c71
SM
1643 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
1644 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
47086fc5
JB
1645
1646 /*
1647 * Use MoreData flag to indicate whether there are
1648 * more buffered frames for this STA
1649 */
24b9c373 1650 if (more_data || !skb_queue_empty(&frames))
47086fc5
JB
1651 hdr->frame_control |=
1652 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
24b9c373
JD
1653 else
1654 hdr->frame_control &=
1655 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
47086fc5 1656
40b96408
JB
1657 if (ieee80211_is_data_qos(hdr->frame_control) ||
1658 ieee80211_is_qos_nullfunc(hdr->frame_control))
1659 qoshdr = ieee80211_get_qos_ctl(hdr);
1660
b77cf4f8 1661 tids |= BIT(skb->priority);
52a3f20c 1662
b77cf4f8
JB
1663 __skb_queue_tail(&pending, skb);
1664
1665 /* end service period after last frame or add one */
1666 if (!skb_queue_empty(&frames))
1667 continue;
1668
1669 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
1670 /* for PS-Poll, there's only one frame */
52a3f20c
MP
1671 info->flags |= IEEE80211_TX_STATUS_EOSP |
1672 IEEE80211_TX_CTL_REQ_TX_STATUS;
b77cf4f8 1673 break;
52a3f20c 1674 }
deeaee19 1675
b77cf4f8
JB
1676 /* For uAPSD, things are a bit more complicated. If the
1677 * last frame has a QoS header (i.e. is a QoS-data or
1678 * QoS-nulldata frame) then just set the EOSP bit there
1679 * and be done.
1680 * If the frame doesn't have a QoS header (which means
1681 * it should be a bufferable MMPDU) then we can't set
1682 * the EOSP bit in the QoS header; add a QoS-nulldata
1683 * frame to the list to send it after the MMPDU.
1684 *
1685 * Note that this code is only in the mac80211-release
1686 * code path, we assume that the driver will not buffer
1687 * anything but QoS-data frames, or if it does, will
1688 * create the QoS-nulldata frame by itself if needed.
1689 *
1690 * Cf. 802.11-2012 10.2.1.10 (c).
1691 */
1692 if (qoshdr) {
1693 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
40b96408 1694
b77cf4f8
JB
1695 info->flags |= IEEE80211_TX_STATUS_EOSP |
1696 IEEE80211_TX_CTL_REQ_TX_STATUS;
1697 } else {
1698 /* The standard isn't completely clear on this
1699 * as it says the more-data bit should be set
1700 * if there are more BUs. The QoS-Null frame
1701 * we're about to send isn't buffered yet, we
1702 * only create it below, but let's pretend it
1703 * was buffered just in case some clients only
1704 * expect more-data=0 when eosp=1.
1705 */
1706 hdr->frame_control |=
1707 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1708 need_null = true;
1709 num++;
1710 }
1711 break;
47086fc5 1712 }
af818581 1713
40b96408
JB
1714 drv_allow_buffered_frames(local, sta, tids, num,
1715 reason, more_data);
1716
47086fc5 1717 ieee80211_add_pending_skbs(local, &pending);
af818581 1718
b77cf4f8
JB
1719 if (need_null)
1720 ieee80211_send_null_response(
0ead2510
EG
1721 sta, find_highest_prio_tid(tids),
1722 reason, false, false);
b77cf4f8 1723
c868cb35 1724 sta_info_recalc_tim(sta);
af818581 1725 } else {
ba8c3d6f
FF
1726 int tid;
1727
af818581 1728 /*
4049e09a
JB
1729 * We need to release a frame that is buffered somewhere in the
1730 * driver ... it'll have to handle that.
f9f760b4
JB
1731 * Note that the driver also has to check the number of frames
1732 * on the TIDs we're releasing from - if there are more than
1733 * n_frames it has to set the more-data bit (if we didn't ask
1734 * it to set it anyway due to other buffered frames); if there
1735 * are fewer than n_frames it has to make sure to adjust that
1736 * to allow the service period to end properly.
4049e09a
JB
1737 */
1738 drv_release_buffered_frames(local, sta, driver_release_tids,
47086fc5 1739 n_frames, reason, more_data);
4049e09a
JB
1740
1741 /*
1742 * Note that we don't recalculate the TIM bit here as it would
1743 * most likely have no effect at all unless the driver told us
f9f760b4 1744 * that the TID(s) became empty before returning here from the
4049e09a 1745 * release function.
f9f760b4 1746 * Either way, however, when the driver tells us that the TID(s)
ba8c3d6f
FF
1747 * became empty or we find that a txq became empty, we'll do the
1748 * TIM recalculation.
af818581 1749 */
ba8c3d6f
FF
1750
1751 if (!sta->sta.txq[0])
1752 return;
1753
1754 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
adf8ed01
JB
1755 if (!sta->sta.txq[tid] ||
1756 !(driver_release_tids & BIT(tid)) ||
1e1430d5 1757 txq_has_queue(sta->sta.txq[tid]))
ba8c3d6f
FF
1758 continue;
1759
1760 sta_info_recalc_tim(sta);
1761 break;
1762 }
af818581
JB
1763 }
1764}
1765
47086fc5
JB
1766void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
1767{
1768 u8 ignore_for_response = sta->sta.uapsd_queues;
1769
1770 /*
1771 * If all ACs are delivery-enabled then we should reply
1772 * from any of them, if only some are enabled we reply
1773 * only from the non-enabled ones.
1774 */
1775 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
1776 ignore_for_response = 0;
1777
1778 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
1779 IEEE80211_FRAME_RELEASE_PSPOLL);
1780}
1781
1782void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
1783{
1784 int n_frames = sta->sta.max_sp;
1785 u8 delivery_enabled = sta->sta.uapsd_queues;
1786
1787 /*
1788 * If we ever grow support for TSPEC this might happen if
1789 * the TSPEC update from hostapd comes in between a trigger
1790 * frame setting WLAN_STA_UAPSD in the RX path and this
1791 * actually getting called.
1792 */
1793 if (!delivery_enabled)
1794 return;
1795
47086fc5
JB
1796 switch (sta->sta.max_sp) {
1797 case 1:
1798 n_frames = 2;
1799 break;
1800 case 2:
1801 n_frames = 4;
1802 break;
1803 case 3:
1804 n_frames = 6;
1805 break;
1806 case 0:
1807 /* XXX: what is a good value? */
13a8098a 1808 n_frames = 128;
47086fc5
JB
1809 break;
1810 }
1811
1812 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
1813 IEEE80211_FRAME_RELEASE_UAPSD);
1814}
1815
af818581
JB
1816void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
1817 struct ieee80211_sta *pubsta, bool block)
1818{
1819 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1820
b5878a2d
JB
1821 trace_api_sta_block_awake(sta->local, pubsta, block);
1822
5ac2e350 1823 if (block) {
c2c98fde 1824 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
17c18bf8 1825 ieee80211_clear_fast_xmit(sta);
5ac2e350
JB
1826 return;
1827 }
1828
1829 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
1830 return;
1831
1832 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
1833 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
1834 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1835 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1836 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
1837 test_sta_flag(sta, WLAN_STA_UAPSD)) {
1838 /* must be asleep in this case */
1839 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
1840 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
1841 } else {
1842 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
17c18bf8 1843 ieee80211_check_fast_xmit(sta);
5ac2e350 1844 }
af818581
JB
1845}
1846EXPORT_SYMBOL(ieee80211_sta_block_awake);
dcf55fb5 1847
e943789e 1848void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
37fbd908
JB
1849{
1850 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1851 struct ieee80211_local *local = sta->local;
37fbd908
JB
1852
1853 trace_api_eosp(local, pubsta);
1854
e943789e 1855 clear_sta_flag(sta, WLAN_STA_SP);
37fbd908 1856}
e943789e 1857EXPORT_SYMBOL(ieee80211_sta_eosp);
37fbd908 1858
0ead2510
EG
1859void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
1860{
1861 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1862 enum ieee80211_frame_release_type reason;
1863 bool more_data;
1864
1865 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
1866
1867 reason = IEEE80211_FRAME_RELEASE_UAPSD;
1868 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
1869 reason, 0);
1870
1871 ieee80211_send_null_response(sta, tid, reason, false, more_data);
1872}
1873EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
1874
042ec453
JB
1875void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
1876 u8 tid, bool buffered)
dcf55fb5
FF
1877{
1878 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
1879
5a306f58 1880 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
042ec453
JB
1881 return;
1882
1b000789
JB
1883 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
1884
948d887d
JB
1885 if (buffered)
1886 set_bit(tid, &sta->driver_buffered_tids);
1887 else
1888 clear_bit(tid, &sta->driver_buffered_tids);
1889
c868cb35 1890 sta_info_recalc_tim(sta);
dcf55fb5 1891}
042ec453 1892EXPORT_SYMBOL(ieee80211_sta_set_buffered);
d9a7ddb0 1893
2433647b
THJ
1894void ieee80211_register_airtime(struct ieee80211_txq *txq,
1895 u32 tx_airtime, u32 rx_airtime)
b4809e94 1896{
2433647b
THJ
1897 struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
1898 struct ieee80211_local *local = sdata->local;
1899 u64 weight_sum, weight_sum_reciprocal;
1900 struct airtime_sched_info *air_sched;
1901 struct airtime_info *air_info;
b4809e94
THJ
1902 u32 airtime = 0;
1903
2433647b
THJ
1904 air_sched = &local->airtime[txq->ac];
1905 air_info = to_airtime_info(txq);
1906
1907 if (local->airtime_flags & AIRTIME_USE_TX)
b4809e94 1908 airtime += tx_airtime;
2433647b 1909 if (local->airtime_flags & AIRTIME_USE_RX)
b4809e94
THJ
1910 airtime += rx_airtime;
1911
2433647b
THJ
1912 /* Weights scale so the unit weight is 256 */
1913 airtime <<= 8;
1914
1915 spin_lock_bh(&air_sched->lock);
1916
1917 air_info->tx_airtime += tx_airtime;
1918 air_info->rx_airtime += rx_airtime;
1919
1920 if (air_sched->weight_sum) {
1921 weight_sum = air_sched->weight_sum;
1922 weight_sum_reciprocal = air_sched->weight_sum_reciprocal;
1923 } else {
1924 weight_sum = air_info->weight;
1925 weight_sum_reciprocal = air_info->weight_reciprocal;
1926 }
1927
1928 /* Round the calculation of global vt */
1929 air_sched->v_t += (u64)((airtime + (weight_sum >> 1)) *
1930 weight_sum_reciprocal) >> IEEE80211_RECIPROCAL_SHIFT_64;
1931 air_info->v_t += (u32)((airtime + (air_info->weight >> 1)) *
1932 air_info->weight_reciprocal) >> IEEE80211_RECIPROCAL_SHIFT_32;
1933 ieee80211_resort_txq(&local->hw, txq);
1934
1935 spin_unlock_bh(&air_sched->lock);
1936}
1937
1938void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,
1939 u32 tx_airtime, u32 rx_airtime)
1940{
1941 struct ieee80211_txq *txq = pubsta->txq[tid];
1942
1943 if (!txq)
1944 return;
1945
1946 ieee80211_register_airtime(txq, tx_airtime, rx_airtime);
b4809e94
THJ
1947}
1948EXPORT_SYMBOL(ieee80211_sta_register_airtime);
1949
3ace10f5
KY
1950void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
1951 struct sta_info *sta, u8 ac,
1952 u16 tx_airtime, bool tx_completed)
1953{
1954 int tx_pending;
1955
911bde0f
THJ
1956 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
1957 return;
1958
3ace10f5
KY
1959 if (!tx_completed) {
1960 if (sta)
1961 atomic_add(tx_airtime,
1962 &sta->airtime[ac].aql_tx_pending);
1963
1964 atomic_add(tx_airtime, &local->aql_total_pending_airtime);
1965 return;
1966 }
1967
1968 if (sta) {
1969 tx_pending = atomic_sub_return(tx_airtime,
1970 &sta->airtime[ac].aql_tx_pending);
04e35caa 1971 if (tx_pending < 0)
3ace10f5
KY
1972 atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
1973 tx_pending, 0);
1974 }
1975
1976 tx_pending = atomic_sub_return(tx_airtime,
1977 &local->aql_total_pending_airtime);
1978 if (WARN_ONCE(tx_pending < 0,
1979 "Device %s AC %d pending airtime underflow: %u, %u",
1980 wiphy_name(local->hw.wiphy), ac, tx_pending,
1981 tx_airtime))
1982 atomic_cmpxchg(&local->aql_total_pending_airtime,
1983 tx_pending, 0);
1984}
1985
83d5cc01
JB
1986int sta_info_move_state(struct sta_info *sta,
1987 enum ieee80211_sta_state new_state)
d9a7ddb0 1988{
8bf11d8d 1989 might_sleep();
d9a7ddb0
JB
1990
1991 if (sta->sta_state == new_state)
1992 return 0;
1993
f09603a2
JB
1994 /* check allowed transitions first */
1995
1996 switch (new_state) {
1997 case IEEE80211_STA_NONE:
1998 if (sta->sta_state != IEEE80211_STA_AUTH)
1999 return -EINVAL;
2000 break;
2001 case IEEE80211_STA_AUTH:
2002 if (sta->sta_state != IEEE80211_STA_NONE &&
2003 sta->sta_state != IEEE80211_STA_ASSOC)
2004 return -EINVAL;
2005 break;
2006 case IEEE80211_STA_ASSOC:
2007 if (sta->sta_state != IEEE80211_STA_AUTH &&
2008 sta->sta_state != IEEE80211_STA_AUTHORIZED)
2009 return -EINVAL;
2010 break;
2011 case IEEE80211_STA_AUTHORIZED:
2012 if (sta->sta_state != IEEE80211_STA_ASSOC)
2013 return -EINVAL;
2014 break;
2015 default:
2016 WARN(1, "invalid state %d", new_state);
2017 return -EINVAL;
2018 }
2019
bdcbd8e0
JB
2020 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
2021 sta->sta.addr, new_state);
f09603a2
JB
2022
2023 /*
2024 * notify the driver before the actual changes so it can
2025 * fail the transition
2026 */
2027 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
2028 int err = drv_sta_state(sta->local, sta->sdata, sta,
2029 sta->sta_state, new_state);
2030 if (err)
2031 return err;
2032 }
2033
2034 /* reflect the change in all state variables */
2035
d9a7ddb0
JB
2036 switch (new_state) {
2037 case IEEE80211_STA_NONE:
2038 if (sta->sta_state == IEEE80211_STA_AUTH)
2039 clear_bit(WLAN_STA_AUTH, &sta->_flags);
d9a7ddb0
JB
2040 break;
2041 case IEEE80211_STA_AUTH:
a7201a6c 2042 if (sta->sta_state == IEEE80211_STA_NONE) {
d9a7ddb0 2043 set_bit(WLAN_STA_AUTH, &sta->_flags);
a7201a6c 2044 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
d9a7ddb0 2045 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
a7201a6c 2046 ieee80211_recalc_min_chandef(sta->sdata);
52cfa1d6
AB
2047 if (!sta->sta.support_p2p_ps)
2048 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
a7201a6c 2049 }
d9a7ddb0
JB
2050 break;
2051 case IEEE80211_STA_ASSOC:
29623892 2052 if (sta->sta_state == IEEE80211_STA_AUTH) {
d9a7ddb0 2053 set_bit(WLAN_STA_ASSOC, &sta->_flags);
9cf02338 2054 sta->assoc_at = ktime_get_boottime_ns();
a7201a6c 2055 ieee80211_recalc_min_chandef(sta->sdata);
52cfa1d6
AB
2056 if (!sta->sta.support_p2p_ps)
2057 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
29623892 2058 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
72f15d53 2059 ieee80211_vif_dec_num_mcast(sta->sdata);
d9a7ddb0 2060 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
17c18bf8 2061 ieee80211_clear_fast_xmit(sta);
49ddf8e6 2062 ieee80211_clear_fast_rx(sta);
f09603a2 2063 }
d9a7ddb0
JB
2064 break;
2065 case IEEE80211_STA_AUTHORIZED:
29623892 2066 if (sta->sta_state == IEEE80211_STA_ASSOC) {
72f15d53 2067 ieee80211_vif_inc_num_mcast(sta->sdata);
d9a7ddb0 2068 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
17c18bf8 2069 ieee80211_check_fast_xmit(sta);
49ddf8e6 2070 ieee80211_check_fast_rx(sta);
f09603a2 2071 }
3e493173
JM
2072 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
2073 sta->sdata->vif.type == NL80211_IFTYPE_AP)
2074 cfg80211_send_layer2_update(sta->sdata->dev,
2075 sta->sta.addr);
d9a7ddb0
JB
2076 break;
2077 default:
f09603a2 2078 break;
d9a7ddb0
JB
2079 }
2080
d9a7ddb0
JB
2081 sta->sta_state = new_state;
2082
2083 return 0;
2084}
687da132
EG
2085
2086u8 sta_info_tx_streams(struct sta_info *sta)
2087{
2088 struct ieee80211_sta_ht_cap *ht_cap = &sta->sta.ht_cap;
2089 u8 rx_streams;
2090
2091 if (!sta->sta.ht_cap.ht_supported)
2092 return 1;
2093
2094 if (sta->sta.vht_cap.vht_supported) {
2095 int i;
2096 u16 tx_mcs_map =
2097 le16_to_cpu(sta->sta.vht_cap.vht_mcs.tx_mcs_map);
2098
2099 for (i = 7; i >= 0; i--)
2100 if ((tx_mcs_map & (0x3 << (i * 2))) !=
2101 IEEE80211_VHT_MCS_NOT_SUPPORTED)
2102 return i + 1;
2103 }
2104
2105 if (ht_cap->mcs.rx_mask[3])
2106 rx_streams = 4;
2107 else if (ht_cap->mcs.rx_mask[2])
2108 rx_streams = 3;
2109 else if (ht_cap->mcs.rx_mask[1])
2110 rx_streams = 2;
2111 else
2112 rx_streams = 1;
2113
2114 if (!(ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_RX_DIFF))
2115 return rx_streams;
2116
2117 return ((ht_cap->mcs.tx_params & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
2118 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
2119}
b7ffbd7e 2120
c9c5962b
JB
2121static struct ieee80211_sta_rx_stats *
2122sta_get_last_rx_stats(struct sta_info *sta)
2123{
2124 struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
c9c5962b
JB
2125 int cpu;
2126
d656a4c6 2127 if (!sta->pcpu_rx_stats)
c9c5962b
JB
2128 return stats;
2129
2130 for_each_possible_cpu(cpu) {
2131 struct ieee80211_sta_rx_stats *cpustats;
2132
2133 cpustats = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2134
2135 if (time_after(cpustats->last_rx, stats->last_rx))
2136 stats = cpustats;
2137 }
2138
2139 return stats;
2140}
2141
41cbb0f5 2142static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate,
4f6b1b3d 2143 struct rate_info *rinfo)
fbd6ff5c 2144{
dcba665b 2145 rinfo->bw = STA_STATS_GET(BW, rate);
4f6b1b3d 2146
dcba665b 2147 switch (STA_STATS_GET(TYPE, rate)) {
7f406cd1 2148 case STA_STATS_RATE_TYPE_VHT:
4f6b1b3d 2149 rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
dcba665b
JB
2150 rinfo->mcs = STA_STATS_GET(VHT_MCS, rate);
2151 rinfo->nss = STA_STATS_GET(VHT_NSS, rate);
2152 if (STA_STATS_GET(SGI, rate))
2153 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
7f406cd1
JB
2154 break;
2155 case STA_STATS_RATE_TYPE_HT:
4f6b1b3d 2156 rinfo->flags = RATE_INFO_FLAGS_MCS;
dcba665b
JB
2157 rinfo->mcs = STA_STATS_GET(HT_MCS, rate);
2158 if (STA_STATS_GET(SGI, rate))
2159 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
7f406cd1
JB
2160 break;
2161 case STA_STATS_RATE_TYPE_LEGACY: {
fbd6ff5c 2162 struct ieee80211_supported_band *sband;
fbd6ff5c 2163 u16 brate;
4f6b1b3d 2164 unsigned int shift;
dcba665b
JB
2165 int band = STA_STATS_GET(LEGACY_BAND, rate);
2166 int rate_idx = STA_STATS_GET(LEGACY_IDX, rate);
4f6b1b3d 2167
dcba665b 2168 sband = local->hw.wiphy->bands[band];
8b783d10
TP
2169
2170 if (WARN_ON_ONCE(!sband->bitrates))
2171 break;
2172
dcba665b 2173 brate = sband->bitrates[rate_idx].bitrate;
4f6b1b3d
JB
2174 if (rinfo->bw == RATE_INFO_BW_5)
2175 shift = 2;
2176 else if (rinfo->bw == RATE_INFO_BW_10)
2177 shift = 1;
2178 else
2179 shift = 0;
fbd6ff5c 2180 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
7f406cd1
JB
2181 break;
2182 }
41cbb0f5
LC
2183 case STA_STATS_RATE_TYPE_HE:
2184 rinfo->flags = RATE_INFO_FLAGS_HE_MCS;
2185 rinfo->mcs = STA_STATS_GET(HE_MCS, rate);
2186 rinfo->nss = STA_STATS_GET(HE_NSS, rate);
2187 rinfo->he_gi = STA_STATS_GET(HE_GI, rate);
2188 rinfo->he_ru_alloc = STA_STATS_GET(HE_RU, rate);
2189 rinfo->he_dcm = STA_STATS_GET(HE_DCM, rate);
2190 break;
fbd6ff5c 2191 }
4f6b1b3d
JB
2192}
2193
a17d93ff 2194static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
4f6b1b3d 2195{
6aa7de05 2196 u16 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
fbd6ff5c 2197
4f6b1b3d 2198 if (rate == STA_STATS_RATE_INVALID)
a17d93ff
BG
2199 return -EINVAL;
2200
2201 sta_stats_decode_rate(sta->local, rate, rinfo);
2202 return 0;
fbd6ff5c
JB
2203}
2204
b255b72b
SM
2205static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
2206 int tid)
2207{
2208 unsigned int start;
2209 u64 value;
2210
2211 do {
2212 start = u64_stats_fetch_begin(&rxstats->syncp);
2213 value = rxstats->msdu[tid];
2214 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2215
2216 return value;
2217}
2218
0f9c5a61
JB
2219static void sta_set_tidstats(struct sta_info *sta,
2220 struct cfg80211_tid_stats *tidstats,
2221 int tid)
2222{
2223 struct ieee80211_local *local = sta->local;
b255b72b 2224 int cpu;
0f9c5a61
JB
2225
2226 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
d656a4c6 2227 tidstats->rx_msdu += sta_get_tidstats_msdu(&sta->rx_stats, tid);
0f9c5a61 2228
b255b72b
SM
2229 if (sta->pcpu_rx_stats) {
2230 for_each_possible_cpu(cpu) {
2231 struct ieee80211_sta_rx_stats *cpurxs;
2232
2233 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2234 tidstats->rx_msdu +=
2235 sta_get_tidstats_msdu(cpurxs, tid);
2236 }
2237 }
0f9c5a61
JB
2238
2239 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
2240 }
2241
2242 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2243 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
2244 tidstats->tx_msdu = sta->tx_stats.msdu[tid];
2245 }
2246
2247 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
2248 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2249 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
2250 tidstats->tx_msdu_retries = sta->status_stats.msdu_retries[tid];
2251 }
2252
2253 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
2254 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2255 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
2256 tidstats->tx_msdu_failed = sta->status_stats.msdu_failed[tid];
2257 }
2fe4a29a
THJ
2258
2259 if (local->ops->wake_tx_queue && tid < IEEE80211_NUM_TIDS) {
2260 spin_lock_bh(&local->fq.lock);
2261 rcu_read_lock();
2262
2263 tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS);
2264 ieee80211_fill_txq_stats(&tidstats->txq_stats,
2265 to_txq_info(sta->sta.txq[tid]));
2266
2267 rcu_read_unlock();
2268 spin_unlock_bh(&local->fq.lock);
2269 }
0f9c5a61
JB
2270}
2271
c9c5962b
JB
2272static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
2273{
2274 unsigned int start;
2275 u64 value;
2276
2277 do {
2278 start = u64_stats_fetch_begin(&rxstats->syncp);
2279 value = rxstats->bytes;
2280 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2281
2282 return value;
2283}
2284
0fdf1493
JB
2285void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
2286 bool tidstats)
b7ffbd7e
JB
2287{
2288 struct ieee80211_sub_if_data *sdata = sta->sdata;
2289 struct ieee80211_local *local = sdata->local;
b7ffbd7e 2290 u32 thr = 0;
c9c5962b
JB
2291 int i, ac, cpu;
2292 struct ieee80211_sta_rx_stats *last_rxstats;
2293
2294 last_rxstats = sta_get_last_rx_stats(sta);
b7ffbd7e
JB
2295
2296 sinfo->generation = sdata->local->sta_generation;
2297
225b8189
JB
2298 /* do before driver, so beacon filtering drivers have a
2299 * chance to e.g. just add the number of filtered beacons
2300 * (or just modify the value entirely, of course)
2301 */
2302 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2303 sinfo->rx_beacon = sdata->u.mgd.count_beacon_signal;
2304
2b9a7e1b 2305 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
a4217750
OE
2306 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
2307 BIT_ULL(NL80211_STA_INFO_STA_FLAGS) |
2308 BIT_ULL(NL80211_STA_INFO_BSS_PARAM) |
2309 BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) |
9cf02338 2310 BIT_ULL(NL80211_STA_INFO_ASSOC_AT_BOOTTIME) |
a4217750 2311 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC);
976bd9ef
JB
2312
2313 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2314 sinfo->beacon_loss_count = sdata->u.mgd.beacon_loss_count;
a4217750 2315 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_LOSS);
976bd9ef 2316 }
b7ffbd7e 2317
84b00607 2318 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
9cf02338 2319 sinfo->assoc_at = sta->assoc_at;
e5a9f8d0 2320 sinfo->inactive_time =
b8da6b6a 2321 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
2b9a7e1b 2322
a4217750
OE
2323 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) |
2324 BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) {
2b9a7e1b
JB
2325 sinfo->tx_bytes = 0;
2326 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
e5a9f8d0 2327 sinfo->tx_bytes += sta->tx_stats.bytes[ac];
a4217750 2328 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
2b9a7e1b
JB
2329 }
2330
a4217750 2331 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_PACKETS))) {
2b9a7e1b
JB
2332 sinfo->tx_packets = 0;
2333 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
e5a9f8d0 2334 sinfo->tx_packets += sta->tx_stats.packets[ac];
a4217750 2335 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
2b9a7e1b
JB
2336 }
2337
a4217750
OE
2338 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES64) |
2339 BIT_ULL(NL80211_STA_INFO_RX_BYTES)))) {
d656a4c6 2340 sinfo->rx_bytes += sta_get_stats_bytes(&sta->rx_stats);
c9c5962b
JB
2341
2342 if (sta->pcpu_rx_stats) {
2343 for_each_possible_cpu(cpu) {
2344 struct ieee80211_sta_rx_stats *cpurxs;
2345
2346 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2347 sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
2348 }
2349 }
0f9c5a61 2350
a4217750 2351 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
2b9a7e1b
JB
2352 }
2353
a4217750 2354 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_PACKETS))) {
e5a9f8d0 2355 sinfo->rx_packets = sta->rx_stats.packets;
c9c5962b
JB
2356 if (sta->pcpu_rx_stats) {
2357 for_each_possible_cpu(cpu) {
2358 struct ieee80211_sta_rx_stats *cpurxs;
2359
2360 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
2361 sinfo->rx_packets += cpurxs->packets;
2362 }
2363 }
a4217750 2364 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
2b9a7e1b
JB
2365 }
2366
a4217750 2367 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_RETRIES))) {
e5a9f8d0 2368 sinfo->tx_retries = sta->status_stats.retry_count;
a4217750 2369 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
2b9a7e1b
JB
2370 }
2371
a4217750 2372 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
e5a9f8d0 2373 sinfo->tx_failed = sta->status_stats.retry_failed;
a4217750 2374 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
b7ffbd7e 2375 }
2b9a7e1b 2376
b4809e94
THJ
2377 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
2378 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2379 sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2380 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
2381 }
2382
2383 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
2384 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2385 sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2386 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
2387 }
2388
2389 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
2433647b 2390 sinfo->airtime_weight = sta->airtime[0].weight;
b4809e94
THJ
2391 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
2392 }
2393
e5a9f8d0 2394 sinfo->rx_dropped_misc = sta->rx_stats.dropped;
c9c5962b
JB
2395 if (sta->pcpu_rx_stats) {
2396 for_each_possible_cpu(cpu) {
2397 struct ieee80211_sta_rx_stats *cpurxs;
2398
2399 cpurxs = per_cpu_ptr(sta->pcpu_rx_stats, cpu);
e165bc02 2400 sinfo->rx_dropped_misc += cpurxs->dropped;
c9c5962b
JB
2401 }
2402 }
b7ffbd7e 2403
225b8189
JB
2404 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2405 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
a4217750
OE
2406 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX) |
2407 BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
225b8189
JB
2408 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
2409 }
2410
30686bf7
JB
2411 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2412 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
a4217750 2413 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL))) {
c9c5962b 2414 sinfo->signal = (s8)last_rxstats->last_signal;
a4217750 2415 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
2b9a7e1b
JB
2416 }
2417
c9c5962b 2418 if (!sta->pcpu_rx_stats &&
a4217750 2419 !(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))) {
40d9a38a 2420 sinfo->signal_avg =
0be6ed13 2421 -ewma_signal_read(&sta->rx_stats_avg.signal);
a4217750 2422 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
2b9a7e1b 2423 }
b7ffbd7e 2424 }
2b9a7e1b 2425
c9c5962b
JB
2426 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
2427 * the sta->rx_stats struct, so the check here is fine with and without
2428 * pcpu statistics
2429 */
2430 if (last_rxstats->chains &&
a4217750
OE
2431 !(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL) |
2432 BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
2433 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
c9c5962b 2434 if (!sta->pcpu_rx_stats)
a4217750 2435 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
c9c5962b
JB
2436
2437 sinfo->chains = last_rxstats->chains;
b7ffbd7e 2438
b7ffbd7e 2439 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
e5a9f8d0 2440 sinfo->chain_signal[i] =
c9c5962b 2441 last_rxstats->chain_signal_last[i];
b7ffbd7e 2442 sinfo->chain_signal_avg[i] =
0be6ed13 2443 -ewma_signal_read(&sta->rx_stats_avg.chain_signal[i]);
b7ffbd7e
JB
2444 }
2445 }
2446
a4217750 2447 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE))) {
e5a9f8d0
JB
2448 sta_set_rate_info_tx(sta, &sta->tx_stats.last_rate,
2449 &sinfo->txrate);
a4217750 2450 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
2b9a7e1b
JB
2451 }
2452
a4217750 2453 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE))) {
a17d93ff 2454 if (sta_set_rate_info_rx(sta, &sinfo->rxrate) == 0)
a4217750 2455 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
2b9a7e1b 2456 }
b7ffbd7e 2457
0fdf1493 2458 if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) {
6af8354f
JB
2459 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
2460 sta_set_tidstats(sta, &sinfo->pertid[i], i);
79c892b8
JB
2461 }
2462
b7ffbd7e
JB
2463 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2464#ifdef CONFIG_MAC80211_MESH
a4217750
OE
2465 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_LLID) |
2466 BIT_ULL(NL80211_STA_INFO_PLID) |
2467 BIT_ULL(NL80211_STA_INFO_PLINK_STATE) |
2468 BIT_ULL(NL80211_STA_INFO_LOCAL_PM) |
2469 BIT_ULL(NL80211_STA_INFO_PEER_PM) |
dbdaee7a 2470 BIT_ULL(NL80211_STA_INFO_NONPEER_PM) |
1303a51c
MT
2471 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_GATE) |
2472 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_AS);
b7ffbd7e 2473
433f5bc1
JB
2474 sinfo->llid = sta->mesh->llid;
2475 sinfo->plid = sta->mesh->plid;
2476 sinfo->plink_state = sta->mesh->plink_state;
b7ffbd7e 2477 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
a4217750 2478 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_T_OFFSET);
433f5bc1 2479 sinfo->t_offset = sta->mesh->t_offset;
b7ffbd7e 2480 }
433f5bc1
JB
2481 sinfo->local_pm = sta->mesh->local_pm;
2482 sinfo->peer_pm = sta->mesh->peer_pm;
2483 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
dbdaee7a 2484 sinfo->connected_to_gate = sta->mesh->connected_to_gate;
1303a51c 2485 sinfo->connected_to_as = sta->mesh->connected_to_as;
b7ffbd7e
JB
2486#endif
2487 }
2488
2489 sinfo->bss_param.flags = 0;
2490 if (sdata->vif.bss_conf.use_cts_prot)
2491 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2492 if (sdata->vif.bss_conf.use_short_preamble)
2493 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2494 if (sdata->vif.bss_conf.use_short_slot)
2495 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
785e21a8 2496 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
b7ffbd7e
JB
2497 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
2498
2499 sinfo->sta_flags.set = 0;
2500 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2501 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2502 BIT(NL80211_STA_FLAG_WME) |
2503 BIT(NL80211_STA_FLAG_MFP) |
2504 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2505 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2506 BIT(NL80211_STA_FLAG_TDLS_PEER);
2507 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2508 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2509 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2510 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
a74a8c84 2511 if (sta->sta.wme)
b7ffbd7e
JB
2512 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
2513 if (test_sta_flag(sta, WLAN_STA_MFP))
2514 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
2515 if (test_sta_flag(sta, WLAN_STA_AUTH))
2516 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2517 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2518 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2519 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2520 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2521
3b17fbf8
MA
2522 thr = sta_get_expected_throughput(sta);
2523
2524 if (thr != 0) {
a4217750 2525 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
3b17fbf8
MA
2526 sinfo->expected_throughput = thr;
2527 }
a78b26ff
VN
2528
2529 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL)) &&
2530 sta->status_stats.ack_signal_filled) {
2531 sinfo->ack_signal = sta->status_stats.last_ack_signal;
2532 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
2533 }
cc60dbbf 2534
9c06602b
BP
2535 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
2536 sta->status_stats.ack_signal_filled) {
cc60dbbf
BP
2537 sinfo->avg_ack_signal =
2538 -(s8)ewma_avg_signal_read(
2539 &sta->status_stats.avg_ack_signal);
2540 sinfo->filled |=
9c06602b 2541 BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
cc60dbbf 2542 }
ab60633c
NM
2543
2544 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2545 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2546 sinfo->airtime_link_metric =
2547 airtime_link_metric_get(local, sta);
2548 }
3b17fbf8
MA
2549}
2550
2551u32 sta_get_expected_throughput(struct sta_info *sta)
2552{
2553 struct ieee80211_sub_if_data *sdata = sta->sdata;
2554 struct ieee80211_local *local = sdata->local;
2555 struct rate_control_ref *ref = NULL;
2556 u32 thr = 0;
2557
2558 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2559 ref = local->rate_ctrl;
2560
b7ffbd7e
JB
2561 /* check if the driver has a SW RC implementation */
2562 if (ref && ref->ops->get_expected_throughput)
2563 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2564 else
4fdbc67a 2565 thr = drv_get_expected_throughput(local, sta);
b7ffbd7e 2566
3b17fbf8 2567 return thr;
b7ffbd7e 2568}
b8da6b6a
JB
2569
2570unsigned long ieee80211_sta_last_active(struct sta_info *sta)
2571{
c9c5962b
JB
2572 struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
2573
285531f9
AZ
2574 if (!sta->status_stats.last_ack ||
2575 time_after(stats->last_rx, sta->status_stats.last_ack))
c9c5962b 2576 return stats->last_rx;
b8da6b6a
JB
2577 return sta->status_stats.last_ack;
2578}
484a54c2
THJ
2579
2580static void sta_update_codel_params(struct sta_info *sta, u32 thr)
2581{
2582 if (!sta->sdata->local->ops->wake_tx_queue)
2583 return;
2584
2585 if (thr && thr < STA_SLOW_THRESHOLD * sta->local->num_sta) {
2586 sta->cparams.target = MS2TIME(50);
2587 sta->cparams.interval = MS2TIME(300);
2588 sta->cparams.ecn = false;
2589 } else {
2590 sta->cparams.target = MS2TIME(20);
2591 sta->cparams.interval = MS2TIME(100);
2592 sta->cparams.ecn = true;
2593 }
2594}
2595
2596void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta,
2597 u32 thr)
2598{
2599 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2600
2601 sta_update_codel_params(sta, thr);
2602}