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