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