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