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