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