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