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 /* Now the link_sta's capabilities are set, update the FW */
1765 iwl_mld_config_tlc(mld, vif, sta);
1766
1767 if (vif->type == NL80211_IFTYPE_AP) {
1768 /* Update MAC_CFG_FILTER_ACCEPT_BEACON if at least
1769 * one sta is associated
1770 */
1771 if (++mld_vif->num_associated_stas == 1)
1772 ret = iwl_mld_mac_fw_action(mld, vif,
1773 FW_CTXT_ACTION_MODIFY);
1774 }
1775
1776 return ret;
1777 } else if (old_state == IEEE80211_STA_ASSOC &&
1778 new_state == IEEE80211_STA_AUTHORIZED) {
1779 ret = 0;
1780
1781 if (!sta->tdls) {
1782 mld_vif->authorized = true;
1783
1784 /* Ensure any block due to a non-BSS link is synced */
1785 iwl_mld_emlsr_check_non_bss_block(mld, 0);
1786
1787 /* Ensure NAN block is synced */
1788 iwl_mld_emlsr_check_nan_block(mld, vif);
1789
1790 /* Block EMLSR until a certain throughput it reached */
1791 if (!mld->fw_status.in_hw_restart &&
1792 IWL_MLD_ENTER_EMLSR_TPT_THRESH > 0)
1793 iwl_mld_block_emlsr(mld_vif->mld, vif,
1794 IWL_MLD_EMLSR_BLOCKED_TPT,
1795 0);
1796
1797 /* clear COEX_HIGH_PRIORITY_ENABLE */
1798 ret = iwl_mld_mac_fw_action(mld, vif,
1799 FW_CTXT_ACTION_MODIFY);
1800 if (ret)
1801 return ret;
1802 iwl_mld_smps_workaround(mld, vif, vif->cfg.ps);
1803 }
1804
1805 /* MFP is set by default before the station is authorized.
1806 * Clear it here in case it's not used.
1807 */
1808 if (!sta->mfp)
1809 ret = iwl_mld_update_all_link_stations(mld, sta);
1810
1811 /* We can use wide bandwidth now, not only 20 MHz */
1812 iwl_mld_config_tlc(mld, vif, sta);
1813
1814 return ret;
1815 } else {
1816 return -EINVAL;
1817 }
1818 }
1819
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)1820 static int iwl_mld_move_sta_state_down(struct iwl_mld *mld,
1821 struct ieee80211_vif *vif,
1822 struct ieee80211_sta *sta,
1823 enum ieee80211_sta_state old_state,
1824 enum ieee80211_sta_state new_state)
1825 {
1826 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
1827
1828 if (old_state == IEEE80211_STA_AUTHORIZED &&
1829 new_state == IEEE80211_STA_ASSOC) {
1830 if (!sta->tdls) {
1831 mld_vif->authorized = false;
1832
1833 memset(&mld_vif->emlsr.zeroed_on_not_authorized, 0,
1834 sizeof(mld_vif->emlsr.zeroed_on_not_authorized));
1835
1836 wiphy_delayed_work_cancel(mld->wiphy,
1837 &mld_vif->emlsr.prevent_done_wk);
1838 wiphy_delayed_work_cancel(mld->wiphy,
1839 &mld_vif->emlsr.tmp_non_bss_done_wk);
1840 wiphy_work_cancel(mld->wiphy, &mld_vif->emlsr.unblock_tpt_wk);
1841 wiphy_delayed_work_cancel(mld->wiphy,
1842 &mld_vif->emlsr.check_tpt_wk);
1843 wiphy_delayed_work_cancel(mld->wiphy,
1844 &mld_vif->mlo_scan_start_wk);
1845
1846 iwl_mld_reset_cca_40mhz_workaround(mld, vif);
1847 iwl_mld_smps_workaround(mld, vif, true);
1848 }
1849
1850 /* once we move into assoc state, need to update the FW to
1851 * stop using wide bandwidth
1852 */
1853 iwl_mld_config_tlc(mld, vif, sta);
1854 } else if (old_state == IEEE80211_STA_ASSOC &&
1855 new_state == IEEE80211_STA_AUTH) {
1856 if (vif->type == NL80211_IFTYPE_AP &&
1857 !WARN_ON(!mld_vif->num_associated_stas)) {
1858 /* Update MAC_CFG_FILTER_ACCEPT_BEACON if the last sta
1859 * is disassociating
1860 */
1861 if (--mld_vif->num_associated_stas == 0)
1862 iwl_mld_mac_fw_action(mld, vif,
1863 FW_CTXT_ACTION_MODIFY);
1864 }
1865 } else if (old_state == IEEE80211_STA_AUTH &&
1866 new_state == IEEE80211_STA_NONE) {
1867 /* nothing */
1868 } else if (old_state == IEEE80211_STA_NONE &&
1869 new_state == IEEE80211_STA_NOTEXIST) {
1870 iwl_mld_remove_sta(mld, sta);
1871
1872 if (sta->tdls && iwl_mld_tdls_sta_count(mld) == 0) {
1873 /* just removed last TDLS STA, so enable PM */
1874 iwl_mld_update_mac_power(mld, vif, false);
1875 }
1876 } else {
1877 return -EINVAL;
1878 }
1879 return 0;
1880 }
1881
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)1882 static int iwl_mld_mac80211_sta_state(struct ieee80211_hw *hw,
1883 struct ieee80211_vif *vif,
1884 struct ieee80211_sta *sta,
1885 enum ieee80211_sta_state old_state,
1886 enum ieee80211_sta_state new_state)
1887 {
1888 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1889 struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
1890
1891 IWL_DEBUG_MAC80211(mld, "station %pM state change %d->%d\n",
1892 sta->addr, old_state, new_state);
1893
1894 mld_sta->sta_state = new_state;
1895
1896 if (old_state < new_state)
1897 return iwl_mld_move_sta_state_up(mld, vif, sta, old_state,
1898 new_state);
1899 else
1900 return iwl_mld_move_sta_state_down(mld, vif, sta, old_state,
1901 new_state);
1902 }
1903
iwl_mld_mac80211_flush(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u32 queues,bool drop)1904 static void iwl_mld_mac80211_flush(struct ieee80211_hw *hw,
1905 struct ieee80211_vif *vif,
1906 u32 queues, bool drop)
1907 {
1908 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1909
1910 /* Make sure we're done with the deferred traffic before flushing */
1911 iwl_mld_add_txq_list(mld);
1912
1913 for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) {
1914 struct ieee80211_link_sta *link_sta =
1915 wiphy_dereference(mld->wiphy,
1916 mld->fw_id_to_link_sta[i]);
1917
1918 if (IS_ERR_OR_NULL(link_sta))
1919 continue;
1920
1921 /* Check that the sta belongs to the given vif */
1922 if (vif && vif != iwl_mld_sta_from_mac80211(link_sta->sta)->vif)
1923 continue;
1924
1925 if (drop)
1926 iwl_mld_flush_sta_txqs(mld, link_sta->sta);
1927 else
1928 iwl_mld_wait_sta_txqs_empty(mld, link_sta->sta);
1929 }
1930 }
1931
iwl_mld_mac80211_flush_sta(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)1932 static void iwl_mld_mac80211_flush_sta(struct ieee80211_hw *hw,
1933 struct ieee80211_vif *vif,
1934 struct ieee80211_sta *sta)
1935 {
1936 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1937
1938 iwl_mld_flush_sta_txqs(mld, sta);
1939 }
1940
1941 static int
iwl_mld_mac80211_ampdu_action(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_ampdu_params * params)1942 iwl_mld_mac80211_ampdu_action(struct ieee80211_hw *hw,
1943 struct ieee80211_vif *vif,
1944 struct ieee80211_ampdu_params *params)
1945 {
1946 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
1947 struct ieee80211_sta *sta = params->sta;
1948 enum ieee80211_ampdu_mlme_action action = params->action;
1949 u16 tid = params->tid;
1950 u16 ssn = params->ssn;
1951 u16 buf_size = params->buf_size;
1952 u16 timeout = params->timeout;
1953 int ret;
1954
1955 IWL_DEBUG_HT(mld, "A-MPDU action on addr %pM tid: %d action: %d\n",
1956 sta->addr, tid, action);
1957
1958 switch (action) {
1959 case IEEE80211_AMPDU_RX_START:
1960 if (!iwl_enable_rx_ampdu()) {
1961 ret = -EINVAL;
1962 break;
1963 }
1964 ret = iwl_mld_ampdu_rx_start(mld, sta, tid, ssn, buf_size,
1965 timeout);
1966 break;
1967 case IEEE80211_AMPDU_RX_STOP:
1968 ret = iwl_mld_ampdu_rx_stop(mld, sta, tid);
1969 break;
1970 default:
1971 /* The mac80211 TX_AMPDU_SETUP_IN_HW flag is set for all
1972 * devices, since all support TX A-MPDU offload in hardware.
1973 * Therefore, no TX action should be requested here.
1974 */
1975 WARN_ON_ONCE(1);
1976 return -EINVAL;
1977 }
1978
1979 return ret;
1980 }
1981
iwl_mld_can_hw_csum(struct sk_buff * skb)1982 static bool iwl_mld_can_hw_csum(struct sk_buff *skb)
1983 {
1984 u8 protocol = ip_hdr(skb)->protocol;
1985
1986 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
1987 }
1988
iwl_mld_mac80211_can_aggregate(struct ieee80211_hw * hw,struct sk_buff * head,struct sk_buff * skb)1989 static bool iwl_mld_mac80211_can_aggregate(struct ieee80211_hw *hw,
1990 struct sk_buff *head,
1991 struct sk_buff *skb)
1992 {
1993 if (!IS_ENABLED(CONFIG_INET))
1994 return false;
1995
1996 /* For now don't aggregate IPv6 in AMSDU */
1997 if (skb->protocol != htons(ETH_P_IP))
1998 return false;
1999
2000 /* Allow aggregation only if both frames have the same HW csum offload
2001 * capability, ensuring consistent HW or SW csum handling in A-MSDU.
2002 */
2003 return iwl_mld_can_hw_csum(skb) == iwl_mld_can_hw_csum(head);
2004 }
2005
iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw * hw)2006 static void iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw *hw)
2007 {
2008 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2009
2010 iwl_mld_sync_rx_queues(mld, IWL_MLD_RXQ_EMPTY, NULL, 0);
2011 }
2012
iwl_mld_sta_rc_update(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_link_sta * link_sta,u32 changed)2013 static void iwl_mld_sta_rc_update(struct ieee80211_hw *hw,
2014 struct ieee80211_vif *vif,
2015 struct ieee80211_link_sta *link_sta,
2016 u32 changed)
2017 {
2018 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2019
2020 if (changed & (IEEE80211_RC_BW_CHANGED |
2021 IEEE80211_RC_SUPP_RATES_CHANGED |
2022 IEEE80211_RC_NSS_CHANGED)) {
2023 struct ieee80211_bss_conf *link =
2024 link_conf_dereference_check(vif, link_sta->link_id);
2025
2026 if (WARN_ON(!link))
2027 return;
2028
2029 iwl_mld_config_tlc_link(mld, vif, link, link_sta);
2030 }
2031 }
2032
2033 #ifdef CONFIG_PM_SLEEP
iwl_mld_set_wakeup(struct ieee80211_hw * hw,bool enabled)2034 static void iwl_mld_set_wakeup(struct ieee80211_hw *hw, bool enabled)
2035 {
2036 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2037
2038 device_set_wakeup_enable(mld->trans->dev, enabled);
2039 }
2040
2041 /* Returns 0 on success. 1 if failed to suspend with wowlan:
2042 * If the circumstances didn't satisfy the conditions for suspension
2043 * with wowlan, mac80211 would use the no_wowlan flow.
2044 * If an error had occurred we update the trans status and state here
2045 * and the result will be stopping the FW.
2046 */
2047 static int
iwl_mld_suspend(struct ieee80211_hw * hw,struct cfg80211_wowlan * wowlan)2048 iwl_mld_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
2049 {
2050 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2051 int ret;
2052
2053 iwl_fw_runtime_suspend(&mld->fwrt);
2054
2055 ret = iwl_mld_wowlan_suspend(mld, wowlan);
2056 if (ret)
2057 return 1;
2058
2059 if (iwl_mld_no_wowlan_suspend(mld))
2060 return 1;
2061
2062 return 0;
2063 }
2064
iwl_mld_resume(struct ieee80211_hw * hw)2065 static int iwl_mld_resume(struct ieee80211_hw *hw)
2066 {
2067 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2068 int ret;
2069
2070 ret = iwl_mld_wowlan_resume(mld);
2071 if (ret)
2072 return ret;
2073
2074 iwl_fw_runtime_resume(&mld->fwrt);
2075
2076 iwl_mld_low_latency_restart(mld);
2077
2078 return 0;
2079 }
2080 #endif
2081
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)2082 static int iwl_mld_alloc_ptk_pn(struct iwl_mld *mld,
2083 struct iwl_mld_sta *mld_sta,
2084 struct ieee80211_key_conf *key,
2085 struct iwl_mld_ptk_pn **ptk_pn)
2086 {
2087 u8 num_rx_queues = mld->trans->info.num_rxqs;
2088 int keyidx = key->keyidx;
2089 struct ieee80211_key_seq seq;
2090
2091 if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2092 return -EINVAL;
2093
2094 WARN_ON(rcu_access_pointer(mld_sta->ptk_pn[keyidx]));
2095 *ptk_pn = kzalloc_flex(**ptk_pn, q, num_rx_queues);
2096 if (!*ptk_pn)
2097 return -ENOMEM;
2098
2099 for (u8 tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2100 ieee80211_get_key_rx_seq(key, tid, &seq);
2101 for (u8 q = 0; q < num_rx_queues; q++)
2102 memcpy((*ptk_pn)->q[q].pn[tid], seq.ccmp.pn,
2103 IEEE80211_CCMP_PN_LEN);
2104 }
2105
2106 rcu_assign_pointer(mld_sta->ptk_pn[keyidx], *ptk_pn);
2107
2108 return 0;
2109 }
2110
iwl_mld_set_key_add(struct iwl_mld * mld,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)2111 static int iwl_mld_set_key_add(struct iwl_mld *mld,
2112 struct ieee80211_vif *vif,
2113 struct ieee80211_sta *sta,
2114 struct ieee80211_key_conf *key)
2115 {
2116 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2117 struct iwl_mld_sta *mld_sta =
2118 sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2119 struct iwl_mld_ptk_pn *ptk_pn = NULL;
2120 int keyidx = key->keyidx;
2121 int ret;
2122
2123 /* Will be set to 0 if added successfully */
2124 key->hw_key_idx = STA_KEY_IDX_INVALID;
2125
2126 switch (key->cipher) {
2127 case WLAN_CIPHER_SUITE_WEP40:
2128 case WLAN_CIPHER_SUITE_WEP104:
2129 IWL_DEBUG_MAC80211(mld, "Use SW encryption for WEP\n");
2130 return -EOPNOTSUPP;
2131 case WLAN_CIPHER_SUITE_TKIP:
2132 if (vif->type == NL80211_IFTYPE_STATION) {
2133 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
2134 break;
2135 }
2136 IWL_DEBUG_MAC80211(mld, "Use SW encryption for TKIP\n");
2137 return -EOPNOTSUPP;
2138 case WLAN_CIPHER_SUITE_CCMP:
2139 case WLAN_CIPHER_SUITE_GCMP:
2140 case WLAN_CIPHER_SUITE_GCMP_256:
2141 case WLAN_CIPHER_SUITE_AES_CMAC:
2142 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2143 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2144 break;
2145 default:
2146 return -EOPNOTSUPP;
2147 }
2148
2149 if (keyidx == 6 || keyidx == 7)
2150 iwl_mld_track_bigtk(mld, vif, key, true);
2151
2152 /* After exiting from RFKILL, hostapd configures GTK/ITGK before the
2153 * AP is started, but those keys can't be sent to the FW before the
2154 * MCAST/BCAST STAs are added to it (which happens upon AP start).
2155 * Store it here to be sent later when the AP is started.
2156 */
2157 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2158 vif->type == NL80211_IFTYPE_AP) && !sta &&
2159 !mld_vif->ap_ibss_active)
2160 return iwl_mld_store_ap_early_key(mld, key, mld_vif);
2161
2162 if (!mld->fw_status.in_hw_restart && mld_sta &&
2163 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2164 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2165 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2166 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2167 ret = iwl_mld_alloc_ptk_pn(mld, mld_sta, key, &ptk_pn);
2168 if (ret)
2169 return ret;
2170 }
2171
2172 IWL_DEBUG_MAC80211(mld, "set hwcrypto key (sta:%pM, id:%d)\n",
2173 sta ? sta->addr : NULL, keyidx);
2174
2175 ret = iwl_mld_add_key(mld, vif, sta, key);
2176 if (ret) {
2177 IWL_WARN(mld, "set key failed (%d)\n", ret);
2178 if (ptk_pn) {
2179 RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2180 kfree(ptk_pn);
2181 }
2182
2183 return -EOPNOTSUPP;
2184 }
2185
2186 return 0;
2187 }
2188
iwl_mld_set_key_remove(struct iwl_mld * mld,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)2189 static void iwl_mld_set_key_remove(struct iwl_mld *mld,
2190 struct ieee80211_vif *vif,
2191 struct ieee80211_sta *sta,
2192 struct ieee80211_key_conf *key)
2193 {
2194 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2195 struct iwl_mld_sta *mld_sta =
2196 sta ? iwl_mld_sta_from_mac80211(sta) : NULL;
2197 int keyidx = key->keyidx;
2198
2199 if (keyidx == 6 || keyidx == 7)
2200 iwl_mld_track_bigtk(mld, vif, key, false);
2201
2202 if (mld_sta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2203 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2204 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2205 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2206 struct iwl_mld_ptk_pn *ptk_pn;
2207
2208 if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn)))
2209 return;
2210
2211 ptk_pn = wiphy_dereference(mld->wiphy,
2212 mld_sta->ptk_pn[keyidx]);
2213 RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL);
2214 if (!WARN_ON(!ptk_pn))
2215 kfree_rcu(ptk_pn, rcu_head);
2216 }
2217
2218 /* if this key was stored to be added later to the FW - free it here */
2219 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
2220 iwl_mld_free_ap_early_key(mld, key, mld_vif);
2221
2222 /* We already removed it */
2223 if (key->hw_key_idx == STA_KEY_IDX_INVALID)
2224 return;
2225
2226 IWL_DEBUG_MAC80211(mld, "disable hwcrypto key\n");
2227
2228 iwl_mld_remove_key(mld, vif, sta, key);
2229 }
2230
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)2231 static int iwl_mld_mac80211_set_key(struct ieee80211_hw *hw,
2232 enum set_key_cmd cmd,
2233 struct ieee80211_vif *vif,
2234 struct ieee80211_sta *sta,
2235 struct ieee80211_key_conf *key)
2236 {
2237 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2238 int ret;
2239
2240 switch (cmd) {
2241 case SET_KEY:
2242 ret = iwl_mld_set_key_add(mld, vif, sta, key);
2243 if (ret)
2244 ret = -EOPNOTSUPP;
2245 break;
2246 case DISABLE_KEY:
2247 iwl_mld_set_key_remove(mld, vif, sta, key);
2248 ret = 0;
2249 break;
2250 default:
2251 ret = -EINVAL;
2252 break;
2253 }
2254
2255 return ret;
2256 }
2257
2258 static int
iwl_mld_pre_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)2259 iwl_mld_pre_channel_switch(struct ieee80211_hw *hw,
2260 struct ieee80211_vif *vif,
2261 struct ieee80211_channel_switch *chsw)
2262 {
2263 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2264 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2265 struct iwl_mld_link *mld_link =
2266 iwl_mld_link_dereference_check(mld_vif, chsw->link_id);
2267 u8 primary;
2268 int selected;
2269
2270 lockdep_assert_wiphy(mld->wiphy);
2271
2272 if (WARN_ON(!mld_link))
2273 return -EINVAL;
2274
2275 IWL_DEBUG_MAC80211(mld, "pre CSA to freq %d\n",
2276 chsw->chandef.center_freq1);
2277
2278 if (!iwl_mld_emlsr_active(vif))
2279 return 0;
2280
2281 primary = iwl_mld_get_primary_link(vif);
2282
2283 /* stay on the primary link unless it is undergoing a CSA with quiet */
2284 if (chsw->link_id == primary && chsw->block_tx)
2285 selected = iwl_mld_get_other_link(vif, primary);
2286 else
2287 selected = primary;
2288
2289 /* Remember to tell the firmware that this link can't tx
2290 * Note that this logic seems to be unrelated to emlsr, but it
2291 * really is needed only when emlsr is active. When we have a
2292 * single link, the firmware will handle all this on its own.
2293 * In multi-link scenarios, we can learn about the CSA from
2294 * another link and this logic is too complex for the firmware
2295 * to track.
2296 * Since we want to de-activate the link that got a CSA with mode=1,
2297 * we need to tell the firmware not to send any frame on that link
2298 * as the firmware may not be aware that link is under a CSA
2299 * with mode=1 (no Tx allowed).
2300 */
2301 mld_link->silent_deactivation = chsw->block_tx;
2302 iwl_mld_exit_emlsr(mld, vif, IWL_MLD_EMLSR_EXIT_CSA, selected);
2303
2304 return 0;
2305 }
2306
2307 static void
iwl_mld_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_channel_switch * chsw)2308 iwl_mld_channel_switch(struct ieee80211_hw *hw,
2309 struct ieee80211_vif *vif,
2310 struct ieee80211_channel_switch *chsw)
2311 {
2312 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2313
2314 /* By implementing this operation, we prevent mac80211 from
2315 * starting its own channel switch timer, so that we can call
2316 * ieee80211_chswitch_done() ourselves at the right time
2317 * (Upon receiving the channel_switch_start notification from the fw)
2318 */
2319 IWL_DEBUG_MAC80211(mld,
2320 "dummy channel switch op\n");
2321 }
2322
2323 static int
iwl_mld_post_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)2324 iwl_mld_post_channel_switch(struct ieee80211_hw *hw,
2325 struct ieee80211_vif *vif,
2326 struct ieee80211_bss_conf *link_conf)
2327 {
2328 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2329 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2330
2331 lockdep_assert_wiphy(mld->wiphy);
2332
2333 WARN_ON(mld_link->silent_deactivation);
2334
2335 return 0;
2336 }
2337
2338 static void
iwl_mld_abort_channel_switch(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * link_conf)2339 iwl_mld_abort_channel_switch(struct ieee80211_hw *hw,
2340 struct ieee80211_vif *vif,
2341 struct ieee80211_bss_conf *link_conf)
2342 {
2343 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2344 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf);
2345
2346 IWL_DEBUG_MAC80211(mld,
2347 "abort channel switch op\n");
2348 mld_link->silent_deactivation = false;
2349 }
2350
2351 static int
iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw * hw,struct ieee80211_vif_chanctx_switch * vifs)2352 iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw *hw,
2353 struct ieee80211_vif_chanctx_switch *vifs)
2354 {
2355 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2356 int ret;
2357
2358 iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2359 vifs[0].old_ctx);
2360 iwl_mld_remove_chanctx(hw, vifs[0].old_ctx);
2361
2362 ret = iwl_mld_add_chanctx(hw, vifs[0].new_ctx);
2363 if (ret) {
2364 IWL_ERR(mld, "failed to add new_ctx during channel switch\n");
2365 goto out_reassign;
2366 }
2367
2368 ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2369 vifs[0].new_ctx);
2370 if (ret) {
2371 IWL_ERR(mld,
2372 "failed to assign new_ctx during channel switch\n");
2373 goto out_remove;
2374 }
2375
2376 return 0;
2377
2378 out_remove:
2379 iwl_mld_remove_chanctx(hw, vifs[0].new_ctx);
2380 out_reassign:
2381 if (iwl_mld_add_chanctx(hw, vifs[0].old_ctx)) {
2382 IWL_ERR(mld, "failed to add old_ctx after failure\n");
2383 return ret;
2384 }
2385
2386 if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2387 vifs[0].old_ctx))
2388 IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2389
2390 return ret;
2391 }
2392
2393 static int
iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw * hw,struct ieee80211_vif_chanctx_switch * vifs)2394 iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw *hw,
2395 struct ieee80211_vif_chanctx_switch *vifs)
2396 {
2397 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2398 int ret;
2399
2400 iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2401 vifs[0].old_ctx);
2402 ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2403 vifs[0].new_ctx);
2404 if (ret) {
2405 IWL_ERR(mld,
2406 "failed to assign new_ctx during channel switch\n");
2407 goto out_reassign;
2408 }
2409
2410 return 0;
2411
2412 out_reassign:
2413 if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf,
2414 vifs[0].old_ctx))
2415 IWL_ERR(mld, "failed to reassign old_ctx after failure\n");
2416
2417 return ret;
2418 }
2419
2420 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)2421 iwl_mld_switch_vif_chanctx(struct ieee80211_hw *hw,
2422 struct ieee80211_vif_chanctx_switch *vifs,
2423 int n_vifs,
2424 enum ieee80211_chanctx_switch_mode mode)
2425 {
2426 int ret;
2427
2428 /* we only support a single-vif right now */
2429 if (n_vifs > 1)
2430 return -EOPNOTSUPP;
2431
2432 switch (mode) {
2433 case CHANCTX_SWMODE_SWAP_CONTEXTS:
2434 ret = iwl_mld_switch_vif_chanctx_swap(hw, vifs);
2435 break;
2436 case CHANCTX_SWMODE_REASSIGN_VIF:
2437 ret = iwl_mld_switch_vif_chanctx_reassign(hw, vifs);
2438 break;
2439 default:
2440 ret = -EOPNOTSUPP;
2441 break;
2442 }
2443
2444 return ret;
2445 }
2446
iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta)2447 static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2448 struct ieee80211_vif *vif,
2449 struct ieee80211_sta *sta)
2450 {
2451 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2452 struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
2453 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2454 struct iwl_mld_link_sta *mld_link_sta;
2455 u8 link_id;
2456
2457 lockdep_assert_wiphy(mld->wiphy);
2458
2459 /* This is called before mac80211 does RCU synchronisation,
2460 * so here we already invalidate our internal RCU-protected
2461 * station pointer. The rest of the code will thus no longer
2462 * be able to find the station this way, and we don't rely
2463 * on further RCU synchronisation after the sta_state()
2464 * callback deleted the station.
2465 */
2466 for_each_mld_link_sta(mld_sta, mld_link_sta, link_id)
2467 RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id],
2468 NULL);
2469
2470 if (sta == mld_vif->ap_sta)
2471 mld_vif->ap_sta = NULL;
2472 }
2473
2474 static void
iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw * hw,struct ieee80211_vif * vif,unsigned int link_id)2475 iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2476 struct ieee80211_vif *vif,
2477 unsigned int link_id)
2478 {
2479 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2480 struct ieee80211_bss_conf *link_conf;
2481 u32 duration;
2482 int ret;
2483
2484 link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]);
2485 if (WARN_ON_ONCE(!link_conf))
2486 return;
2487
2488 /* Protect the session to hear the TDLS setup response on the channel */
2489
2490 duration = 2 * link_conf->dtim_period * link_conf->beacon_int;
2491
2492 ret = iwl_mld_start_session_protection(mld, vif, duration, duration,
2493 link_id, HZ / 5);
2494 if (ret)
2495 IWL_ERR(mld,
2496 "Failed to start session protection for TDLS: %d\n",
2497 ret);
2498 }
2499
iwl_mld_can_activate_links(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 desired_links)2500 static bool iwl_mld_can_activate_links(struct ieee80211_hw *hw,
2501 struct ieee80211_vif *vif,
2502 u16 desired_links)
2503 {
2504 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2505 int n_links = hweight16(desired_links);
2506
2507 /* Check if HW supports the wanted number of links */
2508 return n_links <= iwl_mld_max_active_links(mld, vif);
2509 }
2510
2511 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])2512 iwl_mld_change_vif_links(struct ieee80211_hw *hw,
2513 struct ieee80211_vif *vif,
2514 u16 old_links, u16 new_links,
2515 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
2516 {
2517 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif);
2518 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2519 struct ieee80211_bss_conf *link_conf;
2520 u16 removed = old_links & ~new_links;
2521 u16 added = new_links & ~old_links;
2522 int err;
2523
2524 lockdep_assert_wiphy(mld->wiphy);
2525
2526 /*
2527 * No bits designate non-MLO mode. We can handle MLO exit/enter by
2528 * simply mapping that to link ID zero internally.
2529 * Note that mac80211 does such a non-MLO to MLO switch during restart
2530 * if it was in MLO before. In that case, we do not have a link to
2531 * remove.
2532 */
2533 if (old_links == 0 && !mld->fw_status.in_hw_restart)
2534 removed |= BIT(0);
2535
2536 if (new_links == 0)
2537 added |= BIT(0);
2538
2539 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2540 if (removed & BIT(i) && !WARN_ON(!old[i]))
2541 iwl_mld_remove_link(mld, old[i]);
2542 }
2543
2544 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2545 if (added & BIT(i)) {
2546 link_conf = link_conf_dereference_protected(vif, i);
2547 if (!link_conf) {
2548 err = -EINVAL;
2549 goto remove_added_links;
2550 }
2551
2552 err = iwl_mld_add_link(mld, link_conf);
2553 if (err)
2554 goto remove_added_links;
2555 }
2556 }
2557
2558 /*
2559 * Ensure we always have a valid primary_link. When using multiple
2560 * links the proper value is set in assign_vif_chanctx.
2561 */
2562 mld_vif->emlsr.primary = new_links ? __ffs(new_links) : 0;
2563
2564 /*
2565 * Special MLO restart case. We did not have a link when the interface
2566 * was added, so do the power configuration now.
2567 */
2568 if (old_links == 0 && mld->fw_status.in_hw_restart)
2569 iwl_mld_update_mac_power(mld, vif, false);
2570
2571 return 0;
2572
2573 remove_added_links:
2574 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
2575 if (!(added & BIT(i)))
2576 continue;
2577
2578 link_conf = link_conf_dereference_protected(vif, i);
2579 if (!link_conf || !iwl_mld_link_from_mac80211(link_conf))
2580 continue;
2581
2582 iwl_mld_remove_link(mld, link_conf);
2583 }
2584
2585 if (WARN_ON(!iwl_mld_error_before_recovery(mld)))
2586 return err;
2587
2588 /* reconfig will fix us anyway */
2589 return 0;
2590 }
2591
iwl_mld_change_sta_links(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_sta * sta,u16 old_links,u16 new_links)2592 static int iwl_mld_change_sta_links(struct ieee80211_hw *hw,
2593 struct ieee80211_vif *vif,
2594 struct ieee80211_sta *sta,
2595 u16 old_links, u16 new_links)
2596 {
2597 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2598
2599 return iwl_mld_update_link_stas(mld, vif, sta, old_links, new_links);
2600 }
2601
iwl_mld_mac80211_join_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)2602 static int iwl_mld_mac80211_join_ibss(struct ieee80211_hw *hw,
2603 struct ieee80211_vif *vif)
2604 {
2605 return iwl_mld_start_ap_ibss(hw, vif, &vif->bss_conf);
2606 }
2607
iwl_mld_mac80211_leave_ibss(struct ieee80211_hw * hw,struct ieee80211_vif * vif)2608 static void iwl_mld_mac80211_leave_ibss(struct ieee80211_hw *hw,
2609 struct ieee80211_vif *vif)
2610 {
2611 return iwl_mld_stop_ap_ibss(hw, vif, &vif->bss_conf);
2612 }
2613
iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw * hw)2614 static int iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw *hw)
2615 {
2616 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2617
2618 return mld->ibss_manager;
2619 }
2620
iwl_mld_prep_add_interface(struct ieee80211_hw * hw,enum nl80211_iftype type)2621 static void iwl_mld_prep_add_interface(struct ieee80211_hw *hw,
2622 enum nl80211_iftype type)
2623 {
2624 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2625
2626 IWL_DEBUG_MAC80211(mld, "prep_add_interface: type=%u\n", type);
2627
2628 if (!(type == NL80211_IFTYPE_AP ||
2629 type == NL80211_IFTYPE_P2P_GO ||
2630 type == NL80211_IFTYPE_P2P_CLIENT))
2631 return;
2632
2633 iwl_mld_emlsr_block_tmp_non_bss(mld);
2634 }
2635
iwl_mld_set_hw_timestamp(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_set_hw_timestamp * hwts)2636 static int iwl_mld_set_hw_timestamp(struct ieee80211_hw *hw,
2637 struct ieee80211_vif *vif,
2638 struct cfg80211_set_hw_timestamp *hwts)
2639 {
2640 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2641 u32 protocols = 0;
2642
2643 /* HW timestamping is only supported for a specific station */
2644 if (!hwts->macaddr)
2645 return -EOPNOTSUPP;
2646
2647 if (hwts->enable)
2648 protocols =
2649 IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
2650
2651 return iwl_mld_time_sync_config(mld, hwts->macaddr, protocols);
2652 }
2653
iwl_mld_start_pmsr(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct cfg80211_pmsr_request * request)2654 static int iwl_mld_start_pmsr(struct ieee80211_hw *hw,
2655 struct ieee80211_vif *vif,
2656 struct cfg80211_pmsr_request *request)
2657 {
2658 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2659
2660 return iwl_mld_ftm_start(mld, vif, request);
2661 }
2662
2663 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)2664 iwl_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2665 struct ieee80211_neg_ttlm *neg_ttlm)
2666 {
2667 u16 map;
2668
2669 /* Verify all TIDs are mapped to the same links set */
2670 map = neg_ttlm->downlink[0];
2671 for (int i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
2672 if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] ||
2673 neg_ttlm->uplink[i] != map)
2674 return NEG_TTLM_RES_REJECT;
2675 }
2676
2677 return NEG_TTLM_RES_ACCEPT;
2678 }
2679
iwl_mld_get_antenna(struct ieee80211_hw * hw,int radio_idx,u32 * tx_ant,u32 * rx_ant)2680 static int iwl_mld_get_antenna(struct ieee80211_hw *hw, int radio_idx,
2681 u32 *tx_ant, u32 *rx_ant)
2682 {
2683 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2684
2685 *tx_ant = iwl_mld_get_valid_tx_ant(mld);
2686 *rx_ant = iwl_mld_get_valid_rx_ant(mld);
2687
2688 return 0;
2689 }
2690
iwl_mld_set_antenna(struct ieee80211_hw * hw,int radio_idx,u32 tx_ant,u32 rx_ant)2691 static int iwl_mld_set_antenna(struct ieee80211_hw *hw, int radio_idx,
2692 u32 tx_ant, u32 rx_ant)
2693 {
2694 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw);
2695
2696 if (WARN_ON(!mld->nvm_data))
2697 return -EBUSY;
2698
2699 /* mac80211 ensures the device is not started,
2700 * so the firmware cannot be running
2701 */
2702
2703 mld->set_tx_ant = tx_ant;
2704 mld->set_rx_ant = rx_ant;
2705
2706 iwl_reinit_cab(mld->trans, mld->nvm_data, tx_ant, rx_ant, mld->fw);
2707
2708 return 0;
2709 }
2710
2711 const struct ieee80211_ops iwl_mld_hw_ops = {
2712 .tx = iwl_mld_mac80211_tx,
2713 .start = iwl_mld_mac80211_start,
2714 .stop = iwl_mld_mac80211_stop,
2715 .config = iwl_mld_mac80211_config,
2716 .get_antenna = iwl_mld_get_antenna,
2717 .set_antenna = iwl_mld_set_antenna,
2718 .add_interface = iwl_mld_mac80211_add_interface,
2719 .remove_interface = iwl_mld_mac80211_remove_interface,
2720 .conf_tx = iwl_mld_mac80211_conf_tx,
2721 .prepare_multicast = iwl_mld_mac80211_prepare_multicast,
2722 .configure_filter = iwl_mld_mac80211_configure_filter,
2723 .reconfig_complete = iwl_mld_mac80211_reconfig_complete,
2724 .wake_tx_queue = iwl_mld_mac80211_wake_tx_queue,
2725 .add_chanctx = iwl_mld_add_chanctx,
2726 .remove_chanctx = iwl_mld_remove_chanctx,
2727 .change_chanctx = iwl_mld_change_chanctx,
2728 .assign_vif_chanctx = iwl_mld_assign_vif_chanctx,
2729 .unassign_vif_chanctx = iwl_mld_unassign_vif_chanctx,
2730 .set_rts_threshold = iwl_mld_mac80211_set_rts_threshold,
2731 .link_info_changed = iwl_mld_mac80211_link_info_changed,
2732 .vif_cfg_changed = iwl_mld_mac80211_vif_cfg_changed,
2733 .set_key = iwl_mld_mac80211_set_key,
2734 .hw_scan = iwl_mld_mac80211_hw_scan,
2735 .cancel_hw_scan = iwl_mld_mac80211_cancel_hw_scan,
2736 .sched_scan_start = iwl_mld_mac80211_sched_scan_start,
2737 .sched_scan_stop = iwl_mld_mac80211_sched_scan_stop,
2738 .mgd_prepare_tx = iwl_mld_mac80211_mgd_prepare_tx,
2739 .mgd_complete_tx = iwl_mld_mac_mgd_complete_tx,
2740 .sta_state = iwl_mld_mac80211_sta_state,
2741 .sta_statistics = iwl_mld_mac80211_sta_statistics,
2742 .get_survey = iwl_mld_mac80211_get_survey,
2743 .flush = iwl_mld_mac80211_flush,
2744 .flush_sta = iwl_mld_mac80211_flush_sta,
2745 .ampdu_action = iwl_mld_mac80211_ampdu_action,
2746 .can_aggregate_in_amsdu = iwl_mld_mac80211_can_aggregate,
2747 .sync_rx_queues = iwl_mld_mac80211_sync_rx_queues,
2748 .link_sta_rc_update = iwl_mld_sta_rc_update,
2749 .start_ap = iwl_mld_start_ap_ibss,
2750 .stop_ap = iwl_mld_stop_ap_ibss,
2751 .pre_channel_switch = iwl_mld_pre_channel_switch,
2752 .channel_switch = iwl_mld_channel_switch,
2753 .post_channel_switch = iwl_mld_post_channel_switch,
2754 .abort_channel_switch = iwl_mld_abort_channel_switch,
2755 .switch_vif_chanctx = iwl_mld_switch_vif_chanctx,
2756 .sta_pre_rcu_remove = iwl_mld_sta_pre_rcu_remove,
2757 .remain_on_channel = iwl_mld_start_roc,
2758 .cancel_remain_on_channel = iwl_mld_cancel_roc,
2759 .can_activate_links = iwl_mld_can_activate_links,
2760 .change_vif_links = iwl_mld_change_vif_links,
2761 .change_sta_links = iwl_mld_change_sta_links,
2762 #ifdef CONFIG_PM_SLEEP
2763 .suspend = iwl_mld_suspend,
2764 .resume = iwl_mld_resume,
2765 .set_wakeup = iwl_mld_set_wakeup,
2766 .set_rekey_data = iwl_mld_set_rekey_data,
2767 #if IS_ENABLED(CONFIG_IPV6)
2768 .ipv6_addr_change = iwl_mld_ipv6_addr_change,
2769 #endif /* IS_ENABLED(CONFIG_IPV6) */
2770 #endif /* CONFIG_PM_SLEEP */
2771 #ifdef CONFIG_IWLWIFI_DEBUGFS
2772 .vif_add_debugfs = iwl_mld_add_vif_debugfs,
2773 .link_add_debugfs = iwl_mld_add_link_debugfs,
2774 .link_sta_add_debugfs = iwl_mld_add_link_sta_debugfs,
2775 #endif
2776 .mgd_protect_tdls_discover = iwl_mld_mac80211_mgd_protect_tdls_discover,
2777 .join_ibss = iwl_mld_mac80211_join_ibss,
2778 .leave_ibss = iwl_mld_mac80211_leave_ibss,
2779 .tx_last_beacon = iwl_mld_mac80211_tx_last_beacon,
2780 .prep_add_interface = iwl_mld_prep_add_interface,
2781 .set_hw_timestamp = iwl_mld_set_hw_timestamp,
2782 .start_pmsr = iwl_mld_start_pmsr,
2783 .can_neg_ttlm = iwl_mld_can_neg_ttlm,
2784 .start_nan = iwl_mld_start_nan,
2785 .stop_nan = iwl_mld_stop_nan,
2786 .nan_change_conf = iwl_mld_nan_change_config,
2787 };
2788