xref: /linux/drivers/net/wireless/intel/iwlwifi/mld/mac80211.c (revision d30c1683aaecb93d2ab95685dc4300a33d3cea7a)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2024-2025 Intel Corporation
4  */
5 
6 #include <net/mac80211.h>
7 #include <linux/fips.h>
8 #include <linux/ip.h>
9 
10 #include "mld.h"
11 #include "mac80211.h"
12 #include "phy.h"
13 #include "iface.h"
14 #include "power.h"
15 #include "sta.h"
16 #include "agg.h"
17 #include "scan.h"
18 #include "d3.h"
19 #include "tlc.h"
20 #include "key.h"
21 #include "ap.h"
22 #include "tx.h"
23 #include "roc.h"
24 #include "mlo.h"
25 #include "stats.h"
26 #include "iwl-nvm-parse.h"
27 #include "ftm-initiator.h"
28 #include "low_latency.h"
29 #include "fw/api/scan.h"
30 #include "fw/api/context.h"
31 #include "fw/api/filter.h"
32 #include "fw/api/sta.h"
33 #include "fw/api/tdls.h"
34 #ifdef CONFIG_PM_SLEEP
35 #include "fw/api/d3.h"
36 #endif /* CONFIG_PM_SLEEP */
37 #include "iwl-trans.h"
38 
39 #define IWL_MLD_LIMITS(ap)					\
40 	{							\
41 		.max = 2,					\
42 		.types = BIT(NL80211_IFTYPE_STATION),		\
43 	},							\
44 	{							\
45 		.max = 1,					\
46 		.types = ap |					\
47 			 BIT(NL80211_IFTYPE_P2P_CLIENT) |	\
48 			 BIT(NL80211_IFTYPE_P2P_GO),		\
49 	},							\
50 	{							\
51 		.max = 1,					\
52 		.types = BIT(NL80211_IFTYPE_P2P_DEVICE),	\
53 	}
54 
55 static const struct ieee80211_iface_limit iwl_mld_limits[] = {
56 	IWL_MLD_LIMITS(0)
57 };
58 
59 static const struct ieee80211_iface_limit iwl_mld_limits_ap[] = {
60 	IWL_MLD_LIMITS(BIT(NL80211_IFTYPE_AP))
61 };
62 
63 static const struct ieee80211_iface_combination
64 iwl_mld_iface_combinations[] = {
65 	{
66 		.num_different_channels = 2,
67 		.max_interfaces = 4,
68 		.limits = iwl_mld_limits,
69 		.n_limits = ARRAY_SIZE(iwl_mld_limits),
70 	},
71 	{
72 		.num_different_channels = 1,
73 		.max_interfaces = 4,
74 		.limits = iwl_mld_limits_ap,
75 		.n_limits = ARRAY_SIZE(iwl_mld_limits_ap),
76 	},
77 };
78 
79 static const u8 ext_capa_base[IWL_MLD_STA_EXT_CAPA_SIZE] = {
80 	[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
81 	[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
82 	[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
83 	      WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
84 	[8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
85 };
86 
87 #define IWL_MLD_EMLSR_CAPA	(IEEE80211_EML_CAP_EMLSR_SUPP | \
88 				 IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \
89 					__bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \
90 				 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \
91 					__bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY))
92 #define IWL_MLD_CAPA_OPS (FIELD_PREP_CONST( \
93 			IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \
94 			IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) | \
95 			IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT)
96 
97 static void iwl_mld_hw_set_addresses(struct iwl_mld *mld)
98 {
99 	struct wiphy *wiphy = mld->wiphy;
100 	int num_addrs = 1;
101 
102 	/* Extract MAC address */
103 	memcpy(mld->addresses[0].addr, mld->nvm_data->hw_addr, ETH_ALEN);
104 	wiphy->addresses = mld->addresses;
105 	wiphy->n_addresses = 1;
106 
107 	/* Extract additional MAC addresses if available */
108 	if (mld->nvm_data->n_hw_addrs > 1)
109 		num_addrs = min(mld->nvm_data->n_hw_addrs,
110 				IWL_MLD_MAX_ADDRESSES);
111 
112 	for (int i = 1; i < num_addrs; i++) {
113 		memcpy(mld->addresses[i].addr,
114 		       mld->addresses[i - 1].addr,
115 		       ETH_ALEN);
116 		mld->addresses[i].addr[ETH_ALEN - 1]++;
117 		wiphy->n_addresses++;
118 	}
119 }
120 
121 static void iwl_mld_hw_set_channels(struct iwl_mld *mld)
122 {
123 	struct wiphy *wiphy = mld->wiphy;
124 	struct ieee80211_supported_band *bands = mld->nvm_data->bands;
125 
126 	wiphy->bands[NL80211_BAND_2GHZ] = &bands[NL80211_BAND_2GHZ];
127 	wiphy->bands[NL80211_BAND_5GHZ] = &bands[NL80211_BAND_5GHZ];
128 
129 	if (bands[NL80211_BAND_6GHZ].n_channels)
130 		wiphy->bands[NL80211_BAND_6GHZ] = &bands[NL80211_BAND_6GHZ];
131 }
132 
133 static void iwl_mld_hw_set_security(struct iwl_mld *mld)
134 {
135 	struct ieee80211_hw *hw = mld->hw;
136 	static const u32 mld_ciphers[] = {
137 		WLAN_CIPHER_SUITE_WEP40,
138 		WLAN_CIPHER_SUITE_WEP104,
139 		WLAN_CIPHER_SUITE_TKIP,
140 		WLAN_CIPHER_SUITE_CCMP,
141 		WLAN_CIPHER_SUITE_GCMP,
142 		WLAN_CIPHER_SUITE_GCMP_256,
143 		WLAN_CIPHER_SUITE_AES_CMAC,
144 		WLAN_CIPHER_SUITE_BIP_GMAC_128,
145 		WLAN_CIPHER_SUITE_BIP_GMAC_256
146 	};
147 
148 	if (fips_enabled)
149 		return;
150 
151 	hw->wiphy->n_cipher_suites = ARRAY_SIZE(mld_ciphers);
152 	hw->wiphy->cipher_suites = mld_ciphers;
153 
154 	ieee80211_hw_set(hw, MFP_CAPABLE);
155 	wiphy_ext_feature_set(hw->wiphy,
156 			      NL80211_EXT_FEATURE_BEACON_PROTECTION);
157 }
158 
159 static void iwl_mld_hw_set_antennas(struct iwl_mld *mld)
160 {
161 	struct wiphy *wiphy = mld->wiphy;
162 
163 	wiphy->available_antennas_tx = iwl_mld_get_valid_tx_ant(mld);
164 	wiphy->available_antennas_rx = iwl_mld_get_valid_rx_ant(mld);
165 }
166 
167 static void iwl_mld_hw_set_pm(struct iwl_mld *mld)
168 {
169 #ifdef CONFIG_PM_SLEEP
170 	struct wiphy *wiphy = mld->wiphy;
171 
172 	if (!device_can_wakeup(mld->trans->dev))
173 		return;
174 
175 	if (fips_enabled)
176 		return;
177 
178 	mld->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
179 			     WIPHY_WOWLAN_DISCONNECT |
180 			     WIPHY_WOWLAN_EAP_IDENTITY_REQ |
181 			     WIPHY_WOWLAN_RFKILL_RELEASE |
182 			     WIPHY_WOWLAN_NET_DETECT |
183 			     WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
184 			     WIPHY_WOWLAN_GTK_REKEY_FAILURE |
185 			     WIPHY_WOWLAN_4WAY_HANDSHAKE;
186 
187 	mld->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
188 	mld->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
189 	mld->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
190 	mld->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES_V2;
191 
192 	wiphy->wowlan = &mld->wowlan;
193 #endif /* CONFIG_PM_SLEEP */
194 }
195 
196 static void iwl_mac_hw_set_radiotap(struct iwl_mld *mld)
197 {
198 	struct ieee80211_hw *hw = mld->hw;
199 
200 	hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
201 				    IEEE80211_RADIOTAP_MCS_HAVE_STBC;
202 
203 	hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
204 				    IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
205 
206 	hw->radiotap_timestamp.units_pos =
207 		IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
208 		IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
209 
210 	/* this is the case for CCK frames, it's better (only 8) for OFDM */
211 	hw->radiotap_timestamp.accuracy = 22;
212 }
213 
214 static void iwl_mac_hw_set_flags(struct iwl_mld *mld)
215 {
216 	struct ieee80211_hw *hw = mld->hw;
217 
218 	ieee80211_hw_set(hw, USES_RSS);
219 	ieee80211_hw_set(hw, HANDLES_QUIET_CSA);
220 	ieee80211_hw_set(hw, AP_LINK_PS);
221 	ieee80211_hw_set(hw, SIGNAL_DBM);
222 	ieee80211_hw_set(hw, SPECTRUM_MGMT);
223 	ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
224 	ieee80211_hw_set(hw, WANT_MONITOR_VIF);
225 	ieee80211_hw_set(hw, SUPPORTS_PS);
226 	ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
227 	ieee80211_hw_set(hw, AMPDU_AGGREGATION);
228 	ieee80211_hw_set(hw, CONNECTION_MONITOR);
229 	ieee80211_hw_set(hw, CHANCTX_STA_CSA);
230 	ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
231 	ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
232 	ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
233 	ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
234 	ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
235 	ieee80211_hw_set(hw, STA_MMPDU_TXQ);
236 	ieee80211_hw_set(hw, TX_AMSDU);
237 	ieee80211_hw_set(hw, TX_FRAG_LIST);
238 	ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
239 	ieee80211_hw_set(hw, HAS_RATE_CONTROL);
240 	ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
241 	ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
242 	ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
243 	ieee80211_hw_set(hw, TDLS_WIDER_BW);
244 }
245 
246 static void iwl_mac_hw_set_wiphy(struct iwl_mld *mld)
247 {
248 	struct ieee80211_hw *hw = mld->hw;
249 	struct wiphy *wiphy = hw->wiphy;
250 	const struct iwl_ucode_capabilities *ucode_capa = &mld->fw->ucode_capa;
251 
252 	snprintf(wiphy->fw_version,
253 		 sizeof(wiphy->fw_version),
254 		 "%.31s", mld->fw->fw_version);
255 
256 	wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
257 				 BIT(NL80211_IFTYPE_P2P_CLIENT) |
258 				 BIT(NL80211_IFTYPE_AP) |
259 				 BIT(NL80211_IFTYPE_P2P_GO) |
260 				 BIT(NL80211_IFTYPE_P2P_DEVICE) |
261 				 BIT(NL80211_IFTYPE_ADHOC);
262 
263 	wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
264 			   NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
265 			   NL80211_FEATURE_ND_RANDOM_MAC_ADDR |
266 			   NL80211_FEATURE_HT_IBSS |
267 			   NL80211_FEATURE_P2P_GO_CTWIN |
268 			   NL80211_FEATURE_LOW_PRIORITY_SCAN |
269 			   NL80211_FEATURE_P2P_GO_OPPPS |
270 			   NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
271 			   NL80211_FEATURE_SUPPORTS_WMM_ADMISSION |
272 			   NL80211_FEATURE_TX_POWER_INSERTION |
273 			   NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
274 
275 	wiphy->flags |= WIPHY_FLAG_IBSS_RSN |
276 			WIPHY_FLAG_AP_UAPSD |
277 			WIPHY_FLAG_HAS_CHANNEL_SWITCH |
278 			WIPHY_FLAG_SPLIT_SCAN_6GHZ |
279 			WIPHY_FLAG_SUPPORTS_TDLS |
280 			WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
281 
282 	/* For fips_enabled, don't support WiFi7 due to WPA3/MFP requirements */
283 	if (mld->nvm_data->sku_cap_11be_enable &&
284 	    !iwlwifi_mod_params.disable_11ax &&
285 	    !iwlwifi_mod_params.disable_11be &&
286 	    !fips_enabled)
287 		wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
288 
289 	/* the firmware uses u8 for num of iterations, but 0xff is saved for
290 	 * infinite loop, so the maximum number of iterations is actually 254.
291 	 */
292 	wiphy->max_sched_scan_plan_iterations = 254;
293 	wiphy->max_sched_scan_ie_len = iwl_mld_scan_max_template_size();
294 	wiphy->max_scan_ie_len = iwl_mld_scan_max_template_size();
295 	wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
296 	wiphy->max_scan_ssids = PROBE_OPTION_MAX;
297 	wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
298 	wiphy->max_sched_scan_reqs = 1;
299 	wiphy->max_sched_scan_plan_interval = U16_MAX;
300 	wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES_V2;
301 
302 	wiphy->max_remain_on_channel_duration = 10000;
303 
304 	wiphy->hw_version = mld->trans->info.hw_id;
305 
306 	wiphy->hw_timestamp_max_peers = 1;
307 
308 	wiphy->iface_combinations = iwl_mld_iface_combinations;
309 	wiphy->n_iface_combinations = ARRAY_SIZE(iwl_mld_iface_combinations);
310 
311 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
312 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_DFS_CONCURRENT);
313 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
314 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_START_TIME);
315 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_BSS_PARENT_TSF);
316 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
317 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
318 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
319 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
320 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
321 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
322 
323 	if (fw_has_capa(ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
324 		wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_PROTECTED_TWT);
325 
326 	if (iwlmld_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
327 		wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
328 	else
329 		wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
330 
331 	/* We are done for non-HE */
332 	if (iwlwifi_mod_params.disable_11ax)
333 		return;
334 
335 	ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
336 	ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
337 
338 	wiphy->iftype_ext_capab = mld->ext_capab;
339 	wiphy->num_iftype_ext_capab = ARRAY_SIZE(mld->ext_capab);
340 
341 	BUILD_BUG_ON(sizeof(mld->sta_ext_capab) < sizeof(ext_capa_base));
342 
343 	memcpy(mld->sta_ext_capab, ext_capa_base, sizeof(ext_capa_base));
344 
345 	mld->ext_capab[0].iftype = NL80211_IFTYPE_STATION;
346 	mld->ext_capab[0].extended_capabilities = mld->sta_ext_capab;
347 	mld->ext_capab[0].extended_capabilities_mask = mld->sta_ext_capab;
348 	mld->ext_capab[0].extended_capabilities_len = sizeof(mld->sta_ext_capab);
349 
350 	if (!mld->nvm_data->sku_cap_11be_enable ||
351 	    iwlwifi_mod_params.disable_11be)
352 		return;
353 
354 	mld->ext_capab[0].eml_capabilities = IWL_MLD_EMLSR_CAPA;
355 	mld->ext_capab[0].mld_capa_and_ops = IWL_MLD_CAPA_OPS;
356 
357 }
358 
359 static void iwl_mac_hw_set_misc(struct iwl_mld *mld)
360 {
361 	struct ieee80211_hw *hw = mld->hw;
362 
363 	hw->queues = IEEE80211_NUM_ACS;
364 
365 	hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
366 	hw->netdev_features |= mld->trans->mac_cfg->base->features;
367 
368 	hw->max_tx_fragments = mld->trans->info.max_skb_frags;
369 	hw->max_listen_interval = IWL_MLD_CONN_LISTEN_INTERVAL;
370 
371 	hw->uapsd_max_sp_len = IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL;
372 	hw->uapsd_queues = IEEE80211_WMM_IE_STA_QOSINFO_AC_VO |
373 			   IEEE80211_WMM_IE_STA_QOSINFO_AC_VI |
374 			   IEEE80211_WMM_IE_STA_QOSINFO_AC_BK |
375 			   IEEE80211_WMM_IE_STA_QOSINFO_AC_BE;
376 
377 	hw->chanctx_data_size = sizeof(struct iwl_mld_phy);
378 	hw->vif_data_size = sizeof(struct iwl_mld_vif);
379 	hw->sta_data_size = sizeof(struct iwl_mld_sta);
380 	hw->txq_data_size = sizeof(struct iwl_mld_txq);
381 
382 	/* TODO: Remove this division when IEEE80211_MAX_AMPDU_BUF_EHT size
383 	 * is supported.
384 	 * Note: ensure that IWL_DEFAULT_QUEUE_SIZE_EHT is updated accordingly.
385 	 */
386 	hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_EHT / 2;
387 }
388 
389 static int iwl_mld_hw_verify_preconditions(struct iwl_mld *mld)
390 {
391 	int ratecheck;
392 
393 	/* check for rates version 3 */
394 	ratecheck =
395 		(iwl_fw_lookup_cmd_ver(mld->fw, TX_CMD, 0) >= 11) +
396 		(iwl_fw_lookup_notif_ver(mld->fw, DATA_PATH_GROUP,
397 					 TLC_MNG_UPDATE_NOTIF, 0) >= 4) +
398 		(iwl_fw_lookup_notif_ver(mld->fw, LEGACY_GROUP,
399 					 REPLY_RX_MPDU_CMD, 0) >= 6) +
400 		(iwl_fw_lookup_notif_ver(mld->fw, LONG_GROUP, TX_CMD, 0) >= 9);
401 
402 	if (ratecheck != 0 && ratecheck != 4) {
403 		IWL_ERR(mld, "Firmware has inconsistent rates\n");
404 		return -EINVAL;
405 	}
406 
407 	/* 11ax is expected to be enabled for all supported devices */
408 	if (WARN_ON(!mld->nvm_data->sku_cap_11ax_enable))
409 		return -EINVAL;
410 
411 	/* LAR is expected to be enabled for all supported devices */
412 	if (WARN_ON(!mld->nvm_data->lar_enabled))
413 		return -EINVAL;
414 
415 	/* All supported devices are currently using version 3 of the cmd.
416 	 * Since version 3, IWL_SCAN_MAX_PROFILES_V2 shall be used where
417 	 * necessary.
418 	 */
419 	if (WARN_ON(iwl_fw_lookup_cmd_ver(mld->fw,
420 					  SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
421 					  IWL_FW_CMD_VER_UNKNOWN) != 3))
422 		return -EINVAL;
423 
424 	return 0;
425 }
426 
427 int iwl_mld_register_hw(struct iwl_mld *mld)
428 {
429 	/* verify once essential preconditions required for setting
430 	 * the hw capabilities
431 	 */
432 	if (iwl_mld_hw_verify_preconditions(mld))
433 		return -EINVAL;
434 
435 	iwl_mld_hw_set_addresses(mld);
436 	iwl_mld_hw_set_channels(mld);
437 	iwl_mld_hw_set_security(mld);
438 	iwl_mld_hw_set_pm(mld);
439 	iwl_mld_hw_set_antennas(mld);
440 	iwl_mac_hw_set_radiotap(mld);
441 	iwl_mac_hw_set_flags(mld);
442 	iwl_mac_hw_set_wiphy(mld);
443 	iwl_mac_hw_set_misc(mld);
444 
445 	SET_IEEE80211_DEV(mld->hw, mld->trans->dev);
446 
447 	return ieee80211_register_hw(mld->hw);
448 }
449 
450 static void
451 iwl_mld_mac80211_tx(struct ieee80211_hw *hw,
452 		    struct ieee80211_tx_control *control, struct sk_buff *skb)
453 {
454 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
455 	struct ieee80211_sta *sta = control->sta;
456 	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
457 	struct ieee80211_hdr *hdr = (void *)skb->data;
458 	u32 link_id = u32_get_bits(info->control.flags,
459 				   IEEE80211_TX_CTRL_MLO_LINK);
460 
461 	/* In AP mode, mgmt frames are sent on the bcast station,
462 	 * so the FW can't translate the MLD addr to the link addr. Do it here
463 	 */
464 	if (ieee80211_is_mgmt(hdr->frame_control) && sta &&
465 	    link_id != IEEE80211_LINK_UNSPECIFIED &&
466 	    !ieee80211_is_probe_resp(hdr->frame_control)) {
467 		/* translate MLD addresses to LINK addresses */
468 		struct ieee80211_link_sta *link_sta =
469 			rcu_dereference(sta->link[link_id]);
470 		struct ieee80211_bss_conf *link_conf =
471 			rcu_dereference(info->control.vif->link_conf[link_id]);
472 		struct ieee80211_mgmt *mgmt;
473 
474 		if (WARN_ON(!link_sta || !link_conf)) {
475 			ieee80211_free_txskb(hw, skb);
476 			return;
477 		}
478 
479 		mgmt = (void *)hdr;
480 		memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
481 		memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
482 		memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
483 	}
484 
485 	iwl_mld_tx_skb(mld, skb, NULL);
486 }
487 
488 static void
489 iwl_mld_restart_cleanup(struct iwl_mld *mld)
490 {
491 	iwl_cleanup_mld(mld);
492 
493 	ieee80211_iterate_interfaces(mld->hw, IEEE80211_IFACE_ITER_ACTIVE,
494 				     iwl_mld_cleanup_vif, NULL);
495 
496 	ieee80211_iterate_stations_atomic(mld->hw,
497 					  iwl_mld_cleanup_sta, NULL);
498 
499 	iwl_mld_ftm_restart_cleanup(mld);
500 }
501 
502 static
503 int iwl_mld_mac80211_start(struct ieee80211_hw *hw)
504 {
505 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
506 	bool in_d3 = false;
507 	int ret = 0;
508 
509 	lockdep_assert_wiphy(mld->wiphy);
510 
511 #ifdef CONFIG_PM_SLEEP
512 	/* Unless the host goes into hibernate the FW always stays on and
513 	 * the d3_resume flow is used. When wowlan is configured, mac80211
514 	 * would call it's resume callback and the wowlan_resume flow
515 	 * would be used.
516 	 */
517 
518 	in_d3 = mld->fw_status.in_d3;
519 	if (in_d3) {
520 		/* mac80211 already cleaned up the state, no need for cleanup */
521 		ret = iwl_mld_no_wowlan_resume(mld);
522 		if (ret) {
523 			iwl_mld_stop_fw(mld);
524 			/* We're not really restarting in the sense of
525 			 * in_hw_restart even if we got an error during
526 			 * this. We'll just start again below and have
527 			 * nothing to recover, mac80211 will do anyway.
528 			 */
529 			mld->fw_status.in_hw_restart = false;
530 		}
531 	}
532 #endif /* CONFIG_PM_SLEEP */
533 
534 	if (mld->fw_status.in_hw_restart) {
535 		iwl_mld_stop_fw(mld);
536 		iwl_mld_restart_cleanup(mld);
537 	}
538 
539 	if (!in_d3 || ret) {
540 		ret = iwl_mld_start_fw(mld);
541 		if (ret)
542 			goto error;
543 	}
544 
545 	mld->scan.last_start_time_jiffies = jiffies;
546 
547 	iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
548 			       NULL);
549 	iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
550 			       NULL);
551 
552 	return 0;
553 
554 error:
555 	/* If we failed to restart the hw, there is nothing useful
556 	 * we can do but indicate we are no longer in restart.
557 	 */
558 	mld->fw_status.in_hw_restart = false;
559 
560 	return ret;
561 }
562 
563 static
564 void iwl_mld_mac80211_stop(struct ieee80211_hw *hw, bool suspend)
565 {
566 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
567 
568 	lockdep_assert_wiphy(mld->wiphy);
569 
570 	wiphy_work_cancel(mld->wiphy, &mld->add_txqs_wk);
571 
572 	/* if the suspend flow fails the fw is in error. Stop it here, and it
573 	 * will be started upon wakeup
574 	 */
575 	if (!suspend ||
576 	    (IS_ENABLED(CONFIG_PM_SLEEP) && iwl_mld_no_wowlan_suspend(mld)))
577 		iwl_mld_stop_fw(mld);
578 
579 	/* Clear in_hw_restart flag when stopping the hw, as mac80211 won't
580 	 * execute the restart.
581 	 */
582 	mld->fw_status.in_hw_restart = false;
583 
584 	/* We shouldn't have any UIDs still set. Loop over all the UIDs to
585 	 * make sure there's nothing left there and warn if any is found.
586 	 */
587 	for (int i = 0; i < ARRAY_SIZE(mld->scan.uid_status); i++)
588 		if (WARN_ONCE(mld->scan.uid_status[i],
589 			      "UMAC scan UID %d status was not cleaned (0x%x 0x%x)\n",
590 			      i, mld->scan.uid_status[i], mld->scan.status))
591 			mld->scan.uid_status[i] = 0;
592 }
593 
594 static
595 int iwl_mld_mac80211_config(struct ieee80211_hw *hw, int radio_idx,
596 			    u32 changed)
597 {
598 	return 0;
599 }
600 
601 static
602 int iwl_mld_mac80211_add_interface(struct ieee80211_hw *hw,
603 				   struct ieee80211_vif *vif)
604 {
605 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
606 	int ret;
607 
608 	lockdep_assert_wiphy(mld->wiphy);
609 
610 	/* Construct mld_vif, add it to fw, and map its ID to ieee80211_vif */
611 	ret = iwl_mld_add_vif(mld, vif);
612 	if (ret)
613 		return ret;
614 
615 	/*
616 	 * Add the default link, but not if this is an MLD vif as that implies
617 	 * the HW is restarting and it will be configured by change_vif_links.
618 	 */
619 	if (!ieee80211_vif_is_mld(vif))
620 		ret = iwl_mld_add_link(mld, &vif->bss_conf);
621 	if (ret)
622 		goto err;
623 
624 	if (vif->type == NL80211_IFTYPE_STATION) {
625 		vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC;
626 		if (!vif->p2p)
627 			vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
628 					     IEEE80211_VIF_SUPPORTS_CQM_RSSI;
629 	}
630 
631 	if (vif->p2p)
632 		vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW;
633 
634 	/*
635 	 * For an MLD vif (in restart) we may not have a link; delay the call
636 	 * the initial change_vif_links.
637 	 */
638 	if (vif->type == NL80211_IFTYPE_STATION &&
639 	    !ieee80211_vif_is_mld(vif))
640 		iwl_mld_update_mac_power(mld, vif, false);
641 
642 	if (vif->type == NL80211_IFTYPE_MONITOR) {
643 		mld->monitor.on = true;
644 		ieee80211_hw_set(mld->hw, RX_INCLUDES_FCS);
645 	}
646 
647 	if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
648 		mld->p2p_device_vif = vif;
649 
650 	return 0;
651 
652 err:
653 	iwl_mld_rm_vif(mld, vif);
654 	return ret;
655 }
656 
657 static
658 void iwl_mld_mac80211_remove_interface(struct ieee80211_hw *hw,
659 				       struct ieee80211_vif *vif)
660 {
661 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
662 
663 	lockdep_assert_wiphy(mld->wiphy);
664 
665 	if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_STATION)
666 		vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
667 				       IEEE80211_VIF_SUPPORTS_CQM_RSSI);
668 
669 	if (vif->type == NL80211_IFTYPE_MONITOR) {
670 		__clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mld->hw->flags);
671 		mld->monitor.on = false;
672 	}
673 
674 	if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
675 		mld->p2p_device_vif = NULL;
676 
677 	iwl_mld_remove_link(mld, &vif->bss_conf);
678 
679 #ifdef CONFIG_IWLWIFI_DEBUGFS
680 	debugfs_remove(iwl_mld_vif_from_mac80211(vif)->dbgfs_slink);
681 	iwl_mld_vif_from_mac80211(vif)->dbgfs_slink = NULL;
682 #endif
683 
684 	iwl_mld_rm_vif(mld, vif);
685 
686 	mld->monitor.phy.valid = false;
687 }
688 
689 struct iwl_mld_mc_iter_data {
690 	struct iwl_mld *mld;
691 	int port_id;
692 };
693 
694 static void iwl_mld_mc_iface_iterator(void *data, u8 *mac,
695 				      struct ieee80211_vif *vif)
696 {
697 	struct iwl_mld_mc_iter_data *mc_data = data;
698 	struct iwl_mld *mld = mc_data->mld;
699 	struct iwl_mcast_filter_cmd *cmd = mld->mcast_filter_cmd;
700 	struct iwl_host_cmd hcmd = {
701 		.id = MCAST_FILTER_CMD,
702 		.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
703 	};
704 	int ret, len;
705 
706 	/* If we don't have free ports, mcast frames will be dropped */
707 	if (WARN_ON_ONCE(mc_data->port_id >= MAX_PORT_ID_NUM))
708 		return;
709 
710 	if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc)
711 		return;
712 
713 	cmd->port_id = mc_data->port_id++;
714 	ether_addr_copy(cmd->bssid, vif->bss_conf.bssid);
715 	len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
716 
717 	hcmd.len[0] = len;
718 	hcmd.data[0] = cmd;
719 
720 	ret = iwl_mld_send_cmd(mld, &hcmd);
721 	if (ret)
722 		IWL_ERR(mld, "mcast filter cmd error. ret=%d\n", ret);
723 }
724 
725 void iwl_mld_recalc_multicast_filter(struct iwl_mld *mld)
726 {
727 	struct iwl_mld_mc_iter_data iter_data = {
728 		.mld = mld,
729 	};
730 
731 	if (WARN_ON_ONCE(!mld->mcast_filter_cmd))
732 		return;
733 
734 	ieee80211_iterate_active_interfaces(mld->hw,
735 					    IEEE80211_IFACE_ITER_NORMAL,
736 					    iwl_mld_mc_iface_iterator,
737 					    &iter_data);
738 }
739 
740 static u64
741 iwl_mld_mac80211_prepare_multicast(struct ieee80211_hw *hw,
742 				   struct netdev_hw_addr_list *mc_list)
743 {
744 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
745 	struct iwl_mcast_filter_cmd *cmd;
746 	struct netdev_hw_addr *addr;
747 	int addr_count = netdev_hw_addr_list_count(mc_list);
748 	bool pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES;
749 	int len;
750 
751 	if (pass_all)
752 		addr_count = 0;
753 
754 	/* len must be a multiple of 4 */
755 	len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
756 	cmd = kzalloc(len, GFP_ATOMIC);
757 	if (!cmd)
758 		return 0;
759 
760 	if (pass_all) {
761 		cmd->pass_all = 1;
762 		goto out;
763 	}
764 
765 	netdev_hw_addr_list_for_each(addr, mc_list) {
766 		IWL_DEBUG_MAC80211(mld, "mcast addr (%d): %pM\n",
767 				   cmd->count, addr->addr);
768 		ether_addr_copy(&cmd->addr_list[cmd->count * ETH_ALEN],
769 				addr->addr);
770 		cmd->count++;
771 	}
772 
773 out:
774 	return (u64)(unsigned long)cmd;
775 }
776 
777 static
778 void iwl_mld_mac80211_configure_filter(struct ieee80211_hw *hw,
779 				       unsigned int changed_flags,
780 				       unsigned int *total_flags,
781 				       u64 multicast)
782 {
783 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
784 	struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
785 
786 	/* Replace previous configuration */
787 	kfree(mld->mcast_filter_cmd);
788 	mld->mcast_filter_cmd = cmd;
789 
790 	if (!cmd)
791 		goto out;
792 
793 	if (changed_flags & FIF_ALLMULTI)
794 		cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
795 
796 	if (cmd->pass_all)
797 		cmd->count = 0;
798 
799 	iwl_mld_recalc_multicast_filter(mld);
800 out:
801 	*total_flags = 0;
802 }
803 
804 static
805 void iwl_mld_mac80211_wake_tx_queue(struct ieee80211_hw *hw,
806 				    struct ieee80211_txq *txq)
807 {
808 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
809 	struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq);
810 
811 	if (likely(mld_txq->status.allocated) || !txq->sta) {
812 		iwl_mld_tx_from_txq(mld, txq);
813 		return;
814 	}
815 
816 	/* We don't support TSPEC tids. %IEEE80211_NUM_TIDS is for mgmt */
817 	if (txq->tid != IEEE80211_NUM_TIDS && txq->tid >= IWL_MAX_TID_COUNT) {
818 		IWL_DEBUG_MAC80211(mld, "TID %d is not supported\n", txq->tid);
819 		return;
820 	}
821 
822 	/* The worker will handle any packets we leave on the txq now */
823 
824 	spin_lock_bh(&mld->add_txqs_lock);
825 	/* The list is being deleted only after the queue is fully allocated. */
826 	if (list_empty(&mld_txq->list) &&
827 	    /* recheck under lock, otherwise it can be added twice */
828 	    !mld_txq->status.allocated) {
829 		list_add_tail(&mld_txq->list, &mld->txqs_to_add);
830 		wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
831 	}
832 	spin_unlock_bh(&mld->add_txqs_lock);
833 }
834 
835 static void iwl_mld_teardown_tdls_peers(struct iwl_mld *mld)
836 {
837 	lockdep_assert_wiphy(mld->wiphy);
838 
839 	for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
840 		struct ieee80211_link_sta *link_sta;
841 		struct iwl_mld_sta *mld_sta;
842 
843 		link_sta = wiphy_dereference(mld->wiphy,
844 					     mld->fw_id_to_link_sta[i]);
845 		if (IS_ERR_OR_NULL(link_sta))
846 			continue;
847 
848 		if (!link_sta->sta->tdls)
849 			continue;
850 
851 		mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta);
852 
853 		ieee80211_tdls_oper_request(mld_sta->vif, link_sta->addr,
854 					    NL80211_TDLS_TEARDOWN,
855 					    WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED,
856 					    GFP_KERNEL);
857 	}
858 }
859 
860 static
861 int iwl_mld_add_chanctx(struct ieee80211_hw *hw,
862 			struct ieee80211_chanctx_conf *ctx)
863 {
864 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
865 	struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
866 	int fw_id = iwl_mld_allocate_fw_phy_id(mld);
867 	int ret;
868 
869 	if (fw_id < 0)
870 		return fw_id;
871 
872 	phy->mld = mld;
873 	phy->fw_id = fw_id;
874 	phy->chandef = *iwl_mld_get_chandef_from_chanctx(mld, ctx);
875 
876 	ret = iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_ADD);
877 	if (ret) {
878 		mld->used_phy_ids &= ~BIT(phy->fw_id);
879 		return ret;
880 	}
881 
882 	if (hweight8(mld->used_phy_ids) > 1)
883 		iwl_mld_teardown_tdls_peers(mld);
884 
885 	return 0;
886 }
887 
888 static
889 void iwl_mld_remove_chanctx(struct ieee80211_hw *hw,
890 			    struct ieee80211_chanctx_conf *ctx)
891 {
892 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
893 	struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
894 
895 	iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_REMOVE);
896 	mld->used_phy_ids &= ~BIT(phy->fw_id);
897 }
898 
899 static
900 void iwl_mld_change_chanctx(struct ieee80211_hw *hw,
901 			    struct ieee80211_chanctx_conf *ctx, u32 changed)
902 {
903 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
904 	struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx);
905 	struct cfg80211_chan_def *chandef =
906 		iwl_mld_get_chandef_from_chanctx(mld, ctx);
907 
908 	/* We don't care about these */
909 	if (!(changed & ~(IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
910 			  IEEE80211_CHANCTX_CHANGE_RADAR |
911 			  IEEE80211_CHANCTX_CHANGE_CHANNEL)))
912 		return;
913 
914 	/* Check if a FW update is required */
915 
916 	if (changed & IEEE80211_CHANCTX_CHANGE_AP)
917 		goto update;
918 
919 	if (chandef->chan == phy->chandef.chan &&
920 	    chandef->center_freq1 == phy->chandef.center_freq1 &&
921 	    chandef->punctured == phy->chandef.punctured) {
922 		/* Check if we are toggling between HT and non-HT, no-op */
923 		if (phy->chandef.width == chandef->width ||
924 		    (phy->chandef.width <= NL80211_CHAN_WIDTH_20 &&
925 		     chandef->width <= NL80211_CHAN_WIDTH_20))
926 			return;
927 	}
928 update:
929 
930 	iwl_mld_update_phy_chandef(mld, ctx);
931 }
932 
933 static u8
934 iwl_mld_chandef_get_primary_80(struct cfg80211_chan_def *chandef)
935 {
936 	int data_start;
937 	int control_start;
938 	int bw;
939 
940 	if (chandef->width == NL80211_CHAN_WIDTH_320)
941 		bw = 320;
942 	else if (chandef->width == NL80211_CHAN_WIDTH_160)
943 		bw = 160;
944 	else
945 		return 0;
946 
947 	/* data is bw wide so the start is half the width */
948 	data_start = chandef->center_freq1 - bw / 2;
949 	/* control is 20Mhz width */
950 	control_start = chandef->chan->center_freq - 10;
951 
952 	return (control_start - data_start) / 80;
953 }
954 
955 static bool iwl_mld_can_activate_link(struct iwl_mld *mld,
956 				      struct ieee80211_vif *vif,
957 				      struct ieee80211_bss_conf *link)
958 {
959 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
960 	struct iwl_mld_sta *mld_sta;
961 	struct iwl_mld_link_sta *link_sta;
962 
963 	/* In association, we activate the assoc link before adding the STA. */
964 	if (!mld_vif->ap_sta || !vif->cfg.assoc)
965 		return true;
966 
967 	mld_sta = iwl_mld_sta_from_mac80211(mld_vif->ap_sta);
968 
969 	/* When switching links, we need to wait with the activation until the
970 	 * STA was added to the FW. It'll be activated in
971 	 * iwl_mld_update_link_stas
972 	 */
973 	link_sta = wiphy_dereference(mld->wiphy, mld_sta->link[link->link_id]);
974 
975 	/* In restart we can have a link_sta that doesn't exist in FW yet */
976 	return link_sta && link_sta->in_fw;
977 }
978 
979 static
980 int iwl_mld_assign_vif_chanctx(struct ieee80211_hw *hw,
981 			       struct ieee80211_vif *vif,
982 			       struct ieee80211_bss_conf *link,
983 			       struct ieee80211_chanctx_conf *ctx)
984 {
985 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
986 	struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
987 	unsigned int n_active = iwl_mld_count_active_links(mld, vif);
988 	int ret;
989 
990 	lockdep_assert_wiphy(mld->wiphy);
991 
992 	if (WARN_ON(!mld_link))
993 		return -EINVAL;
994 
995 	/* if the assigned one was not counted yet, count it now */
996 	if (!rcu_access_pointer(mld_link->chan_ctx)) {
997 		n_active++;
998 
999 		/* Track addition of non-BSS link */
1000 		if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
1001 			ret = iwl_mld_emlsr_check_non_bss_block(mld, 1);
1002 			if (ret)
1003 				return ret;
1004 		}
1005 	}
1006 
1007 	/* for AP, mac parameters such as HE support are updated at this stage. */
1008 	if (vif->type == NL80211_IFTYPE_AP) {
1009 		ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1010 
1011 		if (ret) {
1012 			IWL_ERR(mld, "failed to update MAC %pM\n", vif->addr);
1013 			return -EINVAL;
1014 		}
1015 	}
1016 
1017 	rcu_assign_pointer(mld_link->chan_ctx, ctx);
1018 
1019 	if (n_active > 1) {
1020 		struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1021 
1022 		/* Indicate to mac80211 that EML is enabled */
1023 		vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE;
1024 		mld_vif->emlsr.last_entry_ts = jiffies;
1025 
1026 		if (vif->active_links & BIT(mld_vif->emlsr.selected_links))
1027 			mld_vif->emlsr.primary = mld_vif->emlsr.selected_primary;
1028 		else
1029 			mld_vif->emlsr.primary = __ffs(vif->active_links);
1030 
1031 		iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP,
1032 				       NULL);
1033 	}
1034 
1035 	/* First send the link command with the phy context ID.
1036 	 * Now that we have the phy, we know the band so also the rates
1037 	 */
1038 	ret = iwl_mld_change_link_in_fw(mld, link,
1039 					LINK_CONTEXT_MODIFY_RATES_INFO);
1040 	if (ret)
1041 		goto err;
1042 
1043 	/* TODO: Initialize rate control for the AP station, since we might be
1044 	 * doing a link switch here - we cannot initialize it before since
1045 	 * this needs the phy context assigned (and in FW?), and we cannot
1046 	 * do it later because it needs to be initialized as soon as we're
1047 	 * able to TX on the link, i.e. when active. (task=link-switch)
1048 	 */
1049 
1050 	/* Now activate the link */
1051 	if (iwl_mld_can_activate_link(mld, vif, link)) {
1052 		ret = iwl_mld_activate_link(mld, link);
1053 		if (ret)
1054 			goto err;
1055 	}
1056 
1057 	if (vif->type == NL80211_IFTYPE_STATION)
1058 		iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link);
1059 
1060 	if (vif->type == NL80211_IFTYPE_MONITOR) {
1061 		ret = iwl_mld_add_mon_sta(mld, vif, link);
1062 		if (ret)
1063 			goto deactivate_link;
1064 
1065 		mld->monitor.p80 =
1066 			iwl_mld_chandef_get_primary_80(&vif->bss_conf.chanreq.oper);
1067 	}
1068 
1069 	return 0;
1070 
1071 deactivate_link:
1072 	if (mld_link->active)
1073 		iwl_mld_deactivate_link(mld, link);
1074 err:
1075 	RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
1076 	return ret;
1077 }
1078 
1079 static
1080 void iwl_mld_unassign_vif_chanctx(struct ieee80211_hw *hw,
1081 				  struct ieee80211_vif *vif,
1082 				  struct ieee80211_bss_conf *link,
1083 				  struct ieee80211_chanctx_conf *ctx)
1084 {
1085 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1086 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1087 	struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link);
1088 	unsigned int n_active = iwl_mld_count_active_links(mld, vif);
1089 
1090 	if (WARN_ON(!mld_link))
1091 		return;
1092 
1093 	/* Track removal of non-BSS link */
1094 	if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION)
1095 		iwl_mld_emlsr_check_non_bss_block(mld, -1);
1096 
1097 	iwl_mld_deactivate_link(mld, link);
1098 
1099 	if (vif->type == NL80211_IFTYPE_MONITOR)
1100 		iwl_mld_remove_mon_sta(mld, vif, link);
1101 
1102 	if (n_active > 1) {
1103 		/* Indicate to mac80211 that EML is disabled */
1104 		vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE;
1105 
1106 		iwl_dbg_tlv_time_point(&mld->fwrt,
1107 				       IWL_FW_INI_TIME_ESR_LINK_DOWN,
1108 				       NULL);
1109 	}
1110 
1111 	RCU_INIT_POINTER(mld_link->chan_ctx, NULL);
1112 
1113 	/* in the non-MLO case, remove/re-add the link to clean up FW state.
1114 	 * In MLO, it'll be done in drv_change_vif_link
1115 	 */
1116 	if (!ieee80211_vif_is_mld(vif) && !mld_vif->ap_sta &&
1117 	    !WARN_ON_ONCE(vif->cfg.assoc) &&
1118 	    vif->type != NL80211_IFTYPE_AP && !mld->fw_status.in_hw_restart) {
1119 		iwl_mld_remove_link(mld, link);
1120 		iwl_mld_add_link(mld, link);
1121 	}
1122 }
1123 
1124 static
1125 int iwl_mld_mac80211_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
1126 				       u32 value)
1127 {
1128 	return 0;
1129 }
1130 
1131 static void
1132 iwl_mld_link_info_changed_ap_ibss(struct iwl_mld *mld,
1133 				  struct ieee80211_vif *vif,
1134 				  struct ieee80211_bss_conf *link,
1135 				  u64 changes)
1136 {
1137 	u32 link_changes = 0;
1138 
1139 	if (changes & BSS_CHANGED_ERP_SLOT)
1140 		link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
1141 
1142 	if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT))
1143 		link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
1144 
1145 	if (changes & (BSS_CHANGED_QOS | BSS_CHANGED_BANDWIDTH))
1146 		link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
1147 
1148 	if (changes & BSS_CHANGED_HE_BSS_COLOR)
1149 		link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
1150 
1151 	if (link_changes)
1152 		iwl_mld_change_link_in_fw(mld, link, link_changes);
1153 
1154 	if (changes & BSS_CHANGED_BEACON)
1155 		iwl_mld_update_beacon_template(mld, vif, link);
1156 }
1157 
1158 static
1159 u32 iwl_mld_link_changed_mapping(struct iwl_mld *mld,
1160 				 struct ieee80211_vif *vif,
1161 				 struct ieee80211_bss_conf *link_conf,
1162 				 u64 changes)
1163 {
1164 	u32 link_changes = 0;
1165 	bool has_he, has_eht;
1166 
1167 	if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos)
1168 		link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS;
1169 
1170 	if (changes & (BSS_CHANGED_ERP_PREAMBLE | BSS_CHANGED_BASIC_RATES |
1171 		       BSS_CHANGED_ERP_SLOT))
1172 		link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO;
1173 
1174 	if (changes & (BSS_CHANGED_HT | BSS_CHANGED_ERP_CTS_PROT))
1175 		link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS;
1176 
1177 	/* TODO: task=MLO check mac80211's HE flags and if command is needed
1178 	 * every time there's a link change. Currently used flags are
1179 	 * BSS_CHANGED_HE_OBSS_PD and BSS_CHANGED_HE_BSS_COLOR.
1180 	 */
1181 	has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax;
1182 	has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be;
1183 
1184 	if (vif->cfg.assoc && (has_he || has_eht)) {
1185 		IWL_DEBUG_MAC80211(mld, "Associated in HE mode\n");
1186 		link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS;
1187 	}
1188 
1189 	return link_changes;
1190 }
1191 
1192 static void
1193 iwl_mld_mac80211_link_info_changed_sta(struct iwl_mld *mld,
1194 				       struct ieee80211_vif *vif,
1195 				       struct ieee80211_bss_conf *link_conf,
1196 				       u64 changes)
1197 {
1198 	u32 link_changes = iwl_mld_link_changed_mapping(mld, vif, link_conf,
1199 							changes);
1200 
1201 	if (link_changes)
1202 		iwl_mld_change_link_in_fw(mld, link_conf, link_changes);
1203 
1204 	if (changes & BSS_CHANGED_TPE)
1205 		iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link_conf);
1206 
1207 	if (changes & BSS_CHANGED_BEACON_INFO)
1208 		iwl_mld_update_mac_power(mld, vif, false);
1209 
1210 	/* The firmware will wait quite a while after association before it
1211 	 * starts filtering the beacons. We can safely enable beacon filtering
1212 	 * upon CQM configuration, even if we didn't get a beacon yet.
1213 	 */
1214 	if (changes & (BSS_CHANGED_CQM | BSS_CHANGED_BEACON_INFO))
1215 		iwl_mld_enable_beacon_filter(mld, link_conf, false);
1216 
1217 	if (changes & BSS_CHANGED_BANDWIDTH)
1218 		iwl_mld_retry_emlsr(mld, vif);
1219 }
1220 
1221 static int iwl_mld_update_mu_groups(struct iwl_mld *mld,
1222 				    struct ieee80211_bss_conf *link_conf)
1223 {
1224 	struct iwl_mu_group_mgmt_cmd cmd = {};
1225 
1226 	BUILD_BUG_ON(sizeof(cmd.membership_status) !=
1227 		     sizeof(link_conf->mu_group.membership));
1228 	BUILD_BUG_ON(sizeof(cmd.user_position) !=
1229 		     sizeof(link_conf->mu_group.position));
1230 
1231 	memcpy(cmd.membership_status, link_conf->mu_group.membership,
1232 	       WLAN_MEMBERSHIP_LEN);
1233 	memcpy(cmd.user_position, link_conf->mu_group.position,
1234 	       WLAN_USER_POSITION_LEN);
1235 
1236 	return iwl_mld_send_cmd_pdu(mld,
1237 				    WIDE_ID(DATA_PATH_GROUP,
1238 					    UPDATE_MU_GROUPS_CMD),
1239 				    &cmd);
1240 }
1241 
1242 static void
1243 iwl_mld_mac80211_link_info_changed(struct ieee80211_hw *hw,
1244 				   struct ieee80211_vif *vif,
1245 				   struct ieee80211_bss_conf *link_conf,
1246 				   u64 changes)
1247 {
1248 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1249 
1250 	switch (vif->type) {
1251 	case NL80211_IFTYPE_STATION:
1252 		iwl_mld_mac80211_link_info_changed_sta(mld, vif, link_conf,
1253 						       changes);
1254 		break;
1255 	case NL80211_IFTYPE_AP:
1256 	case NL80211_IFTYPE_ADHOC:
1257 		iwl_mld_link_info_changed_ap_ibss(mld, vif, link_conf,
1258 						  changes);
1259 		break;
1260 	case NL80211_IFTYPE_MONITOR:
1261 		/* The firmware tracks this on its own in STATION mode, but
1262 		 * obviously not in sniffer mode.
1263 		 */
1264 		if (changes & BSS_CHANGED_MU_GROUPS)
1265 			iwl_mld_update_mu_groups(mld, link_conf);
1266 		break;
1267 	default:
1268 		/* shouldn't happen */
1269 		WARN_ON_ONCE(1);
1270 	}
1271 
1272 	/* We now know our BSSID, we can configure the MAC context with
1273 	 * eht_support if needed.
1274 	 */
1275 	if (changes & BSS_CHANGED_BSSID)
1276 		iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1277 
1278 	if (changes & BSS_CHANGED_TXPOWER)
1279 		iwl_mld_set_tx_power(mld, link_conf, link_conf->txpower);
1280 }
1281 
1282 static void
1283 iwl_mld_smps_workaround(struct iwl_mld *mld, struct ieee80211_vif *vif, bool enable)
1284 {
1285 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1286 	bool workaround_required =
1287 		iwl_fw_lookup_cmd_ver(mld->fw, MAC_PM_POWER_TABLE, 0) < 2;
1288 
1289 	if (!workaround_required)
1290 		return;
1291 
1292 	/* Send the device-level power commands since the
1293 	 * firmware checks the POWER_TABLE_CMD's POWER_SAVE_EN bit to
1294 	 * determine SMPS mode.
1295 	 */
1296 	if (mld_vif->ps_disabled == !enable)
1297 		return;
1298 
1299 	mld_vif->ps_disabled = !enable;
1300 
1301 	iwl_mld_update_device_power(mld, false);
1302 }
1303 
1304 static
1305 void iwl_mld_mac80211_vif_cfg_changed(struct ieee80211_hw *hw,
1306 				      struct ieee80211_vif *vif,
1307 				      u64 changes)
1308 {
1309 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1310 	int ret;
1311 
1312 	lockdep_assert_wiphy(mld->wiphy);
1313 
1314 	if (vif->type != NL80211_IFTYPE_STATION)
1315 		return;
1316 
1317 	if (changes & BSS_CHANGED_ASSOC) {
1318 		ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY);
1319 		if (ret)
1320 			IWL_ERR(mld, "failed to update context\n");
1321 
1322 		if (vif->cfg.assoc) {
1323 			/* Clear statistics to get clean beacon counter, and
1324 			 * ask for periodic statistics, as they are needed for
1325 			 * link selection and RX OMI decisions.
1326 			 */
1327 			iwl_mld_clear_stats_in_fw(mld);
1328 			iwl_mld_request_periodic_fw_stats(mld, true);
1329 
1330 			iwl_mld_set_vif_associated(mld, vif);
1331 		} else {
1332 			iwl_mld_request_periodic_fw_stats(mld, false);
1333 		}
1334 	}
1335 
1336 	if (changes & BSS_CHANGED_PS) {
1337 		iwl_mld_smps_workaround(mld, vif, vif->cfg.ps);
1338 		iwl_mld_update_mac_power(mld, vif, false);
1339 	}
1340 
1341 	/* TODO: task=MLO BSS_CHANGED_MLD_VALID_LINKS/CHANGED_MLD_TTLM */
1342 }
1343 
1344 static int
1345 iwl_mld_mac80211_hw_scan(struct ieee80211_hw *hw,
1346 			 struct ieee80211_vif *vif,
1347 			 struct ieee80211_scan_request *hw_req)
1348 {
1349 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1350 	int ret;
1351 
1352 	if (WARN_ON(!hw_req->req.n_channels ||
1353 		    hw_req->req.n_channels >
1354 		    mld->fw->ucode_capa.n_scan_channels))
1355 		return -EINVAL;
1356 
1357 	ret = iwl_mld_regular_scan_start(mld, vif, &hw_req->req, &hw_req->ies);
1358 	if (!ret) {
1359 		/* We will be busy with scanning, so the counters may not reflect the
1360 		 * reality. Stop checking the counters until the scan ends
1361 		 */
1362 		iwl_mld_start_ignoring_tpt_updates(mld);
1363 	}
1364 
1365 	return ret;
1366 }
1367 
1368 static void
1369 iwl_mld_mac80211_cancel_hw_scan(struct ieee80211_hw *hw,
1370 				struct ieee80211_vif *vif)
1371 {
1372 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1373 
1374 	/* Due to a race condition, it's possible that mac80211 asks
1375 	 * us to stop a hw_scan when it's already stopped. This can
1376 	 * happen, for instance, if we stopped the scan ourselves,
1377 	 * called ieee80211_scan_completed() and the userspace called
1378 	 * cancel scan before ieee80211_scan_work() could run.
1379 	 * To handle that, simply return if the scan is not running.
1380 	 */
1381 	if (mld->scan.status & IWL_MLD_SCAN_REGULAR) {
1382 		iwl_mld_scan_stop(mld, IWL_MLD_SCAN_REGULAR, true);
1383 		/* Scan is over, we can check again the tpt counters */
1384 		iwl_mld_stop_ignoring_tpt_updates(mld);
1385 	}
1386 }
1387 
1388 static int
1389 iwl_mld_mac80211_sched_scan_start(struct ieee80211_hw *hw,
1390 				  struct ieee80211_vif *vif,
1391 				  struct cfg80211_sched_scan_request *req,
1392 				  struct ieee80211_scan_ies *ies)
1393 {
1394 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1395 
1396 	return iwl_mld_sched_scan_start(mld, vif, req, ies, IWL_MLD_SCAN_SCHED);
1397 }
1398 
1399 static int
1400 iwl_mld_mac80211_sched_scan_stop(struct ieee80211_hw *hw,
1401 				 struct ieee80211_vif *vif)
1402 {
1403 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1404 
1405 	/* Due to a race condition, it's possible that mac80211 asks
1406 	 * us to stop a sched_scan when it's already stopped. This
1407 	 * can happen, for instance, if we stopped the scan ourselves,
1408 	 * called ieee80211_sched_scan_stopped() and the userspace called
1409 	 * stop sched scan before ieee80211_sched_scan_stopped_work()
1410 	 * could run. To handle this, simply return if the scan is
1411 	 * not running.
1412 	 */
1413 	if (!(mld->scan.status & IWL_MLD_SCAN_SCHED))
1414 		return 0;
1415 
1416 	return iwl_mld_scan_stop(mld, IWL_MLD_SCAN_SCHED, false);
1417 }
1418 
1419 static void
1420 iwl_mld_mac80211_reconfig_complete(struct ieee80211_hw *hw,
1421 				   enum ieee80211_reconfig_type reconfig_type)
1422 {
1423 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1424 
1425 	switch (reconfig_type) {
1426 	case IEEE80211_RECONFIG_TYPE_RESTART:
1427 		mld->fw_status.in_hw_restart = false;
1428 		iwl_mld_send_recovery_cmd(mld, ERROR_RECOVERY_END_OF_RECOVERY);
1429 		iwl_trans_finish_sw_reset(mld->trans);
1430 		/* no need to lock, adding in parallel would schedule too */
1431 		if (!list_empty(&mld->txqs_to_add))
1432 			wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk);
1433 
1434 		IWL_INFO(mld, "restart completed\n");
1435 		break;
1436 	case IEEE80211_RECONFIG_TYPE_SUSPEND:
1437 		break;
1438 	}
1439 }
1440 
1441 static
1442 void iwl_mld_mac80211_mgd_prepare_tx(struct ieee80211_hw *hw,
1443 				     struct ieee80211_vif *vif,
1444 				     struct ieee80211_prep_tx_info *info)
1445 {
1446 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1447 	u32 duration = IWL_MLD_SESSION_PROTECTION_ASSOC_TIME_MS;
1448 
1449 	/* After a successful association the connection is established
1450 	 * and we can rely on the quota to send the disassociation frame.
1451 	 */
1452 	if (info->was_assoc)
1453 		return;
1454 
1455 	if (info->duration > duration)
1456 		duration = info->duration;
1457 
1458 	iwl_mld_schedule_session_protection(mld, vif, duration,
1459 					    IWL_MLD_SESSION_PROTECTION_MIN_TIME_MS,
1460 					    info->link_id);
1461 }
1462 
1463 static
1464 void iwl_mld_mac_mgd_complete_tx(struct ieee80211_hw *hw,
1465 				 struct ieee80211_vif *vif,
1466 				 struct ieee80211_prep_tx_info *info)
1467 {
1468 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1469 
1470 	/* Successful authentication is the only case that requires to let
1471 	 * the session protection go. We'll need it for the upcoming
1472 	 * association. For all the other cases, we need to cancel the session
1473 	 * protection.
1474 	 * After successful association the connection is established and
1475 	 * further mgd tx can rely on the quota.
1476 	 */
1477 	if (info->success && info->subtype == IEEE80211_STYPE_AUTH)
1478 		return;
1479 
1480 	/* The firmware will be on medium after we configure the vif as
1481 	 * associated. Removing the session protection allows the firmware
1482 	 * to stop being on medium. In order to ensure the continuity of our
1483 	 * presence on medium, we need first to configure the vif as associated
1484 	 * and only then, remove the session protection.
1485 	 * Currently, mac80211 calls vif_cfg_changed() first and then,
1486 	 * drv_mgd_complete_tx(). Ensure that this assumption stays true by
1487 	 * a warning.
1488 	 */
1489 	WARN_ON(info->success &&
1490 		(info->subtype == IEEE80211_STYPE_ASSOC_REQ ||
1491 		 info->subtype == IEEE80211_STYPE_REASSOC_REQ) &&
1492 		!vif->cfg.assoc);
1493 
1494 	iwl_mld_cancel_session_protection(mld, vif, info->link_id);
1495 }
1496 
1497 static int
1498 iwl_mld_mac80211_conf_tx(struct ieee80211_hw *hw,
1499 			 struct ieee80211_vif *vif,
1500 			 unsigned int link_id, u16 ac,
1501 			 const struct ieee80211_tx_queue_params *params)
1502 {
1503 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1504 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1505 	struct iwl_mld_link *link;
1506 
1507 	lockdep_assert_wiphy(mld->wiphy);
1508 
1509 	link = iwl_mld_link_dereference_check(mld_vif, link_id);
1510 	if (!link)
1511 		return -EINVAL;
1512 
1513 	link->queue_params[ac] = *params;
1514 
1515 	/* No need to update right away, we'll get BSS_CHANGED_QOS
1516 	 * The exception is P2P_DEVICE interface which needs immediate update.
1517 	 */
1518 	if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
1519 		iwl_mld_change_link_in_fw(mld, &vif->bss_conf,
1520 					  LINK_CONTEXT_MODIFY_QOS_PARAMS);
1521 
1522 	return 0;
1523 }
1524 
1525 static void iwl_mld_set_uapsd(struct iwl_mld *mld, struct ieee80211_vif *vif)
1526 {
1527 	vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
1528 
1529 	if (vif->type != NL80211_IFTYPE_STATION)
1530 		return;
1531 
1532 	if (vif->p2p &&
1533 	    !(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_P2P_CLIENT))
1534 		vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
1535 
1536 	if (!vif->p2p &&
1537 	    !(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS))
1538 		vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
1539 }
1540 
1541 int iwl_mld_tdls_sta_count(struct iwl_mld *mld)
1542 {
1543 	int count = 0;
1544 
1545 	lockdep_assert_wiphy(mld->wiphy);
1546 
1547 	for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
1548 		struct ieee80211_link_sta *link_sta;
1549 
1550 		link_sta = wiphy_dereference(mld->wiphy,
1551 					     mld->fw_id_to_link_sta[i]);
1552 		if (IS_ERR_OR_NULL(link_sta))
1553 			continue;
1554 
1555 		if (!link_sta->sta->tdls)
1556 			continue;
1557 
1558 		count++;
1559 	}
1560 
1561 	return count;
1562 }
1563 
1564 static void iwl_mld_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
1565 						    struct cfg80211_bss *bss,
1566 						    void *_data)
1567 {
1568 	bool *tolerated = _data;
1569 	const struct cfg80211_bss_ies *ies;
1570 	const struct element *elem;
1571 
1572 	rcu_read_lock();
1573 	ies = rcu_dereference(bss->ies);
1574 	elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
1575 				  ies->len);
1576 
1577 	if (!elem || elem->datalen < 10 ||
1578 	    !(elem->data[10] &
1579 	      WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
1580 		*tolerated = false;
1581 	}
1582 	rcu_read_unlock();
1583 }
1584 
1585 static void
1586 iwl_mld_check_he_obss_narrow_bw_ru(struct iwl_mld *mld,
1587 				   struct iwl_mld_link *mld_link,
1588 				   struct ieee80211_bss_conf *link_conf)
1589 {
1590 	bool tolerated = true;
1591 
1592 	if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan))
1593 		return;
1594 
1595 	if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) {
1596 		mld_link->he_ru_2mhz_block = false;
1597 		return;
1598 	}
1599 
1600 	cfg80211_bss_iter(mld->wiphy, &link_conf->chanreq.oper,
1601 			  iwl_mld_check_he_obss_narrow_bw_ru_iter, &tolerated);
1602 
1603 	/* If there is at least one AP on radar channel that cannot
1604 	 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
1605 	 */
1606 	mld_link->he_ru_2mhz_block = !tolerated;
1607 }
1608 
1609 static void iwl_mld_link_set_2mhz_block(struct iwl_mld *mld,
1610 					struct ieee80211_vif *vif,
1611 					struct ieee80211_sta *sta)
1612 {
1613 	struct ieee80211_link_sta *link_sta;
1614 	unsigned int link_id;
1615 
1616 	for_each_sta_active_link(vif, sta, link_sta, link_id) {
1617 		struct ieee80211_bss_conf *link_conf =
1618 			link_conf_dereference_protected(vif, link_id);
1619 		struct iwl_mld_link *mld_link =
1620 			iwl_mld_link_from_mac80211(link_conf);
1621 
1622 		if (WARN_ON(!link_conf || !mld_link))
1623 			continue;
1624 
1625 		if (link_sta->he_cap.has_he)
1626 			iwl_mld_check_he_obss_narrow_bw_ru(mld, mld_link,
1627 							   link_conf);
1628 	}
1629 }
1630 
1631 static int iwl_mld_move_sta_state_up(struct iwl_mld *mld,
1632 				     struct ieee80211_vif *vif,
1633 				     struct ieee80211_sta *sta,
1634 				     enum ieee80211_sta_state old_state,
1635 				     enum ieee80211_sta_state new_state)
1636 {
1637 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1638 	int tdls_count = 0;
1639 	int ret;
1640 
1641 	if (old_state == IEEE80211_STA_NOTEXIST &&
1642 	    new_state == IEEE80211_STA_NONE) {
1643 		if (sta->tdls) {
1644 			if (vif->p2p || hweight8(mld->used_phy_ids) != 1)
1645 				return -EBUSY;
1646 
1647 			tdls_count = iwl_mld_tdls_sta_count(mld);
1648 			if (tdls_count >= IWL_TDLS_STA_COUNT)
1649 				return -EBUSY;
1650 		}
1651 
1652 		ret = iwl_mld_add_sta(mld, sta, vif, STATION_TYPE_PEER);
1653 		if (ret)
1654 			return ret;
1655 
1656 		/* just added first TDLS STA, so disable PM */
1657 		if (sta->tdls && tdls_count == 0)
1658 			iwl_mld_update_mac_power(mld, vif, false);
1659 
1660 		if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
1661 			mld_vif->ap_sta = sta;
1662 
1663 		/* Initialize TLC here already - this really tells
1664 		 * the firmware only what the supported legacy rates are
1665 		 * (may be) since it's initialized already from what the
1666 		 * AP advertised in the beacon/probe response. This will
1667 		 * allow the firmware to send auth/assoc frames with one
1668 		 * of the supported rates already, rather than having to
1669 		 * use a mandatory rate.
1670 		 * If we're the AP, we'll just assume mandatory rates at
1671 		 * this point, but we know nothing about the STA anyway.
1672 		 */
1673 		iwl_mld_config_tlc(mld, vif, sta);
1674 
1675 		return ret;
1676 	} else if (old_state == IEEE80211_STA_NONE &&
1677 		   new_state == IEEE80211_STA_AUTH) {
1678 		iwl_mld_set_uapsd(mld, vif);
1679 		return 0;
1680 	} else if (old_state == IEEE80211_STA_AUTH &&
1681 		   new_state == IEEE80211_STA_ASSOC) {
1682 		ret = iwl_mld_update_all_link_stations(mld, sta);
1683 
1684 		if (vif->type == NL80211_IFTYPE_STATION)
1685 			iwl_mld_link_set_2mhz_block(mld, vif, sta);
1686 		/* Now the link_sta's capabilities are set, update the FW */
1687 		iwl_mld_config_tlc(mld, vif, sta);
1688 
1689 		if (vif->type == NL80211_IFTYPE_AP) {
1690 			/* Update MAC_CFG_FILTER_ACCEPT_BEACON if at least
1691 			 * one sta is associated
1692 			 */
1693 			if (++mld_vif->num_associated_stas == 1)
1694 				ret = iwl_mld_mac_fw_action(mld, vif,
1695 							    FW_CTXT_ACTION_MODIFY);
1696 		}
1697 
1698 		return ret;
1699 	} else if (old_state == IEEE80211_STA_ASSOC &&
1700 		   new_state == IEEE80211_STA_AUTHORIZED) {
1701 		ret = 0;
1702 
1703 		if (!sta->tdls) {
1704 			mld_vif->authorized = true;
1705 
1706 			/* Ensure any block due to a non-BSS link is synced */
1707 			iwl_mld_emlsr_check_non_bss_block(mld, 0);
1708 
1709 			/* Block EMLSR until a certain throughput it reached */
1710 			if (!mld->fw_status.in_hw_restart &&
1711 			    IWL_MLD_ENTER_EMLSR_TPT_THRESH > 0)
1712 				iwl_mld_block_emlsr(mld_vif->mld, vif,
1713 						    IWL_MLD_EMLSR_BLOCKED_TPT,
1714 						    0);
1715 
1716 			/* clear COEX_HIGH_PRIORITY_ENABLE */
1717 			ret = iwl_mld_mac_fw_action(mld, vif,
1718 						    FW_CTXT_ACTION_MODIFY);
1719 			if (ret)
1720 				return ret;
1721 			iwl_mld_smps_workaround(mld, vif, vif->cfg.ps);
1722 		}
1723 
1724 		/* MFP is set by default before the station is authorized.
1725 		 * Clear it here in case it's not used.
1726 		 */
1727 		if (!sta->mfp)
1728 			ret = iwl_mld_update_all_link_stations(mld, sta);
1729 
1730 		/* We can use wide bandwidth now, not only 20 MHz */
1731 		iwl_mld_config_tlc(mld, vif, sta);
1732 
1733 		return ret;
1734 	} else {
1735 		return -EINVAL;
1736 	}
1737 }
1738 
1739 static int iwl_mld_move_sta_state_down(struct iwl_mld *mld,
1740 				       struct ieee80211_vif *vif,
1741 				       struct ieee80211_sta *sta,
1742 				       enum ieee80211_sta_state old_state,
1743 				       enum ieee80211_sta_state new_state)
1744 {
1745 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1746 
1747 	if (old_state == IEEE80211_STA_AUTHORIZED &&
1748 	    new_state == IEEE80211_STA_ASSOC) {
1749 		if (!sta->tdls) {
1750 			mld_vif->authorized = false;
1751 
1752 			memset(&mld_vif->emlsr.zeroed_on_not_authorized, 0,
1753 			       sizeof(mld_vif->emlsr.zeroed_on_not_authorized));
1754 
1755 			wiphy_delayed_work_cancel(mld->wiphy,
1756 						  &mld_vif->emlsr.prevent_done_wk);
1757 			wiphy_delayed_work_cancel(mld->wiphy,
1758 						  &mld_vif->emlsr.tmp_non_bss_done_wk);
1759 			wiphy_work_cancel(mld->wiphy, &mld_vif->emlsr.unblock_tpt_wk);
1760 			wiphy_delayed_work_cancel(mld->wiphy,
1761 						  &mld_vif->emlsr.check_tpt_wk);
1762 
1763 			iwl_mld_reset_cca_40mhz_workaround(mld, vif);
1764 			iwl_mld_smps_workaround(mld, vif, true);
1765 		}
1766 
1767 		/* once we move into assoc state, need to update the FW to
1768 		 * stop using wide bandwidth
1769 		 */
1770 		iwl_mld_config_tlc(mld, vif, sta);
1771 	} else if (old_state == IEEE80211_STA_ASSOC &&
1772 		   new_state == IEEE80211_STA_AUTH) {
1773 		if (vif->type == NL80211_IFTYPE_AP &&
1774 		    !WARN_ON(!mld_vif->num_associated_stas)) {
1775 			/* Update MAC_CFG_FILTER_ACCEPT_BEACON if the last sta
1776 			 * is disassociating
1777 			 */
1778 			if (--mld_vif->num_associated_stas == 0)
1779 				iwl_mld_mac_fw_action(mld, vif,
1780 						      FW_CTXT_ACTION_MODIFY);
1781 		}
1782 	} else if (old_state == IEEE80211_STA_AUTH &&
1783 		   new_state == IEEE80211_STA_NONE) {
1784 		/* nothing */
1785 	} else if (old_state == IEEE80211_STA_NONE &&
1786 		   new_state == IEEE80211_STA_NOTEXIST) {
1787 		iwl_mld_remove_sta(mld, sta);
1788 
1789 		if (sta->tdls && iwl_mld_tdls_sta_count(mld) == 0) {
1790 			/* just removed last TDLS STA, so enable PM */
1791 			iwl_mld_update_mac_power(mld, vif, false);
1792 		}
1793 	} else {
1794 		return -EINVAL;
1795 	}
1796 	return 0;
1797 }
1798 
1799 static int iwl_mld_mac80211_sta_state(struct ieee80211_hw *hw,
1800 				      struct ieee80211_vif *vif,
1801 				      struct ieee80211_sta *sta,
1802 				      enum ieee80211_sta_state old_state,
1803 				      enum ieee80211_sta_state new_state)
1804 {
1805 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1806 	struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
1807 
1808 	IWL_DEBUG_MAC80211(mld, "station %pM state change %d->%d\n",
1809 			   sta->addr, old_state, new_state);
1810 
1811 	mld_sta->sta_state = new_state;
1812 
1813 	if (old_state < new_state)
1814 		return iwl_mld_move_sta_state_up(mld, vif, sta, old_state,
1815 						 new_state);
1816 	else
1817 		return iwl_mld_move_sta_state_down(mld, vif, sta, old_state,
1818 						   new_state);
1819 }
1820 
1821 static void iwl_mld_mac80211_flush(struct ieee80211_hw *hw,
1822 				   struct ieee80211_vif *vif,
1823 				   u32 queues, bool drop)
1824 {
1825 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1826 
1827 	/* Make sure we're done with the deferred traffic before flushing */
1828 	iwl_mld_add_txq_list(mld);
1829 
1830 	for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
1831 		struct ieee80211_link_sta *link_sta =
1832 			wiphy_dereference(mld->wiphy,
1833 					  mld->fw_id_to_link_sta[i]);
1834 
1835 		if (IS_ERR_OR_NULL(link_sta))
1836 			continue;
1837 
1838 		/* Check that the sta belongs to the given vif */
1839 		if (vif && vif != iwl_mld_sta_from_mac80211(link_sta->sta)->vif)
1840 			continue;
1841 
1842 		if (drop)
1843 			iwl_mld_flush_sta_txqs(mld, link_sta->sta);
1844 		else
1845 			iwl_mld_wait_sta_txqs_empty(mld, link_sta->sta);
1846 	}
1847 }
1848 
1849 static void iwl_mld_mac80211_flush_sta(struct ieee80211_hw *hw,
1850 				       struct ieee80211_vif *vif,
1851 				       struct ieee80211_sta *sta)
1852 {
1853 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1854 
1855 	iwl_mld_flush_sta_txqs(mld, sta);
1856 }
1857 
1858 static int
1859 iwl_mld_mac80211_ampdu_action(struct ieee80211_hw *hw,
1860 			      struct ieee80211_vif *vif,
1861 			      struct ieee80211_ampdu_params *params)
1862 {
1863 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1864 	struct ieee80211_sta *sta = params->sta;
1865 	enum ieee80211_ampdu_mlme_action action = params->action;
1866 	u16 tid = params->tid;
1867 	u16 ssn = params->ssn;
1868 	u16 buf_size = params->buf_size;
1869 	u16 timeout = params->timeout;
1870 	int ret;
1871 
1872 	IWL_DEBUG_HT(mld, "A-MPDU action on addr %pM tid: %d action: %d\n",
1873 		     sta->addr, tid, action);
1874 
1875 	switch (action) {
1876 	case IEEE80211_AMPDU_RX_START:
1877 		if (!iwl_enable_rx_ampdu()) {
1878 			ret = -EINVAL;
1879 			break;
1880 		}
1881 		ret = iwl_mld_ampdu_rx_start(mld, sta, tid, ssn, buf_size,
1882 					     timeout);
1883 		break;
1884 	case IEEE80211_AMPDU_RX_STOP:
1885 		ret = iwl_mld_ampdu_rx_stop(mld, sta, tid);
1886 		break;
1887 	default:
1888 		/* The mac80211 TX_AMPDU_SETUP_IN_HW flag is set for all
1889 		 * devices, since all support TX A-MPDU offload in hardware.
1890 		 * Therefore, no TX action should be requested here.
1891 		 */
1892 		WARN_ON_ONCE(1);
1893 		return -EINVAL;
1894 	}
1895 
1896 	return ret;
1897 }
1898 
1899 static bool iwl_mld_can_hw_csum(struct sk_buff *skb)
1900 {
1901 	u8 protocol = ip_hdr(skb)->protocol;
1902 
1903 	return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
1904 }
1905 
1906 static bool iwl_mld_mac80211_can_aggregate(struct ieee80211_hw *hw,
1907 					   struct sk_buff *head,
1908 					   struct sk_buff *skb)
1909 {
1910 	if (!IS_ENABLED(CONFIG_INET))
1911 		return false;
1912 
1913 	/* For now don't aggregate IPv6 in AMSDU */
1914 	if (skb->protocol != htons(ETH_P_IP))
1915 		return false;
1916 
1917 	/* Allow aggregation only if both frames have the same HW csum offload
1918 	 * capability, ensuring consistent HW or SW csum handling in A-MSDU.
1919 	 */
1920 	return iwl_mld_can_hw_csum(skb) == iwl_mld_can_hw_csum(head);
1921 }
1922 
1923 static void iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw *hw)
1924 {
1925 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1926 
1927 	iwl_mld_sync_rx_queues(mld, IWL_MLD_RXQ_EMPTY, NULL, 0);
1928 }
1929 
1930 static void iwl_mld_sta_rc_update(struct ieee80211_hw *hw,
1931 				  struct ieee80211_vif *vif,
1932 				  struct ieee80211_link_sta *link_sta,
1933 				  u32 changed)
1934 {
1935 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1936 
1937 	if (changed & (IEEE80211_RC_BW_CHANGED |
1938 		       IEEE80211_RC_SUPP_RATES_CHANGED |
1939 		       IEEE80211_RC_NSS_CHANGED)) {
1940 		struct ieee80211_bss_conf *link =
1941 			link_conf_dereference_check(vif, link_sta->link_id);
1942 
1943 		if (WARN_ON(!link))
1944 			return;
1945 
1946 		iwl_mld_config_tlc_link(mld, vif, link, link_sta);
1947 	}
1948 }
1949 
1950 #ifdef CONFIG_PM_SLEEP
1951 static void iwl_mld_set_wakeup(struct ieee80211_hw *hw, bool enabled)
1952 {
1953 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1954 
1955 	device_set_wakeup_enable(mld->trans->dev, enabled);
1956 }
1957 
1958 /* Returns 0 on success. 1 if failed to suspend with wowlan:
1959  * If the circumstances didn't satisfy the conditions for suspension
1960  * with wowlan, mac80211 would use the no_wowlan flow.
1961  * If an error had occurred we update the trans status and state here
1962  * and the result will be stopping the FW.
1963  */
1964 static int
1965 iwl_mld_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1966 {
1967 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1968 	int ret;
1969 
1970 	iwl_fw_runtime_suspend(&mld->fwrt);
1971 
1972 	ret = iwl_mld_wowlan_suspend(mld, wowlan);
1973 	if (ret)
1974 		return 1;
1975 
1976 	if (iwl_mld_no_wowlan_suspend(mld))
1977 		return 1;
1978 
1979 	return 0;
1980 }
1981 
1982 static int iwl_mld_resume(struct ieee80211_hw *hw)
1983 {
1984 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1985 	int ret;
1986 
1987 	ret = iwl_mld_wowlan_resume(mld);
1988 	if (ret)
1989 		return ret;
1990 
1991 	iwl_fw_runtime_resume(&mld->fwrt);
1992 
1993 	iwl_mld_low_latency_restart(mld);
1994 
1995 	return 0;
1996 }
1997 #endif
1998 
1999 static int iwl_mld_alloc_ptk_pn(struct iwl_mld *mld,
2000 				struct iwl_mld_sta *mld_sta,
2001 				struct ieee80211_key_conf *key,
2002 				struct iwl_mld_ptk_pn **ptk_pn)
2003 {
2004 	u8 num_rx_queues = mld->trans->info.num_rxqs;
2005 	int keyidx = key->keyidx;
2006 	struct ieee80211_key_seq seq;
2007 
2008 	if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2009 		return -EINVAL;
2010 
2011 	WARN_ON(rcu_access_pointer(mld_sta->ptk_pn[keyidx]));
2012 	*ptk_pn = kzalloc(struct_size(*ptk_pn, q, num_rx_queues),
2013 			  GFP_KERNEL);
2014 	if (!*ptk_pn)
2015 		return -ENOMEM;
2016 
2017 	for (u8 tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2018 		ieee80211_get_key_rx_seq(key, tid, &seq);
2019 		for (u8 q = 0; q < num_rx_queues; q++)
2020 			memcpy((*ptk_pn)->q[q].pn[tid], seq.ccmp.pn,
2021 			       IEEE80211_CCMP_PN_LEN);
2022 	}
2023 
2024 	rcu_assign_pointer(mld_sta->ptk_pn[keyidx], *ptk_pn);
2025 
2026 	return 0;
2027 }
2028 
2029 static int iwl_mld_set_key_add(struct iwl_mld *mld,
2030 			       struct ieee80211_vif *vif,
2031 			       struct ieee80211_sta *sta,
2032 			       struct ieee80211_key_conf *key)
2033 {
2034 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2035 	struct iwl_mld_sta *mld_sta =
2036 		sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2037 	struct iwl_mld_ptk_pn *ptk_pn = NULL;
2038 	int keyidx = key->keyidx;
2039 	int ret;
2040 
2041 	/* Will be set to 0 if added successfully */
2042 	key->hw_key_idx = STA_KEY_IDX_INVALID;
2043 
2044 	switch (key->cipher) {
2045 	case WLAN_CIPHER_SUITE_WEP40:
2046 	case WLAN_CIPHER_SUITE_WEP104:
2047 		IWL_DEBUG_MAC80211(mld, "Use SW encryption for WEP\n");
2048 		return -EOPNOTSUPP;
2049 	case WLAN_CIPHER_SUITE_TKIP:
2050 		if (vif->type == NL80211_IFTYPE_STATION) {
2051 			key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
2052 			break;
2053 		}
2054 		IWL_DEBUG_MAC80211(mld, "Use SW encryption for TKIP\n");
2055 		return -EOPNOTSUPP;
2056 	case WLAN_CIPHER_SUITE_CCMP:
2057 	case WLAN_CIPHER_SUITE_GCMP:
2058 	case WLAN_CIPHER_SUITE_GCMP_256:
2059 	case WLAN_CIPHER_SUITE_AES_CMAC:
2060 	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2061 	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2062 		break;
2063 	default:
2064 		return -EOPNOTSUPP;
2065 	}
2066 
2067 	if (keyidx == 6 || keyidx == 7)
2068 		iwl_mld_track_bigtk(mld, vif, key, true);
2069 
2070 	/* After exiting from RFKILL, hostapd configures GTK/ITGK before the
2071 	 * AP is started, but those keys can't be sent to the FW before the
2072 	 * MCAST/BCAST STAs are added to it (which happens upon AP start).
2073 	 * Store it here to be sent later when the AP is started.
2074 	 */
2075 	if ((vif->type == NL80211_IFTYPE_ADHOC ||
2076 	     vif->type == NL80211_IFTYPE_AP) && !sta &&
2077 	     !mld_vif->ap_ibss_active)
2078 		return iwl_mld_store_ap_early_key(mld, key, mld_vif);
2079 
2080 	if (!mld->fw_status.in_hw_restart && mld_sta &&
2081 	    key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2082 	    (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2083 	     key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2084 	     key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2085 		ret = iwl_mld_alloc_ptk_pn(mld, mld_sta, key, &ptk_pn);
2086 		if (ret)
2087 			return ret;
2088 	}
2089 
2090 	IWL_DEBUG_MAC80211(mld, "set hwcrypto key (sta:%pM, id:%d)\n",
2091 			   sta ? sta->addr : NULL, keyidx);
2092 
2093 	ret = iwl_mld_add_key(mld, vif, sta, key);
2094 	if (ret) {
2095 		IWL_WARN(mld, "set key failed (%d)\n", ret);
2096 		if (ptk_pn) {
2097 			RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2098 			kfree(ptk_pn);
2099 		}
2100 
2101 		return -EOPNOTSUPP;
2102 	}
2103 
2104 	return 0;
2105 }
2106 
2107 static void iwl_mld_set_key_remove(struct iwl_mld *mld,
2108 				   struct ieee80211_vif *vif,
2109 				   struct ieee80211_sta *sta,
2110 				   struct ieee80211_key_conf *key)
2111 {
2112 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2113 	struct iwl_mld_sta *mld_sta =
2114 		sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2115 	int keyidx = key->keyidx;
2116 
2117 	if (keyidx == 6 || keyidx == 7)
2118 		iwl_mld_track_bigtk(mld, vif, key, false);
2119 
2120 	if (mld_sta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2121 	    (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2122 	     key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2123 	     key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2124 		struct iwl_mld_ptk_pn *ptk_pn;
2125 
2126 		if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2127 			return;
2128 
2129 		ptk_pn = wiphy_dereference(mld->wiphy,
2130 					   mld_sta->ptk_pn[keyidx]);
2131 		RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2132 		if (!WARN_ON(!ptk_pn))
2133 			kfree_rcu(ptk_pn, rcu_head);
2134 	}
2135 
2136 	/* if this key was stored to be added later to the FW - free it here */
2137 	if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
2138 		iwl_mld_free_ap_early_key(mld, key, mld_vif);
2139 
2140 	/* We already removed it */
2141 	if (key->hw_key_idx == STA_KEY_IDX_INVALID)
2142 		return;
2143 
2144 	IWL_DEBUG_MAC80211(mld, "disable hwcrypto key\n");
2145 
2146 	iwl_mld_remove_key(mld, vif, sta, key);
2147 }
2148 
2149 static int iwl_mld_mac80211_set_key(struct ieee80211_hw *hw,
2150 				    enum set_key_cmd cmd,
2151 				    struct ieee80211_vif *vif,
2152 				    struct ieee80211_sta *sta,
2153 				    struct ieee80211_key_conf *key)
2154 {
2155 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2156 	int ret;
2157 
2158 	switch (cmd) {
2159 	case SET_KEY:
2160 		ret = iwl_mld_set_key_add(mld, vif, sta, key);
2161 		if (ret)
2162 			ret = -EOPNOTSUPP;
2163 		break;
2164 	case DISABLE_KEY:
2165 		iwl_mld_set_key_remove(mld, vif, sta, key);
2166 		ret = 0;
2167 		break;
2168 	default:
2169 		ret = -EINVAL;
2170 		break;
2171 	}
2172 
2173 	return ret;
2174 }
2175 
2176 static int
2177 iwl_mld_pre_channel_switch(struct ieee80211_hw *hw,
2178 			   struct ieee80211_vif *vif,
2179 			   struct ieee80211_channel_switch *chsw)
2180 {
2181 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2182 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2183 	struct iwl_mld_link *mld_link =
2184 		iwl_mld_link_dereference_check(mld_vif, chsw->link_id);
2185 	u8 primary;
2186 	int selected;
2187 
2188 	lockdep_assert_wiphy(mld->wiphy);
2189 
2190 	if (WARN_ON(!mld_link))
2191 		return -EINVAL;
2192 
2193 	IWL_DEBUG_MAC80211(mld, "pre CSA to freq %d\n",
2194 			   chsw->chandef.center_freq1);
2195 
2196 	if (!iwl_mld_emlsr_active(vif))
2197 		return 0;
2198 
2199 	primary = iwl_mld_get_primary_link(vif);
2200 
2201 	/* stay on the primary link unless it is undergoing a CSA with quiet */
2202 	if (chsw->link_id == primary && chsw->block_tx)
2203 		selected = iwl_mld_get_other_link(vif, primary);
2204 	else
2205 		selected = primary;
2206 
2207 	/* Remember to tell the firmware that this link can't tx
2208 	 * Note that this logic seems to be unrelated to emlsr, but it
2209 	 * really is needed only when emlsr is active. When we have a
2210 	 * single link, the firmware will handle all this on its own.
2211 	 * In multi-link scenarios, we can learn about the CSA from
2212 	 * another link and this logic is too complex for the firmware
2213 	 * to track.
2214 	 * Since we want to de-activate the link that got a CSA with mode=1,
2215 	 * we need to tell the firmware not to send any frame on that link
2216 	 * as the firmware may not be aware that link is under a CSA
2217 	 * with mode=1 (no Tx allowed).
2218 	 */
2219 	mld_link->silent_deactivation = chsw->block_tx;
2220 	iwl_mld_exit_emlsr(mld, vif, IWL_MLD_EMLSR_EXIT_CSA, selected);
2221 
2222 	return 0;
2223 }
2224 
2225 static void
2226 iwl_mld_channel_switch(struct ieee80211_hw *hw,
2227 		       struct ieee80211_vif *vif,
2228 		       struct ieee80211_channel_switch *chsw)
2229 {
2230 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2231 
2232 	/* By implementing this operation, we prevent mac80211 from
2233 	 * starting its own channel switch timer, so that we can call
2234 	 * ieee80211_chswitch_done() ourselves at the right time
2235 	 * (Upon receiving the channel_switch_start notification from the fw)
2236 	 */
2237 	IWL_DEBUG_MAC80211(mld,
2238 			   "dummy channel switch op\n");
2239 }
2240 
2241 static int
2242 iwl_mld_post_channel_switch(struct ieee80211_hw *hw,
2243 			    struct ieee80211_vif *vif,
2244 			    struct ieee80211_bss_conf *link_conf)
2245 {
2246 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2247 	struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2248 
2249 	lockdep_assert_wiphy(mld->wiphy);
2250 
2251 	WARN_ON(mld_link->silent_deactivation);
2252 
2253 	return 0;
2254 }
2255 
2256 static void
2257 iwl_mld_abort_channel_switch(struct ieee80211_hw *hw,
2258 			     struct ieee80211_vif *vif,
2259 			     struct ieee80211_bss_conf *link_conf)
2260 {
2261 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2262 	struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2263 
2264 	IWL_DEBUG_MAC80211(mld,
2265 			   "abort channel switch op\n");
2266 	mld_link->silent_deactivation = false;
2267 }
2268 
2269 static int
2270 iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw *hw,
2271 				struct ieee80211_vif_chanctx_switch *vifs)
2272 {
2273 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2274 	int ret;
2275 
2276 	iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2277 				     vifs[0].old_ctx);
2278 	iwl_mld_remove_chanctx(hw, vifs[0].old_ctx);
2279 
2280 	ret = iwl_mld_add_chanctx(hw, vifs[0].new_ctx);
2281 	if (ret) {
2282 		IWL_ERR(mld, "failed to add new_ctx during channel switch\n");
2283 		goto out_reassign;
2284 	}
2285 
2286 	ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2287 					 vifs[0].new_ctx);
2288 	if (ret) {
2289 		IWL_ERR(mld,
2290 			"failed to assign new_ctx during channel switch\n");
2291 		goto out_remove;
2292 	}
2293 
2294 	return 0;
2295 
2296  out_remove:
2297 	iwl_mld_remove_chanctx(hw, vifs[0].new_ctx);
2298  out_reassign:
2299 	if (iwl_mld_add_chanctx(hw, vifs[0].old_ctx)) {
2300 		IWL_ERR(mld, "failed to add old_ctx after failure\n");
2301 		return ret;
2302 	}
2303 
2304 	if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2305 				       vifs[0].old_ctx))
2306 		IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2307 
2308 	return ret;
2309 }
2310 
2311 static int
2312 iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw *hw,
2313 				    struct ieee80211_vif_chanctx_switch *vifs)
2314 {
2315 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2316 	int ret;
2317 
2318 	iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2319 				     vifs[0].old_ctx);
2320 	ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2321 					 vifs[0].new_ctx);
2322 	if (ret) {
2323 		IWL_ERR(mld,
2324 			"failed to assign new_ctx during channel switch\n");
2325 		goto out_reassign;
2326 	}
2327 
2328 	return 0;
2329 
2330 out_reassign:
2331 	if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2332 				       vifs[0].old_ctx))
2333 		IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2334 
2335 	return ret;
2336 }
2337 
2338 static int
2339 iwl_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
2340 			   struct ieee80211_vif_chanctx_switch *vifs,
2341 			   int n_vifs,
2342 			   enum ieee80211_chanctx_switch_mode mode)
2343 {
2344 	int ret;
2345 
2346 	/* we only support a single-vif right now */
2347 	if (n_vifs > 1)
2348 		return -EOPNOTSUPP;
2349 
2350 	switch (mode) {
2351 	case CHANCTX_SWMODE_SWAP_CONTEXTS:
2352 		ret = iwl_mld_switch_vif_chanctx_swap(hw, vifs);
2353 		break;
2354 	case CHANCTX_SWMODE_REASSIGN_VIF:
2355 		ret = iwl_mld_switch_vif_chanctx_reassign(hw, vifs);
2356 		break;
2357 	default:
2358 		ret = -EOPNOTSUPP;
2359 		break;
2360 	}
2361 
2362 	return ret;
2363 }
2364 
2365 static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2366 				       struct ieee80211_vif *vif,
2367 				       struct ieee80211_sta *sta)
2368 {
2369 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2370 	struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
2371 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2372 	struct iwl_mld_link_sta *mld_link_sta;
2373 	u8 link_id;
2374 
2375 	lockdep_assert_wiphy(mld->wiphy);
2376 
2377 	/* This is called before mac80211 does RCU synchronisation,
2378 	 * so here we already invalidate our internal RCU-protected
2379 	 * station pointer. The rest of the code will thus no longer
2380 	 * be able to find the station this way, and we don't rely
2381 	 * on further RCU synchronisation after the sta_state()
2382 	 * callback deleted the station.
2383 	 */
2384 	for_each_mld_link_sta(mld_sta, mld_link_sta, link_id)
2385 		RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id],
2386 				 NULL);
2387 
2388 	if (sta == mld_vif->ap_sta)
2389 		mld_vif->ap_sta = NULL;
2390 }
2391 
2392 static void
2393 iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2394 					   struct ieee80211_vif *vif,
2395 					   unsigned int link_id)
2396 {
2397 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2398 	struct ieee80211_bss_conf *link_conf;
2399 	u32 duration;
2400 	int ret;
2401 
2402 	link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
2403 	if (WARN_ON_ONCE(!link_conf))
2404 		return;
2405 
2406 	/* Protect the session to hear the TDLS setup response on the channel */
2407 
2408 	duration = 2 * link_conf->dtim_period * link_conf->beacon_int;
2409 
2410 	ret = iwl_mld_start_session_protection(mld, vif, duration, duration,
2411 					       link_id, HZ / 5);
2412 	if (ret)
2413 		IWL_ERR(mld,
2414 			"Failed to start session protection for TDLS: %d\n",
2415 			ret);
2416 }
2417 
2418 static bool iwl_mld_can_activate_links(struct ieee80211_hw *hw,
2419 				       struct ieee80211_vif *vif,
2420 				       u16 desired_links)
2421 {
2422 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2423 	int n_links = hweight16(desired_links);
2424 
2425 	/* Check if HW supports the wanted number of links */
2426 	return n_links <= iwl_mld_max_active_links(mld, vif);
2427 }
2428 
2429 static int
2430 iwl_mld_change_vif_links(struct ieee80211_hw *hw,
2431 			 struct ieee80211_vif *vif,
2432 			 u16 old_links, u16 new_links,
2433 			 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
2434 {
2435 	struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2436 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2437 	struct ieee80211_bss_conf *link_conf;
2438 	u16 removed = old_links & ~new_links;
2439 	u16 added = new_links & ~old_links;
2440 	int err;
2441 
2442 	lockdep_assert_wiphy(mld->wiphy);
2443 
2444 	/*
2445 	 * No bits designate non-MLO mode. We can handle MLO exit/enter by
2446 	 * simply mapping that to link ID zero internally.
2447 	 * Note that mac80211 does such a non-MLO to MLO switch during restart
2448 	 * if it was in MLO before. In that case, we do not have a link to
2449 	 * remove.
2450 	 */
2451 	if (old_links == 0 && !mld->fw_status.in_hw_restart)
2452 		removed |= BIT(0);
2453 
2454 	if (new_links == 0)
2455 		added |= BIT(0);
2456 
2457 	for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2458 		if (removed & BIT(i) && !WARN_ON(!old[i]))
2459 			iwl_mld_remove_link(mld, old[i]);
2460 	}
2461 
2462 	for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2463 		if (added & BIT(i)) {
2464 			link_conf = link_conf_dereference_protected(vif, i);
2465 			if (!link_conf) {
2466 				err = -EINVAL;
2467 				goto remove_added_links;
2468 			}
2469 
2470 			err = iwl_mld_add_link(mld, link_conf);
2471 			if (err)
2472 				goto remove_added_links;
2473 		}
2474 	}
2475 
2476 	/*
2477 	 * Ensure we always have a valid primary_link. When using multiple
2478 	 * links the proper value is set in assign_vif_chanctx.
2479 	 */
2480 	mld_vif->emlsr.primary = new_links ? __ffs(new_links) : 0;
2481 
2482 	/*
2483 	 * Special MLO restart case. We did not have a link when the interface
2484 	 * was added, so do the power configuration now.
2485 	 */
2486 	if (old_links == 0 && mld->fw_status.in_hw_restart)
2487 		iwl_mld_update_mac_power(mld, vif, false);
2488 
2489 	return 0;
2490 
2491 remove_added_links:
2492 	for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2493 		if (!(added & BIT(i)))
2494 			continue;
2495 
2496 		link_conf = link_conf_dereference_protected(vif, i);
2497 		if (!link_conf || !iwl_mld_link_from_mac80211(link_conf))
2498 			continue;
2499 
2500 		iwl_mld_remove_link(mld, link_conf);
2501 	}
2502 
2503 	if (WARN_ON(!iwl_mld_error_before_recovery(mld)))
2504 		return err;
2505 
2506 	/* reconfig will fix us anyway */
2507 	return 0;
2508 }
2509 
2510 static int iwl_mld_change_sta_links(struct ieee80211_hw *hw,
2511 				    struct ieee80211_vif *vif,
2512 				    struct ieee80211_sta *sta,
2513 				    u16 old_links, u16 new_links)
2514 {
2515 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2516 
2517 	return iwl_mld_update_link_stas(mld, vif, sta, old_links, new_links);
2518 }
2519 
2520 static int iwl_mld_mac80211_join_ibss(struct ieee80211_hw *hw,
2521 				      struct ieee80211_vif *vif)
2522 {
2523 	return iwl_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
2524 }
2525 
2526 static void iwl_mld_mac80211_leave_ibss(struct ieee80211_hw *hw,
2527 					struct ieee80211_vif *vif)
2528 {
2529 	return iwl_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
2530 }
2531 
2532 static int iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw *hw)
2533 {
2534 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2535 
2536 	return mld->ibss_manager;
2537 }
2538 
2539 static void iwl_mld_prep_add_interface(struct ieee80211_hw *hw,
2540 				       enum nl80211_iftype type)
2541 {
2542 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2543 
2544 	IWL_DEBUG_MAC80211(mld, "prep_add_interface: type=%u\n", type);
2545 
2546 	if (!(type == NL80211_IFTYPE_AP ||
2547 	      type == NL80211_IFTYPE_P2P_GO ||
2548 	      type == NL80211_IFTYPE_P2P_CLIENT))
2549 		return;
2550 
2551 	iwl_mld_emlsr_block_tmp_non_bss(mld);
2552 }
2553 
2554 static int iwl_mld_set_hw_timestamp(struct ieee80211_hw *hw,
2555 				    struct ieee80211_vif *vif,
2556 				    struct cfg80211_set_hw_timestamp *hwts)
2557 {
2558 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2559 	u32 protocols = 0;
2560 
2561 	/* HW timestamping is only supported for a specific station */
2562 	if (!hwts->macaddr)
2563 		return -EOPNOTSUPP;
2564 
2565 	if (hwts->enable)
2566 		protocols =
2567 			IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
2568 
2569 	return iwl_mld_time_sync_config(mld, hwts->macaddr, protocols);
2570 }
2571 
2572 static int iwl_mld_start_pmsr(struct ieee80211_hw *hw,
2573 			      struct ieee80211_vif *vif,
2574 			      struct cfg80211_pmsr_request *request)
2575 {
2576 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2577 
2578 	return iwl_mld_ftm_start(mld, vif, request);
2579 }
2580 
2581 static enum ieee80211_neg_ttlm_res
2582 iwl_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2583 		     struct ieee80211_neg_ttlm *neg_ttlm)
2584 {
2585 	u16 map;
2586 
2587 	/* Verify all TIDs are mapped to the same links set */
2588 	map = neg_ttlm->downlink[0];
2589 	for (int i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
2590 		if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
2591 		    neg_ttlm->uplink[i] != map)
2592 			return NEG_TTLM_RES_REJECT;
2593 	}
2594 
2595 	return NEG_TTLM_RES_ACCEPT;
2596 }
2597 
2598 static int iwl_mld_get_antenna(struct ieee80211_hw *hw, int radio_idx,
2599 			       u32 *tx_ant, u32 *rx_ant)
2600 {
2601 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2602 
2603 	*tx_ant = iwl_mld_get_valid_tx_ant(mld);
2604 	*rx_ant = iwl_mld_get_valid_rx_ant(mld);
2605 
2606 	return 0;
2607 }
2608 
2609 static int iwl_mld_set_antenna(struct ieee80211_hw *hw, int radio_idx,
2610 			       u32 tx_ant, u32 rx_ant)
2611 {
2612 	struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2613 
2614 	if (WARN_ON(!mld->nvm_data))
2615 		return -EBUSY;
2616 
2617 	/* mac80211 ensures the device is not started,
2618 	 * so the firmware cannot be running
2619 	 */
2620 
2621 	mld->set_tx_ant = tx_ant;
2622 	mld->set_rx_ant = rx_ant;
2623 
2624 	iwl_reinit_cab(mld->trans, mld->nvm_data, tx_ant, rx_ant, mld->fw);
2625 
2626 	return 0;
2627 }
2628 
2629 const struct ieee80211_ops iwl_mld_hw_ops = {
2630 	.tx = iwl_mld_mac80211_tx,
2631 	.start = iwl_mld_mac80211_start,
2632 	.stop = iwl_mld_mac80211_stop,
2633 	.config = iwl_mld_mac80211_config,
2634 	.get_antenna = iwl_mld_get_antenna,
2635 	.set_antenna = iwl_mld_set_antenna,
2636 	.add_interface = iwl_mld_mac80211_add_interface,
2637 	.remove_interface = iwl_mld_mac80211_remove_interface,
2638 	.conf_tx = iwl_mld_mac80211_conf_tx,
2639 	.prepare_multicast = iwl_mld_mac80211_prepare_multicast,
2640 	.configure_filter = iwl_mld_mac80211_configure_filter,
2641 	.reconfig_complete = iwl_mld_mac80211_reconfig_complete,
2642 	.wake_tx_queue = iwl_mld_mac80211_wake_tx_queue,
2643 	.add_chanctx = iwl_mld_add_chanctx,
2644 	.remove_chanctx = iwl_mld_remove_chanctx,
2645 	.change_chanctx = iwl_mld_change_chanctx,
2646 	.assign_vif_chanctx = iwl_mld_assign_vif_chanctx,
2647 	.unassign_vif_chanctx = iwl_mld_unassign_vif_chanctx,
2648 	.set_rts_threshold = iwl_mld_mac80211_set_rts_threshold,
2649 	.link_info_changed = iwl_mld_mac80211_link_info_changed,
2650 	.vif_cfg_changed = iwl_mld_mac80211_vif_cfg_changed,
2651 	.set_key = iwl_mld_mac80211_set_key,
2652 	.hw_scan = iwl_mld_mac80211_hw_scan,
2653 	.cancel_hw_scan = iwl_mld_mac80211_cancel_hw_scan,
2654 	.sched_scan_start = iwl_mld_mac80211_sched_scan_start,
2655 	.sched_scan_stop = iwl_mld_mac80211_sched_scan_stop,
2656 	.mgd_prepare_tx = iwl_mld_mac80211_mgd_prepare_tx,
2657 	.mgd_complete_tx = iwl_mld_mac_mgd_complete_tx,
2658 	.sta_state = iwl_mld_mac80211_sta_state,
2659 	.sta_statistics = iwl_mld_mac80211_sta_statistics,
2660 	.get_survey = iwl_mld_mac80211_get_survey,
2661 	.flush = iwl_mld_mac80211_flush,
2662 	.flush_sta = iwl_mld_mac80211_flush_sta,
2663 	.ampdu_action = iwl_mld_mac80211_ampdu_action,
2664 	.can_aggregate_in_amsdu = iwl_mld_mac80211_can_aggregate,
2665 	.sync_rx_queues = iwl_mld_mac80211_sync_rx_queues,
2666 	.link_sta_rc_update = iwl_mld_sta_rc_update,
2667 	.start_ap = iwl_mld_start_ap_ibss,
2668 	.stop_ap = iwl_mld_stop_ap_ibss,
2669 	.pre_channel_switch = iwl_mld_pre_channel_switch,
2670 	.channel_switch = iwl_mld_channel_switch,
2671 	.post_channel_switch = iwl_mld_post_channel_switch,
2672 	.abort_channel_switch = iwl_mld_abort_channel_switch,
2673 	.switch_vif_chanctx = iwl_mld_switch_vif_chanctx,
2674 	.sta_pre_rcu_remove = iwl_mld_sta_pre_rcu_remove,
2675 	.remain_on_channel = iwl_mld_start_roc,
2676 	.cancel_remain_on_channel = iwl_mld_cancel_roc,
2677 	.can_activate_links = iwl_mld_can_activate_links,
2678 	.change_vif_links = iwl_mld_change_vif_links,
2679 	.change_sta_links = iwl_mld_change_sta_links,
2680 #ifdef CONFIG_PM_SLEEP
2681 	.suspend = iwl_mld_suspend,
2682 	.resume = iwl_mld_resume,
2683 	.set_wakeup = iwl_mld_set_wakeup,
2684 	.set_rekey_data = iwl_mld_set_rekey_data,
2685 #if IS_ENABLED(CONFIG_IPV6)
2686 	.ipv6_addr_change = iwl_mld_ipv6_addr_change,
2687 #endif /* IS_ENABLED(CONFIG_IPV6) */
2688 #endif /* CONFIG_PM_SLEEP */
2689 #ifdef CONFIG_IWLWIFI_DEBUGFS
2690 	.vif_add_debugfs = iwl_mld_add_vif_debugfs,
2691 	.link_add_debugfs = iwl_mld_add_link_debugfs,
2692 	.link_sta_add_debugfs = iwl_mld_add_link_sta_debugfs,
2693 #endif
2694 	.mgd_protect_tdls_discover = iwl_mld_mac80211_mgd_protect_tdls_discover,
2695 	.join_ibss = iwl_mld_mac80211_join_ibss,
2696 	.leave_ibss = iwl_mld_mac80211_leave_ibss,
2697 	.tx_last_beacon = iwl_mld_mac80211_tx_last_beacon,
2698 	.prep_add_interface = iwl_mld_prep_add_interface,
2699 	.set_hw_timestamp = iwl_mld_set_hw_timestamp,
2700 	.start_pmsr = iwl_mld_start_pmsr,
2701 	.can_neg_ttlm = iwl_mld_can_neg_ttlm,
2702 };
2703