1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2013-2014 Intel Mobile Communications GmbH
6 * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
7 * Copyright (C) 2018-2023 Intel Corporation
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/etherdevice.h>
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>
18 #include <linux/timer.h>
19 #include <linux/rtnetlink.h>
21 #include <net/codel.h>
22 #include <net/mac80211.h>
23 #include "ieee80211_i.h"
24 #include "driver-ops.h"
27 #include "debugfs_sta.h"
32 * DOC: STA information lifetime rules
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.
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
47 * When the insertion fails (sta_info_insert()) returns non-zero), the
48 * structure will have been freed by sta_info_insert()!
50 * Station entries are added by mac80211 when you establish a link with a
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
53 * receive an association response from the AP. For IBSS this occurs when
54 * get to know about a peer on the same IBSS. For WDS we add the sta for
55 * the peer immediately upon device open. When using AP mode we add stations
56 * for each respective station upon request from userspace through nl80211.
58 * In order to remove a STA info structure, various sta_info_destroy_*()
59 * calls are available.
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.
67 struct sta_link_alloc {
68 struct link_sta_info info;
69 struct ieee80211_link_sta sta;
70 struct rcu_head rcu_head;
73 static const struct rhashtable_params sta_rht_params = {
74 .nelem_hint = 3, /* start small */
75 .automatic_shrinking = true,
76 .head_offset = offsetof(struct sta_info, hash_node),
77 .key_offset = offsetof(struct sta_info, addr),
79 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
82 static const struct rhashtable_params link_sta_rht_params = {
83 .nelem_hint = 3, /* start small */
84 .automatic_shrinking = true,
85 .head_offset = offsetof(struct link_sta_info, link_hash_node),
86 .key_offset = offsetof(struct link_sta_info, addr),
88 .max_size = CONFIG_MAC80211_STA_HASH_MAX_SIZE,
91 /* Caller must hold local->sta_mtx */
92 static int sta_info_hash_del(struct ieee80211_local *local,
95 return rhltable_remove(&local->sta_hash, &sta->hash_node,
99 static int link_sta_info_hash_add(struct ieee80211_local *local,
100 struct link_sta_info *link_sta)
102 lockdep_assert_held(&local->sta_mtx);
103 return rhltable_insert(&local->link_sta_hash,
104 &link_sta->link_hash_node,
105 link_sta_rht_params);
108 static int link_sta_info_hash_del(struct ieee80211_local *local,
109 struct link_sta_info *link_sta)
111 lockdep_assert_held(&local->sta_mtx);
112 return rhltable_remove(&local->link_sta_hash,
113 &link_sta->link_hash_node,
114 link_sta_rht_params);
117 static void __cleanup_single_sta(struct sta_info *sta)
120 struct tid_ampdu_tx *tid_tx;
121 struct ieee80211_sub_if_data *sdata = sta->sdata;
122 struct ieee80211_local *local = sdata->local;
125 if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
126 test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
127 test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
128 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
129 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
130 ps = &sdata->bss->ps;
131 else if (ieee80211_vif_is_mesh(&sdata->vif))
132 ps = &sdata->u.mesh.ps;
136 clear_sta_flag(sta, WLAN_STA_PS_STA);
137 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
138 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
140 atomic_dec(&ps->num_sta_ps);
143 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
144 struct txq_info *txqi;
146 if (!sta->sta.txq[i])
149 txqi = to_txq_info(sta->sta.txq[i]);
151 ieee80211_txq_purge(local, txqi);
154 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
155 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
156 ieee80211_purge_tx_queue(&local->hw, &sta->ps_tx_buf[ac]);
157 ieee80211_purge_tx_queue(&local->hw, &sta->tx_filtered[ac]);
160 if (ieee80211_vif_is_mesh(&sdata->vif))
161 mesh_sta_cleanup(sta);
163 cancel_work_sync(&sta->drv_deliver_wk);
166 * Destroy aggregation state here. It would be nice to wait for the
167 * driver to finish aggregation stop and then clean up, but for now
168 * drivers have to handle aggregation stop being requested, followed
169 * directly by station destruction.
171 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
172 kfree(sta->ampdu_mlme.tid_start_tx[i]);
173 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
176 ieee80211_purge_tx_queue(&local->hw, &tid_tx->pending);
181 static void cleanup_single_sta(struct sta_info *sta)
183 struct ieee80211_sub_if_data *sdata = sta->sdata;
184 struct ieee80211_local *local = sdata->local;
186 __cleanup_single_sta(sta);
187 sta_info_free(local, sta);
190 struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
193 return rhltable_lookup(&local->sta_hash, addr, sta_rht_params);
196 /* protected by RCU */
197 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
200 struct ieee80211_local *local = sdata->local;
201 struct rhlist_head *tmp;
202 struct sta_info *sta;
205 for_each_sta_info(local, addr, sta, tmp) {
206 if (sta->sdata == sdata) {
208 /* this is safe as the caller must already hold
209 * another rcu read section or the mutex
219 * Get sta info either from the specified interface
220 * or from one of its vlans
222 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
225 struct ieee80211_local *local = sdata->local;
226 struct rhlist_head *tmp;
227 struct sta_info *sta;
230 for_each_sta_info(local, addr, sta, tmp) {
231 if (sta->sdata == sdata ||
232 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
234 /* this is safe as the caller must already hold
235 * another rcu read section or the mutex
244 struct rhlist_head *link_sta_info_hash_lookup(struct ieee80211_local *local,
247 return rhltable_lookup(&local->link_sta_hash, addr,
248 link_sta_rht_params);
251 struct link_sta_info *
252 link_sta_info_get_bss(struct ieee80211_sub_if_data *sdata, const u8 *addr)
254 struct ieee80211_local *local = sdata->local;
255 struct rhlist_head *tmp;
256 struct link_sta_info *link_sta;
259 for_each_link_sta_info(local, addr, link_sta, tmp) {
260 struct sta_info *sta = link_sta->sta;
262 if (sta->sdata == sdata ||
263 (sta->sdata->bss && sta->sdata->bss == sdata->bss)) {
265 /* this is safe as the caller must already hold
266 * another rcu read section or the mutex
275 struct ieee80211_sta *
276 ieee80211_find_sta_by_link_addrs(struct ieee80211_hw *hw,
279 unsigned int *link_id)
281 struct ieee80211_local *local = hw_to_local(hw);
282 struct link_sta_info *link_sta;
283 struct rhlist_head *tmp;
285 for_each_link_sta_info(local, addr, link_sta, tmp) {
286 struct sta_info *sta = link_sta->sta;
287 struct ieee80211_link_data *link;
288 u8 _link_id = link_sta->link_id;
296 link = rcu_dereference(sta->sdata->link[_link_id]);
300 if (memcmp(link->conf->addr, localaddr, ETH_ALEN))
310 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_link_addrs);
312 struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
313 const u8 *sta_addr, const u8 *vif_addr)
315 struct rhlist_head *tmp;
316 struct sta_info *sta;
318 for_each_sta_info(local, sta_addr, sta, tmp) {
319 if (ether_addr_equal(vif_addr, sta->sdata->vif.addr))
326 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
329 struct ieee80211_local *local = sdata->local;
330 struct sta_info *sta;
333 list_for_each_entry_rcu(sta, &local->sta_list, list,
334 lockdep_is_held(&local->sta_mtx)) {
335 if (sdata != sta->sdata)
347 static void sta_info_free_link(struct link_sta_info *link_sta)
349 free_percpu(link_sta->pcpu_rx_stats);
352 static void sta_remove_link(struct sta_info *sta, unsigned int link_id,
355 struct sta_link_alloc *alloc = NULL;
356 struct link_sta_info *link_sta;
358 link_sta = rcu_access_pointer(sta->link[link_id]);
359 if (link_sta != &sta->deflink)
360 lockdep_assert_held(&sta->local->sta_mtx);
362 if (WARN_ON(!link_sta))
366 link_sta_info_hash_del(sta->local, link_sta);
368 if (test_sta_flag(sta, WLAN_STA_INSERTED))
369 ieee80211_link_sta_debugfs_remove(link_sta);
371 if (link_sta != &sta->deflink)
372 alloc = container_of(link_sta, typeof(*alloc), info);
374 sta->sta.valid_links &= ~BIT(link_id);
375 RCU_INIT_POINTER(sta->link[link_id], NULL);
376 RCU_INIT_POINTER(sta->sta.link[link_id], NULL);
378 sta_info_free_link(&alloc->info);
379 kfree_rcu(alloc, rcu_head);
382 ieee80211_sta_recalc_aggregates(&sta->sta);
386 * sta_info_free - free STA
388 * @local: pointer to the global information
389 * @sta: STA info to free
391 * This function must undo everything done by sta_info_alloc()
392 * that may happen before sta_info_insert(). It may only be
393 * called when sta_info_insert() has not been attempted (and
394 * if that fails, the station is freed anyway.)
396 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
400 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
401 if (!(sta->sta.valid_links & BIT(i)))
404 sta_remove_link(sta, i, false);
408 * If we had used sta_info_pre_move_state() then we might not
409 * have gone through the state transitions down again, so do
410 * it here now (and warn if it's inserted).
412 * This will clear state such as fast TX/RX that may have been
413 * allocated during state transitions.
415 while (sta->sta_state > IEEE80211_STA_NONE) {
418 WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
420 ret = sta_info_move_state(sta, sta->sta_state - 1);
421 if (WARN_ONCE(ret, "sta_info_move_state() returned %d\n", ret))
426 rate_control_free_sta(sta);
428 sta_dbg(sta->sdata, "Destroyed STA %pM\n", sta->sta.addr);
430 kfree(to_txq_info(sta->sta.txq[0]));
431 kfree(rcu_dereference_raw(sta->sta.rates));
432 #ifdef CONFIG_MAC80211_MESH
436 sta_info_free_link(&sta->deflink);
440 /* Caller must hold local->sta_mtx */
441 static int sta_info_hash_add(struct ieee80211_local *local,
442 struct sta_info *sta)
444 return rhltable_insert(&local->sta_hash, &sta->hash_node,
448 static void sta_deliver_ps_frames(struct work_struct *wk)
450 struct sta_info *sta;
452 sta = container_of(wk, struct sta_info, drv_deliver_wk);
458 if (!test_sta_flag(sta, WLAN_STA_PS_STA))
459 ieee80211_sta_ps_deliver_wakeup(sta);
460 else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL))
461 ieee80211_sta_ps_deliver_poll_response(sta);
462 else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD))
463 ieee80211_sta_ps_deliver_uapsd(sta);
467 static int sta_prepare_rate_control(struct ieee80211_local *local,
468 struct sta_info *sta, gfp_t gfp)
470 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
473 sta->rate_ctrl = local->rate_ctrl;
474 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
476 if (!sta->rate_ctrl_priv)
482 static int sta_info_alloc_link(struct ieee80211_local *local,
483 struct link_sta_info *link_info,
486 struct ieee80211_hw *hw = &local->hw;
489 if (ieee80211_hw_check(hw, USES_RSS)) {
490 link_info->pcpu_rx_stats =
491 alloc_percpu_gfp(struct ieee80211_sta_rx_stats, gfp);
492 if (!link_info->pcpu_rx_stats)
496 link_info->rx_stats.last_rx = jiffies;
497 u64_stats_init(&link_info->rx_stats.syncp);
499 ewma_signal_init(&link_info->rx_stats_avg.signal);
500 ewma_avg_signal_init(&link_info->status_stats.avg_ack_signal);
501 for (i = 0; i < ARRAY_SIZE(link_info->rx_stats_avg.chain_signal); i++)
502 ewma_signal_init(&link_info->rx_stats_avg.chain_signal[i]);
507 static void sta_info_add_link(struct sta_info *sta,
508 unsigned int link_id,
509 struct link_sta_info *link_info,
510 struct ieee80211_link_sta *link_sta)
512 link_info->sta = sta;
513 link_info->link_id = link_id;
514 link_info->pub = link_sta;
515 link_info->pub->sta = &sta->sta;
516 link_sta->link_id = link_id;
517 rcu_assign_pointer(sta->link[link_id], link_info);
518 rcu_assign_pointer(sta->sta.link[link_id], link_sta);
520 link_sta->smps_mode = IEEE80211_SMPS_OFF;
521 link_sta->agg.max_rc_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_BA;
524 static struct sta_info *
525 __sta_info_alloc(struct ieee80211_sub_if_data *sdata,
526 const u8 *addr, int link_id, const u8 *link_addr,
529 struct ieee80211_local *local = sdata->local;
530 struct ieee80211_hw *hw = &local->hw;
531 struct sta_info *sta;
536 sta = kzalloc(sizeof(*sta) + hw->sta_data_size, gfp);
543 if (sta_info_alloc_link(local, &sta->deflink, gfp))
547 sta_info_add_link(sta, link_id, &sta->deflink,
549 sta->sta.valid_links = BIT(link_id);
551 sta_info_add_link(sta, 0, &sta->deflink, &sta->sta.deflink);
554 sta->sta.cur = &sta->sta.deflink.agg;
556 spin_lock_init(&sta->lock);
557 spin_lock_init(&sta->ps_lock);
558 INIT_WORK(&sta->drv_deliver_wk, sta_deliver_ps_frames);
559 INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
560 mutex_init(&sta->ampdu_mlme.mtx);
561 #ifdef CONFIG_MAC80211_MESH
562 if (ieee80211_vif_is_mesh(&sdata->vif)) {
563 sta->mesh = kzalloc(sizeof(*sta->mesh), gfp);
566 sta->mesh->plink_sta = sta;
567 spin_lock_init(&sta->mesh->plink_lock);
568 if (!sdata->u.mesh.user_mpm)
569 timer_setup(&sta->mesh->plink_timer, mesh_plink_timer,
571 sta->mesh->nonpeer_pm = NL80211_MESH_POWER_ACTIVE;
575 memcpy(sta->addr, addr, ETH_ALEN);
576 memcpy(sta->sta.addr, addr, ETH_ALEN);
577 memcpy(sta->deflink.addr, link_addr, ETH_ALEN);
578 memcpy(sta->sta.deflink.addr, link_addr, ETH_ALEN);
579 sta->sta.max_rx_aggregation_subframes =
580 local->hw.max_rx_aggregation_subframes;
582 /* TODO link specific alloc and assignments for MLO Link STA */
584 /* Extended Key ID needs to install keys for keyid 0 and 1 Rx-only.
585 * The Tx path starts to use a key as soon as the key slot ptk_idx
586 * references to is not NULL. To not use the initial Rx-only key
587 * prematurely for Tx initialize ptk_idx to an impossible PTK keyid
588 * which always will refer to a NULL key.
590 BUILD_BUG_ON(ARRAY_SIZE(sta->ptk) <= INVALID_PTK_KEYIDX);
591 sta->ptk_idx = INVALID_PTK_KEYIDX;
594 ieee80211_init_frag_cache(&sta->frags);
596 sta->sta_state = IEEE80211_STA_NONE;
598 if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
599 sta->amsdu_mesh_control = -1;
601 /* Mark TID as unreserved */
602 sta->reserved_tid = IEEE80211_TID_UNRESERVED;
604 sta->last_connected = ktime_get_seconds();
606 size = sizeof(struct txq_info) +
607 ALIGN(hw->txq_data_size, sizeof(void *));
609 txq_data = kcalloc(ARRAY_SIZE(sta->sta.txq), size, gfp);
613 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
614 struct txq_info *txq = txq_data + i * size;
616 /* might not do anything for the (bufferable) MMPDU TXQ */
617 ieee80211_txq_init(sdata, sta, txq, i);
620 if (sta_prepare_rate_control(local, sta, gfp))
623 sta->airtime_weight = IEEE80211_DEFAULT_AIRTIME_WEIGHT;
625 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
626 skb_queue_head_init(&sta->ps_tx_buf[i]);
627 skb_queue_head_init(&sta->tx_filtered[i]);
628 sta->airtime[i].deficit = sta->airtime_weight;
629 atomic_set(&sta->airtime[i].aql_tx_pending, 0);
630 sta->airtime[i].aql_limit_low = local->aql_txq_limit_low[i];
631 sta->airtime[i].aql_limit_high = local->aql_txq_limit_high[i];
634 for (i = 0; i < IEEE80211_NUM_TIDS; i++)
635 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
637 for (i = 0; i < NUM_NL80211_BANDS; i++) {
641 if (!hw->wiphy->bands[i])
645 case NL80211_BAND_2GHZ:
646 case NL80211_BAND_LC:
648 * We use both here, even if we cannot really know for
649 * sure the station will support both, but the only use
650 * for this is when we don't know anything yet and send
651 * management frames, and then we'll pick the lowest
652 * possible rate anyway.
653 * If we don't include _G here, we cannot find a rate
654 * in P2P, and thus trigger the WARN_ONCE() in rate.c
656 mandatory = IEEE80211_RATE_MANDATORY_B |
657 IEEE80211_RATE_MANDATORY_G;
659 case NL80211_BAND_5GHZ:
660 mandatory = IEEE80211_RATE_MANDATORY_A;
662 case NL80211_BAND_60GHZ:
668 for (r = 0; r < hw->wiphy->bands[i]->n_bitrates; r++) {
669 struct ieee80211_rate *rate;
671 rate = &hw->wiphy->bands[i]->bitrates[r];
673 if (!(rate->flags & mandatory))
675 sta->sta.deflink.supp_rates[i] |= BIT(r);
679 sta->cparams.ce_threshold = CODEL_DISABLED_THRESHOLD;
680 sta->cparams.target = MS2TIME(20);
681 sta->cparams.interval = MS2TIME(100);
682 sta->cparams.ecn = true;
683 sta->cparams.ce_threshold_selector = 0;
684 sta->cparams.ce_threshold_mask = 0;
686 sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
691 kfree(to_txq_info(sta->sta.txq[0]));
693 sta_info_free_link(&sta->deflink);
694 #ifdef CONFIG_MAC80211_MESH
701 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
702 const u8 *addr, gfp_t gfp)
704 return __sta_info_alloc(sdata, addr, -1, addr, gfp);
707 struct sta_info *sta_info_alloc_with_link(struct ieee80211_sub_if_data *sdata,
709 unsigned int link_id,
713 return __sta_info_alloc(sdata, mld_addr, link_id, link_addr, gfp);
716 static int sta_info_insert_check(struct sta_info *sta)
718 struct ieee80211_sub_if_data *sdata = sta->sdata;
721 * Can't be a WARN_ON because it can be triggered through a race:
722 * something inserts a STA (on one CPU) without holding the RTNL
723 * and another CPU turns off the net device.
725 if (unlikely(!ieee80211_sdata_running(sdata)))
728 if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
729 !is_valid_ether_addr(sta->sta.addr)))
732 /* The RCU read lock is required by rhashtable due to
733 * asynchronous resize/rehash. We also require the mutex
737 lockdep_assert_held(&sdata->local->sta_mtx);
738 if (ieee80211_hw_check(&sdata->local->hw, NEEDS_UNIQUE_STA_ADDR) &&
739 ieee80211_find_sta_by_ifaddr(&sdata->local->hw, sta->addr, NULL)) {
748 static int sta_info_insert_drv_state(struct ieee80211_local *local,
749 struct ieee80211_sub_if_data *sdata,
750 struct sta_info *sta)
752 enum ieee80211_sta_state state;
755 for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
756 err = drv_sta_state(local, sdata, sta, state, state + 1);
763 * Drivers using legacy sta_add/sta_remove callbacks only
764 * get uploaded set to true after sta_add is called.
766 if (!local->ops->sta_add)
767 sta->uploaded = true;
771 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
773 "failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
774 sta->sta.addr, state + 1, err);
778 /* unwind on error */
779 for (; state > IEEE80211_STA_NOTEXIST; state--)
780 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
786 ieee80211_recalc_p2p_go_ps_allowed(struct ieee80211_sub_if_data *sdata)
788 struct ieee80211_local *local = sdata->local;
789 bool allow_p2p_go_ps = sdata->vif.p2p;
790 struct sta_info *sta;
793 list_for_each_entry_rcu(sta, &local->sta_list, list) {
794 if (sdata != sta->sdata ||
795 !test_sta_flag(sta, WLAN_STA_ASSOC))
797 if (!sta->sta.support_p2p_ps) {
798 allow_p2p_go_ps = false;
804 if (allow_p2p_go_ps != sdata->vif.bss_conf.allow_p2p_go_ps) {
805 sdata->vif.bss_conf.allow_p2p_go_ps = allow_p2p_go_ps;
806 ieee80211_link_info_change_notify(sdata, &sdata->deflink,
812 * should be called with sta_mtx locked
813 * this function replaces the mutex lock
816 static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
818 struct ieee80211_local *local = sta->local;
819 struct ieee80211_sub_if_data *sdata = sta->sdata;
820 struct station_info *sinfo = NULL;
823 lockdep_assert_held(&local->sta_mtx);
825 /* check if STA exists already */
826 if (sta_info_get_bss(sdata, sta->sta.addr)) {
831 sinfo = kzalloc(sizeof(struct station_info), GFP_KERNEL);
838 local->sta_generation++;
841 /* simplify things and don't accept BA sessions yet */
842 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
844 /* make the station visible */
845 err = sta_info_hash_add(local, sta);
849 if (sta->sta.valid_links) {
850 err = link_sta_info_hash_add(local, &sta->deflink);
852 sta_info_hash_del(local, sta);
857 list_add_tail_rcu(&sta->list, &local->sta_list);
859 /* update channel context before notifying the driver about state
860 * change, this enables driver using the updated channel context right away.
862 if (sta->sta_state >= IEEE80211_STA_ASSOC) {
863 ieee80211_recalc_min_chandef(sta->sdata, -1);
864 if (!sta->sta.support_p2p_ps)
865 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
869 err = sta_info_insert_drv_state(local, sdata, sta);
873 set_sta_flag(sta, WLAN_STA_INSERTED);
875 /* accept BA sessions now */
876 clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
878 ieee80211_sta_debugfs_add(sta);
879 rate_control_add_sta_debugfs(sta);
880 if (sta->sta.valid_links) {
883 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
884 struct link_sta_info *link_sta;
886 link_sta = rcu_dereference_protected(sta->link[i],
887 lockdep_is_held(&local->sta_mtx));
892 ieee80211_link_sta_debugfs_add(link_sta);
893 if (sdata->vif.active_links & BIT(i))
894 ieee80211_link_sta_debugfs_drv_add(link_sta);
897 ieee80211_link_sta_debugfs_add(&sta->deflink);
898 ieee80211_link_sta_debugfs_drv_add(&sta->deflink);
901 sinfo->generation = local->sta_generation;
902 cfg80211_new_sta(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
905 sta_dbg(sdata, "Inserted STA %pM\n", sta->sta.addr);
907 /* move reference to rcu-protected */
909 mutex_unlock(&local->sta_mtx);
911 if (ieee80211_vif_is_mesh(&sdata->vif))
912 mesh_accept_plinks_update(sdata);
916 if (sta->sta.valid_links)
917 link_sta_info_hash_del(local, &sta->deflink);
918 sta_info_hash_del(local, sta);
919 list_del_rcu(&sta->list);
924 cleanup_single_sta(sta);
925 mutex_unlock(&local->sta_mtx);
931 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
933 struct ieee80211_local *local = sta->local;
938 mutex_lock(&local->sta_mtx);
940 err = sta_info_insert_check(sta);
942 sta_info_free(local, sta);
943 mutex_unlock(&local->sta_mtx);
948 return sta_info_insert_finish(sta);
951 int sta_info_insert(struct sta_info *sta)
953 int err = sta_info_insert_rcu(sta);
960 static inline void __bss_tim_set(u8 *tim, u16 id)
963 * This format has been mandated by the IEEE specifications,
964 * so this line may not be changed to use the __set_bit() format.
966 tim[id / 8] |= (1 << (id % 8));
969 static inline void __bss_tim_clear(u8 *tim, u16 id)
972 * This format has been mandated by the IEEE specifications,
973 * so this line may not be changed to use the __clear_bit() format.
975 tim[id / 8] &= ~(1 << (id % 8));
978 static inline bool __bss_tim_get(u8 *tim, u16 id)
981 * This format has been mandated by the IEEE specifications,
982 * so this line may not be changed to use the test_bit() format.
984 return tim[id / 8] & (1 << (id % 8));
987 static unsigned long ieee80211_tids_for_ac(int ac)
989 /* If we ever support TIDs > 7, this obviously needs to be adjusted */
991 case IEEE80211_AC_VO:
992 return BIT(6) | BIT(7);
993 case IEEE80211_AC_VI:
994 return BIT(4) | BIT(5);
995 case IEEE80211_AC_BE:
996 return BIT(0) | BIT(3);
997 case IEEE80211_AC_BK:
998 return BIT(1) | BIT(2);
1005 static void __sta_info_recalc_tim(struct sta_info *sta, bool ignore_pending)
1007 struct ieee80211_local *local = sta->local;
1009 bool indicate_tim = false;
1010 u8 ignore_for_tim = sta->sta.uapsd_queues;
1012 u16 id = sta->sta.aid;
1014 if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1015 sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1016 if (WARN_ON_ONCE(!sta->sdata->bss))
1019 ps = &sta->sdata->bss->ps;
1020 #ifdef CONFIG_MAC80211_MESH
1021 } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
1022 ps = &sta->sdata->u.mesh.ps;
1028 /* No need to do anything if the driver does all */
1029 if (ieee80211_hw_check(&local->hw, AP_LINK_PS) && !local->ops->set_tim)
1036 * If all ACs are delivery-enabled then we should build
1037 * the TIM bit for all ACs anyway; if only some are then
1038 * we ignore those and build the TIM bit using only the
1041 if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
1045 ignore_for_tim = BIT(IEEE80211_NUM_ACS) - 1;
1047 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1050 if (ignore_for_tim & ieee80211_ac_to_qos_mask[ac])
1053 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
1054 !skb_queue_empty(&sta->ps_tx_buf[ac]);
1058 tids = ieee80211_tids_for_ac(ac);
1061 sta->driver_buffered_tids & tids;
1063 sta->txq_buffered_tids & tids;
1067 spin_lock_bh(&local->tim_lock);
1069 if (indicate_tim == __bss_tim_get(ps->tim, id))
1073 __bss_tim_set(ps->tim, id);
1075 __bss_tim_clear(ps->tim, id);
1077 if (local->ops->set_tim && !WARN_ON(sta->dead)) {
1078 local->tim_in_locked_section = true;
1079 drv_set_tim(local, &sta->sta, indicate_tim);
1080 local->tim_in_locked_section = false;
1084 spin_unlock_bh(&local->tim_lock);
1087 void sta_info_recalc_tim(struct sta_info *sta)
1089 __sta_info_recalc_tim(sta, false);
1092 static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
1094 struct ieee80211_tx_info *info;
1100 info = IEEE80211_SKB_CB(skb);
1102 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
1103 timeout = (sta->listen_interval *
1104 sta->sdata->vif.bss_conf.beacon_int *
1106 if (timeout < STA_TX_BUFFER_EXPIRE)
1107 timeout = STA_TX_BUFFER_EXPIRE;
1108 return time_after(jiffies, info->control.jiffies + timeout);
1112 static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
1113 struct sta_info *sta, int ac)
1115 unsigned long flags;
1116 struct sk_buff *skb;
1119 * First check for frames that should expire on the filtered
1120 * queue. Frames here were rejected by the driver and are on
1121 * a separate queue to avoid reordering with normal PS-buffered
1122 * frames. They also aren't accounted for right now in the
1123 * total_ps_buffered counter.
1126 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1127 skb = skb_peek(&sta->tx_filtered[ac]);
1128 if (sta_info_buffer_expired(sta, skb))
1129 skb = __skb_dequeue(&sta->tx_filtered[ac]);
1132 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1135 * Frames are queued in order, so if this one
1136 * hasn't expired yet we can stop testing. If
1137 * we actually reached the end of the queue we
1138 * also need to stop, of course.
1142 ieee80211_free_txskb(&local->hw, skb);
1146 * Now also check the normal PS-buffered queue, this will
1147 * only find something if the filtered queue was emptied
1148 * since the filtered frames are all before the normal PS
1152 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1153 skb = skb_peek(&sta->ps_tx_buf[ac]);
1154 if (sta_info_buffer_expired(sta, skb))
1155 skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
1158 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1161 * frames are queued in order, so if this one
1162 * hasn't expired yet (or we reached the end of
1163 * the queue) we can stop testing
1168 local->total_ps_buffered--;
1169 ps_dbg(sta->sdata, "Buffered frame expired (STA %pM)\n",
1171 ieee80211_free_txskb(&local->hw, skb);
1175 * Finally, recalculate the TIM bit for this station -- it might
1176 * now be clear because the station was too slow to retrieve its
1179 sta_info_recalc_tim(sta);
1182 * Return whether there are any frames still buffered, this is
1183 * used to check whether the cleanup timer still needs to run,
1184 * if there are no frames we don't need to rearm the timer.
1186 return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
1187 skb_queue_empty(&sta->tx_filtered[ac]));
1190 static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
1191 struct sta_info *sta)
1193 bool have_buffered = false;
1196 /* This is only necessary for stations on BSS/MBSS interfaces */
1197 if (!sta->sdata->bss &&
1198 !ieee80211_vif_is_mesh(&sta->sdata->vif))
1201 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1203 sta_info_cleanup_expire_buffered_ac(local, sta, ac);
1205 return have_buffered;
1208 static int __must_check __sta_info_destroy_part1(struct sta_info *sta)
1210 struct ieee80211_local *local;
1211 struct ieee80211_sub_if_data *sdata;
1222 lockdep_assert_held(&local->sta_mtx);
1225 * Before removing the station from the driver and
1226 * rate control, it might still start new aggregation
1227 * sessions -- block that to make sure the tear-down
1228 * will be sufficient.
1230 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
1231 ieee80211_sta_tear_down_BA_sessions(sta, AGG_STOP_DESTROY_STA);
1234 * Before removing the station from the driver there might be pending
1235 * rx frames on RSS queues sent prior to the disassociation - wait for
1236 * all such frames to be processed.
1238 drv_sync_rx_queues(local, sta);
1240 for (i = 0; i < ARRAY_SIZE(sta->link); i++) {
1241 struct link_sta_info *link_sta;
1243 if (!(sta->sta.valid_links & BIT(i)))
1246 link_sta = rcu_dereference_protected(sta->link[i],
1247 lockdep_is_held(&local->sta_mtx));
1249 link_sta_info_hash_del(local, link_sta);
1252 ret = sta_info_hash_del(local, sta);
1257 * for TDLS peers, make sure to return to the base channel before
1260 if (test_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL)) {
1261 drv_tdls_cancel_channel_switch(local, sdata, &sta->sta);
1262 clear_sta_flag(sta, WLAN_STA_TDLS_OFF_CHANNEL);
1265 list_del_rcu(&sta->list);
1266 sta->removed = true;
1269 drv_sta_pre_rcu_remove(local, sta->sdata, sta);
1271 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1272 rcu_access_pointer(sdata->u.vlan.sta) == sta)
1273 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
1278 static int _sta_info_move_state(struct sta_info *sta,
1279 enum ieee80211_sta_state new_state,
1284 if (sta->sta_state == new_state)
1287 /* check allowed transitions first */
1289 switch (new_state) {
1290 case IEEE80211_STA_NONE:
1291 if (sta->sta_state != IEEE80211_STA_AUTH)
1294 case IEEE80211_STA_AUTH:
1295 if (sta->sta_state != IEEE80211_STA_NONE &&
1296 sta->sta_state != IEEE80211_STA_ASSOC)
1299 case IEEE80211_STA_ASSOC:
1300 if (sta->sta_state != IEEE80211_STA_AUTH &&
1301 sta->sta_state != IEEE80211_STA_AUTHORIZED)
1304 case IEEE80211_STA_AUTHORIZED:
1305 if (sta->sta_state != IEEE80211_STA_ASSOC)
1309 WARN(1, "invalid state %d", new_state);
1313 sta_dbg(sta->sdata, "moving STA %pM to state %d\n",
1314 sta->sta.addr, new_state);
1316 /* notify the driver before the actual changes so it can
1317 * fail the transition
1319 if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
1320 int err = drv_sta_state(sta->local, sta->sdata, sta,
1321 sta->sta_state, new_state);
1326 /* reflect the change in all state variables */
1328 switch (new_state) {
1329 case IEEE80211_STA_NONE:
1330 if (sta->sta_state == IEEE80211_STA_AUTH)
1331 clear_bit(WLAN_STA_AUTH, &sta->_flags);
1333 case IEEE80211_STA_AUTH:
1334 if (sta->sta_state == IEEE80211_STA_NONE) {
1335 set_bit(WLAN_STA_AUTH, &sta->_flags);
1336 } else if (sta->sta_state == IEEE80211_STA_ASSOC) {
1337 clear_bit(WLAN_STA_ASSOC, &sta->_flags);
1339 ieee80211_recalc_min_chandef(sta->sdata, -1);
1340 if (!sta->sta.support_p2p_ps)
1341 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1345 case IEEE80211_STA_ASSOC:
1346 if (sta->sta_state == IEEE80211_STA_AUTH) {
1347 set_bit(WLAN_STA_ASSOC, &sta->_flags);
1348 sta->assoc_at = ktime_get_boottime_ns();
1350 ieee80211_recalc_min_chandef(sta->sdata, -1);
1351 if (!sta->sta.support_p2p_ps)
1352 ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
1354 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1355 ieee80211_vif_dec_num_mcast(sta->sdata);
1356 clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1357 ieee80211_clear_fast_xmit(sta);
1358 ieee80211_clear_fast_rx(sta);
1361 case IEEE80211_STA_AUTHORIZED:
1362 if (sta->sta_state == IEEE80211_STA_ASSOC) {
1363 ieee80211_vif_inc_num_mcast(sta->sdata);
1364 set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
1365 ieee80211_check_fast_xmit(sta);
1366 ieee80211_check_fast_rx(sta);
1368 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1369 sta->sdata->vif.type == NL80211_IFTYPE_AP)
1370 cfg80211_send_layer2_update(sta->sdata->dev,
1377 sta->sta_state = new_state;
1382 int sta_info_move_state(struct sta_info *sta,
1383 enum ieee80211_sta_state new_state)
1385 return _sta_info_move_state(sta, new_state, true);
1388 static void __sta_info_destroy_part2(struct sta_info *sta, bool recalc)
1390 struct ieee80211_local *local = sta->local;
1391 struct ieee80211_sub_if_data *sdata = sta->sdata;
1392 struct station_info *sinfo;
1396 * NOTE: This assumes at least synchronize_net() was done
1397 * after _part1 and before _part2!
1401 lockdep_assert_held(&local->sta_mtx);
1403 if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1404 ret = _sta_info_move_state(sta, IEEE80211_STA_ASSOC, recalc);
1408 /* Flush queues before removing keys, as that might remove them
1409 * from hardware, and then depending on the offload method, any
1410 * frames sitting on hardware queues might be sent out without
1411 * any encryption at all.
1413 if (local->ops->set_key) {
1414 if (local->ops->flush_sta)
1415 drv_flush_sta(local, sta->sdata, sta);
1417 ieee80211_flush_queues(local, sta->sdata, false);
1420 /* now keys can no longer be reached */
1421 ieee80211_free_sta_keys(local, sta);
1423 /* disable TIM bit - last chance to tell driver */
1424 __sta_info_recalc_tim(sta, true);
1429 local->sta_generation++;
1431 while (sta->sta_state > IEEE80211_STA_NONE) {
1432 ret = _sta_info_move_state(sta, sta->sta_state - 1, recalc);
1439 if (sta->uploaded) {
1440 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
1441 IEEE80211_STA_NOTEXIST);
1442 WARN_ON_ONCE(ret != 0);
1445 sta_dbg(sdata, "Removed STA %pM\n", sta->sta.addr);
1447 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
1449 sta_set_sinfo(sta, sinfo, true);
1450 cfg80211_del_sta_sinfo(sdata->dev, sta->sta.addr, sinfo, GFP_KERNEL);
1453 ieee80211_sta_debugfs_remove(sta);
1455 ieee80211_destroy_frag_cache(&sta->frags);
1457 cleanup_single_sta(sta);
1460 int __must_check __sta_info_destroy(struct sta_info *sta)
1462 int err = __sta_info_destroy_part1(sta);
1469 __sta_info_destroy_part2(sta, true);
1474 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
1476 struct sta_info *sta;
1479 mutex_lock(&sdata->local->sta_mtx);
1480 sta = sta_info_get(sdata, addr);
1481 ret = __sta_info_destroy(sta);
1482 mutex_unlock(&sdata->local->sta_mtx);
1487 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
1490 struct sta_info *sta;
1493 mutex_lock(&sdata->local->sta_mtx);
1494 sta = sta_info_get_bss(sdata, addr);
1495 ret = __sta_info_destroy(sta);
1496 mutex_unlock(&sdata->local->sta_mtx);
1501 static void sta_info_cleanup(struct timer_list *t)
1503 struct ieee80211_local *local = from_timer(local, t, sta_cleanup);
1504 struct sta_info *sta;
1505 bool timer_needed = false;
1508 list_for_each_entry_rcu(sta, &local->sta_list, list)
1509 if (sta_info_cleanup_expire_buffered(local, sta))
1510 timer_needed = true;
1513 if (local->quiescing)
1519 mod_timer(&local->sta_cleanup,
1520 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
1523 int sta_info_init(struct ieee80211_local *local)
1527 err = rhltable_init(&local->sta_hash, &sta_rht_params);
1531 err = rhltable_init(&local->link_sta_hash, &link_sta_rht_params);
1533 rhltable_destroy(&local->sta_hash);
1537 spin_lock_init(&local->tim_lock);
1538 mutex_init(&local->sta_mtx);
1539 INIT_LIST_HEAD(&local->sta_list);
1541 timer_setup(&local->sta_cleanup, sta_info_cleanup, 0);
1545 void sta_info_stop(struct ieee80211_local *local)
1547 del_timer_sync(&local->sta_cleanup);
1548 rhltable_destroy(&local->sta_hash);
1549 rhltable_destroy(&local->link_sta_hash);
1553 int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans)
1555 struct ieee80211_local *local = sdata->local;
1556 struct sta_info *sta, *tmp;
1557 LIST_HEAD(free_list);
1562 WARN_ON(vlans && sdata->vif.type != NL80211_IFTYPE_AP);
1563 WARN_ON(vlans && !sdata->bss);
1565 mutex_lock(&local->sta_mtx);
1566 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1567 if (sdata == sta->sdata ||
1568 (vlans && sdata->bss == sta->sdata->bss)) {
1569 if (!WARN_ON(__sta_info_destroy_part1(sta)))
1570 list_add(&sta->free_list, &free_list);
1575 if (!list_empty(&free_list)) {
1576 bool support_p2p_ps = true;
1579 list_for_each_entry_safe(sta, tmp, &free_list, free_list) {
1580 if (!sta->sta.support_p2p_ps)
1581 support_p2p_ps = false;
1582 __sta_info_destroy_part2(sta, false);
1585 ieee80211_recalc_min_chandef(sdata, -1);
1586 if (!support_p2p_ps)
1587 ieee80211_recalc_p2p_go_ps_allowed(sdata);
1589 mutex_unlock(&local->sta_mtx);
1594 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
1595 unsigned long exp_time)
1597 struct ieee80211_local *local = sdata->local;
1598 struct sta_info *sta, *tmp;
1600 mutex_lock(&local->sta_mtx);
1602 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
1603 unsigned long last_active = ieee80211_sta_last_active(sta);
1605 if (sdata != sta->sdata)
1608 if (time_is_before_jiffies(last_active + exp_time)) {
1609 sta_dbg(sta->sdata, "expiring inactive STA %pM\n",
1612 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1613 test_sta_flag(sta, WLAN_STA_PS_STA))
1614 atomic_dec(&sdata->u.mesh.ps.num_sta_ps);
1616 WARN_ON(__sta_info_destroy(sta));
1620 mutex_unlock(&local->sta_mtx);
1623 struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
1625 const u8 *localaddr)
1627 struct ieee80211_local *local = hw_to_local(hw);
1628 struct rhlist_head *tmp;
1629 struct sta_info *sta;
1632 * Just return a random station if localaddr is NULL
1633 * ... first in list.
1635 for_each_sta_info(local, addr, sta, tmp) {
1637 !ether_addr_equal(sta->sdata->vif.addr, localaddr))
1646 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
1648 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
1651 struct sta_info *sta;
1656 sta = sta_info_get_bss(vif_to_sdata(vif), addr);
1665 EXPORT_SYMBOL(ieee80211_find_sta);
1667 /* powersave support code */
1668 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
1670 struct ieee80211_sub_if_data *sdata = sta->sdata;
1671 struct ieee80211_local *local = sdata->local;
1672 struct sk_buff_head pending;
1673 int filtered = 0, buffered = 0, ac, i;
1674 unsigned long flags;
1677 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1678 sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
1681 if (sdata->vif.type == NL80211_IFTYPE_AP)
1682 ps = &sdata->bss->ps;
1683 else if (ieee80211_vif_is_mesh(&sdata->vif))
1684 ps = &sdata->u.mesh.ps;
1688 clear_sta_flag(sta, WLAN_STA_SP);
1690 BUILD_BUG_ON(BITS_TO_LONGS(IEEE80211_NUM_TIDS) > 1);
1691 sta->driver_buffered_tids = 0;
1692 sta->txq_buffered_tids = 0;
1694 if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
1695 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
1697 for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
1698 if (!sta->sta.txq[i] || !txq_has_queue(sta->sta.txq[i]))
1701 schedule_and_wake_txq(local, to_txq_info(sta->sta.txq[i]));
1704 skb_queue_head_init(&pending);
1706 /* sync with ieee80211_tx_h_unicast_ps_buf */
1707 spin_lock(&sta->ps_lock);
1708 /* Send all buffered frames to the station */
1709 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1710 int count = skb_queue_len(&pending), tmp;
1712 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
1713 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
1714 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
1715 tmp = skb_queue_len(&pending);
1716 filtered += tmp - count;
1719 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
1720 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
1721 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
1722 tmp = skb_queue_len(&pending);
1723 buffered += tmp - count;
1726 ieee80211_add_pending_skbs(local, &pending);
1728 /* now we're no longer in the deliver code */
1729 clear_sta_flag(sta, WLAN_STA_PS_DELIVER);
1731 /* The station might have polled and then woken up before we responded,
1732 * so clear these flags now to avoid them sticking around.
1734 clear_sta_flag(sta, WLAN_STA_PSPOLL);
1735 clear_sta_flag(sta, WLAN_STA_UAPSD);
1736 spin_unlock(&sta->ps_lock);
1738 atomic_dec(&ps->num_sta_ps);
1740 local->total_ps_buffered -= buffered;
1742 sta_info_recalc_tim(sta);
1745 "STA %pM aid %d sending %d filtered/%d PS frames since STA woke up\n",
1746 sta->sta.addr, sta->sta.aid, filtered, buffered);
1748 ieee80211_check_fast_xmit(sta);
1751 static void ieee80211_send_null_response(struct sta_info *sta, int tid,
1752 enum ieee80211_frame_release_type reason,
1753 bool call_driver, bool more_data)
1755 struct ieee80211_sub_if_data *sdata = sta->sdata;
1756 struct ieee80211_local *local = sdata->local;
1757 struct ieee80211_qos_hdr *nullfunc;
1758 struct sk_buff *skb;
1759 int size = sizeof(*nullfunc);
1761 bool qos = sta->sta.wme;
1762 struct ieee80211_tx_info *info;
1763 struct ieee80211_chanctx_conf *chanctx_conf;
1766 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1767 IEEE80211_STYPE_QOS_NULLFUNC |
1768 IEEE80211_FCTL_FROMDS);
1771 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
1772 IEEE80211_STYPE_NULLFUNC |
1773 IEEE80211_FCTL_FROMDS);
1776 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
1780 skb_reserve(skb, local->hw.extra_tx_headroom);
1782 nullfunc = skb_put(skb, size);
1783 nullfunc->frame_control = fc;
1784 nullfunc->duration_id = 0;
1785 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
1786 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
1787 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
1788 nullfunc->seq_ctrl = 0;
1790 skb->priority = tid;
1791 skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
1793 nullfunc->qos_ctrl = cpu_to_le16(tid);
1795 if (reason == IEEE80211_FRAME_RELEASE_UAPSD) {
1796 nullfunc->qos_ctrl |=
1797 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
1799 nullfunc->frame_control |=
1800 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1804 info = IEEE80211_SKB_CB(skb);
1807 * Tell TX path to send this frame even though the
1808 * STA may still remain is PS mode after this frame
1809 * exchange. Also set EOSP to indicate this packet
1810 * ends the poll/service period.
1812 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
1813 IEEE80211_TX_STATUS_EOSP |
1814 IEEE80211_TX_CTL_REQ_TX_STATUS;
1816 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
1819 drv_allow_buffered_frames(local, sta, BIT(tid), 1,
1822 skb->dev = sdata->dev;
1825 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
1826 if (WARN_ON(!chanctx_conf)) {
1832 info->band = chanctx_conf->def.chan->band;
1833 ieee80211_xmit(sdata, sta, skb);
1837 static int find_highest_prio_tid(unsigned long tids)
1839 /* lower 3 TIDs aren't ordered perfectly */
1841 return fls(tids) - 1;
1842 /* TID 0 is BE just like TID 3 */
1845 return fls(tids) - 1;
1848 /* Indicates if the MORE_DATA bit should be set in the last
1849 * frame obtained by ieee80211_sta_ps_get_frames.
1850 * Note that driver_release_tids is relevant only if
1851 * reason = IEEE80211_FRAME_RELEASE_PSPOLL
1854 ieee80211_sta_ps_more_data(struct sta_info *sta, u8 ignored_acs,
1855 enum ieee80211_frame_release_type reason,
1856 unsigned long driver_release_tids)
1860 /* If the driver has data on more than one TID then
1861 * certainly there's more data if we release just a
1862 * single frame now (from a single TID). This will
1863 * only happen for PS-Poll.
1865 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
1866 hweight16(driver_release_tids) > 1)
1869 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1870 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
1873 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1874 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1882 ieee80211_sta_ps_get_frames(struct sta_info *sta, int n_frames, u8 ignored_acs,
1883 enum ieee80211_frame_release_type reason,
1884 struct sk_buff_head *frames,
1885 unsigned long *driver_release_tids)
1887 struct ieee80211_sub_if_data *sdata = sta->sdata;
1888 struct ieee80211_local *local = sdata->local;
1891 /* Get response frame(s) and more data bit for the last one. */
1892 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1895 if (ignored_acs & ieee80211_ac_to_qos_mask[ac])
1898 tids = ieee80211_tids_for_ac(ac);
1900 /* if we already have frames from software, then we can't also
1901 * release from hardware queues
1903 if (skb_queue_empty(frames)) {
1904 *driver_release_tids |=
1905 sta->driver_buffered_tids & tids;
1906 *driver_release_tids |= sta->txq_buffered_tids & tids;
1909 if (!*driver_release_tids) {
1910 struct sk_buff *skb;
1912 while (n_frames > 0) {
1913 skb = skb_dequeue(&sta->tx_filtered[ac]);
1916 &sta->ps_tx_buf[ac]);
1918 local->total_ps_buffered--;
1923 __skb_queue_tail(frames, skb);
1927 /* If we have more frames buffered on this AC, then abort the
1928 * loop since we can't send more data from other ACs before
1929 * the buffered frames from this.
1931 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
1932 !skb_queue_empty(&sta->ps_tx_buf[ac]))
1938 ieee80211_sta_ps_deliver_response(struct sta_info *sta,
1939 int n_frames, u8 ignored_acs,
1940 enum ieee80211_frame_release_type reason)
1942 struct ieee80211_sub_if_data *sdata = sta->sdata;
1943 struct ieee80211_local *local = sdata->local;
1944 unsigned long driver_release_tids = 0;
1945 struct sk_buff_head frames;
1948 /* Service or PS-Poll period starts */
1949 set_sta_flag(sta, WLAN_STA_SP);
1951 __skb_queue_head_init(&frames);
1953 ieee80211_sta_ps_get_frames(sta, n_frames, ignored_acs, reason,
1954 &frames, &driver_release_tids);
1956 more_data = ieee80211_sta_ps_more_data(sta, ignored_acs, reason, driver_release_tids);
1958 if (driver_release_tids && reason == IEEE80211_FRAME_RELEASE_PSPOLL)
1959 driver_release_tids =
1960 BIT(find_highest_prio_tid(driver_release_tids));
1962 if (skb_queue_empty(&frames) && !driver_release_tids) {
1966 * For PS-Poll, this can only happen due to a race condition
1967 * when we set the TIM bit and the station notices it, but
1968 * before it can poll for the frame we expire it.
1970 * For uAPSD, this is said in the standard (11.2.1.5 h):
1971 * At each unscheduled SP for a non-AP STA, the AP shall
1972 * attempt to transmit at least one MSDU or MMPDU, but no
1973 * more than the value specified in the Max SP Length field
1974 * in the QoS Capability element from delivery-enabled ACs,
1975 * that are destined for the non-AP STA.
1977 * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
1980 /* This will evaluate to 1, 3, 5 or 7. */
1981 for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++)
1982 if (!(ignored_acs & ieee80211_ac_to_qos_mask[ac]))
1986 ieee80211_send_null_response(sta, tid, reason, true, false);
1987 } else if (!driver_release_tids) {
1988 struct sk_buff_head pending;
1989 struct sk_buff *skb;
1992 bool need_null = false;
1994 skb_queue_head_init(&pending);
1996 while ((skb = __skb_dequeue(&frames))) {
1997 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1998 struct ieee80211_hdr *hdr = (void *) skb->data;
2004 * Tell TX path to send this frame even though the
2005 * STA may still remain is PS mode after this frame
2008 info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
2009 info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
2012 * Use MoreData flag to indicate whether there are
2013 * more buffered frames for this STA
2015 if (more_data || !skb_queue_empty(&frames))
2016 hdr->frame_control |=
2017 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2019 hdr->frame_control &=
2020 cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
2022 if (ieee80211_is_data_qos(hdr->frame_control) ||
2023 ieee80211_is_qos_nullfunc(hdr->frame_control))
2024 qoshdr = ieee80211_get_qos_ctl(hdr);
2026 tids |= BIT(skb->priority);
2028 __skb_queue_tail(&pending, skb);
2030 /* end service period after last frame or add one */
2031 if (!skb_queue_empty(&frames))
2034 if (reason != IEEE80211_FRAME_RELEASE_UAPSD) {
2035 /* for PS-Poll, there's only one frame */
2036 info->flags |= IEEE80211_TX_STATUS_EOSP |
2037 IEEE80211_TX_CTL_REQ_TX_STATUS;
2041 /* For uAPSD, things are a bit more complicated. If the
2042 * last frame has a QoS header (i.e. is a QoS-data or
2043 * QoS-nulldata frame) then just set the EOSP bit there
2045 * If the frame doesn't have a QoS header (which means
2046 * it should be a bufferable MMPDU) then we can't set
2047 * the EOSP bit in the QoS header; add a QoS-nulldata
2048 * frame to the list to send it after the MMPDU.
2050 * Note that this code is only in the mac80211-release
2051 * code path, we assume that the driver will not buffer
2052 * anything but QoS-data frames, or if it does, will
2053 * create the QoS-nulldata frame by itself if needed.
2055 * Cf. 802.11-2012 10.2.1.10 (c).
2058 *qoshdr |= IEEE80211_QOS_CTL_EOSP;
2060 info->flags |= IEEE80211_TX_STATUS_EOSP |
2061 IEEE80211_TX_CTL_REQ_TX_STATUS;
2063 /* The standard isn't completely clear on this
2064 * as it says the more-data bit should be set
2065 * if there are more BUs. The QoS-Null frame
2066 * we're about to send isn't buffered yet, we
2067 * only create it below, but let's pretend it
2068 * was buffered just in case some clients only
2069 * expect more-data=0 when eosp=1.
2071 hdr->frame_control |=
2072 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2079 drv_allow_buffered_frames(local, sta, tids, num,
2082 ieee80211_add_pending_skbs(local, &pending);
2085 ieee80211_send_null_response(
2086 sta, find_highest_prio_tid(tids),
2087 reason, false, false);
2089 sta_info_recalc_tim(sta);
2094 * We need to release a frame that is buffered somewhere in the
2095 * driver ... it'll have to handle that.
2096 * Note that the driver also has to check the number of frames
2097 * on the TIDs we're releasing from - if there are more than
2098 * n_frames it has to set the more-data bit (if we didn't ask
2099 * it to set it anyway due to other buffered frames); if there
2100 * are fewer than n_frames it has to make sure to adjust that
2101 * to allow the service period to end properly.
2103 drv_release_buffered_frames(local, sta, driver_release_tids,
2104 n_frames, reason, more_data);
2107 * Note that we don't recalculate the TIM bit here as it would
2108 * most likely have no effect at all unless the driver told us
2109 * that the TID(s) became empty before returning here from the
2111 * Either way, however, when the driver tells us that the TID(s)
2112 * became empty or we find that a txq became empty, we'll do the
2113 * TIM recalculation.
2116 for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
2117 if (!sta->sta.txq[tid] ||
2118 !(driver_release_tids & BIT(tid)) ||
2119 txq_has_queue(sta->sta.txq[tid]))
2122 sta_info_recalc_tim(sta);
2128 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
2130 u8 ignore_for_response = sta->sta.uapsd_queues;
2133 * If all ACs are delivery-enabled then we should reply
2134 * from any of them, if only some are enabled we reply
2135 * only from the non-enabled ones.
2137 if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
2138 ignore_for_response = 0;
2140 ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
2141 IEEE80211_FRAME_RELEASE_PSPOLL);
2144 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
2146 int n_frames = sta->sta.max_sp;
2147 u8 delivery_enabled = sta->sta.uapsd_queues;
2150 * If we ever grow support for TSPEC this might happen if
2151 * the TSPEC update from hostapd comes in between a trigger
2152 * frame setting WLAN_STA_UAPSD in the RX path and this
2153 * actually getting called.
2155 if (!delivery_enabled)
2158 switch (sta->sta.max_sp) {
2169 /* XXX: what is a good value? */
2174 ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
2175 IEEE80211_FRAME_RELEASE_UAPSD);
2178 void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
2179 struct ieee80211_sta *pubsta, bool block)
2181 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2183 trace_api_sta_block_awake(sta->local, pubsta, block);
2186 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
2187 ieee80211_clear_fast_xmit(sta);
2191 if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
2194 if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
2195 set_sta_flag(sta, WLAN_STA_PS_DELIVER);
2196 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2197 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2198 } else if (test_sta_flag(sta, WLAN_STA_PSPOLL) ||
2199 test_sta_flag(sta, WLAN_STA_UAPSD)) {
2200 /* must be asleep in this case */
2201 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2202 ieee80211_queue_work(hw, &sta->drv_deliver_wk);
2204 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
2205 ieee80211_check_fast_xmit(sta);
2208 EXPORT_SYMBOL(ieee80211_sta_block_awake);
2210 void ieee80211_sta_eosp(struct ieee80211_sta *pubsta)
2212 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2213 struct ieee80211_local *local = sta->local;
2215 trace_api_eosp(local, pubsta);
2217 clear_sta_flag(sta, WLAN_STA_SP);
2219 EXPORT_SYMBOL(ieee80211_sta_eosp);
2221 void ieee80211_send_eosp_nullfunc(struct ieee80211_sta *pubsta, int tid)
2223 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2224 enum ieee80211_frame_release_type reason;
2227 trace_api_send_eosp_nullfunc(sta->local, pubsta, tid);
2229 reason = IEEE80211_FRAME_RELEASE_UAPSD;
2230 more_data = ieee80211_sta_ps_more_data(sta, ~sta->sta.uapsd_queues,
2233 ieee80211_send_null_response(sta, tid, reason, false, more_data);
2235 EXPORT_SYMBOL(ieee80211_send_eosp_nullfunc);
2237 void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
2238 u8 tid, bool buffered)
2240 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2242 if (WARN_ON(tid >= IEEE80211_NUM_TIDS))
2245 trace_api_sta_set_buffered(sta->local, pubsta, tid, buffered);
2248 set_bit(tid, &sta->driver_buffered_tids);
2250 clear_bit(tid, &sta->driver_buffered_tids);
2252 sta_info_recalc_tim(sta);
2254 EXPORT_SYMBOL(ieee80211_sta_set_buffered);
2256 void ieee80211_sta_register_airtime(struct ieee80211_sta *pubsta, u8 tid,
2257 u32 tx_airtime, u32 rx_airtime)
2259 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2260 struct ieee80211_local *local = sta->sdata->local;
2261 u8 ac = ieee80211_ac_from_tid(tid);
2265 if (sta->local->airtime_flags & AIRTIME_USE_TX)
2266 airtime += tx_airtime;
2267 if (sta->local->airtime_flags & AIRTIME_USE_RX)
2268 airtime += rx_airtime;
2270 spin_lock_bh(&local->active_txq_lock[ac]);
2271 sta->airtime[ac].tx_airtime += tx_airtime;
2272 sta->airtime[ac].rx_airtime += rx_airtime;
2274 diff = (u32)jiffies - sta->airtime[ac].last_active;
2275 if (diff <= AIRTIME_ACTIVE_DURATION)
2276 sta->airtime[ac].deficit -= airtime;
2278 spin_unlock_bh(&local->active_txq_lock[ac]);
2280 EXPORT_SYMBOL(ieee80211_sta_register_airtime);
2282 void __ieee80211_sta_recalc_aggregates(struct sta_info *sta, u16 active_links)
2287 if (!sta->sta.valid_links || !sta->sta.mlo) {
2288 sta->sta.cur = &sta->sta.deflink.agg;
2293 for (link_id = 0; link_id < ARRAY_SIZE((sta)->link); link_id++) {
2294 struct ieee80211_link_sta *link_sta;
2297 if (!(active_links & BIT(link_id)))
2300 link_sta = rcu_dereference(sta->sta.link[link_id]);
2305 sta->cur = sta->sta.deflink.agg;
2310 sta->cur.max_amsdu_len =
2311 min(sta->cur.max_amsdu_len,
2312 link_sta->agg.max_amsdu_len);
2313 sta->cur.max_rc_amsdu_len =
2314 min(sta->cur.max_rc_amsdu_len,
2315 link_sta->agg.max_rc_amsdu_len);
2317 for (i = 0; i < ARRAY_SIZE(sta->cur.max_tid_amsdu_len); i++)
2318 sta->cur.max_tid_amsdu_len[i] =
2319 min(sta->cur.max_tid_amsdu_len[i],
2320 link_sta->agg.max_tid_amsdu_len[i]);
2324 sta->sta.cur = &sta->cur;
2327 void ieee80211_sta_recalc_aggregates(struct ieee80211_sta *pubsta)
2329 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2331 __ieee80211_sta_recalc_aggregates(sta, sta->sdata->vif.active_links);
2333 EXPORT_SYMBOL(ieee80211_sta_recalc_aggregates);
2335 void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
2336 struct sta_info *sta, u8 ac,
2337 u16 tx_airtime, bool tx_completed)
2341 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
2344 if (!tx_completed) {
2346 atomic_add(tx_airtime,
2347 &sta->airtime[ac].aql_tx_pending);
2349 atomic_add(tx_airtime, &local->aql_total_pending_airtime);
2350 atomic_add(tx_airtime, &local->aql_ac_pending_airtime[ac]);
2355 tx_pending = atomic_sub_return(tx_airtime,
2356 &sta->airtime[ac].aql_tx_pending);
2358 atomic_cmpxchg(&sta->airtime[ac].aql_tx_pending,
2362 atomic_sub(tx_airtime, &local->aql_total_pending_airtime);
2363 tx_pending = atomic_sub_return(tx_airtime,
2364 &local->aql_ac_pending_airtime[ac]);
2365 if (WARN_ONCE(tx_pending < 0,
2366 "Device %s AC %d pending airtime underflow: %u, %u",
2367 wiphy_name(local->hw.wiphy), ac, tx_pending,
2369 atomic_cmpxchg(&local->aql_ac_pending_airtime[ac],
2371 atomic_sub(tx_pending, &local->aql_total_pending_airtime);
2375 static struct ieee80211_sta_rx_stats *
2376 sta_get_last_rx_stats(struct sta_info *sta)
2378 struct ieee80211_sta_rx_stats *stats = &sta->deflink.rx_stats;
2381 if (!sta->deflink.pcpu_rx_stats)
2384 for_each_possible_cpu(cpu) {
2385 struct ieee80211_sta_rx_stats *cpustats;
2387 cpustats = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2389 if (time_after(cpustats->last_rx, stats->last_rx))
2396 static void sta_stats_decode_rate(struct ieee80211_local *local, u32 rate,
2397 struct rate_info *rinfo)
2399 rinfo->bw = STA_STATS_GET(BW, rate);
2401 switch (STA_STATS_GET(TYPE, rate)) {
2402 case STA_STATS_RATE_TYPE_VHT:
2403 rinfo->flags = RATE_INFO_FLAGS_VHT_MCS;
2404 rinfo->mcs = STA_STATS_GET(VHT_MCS, rate);
2405 rinfo->nss = STA_STATS_GET(VHT_NSS, rate);
2406 if (STA_STATS_GET(SGI, rate))
2407 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2409 case STA_STATS_RATE_TYPE_HT:
2410 rinfo->flags = RATE_INFO_FLAGS_MCS;
2411 rinfo->mcs = STA_STATS_GET(HT_MCS, rate);
2412 if (STA_STATS_GET(SGI, rate))
2413 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
2415 case STA_STATS_RATE_TYPE_LEGACY: {
2416 struct ieee80211_supported_band *sband;
2419 int band = STA_STATS_GET(LEGACY_BAND, rate);
2420 int rate_idx = STA_STATS_GET(LEGACY_IDX, rate);
2422 sband = local->hw.wiphy->bands[band];
2424 if (WARN_ON_ONCE(!sband->bitrates))
2427 brate = sband->bitrates[rate_idx].bitrate;
2428 if (rinfo->bw == RATE_INFO_BW_5)
2430 else if (rinfo->bw == RATE_INFO_BW_10)
2434 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
2437 case STA_STATS_RATE_TYPE_HE:
2438 rinfo->flags = RATE_INFO_FLAGS_HE_MCS;
2439 rinfo->mcs = STA_STATS_GET(HE_MCS, rate);
2440 rinfo->nss = STA_STATS_GET(HE_NSS, rate);
2441 rinfo->he_gi = STA_STATS_GET(HE_GI, rate);
2442 rinfo->he_ru_alloc = STA_STATS_GET(HE_RU, rate);
2443 rinfo->he_dcm = STA_STATS_GET(HE_DCM, rate);
2445 case STA_STATS_RATE_TYPE_EHT:
2446 rinfo->flags = RATE_INFO_FLAGS_EHT_MCS;
2447 rinfo->mcs = STA_STATS_GET(EHT_MCS, rate);
2448 rinfo->nss = STA_STATS_GET(EHT_NSS, rate);
2449 rinfo->eht_gi = STA_STATS_GET(EHT_GI, rate);
2450 rinfo->eht_ru_alloc = STA_STATS_GET(EHT_RU, rate);
2455 static int sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
2457 u32 rate = READ_ONCE(sta_get_last_rx_stats(sta)->last_rate);
2459 if (rate == STA_STATS_RATE_INVALID)
2462 sta_stats_decode_rate(sta->local, rate, rinfo);
2466 static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
2473 start = u64_stats_fetch_begin(&rxstats->syncp);
2474 value = rxstats->msdu[tid];
2475 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2480 static void sta_set_tidstats(struct sta_info *sta,
2481 struct cfg80211_tid_stats *tidstats,
2484 struct ieee80211_local *local = sta->local;
2487 if (!(tidstats->filled & BIT(NL80211_TID_STATS_RX_MSDU))) {
2488 tidstats->rx_msdu += sta_get_tidstats_msdu(&sta->deflink.rx_stats,
2491 if (sta->deflink.pcpu_rx_stats) {
2492 for_each_possible_cpu(cpu) {
2493 struct ieee80211_sta_rx_stats *cpurxs;
2495 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2497 tidstats->rx_msdu +=
2498 sta_get_tidstats_msdu(cpurxs, tid);
2502 tidstats->filled |= BIT(NL80211_TID_STATS_RX_MSDU);
2505 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU))) {
2506 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU);
2507 tidstats->tx_msdu = sta->deflink.tx_stats.msdu[tid];
2510 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_RETRIES)) &&
2511 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2512 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_RETRIES);
2513 tidstats->tx_msdu_retries = sta->deflink.status_stats.msdu_retries[tid];
2516 if (!(tidstats->filled & BIT(NL80211_TID_STATS_TX_MSDU_FAILED)) &&
2517 ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
2518 tidstats->filled |= BIT(NL80211_TID_STATS_TX_MSDU_FAILED);
2519 tidstats->tx_msdu_failed = sta->deflink.status_stats.msdu_failed[tid];
2522 if (tid < IEEE80211_NUM_TIDS) {
2523 spin_lock_bh(&local->fq.lock);
2526 tidstats->filled |= BIT(NL80211_TID_STATS_TXQ_STATS);
2527 ieee80211_fill_txq_stats(&tidstats->txq_stats,
2528 to_txq_info(sta->sta.txq[tid]));
2531 spin_unlock_bh(&local->fq.lock);
2535 static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
2541 start = u64_stats_fetch_begin(&rxstats->syncp);
2542 value = rxstats->bytes;
2543 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
2548 void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
2551 struct ieee80211_sub_if_data *sdata = sta->sdata;
2552 struct ieee80211_local *local = sdata->local;
2555 struct ieee80211_sta_rx_stats *last_rxstats;
2557 last_rxstats = sta_get_last_rx_stats(sta);
2559 sinfo->generation = sdata->local->sta_generation;
2561 /* do before driver, so beacon filtering drivers have a
2562 * chance to e.g. just add the number of filtered beacons
2563 * (or just modify the value entirely, of course)
2565 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2566 sinfo->rx_beacon = sdata->deflink.u.mgd.count_beacon_signal;
2568 drv_sta_statistics(local, sdata, &sta->sta, sinfo);
2569 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_INACTIVE_TIME) |
2570 BIT_ULL(NL80211_STA_INFO_STA_FLAGS) |
2571 BIT_ULL(NL80211_STA_INFO_BSS_PARAM) |
2572 BIT_ULL(NL80211_STA_INFO_CONNECTED_TIME) |
2573 BIT_ULL(NL80211_STA_INFO_ASSOC_AT_BOOTTIME) |
2574 BIT_ULL(NL80211_STA_INFO_RX_DROP_MISC);
2576 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2577 sinfo->beacon_loss_count =
2578 sdata->deflink.u.mgd.beacon_loss_count;
2579 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_LOSS);
2582 sinfo->connected_time = ktime_get_seconds() - sta->last_connected;
2583 sinfo->assoc_at = sta->assoc_at;
2584 sinfo->inactive_time =
2585 jiffies_to_msecs(jiffies - ieee80211_sta_last_active(sta));
2587 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES64) |
2588 BIT_ULL(NL80211_STA_INFO_TX_BYTES)))) {
2589 sinfo->tx_bytes = 0;
2590 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2591 sinfo->tx_bytes += sta->deflink.tx_stats.bytes[ac];
2592 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BYTES64);
2595 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_PACKETS))) {
2596 sinfo->tx_packets = 0;
2597 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2598 sinfo->tx_packets += sta->deflink.tx_stats.packets[ac];
2599 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_PACKETS);
2602 if (!(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES64) |
2603 BIT_ULL(NL80211_STA_INFO_RX_BYTES)))) {
2604 sinfo->rx_bytes += sta_get_stats_bytes(&sta->deflink.rx_stats);
2606 if (sta->deflink.pcpu_rx_stats) {
2607 for_each_possible_cpu(cpu) {
2608 struct ieee80211_sta_rx_stats *cpurxs;
2610 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2612 sinfo->rx_bytes += sta_get_stats_bytes(cpurxs);
2616 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BYTES64);
2619 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_PACKETS))) {
2620 sinfo->rx_packets = sta->deflink.rx_stats.packets;
2621 if (sta->deflink.pcpu_rx_stats) {
2622 for_each_possible_cpu(cpu) {
2623 struct ieee80211_sta_rx_stats *cpurxs;
2625 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats,
2627 sinfo->rx_packets += cpurxs->packets;
2630 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_PACKETS);
2633 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_RETRIES))) {
2634 sinfo->tx_retries = sta->deflink.status_stats.retry_count;
2635 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
2638 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_FAILED))) {
2639 sinfo->tx_failed = sta->deflink.status_stats.retry_failed;
2640 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
2643 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_DURATION))) {
2644 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2645 sinfo->rx_duration += sta->airtime[ac].rx_airtime;
2646 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
2649 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_DURATION))) {
2650 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
2651 sinfo->tx_duration += sta->airtime[ac].tx_airtime;
2652 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
2655 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT))) {
2656 sinfo->airtime_weight = sta->airtime_weight;
2657 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_WEIGHT);
2660 sinfo->rx_dropped_misc = sta->deflink.rx_stats.dropped;
2661 if (sta->deflink.pcpu_rx_stats) {
2662 for_each_possible_cpu(cpu) {
2663 struct ieee80211_sta_rx_stats *cpurxs;
2665 cpurxs = per_cpu_ptr(sta->deflink.pcpu_rx_stats, cpu);
2666 sinfo->rx_dropped_misc += cpurxs->dropped;
2670 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
2671 !(sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)) {
2672 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX) |
2673 BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
2674 sinfo->rx_beacon_signal_avg = ieee80211_ave_rssi(&sdata->vif);
2677 if (ieee80211_hw_check(&sta->local->hw, SIGNAL_DBM) ||
2678 ieee80211_hw_check(&sta->local->hw, SIGNAL_UNSPEC)) {
2679 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL))) {
2680 sinfo->signal = (s8)last_rxstats->last_signal;
2681 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
2684 if (!sta->deflink.pcpu_rx_stats &&
2685 !(sinfo->filled & BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG))) {
2687 -ewma_signal_read(&sta->deflink.rx_stats_avg.signal);
2688 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
2692 /* for the average - if pcpu_rx_stats isn't set - rxstats must point to
2693 * the sta->rx_stats struct, so the check here is fine with and without
2696 if (last_rxstats->chains &&
2697 !(sinfo->filled & (BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL) |
2698 BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)))) {
2699 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
2700 if (!sta->deflink.pcpu_rx_stats)
2701 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
2703 sinfo->chains = last_rxstats->chains;
2705 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
2706 sinfo->chain_signal[i] =
2707 last_rxstats->chain_signal_last[i];
2708 sinfo->chain_signal_avg[i] =
2709 -ewma_signal_read(&sta->deflink.rx_stats_avg.chain_signal[i]);
2713 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) &&
2714 !sta->sta.valid_links) {
2715 sta_set_rate_info_tx(sta, &sta->deflink.tx_stats.last_rate,
2717 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
2720 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) &&
2721 !sta->sta.valid_links) {
2722 if (sta_set_rate_info_rx(sta, &sinfo->rxrate) == 0)
2723 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_BITRATE);
2726 if (tidstats && !cfg80211_sinfo_alloc_tid_stats(sinfo, GFP_KERNEL)) {
2727 for (i = 0; i < IEEE80211_NUM_TIDS + 1; i++)
2728 sta_set_tidstats(sta, &sinfo->pertid[i], i);
2731 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2732 #ifdef CONFIG_MAC80211_MESH
2733 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_LLID) |
2734 BIT_ULL(NL80211_STA_INFO_PLID) |
2735 BIT_ULL(NL80211_STA_INFO_PLINK_STATE) |
2736 BIT_ULL(NL80211_STA_INFO_LOCAL_PM) |
2737 BIT_ULL(NL80211_STA_INFO_PEER_PM) |
2738 BIT_ULL(NL80211_STA_INFO_NONPEER_PM) |
2739 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_GATE) |
2740 BIT_ULL(NL80211_STA_INFO_CONNECTED_TO_AS);
2742 sinfo->llid = sta->mesh->llid;
2743 sinfo->plid = sta->mesh->plid;
2744 sinfo->plink_state = sta->mesh->plink_state;
2745 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
2746 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_T_OFFSET);
2747 sinfo->t_offset = sta->mesh->t_offset;
2749 sinfo->local_pm = sta->mesh->local_pm;
2750 sinfo->peer_pm = sta->mesh->peer_pm;
2751 sinfo->nonpeer_pm = sta->mesh->nonpeer_pm;
2752 sinfo->connected_to_gate = sta->mesh->connected_to_gate;
2753 sinfo->connected_to_as = sta->mesh->connected_to_as;
2757 sinfo->bss_param.flags = 0;
2758 if (sdata->vif.bss_conf.use_cts_prot)
2759 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
2760 if (sdata->vif.bss_conf.use_short_preamble)
2761 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
2762 if (sdata->vif.bss_conf.use_short_slot)
2763 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
2764 sinfo->bss_param.dtim_period = sdata->vif.bss_conf.dtim_period;
2765 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
2767 sinfo->sta_flags.set = 0;
2768 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
2769 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
2770 BIT(NL80211_STA_FLAG_WME) |
2771 BIT(NL80211_STA_FLAG_MFP) |
2772 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
2773 BIT(NL80211_STA_FLAG_ASSOCIATED) |
2774 BIT(NL80211_STA_FLAG_TDLS_PEER);
2775 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2776 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
2777 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
2778 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
2780 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
2781 if (test_sta_flag(sta, WLAN_STA_MFP))
2782 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
2783 if (test_sta_flag(sta, WLAN_STA_AUTH))
2784 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
2785 if (test_sta_flag(sta, WLAN_STA_ASSOC))
2786 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
2787 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
2788 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
2790 thr = sta_get_expected_throughput(sta);
2793 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_EXPECTED_THROUGHPUT);
2794 sinfo->expected_throughput = thr;
2797 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL)) &&
2798 sta->deflink.status_stats.ack_signal_filled) {
2799 sinfo->ack_signal = sta->deflink.status_stats.last_ack_signal;
2800 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL);
2803 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG)) &&
2804 sta->deflink.status_stats.ack_signal_filled) {
2805 sinfo->avg_ack_signal =
2806 -(s8)ewma_avg_signal_read(
2807 &sta->deflink.status_stats.avg_ack_signal);
2809 BIT_ULL(NL80211_STA_INFO_ACK_SIGNAL_AVG);
2812 if (ieee80211_vif_is_mesh(&sdata->vif)) {
2813 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_AIRTIME_LINK_METRIC);
2814 sinfo->airtime_link_metric =
2815 airtime_link_metric_get(local, sta);
2819 u32 sta_get_expected_throughput(struct sta_info *sta)
2821 struct ieee80211_sub_if_data *sdata = sta->sdata;
2822 struct ieee80211_local *local = sdata->local;
2823 struct rate_control_ref *ref = NULL;
2826 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
2827 ref = local->rate_ctrl;
2829 /* check if the driver has a SW RC implementation */
2830 if (ref && ref->ops->get_expected_throughput)
2831 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
2833 thr = drv_get_expected_throughput(local, sta);
2838 unsigned long ieee80211_sta_last_active(struct sta_info *sta)
2840 struct ieee80211_sta_rx_stats *stats = sta_get_last_rx_stats(sta);
2842 if (!sta->deflink.status_stats.last_ack ||
2843 time_after(stats->last_rx, sta->deflink.status_stats.last_ack))
2844 return stats->last_rx;
2845 return sta->deflink.status_stats.last_ack;
2848 static void sta_update_codel_params(struct sta_info *sta, u32 thr)
2850 if (thr && thr < STA_SLOW_THRESHOLD * sta->local->num_sta) {
2851 sta->cparams.target = MS2TIME(50);
2852 sta->cparams.interval = MS2TIME(300);
2853 sta->cparams.ecn = false;
2855 sta->cparams.target = MS2TIME(20);
2856 sta->cparams.interval = MS2TIME(100);
2857 sta->cparams.ecn = true;
2861 void ieee80211_sta_set_expected_throughput(struct ieee80211_sta *pubsta,
2864 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
2866 sta_update_codel_params(sta, thr);
2869 int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id)
2871 struct ieee80211_sub_if_data *sdata = sta->sdata;
2872 struct sta_link_alloc *alloc;
2875 lockdep_assert_held(&sdata->local->sta_mtx);
2877 /* must represent an MLD from the start */
2878 if (WARN_ON(!sta->sta.valid_links))
2881 if (WARN_ON(sta->sta.valid_links & BIT(link_id) ||
2882 sta->link[link_id]))
2885 alloc = kzalloc(sizeof(*alloc), GFP_KERNEL);
2889 ret = sta_info_alloc_link(sdata->local, &alloc->info, GFP_KERNEL);
2895 sta_info_add_link(sta, link_id, &alloc->info, &alloc->sta);
2897 ieee80211_link_sta_debugfs_add(&alloc->info);
2902 void ieee80211_sta_free_link(struct sta_info *sta, unsigned int link_id)
2904 lockdep_assert_held(&sta->sdata->local->sta_mtx);
2906 sta_remove_link(sta, link_id, false);
2909 int ieee80211_sta_activate_link(struct sta_info *sta, unsigned int link_id)
2911 struct ieee80211_sub_if_data *sdata = sta->sdata;
2912 struct link_sta_info *link_sta;
2913 u16 old_links = sta->sta.valid_links;
2914 u16 new_links = old_links | BIT(link_id);
2917 link_sta = rcu_dereference_protected(sta->link[link_id],
2918 lockdep_is_held(&sdata->local->sta_mtx));
2920 if (WARN_ON(old_links == new_links || !link_sta))
2924 if (link_sta_info_hash_lookup(sdata->local, link_sta->addr)) {
2928 /* we only modify under the mutex so this is fine */
2931 sta->sta.valid_links = new_links;
2933 if (!test_sta_flag(sta, WLAN_STA_INSERTED))
2936 ieee80211_recalc_min_chandef(sdata, link_id);
2938 /* Ensure the values are updated for the driver,
2939 * redone by sta_remove_link on failure.
2941 ieee80211_sta_recalc_aggregates(&sta->sta);
2943 ret = drv_change_sta_links(sdata->local, sdata, &sta->sta,
2944 old_links, new_links);
2946 sta->sta.valid_links = old_links;
2947 sta_remove_link(sta, link_id, false);
2952 ret = link_sta_info_hash_add(sdata->local, link_sta);
2957 void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id)
2959 struct ieee80211_sub_if_data *sdata = sta->sdata;
2960 u16 old_links = sta->sta.valid_links;
2962 lockdep_assert_held(&sdata->local->sta_mtx);
2964 sta->sta.valid_links &= ~BIT(link_id);
2966 if (test_sta_flag(sta, WLAN_STA_INSERTED))
2967 drv_change_sta_links(sdata->local, sdata, &sta->sta,
2968 old_links, sta->sta.valid_links);
2970 sta_remove_link(sta, link_id, true);
2973 void ieee80211_sta_set_max_amsdu_subframes(struct sta_info *sta,
2974 const u8 *ext_capab,
2975 unsigned int ext_capab_len)
2979 sta->sta.max_amsdu_subframes = 0;
2981 if (ext_capab_len < 8)
2984 /* The sender might not have sent the last bit, consider it to be 0 */
2985 val = u8_get_bits(ext_capab[7], WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB);
2987 /* we did get all the bits, take the MSB as well */
2988 if (ext_capab_len >= 9)
2989 val |= u8_get_bits(ext_capab[8],
2990 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB) << 1;
2993 sta->sta.max_amsdu_subframes = 4 << (4 - val);
2996 #ifdef CONFIG_LOCKDEP
2997 bool lockdep_sta_mutex_held(struct ieee80211_sta *pubsta)
2999 struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
3001 return lockdep_is_held(&sta->local->sta_mtx);
3003 EXPORT_SYMBOL(lockdep_sta_mutex_held);