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