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