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