xref: /freebsd/sys/contrib/dev/iwlwifi/mvm/mvm.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2012-2014, 2018-2022 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 #ifdef CONFIG_IWLWIFI_LEDS
13 #include <linux/leds.h>
14 #endif
15 #include <linux/in6.h>
16 
17 #ifdef CONFIG_THERMAL
18 #include <linux/thermal.h>
19 #endif
20 
21 #include <linux/ktime.h>
22 
23 #include "iwl-op-mode.h"
24 #include "iwl-trans.h"
25 #include "fw/notif-wait.h"
26 #include "iwl-eeprom-parse.h"
27 #include "fw/file.h"
28 #include "iwl-config.h"
29 #include "sta.h"
30 #include "fw-api.h"
31 #include "constants.h"
32 #include "fw/runtime.h"
33 #include "fw/dbg.h"
34 #include "fw/acpi.h"
35 #include "mei/iwl-mei.h"
36 #include "iwl-nvm-parse.h"
37 
38 #include <linux/average.h>
39 #if defined(__FreeBSD__)
40 #include <net/if_inet6.h>
41 #endif
42 
43 #define IWL_MVM_MAX_ADDRESSES		5
44 /* RSSI offset for WkP */
45 #define IWL_RSSI_OFFSET 50
46 #define IWL_MVM_MISSED_BEACONS_THRESHOLD 8
47 #define IWL_MVM_MISSED_BEACONS_THRESHOLD_LONG 16
48 
49 /* A TimeUnit is 1024 microsecond */
50 #define MSEC_TO_TU(_msec)	(_msec*1000/1024)
51 
52 /* For GO, this value represents the number of TUs before CSA "beacon
53  * 0" TBTT when the CSA time-event needs to be scheduled to start.  It
54  * must be big enough to ensure that we switch in time.
55  */
56 #define IWL_MVM_CHANNEL_SWITCH_TIME_GO		40
57 
58 /* For client, this value represents the number of TUs before CSA
59  * "beacon 1" TBTT, instead.  This is because we don't know when the
60  * GO/AP will be in the new channel, so we switch early enough.
61  */
62 #define IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT	10
63 
64 /*
65  * This value (in TUs) is used to fine tune the CSA NoA end time which should
66  * be just before "beacon 0" TBTT.
67  */
68 #define IWL_MVM_CHANNEL_SWITCH_MARGIN 4
69 
70 /*
71  * Number of beacons to transmit on a new channel until we unblock tx to
72  * the stations, even if we didn't identify them on a new channel
73  */
74 #define IWL_MVM_CS_UNBLOCK_TX_TIMEOUT 3
75 
76 /* offchannel queue towards mac80211 */
77 #define IWL_MVM_OFFCHANNEL_QUEUE 0
78 
79 extern const struct ieee80211_ops iwl_mvm_hw_ops;
80 
81 /**
82  * struct iwl_mvm_mod_params - module parameters for iwlmvm
83  * @init_dbg: if true, then the NIC won't be stopped if the INIT fw asserted.
84  *	We will register to mac80211 to have testmode working. The NIC must not
85  *	be up'ed after the INIT fw asserted. This is useful to be able to use
86  *	proprietary tools over testmode to debug the INIT fw.
87  * @power_scheme: one of enum iwl_power_scheme
88  */
89 struct iwl_mvm_mod_params {
90 	bool init_dbg;
91 	int power_scheme;
92 };
93 extern struct iwl_mvm_mod_params iwlmvm_mod_params;
94 
95 struct iwl_mvm_phy_ctxt {
96 	u16 id;
97 	u16 color;
98 	u32 ref;
99 
100 	enum nl80211_chan_width width;
101 
102 	struct ieee80211_channel *channel;
103 
104 	/* track for RLC config command */
105 	u32 center_freq1;
106 };
107 
108 struct iwl_mvm_time_event_data {
109 	struct ieee80211_vif *vif;
110 	struct list_head list;
111 	unsigned long end_jiffies;
112 	u32 duration;
113 	bool running;
114 	u32 uid;
115 
116 	/*
117 	 * The access to the 'id' field must be done when the
118 	 * mvm->time_event_lock is held, as it value is used to indicate
119 	 * if the te is in the time event list or not (when id == TE_MAX)
120 	 */
121 	u32 id;
122 };
123 
124  /* Power management */
125 
126 /**
127  * enum iwl_power_scheme
128  * @IWL_POWER_LEVEL_CAM - Continuously Active Mode
129  * @IWL_POWER_LEVEL_BPS - Balanced Power Save (default)
130  * @IWL_POWER_LEVEL_LP  - Low Power
131  */
132 enum iwl_power_scheme {
133 	IWL_POWER_SCHEME_CAM = 1,
134 	IWL_POWER_SCHEME_BPS,
135 	IWL_POWER_SCHEME_LP
136 };
137 
138 #define IWL_CONN_MAX_LISTEN_INTERVAL	10
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  * struct 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 * struct 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_vif_bf_data - beacon filtering related data
255 * @bf_enabled: indicates if beacon filtering is enabled
256 * @ba_enabled: indicated if beacon abort is enabled
257 * @ave_beacon_signal: average beacon signal
258 * @last_cqm_event: rssi of the last cqm event
259 * @bt_coex_min_thold: minimum threshold for BT coex
260 * @bt_coex_max_thold: maximum threshold for BT coex
261 * @last_bt_coex_event: rssi of the last BT coex event
262 */
263 struct iwl_mvm_vif_bf_data {
264 	bool bf_enabled;
265 	bool ba_enabled;
266 	int ave_beacon_signal;
267 	int last_cqm_event;
268 	int bt_coex_min_thold;
269 	int bt_coex_max_thold;
270 	int last_bt_coex_event;
271 };
272 
273 /**
274  * struct iwl_probe_resp_data - data for NoA/CSA updates
275  * @rcu_head: used for freeing the data on update
276  * @notif: notification data
277  * @noa_len: length of NoA attribute, calculated from the notification
278  */
279 struct iwl_probe_resp_data {
280 	struct rcu_head rcu_head;
281 	struct iwl_probe_resp_data_notif notif;
282 	int noa_len;
283 };
284 
285 /**
286  * struct iwl_mvm_vif - data per Virtual Interface, it is a MAC context
287  * @id: between 0 and 3
288  * @color: to solve races upon MAC addition and removal
289  * @ap_sta_id: the sta_id of the AP - valid only if VIF type is STA
290  * @bssid: BSSID for this (client) interface
291  * @associated: indicates that we're currently associated, used only for
292  *	managing the firmware state in iwl_mvm_bss_info_changed_station()
293  * @ap_assoc_sta_count: count of stations associated to us - valid only
294  *	if VIF type is AP
295  * @uploaded: indicates the MAC context has been added to the device
296  * @ap_ibss_active: indicates that AP/IBSS is configured and that the interface
297  *	should get quota etc.
298  * @pm_enabled - Indicate if MAC power management is allowed
299  * @monitor_active: indicates that monitor context is configured, and that the
300  *	interface should get quota etc.
301  * @low_latency: bit flags for low latency
302  *	see enum &iwl_mvm_low_latency_cause for causes.
303  * @low_latency_actual: boolean, indicates low latency is set,
304  *	as a result from low_latency bit flags and takes force into account.
305  * @authorized: indicates the AP station was set to authorized
306  * @ps_disabled: indicates that this interface requires PS to be disabled
307  * @queue_params: QoS params for this MAC
308  * @bcast_sta: station used for broadcast packets. Used by the following
309  *  vifs: P2P_DEVICE, GO and AP.
310  * @beacon_skb: the skb used to hold the AP/GO beacon template
311  * @smps_requests: the SMPS requests of different parts of the driver,
312  *	combined on update to yield the overall request to mac80211.
313  * @beacon_stats: beacon statistics, containing the # of received beacons,
314  *	# of received beacons accumulated over FW restart, and the current
315  *	average signal of beacons retrieved from the firmware
316  * @csa_failed: CSA failed to schedule time event, report an error later
317  * @features: hw features active for this vif
318  * @probe_resp_data: data from FW notification to store NOA and CSA related
319  *	data to be inserted into probe response.
320  */
321 struct iwl_mvm_vif {
322 	struct iwl_mvm *mvm;
323 	u16 id;
324 	u16 color;
325 	u8 ap_sta_id;
326 
327 	u8 bssid[ETH_ALEN];
328 	bool associated;
329 	u8 ap_assoc_sta_count;
330 
331 	u16 cab_queue;
332 
333 	bool uploaded;
334 	bool ap_ibss_active;
335 	bool pm_enabled;
336 	bool monitor_active;
337 	u8 low_latency: 6;
338 	u8 low_latency_actual: 1;
339 	u8 authorized:1;
340 	bool ps_disabled;
341 	struct iwl_mvm_vif_bf_data bf_data;
342 
343 	struct {
344 		u32 num_beacons, accu_num_beacons;
345 		u8 avg_signal;
346 	} beacon_stats;
347 
348 	u32 ap_beacon_time;
349 
350 	enum iwl_tsf_id tsf_id;
351 
352 	/*
353 	 * QoS data from mac80211, need to store this here
354 	 * as mac80211 has a separate callback but we need
355 	 * to have the data for the MAC context
356 	 */
357 	struct ieee80211_tx_queue_params queue_params[IEEE80211_NUM_ACS];
358 	struct iwl_mvm_time_event_data time_event_data;
359 	struct iwl_mvm_time_event_data hs_time_event_data;
360 
361 	struct iwl_mvm_int_sta bcast_sta;
362 	struct iwl_mvm_int_sta mcast_sta;
363 
364 	/*
365 	 * Assigned while mac80211 has the interface in a channel context,
366 	 * or, for P2P Device, while it exists.
367 	 */
368 	struct iwl_mvm_phy_ctxt *phy_ctxt;
369 
370 #ifdef CONFIG_PM
371 	/* WoWLAN GTK rekey data */
372 	struct {
373 		u8 kck[NL80211_KCK_EXT_LEN];
374 		u8 kek[NL80211_KEK_EXT_LEN];
375 		size_t kek_len;
376 		size_t kck_len;
377 		u32 akm;
378 		__le64 replay_ctr;
379 		bool valid;
380 	} rekey_data;
381 
382 	int tx_key_idx;
383 
384 	bool seqno_valid;
385 	u16 seqno;
386 #endif
387 
388 #if IS_ENABLED(CONFIG_IPV6)
389 	/* IPv6 addresses for WoWLAN */
390 	struct in6_addr target_ipv6_addrs[IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX];
391 	unsigned long tentative_addrs[BITS_TO_LONGS(IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)];
392 	int num_target_ipv6_addrs;
393 #endif
394 
395 #ifdef CONFIG_IWLWIFI_DEBUGFS
396 	struct dentry *dbgfs_dir;
397 	struct dentry *dbgfs_slink;
398 	struct iwl_dbgfs_pm dbgfs_pm;
399 	struct iwl_dbgfs_bf dbgfs_bf;
400 	struct iwl_mac_power_cmd mac_pwr_cmd;
401 	int dbgfs_quota_min;
402 #endif
403 
404 	enum ieee80211_smps_mode smps_requests[NUM_IWL_MVM_SMPS_REQ];
405 
406 	/* FW identified misbehaving AP */
407 	u8 uapsd_misbehaving_bssid[ETH_ALEN];
408 
409 	struct delayed_work uapsd_nonagg_detected_wk;
410 
411 	/* Indicates that CSA countdown may be started */
412 	bool csa_countdown;
413 	bool csa_failed;
414 	u16 csa_target_freq;
415 	u16 csa_count;
416 	u16 csa_misbehave;
417 	struct delayed_work csa_work;
418 
419 	/* Indicates that we are waiting for a beacon on a new channel */
420 	bool csa_bcn_pending;
421 
422 	/* TCP Checksum Offload */
423 	netdev_features_t features;
424 
425 	struct iwl_probe_resp_data __rcu *probe_resp_data;
426 
427 	/* we can only have 2 GTK + 2 IGTK active at a time */
428 	struct ieee80211_key_conf *ap_early_keys[4];
429 
430 	/* 26-tone RU OFDMA transmissions should be blocked */
431 	bool he_ru_2mhz_block;
432 
433 	struct {
434 		struct ieee80211_key_conf __rcu *keys[2];
435 	} bcn_prot;
436 };
437 
438 static inline struct iwl_mvm_vif *
439 iwl_mvm_vif_from_mac80211(struct ieee80211_vif *vif)
440 {
441 	return (void *)vif->drv_priv;
442 }
443 
444 extern const u8 tid_to_mac80211_ac[];
445 
446 #define IWL_MVM_SCAN_STOPPING_SHIFT	8
447 
448 enum iwl_scan_status {
449 	IWL_MVM_SCAN_REGULAR		= BIT(0),
450 	IWL_MVM_SCAN_SCHED		= BIT(1),
451 	IWL_MVM_SCAN_NETDETECT		= BIT(2),
452 
453 	IWL_MVM_SCAN_STOPPING_REGULAR	= BIT(8),
454 	IWL_MVM_SCAN_STOPPING_SCHED	= BIT(9),
455 	IWL_MVM_SCAN_STOPPING_NETDETECT	= BIT(10),
456 
457 	IWL_MVM_SCAN_REGULAR_MASK	= IWL_MVM_SCAN_REGULAR |
458 					  IWL_MVM_SCAN_STOPPING_REGULAR,
459 	IWL_MVM_SCAN_SCHED_MASK		= IWL_MVM_SCAN_SCHED |
460 					  IWL_MVM_SCAN_STOPPING_SCHED,
461 	IWL_MVM_SCAN_NETDETECT_MASK	= IWL_MVM_SCAN_NETDETECT |
462 					  IWL_MVM_SCAN_STOPPING_NETDETECT,
463 
464 	IWL_MVM_SCAN_STOPPING_MASK	= 0xff << IWL_MVM_SCAN_STOPPING_SHIFT,
465 	IWL_MVM_SCAN_MASK		= 0xff,
466 };
467 
468 enum iwl_mvm_scan_type {
469 	IWL_SCAN_TYPE_NOT_SET,
470 	IWL_SCAN_TYPE_UNASSOC,
471 	IWL_SCAN_TYPE_WILD,
472 	IWL_SCAN_TYPE_MILD,
473 	IWL_SCAN_TYPE_FRAGMENTED,
474 	IWL_SCAN_TYPE_FAST_BALANCE,
475 };
476 
477 enum iwl_mvm_sched_scan_pass_all_states {
478 	SCHED_SCAN_PASS_ALL_DISABLED,
479 	SCHED_SCAN_PASS_ALL_ENABLED,
480 	SCHED_SCAN_PASS_ALL_FOUND,
481 };
482 
483 /**
484  * struct iwl_mvm_tt_mgnt - Thermal Throttling Management structure
485  * @ct_kill_exit: worker to exit thermal kill
486  * @dynamic_smps: Is thermal throttling enabled dynamic_smps?
487  * @tx_backoff: The current thremal throttling tx backoff in uSec.
488  * @min_backoff: The minimal tx backoff due to power restrictions
489  * @params: Parameters to configure the thermal throttling algorithm.
490  * @throttle: Is thermal throttling is active?
491  */
492 struct iwl_mvm_tt_mgmt {
493 	struct delayed_work ct_kill_exit;
494 	bool dynamic_smps;
495 	u32 tx_backoff;
496 	u32 min_backoff;
497 	struct iwl_tt_params params;
498 	bool throttle;
499 };
500 
501 #ifdef CONFIG_THERMAL
502 /**
503  *struct iwl_mvm_thermal_device - thermal zone related data
504  * @temp_trips: temperature thresholds for report
505  * @fw_trips_index: keep indexes to original array - temp_trips
506  * @tzone: thermal zone device data
507 */
508 struct iwl_mvm_thermal_device {
509 	s16 temp_trips[IWL_MAX_DTS_TRIPS];
510 	u8 fw_trips_index[IWL_MAX_DTS_TRIPS];
511 	struct thermal_zone_device *tzone;
512 };
513 
514 /*
515  * struct iwl_mvm_cooling_device
516  * @cur_state: current state
517  * @cdev: struct thermal cooling device
518  */
519 struct iwl_mvm_cooling_device {
520 	u32 cur_state;
521 	struct thermal_cooling_device *cdev;
522 };
523 #endif
524 
525 #define IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES 8
526 
527 struct iwl_mvm_frame_stats {
528 	u32 legacy_frames;
529 	u32 ht_frames;
530 	u32 vht_frames;
531 	u32 bw_20_frames;
532 	u32 bw_40_frames;
533 	u32 bw_80_frames;
534 	u32 bw_160_frames;
535 	u32 sgi_frames;
536 	u32 ngi_frames;
537 	u32 siso_frames;
538 	u32 mimo2_frames;
539 	u32 agg_frames;
540 	u32 ampdu_count;
541 	u32 success_frames;
542 	u32 fail_frames;
543 	u32 last_rates[IWL_MVM_NUM_LAST_FRAMES_UCODE_RATES];
544 	int last_frame_idx;
545 };
546 
547 #define IWL_MVM_DEBUG_SET_TEMPERATURE_DISABLE 0xff
548 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MIN -100
549 #define IWL_MVM_DEBUG_SET_TEMPERATURE_MAX 200
550 
551 enum iwl_mvm_tdls_cs_state {
552 	IWL_MVM_TDLS_SW_IDLE = 0,
553 	IWL_MVM_TDLS_SW_REQ_SENT,
554 	IWL_MVM_TDLS_SW_RESP_RCVD,
555 	IWL_MVM_TDLS_SW_REQ_RCVD,
556 	IWL_MVM_TDLS_SW_ACTIVE,
557 };
558 
559 enum iwl_mvm_traffic_load {
560 	IWL_MVM_TRAFFIC_LOW,
561 	IWL_MVM_TRAFFIC_MEDIUM,
562 	IWL_MVM_TRAFFIC_HIGH,
563 };
564 
565 DECLARE_EWMA(rate, 16, 16)
566 
567 struct iwl_mvm_tcm_mac {
568 	struct {
569 		u32 pkts[IEEE80211_NUM_ACS];
570 		u32 airtime;
571 	} tx;
572 	struct {
573 		u32 pkts[IEEE80211_NUM_ACS];
574 		u32 airtime;
575 		u32 last_ampdu_ref;
576 	} rx;
577 	struct {
578 		/* track AP's transfer in client mode */
579 		u64 rx_bytes;
580 		struct ewma_rate rate;
581 		bool detected;
582 	} uapsd_nonagg_detect;
583 	bool opened_rx_ba_sessions;
584 };
585 
586 struct iwl_mvm_tcm {
587 	struct delayed_work work;
588 	spinlock_t lock; /* used when time elapsed */
589 	unsigned long ts; /* timestamp when period ends */
590 	unsigned long ll_ts;
591 	unsigned long uapsd_nonagg_ts;
592 	bool paused;
593 	struct iwl_mvm_tcm_mac data[NUM_MAC_INDEX_DRIVER];
594 	struct {
595 		u32 elapsed; /* milliseconds for this TCM period */
596 		u32 airtime[NUM_MAC_INDEX_DRIVER];
597 		enum iwl_mvm_traffic_load load[NUM_MAC_INDEX_DRIVER];
598 		enum iwl_mvm_traffic_load band_load[NUM_NL80211_BANDS];
599 		enum iwl_mvm_traffic_load global_load;
600 		bool low_latency[NUM_MAC_INDEX_DRIVER];
601 		bool change[NUM_MAC_INDEX_DRIVER];
602 	} result;
603 };
604 
605 /**
606  * struct iwl_mvm_reorder_buffer - per ra/tid/queue reorder buffer
607  * @head_sn: reorder window head sn
608  * @num_stored: number of mpdus stored in the buffer
609  * @buf_size: the reorder buffer size as set by the last addba request
610  * @queue: queue of this reorder buffer
611  * @last_amsdu: track last ASMDU SN for duplication detection
612  * @last_sub_index: track ASMDU sub frame index for duplication detection
613  * @reorder_timer: timer for frames are in the reorder buffer. For AMSDU
614  *	it is the time of last received sub-frame
615  * @removed: prevent timer re-arming
616  * @valid: reordering is valid for this queue
617  * @lock: protect reorder buffer internal state
618  * @mvm: mvm pointer, needed for frame timer context
619  * @consec_oldsn_drops: consecutive drops due to old SN
620  * @consec_oldsn_ampdu_gp2: A-MPDU GP2 timestamp to track
621  *	when to apply old SN consecutive drop workaround
622  * @consec_oldsn_prev_drop: track whether or not an MPDU
623  *	that was single/part of the previous A-MPDU was
624  *	dropped due to old SN
625  */
626 struct iwl_mvm_reorder_buffer {
627 	u16 head_sn;
628 	u16 num_stored;
629 	u16 buf_size;
630 	int queue;
631 	u16 last_amsdu;
632 	u8 last_sub_index;
633 	struct timer_list reorder_timer;
634 	bool removed;
635 	bool valid;
636 	spinlock_t lock;
637 	struct iwl_mvm *mvm;
638 	unsigned int consec_oldsn_drops;
639 	u32 consec_oldsn_ampdu_gp2;
640 	unsigned int consec_oldsn_prev_drop:1;
641 } ____cacheline_aligned_in_smp;
642 
643 /**
644  * struct _iwl_mvm_reorder_buf_entry - reorder buffer entry per-queue/per-seqno
645  * @frames: list of skbs stored
646  * @reorder_time: time the packet was stored in the reorder buffer
647  */
648 struct _iwl_mvm_reorder_buf_entry {
649 	struct sk_buff_head frames;
650 	unsigned long reorder_time;
651 };
652 
653 /* make this indirection to get the aligned thing */
654 struct iwl_mvm_reorder_buf_entry {
655 	struct _iwl_mvm_reorder_buf_entry e;
656 }
657 #if defined(__FreeBSD__)
658 __aligned(roundup2(sizeof(struct _iwl_mvm_reorder_buf_entry), 32))
659 #elif !defined(__CHECKER__)
660 /* sparse doesn't like this construct: "bad integer constant expression" */
661 /* clang on FreeBSD: error: 'aligned' attribute requires integer constant */
662 __aligned(roundup_pow_of_two(sizeof(struct _iwl_mvm_reorder_buf_entry)))
663 #endif
664 ;
665 
666 /**
667  * struct iwl_mvm_baid_data - BA session data
668  * @sta_id: station id
669  * @tid: tid of the session
670  * @baid baid of the session
671  * @timeout: the timeout set in the addba request
672  * @entries_per_queue: # of buffers per queue, this actually gets
673  *	aligned up to avoid cache line sharing between queues
674  * @last_rx: last rx jiffies, updated only if timeout passed from last update
675  * @session_timer: timer to check if BA session expired, runs at 2 * timeout
676  * @mvm: mvm pointer, needed for timer context
677  * @reorder_buf: reorder buffer, allocated per queue
678  * @reorder_buf_data: data
679  */
680 struct iwl_mvm_baid_data {
681 	struct rcu_head rcu_head;
682 	u8 sta_id;
683 	u8 tid;
684 	u8 baid;
685 	u16 timeout;
686 	u16 entries_per_queue;
687 	unsigned long last_rx;
688 	struct timer_list session_timer;
689 	struct iwl_mvm_baid_data __rcu **rcu_ptr;
690 	struct iwl_mvm *mvm;
691 	struct iwl_mvm_reorder_buffer reorder_buf[IWL_MAX_RX_HW_QUEUES];
692 	struct iwl_mvm_reorder_buf_entry entries[];
693 };
694 
695 static inline struct iwl_mvm_baid_data *
696 iwl_mvm_baid_data_from_reorder_buf(struct iwl_mvm_reorder_buffer *buf)
697 {
698 	return (void *)((u8 *)buf -
699 			offsetof(struct iwl_mvm_baid_data, reorder_buf) -
700 			sizeof(*buf) * buf->queue);
701 }
702 
703 /*
704  * enum iwl_mvm_queue_status - queue status
705  * @IWL_MVM_QUEUE_FREE: the queue is not allocated nor reserved
706  *	Basically, this means that this queue can be used for any purpose
707  * @IWL_MVM_QUEUE_RESERVED: queue is reserved but not yet in use
708  *	This is the state of a queue that has been dedicated for some RATID
709  *	(agg'd or not), but that hasn't yet gone through the actual enablement
710  *	of iwl_mvm_enable_txq(), and therefore no traffic can go through it yet.
711  *	Note that in this state there is no requirement to already know what TID
712  *	should be used with this queue, it is just marked as a queue that will
713  *	be used, and shouldn't be allocated to anyone else.
714  * @IWL_MVM_QUEUE_READY: queue is ready to be used
715  *	This is the state of a queue that has been fully configured (including
716  *	SCD pointers, etc), has a specific RA/TID assigned to it, and can be
717  *	used to send traffic.
718  * @IWL_MVM_QUEUE_SHARED: queue is shared, or in a process of becoming shared
719  *	This is a state in which a single queue serves more than one TID, all of
720  *	which are not aggregated. Note that the queue is only associated to one
721  *	RA.
722  */
723 enum iwl_mvm_queue_status {
724 	IWL_MVM_QUEUE_FREE,
725 	IWL_MVM_QUEUE_RESERVED,
726 	IWL_MVM_QUEUE_READY,
727 	IWL_MVM_QUEUE_SHARED,
728 };
729 
730 #define IWL_MVM_DQA_QUEUE_TIMEOUT	(5 * HZ)
731 #define IWL_MVM_INVALID_QUEUE		0xFFFF
732 
733 #define IWL_MVM_NUM_CIPHERS             10
734 
735 
736 struct iwl_mvm_txq {
737 	struct list_head list;
738 	u16 txq_id;
739 	atomic_t tx_request;
740 	bool stopped;
741 };
742 
743 static inline struct iwl_mvm_txq *
744 iwl_mvm_txq_from_mac80211(struct ieee80211_txq *txq)
745 {
746 	return (void *)txq->drv_priv;
747 }
748 
749 static inline struct iwl_mvm_txq *
750 iwl_mvm_txq_from_tid(struct ieee80211_sta *sta, u8 tid)
751 {
752 	if (tid == IWL_MAX_TID_COUNT)
753 		tid = IEEE80211_NUM_TIDS;
754 
755 	return (void *)sta->txq[tid]->drv_priv;
756 }
757 
758 /**
759  * struct iwl_mvm_tvqm_txq_info - maps TVQM hw queue to tid
760  *
761  * @sta_id: sta id
762  * @txq_tid: txq tid
763  */
764 struct iwl_mvm_tvqm_txq_info {
765 	u8 sta_id;
766 	u8 txq_tid;
767 };
768 
769 struct iwl_mvm_dqa_txq_info {
770 	u8 ra_sta_id; /* The RA this queue is mapped to, if exists */
771 	bool reserved; /* Is this the TXQ reserved for a STA */
772 	u8 mac80211_ac; /* The mac80211 AC this queue is mapped to */
773 	u8 txq_tid; /* The TID "owner" of this queue*/
774 	u16 tid_bitmap; /* Bitmap of the TIDs mapped to this queue */
775 	/* Timestamp for inactivation per TID of this queue */
776 	unsigned long last_frame_time[IWL_MAX_TID_COUNT + 1];
777 	enum iwl_mvm_queue_status status;
778 };
779 
780 struct iwl_mvm {
781 	/* for logger access */
782 	struct device *dev;
783 
784 	struct iwl_trans *trans;
785 	const struct iwl_fw *fw;
786 	const struct iwl_cfg *cfg;
787 	struct iwl_phy_db *phy_db;
788 	struct ieee80211_hw *hw;
789 
790 	/* for protecting access to iwl_mvm */
791 	struct mutex mutex;
792 	struct list_head async_handlers_list;
793 	spinlock_t async_handlers_lock;
794 	struct work_struct async_handlers_wk;
795 
796 	struct work_struct roc_done_wk;
797 
798 	unsigned long init_status;
799 
800 	unsigned long status;
801 
802 	u32 queue_sync_cookie;
803 	unsigned long queue_sync_state;
804 	/*
805 	 * for beacon filtering -
806 	 * currently only one interface can be supported
807 	 */
808 	struct iwl_mvm_vif *bf_allowed_vif;
809 
810 	bool hw_registered;
811 	bool rfkill_safe_init_done;
812 
813 	u8 cca_40mhz_workaround;
814 
815 	u32 ampdu_ref;
816 	bool ampdu_toggle;
817 
818 	struct iwl_notif_wait_data notif_wait;
819 
820 	union {
821 		struct mvm_statistics_rx_v3 rx_stats_v3;
822 		struct mvm_statistics_rx rx_stats;
823 	};
824 
825 	struct {
826 		u64 rx_time;
827 		u64 tx_time;
828 		u64 on_time_rf;
829 		u64 on_time_scan;
830 	} radio_stats, accu_radio_stats;
831 
832 	struct list_head add_stream_txqs;
833 	union {
834 		struct iwl_mvm_dqa_txq_info queue_info[IWL_MAX_HW_QUEUES];
835 		struct iwl_mvm_tvqm_txq_info tvqm_info[IWL_MAX_TVQM_QUEUES];
836 	};
837 	struct work_struct add_stream_wk; /* To add streams to queues */
838 
839 	const char *nvm_file_name;
840 	struct iwl_nvm_data *nvm_data;
841 	struct iwl_mei_nvm *mei_nvm_data;
842 	struct iwl_mvm_csme_conn_info __rcu *csme_conn_info;
843 	bool mei_rfkill_blocked;
844 	bool mei_registered;
845 	struct work_struct sap_connected_wk;
846 
847 	/*
848 	 * NVM built based on the SAP data but that we can't free even after
849 	 * we get ownership because it contains the cfg80211's channel.
850 	 */
851 	struct iwl_nvm_data *temp_nvm_data;
852 
853 	/* NVM sections */
854 	struct iwl_nvm_section nvm_sections[NVM_MAX_NUM_SECTIONS];
855 
856 	struct iwl_fw_runtime fwrt;
857 
858 	/* EEPROM MAC addresses */
859 	struct mac_address addresses[IWL_MVM_MAX_ADDRESSES];
860 
861 	/* data related to data path */
862 	struct iwl_rx_phy_info last_phy_info;
863 	struct ieee80211_sta __rcu *fw_id_to_mac_id[IWL_MVM_STATION_COUNT_MAX];
864 	u8 rx_ba_sessions;
865 
866 	/* configured by mac80211 */
867 	u32 rts_threshold;
868 
869 	/* Scan status, cmd (pre-allocated) and auxiliary station */
870 	unsigned int scan_status;
871 	void *scan_cmd;
872 	struct iwl_mcast_filter_cmd *mcast_filter_cmd;
873 	/* For CDB this is low band scan type, for non-CDB - type. */
874 	enum iwl_mvm_scan_type scan_type;
875 	enum iwl_mvm_scan_type hb_scan_type;
876 
877 	enum iwl_mvm_sched_scan_pass_all_states sched_scan_pass_all;
878 	struct delayed_work scan_timeout_dwork;
879 
880 	/* max number of simultaneous scans the FW supports */
881 	unsigned int max_scans;
882 
883 	/* UMAC scan tracking */
884 	u32 scan_uid_status[IWL_MVM_MAX_UMAC_SCANS];
885 
886 	/* start time of last scan in TSF of the mac that requested the scan */
887 	u64 scan_start;
888 
889 	/* the vif that requested the current scan */
890 	struct iwl_mvm_vif *scan_vif;
891 
892 	/* rx chain antennas set through debugfs for the scan command */
893 	u8 scan_rx_ant;
894 
895 	/* Internal station */
896 	struct iwl_mvm_int_sta aux_sta;
897 	struct iwl_mvm_int_sta snif_sta;
898 
899 	bool last_ebs_successful;
900 
901 	u8 scan_last_antenna_idx; /* to toggle TX between antennas */
902 	u8 mgmt_last_antenna_idx;
903 
904 	/* last smart fifo state that was successfully sent to firmware */
905 	enum iwl_sf_state sf_state;
906 
907 	/*
908 	 * Leave this pointer outside the ifdef below so that it can be
909 	 * assigned without ifdef in the source code.
910 	 */
911 	struct dentry *debugfs_dir;
912 #ifdef CONFIG_IWLWIFI_DEBUGFS
913 	u32 dbgfs_sram_offset, dbgfs_sram_len;
914 	u32 dbgfs_prph_reg_addr;
915 	bool disable_power_off;
916 	bool disable_power_off_d3;
917 	bool beacon_inject_active;
918 
919 	bool scan_iter_notif_enabled;
920 
921 	struct debugfs_blob_wrapper nvm_hw_blob;
922 	struct debugfs_blob_wrapper nvm_sw_blob;
923 	struct debugfs_blob_wrapper nvm_calib_blob;
924 	struct debugfs_blob_wrapper nvm_prod_blob;
925 	struct debugfs_blob_wrapper nvm_phy_sku_blob;
926 	struct debugfs_blob_wrapper nvm_reg_blob;
927 
928 	struct iwl_mvm_frame_stats drv_rx_stats;
929 	spinlock_t drv_stats_lock;
930 	u16 dbgfs_rx_phyinfo;
931 #endif
932 
933 	struct iwl_mvm_phy_ctxt phy_ctxts[NUM_PHY_CTX];
934 
935 	struct list_head time_event_list;
936 	spinlock_t time_event_lock;
937 
938 	/*
939 	 * A bitmap indicating the index of the key in use. The firmware
940 	 * can hold 16 keys at most. Reflect this fact.
941 	 */
942 	unsigned long fw_key_table[BITS_TO_LONGS(STA_KEY_MAX_NUM)];
943 	u8 fw_key_deleted[STA_KEY_MAX_NUM];
944 
945 	u8 vif_count;
946 	struct ieee80211_vif __rcu *vif_id_to_mac[NUM_MAC_INDEX_DRIVER];
947 
948 	/* -1 for always, 0 for never, >0 for that many times */
949 	s8 fw_restart;
950 	u8 *error_recovery_buf;
951 
952 #ifdef CONFIG_IWLWIFI_LEDS
953 	struct led_classdev led;
954 #endif
955 
956 	struct ieee80211_vif *p2p_device_vif;
957 
958 #ifdef CONFIG_PM
959 	struct wiphy_wowlan_support wowlan;
960 	int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
961 
962 	/* sched scan settings for net detect */
963 	struct ieee80211_scan_ies nd_ies;
964 	struct cfg80211_match_set *nd_match_sets;
965 	int n_nd_match_sets;
966 	struct ieee80211_channel **nd_channels;
967 	int n_nd_channels;
968 	bool net_detect;
969 	u8 offload_tid;
970 #ifdef CONFIG_IWLWIFI_DEBUGFS
971 	bool d3_wake_sysassert;
972 	bool d3_test_active;
973 	u32 d3_test_pme_ptr;
974 	struct ieee80211_vif *keep_vif;
975 	u32 last_netdetect_scans; /* no. of scans in the last net-detect wake */
976 #endif
977 #endif
978 
979 	wait_queue_head_t rx_sync_waitq;
980 
981 	/* BT-Coex */
982 	struct iwl_bt_coex_profile_notif last_bt_notif;
983 	struct iwl_bt_coex_ci_cmd last_bt_ci_cmd;
984 
985 	u8 bt_tx_prio;
986 	enum iwl_bt_force_ant_mode bt_force_ant_mode;
987 
988 	/* Aux ROC */
989 	struct list_head aux_roc_te_list;
990 
991 	/* Thermal Throttling and CTkill */
992 	struct iwl_mvm_tt_mgmt thermal_throttle;
993 #ifdef CONFIG_THERMAL
994 	struct iwl_mvm_thermal_device tz_device;
995 	struct iwl_mvm_cooling_device cooling_dev;
996 #endif
997 
998 	s32 temperature;	/* Celsius */
999 	/*
1000 	 * Debug option to set the NIC temperature. This option makes the
1001 	 * driver think this is the actual NIC temperature, and ignore the
1002 	 * real temperature that is received from the fw
1003 	 */
1004 	bool temperature_test;  /* Debug test temperature is enabled */
1005 
1006 	bool fw_static_smps_request;
1007 
1008 	unsigned long bt_coex_last_tcm_ts;
1009 	struct iwl_mvm_tcm tcm;
1010 
1011 	u8 uapsd_noagg_bssid_write_idx;
1012 	struct mac_address uapsd_noagg_bssids[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM]
1013 		__aligned(2);
1014 
1015 	struct iwl_time_quota_cmd last_quota_cmd;
1016 
1017 #ifdef CONFIG_NL80211_TESTMODE
1018 	u32 noa_duration;
1019 	struct ieee80211_vif *noa_vif;
1020 #endif
1021 
1022 	/* Tx queues */
1023 	u16 aux_queue;
1024 	u16 snif_queue;
1025 	u16 probe_queue;
1026 	u16 p2p_dev_queue;
1027 
1028 	/* Indicate if device power save is allowed */
1029 	u8 ps_disabled; /* u8 instead of bool to ease debugfs_create_* usage */
1030 	/* Indicate if 32Khz external clock is valid */
1031 	u32 ext_clock_valid;
1032 
1033 	/* This vif used by CSME to send / receive traffic */
1034 	struct ieee80211_vif *csme_vif;
1035 	struct ieee80211_vif __rcu *csa_vif;
1036 	struct ieee80211_vif __rcu *csa_tx_blocked_vif;
1037 	u8 csa_tx_block_bcn_timeout;
1038 
1039 	/* system time of last beacon (for AP/GO interface) */
1040 	u32 ap_last_beacon_gp2;
1041 
1042 	/* indicates that we transmitted the last beacon */
1043 	bool ibss_manager;
1044 
1045 	bool lar_regdom_set;
1046 	enum iwl_mcc_source mcc_src;
1047 
1048 	/* TDLS channel switch data */
1049 	struct {
1050 		struct delayed_work dwork;
1051 		enum iwl_mvm_tdls_cs_state state;
1052 
1053 		/*
1054 		 * Current cs sta - might be different from periodic cs peer
1055 		 * station. Value is meaningless when the cs-state is idle.
1056 		 */
1057 		u8 cur_sta_id;
1058 
1059 		/* TDLS periodic channel-switch peer */
1060 		struct {
1061 			u8 sta_id;
1062 			u8 op_class;
1063 			bool initiator; /* are we the link initiator */
1064 			struct cfg80211_chan_def chandef;
1065 			struct sk_buff *skb; /* ch sw template */
1066 			u32 ch_sw_tm_ie;
1067 
1068 			/* timestamp of last ch-sw request sent (GP2 time) */
1069 			u32 sent_timestamp;
1070 		} peer;
1071 	} tdls_cs;
1072 
1073 
1074 	u32 ciphers[IWL_MVM_NUM_CIPHERS];
1075 
1076 	struct cfg80211_ftm_responder_stats ftm_resp_stats;
1077 	struct {
1078 		struct cfg80211_pmsr_request *req;
1079 		struct wireless_dev *req_wdev;
1080 		struct list_head loc_list;
1081 		int responses[IWL_MVM_TOF_MAX_APS];
1082 		struct {
1083 			struct list_head resp;
1084 		} smooth;
1085 		struct list_head pasn_list;
1086 	} ftm_initiator;
1087 
1088 	struct list_head resp_pasn_list;
1089 
1090 	struct {
1091 		u8 d0i3_resp;
1092 		u8 range_resp;
1093 	} cmd_ver;
1094 
1095 	struct ieee80211_vif *nan_vif;
1096 	struct iwl_mvm_baid_data __rcu *baid_map[IWL_MAX_BAID];
1097 
1098 	/*
1099 	 * Drop beacons from other APs in AP mode when there are no connected
1100 	 * clients.
1101 	 */
1102 	bool drop_bcn_ap_mode;
1103 
1104 	struct delayed_work cs_tx_unblock_dwork;
1105 
1106 	/* does a monitor vif exist (only one can exist hence bool) */
1107 	bool monitor_on;
1108 
1109 	/* sniffer data to include in radiotap */
1110 	__le16 cur_aid;
1111 	u8 cur_bssid[ETH_ALEN];
1112 
1113 	unsigned long last_6ghz_passive_scan_jiffies;
1114 	unsigned long last_reset_or_resume_time_jiffies;
1115 
1116 	bool sta_remove_requires_queue_remove;
1117 };
1118 
1119 /* Extract MVM priv from op_mode and _hw */
1120 #define IWL_OP_MODE_GET_MVM(_iwl_op_mode)		\
1121 	((struct iwl_mvm *)(_iwl_op_mode)->op_mode_specific)
1122 
1123 #define IWL_MAC80211_GET_MVM(_hw)			\
1124 	IWL_OP_MODE_GET_MVM((struct iwl_op_mode *)((_hw)->priv))
1125 
1126 /**
1127  * enum iwl_mvm_status - MVM status bits
1128  * @IWL_MVM_STATUS_HW_RFKILL: HW RF-kill is asserted
1129  * @IWL_MVM_STATUS_HW_CTKILL: CT-kill is active
1130  * @IWL_MVM_STATUS_ROC_RUNNING: remain-on-channel is running
1131  * @IWL_MVM_STATUS_HW_RESTART_REQUESTED: HW restart was requested
1132  * @IWL_MVM_STATUS_IN_HW_RESTART: HW restart is active
1133  * @IWL_MVM_STATUS_ROC_AUX_RUNNING: AUX remain-on-channel is running
1134  * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running
1135  * @IWL_MVM_STATUS_NEED_FLUSH_P2P: need to flush P2P bcast STA
1136  * @IWL_MVM_STATUS_IN_D3: in D3 (or at least about to go into it)
1137  * @IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE: suppress one error log
1138  *	if this is set, when intentionally triggered
1139  * @IWL_MVM_STATUS_STARTING: starting mac,
1140  *	used to disable restart flow while in STARTING state
1141  */
1142 enum iwl_mvm_status {
1143 	IWL_MVM_STATUS_HW_RFKILL,
1144 	IWL_MVM_STATUS_HW_CTKILL,
1145 	IWL_MVM_STATUS_ROC_RUNNING,
1146 	IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1147 	IWL_MVM_STATUS_IN_HW_RESTART,
1148 	IWL_MVM_STATUS_ROC_AUX_RUNNING,
1149 	IWL_MVM_STATUS_FIRMWARE_RUNNING,
1150 	IWL_MVM_STATUS_NEED_FLUSH_P2P,
1151 	IWL_MVM_STATUS_IN_D3,
1152 	IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,
1153 	IWL_MVM_STATUS_STARTING,
1154 };
1155 
1156 struct iwl_mvm_csme_conn_info {
1157 	struct rcu_head rcu_head;
1158 	struct iwl_mei_conn_info conn_info;
1159 };
1160 
1161 /* Keep track of completed init configuration */
1162 enum iwl_mvm_init_status {
1163 	IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE = BIT(0),
1164 	IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE = BIT(1),
1165 };
1166 
1167 static inline bool iwl_mvm_is_radio_killed(struct iwl_mvm *mvm)
1168 {
1169 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status) ||
1170 	       test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1171 }
1172 
1173 static inline bool iwl_mvm_is_radio_hw_killed(struct iwl_mvm *mvm)
1174 {
1175 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1176 }
1177 
1178 static inline bool iwl_mvm_firmware_running(struct iwl_mvm *mvm)
1179 {
1180 	return test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1181 }
1182 
1183 /* Must be called with rcu_read_lock() held and it can only be
1184  * released when mvmsta is not needed anymore.
1185  */
1186 static inline struct iwl_mvm_sta *
1187 iwl_mvm_sta_from_staid_rcu(struct iwl_mvm *mvm, u8 sta_id)
1188 {
1189 	struct ieee80211_sta *sta;
1190 
1191 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1192 		return NULL;
1193 
1194 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1195 
1196 	/* This can happen if the station has been removed right now */
1197 	if (IS_ERR_OR_NULL(sta))
1198 		return NULL;
1199 
1200 	return iwl_mvm_sta_from_mac80211(sta);
1201 }
1202 
1203 static inline struct iwl_mvm_sta *
1204 iwl_mvm_sta_from_staid_protected(struct iwl_mvm *mvm, u8 sta_id)
1205 {
1206 	struct ieee80211_sta *sta;
1207 
1208 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1209 		return NULL;
1210 
1211 	sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1212 					lockdep_is_held(&mvm->mutex));
1213 
1214 	/* This can happen if the station has been removed right now */
1215 	if (IS_ERR_OR_NULL(sta))
1216 		return NULL;
1217 
1218 	return iwl_mvm_sta_from_mac80211(sta);
1219 }
1220 
1221 static inline struct ieee80211_vif *
1222 iwl_mvm_rcu_dereference_vif_id(struct iwl_mvm *mvm, u8 vif_id, bool rcu)
1223 {
1224 	if (WARN_ON(vif_id >= ARRAY_SIZE(mvm->vif_id_to_mac)))
1225 		return NULL;
1226 
1227 	if (rcu)
1228 		return rcu_dereference(mvm->vif_id_to_mac[vif_id]);
1229 
1230 	return rcu_dereference_protected(mvm->vif_id_to_mac[vif_id],
1231 					 lockdep_is_held(&mvm->mutex));
1232 }
1233 
1234 static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
1235 {
1236 	return fw_has_api(&mvm->fw->ucode_capa,
1237 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL);
1238 }
1239 
1240 static inline bool iwl_mvm_is_adaptive_dwell_v2_supported(struct iwl_mvm *mvm)
1241 {
1242 	return fw_has_api(&mvm->fw->ucode_capa,
1243 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL_V2);
1244 }
1245 
1246 static inline bool iwl_mvm_is_adwell_hb_ap_num_supported(struct iwl_mvm *mvm)
1247 {
1248 	return fw_has_api(&mvm->fw->ucode_capa,
1249 			  IWL_UCODE_TLV_API_ADWELL_HB_DEF_N_AP);
1250 }
1251 
1252 static inline bool iwl_mvm_is_oce_supported(struct iwl_mvm *mvm)
1253 {
1254 	/* OCE should never be enabled for LMAC scan FWs */
1255 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_OCE);
1256 }
1257 
1258 static inline bool iwl_mvm_is_frag_ebs_supported(struct iwl_mvm *mvm)
1259 {
1260 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAG_EBS);
1261 }
1262 
1263 static inline bool iwl_mvm_is_short_beacon_notif_supported(struct iwl_mvm *mvm)
1264 {
1265 	return fw_has_api(&mvm->fw->ucode_capa,
1266 			  IWL_UCODE_TLV_API_SHORT_BEACON_NOTIF);
1267 }
1268 
1269 static inline bool iwl_mvm_is_dqa_data_queue(struct iwl_mvm *mvm, u8 queue)
1270 {
1271 	return (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE) &&
1272 	       (queue <= IWL_MVM_DQA_MAX_DATA_QUEUE);
1273 }
1274 
1275 static inline bool iwl_mvm_is_dqa_mgmt_queue(struct iwl_mvm *mvm, u8 queue)
1276 {
1277 	return (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) &&
1278 	       (queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE);
1279 }
1280 
1281 static inline bool iwl_mvm_is_lar_supported(struct iwl_mvm *mvm)
1282 {
1283 	bool nvm_lar = mvm->nvm_data->lar_enabled;
1284 	bool tlv_lar = fw_has_capa(&mvm->fw->ucode_capa,
1285 				   IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
1286 
1287 	/*
1288 	 * Enable LAR only if it is supported by the FW (TLV) &&
1289 	 * enabled in the NVM
1290 	 */
1291 	if (mvm->cfg->nvm_type == IWL_NVM_EXT)
1292 		return nvm_lar && tlv_lar;
1293 	else
1294 		return tlv_lar;
1295 }
1296 
1297 static inline bool iwl_mvm_is_wifi_mcc_supported(struct iwl_mvm *mvm)
1298 {
1299 	return fw_has_api(&mvm->fw->ucode_capa,
1300 			  IWL_UCODE_TLV_API_WIFI_MCC_UPDATE) ||
1301 	       fw_has_capa(&mvm->fw->ucode_capa,
1302 			   IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC);
1303 }
1304 
1305 static inline bool iwl_mvm_bt_is_rrc_supported(struct iwl_mvm *mvm)
1306 {
1307 	return fw_has_capa(&mvm->fw->ucode_capa,
1308 			   IWL_UCODE_TLV_CAPA_BT_COEX_RRC) &&
1309 		IWL_MVM_BT_COEX_RRC;
1310 }
1311 
1312 static inline bool iwl_mvm_is_csum_supported(struct iwl_mvm *mvm)
1313 {
1314 	return fw_has_capa(&mvm->fw->ucode_capa,
1315 			   IWL_UCODE_TLV_CAPA_CSUM_SUPPORT) &&
1316                !IWL_MVM_HW_CSUM_DISABLE;
1317 }
1318 
1319 static inline bool iwl_mvm_is_mplut_supported(struct iwl_mvm *mvm)
1320 {
1321 	return fw_has_capa(&mvm->fw->ucode_capa,
1322 			   IWL_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT) &&
1323 		IWL_MVM_BT_COEX_MPLUT;
1324 }
1325 
1326 static inline
1327 bool iwl_mvm_is_p2p_scm_uapsd_supported(struct iwl_mvm *mvm)
1328 {
1329 	return fw_has_capa(&mvm->fw->ucode_capa,
1330 			   IWL_UCODE_TLV_CAPA_P2P_SCM_UAPSD) &&
1331 		!(iwlwifi_mod_params.uapsd_disable &
1332 		  IWL_DISABLE_UAPSD_P2P_CLIENT);
1333 }
1334 
1335 static inline bool iwl_mvm_has_new_rx_api(struct iwl_mvm *mvm)
1336 {
1337 	return fw_has_capa(&mvm->fw->ucode_capa,
1338 			   IWL_UCODE_TLV_CAPA_MULTI_QUEUE_RX_SUPPORT);
1339 }
1340 
1341 static inline bool iwl_mvm_has_new_tx_api(struct iwl_mvm *mvm)
1342 {
1343 	/* TODO - replace with TLV once defined */
1344 	return mvm->trans->trans_cfg->use_tfh;
1345 }
1346 
1347 static inline bool iwl_mvm_has_unified_ucode(struct iwl_mvm *mvm)
1348 {
1349 	/* TODO - better define this */
1350 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1351 }
1352 
1353 static inline bool iwl_mvm_is_cdb_supported(struct iwl_mvm *mvm)
1354 {
1355 	/*
1356 	 * TODO:
1357 	 * The issue of how to determine CDB APIs and usage is still not fully
1358 	 * defined.
1359 	 * There is a compilation for CDB and non-CDB FW, but there may
1360 	 * be also runtime check.
1361 	 * For now there is a TLV for checking compilation mode, but a
1362 	 * runtime check will also have to be here - once defined.
1363 	 */
1364 	return fw_has_capa(&mvm->fw->ucode_capa,
1365 			   IWL_UCODE_TLV_CAPA_CDB_SUPPORT);
1366 }
1367 
1368 static inline bool iwl_mvm_cdb_scan_api(struct iwl_mvm *mvm)
1369 {
1370 	/*
1371 	 * TODO: should this be the same as iwl_mvm_is_cdb_supported()?
1372 	 * but then there's a little bit of code in scan that won't make
1373 	 * any sense...
1374 	 */
1375 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1376 }
1377 
1378 static inline bool iwl_mvm_is_scan_ext_chan_supported(struct iwl_mvm *mvm)
1379 {
1380 	return fw_has_api(&mvm->fw->ucode_capa,
1381 			  IWL_UCODE_TLV_API_SCAN_EXT_CHAN_VER);
1382 }
1383 
1384 
1385 static inline bool iwl_mvm_is_reduced_config_scan_supported(struct iwl_mvm *mvm)
1386 {
1387 	return fw_has_api(&mvm->fw->ucode_capa,
1388 			  IWL_UCODE_TLV_API_REDUCED_SCAN_CONFIG);
1389 }
1390 
1391 static inline bool iwl_mvm_is_band_in_rx_supported(struct iwl_mvm *mvm)
1392 {
1393 	return fw_has_api(&mvm->fw->ucode_capa,
1394 			   IWL_UCODE_TLV_API_BAND_IN_RX_DATA);
1395 }
1396 
1397 static inline bool iwl_mvm_has_new_rx_stats_api(struct iwl_mvm *mvm)
1398 {
1399 	return fw_has_api(&mvm->fw->ucode_capa,
1400 			  IWL_UCODE_TLV_API_NEW_RX_STATS);
1401 }
1402 
1403 static inline bool iwl_mvm_has_quota_low_latency(struct iwl_mvm *mvm)
1404 {
1405 	return fw_has_api(&mvm->fw->ucode_capa,
1406 			  IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY);
1407 }
1408 
1409 static inline bool iwl_mvm_has_tlc_offload(const struct iwl_mvm *mvm)
1410 {
1411 	return fw_has_capa(&mvm->fw->ucode_capa,
1412 			   IWL_UCODE_TLV_CAPA_TLC_OFFLOAD);
1413 }
1414 
1415 static inline struct agg_tx_status *
1416 iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp)
1417 {
1418 	if (iwl_mvm_has_new_tx_api(mvm))
1419 		return &((struct iwl_mvm_tx_resp *)tx_resp)->status;
1420 	else
1421 		return ((struct iwl_mvm_tx_resp_v3 *)tx_resp)->status;
1422 }
1423 
1424 static inline bool iwl_mvm_is_tt_in_fw(struct iwl_mvm *mvm)
1425 {
1426 	/* these two TLV are redundant since the responsibility to CT-kill by
1427 	 * FW happens only after we send at least one command of
1428 	 * temperature THs report.
1429 	 */
1430 	return fw_has_capa(&mvm->fw->ucode_capa,
1431 			   IWL_UCODE_TLV_CAPA_CT_KILL_BY_FW) &&
1432 	       fw_has_capa(&mvm->fw->ucode_capa,
1433 			   IWL_UCODE_TLV_CAPA_TEMP_THS_REPORT_SUPPORT);
1434 }
1435 
1436 static inline bool iwl_mvm_is_ctdp_supported(struct iwl_mvm *mvm)
1437 {
1438 	return fw_has_capa(&mvm->fw->ucode_capa,
1439 			   IWL_UCODE_TLV_CAPA_CTDP_SUPPORT);
1440 }
1441 
1442 extern const u8 iwl_mvm_ac_to_tx_fifo[];
1443 extern const u8 iwl_mvm_ac_to_gen2_tx_fifo[];
1444 
1445 static inline u8 iwl_mvm_mac_ac_to_tx_fifo(struct iwl_mvm *mvm,
1446 					   enum ieee80211_ac_numbers ac)
1447 {
1448 	return iwl_mvm_has_new_tx_api(mvm) ?
1449 		iwl_mvm_ac_to_gen2_tx_fifo[ac] : iwl_mvm_ac_to_tx_fifo[ac];
1450 }
1451 
1452 struct iwl_rate_info {
1453 	u8 plcp;	/* uCode API:  IWL_RATE_6M_PLCP, etc. */
1454 	u8 plcp_siso;	/* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
1455 	u8 plcp_mimo2;	/* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
1456 	u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
1457 	u8 ieee;	/* MAC header:  IWL_RATE_6M_IEEE, etc. */
1458 };
1459 
1460 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm);
1461 int __iwl_mvm_mac_start(struct iwl_mvm *mvm);
1462 
1463 /******************
1464  * MVM Methods
1465  ******************/
1466 /* uCode */
1467 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm);
1468 
1469 /* Utils */
1470 int iwl_mvm_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
1471 					  enum nl80211_band band);
1472 int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
1473 					enum nl80211_band band);
1474 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
1475 			       enum nl80211_band band,
1476 			       struct ieee80211_tx_rate *r);
1477 void iwl_mvm_hwrate_to_tx_rate_v1(u32 rate_n_flags,
1478 				  enum nl80211_band band,
1479 				  struct ieee80211_tx_rate *r);
1480 u8 iwl_mvm_mac80211_idx_to_hwrate(const struct iwl_fw *fw, int rate_idx);
1481 u8 iwl_mvm_mac80211_ac_to_ucode_ac(enum ieee80211_ac_numbers ac);
1482 
1483 static inline void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
1484 {
1485 	iwl_fwrt_dump_error_logs(&mvm->fwrt);
1486 }
1487 
1488 u8 first_antenna(u8 mask);
1489 u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx);
1490 void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, int clock_type, u32 *gp2,
1491 			   u64 *boottime, ktime_t *realtime);
1492 u32 iwl_mvm_get_systime(struct iwl_mvm *mvm);
1493 
1494 /* Tx / Host Commands */
1495 int __must_check iwl_mvm_send_cmd(struct iwl_mvm *mvm,
1496 				  struct iwl_host_cmd *cmd);
1497 int __must_check iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
1498 				      u32 flags, u16 len, const void *data);
1499 int __must_check iwl_mvm_send_cmd_status(struct iwl_mvm *mvm,
1500 					 struct iwl_host_cmd *cmd,
1501 					 u32 *status);
1502 int __must_check iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id,
1503 					     u16 len, const void *data,
1504 					     u32 *status);
1505 int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
1506 		       struct ieee80211_sta *sta);
1507 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb);
1508 void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
1509 			struct iwl_tx_cmd *tx_cmd,
1510 			struct ieee80211_tx_info *info, u8 sta_id);
1511 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
1512 			    struct ieee80211_tx_info *info,
1513 			    struct ieee80211_sta *sta, __le16 fc);
1514 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
1515 unsigned int iwl_mvm_max_amsdu_size(struct iwl_mvm *mvm,
1516 				    struct ieee80211_sta *sta,
1517 				    unsigned int tid);
1518 u32 iwl_mvm_tx_csum_bz(struct iwl_mvm *mvm, struct sk_buff *skb, bool amsdu);
1519 
1520 #ifdef CONFIG_IWLWIFI_DEBUG
1521 const char *iwl_mvm_get_tx_fail_reason(u32 status);
1522 #else
1523 static inline const char *iwl_mvm_get_tx_fail_reason(u32 status) { return ""; }
1524 #endif
1525 int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk);
1526 int iwl_mvm_flush_sta(struct iwl_mvm *mvm, void *sta, bool internal);
1527 int iwl_mvm_flush_sta_tids(struct iwl_mvm *mvm, u32 sta_id, u16 tids);
1528 
1529 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm);
1530 
1531 static inline void iwl_mvm_set_tx_cmd_ccmp(struct ieee80211_tx_info *info,
1532 					   struct iwl_tx_cmd *tx_cmd)
1533 {
1534 	struct ieee80211_key_conf *keyconf = info->control.hw_key;
1535 
1536 	tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
1537 	memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
1538 }
1539 
1540 static inline void iwl_mvm_wait_for_async_handlers(struct iwl_mvm *mvm)
1541 {
1542 	flush_work(&mvm->async_handlers_wk);
1543 }
1544 
1545 /* Statistics */
1546 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1547 				  struct iwl_rx_packet *pkt);
1548 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
1549 			   struct iwl_rx_cmd_buffer *rxb);
1550 int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear);
1551 void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm);
1552 
1553 /* NVM */
1554 int iwl_nvm_init(struct iwl_mvm *mvm);
1555 int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm);
1556 
1557 static inline u8 iwl_mvm_get_valid_tx_ant(struct iwl_mvm *mvm)
1558 {
1559 	return mvm->nvm_data && mvm->nvm_data->valid_tx_ant ?
1560 	       mvm->fw->valid_tx_ant & mvm->nvm_data->valid_tx_ant :
1561 	       mvm->fw->valid_tx_ant;
1562 }
1563 
1564 static inline u8 iwl_mvm_get_valid_rx_ant(struct iwl_mvm *mvm)
1565 {
1566 	return mvm->nvm_data && mvm->nvm_data->valid_rx_ant ?
1567 	       mvm->fw->valid_rx_ant & mvm->nvm_data->valid_rx_ant :
1568 	       mvm->fw->valid_rx_ant;
1569 }
1570 
1571 static inline void iwl_mvm_toggle_tx_ant(struct iwl_mvm *mvm, u8 *ant)
1572 {
1573 	*ant = iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), *ant);
1574 }
1575 
1576 static inline u32 iwl_mvm_get_phy_config(struct iwl_mvm *mvm)
1577 {
1578 	u32 phy_config = ~(FW_PHY_CFG_TX_CHAIN |
1579 			   FW_PHY_CFG_RX_CHAIN);
1580 	u32 valid_rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
1581 	u32 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
1582 
1583 	phy_config |= valid_tx_ant << FW_PHY_CFG_TX_CHAIN_POS |
1584 		      valid_rx_ant << FW_PHY_CFG_RX_CHAIN_POS;
1585 
1586 	return mvm->fw->phy_config & phy_config;
1587 }
1588 
1589 int iwl_mvm_up(struct iwl_mvm *mvm);
1590 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm);
1591 
1592 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm);
1593 
1594 /*
1595  * FW notifications / CMD responses handlers
1596  * Convention: iwl_mvm_rx_<NAME OF THE CMD>
1597  */
1598 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1599 		   struct napi_struct *napi,
1600 		   struct iwl_rx_cmd_buffer *rxb);
1601 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1602 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1603 			struct iwl_rx_cmd_buffer *rxb);
1604 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1605 			struct iwl_rx_cmd_buffer *rxb, int queue);
1606 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1607 				struct iwl_rx_cmd_buffer *rxb, int queue);
1608 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1609 			      struct iwl_rx_cmd_buffer *rxb, int queue);
1610 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1611 				  struct iwl_rx_cmd_buffer *rxb, int queue);
1612 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
1613 			    struct iwl_rx_cmd_buffer *rxb, int queue);
1614 void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1615 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
1616 				   struct iwl_rx_cmd_buffer *rxb);
1617 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags);
1618 void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1619 void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1620 				   struct iwl_rx_cmd_buffer *rxb);
1621 void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1622 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1623 			     struct iwl_rx_cmd_buffer *rxb);
1624 void iwl_mvm_rx_shared_mem_cfg_notif(struct iwl_mvm *mvm,
1625 				     struct iwl_rx_cmd_buffer *rxb);
1626 
1627 /* MVM PHY */
1628 int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1629 			 struct cfg80211_chan_def *chandef,
1630 			 u8 chains_static, u8 chains_dynamic);
1631 int iwl_mvm_phy_ctxt_changed(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1632 			     struct cfg80211_chan_def *chandef,
1633 			     u8 chains_static, u8 chains_dynamic);
1634 void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm,
1635 			  struct iwl_mvm_phy_ctxt *ctxt);
1636 void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm,
1637 			    struct iwl_mvm_phy_ctxt *ctxt);
1638 int iwl_mvm_phy_ctx_count(struct iwl_mvm *mvm);
1639 u8 iwl_mvm_get_channel_width(struct cfg80211_chan_def *chandef);
1640 u8 iwl_mvm_get_ctrl_pos(struct cfg80211_chan_def *chandef);
1641 
1642 /* MAC (virtual interface) programming */
1643 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1644 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1645 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1646 			     bool force_assoc_off, const u8 *bssid_override);
1647 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1648 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1649 				    struct ieee80211_vif *vif);
1650 int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1651 				 struct ieee80211_vif *vif,
1652 				 struct sk_buff *beacon);
1653 int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
1654 				     struct sk_buff *beacon,
1655 				     void *data, int len);
1656 u8 iwl_mvm_mac_ctxt_get_lowest_rate(struct ieee80211_tx_info *info,
1657 				    struct ieee80211_vif *vif);
1658 u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw,
1659 				      u8 rate_idx);
1660 void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
1661 			      __le32 *tim_index, __le32 *tim_size,
1662 			      u8 *beacon, u32 frame_size);
1663 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1664 			     struct iwl_rx_cmd_buffer *rxb);
1665 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1666 				     struct iwl_rx_cmd_buffer *rxb);
1667 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1668 				    struct iwl_rx_cmd_buffer *rxb);
1669 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1670 			       struct iwl_rx_cmd_buffer *rxb);
1671 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1672 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1673 				 struct iwl_rx_cmd_buffer *rxb);
1674 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
1675 				    struct ieee80211_vif *vif);
1676 void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1677 				   struct iwl_rx_cmd_buffer *rxb);
1678 void iwl_mvm_rx_missed_vap_notif(struct iwl_mvm *mvm,
1679 				 struct iwl_rx_cmd_buffer *rxb);
1680 void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
1681 					struct iwl_rx_cmd_buffer *rxb);
1682 void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
1683 					struct iwl_rx_cmd_buffer *rxb);
1684 /* Bindings */
1685 int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1686 int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1687 
1688 /* Quota management */
1689 static inline size_t iwl_mvm_quota_cmd_size(struct iwl_mvm *mvm)
1690 {
1691 	return iwl_mvm_has_quota_low_latency(mvm) ?
1692 		sizeof(struct iwl_time_quota_cmd) :
1693 		sizeof(struct iwl_time_quota_cmd_v1);
1694 }
1695 
1696 static inline struct iwl_time_quota_data
1697 *iwl_mvm_quota_cmd_get_quota(struct iwl_mvm *mvm,
1698 			     struct iwl_time_quota_cmd *cmd,
1699 			     int i)
1700 {
1701 	struct iwl_time_quota_data_v1 *quotas;
1702 
1703 	if (iwl_mvm_has_quota_low_latency(mvm))
1704 		return &cmd->quotas[i];
1705 
1706 	quotas = (struct iwl_time_quota_data_v1 *)cmd->quotas;
1707 	return (struct iwl_time_quota_data *)&quotas[i];
1708 }
1709 
1710 int iwl_mvm_update_quotas(struct iwl_mvm *mvm, bool force_upload,
1711 			  struct ieee80211_vif *disabled_vif);
1712 
1713 /* Scanning */
1714 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1715 			   struct cfg80211_scan_request *req,
1716 			   struct ieee80211_scan_ies *ies);
1717 int iwl_mvm_scan_size(struct iwl_mvm *mvm);
1718 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify);
1719 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm);
1720 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm);
1721 void iwl_mvm_scan_timeout_wk(struct work_struct *work);
1722 
1723 /* Scheduled scan */
1724 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
1725 					 struct iwl_rx_cmd_buffer *rxb);
1726 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1727 					      struct iwl_rx_cmd_buffer *rxb);
1728 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1729 			     struct ieee80211_vif *vif,
1730 			     struct cfg80211_sched_scan_request *req,
1731 			     struct ieee80211_scan_ies *ies,
1732 			     int type);
1733 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
1734 				 struct iwl_rx_cmd_buffer *rxb);
1735 
1736 /* UMAC scan */
1737 int iwl_mvm_config_scan(struct iwl_mvm *mvm);
1738 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1739 					 struct iwl_rx_cmd_buffer *rxb);
1740 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1741 					      struct iwl_rx_cmd_buffer *rxb);
1742 
1743 /* MVM debugfs */
1744 #ifdef CONFIG_IWLWIFI_DEBUGFS
1745 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm);
1746 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1747 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1748 #else
1749 static inline void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
1750 {
1751 }
1752 static inline void
1753 iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1754 {
1755 }
1756 static inline void
1757 iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1758 {
1759 }
1760 #endif /* CONFIG_IWLWIFI_DEBUGFS */
1761 
1762 /* rate scaling */
1763 int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq);
1764 void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg);
1765 int rs_pretty_print_rate_v1(char *buf, int bufsz, const u32 rate);
1766 void rs_update_last_rssi(struct iwl_mvm *mvm,
1767 			 struct iwl_mvm_sta *mvmsta,
1768 			 struct ieee80211_rx_status *rx_status);
1769 
1770 /* power management */
1771 int iwl_mvm_power_update_device(struct iwl_mvm *mvm);
1772 int iwl_mvm_power_update_mac(struct iwl_mvm *mvm);
1773 int iwl_mvm_power_update_ps(struct iwl_mvm *mvm);
1774 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1775 				 char *buf, int bufsz);
1776 
1777 void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1778 void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
1779 					      struct iwl_rx_cmd_buffer *rxb);
1780 
1781 #ifdef CONFIG_IWLWIFI_LEDS
1782 int iwl_mvm_leds_init(struct iwl_mvm *mvm);
1783 void iwl_mvm_leds_exit(struct iwl_mvm *mvm);
1784 void iwl_mvm_leds_sync(struct iwl_mvm *mvm);
1785 #else
1786 static inline int iwl_mvm_leds_init(struct iwl_mvm *mvm)
1787 {
1788 	return 0;
1789 }
1790 static inline void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
1791 {
1792 }
1793 static inline void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
1794 {
1795 }
1796 #endif
1797 
1798 /* D3 (WoWLAN, NetDetect) */
1799 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
1800 int iwl_mvm_resume(struct ieee80211_hw *hw);
1801 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled);
1802 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
1803 			    struct ieee80211_vif *vif,
1804 			    struct cfg80211_gtk_rekey_data *data);
1805 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
1806 			      struct ieee80211_vif *vif,
1807 			      struct inet6_dev *idev);
1808 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
1809 				     struct ieee80211_vif *vif, int idx);
1810 extern const struct file_operations iwl_dbgfs_d3_test_ops;
1811 #ifdef CONFIG_PM
1812 void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm,
1813 				 struct ieee80211_vif *vif);
1814 #else
1815 static inline void
1816 iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1817 {
1818 }
1819 #endif
1820 void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
1821 				struct iwl_wowlan_config_cmd *cmd);
1822 int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
1823 			       struct ieee80211_vif *vif,
1824 			       bool disable_offloading,
1825 			       bool offload_ns,
1826 			       u32 cmd_flags);
1827 
1828 /* BT Coex */
1829 int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm);
1830 void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
1831 			      struct iwl_rx_cmd_buffer *rxb);
1832 void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1833 			   enum ieee80211_rssi_event_data);
1834 void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm);
1835 u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
1836 				struct ieee80211_sta *sta);
1837 bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
1838 				     struct ieee80211_sta *sta);
1839 bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant);
1840 bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm);
1841 bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
1842 				    enum nl80211_band band);
1843 u8 iwl_mvm_bt_coex_get_single_ant_msk(struct iwl_mvm *mvm, u8 enabled_ants);
1844 u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
1845 			   struct ieee80211_tx_info *info, u8 ac);
1846 
1847 /* beacon filtering */
1848 #ifdef CONFIG_IWLWIFI_DEBUGFS
1849 void
1850 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1851 					 struct iwl_beacon_filter_cmd *cmd);
1852 #else
1853 static inline void
1854 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1855 					 struct iwl_beacon_filter_cmd *cmd)
1856 {}
1857 #endif
1858 int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
1859 				 struct ieee80211_vif *vif,
1860 				 u32 flags);
1861 int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
1862 				  struct ieee80211_vif *vif,
1863 				  u32 flags);
1864 /* SMPS */
1865 void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1866 				enum iwl_mvm_smps_type_request req_type,
1867 				enum ieee80211_smps_mode smps_request);
1868 bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm,
1869 				  struct iwl_mvm_phy_ctxt *ctxt);
1870 void iwl_mvm_apply_fw_smps_request(struct ieee80211_vif *vif);
1871 
1872 /* Low latency */
1873 int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1874 			      bool low_latency,
1875 			      enum iwl_mvm_low_latency_cause cause);
1876 /* get SystemLowLatencyMode - only needed for beacon threshold? */
1877 bool iwl_mvm_low_latency(struct iwl_mvm *mvm);
1878 bool iwl_mvm_low_latency_band(struct iwl_mvm *mvm, enum nl80211_band band);
1879 void iwl_mvm_send_low_latency_cmd(struct iwl_mvm *mvm, bool low_latency,
1880 				  u16 mac_id);
1881 
1882 /* get VMACLowLatencyMode */
1883 static inline bool iwl_mvm_vif_low_latency(struct iwl_mvm_vif *mvmvif)
1884 {
1885 	/*
1886 	 * should this consider associated/active/... state?
1887 	 *
1888 	 * Normally low-latency should only be active on interfaces
1889 	 * that are active, but at least with debugfs it can also be
1890 	 * enabled on interfaces that aren't active. However, when
1891 	 * interface aren't active then they aren't added into the
1892 	 * binding, so this has no real impact. For now, just return
1893 	 * the current desired low-latency state.
1894 	 */
1895 	return mvmvif->low_latency_actual;
1896 }
1897 
1898 static inline
1899 void iwl_mvm_vif_set_low_latency(struct iwl_mvm_vif *mvmvif, bool set,
1900 				 enum iwl_mvm_low_latency_cause cause)
1901 {
1902 	u8 new_state;
1903 
1904 	if (set)
1905 		mvmvif->low_latency |= cause;
1906 	else
1907 		mvmvif->low_latency &= ~cause;
1908 
1909 	/*
1910 	 * if LOW_LATENCY_DEBUGFS_FORCE_ENABLE is enabled no changes are
1911 	 * allowed to actual mode.
1912 	 */
1913 	if (mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE_ENABLE &&
1914 	    cause != LOW_LATENCY_DEBUGFS_FORCE_ENABLE)
1915 		return;
1916 
1917 	if (cause == LOW_LATENCY_DEBUGFS_FORCE_ENABLE && set)
1918 		/*
1919 		 * We enter force state
1920 		 */
1921 		new_state = !!(mvmvif->low_latency &
1922 			       LOW_LATENCY_DEBUGFS_FORCE);
1923 	else
1924 		/*
1925 		 * Check if any other one set low latency
1926 		 */
1927 		new_state = !!(mvmvif->low_latency &
1928 				  ~(LOW_LATENCY_DEBUGFS_FORCE_ENABLE |
1929 				    LOW_LATENCY_DEBUGFS_FORCE));
1930 
1931 	mvmvif->low_latency_actual = new_state;
1932 }
1933 
1934 /* Return a bitmask with all the hw supported queues, except for the
1935  * command queue, which can't be flushed.
1936  */
1937 static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
1938 {
1939 	return ((BIT(mvm->trans->trans_cfg->base_params->num_of_queues) - 1) &
1940 		~BIT(IWL_MVM_DQA_CMD_QUEUE));
1941 }
1942 
1943 void iwl_mvm_stop_device(struct iwl_mvm *mvm);
1944 
1945 /* Thermal management and CT-kill */
1946 void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff);
1947 void iwl_mvm_temp_notif(struct iwl_mvm *mvm,
1948 			struct iwl_rx_cmd_buffer *rxb);
1949 void iwl_mvm_tt_handler(struct iwl_mvm *mvm);
1950 void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff);
1951 void iwl_mvm_thermal_exit(struct iwl_mvm *mvm);
1952 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state);
1953 int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp);
1954 void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1955 void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);
1956 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm);
1957 int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget);
1958 
1959 #if IS_ENABLED(CONFIG_IWLMEI)
1960 
1961 /* vendor commands */
1962 void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
1963 
1964 #else
1965 
1966 static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
1967 
1968 #endif
1969 
1970 /* Location Aware Regulatory */
1971 struct iwl_mcc_update_resp *
1972 iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
1973 		   enum iwl_mcc_source src_id);
1974 int iwl_mvm_init_mcc(struct iwl_mvm *mvm);
1975 void iwl_mvm_rx_chub_update_mcc(struct iwl_mvm *mvm,
1976 				struct iwl_rx_cmd_buffer *rxb);
1977 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
1978 						  const char *alpha2,
1979 						  enum iwl_mcc_source src_id,
1980 						  bool *changed);
1981 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
1982 							  bool *changed);
1983 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm);
1984 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm);
1985 
1986 /* smart fifo */
1987 int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1988 		      bool added_vif);
1989 
1990 /* FTM responder */
1991 int iwl_mvm_ftm_start_responder(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1992 void iwl_mvm_ftm_restart_responder(struct iwl_mvm *mvm,
1993 				   struct ieee80211_vif *vif);
1994 void iwl_mvm_ftm_responder_stats(struct iwl_mvm *mvm,
1995 				 struct iwl_rx_cmd_buffer *rxb);
1996 int iwl_mvm_ftm_resp_remove_pasn_sta(struct iwl_mvm *mvm,
1997 				     struct ieee80211_vif *vif, u8 *addr);
1998 int iwl_mvm_ftm_respoder_add_pasn_sta(struct iwl_mvm *mvm,
1999 				      struct ieee80211_vif *vif,
2000 				      u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2001 				      u8 *hltk, u32 hltk_len);
2002 void iwl_mvm_ftm_responder_clear(struct iwl_mvm *mvm,
2003 				 struct ieee80211_vif *vif);
2004 
2005 /* FTM initiator */
2006 void iwl_mvm_ftm_restart(struct iwl_mvm *mvm);
2007 void iwl_mvm_ftm_range_resp(struct iwl_mvm *mvm,
2008 			    struct iwl_rx_cmd_buffer *rxb);
2009 void iwl_mvm_ftm_lc_notif(struct iwl_mvm *mvm,
2010 			  struct iwl_rx_cmd_buffer *rxb);
2011 int iwl_mvm_ftm_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2012 		      struct cfg80211_pmsr_request *request);
2013 void iwl_mvm_ftm_abort(struct iwl_mvm *mvm, struct cfg80211_pmsr_request *req);
2014 void iwl_mvm_ftm_initiator_smooth_config(struct iwl_mvm *mvm);
2015 void iwl_mvm_ftm_initiator_smooth_stop(struct iwl_mvm *mvm);
2016 int iwl_mvm_ftm_add_pasn_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2017 			     u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2018 			     u8 *hltk, u32 hltk_len);
2019 void iwl_mvm_ftm_remove_pasn_sta(struct iwl_mvm *mvm, u8 *addr);
2020 
2021 /* TDLS */
2022 
2023 /*
2024  * We use TID 4 (VI) as a FW-used-only TID when TDLS connections are present.
2025  * This TID is marked as used vs the AP and all connected TDLS peers.
2026  */
2027 #define IWL_MVM_TDLS_FW_TID 4
2028 
2029 int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2030 void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm);
2031 void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2032 			       bool sta_added);
2033 void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2034 					   struct ieee80211_vif *vif);
2035 int iwl_mvm_tdls_channel_switch(struct ieee80211_hw *hw,
2036 				struct ieee80211_vif *vif,
2037 				struct ieee80211_sta *sta, u8 oper_class,
2038 				struct cfg80211_chan_def *chandef,
2039 				struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie);
2040 void iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw *hw,
2041 				      struct ieee80211_vif *vif,
2042 				      struct ieee80211_tdls_ch_sw_params *params);
2043 void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw *hw,
2044 					struct ieee80211_vif *vif,
2045 					struct ieee80211_sta *sta);
2046 void iwl_mvm_rx_tdls_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2047 void iwl_mvm_tdls_ch_switch_work(struct work_struct *work);
2048 
2049 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
2050 				     enum iwl_mvm_rxq_notif_type type,
2051 				     bool sync,
2052 				     const void *data, u32 size);
2053 void iwl_mvm_reorder_timer_expired(struct timer_list *t);
2054 struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
2055 struct ieee80211_vif *iwl_mvm_get_vif_by_macid(struct iwl_mvm *mvm, u32 macid);
2056 bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm);
2057 
2058 #define MVM_TCM_PERIOD_MSEC 500
2059 #define MVM_TCM_PERIOD (HZ * MVM_TCM_PERIOD_MSEC / 1000)
2060 #define MVM_LL_PERIOD (10 * HZ)
2061 void iwl_mvm_tcm_work(struct work_struct *work);
2062 void iwl_mvm_recalc_tcm(struct iwl_mvm *mvm);
2063 void iwl_mvm_pause_tcm(struct iwl_mvm *mvm, bool with_cancel);
2064 void iwl_mvm_resume_tcm(struct iwl_mvm *mvm);
2065 void iwl_mvm_tcm_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2066 void iwl_mvm_tcm_rm_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2067 u8 iwl_mvm_tcm_load_percentage(u32 airtime, u32 elapsed);
2068 
2069 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error);
2070 unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
2071 				    struct ieee80211_vif *vif,
2072 				    bool tdls, bool cmd_q);
2073 void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2074 			     const char *errmsg);
2075 void iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
2076 					  struct ieee80211_vif *vif,
2077 					  const struct ieee80211_sta *sta,
2078 					  u16 tid);
2079 
2080 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b);
2081 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm);
2082 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm);
2083 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm);
2084 #ifdef CONFIG_IWLWIFI_DEBUGFS
2085 void iwl_mvm_sta_add_debugfs(struct ieee80211_hw *hw,
2086 			     struct ieee80211_vif *vif,
2087 			     struct ieee80211_sta *sta,
2088 			     struct dentry *dir);
2089 #endif
2090 
2091 int iwl_rfi_send_config_cmd(struct iwl_mvm *mvm,
2092 			    struct iwl_rfi_lut_entry *rfi_table);
2093 struct iwl_rfi_freq_table_resp_cmd *iwl_rfi_get_freq_table(struct iwl_mvm *mvm);
2094 void iwl_rfi_deactivate_notif_handler(struct iwl_mvm *mvm,
2095 				      struct iwl_rx_cmd_buffer *rxb);
2096 
2097 static inline u8 iwl_mvm_phy_band_from_nl80211(enum nl80211_band band)
2098 {
2099 	switch (band) {
2100 	case NL80211_BAND_2GHZ:
2101 		return PHY_BAND_24;
2102 	case NL80211_BAND_5GHZ:
2103 		return PHY_BAND_5;
2104 	case NL80211_BAND_6GHZ:
2105 		return PHY_BAND_6;
2106 	default:
2107 		WARN_ONCE(1, "Unsupported band (%u)\n", band);
2108 		return PHY_BAND_5;
2109 	}
2110 }
2111 
2112 /* Channel info utils */
2113 static inline bool iwl_mvm_has_ultra_hb_channel(struct iwl_mvm *mvm)
2114 {
2115 	return fw_has_capa(&mvm->fw->ucode_capa,
2116 			   IWL_UCODE_TLV_CAPA_ULTRA_HB_CHANNELS);
2117 }
2118 
2119 static inline void *iwl_mvm_chan_info_cmd_tail(struct iwl_mvm *mvm,
2120 					       struct iwl_fw_channel_info *ci)
2121 {
2122 	return (u8 *)ci + (iwl_mvm_has_ultra_hb_channel(mvm) ?
2123 			   sizeof(struct iwl_fw_channel_info) :
2124 			   sizeof(struct iwl_fw_channel_info_v1));
2125 }
2126 
2127 static inline size_t iwl_mvm_chan_info_padding(struct iwl_mvm *mvm)
2128 {
2129 	return iwl_mvm_has_ultra_hb_channel(mvm) ? 0 :
2130 		sizeof(struct iwl_fw_channel_info) -
2131 		sizeof(struct iwl_fw_channel_info_v1);
2132 }
2133 
2134 static inline void iwl_mvm_set_chan_info(struct iwl_mvm *mvm,
2135 					 struct iwl_fw_channel_info *ci,
2136 					 u32 chan, u8 band, u8 width,
2137 					 u8 ctrl_pos)
2138 {
2139 	if (iwl_mvm_has_ultra_hb_channel(mvm)) {
2140 		ci->channel = cpu_to_le32(chan);
2141 		ci->band = band;
2142 		ci->width = width;
2143 		ci->ctrl_pos = ctrl_pos;
2144 	} else {
2145 		struct iwl_fw_channel_info_v1 *ci_v1 =
2146 					(struct iwl_fw_channel_info_v1 *)ci;
2147 
2148 		ci_v1->channel = chan;
2149 		ci_v1->band = band;
2150 		ci_v1->width = width;
2151 		ci_v1->ctrl_pos = ctrl_pos;
2152 	}
2153 }
2154 
2155 static inline void
2156 iwl_mvm_set_chan_info_chandef(struct iwl_mvm *mvm,
2157 			      struct iwl_fw_channel_info *ci,
2158 			      struct cfg80211_chan_def *chandef)
2159 {
2160 	enum nl80211_band band = chandef->chan->band;
2161 
2162 	iwl_mvm_set_chan_info(mvm, ci, chandef->chan->hw_value,
2163 			      iwl_mvm_phy_band_from_nl80211(band),
2164 			      iwl_mvm_get_channel_width(chandef),
2165 			      iwl_mvm_get_ctrl_pos(chandef));
2166 }
2167 
2168 static inline int iwl_umac_scan_get_max_profiles(const struct iwl_fw *fw)
2169 {
2170 	u8 ver = iwl_fw_lookup_cmd_ver(fw, SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
2171 				       IWL_FW_CMD_VER_UNKNOWN);
2172 	return (ver == IWL_FW_CMD_VER_UNKNOWN || ver < 3) ?
2173 		IWL_SCAN_MAX_PROFILES : IWL_SCAN_MAX_PROFILES_V2;
2174 }
2175 
2176 static inline
2177 enum iwl_location_cipher iwl_mvm_cipher_to_location_cipher(u32 cipher)
2178 {
2179 	switch (cipher) {
2180 	case WLAN_CIPHER_SUITE_CCMP:
2181 		return IWL_LOCATION_CIPHER_CCMP_128;
2182 	case WLAN_CIPHER_SUITE_GCMP:
2183 		return IWL_LOCATION_CIPHER_GCMP_128;
2184 	case WLAN_CIPHER_SUITE_GCMP_256:
2185 		return IWL_LOCATION_CIPHER_GCMP_256;
2186 	default:
2187 		return IWL_LOCATION_CIPHER_INVALID;
2188 	}
2189 }
2190 
2191 struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm);
2192 static inline int iwl_mvm_mei_get_ownership(struct iwl_mvm *mvm)
2193 {
2194 	if (mvm->mei_registered)
2195 		return iwl_mei_get_ownership();
2196 	return 0;
2197 }
2198 
2199 static inline void iwl_mvm_mei_tx_copy_to_csme(struct iwl_mvm *mvm,
2200 					       struct sk_buff *skb,
2201 					       unsigned int ivlen)
2202 {
2203 	if (mvm->mei_registered)
2204 		iwl_mei_tx_copy_to_csme(skb, ivlen);
2205 }
2206 
2207 static inline void iwl_mvm_mei_host_disassociated(struct iwl_mvm *mvm)
2208 {
2209 	if (mvm->mei_registered)
2210 		iwl_mei_host_disassociated();
2211 }
2212 
2213 static inline void iwl_mvm_mei_device_down(struct iwl_mvm *mvm)
2214 {
2215 	if (mvm->mei_registered)
2216 		iwl_mei_device_down();
2217 }
2218 
2219 static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm)
2220 {
2221 	bool sw_rfkill =
2222 		mvm->hw_registered ? rfkill_soft_blocked(mvm->hw->wiphy->rfkill) : false;
2223 
2224 	if (mvm->mei_registered)
2225 		iwl_mei_set_rfkill_state(iwl_mvm_is_radio_killed(mvm),
2226 					 sw_rfkill);
2227 }
2228 
2229 void iwl_mvm_send_roaming_forbidden_event(struct iwl_mvm *mvm,
2230 					  struct ieee80211_vif *vif,
2231 					  bool forbidden);
2232 
2233 #endif /* __IWL_MVM_H__ */
2234