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