xref: /OK3568_Linux_fs/kernel/net/mac80211/sta_info.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2002-2005, Devicescape Software, Inc.
4*4882a593Smuzhiyun  * Copyright 2013-2014  Intel Mobile Communications GmbH
5*4882a593Smuzhiyun  * Copyright(c) 2015-2017 Intel Deutschland GmbH
6*4882a593Smuzhiyun  * Copyright(c) 2020-2021 Intel Corporation
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef STA_INFO_H
10*4882a593Smuzhiyun #define STA_INFO_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/list.h>
13*4882a593Smuzhiyun #include <linux/types.h>
14*4882a593Smuzhiyun #include <linux/if_ether.h>
15*4882a593Smuzhiyun #include <linux/workqueue.h>
16*4882a593Smuzhiyun #include <linux/average.h>
17*4882a593Smuzhiyun #include <linux/bitfield.h>
18*4882a593Smuzhiyun #include <linux/etherdevice.h>
19*4882a593Smuzhiyun #include <linux/rhashtable.h>
20*4882a593Smuzhiyun #include <linux/u64_stats_sync.h>
21*4882a593Smuzhiyun #include "key.h"
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /**
24*4882a593Smuzhiyun  * enum ieee80211_sta_info_flags - Stations flags
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * These flags are used with &struct sta_info's @flags member, but
27*4882a593Smuzhiyun  * only indirectly with set_sta_flag() and friends.
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * @WLAN_STA_AUTH: Station is authenticated.
30*4882a593Smuzhiyun  * @WLAN_STA_ASSOC: Station is associated.
31*4882a593Smuzhiyun  * @WLAN_STA_PS_STA: Station is in power-save mode
32*4882a593Smuzhiyun  * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic.
33*4882a593Smuzhiyun  *	This bit is always checked so needs to be enabled for all stations
34*4882a593Smuzhiyun  *	when virtual port control is not in use.
35*4882a593Smuzhiyun  * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
36*4882a593Smuzhiyun  *	frames.
37*4882a593Smuzhiyun  * @WLAN_STA_WDS: Station is one of our WDS peers.
38*4882a593Smuzhiyun  * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
39*4882a593Smuzhiyun  *	IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
40*4882a593Smuzhiyun  *	frame to this station is transmitted.
41*4882a593Smuzhiyun  * @WLAN_STA_MFP: Management frame protection is used with this STA.
42*4882a593Smuzhiyun  * @WLAN_STA_BLOCK_BA: Used to deny ADDBA requests (both TX and RX)
43*4882a593Smuzhiyun  *	during suspend/resume and station removal.
44*4882a593Smuzhiyun  * @WLAN_STA_PS_DRIVER: driver requires keeping this station in
45*4882a593Smuzhiyun  *	power-save mode logically to flush frames that might still
46*4882a593Smuzhiyun  *	be in the queues
47*4882a593Smuzhiyun  * @WLAN_STA_PSPOLL: Station sent PS-poll while driver was keeping
48*4882a593Smuzhiyun  *	station in power-save mode, reply when the driver unblocks.
49*4882a593Smuzhiyun  * @WLAN_STA_TDLS_PEER: Station is a TDLS peer.
50*4882a593Smuzhiyun  * @WLAN_STA_TDLS_PEER_AUTH: This TDLS peer is authorized to send direct
51*4882a593Smuzhiyun  *	packets. This means the link is enabled.
52*4882a593Smuzhiyun  * @WLAN_STA_TDLS_INITIATOR: We are the initiator of the TDLS link with this
53*4882a593Smuzhiyun  *	station.
54*4882a593Smuzhiyun  * @WLAN_STA_TDLS_CHAN_SWITCH: This TDLS peer supports TDLS channel-switching
55*4882a593Smuzhiyun  * @WLAN_STA_TDLS_OFF_CHANNEL: The local STA is currently off-channel with this
56*4882a593Smuzhiyun  *	TDLS peer
57*4882a593Smuzhiyun  * @WLAN_STA_TDLS_WIDER_BW: This TDLS peer supports working on a wider bw on
58*4882a593Smuzhiyun  *	the BSS base channel.
59*4882a593Smuzhiyun  * @WLAN_STA_UAPSD: Station requested unscheduled SP while driver was
60*4882a593Smuzhiyun  *	keeping station in power-save mode, reply when the driver
61*4882a593Smuzhiyun  *	unblocks the station.
62*4882a593Smuzhiyun  * @WLAN_STA_SP: Station is in a service period, so don't try to
63*4882a593Smuzhiyun  *	reply to other uAPSD trigger frames or PS-Poll.
64*4882a593Smuzhiyun  * @WLAN_STA_4ADDR_EVENT: 4-addr event was already sent for this frame.
65*4882a593Smuzhiyun  * @WLAN_STA_INSERTED: This station is inserted into the hash table.
66*4882a593Smuzhiyun  * @WLAN_STA_RATE_CONTROL: rate control was initialized for this station.
67*4882a593Smuzhiyun  * @WLAN_STA_TOFFSET_KNOWN: toffset calculated for this station is valid.
68*4882a593Smuzhiyun  * @WLAN_STA_MPSP_OWNER: local STA is owner of a mesh Peer Service Period.
69*4882a593Smuzhiyun  * @WLAN_STA_MPSP_RECIPIENT: local STA is recipient of a MPSP.
70*4882a593Smuzhiyun  * @WLAN_STA_PS_DELIVER: station woke up, but we're still blocking TX
71*4882a593Smuzhiyun  *	until pending frames are delivered
72*4882a593Smuzhiyun  * @WLAN_STA_USES_ENCRYPTION: This station was configured for encryption,
73*4882a593Smuzhiyun  *	so drop all packets without a key later.
74*4882a593Smuzhiyun  *
75*4882a593Smuzhiyun  * @NUM_WLAN_STA_FLAGS: number of defined flags
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun enum ieee80211_sta_info_flags {
78*4882a593Smuzhiyun 	WLAN_STA_AUTH,
79*4882a593Smuzhiyun 	WLAN_STA_ASSOC,
80*4882a593Smuzhiyun 	WLAN_STA_PS_STA,
81*4882a593Smuzhiyun 	WLAN_STA_AUTHORIZED,
82*4882a593Smuzhiyun 	WLAN_STA_SHORT_PREAMBLE,
83*4882a593Smuzhiyun 	WLAN_STA_WDS,
84*4882a593Smuzhiyun 	WLAN_STA_CLEAR_PS_FILT,
85*4882a593Smuzhiyun 	WLAN_STA_MFP,
86*4882a593Smuzhiyun 	WLAN_STA_BLOCK_BA,
87*4882a593Smuzhiyun 	WLAN_STA_PS_DRIVER,
88*4882a593Smuzhiyun 	WLAN_STA_PSPOLL,
89*4882a593Smuzhiyun 	WLAN_STA_TDLS_PEER,
90*4882a593Smuzhiyun 	WLAN_STA_TDLS_PEER_AUTH,
91*4882a593Smuzhiyun 	WLAN_STA_TDLS_INITIATOR,
92*4882a593Smuzhiyun 	WLAN_STA_TDLS_CHAN_SWITCH,
93*4882a593Smuzhiyun 	WLAN_STA_TDLS_OFF_CHANNEL,
94*4882a593Smuzhiyun 	WLAN_STA_TDLS_WIDER_BW,
95*4882a593Smuzhiyun 	WLAN_STA_UAPSD,
96*4882a593Smuzhiyun 	WLAN_STA_SP,
97*4882a593Smuzhiyun 	WLAN_STA_4ADDR_EVENT,
98*4882a593Smuzhiyun 	WLAN_STA_INSERTED,
99*4882a593Smuzhiyun 	WLAN_STA_RATE_CONTROL,
100*4882a593Smuzhiyun 	WLAN_STA_TOFFSET_KNOWN,
101*4882a593Smuzhiyun 	WLAN_STA_MPSP_OWNER,
102*4882a593Smuzhiyun 	WLAN_STA_MPSP_RECIPIENT,
103*4882a593Smuzhiyun 	WLAN_STA_PS_DELIVER,
104*4882a593Smuzhiyun 	WLAN_STA_USES_ENCRYPTION,
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun 	NUM_WLAN_STA_FLAGS,
107*4882a593Smuzhiyun };
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #define ADDBA_RESP_INTERVAL HZ
110*4882a593Smuzhiyun #define HT_AGG_MAX_RETRIES		15
111*4882a593Smuzhiyun #define HT_AGG_BURST_RETRIES		3
112*4882a593Smuzhiyun #define HT_AGG_RETRIES_PERIOD		(15 * HZ)
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #define HT_AGG_STATE_DRV_READY		0
115*4882a593Smuzhiyun #define HT_AGG_STATE_RESPONSE_RECEIVED	1
116*4882a593Smuzhiyun #define HT_AGG_STATE_OPERATIONAL	2
117*4882a593Smuzhiyun #define HT_AGG_STATE_STOPPING		3
118*4882a593Smuzhiyun #define HT_AGG_STATE_WANT_START		4
119*4882a593Smuzhiyun #define HT_AGG_STATE_WANT_STOP		5
120*4882a593Smuzhiyun #define HT_AGG_STATE_START_CB		6
121*4882a593Smuzhiyun #define HT_AGG_STATE_STOP_CB		7
122*4882a593Smuzhiyun #define HT_AGG_STATE_SENT_ADDBA		8
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun DECLARE_EWMA(avg_signal, 10, 8)
125*4882a593Smuzhiyun enum ieee80211_agg_stop_reason {
126*4882a593Smuzhiyun 	AGG_STOP_DECLINED,
127*4882a593Smuzhiyun 	AGG_STOP_LOCAL_REQUEST,
128*4882a593Smuzhiyun 	AGG_STOP_PEER_REQUEST,
129*4882a593Smuzhiyun 	AGG_STOP_DESTROY_STA,
130*4882a593Smuzhiyun };
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun /* Debugfs flags to enable/disable use of RX/TX airtime in scheduler */
133*4882a593Smuzhiyun #define AIRTIME_USE_TX		BIT(0)
134*4882a593Smuzhiyun #define AIRTIME_USE_RX		BIT(1)
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun struct airtime_info {
137*4882a593Smuzhiyun 	u64 rx_airtime;
138*4882a593Smuzhiyun 	u64 tx_airtime;
139*4882a593Smuzhiyun 	s64 deficit;
140*4882a593Smuzhiyun 	atomic_t aql_tx_pending; /* Estimated airtime for frames pending */
141*4882a593Smuzhiyun 	u32 aql_limit_low;
142*4882a593Smuzhiyun 	u32 aql_limit_high;
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
146*4882a593Smuzhiyun 					  struct sta_info *sta, u8 ac,
147*4882a593Smuzhiyun 					  u16 tx_airtime, bool tx_completed);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun struct sta_info;
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun /**
152*4882a593Smuzhiyun  * struct tid_ampdu_tx - TID aggregation information (Tx).
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  * @rcu_head: rcu head for freeing structure
155*4882a593Smuzhiyun  * @session_timer: check if we keep Tx-ing on the TID (by timeout value)
156*4882a593Smuzhiyun  * @addba_resp_timer: timer for peer's response to addba request
157*4882a593Smuzhiyun  * @pending: pending frames queue -- use sta's spinlock to protect
158*4882a593Smuzhiyun  * @sta: station we are attached to
159*4882a593Smuzhiyun  * @dialog_token: dialog token for aggregation session
160*4882a593Smuzhiyun  * @timeout: session timeout value to be filled in ADDBA requests
161*4882a593Smuzhiyun  * @tid: TID number
162*4882a593Smuzhiyun  * @state: session state (see above)
163*4882a593Smuzhiyun  * @last_tx: jiffies of last tx activity
164*4882a593Smuzhiyun  * @stop_initiator: initiator of a session stop
165*4882a593Smuzhiyun  * @tx_stop: TX DelBA frame when stopping
166*4882a593Smuzhiyun  * @buf_size: reorder buffer size at receiver
167*4882a593Smuzhiyun  * @failed_bar_ssn: ssn of the last failed BAR tx attempt
168*4882a593Smuzhiyun  * @bar_pending: BAR needs to be re-sent
169*4882a593Smuzhiyun  * @amsdu: support A-MSDU withing A-MDPU
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * This structure's lifetime is managed by RCU, assignments to
172*4882a593Smuzhiyun  * the array holding it must hold the aggregation mutex.
173*4882a593Smuzhiyun  *
174*4882a593Smuzhiyun  * The TX path can access it under RCU lock-free if, and
175*4882a593Smuzhiyun  * only if, the state has the flag %HT_AGG_STATE_OPERATIONAL
176*4882a593Smuzhiyun  * set. Otherwise, the TX path must also acquire the spinlock
177*4882a593Smuzhiyun  * and re-check the state, see comments in the tx code
178*4882a593Smuzhiyun  * touching it.
179*4882a593Smuzhiyun  */
180*4882a593Smuzhiyun struct tid_ampdu_tx {
181*4882a593Smuzhiyun 	struct rcu_head rcu_head;
182*4882a593Smuzhiyun 	struct timer_list session_timer;
183*4882a593Smuzhiyun 	struct timer_list addba_resp_timer;
184*4882a593Smuzhiyun 	struct sk_buff_head pending;
185*4882a593Smuzhiyun 	struct sta_info *sta;
186*4882a593Smuzhiyun 	unsigned long state;
187*4882a593Smuzhiyun 	unsigned long last_tx;
188*4882a593Smuzhiyun 	u16 timeout;
189*4882a593Smuzhiyun 	u8 dialog_token;
190*4882a593Smuzhiyun 	u8 stop_initiator;
191*4882a593Smuzhiyun 	bool tx_stop;
192*4882a593Smuzhiyun 	u16 buf_size;
193*4882a593Smuzhiyun 	u16 ssn;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	u16 failed_bar_ssn;
196*4882a593Smuzhiyun 	bool bar_pending;
197*4882a593Smuzhiyun 	bool amsdu;
198*4882a593Smuzhiyun 	u8 tid;
199*4882a593Smuzhiyun };
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /**
202*4882a593Smuzhiyun  * struct tid_ampdu_rx - TID aggregation information (Rx).
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * @reorder_buf: buffer to reorder incoming aggregated MPDUs. An MPDU may be an
205*4882a593Smuzhiyun  *	A-MSDU with individually reported subframes.
206*4882a593Smuzhiyun  * @reorder_buf_filtered: bitmap indicating where there are filtered frames in
207*4882a593Smuzhiyun  *	the reorder buffer that should be ignored when releasing frames
208*4882a593Smuzhiyun  * @reorder_time: jiffies when skb was added
209*4882a593Smuzhiyun  * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
210*4882a593Smuzhiyun  * @reorder_timer: releases expired frames from the reorder buffer.
211*4882a593Smuzhiyun  * @sta: station we are attached to
212*4882a593Smuzhiyun  * @last_rx: jiffies of last rx activity
213*4882a593Smuzhiyun  * @head_seq_num: head sequence number in reordering buffer.
214*4882a593Smuzhiyun  * @stored_mpdu_num: number of MPDUs in reordering buffer
215*4882a593Smuzhiyun  * @ssn: Starting Sequence Number expected to be aggregated.
216*4882a593Smuzhiyun  * @buf_size: buffer size for incoming A-MPDUs
217*4882a593Smuzhiyun  * @timeout: reset timer value (in TUs).
218*4882a593Smuzhiyun  * @tid: TID number
219*4882a593Smuzhiyun  * @rcu_head: RCU head used for freeing this struct
220*4882a593Smuzhiyun  * @reorder_lock: serializes access to reorder buffer, see below.
221*4882a593Smuzhiyun  * @auto_seq: used for offloaded BA sessions to automatically pick head_seq_and
222*4882a593Smuzhiyun  *	and ssn.
223*4882a593Smuzhiyun  * @removed: this session is removed (but might have been found due to RCU)
224*4882a593Smuzhiyun  * @started: this session has started (head ssn or higher was received)
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  * This structure's lifetime is managed by RCU, assignments to
227*4882a593Smuzhiyun  * the array holding it must hold the aggregation mutex.
228*4882a593Smuzhiyun  *
229*4882a593Smuzhiyun  * The @reorder_lock is used to protect the members of this
230*4882a593Smuzhiyun  * struct, except for @timeout, @buf_size and @dialog_token,
231*4882a593Smuzhiyun  * which are constant across the lifetime of the struct (the
232*4882a593Smuzhiyun  * dialog token being used only for debugging).
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun struct tid_ampdu_rx {
235*4882a593Smuzhiyun 	struct rcu_head rcu_head;
236*4882a593Smuzhiyun 	spinlock_t reorder_lock;
237*4882a593Smuzhiyun 	u64 reorder_buf_filtered;
238*4882a593Smuzhiyun 	struct sk_buff_head *reorder_buf;
239*4882a593Smuzhiyun 	unsigned long *reorder_time;
240*4882a593Smuzhiyun 	struct sta_info *sta;
241*4882a593Smuzhiyun 	struct timer_list session_timer;
242*4882a593Smuzhiyun 	struct timer_list reorder_timer;
243*4882a593Smuzhiyun 	unsigned long last_rx;
244*4882a593Smuzhiyun 	u16 head_seq_num;
245*4882a593Smuzhiyun 	u16 stored_mpdu_num;
246*4882a593Smuzhiyun 	u16 ssn;
247*4882a593Smuzhiyun 	u16 buf_size;
248*4882a593Smuzhiyun 	u16 timeout;
249*4882a593Smuzhiyun 	u8 tid;
250*4882a593Smuzhiyun 	u8 auto_seq:1,
251*4882a593Smuzhiyun 	   removed:1,
252*4882a593Smuzhiyun 	   started:1;
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun /**
256*4882a593Smuzhiyun  * struct sta_ampdu_mlme - STA aggregation information.
257*4882a593Smuzhiyun  *
258*4882a593Smuzhiyun  * @mtx: mutex to protect all TX data (except non-NULL assignments
259*4882a593Smuzhiyun  *	to tid_tx[idx], which are protected by the sta spinlock)
260*4882a593Smuzhiyun  *	tid_start_tx is also protected by sta->lock.
261*4882a593Smuzhiyun  * @tid_rx: aggregation info for Rx per TID -- RCU protected
262*4882a593Smuzhiyun  * @tid_rx_token: dialog tokens for valid aggregation sessions
263*4882a593Smuzhiyun  * @tid_rx_timer_expired: bitmap indicating on which TIDs the
264*4882a593Smuzhiyun  *	RX timer expired until the work for it runs
265*4882a593Smuzhiyun  * @tid_rx_stop_requested:  bitmap indicating which BA sessions per TID the
266*4882a593Smuzhiyun  *	driver requested to close until the work for it runs
267*4882a593Smuzhiyun  * @tid_rx_manage_offl: bitmap indicating which BA sessions were requested
268*4882a593Smuzhiyun  *	to be treated as started/stopped due to offloading
269*4882a593Smuzhiyun  * @agg_session_valid: bitmap indicating which TID has a rx BA session open on
270*4882a593Smuzhiyun  * @unexpected_agg: bitmap indicating which TID already sent a delBA due to
271*4882a593Smuzhiyun  *	unexpected aggregation related frames outside a session
272*4882a593Smuzhiyun  * @work: work struct for starting/stopping aggregation
273*4882a593Smuzhiyun  * @tid_tx: aggregation info for Tx per TID
274*4882a593Smuzhiyun  * @tid_start_tx: sessions where start was requested
275*4882a593Smuzhiyun  * @last_addba_req_time: timestamp of the last addBA request.
276*4882a593Smuzhiyun  * @addba_req_num: number of times addBA request has been sent.
277*4882a593Smuzhiyun  * @dialog_token_allocator: dialog token enumerator for each new session;
278*4882a593Smuzhiyun  */
279*4882a593Smuzhiyun struct sta_ampdu_mlme {
280*4882a593Smuzhiyun 	struct mutex mtx;
281*4882a593Smuzhiyun 	/* rx */
282*4882a593Smuzhiyun 	struct tid_ampdu_rx __rcu *tid_rx[IEEE80211_NUM_TIDS];
283*4882a593Smuzhiyun 	u8 tid_rx_token[IEEE80211_NUM_TIDS];
284*4882a593Smuzhiyun 	unsigned long tid_rx_timer_expired[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
285*4882a593Smuzhiyun 	unsigned long tid_rx_stop_requested[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
286*4882a593Smuzhiyun 	unsigned long tid_rx_manage_offl[BITS_TO_LONGS(2 * IEEE80211_NUM_TIDS)];
287*4882a593Smuzhiyun 	unsigned long agg_session_valid[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
288*4882a593Smuzhiyun 	unsigned long unexpected_agg[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
289*4882a593Smuzhiyun 	/* tx */
290*4882a593Smuzhiyun 	struct work_struct work;
291*4882a593Smuzhiyun 	struct tid_ampdu_tx __rcu *tid_tx[IEEE80211_NUM_TIDS];
292*4882a593Smuzhiyun 	struct tid_ampdu_tx *tid_start_tx[IEEE80211_NUM_TIDS];
293*4882a593Smuzhiyun 	unsigned long last_addba_req_time[IEEE80211_NUM_TIDS];
294*4882a593Smuzhiyun 	u8 addba_req_num[IEEE80211_NUM_TIDS];
295*4882a593Smuzhiyun 	u8 dialog_token_allocator;
296*4882a593Smuzhiyun };
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun /* Value to indicate no TID reservation */
300*4882a593Smuzhiyun #define IEEE80211_TID_UNRESERVED	0xff
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun #define IEEE80211_FAST_XMIT_MAX_IV	18
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun /**
305*4882a593Smuzhiyun  * struct ieee80211_fast_tx - TX fastpath information
306*4882a593Smuzhiyun  * @key: key to use for hw crypto
307*4882a593Smuzhiyun  * @hdr: the 802.11 header to put with the frame
308*4882a593Smuzhiyun  * @hdr_len: actual 802.11 header length
309*4882a593Smuzhiyun  * @sa_offs: offset of the SA
310*4882a593Smuzhiyun  * @da_offs: offset of the DA
311*4882a593Smuzhiyun  * @pn_offs: offset where to put PN for crypto (or 0 if not needed)
312*4882a593Smuzhiyun  * @band: band this will be transmitted on, for tx_info
313*4882a593Smuzhiyun  * @rcu_head: RCU head to free this struct
314*4882a593Smuzhiyun  *
315*4882a593Smuzhiyun  * This struct is small enough so that the common case (maximum crypto
316*4882a593Smuzhiyun  * header length of 8 like for CCMP/GCMP) fits into a single 64-byte
317*4882a593Smuzhiyun  * cache line.
318*4882a593Smuzhiyun  */
319*4882a593Smuzhiyun struct ieee80211_fast_tx {
320*4882a593Smuzhiyun 	struct ieee80211_key *key;
321*4882a593Smuzhiyun 	u8 hdr_len;
322*4882a593Smuzhiyun 	u8 sa_offs, da_offs, pn_offs;
323*4882a593Smuzhiyun 	u8 band;
324*4882a593Smuzhiyun 	u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
325*4882a593Smuzhiyun 	       sizeof(rfc1042_header)] __aligned(2);
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	struct rcu_head rcu_head;
328*4882a593Smuzhiyun };
329*4882a593Smuzhiyun 
330*4882a593Smuzhiyun /**
331*4882a593Smuzhiyun  * struct ieee80211_fast_rx - RX fastpath information
332*4882a593Smuzhiyun  * @dev: netdevice for reporting the SKB
333*4882a593Smuzhiyun  * @vif_type: (P2P-less) interface type of the original sdata (sdata->vif.type)
334*4882a593Smuzhiyun  * @vif_addr: interface address
335*4882a593Smuzhiyun  * @rfc1042_hdr: copy of the RFC 1042 SNAP header (to have in cache)
336*4882a593Smuzhiyun  * @control_port_protocol: control port protocol copied from sdata
337*4882a593Smuzhiyun  * @expected_ds_bits: from/to DS bits expected
338*4882a593Smuzhiyun  * @icv_len: length of the MIC if present
339*4882a593Smuzhiyun  * @key: bool indicating encryption is expected (key is set)
340*4882a593Smuzhiyun  * @internal_forward: forward froms internally on AP/VLAN type interfaces
341*4882a593Smuzhiyun  * @uses_rss: copy of USES_RSS hw flag
342*4882a593Smuzhiyun  * @da_offs: offset of the DA in the header (for header conversion)
343*4882a593Smuzhiyun  * @sa_offs: offset of the SA in the header (for header conversion)
344*4882a593Smuzhiyun  * @rcu_head: RCU head for freeing this structure
345*4882a593Smuzhiyun  */
346*4882a593Smuzhiyun struct ieee80211_fast_rx {
347*4882a593Smuzhiyun 	struct net_device *dev;
348*4882a593Smuzhiyun 	enum nl80211_iftype vif_type;
349*4882a593Smuzhiyun 	u8 vif_addr[ETH_ALEN] __aligned(2);
350*4882a593Smuzhiyun 	u8 rfc1042_hdr[6] __aligned(2);
351*4882a593Smuzhiyun 	__be16 control_port_protocol;
352*4882a593Smuzhiyun 	__le16 expected_ds_bits;
353*4882a593Smuzhiyun 	u8 icv_len;
354*4882a593Smuzhiyun 	u8 key:1,
355*4882a593Smuzhiyun 	   internal_forward:1,
356*4882a593Smuzhiyun 	   uses_rss:1;
357*4882a593Smuzhiyun 	u8 da_offs, sa_offs;
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun 	struct rcu_head rcu_head;
360*4882a593Smuzhiyun };
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun /* we use only values in the range 0-100, so pick a large precision */
363*4882a593Smuzhiyun DECLARE_EWMA(mesh_fail_avg, 20, 8)
364*4882a593Smuzhiyun DECLARE_EWMA(mesh_tx_rate_avg, 8, 16)
365*4882a593Smuzhiyun 
366*4882a593Smuzhiyun /**
367*4882a593Smuzhiyun  * struct mesh_sta - mesh STA information
368*4882a593Smuzhiyun  * @plink_lock: serialize access to plink fields
369*4882a593Smuzhiyun  * @llid: Local link ID
370*4882a593Smuzhiyun  * @plid: Peer link ID
371*4882a593Smuzhiyun  * @aid: local aid supplied by peer
372*4882a593Smuzhiyun  * @reason: Cancel reason on PLINK_HOLDING state
373*4882a593Smuzhiyun  * @plink_retries: Retries in establishment
374*4882a593Smuzhiyun  * @plink_state: peer link state
375*4882a593Smuzhiyun  * @plink_timeout: timeout of peer link
376*4882a593Smuzhiyun  * @plink_timer: peer link watch timer
377*4882a593Smuzhiyun  * @plink_sta: peer link watch timer's sta_info
378*4882a593Smuzhiyun  * @t_offset: timing offset relative to this host
379*4882a593Smuzhiyun  * @t_offset_setpoint: reference timing offset of this sta to be used when
380*4882a593Smuzhiyun  * 	calculating clockdrift
381*4882a593Smuzhiyun  * @local_pm: local link-specific power save mode
382*4882a593Smuzhiyun  * @peer_pm: peer-specific power save mode towards local STA
383*4882a593Smuzhiyun  * @nonpeer_pm: STA power save mode towards non-peer neighbors
384*4882a593Smuzhiyun  * @processed_beacon: set to true after peer rates and capabilities are
385*4882a593Smuzhiyun  *	processed
386*4882a593Smuzhiyun  * @connected_to_gate: true if mesh STA has a path to a mesh gate
387*4882a593Smuzhiyun  * @connected_to_as: true if mesh STA has a path to a authentication server
388*4882a593Smuzhiyun  * @fail_avg: moving percentage of failed MSDUs
389*4882a593Smuzhiyun  * @tx_rate_avg: moving average of tx bitrate
390*4882a593Smuzhiyun  */
391*4882a593Smuzhiyun struct mesh_sta {
392*4882a593Smuzhiyun 	struct timer_list plink_timer;
393*4882a593Smuzhiyun 	struct sta_info *plink_sta;
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun 	s64 t_offset;
396*4882a593Smuzhiyun 	s64 t_offset_setpoint;
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	spinlock_t plink_lock;
399*4882a593Smuzhiyun 	u16 llid;
400*4882a593Smuzhiyun 	u16 plid;
401*4882a593Smuzhiyun 	u16 aid;
402*4882a593Smuzhiyun 	u16 reason;
403*4882a593Smuzhiyun 	u8 plink_retries;
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun 	bool processed_beacon;
406*4882a593Smuzhiyun 	bool connected_to_gate;
407*4882a593Smuzhiyun 	bool connected_to_as;
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun 	enum nl80211_plink_state plink_state;
410*4882a593Smuzhiyun 	u32 plink_timeout;
411*4882a593Smuzhiyun 
412*4882a593Smuzhiyun 	/* mesh power save */
413*4882a593Smuzhiyun 	enum nl80211_mesh_power_mode local_pm;
414*4882a593Smuzhiyun 	enum nl80211_mesh_power_mode peer_pm;
415*4882a593Smuzhiyun 	enum nl80211_mesh_power_mode nonpeer_pm;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun 	/* moving percentage of failed MSDUs */
418*4882a593Smuzhiyun 	struct ewma_mesh_fail_avg fail_avg;
419*4882a593Smuzhiyun 	/* moving average of tx bitrate */
420*4882a593Smuzhiyun 	struct ewma_mesh_tx_rate_avg tx_rate_avg;
421*4882a593Smuzhiyun };
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun DECLARE_EWMA(signal, 10, 8)
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun struct ieee80211_sta_rx_stats {
426*4882a593Smuzhiyun 	unsigned long packets;
427*4882a593Smuzhiyun 	unsigned long last_rx;
428*4882a593Smuzhiyun 	unsigned long num_duplicates;
429*4882a593Smuzhiyun 	unsigned long fragments;
430*4882a593Smuzhiyun 	unsigned long dropped;
431*4882a593Smuzhiyun 	int last_signal;
432*4882a593Smuzhiyun 	u8 chains;
433*4882a593Smuzhiyun 	s8 chain_signal_last[IEEE80211_MAX_CHAINS];
434*4882a593Smuzhiyun 	u32 last_rate;
435*4882a593Smuzhiyun 	struct u64_stats_sync syncp;
436*4882a593Smuzhiyun 	u64 bytes;
437*4882a593Smuzhiyun 	u64 msdu[IEEE80211_NUM_TIDS + 1];
438*4882a593Smuzhiyun };
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun /*
441*4882a593Smuzhiyun  * IEEE 802.11-2016 (10.6 "Defragmentation") recommends support for "concurrent
442*4882a593Smuzhiyun  * reception of at least one MSDU per access category per associated STA"
443*4882a593Smuzhiyun  * on APs, or "at least one MSDU per access category" on other interface types.
444*4882a593Smuzhiyun  *
445*4882a593Smuzhiyun  * This limit can be increased by changing this define, at the cost of slower
446*4882a593Smuzhiyun  * frame reassembly and increased memory use while fragments are pending.
447*4882a593Smuzhiyun  */
448*4882a593Smuzhiyun #define IEEE80211_FRAGMENT_MAX 4
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun struct ieee80211_fragment_entry {
451*4882a593Smuzhiyun 	struct sk_buff_head skb_list;
452*4882a593Smuzhiyun 	unsigned long first_frag_time;
453*4882a593Smuzhiyun 	u16 seq;
454*4882a593Smuzhiyun 	u16 extra_len;
455*4882a593Smuzhiyun 	u16 last_frag;
456*4882a593Smuzhiyun 	u8 rx_queue;
457*4882a593Smuzhiyun 	u8 check_sequential_pn:1, /* needed for CCMP/GCMP */
458*4882a593Smuzhiyun 	   is_protected:1;
459*4882a593Smuzhiyun 	u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
460*4882a593Smuzhiyun 	unsigned int key_color;
461*4882a593Smuzhiyun };
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun struct ieee80211_fragment_cache {
464*4882a593Smuzhiyun 	struct ieee80211_fragment_entry	entries[IEEE80211_FRAGMENT_MAX];
465*4882a593Smuzhiyun 	unsigned int next;
466*4882a593Smuzhiyun };
467*4882a593Smuzhiyun 
468*4882a593Smuzhiyun /*
469*4882a593Smuzhiyun  * The bandwidth threshold below which the per-station CoDel parameters will be
470*4882a593Smuzhiyun  * scaled to be more lenient (to prevent starvation of slow stations). This
471*4882a593Smuzhiyun  * value will be scaled by the number of active stations when it is being
472*4882a593Smuzhiyun  * applied.
473*4882a593Smuzhiyun  */
474*4882a593Smuzhiyun #define STA_SLOW_THRESHOLD 6000 /* 6 Mbps */
475*4882a593Smuzhiyun 
476*4882a593Smuzhiyun /**
477*4882a593Smuzhiyun  * struct sta_info - STA information
478*4882a593Smuzhiyun  *
479*4882a593Smuzhiyun  * This structure collects information about a station that
480*4882a593Smuzhiyun  * mac80211 is communicating with.
481*4882a593Smuzhiyun  *
482*4882a593Smuzhiyun  * @list: global linked list entry
483*4882a593Smuzhiyun  * @free_list: list entry for keeping track of stations to free
484*4882a593Smuzhiyun  * @hash_node: hash node for rhashtable
485*4882a593Smuzhiyun  * @addr: station's MAC address - duplicated from public part to
486*4882a593Smuzhiyun  *	let the hash table work with just a single cacheline
487*4882a593Smuzhiyun  * @local: pointer to the global information
488*4882a593Smuzhiyun  * @sdata: virtual interface this station belongs to
489*4882a593Smuzhiyun  * @ptk: peer keys negotiated with this station, if any
490*4882a593Smuzhiyun  * @ptk_idx: last installed peer key index
491*4882a593Smuzhiyun  * @gtk: group keys negotiated with this station, if any
492*4882a593Smuzhiyun  * @rate_ctrl: rate control algorithm reference
493*4882a593Smuzhiyun  * @rate_ctrl_lock: spinlock used to protect rate control data
494*4882a593Smuzhiyun  *	(data inside the algorithm, so serializes calls there)
495*4882a593Smuzhiyun  * @rate_ctrl_priv: rate control private per-STA pointer
496*4882a593Smuzhiyun  * @lock: used for locking all fields that require locking, see comments
497*4882a593Smuzhiyun  *	in the header file.
498*4882a593Smuzhiyun  * @drv_deliver_wk: used for delivering frames after driver PS unblocking
499*4882a593Smuzhiyun  * @listen_interval: listen interval of this station, when we're acting as AP
500*4882a593Smuzhiyun  * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly
501*4882a593Smuzhiyun  * @ps_lock: used for powersave (when mac80211 is the AP) related locking
502*4882a593Smuzhiyun  * @ps_tx_buf: buffers (per AC) of frames to transmit to this station
503*4882a593Smuzhiyun  *	when it leaves power saving state or polls
504*4882a593Smuzhiyun  * @tx_filtered: buffers (per AC) of frames we already tried to
505*4882a593Smuzhiyun  *	transmit but were filtered by hardware due to STA having
506*4882a593Smuzhiyun  *	entered power saving state, these are also delivered to
507*4882a593Smuzhiyun  *	the station when it leaves powersave or polls for frames
508*4882a593Smuzhiyun  * @driver_buffered_tids: bitmap of TIDs the driver has data buffered on
509*4882a593Smuzhiyun  * @txq_buffered_tids: bitmap of TIDs that mac80211 has txq data buffered on
510*4882a593Smuzhiyun  * @assoc_at: clock boottime (in ns) of last association
511*4882a593Smuzhiyun  * @last_connected: time (in seconds) when a station got connected
512*4882a593Smuzhiyun  * @last_seq_ctrl: last received seq/frag number from this STA (per TID
513*4882a593Smuzhiyun  *	plus one for non-QoS frames)
514*4882a593Smuzhiyun  * @tid_seq: per-TID sequence numbers for sending to this STA
515*4882a593Smuzhiyun  * @airtime: per-AC struct airtime_info describing airtime statistics for this
516*4882a593Smuzhiyun  *	station
517*4882a593Smuzhiyun  * @airtime_weight: station weight for airtime fairness calculation purposes
518*4882a593Smuzhiyun  * @ampdu_mlme: A-MPDU state machine state
519*4882a593Smuzhiyun  * @mesh: mesh STA information
520*4882a593Smuzhiyun  * @debugfs_dir: debug filesystem directory dentry
521*4882a593Smuzhiyun  * @dead: set to true when sta is unlinked
522*4882a593Smuzhiyun  * @removed: set to true when sta is being removed from sta_list
523*4882a593Smuzhiyun  * @uploaded: set to true when sta is uploaded to the driver
524*4882a593Smuzhiyun  * @sta: station information we share with the driver
525*4882a593Smuzhiyun  * @sta_state: duplicates information about station state (for debug)
526*4882a593Smuzhiyun  * @rcu_head: RCU head used for freeing this station struct
527*4882a593Smuzhiyun  * @cur_max_bandwidth: maximum bandwidth to use for TX to the station,
528*4882a593Smuzhiyun  *	taken from HT/VHT capabilities or VHT operating mode notification
529*4882a593Smuzhiyun  * @known_smps_mode: the smps_mode the client thinks we are in. Relevant for
530*4882a593Smuzhiyun  *	AP only.
531*4882a593Smuzhiyun  * @cipher_scheme: optional cipher scheme for this station
532*4882a593Smuzhiyun  * @cparams: CoDel parameters for this station.
533*4882a593Smuzhiyun  * @reserved_tid: reserved TID (if any, otherwise IEEE80211_TID_UNRESERVED)
534*4882a593Smuzhiyun  * @fast_tx: TX fastpath information
535*4882a593Smuzhiyun  * @fast_rx: RX fastpath information
536*4882a593Smuzhiyun  * @tdls_chandef: a TDLS peer can have a wider chandef that is compatible to
537*4882a593Smuzhiyun  *	the BSS one.
538*4882a593Smuzhiyun  * @tx_stats: TX statistics
539*4882a593Smuzhiyun  * @tx_stats.packets: # of packets transmitted
540*4882a593Smuzhiyun  * @tx_stats.bytes: # of bytes in all packets transmitted
541*4882a593Smuzhiyun  * @tx_stats.last_rate: last TX rate
542*4882a593Smuzhiyun  * @tx_stats.msdu: # of transmitted MSDUs per TID
543*4882a593Smuzhiyun  * @rx_stats: RX statistics
544*4882a593Smuzhiyun  * @rx_stats_avg: averaged RX statistics
545*4882a593Smuzhiyun  * @rx_stats_avg.signal: averaged signal
546*4882a593Smuzhiyun  * @rx_stats_avg.chain_signal: averaged per-chain signal
547*4882a593Smuzhiyun  * @pcpu_rx_stats: per-CPU RX statistics, assigned only if the driver needs
548*4882a593Smuzhiyun  *	this (by advertising the USES_RSS hw flag)
549*4882a593Smuzhiyun  * @status_stats: TX status statistics
550*4882a593Smuzhiyun  * @status_stats.filtered: # of filtered frames
551*4882a593Smuzhiyun  * @status_stats.retry_failed: # of frames that failed after retry
552*4882a593Smuzhiyun  * @status_stats.retry_count: # of retries attempted
553*4882a593Smuzhiyun  * @status_stats.lost_packets: # of lost packets
554*4882a593Smuzhiyun  * @status_stats.last_pkt_time: timestamp of last ACKed packet
555*4882a593Smuzhiyun  * @status_stats.msdu_retries: # of MSDU retries
556*4882a593Smuzhiyun  * @status_stats.msdu_failed: # of failed MSDUs
557*4882a593Smuzhiyun  * @status_stats.last_ack: last ack timestamp (jiffies)
558*4882a593Smuzhiyun  * @status_stats.last_ack_signal: last ACK signal
559*4882a593Smuzhiyun  * @status_stats.ack_signal_filled: last ACK signal validity
560*4882a593Smuzhiyun  * @status_stats.avg_ack_signal: average ACK signal
561*4882a593Smuzhiyun  * @frags: fragment cache
562*4882a593Smuzhiyun  */
563*4882a593Smuzhiyun struct sta_info {
564*4882a593Smuzhiyun 	/* General information, mostly static */
565*4882a593Smuzhiyun 	struct list_head list, free_list;
566*4882a593Smuzhiyun 	struct rcu_head rcu_head;
567*4882a593Smuzhiyun 	struct rhlist_head hash_node;
568*4882a593Smuzhiyun 	u8 addr[ETH_ALEN];
569*4882a593Smuzhiyun 	struct ieee80211_local *local;
570*4882a593Smuzhiyun 	struct ieee80211_sub_if_data *sdata;
571*4882a593Smuzhiyun 	struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS +
572*4882a593Smuzhiyun 					NUM_DEFAULT_MGMT_KEYS +
573*4882a593Smuzhiyun 					NUM_DEFAULT_BEACON_KEYS];
574*4882a593Smuzhiyun 	struct ieee80211_key __rcu *ptk[NUM_DEFAULT_KEYS];
575*4882a593Smuzhiyun 	u8 ptk_idx;
576*4882a593Smuzhiyun 	struct rate_control_ref *rate_ctrl;
577*4882a593Smuzhiyun 	void *rate_ctrl_priv;
578*4882a593Smuzhiyun 	spinlock_t rate_ctrl_lock;
579*4882a593Smuzhiyun 	spinlock_t lock;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	struct ieee80211_fast_tx __rcu *fast_tx;
582*4882a593Smuzhiyun 	struct ieee80211_fast_rx __rcu *fast_rx;
583*4882a593Smuzhiyun 	struct ieee80211_sta_rx_stats __percpu *pcpu_rx_stats;
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_MESH
586*4882a593Smuzhiyun 	struct mesh_sta *mesh;
587*4882a593Smuzhiyun #endif
588*4882a593Smuzhiyun 
589*4882a593Smuzhiyun 	struct work_struct drv_deliver_wk;
590*4882a593Smuzhiyun 
591*4882a593Smuzhiyun 	u16 listen_interval;
592*4882a593Smuzhiyun 
593*4882a593Smuzhiyun 	bool dead;
594*4882a593Smuzhiyun 	bool removed;
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun 	bool uploaded;
597*4882a593Smuzhiyun 
598*4882a593Smuzhiyun 	enum ieee80211_sta_state sta_state;
599*4882a593Smuzhiyun 
600*4882a593Smuzhiyun 	/* use the accessors defined below */
601*4882a593Smuzhiyun 	unsigned long _flags;
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 	/* STA powersave lock and frame queues */
604*4882a593Smuzhiyun 	spinlock_t ps_lock;
605*4882a593Smuzhiyun 	struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
606*4882a593Smuzhiyun 	struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
607*4882a593Smuzhiyun 	unsigned long driver_buffered_tids;
608*4882a593Smuzhiyun 	unsigned long txq_buffered_tids;
609*4882a593Smuzhiyun 
610*4882a593Smuzhiyun 	u64 assoc_at;
611*4882a593Smuzhiyun 	long last_connected;
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	/* Updated from RX path only, no locking requirements */
614*4882a593Smuzhiyun 	struct ieee80211_sta_rx_stats rx_stats;
615*4882a593Smuzhiyun 	struct {
616*4882a593Smuzhiyun 		struct ewma_signal signal;
617*4882a593Smuzhiyun 		struct ewma_signal chain_signal[IEEE80211_MAX_CHAINS];
618*4882a593Smuzhiyun 	} rx_stats_avg;
619*4882a593Smuzhiyun 
620*4882a593Smuzhiyun 	/* Plus 1 for non-QoS frames */
621*4882a593Smuzhiyun 	__le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
622*4882a593Smuzhiyun 
623*4882a593Smuzhiyun 	/* Updated from TX status path only, no locking requirements */
624*4882a593Smuzhiyun 	struct {
625*4882a593Smuzhiyun 		unsigned long filtered;
626*4882a593Smuzhiyun 		unsigned long retry_failed, retry_count;
627*4882a593Smuzhiyun 		unsigned int lost_packets;
628*4882a593Smuzhiyun 		unsigned long last_pkt_time;
629*4882a593Smuzhiyun 		u64 msdu_retries[IEEE80211_NUM_TIDS + 1];
630*4882a593Smuzhiyun 		u64 msdu_failed[IEEE80211_NUM_TIDS + 1];
631*4882a593Smuzhiyun 		unsigned long last_ack;
632*4882a593Smuzhiyun 		s8 last_ack_signal;
633*4882a593Smuzhiyun 		bool ack_signal_filled;
634*4882a593Smuzhiyun 		struct ewma_avg_signal avg_ack_signal;
635*4882a593Smuzhiyun 	} status_stats;
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun 	/* Updated from TX path only, no locking requirements */
638*4882a593Smuzhiyun 	struct {
639*4882a593Smuzhiyun 		u64 packets[IEEE80211_NUM_ACS];
640*4882a593Smuzhiyun 		u64 bytes[IEEE80211_NUM_ACS];
641*4882a593Smuzhiyun 		struct ieee80211_tx_rate last_rate;
642*4882a593Smuzhiyun 		struct rate_info last_rate_info;
643*4882a593Smuzhiyun 		u64 msdu[IEEE80211_NUM_TIDS + 1];
644*4882a593Smuzhiyun 	} tx_stats;
645*4882a593Smuzhiyun 	u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
646*4882a593Smuzhiyun 
647*4882a593Smuzhiyun 	struct airtime_info airtime[IEEE80211_NUM_ACS];
648*4882a593Smuzhiyun 	u16 airtime_weight;
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 	/*
651*4882a593Smuzhiyun 	 * Aggregation information, locked with lock.
652*4882a593Smuzhiyun 	 */
653*4882a593Smuzhiyun 	struct sta_ampdu_mlme ampdu_mlme;
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_DEBUGFS
656*4882a593Smuzhiyun 	struct dentry *debugfs_dir;
657*4882a593Smuzhiyun #endif
658*4882a593Smuzhiyun 
659*4882a593Smuzhiyun 	enum ieee80211_sta_rx_bandwidth cur_max_bandwidth;
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 	enum ieee80211_smps_mode known_smps_mode;
662*4882a593Smuzhiyun 	const struct ieee80211_cipher_scheme *cipher_scheme;
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	struct codel_params cparams;
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	u8 reserved_tid;
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 	struct cfg80211_chan_def tdls_chandef;
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 	struct ieee80211_fragment_cache frags;
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun 	/* keep last! */
673*4882a593Smuzhiyun 	struct ieee80211_sta sta;
674*4882a593Smuzhiyun };
675*4882a593Smuzhiyun 
sta_plink_state(struct sta_info * sta)676*4882a593Smuzhiyun static inline enum nl80211_plink_state sta_plink_state(struct sta_info *sta)
677*4882a593Smuzhiyun {
678*4882a593Smuzhiyun #ifdef CONFIG_MAC80211_MESH
679*4882a593Smuzhiyun 	return sta->mesh->plink_state;
680*4882a593Smuzhiyun #endif
681*4882a593Smuzhiyun 	return NL80211_PLINK_LISTEN;
682*4882a593Smuzhiyun }
683*4882a593Smuzhiyun 
set_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)684*4882a593Smuzhiyun static inline void set_sta_flag(struct sta_info *sta,
685*4882a593Smuzhiyun 				enum ieee80211_sta_info_flags flag)
686*4882a593Smuzhiyun {
687*4882a593Smuzhiyun 	WARN_ON(flag == WLAN_STA_AUTH ||
688*4882a593Smuzhiyun 		flag == WLAN_STA_ASSOC ||
689*4882a593Smuzhiyun 		flag == WLAN_STA_AUTHORIZED);
690*4882a593Smuzhiyun 	set_bit(flag, &sta->_flags);
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun 
clear_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)693*4882a593Smuzhiyun static inline void clear_sta_flag(struct sta_info *sta,
694*4882a593Smuzhiyun 				  enum ieee80211_sta_info_flags flag)
695*4882a593Smuzhiyun {
696*4882a593Smuzhiyun 	WARN_ON(flag == WLAN_STA_AUTH ||
697*4882a593Smuzhiyun 		flag == WLAN_STA_ASSOC ||
698*4882a593Smuzhiyun 		flag == WLAN_STA_AUTHORIZED);
699*4882a593Smuzhiyun 	clear_bit(flag, &sta->_flags);
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun 
test_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)702*4882a593Smuzhiyun static inline int test_sta_flag(struct sta_info *sta,
703*4882a593Smuzhiyun 				enum ieee80211_sta_info_flags flag)
704*4882a593Smuzhiyun {
705*4882a593Smuzhiyun 	return test_bit(flag, &sta->_flags);
706*4882a593Smuzhiyun }
707*4882a593Smuzhiyun 
test_and_clear_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)708*4882a593Smuzhiyun static inline int test_and_clear_sta_flag(struct sta_info *sta,
709*4882a593Smuzhiyun 					  enum ieee80211_sta_info_flags flag)
710*4882a593Smuzhiyun {
711*4882a593Smuzhiyun 	WARN_ON(flag == WLAN_STA_AUTH ||
712*4882a593Smuzhiyun 		flag == WLAN_STA_ASSOC ||
713*4882a593Smuzhiyun 		flag == WLAN_STA_AUTHORIZED);
714*4882a593Smuzhiyun 	return test_and_clear_bit(flag, &sta->_flags);
715*4882a593Smuzhiyun }
716*4882a593Smuzhiyun 
test_and_set_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)717*4882a593Smuzhiyun static inline int test_and_set_sta_flag(struct sta_info *sta,
718*4882a593Smuzhiyun 					enum ieee80211_sta_info_flags flag)
719*4882a593Smuzhiyun {
720*4882a593Smuzhiyun 	WARN_ON(flag == WLAN_STA_AUTH ||
721*4882a593Smuzhiyun 		flag == WLAN_STA_ASSOC ||
722*4882a593Smuzhiyun 		flag == WLAN_STA_AUTHORIZED);
723*4882a593Smuzhiyun 	return test_and_set_bit(flag, &sta->_flags);
724*4882a593Smuzhiyun }
725*4882a593Smuzhiyun 
726*4882a593Smuzhiyun int sta_info_move_state(struct sta_info *sta,
727*4882a593Smuzhiyun 			enum ieee80211_sta_state new_state);
728*4882a593Smuzhiyun 
sta_info_pre_move_state(struct sta_info * sta,enum ieee80211_sta_state new_state)729*4882a593Smuzhiyun static inline void sta_info_pre_move_state(struct sta_info *sta,
730*4882a593Smuzhiyun 					   enum ieee80211_sta_state new_state)
731*4882a593Smuzhiyun {
732*4882a593Smuzhiyun 	int ret;
733*4882a593Smuzhiyun 
734*4882a593Smuzhiyun 	WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 	ret = sta_info_move_state(sta, new_state);
737*4882a593Smuzhiyun 	WARN_ON_ONCE(ret);
738*4882a593Smuzhiyun }
739*4882a593Smuzhiyun 
740*4882a593Smuzhiyun 
741*4882a593Smuzhiyun void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
742*4882a593Smuzhiyun 			     struct tid_ampdu_tx *tid_tx);
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun static inline struct tid_ampdu_tx *
rcu_dereference_protected_tid_tx(struct sta_info * sta,int tid)745*4882a593Smuzhiyun rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)
746*4882a593Smuzhiyun {
747*4882a593Smuzhiyun 	return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
748*4882a593Smuzhiyun 					 lockdep_is_held(&sta->lock) ||
749*4882a593Smuzhiyun 					 lockdep_is_held(&sta->ampdu_mlme.mtx));
750*4882a593Smuzhiyun }
751*4882a593Smuzhiyun 
752*4882a593Smuzhiyun /* Maximum number of frames to buffer per power saving station per AC */
753*4882a593Smuzhiyun #define STA_MAX_TX_BUFFER	64
754*4882a593Smuzhiyun 
755*4882a593Smuzhiyun /* Minimum buffered frame expiry time. If STA uses listen interval that is
756*4882a593Smuzhiyun  * smaller than this value, the minimum value here is used instead. */
757*4882a593Smuzhiyun #define STA_TX_BUFFER_EXPIRE (10 * HZ)
758*4882a593Smuzhiyun 
759*4882a593Smuzhiyun /* How often station data is cleaned up (e.g., expiration of buffered frames)
760*4882a593Smuzhiyun  */
761*4882a593Smuzhiyun #define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
762*4882a593Smuzhiyun 
763*4882a593Smuzhiyun struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
764*4882a593Smuzhiyun 					 const u8 *addr);
765*4882a593Smuzhiyun 
766*4882a593Smuzhiyun /*
767*4882a593Smuzhiyun  * Get a STA info, must be under RCU read lock.
768*4882a593Smuzhiyun  */
769*4882a593Smuzhiyun struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
770*4882a593Smuzhiyun 			      const u8 *addr);
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
773*4882a593Smuzhiyun 				  const u8 *addr);
774*4882a593Smuzhiyun 
775*4882a593Smuzhiyun /* user must hold sta_mtx or be in RCU critical section */
776*4882a593Smuzhiyun struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
777*4882a593Smuzhiyun 				       const u8 *sta_addr, const u8 *vif_addr);
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun #define for_each_sta_info(local, _addr, _sta, _tmp)			\
780*4882a593Smuzhiyun 	rhl_for_each_entry_rcu(_sta, _tmp,				\
781*4882a593Smuzhiyun 			       sta_info_hash_lookup(local, _addr), hash_node)
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun /*
784*4882a593Smuzhiyun  * Get STA info by index, BROKEN!
785*4882a593Smuzhiyun  */
786*4882a593Smuzhiyun struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
787*4882a593Smuzhiyun 				     int idx);
788*4882a593Smuzhiyun /*
789*4882a593Smuzhiyun  * Create a new STA info, caller owns returned structure
790*4882a593Smuzhiyun  * until sta_info_insert().
791*4882a593Smuzhiyun  */
792*4882a593Smuzhiyun struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
793*4882a593Smuzhiyun 				const u8 *addr, gfp_t gfp);
794*4882a593Smuzhiyun 
795*4882a593Smuzhiyun void sta_info_free(struct ieee80211_local *local, struct sta_info *sta);
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun /*
798*4882a593Smuzhiyun  * Insert STA info into hash table/list, returns zero or a
799*4882a593Smuzhiyun  * -EEXIST if (if the same MAC address is already present).
800*4882a593Smuzhiyun  *
801*4882a593Smuzhiyun  * Calling the non-rcu version makes the caller relinquish,
802*4882a593Smuzhiyun  * the _rcu version calls read_lock_rcu() and must be called
803*4882a593Smuzhiyun  * without it held.
804*4882a593Smuzhiyun  */
805*4882a593Smuzhiyun int sta_info_insert(struct sta_info *sta);
806*4882a593Smuzhiyun int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU);
807*4882a593Smuzhiyun 
808*4882a593Smuzhiyun int __must_check __sta_info_destroy(struct sta_info *sta);
809*4882a593Smuzhiyun int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata,
810*4882a593Smuzhiyun 			  const u8 *addr);
811*4882a593Smuzhiyun int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
812*4882a593Smuzhiyun 			      const u8 *addr);
813*4882a593Smuzhiyun 
814*4882a593Smuzhiyun void sta_info_recalc_tim(struct sta_info *sta);
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun int sta_info_init(struct ieee80211_local *local);
817*4882a593Smuzhiyun void sta_info_stop(struct ieee80211_local *local);
818*4882a593Smuzhiyun 
819*4882a593Smuzhiyun /**
820*4882a593Smuzhiyun  * __sta_info_flush - flush matching STA entries from the STA table
821*4882a593Smuzhiyun  *
822*4882a593Smuzhiyun  * Returns the number of removed STA entries.
823*4882a593Smuzhiyun  *
824*4882a593Smuzhiyun  * @sdata: sdata to remove all stations from
825*4882a593Smuzhiyun  * @vlans: if the given interface is an AP interface, also flush VLANs
826*4882a593Smuzhiyun  */
827*4882a593Smuzhiyun int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans);
828*4882a593Smuzhiyun 
829*4882a593Smuzhiyun /**
830*4882a593Smuzhiyun  * sta_info_flush - flush matching STA entries from the STA table
831*4882a593Smuzhiyun  *
832*4882a593Smuzhiyun  * Returns the number of removed STA entries.
833*4882a593Smuzhiyun  *
834*4882a593Smuzhiyun  * @sdata: sdata to remove all stations from
835*4882a593Smuzhiyun  */
sta_info_flush(struct ieee80211_sub_if_data * sdata)836*4882a593Smuzhiyun static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata)
837*4882a593Smuzhiyun {
838*4882a593Smuzhiyun 	return __sta_info_flush(sdata, false);
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun 
841*4882a593Smuzhiyun void sta_set_rate_info_tx(struct sta_info *sta,
842*4882a593Smuzhiyun 			  const struct ieee80211_tx_rate *rate,
843*4882a593Smuzhiyun 			  struct rate_info *rinfo);
844*4882a593Smuzhiyun void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
845*4882a593Smuzhiyun 		   bool tidstats);
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun u32 sta_get_expected_throughput(struct sta_info *sta);
848*4882a593Smuzhiyun 
849*4882a593Smuzhiyun void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
850*4882a593Smuzhiyun 			  unsigned long exp_time);
851*4882a593Smuzhiyun u8 sta_info_tx_streams(struct sta_info *sta);
852*4882a593Smuzhiyun 
853*4882a593Smuzhiyun void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta);
854*4882a593Smuzhiyun void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta);
855*4882a593Smuzhiyun void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta);
856*4882a593Smuzhiyun 
857*4882a593Smuzhiyun unsigned long ieee80211_sta_last_active(struct sta_info *sta);
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun enum sta_stats_type {
860*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_INVALID = 0,
861*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_LEGACY,
862*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_HT,
863*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_VHT,
864*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_HE,
865*4882a593Smuzhiyun 	STA_STATS_RATE_TYPE_S1G,
866*4882a593Smuzhiyun };
867*4882a593Smuzhiyun 
868*4882a593Smuzhiyun #define STA_STATS_FIELD_HT_MCS		GENMASK( 7,  0)
869*4882a593Smuzhiyun #define STA_STATS_FIELD_LEGACY_IDX	GENMASK( 3,  0)
870*4882a593Smuzhiyun #define STA_STATS_FIELD_LEGACY_BAND	GENMASK( 7,  4)
871*4882a593Smuzhiyun #define STA_STATS_FIELD_VHT_MCS		GENMASK( 3,  0)
872*4882a593Smuzhiyun #define STA_STATS_FIELD_VHT_NSS		GENMASK( 7,  4)
873*4882a593Smuzhiyun #define STA_STATS_FIELD_HE_MCS		GENMASK( 3,  0)
874*4882a593Smuzhiyun #define STA_STATS_FIELD_HE_NSS		GENMASK( 7,  4)
875*4882a593Smuzhiyun #define STA_STATS_FIELD_BW		GENMASK(11,  8)
876*4882a593Smuzhiyun #define STA_STATS_FIELD_SGI		GENMASK(12, 12)
877*4882a593Smuzhiyun #define STA_STATS_FIELD_TYPE		GENMASK(15, 13)
878*4882a593Smuzhiyun #define STA_STATS_FIELD_HE_RU		GENMASK(18, 16)
879*4882a593Smuzhiyun #define STA_STATS_FIELD_HE_GI		GENMASK(20, 19)
880*4882a593Smuzhiyun #define STA_STATS_FIELD_HE_DCM		GENMASK(21, 21)
881*4882a593Smuzhiyun 
882*4882a593Smuzhiyun #define STA_STATS_FIELD(_n, _v)		FIELD_PREP(STA_STATS_FIELD_ ## _n, _v)
883*4882a593Smuzhiyun #define STA_STATS_GET(_n, _v)		FIELD_GET(STA_STATS_FIELD_ ## _n, _v)
884*4882a593Smuzhiyun 
885*4882a593Smuzhiyun #define STA_STATS_RATE_INVALID		0
886*4882a593Smuzhiyun 
sta_stats_encode_rate(struct ieee80211_rx_status * s)887*4882a593Smuzhiyun static inline u32 sta_stats_encode_rate(struct ieee80211_rx_status *s)
888*4882a593Smuzhiyun {
889*4882a593Smuzhiyun 	u32 r;
890*4882a593Smuzhiyun 
891*4882a593Smuzhiyun 	r = STA_STATS_FIELD(BW, s->bw);
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun 	if (s->enc_flags & RX_ENC_FLAG_SHORT_GI)
894*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(SGI, 1);
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	switch (s->encoding) {
897*4882a593Smuzhiyun 	case RX_ENC_VHT:
898*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_VHT);
899*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(VHT_NSS, s->nss);
900*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(VHT_MCS, s->rate_idx);
901*4882a593Smuzhiyun 		break;
902*4882a593Smuzhiyun 	case RX_ENC_HT:
903*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HT);
904*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HT_MCS, s->rate_idx);
905*4882a593Smuzhiyun 		break;
906*4882a593Smuzhiyun 	case RX_ENC_LEGACY:
907*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_LEGACY);
908*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(LEGACY_BAND, s->band);
909*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(LEGACY_IDX, s->rate_idx);
910*4882a593Smuzhiyun 		break;
911*4882a593Smuzhiyun 	case RX_ENC_HE:
912*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HE);
913*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HE_NSS, s->nss);
914*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HE_MCS, s->rate_idx);
915*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HE_GI, s->he_gi);
916*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HE_RU, s->he_ru);
917*4882a593Smuzhiyun 		r |= STA_STATS_FIELD(HE_DCM, s->he_dcm);
918*4882a593Smuzhiyun 		break;
919*4882a593Smuzhiyun 	default:
920*4882a593Smuzhiyun 		WARN_ON(1);
921*4882a593Smuzhiyun 		return STA_STATS_RATE_INVALID;
922*4882a593Smuzhiyun 	}
923*4882a593Smuzhiyun 
924*4882a593Smuzhiyun 	return r;
925*4882a593Smuzhiyun }
926*4882a593Smuzhiyun 
927*4882a593Smuzhiyun #endif /* STA_INFO_H */
928