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