1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2f0706e82SJiri Benc /*
3f0706e82SJiri Benc * Copyright 2002-2005, Devicescape Software, Inc.
4d98ad83eSJohannes Berg * Copyright 2013-2014 Intel Mobile Communications GmbH
5da6a4352SJohannes Berg * Copyright(c) 2015-2017 Intel Deutschland GmbH
6*86e7bdc5SJohannes Berg * Copyright(c) 2020-2024 Intel Corporation
7f0706e82SJiri Benc */
8f0706e82SJiri Benc
9f0706e82SJiri Benc #ifndef STA_INFO_H
10f0706e82SJiri Benc #define STA_INFO_H
11f0706e82SJiri Benc
12f0706e82SJiri Benc #include <linux/list.h>
13f0706e82SJiri Benc #include <linux/types.h>
14f0706e82SJiri Benc #include <linux/if_ether.h>
15af818581SJohannes Berg #include <linux/workqueue.h>
16541a45a1SBruno Randolf #include <linux/average.h>
17dcba665bSJohannes Berg #include <linux/bitfield.h>
18888d04dfSFelix Fietkau #include <linux/etherdevice.h>
197bedd0cfSJohannes Berg #include <linux/rhashtable.h>
200f9c5a61SJohannes Berg #include <linux/u64_stats_sync.h>
212c8dccc7SJohannes Berg #include "key.h"
22f0706e82SJiri Benc
23238814fdSJohannes Berg /**
24238814fdSJohannes Berg * enum ieee80211_sta_info_flags - Stations flags
25238814fdSJohannes Berg *
26c2c98fdeSJohannes Berg * These flags are used with &struct sta_info's @flags member, but
27c2c98fdeSJohannes Berg * only indirectly with set_sta_flag() and friends.
28238814fdSJohannes Berg *
29238814fdSJohannes Berg * @WLAN_STA_AUTH: Station is authenticated.
30238814fdSJohannes Berg * @WLAN_STA_ASSOC: Station is associated.
31af818581SJohannes Berg * @WLAN_STA_PS_STA: Station is in power-save mode
32238814fdSJohannes Berg * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic.
33238814fdSJohannes Berg * This bit is always checked so needs to be enabled for all stations
34238814fdSJohannes Berg * when virtual port control is not in use.
35238814fdSJohannes Berg * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
36238814fdSJohannes Berg * frames.
37238814fdSJohannes Berg * @WLAN_STA_WDS: Station is one of our WDS peers.
38d46e144bSJohannes Berg * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
39e039fa4aSJohannes Berg * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
40d46e144bSJohannes Berg * frame to this station is transmitted.
415394af4dSJouni Malinen * @WLAN_STA_MFP: Management frame protection is used with this STA.
42618f356bSJohannes Berg * @WLAN_STA_BLOCK_BA: Used to deny ADDBA requests (both TX and RX)
43098a6070SJohannes Berg * during suspend/resume and station removal.
44af818581SJohannes Berg * @WLAN_STA_PS_DRIVER: driver requires keeping this station in
45af818581SJohannes Berg * power-save mode logically to flush frames that might still
46af818581SJohannes Berg * be in the queues
47af818581SJohannes Berg * @WLAN_STA_PSPOLL: Station sent PS-poll while driver was keeping
48af818581SJohannes Berg * station in power-save mode, reply when the driver unblocks.
49941c93cdSArik Nemtsov * @WLAN_STA_TDLS_PEER: Station is a TDLS peer.
50941c93cdSArik Nemtsov * @WLAN_STA_TDLS_PEER_AUTH: This TDLS peer is authorized to send direct
51941c93cdSArik Nemtsov * packets. This means the link is enabled.
52626911ccSArik Nemtsov * @WLAN_STA_TDLS_INITIATOR: We are the initiator of the TDLS link with this
53626911ccSArik Nemtsov * station.
549041c1faSArik Nemtsov * @WLAN_STA_TDLS_CHAN_SWITCH: This TDLS peer supports TDLS channel-switching
55a7a6bdd0SArik Nemtsov * @WLAN_STA_TDLS_OFF_CHANNEL: The local STA is currently off-channel with this
56a7a6bdd0SArik Nemtsov * TDLS peer
57b98fb44fSArik Nemtsov * @WLAN_STA_TDLS_WIDER_BW: This TDLS peer supports working on a wider bw on
58b98fb44fSArik Nemtsov * the BSS base channel.
5947086fc5SJohannes Berg * @WLAN_STA_UAPSD: Station requested unscheduled SP while driver was
6047086fc5SJohannes Berg * keeping station in power-save mode, reply when the driver
6147086fc5SJohannes Berg * unblocks the station.
6247086fc5SJohannes Berg * @WLAN_STA_SP: Station is in a service period, so don't try to
63deeaee19SJohannes Berg * reply to other uAPSD trigger frames or PS-Poll.
64e7f4a940SJohannes Berg * @WLAN_STA_4ADDR_EVENT: 4-addr event was already sent for this frame.
6583d5cc01SJohannes Berg * @WLAN_STA_INSERTED: This station is inserted into the hash table.
66e1936e94SJohannes Berg * @WLAN_STA_RATE_CONTROL: rate control was initialized for this station.
67dbf498fbSJavier Cardona * @WLAN_STA_TOFFSET_KNOWN: toffset calculated for this station is valid.
683f52b7e3SMarco Porsch * @WLAN_STA_MPSP_OWNER: local STA is owner of a mesh Peer Service Period.
693f52b7e3SMarco Porsch * @WLAN_STA_MPSP_RECIPIENT: local STA is recipient of a MPSP.
705ac2e350SJohannes Berg * @WLAN_STA_PS_DELIVER: station woke up, but we're still blocking TX
715ac2e350SJohannes Berg * until pending frames are delivered
72b6b5c42eSJohannes Berg * @WLAN_STA_USES_ENCRYPTION: This station was configured for encryption,
73b6b5c42eSJohannes Berg * so drop all packets without a key later.
7480a915ecSFelix Fietkau * @WLAN_STA_DECAP_OFFLOAD: This station uses rx decap offload
75c84387d2SJohannes Berg *
76c84387d2SJohannes Berg * @NUM_WLAN_STA_FLAGS: number of defined flags
77f0706e82SJiri Benc */
78238814fdSJohannes Berg enum ieee80211_sta_info_flags {
79c2c98fdeSJohannes Berg WLAN_STA_AUTH,
80c2c98fdeSJohannes Berg WLAN_STA_ASSOC,
81c2c98fdeSJohannes Berg WLAN_STA_PS_STA,
82c2c98fdeSJohannes Berg WLAN_STA_AUTHORIZED,
83c2c98fdeSJohannes Berg WLAN_STA_SHORT_PREAMBLE,
84c2c98fdeSJohannes Berg WLAN_STA_WDS,
85c2c98fdeSJohannes Berg WLAN_STA_CLEAR_PS_FILT,
86c2c98fdeSJohannes Berg WLAN_STA_MFP,
87c2c98fdeSJohannes Berg WLAN_STA_BLOCK_BA,
88c2c98fdeSJohannes Berg WLAN_STA_PS_DRIVER,
89c2c98fdeSJohannes Berg WLAN_STA_PSPOLL,
90c2c98fdeSJohannes Berg WLAN_STA_TDLS_PEER,
91c2c98fdeSJohannes Berg WLAN_STA_TDLS_PEER_AUTH,
92626911ccSArik Nemtsov WLAN_STA_TDLS_INITIATOR,
939041c1faSArik Nemtsov WLAN_STA_TDLS_CHAN_SWITCH,
94a7a6bdd0SArik Nemtsov WLAN_STA_TDLS_OFF_CHANNEL,
95b98fb44fSArik Nemtsov WLAN_STA_TDLS_WIDER_BW,
96c2c98fdeSJohannes Berg WLAN_STA_UAPSD,
97c2c98fdeSJohannes Berg WLAN_STA_SP,
98e7f4a940SJohannes Berg WLAN_STA_4ADDR_EVENT,
9983d5cc01SJohannes Berg WLAN_STA_INSERTED,
100e1936e94SJohannes Berg WLAN_STA_RATE_CONTROL,
101dbf498fbSJavier Cardona WLAN_STA_TOFFSET_KNOWN,
1023f52b7e3SMarco Porsch WLAN_STA_MPSP_OWNER,
1033f52b7e3SMarco Porsch WLAN_STA_MPSP_RECIPIENT,
1045ac2e350SJohannes Berg WLAN_STA_PS_DELIVER,
105a0761a30SJohannes Berg WLAN_STA_USES_ENCRYPTION,
10680a915ecSFelix Fietkau WLAN_STA_DECAP_OFFLOAD,
107c84387d2SJohannes Berg
108c84387d2SJohannes Berg NUM_WLAN_STA_FLAGS,
109238814fdSJohannes Berg };
110f0706e82SJiri Benc
1115aae2880SRon Rindjunsky #define ADDBA_RESP_INTERVAL HZ
11284381b4eSNikolay Martynov #define HT_AGG_MAX_RETRIES 15
11384381b4eSNikolay Martynov #define HT_AGG_BURST_RETRIES 3
11484381b4eSNikolay Martynov #define HT_AGG_RETRIES_PERIOD (15 * HZ)
1155aae2880SRon Rindjunsky
116a622ab72SJohannes Berg #define HT_AGG_STATE_DRV_READY 0
117a622ab72SJohannes Berg #define HT_AGG_STATE_RESPONSE_RECEIVED 1
118a622ab72SJohannes Berg #define HT_AGG_STATE_OPERATIONAL 2
119a622ab72SJohannes Berg #define HT_AGG_STATE_STOPPING 3
1200ab33703SJohannes Berg #define HT_AGG_STATE_WANT_START 4
1210ab33703SJohannes Berg #define HT_AGG_STATE_WANT_STOP 5
1227a7c0a64SJohannes Berg #define HT_AGG_STATE_START_CB 6
1237a7c0a64SJohannes Berg #define HT_AGG_STATE_STOP_CB 7
1240c197f16SMordechay Goodstein #define HT_AGG_STATE_SENT_ADDBA 8
12580656c20SRon Rindjunsky
126cc60dbbfSBalaji Pothunoori DECLARE_EWMA(avg_signal, 10, 8)
127c82c4a80SJohannes Berg enum ieee80211_agg_stop_reason {
128c82c4a80SJohannes Berg AGG_STOP_DECLINED,
129c82c4a80SJohannes Berg AGG_STOP_LOCAL_REQUEST,
130c82c4a80SJohannes Berg AGG_STOP_PEER_REQUEST,
131c82c4a80SJohannes Berg AGG_STOP_DESTROY_STA,
132c82c4a80SJohannes Berg };
133c82c4a80SJohannes Berg
134b4809e94SToke Høiland-Jørgensen /* Debugfs flags to enable/disable use of RX/TX airtime in scheduler */
135b4809e94SToke Høiland-Jørgensen #define AIRTIME_USE_TX BIT(0)
136b4809e94SToke Høiland-Jørgensen #define AIRTIME_USE_RX BIT(1)
137b4809e94SToke Høiland-Jørgensen
138b4809e94SToke Høiland-Jørgensen struct airtime_info {
139b4809e94SToke Høiland-Jørgensen u64 rx_airtime;
140b4809e94SToke Høiland-Jørgensen u64 tx_airtime;
1418ccc0702SFelix Fietkau u32 last_active;
142445452d4SFelix Fietkau s32 deficit;
1433ace10f5SKan Yan atomic_t aql_tx_pending; /* Estimated airtime for frames pending */
1443ace10f5SKan Yan u32 aql_limit_low;
1453ace10f5SKan Yan u32 aql_limit_high;
146b4809e94SToke Høiland-Jørgensen };
147b4809e94SToke Høiland-Jørgensen
1483ace10f5SKan Yan void ieee80211_sta_update_pending_airtime(struct ieee80211_local *local,
1493ace10f5SKan Yan struct sta_info *sta, u8 ac,
1503ace10f5SKan Yan u16 tx_airtime, bool tx_completed);
1513ace10f5SKan Yan
1527cca2acdSKees Cook struct sta_info;
1537cca2acdSKees Cook
15480656c20SRon Rindjunsky /**
15580656c20SRon Rindjunsky * struct tid_ampdu_tx - TID aggregation information (Tx).
15680656c20SRon Rindjunsky *
157a622ab72SJohannes Berg * @rcu_head: rcu head for freeing structure
158285fa695SNikolay Martynov * @session_timer: check if we keep Tx-ing on the TID (by timeout value)
15980656c20SRon Rindjunsky * @addba_resp_timer: timer for peer's response to addba request
160cd8ffc80SJohannes Berg * @pending: pending frames queue -- use sta's spinlock to protect
1617cca2acdSKees Cook * @sta: station we are attached to
162cee24a3eSRon Rindjunsky * @dialog_token: dialog token for aggregation session
163bd2ce6e4SSujith Manoharan * @timeout: session timeout value to be filled in ADDBA requests
1647cca2acdSKees Cook * @tid: TID number
165a622ab72SJohannes Berg * @state: session state (see above)
16612d3952fSFelix Fietkau * @last_tx: jiffies of last tx activity
167a622ab72SJohannes Berg * @stop_initiator: initiator of a session stop
16853f73c09SJohannes Berg * @tx_stop: TX DelBA frame when stopping
1690b01f030SJohannes Berg * @buf_size: reorder buffer size at receiver
170f0425bedSFelix Fietkau * @failed_bar_ssn: ssn of the last failed BAR tx attempt
171f0425bedSFelix Fietkau * @bar_pending: BAR needs to be re-sent
172e3abc8ffSEmmanuel Grumbach * @amsdu: support A-MSDU withing A-MDPU
173af9d3a29SJohannes Berg * @ssn: starting sequence number of the session
174a622ab72SJohannes Berg *
175dd318575SJohannes Berg * This structure's lifetime is managed by RCU, assignments to
176dd318575SJohannes Berg * the array holding it must hold the aggregation mutex.
177dd318575SJohannes Berg *
178dd318575SJohannes Berg * The TX path can access it under RCU lock-free if, and
179dd318575SJohannes Berg * only if, the state has the flag %HT_AGG_STATE_OPERATIONAL
180dd318575SJohannes Berg * set. Otherwise, the TX path must also acquire the spinlock
181dd318575SJohannes Berg * and re-check the state, see comments in the tx code
182dd318575SJohannes Berg * touching it.
18380656c20SRon Rindjunsky */
18480656c20SRon Rindjunsky struct tid_ampdu_tx {
185a622ab72SJohannes Berg struct rcu_head rcu_head;
186285fa695SNikolay Martynov struct timer_list session_timer;
18780656c20SRon Rindjunsky struct timer_list addba_resp_timer;
188cd8ffc80SJohannes Berg struct sk_buff_head pending;
1897cca2acdSKees Cook struct sta_info *sta;
190a622ab72SJohannes Berg unsigned long state;
19112d3952fSFelix Fietkau unsigned long last_tx;
192bd2ce6e4SSujith Manoharan u16 timeout;
193cee24a3eSRon Rindjunsky u8 dialog_token;
194a622ab72SJohannes Berg u8 stop_initiator;
19553f73c09SJohannes Berg bool tx_stop;
19641cbb0f5SLuca Coelho u16 buf_size;
19773111efaSFelix Fietkau u16 ssn;
198f0425bedSFelix Fietkau
199f0425bedSFelix Fietkau u16 failed_bar_ssn;
200f0425bedSFelix Fietkau bool bar_pending;
201e3abc8ffSEmmanuel Grumbach bool amsdu;
2027cca2acdSKees Cook u8 tid;
20380656c20SRon Rindjunsky };
2045aae2880SRon Rindjunsky
2055aae2880SRon Rindjunsky /**
2065aae2880SRon Rindjunsky * struct tid_ampdu_rx - TID aggregation information (Rx).
2075aae2880SRon Rindjunsky *
20883eb935eSMichal Kazior * @reorder_buf: buffer to reorder incoming aggregated MPDUs. An MPDU may be an
20983eb935eSMichal Kazior * A-MSDU with individually reported subframes.
21006470f74SSara Sharon * @reorder_buf_filtered: bitmap indicating where there are filtered frames in
21106470f74SSara Sharon * the reorder buffer that should be ignored when releasing frames
2124d050f1dSJouni Malinen * @reorder_time: jiffies when skb was added
2135aae2880SRon Rindjunsky * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
2142bff8ebfSChristian Lamparter * @reorder_timer: releases expired frames from the reorder buffer.
2157cca2acdSKees Cook * @sta: station we are attached to
21612d3952fSFelix Fietkau * @last_rx: jiffies of last rx activity
217056cdd59SJohannes Berg * @head_seq_num: head sequence number in reordering buffer.
218056cdd59SJohannes Berg * @stored_mpdu_num: number of MPDUs in reordering buffer
219cee24a3eSRon Rindjunsky * @ssn: Starting Sequence Number expected to be aggregated.
220cee24a3eSRon Rindjunsky * @buf_size: buffer size for incoming A-MPDUs
22120ad19d0SJohannes Berg * @timeout: reset timer value (in TUs).
2227cca2acdSKees Cook * @tid: TID number
223a87f736dSJohannes Berg * @rcu_head: RCU head used for freeing this struct
2242bff8ebfSChristian Lamparter * @reorder_lock: serializes access to reorder buffer, see below.
2254549cf2bSMichal Kazior * @auto_seq: used for offloaded BA sessions to automatically pick head_seq_and
2264549cf2bSMichal Kazior * and ssn.
227788211d8SJohannes Berg * @removed: this session is removed (but might have been found due to RCU)
228b7540d8fSSara Sharon * @started: this session has started (head ssn or higher was received)
229a87f736dSJohannes Berg *
230dd318575SJohannes Berg * This structure's lifetime is managed by RCU, assignments to
231dd318575SJohannes Berg * the array holding it must hold the aggregation mutex.
2322bff8ebfSChristian Lamparter *
233dd318575SJohannes Berg * The @reorder_lock is used to protect the members of this
234dd318575SJohannes Berg * struct, except for @timeout, @buf_size and @dialog_token,
235dd318575SJohannes Berg * which are constant across the lifetime of the struct (the
236dd318575SJohannes Berg * dialog token being used only for debugging).
2375aae2880SRon Rindjunsky */
2385aae2880SRon Rindjunsky struct tid_ampdu_rx {
239a87f736dSJohannes Berg struct rcu_head rcu_head;
2402bff8ebfSChristian Lamparter spinlock_t reorder_lock;
24106470f74SSara Sharon u64 reorder_buf_filtered;
24283eb935eSMichal Kazior struct sk_buff_head *reorder_buf;
2434d050f1dSJouni Malinen unsigned long *reorder_time;
2447cca2acdSKees Cook struct sta_info *sta;
2455aae2880SRon Rindjunsky struct timer_list session_timer;
2462bff8ebfSChristian Lamparter struct timer_list reorder_timer;
24712d3952fSFelix Fietkau unsigned long last_rx;
248056cdd59SJohannes Berg u16 head_seq_num;
249056cdd59SJohannes Berg u16 stored_mpdu_num;
250cee24a3eSRon Rindjunsky u16 ssn;
251cee24a3eSRon Rindjunsky u16 buf_size;
252cee24a3eSRon Rindjunsky u16 timeout;
2537cca2acdSKees Cook u8 tid;
254b7540d8fSSara Sharon u8 auto_seq:1,
255b7540d8fSSara Sharon removed:1,
256b7540d8fSSara Sharon started:1;
2575aae2880SRon Rindjunsky };
2585aae2880SRon Rindjunsky
259b4e08ea1SLuis Carlos Cobo /**
260fcea6007SJohannes Berg * struct sta_ampdu_mlme - STA aggregation information.
261fcea6007SJohannes Berg *
262412a6d80SSara Sharon * @mtx: mutex to protect all TX data (except non-NULL assignments
263412a6d80SSara Sharon * to tid_tx[idx], which are protected by the sta spinlock)
264412a6d80SSara Sharon * tid_start_tx is also protected by sta->lock.
265a87f736dSJohannes Berg * @tid_rx: aggregation info for Rx per TID -- RCU protected
2661c3d185aSJohannes Berg * @tid_rx_token: dialog tokens for valid aggregation sessions
2677c3b1dd8SJohannes Berg * @tid_rx_timer_expired: bitmap indicating on which TIDs the
2687c3b1dd8SJohannes Berg * RX timer expired until the work for it runs
269f41ccd71SShahar Levi * @tid_rx_stop_requested: bitmap indicating which BA sessions per TID the
270f41ccd71SShahar Levi * driver requested to close until the work for it runs
271699cb58cSJohannes Berg * @tid_rx_manage_offl: bitmap indicating which BA sessions were requested
272699cb58cSJohannes Berg * to be treated as started/stopped due to offloading
273412a6d80SSara Sharon * @agg_session_valid: bitmap indicating which TID has a rx BA session open on
274bfe40fa3SJohannes Berg * @unexpected_agg: bitmap indicating which TID already sent a delBA due to
275bfe40fa3SJohannes Berg * unexpected aggregation related frames outside a session
276412a6d80SSara Sharon * @work: work struct for starting/stopping aggregation
277412a6d80SSara Sharon * @tid_tx: aggregation info for Tx per TID
278412a6d80SSara Sharon * @tid_start_tx: sessions where start was requested
279412a6d80SSara Sharon * @last_addba_req_time: timestamp of the last addBA request.
280412a6d80SSara Sharon * @addba_req_num: number of times addBA request has been sent.
281412a6d80SSara Sharon * @dialog_token_allocator: dialog token enumerator for each new session;
282fcea6007SJohannes Berg */
283fcea6007SJohannes Berg struct sta_ampdu_mlme {
284a93e3644SJohannes Berg struct mutex mtx;
285fcea6007SJohannes Berg /* rx */
2865a306f58SJohannes Berg struct tid_ampdu_rx __rcu *tid_rx[IEEE80211_NUM_TIDS];
2871c3d185aSJohannes Berg u8 tid_rx_token[IEEE80211_NUM_TIDS];
2885a306f58SJohannes Berg unsigned long tid_rx_timer_expired[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
2895a306f58SJohannes Berg unsigned long tid_rx_stop_requested[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
290699cb58cSJohannes Berg unsigned long tid_rx_manage_offl[BITS_TO_LONGS(2 * IEEE80211_NUM_TIDS)];
291412a6d80SSara Sharon unsigned long agg_session_valid[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
292bfe40fa3SJohannes Berg unsigned long unexpected_agg[BITS_TO_LONGS(IEEE80211_NUM_TIDS)];
293fcea6007SJohannes Berg /* tx */
2940ab33703SJohannes Berg struct work_struct work;
2955a306f58SJohannes Berg struct tid_ampdu_tx __rcu *tid_tx[IEEE80211_NUM_TIDS];
2965a306f58SJohannes Berg struct tid_ampdu_tx *tid_start_tx[IEEE80211_NUM_TIDS];
2975a306f58SJohannes Berg unsigned long last_addba_req_time[IEEE80211_NUM_TIDS];
2985a306f58SJohannes Berg u8 addba_req_num[IEEE80211_NUM_TIDS];
299fcea6007SJohannes Berg u8 dialog_token_allocator;
300fcea6007SJohannes Berg };
301fcea6007SJohannes Berg
302fcea6007SJohannes Berg
303b6da911bSLiad Kaufman /* Value to indicate no TID reservation */
304b6da911bSLiad Kaufman #define IEEE80211_TID_UNRESERVED 0xff
305b6da911bSLiad Kaufman
306e495c247SJohannes Berg #define IEEE80211_FAST_XMIT_MAX_IV 18
307e495c247SJohannes Berg
308fcea6007SJohannes Berg /**
30917c18bf8SJohannes Berg * struct ieee80211_fast_tx - TX fastpath information
31017c18bf8SJohannes Berg * @key: key to use for hw crypto
31117c18bf8SJohannes Berg * @hdr: the 802.11 header to put with the frame
31217c18bf8SJohannes Berg * @hdr_len: actual 802.11 header length
31317c18bf8SJohannes Berg * @sa_offs: offset of the SA
31417c18bf8SJohannes Berg * @da_offs: offset of the DA
31517c18bf8SJohannes Berg * @pn_offs: offset where to put PN for crypto (or 0 if not needed)
31617c18bf8SJohannes Berg * @band: band this will be transmitted on, for tx_info
31717c18bf8SJohannes Berg * @rcu_head: RCU head to free this struct
31817c18bf8SJohannes Berg *
319e495c247SJohannes Berg * This struct is small enough so that the common case (maximum crypto
320e495c247SJohannes Berg * header length of 8 like for CCMP/GCMP) fits into a single 64-byte
321e495c247SJohannes Berg * cache line.
32217c18bf8SJohannes Berg */
32317c18bf8SJohannes Berg struct ieee80211_fast_tx {
32417c18bf8SJohannes Berg struct ieee80211_key *key;
32517c18bf8SJohannes Berg u8 hdr_len;
32617c18bf8SJohannes Berg u8 sa_offs, da_offs, pn_offs;
32717c18bf8SJohannes Berg u8 band;
328e495c247SJohannes Berg u8 hdr[30 + 2 + IEEE80211_FAST_XMIT_MAX_IV +
3296fe04128SFelix Fietkau sizeof(rfc1042_header)] __aligned(2);
33017c18bf8SJohannes Berg
33117c18bf8SJohannes Berg struct rcu_head rcu_head;
33217c18bf8SJohannes Berg };
33317c18bf8SJohannes Berg
33417c18bf8SJohannes Berg /**
33549ddf8e6SJohannes Berg * struct ieee80211_fast_rx - RX fastpath information
33649ddf8e6SJohannes Berg * @dev: netdevice for reporting the SKB
33749ddf8e6SJohannes Berg * @vif_type: (P2P-less) interface type of the original sdata (sdata->vif.type)
33849ddf8e6SJohannes Berg * @vif_addr: interface address
33949ddf8e6SJohannes Berg * @rfc1042_hdr: copy of the RFC 1042 SNAP header (to have in cache)
34049ddf8e6SJohannes Berg * @control_port_protocol: control port protocol copied from sdata
34149ddf8e6SJohannes Berg * @expected_ds_bits: from/to DS bits expected
34249ddf8e6SJohannes Berg * @icv_len: length of the MIC if present
34349ddf8e6SJohannes Berg * @key: bool indicating encryption is expected (key is set)
34449ddf8e6SJohannes Berg * @internal_forward: forward froms internally on AP/VLAN type interfaces
345c9c5962bSJohannes Berg * @uses_rss: copy of USES_RSS hw flag
34649ddf8e6SJohannes Berg * @da_offs: offset of the DA in the header (for header conversion)
34749ddf8e6SJohannes Berg * @sa_offs: offset of the SA in the header (for header conversion)
34849ddf8e6SJohannes Berg * @rcu_head: RCU head for freeing this structure
34949ddf8e6SJohannes Berg */
35049ddf8e6SJohannes Berg struct ieee80211_fast_rx {
35149ddf8e6SJohannes Berg struct net_device *dev;
35249ddf8e6SJohannes Berg enum nl80211_iftype vif_type;
35349ddf8e6SJohannes Berg u8 vif_addr[ETH_ALEN] __aligned(2);
35449ddf8e6SJohannes Berg u8 rfc1042_hdr[6] __aligned(2);
35549ddf8e6SJohannes Berg __be16 control_port_protocol;
35649ddf8e6SJohannes Berg __le16 expected_ds_bits;
35749ddf8e6SJohannes Berg u8 icv_len;
35849ddf8e6SJohannes Berg u8 key:1,
359c9c5962bSJohannes Berg internal_forward:1,
360c9c5962bSJohannes Berg uses_rss:1;
36149ddf8e6SJohannes Berg u8 da_offs, sa_offs;
36249ddf8e6SJohannes Berg
36349ddf8e6SJohannes Berg struct rcu_head rcu_head;
36449ddf8e6SJohannes Berg };
36549ddf8e6SJohannes Berg
3663eb0928fSManoharan, Rajkumar /* we use only values in the range 0-100, so pick a large precision */
3673eb0928fSManoharan, Rajkumar DECLARE_EWMA(mesh_fail_avg, 20, 8)
36867fc0554SJulan Hsu DECLARE_EWMA(mesh_tx_rate_avg, 8, 16)
3693eb0928fSManoharan, Rajkumar
37049ddf8e6SJohannes Berg /**
371433f5bc1SJohannes Berg * struct mesh_sta - mesh STA information
372433f5bc1SJohannes Berg * @plink_lock: serialize access to plink fields
373433f5bc1SJohannes Berg * @llid: Local link ID
374433f5bc1SJohannes Berg * @plid: Peer link ID
375a69bd8e6SBob Copeland * @aid: local aid supplied by peer
376433f5bc1SJohannes Berg * @reason: Cancel reason on PLINK_HOLDING state
377433f5bc1SJohannes Berg * @plink_retries: Retries in establishment
378433f5bc1SJohannes Berg * @plink_state: peer link state
379433f5bc1SJohannes Berg * @plink_timeout: timeout of peer link
380433f5bc1SJohannes Berg * @plink_timer: peer link watch timer
3814c02d62fSKees Cook * @plink_sta: peer link watch timer's sta_info
382433f5bc1SJohannes Berg * @t_offset: timing offset relative to this host
383433f5bc1SJohannes Berg * @t_offset_setpoint: reference timing offset of this sta to be used when
384433f5bc1SJohannes Berg * calculating clockdrift
385433f5bc1SJohannes Berg * @local_pm: local link-specific power save mode
386433f5bc1SJohannes Berg * @peer_pm: peer-specific power save mode towards local STA
387433f5bc1SJohannes Berg * @nonpeer_pm: STA power save mode towards non-peer neighbors
388433f5bc1SJohannes Berg * @processed_beacon: set to true after peer rates and capabilities are
389433f5bc1SJohannes Berg * processed
390dbdaee7aSBob Copeland * @connected_to_gate: true if mesh STA has a path to a mesh gate
3911303a51cSMarkus Theil * @connected_to_as: true if mesh STA has a path to a authentication server
392a76d5e0aSJohannes Berg * @fail_avg: moving percentage of failed MSDUs
39367fc0554SJulan Hsu * @tx_rate_avg: moving average of tx bitrate
394433f5bc1SJohannes Berg */
395433f5bc1SJohannes Berg struct mesh_sta {
396433f5bc1SJohannes Berg struct timer_list plink_timer;
3974c02d62fSKees Cook struct sta_info *plink_sta;
398433f5bc1SJohannes Berg
399433f5bc1SJohannes Berg s64 t_offset;
400433f5bc1SJohannes Berg s64 t_offset_setpoint;
401433f5bc1SJohannes Berg
402433f5bc1SJohannes Berg spinlock_t plink_lock;
403433f5bc1SJohannes Berg u16 llid;
404433f5bc1SJohannes Berg u16 plid;
405a69bd8e6SBob Copeland u16 aid;
406433f5bc1SJohannes Berg u16 reason;
407433f5bc1SJohannes Berg u8 plink_retries;
408433f5bc1SJohannes Berg
409433f5bc1SJohannes Berg bool processed_beacon;
410dbdaee7aSBob Copeland bool connected_to_gate;
4111303a51cSMarkus Theil bool connected_to_as;
412433f5bc1SJohannes Berg
413433f5bc1SJohannes Berg enum nl80211_plink_state plink_state;
414433f5bc1SJohannes Berg u32 plink_timeout;
415433f5bc1SJohannes Berg
416433f5bc1SJohannes Berg /* mesh power save */
417433f5bc1SJohannes Berg enum nl80211_mesh_power_mode local_pm;
418433f5bc1SJohannes Berg enum nl80211_mesh_power_mode peer_pm;
419433f5bc1SJohannes Berg enum nl80211_mesh_power_mode nonpeer_pm;
420a76d5e0aSJohannes Berg
421a76d5e0aSJohannes Berg /* moving percentage of failed MSDUs */
4223eb0928fSManoharan, Rajkumar struct ewma_mesh_fail_avg fail_avg;
42367fc0554SJulan Hsu /* moving average of tx bitrate */
42467fc0554SJulan Hsu struct ewma_mesh_tx_rate_avg tx_rate_avg;
425433f5bc1SJohannes Berg };
426433f5bc1SJohannes Berg
427eb1e011aSJohannes Berg DECLARE_EWMA(signal, 10, 8)
42840d9a38aSJohannes Berg
429c9c5962bSJohannes Berg struct ieee80211_sta_rx_stats {
430c9c5962bSJohannes Berg unsigned long packets;
431c9c5962bSJohannes Berg unsigned long last_rx;
432c9c5962bSJohannes Berg unsigned long num_duplicates;
433c9c5962bSJohannes Berg unsigned long fragments;
434c9c5962bSJohannes Berg unsigned long dropped;
435c9c5962bSJohannes Berg int last_signal;
436c9c5962bSJohannes Berg u8 chains;
437c9c5962bSJohannes Berg s8 chain_signal_last[IEEE80211_MAX_CHAINS];
43841cbb0f5SLuca Coelho u32 last_rate;
439c9c5962bSJohannes Berg struct u64_stats_sync syncp;
440c9c5962bSJohannes Berg u64 bytes;
441c9c5962bSJohannes Berg u64 msdu[IEEE80211_NUM_TIDS + 1];
442c9c5962bSJohannes Berg };
443c9c5962bSJohannes Berg
4448f797c28SStanislaw Gruszka /*
4453a11ce08SJohannes Berg * IEEE 802.11-2016 (10.6 "Defragmentation") recommends support for "concurrent
4463a11ce08SJohannes Berg * reception of at least one MSDU per access category per associated STA"
4473a11ce08SJohannes Berg * on APs, or "at least one MSDU per access category" on other interface types.
4483a11ce08SJohannes Berg *
4493a11ce08SJohannes Berg * This limit can be increased by changing this define, at the cost of slower
4503a11ce08SJohannes Berg * frame reassembly and increased memory use while fragments are pending.
4513a11ce08SJohannes Berg */
4523a11ce08SJohannes Berg #define IEEE80211_FRAGMENT_MAX 4
4533a11ce08SJohannes Berg
4543a11ce08SJohannes Berg struct ieee80211_fragment_entry {
4553a11ce08SJohannes Berg struct sk_buff_head skb_list;
4563a11ce08SJohannes Berg unsigned long first_frag_time;
4573a11ce08SJohannes Berg u16 seq;
4583a11ce08SJohannes Berg u16 extra_len;
4593a11ce08SJohannes Berg u16 last_frag;
4603a11ce08SJohannes Berg u8 rx_queue;
4617e44a0b5SJohannes Berg u8 check_sequential_pn:1, /* needed for CCMP/GCMP */
4627e44a0b5SJohannes Berg is_protected:1;
4633a11ce08SJohannes Berg u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
4643a11ce08SJohannes Berg unsigned int key_color;
4653a11ce08SJohannes Berg };
4663a11ce08SJohannes Berg
4673a11ce08SJohannes Berg struct ieee80211_fragment_cache {
4683a11ce08SJohannes Berg struct ieee80211_fragment_entry entries[IEEE80211_FRAGMENT_MAX];
4693a11ce08SJohannes Berg unsigned int next;
4703a11ce08SJohannes Berg };
4713a11ce08SJohannes Berg
4723a11ce08SJohannes Berg /*
473484a54c2SToke Høiland-Jørgensen * The bandwidth threshold below which the per-station CoDel parameters will be
474484a54c2SToke Høiland-Jørgensen * scaled to be more lenient (to prevent starvation of slow stations). This
475484a54c2SToke Høiland-Jørgensen * value will be scaled by the number of active stations when it is being
476484a54c2SToke Høiland-Jørgensen * applied.
477484a54c2SToke Høiland-Jørgensen */
478484a54c2SToke Høiland-Jørgensen #define STA_SLOW_THRESHOLD 6000 /* 6 Mbps */
479484a54c2SToke Høiland-Jørgensen
480484a54c2SToke Høiland-Jørgensen /**
481046d2e7cSSriram R * struct link_sta_info - Link STA information
482046d2e7cSSriram R * All link specific sta info are stored here for reference. This can be
483046d2e7cSSriram R * a single entry for non-MLD STA or multiple entries for MLD STA
484046d2e7cSSriram R * @addr: Link MAC address - Can be same as MLD STA mac address and is always
485046d2e7cSSriram R * same for non-MLD STA. This is used as key for searching link STA
486046d2e7cSSriram R * @link_id: Link ID uniquely identifying the link STA. This is 0 for non-MLD
487046d2e7cSSriram R * and set to the corresponding vif LinkId for MLD STA
488*86e7bdc5SJohannes Berg * @op_mode_nss: NSS limit as set by operating mode notification, or 0
489*86e7bdc5SJohannes Berg * @capa_nss: NSS limit as determined by local and peer capabilities
490ba6ddab9SJohannes Berg * @link_hash_node: hash node for rhashtable
491046d2e7cSSriram R * @sta: Points to the STA info
492046d2e7cSSriram R * @gtk: group keys negotiated with this station, if any
493046d2e7cSSriram R * @tx_stats: TX statistics
494046d2e7cSSriram R * @tx_stats.packets: # of packets transmitted
495046d2e7cSSriram R * @tx_stats.bytes: # of bytes in all packets transmitted
496046d2e7cSSriram R * @tx_stats.last_rate: last TX rate
497046d2e7cSSriram R * @tx_stats.msdu: # of transmitted MSDUs per TID
498046d2e7cSSriram R * @rx_stats: RX statistics
499046d2e7cSSriram R * @rx_stats_avg: averaged RX statistics
500046d2e7cSSriram R * @rx_stats_avg.signal: averaged signal
501046d2e7cSSriram R * @rx_stats_avg.chain_signal: averaged per-chain signal
502046d2e7cSSriram R * @pcpu_rx_stats: per-CPU RX statistics, assigned only if the driver needs
503046d2e7cSSriram R * this (by advertising the USES_RSS hw flag)
504046d2e7cSSriram R * @status_stats: TX status statistics
505046d2e7cSSriram R * @status_stats.filtered: # of filtered frames
506046d2e7cSSriram R * @status_stats.retry_failed: # of frames that failed after retry
507046d2e7cSSriram R * @status_stats.retry_count: # of retries attempted
508046d2e7cSSriram R * @status_stats.lost_packets: # of lost packets
509046d2e7cSSriram R * @status_stats.last_pkt_time: timestamp of last ACKed packet
510046d2e7cSSriram R * @status_stats.msdu_retries: # of MSDU retries
511046d2e7cSSriram R * @status_stats.msdu_failed: # of failed MSDUs
512046d2e7cSSriram R * @status_stats.last_ack: last ack timestamp (jiffies)
513046d2e7cSSriram R * @status_stats.last_ack_signal: last ACK signal
514046d2e7cSSriram R * @status_stats.ack_signal_filled: last ACK signal validity
515046d2e7cSSriram R * @status_stats.avg_ack_signal: average ACK signal
516fe37f73dSMauro Carvalho Chehab * @cur_max_bandwidth: maximum bandwidth to use for TX to the station,
517fe37f73dSMauro Carvalho Chehab * taken from HT/VHT capabilities or VHT operating mode notification
518d2caad52SBenjamin Berg * @debugfs_dir: debug filesystem directory dentry
519c71420dbSJohannes Berg * @pub: public (driver visible) link STA data
520046d2e7cSSriram R * TODO Move other link params from sta_info as required for MLD operation
521046d2e7cSSriram R */
522046d2e7cSSriram R struct link_sta_info {
523046d2e7cSSriram R u8 addr[ETH_ALEN];
524046d2e7cSSriram R u8 link_id;
525046d2e7cSSriram R
526*86e7bdc5SJohannes Berg u8 op_mode_nss, capa_nss;
527*86e7bdc5SJohannes Berg
528ba6ddab9SJohannes Berg struct rhlist_head link_hash_node;
529046d2e7cSSriram R
530046d2e7cSSriram R struct sta_info *sta;
531046d2e7cSSriram R struct ieee80211_key __rcu *gtk[NUM_DEFAULT_KEYS +
532046d2e7cSSriram R NUM_DEFAULT_MGMT_KEYS +
533046d2e7cSSriram R NUM_DEFAULT_BEACON_KEYS];
534046d2e7cSSriram R struct ieee80211_sta_rx_stats __percpu *pcpu_rx_stats;
535046d2e7cSSriram R
536046d2e7cSSriram R /* Updated from RX path only, no locking requirements */
537046d2e7cSSriram R struct ieee80211_sta_rx_stats rx_stats;
538046d2e7cSSriram R struct {
539046d2e7cSSriram R struct ewma_signal signal;
540046d2e7cSSriram R struct ewma_signal chain_signal[IEEE80211_MAX_CHAINS];
541046d2e7cSSriram R } rx_stats_avg;
542046d2e7cSSriram R
543046d2e7cSSriram R /* Updated from TX status path only, no locking requirements */
544046d2e7cSSriram R struct {
545046d2e7cSSriram R unsigned long filtered;
546046d2e7cSSriram R unsigned long retry_failed, retry_count;
547046d2e7cSSriram R unsigned int lost_packets;
548046d2e7cSSriram R unsigned long last_pkt_time;
549046d2e7cSSriram R u64 msdu_retries[IEEE80211_NUM_TIDS + 1];
550046d2e7cSSriram R u64 msdu_failed[IEEE80211_NUM_TIDS + 1];
551046d2e7cSSriram R unsigned long last_ack;
552046d2e7cSSriram R s8 last_ack_signal;
553046d2e7cSSriram R bool ack_signal_filled;
554046d2e7cSSriram R struct ewma_avg_signal avg_ack_signal;
555046d2e7cSSriram R } status_stats;
556046d2e7cSSriram R
557046d2e7cSSriram R /* Updated from TX path only, no locking requirements */
558046d2e7cSSriram R struct {
559046d2e7cSSriram R u64 packets[IEEE80211_NUM_ACS];
560046d2e7cSSriram R u64 bytes[IEEE80211_NUM_ACS];
561046d2e7cSSriram R struct ieee80211_tx_rate last_rate;
562046d2e7cSSriram R struct rate_info last_rate_info;
563046d2e7cSSriram R u64 msdu[IEEE80211_NUM_TIDS + 1];
564046d2e7cSSriram R } tx_stats;
565046d2e7cSSriram R
566046d2e7cSSriram R enum ieee80211_sta_rx_bandwidth cur_max_bandwidth;
567c71420dbSJohannes Berg
568d2caad52SBenjamin Berg #ifdef CONFIG_MAC80211_DEBUGFS
569d2caad52SBenjamin Berg struct dentry *debugfs_dir;
570d2caad52SBenjamin Berg #endif
571d2caad52SBenjamin Berg
572c71420dbSJohannes Berg struct ieee80211_link_sta *pub;
573046d2e7cSSriram R };
574046d2e7cSSriram R
575046d2e7cSSriram R /**
576693b1bbcSJohannes Berg * struct sta_info - STA information
577693b1bbcSJohannes Berg *
578693b1bbcSJohannes Berg * This structure collects information about a station that
579693b1bbcSJohannes Berg * mac80211 is communicating with.
580693b1bbcSJohannes Berg *
581693b1bbcSJohannes Berg * @list: global linked list entry
582d778207bSJohannes Berg * @free_list: list entry for keeping track of stations to free
5837bedd0cfSJohannes Berg * @hash_node: hash node for rhashtable
584ac100ce5SJohannes Berg * @addr: station's MAC address - duplicated from public part to
585ac100ce5SJohannes Berg * let the hash table work with just a single cacheline
586693b1bbcSJohannes Berg * @local: pointer to the global information
587e25cf4a6SJohannes Berg * @sdata: virtual interface this station belongs to
5882475b1ccSMax Stepanov * @ptk: peer keys negotiated with this station, if any
5892475b1ccSMax Stepanov * @ptk_idx: last installed peer key index
590e25cf4a6SJohannes Berg * @rate_ctrl: rate control algorithm reference
591bbbe8c8cSJohannes Berg * @rate_ctrl_lock: spinlock used to protect rate control data
592bbbe8c8cSJohannes Berg * (data inside the algorithm, so serializes calls there)
593e25cf4a6SJohannes Berg * @rate_ctrl_priv: rate control private per-STA pointer
5946ef307bcSRandy Dunlap * @lock: used for locking all fields that require locking, see comments
5956ef307bcSRandy Dunlap * in the header file.
5965ac2e350SJohannes Berg * @drv_deliver_wk: used for delivering frames after driver PS unblocking
597e25cf4a6SJohannes Berg * @listen_interval: listen interval of this station, when we're acting as AP
598c2c98fdeSJohannes Berg * @_flags: STA flags, see &enum ieee80211_sta_info_flags, do not use directly
5991d147bfaSEmmanuel Grumbach * @ps_lock: used for powersave (when mac80211 is the AP) related locking
600948d887dSJohannes Berg * @ps_tx_buf: buffers (per AC) of frames to transmit to this station
601948d887dSJohannes Berg * when it leaves power saving state or polls
602948d887dSJohannes Berg * @tx_filtered: buffers (per AC) of frames we already tried to
603948d887dSJohannes Berg * transmit but were filtered by hardware due to STA having
604948d887dSJohannes Berg * entered power saving state, these are also delivered to
605948d887dSJohannes Berg * the station when it leaves powersave or polls for frames
606948d887dSJohannes Berg * @driver_buffered_tids: bitmap of TIDs the driver has data buffered on
607ba8c3d6fSFelix Fietkau * @txq_buffered_tids: bitmap of TIDs that mac80211 has txq data buffered on
6089cf02338SBen Greear * @assoc_at: clock boottime (in ns) of last association
609ebe27c91SMohammed Shafi Shajakhan * @last_connected: time (in seconds) when a station got connected
610798a457dSJohannes Berg * @last_seq_ctrl: last received seq/frag number from this STA (per TID
611798a457dSJohannes Berg * plus one for non-QoS frames)
612e25cf4a6SJohannes Berg * @tid_seq: per-TID sequence numbers for sending to this STA
613cb86880eSToke Høiland-Jørgensen * @airtime: per-AC struct airtime_info describing airtime statistics for this
614cb86880eSToke Høiland-Jørgensen * station
615942741daSFelix Fietkau * @airtime_weight: station weight for airtime fairness calculation purposes
616e25cf4a6SJohannes Berg * @ampdu_mlme: A-MPDU state machine state
617433f5bc1SJohannes Berg * @mesh: mesh STA information
618fc4a25c5SJohannes Berg * @debugfs_dir: debug filesystem directory dentry
619af818581SJohannes Berg * @dead: set to true when sta is unlinked
620ef044763SEliad Peller * @removed: set to true when sta is being removed from sta_list
62134e89507SJohannes Berg * @uploaded: set to true when sta is uploaded to the driver
6222a33bee2SGuy Eilam * @sta: station information we share with the driver
623d9a7ddb0SJohannes Berg * @sta_state: duplicates information about station state (for debug)
624077f897aSJohannes Berg * @rcu_head: RCU head used for freeing this station struct
6250af83d3dSJohannes Berg * @cur_max_bandwidth: maximum bandwidth to use for TX to the station,
6260af83d3dSJohannes Berg * taken from HT/VHT capabilities or VHT operating mode notification
627484a54c2SToke Høiland-Jørgensen * @cparams: CoDel parameters for this station.
628b6da911bSLiad Kaufman * @reserved_tid: reserved TID (if any, otherwise IEEE80211_TID_UNRESERVED)
629f102424bSBagas Sanjaya * @amsdu_mesh_control: track the mesh A-MSDU format used by the peer:
630f102424bSBagas Sanjaya *
631f102424bSBagas Sanjaya * * -1: not yet known
632f102424bSBagas Sanjaya * * 0: non-mesh A-MSDU length field
633f102424bSBagas Sanjaya * * 1: big-endian mesh A-MSDU length field
634f102424bSBagas Sanjaya * * 2: little-endian mesh A-MSDU length field
635f102424bSBagas Sanjaya *
63617c18bf8SJohannes Berg * @fast_tx: TX fastpath information
63749ddf8e6SJohannes Berg * @fast_rx: RX fastpath information
6380fabfaafSArik Nemtsov * @tdls_chandef: a TDLS peer can have a wider chandef that is compatible to
6390fabfaafSArik Nemtsov * the BSS one.
6403a11ce08SJohannes Berg * @frags: fragment cache
6414c51541dSBenjamin Berg * @cur: storage for aggregation data
6424c51541dSBenjamin Berg * &struct ieee80211_sta points either here or to deflink.agg.
643046d2e7cSSriram R * @deflink: This is the default link STA information, for non MLO STA all link
644046d2e7cSSriram R * specific STA information is accessed through @deflink or through
645046d2e7cSSriram R * link[0] which points to address of @deflink. For MLO Link STA
646046d2e7cSSriram R * the first added link STA will point to deflink.
647046d2e7cSSriram R * @link: reference to Link Sta entries. For Non MLO STA, except 1st link,
648046d2e7cSSriram R * i.e link[0] all links would be assigned to NULL by default and
649046d2e7cSSriram R * would access link information via @deflink or link[0]. For MLO
650046d2e7cSSriram R * STA, first link STA being added will point its link pointer to
651046d2e7cSSriram R * @deflink address and remaining would be allocated and the address
652046d2e7cSSriram R * would be assigned to link[link_id] where link_id is the id assigned
653046d2e7cSSriram R * by the AP.
654693b1bbcSJohannes Berg */
655f0706e82SJiri Benc struct sta_info {
656693b1bbcSJohannes Berg /* General information, mostly static */
657d778207bSJohannes Berg struct list_head list, free_list;
658b22cfcfcSEliad Peller struct rcu_head rcu_head;
65983e7e4ceSHerbert Xu struct rhlist_head hash_node;
660ac100ce5SJohannes Berg u8 addr[ETH_ALEN];
661f0706e82SJiri Benc struct ieee80211_local *local;
662d0709a65SJohannes Berg struct ieee80211_sub_if_data *sdata;
6632475b1ccSMax Stepanov struct ieee80211_key __rcu *ptk[NUM_DEFAULT_KEYS];
6642475b1ccSMax Stepanov u8 ptk_idx;
665f0706e82SJiri Benc struct rate_control_ref *rate_ctrl;
666f0706e82SJiri Benc void *rate_ctrl_priv;
66735c347acSJohannes Berg spinlock_t rate_ctrl_lock;
66807346f81SJohannes Berg spinlock_t lock;
66917741cdcSJohannes Berg
67017c18bf8SJohannes Berg struct ieee80211_fast_tx __rcu *fast_tx;
67149ddf8e6SJohannes Berg struct ieee80211_fast_rx __rcu *fast_rx;
67217c18bf8SJohannes Berg
673433f5bc1SJohannes Berg #ifdef CONFIG_MAC80211_MESH
674433f5bc1SJohannes Berg struct mesh_sta *mesh;
675433f5bc1SJohannes Berg #endif
676433f5bc1SJohannes Berg
6775ac2e350SJohannes Berg struct work_struct drv_deliver_wk;
678af818581SJohannes Berg
679f0706e82SJiri Benc u16 listen_interval;
680e9f207f0SJiri Benc
681af818581SJohannes Berg bool dead;
682ef044763SEliad Peller bool removed;
683af818581SJohannes Berg
68434e89507SJohannes Berg bool uploaded;
685d0709a65SJohannes Berg
686d9a7ddb0SJohannes Berg enum ieee80211_sta_state sta_state;
687d9a7ddb0SJohannes Berg
688c2c98fdeSJohannes Berg /* use the accessors defined below */
689c2c98fdeSJohannes Berg unsigned long _flags;
690693b1bbcSJohannes Berg
6911d147bfaSEmmanuel Grumbach /* STA powersave lock and frame queues */
6921d147bfaSEmmanuel Grumbach spinlock_t ps_lock;
693948d887dSJohannes Berg struct sk_buff_head ps_tx_buf[IEEE80211_NUM_ACS];
694948d887dSJohannes Berg struct sk_buff_head tx_filtered[IEEE80211_NUM_ACS];
695948d887dSJohannes Berg unsigned long driver_buffered_tids;
696ba8c3d6fSFelix Fietkau unsigned long txq_buffered_tids;
697693b1bbcSJohannes Berg
6989cf02338SBen Greear u64 assoc_at;
699ebe27c91SMohammed Shafi Shajakhan long last_connected;
700e5a9f8d0SJohannes Berg
7019e26297aSJohannes Berg /* Plus 1 for non-QoS frames */
7025a306f58SJohannes Berg __le16 last_seq_ctrl[IEEE80211_NUM_TIDS + 1];
703693b1bbcSJohannes Berg
704f591fa5dSJohannes Berg u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
705693b1bbcSJohannes Berg
706b4809e94SToke Høiland-Jørgensen struct airtime_info airtime[IEEE80211_NUM_ACS];
707942741daSFelix Fietkau u16 airtime_weight;
708b4809e94SToke Høiland-Jørgensen
709693b1bbcSJohannes Berg /*
71007346f81SJohannes Berg * Aggregation information, locked with lock.
711693b1bbcSJohannes Berg */
7125aae2880SRon Rindjunsky struct sta_ampdu_mlme ampdu_mlme;
713693b1bbcSJohannes Berg
714e9f207f0SJiri Benc #ifdef CONFIG_MAC80211_DEBUGFS
715fc4a25c5SJohannes Berg struct dentry *debugfs_dir;
716e9f207f0SJiri Benc #endif
71717741cdcSJohannes Berg
718484a54c2SToke Høiland-Jørgensen struct codel_params cparams;
719484a54c2SToke Høiland-Jørgensen
720b6da911bSLiad Kaufman u8 reserved_tid;
7216e4c0d04SFelix Fietkau s8 amsdu_mesh_control;
722b6da911bSLiad Kaufman
7230fabfaafSArik Nemtsov struct cfg80211_chan_def tdls_chandef;
7240fabfaafSArik Nemtsov
7253a11ce08SJohannes Berg struct ieee80211_fragment_cache frags;
7263a11ce08SJohannes Berg
7274c51541dSBenjamin Berg struct ieee80211_sta_aggregates cur;
728046d2e7cSSriram R struct link_sta_info deflink;
729c71420dbSJohannes Berg struct link_sta_info __rcu *link[IEEE80211_MLD_MAX_NUM_LINKS];
730046d2e7cSSriram R
73117741cdcSJohannes Berg /* keep last! */
73217741cdcSJohannes Berg struct ieee80211_sta sta;
733f0706e82SJiri Benc };
734f0706e82SJiri Benc
sta_plink_state(struct sta_info * sta)73557cf8043SJavier Cardona static inline enum nl80211_plink_state sta_plink_state(struct sta_info *sta)
736d6d1a5a7SJohannes Berg {
737d6d1a5a7SJohannes Berg #ifdef CONFIG_MAC80211_MESH
738433f5bc1SJohannes Berg return sta->mesh->plink_state;
739d6d1a5a7SJohannes Berg #endif
74057cf8043SJavier Cardona return NL80211_PLINK_LISTEN;
741d6d1a5a7SJohannes Berg }
742d6d1a5a7SJohannes Berg
set_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)743c2c98fdeSJohannes Berg static inline void set_sta_flag(struct sta_info *sta,
744c2c98fdeSJohannes Berg enum ieee80211_sta_info_flags flag)
74507346f81SJohannes Berg {
746d9a7ddb0SJohannes Berg WARN_ON(flag == WLAN_STA_AUTH ||
747d9a7ddb0SJohannes Berg flag == WLAN_STA_ASSOC ||
748d9a7ddb0SJohannes Berg flag == WLAN_STA_AUTHORIZED);
749c2c98fdeSJohannes Berg set_bit(flag, &sta->_flags);
75007346f81SJohannes Berg }
75107346f81SJohannes Berg
clear_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)752c2c98fdeSJohannes Berg static inline void clear_sta_flag(struct sta_info *sta,
753c2c98fdeSJohannes Berg enum ieee80211_sta_info_flags flag)
75407346f81SJohannes Berg {
755d9a7ddb0SJohannes Berg WARN_ON(flag == WLAN_STA_AUTH ||
756d9a7ddb0SJohannes Berg flag == WLAN_STA_ASSOC ||
757d9a7ddb0SJohannes Berg flag == WLAN_STA_AUTHORIZED);
758c2c98fdeSJohannes Berg clear_bit(flag, &sta->_flags);
75907346f81SJohannes Berg }
76007346f81SJohannes Berg
test_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)761c2c98fdeSJohannes Berg static inline int test_sta_flag(struct sta_info *sta,
762c2c98fdeSJohannes Berg enum ieee80211_sta_info_flags flag)
76307346f81SJohannes Berg {
764c2c98fdeSJohannes Berg return test_bit(flag, &sta->_flags);
76507346f81SJohannes Berg }
76607346f81SJohannes Berg
test_and_clear_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)767c2c98fdeSJohannes Berg static inline int test_and_clear_sta_flag(struct sta_info *sta,
768c2c98fdeSJohannes Berg enum ieee80211_sta_info_flags flag)
76907346f81SJohannes Berg {
770d9a7ddb0SJohannes Berg WARN_ON(flag == WLAN_STA_AUTH ||
771d9a7ddb0SJohannes Berg flag == WLAN_STA_ASSOC ||
772d9a7ddb0SJohannes Berg flag == WLAN_STA_AUTHORIZED);
773c2c98fdeSJohannes Berg return test_and_clear_bit(flag, &sta->_flags);
77407346f81SJohannes Berg }
77507346f81SJohannes Berg
test_and_set_sta_flag(struct sta_info * sta,enum ieee80211_sta_info_flags flag)776e7f4a940SJohannes Berg static inline int test_and_set_sta_flag(struct sta_info *sta,
777e7f4a940SJohannes Berg enum ieee80211_sta_info_flags flag)
778e7f4a940SJohannes Berg {
779d9a7ddb0SJohannes Berg WARN_ON(flag == WLAN_STA_AUTH ||
780d9a7ddb0SJohannes Berg flag == WLAN_STA_ASSOC ||
781d9a7ddb0SJohannes Berg flag == WLAN_STA_AUTHORIZED);
782e7f4a940SJohannes Berg return test_and_set_bit(flag, &sta->_flags);
783e7f4a940SJohannes Berg }
784e7f4a940SJohannes Berg
78583d5cc01SJohannes Berg int sta_info_move_state(struct sta_info *sta,
786d9a7ddb0SJohannes Berg enum ieee80211_sta_state new_state);
787d9a7ddb0SJohannes Berg
sta_info_pre_move_state(struct sta_info * sta,enum ieee80211_sta_state new_state)78883d5cc01SJohannes Berg static inline void sta_info_pre_move_state(struct sta_info *sta,
789d9a7ddb0SJohannes Berg enum ieee80211_sta_state new_state)
790d9a7ddb0SJohannes Berg {
79183d5cc01SJohannes Berg int ret;
79283d5cc01SJohannes Berg
79383d5cc01SJohannes Berg WARN_ON_ONCE(test_sta_flag(sta, WLAN_STA_INSERTED));
79483d5cc01SJohannes Berg
79583d5cc01SJohannes Berg ret = sta_info_move_state(sta, new_state);
796d9a7ddb0SJohannes Berg WARN_ON_ONCE(ret);
797d9a7ddb0SJohannes Berg }
798d9a7ddb0SJohannes Berg
799d9a7ddb0SJohannes Berg
800ec034b20SJohannes Berg void ieee80211_assign_tid_tx(struct sta_info *sta, int tid,
801ec034b20SJohannes Berg struct tid_ampdu_tx *tid_tx);
802f0706e82SJiri Benc
80340b275b6SJohannes Berg static inline struct tid_ampdu_tx *
rcu_dereference_protected_tid_tx(struct sta_info * sta,int tid)80440b275b6SJohannes Berg rcu_dereference_protected_tid_tx(struct sta_info *sta, int tid)
80540b275b6SJohannes Berg {
80640b275b6SJohannes Berg return rcu_dereference_protected(sta->ampdu_mlme.tid_tx[tid],
80740b275b6SJohannes Berg lockdep_is_held(&sta->lock) ||
80840b275b6SJohannes Berg lockdep_is_held(&sta->ampdu_mlme.mtx));
80940b275b6SJohannes Berg }
810f0706e82SJiri Benc
811948d887dSJohannes Berg /* Maximum number of frames to buffer per power saving station per AC */
812948d887dSJohannes Berg #define STA_MAX_TX_BUFFER 64
813f0706e82SJiri Benc
814f0706e82SJiri Benc /* Minimum buffered frame expiry time. If STA uses listen interval that is
815f0706e82SJiri Benc * smaller than this value, the minimum value here is used instead. */
816f0706e82SJiri Benc #define STA_TX_BUFFER_EXPIRE (10 * HZ)
817f0706e82SJiri Benc
818f0706e82SJiri Benc /* How often station data is cleaned up (e.g., expiration of buffered frames)
819f0706e82SJiri Benc */
820f0706e82SJiri Benc #define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
821f0706e82SJiri Benc
82283e7e4ceSHerbert Xu struct rhlist_head *sta_info_hash_lookup(struct ieee80211_local *local,
82383e7e4ceSHerbert Xu const u8 *addr);
82483e7e4ceSHerbert Xu
825d0709a65SJohannes Berg /*
826abe60632SJohannes Berg * Get a STA info, must be under RCU read lock.
827d0709a65SJohannes Berg */
828abe60632SJohannes Berg struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
829abe60632SJohannes Berg const u8 *addr);
830abe60632SJohannes Berg
8310e5ded5aSFelix Fietkau struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
8320e5ded5aSFelix Fietkau const u8 *addr);
8330e5ded5aSFelix Fietkau
8345072f73cSToke Høiland-Jørgensen /* user must hold sta_mtx or be in RCU critical section */
8355072f73cSToke Høiland-Jørgensen struct sta_info *sta_info_get_by_addrs(struct ieee80211_local *local,
8365072f73cSToke Høiland-Jørgensen const u8 *sta_addr, const u8 *vif_addr);
8375072f73cSToke Høiland-Jørgensen
83883e7e4ceSHerbert Xu #define for_each_sta_info(local, _addr, _sta, _tmp) \
83983e7e4ceSHerbert Xu rhl_for_each_entry_rcu(_sta, _tmp, \
84083e7e4ceSHerbert Xu sta_info_hash_lookup(local, _addr), hash_node)
841abe60632SJohannes Berg
842ba6ddab9SJohannes Berg struct rhlist_head *link_sta_info_hash_lookup(struct ieee80211_local *local,
843ba6ddab9SJohannes Berg const u8 *addr);
844ba6ddab9SJohannes Berg
845ba6ddab9SJohannes Berg #define for_each_link_sta_info(local, _addr, _sta, _tmp) \
846ba6ddab9SJohannes Berg rhl_for_each_entry_rcu(_sta, _tmp, \
847ba6ddab9SJohannes Berg link_sta_info_hash_lookup(local, _addr), \
848ba6ddab9SJohannes Berg link_hash_node)
849ba6ddab9SJohannes Berg
850ba6ddab9SJohannes Berg struct link_sta_info *
851ba6ddab9SJohannes Berg link_sta_info_get_bss(struct ieee80211_sub_if_data *sdata, const u8 *addr);
852ba6ddab9SJohannes Berg
853d0709a65SJohannes Berg /*
854d0709a65SJohannes Berg * Get STA info by index, BROKEN!
855d0709a65SJohannes Berg */
8563b53fde8SJohannes Berg struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
8573b53fde8SJohannes Berg int idx);
858d0709a65SJohannes Berg /*
85973651ee6SJohannes Berg * Create a new STA info, caller owns returned structure
86073651ee6SJohannes Berg * until sta_info_insert().
861d0709a65SJohannes Berg */
86273651ee6SJohannes Berg struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
863f36fe0a2SJohannes Berg const u8 *addr, gfp_t gfp);
864f36fe0a2SJohannes Berg struct sta_info *sta_info_alloc_with_link(struct ieee80211_sub_if_data *sdata,
865f36fe0a2SJohannes Berg const u8 *mld_addr,
866f36fe0a2SJohannes Berg unsigned int link_id,
867f36fe0a2SJohannes Berg const u8 *link_addr,
868f36fe0a2SJohannes Berg gfp_t gfp);
869d9a7ddb0SJohannes Berg
870d9a7ddb0SJohannes Berg void sta_info_free(struct ieee80211_local *local, struct sta_info *sta);
871d9a7ddb0SJohannes Berg
87273651ee6SJohannes Berg /*
87373651ee6SJohannes Berg * Insert STA info into hash table/list, returns zero or a
87473651ee6SJohannes Berg * -EEXIST if (if the same MAC address is already present).
87573651ee6SJohannes Berg *
87634e89507SJohannes Berg * Calling the non-rcu version makes the caller relinquish,
87734e89507SJohannes Berg * the _rcu version calls read_lock_rcu() and must be called
87834e89507SJohannes Berg * without it held.
87973651ee6SJohannes Berg */
88073651ee6SJohannes Berg int sta_info_insert(struct sta_info *sta);
88134e89507SJohannes Berg int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU);
882d0709a65SJohannes Berg
88383d5cc01SJohannes Berg int __must_check __sta_info_destroy(struct sta_info *sta);
88434e89507SJohannes Berg int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata,
88534e89507SJohannes Berg const u8 *addr);
88634e89507SJohannes Berg int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
88734e89507SJohannes Berg const u8 *addr);
88834e89507SJohannes Berg
889c868cb35SJohannes Berg void sta_info_recalc_tim(struct sta_info *sta);
890d0709a65SJohannes Berg
8917bedd0cfSJohannes Berg int sta_info_init(struct ieee80211_local *local);
892f0706e82SJiri Benc void sta_info_stop(struct ieee80211_local *local);
893051007d9SJohannes Berg
894051007d9SJohannes Berg /**
895b1e8eb11SMauro Carvalho Chehab * __sta_info_flush - flush matching STA entries from the STA table
896051007d9SJohannes Berg *
897051007d9SJohannes Berg * Returns the number of removed STA entries.
898051007d9SJohannes Berg *
899051007d9SJohannes Berg * @sdata: sdata to remove all stations from
900e716251dSJohannes Berg * @vlans: if the given interface is an AP interface, also flush VLANs
901051007d9SJohannes Berg */
902e716251dSJohannes Berg int __sta_info_flush(struct ieee80211_sub_if_data *sdata, bool vlans);
903e716251dSJohannes Berg
904b1e8eb11SMauro Carvalho Chehab /**
905b1e8eb11SMauro Carvalho Chehab * sta_info_flush - flush matching STA entries from the STA table
906b1e8eb11SMauro Carvalho Chehab *
907b1e8eb11SMauro Carvalho Chehab * Returns the number of removed STA entries.
908b1e8eb11SMauro Carvalho Chehab *
909b1e8eb11SMauro Carvalho Chehab * @sdata: sdata to remove all stations from
910b1e8eb11SMauro Carvalho Chehab */
sta_info_flush(struct ieee80211_sub_if_data * sdata)911e716251dSJohannes Berg static inline int sta_info_flush(struct ieee80211_sub_if_data *sdata)
912e716251dSJohannes Berg {
913e716251dSJohannes Berg return __sta_info_flush(sdata, false);
914e716251dSJohannes Berg }
915051007d9SJohannes Berg
9166b62bf32SThomas Pedersen void sta_set_rate_info_tx(struct sta_info *sta,
9176b62bf32SThomas Pedersen const struct ieee80211_tx_rate *rate,
9186b62bf32SThomas Pedersen struct rate_info *rinfo);
9190fdf1493SJohannes Berg void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo,
9200fdf1493SJohannes Berg bool tidstats);
921b7ffbd7eSJohannes Berg
9223b17fbf8SMaxim Altshul u32 sta_get_expected_throughput(struct sta_info *sta);
9233b17fbf8SMaxim Altshul
92424723d1bSJohannes Berg void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
92524723d1bSJohannes Berg unsigned long exp_time);
926004c872eSJohannes Berg
927cb71f1d1SJohannes Berg int ieee80211_sta_allocate_link(struct sta_info *sta, unsigned int link_id);
92821476ad1SShaul Triebitz void ieee80211_sta_free_link(struct sta_info *sta, unsigned int link_id);
929cb71f1d1SJohannes Berg int ieee80211_sta_activate_link(struct sta_info *sta, unsigned int link_id);
930cb71f1d1SJohannes Berg void ieee80211_sta_remove_link(struct sta_info *sta, unsigned int link_id);
931cb71f1d1SJohannes Berg
932af818581SJohannes Berg void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta);
933af818581SJohannes Berg void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta);
93447086fc5SJohannes Berg void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta);
935af818581SJohannes Berg
936b8da6b6aSJohannes Berg unsigned long ieee80211_sta_last_active(struct sta_info *sta);
937b8da6b6aSJohannes Berg
938175ad2ecSJohannes Berg void ieee80211_sta_set_max_amsdu_subframes(struct sta_info *sta,
939175ad2ecSJohannes Berg const u8 *ext_capab,
940175ad2ecSJohannes Berg unsigned int ext_capab_len);
941175ad2ecSJohannes Berg
9429b41a9d7SJohannes Berg void __ieee80211_sta_recalc_aggregates(struct sta_info *sta, u16 active_links);
9439b41a9d7SJohannes Berg
944dcba665bSJohannes Berg enum sta_stats_type {
945dcba665bSJohannes Berg STA_STATS_RATE_TYPE_INVALID = 0,
946dcba665bSJohannes Berg STA_STATS_RATE_TYPE_LEGACY,
947dcba665bSJohannes Berg STA_STATS_RATE_TYPE_HT,
948dcba665bSJohannes Berg STA_STATS_RATE_TYPE_VHT,
94941cbb0f5SLuca Coelho STA_STATS_RATE_TYPE_HE,
95012bf8fadSThomas Pedersen STA_STATS_RATE_TYPE_S1G,
951f66c48afSJohannes Berg STA_STATS_RATE_TYPE_EHT,
952dcba665bSJohannes Berg };
953dcba665bSJohannes Berg
954dcba665bSJohannes Berg #define STA_STATS_FIELD_HT_MCS GENMASK( 7, 0)
955dcba665bSJohannes Berg #define STA_STATS_FIELD_LEGACY_IDX GENMASK( 3, 0)
956dcba665bSJohannes Berg #define STA_STATS_FIELD_LEGACY_BAND GENMASK( 7, 4)
957dcba665bSJohannes Berg #define STA_STATS_FIELD_VHT_MCS GENMASK( 3, 0)
958dcba665bSJohannes Berg #define STA_STATS_FIELD_VHT_NSS GENMASK( 7, 4)
95941cbb0f5SLuca Coelho #define STA_STATS_FIELD_HE_MCS GENMASK( 3, 0)
96041cbb0f5SLuca Coelho #define STA_STATS_FIELD_HE_NSS GENMASK( 7, 4)
961f66c48afSJohannes Berg #define STA_STATS_FIELD_EHT_MCS GENMASK( 3, 0)
962f66c48afSJohannes Berg #define STA_STATS_FIELD_EHT_NSS GENMASK( 7, 4)
963f66c48afSJohannes Berg #define STA_STATS_FIELD_BW GENMASK(12, 8)
964f66c48afSJohannes Berg #define STA_STATS_FIELD_SGI GENMASK(13, 13)
965f66c48afSJohannes Berg #define STA_STATS_FIELD_TYPE GENMASK(16, 14)
966f66c48afSJohannes Berg #define STA_STATS_FIELD_HE_RU GENMASK(19, 17)
967f66c48afSJohannes Berg #define STA_STATS_FIELD_HE_GI GENMASK(21, 20)
968f66c48afSJohannes Berg #define STA_STATS_FIELD_HE_DCM GENMASK(22, 22)
969f66c48afSJohannes Berg #define STA_STATS_FIELD_EHT_RU GENMASK(20, 17)
970f66c48afSJohannes Berg #define STA_STATS_FIELD_EHT_GI GENMASK(22, 21)
971dcba665bSJohannes Berg
972dcba665bSJohannes Berg #define STA_STATS_FIELD(_n, _v) FIELD_PREP(STA_STATS_FIELD_ ## _n, _v)
973dcba665bSJohannes Berg #define STA_STATS_GET(_n, _v) FIELD_GET(STA_STATS_FIELD_ ## _n, _v)
974dcba665bSJohannes Berg
9754f6b1b3dSJohannes Berg #define STA_STATS_RATE_INVALID 0
9764f6b1b3dSJohannes Berg
sta_stats_encode_rate(struct ieee80211_rx_status * s)977dcba665bSJohannes Berg static inline u32 sta_stats_encode_rate(struct ieee80211_rx_status *s)
9784f6b1b3dSJohannes Berg {
97941cbb0f5SLuca Coelho u32 r;
9804f6b1b3dSJohannes Berg
981dcba665bSJohannes Berg r = STA_STATS_FIELD(BW, s->bw);
9824f6b1b3dSJohannes Berg
9837fdd69c5SJohannes Berg if (s->enc_flags & RX_ENC_FLAG_SHORT_GI)
984dcba665bSJohannes Berg r |= STA_STATS_FIELD(SGI, 1);
9854f6b1b3dSJohannes Berg
986da6a4352SJohannes Berg switch (s->encoding) {
987da6a4352SJohannes Berg case RX_ENC_VHT:
988dcba665bSJohannes Berg r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_VHT);
989dcba665bSJohannes Berg r |= STA_STATS_FIELD(VHT_NSS, s->nss);
990dcba665bSJohannes Berg r |= STA_STATS_FIELD(VHT_MCS, s->rate_idx);
991da6a4352SJohannes Berg break;
992da6a4352SJohannes Berg case RX_ENC_HT:
993dcba665bSJohannes Berg r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HT);
994dcba665bSJohannes Berg r |= STA_STATS_FIELD(HT_MCS, s->rate_idx);
995dcba665bSJohannes Berg break;
996dcba665bSJohannes Berg case RX_ENC_LEGACY:
997dcba665bSJohannes Berg r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_LEGACY);
998dcba665bSJohannes Berg r |= STA_STATS_FIELD(LEGACY_BAND, s->band);
999dcba665bSJohannes Berg r |= STA_STATS_FIELD(LEGACY_IDX, s->rate_idx);
1000da6a4352SJohannes Berg break;
100141cbb0f5SLuca Coelho case RX_ENC_HE:
100241cbb0f5SLuca Coelho r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_HE);
100341cbb0f5SLuca Coelho r |= STA_STATS_FIELD(HE_NSS, s->nss);
100441cbb0f5SLuca Coelho r |= STA_STATS_FIELD(HE_MCS, s->rate_idx);
100541cbb0f5SLuca Coelho r |= STA_STATS_FIELD(HE_GI, s->he_gi);
100641cbb0f5SLuca Coelho r |= STA_STATS_FIELD(HE_RU, s->he_ru);
100741cbb0f5SLuca Coelho r |= STA_STATS_FIELD(HE_DCM, s->he_dcm);
100841cbb0f5SLuca Coelho break;
1009f66c48afSJohannes Berg case RX_ENC_EHT:
1010f66c48afSJohannes Berg r |= STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_EHT);
1011f66c48afSJohannes Berg r |= STA_STATS_FIELD(EHT_NSS, s->nss);
1012f66c48afSJohannes Berg r |= STA_STATS_FIELD(EHT_MCS, s->rate_idx);
1013f66c48afSJohannes Berg r |= STA_STATS_FIELD(EHT_GI, s->eht.gi);
1014f66c48afSJohannes Berg r |= STA_STATS_FIELD(EHT_RU, s->eht.ru);
1015f66c48afSJohannes Berg break;
1016da6a4352SJohannes Berg default:
1017da6a4352SJohannes Berg WARN_ON(1);
1018dcba665bSJohannes Berg return STA_STATS_RATE_INVALID;
1019da6a4352SJohannes Berg }
10204f6b1b3dSJohannes Berg
10214f6b1b3dSJohannes Berg return r;
10224f6b1b3dSJohannes Berg }
10234f6b1b3dSJohannes Berg
1024f0706e82SJiri Benc #endif /* STA_INFO_H */
1025