Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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