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