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