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