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