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