1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * This file is provided under a dual BSD/GPLv2 license. When using or
4*4882a593Smuzhiyun * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
11*4882a593Smuzhiyun * Copyright(c) 2018 - 2020 Intel Corporation
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
14*4882a593Smuzhiyun * it under the terms of version 2 of the GNU General Public License as
15*4882a593Smuzhiyun * published by the Free Software Foundation.
16*4882a593Smuzhiyun *
17*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
18*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
19*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20*4882a593Smuzhiyun * General Public License for more details.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * The full GNU General Public License is included in this distribution
23*4882a593Smuzhiyun * in the file called COPYING.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Contact Information:
26*4882a593Smuzhiyun * Intel Linux Wireless <linuxwifi@intel.com>
27*4882a593Smuzhiyun * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * BSD LICENSE
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32*4882a593Smuzhiyun * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
33*4882a593Smuzhiyun * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
34*4882a593Smuzhiyun * Copyright(c) 2018 - 2020 Intel Corporation
35*4882a593Smuzhiyun * All rights reserved.
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
38*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
39*4882a593Smuzhiyun * are met:
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
42*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
43*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
44*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
45*4882a593Smuzhiyun * the documentation and/or other materials provided with the
46*4882a593Smuzhiyun * distribution.
47*4882a593Smuzhiyun * * Neither the name Intel Corporation nor the names of its
48*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
49*4882a593Smuzhiyun * from this software without specific prior written permission.
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun *****************************************************************************/
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun #ifndef __sta_h__
66*4882a593Smuzhiyun #define __sta_h__
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #include <linux/spinlock.h>
69*4882a593Smuzhiyun #include <net/mac80211.h>
70*4882a593Smuzhiyun #include <linux/wait.h>
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun #include "iwl-trans.h" /* for IWL_MAX_TID_COUNT */
73*4882a593Smuzhiyun #include "fw-api.h" /* IWL_MVM_STATION_COUNT_MAX */
74*4882a593Smuzhiyun #include "rs.h"
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun struct iwl_mvm;
77*4882a593Smuzhiyun struct iwl_mvm_vif;
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun /**
80*4882a593Smuzhiyun * DOC: DQA - Dynamic Queue Allocation -introduction
81*4882a593Smuzhiyun *
82*4882a593Smuzhiyun * Dynamic Queue Allocation (AKA "DQA") is a feature implemented in iwlwifi
83*4882a593Smuzhiyun * driver to allow dynamic allocation of queues on-demand, rather than allocate
84*4882a593Smuzhiyun * them statically ahead of time. Ideally, we would like to allocate one queue
85*4882a593Smuzhiyun * per RA/TID, thus allowing an AP - for example - to send BE traffic to STA2
86*4882a593Smuzhiyun * even if it also needs to send traffic to a sleeping STA1, without being
87*4882a593Smuzhiyun * blocked by the sleeping station.
88*4882a593Smuzhiyun *
89*4882a593Smuzhiyun * Although the queues in DQA mode are dynamically allocated, there are still
90*4882a593Smuzhiyun * some queues that are statically allocated:
91*4882a593Smuzhiyun * TXQ #0 - command queue
92*4882a593Smuzhiyun * TXQ #1 - aux frames
93*4882a593Smuzhiyun * TXQ #2 - P2P device frames
94*4882a593Smuzhiyun * TXQ #3 - P2P GO/SoftAP GCAST/BCAST frames
95*4882a593Smuzhiyun * TXQ #4 - BSS DATA frames queue
96*4882a593Smuzhiyun * TXQ #5-8 - Non-QoS and MGMT frames queue pool
97*4882a593Smuzhiyun * TXQ #9 - P2P GO/SoftAP probe responses
98*4882a593Smuzhiyun * TXQ #10-31 - DATA frames queue pool
99*4882a593Smuzhiyun * The queues are dynamically taken from either the MGMT frames queue pool or
100*4882a593Smuzhiyun * the DATA frames one. See the %iwl_mvm_dqa_txq for more information on every
101*4882a593Smuzhiyun * queue.
102*4882a593Smuzhiyun *
103*4882a593Smuzhiyun * When a frame for a previously unseen RA/TID comes in, it needs to be deferred
104*4882a593Smuzhiyun * until a queue is allocated for it, and only then can be TXed. Therefore, it
105*4882a593Smuzhiyun * is placed into %iwl_mvm_tid_data.deferred_tx_frames, and a worker called
106*4882a593Smuzhiyun * %mvm->add_stream_wk later allocates the queues and TXes the deferred frames.
107*4882a593Smuzhiyun *
108*4882a593Smuzhiyun * For convenience, MGMT is considered as if it has TID=8, and go to the MGMT
109*4882a593Smuzhiyun * queues in the pool. If there is no longer a free MGMT queue to allocate, a
110*4882a593Smuzhiyun * queue will be allocated from the DATA pool instead. Since QoS NDPs can create
111*4882a593Smuzhiyun * a problem for aggregations, they too will use a MGMT queue.
112*4882a593Smuzhiyun *
113*4882a593Smuzhiyun * When adding a STA, a DATA queue is reserved for it so that it can TX from
114*4882a593Smuzhiyun * it. If no such free queue exists for reserving, the STA addition will fail.
115*4882a593Smuzhiyun *
116*4882a593Smuzhiyun * If the DATA queue pool gets exhausted, no new STA will be accepted, and if a
117*4882a593Smuzhiyun * new RA/TID comes in for an existing STA, one of the STA's queues will become
118*4882a593Smuzhiyun * shared and will serve more than the single TID (but always for the same RA!).
119*4882a593Smuzhiyun *
120*4882a593Smuzhiyun * When a RA/TID needs to become aggregated, no new queue is required to be
121*4882a593Smuzhiyun * allocated, only mark the queue as aggregated via the ADD_STA command. Note,
122*4882a593Smuzhiyun * however, that a shared queue cannot be aggregated, and only after the other
123*4882a593Smuzhiyun * TIDs become inactive and are removed - only then can the queue be
124*4882a593Smuzhiyun * reconfigured and become aggregated.
125*4882a593Smuzhiyun *
126*4882a593Smuzhiyun * When removing a station, its queues are returned to the pool for reuse. Here
127*4882a593Smuzhiyun * we also need to make sure that we are synced with the worker thread that TXes
128*4882a593Smuzhiyun * the deferred frames so we don't get into a situation where the queues are
129*4882a593Smuzhiyun * removed and then the worker puts deferred frames onto the released queues or
130*4882a593Smuzhiyun * tries to allocate new queues for a STA we don't need anymore.
131*4882a593Smuzhiyun */
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun /**
134*4882a593Smuzhiyun * DOC: station table - introduction
135*4882a593Smuzhiyun *
136*4882a593Smuzhiyun * The station table is a list of data structure that reprensent the stations.
137*4882a593Smuzhiyun * In STA/P2P client mode, the driver will hold one station for the AP/ GO.
138*4882a593Smuzhiyun * In GO/AP mode, the driver will have as many stations as associated clients.
139*4882a593Smuzhiyun * All these stations are reflected in the fw's station table. The driver
140*4882a593Smuzhiyun * keeps the fw's station table up to date with the ADD_STA command. Stations
141*4882a593Smuzhiyun * can be removed by the REMOVE_STA command.
142*4882a593Smuzhiyun *
143*4882a593Smuzhiyun * All the data related to a station is held in the structure %iwl_mvm_sta
144*4882a593Smuzhiyun * which is embed in the mac80211's %ieee80211_sta (in the drv_priv) area.
145*4882a593Smuzhiyun * This data includes the index of the station in the fw, per tid information
146*4882a593Smuzhiyun * (sequence numbers, Block-ack state machine, etc...). The stations are
147*4882a593Smuzhiyun * created and deleted by the %sta_state callback from %ieee80211_ops.
148*4882a593Smuzhiyun *
149*4882a593Smuzhiyun * The driver holds a map: %fw_id_to_mac_id that allows to fetch a
150*4882a593Smuzhiyun * %ieee80211_sta (and the %iwl_mvm_sta embedded into it) based on a fw
151*4882a593Smuzhiyun * station index. That way, the driver is able to get the tid related data in
152*4882a593Smuzhiyun * O(1) in time sensitive paths (Tx / Tx response / BA notification). These
153*4882a593Smuzhiyun * paths are triggered by the fw, and the driver needs to get a pointer to the
154*4882a593Smuzhiyun * %ieee80211 structure. This map helps to get that pointer quickly.
155*4882a593Smuzhiyun */
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun /**
158*4882a593Smuzhiyun * DOC: station table - locking
159*4882a593Smuzhiyun *
160*4882a593Smuzhiyun * As stated before, the station is created / deleted by mac80211's %sta_state
161*4882a593Smuzhiyun * callback from %ieee80211_ops which can sleep. The next paragraph explains
162*4882a593Smuzhiyun * the locking of a single stations, the next ones relates to the station
163*4882a593Smuzhiyun * table.
164*4882a593Smuzhiyun *
165*4882a593Smuzhiyun * The station holds the sequence number per tid. So this data needs to be
166*4882a593Smuzhiyun * accessed in the Tx path (which is softIRQ). It also holds the Block-Ack
167*4882a593Smuzhiyun * information (the state machine / and the logic that checks if the queues
168*4882a593Smuzhiyun * were drained), so it also needs to be accessible from the Tx response flow.
169*4882a593Smuzhiyun * In short, the station needs to be access from sleepable context as well as
170*4882a593Smuzhiyun * from tasklets, so the station itself needs a spinlock.
171*4882a593Smuzhiyun *
172*4882a593Smuzhiyun * The writers of %fw_id_to_mac_id map are serialized by the global mutex of
173*4882a593Smuzhiyun * the mvm op_mode. This is possible since %sta_state can sleep.
174*4882a593Smuzhiyun * The pointers in this map are RCU protected, hence we won't replace the
175*4882a593Smuzhiyun * station while we have Tx / Tx response / BA notification running.
176*4882a593Smuzhiyun *
177*4882a593Smuzhiyun * If a station is deleted while it still has packets in its A-MPDU queues,
178*4882a593Smuzhiyun * then the reclaim flow will notice that there is no station in the map for
179*4882a593Smuzhiyun * sta_id and it will dump the responses.
180*4882a593Smuzhiyun */
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun /**
183*4882a593Smuzhiyun * DOC: station table - internal stations
184*4882a593Smuzhiyun *
185*4882a593Smuzhiyun * The FW needs a few internal stations that are not reflected in
186*4882a593Smuzhiyun * mac80211, such as broadcast station in AP / GO mode, or AUX sta for
187*4882a593Smuzhiyun * scanning and P2P device (during the GO negotiation).
188*4882a593Smuzhiyun * For these kind of stations we have %iwl_mvm_int_sta struct which holds the
189*4882a593Smuzhiyun * data relevant for them from both %iwl_mvm_sta and %ieee80211_sta.
190*4882a593Smuzhiyun * Usually the data for these stations is static, so no locking is required,
191*4882a593Smuzhiyun * and no TID data as this is also not needed.
192*4882a593Smuzhiyun * One thing to note, is that these stations have an ID in the fw, but not
193*4882a593Smuzhiyun * in mac80211. In order to "reserve" them a sta_id in %fw_id_to_mac_id
194*4882a593Smuzhiyun * we fill ERR_PTR(EINVAL) in this mapping and all other dereferencing of
195*4882a593Smuzhiyun * pointers from this mapping need to check that the value is not error
196*4882a593Smuzhiyun * or NULL.
197*4882a593Smuzhiyun *
198*4882a593Smuzhiyun * Currently there is only one auxiliary station for scanning, initialized
199*4882a593Smuzhiyun * on init.
200*4882a593Smuzhiyun */
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /**
203*4882a593Smuzhiyun * DOC: station table - AP Station in STA mode
204*4882a593Smuzhiyun *
205*4882a593Smuzhiyun * %iwl_mvm_vif includes the index of the AP station in the fw's STA table:
206*4882a593Smuzhiyun * %ap_sta_id. To get the point to the corresponding %ieee80211_sta,
207*4882a593Smuzhiyun * &fw_id_to_mac_id can be used. Due to the way the fw works, we must not remove
208*4882a593Smuzhiyun * the AP station from the fw before setting the MAC context as unassociated.
209*4882a593Smuzhiyun * Hence, %fw_id_to_mac_id[%ap_sta_id] will be NULLed when the AP station is
210*4882a593Smuzhiyun * removed by mac80211, but the station won't be removed in the fw until the
211*4882a593Smuzhiyun * VIF is set as unassociated. Then, %ap_sta_id will be invalidated.
212*4882a593Smuzhiyun */
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun /**
215*4882a593Smuzhiyun * DOC: station table - Drain vs. Flush
216*4882a593Smuzhiyun *
217*4882a593Smuzhiyun * Flush means that all the frames in the SCD queue are dumped regardless the
218*4882a593Smuzhiyun * station to which they were sent. We do that when we disassociate and before
219*4882a593Smuzhiyun * we remove the STA of the AP. The flush can be done synchronously against the
220*4882a593Smuzhiyun * fw.
221*4882a593Smuzhiyun * Drain means that the fw will drop all the frames sent to a specific station.
222*4882a593Smuzhiyun * This is useful when a client (if we are IBSS / GO or AP) disassociates.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /**
226*4882a593Smuzhiyun * DOC: station table - fw restart
227*4882a593Smuzhiyun *
228*4882a593Smuzhiyun * When the fw asserts, or we have any other issue that requires to reset the
229*4882a593Smuzhiyun * driver, we require mac80211 to reconfigure the driver. Since the private
230*4882a593Smuzhiyun * data of the stations is embed in mac80211's %ieee80211_sta, that data will
231*4882a593Smuzhiyun * not be zeroed and needs to be reinitialized manually.
232*4882a593Smuzhiyun * %IWL_MVM_STATUS_IN_HW_RESTART is set during restart and that will hint us
233*4882a593Smuzhiyun * that we must not allocate a new sta_id but reuse the previous one. This
234*4882a593Smuzhiyun * means that the stations being re-added after the reset will have the same
235*4882a593Smuzhiyun * place in the fw as before the reset. We do need to zero the %fw_id_to_mac_id
236*4882a593Smuzhiyun * map, since the stations aren't in the fw any more. Internal stations that
237*4882a593Smuzhiyun * are not added by mac80211 will be re-added in the init flow that is called
238*4882a593Smuzhiyun * after the restart: mac80211 call's %iwl_mvm_mac_start which calls to
239*4882a593Smuzhiyun * %iwl_mvm_up.
240*4882a593Smuzhiyun */
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun /**
243*4882a593Smuzhiyun * DOC: AP mode - PS
244*4882a593Smuzhiyun *
245*4882a593Smuzhiyun * When a station is asleep, the fw will set it as "asleep". All frames on
246*4882a593Smuzhiyun * shared queues (i.e. non-aggregation queues) to that station will be dropped
247*4882a593Smuzhiyun * by the fw (%TX_STATUS_FAIL_DEST_PS failure code).
248*4882a593Smuzhiyun *
249*4882a593Smuzhiyun * AMPDUs are in a separate queue that is stopped by the fw. We just need to
250*4882a593Smuzhiyun * let mac80211 know when there are frames in these queues so that it can
251*4882a593Smuzhiyun * properly handle trigger frames.
252*4882a593Smuzhiyun *
253*4882a593Smuzhiyun * When a trigger frame is received, mac80211 tells the driver to send frames
254*4882a593Smuzhiyun * from the AMPDU queues or sends frames to non-aggregation queues itself,
255*4882a593Smuzhiyun * depending on which ACs are delivery-enabled and what TID has frames to
256*4882a593Smuzhiyun * transmit. Note that mac80211 has all the knowledge since all the non-agg
257*4882a593Smuzhiyun * frames are buffered / filtered, and the driver tells mac80211 about agg
258*4882a593Smuzhiyun * frames). The driver needs to tell the fw to let frames out even if the
259*4882a593Smuzhiyun * station is asleep. This is done by %iwl_mvm_sta_modify_sleep_tx_count.
260*4882a593Smuzhiyun *
261*4882a593Smuzhiyun * When we receive a frame from that station with PM bit unset, the driver
262*4882a593Smuzhiyun * needs to let the fw know that this station isn't asleep any more. This is
263*4882a593Smuzhiyun * done by %iwl_mvm_sta_modify_ps_wake in response to mac80211 signaling the
264*4882a593Smuzhiyun * station's wakeup.
265*4882a593Smuzhiyun *
266*4882a593Smuzhiyun * For a GO, the Service Period might be cut short due to an absence period
267*4882a593Smuzhiyun * of the GO. In this (and all other cases) the firmware notifies us with the
268*4882a593Smuzhiyun * EOSP_NOTIFICATION, and we notify mac80211 of that. Further frames that we
269*4882a593Smuzhiyun * already sent to the device will be rejected again.
270*4882a593Smuzhiyun *
271*4882a593Smuzhiyun * See also "AP support for powersaving clients" in mac80211.h.
272*4882a593Smuzhiyun */
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun /**
275*4882a593Smuzhiyun * enum iwl_mvm_agg_state
276*4882a593Smuzhiyun *
277*4882a593Smuzhiyun * The state machine of the BA agreement establishment / tear down.
278*4882a593Smuzhiyun * These states relate to a specific RA / TID.
279*4882a593Smuzhiyun *
280*4882a593Smuzhiyun * @IWL_AGG_OFF: aggregation is not used
281*4882a593Smuzhiyun * @IWL_AGG_QUEUED: aggregation start work has been queued
282*4882a593Smuzhiyun * @IWL_AGG_STARTING: aggregation are starting (between start and oper)
283*4882a593Smuzhiyun * @IWL_AGG_ON: aggregation session is up
284*4882a593Smuzhiyun * @IWL_EMPTYING_HW_QUEUE_ADDBA: establishing a BA session - waiting for the
285*4882a593Smuzhiyun * HW queue to be empty from packets for this RA /TID.
286*4882a593Smuzhiyun * @IWL_EMPTYING_HW_QUEUE_DELBA: tearing down a BA session - waiting for the
287*4882a593Smuzhiyun * HW queue to be empty from packets for this RA /TID.
288*4882a593Smuzhiyun */
289*4882a593Smuzhiyun enum iwl_mvm_agg_state {
290*4882a593Smuzhiyun IWL_AGG_OFF = 0,
291*4882a593Smuzhiyun IWL_AGG_QUEUED,
292*4882a593Smuzhiyun IWL_AGG_STARTING,
293*4882a593Smuzhiyun IWL_AGG_ON,
294*4882a593Smuzhiyun IWL_EMPTYING_HW_QUEUE_ADDBA,
295*4882a593Smuzhiyun IWL_EMPTYING_HW_QUEUE_DELBA,
296*4882a593Smuzhiyun };
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun /**
299*4882a593Smuzhiyun * struct iwl_mvm_tid_data - holds the states for each RA / TID
300*4882a593Smuzhiyun * @seq_number: the next WiFi sequence number to use
301*4882a593Smuzhiyun * @next_reclaimed: the WiFi sequence number of the next packet to be acked.
302*4882a593Smuzhiyun * This is basically (last acked packet++).
303*4882a593Smuzhiyun * @rate_n_flags: Rate at which Tx was attempted. Holds the data between the
304*4882a593Smuzhiyun * Tx response (TX_CMD), and the block ack notification (COMPRESSED_BA).
305*4882a593Smuzhiyun * @lq_color: the color of the LQ command as it appears in tx response.
306*4882a593Smuzhiyun * @amsdu_in_ampdu_allowed: true if A-MSDU in A-MPDU is allowed.
307*4882a593Smuzhiyun * @state: state of the BA agreement establishment / tear down.
308*4882a593Smuzhiyun * @txq_id: Tx queue used by the BA session / DQA
309*4882a593Smuzhiyun * @ssn: the first packet to be sent in AGG HW queue in Tx AGG start flow, or
310*4882a593Smuzhiyun * the first packet to be sent in legacy HW queue in Tx AGG stop flow.
311*4882a593Smuzhiyun * Basically when next_reclaimed reaches ssn, we can tell mac80211 that
312*4882a593Smuzhiyun * we are ready to finish the Tx AGG stop / start flow.
313*4882a593Smuzhiyun * @tx_time: medium time consumed by this A-MPDU
314*4882a593Smuzhiyun * @tpt_meas_start: time of the throughput measurements start, is reset every HZ
315*4882a593Smuzhiyun * @tx_count_last: number of frames transmitted during the last second
316*4882a593Smuzhiyun * @tx_count: counts the number of frames transmitted since the last reset of
317*4882a593Smuzhiyun * tpt_meas_start
318*4882a593Smuzhiyun */
319*4882a593Smuzhiyun struct iwl_mvm_tid_data {
320*4882a593Smuzhiyun u16 seq_number;
321*4882a593Smuzhiyun u16 next_reclaimed;
322*4882a593Smuzhiyun /* The rest is Tx AGG related */
323*4882a593Smuzhiyun u32 rate_n_flags;
324*4882a593Smuzhiyun u8 lq_color;
325*4882a593Smuzhiyun bool amsdu_in_ampdu_allowed;
326*4882a593Smuzhiyun enum iwl_mvm_agg_state state;
327*4882a593Smuzhiyun u16 txq_id;
328*4882a593Smuzhiyun u16 ssn;
329*4882a593Smuzhiyun u16 tx_time;
330*4882a593Smuzhiyun unsigned long tpt_meas_start;
331*4882a593Smuzhiyun u32 tx_count_last;
332*4882a593Smuzhiyun u32 tx_count;
333*4882a593Smuzhiyun };
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun struct iwl_mvm_key_pn {
336*4882a593Smuzhiyun struct rcu_head rcu_head;
337*4882a593Smuzhiyun struct {
338*4882a593Smuzhiyun u8 pn[IWL_MAX_TID_COUNT][IEEE80211_CCMP_PN_LEN];
339*4882a593Smuzhiyun } ____cacheline_aligned_in_smp q[];
340*4882a593Smuzhiyun };
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun struct iwl_mvm_delba_data {
343*4882a593Smuzhiyun u32 baid;
344*4882a593Smuzhiyun } __packed;
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun struct iwl_mvm_nssn_sync_data {
347*4882a593Smuzhiyun u32 baid;
348*4882a593Smuzhiyun u32 nssn;
349*4882a593Smuzhiyun } __packed;
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun struct iwl_mvm_rss_sync_notif {
352*4882a593Smuzhiyun struct iwl_mvm_internal_rxq_notif metadata;
353*4882a593Smuzhiyun union {
354*4882a593Smuzhiyun struct iwl_mvm_delba_data delba;
355*4882a593Smuzhiyun struct iwl_mvm_nssn_sync_data nssn_sync;
356*4882a593Smuzhiyun };
357*4882a593Smuzhiyun } __packed;
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun /**
360*4882a593Smuzhiyun * struct iwl_mvm_rxq_dup_data - per station per rx queue data
361*4882a593Smuzhiyun * @last_seq: last sequence per tid for duplicate packet detection
362*4882a593Smuzhiyun * @last_sub_frame: last subframe packet
363*4882a593Smuzhiyun */
364*4882a593Smuzhiyun struct iwl_mvm_rxq_dup_data {
365*4882a593Smuzhiyun __le16 last_seq[IWL_MAX_TID_COUNT + 1];
366*4882a593Smuzhiyun u8 last_sub_frame[IWL_MAX_TID_COUNT + 1];
367*4882a593Smuzhiyun } ____cacheline_aligned_in_smp;
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun /**
370*4882a593Smuzhiyun * struct iwl_mvm_sta - representation of a station in the driver
371*4882a593Smuzhiyun * @sta_id: the index of the station in the fw (will be replaced by id_n_color)
372*4882a593Smuzhiyun * @tfd_queue_msk: the tfd queues used by the station
373*4882a593Smuzhiyun * @mac_id_n_color: the MAC context this station is linked to
374*4882a593Smuzhiyun * @tid_disable_agg: bitmap: if bit(tid) is set, the fw won't send ampdus for
375*4882a593Smuzhiyun * tid.
376*4882a593Smuzhiyun * @max_agg_bufsize: the maximal size of the AGG buffer for this station
377*4882a593Smuzhiyun * @sta_type: station type
378*4882a593Smuzhiyun * @sta_state: station state according to enum %ieee80211_sta_state
379*4882a593Smuzhiyun * @bt_reduced_txpower: is reduced tx power enabled for this station
380*4882a593Smuzhiyun * @next_status_eosp: the next reclaimed packet is a PS-Poll response and
381*4882a593Smuzhiyun * we need to signal the EOSP
382*4882a593Smuzhiyun * @lock: lock to protect the whole struct. Since %tid_data is access from Tx
383*4882a593Smuzhiyun * and from Tx response flow, it needs a spinlock.
384*4882a593Smuzhiyun * @tid_data: per tid data + mgmt. Look at %iwl_mvm_tid_data.
385*4882a593Smuzhiyun * @tid_to_baid: a simple map of TID to baid
386*4882a593Smuzhiyun * @lq_sta: holds rate scaling data, either for the case when RS is done in
387*4882a593Smuzhiyun * the driver - %rs_drv or in the FW - %rs_fw.
388*4882a593Smuzhiyun * @reserved_queue: the queue reserved for this STA for DQA purposes
389*4882a593Smuzhiyun * Every STA has is given one reserved queue to allow it to operate. If no
390*4882a593Smuzhiyun * such queue can be guaranteed, the STA addition will fail.
391*4882a593Smuzhiyun * @tx_protection: reference counter for controlling the Tx protection.
392*4882a593Smuzhiyun * @tt_tx_protection: is thermal throttling enable Tx protection?
393*4882a593Smuzhiyun * @disable_tx: is tx to this STA disabled?
394*4882a593Smuzhiyun * @amsdu_enabled: bitmap of TX AMSDU allowed TIDs.
395*4882a593Smuzhiyun * In case TLC offload is not active it is either 0xFFFF or 0.
396*4882a593Smuzhiyun * @max_amsdu_len: max AMSDU length
397*4882a593Smuzhiyun * @orig_amsdu_len: used to save the original amsdu_len when it is changed via
398*4882a593Smuzhiyun * debugfs. If it's set to 0, it means that it is it's not set via
399*4882a593Smuzhiyun * debugfs.
400*4882a593Smuzhiyun * @agg_tids: bitmap of tids whose status is operational aggregated (IWL_AGG_ON)
401*4882a593Smuzhiyun * @sleep_tx_count: the number of frames that we told the firmware to let out
402*4882a593Smuzhiyun * even when that station is asleep. This is useful in case the queue
403*4882a593Smuzhiyun * gets empty before all the frames were sent, which can happen when
404*4882a593Smuzhiyun * we are sending frames from an AMPDU queue and there was a hole in
405*4882a593Smuzhiyun * the BA window. To be used for UAPSD only.
406*4882a593Smuzhiyun * @ptk_pn: per-queue PTK PN data structures
407*4882a593Smuzhiyun * @dup_data: per queue duplicate packet detection data
408*4882a593Smuzhiyun * @deferred_traffic_tid_map: indication bitmap of deferred traffic per-TID
409*4882a593Smuzhiyun * @tx_ant: the index of the antenna to use for data tx to this station. Only
410*4882a593Smuzhiyun * used during connection establishment (e.g. for the 4 way handshake
411*4882a593Smuzhiyun * exchange).
412*4882a593Smuzhiyun *
413*4882a593Smuzhiyun * When mac80211 creates a station it reserves some space (hw->sta_data_size)
414*4882a593Smuzhiyun * in the structure for use by driver. This structure is placed in that
415*4882a593Smuzhiyun * space.
416*4882a593Smuzhiyun *
417*4882a593Smuzhiyun */
418*4882a593Smuzhiyun struct iwl_mvm_sta {
419*4882a593Smuzhiyun u32 sta_id;
420*4882a593Smuzhiyun u32 tfd_queue_msk;
421*4882a593Smuzhiyun u32 mac_id_n_color;
422*4882a593Smuzhiyun u16 tid_disable_agg;
423*4882a593Smuzhiyun u16 max_agg_bufsize;
424*4882a593Smuzhiyun enum iwl_sta_type sta_type;
425*4882a593Smuzhiyun enum ieee80211_sta_state sta_state;
426*4882a593Smuzhiyun bool bt_reduced_txpower;
427*4882a593Smuzhiyun bool next_status_eosp;
428*4882a593Smuzhiyun spinlock_t lock;
429*4882a593Smuzhiyun struct iwl_mvm_tid_data tid_data[IWL_MAX_TID_COUNT + 1];
430*4882a593Smuzhiyun u8 tid_to_baid[IWL_MAX_TID_COUNT];
431*4882a593Smuzhiyun union {
432*4882a593Smuzhiyun struct iwl_lq_sta_rs_fw rs_fw;
433*4882a593Smuzhiyun struct iwl_lq_sta rs_drv;
434*4882a593Smuzhiyun } lq_sta;
435*4882a593Smuzhiyun struct ieee80211_vif *vif;
436*4882a593Smuzhiyun struct iwl_mvm_key_pn __rcu *ptk_pn[4];
437*4882a593Smuzhiyun struct iwl_mvm_rxq_dup_data *dup_data;
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun u8 reserved_queue;
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun /* Temporary, until the new TLC will control the Tx protection */
442*4882a593Smuzhiyun s8 tx_protection;
443*4882a593Smuzhiyun bool tt_tx_protection;
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun bool disable_tx;
446*4882a593Smuzhiyun u16 amsdu_enabled;
447*4882a593Smuzhiyun u16 max_amsdu_len;
448*4882a593Smuzhiyun u16 orig_amsdu_len;
449*4882a593Smuzhiyun bool sleeping;
450*4882a593Smuzhiyun u8 agg_tids;
451*4882a593Smuzhiyun u8 sleep_tx_count;
452*4882a593Smuzhiyun u8 avg_energy;
453*4882a593Smuzhiyun u8 tx_ant;
454*4882a593Smuzhiyun };
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun u16 iwl_mvm_tid_queued(struct iwl_mvm *mvm, struct iwl_mvm_tid_data *tid_data);
457*4882a593Smuzhiyun
458*4882a593Smuzhiyun static inline struct iwl_mvm_sta *
iwl_mvm_sta_from_mac80211(struct ieee80211_sta * sta)459*4882a593Smuzhiyun iwl_mvm_sta_from_mac80211(struct ieee80211_sta *sta)
460*4882a593Smuzhiyun {
461*4882a593Smuzhiyun return (void *)sta->drv_priv;
462*4882a593Smuzhiyun }
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun /**
465*4882a593Smuzhiyun * struct iwl_mvm_int_sta - representation of an internal station (auxiliary or
466*4882a593Smuzhiyun * broadcast)
467*4882a593Smuzhiyun * @sta_id: the index of the station in the fw (will be replaced by id_n_color)
468*4882a593Smuzhiyun * @type: station type
469*4882a593Smuzhiyun * @tfd_queue_msk: the tfd queues used by the station
470*4882a593Smuzhiyun */
471*4882a593Smuzhiyun struct iwl_mvm_int_sta {
472*4882a593Smuzhiyun u32 sta_id;
473*4882a593Smuzhiyun enum iwl_sta_type type;
474*4882a593Smuzhiyun u32 tfd_queue_msk;
475*4882a593Smuzhiyun };
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun /**
478*4882a593Smuzhiyun * Send the STA info to the FW.
479*4882a593Smuzhiyun *
480*4882a593Smuzhiyun * @mvm: the iwl_mvm* to use
481*4882a593Smuzhiyun * @sta: the STA
482*4882a593Smuzhiyun * @update: this is true if the FW is being updated about a STA it already knows
483*4882a593Smuzhiyun * about. Otherwise (if this is a new STA), this should be false.
484*4882a593Smuzhiyun * @flags: if update==true, this marks what is being changed via ORs of values
485*4882a593Smuzhiyun * from enum iwl_sta_modify_flag. Otherwise, this is ignored.
486*4882a593Smuzhiyun */
487*4882a593Smuzhiyun int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
488*4882a593Smuzhiyun bool update, unsigned int flags);
489*4882a593Smuzhiyun int iwl_mvm_add_sta(struct iwl_mvm *mvm,
490*4882a593Smuzhiyun struct ieee80211_vif *vif,
491*4882a593Smuzhiyun struct ieee80211_sta *sta);
492*4882a593Smuzhiyun
iwl_mvm_update_sta(struct iwl_mvm * mvm,struct ieee80211_vif * vif,struct ieee80211_sta * sta)493*4882a593Smuzhiyun static inline int iwl_mvm_update_sta(struct iwl_mvm *mvm,
494*4882a593Smuzhiyun struct ieee80211_vif *vif,
495*4882a593Smuzhiyun struct ieee80211_sta *sta)
496*4882a593Smuzhiyun {
497*4882a593Smuzhiyun return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0);
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun int iwl_mvm_wait_sta_queues_empty(struct iwl_mvm *mvm,
501*4882a593Smuzhiyun struct iwl_mvm_sta *mvm_sta);
502*4882a593Smuzhiyun int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
503*4882a593Smuzhiyun struct ieee80211_vif *vif,
504*4882a593Smuzhiyun struct ieee80211_sta *sta);
505*4882a593Smuzhiyun int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
506*4882a593Smuzhiyun struct ieee80211_vif *vif,
507*4882a593Smuzhiyun u8 sta_id);
508*4882a593Smuzhiyun int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
509*4882a593Smuzhiyun struct ieee80211_vif *vif,
510*4882a593Smuzhiyun struct ieee80211_sta *sta,
511*4882a593Smuzhiyun struct ieee80211_key_conf *keyconf,
512*4882a593Smuzhiyun u8 key_offset);
513*4882a593Smuzhiyun int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
514*4882a593Smuzhiyun struct ieee80211_vif *vif,
515*4882a593Smuzhiyun struct ieee80211_sta *sta,
516*4882a593Smuzhiyun struct ieee80211_key_conf *keyconf);
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
519*4882a593Smuzhiyun struct ieee80211_vif *vif,
520*4882a593Smuzhiyun struct ieee80211_key_conf *keyconf,
521*4882a593Smuzhiyun struct ieee80211_sta *sta, u32 iv32,
522*4882a593Smuzhiyun u16 *phase1key);
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
525*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb);
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun /* AMPDU */
528*4882a593Smuzhiyun int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
529*4882a593Smuzhiyun int tid, u16 ssn, bool start, u16 buf_size, u16 timeout);
530*4882a593Smuzhiyun int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
531*4882a593Smuzhiyun struct ieee80211_sta *sta, u16 tid, u16 *ssn);
532*4882a593Smuzhiyun int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
533*4882a593Smuzhiyun struct ieee80211_sta *sta, u16 tid, u16 buf_size,
534*4882a593Smuzhiyun bool amsdu);
535*4882a593Smuzhiyun int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
536*4882a593Smuzhiyun struct ieee80211_sta *sta, u16 tid);
537*4882a593Smuzhiyun int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
538*4882a593Smuzhiyun struct ieee80211_sta *sta, u16 tid);
539*4882a593Smuzhiyun
540*4882a593Smuzhiyun int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
541*4882a593Smuzhiyun int tid, u8 queue, bool start);
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm, u32 lmac_id);
544*4882a593Smuzhiyun int iwl_mvm_rm_aux_sta(struct iwl_mvm *mvm);
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
547*4882a593Smuzhiyun int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
548*4882a593Smuzhiyun int iwl_mvm_add_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
549*4882a593Smuzhiyun int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
550*4882a593Smuzhiyun int iwl_mvm_rm_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
551*4882a593Smuzhiyun int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
552*4882a593Smuzhiyun int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
553*4882a593Smuzhiyun int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
554*4882a593Smuzhiyun struct iwl_mvm_int_sta *sta,
555*4882a593Smuzhiyun u32 qmask, enum nl80211_iftype iftype,
556*4882a593Smuzhiyun enum iwl_sta_type type);
557*4882a593Smuzhiyun void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
558*4882a593Smuzhiyun void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta);
559*4882a593Smuzhiyun int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
560*4882a593Smuzhiyun int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
561*4882a593Smuzhiyun void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm);
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
564*4882a593Smuzhiyun struct ieee80211_sta *sta);
565*4882a593Smuzhiyun void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
566*4882a593Smuzhiyun struct ieee80211_sta *sta,
567*4882a593Smuzhiyun enum ieee80211_frame_release_type reason,
568*4882a593Smuzhiyun u16 cnt, u16 tids, bool more_data,
569*4882a593Smuzhiyun bool single_sta_queue);
570*4882a593Smuzhiyun int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
571*4882a593Smuzhiyun bool drain);
572*4882a593Smuzhiyun void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
573*4882a593Smuzhiyun struct iwl_mvm_sta *mvmsta, bool disable);
574*4882a593Smuzhiyun void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
575*4882a593Smuzhiyun struct ieee80211_sta *sta,
576*4882a593Smuzhiyun bool disable);
577*4882a593Smuzhiyun void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
578*4882a593Smuzhiyun struct iwl_mvm_vif *mvmvif,
579*4882a593Smuzhiyun bool disable);
580*4882a593Smuzhiyun void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
581*4882a593Smuzhiyun void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk);
582*4882a593Smuzhiyun int iwl_mvm_add_pasn_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
583*4882a593Smuzhiyun struct iwl_mvm_int_sta *sta, u8 *addr, u32 cipher,
584*4882a593Smuzhiyun u8 *key, u32 key_len);
585*4882a593Smuzhiyun #endif /* __sta_h__ */
586