xref: /linux/drivers/net/wireless/intel/iwlwifi/mld/mld.h (revision 8be4d31cb8aaeea27bde4b7ddb26e28a89062ebf)
1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2024-2025 Intel Corporation
4  */
5 #ifndef __iwl_mld_h__
6 #define __iwl_mld_h__
7 
8 #include <linux/leds.h>
9 #include <net/mac80211.h>
10 
11 #include "iwl-trans.h"
12 #include "iwl-op-mode.h"
13 #include "fw/runtime.h"
14 #include "fw/notif-wait.h"
15 #include "fw/api/commands.h"
16 #include "fw/api/scan.h"
17 #include "fw/api/mac-cfg.h"
18 #include "fw/api/mac.h"
19 #include "fw/api/phy-ctxt.h"
20 #include "fw/api/datapath.h"
21 #include "fw/api/rx.h"
22 #include "fw/api/rs.h"
23 #include "fw/api/context.h"
24 #include "fw/api/coex.h"
25 #include "fw/api/location.h"
26 
27 #include "fw/dbg.h"
28 
29 #include "notif.h"
30 #include "scan.h"
31 #include "rx.h"
32 #include "thermal.h"
33 #include "low_latency.h"
34 #include "constants.h"
35 #include "ptp.h"
36 #include "time_sync.h"
37 #include "ftm-initiator.h"
38 
39 /**
40  * DOC: Introduction
41  *
42  * iwlmld is an operation mode (a.k.a. op_mode) for Intel wireless devices.
43  * It is used for devices that ship after 2024 which typically support
44  * the WiFi-7 features. MLD stands for multi-link device. Note that there are
45  * devices that do not support WiFi-7 or even WiFi 6E and yet use iwlmld, but
46  * the firmware APIs used in this driver are WiFi-7 compatible.
47  *
48  * In the architecture of iwlwifi, an op_mode is a layer that translates
49  * mac80211's APIs into commands for the firmware and, of course, notifications
50  * from the firmware to mac80211's APIs. An op_mode must implement the
51  * interface defined in iwl-op-mode.h to interact with the transport layer
52  * which allows to send and receive data to the device, start the hardware,
53  * etc...
54  */
55 
56 /**
57  * DOC: Locking policy
58  *
59  * iwlmld has a very simple locking policy: it doesn't have any mutexes. It
60  * relies on cfg80211's wiphy->mtx and takes the lock when needed. All the
61  * control flows originating from mac80211 already acquired the lock, so that
62  * part is trivial, but also notifications that are received from the firmware
63  * and handled asynchronously are handled only after having taken the lock.
64  * This is described in notif.c.
65  * There are spin_locks needed to synchronize with the data path, around the
66  * allocation of the queues, for example.
67  */
68 
69 /**
70  * DOC: Debugfs
71  *
72  * iwlmld adds its share of debugfs hooks and its handlers are synchronized
73  * with the wiphy_lock using wiphy_locked_debugfs. This avoids races against
74  * resources deletion while the debugfs hook is being used.
75  */
76 
77 /**
78  * DOC: Main resources
79  *
80  * iwlmld is designed with the life cycle of the resource in mind. The
81  * resources are:
82  *
83  *  - struct iwl_mld (matches mac80211's struct ieee80211_hw)
84  *
85  *  - struct iwl_mld_vif (matches macu80211's struct ieee80211_vif)
86  *    iwl_mld_vif contains an array of pointers to struct iwl_mld_link
87  *    which describe the links for this vif.
88  *
89  *  - struct iwl_mld_sta (matches mac80211's struct ieee80211_sta)
90  *    iwl_mld_sta contains an array of points to struct iwl_mld_link_sta
91  *    which describes the link stations for this station
92  *
93  * Each object has properties that can survive a firmware reset or not.
94  * Asynchronous firmware notifications can declare themselves as dependent on a
95  * certain instance of those resources and that means that the notifications
96  * will be cancelled once the instance is destroyed.
97  */
98 
99 #define IWL_MLD_MAX_ADDRESSES		5
100 
101 /**
102  * struct iwl_mld - MLD op mode
103  *
104  * @fw_id_to_bss_conf: maps a fw id of a link to the corresponding
105  *	ieee80211_bss_conf.
106  * @fw_id_to_vif: maps a fw id of a MAC context to the corresponding
107  *	ieee80211_vif. Mapping is valid only when the MAC exists in the fw.
108  * @fw_id_to_txq: maps a fw id of a txq to the corresponding
109  *	ieee80211_txq.
110  * @used_phy_ids: a bitmap of the phy IDs used. If a bit is set, it means
111  *	that the index of this bit is already used as a PHY id.
112  * @num_igtks: the number if iGTKs that were sent to the FW.
113  * @monitor: monitor related data
114  * @monitor.on: does a monitor vif exist (singleton hence bool)
115  * @monitor.ampdu_ref: the id of the A-MPDU for sniffer
116  * @monitor.ampdu_toggle: the state of the previous packet to track A-MPDU
117  * @monitor.cur_aid: current association id tracked by the sniffer
118  * @monitor.cur_bssid: current bssid tracked by the sniffer
119  * @monitor.ptp_time: set the Rx mactime using the device's PTP clock time
120  * @monitor.p80: primary channel position relative to he whole bandwidth, in
121  * steps of 80 MHz
122  * @fw_id_to_link_sta: maps a fw id of a sta to the corresponding
123  *	ieee80211_link_sta. This is not cleaned up on restart since we want to
124  *	preserve the fw sta ids during a restart (for SN/PN restoring).
125  *	FW ids of internal stations will be mapped to ERR_PTR, and will be
126  *	re-allocated during a restart, so make sure to free it in restart
127  *	cleanup using iwl_mld_free_internal_sta
128  * @netdetect: indicates the FW is in suspend mode with netdetect configured
129  * @p2p_device_vif: points to the p2p device vif if exists
130  * @bt_is_active: indicates that BT is active
131  * @dev: pointer to device struct. For printing purposes
132  * @trans: pointer to the transport layer
133  * @cfg: pointer to the device configuration
134  * @fw: a pointer to the fw object
135  * @hw: pointer to the hw object.
136  * @wiphy: a pointer to the wiphy struct, for easier access to it.
137  * @nvm_data: pointer to the nvm_data that includes all our capabilities
138  * @fwrt: fw runtime data
139  * @debugfs_dir: debugfs directory
140  * @notif_wait: notification wait related data.
141  * @async_handlers_list: a list of all async RX handlers. When a notifciation
142  *	with an async handler is received, it is added to this list.
143  *	When &async_handlers_wk runs - it runs these handlers one by one.
144  * @async_handlers_lock: a lock for &async_handlers_list. Sync
145  *	&async_handlers_wk and RX notifcation path.
146  * @async_handlers_wk: A work to run all async RX handlers from
147  *	&async_handlers_list.
148  * @ct_kill_exit_wk: worker to exit thermal kill
149  * @fw_status: bitmap of fw status bits
150  * @running: true if the firmware is running
151  * @do_not_dump_once: true if firmware dump must be prevented once
152  * @in_d3: indicates FW is in suspend mode and should be resumed
153  * @resuming: indicates the driver is resuming from wowlan
154  * @in_hw_restart: indicates that we are currently in restart flow.
155  *	rather than restarted. Should be unset upon restart.
156  * @radio_kill: bitmap of radio kill status
157  * @radio_kill.hw: radio is killed by hw switch
158  * @radio_kill.ct: radio is killed because the device it too hot
159  * @power_budget_mw: maximum cTDP power budget as defined for this system and
160  *	device
161  * @addresses: device MAC addresses.
162  * @scan: instance of the scan object
163  * @channel_survey: channel survey information collected during scan
164  * @wowlan: WoWLAN support data.
165  * @debug_max_sleep: maximum sleep time in D3 (for debug purposes)
166  * @led: the led device
167  * @mcc_src: the source id of the MCC, comes from the firmware
168  * @bios_enable_puncturing: is puncturing enabled by bios
169  * @fw_id_to_ba: maps a fw (BA) id to a corresponding Block Ack session data.
170  * @num_rx_ba_sessions: tracks the number of active Rx Block Ack (BA) sessions.
171  *	the driver ensures that new BA sessions are blocked once the maximum
172  *	supported by the firmware is reached, preventing firmware asserts.
173  * @rxq_sync: manages RX queue sync state
174  * @txqs_to_add: a list of &ieee80211_txq's to allocate in &add_txqs_wk
175  * @add_txqs_wk: a worker to allocate txqs.
176  * @add_txqs_lock: to lock the &txqs_to_add list.
177  * @error_recovery_buf: pointer to the recovery buffer that will be read
178  *	from firmware upon fw/hw error and sent back to the firmware in
179  *	reconfig flow (after NIC reset).
180  * @mcast_filter_cmd: pointer to the multicast filter command.
181  * @mgmt_tx_ant: stores the last TX antenna index; used for setting
182  *	TX rate_n_flags for non-STA mgmt frames (toggles on every TX failure).
183  * @fw_rates_ver_3: FW rates are in version 3
184  * @low_latency: low-latency manager.
185  * @tzone: thermal zone device's data
186  * @cooling_dev: cooling device's related data
187  * @ibss_manager: in IBSS mode (only one vif can be active), indicates what
188  *	firmware indicated about having transmitted the last beacon, i.e.
189  *	being IBSS manager for that time and needing to respond to probe
190  *	requests
191  * @ptp_data: data of the PTP clock
192  * @time_sync: time sync data.
193  * @ftm_initiator: FTM initiator data
194  */
195 struct iwl_mld {
196 	/* Add here fields that need clean up on restart */
197 	struct_group(zeroed_on_hw_restart,
198 		struct ieee80211_bss_conf __rcu *fw_id_to_bss_conf[IWL_FW_MAX_LINK_ID + 1];
199 		struct ieee80211_vif __rcu *fw_id_to_vif[NUM_MAC_INDEX_DRIVER];
200 		struct ieee80211_txq __rcu *fw_id_to_txq[IWL_MAX_TVQM_QUEUES];
201 		u8 used_phy_ids: NUM_PHY_CTX;
202 		u8 num_igtks;
203 		struct {
204 			bool on;
205 			u32 ampdu_ref;
206 			bool ampdu_toggle;
207 			u8 p80;
208 #ifdef CONFIG_IWLWIFI_DEBUGFS
209 			__le16 cur_aid;
210 			u8 cur_bssid[ETH_ALEN];
211 			bool ptp_time;
212 #endif
213 		} monitor;
214 #ifdef CONFIG_PM_SLEEP
215 		bool netdetect;
216 #endif /* CONFIG_PM_SLEEP */
217 		struct ieee80211_vif *p2p_device_vif;
218 		bool bt_is_active;
219 	);
220 	struct ieee80211_link_sta __rcu *fw_id_to_link_sta[IWL_STATION_COUNT_MAX];
221 	/* And here fields that survive a fw restart */
222 	struct device *dev;
223 	struct iwl_trans *trans;
224 	const struct iwl_rf_cfg *cfg;
225 	const struct iwl_fw *fw;
226 	struct ieee80211_hw *hw;
227 	struct wiphy *wiphy;
228 	struct iwl_nvm_data *nvm_data;
229 	struct iwl_fw_runtime fwrt;
230 	struct dentry *debugfs_dir;
231 	struct iwl_notif_wait_data notif_wait;
232 	struct list_head async_handlers_list;
233 	spinlock_t async_handlers_lock;
234 	struct wiphy_work async_handlers_wk;
235 	struct wiphy_delayed_work ct_kill_exit_wk;
236 
237 	struct {
238 		u32 running:1,
239 		    do_not_dump_once:1,
240 #ifdef CONFIG_PM_SLEEP
241 		    in_d3:1,
242 		    resuming:1,
243 #endif
244 		    in_hw_restart:1;
245 
246 	} fw_status;
247 
248 	struct {
249 		u32 hw:1,
250 		    ct:1;
251 	} radio_kill;
252 
253 	u32 power_budget_mw;
254 
255 	struct mac_address addresses[IWL_MLD_MAX_ADDRESSES];
256 	struct iwl_mld_scan scan;
257 	struct iwl_mld_survey *channel_survey;
258 #ifdef CONFIG_PM_SLEEP
259 	struct wiphy_wowlan_support wowlan;
260 	u32 debug_max_sleep;
261 #endif /* CONFIG_PM_SLEEP */
262 #ifdef CONFIG_IWLWIFI_LEDS
263 	struct led_classdev led;
264 #endif
265 	enum iwl_mcc_source mcc_src;
266 	bool bios_enable_puncturing;
267 
268 	struct iwl_mld_baid_data __rcu *fw_id_to_ba[IWL_MAX_BAID];
269 	u8 num_rx_ba_sessions;
270 
271 	struct iwl_mld_rx_queues_sync rxq_sync;
272 
273 	struct list_head txqs_to_add;
274 	struct wiphy_work add_txqs_wk;
275 	spinlock_t add_txqs_lock;
276 
277 	u8 *error_recovery_buf;
278 	struct iwl_mcast_filter_cmd *mcast_filter_cmd;
279 
280 	u8 mgmt_tx_ant;
281 
282 	bool fw_rates_ver_3;
283 
284 	struct iwl_mld_low_latency low_latency;
285 
286 	bool ibss_manager;
287 #ifdef CONFIG_THERMAL
288 	struct thermal_zone_device *tzone;
289 	struct iwl_mld_cooling_device cooling_dev;
290 #endif
291 
292 	struct ptp_data ptp_data;
293 
294 	struct iwl_mld_time_sync_data __rcu *time_sync;
295 
296 	struct ftm_initiator_data ftm_initiator;
297 };
298 
299 /* memset the part of the struct that requires cleanup on restart */
300 #define CLEANUP_STRUCT(_ptr)                             \
301 	memset((void *)&(_ptr)->zeroed_on_hw_restart, 0, \
302 	       sizeof((_ptr)->zeroed_on_hw_restart))
303 
304 /* Cleanup function for struct iwl_mld, will be called in restart */
305 static inline void
iwl_cleanup_mld(struct iwl_mld * mld)306 iwl_cleanup_mld(struct iwl_mld *mld)
307 {
308 	CLEANUP_STRUCT(mld);
309 	CLEANUP_STRUCT(&mld->scan);
310 
311 #ifdef CONFIG_PM_SLEEP
312 	mld->fw_status.in_d3 = false;
313 #endif
314 
315 	iwl_mld_low_latency_restart_cleanup(mld);
316 }
317 
318 enum iwl_power_scheme {
319 	IWL_POWER_SCHEME_CAM = 1,
320 	IWL_POWER_SCHEME_BPS,
321 };
322 
323 /**
324  * struct iwl_mld_mod_params - module parameters for iwlmld
325  * @power_scheme: one of enum iwl_power_scheme
326  */
327 struct iwl_mld_mod_params {
328 	int power_scheme;
329 };
330 
331 extern struct iwl_mld_mod_params iwlmld_mod_params;
332 
333 /* Extract MLD priv from op_mode */
334 #define IWL_OP_MODE_GET_MLD(_iwl_op_mode)		\
335 	((struct iwl_mld *)(_iwl_op_mode)->op_mode_specific)
336 
337 #define IWL_MAC80211_GET_MLD(_hw)			\
338 	IWL_OP_MODE_GET_MLD((struct iwl_op_mode *)((_hw)->priv))
339 
340 #ifdef CONFIG_IWLWIFI_DEBUGFS
341 void
342 iwl_mld_add_debugfs_files(struct iwl_mld *mld, struct dentry *debugfs_dir);
343 #else
344 static inline void
iwl_mld_add_debugfs_files(struct iwl_mld * mld,struct dentry * debugfs_dir)345 iwl_mld_add_debugfs_files(struct iwl_mld *mld, struct dentry *debugfs_dir)
346 {}
347 #endif
348 
349 int iwl_mld_load_fw(struct iwl_mld *mld);
350 void iwl_mld_stop_fw(struct iwl_mld *mld);
351 int iwl_mld_start_fw(struct iwl_mld *mld);
352 void iwl_mld_send_recovery_cmd(struct iwl_mld *mld, u32 flags);
353 
iwl_mld_set_ctkill(struct iwl_mld * mld,bool state)354 static inline void iwl_mld_set_ctkill(struct iwl_mld *mld, bool state)
355 {
356 	mld->radio_kill.ct = state;
357 
358 	wiphy_rfkill_set_hw_state(mld->wiphy,
359 				  mld->radio_kill.hw || mld->radio_kill.ct);
360 }
361 
iwl_mld_set_hwkill(struct iwl_mld * mld,bool state)362 static inline void iwl_mld_set_hwkill(struct iwl_mld *mld, bool state)
363 {
364 	mld->radio_kill.hw = state;
365 
366 	wiphy_rfkill_set_hw_state(mld->wiphy,
367 				  mld->radio_kill.hw || mld->radio_kill.ct);
368 }
369 
iwl_mld_get_valid_tx_ant(const struct iwl_mld * mld)370 static inline u8 iwl_mld_get_valid_tx_ant(const struct iwl_mld *mld)
371 {
372 	u8 tx_ant = mld->fw->valid_tx_ant;
373 
374 	if (mld->nvm_data && mld->nvm_data->valid_tx_ant)
375 		tx_ant &= mld->nvm_data->valid_tx_ant;
376 
377 	return tx_ant;
378 }
379 
iwl_mld_get_valid_rx_ant(const struct iwl_mld * mld)380 static inline u8 iwl_mld_get_valid_rx_ant(const struct iwl_mld *mld)
381 {
382 	u8 rx_ant = mld->fw->valid_rx_ant;
383 
384 	if (mld->nvm_data && mld->nvm_data->valid_rx_ant)
385 		rx_ant &= mld->nvm_data->valid_rx_ant;
386 
387 	return rx_ant;
388 }
389 
iwl_mld_nl80211_band_to_fw(enum nl80211_band band)390 static inline u8 iwl_mld_nl80211_band_to_fw(enum nl80211_band band)
391 {
392 	switch (band) {
393 	case NL80211_BAND_2GHZ:
394 		return PHY_BAND_24;
395 	case NL80211_BAND_5GHZ:
396 		return PHY_BAND_5;
397 	case NL80211_BAND_6GHZ:
398 		return PHY_BAND_6;
399 	default:
400 		WARN_ONCE(1, "Unsupported band (%u)\n", band);
401 		return PHY_BAND_5;
402 	}
403 }
404 
iwl_mld_phy_band_to_nl80211(u8 phy_band)405 static inline u8 iwl_mld_phy_band_to_nl80211(u8 phy_band)
406 {
407 	switch (phy_band) {
408 	case PHY_BAND_24:
409 		return NL80211_BAND_2GHZ;
410 	case PHY_BAND_5:
411 		return NL80211_BAND_5GHZ;
412 	case PHY_BAND_6:
413 		return NL80211_BAND_6GHZ;
414 	default:
415 		WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
416 		return NL80211_BAND_5GHZ;
417 	}
418 }
419 
420 static inline int
iwl_mld_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,enum nl80211_band band)421 iwl_mld_legacy_hw_idx_to_mac80211_idx(u32 rate_n_flags,
422 				      enum nl80211_band band)
423 {
424 	int format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
425 	int rate = rate_n_flags & RATE_LEGACY_RATE_MSK;
426 	bool is_lb = band == NL80211_BAND_2GHZ;
427 
428 	if (format == RATE_MCS_MOD_TYPE_LEGACY_OFDM)
429 		return is_lb ? rate + IWL_FIRST_OFDM_RATE : rate;
430 
431 	/* CCK is not allowed in 5 GHz */
432 	return is_lb ? rate : -1;
433 }
434 
435 extern const struct ieee80211_ops iwl_mld_hw_ops;
436 
437 /**
438  * enum iwl_rx_handler_context: context for Rx handler
439  * @RX_HANDLER_SYNC: this means that it will be called in the Rx path
440  *	which can't acquire the wiphy->mutex.
441  * @RX_HANDLER_ASYNC: If the handler needs to hold wiphy->mutex
442  *	(and only in this case!), it should be set as ASYNC. In that case,
443  *	it will be called from a worker with wiphy->mutex held.
444  */
445 enum iwl_rx_handler_context {
446 	RX_HANDLER_SYNC,
447 	RX_HANDLER_ASYNC,
448 };
449 
450 /**
451  * struct iwl_rx_handler: handler for FW notification
452  * @val_fn: input validation function.
453  * @sizes: an array that mapps a version to the expected size.
454  * @fn: the function is called when notification is handled
455  * @cmd_id: command id
456  * @n_sizes: number of elements in &sizes.
457  * @context: see &iwl_rx_handler_context
458  * @obj_type: the type of the object that this handler is related to.
459  *	See &iwl_mld_object_type. Use IWL_MLD_OBJECT_TYPE_NONE if not related.
460  * @cancel: function to cancel the notification. valid only if obj_type is not
461  *	IWL_MLD_OBJECT_TYPE_NONE.
462  */
463 struct iwl_rx_handler {
464 	union {
465 		bool (*val_fn)(struct iwl_mld *mld, struct iwl_rx_packet *pkt);
466 		const struct iwl_notif_struct_size *sizes;
467 	};
468 	void (*fn)(struct iwl_mld *mld, struct iwl_rx_packet *pkt);
469 	u16 cmd_id;
470 	u8 n_sizes;
471 	u8 context;
472 	enum iwl_mld_object_type obj_type;
473 	bool (*cancel)(struct iwl_mld *mld, struct iwl_rx_packet *pkt,
474 		       u32 obj_id);
475 };
476 
477 /**
478  * struct iwl_notif_struct_size: map a notif ver to the expected size
479  *
480  * @size: the size to expect
481  * @ver: the version of the notification
482  */
483 struct iwl_notif_struct_size {
484 	u32 size:24, ver:8;
485 };
486 
487 #if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
488 extern const struct iwl_hcmd_arr iwl_mld_groups[];
489 extern const unsigned int global_iwl_mld_goups_size;
490 extern const struct iwl_rx_handler iwl_mld_rx_handlers[];
491 extern const unsigned int iwl_mld_rx_handlers_num;
492 
493 bool
494 iwl_mld_is_dup(struct iwl_mld *mld, struct ieee80211_sta *sta,
495 	       struct ieee80211_hdr *hdr,
496 	       const struct iwl_rx_mpdu_desc *mpdu_desc,
497 	       struct ieee80211_rx_status *rx_status, int queue);
498 
499 void iwl_construct_mld(struct iwl_mld *mld, struct iwl_trans *trans,
500 		       const struct iwl_rf_cfg *cfg, const struct iwl_fw *fw,
501 		       struct ieee80211_hw *hw, struct dentry *dbgfs_dir);
502 #endif
503 
504 #define IWL_MLD_INVALID_FW_ID 0xff
505 
506 #define IWL_MLD_ALLOC_FN(_type, _mac80211_type)						\
507 static int										\
508 iwl_mld_allocate_##_type##_fw_id(struct iwl_mld *mld,					\
509 				 u8 *fw_id,				\
510 				 struct ieee80211_##_mac80211_type *mac80211_ptr)	\
511 {											\
512 	u8 rand = IWL_MLD_DIS_RANDOM_FW_ID ? 0 : get_random_u8();			\
513 	u8 arr_sz = ARRAY_SIZE(mld->fw_id_to_##_mac80211_type);				\
514 	if (__builtin_types_compatible_p(typeof(*mac80211_ptr),				\
515 					 struct ieee80211_link_sta))			\
516 		arr_sz = mld->fw->ucode_capa.num_stations;				\
517 	if (__builtin_types_compatible_p(typeof(*mac80211_ptr),				\
518 					 struct ieee80211_bss_conf))			\
519 		arr_sz = mld->fw->ucode_capa.num_links;					\
520 	for (int i = 0; i < arr_sz; i++) {						\
521 		u8 idx = (i + rand) % arr_sz;						\
522 		if (rcu_access_pointer(mld->fw_id_to_##_mac80211_type[idx]))		\
523 			continue;							\
524 		IWL_DEBUG_INFO(mld, "Allocated at index %d / %d\n", idx, arr_sz);	\
525 		*fw_id = idx;								\
526 		rcu_assign_pointer(mld->fw_id_to_##_mac80211_type[idx], mac80211_ptr);	\
527 		return 0;								\
528 	}										\
529 	return -ENOSPC;									\
530 }
531 
532 static inline struct ieee80211_bss_conf *
iwl_mld_fw_id_to_link_conf(struct iwl_mld * mld,u8 fw_link_id)533 iwl_mld_fw_id_to_link_conf(struct iwl_mld *mld, u8 fw_link_id)
534 {
535 	if (IWL_FW_CHECK(mld, fw_link_id >= mld->fw->ucode_capa.num_links,
536 			 "Invalid fw_link_id: %d\n", fw_link_id))
537 		return NULL;
538 
539 	return wiphy_dereference(mld->wiphy,
540 				 mld->fw_id_to_bss_conf[fw_link_id]);
541 }
542 
543 #define MSEC_TO_TU(_msec)	((_msec) * 1000 / 1024)
544 
545 void iwl_mld_add_vif_debugfs(struct ieee80211_hw *hw,
546 			     struct ieee80211_vif *vif);
547 void iwl_mld_add_link_debugfs(struct ieee80211_hw *hw,
548 			      struct ieee80211_vif *vif,
549 			      struct ieee80211_bss_conf *link_conf,
550 			      struct dentry *dir);
551 void iwl_mld_add_link_sta_debugfs(struct ieee80211_hw *hw,
552 				  struct ieee80211_vif *vif,
553 				  struct ieee80211_link_sta *link_sta,
554 				  struct dentry *dir);
555 
556 /* Utilities */
557 
iwl_mld_mac80211_ac_to_fw_tx_fifo(enum ieee80211_ac_numbers ac)558 static inline u8 iwl_mld_mac80211_ac_to_fw_tx_fifo(enum ieee80211_ac_numbers ac)
559 {
560 	static const u8 mac80211_ac_to_fw_tx_fifo[] = {
561 		IWL_BZ_EDCA_TX_FIFO_VO,
562 		IWL_BZ_EDCA_TX_FIFO_VI,
563 		IWL_BZ_EDCA_TX_FIFO_BE,
564 		IWL_BZ_EDCA_TX_FIFO_BK,
565 		IWL_BZ_TRIG_TX_FIFO_VO,
566 		IWL_BZ_TRIG_TX_FIFO_VI,
567 		IWL_BZ_TRIG_TX_FIFO_BE,
568 		IWL_BZ_TRIG_TX_FIFO_BK,
569 	};
570 	return mac80211_ac_to_fw_tx_fifo[ac];
571 }
572 
573 static inline u32
iwl_mld_get_lmac_id(struct iwl_mld * mld,enum nl80211_band band)574 iwl_mld_get_lmac_id(struct iwl_mld *mld, enum nl80211_band band)
575 {
576 	if (!fw_has_capa(&mld->fw->ucode_capa,
577 			 IWL_UCODE_TLV_CAPA_CDB_SUPPORT) ||
578 	    band == NL80211_BAND_2GHZ)
579 		return IWL_LMAC_24G_INDEX;
580 	return IWL_LMAC_5G_INDEX;
581 }
582 
583 /* Check if we had an error, but reconfig flow didn't start yet */
iwl_mld_error_before_recovery(struct iwl_mld * mld)584 static inline bool iwl_mld_error_before_recovery(struct iwl_mld *mld)
585 {
586 	return mld->fw_status.in_hw_restart &&
587 		!iwl_trans_fw_running(mld->trans);
588 }
589 
590 int iwl_mld_tdls_sta_count(struct iwl_mld *mld);
591 
592 #endif /* __iwl_mld_h__ */
593