xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h (revision 08062af0a52107a243f7608fd972edb54ca5b7f8)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6  */
7 #ifndef __IWL_MVM_H__
8 #define __IWL_MVM_H__
9 
10 #include <linux/list.h>
11 #include <linux/spinlock.h>
12 #include <linux/cleanup.h>
13 #include <linux/leds.h>
14 #include <linux/in6.h>
15 
16 #ifdef CONFIG_THERMAL
17 #include <linux/thermal.h>
18 #endif
19 
20 #include <linux/ptp_clock_kernel.h>
21 
22 #include <linux/ktime.h>
23 
24 #include "iwl-op-mode.h"
25 #include "iwl-trans.h"
26 #include "fw/notif-wait.h"
27 #include "iwl-nvm-utils.h"
28 #include "fw/file.h"
29 #include "iwl-config.h"
30 #include "sta.h"
31 #include "fw-api.h"
32 #include "constants.h"
33 #include "fw/runtime.h"
34 #include "fw/dbg.h"
35 #include "fw/acpi.h"
36 #include "mei/iwl-mei.h"
37 #include "iwl-nvm-parse.h"
38 
39 #include <linux/average.h>
40 
41 #define IWL_MVM_MAX_ADDRESSES		5
42 /* RSSI offset for WkP */
43 #define IWL_RSSI_OFFSET 50
44 #define IWL_MVM_MISSED_BEACONS_SINCE_RX_THOLD 4
45 #define IWL_MVM_MISSED_BEACONS_THRESHOLD 8
46 #define IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG 19
47 
48 /* A TimeUnit is 1024 microsecond */
49 #define MSEC_TO_TU(_msec)	(_msec*1000/1024)
50 
51 /* For GO, this value represents the number of TUs before CSA "beacon
52  * 0" TBTT when the CSA time-event needs to be scheduled to start.  It
53  * must be big enough to ensure that we switch in time.
54  */
55 #define IWL_MVM_CHANNEL_SWITCH_TIME_GO		40
56 
57 /* For client, this value represents the number of TUs before CSA
58  * "beacon 1" TBTT, instead.  This is because we don't know when the
59  * GO/AP will be in the new channel, so we switch early enough.
60  */
61 #define IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT	10
62 
63 /*
64  * This value (in TUs) is used to fine tune the CSA NoA end time which should
65  * be just before "beacon 0" TBTT.
66  */
67 #define IWL_MVM_CHANNEL_SWITCH_MARGIN 4
68 
69 /*
70  * Number of beacons to transmit on a new channel until we unblock tx to
71  * the stations, even if we didn't identify them on a new channel
72  */
73 #define IWL_MVM_CS_UNBLOCK_TX_TIMEOUT 3
74 
75 /* offchannel queue towards mac80211 */
76 #define IWL_MVM_OFFCHANNEL_QUEUE 0
77 
78 /* invalid value for FW link id */
79 #define IWL_MVM_FW_LINK_ID_INVALID 0xff
80 
81 extern const struct ieee80211_ops iwl_mvm_hw_ops;
82 extern const struct ieee80211_ops iwl_mvm_mld_hw_ops;
83 
84 /**
85  * struct iwl_mvm_mod_params - module parameters for iwlmvm
86  * @power_scheme: one of enum iwl_power_scheme
87  */
88 struct iwl_mvm_mod_params {
89 	int power_scheme;
90 };
91 extern struct iwl_mvm_mod_params iwlmvm_mod_params;
92 
93 struct iwl_mvm_phy_ctxt {
94 	u16 id;
95 	u16 color;
96 	u32 ref;
97 
98 	enum nl80211_chan_width width;
99 
100 	struct ieee80211_channel *channel;
101 
102 	/* track for RLC config command */
103 	u32 center_freq1;
104 	bool rlc_disabled;
105 	u32 channel_load_by_us;
106 };
107 
108 struct iwl_mvm_time_event_data {
109 	struct ieee80211_vif *vif;
110 	struct list_head list;
111 	unsigned long end_jiffies;
112 	u32 duration;
113 	bool running;
114 	u32 uid;
115 
116 	/*
117 	 * The access to the 'id' field must be done when the
118 	 * mvm->time_event_lock is held, as it value is used to indicate
119 	 * if the te is in the time event list or not (when id == TE_MAX)
120 	 */
121 	u32 id;
122 	s8 link_id;
123 };
124 
125  /* Power management */
126 
127 /**
128  * enum iwl_power_scheme
129  * @IWL_POWER_SCHEME_CAM: Continuously Active Mode
130  * @IWL_POWER_SCHEME_BPS: Balanced Power Save (default)
131  * @IWL_POWER_SCHEME_LP: Low Power
132  */
133 enum iwl_power_scheme {
134 	IWL_POWER_SCHEME_CAM = 1,
135 	IWL_POWER_SCHEME_BPS,
136 	IWL_POWER_SCHEME_LP
137 };
138 
139 #define IWL_UAPSD_MAX_SP		IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL
140 
141 #ifdef CONFIG_IWLWIFI_DEBUGFS
142 enum iwl_dbgfs_pm_mask {
143 	MVM_DEBUGFS_PM_KEEP_ALIVE = BIT(0),
144 	MVM_DEBUGFS_PM_SKIP_OVER_DTIM = BIT(1),
145 	MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS = BIT(2),
146 	MVM_DEBUGFS_PM_RX_DATA_TIMEOUT = BIT(3),
147 	MVM_DEBUGFS_PM_TX_DATA_TIMEOUT = BIT(4),
148 	MVM_DEBUGFS_PM_LPRX_ENA = BIT(6),
149 	MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD = BIT(7),
150 	MVM_DEBUGFS_PM_SNOOZE_ENABLE = BIT(8),
151 	MVM_DEBUGFS_PM_UAPSD_MISBEHAVING = BIT(9),
152 	MVM_DEBUGFS_PM_USE_PS_POLL = BIT(10),
153 };
154 
155 struct iwl_dbgfs_pm {
156 	u16 keep_alive_seconds;
157 	u32 rx_data_timeout;
158 	u32 tx_data_timeout;
159 	bool skip_over_dtim;
160 	u8 skip_dtim_periods;
161 	bool lprx_ena;
162 	u32 lprx_rssi_threshold;
163 	bool snooze_ena;
164 	bool uapsd_misbehaving;
165 	bool use_ps_poll;
166 	int mask;
167 };
168 
169 /* beacon filtering */
170 
171 enum iwl_dbgfs_bf_mask {
172 	MVM_DEBUGFS_BF_ENERGY_DELTA = BIT(0),
173 	MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA = BIT(1),
174 	MVM_DEBUGFS_BF_ROAMING_STATE = BIT(2),
175 	MVM_DEBUGFS_BF_TEMP_THRESHOLD = BIT(3),
176 	MVM_DEBUGFS_BF_TEMP_FAST_FILTER = BIT(4),
177 	MVM_DEBUGFS_BF_TEMP_SLOW_FILTER = BIT(5),
178 	MVM_DEBUGFS_BF_ENABLE_BEACON_FILTER = BIT(6),
179 	MVM_DEBUGFS_BF_DEBUG_FLAG = BIT(7),
180 	MVM_DEBUGFS_BF_ESCAPE_TIMER = BIT(8),
181 	MVM_DEBUGFS_BA_ESCAPE_TIMER = BIT(9),
182 	MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT = BIT(10),
183 };
184 
185 struct iwl_dbgfs_bf {
186 	u32 bf_energy_delta;
187 	u32 bf_roaming_energy_delta;
188 	u32 bf_roaming_state;
189 	u32 bf_temp_threshold;
190 	u32 bf_temp_fast_filter;
191 	u32 bf_temp_slow_filter;
192 	u32 bf_enable_beacon_filter;
193 	u32 bf_debug_flag;
194 	u32 bf_escape_timer;
195 	u32 ba_escape_timer;
196 	u32 ba_enable_beacon_abort;
197 	int mask;
198 };
199 #endif
200 
201 enum iwl_mvm_smps_type_request {
202 	IWL_MVM_SMPS_REQ_BT_COEX,
203 	IWL_MVM_SMPS_REQ_TT,
204 	IWL_MVM_SMPS_REQ_PROT,
205 	IWL_MVM_SMPS_REQ_FW,
206 	NUM_IWL_MVM_SMPS_REQ,
207 };
208 
209 enum iwl_bt_force_ant_mode {
210 	BT_FORCE_ANT_DIS = 0,
211 	BT_FORCE_ANT_AUTO,
212 	BT_FORCE_ANT_BT,
213 	BT_FORCE_ANT_WIFI,
214 
215 	BT_FORCE_ANT_MAX,
216 };
217 
218 /**
219  * enum iwl_mvm_low_latency_force - low latency force mode set by debugfs
220  * @LOW_LATENCY_FORCE_UNSET: unset force mode
221  * @LOW_LATENCY_FORCE_ON: for low latency on
222  * @LOW_LATENCY_FORCE_OFF: for low latency off
223  * @NUM_LOW_LATENCY_FORCE: max num of modes
224  */
225 enum iwl_mvm_low_latency_force {
226 	LOW_LATENCY_FORCE_UNSET,
227 	LOW_LATENCY_FORCE_ON,
228 	LOW_LATENCY_FORCE_OFF,
229 	NUM_LOW_LATENCY_FORCE
230 };
231 
232 /**
233 * enum iwl_mvm_low_latency_cause - low latency set causes
234 * @LOW_LATENCY_TRAFFIC: indicates low latency traffic was detected
235 * @LOW_LATENCY_DEBUGFS: low latency mode set from debugfs
236 * @LOW_LATENCY_VCMD: low latency mode set from vendor command
237 * @LOW_LATENCY_VIF_TYPE: low latency mode set because of vif type (ap)
238 * @LOW_LATENCY_DEBUGFS_FORCE_ENABLE: indicate that force mode is enabled
239 *	the actual set/unset is done with LOW_LATENCY_DEBUGFS_FORCE
240 * @LOW_LATENCY_DEBUGFS_FORCE: low latency force mode from debugfs
241 *	set this with LOW_LATENCY_DEBUGFS_FORCE_ENABLE flag
242 *	in low_latency.
243 */
244 enum iwl_mvm_low_latency_cause {
245 	LOW_LATENCY_TRAFFIC = BIT(0),
246 	LOW_LATENCY_DEBUGFS = BIT(1),
247 	LOW_LATENCY_VCMD = BIT(2),
248 	LOW_LATENCY_VIF_TYPE = BIT(3),
249 	LOW_LATENCY_DEBUGFS_FORCE_ENABLE = BIT(4),
250 	LOW_LATENCY_DEBUGFS_FORCE = BIT(5),
251 };
252 
253 /**
254 * struct iwl_mvm_link_bf_data - beacon filtering related data
255 * @ave_beacon_signal: average beacon signal
256 * @last_cqm_event: rssi of the last cqm event
257 * @bt_coex_min_thold: minimum threshold for BT coex
258 * @bt_coex_max_thold: maximum threshold for BT coex
259 * @last_bt_coex_event: rssi of the last BT coex event
260 */
261 struct iwl_mvm_link_bf_data {
262 	int ave_beacon_signal;
263 	int last_cqm_event;
264 	int bt_coex_min_thold;
265 	int bt_coex_max_thold;
266 	int last_bt_coex_event;
267 };
268 
269 /**
270  * struct iwl_probe_resp_data - data for NoA/CSA updates
271  * @rcu_head: used for freeing the data on update
272  * @notif: notification data
273  * @noa_len: length of NoA attribute, calculated from the notification
274  */
275 struct iwl_probe_resp_data {
276 	struct rcu_head rcu_head;
277 	struct iwl_probe_resp_data_notif notif;
278 	int noa_len;
279 };
280 
281 /**
282  * struct iwl_mvm_vif_link_info - per link data in Virtual Interface
283  * @ap_sta_id: the sta_id of the AP - valid only if VIF type is STA
284  * @fw_link_id: the id of the link according to the FW API
285  * @bssid: BSSID for this (client) interface
286  * @bcast_sta: station used for broadcast packets. Used by the following
287  *	vifs: P2P_DEVICE, GO and AP.
288  * @beacon_stats: beacon statistics, containing the # of received beacons,
289  *	# of received beacons accumulated over FW restart, and the current
290  *	average signal of beacons retrieved from the firmware
291  * @smps_requests: the SMPS requests of different parts of the driver,
292  *	combined on update to yield the overall request to mac80211.
293  * @probe_resp_data: data from FW notification to store NOA and CSA related
294  *	data to be inserted into probe response.
295  * @he_ru_2mhz_block: 26-tone RU OFDMA transmissions should be blocked
296  * @queue_params: QoS params for this MAC
297  * @mgmt_queue: queue number for unbufferable management frames
298  * @igtk: the current IGTK programmed into the firmware
299  * @active: indicates the link is active in FW (for sanity checking)
300  * @cab_queue: content-after-beacon (multicast) queue
301  * @listen_lmac: indicates this link is allocated to the listen LMAC
302  * @csa_block_tx: we got CSA with mode=1
303  * @mcast_sta: multicast station
304  * @phy_ctxt: phy context allocated to this link, if any
305  * @bf_data: beacon filtering data
306  */
307 struct iwl_mvm_vif_link_info {
308 	u8 bssid[ETH_ALEN];
309 	u8 ap_sta_id;
310 	u8 fw_link_id;
311 
312 	struct iwl_mvm_int_sta bcast_sta;
313 	struct iwl_mvm_int_sta mcast_sta;
314 
315 	struct {
316 		u32 num_beacons, accu_num_beacons;
317 		u8 avg_signal;
318 	} beacon_stats;
319 
320 	enum ieee80211_smps_mode smps_requests[NUM_IWL_MVM_SMPS_REQ];
321 	struct iwl_probe_resp_data __rcu *probe_resp_data;
322 
323 	struct ieee80211_key_conf *igtk;
324 
325 	bool he_ru_2mhz_block;
326 	bool active;
327 	bool listen_lmac;
328 	bool csa_block_tx;
329 
330 	u16 cab_queue;
331 	/* Assigned while mac80211 has the link in a channel context,
332 	 * or, for P2P Device, while it exists.
333 	 */
334 	struct iwl_mvm_phy_ctxt *phy_ctxt;
335 	/* QoS data from mac80211, need to store this here
336 	 * as mac80211 has a separate callback but we need
337 	 * to have the data for the MAC context
338 	 */
339 	struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
340 
341 	u16 mgmt_queue;
342 
343 	struct iwl_mvm_link_bf_data bf_data;
344 };
345 
346 /**
347  * enum iwl_mvm_esr_state - defines reasons for which the EMLSR is exited or
348  * blocked.
349  * The low 16 bits are used for blocking reasons, and the 16 higher bits
350  * are used for exit reasons.
351  * For the blocking reasons - use iwl_mvm_(un)block_esr(), and for the exit
352  * reasons - use iwl_mvm_exit_esr().
353  *
354  * Note: new reasons shall be added to HANDLE_ESR_REASONS as well (for logs)
355  *
356  * @IWL_MVM_ESR_BLOCKED_PREVENTION: Prevent EMLSR to avoid entering and exiting
357  *	in a loop.
358  * @IWL_MVM_ESR_BLOCKED_WOWLAN: WOWLAN is preventing the enablement of EMLSR
359  * @IWL_MVM_ESR_BLOCKED_TPT: block EMLSR when there is not enough traffic
360  * @IWL_MVM_ESR_BLOCKED_FW: FW didn't recommended/forced exit from EMLSR
361  * @IWL_MVM_ESR_BLOCKED_NON_BSS: An active non-BSS interface's link is
362  *	preventing EMLSR
363  * @IWL_MVM_ESR_BLOCKED_ROC: remain-on-channel is preventing EMLSR
364  * @IWL_MVM_ESR_EXIT_MISSED_BEACON: exited EMLSR due to missed beacons
365  * @IWL_MVM_ESR_EXIT_LOW_RSSI: link is deactivated/not allowed for EMLSR
366  *	due to low RSSI.
367  * @IWL_MVM_ESR_EXIT_COEX: link is deactivated/not allowed for EMLSR
368  *	due to BT Coex.
369  * @IWL_MVM_ESR_EXIT_BANDWIDTH: Bandwidths of primary and secondry links
370  *	preventing the enablement of EMLSR
371  * @IWL_MVM_ESR_EXIT_CSA: CSA happened, so exit EMLSR
372  * @IWL_MVM_ESR_EXIT_LINK_USAGE: Exit EMLSR due to low tpt on secondary link
373  * @IWL_MVM_ESR_EXIT_FAIL_ENTRY: Exit EMLSR due to entry failure
374  */
375 enum iwl_mvm_esr_state {
376 	IWL_MVM_ESR_BLOCKED_PREVENTION	= 0x1,
377 	IWL_MVM_ESR_BLOCKED_WOWLAN	= 0x2,
378 	IWL_MVM_ESR_BLOCKED_TPT		= 0x4,
379 	IWL_MVM_ESR_BLOCKED_FW		= 0x8,
380 	IWL_MVM_ESR_BLOCKED_NON_BSS	= 0x10,
381 	IWL_MVM_ESR_BLOCKED_ROC		= 0x20,
382 	IWL_MVM_ESR_EXIT_MISSED_BEACON	= 0x10000,
383 	IWL_MVM_ESR_EXIT_LOW_RSSI	= 0x20000,
384 	IWL_MVM_ESR_EXIT_COEX		= 0x40000,
385 	IWL_MVM_ESR_EXIT_BANDWIDTH	= 0x80000,
386 	IWL_MVM_ESR_EXIT_CSA		= 0x100000,
387 	IWL_MVM_ESR_EXIT_LINK_USAGE	= 0x200000,
388 	IWL_MVM_ESR_EXIT_FAIL_ENTRY	= 0x400000,
389 };
390 
391 #define IWL_MVM_BLOCK_ESR_REASONS 0xffff
392 
393 const char *iwl_get_esr_state_string(enum iwl_mvm_esr_state state);
394 
395 /**
396  * struct iwl_mvm_esr_exit - details of the last exit from EMLSR mode.
397  * @reason: The reason for the last exit from EMLSR.
398  *	&iwl_mvm_prevent_esr_reasons. Will be 0 before exiting EMLSR.
399  * @ts: the time stamp of the last time we existed EMLSR.
400  */
401 struct iwl_mvm_esr_exit {
402 	unsigned long ts;
403 	enum iwl_mvm_esr_state reason;
404 };
405 
406 /**
407  * struct iwl_mvm_vif - data per Virtual Interface, it is a MAC context
408  * @mvm: pointer back to the mvm struct
409  * @id: between 0 and 3
410  * @color: to solve races upon MAC addition and removal
411  * @associated: indicates that we're currently associated, used only for
412  *	managing the firmware state in iwl_mvm_bss_info_changed_station()
413  * @ap_assoc_sta_count: count of stations associated to us - valid only
414  *	if VIF type is AP
415  * @uploaded: indicates the MAC context has been added to the device
416  * @ap_ibss_active: indicates that AP/IBSS is configured and that the interface
417  *	should get quota etc.
418  * @pm_enabled - indicate if MAC power management is allowed
419  * @monitor_active: indicates that monitor context is configured, and that the
420  *	interface should get quota etc.
421  * @low_latency: bit flags for low latency
422  *	see enum &iwl_mvm_low_latency_cause for causes.
423  * @low_latency_actual: boolean, indicates low latency is set,
424  *	as a result from low_latency bit flags and takes force into account.
425  * @authorized: indicates the AP station was set to authorized
426  * @ps_disabled: indicates that this interface requires PS to be disabled
427  * @csa_countdown: indicates that CSA countdown may be started
428  * @csa_failed: CSA failed to schedule time event, report an error later
429  * @csa_bcn_pending: indicates that we are waiting for a beacon on a new channel
430  * @csa_blocks_tx: CSA is blocking TX
431  * @features: hw features active for this vif
432  * @max_tx_op: max TXOP in usecs for all ACs, zero for no limit.
433  * @ap_beacon_time: AP beacon time for synchronisation (on older FW)
434  * @bf_enabled: indicates if beacon filtering is enabled
435  * @ba_enabled: indicated if beacon abort is enabled
436  * @bcn_prot: beacon protection data (keys; FIXME: needs to be per link)
437  * @deflink: default link data for use in non-MLO
438  * @link: link data for each link in MLO
439  * @esr_active: indicates eSR mode is active
440  * @esr_disable_reason: a bitmap of &enum iwl_mvm_esr_state
441  * @pm_enabled: indicates powersave is enabled
442  * @link_selection_res: bitmap of active links as it was decided in the last
443  *	link selection. Valid only for a MLO vif after assoc. 0 if there wasn't
444  *	any link selection yet.
445  * @link_selection_primary: primary link selected by link selection
446  * @primary_link: primary link in eSR. Valid only for an associated MLD vif,
447  *	and in eSR mode. Valid only for a STA.
448  * @last_esr_exit: Details of the last exit from EMLSR.
449  * @exit_same_reason_count: The number of times we exited due to the specified
450  *	@last_esr_exit::reason, only counting exits due to
451  *	&IWL_MVM_ESR_PREVENT_REASONS.
452  * @prevent_esr_done_wk: work that should be done when esr prevention ends.
453  * @mlo_int_scan_wk: work for the internal MLO scan.
454  * @unblock_esr_tpt_wk: work for unblocking EMLSR when tpt is high enough.
455  * @roc_activity: currently running ROC activity for this vif (or
456  *	ROC_NUM_ACTIVITIES if no activity is running).
457  * @session_prot_connection_loss: the connection was lost due to session
458  *	protection ending without receiving a beacon, so we need to now
459  *	protect the deauth separately
460  * @ap_early_keys: The firmware cannot install keys before stations etc.,
461  *	but higher layers work differently, so we store the keys here for
462  *	later installation.
463  * @ap_sta: pointer to the AP STA data structure
464  * @csa_count: CSA counter (old CSA implementation w/o firmware)
465  * @csa_misbehave: CSA AP misbehaviour flag (old implementation)
466  * @csa_target_freq: CSA target channel frequency (old implementation)
467  * @csa_work: CSA work (old implementation)
468  * @dbgfs_bf: beamforming debugfs data
469  * @dbgfs_dir: debugfs directory for this vif
470  * @dbgfs_pm: power management debugfs data
471  * @dbgfs_quota_min: debugfs value for minimal quota
472  * @dbgfs_slink: debugfs symlink for this interface
473  * @ftm_unprotected: unprotected FTM debugfs override
474  * @hs_time_event_data: hotspot/AUX ROC time event data
475  * @mac_pwr_cmd: debugfs override for MAC power command
476  * @target_ipv6_addrs: IPv6 addresses on this interface for offload
477  * @num_target_ipv6_addrs: number of @target_ipv6_addrs
478  * @tentative_addrs: bitmap of tentative IPv6 addresses in @target_ipv6_addrs
479  * @rekey_data: rekeying data for WoWLAN GTK rekey offload
480  * @seqno: storage for seqno for older firmware D0/D3 transition
481  * @seqno_valid: indicates @seqno is valid
482  * @time_event_data: session protection time event data
483  * @tsf_id: the TSF resource ID assigned in firmware (for firmware needing that)
484  * @tx_key_idx: WEP transmit key index for D3
485  * @uapsd_misbehaving_ap_addr: MLD address/BSSID of U-APSD misbehaving AP, to
486  *	not use U-APSD on reconnection
487  * @uapsd_nonagg_detected_wk: worker for handling detection of no aggregation
488  *	in U-APSD
489  */
490 struct iwl_mvm_vif {
491 	struct iwl_mvm *mvm;
492 	u16 id;
493 	u16 color;
494 
495 	bool associated;
496 	u8 ap_assoc_sta_count;
497 	bool uploaded;
498 	bool ap_ibss_active;
499 	bool pm_enabled;
500 	bool monitor_active;
501 	bool esr_active;
502 	bool session_prot_connection_loss;
503 
504 	u8 low_latency: 6;
505 	u8 low_latency_actual: 1;
506 
507 	u8 authorized:1;
508 	bool ps_disabled;
509 
510 	u32 esr_disable_reason;
511 	u32 ap_beacon_time;
512 	bool bf_enabled;
513 	bool ba_enabled;
514 
515 #ifdef CONFIG_PM
516 	/* WoWLAN GTK rekey data */
517 	struct {
518 		u8 kck[NL80211_KCK_EXT_LEN];
519 		u8 kek[NL80211_KEK_EXT_LEN];
520 		size_t kek_len;
521 		size_t kck_len;
522 		u32 akm;
523 		__le64 replay_ctr;
524 		bool valid;
525 	} rekey_data;
526 
527 	int tx_key_idx;
528 
529 	bool seqno_valid;
530 	u16 seqno;
531 #endif
532 
533 #if IS_ENABLED(CONFIG_IPV6)
534 	/* IPv6 addresses for WoWLAN */
535 	struct in6_addr target_ipv6_addrs[IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX];
536 	unsigned long tentative_addrs[BITS_TO_LONGS(IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)];
537 	int num_target_ipv6_addrs;
538 #endif
539 
540 #ifdef CONFIG_IWLWIFI_DEBUGFS
541 	struct dentry *dbgfs_dir;
542 	struct dentry *dbgfs_slink;
543 	struct iwl_dbgfs_pm dbgfs_pm;
544 	struct iwl_dbgfs_bf dbgfs_bf;
545 	struct iwl_mac_power_cmd mac_pwr_cmd;
546 	int dbgfs_quota_min;
547 	bool ftm_unprotected;
548 #endif
549 
550 	/* FW identified misbehaving AP */
551 	u8 uapsd_misbehaving_ap_addr[ETH_ALEN] __aligned(2);
552 	struct delayed_work uapsd_nonagg_detected_wk;
553 
554 	bool csa_countdown;
555 	bool csa_failed;
556 	bool csa_bcn_pending;
557 	bool csa_blocks_tx;
558 	u16 csa_target_freq;
559 	u16 csa_count;
560 	u16 csa_misbehave;
561 	struct delayed_work csa_work;
562 
563 	enum iwl_tsf_id tsf_id;
564 
565 	struct iwl_mvm_time_event_data time_event_data;
566 	struct iwl_mvm_time_event_data hs_time_event_data;
567 	enum iwl_roc_activity roc_activity;
568 
569 	/* TCP Checksum Offload */
570 	netdev_features_t features;
571 
572 	struct ieee80211_sta *ap_sta;
573 
574 	/* we can only have 2 GTK + 2 IGTK active at a time */
575 	struct ieee80211_key_conf *ap_early_keys[4];
576 
577 	struct {
578 		struct ieee80211_key_conf __rcu *keys[2];
579 	} bcn_prot;
580 
581 	u16 max_tx_op;
582 
583 	u16 link_selection_res;
584 	u8 link_selection_primary;
585 	u8 primary_link;
586 	struct iwl_mvm_esr_exit last_esr_exit;
587 	u8 exit_same_reason_count;
588 	struct wiphy_delayed_work prevent_esr_done_wk;
589 	struct wiphy_delayed_work mlo_int_scan_wk;
590 	struct wiphy_work unblock_esr_tpt_wk;
591 
592 	struct iwl_mvm_vif_link_info deflink;
593 	struct iwl_mvm_vif_link_info *link[IEEE80211_MLD_MAX_NUM_LINKS];
594 };
595 
596 #define for_each_mvm_vif_valid_link(mvm_vif, link_id)			\
597 	for (link_id = 0;						\
598 	     link_id < ARRAY_SIZE((mvm_vif)->link);			\
599 	     link_id++)							\
600 		if ((mvm_vif)->link[link_id])
601 
602 static inline struct iwl_mvm_vif *
603 iwl_mvm_vif_from_mac80211(struct ieee80211_vif *vif)
604 {
605 	return (void *)vif->drv_priv;
606 }
607 
608 extern const u8 tid_to_mac80211_ac[];
609 
610 #define IWL_MVM_SCAN_STOPPING_SHIFT	8
611 
612 enum iwl_scan_status {
613 	IWL_MVM_SCAN_REGULAR		= BIT(0),
614 	IWL_MVM_SCAN_SCHED		= BIT(1),
615 	IWL_MVM_SCAN_NETDETECT		= BIT(2),
616 	IWL_MVM_SCAN_INT_MLO		= BIT(3),
617 
618 	IWL_MVM_SCAN_STOPPING_REGULAR	= BIT(8),
619 	IWL_MVM_SCAN_STOPPING_SCHED	= BIT(9),
620 	IWL_MVM_SCAN_STOPPING_NETDETECT	= BIT(10),
621 	IWL_MVM_SCAN_STOPPING_INT_MLO	= BIT(11),
622 
623 	IWL_MVM_SCAN_REGULAR_MASK	= IWL_MVM_SCAN_REGULAR |
624 					  IWL_MVM_SCAN_STOPPING_REGULAR,
625 	IWL_MVM_SCAN_SCHED_MASK		= IWL_MVM_SCAN_SCHED |
626 					  IWL_MVM_SCAN_STOPPING_SCHED,
627 	IWL_MVM_SCAN_NETDETECT_MASK	= IWL_MVM_SCAN_NETDETECT |
628 					  IWL_MVM_SCAN_STOPPING_NETDETECT,
629 	IWL_MVM_SCAN_INT_MLO_MASK       = IWL_MVM_SCAN_INT_MLO |
630 					  IWL_MVM_SCAN_STOPPING_INT_MLO,
631 
632 	IWL_MVM_SCAN_STOPPING_MASK	= 0xff << IWL_MVM_SCAN_STOPPING_SHIFT,
633 	IWL_MVM_SCAN_MASK		= 0xff,
634 };
635 
636 enum iwl_mvm_scan_type {
637 	IWL_SCAN_TYPE_NOT_SET,
638 	IWL_SCAN_TYPE_UNASSOC,
639 	IWL_SCAN_TYPE_WILD,
640 	IWL_SCAN_TYPE_MILD,
641 	IWL_SCAN_TYPE_FRAGMENTED,
642 	IWL_SCAN_TYPE_FAST_BALANCE,
643 };
644 
645 enum iwl_mvm_sched_scan_pass_all_states {
646 	SCHED_SCAN_PASS_ALL_DISABLED,
647 	SCHED_SCAN_PASS_ALL_ENABLED,
648 	SCHED_SCAN_PASS_ALL_FOUND,
649 };
650 
651 /**
652  * struct iwl_mvm_tt_mgmt - Thermal Throttling Management structure
653  * @ct_kill_exit: worker to exit thermal kill
654  * @dynamic_smps: Is thermal throttling enabled dynamic_smps?
655  * @tx_backoff: The current thremal throttling tx backoff in uSec.
656  * @min_backoff: The minimal tx backoff due to power restrictions
657  * @params: Parameters to configure the thermal throttling algorithm.
658  * @throttle: Is thermal throttling is active?
659  */
660 struct iwl_mvm_tt_mgmt {
661 	struct delayed_work ct_kill_exit;
662 	bool dynamic_smps;
663 	u32 tx_backoff;
664 	u32 min_backoff;
665 	struct iwl_tt_params params;
666 	bool throttle;
667 };
668 
669 #ifdef CONFIG_THERMAL
670 /**
671  * struct iwl_mvm_thermal_device - thermal zone related data
672  * @trips: temperature thresholds for report
673  * @tzone: thermal zone device data
674 */
675 struct iwl_mvm_thermal_device {
676 	struct thermal_trip trips[IWL_MAX_DTS_TRIPS];
677 	struct thermal_zone_device *tzone;
678 };
679 
680 /*
681  * struct iwl_mvm_cooling_device
682  * @cur_state: current state
683  * @cdev: struct thermal cooling device
684  */
685 struct iwl_mvm_cooling_device {
686 	u32 cur_state;
687 	struct thermal_cooling_device *cdev;
688 };
689 #endif
690 
691 #define IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES 8
692 
693 struct iwl_mvm_frame_stats {
694 	u32 legacy_frames;
695 	u32 ht_frames;
696 	u32 vht_frames;
697 	u32 bw_20_frames;
698 	u32 bw_40_frames;
699 	u32 bw_80_frames;
700 	u32 bw_160_frames;
701 	u32 sgi_frames;
702 	u32 ngi_frames;
703 	u32 siso_frames;
704 	u32 mimo2_frames;
705 	u32 agg_frames;
706 	u32 ampdu_count;
707 	u32 success_frames;
708 	u32 fail_frames;
709 	u32 last_rates[IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES];
710 	int last_frame_idx;
711 };
712 
713 #define IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE 0xff
714 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -100
715 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MAX 200
716 
717 enum iwl_mvm_tdls_cs_state {
718 	IWL_MVM_TDLS_SW_IDLE = 0,
719 	IWL_MVM_TDLS_SW_REQ_SENT,
720 	IWL_MVM_TDLS_SW_RESP_RCVD,
721 	IWL_MVM_TDLS_SW_REQ_RCVD,
722 	IWL_MVM_TDLS_SW_ACTIVE,
723 };
724 
725 enum iwl_mvm_traffic_load {
726 	IWL_MVM_TRAFFIC_LOW,
727 	IWL_MVM_TRAFFIC_MEDIUM,
728 	IWL_MVM_TRAFFIC_HIGH,
729 };
730 
731 DECLARE_EWMA(rate, 16, 16)
732 
733 struct iwl_mvm_tcm_mac {
734 	struct {
735 		u32 pkts[IEEE80211_NUM_ACS];
736 		u32 airtime;
737 	} tx;
738 	struct {
739 		u32 pkts[IEEE80211_NUM_ACS];
740 		u32 airtime;
741 		u32 last_ampdu_ref;
742 	} rx;
743 	struct {
744 		/* track AP's transfer in client mode */
745 		u64 rx_bytes;
746 		struct ewma_rate rate;
747 		bool detected;
748 	} uapsd_nonagg_detect;
749 	bool opened_rx_ba_sessions;
750 };
751 
752 struct iwl_mvm_tcm {
753 	struct delayed_work work;
754 	spinlock_t lock; /* used when time elapsed */
755 	unsigned long ts; /* timestamp when period ends */
756 	unsigned long ll_ts;
757 	unsigned long uapsd_nonagg_ts;
758 	bool paused;
759 	struct iwl_mvm_tcm_mac data[NUM_MAC_INDEX_DRIVER];
760 	struct {
761 		u32 elapsed; /* milliseconds for this TCM period */
762 		u32 airtime[NUM_MAC_INDEX_DRIVER];
763 		enum iwl_mvm_traffic_load load[NUM_MAC_INDEX_DRIVER];
764 		enum iwl_mvm_traffic_load band_load[NUM_NL80211_BANDS];
765 		enum iwl_mvm_traffic_load global_load;
766 		bool low_latency[NUM_MAC_INDEX_DRIVER];
767 		bool change[NUM_MAC_INDEX_DRIVER];
768 	} result;
769 };
770 
771 /**
772  * struct iwl_mvm_reorder_buffer - per ra/tid/queue reorder buffer
773  * @head_sn: reorder window head sn
774  * @num_stored: number of mpdus stored in the buffer
775  * @queue: queue of this reorder buffer
776  * @last_amsdu: track last ASMDU SN for duplication detection
777  * @valid: reordering is valid for this queue
778  * @lock: protect reorder buffer internal state
779  */
780 struct iwl_mvm_reorder_buffer {
781 	u16 head_sn;
782 	u16 num_stored;
783 	int queue;
784 	u16 last_amsdu;
785 	bool valid;
786 	spinlock_t lock;
787 } ____cacheline_aligned_in_smp;
788 
789 /**
790  * struct iwl_mvm_reorder_buf_entry - reorder buffer entry per-queue/per-seqno
791  * @frames: list of skbs stored
792  */
793 struct iwl_mvm_reorder_buf_entry {
794 	struct sk_buff_head frames;
795 }
796 #ifndef __CHECKER__
797 /* sparse doesn't like this construct: "bad integer constant expression" */
798 __aligned(roundup_pow_of_two(sizeof(struct sk_buff_head)))
799 #endif
800 ;
801 
802 /**
803  * struct iwl_mvm_baid_data - BA session data
804  * @sta_mask: current station mask for the BAID
805  * @tid: tid of the session
806  * @baid: baid of the session
807  * @timeout: the timeout set in the addba request
808  * @buf_size: the reorder buffer size as set by the last addba request
809  * @entries_per_queue: # of buffers per queue, this actually gets
810  *	aligned up to avoid cache line sharing between queues
811  * @last_rx: last rx jiffies, updated only if timeout passed from last update
812  * @session_timer: timer to check if BA session expired, runs at 2 * timeout
813  * @rcu_ptr: BA data RCU protected access
814  * @rcu_head: RCU head for freeing this data
815  * @mvm: mvm pointer, needed for timer context
816  * @reorder_buf: reorder buffer, allocated per queue
817  * @entries: data
818  */
819 struct iwl_mvm_baid_data {
820 	struct rcu_head rcu_head;
821 	u32 sta_mask;
822 	u8 tid;
823 	u8 baid;
824 	u16 timeout;
825 	u16 buf_size;
826 	u16 entries_per_queue;
827 	unsigned long last_rx;
828 	struct timer_list session_timer;
829 	struct iwl_mvm_baid_data __rcu **rcu_ptr;
830 	struct iwl_mvm *mvm;
831 	struct iwl_mvm_reorder_buffer reorder_buf[IWL_MAX_RX_HW_QUEUES];
832 	struct iwl_mvm_reorder_buf_entry entries[] ____cacheline_aligned_in_smp;
833 };
834 
835 static inline struct iwl_mvm_baid_data *
836 iwl_mvm_baid_data_from_reorder_buf(struct iwl_mvm_reorder_buffer *buf)
837 {
838 	return (void *)((u8 *)buf -
839 			offsetof(struct iwl_mvm_baid_data, reorder_buf) -
840 			sizeof(*buf) * buf->queue);
841 }
842 
843 /*
844  * enum iwl_mvm_queue_status - queue status
845  * @IWL_MVM_QUEUE_FREE: the queue is not allocated nor reserved
846  *	Basically, this means that this queue can be used for any purpose
847  * @IWL_MVM_QUEUE_RESERVED: queue is reserved but not yet in use
848  *	This is the state of a queue that has been dedicated for some RATID
849  *	(agg'd or not), but that hasn't yet gone through the actual enablement
850  *	of iwl_mvm_enable_txq(), and therefore no traffic can go through it yet.
851  *	Note that in this state there is no requirement to already know what TID
852  *	should be used with this queue, it is just marked as a queue that will
853  *	be used, and shouldn't be allocated to anyone else.
854  * @IWL_MVM_QUEUE_READY: queue is ready to be used
855  *	This is the state of a queue that has been fully configured (including
856  *	SCD pointers, etc), has a specific RA/TID assigned to it, and can be
857  *	used to send traffic.
858  * @IWL_MVM_QUEUE_SHARED: queue is shared, or in a process of becoming shared
859  *	This is a state in which a single queue serves more than one TID, all of
860  *	which are not aggregated. Note that the queue is only associated to one
861  *	RA.
862  */
863 enum iwl_mvm_queue_status {
864 	IWL_MVM_QUEUE_FREE,
865 	IWL_MVM_QUEUE_RESERVED,
866 	IWL_MVM_QUEUE_READY,
867 	IWL_MVM_QUEUE_SHARED,
868 };
869 
870 #define IWL_MVM_DQA_QUEUE_TIMEOUT	(5 * HZ)
871 #define IWL_MVM_INVALID_QUEUE		0xFFFF
872 
873 #define IWL_MVM_NUM_CIPHERS             10
874 
875 
876 struct iwl_mvm_txq {
877 	struct list_head list;
878 	u16 txq_id;
879 	atomic_t tx_request;
880 #define IWL_MVM_TXQ_STATE_READY		0
881 #define IWL_MVM_TXQ_STATE_STOP_FULL	1
882 #define IWL_MVM_TXQ_STATE_STOP_REDIRECT	2
883 #define IWL_MVM_TXQ_STATE_STOP_AP_CSA	3
884 	unsigned long state;
885 };
886 
887 static inline struct iwl_mvm_txq *
888 iwl_mvm_txq_from_mac80211(struct ieee80211_txq *txq)
889 {
890 	return (void *)txq->drv_priv;
891 }
892 
893 static inline struct iwl_mvm_txq *
894 iwl_mvm_txq_from_tid(struct ieee80211_sta *sta, u8 tid)
895 {
896 	if (tid == IWL_MAX_TID_COUNT)
897 		tid = IEEE80211_NUM_TIDS;
898 
899 	return (void *)sta->txq[tid]->drv_priv;
900 }
901 
902 /**
903  * struct iwl_mvm_tvqm_txq_info - maps TVQM hw queue to tid
904  *
905  * @sta_id: sta id
906  * @txq_tid: txq tid
907  */
908 struct iwl_mvm_tvqm_txq_info {
909 	u8 sta_id;
910 	u8 txq_tid;
911 };
912 
913 struct iwl_mvm_dqa_txq_info {
914 	u8 ra_sta_id; /* The RA this queue is mapped to, if exists */
915 	bool reserved; /* Is this the TXQ reserved for a STA */
916 	u8 mac80211_ac; /* The mac80211 AC this queue is mapped to */
917 	u8 txq_tid; /* The TID "owner" of this queue*/
918 	u16 tid_bitmap; /* Bitmap of the TIDs mapped to this queue */
919 	/* Timestamp for inactivation per TID of this queue */
920 	unsigned long last_frame_time[IWL_MAX_TID_COUNT + 1];
921 	enum iwl_mvm_queue_status status;
922 };
923 
924 struct ptp_data {
925 	struct ptp_clock *ptp_clock;
926 	struct ptp_clock_info ptp_clock_info;
927 
928 	struct delayed_work dwork;
929 
930 	/* The last GP2 reading from the hw */
931 	u32 last_gp2;
932 
933 	/* number of wraparounds since scale_update_adj_time_ns */
934 	u32 wrap_counter;
935 
936 	/* GP2 time when the scale was last updated */
937 	u32 scale_update_gp2;
938 
939 	/* Adjusted time when the scale was last updated in nanoseconds */
940 	u64 scale_update_adj_time_ns;
941 
942 	/* clock frequency offset, scaled to 65536000000 */
943 	u64 scaled_freq;
944 
945 	/* Delta between hardware clock and ptp clock in nanoseconds */
946 	s64 delta;
947 };
948 
949 struct iwl_time_sync_data {
950 	struct sk_buff_head frame_list;
951 	u8 peer_addr[ETH_ALEN];
952 	bool active;
953 };
954 
955 struct iwl_mei_scan_filter {
956 	bool is_mei_limited_scan;
957 	struct sk_buff_head scan_res;
958 	struct work_struct scan_work;
959 };
960 
961 /**
962  * struct iwl_mvm_acs_survey_channel - per-channel survey information
963  *
964  * Stripped down version of &struct survey_info.
965  *
966  * @time: time in ms the radio was on the channel
967  * @time_busy: time in ms the channel was sensed busy
968  * @time_tx: time in ms spent transmitting data
969  * @time_rx: time in ms spent receiving data
970  * @noise: channel noise in dBm
971  */
972 struct iwl_mvm_acs_survey_channel {
973 	u32 time;
974 	u32 time_busy;
975 	u32 time_tx;
976 	u32 time_rx;
977 	s8 noise;
978 };
979 
980 struct iwl_mvm_acs_survey {
981 	struct iwl_mvm_acs_survey_channel *bands[NUM_NL80211_BANDS];
982 
983 	/* Overall number of channels */
984 	int n_channels;
985 
986 	/* Storage space for per-channel information follows */
987 	struct iwl_mvm_acs_survey_channel channels[] __counted_by(n_channels);
988 };
989 
990 struct iwl_mvm {
991 	/* for logger access */
992 	struct device *dev;
993 
994 	struct iwl_trans *trans;
995 	const struct iwl_fw *fw;
996 	const struct iwl_cfg *cfg;
997 	struct iwl_phy_db *phy_db;
998 	struct ieee80211_hw *hw;
999 
1000 	/* for protecting access to iwl_mvm */
1001 	struct mutex mutex;
1002 	struct list_head async_handlers_list;
1003 	spinlock_t async_handlers_lock;
1004 	struct work_struct async_handlers_wk;
1005 
1006 	/* For async rx handlers that require the wiphy lock */
1007 	struct wiphy_work async_handlers_wiphy_wk;
1008 
1009 	struct wiphy_work trig_link_selection_wk;
1010 
1011 	struct work_struct roc_done_wk;
1012 
1013 	unsigned long init_status;
1014 
1015 	unsigned long status;
1016 
1017 	u32 queue_sync_cookie;
1018 	unsigned long queue_sync_state;
1019 	/*
1020 	 * for beacon filtering -
1021 	 * currently only one interface can be supported
1022 	 */
1023 	struct iwl_mvm_vif *bf_allowed_vif;
1024 
1025 	bool hw_registered;
1026 	bool rfkill_safe_init_done;
1027 
1028 	u8 cca_40mhz_workaround;
1029 
1030 	u32 ampdu_ref;
1031 	bool ampdu_toggle;
1032 
1033 	struct iwl_notif_wait_data notif_wait;
1034 
1035 	union {
1036 		struct mvm_statistics_rx_v3 rx_stats_v3;
1037 		struct mvm_statistics_rx rx_stats;
1038 	};
1039 
1040 	struct {
1041 		u64 rx_time;
1042 		u64 tx_time;
1043 		u64 on_time_rf;
1044 		u64 on_time_scan;
1045 	} radio_stats, accu_radio_stats;
1046 
1047 	struct list_head add_stream_txqs;
1048 	union {
1049 		struct iwl_mvm_dqa_txq_info queue_info[IWL_MAX_HW_QUEUES];
1050 		struct iwl_mvm_tvqm_txq_info tvqm_info[IWL_MAX_TVQM_QUEUES];
1051 	};
1052 	struct work_struct add_stream_wk; /* To add streams to queues */
1053 	spinlock_t add_stream_lock;
1054 
1055 	const char *nvm_file_name;
1056 	struct iwl_nvm_data *nvm_data;
1057 	struct iwl_mei_nvm *mei_nvm_data;
1058 	struct iwl_mvm_csme_conn_info __rcu *csme_conn_info;
1059 	bool mei_rfkill_blocked;
1060 	bool mei_registered;
1061 	struct work_struct sap_connected_wk;
1062 
1063 	/*
1064 	 * NVM built based on the SAP data but that we can't free even after
1065 	 * we get ownership because it contains the cfg80211's channel.
1066 	 */
1067 	struct iwl_nvm_data *temp_nvm_data;
1068 
1069 	/* NVM sections */
1070 	struct iwl_nvm_section nvm_sections[NVM_MAX_NUM_SECTIONS];
1071 
1072 	struct iwl_fw_runtime fwrt;
1073 
1074 	/* EEPROM MAC addresses */
1075 	struct mac_address addresses[IWL_MVM_MAX_ADDRESSES];
1076 
1077 	/* data related to data path */
1078 	struct iwl_rx_phy_info last_phy_info;
1079 	struct ieee80211_sta __rcu *fw_id_to_mac_id[IWL_STATION_COUNT_MAX];
1080 	struct ieee80211_link_sta __rcu *fw_id_to_link_sta[IWL_STATION_COUNT_MAX];
1081 	u8 rx_ba_sessions;
1082 
1083 	/* configured by mac80211 */
1084 	u32 rts_threshold;
1085 
1086 	/* Scan status, cmd (pre-allocated) and auxiliary station */
1087 	unsigned int scan_status;
1088 	size_t scan_cmd_size;
1089 	void *scan_cmd;
1090 	struct iwl_mcast_filter_cmd *mcast_filter_cmd;
1091 	/* For CDB this is low band scan type, for non-CDB - type. */
1092 	enum iwl_mvm_scan_type scan_type;
1093 	enum iwl_mvm_scan_type hb_scan_type;
1094 
1095 	enum iwl_mvm_sched_scan_pass_all_states sched_scan_pass_all;
1096 	struct delayed_work scan_timeout_dwork;
1097 
1098 	/* max number of simultaneous scans the FW supports */
1099 	unsigned int max_scans;
1100 
1101 	/* UMAC scan tracking */
1102 	u32 scan_uid_status[IWL_MAX_UMAC_SCANS];
1103 
1104 	/* start time of last scan in TSF of the mac that requested the scan */
1105 	u64 scan_start;
1106 
1107 	/* the vif that requested the current scan */
1108 	struct iwl_mvm_vif *scan_vif;
1109 	u8 scan_link_id;
1110 
1111 	/* rx chain antennas set through debugfs for the scan command */
1112 	u8 scan_rx_ant;
1113 
1114 	/* Internal station */
1115 	struct iwl_mvm_int_sta aux_sta;
1116 	struct iwl_mvm_int_sta snif_sta;
1117 
1118 	bool last_ebs_successful;
1119 
1120 	u8 scan_last_antenna_idx; /* to toggle TX between antennas */
1121 	u8 mgmt_last_antenna_idx;
1122 
1123 	u8 set_tx_ant;
1124 	u8 set_rx_ant;
1125 
1126 	/* last smart fifo state that was successfully sent to firmware */
1127 	enum iwl_sf_state sf_state;
1128 
1129 	/*
1130 	 * Leave this pointer outside the ifdef below so that it can be
1131 	 * assigned without ifdef in the source code.
1132 	 */
1133 	struct dentry *debugfs_dir;
1134 #ifdef CONFIG_IWLWIFI_DEBUGFS
1135 	u32 dbgfs_sram_offset, dbgfs_sram_len;
1136 	u32 dbgfs_prph_reg_addr;
1137 	bool disable_power_off;
1138 	bool disable_power_off_d3;
1139 	bool beacon_inject_active;
1140 
1141 	bool scan_iter_notif_enabled;
1142 
1143 	struct debugfs_blob_wrapper nvm_hw_blob;
1144 	struct debugfs_blob_wrapper nvm_sw_blob;
1145 	struct debugfs_blob_wrapper nvm_calib_blob;
1146 	struct debugfs_blob_wrapper nvm_prod_blob;
1147 	struct debugfs_blob_wrapper nvm_phy_sku_blob;
1148 	struct debugfs_blob_wrapper nvm_reg_blob;
1149 
1150 	struct iwl_mvm_frame_stats drv_rx_stats;
1151 	spinlock_t drv_stats_lock;
1152 	u16 dbgfs_rx_phyinfo;
1153 #endif
1154 
1155 	struct iwl_mvm_phy_ctxt phy_ctxts[NUM_PHY_CTX];
1156 
1157 	struct list_head time_event_list;
1158 	spinlock_t time_event_lock;
1159 
1160 	/*
1161 	 * A bitmap indicating the index of the key in use. The firmware
1162 	 * can hold 16 keys at most. Reflect this fact.
1163 	 */
1164 	unsigned long fw_key_table[BITS_TO_LONGS(STA_KEY_MAX_NUM)];
1165 	u8 fw_key_deleted[STA_KEY_MAX_NUM];
1166 
1167 	struct ieee80211_vif __rcu *vif_id_to_mac[NUM_MAC_INDEX_DRIVER];
1168 
1169 	struct ieee80211_bss_conf __rcu *link_id_to_link_conf[IWL_FW_MAX_LINK_ID + 1];
1170 
1171 	/* -1 for always, 0 for never, >0 for that many times */
1172 	s8 fw_restart;
1173 	u8 *error_recovery_buf;
1174 
1175 #ifdef CONFIG_IWLWIFI_LEDS
1176 	struct led_classdev led;
1177 #endif
1178 
1179 	struct ieee80211_vif *p2p_device_vif;
1180 
1181 #ifdef CONFIG_PM
1182 	struct wiphy_wowlan_support wowlan;
1183 	int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
1184 
1185 	/* sched scan settings for net detect */
1186 	struct ieee80211_scan_ies nd_ies;
1187 	struct cfg80211_match_set *nd_match_sets;
1188 	int n_nd_match_sets;
1189 	struct ieee80211_channel **nd_channels;
1190 	int n_nd_channels;
1191 	bool net_detect;
1192 	bool fast_resume;
1193 	u8 offload_tid;
1194 #ifdef CONFIG_IWLWIFI_DEBUGFS
1195 	bool d3_wake_sysassert;
1196 	bool d3_test_active;
1197 	u32 d3_test_pme_ptr;
1198 	struct ieee80211_vif *keep_vif;
1199 	u32 last_netdetect_scans; /* no. of scans in the last net-detect wake */
1200 #endif
1201 #endif
1202 
1203 	wait_queue_head_t rx_sync_waitq;
1204 
1205 	/* BT-Coex - only one of those will be used */
1206 	union {
1207 		struct iwl_bt_coex_prof_old_notif last_bt_notif;
1208 		struct iwl_bt_coex_profile_notif last_bt_wifi_loss;
1209 	};
1210 	struct iwl_bt_coex_ci_cmd last_bt_ci_cmd;
1211 
1212 	u8 bt_tx_prio;
1213 	enum iwl_bt_force_ant_mode bt_force_ant_mode;
1214 
1215 	/* Aux ROC */
1216 	struct list_head aux_roc_te_list;
1217 
1218 	/* Thermal Throttling and CTkill */
1219 	struct iwl_mvm_tt_mgmt thermal_throttle;
1220 #ifdef CONFIG_THERMAL
1221 	struct iwl_mvm_thermal_device tz_device;
1222 	struct iwl_mvm_cooling_device cooling_dev;
1223 #endif
1224 
1225 	s32 temperature;	/* Celsius */
1226 	/*
1227 	 * Debug option to set the NIC temperature. This option makes the
1228 	 * driver think this is the actual NIC temperature, and ignore the
1229 	 * real temperature that is received from the fw
1230 	 */
1231 	bool temperature_test;  /* Debug test temperature is enabled */
1232 
1233 	bool fw_static_smps_request;
1234 
1235 	unsigned long bt_coex_last_tcm_ts;
1236 	struct iwl_mvm_tcm tcm;
1237 
1238 	u8 uapsd_noagg_bssid_write_idx;
1239 	struct mac_address uapsd_noagg_bssids[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM]
1240 		__aligned(2);
1241 
1242 	struct iwl_time_quota_cmd last_quota_cmd;
1243 
1244 #ifdef CONFIG_NL80211_TESTMODE
1245 	u32 noa_duration;
1246 	struct ieee80211_vif *noa_vif;
1247 #endif
1248 
1249 	/* Tx queues */
1250 	u16 aux_queue;
1251 	u16 snif_queue;
1252 	u16 probe_queue;
1253 	u16 p2p_dev_queue;
1254 
1255 	/* Indicate if device power save is allowed */
1256 	u8 ps_disabled; /* u8 instead of bool to ease debugfs_create_* usage */
1257 	/* Indicate if 32Khz external clock is valid */
1258 	u32 ext_clock_valid;
1259 
1260 	/* This vif used by CSME to send / receive traffic */
1261 	struct ieee80211_vif *csme_vif;
1262 	struct ieee80211_vif __rcu *csa_vif;
1263 	struct ieee80211_vif __rcu *csa_tx_blocked_vif;
1264 	u8 csa_tx_block_bcn_timeout;
1265 
1266 	/* system time of last beacon (for AP/GO interface) */
1267 	u32 ap_last_beacon_gp2;
1268 
1269 	/* indicates that we transmitted the last beacon */
1270 	bool ibss_manager;
1271 
1272 	bool lar_regdom_set;
1273 	enum iwl_mcc_source mcc_src;
1274 
1275 	/* TDLS channel switch data */
1276 	struct {
1277 		struct delayed_work dwork;
1278 		enum iwl_mvm_tdls_cs_state state;
1279 
1280 		/*
1281 		 * Current cs sta - might be different from periodic cs peer
1282 		 * station. Value is meaningless when the cs-state is idle.
1283 		 */
1284 		u8 cur_sta_id;
1285 
1286 		/* TDLS periodic channel-switch peer */
1287 		struct {
1288 			u8 sta_id;
1289 			u8 op_class;
1290 			bool initiator; /* are we the link initiator */
1291 			struct cfg80211_chan_def chandef;
1292 			struct sk_buff *skb; /* ch sw template */
1293 			u32 ch_sw_tm_ie;
1294 
1295 			/* timestamp of last ch-sw request sent (GP2 time) */
1296 			u32 sent_timestamp;
1297 		} peer;
1298 	} tdls_cs;
1299 
1300 
1301 	u32 ciphers[IWL_MVM_NUM_CIPHERS];
1302 
1303 	struct cfg80211_ftm_responder_stats ftm_resp_stats;
1304 	struct {
1305 		struct cfg80211_pmsr_request *req;
1306 		struct wireless_dev *req_wdev;
1307 		struct list_head loc_list;
1308 		int responses[IWL_MVM_TOF_MAX_APS];
1309 		struct {
1310 			struct list_head resp;
1311 		} smooth;
1312 		struct list_head pasn_list;
1313 	} ftm_initiator;
1314 
1315 	struct list_head resp_pasn_list;
1316 
1317 	struct ptp_data ptp_data;
1318 
1319 	struct {
1320 		u8 range_resp;
1321 	} cmd_ver;
1322 
1323 	struct ieee80211_vif *nan_vif;
1324 	struct iwl_mvm_baid_data __rcu *baid_map[IWL_MAX_BAID];
1325 
1326 	/*
1327 	 * Drop beacons from other APs in AP mode when there are no connected
1328 	 * clients.
1329 	 */
1330 	bool drop_bcn_ap_mode;
1331 
1332 	struct delayed_work cs_tx_unblock_dwork;
1333 
1334 	/* does a monitor vif exist (only one can exist hence bool) */
1335 	bool monitor_on;
1336 	/*
1337 	 * primary channel position relative to he whole bandwidth,
1338 	 * in steps of 80 MHz
1339 	 */
1340 	u8 monitor_p80;
1341 
1342 	/* sniffer data to include in radiotap */
1343 	__le16 cur_aid;
1344 	u8 cur_bssid[ETH_ALEN];
1345 
1346 #ifdef CONFIG_ACPI
1347 	struct iwl_phy_specific_cfg phy_filters;
1348 #endif
1349 
1350 	/* report rx timestamp in ptp clock time */
1351 	bool rx_ts_ptp;
1352 
1353 	unsigned long last_6ghz_passive_scan_jiffies;
1354 	unsigned long last_reset_or_resume_time_jiffies;
1355 
1356 	bool sta_remove_requires_queue_remove;
1357 	bool mld_api_is_used;
1358 
1359 	/*
1360 	 * Indicates that firmware will do a product reset (and then
1361 	 * therefore fail to load) when we start it (due to OTP burn),
1362 	 * if so don't dump errors etc. since this is expected.
1363 	 */
1364 	bool fw_product_reset;
1365 
1366 	struct iwl_time_sync_data time_sync;
1367 
1368 	struct iwl_mei_scan_filter mei_scan_filter;
1369 
1370 	struct iwl_mvm_acs_survey *acs_survey;
1371 
1372 	bool statistics_clear;
1373 	u32 bios_enable_puncturing;
1374 };
1375 
1376 /* Extract MVM priv from op_mode and _hw */
1377 #define IWL_OP_MODE_GET_MVM(_iwl_op_mode)		\
1378 	((struct iwl_mvm *)(_iwl_op_mode)->op_mode_specific)
1379 
1380 #define IWL_MAC80211_GET_MVM(_hw)			\
1381 	IWL_OP_MODE_GET_MVM((struct iwl_op_mode *)((_hw)->priv))
1382 
1383 DEFINE_GUARD(mvm, struct iwl_mvm *, mutex_lock(&_T->mutex), mutex_unlock(&_T->mutex))
1384 
1385 /**
1386  * enum iwl_mvm_status - MVM status bits
1387  * @IWL_MVM_STATUS_HW_RFKILL: HW RF-kill is asserted
1388  * @IWL_MVM_STATUS_HW_CTKILL: CT-kill is active
1389  * @IWL_MVM_STATUS_ROC_P2P_RUNNING: remain-on-channel on P2P is running (when
1390  *	P2P is not over AUX)
1391  * @IWL_MVM_STATUS_HW_RESTART_REQUESTED: HW restart was requested
1392  * @IWL_MVM_STATUS_IN_HW_RESTART: HW restart is active
1393  * @IWL_MVM_STATUS_ROC_AUX_RUNNING: AUX remain-on-channel is running
1394  * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running
1395  * @IWL_MVM_STATUS_IN_D3: in D3 (or at least about to go into it)
1396  * @IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE: suppress one error log
1397  *	if this is set, when intentionally triggered
1398  * @IWL_MVM_STATUS_STARTING: starting mac,
1399  *	used to disable restart flow while in STARTING state
1400  */
1401 enum iwl_mvm_status {
1402 	IWL_MVM_STATUS_HW_RFKILL,
1403 	IWL_MVM_STATUS_HW_CTKILL,
1404 	IWL_MVM_STATUS_ROC_P2P_RUNNING,
1405 	IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1406 	IWL_MVM_STATUS_IN_HW_RESTART,
1407 	IWL_MVM_STATUS_ROC_AUX_RUNNING,
1408 	IWL_MVM_STATUS_FIRMWARE_RUNNING,
1409 	IWL_MVM_STATUS_IN_D3,
1410 	IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,
1411 	IWL_MVM_STATUS_STARTING,
1412 };
1413 
1414 struct iwl_mvm_csme_conn_info {
1415 	struct rcu_head rcu_head;
1416 	struct iwl_mei_conn_info conn_info;
1417 };
1418 
1419 /* Keep track of completed init configuration */
1420 enum iwl_mvm_init_status {
1421 	IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE = BIT(0),
1422 	IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE = BIT(1),
1423 };
1424 
1425 static inline bool iwl_mvm_is_radio_killed(struct iwl_mvm *mvm)
1426 {
1427 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status) ||
1428 	       test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1429 }
1430 
1431 static inline bool iwl_mvm_is_radio_hw_killed(struct iwl_mvm *mvm)
1432 {
1433 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1434 }
1435 
1436 static inline bool iwl_mvm_firmware_running(struct iwl_mvm *mvm)
1437 {
1438 	return test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1439 }
1440 
1441 /* Must be called with rcu_read_lock() held and it can only be
1442  * released when mvmsta is not needed anymore.
1443  */
1444 static inline struct iwl_mvm_sta *
1445 iwl_mvm_sta_from_staid_rcu(struct iwl_mvm *mvm, u8 sta_id)
1446 {
1447 	struct ieee80211_sta *sta;
1448 
1449 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1450 		return NULL;
1451 
1452 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1453 
1454 	/* This can happen if the station has been removed right now */
1455 	if (IS_ERR_OR_NULL(sta))
1456 		return NULL;
1457 
1458 	return iwl_mvm_sta_from_mac80211(sta);
1459 }
1460 
1461 static inline struct iwl_mvm_sta *
1462 iwl_mvm_sta_from_staid_protected(struct iwl_mvm *mvm, u8 sta_id)
1463 {
1464 	struct ieee80211_sta *sta;
1465 
1466 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1467 		return NULL;
1468 
1469 	sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1470 					lockdep_is_held(&mvm->mutex));
1471 
1472 	/* This can happen if the station has been removed right now */
1473 	if (IS_ERR_OR_NULL(sta))
1474 		return NULL;
1475 
1476 	return iwl_mvm_sta_from_mac80211(sta);
1477 }
1478 
1479 static inline struct ieee80211_vif *
1480 iwl_mvm_rcu_dereference_vif_id(struct iwl_mvm *mvm, u8 vif_id, bool rcu)
1481 {
1482 	if (WARN_ON(vif_id >= ARRAY_SIZE(mvm->vif_id_to_mac)))
1483 		return NULL;
1484 
1485 	if (rcu)
1486 		return rcu_dereference(mvm->vif_id_to_mac[vif_id]);
1487 
1488 	return rcu_dereference_protected(mvm->vif_id_to_mac[vif_id],
1489 					 lockdep_is_held(&mvm->mutex));
1490 }
1491 
1492 static inline struct ieee80211_bss_conf *
1493 iwl_mvm_rcu_fw_link_id_to_link_conf(struct iwl_mvm *mvm, u8 link_id, bool rcu)
1494 {
1495 	if (IWL_FW_CHECK(mvm, link_id >= ARRAY_SIZE(mvm->link_id_to_link_conf),
1496 			 "erroneous FW link ID: %d\n", link_id))
1497 		return NULL;
1498 
1499 	if (rcu)
1500 		return rcu_dereference(mvm->link_id_to_link_conf[link_id]);
1501 
1502 	return rcu_dereference_protected(mvm->link_id_to_link_conf[link_id],
1503 					 lockdep_is_held(&mvm->mutex));
1504 }
1505 
1506 static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
1507 {
1508 	return fw_has_api(&mvm->fw->ucode_capa,
1509 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL);
1510 }
1511 
1512 static inline bool iwl_mvm_is_adaptive_dwell_v2_supported(struct iwl_mvm *mvm)
1513 {
1514 	return fw_has_api(&mvm->fw->ucode_capa,
1515 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL_V2);
1516 }
1517 
1518 static inline bool iwl_mvm_is_adwell_hb_ap_num_supported(struct iwl_mvm *mvm)
1519 {
1520 	return fw_has_api(&mvm->fw->ucode_capa,
1521 			  IWL_UCODE_TLV_API_ADWELL_HB_DEF_N_AP);
1522 }
1523 
1524 static inline bool iwl_mvm_is_oce_supported(struct iwl_mvm *mvm)
1525 {
1526 	/* OCE should never be enabled for LMAC scan FWs */
1527 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_OCE);
1528 }
1529 
1530 static inline bool iwl_mvm_is_frag_ebs_supported(struct iwl_mvm *mvm)
1531 {
1532 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAG_EBS);
1533 }
1534 
1535 static inline bool iwl_mvm_is_short_beacon_notif_supported(struct iwl_mvm *mvm)
1536 {
1537 	return fw_has_api(&mvm->fw->ucode_capa,
1538 			  IWL_UCODE_TLV_API_SHORT_BEACON_NOTIF);
1539 }
1540 
1541 static inline bool iwl_mvm_is_dqa_data_queue(struct iwl_mvm *mvm, u8 queue)
1542 {
1543 	return (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE) &&
1544 	       (queue <= IWL_MVM_DQA_MAX_DATA_QUEUE);
1545 }
1546 
1547 static inline bool iwl_mvm_is_dqa_mgmt_queue(struct iwl_mvm *mvm, u8 queue)
1548 {
1549 	return (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) &&
1550 	       (queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE);
1551 }
1552 
1553 static inline bool iwl_mvm_is_lar_supported(struct iwl_mvm *mvm)
1554 {
1555 	bool nvm_lar = mvm->nvm_data->lar_enabled;
1556 	bool tlv_lar = fw_has_capa(&mvm->fw->ucode_capa,
1557 				   IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
1558 
1559 	/*
1560 	 * Enable LAR only if it is supported by the FW (TLV) &&
1561 	 * enabled in the NVM
1562 	 */
1563 	if (mvm->cfg->nvm_type == IWL_NVM_EXT)
1564 		return nvm_lar && tlv_lar;
1565 	else
1566 		return tlv_lar;
1567 }
1568 
1569 static inline bool iwl_mvm_is_wifi_mcc_supported(struct iwl_mvm *mvm)
1570 {
1571 	return fw_has_api(&mvm->fw->ucode_capa,
1572 			  IWL_UCODE_TLV_API_WIFI_MCC_UPDATE) ||
1573 	       fw_has_capa(&mvm->fw->ucode_capa,
1574 			   IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC);
1575 }
1576 
1577 static inline bool iwl_mvm_bt_is_rrc_supported(struct iwl_mvm *mvm)
1578 {
1579 	return fw_has_capa(&mvm->fw->ucode_capa,
1580 			   IWL_UCODE_TLV_CAPA_BT_COEX_RRC) &&
1581 		IWL_MVM_BT_COEX_RRC;
1582 }
1583 
1584 static inline bool iwl_mvm_is_csum_supported(struct iwl_mvm *mvm)
1585 {
1586 	return fw_has_capa(&mvm->fw->ucode_capa,
1587 			   IWL_UCODE_TLV_CAPA_CSUM_SUPPORT) &&
1588 		!IWL_MVM_HW_CSUM_DISABLE;
1589 }
1590 
1591 static inline bool iwl_mvm_is_mplut_supported(struct iwl_mvm *mvm)
1592 {
1593 	return fw_has_capa(&mvm->fw->ucode_capa,
1594 			   IWL_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT) &&
1595 		IWL_MVM_BT_COEX_MPLUT;
1596 }
1597 
1598 static inline
1599 bool iwl_mvm_is_p2p_scm_uapsd_supported(struct iwl_mvm *mvm)
1600 {
1601 	return fw_has_capa(&mvm->fw->ucode_capa,
1602 			   IWL_UCODE_TLV_CAPA_P2P_SCM_UAPSD) &&
1603 		!(iwlwifi_mod_params.uapsd_disable &
1604 		  IWL_DISABLE_UAPSD_P2P_CLIENT);
1605 }
1606 
1607 static inline bool iwl_mvm_has_new_rx_api(struct iwl_mvm *mvm)
1608 {
1609 	return fw_has_capa(&mvm->fw->ucode_capa,
1610 			   IWL_UCODE_TLV_CAPA_MULTI_QUEUE_RX_SUPPORT);
1611 }
1612 
1613 static inline bool iwl_mvm_has_mld_api(const struct iwl_fw *fw)
1614 {
1615 	return fw_has_capa(&fw->ucode_capa,
1616 			   IWL_UCODE_TLV_CAPA_MLD_API_SUPPORT);
1617 }
1618 
1619 static inline bool iwl_mvm_has_new_station_api(const struct iwl_fw *fw)
1620 {
1621 	return iwl_mvm_has_mld_api(fw) ||
1622 	       iwl_fw_lookup_cmd_ver(fw, ADD_STA, 0) >= 12;
1623 }
1624 
1625 static inline bool iwl_mvm_has_new_tx_api(struct iwl_mvm *mvm)
1626 {
1627 	/* TODO - replace with TLV once defined */
1628 	return mvm->trans->trans_cfg->gen2;
1629 }
1630 
1631 static inline bool iwl_mvm_has_unified_ucode(struct iwl_mvm *mvm)
1632 {
1633 	/* TODO - better define this */
1634 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1635 }
1636 
1637 static inline bool iwl_mvm_is_cdb_supported(struct iwl_mvm *mvm)
1638 {
1639 	/*
1640 	 * TODO:
1641 	 * The issue of how to determine CDB APIs and usage is still not fully
1642 	 * defined.
1643 	 * There is a compilation for CDB and non-CDB FW, but there may
1644 	 * be also runtime check.
1645 	 * For now there is a TLV for checking compilation mode, but a
1646 	 * runtime check will also have to be here - once defined.
1647 	 */
1648 	return fw_has_capa(&mvm->fw->ucode_capa,
1649 			   IWL_UCODE_TLV_CAPA_CDB_SUPPORT);
1650 }
1651 
1652 static inline bool iwl_mvm_cdb_scan_api(struct iwl_mvm *mvm)
1653 {
1654 	/*
1655 	 * TODO: should this be the same as iwl_mvm_is_cdb_supported()?
1656 	 * but then there's a little bit of code in scan that won't make
1657 	 * any sense...
1658 	 */
1659 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1660 }
1661 
1662 static inline bool iwl_mvm_is_scan_ext_chan_supported(struct iwl_mvm *mvm)
1663 {
1664 	return fw_has_api(&mvm->fw->ucode_capa,
1665 			  IWL_UCODE_TLV_API_SCAN_EXT_CHAN_VER);
1666 }
1667 
1668 
1669 static inline bool iwl_mvm_is_reduced_config_scan_supported(struct iwl_mvm *mvm)
1670 {
1671 	return fw_has_api(&mvm->fw->ucode_capa,
1672 			  IWL_UCODE_TLV_API_REDUCED_SCAN_CONFIG);
1673 }
1674 
1675 static inline bool iwl_mvm_is_band_in_rx_supported(struct iwl_mvm *mvm)
1676 {
1677 	return fw_has_api(&mvm->fw->ucode_capa,
1678 			   IWL_UCODE_TLV_API_BAND_IN_RX_DATA);
1679 }
1680 
1681 static inline bool iwl_mvm_has_new_rx_stats_api(struct iwl_mvm *mvm)
1682 {
1683 	return fw_has_api(&mvm->fw->ucode_capa,
1684 			  IWL_UCODE_TLV_API_NEW_RX_STATS);
1685 }
1686 
1687 static inline bool iwl_mvm_has_quota_low_latency(struct iwl_mvm *mvm)
1688 {
1689 	return fw_has_api(&mvm->fw->ucode_capa,
1690 			  IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY);
1691 }
1692 
1693 static inline bool iwl_mvm_has_no_host_disable_tx(struct iwl_mvm *mvm)
1694 {
1695 	return fw_has_api(&mvm->fw->ucode_capa,
1696 			  IWL_UCODE_TLV_API_NO_HOST_DISABLE_TX);
1697 }
1698 
1699 static inline bool iwl_mvm_has_tlc_offload(const struct iwl_mvm *mvm)
1700 {
1701 	return fw_has_capa(&mvm->fw->ucode_capa,
1702 			   IWL_UCODE_TLV_CAPA_TLC_OFFLOAD);
1703 }
1704 
1705 static inline struct agg_tx_status *
1706 iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp)
1707 {
1708 	if (iwl_mvm_has_new_tx_api(mvm))
1709 		return &((struct iwl_tx_resp *)tx_resp)->status;
1710 	else
1711 		return ((struct iwl_tx_resp_v3 *)tx_resp)->status;
1712 }
1713 
1714 static inline bool iwl_mvm_is_tt_in_fw(struct iwl_mvm *mvm)
1715 {
1716 	/* these two TLV are redundant since the responsibility to CT-kill by
1717 	 * FW happens only after we send at least one command of
1718 	 * temperature THs report.
1719 	 */
1720 	return fw_has_capa(&mvm->fw->ucode_capa,
1721 			   IWL_UCODE_TLV_CAPA_CT_KILL_BY_FW) &&
1722 	       fw_has_capa(&mvm->fw->ucode_capa,
1723 			   IWL_UCODE_TLV_CAPA_TEMP_THS_REPORT_SUPPORT);
1724 }
1725 
1726 static inline bool iwl_mvm_is_ctdp_supported(struct iwl_mvm *mvm)
1727 {
1728 	return fw_has_capa(&mvm->fw->ucode_capa,
1729 			   IWL_UCODE_TLV_CAPA_CTDP_SUPPORT);
1730 }
1731 
1732 static inline bool iwl_mvm_is_esr_supported(struct iwl_trans *trans)
1733 {
1734 	if ((CSR_HW_RFID_TYPE(trans->hw_rf_id) == IWL_CFG_RF_TYPE_FM) &&
1735 	    !CSR_HW_RFID_IS_CDB(trans->hw_rf_id))
1736 		/* Step A doesn't support eSR */
1737 		return CSR_HW_RFID_STEP(trans->hw_rf_id);
1738 
1739 	return false;
1740 }
1741 
1742 static inline int iwl_mvm_max_active_links(struct iwl_mvm *mvm,
1743 					   struct ieee80211_vif *vif)
1744 {
1745 	struct iwl_trans *trans = mvm->fwrt.trans;
1746 
1747 	if (vif->type == NL80211_IFTYPE_AP)
1748 		return mvm->fw->ucode_capa.num_beacons;
1749 
1750 	/* Check if HW supports eSR or STR */
1751 	if (iwl_mvm_is_esr_supported(trans) ||
1752 	    (CSR_HW_RFID_TYPE(trans->hw_rf_id) == IWL_CFG_RF_TYPE_FM &&
1753 	     CSR_HW_RFID_IS_CDB(trans->hw_rf_id)))
1754 		return IWL_FW_MAX_ACTIVE_LINKS_NUM;
1755 
1756 	return 1;
1757 }
1758 
1759 extern const u8 iwl_mvm_ac_to_tx_fifo[];
1760 extern const u8 iwl_mvm_ac_to_gen2_tx_fifo[];
1761 extern const u8 iwl_mvm_ac_to_bz_tx_fifo[];
1762 
1763 static inline u8 iwl_mvm_mac_ac_to_tx_fifo(struct iwl_mvm *mvm,
1764 					   enum ieee80211_ac_numbers ac)
1765 {
1766 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
1767 		return iwl_mvm_ac_to_bz_tx_fifo[ac];
1768 	if (iwl_mvm_has_new_tx_api(mvm))
1769 		return iwl_mvm_ac_to_gen2_tx_fifo[ac];
1770 	return iwl_mvm_ac_to_tx_fifo[ac];
1771 }
1772 
1773 static inline bool iwl_mvm_has_rlc_offload(struct iwl_mvm *mvm)
1774 {
1775 	return iwl_fw_lookup_cmd_ver(mvm->fw,
1776 				     WIDE_ID(DATA_PATH_GROUP, RLC_CONFIG_CMD),
1777 				     0) >= 3;
1778 }
1779 
1780 struct iwl_rate_info {
1781 	u8 plcp;	/* uCode API:  IWL_RATE_6M_PLCP, etc. */
1782 	u8 plcp_siso;	/* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
1783 	u8 plcp_mimo2;	/* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
1784 	u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
1785 	u8 ieee;	/* MAC header:  IWL_RATE_6M_IEEE, etc. */
1786 };
1787 
1788 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm, bool suspend);
1789 int __iwl_mvm_mac_start(struct iwl_mvm *mvm);
1790 
1791 /******************
1792  * MVM Methods
1793  ******************/
1794 /* uCode */
1795 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm);
1796 
1797 /* Utils */
1798 int iwl_mvm_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
1799 					  enum nl80211_band band);
1800 int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
1801 					enum nl80211_band band);
1802 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
1803 			       enum nl80211_band band,
1804 			       struct ieee80211_tx_rate *r);
1805 void iwl_mvm_hwrate_to_tx_rate_v1(u32 rate_n_flags,
1806 				  enum nl80211_band band,
1807 				  struct ieee80211_tx_rate *r);
1808 u8 iwl_mvm_mac80211_idx_to_hwrate(const struct iwl_fw *fw, int rate_idx);
1809 u8 iwl_mvm_mac80211_ac_to_ucode_ac(enum ieee80211_ac_numbers ac);
1810 bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1811 
1812 static inline void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
1813 {
1814 	iwl_fwrt_dump_error_logs(&mvm->fwrt);
1815 }
1816 
1817 u8 first_antenna(u8 mask);
1818 u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx);
1819 void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, int clock_type, u32 *gp2,
1820 			   u64 *boottime, ktime_t *realtime);
1821 u32 iwl_mvm_get_systime(struct iwl_mvm *mvm);
1822 u32 iwl_mvm_find_ie_offset(u8 *beacon, u8 eid, u32 frame_size);
1823 
1824 /* Tx / Host Commands */
1825 int __must_check iwl_mvm_send_cmd(struct iwl_mvm *mvm,
1826 				  struct iwl_host_cmd *cmd);
1827 int __must_check iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
1828 				      u32 flags, u16 len, const void *data);
1829 int __must_check iwl_mvm_send_cmd_status(struct iwl_mvm *mvm,
1830 					 struct iwl_host_cmd *cmd,
1831 					 u32 *status);
1832 int __must_check iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id,
1833 					     u16 len, const void *data,
1834 					     u32 *status);
1835 int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
1836 		       struct ieee80211_sta *sta);
1837 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb);
1838 void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
1839 			struct iwl_tx_cmd *tx_cmd,
1840 			struct ieee80211_tx_info *info, u8 sta_id);
1841 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
1842 			    struct ieee80211_tx_info *info,
1843 			    struct ieee80211_sta *sta, __le16 fc);
1844 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
1845 unsigned int iwl_mvm_max_amsdu_size(struct iwl_mvm *mvm,
1846 				    struct ieee80211_sta *sta,
1847 				    unsigned int tid);
1848 
1849 #ifdef CONFIG_IWLWIFI_DEBUG
1850 const char *iwl_mvm_get_tx_fail_reason(u32 status);
1851 #else
1852 static inline const char *iwl_mvm_get_tx_fail_reason(u32 status) { return ""; }
1853 #endif
1854 int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk);
1855 int iwl_mvm_flush_sta(struct iwl_mvm *mvm, u32 sta_id, u32 tfd_queue_mask);
1856 int iwl_mvm_flush_sta_tids(struct iwl_mvm *mvm, u32 sta_id, u16 tids);
1857 
1858 /* Utils to extract sta related data */
1859 __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta,
1860 				 struct ieee80211_link_sta *link_sta);
1861 u8 iwl_mvm_get_sta_uapsd_acs(struct ieee80211_sta *sta);
1862 u32 iwl_mvm_get_sta_ampdu_dens(struct ieee80211_link_sta *link_sta,
1863 			       struct ieee80211_bss_conf *link_conf,
1864 			       u32 *_agg_size);
1865 int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm,
1866 			    struct ieee80211_link_sta *link_sta,
1867 			    struct iwl_he_pkt_ext_v2 *pkt_ext);
1868 
1869 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm);
1870 
1871 static inline void iwl_mvm_set_tx_cmd_ccmp(struct ieee80211_tx_info *info,
1872 					   struct iwl_tx_cmd *tx_cmd)
1873 {
1874 	struct ieee80211_key_conf *keyconf = info->control.hw_key;
1875 
1876 	tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
1877 	memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
1878 }
1879 
1880 static inline void iwl_mvm_wait_for_async_handlers(struct iwl_mvm *mvm)
1881 {
1882 	flush_work(&mvm->async_handlers_wk);
1883 }
1884 
1885 /* Statistics */
1886 void iwl_mvm_handle_rx_system_oper_stats(struct iwl_mvm *mvm,
1887 					 struct iwl_rx_cmd_buffer *rxb);
1888 void iwl_mvm_handle_rx_system_oper_part1_stats(struct iwl_mvm *mvm,
1889 					       struct iwl_rx_cmd_buffer *rxb);
1890 static inline void
1891 iwl_mvm_handle_rx_system_end_stats_notif(struct iwl_mvm *mvm,
1892 					 struct iwl_rx_cmd_buffer *rxb)
1893 {
1894 }
1895 
1896 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1897 				  struct iwl_rx_packet *pkt);
1898 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
1899 			   struct iwl_rx_cmd_buffer *rxb);
1900 int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear);
1901 int iwl_mvm_request_periodic_system_statistics(struct iwl_mvm *mvm,
1902 					       bool enable);
1903 void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm);
1904 
1905 /* NVM */
1906 int iwl_nvm_init(struct iwl_mvm *mvm);
1907 int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm);
1908 
1909 static inline u8 iwl_mvm_get_valid_tx_ant(struct iwl_mvm *mvm)
1910 {
1911 	u8 tx_ant = mvm->fw->valid_tx_ant;
1912 
1913 	if (mvm->nvm_data && mvm->nvm_data->valid_tx_ant)
1914 		tx_ant &= mvm->nvm_data->valid_tx_ant;
1915 
1916 	if (mvm->set_tx_ant)
1917 		tx_ant &= mvm->set_tx_ant;
1918 
1919 	return tx_ant;
1920 }
1921 
1922 static inline u8 iwl_mvm_get_valid_rx_ant(struct iwl_mvm *mvm)
1923 {
1924 	u8 rx_ant = mvm->fw->valid_rx_ant;
1925 
1926 	if (mvm->nvm_data && mvm->nvm_data->valid_rx_ant)
1927 		rx_ant &= mvm->nvm_data->valid_rx_ant;
1928 
1929 	if (mvm->set_rx_ant)
1930 		rx_ant &= mvm->set_rx_ant;
1931 
1932 	return rx_ant;
1933 
1934 }
1935 
1936 static inline void iwl_mvm_toggle_tx_ant(struct iwl_mvm *mvm, u8 *ant)
1937 {
1938 	*ant = iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), *ant);
1939 }
1940 
1941 static inline u32 iwl_mvm_get_phy_config(struct iwl_mvm *mvm)
1942 {
1943 	u32 phy_config = ~(FW_PHY_CFG_TX_CHAIN |
1944 			   FW_PHY_CFG_RX_CHAIN);
1945 	u32 valid_rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
1946 	u32 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
1947 
1948 	phy_config |= valid_tx_ant << FW_PHY_CFG_TX_CHAIN_POS |
1949 		      valid_rx_ant << FW_PHY_CFG_RX_CHAIN_POS;
1950 
1951 	return mvm->fw->phy_config & phy_config;
1952 }
1953 
1954 int iwl_mvm_up(struct iwl_mvm *mvm);
1955 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm);
1956 
1957 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm);
1958 
1959 void iwl_mvm_mac_init_mvmvif(struct iwl_mvm *mvm, struct iwl_mvm_vif *mvmvif);
1960 
1961 /*
1962  * FW notifications / CMD responses handlers
1963  * Convention: iwl_mvm_rx_<NAME OF THE CMD>
1964  */
1965 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1966 		   struct napi_struct *napi,
1967 		   struct iwl_rx_cmd_buffer *rxb);
1968 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1969 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1970 			struct iwl_rx_cmd_buffer *rxb);
1971 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1972 			struct iwl_rx_cmd_buffer *rxb, int queue);
1973 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1974 				struct iwl_rx_cmd_buffer *rxb, int queue);
1975 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1976 			      struct iwl_rx_cmd_buffer *rxb, int queue);
1977 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1978 				  struct iwl_rx_cmd_buffer *rxb, int queue);
1979 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
1980 			    struct iwl_rx_cmd_buffer *rxb, int queue);
1981 void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1982 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
1983 				   struct iwl_rx_cmd_buffer *rxb);
1984 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags);
1985 void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1986 void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1987 				   struct iwl_rx_cmd_buffer *rxb);
1988 void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1989 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1990 			     struct iwl_rx_cmd_buffer *rxb);
1991 void iwl_mvm_rx_shared_mem_cfg_notif(struct iwl_mvm *mvm,
1992 				     struct iwl_rx_cmd_buffer *rxb);
1993 
1994 /* MVM PHY */
1995 struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm);
1996 int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1997 			 const struct cfg80211_chan_def *chandef,
1998 			 const struct cfg80211_chan_def *ap,
1999 			 u8 chains_static, u8 chains_dynamic);
2000 int iwl_mvm_phy_ctxt_changed(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
2001 			     const struct cfg80211_chan_def *chandef,
2002 			     const struct cfg80211_chan_def *ap,
2003 			     u8 chains_static, u8 chains_dynamic);
2004 void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm,
2005 			  struct iwl_mvm_phy_ctxt *ctxt);
2006 void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm,
2007 			    struct iwl_mvm_phy_ctxt *ctxt);
2008 int iwl_mvm_phy_ctx_count(struct iwl_mvm *mvm);
2009 u8 iwl_mvm_get_channel_width(const struct cfg80211_chan_def *chandef);
2010 u8 iwl_mvm_get_ctrl_pos(const struct cfg80211_chan_def *chandef);
2011 int iwl_mvm_phy_send_rlc(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
2012 			 u8 chains_static, u8 chains_dynamic);
2013 
2014 /* MAC (virtual interface) programming */
2015 
2016 void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
2017 				 struct ieee80211_vif *vif);
2018 void iwl_mvm_set_fw_basic_rates(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2019 				struct iwl_mvm_vif_link_info *link_info,
2020 				__le32 *cck_rates, __le32 *ofdm_rates);
2021 void iwl_mvm_set_fw_protection_flags(struct iwl_mvm *mvm,
2022 				     struct ieee80211_vif *vif,
2023 				     struct ieee80211_bss_conf *link_conf,
2024 				     __le32 *protection_flags, u32 ht_flag,
2025 				     u32 tgg_flag);
2026 void iwl_mvm_set_fw_qos_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2027 			       struct ieee80211_bss_conf *link_conf,
2028 			       struct iwl_ac_qos *ac, __le32 *qos_flags);
2029 bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm,
2030 				   const struct iwl_mvm_vif_link_info *link_info,
2031 				   struct iwl_he_backoff_conf *trig_based_txf);
2032 void iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2033 			      struct ieee80211_bss_conf *link_conf,
2034 			      __le64 *dtim_tsf, __le32 *dtim_time,
2035 			      __le32 *assoc_beacon_arrive_time);
2036 __le32 iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm *mvm,
2037 					      struct ieee80211_vif *vif);
2038 void iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm *mvm,
2039 					      struct iwl_mvm_vif *mvmvif,
2040 					      __le32 *filter_flags,
2041 					      int accept_probe_req_flag,
2042 					      int accept_beacon_flag);
2043 int iwl_mvm_get_mac_type(struct ieee80211_vif *vif);
2044 __le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm,
2045 						    struct ieee80211_vif *vif);
2046 u32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm,
2047 					    struct ieee80211_vif *vif);
2048 int iwl_mvm_mld_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2049 int iwl_mvm_mld_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2050 				 bool force_assoc_off);
2051 int iwl_mvm_mld_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2052 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2053 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2054 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2055 			     bool force_assoc_off, const u8 *bssid_override);
2056 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2057 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
2058 				    struct ieee80211_vif *vif,
2059 				    struct ieee80211_bss_conf *link_conf);
2060 int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
2061 				     struct sk_buff *beacon,
2062 				     void *data, int len);
2063 u8 iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm *mvm,
2064 				    struct ieee80211_tx_info *info,
2065 				    struct ieee80211_vif *vif);
2066 u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct iwl_mvm *mvm,
2067 				    struct ieee80211_tx_info *info,
2068 				    struct ieee80211_vif *vif);
2069 u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw,
2070 				      u8 rate_idx);
2071 void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
2072 			      __le32 *tim_index, __le32 *tim_size,
2073 			      u8 *beacon, u32 frame_size);
2074 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
2075 			     struct iwl_rx_cmd_buffer *rxb);
2076 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
2077 				     struct iwl_rx_cmd_buffer *rxb);
2078 void iwl_mvm_rx_missed_beacons_notif_legacy(struct iwl_mvm *mvm,
2079 					    struct iwl_rx_cmd_buffer *rxb);
2080 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
2081 				    struct iwl_rx_cmd_buffer *rxb);
2082 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2083 			       struct iwl_rx_cmd_buffer *rxb);
2084 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2085 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
2086 				 struct iwl_rx_cmd_buffer *rxb);
2087 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
2088 				    struct ieee80211_vif *vif);
2089 void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
2090 				   struct iwl_rx_cmd_buffer *rxb);
2091 void iwl_mvm_rx_missed_vap_notif(struct iwl_mvm *mvm,
2092 				 struct iwl_rx_cmd_buffer *rxb);
2093 void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
2094 					struct iwl_rx_cmd_buffer *rxb);
2095 void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
2096 					struct iwl_rx_cmd_buffer *rxb);
2097 /* Bindings */
2098 int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2099 int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2100 u32 iwl_mvm_get_lmac_id(struct iwl_mvm *mvm, enum nl80211_band band);
2101 
2102 /* Links */
2103 int iwl_mvm_set_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2104 			     struct ieee80211_bss_conf *link_conf);
2105 int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2106 		     struct ieee80211_bss_conf *link_conf);
2107 int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2108 			 struct ieee80211_bss_conf *link_conf,
2109 			 u32 changes, bool active);
2110 int iwl_mvm_unset_link_mapping(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2111 			       struct ieee80211_bss_conf *link_conf);
2112 int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2113 			struct ieee80211_bss_conf *link_conf);
2114 int iwl_mvm_disable_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2115 			 struct ieee80211_bss_conf *link_conf);
2116 
2117 void iwl_mvm_select_links(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2118 u8 iwl_mvm_get_primary_link(struct ieee80211_vif *vif);
2119 u8 iwl_mvm_get_other_link(struct ieee80211_vif *vif, u8 link_id);
2120 
2121 struct iwl_mvm_link_sel_data {
2122 	u8 link_id;
2123 	const struct cfg80211_chan_def *chandef;
2124 	s32 signal;
2125 	u16 grade;
2126 };
2127 
2128 #if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
2129 unsigned int iwl_mvm_get_link_grade(struct ieee80211_bss_conf *link_conf);
2130 bool iwl_mvm_mld_valid_link_pair(struct ieee80211_vif *vif,
2131 				 const struct iwl_mvm_link_sel_data *a,
2132 				 const struct iwl_mvm_link_sel_data *b);
2133 
2134 s8 iwl_mvm_average_dbm_values(const struct iwl_umac_scan_channel_survey_notif *notif);
2135 #endif
2136 
2137 /* AP and IBSS */
2138 bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw,
2139 				  struct ieee80211_vif *vif, int *ret);
2140 void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm,
2141 				 struct ieee80211_vif *vif);
2142 
2143 /* BSS Info */
2144 void iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm,
2145 					     struct ieee80211_vif *vif,
2146 					     struct ieee80211_bss_conf *link_conf,
2147 					     u64 changes);
2148 void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm,
2149 					    struct ieee80211_vif *vif,
2150 					    u64 changes);
2151 
2152 /* ROC */
2153 /**
2154  * struct iwl_mvm_roc_ops - callbacks for the remain_on_channel()
2155  *
2156  * Since the only difference between both MLD and
2157  * non-MLD versions of remain_on_channel() is these function calls,
2158  * each version will send its specific function calls to
2159  * %iwl_mvm_roc_common().
2160  *
2161  * @add_aux_sta_for_hs20: pointer to the function that adds an aux sta
2162  *	for Hot Spot 2.0
2163  * @link: For a P2P Device interface, pointer to a function that links the
2164  *      MAC/Link to the PHY context
2165  */
2166 struct iwl_mvm_roc_ops {
2167 	int (*add_aux_sta_for_hs20)(struct iwl_mvm *mvm, u32 lmac_id);
2168 	int (*link)(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2169 };
2170 
2171 int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2172 		       struct ieee80211_channel *channel, int duration,
2173 		       enum ieee80211_roc_type type,
2174 		       const struct iwl_mvm_roc_ops *ops);
2175 int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
2176 		       struct ieee80211_vif *vif);
2177 /*Session Protection */
2178 void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2179 			   u32 duration_override, unsigned int link_id);
2180 
2181 /* Quota management */
2182 static inline size_t iwl_mvm_quota_cmd_size(struct iwl_mvm *mvm)
2183 {
2184 	return iwl_mvm_has_quota_low_latency(mvm) ?
2185 		sizeof(struct iwl_time_quota_cmd) :
2186 		sizeof(struct iwl_time_quota_cmd_v1);
2187 }
2188 
2189 static inline struct iwl_time_quota_data
2190 *iwl_mvm_quota_cmd_get_quota(struct iwl_mvm *mvm,
2191 			     struct iwl_time_quota_cmd *cmd,
2192 			     int i)
2193 {
2194 	struct iwl_time_quota_data_v1 *quotas;
2195 
2196 	if (iwl_mvm_has_quota_low_latency(mvm))
2197 		return &cmd->quotas[i];
2198 
2199 	quotas = (struct iwl_time_quota_data_v1 *)cmd->quotas;
2200 	return (struct iwl_time_quota_data *)&quotas[i];
2201 }
2202 
2203 int iwl_mvm_update_quotas(struct iwl_mvm *mvm, bool force_upload,
2204 			  struct ieee80211_vif *disabled_vif);
2205 
2206 /* Scanning */
2207 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2208 			   struct cfg80211_scan_request *req,
2209 			   struct ieee80211_scan_ies *ies);
2210 size_t iwl_mvm_scan_size(struct iwl_mvm *mvm);
2211 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify);
2212 
2213 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm);
2214 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm);
2215 void iwl_mvm_scan_timeout_wk(struct work_struct *work);
2216 int iwl_mvm_int_mlo_scan(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2217 void iwl_mvm_rx_channel_survey_notif(struct iwl_mvm *mvm,
2218 				     struct iwl_rx_cmd_buffer *rxb);
2219 
2220 /* Scheduled scan */
2221 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
2222 					 struct iwl_rx_cmd_buffer *rxb);
2223 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
2224 					      struct iwl_rx_cmd_buffer *rxb);
2225 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
2226 			     struct ieee80211_vif *vif,
2227 			     struct cfg80211_sched_scan_request *req,
2228 			     struct ieee80211_scan_ies *ies,
2229 			     int type);
2230 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
2231 				 struct iwl_rx_cmd_buffer *rxb);
2232 
2233 /* UMAC scan */
2234 int iwl_mvm_config_scan(struct iwl_mvm *mvm);
2235 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
2236 					 struct iwl_rx_cmd_buffer *rxb);
2237 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
2238 					      struct iwl_rx_cmd_buffer *rxb);
2239 
2240 /* MVM debugfs */
2241 #ifdef CONFIG_IWLWIFI_DEBUGFS
2242 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm);
2243 void iwl_mvm_vif_add_debugfs(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
2244 void iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2245 void iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2246 #else
2247 static inline void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
2248 {
2249 }
2250 static inline void
2251 iwl_mvm_vif_dbgfs_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2252 {
2253 }
2254 static inline void
2255 iwl_mvm_vif_dbgfs_rm_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2256 {
2257 }
2258 #endif /* CONFIG_IWLWIFI_DEBUGFS */
2259 
2260 /* rate scaling */
2261 int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq);
2262 void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg);
2263 int rs_pretty_print_rate_v1(char *buf, int bufsz, const u32 rate);
2264 void rs_update_last_rssi(struct iwl_mvm *mvm,
2265 			 struct iwl_mvm_sta *mvmsta,
2266 			 struct ieee80211_rx_status *rx_status);
2267 
2268 /* power management */
2269 int iwl_mvm_power_update_device(struct iwl_mvm *mvm);
2270 int iwl_mvm_power_update_mac(struct iwl_mvm *mvm);
2271 int iwl_mvm_power_update_ps(struct iwl_mvm *mvm);
2272 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2273 				 char *buf, int bufsz);
2274 
2275 void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2276 void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
2277 					      struct iwl_rx_cmd_buffer *rxb);
2278 
2279 #ifdef CONFIG_IWLWIFI_LEDS
2280 int iwl_mvm_leds_init(struct iwl_mvm *mvm);
2281 void iwl_mvm_leds_exit(struct iwl_mvm *mvm);
2282 void iwl_mvm_leds_sync(struct iwl_mvm *mvm);
2283 #else
2284 static inline int iwl_mvm_leds_init(struct iwl_mvm *mvm)
2285 {
2286 	return 0;
2287 }
2288 static inline void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
2289 {
2290 }
2291 static inline void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
2292 {
2293 }
2294 #endif
2295 
2296 /* D3 (WoWLAN, NetDetect) */
2297 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
2298 int iwl_mvm_resume(struct ieee80211_hw *hw);
2299 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled);
2300 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
2301 			    struct ieee80211_vif *vif,
2302 			    struct cfg80211_gtk_rekey_data *data);
2303 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
2304 			      struct ieee80211_vif *vif,
2305 			      struct inet6_dev *idev);
2306 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
2307 				     struct ieee80211_vif *vif, int idx);
2308 extern const struct file_operations iwl_dbgfs_d3_test_ops;
2309 #ifdef CONFIG_PM
2310 void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm,
2311 				 struct ieee80211_vif *vif);
2312 void iwl_mvm_fast_suspend(struct iwl_mvm *mvm);
2313 int iwl_mvm_fast_resume(struct iwl_mvm *mvm);
2314 #else
2315 static inline void
2316 iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2317 {
2318 }
2319 
2320 static inline void iwl_mvm_fast_suspend(struct iwl_mvm *mvm)
2321 {
2322 }
2323 
2324 static inline int iwl_mvm_fast_resume(struct iwl_mvm *mvm)
2325 {
2326 	return 0;
2327 }
2328 #endif
2329 void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
2330 				struct iwl_wowlan_config_cmd *cmd);
2331 int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
2332 			       struct ieee80211_vif *vif,
2333 			       bool disable_offloading,
2334 			       bool offload_ns,
2335 			       u32 cmd_flags,
2336 			       u8 sta_id);
2337 
2338 /* BT Coex */
2339 int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm);
2340 void iwl_mvm_rx_bt_coex_old_notif(struct iwl_mvm *mvm,
2341 				  struct iwl_rx_cmd_buffer *rxb);
2342 void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
2343 			      struct iwl_rx_cmd_buffer *rxb);
2344 void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2345 			   enum ieee80211_rssi_event_data);
2346 void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm);
2347 u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
2348 				struct ieee80211_sta *sta);
2349 bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
2350 				     struct ieee80211_sta *sta);
2351 bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant);
2352 bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm);
2353 bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
2354 				    enum nl80211_band band);
2355 u8 iwl_mvm_bt_coex_get_single_ant_msk(struct iwl_mvm *mvm, u8 enabled_ants);
2356 u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
2357 			   struct ieee80211_tx_info *info, u8 ac);
2358 
2359 /* beacon filtering */
2360 #ifdef CONFIG_IWLWIFI_DEBUGFS
2361 void
2362 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
2363 					 struct iwl_beacon_filter_cmd *cmd);
2364 #else
2365 static inline void
2366 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
2367 					 struct iwl_beacon_filter_cmd *cmd)
2368 {}
2369 #endif
2370 int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
2371 				 struct ieee80211_vif *vif);
2372 int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
2373 				  struct ieee80211_vif *vif);
2374 /* SMPS */
2375 void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2376 				enum iwl_mvm_smps_type_request req_type,
2377 				enum ieee80211_smps_mode smps_request,
2378 				unsigned int link_id);
2379 void
2380 iwl_mvm_update_smps_on_active_links(struct iwl_mvm *mvm,
2381 				    struct ieee80211_vif *vif,
2382 				    enum iwl_mvm_smps_type_request req_type,
2383 				    enum ieee80211_smps_mode smps_request);
2384 bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm,
2385 				  struct iwl_mvm_phy_ctxt *ctxt);
2386 void iwl_mvm_update_link_smps(struct ieee80211_vif *vif,
2387 			      struct ieee80211_bss_conf *link_conf);
2388 
2389 /* Low latency */
2390 int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2391 			      bool low_latency,
2392 			      enum iwl_mvm_low_latency_cause cause);
2393 /* get SystemLowLatencyMode - only needed for beacon threshold? */
2394 bool iwl_mvm_low_latency(struct iwl_mvm *mvm);
2395 bool iwl_mvm_low_latency_band(struct iwl_mvm *mvm, enum nl80211_band band);
2396 void iwl_mvm_send_low_latency_cmd(struct iwl_mvm *mvm, bool low_latency,
2397 				  u16 mac_id);
2398 
2399 /* get VMACLowLatencyMode */
2400 static inline bool iwl_mvm_vif_low_latency(struct iwl_mvm_vif *mvmvif)
2401 {
2402 	/*
2403 	 * should this consider associated/active/... state?
2404 	 *
2405 	 * Normally low-latency should only be active on interfaces
2406 	 * that are active, but at least with debugfs it can also be
2407 	 * enabled on interfaces that aren't active. However, when
2408 	 * interface aren't active then they aren't added into the
2409 	 * binding, so this has no real impact. For now, just return
2410 	 * the current desired low-latency state.
2411 	 */
2412 	return mvmvif->low_latency_actual;
2413 }
2414 
2415 static inline
2416 void iwl_mvm_vif_set_low_latency(struct iwl_mvm_vif *mvmvif, bool set,
2417 				 enum iwl_mvm_low_latency_cause cause)
2418 {
2419 	u8 new_state;
2420 
2421 	if (set)
2422 		mvmvif->low_latency |= cause;
2423 	else
2424 		mvmvif->low_latency &= ~cause;
2425 
2426 	/*
2427 	 * if LOW_LATENCY_DEBUGFS_FORCE_ENABLE is enabled no changes are
2428 	 * allowed to actual mode.
2429 	 */
2430 	if (mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE_ENABLE &&
2431 	    cause != LOW_LATENCY_DEBUGFS_FORCE_ENABLE)
2432 		return;
2433 
2434 	if (cause == LOW_LATENCY_DEBUGFS_FORCE_ENABLE && set)
2435 		/*
2436 		 * We enter force state
2437 		 */
2438 		new_state = !!(mvmvif->low_latency &
2439 			       LOW_LATENCY_DEBUGFS_FORCE);
2440 	else
2441 		/*
2442 		 * Check if any other one set low latency
2443 		 */
2444 		new_state = !!(mvmvif->low_latency &
2445 				  ~(LOW_LATENCY_DEBUGFS_FORCE_ENABLE |
2446 				    LOW_LATENCY_DEBUGFS_FORCE));
2447 
2448 	mvmvif->low_latency_actual = new_state;
2449 }
2450 
2451 /* Return a bitmask with all the hw supported queues, except for the
2452  * command queue, which can't be flushed.
2453  */
2454 static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
2455 {
2456 	return ((BIT(mvm->trans->trans_cfg->base_params->num_of_queues) - 1) &
2457 		~BIT(IWL_MVM_DQA_CMD_QUEUE));
2458 }
2459 
2460 void iwl_mvm_stop_device(struct iwl_mvm *mvm);
2461 
2462 /* Thermal management and CT-kill */
2463 void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff);
2464 void iwl_mvm_temp_notif(struct iwl_mvm *mvm,
2465 			struct iwl_rx_cmd_buffer *rxb);
2466 void iwl_mvm_tt_handler(struct iwl_mvm *mvm);
2467 void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff);
2468 void iwl_mvm_thermal_exit(struct iwl_mvm *mvm);
2469 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state);
2470 int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp);
2471 void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2472 void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);
2473 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm);
2474 int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget);
2475 
2476 #if IS_ENABLED(CONFIG_IWLMEI)
2477 
2478 /* vendor commands */
2479 void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
2480 
2481 #else
2482 
2483 static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
2484 
2485 #endif
2486 
2487 /* Location Aware Regulatory */
2488 struct iwl_mcc_update_resp_v8 *
2489 iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
2490 		   enum iwl_mcc_source src_id);
2491 int iwl_mvm_init_mcc(struct iwl_mvm *mvm);
2492 void iwl_mvm_rx_chub_update_mcc(struct iwl_mvm *mvm,
2493 				struct iwl_rx_cmd_buffer *rxb);
2494 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
2495 						  const char *alpha2,
2496 						  enum iwl_mcc_source src_id,
2497 						  bool *changed);
2498 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
2499 							  bool *changed);
2500 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm, bool force_regd_sync);
2501 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm);
2502 
2503 /* smart fifo */
2504 int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2505 		      bool added_vif);
2506 
2507 /* FTM responder */
2508 int iwl_mvm_ftm_start_responder(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2509 				struct ieee80211_bss_conf *bss_conf);
2510 void iwl_mvm_ftm_restart_responder(struct iwl_mvm *mvm,
2511 				   struct ieee80211_vif *vif,
2512 				   struct ieee80211_bss_conf *bss_conf);
2513 void iwl_mvm_ftm_responder_stats(struct iwl_mvm *mvm,
2514 				 struct iwl_rx_cmd_buffer *rxb);
2515 int iwl_mvm_ftm_resp_remove_pasn_sta(struct iwl_mvm *mvm,
2516 				     struct ieee80211_vif *vif, u8 *addr);
2517 int iwl_mvm_ftm_respoder_add_pasn_sta(struct iwl_mvm *mvm,
2518 				      struct ieee80211_vif *vif,
2519 				      u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2520 				      u8 *hltk, u32 hltk_len);
2521 void iwl_mvm_ftm_responder_clear(struct iwl_mvm *mvm,
2522 				 struct ieee80211_vif *vif);
2523 
2524 /* FTM initiator */
2525 void iwl_mvm_ftm_restart(struct iwl_mvm *mvm);
2526 void iwl_mvm_ftm_range_resp(struct iwl_mvm *mvm,
2527 			    struct iwl_rx_cmd_buffer *rxb);
2528 void iwl_mvm_ftm_lc_notif(struct iwl_mvm *mvm,
2529 			  struct iwl_rx_cmd_buffer *rxb);
2530 int iwl_mvm_ftm_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2531 		      struct cfg80211_pmsr_request *request);
2532 void iwl_mvm_ftm_abort(struct iwl_mvm *mvm, struct cfg80211_pmsr_request *req);
2533 void iwl_mvm_ftm_initiator_smooth_config(struct iwl_mvm *mvm);
2534 void iwl_mvm_ftm_initiator_smooth_stop(struct iwl_mvm *mvm);
2535 int iwl_mvm_ftm_add_pasn_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2536 			     u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2537 			     u8 *hltk, u32 hltk_len);
2538 void iwl_mvm_ftm_remove_pasn_sta(struct iwl_mvm *mvm, u8 *addr);
2539 
2540 /* TDLS */
2541 
2542 /*
2543  * We use TID 4 (VI) as a FW-used-only TID when TDLS connections are present.
2544  * This TID is marked as used vs the AP and all connected TDLS peers.
2545  */
2546 #define IWL_MVM_TDLS_FW_TID 4
2547 
2548 int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2549 void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm);
2550 void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2551 			       bool sta_added);
2552 void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2553 					   struct ieee80211_vif *vif,
2554 					   unsigned int link_id);
2555 int iwl_mvm_tdls_channel_switch(struct ieee80211_hw *hw,
2556 				struct ieee80211_vif *vif,
2557 				struct ieee80211_sta *sta, u8 oper_class,
2558 				struct cfg80211_chan_def *chandef,
2559 				struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie);
2560 void iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw *hw,
2561 				      struct ieee80211_vif *vif,
2562 				      struct ieee80211_tdls_ch_sw_params *params);
2563 void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw *hw,
2564 					struct ieee80211_vif *vif,
2565 					struct ieee80211_sta *sta);
2566 void iwl_mvm_rx_tdls_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2567 void iwl_mvm_tdls_ch_switch_work(struct work_struct *work);
2568 
2569 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
2570 				     enum iwl_mvm_rxq_notif_type type,
2571 				     bool sync,
2572 				     const void *data, u32 size);
2573 struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
2574 struct ieee80211_vif *iwl_mvm_get_vif_by_macid(struct iwl_mvm *mvm, u32 macid);
2575 bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm);
2576 
2577 #define MVM_TCM_PERIOD_MSEC 500
2578 #define MVM_TCM_PERIOD (HZ * MVM_TCM_PERIOD_MSEC / 1000)
2579 #define MVM_LL_PERIOD (10 * HZ)
2580 void iwl_mvm_tcm_work(struct work_struct *work);
2581 void iwl_mvm_recalc_tcm(struct iwl_mvm *mvm);
2582 void iwl_mvm_pause_tcm(struct iwl_mvm *mvm, bool with_cancel);
2583 void iwl_mvm_resume_tcm(struct iwl_mvm *mvm);
2584 void iwl_mvm_tcm_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2585 void iwl_mvm_tcm_rm_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2586 u8 iwl_mvm_tcm_load_percentage(u32 airtime, u32 elapsed);
2587 
2588 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error);
2589 unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
2590 				    struct ieee80211_vif *vif);
2591 void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2592 			     const char *errmsg);
2593 void iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
2594 					  struct ieee80211_vif *vif,
2595 					  const struct ieee80211_sta *sta,
2596 					  u16 tid);
2597 void iwl_mvm_mei_scan_filter_init(struct iwl_mei_scan_filter *mei_scan_filter);
2598 
2599 void iwl_mvm_ptp_init(struct iwl_mvm *mvm);
2600 void iwl_mvm_ptp_remove(struct iwl_mvm *mvm);
2601 u64 iwl_mvm_ptp_get_adj_time(struct iwl_mvm *mvm, u64 base_time);
2602 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b);
2603 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm);
2604 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm);
2605 void iwl_mvm_get_bios_tables(struct iwl_mvm *mvm);
2606 #ifdef CONFIG_IWLWIFI_DEBUGFS
2607 void iwl_mvm_link_sta_add_debugfs(struct ieee80211_hw *hw,
2608 				  struct ieee80211_vif *vif,
2609 				  struct ieee80211_link_sta *link_sta,
2610 				  struct dentry *dir);
2611 void iwl_mvm_link_add_debugfs(struct ieee80211_hw *hw,
2612 			      struct ieee80211_vif *vif,
2613 			      struct ieee80211_bss_conf *link_conf,
2614 			      struct dentry *dir);
2615 #endif
2616 
2617 /* new MLD related APIs */
2618 int iwl_mvm_sec_key_add(struct iwl_mvm *mvm,
2619 			struct ieee80211_vif *vif,
2620 			struct ieee80211_sta *sta,
2621 			struct ieee80211_key_conf *keyconf);
2622 int iwl_mvm_sec_key_del(struct iwl_mvm *mvm,
2623 			struct ieee80211_vif *vif,
2624 			struct ieee80211_sta *sta,
2625 			struct ieee80211_key_conf *keyconf);
2626 int iwl_mvm_sec_key_del_pasn(struct iwl_mvm *mvm,
2627 			     struct ieee80211_vif *vif,
2628 			     u32 sta_mask,
2629 			     struct ieee80211_key_conf *keyconf);
2630 void iwl_mvm_sec_key_remove_ap(struct iwl_mvm *mvm,
2631 			       struct ieee80211_vif *vif,
2632 			       struct iwl_mvm_vif_link_info *link,
2633 			       unsigned int link_id);
2634 int iwl_mvm_mld_update_sta_keys(struct iwl_mvm *mvm,
2635 				struct ieee80211_vif *vif,
2636 				struct ieee80211_sta *sta,
2637 				u32 old_sta_mask,
2638 				u32 new_sta_mask);
2639 int iwl_mvm_mld_send_key(struct iwl_mvm *mvm, u32 sta_mask, u32 key_flags,
2640 			 struct ieee80211_key_conf *keyconf);
2641 u32 iwl_mvm_get_sec_flags(struct iwl_mvm *mvm,
2642 			  struct ieee80211_vif *vif,
2643 			  struct ieee80211_sta *sta,
2644 			  struct ieee80211_key_conf *keyconf);
2645 
2646 bool iwl_rfi_supported(struct iwl_mvm *mvm);
2647 int iwl_rfi_send_config_cmd(struct iwl_mvm *mvm,
2648 			    struct iwl_rfi_lut_entry *rfi_table);
2649 struct iwl_rfi_freq_table_resp_cmd *iwl_rfi_get_freq_table(struct iwl_mvm *mvm);
2650 void iwl_rfi_deactivate_notif_handler(struct iwl_mvm *mvm,
2651 				      struct iwl_rx_cmd_buffer *rxb);
2652 
2653 static inline u8 iwl_mvm_phy_band_from_nl80211(enum nl80211_band band)
2654 {
2655 	switch (band) {
2656 	case NL80211_BAND_2GHZ:
2657 		return PHY_BAND_24;
2658 	case NL80211_BAND_5GHZ:
2659 		return PHY_BAND_5;
2660 	case NL80211_BAND_6GHZ:
2661 		return PHY_BAND_6;
2662 	default:
2663 		WARN_ONCE(1, "Unsupported band (%u)\n", band);
2664 		return PHY_BAND_5;
2665 	}
2666 }
2667 
2668 static inline u8 iwl_mvm_nl80211_band_from_phy(u8 phy_band)
2669 {
2670 	switch (phy_band) {
2671 	case PHY_BAND_24:
2672 		return NL80211_BAND_2GHZ;
2673 	case PHY_BAND_5:
2674 		return NL80211_BAND_5GHZ;
2675 	case PHY_BAND_6:
2676 		return NL80211_BAND_6GHZ;
2677 	default:
2678 		WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
2679 		return NL80211_BAND_5GHZ;
2680 	}
2681 }
2682 
2683 /* Channel Switch */
2684 void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk);
2685 int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
2686 				struct ieee80211_vif *vif,
2687 				struct ieee80211_bss_conf *link);
2688 
2689 /* Channel Context */
2690 /**
2691  * struct iwl_mvm_switch_vif_chanctx_ops - callbacks for switch_vif_chanctx()
2692  *
2693  * Since the only difference between both MLD and
2694  * non-MLD versions of switch_vif_chanctx() is these function calls,
2695  * each version will send its specific function calls to
2696  * %iwl_mvm_switch_vif_chanctx_common().
2697  *
2698  * @__assign_vif_chanctx: pointer to the function that assigns a chanctx to
2699  *	a given vif
2700  * @__unassign_vif_chanctx: pointer to the function that unassigns a chanctx to
2701  *	a given vif
2702  */
2703 struct iwl_mvm_switch_vif_chanctx_ops {
2704 	int (*__assign_vif_chanctx)(struct iwl_mvm *mvm,
2705 				    struct ieee80211_vif *vif,
2706 				    struct ieee80211_bss_conf *link_conf,
2707 				    struct ieee80211_chanctx_conf *ctx,
2708 				    bool switching_chanctx);
2709 	void (*__unassign_vif_chanctx)(struct iwl_mvm *mvm,
2710 				       struct ieee80211_vif *vif,
2711 				       struct ieee80211_bss_conf *link_conf,
2712 				       struct ieee80211_chanctx_conf *ctx,
2713 				       bool switching_chanctx);
2714 };
2715 
2716 int
2717 iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw,
2718 				  struct ieee80211_vif_chanctx_switch *vifs,
2719 				  int n_vifs,
2720 				  enum ieee80211_chanctx_switch_mode mode,
2721 				  const struct iwl_mvm_switch_vif_chanctx_ops *ops);
2722 
2723 /* Channel info utils */
2724 static inline bool iwl_mvm_has_ultra_hb_channel(struct iwl_mvm *mvm)
2725 {
2726 	return fw_has_capa(&mvm->fw->ucode_capa,
2727 			   IWL_UCODE_TLV_CAPA_ULTRA_HB_CHANNELS);
2728 }
2729 
2730 static inline void *iwl_mvm_chan_info_cmd_tail(struct iwl_mvm *mvm,
2731 					       struct iwl_fw_channel_info *ci)
2732 {
2733 	return (u8 *)ci + (iwl_mvm_has_ultra_hb_channel(mvm) ?
2734 			   sizeof(struct iwl_fw_channel_info) :
2735 			   sizeof(struct iwl_fw_channel_info_v1));
2736 }
2737 
2738 static inline size_t iwl_mvm_chan_info_padding(struct iwl_mvm *mvm)
2739 {
2740 	return iwl_mvm_has_ultra_hb_channel(mvm) ? 0 :
2741 		sizeof(struct iwl_fw_channel_info) -
2742 		sizeof(struct iwl_fw_channel_info_v1);
2743 }
2744 
2745 static inline void iwl_mvm_set_chan_info(struct iwl_mvm *mvm,
2746 					 struct iwl_fw_channel_info *ci,
2747 					 u32 chan, u8 band, u8 width,
2748 					 u8 ctrl_pos)
2749 {
2750 	if (iwl_mvm_has_ultra_hb_channel(mvm)) {
2751 		ci->channel = cpu_to_le32(chan);
2752 		ci->band = band;
2753 		ci->width = width;
2754 		ci->ctrl_pos = ctrl_pos;
2755 	} else {
2756 		struct iwl_fw_channel_info_v1 *ci_v1 =
2757 					(struct iwl_fw_channel_info_v1 *)ci;
2758 
2759 		ci_v1->channel = chan;
2760 		ci_v1->band = band;
2761 		ci_v1->width = width;
2762 		ci_v1->ctrl_pos = ctrl_pos;
2763 	}
2764 }
2765 
2766 static inline void
2767 iwl_mvm_set_chan_info_chandef(struct iwl_mvm *mvm,
2768 			      struct iwl_fw_channel_info *ci,
2769 			      const struct cfg80211_chan_def *chandef)
2770 {
2771 	enum nl80211_band band = chandef->chan->band;
2772 
2773 	iwl_mvm_set_chan_info(mvm, ci, chandef->chan->hw_value,
2774 			      iwl_mvm_phy_band_from_nl80211(band),
2775 			      iwl_mvm_get_channel_width(chandef),
2776 			      iwl_mvm_get_ctrl_pos(chandef));
2777 }
2778 
2779 static inline int iwl_umac_scan_get_max_profiles(const struct iwl_fw *fw)
2780 {
2781 	u8 ver = iwl_fw_lookup_cmd_ver(fw, SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
2782 				       IWL_FW_CMD_VER_UNKNOWN);
2783 	return (ver == IWL_FW_CMD_VER_UNKNOWN || ver < 3) ?
2784 		IWL_SCAN_MAX_PROFILES : IWL_SCAN_MAX_PROFILES_V2;
2785 }
2786 
2787 static inline
2788 enum iwl_location_cipher iwl_mvm_cipher_to_location_cipher(u32 cipher)
2789 {
2790 	switch (cipher) {
2791 	case WLAN_CIPHER_SUITE_CCMP:
2792 		return IWL_LOCATION_CIPHER_CCMP_128;
2793 	case WLAN_CIPHER_SUITE_GCMP:
2794 		return IWL_LOCATION_CIPHER_GCMP_128;
2795 	case WLAN_CIPHER_SUITE_GCMP_256:
2796 		return IWL_LOCATION_CIPHER_GCMP_256;
2797 	default:
2798 		return IWL_LOCATION_CIPHER_INVALID;
2799 	}
2800 }
2801 
2802 struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm);
2803 static inline int iwl_mvm_mei_get_ownership(struct iwl_mvm *mvm)
2804 {
2805 	if (mvm->mei_registered)
2806 		return iwl_mei_get_ownership();
2807 	return 0;
2808 }
2809 
2810 static inline void iwl_mvm_mei_tx_copy_to_csme(struct iwl_mvm *mvm,
2811 					       struct sk_buff *skb,
2812 					       unsigned int ivlen)
2813 {
2814 	if (mvm->mei_registered)
2815 		iwl_mei_tx_copy_to_csme(skb, ivlen);
2816 }
2817 
2818 static inline void iwl_mvm_mei_host_disassociated(struct iwl_mvm *mvm)
2819 {
2820 	if (mvm->mei_registered)
2821 		iwl_mei_host_disassociated();
2822 }
2823 
2824 static inline void iwl_mvm_mei_device_state(struct iwl_mvm *mvm, bool up)
2825 {
2826 	if (mvm->mei_registered)
2827 		iwl_mei_device_state(up);
2828 }
2829 
2830 static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm)
2831 {
2832 	bool sw_rfkill =
2833 		mvm->hw_registered ? rfkill_soft_blocked(mvm->hw->wiphy->rfkill) : false;
2834 
2835 	if (mvm->mei_registered)
2836 		iwl_mei_set_rfkill_state(iwl_mvm_is_radio_killed(mvm),
2837 					 sw_rfkill);
2838 }
2839 
2840 static inline bool iwl_mvm_has_p2p_over_aux(struct iwl_mvm *mvm)
2841 {
2842 	u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD);
2843 
2844 	return iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 0) >= 4;
2845 }
2846 
2847 static inline bool iwl_mvm_mei_filter_scan(struct iwl_mvm *mvm,
2848 					   struct sk_buff *skb)
2849 {
2850 	struct ieee80211_mgmt *mgmt = (void *)skb->data;
2851 
2852 	if (mvm->mei_scan_filter.is_mei_limited_scan &&
2853 	    (ieee80211_is_probe_resp(mgmt->frame_control) ||
2854 	     ieee80211_is_beacon(mgmt->frame_control))) {
2855 		skb_queue_tail(&mvm->mei_scan_filter.scan_res, skb);
2856 		schedule_work(&mvm->mei_scan_filter.scan_work);
2857 		return true;
2858 	}
2859 
2860 	return false;
2861 }
2862 
2863 void iwl_mvm_send_roaming_forbidden_event(struct iwl_mvm *mvm,
2864 					  struct ieee80211_vif *vif,
2865 					  bool forbidden);
2866 
2867 /* Callbacks for ieee80211_ops */
2868 void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
2869 		    struct ieee80211_tx_control *control, struct sk_buff *skb);
2870 void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
2871 			       struct ieee80211_txq *txq);
2872 
2873 int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
2874 			     struct ieee80211_vif *vif,
2875 			     struct ieee80211_ampdu_params *params);
2876 int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant);
2877 int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant);
2878 int iwl_mvm_mac_start(struct ieee80211_hw *hw);
2879 void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
2880 				   enum ieee80211_reconfig_type reconfig_type);
2881 void iwl_mvm_mac_stop(struct ieee80211_hw *hw, bool suspend);
2882 static inline int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
2883 {
2884 	return 0;
2885 }
2886 
2887 u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
2888 			      struct netdev_hw_addr_list *mc_list);
2889 
2890 void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
2891 			      unsigned int changed_flags,
2892 			      unsigned int *total_flags, u64 multicast);
2893 int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2894 			struct ieee80211_scan_request *hw_req);
2895 void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2896 				struct ieee80211_vif *vif);
2897 void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2898 				struct ieee80211_vif *vif,
2899 				struct ieee80211_sta *sta);
2900 void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2901 			    enum sta_notify_cmd cmd,
2902 			    struct ieee80211_sta *sta);
2903 void
2904 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2905 				  struct ieee80211_sta *sta, u16 tids,
2906 				  int num_frames,
2907 				  enum ieee80211_frame_release_type reason,
2908 				  bool more_data);
2909 void
2910 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2911 				    struct ieee80211_sta *sta, u16 tids,
2912 				    int num_frames,
2913 				    enum ieee80211_frame_release_type reason,
2914 				    bool more_data);
2915 int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value);
2916 void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2917 			   struct ieee80211_sta *sta, u32 changed);
2918 void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2919 				struct ieee80211_vif *vif,
2920 				struct ieee80211_prep_tx_info *info);
2921 void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
2922 				 struct ieee80211_vif *vif,
2923 				 struct ieee80211_prep_tx_info *info);
2924 void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2925 		       u32 queues, bool drop);
2926 void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2927 			   struct ieee80211_sta *sta);
2928 int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2929 				 struct ieee80211_vif *vif,
2930 				 struct cfg80211_sched_scan_request *req,
2931 				 struct ieee80211_scan_ies *ies);
2932 int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2933 				struct ieee80211_vif *vif);
2934 int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2935 			struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2936 			struct ieee80211_key_conf *key);
2937 void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2938 				 struct ieee80211_vif *vif,
2939 				 struct ieee80211_key_conf *keyconf,
2940 				 struct ieee80211_sta *sta,
2941 				 u32 iv32, u16 *phase1key);
2942 int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2943 			struct ieee80211_chanctx_conf *ctx);
2944 void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2945 			    struct ieee80211_chanctx_conf *ctx);
2946 void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2947 			    struct ieee80211_chanctx_conf *ctx, u32 changed);
2948 int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw);
2949 void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2950 			    struct ieee80211_channel_switch *chsw);
2951 int iwl_mvm_pre_channel_switch(struct iwl_mvm *mvm,
2952 			       struct ieee80211_vif *vif,
2953 			       struct ieee80211_channel_switch *chsw);
2954 void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
2955 				  struct ieee80211_vif *vif,
2956 				  struct ieee80211_bss_conf *link_conf);
2957 void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
2958 				      struct ieee80211_vif *vif,
2959 				      struct ieee80211_channel_switch *chsw);
2960 void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
2961 				struct ieee80211_vif *vif,
2962 				const struct ieee80211_event *event);
2963 void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw);
2964 int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2965 			     struct ieee80211_vif *vif,
2966 			     void *data, int len);
2967 int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
2968 			   struct survey_info *survey);
2969 void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
2970 				struct ieee80211_vif *vif,
2971 				struct ieee80211_sta *sta,
2972 				struct station_info *sinfo);
2973 int
2974 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
2975 				    struct ieee80211_vif *vif,
2976 				    struct cfg80211_ftm_responder_stats *stats);
2977 int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2978 		       struct cfg80211_pmsr_request *request);
2979 void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2980 			struct cfg80211_pmsr_request *request);
2981 
2982 bool iwl_mvm_have_links_same_channel(struct iwl_mvm_vif *vif1,
2983 				     struct iwl_mvm_vif *vif2);
2984 bool iwl_mvm_vif_is_active(struct iwl_mvm_vif *mvmvif);
2985 int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2986 			 s16 tx_power);
2987 int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw,
2988 			     struct ieee80211_vif *vif,
2989 			     struct cfg80211_set_hw_timestamp *hwts);
2990 int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2991 bool iwl_mvm_enable_fils(struct iwl_mvm *mvm,
2992 			 struct ieee80211_chanctx_conf *ctx);
2993 bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
2994 				      struct ieee80211_chanctx_conf *ctx);
2995 
2996 static inline struct cfg80211_chan_def *
2997 iwl_mvm_chanctx_def(struct iwl_mvm *mvm, struct ieee80211_chanctx_conf *ctx)
2998 {
2999 	bool use_def = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx) ||
3000 		iwl_mvm_enable_fils(mvm, ctx);
3001 
3002 	return use_def ? &ctx->def : &ctx->min_def;
3003 }
3004 
3005 void iwl_mvm_roc_duration_and_delay(struct ieee80211_vif *vif,
3006 				    u32 duration_ms,
3007 				    u32 *duration_tu,
3008 				    u32 *delay);
3009 int iwl_mvm_roc_add_cmd(struct iwl_mvm *mvm,
3010 			struct ieee80211_channel *channel,
3011 			struct ieee80211_vif *vif,
3012 			int duration, enum iwl_roc_activity activity);
3013 
3014 /* EMLSR */
3015 bool iwl_mvm_vif_has_esr_cap(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
3016 void iwl_mvm_block_esr(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3017 		       enum iwl_mvm_esr_state reason,
3018 		       u8 link_to_keep);
3019 int iwl_mvm_block_esr_sync(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3020 			   enum iwl_mvm_esr_state reason);
3021 void iwl_mvm_unblock_esr(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3022 			 enum iwl_mvm_esr_state reason);
3023 void iwl_mvm_exit_esr(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3024 		      enum iwl_mvm_esr_state reason,
3025 		      u8 link_to_keep);
3026 s8 iwl_mvm_get_esr_rssi_thresh(struct iwl_mvm *mvm,
3027 			       const struct cfg80211_chan_def *chandef,
3028 			       bool low);
3029 void iwl_mvm_bt_coex_update_link_esr(struct iwl_mvm *mvm,
3030 				     struct ieee80211_vif *vif,
3031 				     int link_id);
3032 bool
3033 iwl_mvm_bt_coex_calculate_esr_mode(struct iwl_mvm *mvm,
3034 				   struct ieee80211_vif *vif,
3035 				   s32 link_rssi,
3036 				   bool primary);
3037 int iwl_mvm_esr_non_bss_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3038 			     unsigned int link_id, bool active);
3039 
3040 void
3041 iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm *mvm,
3042 					struct ieee80211_vif *vif,
3043 					struct ieee80211_bss_conf *bss_conf,
3044 					bool is_ap);
3045 #endif /* __IWL_MVM_H__ */
3046