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