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