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