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