xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h (revision c7eca79def44f1faf024d8442044287bef749818)
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_time_sync_data {
785 	struct sk_buff_head frame_list;
786 	u8 peer_addr[ETH_ALEN];
787 	bool active;
788 };
789 
790 struct iwl_mvm {
791 	/* for logger access */
792 	struct device *dev;
793 
794 	struct iwl_trans *trans;
795 	const struct iwl_fw *fw;
796 	const struct iwl_cfg *cfg;
797 	struct iwl_phy_db *phy_db;
798 	struct ieee80211_hw *hw;
799 
800 	/* for protecting access to iwl_mvm */
801 	struct mutex mutex;
802 	struct list_head async_handlers_list;
803 	spinlock_t async_handlers_lock;
804 	struct work_struct async_handlers_wk;
805 
806 	struct work_struct roc_done_wk;
807 
808 	unsigned long init_status;
809 
810 	unsigned long status;
811 
812 	u32 queue_sync_cookie;
813 	unsigned long queue_sync_state;
814 	/*
815 	 * for beacon filtering -
816 	 * currently only one interface can be supported
817 	 */
818 	struct iwl_mvm_vif *bf_allowed_vif;
819 
820 	bool hw_registered;
821 	bool rfkill_safe_init_done;
822 
823 	u8 cca_40mhz_workaround;
824 
825 	u32 ampdu_ref;
826 	bool ampdu_toggle;
827 
828 	struct iwl_notif_wait_data notif_wait;
829 
830 	union {
831 		struct mvm_statistics_rx_v3 rx_stats_v3;
832 		struct mvm_statistics_rx rx_stats;
833 	};
834 
835 	struct {
836 		u64 rx_time;
837 		u64 tx_time;
838 		u64 on_time_rf;
839 		u64 on_time_scan;
840 	} radio_stats, accu_radio_stats;
841 
842 	struct list_head add_stream_txqs;
843 	union {
844 		struct iwl_mvm_dqa_txq_info queue_info[IWL_MAX_HW_QUEUES];
845 		struct iwl_mvm_tvqm_txq_info tvqm_info[IWL_MAX_TVQM_QUEUES];
846 	};
847 	struct work_struct add_stream_wk; /* To add streams to queues */
848 
849 	const char *nvm_file_name;
850 	struct iwl_nvm_data *nvm_data;
851 	struct iwl_mei_nvm *mei_nvm_data;
852 	struct iwl_mvm_csme_conn_info __rcu *csme_conn_info;
853 	bool mei_rfkill_blocked;
854 	bool mei_registered;
855 	struct work_struct sap_connected_wk;
856 
857 	/*
858 	 * NVM built based on the SAP data but that we can't free even after
859 	 * we get ownership because it contains the cfg80211's channel.
860 	 */
861 	struct iwl_nvm_data *temp_nvm_data;
862 
863 	/* NVM sections */
864 	struct iwl_nvm_section nvm_sections[NVM_MAX_NUM_SECTIONS];
865 
866 	struct iwl_fw_runtime fwrt;
867 
868 	/* EEPROM MAC addresses */
869 	struct mac_address addresses[IWL_MVM_MAX_ADDRESSES];
870 
871 	/* data related to data path */
872 	struct iwl_rx_phy_info last_phy_info;
873 	struct ieee80211_sta __rcu *fw_id_to_mac_id[IWL_MVM_STATION_COUNT_MAX];
874 	u8 rx_ba_sessions;
875 
876 	/* configured by mac80211 */
877 	u32 rts_threshold;
878 
879 	/* Scan status, cmd (pre-allocated) and auxiliary station */
880 	unsigned int scan_status;
881 	size_t scan_cmd_size;
882 	void *scan_cmd;
883 	struct iwl_mcast_filter_cmd *mcast_filter_cmd;
884 	/* For CDB this is low band scan type, for non-CDB - type. */
885 	enum iwl_mvm_scan_type scan_type;
886 	enum iwl_mvm_scan_type hb_scan_type;
887 
888 	enum iwl_mvm_sched_scan_pass_all_states sched_scan_pass_all;
889 	struct delayed_work scan_timeout_dwork;
890 
891 	/* max number of simultaneous scans the FW supports */
892 	unsigned int max_scans;
893 
894 	/* UMAC scan tracking */
895 	u32 scan_uid_status[IWL_MVM_MAX_UMAC_SCANS];
896 
897 	/* start time of last scan in TSF of the mac that requested the scan */
898 	u64 scan_start;
899 
900 	/* the vif that requested the current scan */
901 	struct iwl_mvm_vif *scan_vif;
902 
903 	/* rx chain antennas set through debugfs for the scan command */
904 	u8 scan_rx_ant;
905 
906 	/* Internal station */
907 	struct iwl_mvm_int_sta aux_sta;
908 	struct iwl_mvm_int_sta snif_sta;
909 
910 	bool last_ebs_successful;
911 
912 	u8 scan_last_antenna_idx; /* to toggle TX between antennas */
913 	u8 mgmt_last_antenna_idx;
914 
915 	/* last smart fifo state that was successfully sent to firmware */
916 	enum iwl_sf_state sf_state;
917 
918 	/*
919 	 * Leave this pointer outside the ifdef below so that it can be
920 	 * assigned without ifdef in the source code.
921 	 */
922 	struct dentry *debugfs_dir;
923 #ifdef CONFIG_IWLWIFI_DEBUGFS
924 	u32 dbgfs_sram_offset, dbgfs_sram_len;
925 	u32 dbgfs_prph_reg_addr;
926 	bool disable_power_off;
927 	bool disable_power_off_d3;
928 	bool beacon_inject_active;
929 
930 	bool scan_iter_notif_enabled;
931 
932 	struct debugfs_blob_wrapper nvm_hw_blob;
933 	struct debugfs_blob_wrapper nvm_sw_blob;
934 	struct debugfs_blob_wrapper nvm_calib_blob;
935 	struct debugfs_blob_wrapper nvm_prod_blob;
936 	struct debugfs_blob_wrapper nvm_phy_sku_blob;
937 	struct debugfs_blob_wrapper nvm_reg_blob;
938 
939 	struct iwl_mvm_frame_stats drv_rx_stats;
940 	spinlock_t drv_stats_lock;
941 	u16 dbgfs_rx_phyinfo;
942 #endif
943 
944 	struct iwl_mvm_phy_ctxt phy_ctxts[NUM_PHY_CTX];
945 
946 	struct list_head time_event_list;
947 	spinlock_t time_event_lock;
948 
949 	/*
950 	 * A bitmap indicating the index of the key in use. The firmware
951 	 * can hold 16 keys at most. Reflect this fact.
952 	 */
953 	unsigned long fw_key_table[BITS_TO_LONGS(STA_KEY_MAX_NUM)];
954 	u8 fw_key_deleted[STA_KEY_MAX_NUM];
955 
956 	struct ieee80211_vif __rcu *vif_id_to_mac[NUM_MAC_INDEX_DRIVER];
957 
958 	/* -1 for always, 0 for never, >0 for that many times */
959 	s8 fw_restart;
960 	u8 *error_recovery_buf;
961 
962 #ifdef CONFIG_IWLWIFI_LEDS
963 	struct led_classdev led;
964 #endif
965 
966 	struct ieee80211_vif *p2p_device_vif;
967 
968 #ifdef CONFIG_PM
969 	struct wiphy_wowlan_support wowlan;
970 	int gtk_ivlen, gtk_icvlen, ptk_ivlen, ptk_icvlen;
971 
972 	/* sched scan settings for net detect */
973 	struct ieee80211_scan_ies nd_ies;
974 	struct cfg80211_match_set *nd_match_sets;
975 	int n_nd_match_sets;
976 	struct ieee80211_channel **nd_channels;
977 	int n_nd_channels;
978 	bool net_detect;
979 	u8 offload_tid;
980 #ifdef CONFIG_IWLWIFI_DEBUGFS
981 	bool d3_wake_sysassert;
982 	bool d3_test_active;
983 	u32 d3_test_pme_ptr;
984 	struct ieee80211_vif *keep_vif;
985 	u32 last_netdetect_scans; /* no. of scans in the last net-detect wake */
986 #endif
987 #endif
988 
989 	wait_queue_head_t rx_sync_waitq;
990 
991 	/* BT-Coex */
992 	struct iwl_bt_coex_profile_notif last_bt_notif;
993 	struct iwl_bt_coex_ci_cmd last_bt_ci_cmd;
994 
995 	u8 bt_tx_prio;
996 	enum iwl_bt_force_ant_mode bt_force_ant_mode;
997 
998 	/* Aux ROC */
999 	struct list_head aux_roc_te_list;
1000 
1001 	/* Thermal Throttling and CTkill */
1002 	struct iwl_mvm_tt_mgmt thermal_throttle;
1003 #ifdef CONFIG_THERMAL
1004 	struct iwl_mvm_thermal_device tz_device;
1005 	struct iwl_mvm_cooling_device cooling_dev;
1006 #endif
1007 
1008 	s32 temperature;	/* Celsius */
1009 	/*
1010 	 * Debug option to set the NIC temperature. This option makes the
1011 	 * driver think this is the actual NIC temperature, and ignore the
1012 	 * real temperature that is received from the fw
1013 	 */
1014 	bool temperature_test;  /* Debug test temperature is enabled */
1015 
1016 	bool fw_static_smps_request;
1017 
1018 	unsigned long bt_coex_last_tcm_ts;
1019 	struct iwl_mvm_tcm tcm;
1020 
1021 	u8 uapsd_noagg_bssid_write_idx;
1022 	struct mac_address uapsd_noagg_bssids[IWL_MVM_UAPSD_NOAGG_BSSIDS_NUM]
1023 		__aligned(2);
1024 
1025 	struct iwl_time_quota_cmd last_quota_cmd;
1026 
1027 #ifdef CONFIG_NL80211_TESTMODE
1028 	u32 noa_duration;
1029 	struct ieee80211_vif *noa_vif;
1030 #endif
1031 
1032 	/* Tx queues */
1033 	u16 aux_queue;
1034 	u16 snif_queue;
1035 	u16 probe_queue;
1036 	u16 p2p_dev_queue;
1037 
1038 	/* Indicate if device power save is allowed */
1039 	u8 ps_disabled; /* u8 instead of bool to ease debugfs_create_* usage */
1040 	/* Indicate if 32Khz external clock is valid */
1041 	u32 ext_clock_valid;
1042 
1043 	/* This vif used by CSME to send / receive traffic */
1044 	struct ieee80211_vif *csme_vif;
1045 	struct ieee80211_vif __rcu *csa_vif;
1046 	struct ieee80211_vif __rcu *csa_tx_blocked_vif;
1047 	u8 csa_tx_block_bcn_timeout;
1048 
1049 	/* system time of last beacon (for AP/GO interface) */
1050 	u32 ap_last_beacon_gp2;
1051 
1052 	/* indicates that we transmitted the last beacon */
1053 	bool ibss_manager;
1054 
1055 	bool lar_regdom_set;
1056 	enum iwl_mcc_source mcc_src;
1057 
1058 	/* TDLS channel switch data */
1059 	struct {
1060 		struct delayed_work dwork;
1061 		enum iwl_mvm_tdls_cs_state state;
1062 
1063 		/*
1064 		 * Current cs sta - might be different from periodic cs peer
1065 		 * station. Value is meaningless when the cs-state is idle.
1066 		 */
1067 		u8 cur_sta_id;
1068 
1069 		/* TDLS periodic channel-switch peer */
1070 		struct {
1071 			u8 sta_id;
1072 			u8 op_class;
1073 			bool initiator; /* are we the link initiator */
1074 			struct cfg80211_chan_def chandef;
1075 			struct sk_buff *skb; /* ch sw template */
1076 			u32 ch_sw_tm_ie;
1077 
1078 			/* timestamp of last ch-sw request sent (GP2 time) */
1079 			u32 sent_timestamp;
1080 		} peer;
1081 	} tdls_cs;
1082 
1083 
1084 	u32 ciphers[IWL_MVM_NUM_CIPHERS];
1085 
1086 	struct cfg80211_ftm_responder_stats ftm_resp_stats;
1087 	struct {
1088 		struct cfg80211_pmsr_request *req;
1089 		struct wireless_dev *req_wdev;
1090 		struct list_head loc_list;
1091 		int responses[IWL_MVM_TOF_MAX_APS];
1092 		struct {
1093 			struct list_head resp;
1094 		} smooth;
1095 		struct list_head pasn_list;
1096 	} ftm_initiator;
1097 
1098 	struct list_head resp_pasn_list;
1099 
1100 	struct ptp_data ptp_data;
1101 
1102 	struct {
1103 		u8 range_resp;
1104 	} cmd_ver;
1105 
1106 	struct ieee80211_vif *nan_vif;
1107 	struct iwl_mvm_baid_data __rcu *baid_map[IWL_MAX_BAID];
1108 
1109 	/*
1110 	 * Drop beacons from other APs in AP mode when there are no connected
1111 	 * clients.
1112 	 */
1113 	bool drop_bcn_ap_mode;
1114 
1115 	struct delayed_work cs_tx_unblock_dwork;
1116 
1117 	/* does a monitor vif exist (only one can exist hence bool) */
1118 	bool monitor_on;
1119 	/*
1120 	 * primary channel position relative to he whole bandwidth,
1121 	 * in steps of 80 MHz
1122 	 */
1123 	u8 monitor_p80;
1124 
1125 	/* sniffer data to include in radiotap */
1126 	__le16 cur_aid;
1127 	u8 cur_bssid[ETH_ALEN];
1128 
1129 	unsigned long last_6ghz_passive_scan_jiffies;
1130 	unsigned long last_reset_or_resume_time_jiffies;
1131 
1132 	bool sta_remove_requires_queue_remove;
1133 
1134 	bool pldr_sync;
1135 
1136 	struct iwl_time_sync_data time_sync;
1137 };
1138 
1139 /* Extract MVM priv from op_mode and _hw */
1140 #define IWL_OP_MODE_GET_MVM(_iwl_op_mode)		\
1141 	((struct iwl_mvm *)(_iwl_op_mode)->op_mode_specific)
1142 
1143 #define IWL_MAC80211_GET_MVM(_hw)			\
1144 	IWL_OP_MODE_GET_MVM((struct iwl_op_mode *)((_hw)->priv))
1145 
1146 /**
1147  * enum iwl_mvm_status - MVM status bits
1148  * @IWL_MVM_STATUS_HW_RFKILL: HW RF-kill is asserted
1149  * @IWL_MVM_STATUS_HW_CTKILL: CT-kill is active
1150  * @IWL_MVM_STATUS_ROC_RUNNING: remain-on-channel is running
1151  * @IWL_MVM_STATUS_HW_RESTART_REQUESTED: HW restart was requested
1152  * @IWL_MVM_STATUS_IN_HW_RESTART: HW restart is active
1153  * @IWL_MVM_STATUS_ROC_AUX_RUNNING: AUX remain-on-channel is running
1154  * @IWL_MVM_STATUS_FIRMWARE_RUNNING: firmware is running
1155  * @IWL_MVM_STATUS_NEED_FLUSH_P2P: need to flush P2P bcast STA
1156  * @IWL_MVM_STATUS_IN_D3: in D3 (or at least about to go into it)
1157  * @IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE: suppress one error log
1158  *	if this is set, when intentionally triggered
1159  * @IWL_MVM_STATUS_STARTING: starting mac,
1160  *	used to disable restart flow while in STARTING state
1161  */
1162 enum iwl_mvm_status {
1163 	IWL_MVM_STATUS_HW_RFKILL,
1164 	IWL_MVM_STATUS_HW_CTKILL,
1165 	IWL_MVM_STATUS_ROC_RUNNING,
1166 	IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1167 	IWL_MVM_STATUS_IN_HW_RESTART,
1168 	IWL_MVM_STATUS_ROC_AUX_RUNNING,
1169 	IWL_MVM_STATUS_FIRMWARE_RUNNING,
1170 	IWL_MVM_STATUS_NEED_FLUSH_P2P,
1171 	IWL_MVM_STATUS_IN_D3,
1172 	IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,
1173 	IWL_MVM_STATUS_STARTING,
1174 };
1175 
1176 struct iwl_mvm_csme_conn_info {
1177 	struct rcu_head rcu_head;
1178 	struct iwl_mei_conn_info conn_info;
1179 };
1180 
1181 /* Keep track of completed init configuration */
1182 enum iwl_mvm_init_status {
1183 	IWL_MVM_INIT_STATUS_THERMAL_INIT_COMPLETE = BIT(0),
1184 	IWL_MVM_INIT_STATUS_LEDS_INIT_COMPLETE = BIT(1),
1185 };
1186 
1187 static inline bool iwl_mvm_is_radio_killed(struct iwl_mvm *mvm)
1188 {
1189 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status) ||
1190 	       test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1191 }
1192 
1193 static inline bool iwl_mvm_is_radio_hw_killed(struct iwl_mvm *mvm)
1194 {
1195 	return test_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1196 }
1197 
1198 static inline bool iwl_mvm_firmware_running(struct iwl_mvm *mvm)
1199 {
1200 	return test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1201 }
1202 
1203 /* Must be called with rcu_read_lock() held and it can only be
1204  * released when mvmsta is not needed anymore.
1205  */
1206 static inline struct iwl_mvm_sta *
1207 iwl_mvm_sta_from_staid_rcu(struct iwl_mvm *mvm, u8 sta_id)
1208 {
1209 	struct ieee80211_sta *sta;
1210 
1211 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1212 		return NULL;
1213 
1214 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1215 
1216 	/* This can happen if the station has been removed right now */
1217 	if (IS_ERR_OR_NULL(sta))
1218 		return NULL;
1219 
1220 	return iwl_mvm_sta_from_mac80211(sta);
1221 }
1222 
1223 static inline struct iwl_mvm_sta *
1224 iwl_mvm_sta_from_staid_protected(struct iwl_mvm *mvm, u8 sta_id)
1225 {
1226 	struct ieee80211_sta *sta;
1227 
1228 	if (sta_id >= mvm->fw->ucode_capa.num_stations)
1229 		return NULL;
1230 
1231 	sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1232 					lockdep_is_held(&mvm->mutex));
1233 
1234 	/* This can happen if the station has been removed right now */
1235 	if (IS_ERR_OR_NULL(sta))
1236 		return NULL;
1237 
1238 	return iwl_mvm_sta_from_mac80211(sta);
1239 }
1240 
1241 static inline struct ieee80211_vif *
1242 iwl_mvm_rcu_dereference_vif_id(struct iwl_mvm *mvm, u8 vif_id, bool rcu)
1243 {
1244 	if (WARN_ON(vif_id >= ARRAY_SIZE(mvm->vif_id_to_mac)))
1245 		return NULL;
1246 
1247 	if (rcu)
1248 		return rcu_dereference(mvm->vif_id_to_mac[vif_id]);
1249 
1250 	return rcu_dereference_protected(mvm->vif_id_to_mac[vif_id],
1251 					 lockdep_is_held(&mvm->mutex));
1252 }
1253 
1254 static inline bool iwl_mvm_is_adaptive_dwell_supported(struct iwl_mvm *mvm)
1255 {
1256 	return fw_has_api(&mvm->fw->ucode_capa,
1257 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL);
1258 }
1259 
1260 static inline bool iwl_mvm_is_adaptive_dwell_v2_supported(struct iwl_mvm *mvm)
1261 {
1262 	return fw_has_api(&mvm->fw->ucode_capa,
1263 			  IWL_UCODE_TLV_API_ADAPTIVE_DWELL_V2);
1264 }
1265 
1266 static inline bool iwl_mvm_is_adwell_hb_ap_num_supported(struct iwl_mvm *mvm)
1267 {
1268 	return fw_has_api(&mvm->fw->ucode_capa,
1269 			  IWL_UCODE_TLV_API_ADWELL_HB_DEF_N_AP);
1270 }
1271 
1272 static inline bool iwl_mvm_is_oce_supported(struct iwl_mvm *mvm)
1273 {
1274 	/* OCE should never be enabled for LMAC scan FWs */
1275 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_OCE);
1276 }
1277 
1278 static inline bool iwl_mvm_is_frag_ebs_supported(struct iwl_mvm *mvm)
1279 {
1280 	return fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_FRAG_EBS);
1281 }
1282 
1283 static inline bool iwl_mvm_is_short_beacon_notif_supported(struct iwl_mvm *mvm)
1284 {
1285 	return fw_has_api(&mvm->fw->ucode_capa,
1286 			  IWL_UCODE_TLV_API_SHORT_BEACON_NOTIF);
1287 }
1288 
1289 static inline bool iwl_mvm_is_dqa_data_queue(struct iwl_mvm *mvm, u8 queue)
1290 {
1291 	return (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE) &&
1292 	       (queue <= IWL_MVM_DQA_MAX_DATA_QUEUE);
1293 }
1294 
1295 static inline bool iwl_mvm_is_dqa_mgmt_queue(struct iwl_mvm *mvm, u8 queue)
1296 {
1297 	return (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) &&
1298 	       (queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE);
1299 }
1300 
1301 static inline bool iwl_mvm_is_lar_supported(struct iwl_mvm *mvm)
1302 {
1303 	bool nvm_lar = mvm->nvm_data->lar_enabled;
1304 	bool tlv_lar = fw_has_capa(&mvm->fw->ucode_capa,
1305 				   IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
1306 
1307 	/*
1308 	 * Enable LAR only if it is supported by the FW (TLV) &&
1309 	 * enabled in the NVM
1310 	 */
1311 	if (mvm->cfg->nvm_type == IWL_NVM_EXT)
1312 		return nvm_lar && tlv_lar;
1313 	else
1314 		return tlv_lar;
1315 }
1316 
1317 static inline bool iwl_mvm_is_wifi_mcc_supported(struct iwl_mvm *mvm)
1318 {
1319 	return fw_has_api(&mvm->fw->ucode_capa,
1320 			  IWL_UCODE_TLV_API_WIFI_MCC_UPDATE) ||
1321 	       fw_has_capa(&mvm->fw->ucode_capa,
1322 			   IWL_UCODE_TLV_CAPA_LAR_MULTI_MCC);
1323 }
1324 
1325 static inline bool iwl_mvm_bt_is_rrc_supported(struct iwl_mvm *mvm)
1326 {
1327 	return fw_has_capa(&mvm->fw->ucode_capa,
1328 			   IWL_UCODE_TLV_CAPA_BT_COEX_RRC) &&
1329 		IWL_MVM_BT_COEX_RRC;
1330 }
1331 
1332 static inline bool iwl_mvm_is_csum_supported(struct iwl_mvm *mvm)
1333 {
1334 	return fw_has_capa(&mvm->fw->ucode_capa,
1335 			   IWL_UCODE_TLV_CAPA_CSUM_SUPPORT) &&
1336 		!IWL_MVM_HW_CSUM_DISABLE;
1337 }
1338 
1339 static inline bool iwl_mvm_is_mplut_supported(struct iwl_mvm *mvm)
1340 {
1341 	return fw_has_capa(&mvm->fw->ucode_capa,
1342 			   IWL_UCODE_TLV_CAPA_BT_MPLUT_SUPPORT) &&
1343 		IWL_MVM_BT_COEX_MPLUT;
1344 }
1345 
1346 static inline
1347 bool iwl_mvm_is_p2p_scm_uapsd_supported(struct iwl_mvm *mvm)
1348 {
1349 	return fw_has_capa(&mvm->fw->ucode_capa,
1350 			   IWL_UCODE_TLV_CAPA_P2P_SCM_UAPSD) &&
1351 		!(iwlwifi_mod_params.uapsd_disable &
1352 		  IWL_DISABLE_UAPSD_P2P_CLIENT);
1353 }
1354 
1355 static inline bool iwl_mvm_has_new_rx_api(struct iwl_mvm *mvm)
1356 {
1357 	return fw_has_capa(&mvm->fw->ucode_capa,
1358 			   IWL_UCODE_TLV_CAPA_MULTI_QUEUE_RX_SUPPORT);
1359 }
1360 
1361 static inline bool iwl_mvm_has_new_tx_api(struct iwl_mvm *mvm)
1362 {
1363 	/* TODO - replace with TLV once defined */
1364 	return mvm->trans->trans_cfg->use_tfh;
1365 }
1366 
1367 static inline bool iwl_mvm_has_unified_ucode(struct iwl_mvm *mvm)
1368 {
1369 	/* TODO - better define this */
1370 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1371 }
1372 
1373 static inline bool iwl_mvm_is_cdb_supported(struct iwl_mvm *mvm)
1374 {
1375 	/*
1376 	 * TODO:
1377 	 * The issue of how to determine CDB APIs and usage is still not fully
1378 	 * defined.
1379 	 * There is a compilation for CDB and non-CDB FW, but there may
1380 	 * be also runtime check.
1381 	 * For now there is a TLV for checking compilation mode, but a
1382 	 * runtime check will also have to be here - once defined.
1383 	 */
1384 	return fw_has_capa(&mvm->fw->ucode_capa,
1385 			   IWL_UCODE_TLV_CAPA_CDB_SUPPORT);
1386 }
1387 
1388 static inline bool iwl_mvm_cdb_scan_api(struct iwl_mvm *mvm)
1389 {
1390 	/*
1391 	 * TODO: should this be the same as iwl_mvm_is_cdb_supported()?
1392 	 * but then there's a little bit of code in scan that won't make
1393 	 * any sense...
1394 	 */
1395 	return mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000;
1396 }
1397 
1398 static inline bool iwl_mvm_is_scan_ext_chan_supported(struct iwl_mvm *mvm)
1399 {
1400 	return fw_has_api(&mvm->fw->ucode_capa,
1401 			  IWL_UCODE_TLV_API_SCAN_EXT_CHAN_VER);
1402 }
1403 
1404 
1405 static inline bool iwl_mvm_is_reduced_config_scan_supported(struct iwl_mvm *mvm)
1406 {
1407 	return fw_has_api(&mvm->fw->ucode_capa,
1408 			  IWL_UCODE_TLV_API_REDUCED_SCAN_CONFIG);
1409 }
1410 
1411 static inline bool iwl_mvm_is_band_in_rx_supported(struct iwl_mvm *mvm)
1412 {
1413 	return fw_has_api(&mvm->fw->ucode_capa,
1414 			   IWL_UCODE_TLV_API_BAND_IN_RX_DATA);
1415 }
1416 
1417 static inline bool iwl_mvm_has_new_rx_stats_api(struct iwl_mvm *mvm)
1418 {
1419 	return fw_has_api(&mvm->fw->ucode_capa,
1420 			  IWL_UCODE_TLV_API_NEW_RX_STATS);
1421 }
1422 
1423 static inline bool iwl_mvm_has_quota_low_latency(struct iwl_mvm *mvm)
1424 {
1425 	return fw_has_api(&mvm->fw->ucode_capa,
1426 			  IWL_UCODE_TLV_API_QUOTA_LOW_LATENCY);
1427 }
1428 
1429 static inline bool iwl_mvm_has_tlc_offload(const struct iwl_mvm *mvm)
1430 {
1431 	return fw_has_capa(&mvm->fw->ucode_capa,
1432 			   IWL_UCODE_TLV_CAPA_TLC_OFFLOAD);
1433 }
1434 
1435 static inline struct agg_tx_status *
1436 iwl_mvm_get_agg_status(struct iwl_mvm *mvm, void *tx_resp)
1437 {
1438 	if (iwl_mvm_has_new_tx_api(mvm))
1439 		return &((struct iwl_mvm_tx_resp *)tx_resp)->status;
1440 	else
1441 		return ((struct iwl_mvm_tx_resp_v3 *)tx_resp)->status;
1442 }
1443 
1444 static inline bool iwl_mvm_is_tt_in_fw(struct iwl_mvm *mvm)
1445 {
1446 	/* these two TLV are redundant since the responsibility to CT-kill by
1447 	 * FW happens only after we send at least one command of
1448 	 * temperature THs report.
1449 	 */
1450 	return fw_has_capa(&mvm->fw->ucode_capa,
1451 			   IWL_UCODE_TLV_CAPA_CT_KILL_BY_FW) &&
1452 	       fw_has_capa(&mvm->fw->ucode_capa,
1453 			   IWL_UCODE_TLV_CAPA_TEMP_THS_REPORT_SUPPORT);
1454 }
1455 
1456 static inline bool iwl_mvm_is_ctdp_supported(struct iwl_mvm *mvm)
1457 {
1458 	return fw_has_capa(&mvm->fw->ucode_capa,
1459 			   IWL_UCODE_TLV_CAPA_CTDP_SUPPORT);
1460 }
1461 
1462 extern const u8 iwl_mvm_ac_to_tx_fifo[];
1463 extern const u8 iwl_mvm_ac_to_gen2_tx_fifo[];
1464 
1465 static inline u8 iwl_mvm_mac_ac_to_tx_fifo(struct iwl_mvm *mvm,
1466 					   enum ieee80211_ac_numbers ac)
1467 {
1468 	return iwl_mvm_has_new_tx_api(mvm) ?
1469 		iwl_mvm_ac_to_gen2_tx_fifo[ac] : iwl_mvm_ac_to_tx_fifo[ac];
1470 }
1471 
1472 struct iwl_rate_info {
1473 	u8 plcp;	/* uCode API:  IWL_RATE_6M_PLCP, etc. */
1474 	u8 plcp_siso;	/* uCode API:  IWL_RATE_SISO_6M_PLCP, etc. */
1475 	u8 plcp_mimo2;	/* uCode API:  IWL_RATE_MIMO2_6M_PLCP, etc. */
1476 	u8 plcp_mimo3;  /* uCode API:  IWL_RATE_MIMO3_6M_PLCP, etc. */
1477 	u8 ieee;	/* MAC header:  IWL_RATE_6M_IEEE, etc. */
1478 };
1479 
1480 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm);
1481 int __iwl_mvm_mac_start(struct iwl_mvm *mvm);
1482 
1483 /******************
1484  * MVM Methods
1485  ******************/
1486 /* uCode */
1487 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm);
1488 
1489 /* Utils */
1490 int iwl_mvm_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
1491 					  enum nl80211_band band);
1492 int iwl_mvm_legacy_rate_to_mac80211_idx(u32 rate_n_flags,
1493 					enum nl80211_band band);
1494 void iwl_mvm_hwrate_to_tx_rate(u32 rate_n_flags,
1495 			       enum nl80211_band band,
1496 			       struct ieee80211_tx_rate *r);
1497 void iwl_mvm_hwrate_to_tx_rate_v1(u32 rate_n_flags,
1498 				  enum nl80211_band band,
1499 				  struct ieee80211_tx_rate *r);
1500 u8 iwl_mvm_mac80211_idx_to_hwrate(const struct iwl_fw *fw, int rate_idx);
1501 u8 iwl_mvm_mac80211_ac_to_ucode_ac(enum ieee80211_ac_numbers ac);
1502 bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1503 
1504 static inline void iwl_mvm_dump_nic_error_log(struct iwl_mvm *mvm)
1505 {
1506 	iwl_fwrt_dump_error_logs(&mvm->fwrt);
1507 }
1508 
1509 u8 first_antenna(u8 mask);
1510 u8 iwl_mvm_next_antenna(struct iwl_mvm *mvm, u8 valid, u8 last_idx);
1511 void iwl_mvm_get_sync_time(struct iwl_mvm *mvm, int clock_type, u32 *gp2,
1512 			   u64 *boottime, ktime_t *realtime);
1513 u32 iwl_mvm_get_systime(struct iwl_mvm *mvm);
1514 
1515 /* Tx / Host Commands */
1516 int __must_check iwl_mvm_send_cmd(struct iwl_mvm *mvm,
1517 				  struct iwl_host_cmd *cmd);
1518 int __must_check iwl_mvm_send_cmd_pdu(struct iwl_mvm *mvm, u32 id,
1519 				      u32 flags, u16 len, const void *data);
1520 int __must_check iwl_mvm_send_cmd_status(struct iwl_mvm *mvm,
1521 					 struct iwl_host_cmd *cmd,
1522 					 u32 *status);
1523 int __must_check iwl_mvm_send_cmd_pdu_status(struct iwl_mvm *mvm, u32 id,
1524 					     u16 len, const void *data,
1525 					     u32 *status);
1526 int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
1527 		       struct ieee80211_sta *sta);
1528 int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb);
1529 void iwl_mvm_set_tx_cmd(struct iwl_mvm *mvm, struct sk_buff *skb,
1530 			struct iwl_tx_cmd *tx_cmd,
1531 			struct ieee80211_tx_info *info, u8 sta_id);
1532 void iwl_mvm_set_tx_cmd_rate(struct iwl_mvm *mvm, struct iwl_tx_cmd *tx_cmd,
1533 			    struct ieee80211_tx_info *info,
1534 			    struct ieee80211_sta *sta, __le16 fc);
1535 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
1536 unsigned int iwl_mvm_max_amsdu_size(struct iwl_mvm *mvm,
1537 				    struct ieee80211_sta *sta,
1538 				    unsigned int tid);
1539 u32 iwl_mvm_tx_csum_bz(struct iwl_mvm *mvm, struct sk_buff *skb, bool amsdu);
1540 
1541 #ifdef CONFIG_IWLWIFI_DEBUG
1542 const char *iwl_mvm_get_tx_fail_reason(u32 status);
1543 #else
1544 static inline const char *iwl_mvm_get_tx_fail_reason(u32 status) { return ""; }
1545 #endif
1546 int iwl_mvm_flush_tx_path(struct iwl_mvm *mvm, u32 tfd_msk);
1547 int iwl_mvm_flush_sta(struct iwl_mvm *mvm, void *sta, bool internal);
1548 int iwl_mvm_flush_sta_tids(struct iwl_mvm *mvm, u32 sta_id, u16 tids);
1549 
1550 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm);
1551 
1552 static inline void iwl_mvm_set_tx_cmd_ccmp(struct ieee80211_tx_info *info,
1553 					   struct iwl_tx_cmd *tx_cmd)
1554 {
1555 	struct ieee80211_key_conf *keyconf = info->control.hw_key;
1556 
1557 	tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
1558 	memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
1559 }
1560 
1561 static inline void iwl_mvm_wait_for_async_handlers(struct iwl_mvm *mvm)
1562 {
1563 	flush_work(&mvm->async_handlers_wk);
1564 }
1565 
1566 /* Statistics */
1567 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1568 				  struct iwl_rx_packet *pkt);
1569 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
1570 			   struct iwl_rx_cmd_buffer *rxb);
1571 int iwl_mvm_request_statistics(struct iwl_mvm *mvm, bool clear);
1572 void iwl_mvm_accu_radio_stats(struct iwl_mvm *mvm);
1573 
1574 /* NVM */
1575 int iwl_nvm_init(struct iwl_mvm *mvm);
1576 int iwl_mvm_load_nvm_to_nic(struct iwl_mvm *mvm);
1577 
1578 static inline u8 iwl_mvm_get_valid_tx_ant(struct iwl_mvm *mvm)
1579 {
1580 	return mvm->nvm_data && mvm->nvm_data->valid_tx_ant ?
1581 	       mvm->fw->valid_tx_ant & mvm->nvm_data->valid_tx_ant :
1582 	       mvm->fw->valid_tx_ant;
1583 }
1584 
1585 static inline u8 iwl_mvm_get_valid_rx_ant(struct iwl_mvm *mvm)
1586 {
1587 	return mvm->nvm_data && mvm->nvm_data->valid_rx_ant ?
1588 	       mvm->fw->valid_rx_ant & mvm->nvm_data->valid_rx_ant :
1589 	       mvm->fw->valid_rx_ant;
1590 }
1591 
1592 static inline void iwl_mvm_toggle_tx_ant(struct iwl_mvm *mvm, u8 *ant)
1593 {
1594 	*ant = iwl_mvm_next_antenna(mvm, iwl_mvm_get_valid_tx_ant(mvm), *ant);
1595 }
1596 
1597 static inline u32 iwl_mvm_get_phy_config(struct iwl_mvm *mvm)
1598 {
1599 	u32 phy_config = ~(FW_PHY_CFG_TX_CHAIN |
1600 			   FW_PHY_CFG_RX_CHAIN);
1601 	u32 valid_rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
1602 	u32 valid_tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
1603 
1604 	phy_config |= valid_tx_ant << FW_PHY_CFG_TX_CHAIN_POS |
1605 		      valid_rx_ant << FW_PHY_CFG_RX_CHAIN_POS;
1606 
1607 	return mvm->fw->phy_config & phy_config;
1608 }
1609 
1610 int iwl_mvm_up(struct iwl_mvm *mvm);
1611 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm);
1612 
1613 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm);
1614 
1615 /*
1616  * FW notifications / CMD responses handlers
1617  * Convention: iwl_mvm_rx_<NAME OF THE CMD>
1618  */
1619 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1620 		   struct napi_struct *napi,
1621 		   struct iwl_rx_cmd_buffer *rxb);
1622 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1623 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1624 			struct iwl_rx_cmd_buffer *rxb);
1625 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1626 			struct iwl_rx_cmd_buffer *rxb, int queue);
1627 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1628 				struct iwl_rx_cmd_buffer *rxb, int queue);
1629 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1630 			      struct iwl_rx_cmd_buffer *rxb, int queue);
1631 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1632 				  struct iwl_rx_cmd_buffer *rxb, int queue);
1633 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
1634 			    struct iwl_rx_cmd_buffer *rxb, int queue);
1635 void iwl_mvm_rx_tx_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1636 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
1637 				   struct iwl_rx_cmd_buffer *rxb);
1638 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags);
1639 void iwl_mvm_rx_ba_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1640 void iwl_mvm_rx_ant_coupling_notif(struct iwl_mvm *mvm,
1641 				   struct iwl_rx_cmd_buffer *rxb);
1642 void iwl_mvm_rx_fw_error(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1643 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1644 			     struct iwl_rx_cmd_buffer *rxb);
1645 void iwl_mvm_rx_shared_mem_cfg_notif(struct iwl_mvm *mvm,
1646 				     struct iwl_rx_cmd_buffer *rxb);
1647 
1648 /* MVM PHY */
1649 struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm);
1650 int iwl_mvm_phy_ctxt_add(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1651 			 struct cfg80211_chan_def *chandef,
1652 			 u8 chains_static, u8 chains_dynamic);
1653 int iwl_mvm_phy_ctxt_changed(struct iwl_mvm *mvm, struct iwl_mvm_phy_ctxt *ctxt,
1654 			     struct cfg80211_chan_def *chandef,
1655 			     u8 chains_static, u8 chains_dynamic);
1656 void iwl_mvm_phy_ctxt_ref(struct iwl_mvm *mvm,
1657 			  struct iwl_mvm_phy_ctxt *ctxt);
1658 void iwl_mvm_phy_ctxt_unref(struct iwl_mvm *mvm,
1659 			    struct iwl_mvm_phy_ctxt *ctxt);
1660 int iwl_mvm_phy_ctx_count(struct iwl_mvm *mvm);
1661 u8 iwl_mvm_get_channel_width(struct cfg80211_chan_def *chandef);
1662 u8 iwl_mvm_get_ctrl_pos(struct cfg80211_chan_def *chandef);
1663 
1664 /* MAC (virtual interface) programming */
1665 
1666 bool iwl_mvm_mac_add_interface_common(struct iwl_mvm *mvm,
1667 				      struct ieee80211_hw *hw,
1668 				      struct ieee80211_vif *vif, int *ret);
1669 bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw,
1670 					 struct ieee80211_vif *vif);
1671 void iwl_mvm_set_fw_basic_rates(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1672 				__le32 *cck_rates, __le32 *ofdm_rates);
1673 void iwl_mvm_set_fw_protection_flags(struct iwl_mvm *mvm,
1674 				     struct ieee80211_vif *vif,
1675 				     __le32 *protection_flags, u32 ht_flag,
1676 				  u32 tgg_flag);
1677 void iwl_mvm_set_fw_qos_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1678 			       struct iwl_ac_qos *ac, __le32 *qos_flags);
1679 bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm,
1680 				   struct iwl_mvm_vif *mvmvif,
1681 				   struct iwl_he_backoff_conf *trig_based_txf);
1682 void iwl_mvm_set_fw_dtim_tbtt(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1683 			      __le64 *dtim_tsf, __le32 *dtim_time,
1684 			      __le32 *assoc_beacon_arrive_time);
1685 __le32 iwl_mac_ctxt_p2p_dev_has_extended_disc(struct iwl_mvm *mvm,
1686 					      struct ieee80211_vif *vif);
1687 void iwl_mvm_mac_ctxt_cmd_ap_set_filter_flags(struct iwl_mvm *mvm,
1688 					      struct iwl_mvm_vif *mvmvif,
1689 					      __le32 *filter_flags,
1690 					      int accept_probe_req_flag,
1691 					      int accept_beacon_flag);
1692 int iwl_mvm_get_mac_type(struct ieee80211_vif *vif);
1693 __le32 iwl_mvm_mac_ctxt_cmd_p2p_sta_get_oppps_ctwin(struct iwl_mvm *mvm,
1694 						    struct ieee80211_vif *vif);
1695 __le32 iwl_mvm_mac_ctxt_cmd_sta_get_twt_policy(struct iwl_mvm *mvm,
1696 					       struct ieee80211_vif *vif);
1697 int iwl_mvm_mld_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1698 int iwl_mvm_mld_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1699 				 bool force_assoc_off);
1700 int iwl_mvm_mld_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1701 int iwl_mvm_mac_ctxt_init(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1702 int iwl_mvm_mac_ctxt_add(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1703 int iwl_mvm_mac_ctxt_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1704 			     bool force_assoc_off, const u8 *bssid_override);
1705 int iwl_mvm_mac_ctxt_remove(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1706 int iwl_mvm_mac_ctxt_beacon_changed(struct iwl_mvm *mvm,
1707 				    struct ieee80211_vif *vif);
1708 int iwl_mvm_mac_ctxt_send_beacon(struct iwl_mvm *mvm,
1709 				 struct ieee80211_vif *vif,
1710 				 struct sk_buff *beacon);
1711 int iwl_mvm_mac_ctxt_send_beacon_cmd(struct iwl_mvm *mvm,
1712 				     struct sk_buff *beacon,
1713 				     void *data, int len);
1714 u8 iwl_mvm_mac_ctxt_get_beacon_rate(struct iwl_mvm *mvm,
1715 				    struct ieee80211_tx_info *info,
1716 				    struct ieee80211_vif *vif);
1717 u16 iwl_mvm_mac_ctxt_get_beacon_flags(const struct iwl_fw *fw,
1718 				      u8 rate_idx);
1719 void iwl_mvm_mac_ctxt_set_tim(struct iwl_mvm *mvm,
1720 			      __le32 *tim_index, __le32 *tim_size,
1721 			      u8 *beacon, u32 frame_size);
1722 void iwl_mvm_rx_beacon_notif(struct iwl_mvm *mvm,
1723 			     struct iwl_rx_cmd_buffer *rxb);
1724 void iwl_mvm_rx_missed_beacons_notif(struct iwl_mvm *mvm,
1725 				     struct iwl_rx_cmd_buffer *rxb);
1726 void iwl_mvm_rx_stored_beacon_notif(struct iwl_mvm *mvm,
1727 				    struct iwl_rx_cmd_buffer *rxb);
1728 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1729 			       struct iwl_rx_cmd_buffer *rxb);
1730 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1731 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1732 				 struct iwl_rx_cmd_buffer *rxb);
1733 void iwl_mvm_mac_ctxt_recalc_tsf_id(struct iwl_mvm *mvm,
1734 				    struct ieee80211_vif *vif);
1735 void iwl_mvm_probe_resp_data_notif(struct iwl_mvm *mvm,
1736 				   struct iwl_rx_cmd_buffer *rxb);
1737 void iwl_mvm_rx_missed_vap_notif(struct iwl_mvm *mvm,
1738 				 struct iwl_rx_cmd_buffer *rxb);
1739 void iwl_mvm_channel_switch_start_notif(struct iwl_mvm *mvm,
1740 					struct iwl_rx_cmd_buffer *rxb);
1741 void iwl_mvm_channel_switch_error_notif(struct iwl_mvm *mvm,
1742 					struct iwl_rx_cmd_buffer *rxb);
1743 /* Bindings */
1744 int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1745 int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1746 
1747 /* Links */
1748 int iwl_mvm_add_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1749 int iwl_mvm_link_changed(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1750 			 u32 changes, bool active);
1751 int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1752 
1753 /* Quota management */
1754 static inline size_t iwl_mvm_quota_cmd_size(struct iwl_mvm *mvm)
1755 {
1756 	return iwl_mvm_has_quota_low_latency(mvm) ?
1757 		sizeof(struct iwl_time_quota_cmd) :
1758 		sizeof(struct iwl_time_quota_cmd_v1);
1759 }
1760 
1761 static inline struct iwl_time_quota_data
1762 *iwl_mvm_quota_cmd_get_quota(struct iwl_mvm *mvm,
1763 			     struct iwl_time_quota_cmd *cmd,
1764 			     int i)
1765 {
1766 	struct iwl_time_quota_data_v1 *quotas;
1767 
1768 	if (iwl_mvm_has_quota_low_latency(mvm))
1769 		return &cmd->quotas[i];
1770 
1771 	quotas = (struct iwl_time_quota_data_v1 *)cmd->quotas;
1772 	return (struct iwl_time_quota_data *)&quotas[i];
1773 }
1774 
1775 int iwl_mvm_update_quotas(struct iwl_mvm *mvm, bool force_upload,
1776 			  struct ieee80211_vif *disabled_vif);
1777 
1778 /* Scanning */
1779 int iwl_mvm_reg_scan_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1780 			   struct cfg80211_scan_request *req,
1781 			   struct ieee80211_scan_ies *ies);
1782 size_t iwl_mvm_scan_size(struct iwl_mvm *mvm);
1783 int iwl_mvm_scan_stop(struct iwl_mvm *mvm, int type, bool notify);
1784 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm);
1785 void iwl_mvm_report_scan_aborted(struct iwl_mvm *mvm);
1786 void iwl_mvm_scan_timeout_wk(struct work_struct *work);
1787 
1788 /* Scheduled scan */
1789 void iwl_mvm_rx_lmac_scan_complete_notif(struct iwl_mvm *mvm,
1790 					 struct iwl_rx_cmd_buffer *rxb);
1791 void iwl_mvm_rx_lmac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1792 					      struct iwl_rx_cmd_buffer *rxb);
1793 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
1794 			     struct ieee80211_vif *vif,
1795 			     struct cfg80211_sched_scan_request *req,
1796 			     struct ieee80211_scan_ies *ies,
1797 			     int type);
1798 void iwl_mvm_rx_scan_match_found(struct iwl_mvm *mvm,
1799 				 struct iwl_rx_cmd_buffer *rxb);
1800 
1801 /* UMAC scan */
1802 int iwl_mvm_config_scan(struct iwl_mvm *mvm);
1803 void iwl_mvm_rx_umac_scan_complete_notif(struct iwl_mvm *mvm,
1804 					 struct iwl_rx_cmd_buffer *rxb);
1805 void iwl_mvm_rx_umac_scan_iter_complete_notif(struct iwl_mvm *mvm,
1806 					      struct iwl_rx_cmd_buffer *rxb);
1807 
1808 /* MVM debugfs */
1809 #ifdef CONFIG_IWLWIFI_DEBUGFS
1810 void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm);
1811 void iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1812 void iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1813 #else
1814 static inline void iwl_mvm_dbgfs_register(struct iwl_mvm *mvm)
1815 {
1816 }
1817 static inline void
1818 iwl_mvm_vif_dbgfs_register(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1819 {
1820 }
1821 static inline void
1822 iwl_mvm_vif_dbgfs_clean(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1823 {
1824 }
1825 #endif /* CONFIG_IWLWIFI_DEBUGFS */
1826 
1827 /* rate scaling */
1828 int iwl_mvm_send_lq_cmd(struct iwl_mvm *mvm, struct iwl_lq_cmd *lq);
1829 void iwl_mvm_update_frame_stats(struct iwl_mvm *mvm, u32 rate, bool agg);
1830 int rs_pretty_print_rate_v1(char *buf, int bufsz, const u32 rate);
1831 void rs_update_last_rssi(struct iwl_mvm *mvm,
1832 			 struct iwl_mvm_sta *mvmsta,
1833 			 struct ieee80211_rx_status *rx_status);
1834 
1835 /* power management */
1836 int iwl_mvm_power_update_device(struct iwl_mvm *mvm);
1837 int iwl_mvm_power_update_mac(struct iwl_mvm *mvm);
1838 int iwl_mvm_power_update_ps(struct iwl_mvm *mvm);
1839 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1840 				 char *buf, int bufsz);
1841 
1842 void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
1843 void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
1844 					      struct iwl_rx_cmd_buffer *rxb);
1845 
1846 #ifdef CONFIG_IWLWIFI_LEDS
1847 int iwl_mvm_leds_init(struct iwl_mvm *mvm);
1848 void iwl_mvm_leds_exit(struct iwl_mvm *mvm);
1849 void iwl_mvm_leds_sync(struct iwl_mvm *mvm);
1850 #else
1851 static inline int iwl_mvm_leds_init(struct iwl_mvm *mvm)
1852 {
1853 	return 0;
1854 }
1855 static inline void iwl_mvm_leds_exit(struct iwl_mvm *mvm)
1856 {
1857 }
1858 static inline void iwl_mvm_leds_sync(struct iwl_mvm *mvm)
1859 {
1860 }
1861 #endif
1862 
1863 /* D3 (WoWLAN, NetDetect) */
1864 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
1865 int iwl_mvm_resume(struct ieee80211_hw *hw);
1866 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled);
1867 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
1868 			    struct ieee80211_vif *vif,
1869 			    struct cfg80211_gtk_rekey_data *data);
1870 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
1871 			      struct ieee80211_vif *vif,
1872 			      struct inet6_dev *idev);
1873 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
1874 				     struct ieee80211_vif *vif, int idx);
1875 extern const struct file_operations iwl_dbgfs_d3_test_ops;
1876 #ifdef CONFIG_PM
1877 void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm,
1878 				 struct ieee80211_vif *vif);
1879 #else
1880 static inline void
1881 iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1882 {
1883 }
1884 #endif
1885 void iwl_mvm_set_wowlan_qos_seq(struct iwl_mvm_sta *mvm_ap_sta,
1886 				struct iwl_wowlan_config_cmd *cmd);
1887 int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm,
1888 			       struct ieee80211_vif *vif,
1889 			       bool disable_offloading,
1890 			       bool offload_ns,
1891 			       u32 cmd_flags);
1892 
1893 /* BT Coex */
1894 int iwl_mvm_send_bt_init_conf(struct iwl_mvm *mvm);
1895 void iwl_mvm_rx_bt_coex_notif(struct iwl_mvm *mvm,
1896 			      struct iwl_rx_cmd_buffer *rxb);
1897 void iwl_mvm_bt_rssi_event(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1898 			   enum ieee80211_rssi_event_data);
1899 void iwl_mvm_bt_coex_vif_change(struct iwl_mvm *mvm);
1900 u16 iwl_mvm_coex_agg_time_limit(struct iwl_mvm *mvm,
1901 				struct ieee80211_sta *sta);
1902 bool iwl_mvm_bt_coex_is_mimo_allowed(struct iwl_mvm *mvm,
1903 				     struct ieee80211_sta *sta);
1904 bool iwl_mvm_bt_coex_is_ant_avail(struct iwl_mvm *mvm, u8 ant);
1905 bool iwl_mvm_bt_coex_is_shared_ant_avail(struct iwl_mvm *mvm);
1906 bool iwl_mvm_bt_coex_is_tpc_allowed(struct iwl_mvm *mvm,
1907 				    enum nl80211_band band);
1908 u8 iwl_mvm_bt_coex_get_single_ant_msk(struct iwl_mvm *mvm, u8 enabled_ants);
1909 u8 iwl_mvm_bt_coex_tx_prio(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
1910 			   struct ieee80211_tx_info *info, u8 ac);
1911 
1912 /* beacon filtering */
1913 #ifdef CONFIG_IWLWIFI_DEBUGFS
1914 void
1915 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1916 					 struct iwl_beacon_filter_cmd *cmd);
1917 #else
1918 static inline void
1919 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
1920 					 struct iwl_beacon_filter_cmd *cmd)
1921 {}
1922 #endif
1923 int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
1924 				 struct ieee80211_vif *vif,
1925 				 u32 flags);
1926 int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
1927 				  struct ieee80211_vif *vif,
1928 				  u32 flags);
1929 /* SMPS */
1930 void iwl_mvm_update_smps(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1931 				enum iwl_mvm_smps_type_request req_type,
1932 				enum ieee80211_smps_mode smps_request);
1933 bool iwl_mvm_rx_diversity_allowed(struct iwl_mvm *mvm,
1934 				  struct iwl_mvm_phy_ctxt *ctxt);
1935 void iwl_mvm_apply_fw_smps_request(struct ieee80211_vif *vif);
1936 
1937 /* Low latency */
1938 int iwl_mvm_update_low_latency(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1939 			      bool low_latency,
1940 			      enum iwl_mvm_low_latency_cause cause);
1941 /* get SystemLowLatencyMode - only needed for beacon threshold? */
1942 bool iwl_mvm_low_latency(struct iwl_mvm *mvm);
1943 bool iwl_mvm_low_latency_band(struct iwl_mvm *mvm, enum nl80211_band band);
1944 void iwl_mvm_send_low_latency_cmd(struct iwl_mvm *mvm, bool low_latency,
1945 				  u16 mac_id);
1946 
1947 /* get VMACLowLatencyMode */
1948 static inline bool iwl_mvm_vif_low_latency(struct iwl_mvm_vif *mvmvif)
1949 {
1950 	/*
1951 	 * should this consider associated/active/... state?
1952 	 *
1953 	 * Normally low-latency should only be active on interfaces
1954 	 * that are active, but at least with debugfs it can also be
1955 	 * enabled on interfaces that aren't active. However, when
1956 	 * interface aren't active then they aren't added into the
1957 	 * binding, so this has no real impact. For now, just return
1958 	 * the current desired low-latency state.
1959 	 */
1960 	return mvmvif->low_latency_actual;
1961 }
1962 
1963 static inline
1964 void iwl_mvm_vif_set_low_latency(struct iwl_mvm_vif *mvmvif, bool set,
1965 				 enum iwl_mvm_low_latency_cause cause)
1966 {
1967 	u8 new_state;
1968 
1969 	if (set)
1970 		mvmvif->low_latency |= cause;
1971 	else
1972 		mvmvif->low_latency &= ~cause;
1973 
1974 	/*
1975 	 * if LOW_LATENCY_DEBUGFS_FORCE_ENABLE is enabled no changes are
1976 	 * allowed to actual mode.
1977 	 */
1978 	if (mvmvif->low_latency & LOW_LATENCY_DEBUGFS_FORCE_ENABLE &&
1979 	    cause != LOW_LATENCY_DEBUGFS_FORCE_ENABLE)
1980 		return;
1981 
1982 	if (cause == LOW_LATENCY_DEBUGFS_FORCE_ENABLE && set)
1983 		/*
1984 		 * We enter force state
1985 		 */
1986 		new_state = !!(mvmvif->low_latency &
1987 			       LOW_LATENCY_DEBUGFS_FORCE);
1988 	else
1989 		/*
1990 		 * Check if any other one set low latency
1991 		 */
1992 		new_state = !!(mvmvif->low_latency &
1993 				  ~(LOW_LATENCY_DEBUGFS_FORCE_ENABLE |
1994 				    LOW_LATENCY_DEBUGFS_FORCE));
1995 
1996 	mvmvif->low_latency_actual = new_state;
1997 }
1998 
1999 /* Return a bitmask with all the hw supported queues, except for the
2000  * command queue, which can't be flushed.
2001  */
2002 static inline u32 iwl_mvm_flushable_queues(struct iwl_mvm *mvm)
2003 {
2004 	return ((BIT(mvm->trans->trans_cfg->base_params->num_of_queues) - 1) &
2005 		~BIT(IWL_MVM_DQA_CMD_QUEUE));
2006 }
2007 
2008 void iwl_mvm_stop_device(struct iwl_mvm *mvm);
2009 
2010 /* Thermal management and CT-kill */
2011 void iwl_mvm_tt_tx_backoff(struct iwl_mvm *mvm, u32 backoff);
2012 void iwl_mvm_temp_notif(struct iwl_mvm *mvm,
2013 			struct iwl_rx_cmd_buffer *rxb);
2014 void iwl_mvm_tt_handler(struct iwl_mvm *mvm);
2015 void iwl_mvm_thermal_initialize(struct iwl_mvm *mvm, u32 min_backoff);
2016 void iwl_mvm_thermal_exit(struct iwl_mvm *mvm);
2017 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state);
2018 int iwl_mvm_get_temp(struct iwl_mvm *mvm, s32 *temp);
2019 void iwl_mvm_ct_kill_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2020 void iwl_mvm_enter_ctkill(struct iwl_mvm *mvm);
2021 int iwl_mvm_send_temp_report_ths_cmd(struct iwl_mvm *mvm);
2022 int iwl_mvm_ctdp_command(struct iwl_mvm *mvm, u32 op, u32 budget);
2023 
2024 #if IS_ENABLED(CONFIG_IWLMEI)
2025 
2026 /* vendor commands */
2027 void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm);
2028 
2029 #else
2030 
2031 static inline void iwl_mvm_vendor_cmds_register(struct iwl_mvm *mvm) {}
2032 
2033 #endif
2034 
2035 /* Location Aware Regulatory */
2036 struct iwl_mcc_update_resp *
2037 iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
2038 		   enum iwl_mcc_source src_id);
2039 int iwl_mvm_init_mcc(struct iwl_mvm *mvm);
2040 void iwl_mvm_rx_chub_update_mcc(struct iwl_mvm *mvm,
2041 				struct iwl_rx_cmd_buffer *rxb);
2042 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
2043 						  const char *alpha2,
2044 						  enum iwl_mcc_source src_id,
2045 						  bool *changed);
2046 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
2047 							  bool *changed);
2048 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm);
2049 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm);
2050 
2051 /* smart fifo */
2052 int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2053 		      bool added_vif);
2054 
2055 /* FTM responder */
2056 int iwl_mvm_ftm_start_responder(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2057 void iwl_mvm_ftm_restart_responder(struct iwl_mvm *mvm,
2058 				   struct ieee80211_vif *vif);
2059 void iwl_mvm_ftm_responder_stats(struct iwl_mvm *mvm,
2060 				 struct iwl_rx_cmd_buffer *rxb);
2061 int iwl_mvm_ftm_resp_remove_pasn_sta(struct iwl_mvm *mvm,
2062 				     struct ieee80211_vif *vif, u8 *addr);
2063 int iwl_mvm_ftm_respoder_add_pasn_sta(struct iwl_mvm *mvm,
2064 				      struct ieee80211_vif *vif,
2065 				      u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2066 				      u8 *hltk, u32 hltk_len);
2067 void iwl_mvm_ftm_responder_clear(struct iwl_mvm *mvm,
2068 				 struct ieee80211_vif *vif);
2069 
2070 /* FTM initiator */
2071 void iwl_mvm_ftm_restart(struct iwl_mvm *mvm);
2072 void iwl_mvm_ftm_range_resp(struct iwl_mvm *mvm,
2073 			    struct iwl_rx_cmd_buffer *rxb);
2074 void iwl_mvm_ftm_lc_notif(struct iwl_mvm *mvm,
2075 			  struct iwl_rx_cmd_buffer *rxb);
2076 int iwl_mvm_ftm_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2077 		      struct cfg80211_pmsr_request *request);
2078 void iwl_mvm_ftm_abort(struct iwl_mvm *mvm, struct cfg80211_pmsr_request *req);
2079 void iwl_mvm_ftm_initiator_smooth_config(struct iwl_mvm *mvm);
2080 void iwl_mvm_ftm_initiator_smooth_stop(struct iwl_mvm *mvm);
2081 int iwl_mvm_ftm_add_pasn_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2082 			     u8 *addr, u32 cipher, u8 *tk, u32 tk_len,
2083 			     u8 *hltk, u32 hltk_len);
2084 void iwl_mvm_ftm_remove_pasn_sta(struct iwl_mvm *mvm, u8 *addr);
2085 
2086 /* TDLS */
2087 
2088 /*
2089  * We use TID 4 (VI) as a FW-used-only TID when TDLS connections are present.
2090  * This TID is marked as used vs the AP and all connected TDLS peers.
2091  */
2092 #define IWL_MVM_TDLS_FW_TID 4
2093 
2094 int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2095 void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm);
2096 void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2097 			       bool sta_added);
2098 void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2099 					   struct ieee80211_vif *vif);
2100 int iwl_mvm_tdls_channel_switch(struct ieee80211_hw *hw,
2101 				struct ieee80211_vif *vif,
2102 				struct ieee80211_sta *sta, u8 oper_class,
2103 				struct cfg80211_chan_def *chandef,
2104 				struct sk_buff *tmpl_skb, u32 ch_sw_tm_ie);
2105 void iwl_mvm_tdls_recv_channel_switch(struct ieee80211_hw *hw,
2106 				      struct ieee80211_vif *vif,
2107 				      struct ieee80211_tdls_ch_sw_params *params);
2108 void iwl_mvm_tdls_cancel_channel_switch(struct ieee80211_hw *hw,
2109 					struct ieee80211_vif *vif,
2110 					struct ieee80211_sta *sta);
2111 void iwl_mvm_rx_tdls_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
2112 void iwl_mvm_tdls_ch_switch_work(struct work_struct *work);
2113 
2114 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
2115 				     enum iwl_mvm_rxq_notif_type type,
2116 				     bool sync,
2117 				     const void *data, u32 size);
2118 void iwl_mvm_reorder_timer_expired(struct timer_list *t);
2119 struct ieee80211_vif *iwl_mvm_get_bss_vif(struct iwl_mvm *mvm);
2120 struct ieee80211_vif *iwl_mvm_get_vif_by_macid(struct iwl_mvm *mvm, u32 macid);
2121 bool iwl_mvm_is_vif_assoc(struct iwl_mvm *mvm);
2122 
2123 #define MVM_TCM_PERIOD_MSEC 500
2124 #define MVM_TCM_PERIOD (HZ * MVM_TCM_PERIOD_MSEC / 1000)
2125 #define MVM_LL_PERIOD (10 * HZ)
2126 void iwl_mvm_tcm_work(struct work_struct *work);
2127 void iwl_mvm_recalc_tcm(struct iwl_mvm *mvm);
2128 void iwl_mvm_pause_tcm(struct iwl_mvm *mvm, bool with_cancel);
2129 void iwl_mvm_resume_tcm(struct iwl_mvm *mvm);
2130 void iwl_mvm_tcm_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2131 void iwl_mvm_tcm_rm_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
2132 u8 iwl_mvm_tcm_load_percentage(u32 airtime, u32 elapsed);
2133 
2134 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error);
2135 unsigned int iwl_mvm_get_wd_timeout(struct iwl_mvm *mvm,
2136 				    struct ieee80211_vif *vif,
2137 				    bool tdls, bool cmd_q);
2138 void iwl_mvm_connection_loss(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2139 			     const char *errmsg);
2140 void iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
2141 					  struct ieee80211_vif *vif,
2142 					  const struct ieee80211_sta *sta,
2143 					  u16 tid);
2144 
2145 void iwl_mvm_ptp_init(struct iwl_mvm *mvm);
2146 void iwl_mvm_ptp_remove(struct iwl_mvm *mvm);
2147 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b);
2148 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm);
2149 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm);
2150 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm);
2151 #ifdef CONFIG_IWLWIFI_DEBUGFS
2152 void iwl_mvm_sta_add_debugfs(struct ieee80211_hw *hw,
2153 			     struct ieee80211_vif *vif,
2154 			     struct ieee80211_sta *sta,
2155 			     struct dentry *dir);
2156 #endif
2157 
2158 /* new MLD related APIs */
2159 int iwl_mvm_sec_key_add(struct iwl_mvm *mvm,
2160 			struct ieee80211_vif *vif,
2161 			struct ieee80211_sta *sta,
2162 			struct ieee80211_key_conf *keyconf);
2163 int iwl_mvm_sec_key_del(struct iwl_mvm *mvm,
2164 			struct ieee80211_vif *vif,
2165 			struct ieee80211_sta *sta,
2166 			struct ieee80211_key_conf *keyconf);
2167 void iwl_mvm_sec_key_remove_ap(struct iwl_mvm *mvm,
2168 			       struct ieee80211_vif *vif);
2169 
2170 int iwl_rfi_send_config_cmd(struct iwl_mvm *mvm,
2171 			    struct iwl_rfi_lut_entry *rfi_table);
2172 struct iwl_rfi_freq_table_resp_cmd *iwl_rfi_get_freq_table(struct iwl_mvm *mvm);
2173 void iwl_rfi_deactivate_notif_handler(struct iwl_mvm *mvm,
2174 				      struct iwl_rx_cmd_buffer *rxb);
2175 
2176 static inline u8 iwl_mvm_phy_band_from_nl80211(enum nl80211_band band)
2177 {
2178 	switch (band) {
2179 	case NL80211_BAND_2GHZ:
2180 		return PHY_BAND_24;
2181 	case NL80211_BAND_5GHZ:
2182 		return PHY_BAND_5;
2183 	case NL80211_BAND_6GHZ:
2184 		return PHY_BAND_6;
2185 	default:
2186 		WARN_ONCE(1, "Unsupported band (%u)\n", band);
2187 		return PHY_BAND_5;
2188 	}
2189 }
2190 
2191 /* Channel Switch */
2192 void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk);
2193 
2194 /* Channel Context */
2195 bool __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm,
2196 					 struct ieee80211_vif *vif,
2197 					 struct ieee80211_chanctx_conf *ctx,
2198 					 bool switching_chanctx, int *ret);
2199 bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm,
2200 					   struct ieee80211_vif *vif,
2201 					   bool switching_chanctx);
2202 
2203 /* Channel info utils */
2204 static inline bool iwl_mvm_has_ultra_hb_channel(struct iwl_mvm *mvm)
2205 {
2206 	return fw_has_capa(&mvm->fw->ucode_capa,
2207 			   IWL_UCODE_TLV_CAPA_ULTRA_HB_CHANNELS);
2208 }
2209 
2210 static inline void *iwl_mvm_chan_info_cmd_tail(struct iwl_mvm *mvm,
2211 					       struct iwl_fw_channel_info *ci)
2212 {
2213 	return (u8 *)ci + (iwl_mvm_has_ultra_hb_channel(mvm) ?
2214 			   sizeof(struct iwl_fw_channel_info) :
2215 			   sizeof(struct iwl_fw_channel_info_v1));
2216 }
2217 
2218 static inline size_t iwl_mvm_chan_info_padding(struct iwl_mvm *mvm)
2219 {
2220 	return iwl_mvm_has_ultra_hb_channel(mvm) ? 0 :
2221 		sizeof(struct iwl_fw_channel_info) -
2222 		sizeof(struct iwl_fw_channel_info_v1);
2223 }
2224 
2225 static inline void iwl_mvm_set_chan_info(struct iwl_mvm *mvm,
2226 					 struct iwl_fw_channel_info *ci,
2227 					 u32 chan, u8 band, u8 width,
2228 					 u8 ctrl_pos)
2229 {
2230 	if (iwl_mvm_has_ultra_hb_channel(mvm)) {
2231 		ci->channel = cpu_to_le32(chan);
2232 		ci->band = band;
2233 		ci->width = width;
2234 		ci->ctrl_pos = ctrl_pos;
2235 	} else {
2236 		struct iwl_fw_channel_info_v1 *ci_v1 =
2237 					(struct iwl_fw_channel_info_v1 *)ci;
2238 
2239 		ci_v1->channel = chan;
2240 		ci_v1->band = band;
2241 		ci_v1->width = width;
2242 		ci_v1->ctrl_pos = ctrl_pos;
2243 	}
2244 }
2245 
2246 static inline void
2247 iwl_mvm_set_chan_info_chandef(struct iwl_mvm *mvm,
2248 			      struct iwl_fw_channel_info *ci,
2249 			      struct cfg80211_chan_def *chandef)
2250 {
2251 	enum nl80211_band band = chandef->chan->band;
2252 
2253 	iwl_mvm_set_chan_info(mvm, ci, chandef->chan->hw_value,
2254 			      iwl_mvm_phy_band_from_nl80211(band),
2255 			      iwl_mvm_get_channel_width(chandef),
2256 			      iwl_mvm_get_ctrl_pos(chandef));
2257 }
2258 
2259 static inline int iwl_umac_scan_get_max_profiles(const struct iwl_fw *fw)
2260 {
2261 	u8 ver = iwl_fw_lookup_cmd_ver(fw, SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
2262 				       IWL_FW_CMD_VER_UNKNOWN);
2263 	return (ver == IWL_FW_CMD_VER_UNKNOWN || ver < 3) ?
2264 		IWL_SCAN_MAX_PROFILES : IWL_SCAN_MAX_PROFILES_V2;
2265 }
2266 
2267 static inline
2268 enum iwl_location_cipher iwl_mvm_cipher_to_location_cipher(u32 cipher)
2269 {
2270 	switch (cipher) {
2271 	case WLAN_CIPHER_SUITE_CCMP:
2272 		return IWL_LOCATION_CIPHER_CCMP_128;
2273 	case WLAN_CIPHER_SUITE_GCMP:
2274 		return IWL_LOCATION_CIPHER_GCMP_128;
2275 	case WLAN_CIPHER_SUITE_GCMP_256:
2276 		return IWL_LOCATION_CIPHER_GCMP_256;
2277 	default:
2278 		return IWL_LOCATION_CIPHER_INVALID;
2279 	}
2280 }
2281 
2282 struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm);
2283 static inline int iwl_mvm_mei_get_ownership(struct iwl_mvm *mvm)
2284 {
2285 	if (mvm->mei_registered)
2286 		return iwl_mei_get_ownership();
2287 	return 0;
2288 }
2289 
2290 static inline void iwl_mvm_mei_tx_copy_to_csme(struct iwl_mvm *mvm,
2291 					       struct sk_buff *skb,
2292 					       unsigned int ivlen)
2293 {
2294 	if (mvm->mei_registered)
2295 		iwl_mei_tx_copy_to_csme(skb, ivlen);
2296 }
2297 
2298 static inline void iwl_mvm_mei_host_disassociated(struct iwl_mvm *mvm)
2299 {
2300 	if (mvm->mei_registered)
2301 		iwl_mei_host_disassociated();
2302 }
2303 
2304 static inline void iwl_mvm_mei_device_state(struct iwl_mvm *mvm, bool up)
2305 {
2306 	if (mvm->mei_registered)
2307 		iwl_mei_device_state(up);
2308 }
2309 
2310 static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm)
2311 {
2312 	bool sw_rfkill =
2313 		mvm->hw_registered ? rfkill_soft_blocked(mvm->hw->wiphy->rfkill) : false;
2314 
2315 	if (mvm->mei_registered)
2316 		iwl_mei_set_rfkill_state(iwl_mvm_is_radio_killed(mvm),
2317 					 sw_rfkill);
2318 }
2319 
2320 void iwl_mvm_send_roaming_forbidden_event(struct iwl_mvm *mvm,
2321 					  struct ieee80211_vif *vif,
2322 					  bool forbidden);
2323 
2324 #endif /* __IWL_MVM_H__ */
2325