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, int radio_idx, 585 u32 changed) 586 { 587 return 0; 588 } 589 590 static 591 int iwl_mld_mac80211_add_interface(struct ieee80211_hw *hw, 592 struct ieee80211_vif *vif) 593 { 594 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 595 int ret; 596 597 lockdep_assert_wiphy(mld->wiphy); 598 599 /* Construct mld_vif, add it to fw, and map its ID to ieee80211_vif */ 600 ret = iwl_mld_add_vif(mld, vif); 601 if (ret) 602 return ret; 603 604 /* 605 * Add the default link, but not if this is an MLD vif as that implies 606 * the HW is restarting and it will be configured by change_vif_links. 607 */ 608 if (!ieee80211_vif_is_mld(vif)) 609 ret = iwl_mld_add_link(mld, &vif->bss_conf); 610 if (ret) 611 goto err; 612 613 if (vif->type == NL80211_IFTYPE_STATION) { 614 vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC; 615 if (!vif->p2p) 616 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 617 IEEE80211_VIF_SUPPORTS_CQM_RSSI; 618 } 619 620 if (vif->p2p || iwl_fw_lookup_cmd_ver(mld->fw, PHY_CONTEXT_CMD, 0) < 5) 621 vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW; 622 623 /* 624 * For an MLD vif (in restart) we may not have a link; delay the call 625 * the initial change_vif_links. 626 */ 627 if (vif->type == NL80211_IFTYPE_STATION && 628 !ieee80211_vif_is_mld(vif)) 629 iwl_mld_update_mac_power(mld, vif, false); 630 631 if (vif->type == NL80211_IFTYPE_MONITOR) { 632 mld->monitor.on = true; 633 ieee80211_hw_set(mld->hw, RX_INCLUDES_FCS); 634 } 635 636 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 637 mld->p2p_device_vif = vif; 638 639 return 0; 640 641 err: 642 iwl_mld_rm_vif(mld, vif); 643 return ret; 644 } 645 646 static 647 void iwl_mld_mac80211_remove_interface(struct ieee80211_hw *hw, 648 struct ieee80211_vif *vif) 649 { 650 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 651 652 lockdep_assert_wiphy(mld->wiphy); 653 654 if (ieee80211_vif_type_p2p(vif) == NL80211_IFTYPE_STATION) 655 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 656 IEEE80211_VIF_SUPPORTS_CQM_RSSI); 657 658 if (vif->type == NL80211_IFTYPE_MONITOR) { 659 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mld->hw->flags); 660 mld->monitor.on = false; 661 } 662 663 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 664 mld->p2p_device_vif = NULL; 665 666 iwl_mld_remove_link(mld, &vif->bss_conf); 667 668 #ifdef CONFIG_IWLWIFI_DEBUGFS 669 debugfs_remove(iwl_mld_vif_from_mac80211(vif)->dbgfs_slink); 670 iwl_mld_vif_from_mac80211(vif)->dbgfs_slink = NULL; 671 #endif 672 673 iwl_mld_rm_vif(mld, vif); 674 } 675 676 struct iwl_mld_mc_iter_data { 677 struct iwl_mld *mld; 678 int port_id; 679 }; 680 681 static void iwl_mld_mc_iface_iterator(void *data, u8 *mac, 682 struct ieee80211_vif *vif) 683 { 684 struct iwl_mld_mc_iter_data *mc_data = data; 685 struct iwl_mld *mld = mc_data->mld; 686 struct iwl_mcast_filter_cmd *cmd = mld->mcast_filter_cmd; 687 struct iwl_host_cmd hcmd = { 688 .id = MCAST_FILTER_CMD, 689 .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 690 }; 691 int ret, len; 692 693 /* If we don't have free ports, mcast frames will be dropped */ 694 if (WARN_ON_ONCE(mc_data->port_id >= MAX_PORT_ID_NUM)) 695 return; 696 697 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc) 698 return; 699 700 cmd->port_id = mc_data->port_id++; 701 ether_addr_copy(cmd->bssid, vif->bss_conf.bssid); 702 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 703 704 hcmd.len[0] = len; 705 hcmd.data[0] = cmd; 706 707 ret = iwl_mld_send_cmd(mld, &hcmd); 708 if (ret) 709 IWL_ERR(mld, "mcast filter cmd error. ret=%d\n", ret); 710 } 711 712 void iwl_mld_recalc_multicast_filter(struct iwl_mld *mld) 713 { 714 struct iwl_mld_mc_iter_data iter_data = { 715 .mld = mld, 716 }; 717 718 if (WARN_ON_ONCE(!mld->mcast_filter_cmd)) 719 return; 720 721 ieee80211_iterate_active_interfaces(mld->hw, 722 IEEE80211_IFACE_ITER_NORMAL, 723 iwl_mld_mc_iface_iterator, 724 &iter_data); 725 } 726 727 static u64 728 iwl_mld_mac80211_prepare_multicast(struct ieee80211_hw *hw, 729 struct netdev_hw_addr_list *mc_list) 730 { 731 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 732 struct iwl_mcast_filter_cmd *cmd; 733 struct netdev_hw_addr *addr; 734 int addr_count = netdev_hw_addr_list_count(mc_list); 735 bool pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES; 736 int len; 737 738 if (pass_all) 739 addr_count = 0; 740 741 /* len must be a multiple of 4 */ 742 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 743 cmd = kzalloc(len, GFP_ATOMIC); 744 if (!cmd) 745 return 0; 746 747 if (pass_all) { 748 cmd->pass_all = 1; 749 goto out; 750 } 751 752 netdev_hw_addr_list_for_each(addr, mc_list) { 753 IWL_DEBUG_MAC80211(mld, "mcast addr (%d): %pM\n", 754 cmd->count, addr->addr); 755 ether_addr_copy(&cmd->addr_list[cmd->count * ETH_ALEN], 756 addr->addr); 757 cmd->count++; 758 } 759 760 out: 761 return (u64)(unsigned long)cmd; 762 } 763 764 static 765 void iwl_mld_mac80211_configure_filter(struct ieee80211_hw *hw, 766 unsigned int changed_flags, 767 unsigned int *total_flags, 768 u64 multicast) 769 { 770 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 771 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 772 773 /* Replace previous configuration */ 774 kfree(mld->mcast_filter_cmd); 775 mld->mcast_filter_cmd = cmd; 776 777 if (!cmd) 778 goto out; 779 780 if (changed_flags & FIF_ALLMULTI) 781 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 782 783 if (cmd->pass_all) 784 cmd->count = 0; 785 786 iwl_mld_recalc_multicast_filter(mld); 787 out: 788 *total_flags = 0; 789 } 790 791 static 792 void iwl_mld_mac80211_wake_tx_queue(struct ieee80211_hw *hw, 793 struct ieee80211_txq *txq) 794 { 795 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 796 struct iwl_mld_txq *mld_txq = iwl_mld_txq_from_mac80211(txq); 797 798 if (likely(mld_txq->status.allocated) || !txq->sta) { 799 iwl_mld_tx_from_txq(mld, txq); 800 return; 801 } 802 803 /* We don't support TSPEC tids. %IEEE80211_NUM_TIDS is for mgmt */ 804 if (txq->tid != IEEE80211_NUM_TIDS && txq->tid >= IWL_MAX_TID_COUNT) { 805 IWL_DEBUG_MAC80211(mld, "TID %d is not supported\n", txq->tid); 806 return; 807 } 808 809 /* The worker will handle any packets we leave on the txq now */ 810 811 spin_lock_bh(&mld->add_txqs_lock); 812 /* The list is being deleted only after the queue is fully allocated. */ 813 if (list_empty(&mld_txq->list) && 814 /* recheck under lock, otherwise it can be added twice */ 815 !mld_txq->status.allocated) { 816 list_add_tail(&mld_txq->list, &mld->txqs_to_add); 817 wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk); 818 } 819 spin_unlock_bh(&mld->add_txqs_lock); 820 } 821 822 static void iwl_mld_teardown_tdls_peers(struct iwl_mld *mld) 823 { 824 lockdep_assert_wiphy(mld->wiphy); 825 826 for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) { 827 struct ieee80211_link_sta *link_sta; 828 struct iwl_mld_sta *mld_sta; 829 830 link_sta = wiphy_dereference(mld->wiphy, 831 mld->fw_id_to_link_sta[i]); 832 if (IS_ERR_OR_NULL(link_sta)) 833 continue; 834 835 if (!link_sta->sta->tdls) 836 continue; 837 838 mld_sta = iwl_mld_sta_from_mac80211(link_sta->sta); 839 840 ieee80211_tdls_oper_request(mld_sta->vif, link_sta->addr, 841 NL80211_TDLS_TEARDOWN, 842 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED, 843 GFP_KERNEL); 844 } 845 } 846 847 static 848 int iwl_mld_add_chanctx(struct ieee80211_hw *hw, 849 struct ieee80211_chanctx_conf *ctx) 850 { 851 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 852 struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx); 853 int fw_id = iwl_mld_allocate_fw_phy_id(mld); 854 int ret; 855 856 if (fw_id < 0) 857 return fw_id; 858 859 phy->mld = mld; 860 phy->fw_id = fw_id; 861 phy->chandef = *iwl_mld_get_chandef_from_chanctx(mld, ctx); 862 863 ret = iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_ADD); 864 if (ret) { 865 mld->used_phy_ids &= ~BIT(phy->fw_id); 866 return ret; 867 } 868 869 if (hweight8(mld->used_phy_ids) > 1) 870 iwl_mld_teardown_tdls_peers(mld); 871 872 return 0; 873 } 874 875 static 876 void iwl_mld_remove_chanctx(struct ieee80211_hw *hw, 877 struct ieee80211_chanctx_conf *ctx) 878 { 879 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 880 struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx); 881 882 iwl_mld_phy_fw_action(mld, ctx, FW_CTXT_ACTION_REMOVE); 883 mld->used_phy_ids &= ~BIT(phy->fw_id); 884 } 885 886 static 887 void iwl_mld_change_chanctx(struct ieee80211_hw *hw, 888 struct ieee80211_chanctx_conf *ctx, u32 changed) 889 { 890 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 891 struct iwl_mld_phy *phy = iwl_mld_phy_from_mac80211(ctx); 892 struct cfg80211_chan_def *chandef = 893 iwl_mld_get_chandef_from_chanctx(mld, ctx); 894 895 /* We don't care about these */ 896 if (!(changed & ~(IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 897 IEEE80211_CHANCTX_CHANGE_RADAR | 898 IEEE80211_CHANCTX_CHANGE_CHANNEL))) 899 return; 900 901 /* Check if a FW update is required */ 902 903 if (changed & IEEE80211_CHANCTX_CHANGE_AP) 904 goto update; 905 906 if (chandef->chan == phy->chandef.chan && 907 chandef->center_freq1 == phy->chandef.center_freq1 && 908 chandef->punctured == phy->chandef.punctured) { 909 /* Check if we are toggling between HT and non-HT, no-op */ 910 if (phy->chandef.width == chandef->width || 911 (phy->chandef.width <= NL80211_CHAN_WIDTH_20 && 912 chandef->width <= NL80211_CHAN_WIDTH_20)) 913 return; 914 } 915 update: 916 917 iwl_mld_update_phy_chandef(mld, ctx); 918 } 919 920 static u8 921 iwl_mld_chandef_get_primary_80(struct cfg80211_chan_def *chandef) 922 { 923 int data_start; 924 int control_start; 925 int bw; 926 927 if (chandef->width == NL80211_CHAN_WIDTH_320) 928 bw = 320; 929 else if (chandef->width == NL80211_CHAN_WIDTH_160) 930 bw = 160; 931 else 932 return 0; 933 934 /* data is bw wide so the start is half the width */ 935 data_start = chandef->center_freq1 - bw / 2; 936 /* control is 20Mhz width */ 937 control_start = chandef->chan->center_freq - 10; 938 939 return (control_start - data_start) / 80; 940 } 941 942 static bool iwl_mld_can_activate_link(struct iwl_mld *mld, 943 struct ieee80211_vif *vif, 944 struct ieee80211_bss_conf *link) 945 { 946 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 947 struct iwl_mld_sta *mld_sta; 948 struct iwl_mld_link_sta *link_sta; 949 950 /* In association, we activate the assoc link before adding the STA. */ 951 if (!mld_vif->ap_sta || !vif->cfg.assoc) 952 return true; 953 954 mld_sta = iwl_mld_sta_from_mac80211(mld_vif->ap_sta); 955 956 /* When switching links, we need to wait with the activation until the 957 * STA was added to the FW. It'll be activated in 958 * iwl_mld_update_link_stas 959 */ 960 link_sta = wiphy_dereference(mld->wiphy, mld_sta->link[link->link_id]); 961 962 /* In restart we can have a link_sta that doesn't exist in FW yet */ 963 return link_sta && link_sta->in_fw; 964 } 965 966 static 967 int iwl_mld_assign_vif_chanctx(struct ieee80211_hw *hw, 968 struct ieee80211_vif *vif, 969 struct ieee80211_bss_conf *link, 970 struct ieee80211_chanctx_conf *ctx) 971 { 972 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 973 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link); 974 unsigned int n_active = iwl_mld_count_active_links(mld, vif); 975 int ret; 976 977 lockdep_assert_wiphy(mld->wiphy); 978 979 if (WARN_ON(!mld_link)) 980 return -EINVAL; 981 982 /* if the assigned one was not counted yet, count it now */ 983 if (!rcu_access_pointer(mld_link->chan_ctx)) { 984 n_active++; 985 986 /* Track addition of non-BSS link */ 987 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) { 988 ret = iwl_mld_emlsr_check_non_bss_block(mld, 1); 989 if (ret) 990 return ret; 991 } 992 } 993 994 /* for AP, mac parameters such as HE support are updated at this stage. */ 995 if (vif->type == NL80211_IFTYPE_AP) { 996 ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY); 997 998 if (ret) { 999 IWL_ERR(mld, "failed to update MAC %pM\n", vif->addr); 1000 return -EINVAL; 1001 } 1002 } 1003 1004 rcu_assign_pointer(mld_link->chan_ctx, ctx); 1005 1006 if (n_active > 1) { 1007 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1008 1009 iwl_mld_leave_omi_bw_reduction(mld); 1010 1011 /* Indicate to mac80211 that EML is enabled */ 1012 vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE; 1013 mld_vif->emlsr.last_entry_ts = jiffies; 1014 1015 if (vif->active_links & BIT(mld_vif->emlsr.selected_links)) 1016 mld_vif->emlsr.primary = mld_vif->emlsr.selected_primary; 1017 else 1018 mld_vif->emlsr.primary = __ffs(vif->active_links); 1019 1020 iwl_dbg_tlv_time_point(&mld->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP, 1021 NULL); 1022 } 1023 1024 /* First send the link command with the phy context ID. 1025 * Now that we have the phy, we know the band so also the rates 1026 */ 1027 ret = iwl_mld_change_link_in_fw(mld, link, 1028 LINK_CONTEXT_MODIFY_RATES_INFO); 1029 if (ret) 1030 goto err; 1031 1032 /* TODO: Initialize rate control for the AP station, since we might be 1033 * doing a link switch here - we cannot initialize it before since 1034 * this needs the phy context assigned (and in FW?), and we cannot 1035 * do it later because it needs to be initialized as soon as we're 1036 * able to TX on the link, i.e. when active. (task=link-switch) 1037 */ 1038 1039 /* Now activate the link */ 1040 if (iwl_mld_can_activate_link(mld, vif, link)) { 1041 ret = iwl_mld_activate_link(mld, link); 1042 if (ret) 1043 goto err; 1044 } 1045 1046 if (vif->type == NL80211_IFTYPE_STATION) 1047 iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link); 1048 1049 if (vif->type == NL80211_IFTYPE_MONITOR) { 1050 ret = iwl_mld_add_mon_sta(mld, vif, link); 1051 if (ret) 1052 goto deactivate_link; 1053 1054 mld->monitor.p80 = 1055 iwl_mld_chandef_get_primary_80(&vif->bss_conf.chanreq.oper); 1056 } 1057 1058 return 0; 1059 1060 deactivate_link: 1061 if (mld_link->active) 1062 iwl_mld_deactivate_link(mld, link); 1063 err: 1064 RCU_INIT_POINTER(mld_link->chan_ctx, NULL); 1065 return ret; 1066 } 1067 1068 static 1069 void iwl_mld_unassign_vif_chanctx(struct ieee80211_hw *hw, 1070 struct ieee80211_vif *vif, 1071 struct ieee80211_bss_conf *link, 1072 struct ieee80211_chanctx_conf *ctx) 1073 { 1074 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1075 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1076 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link); 1077 unsigned int n_active = iwl_mld_count_active_links(mld, vif); 1078 1079 if (WARN_ON(!mld_link)) 1080 return; 1081 1082 /* Track removal of non-BSS link */ 1083 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) 1084 iwl_mld_emlsr_check_non_bss_block(mld, -1); 1085 1086 iwl_mld_deactivate_link(mld, link); 1087 1088 if (vif->type == NL80211_IFTYPE_MONITOR) 1089 iwl_mld_remove_mon_sta(mld, vif, link); 1090 1091 if (n_active > 1) { 1092 /* Indicate to mac80211 that EML is disabled */ 1093 vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE; 1094 1095 iwl_dbg_tlv_time_point(&mld->fwrt, 1096 IWL_FW_INI_TIME_ESR_LINK_DOWN, 1097 NULL); 1098 } 1099 1100 RCU_INIT_POINTER(mld_link->chan_ctx, NULL); 1101 1102 /* in the non-MLO case, remove/re-add the link to clean up FW state. 1103 * In MLO, it'll be done in drv_change_vif_link 1104 */ 1105 if (!ieee80211_vif_is_mld(vif) && !mld_vif->ap_sta && 1106 !WARN_ON_ONCE(vif->cfg.assoc) && 1107 vif->type != NL80211_IFTYPE_AP && !mld->fw_status.in_hw_restart) { 1108 iwl_mld_remove_link(mld, link); 1109 iwl_mld_add_link(mld, link); 1110 } 1111 } 1112 1113 static 1114 int iwl_mld_mac80211_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx, 1115 u32 value) 1116 { 1117 return 0; 1118 } 1119 1120 static void 1121 iwl_mld_link_info_changed_ap_ibss(struct iwl_mld *mld, 1122 struct ieee80211_vif *vif, 1123 struct ieee80211_bss_conf *link, 1124 u64 changes) 1125 { 1126 u32 link_changes = 0; 1127 1128 if (changes & BSS_CHANGED_ERP_SLOT) 1129 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO; 1130 1131 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT)) 1132 link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS; 1133 1134 if (changes & (BSS_CHANGED_QOS | BSS_CHANGED_BANDWIDTH)) 1135 link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS; 1136 1137 if (changes & BSS_CHANGED_HE_BSS_COLOR) 1138 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS; 1139 1140 if (link_changes) 1141 iwl_mld_change_link_in_fw(mld, link, link_changes); 1142 1143 if (changes & BSS_CHANGED_BEACON) 1144 iwl_mld_update_beacon_template(mld, vif, link); 1145 } 1146 1147 static 1148 u32 iwl_mld_link_changed_mapping(struct iwl_mld *mld, 1149 struct ieee80211_vif *vif, 1150 struct ieee80211_bss_conf *link_conf, 1151 u64 changes) 1152 { 1153 u32 link_changes = 0; 1154 bool has_he, has_eht; 1155 1156 if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos) 1157 link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS; 1158 1159 if (changes & (BSS_CHANGED_ERP_PREAMBLE | BSS_CHANGED_BASIC_RATES | 1160 BSS_CHANGED_ERP_SLOT)) 1161 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO; 1162 1163 if (changes & (BSS_CHANGED_HT | BSS_CHANGED_ERP_CTS_PROT)) 1164 link_changes |= LINK_CONTEXT_MODIFY_PROTECT_FLAGS; 1165 1166 /* TODO: task=MLO check mac80211's HE flags and if command is needed 1167 * every time there's a link change. Currently used flags are 1168 * BSS_CHANGED_HE_OBSS_PD and BSS_CHANGED_HE_BSS_COLOR. 1169 */ 1170 has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax; 1171 has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be; 1172 1173 if (vif->cfg.assoc && (has_he || has_eht)) { 1174 IWL_DEBUG_MAC80211(mld, "Associated in HE mode\n"); 1175 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS; 1176 } 1177 1178 return link_changes; 1179 } 1180 1181 static void 1182 iwl_mld_mac80211_link_info_changed_sta(struct iwl_mld *mld, 1183 struct ieee80211_vif *vif, 1184 struct ieee80211_bss_conf *link_conf, 1185 u64 changes) 1186 { 1187 u32 link_changes = iwl_mld_link_changed_mapping(mld, vif, link_conf, 1188 changes); 1189 1190 if (link_changes) 1191 iwl_mld_change_link_in_fw(mld, link_conf, link_changes); 1192 1193 if (changes & BSS_CHANGED_TPE) 1194 iwl_mld_send_ap_tx_power_constraint_cmd(mld, vif, link_conf); 1195 1196 if (changes & BSS_CHANGED_BEACON_INFO) 1197 iwl_mld_update_mac_power(mld, vif, false); 1198 1199 /* The firmware will wait quite a while after association before it 1200 * starts filtering the beacons. We can safely enable beacon filtering 1201 * upon CQM configuration, even if we didn't get a beacon yet. 1202 */ 1203 if (changes & (BSS_CHANGED_CQM | BSS_CHANGED_BEACON_INFO)) 1204 iwl_mld_enable_beacon_filter(mld, link_conf, false); 1205 1206 /* If we have used OMI before to reduce bandwidth to 80 MHz and then 1207 * increased to 160 MHz again, and then the AP changes to 320 MHz, it 1208 * will think that we're limited to 160 MHz right now. Update it by 1209 * requesting a new OMI bandwidth. 1210 */ 1211 if (changes & BSS_CHANGED_BANDWIDTH) { 1212 enum ieee80211_sta_rx_bandwidth bw; 1213 1214 bw = ieee80211_chan_width_to_rx_bw(link_conf->chanreq.oper.width); 1215 1216 iwl_mld_omi_ap_changed_bw(mld, link_conf, bw); 1217 1218 } 1219 1220 if (changes & BSS_CHANGED_BANDWIDTH) 1221 iwl_mld_retry_emlsr(mld, vif); 1222 } 1223 1224 static int iwl_mld_update_mu_groups(struct iwl_mld *mld, 1225 struct ieee80211_bss_conf *link_conf) 1226 { 1227 struct iwl_mu_group_mgmt_cmd cmd = {}; 1228 1229 BUILD_BUG_ON(sizeof(cmd.membership_status) != 1230 sizeof(link_conf->mu_group.membership)); 1231 BUILD_BUG_ON(sizeof(cmd.user_position) != 1232 sizeof(link_conf->mu_group.position)); 1233 1234 memcpy(cmd.membership_status, link_conf->mu_group.membership, 1235 WLAN_MEMBERSHIP_LEN); 1236 memcpy(cmd.user_position, link_conf->mu_group.position, 1237 WLAN_USER_POSITION_LEN); 1238 1239 return iwl_mld_send_cmd_pdu(mld, 1240 WIDE_ID(DATA_PATH_GROUP, 1241 UPDATE_MU_GROUPS_CMD), 1242 &cmd); 1243 } 1244 1245 static void 1246 iwl_mld_mac80211_link_info_changed(struct ieee80211_hw *hw, 1247 struct ieee80211_vif *vif, 1248 struct ieee80211_bss_conf *link_conf, 1249 u64 changes) 1250 { 1251 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1252 1253 switch (vif->type) { 1254 case NL80211_IFTYPE_STATION: 1255 iwl_mld_mac80211_link_info_changed_sta(mld, vif, link_conf, 1256 changes); 1257 break; 1258 case NL80211_IFTYPE_AP: 1259 case NL80211_IFTYPE_ADHOC: 1260 iwl_mld_link_info_changed_ap_ibss(mld, vif, link_conf, 1261 changes); 1262 break; 1263 case NL80211_IFTYPE_MONITOR: 1264 /* The firmware tracks this on its own in STATION mode, but 1265 * obviously not in sniffer mode. 1266 */ 1267 if (changes & BSS_CHANGED_MU_GROUPS) 1268 iwl_mld_update_mu_groups(mld, link_conf); 1269 break; 1270 default: 1271 /* shouldn't happen */ 1272 WARN_ON_ONCE(1); 1273 } 1274 1275 /* We now know our BSSID, we can configure the MAC context with 1276 * eht_support if needed. 1277 */ 1278 if (changes & BSS_CHANGED_BSSID) 1279 iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY); 1280 1281 if (changes & BSS_CHANGED_TXPOWER) 1282 iwl_mld_set_tx_power(mld, link_conf, link_conf->txpower); 1283 } 1284 1285 static void 1286 iwl_mld_smps_workaround(struct iwl_mld *mld, struct ieee80211_vif *vif, bool enable) 1287 { 1288 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1289 bool workaround_required = 1290 iwl_fw_lookup_cmd_ver(mld->fw, MAC_PM_POWER_TABLE, 0) < 2; 1291 1292 if (!workaround_required) 1293 return; 1294 1295 /* Send the device-level power commands since the 1296 * firmware checks the POWER_TABLE_CMD's POWER_SAVE_EN bit to 1297 * determine SMPS mode. 1298 */ 1299 if (mld_vif->ps_disabled == !enable) 1300 return; 1301 1302 mld_vif->ps_disabled = !enable; 1303 1304 iwl_mld_update_device_power(mld, false); 1305 } 1306 1307 static 1308 void iwl_mld_mac80211_vif_cfg_changed(struct ieee80211_hw *hw, 1309 struct ieee80211_vif *vif, 1310 u64 changes) 1311 { 1312 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1313 int ret; 1314 1315 lockdep_assert_wiphy(mld->wiphy); 1316 1317 if (vif->type != NL80211_IFTYPE_STATION) 1318 return; 1319 1320 if (changes & BSS_CHANGED_ASSOC) { 1321 ret = iwl_mld_mac_fw_action(mld, vif, FW_CTXT_ACTION_MODIFY); 1322 if (ret) 1323 IWL_ERR(mld, "failed to update context\n"); 1324 1325 if (vif->cfg.assoc) { 1326 /* Clear statistics to get clean beacon counter, and 1327 * ask for periodic statistics, as they are needed for 1328 * link selection and RX OMI decisions. 1329 */ 1330 iwl_mld_clear_stats_in_fw(mld); 1331 iwl_mld_request_periodic_fw_stats(mld, true); 1332 1333 iwl_mld_set_vif_associated(mld, vif); 1334 } else { 1335 iwl_mld_request_periodic_fw_stats(mld, false); 1336 } 1337 } 1338 1339 if (changes & BSS_CHANGED_PS) { 1340 iwl_mld_smps_workaround(mld, vif, vif->cfg.ps); 1341 iwl_mld_update_mac_power(mld, vif, false); 1342 } 1343 1344 /* TODO: task=MLO BSS_CHANGED_MLD_VALID_LINKS/CHANGED_MLD_TTLM */ 1345 } 1346 1347 static int 1348 iwl_mld_mac80211_hw_scan(struct ieee80211_hw *hw, 1349 struct ieee80211_vif *vif, 1350 struct ieee80211_scan_request *hw_req) 1351 { 1352 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1353 int ret; 1354 1355 if (WARN_ON(!hw_req->req.n_channels || 1356 hw_req->req.n_channels > 1357 mld->fw->ucode_capa.n_scan_channels)) 1358 return -EINVAL; 1359 1360 ret = iwl_mld_regular_scan_start(mld, vif, &hw_req->req, &hw_req->ies); 1361 if (!ret) { 1362 /* We will be busy with scanning, so the counters may not reflect the 1363 * reality. Stop checking the counters until the scan ends 1364 */ 1365 iwl_mld_start_ignoring_tpt_updates(mld); 1366 } 1367 1368 return ret; 1369 } 1370 1371 static void 1372 iwl_mld_mac80211_cancel_hw_scan(struct ieee80211_hw *hw, 1373 struct ieee80211_vif *vif) 1374 { 1375 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1376 1377 /* Due to a race condition, it's possible that mac80211 asks 1378 * us to stop a hw_scan when it's already stopped. This can 1379 * happen, for instance, if we stopped the scan ourselves, 1380 * called ieee80211_scan_completed() and the userspace called 1381 * cancel scan before ieee80211_scan_work() could run. 1382 * To handle that, simply return if the scan is not running. 1383 */ 1384 if (mld->scan.status & IWL_MLD_SCAN_REGULAR) { 1385 iwl_mld_scan_stop(mld, IWL_MLD_SCAN_REGULAR, true); 1386 /* Scan is over, we can check again the tpt counters */ 1387 iwl_mld_stop_ignoring_tpt_updates(mld); 1388 } 1389 } 1390 1391 static int 1392 iwl_mld_mac80211_sched_scan_start(struct ieee80211_hw *hw, 1393 struct ieee80211_vif *vif, 1394 struct cfg80211_sched_scan_request *req, 1395 struct ieee80211_scan_ies *ies) 1396 { 1397 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1398 1399 return iwl_mld_sched_scan_start(mld, vif, req, ies, IWL_MLD_SCAN_SCHED); 1400 } 1401 1402 static int 1403 iwl_mld_mac80211_sched_scan_stop(struct ieee80211_hw *hw, 1404 struct ieee80211_vif *vif) 1405 { 1406 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1407 1408 /* Due to a race condition, it's possible that mac80211 asks 1409 * us to stop a sched_scan when it's already stopped. This 1410 * can happen, for instance, if we stopped the scan ourselves, 1411 * called ieee80211_sched_scan_stopped() and the userspace called 1412 * stop sched scan before ieee80211_sched_scan_stopped_work() 1413 * could run. To handle this, simply return if the scan is 1414 * not running. 1415 */ 1416 if (!(mld->scan.status & IWL_MLD_SCAN_SCHED)) 1417 return 0; 1418 1419 return iwl_mld_scan_stop(mld, IWL_MLD_SCAN_SCHED, false); 1420 } 1421 1422 static void 1423 iwl_mld_restart_complete_vif(void *data, u8 *mac, struct ieee80211_vif *vif) 1424 { 1425 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1426 struct ieee80211_bss_conf *link_conf; 1427 struct iwl_mld *mld = data; 1428 int link_id; 1429 1430 for_each_vif_active_link(vif, link_conf, link_id) { 1431 enum ieee80211_sta_rx_bandwidth bw; 1432 struct iwl_mld_link *mld_link; 1433 1434 mld_link = wiphy_dereference(mld->wiphy, 1435 mld_vif->link[link_id]); 1436 1437 if (WARN_ON_ONCE(!mld_link)) 1438 continue; 1439 1440 bw = mld_link->rx_omi.bw_in_progress; 1441 if (bw) 1442 iwl_mld_change_link_omi_bw(mld, link_conf, bw); 1443 } 1444 } 1445 1446 static void 1447 iwl_mld_mac80211_reconfig_complete(struct ieee80211_hw *hw, 1448 enum ieee80211_reconfig_type reconfig_type) 1449 { 1450 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1451 1452 switch (reconfig_type) { 1453 case IEEE80211_RECONFIG_TYPE_RESTART: 1454 mld->fw_status.in_hw_restart = false; 1455 iwl_mld_send_recovery_cmd(mld, ERROR_RECOVERY_END_OF_RECOVERY); 1456 1457 ieee80211_iterate_interfaces(mld->hw, 1458 IEEE80211_IFACE_ITER_NORMAL, 1459 iwl_mld_restart_complete_vif, mld); 1460 1461 iwl_trans_finish_sw_reset(mld->trans); 1462 /* no need to lock, adding in parallel would schedule too */ 1463 if (!list_empty(&mld->txqs_to_add)) 1464 wiphy_work_queue(mld->wiphy, &mld->add_txqs_wk); 1465 1466 IWL_INFO(mld, "restart completed\n"); 1467 break; 1468 case IEEE80211_RECONFIG_TYPE_SUSPEND: 1469 break; 1470 } 1471 } 1472 1473 static 1474 void iwl_mld_mac80211_mgd_prepare_tx(struct ieee80211_hw *hw, 1475 struct ieee80211_vif *vif, 1476 struct ieee80211_prep_tx_info *info) 1477 { 1478 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1479 u32 duration = IWL_MLD_SESSION_PROTECTION_ASSOC_TIME_MS; 1480 1481 /* After a successful association the connection is established 1482 * and we can rely on the quota to send the disassociation frame. 1483 */ 1484 if (info->was_assoc) 1485 return; 1486 1487 if (info->duration > duration) 1488 duration = info->duration; 1489 1490 iwl_mld_schedule_session_protection(mld, vif, duration, 1491 IWL_MLD_SESSION_PROTECTION_MIN_TIME_MS, 1492 info->link_id); 1493 } 1494 1495 static 1496 void iwl_mld_mac_mgd_complete_tx(struct ieee80211_hw *hw, 1497 struct ieee80211_vif *vif, 1498 struct ieee80211_prep_tx_info *info) 1499 { 1500 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1501 1502 /* Successful authentication is the only case that requires to let 1503 * the session protection go. We'll need it for the upcoming 1504 * association. For all the other cases, we need to cancel the session 1505 * protection. 1506 * After successful association the connection is established and 1507 * further mgd tx can rely on the quota. 1508 */ 1509 if (info->success && info->subtype == IEEE80211_STYPE_AUTH) 1510 return; 1511 1512 /* The firmware will be on medium after we configure the vif as 1513 * associated. Removing the session protection allows the firmware 1514 * to stop being on medium. In order to ensure the continuity of our 1515 * presence on medium, we need first to configure the vif as associated 1516 * and only then, remove the session protection. 1517 * Currently, mac80211 calls vif_cfg_changed() first and then, 1518 * drv_mgd_complete_tx(). Ensure that this assumption stays true by 1519 * a warning. 1520 */ 1521 WARN_ON(info->success && 1522 (info->subtype == IEEE80211_STYPE_ASSOC_REQ || 1523 info->subtype == IEEE80211_STYPE_REASSOC_REQ) && 1524 !vif->cfg.assoc); 1525 1526 iwl_mld_cancel_session_protection(mld, vif, info->link_id); 1527 } 1528 1529 static int 1530 iwl_mld_mac80211_conf_tx(struct ieee80211_hw *hw, 1531 struct ieee80211_vif *vif, 1532 unsigned int link_id, u16 ac, 1533 const struct ieee80211_tx_queue_params *params) 1534 { 1535 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1536 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1537 struct iwl_mld_link *link; 1538 1539 lockdep_assert_wiphy(mld->wiphy); 1540 1541 link = iwl_mld_link_dereference_check(mld_vif, link_id); 1542 if (!link) 1543 return -EINVAL; 1544 1545 link->queue_params[ac] = *params; 1546 1547 /* No need to update right away, we'll get BSS_CHANGED_QOS 1548 * The exception is P2P_DEVICE interface which needs immediate update. 1549 */ 1550 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 1551 iwl_mld_change_link_in_fw(mld, &vif->bss_conf, 1552 LINK_CONTEXT_MODIFY_QOS_PARAMS); 1553 1554 return 0; 1555 } 1556 1557 static void iwl_mld_set_uapsd(struct iwl_mld *mld, struct ieee80211_vif *vif) 1558 { 1559 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 1560 1561 if (vif->type != NL80211_IFTYPE_STATION) 1562 return; 1563 1564 if (vif->p2p && 1565 !(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_P2P_CLIENT)) 1566 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 1567 1568 if (!vif->p2p && 1569 !(iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) 1570 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 1571 } 1572 1573 int iwl_mld_tdls_sta_count(struct iwl_mld *mld) 1574 { 1575 int count = 0; 1576 1577 lockdep_assert_wiphy(mld->wiphy); 1578 1579 for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) { 1580 struct ieee80211_link_sta *link_sta; 1581 1582 link_sta = wiphy_dereference(mld->wiphy, 1583 mld->fw_id_to_link_sta[i]); 1584 if (IS_ERR_OR_NULL(link_sta)) 1585 continue; 1586 1587 if (!link_sta->sta->tdls) 1588 continue; 1589 1590 count++; 1591 } 1592 1593 return count; 1594 } 1595 1596 static void iwl_mld_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 1597 struct cfg80211_bss *bss, 1598 void *_data) 1599 { 1600 bool *tolerated = _data; 1601 const struct cfg80211_bss_ies *ies; 1602 const struct element *elem; 1603 1604 rcu_read_lock(); 1605 ies = rcu_dereference(bss->ies); 1606 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 1607 ies->len); 1608 1609 if (!elem || elem->datalen < 10 || 1610 !(elem->data[10] & 1611 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 1612 *tolerated = false; 1613 } 1614 rcu_read_unlock(); 1615 } 1616 1617 static void 1618 iwl_mld_check_he_obss_narrow_bw_ru(struct iwl_mld *mld, 1619 struct iwl_mld_link *mld_link, 1620 struct ieee80211_bss_conf *link_conf) 1621 { 1622 bool tolerated = true; 1623 1624 if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan)) 1625 return; 1626 1627 if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) { 1628 mld_link->he_ru_2mhz_block = false; 1629 return; 1630 } 1631 1632 cfg80211_bss_iter(mld->wiphy, &link_conf->chanreq.oper, 1633 iwl_mld_check_he_obss_narrow_bw_ru_iter, &tolerated); 1634 1635 /* If there is at least one AP on radar channel that cannot 1636 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 1637 */ 1638 mld_link->he_ru_2mhz_block = !tolerated; 1639 } 1640 1641 static void iwl_mld_link_set_2mhz_block(struct iwl_mld *mld, 1642 struct ieee80211_vif *vif, 1643 struct ieee80211_sta *sta) 1644 { 1645 struct ieee80211_link_sta *link_sta; 1646 unsigned int link_id; 1647 1648 for_each_sta_active_link(vif, sta, link_sta, link_id) { 1649 struct ieee80211_bss_conf *link_conf = 1650 link_conf_dereference_protected(vif, link_id); 1651 struct iwl_mld_link *mld_link = 1652 iwl_mld_link_from_mac80211(link_conf); 1653 1654 if (WARN_ON(!link_conf || !mld_link)) 1655 continue; 1656 1657 if (link_sta->he_cap.has_he) 1658 iwl_mld_check_he_obss_narrow_bw_ru(mld, mld_link, 1659 link_conf); 1660 } 1661 } 1662 1663 static int iwl_mld_move_sta_state_up(struct iwl_mld *mld, 1664 struct ieee80211_vif *vif, 1665 struct ieee80211_sta *sta, 1666 enum ieee80211_sta_state old_state, 1667 enum ieee80211_sta_state new_state) 1668 { 1669 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1670 int tdls_count = 0; 1671 int ret; 1672 1673 if (old_state == IEEE80211_STA_NOTEXIST && 1674 new_state == IEEE80211_STA_NONE) { 1675 if (sta->tdls) { 1676 if (vif->p2p || hweight8(mld->used_phy_ids) != 1) 1677 return -EBUSY; 1678 1679 tdls_count = iwl_mld_tdls_sta_count(mld); 1680 if (tdls_count >= IWL_TDLS_STA_COUNT) 1681 return -EBUSY; 1682 } 1683 1684 /* 1685 * If this is the first STA (i.e. the AP) it won't do 1686 * anything, otherwise must leave for any new STA on 1687 * any other interface, or for TDLS, etc. 1688 * Need to call this _before_ adding the STA so it can 1689 * look up the one STA to use to ask mac80211 to leave 1690 * OMI; in the unlikely event that adding the new STA 1691 * then fails we'll just re-enter OMI later (via the 1692 * statistics notification handling.) 1693 */ 1694 iwl_mld_leave_omi_bw_reduction(mld); 1695 1696 ret = iwl_mld_add_sta(mld, sta, vif, STATION_TYPE_PEER); 1697 if (ret) 1698 return ret; 1699 1700 /* just added first TDLS STA, so disable PM */ 1701 if (sta->tdls && tdls_count == 0) 1702 iwl_mld_update_mac_power(mld, vif, false); 1703 1704 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 1705 mld_vif->ap_sta = sta; 1706 1707 /* Initialize TLC here already - this really tells 1708 * the firmware only what the supported legacy rates are 1709 * (may be) since it's initialized already from what the 1710 * AP advertised in the beacon/probe response. This will 1711 * allow the firmware to send auth/assoc frames with one 1712 * of the supported rates already, rather than having to 1713 * use a mandatory rate. 1714 * If we're the AP, we'll just assume mandatory rates at 1715 * this point, but we know nothing about the STA anyway. 1716 */ 1717 iwl_mld_config_tlc(mld, vif, sta); 1718 1719 return ret; 1720 } else if (old_state == IEEE80211_STA_NONE && 1721 new_state == IEEE80211_STA_AUTH) { 1722 iwl_mld_set_uapsd(mld, vif); 1723 return 0; 1724 } else if (old_state == IEEE80211_STA_AUTH && 1725 new_state == IEEE80211_STA_ASSOC) { 1726 ret = iwl_mld_update_all_link_stations(mld, sta); 1727 1728 if (vif->type == NL80211_IFTYPE_STATION) 1729 iwl_mld_link_set_2mhz_block(mld, vif, sta); 1730 /* Now the link_sta's capabilities are set, update the FW */ 1731 iwl_mld_config_tlc(mld, vif, sta); 1732 1733 if (vif->type == NL80211_IFTYPE_AP) { 1734 /* Update MAC_CFG_FILTER_ACCEPT_BEACON if at least 1735 * one sta is associated 1736 */ 1737 if (++mld_vif->num_associated_stas == 1) 1738 ret = iwl_mld_mac_fw_action(mld, vif, 1739 FW_CTXT_ACTION_MODIFY); 1740 } 1741 1742 return ret; 1743 } else if (old_state == IEEE80211_STA_ASSOC && 1744 new_state == IEEE80211_STA_AUTHORIZED) { 1745 ret = 0; 1746 1747 if (!sta->tdls) { 1748 mld_vif->authorized = true; 1749 1750 /* Ensure any block due to a non-BSS link is synced */ 1751 iwl_mld_emlsr_check_non_bss_block(mld, 0); 1752 1753 /* Block EMLSR until a certain throughput it reached */ 1754 if (!mld->fw_status.in_hw_restart && 1755 IWL_MLD_ENTER_EMLSR_TPT_THRESH > 0) 1756 iwl_mld_block_emlsr(mld_vif->mld, vif, 1757 IWL_MLD_EMLSR_BLOCKED_TPT, 1758 0); 1759 1760 /* clear COEX_HIGH_PRIORITY_ENABLE */ 1761 ret = iwl_mld_mac_fw_action(mld, vif, 1762 FW_CTXT_ACTION_MODIFY); 1763 if (ret) 1764 return ret; 1765 iwl_mld_smps_workaround(mld, vif, vif->cfg.ps); 1766 } 1767 1768 /* MFP is set by default before the station is authorized. 1769 * Clear it here in case it's not used. 1770 */ 1771 if (!sta->mfp) 1772 ret = iwl_mld_update_all_link_stations(mld, sta); 1773 1774 /* We can use wide bandwidth now, not only 20 MHz */ 1775 iwl_mld_config_tlc(mld, vif, sta); 1776 1777 return ret; 1778 } else { 1779 return -EINVAL; 1780 } 1781 } 1782 1783 static int iwl_mld_move_sta_state_down(struct iwl_mld *mld, 1784 struct ieee80211_vif *vif, 1785 struct ieee80211_sta *sta, 1786 enum ieee80211_sta_state old_state, 1787 enum ieee80211_sta_state new_state) 1788 { 1789 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 1790 1791 if (old_state == IEEE80211_STA_AUTHORIZED && 1792 new_state == IEEE80211_STA_ASSOC) { 1793 if (!sta->tdls) { 1794 mld_vif->authorized = false; 1795 1796 memset(&mld_vif->emlsr.zeroed_on_not_authorized, 0, 1797 sizeof(mld_vif->emlsr.zeroed_on_not_authorized)); 1798 1799 wiphy_delayed_work_cancel(mld->wiphy, 1800 &mld_vif->emlsr.prevent_done_wk); 1801 wiphy_delayed_work_cancel(mld->wiphy, 1802 &mld_vif->emlsr.tmp_non_bss_done_wk); 1803 wiphy_work_cancel(mld->wiphy, &mld_vif->emlsr.unblock_tpt_wk); 1804 wiphy_delayed_work_cancel(mld->wiphy, 1805 &mld_vif->emlsr.check_tpt_wk); 1806 1807 iwl_mld_reset_cca_40mhz_workaround(mld, vif); 1808 iwl_mld_smps_workaround(mld, vif, true); 1809 } 1810 1811 /* once we move into assoc state, need to update the FW to 1812 * stop using wide bandwidth 1813 */ 1814 iwl_mld_config_tlc(mld, vif, sta); 1815 } else if (old_state == IEEE80211_STA_ASSOC && 1816 new_state == IEEE80211_STA_AUTH) { 1817 if (vif->type == NL80211_IFTYPE_AP && 1818 !WARN_ON(!mld_vif->num_associated_stas)) { 1819 /* Update MAC_CFG_FILTER_ACCEPT_BEACON if the last sta 1820 * is disassociating 1821 */ 1822 if (--mld_vif->num_associated_stas == 0) 1823 iwl_mld_mac_fw_action(mld, vif, 1824 FW_CTXT_ACTION_MODIFY); 1825 } 1826 } else if (old_state == IEEE80211_STA_AUTH && 1827 new_state == IEEE80211_STA_NONE) { 1828 /* nothing */ 1829 } else if (old_state == IEEE80211_STA_NONE && 1830 new_state == IEEE80211_STA_NOTEXIST) { 1831 iwl_mld_remove_sta(mld, sta); 1832 1833 if (sta->tdls && iwl_mld_tdls_sta_count(mld) == 0) { 1834 /* just removed last TDLS STA, so enable PM */ 1835 iwl_mld_update_mac_power(mld, vif, false); 1836 } 1837 } else { 1838 return -EINVAL; 1839 } 1840 return 0; 1841 } 1842 1843 static int iwl_mld_mac80211_sta_state(struct ieee80211_hw *hw, 1844 struct ieee80211_vif *vif, 1845 struct ieee80211_sta *sta, 1846 enum ieee80211_sta_state old_state, 1847 enum ieee80211_sta_state new_state) 1848 { 1849 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1850 struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta); 1851 1852 IWL_DEBUG_MAC80211(mld, "station %pM state change %d->%d\n", 1853 sta->addr, old_state, new_state); 1854 1855 mld_sta->sta_state = new_state; 1856 1857 if (old_state < new_state) 1858 return iwl_mld_move_sta_state_up(mld, vif, sta, old_state, 1859 new_state); 1860 else 1861 return iwl_mld_move_sta_state_down(mld, vif, sta, old_state, 1862 new_state); 1863 } 1864 1865 static void iwl_mld_mac80211_flush(struct ieee80211_hw *hw, 1866 struct ieee80211_vif *vif, 1867 u32 queues, bool drop) 1868 { 1869 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1870 1871 /* Make sure we're done with the deferred traffic before flushing */ 1872 iwl_mld_add_txq_list(mld); 1873 1874 for (int i = 0; i < mld->fw->ucode_capa.num_stations; i++) { 1875 struct ieee80211_link_sta *link_sta = 1876 wiphy_dereference(mld->wiphy, 1877 mld->fw_id_to_link_sta[i]); 1878 1879 if (IS_ERR_OR_NULL(link_sta)) 1880 continue; 1881 1882 /* Check that the sta belongs to the given vif */ 1883 if (vif && vif != iwl_mld_sta_from_mac80211(link_sta->sta)->vif) 1884 continue; 1885 1886 if (drop) 1887 iwl_mld_flush_sta_txqs(mld, link_sta->sta); 1888 else 1889 iwl_mld_wait_sta_txqs_empty(mld, link_sta->sta); 1890 } 1891 } 1892 1893 static void iwl_mld_mac80211_flush_sta(struct ieee80211_hw *hw, 1894 struct ieee80211_vif *vif, 1895 struct ieee80211_sta *sta) 1896 { 1897 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1898 1899 iwl_mld_flush_sta_txqs(mld, sta); 1900 } 1901 1902 static int 1903 iwl_mld_mac80211_ampdu_action(struct ieee80211_hw *hw, 1904 struct ieee80211_vif *vif, 1905 struct ieee80211_ampdu_params *params) 1906 { 1907 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1908 struct ieee80211_sta *sta = params->sta; 1909 enum ieee80211_ampdu_mlme_action action = params->action; 1910 u16 tid = params->tid; 1911 u16 ssn = params->ssn; 1912 u16 buf_size = params->buf_size; 1913 u16 timeout = params->timeout; 1914 int ret; 1915 1916 IWL_DEBUG_HT(mld, "A-MPDU action on addr %pM tid: %d action: %d\n", 1917 sta->addr, tid, action); 1918 1919 switch (action) { 1920 case IEEE80211_AMPDU_RX_START: 1921 ret = iwl_mld_ampdu_rx_start(mld, sta, tid, ssn, buf_size, 1922 timeout); 1923 break; 1924 case IEEE80211_AMPDU_RX_STOP: 1925 ret = iwl_mld_ampdu_rx_stop(mld, sta, tid); 1926 break; 1927 default: 1928 /* The mac80211 TX_AMPDU_SETUP_IN_HW flag is set for all 1929 * devices, since all support TX A-MPDU offload in hardware. 1930 * Therefore, no TX action should be requested here. 1931 */ 1932 WARN_ON_ONCE(1); 1933 return -EINVAL; 1934 } 1935 1936 return ret; 1937 } 1938 1939 static bool iwl_mld_can_hw_csum(struct sk_buff *skb) 1940 { 1941 u8 protocol = ip_hdr(skb)->protocol; 1942 1943 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 1944 } 1945 1946 static bool iwl_mld_mac80211_can_aggregate(struct ieee80211_hw *hw, 1947 struct sk_buff *head, 1948 struct sk_buff *skb) 1949 { 1950 if (!IS_ENABLED(CONFIG_INET)) 1951 return false; 1952 1953 /* For now don't aggregate IPv6 in AMSDU */ 1954 if (skb->protocol != htons(ETH_P_IP)) 1955 return false; 1956 1957 /* Allow aggregation only if both frames have the same HW csum offload 1958 * capability, ensuring consistent HW or SW csum handling in A-MSDU. 1959 */ 1960 return iwl_mld_can_hw_csum(skb) == iwl_mld_can_hw_csum(head); 1961 } 1962 1963 static void iwl_mld_mac80211_sync_rx_queues(struct ieee80211_hw *hw) 1964 { 1965 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1966 1967 iwl_mld_sync_rx_queues(mld, IWL_MLD_RXQ_EMPTY, NULL, 0); 1968 } 1969 1970 static void iwl_mld_sta_rc_update(struct ieee80211_hw *hw, 1971 struct ieee80211_vif *vif, 1972 struct ieee80211_link_sta *link_sta, 1973 u32 changed) 1974 { 1975 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1976 1977 if (changed & (IEEE80211_RC_BW_CHANGED | 1978 IEEE80211_RC_SUPP_RATES_CHANGED | 1979 IEEE80211_RC_NSS_CHANGED)) { 1980 struct ieee80211_bss_conf *link = 1981 link_conf_dereference_check(vif, link_sta->link_id); 1982 1983 if (WARN_ON(!link)) 1984 return; 1985 1986 iwl_mld_config_tlc_link(mld, vif, link, link_sta); 1987 } 1988 } 1989 1990 #ifdef CONFIG_PM_SLEEP 1991 static void iwl_mld_set_wakeup(struct ieee80211_hw *hw, bool enabled) 1992 { 1993 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 1994 1995 device_set_wakeup_enable(mld->trans->dev, enabled); 1996 } 1997 1998 /* Returns 0 on success. 1 if failed to suspend with wowlan: 1999 * If the circumstances didn't satisfy the conditions for suspension 2000 * with wowlan, mac80211 would use the no_wowlan flow. 2001 * If an error had occurred we update the trans status and state here 2002 * and the result will be stopping the FW. 2003 */ 2004 static int 2005 iwl_mld_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) 2006 { 2007 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2008 int ret; 2009 2010 iwl_fw_runtime_suspend(&mld->fwrt); 2011 2012 ret = iwl_mld_wowlan_suspend(mld, wowlan); 2013 if (ret) { 2014 if (ret < 0) { 2015 mld->trans->state = IWL_TRANS_NO_FW; 2016 set_bit(STATUS_FW_ERROR, &mld->trans->status); 2017 } 2018 return 1; 2019 } 2020 2021 if (iwl_mld_no_wowlan_suspend(mld)) 2022 return 1; 2023 2024 return 0; 2025 } 2026 2027 static int iwl_mld_resume(struct ieee80211_hw *hw) 2028 { 2029 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2030 int ret; 2031 2032 ret = iwl_mld_wowlan_resume(mld); 2033 if (ret) 2034 return ret; 2035 2036 iwl_fw_runtime_resume(&mld->fwrt); 2037 2038 iwl_mld_low_latency_restart(mld); 2039 2040 return 0; 2041 } 2042 #endif 2043 2044 static int iwl_mld_alloc_ptk_pn(struct iwl_mld *mld, 2045 struct iwl_mld_sta *mld_sta, 2046 struct ieee80211_key_conf *key, 2047 struct iwl_mld_ptk_pn **ptk_pn) 2048 { 2049 u8 num_rx_queues = mld->trans->info.num_rxqs; 2050 int keyidx = key->keyidx; 2051 struct ieee80211_key_seq seq; 2052 2053 if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn))) 2054 return -EINVAL; 2055 2056 WARN_ON(rcu_access_pointer(mld_sta->ptk_pn[keyidx])); 2057 *ptk_pn = kzalloc(struct_size(*ptk_pn, q, num_rx_queues), 2058 GFP_KERNEL); 2059 if (!*ptk_pn) 2060 return -ENOMEM; 2061 2062 for (u8 tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 2063 ieee80211_get_key_rx_seq(key, tid, &seq); 2064 for (u8 q = 0; q < num_rx_queues; q++) 2065 memcpy((*ptk_pn)->q[q].pn[tid], seq.ccmp.pn, 2066 IEEE80211_CCMP_PN_LEN); 2067 } 2068 2069 rcu_assign_pointer(mld_sta->ptk_pn[keyidx], *ptk_pn); 2070 2071 return 0; 2072 } 2073 2074 static int iwl_mld_set_key_add(struct iwl_mld *mld, 2075 struct ieee80211_vif *vif, 2076 struct ieee80211_sta *sta, 2077 struct ieee80211_key_conf *key) 2078 { 2079 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 2080 struct iwl_mld_sta *mld_sta = 2081 sta ? iwl_mld_sta_from_mac80211(sta) : NULL; 2082 struct iwl_mld_ptk_pn *ptk_pn = NULL; 2083 int keyidx = key->keyidx; 2084 int ret; 2085 2086 /* Will be set to 0 if added successfully */ 2087 key->hw_key_idx = STA_KEY_IDX_INVALID; 2088 2089 switch (key->cipher) { 2090 case WLAN_CIPHER_SUITE_WEP40: 2091 case WLAN_CIPHER_SUITE_WEP104: 2092 IWL_DEBUG_MAC80211(mld, "Use SW encryption for WEP\n"); 2093 return -EOPNOTSUPP; 2094 case WLAN_CIPHER_SUITE_TKIP: 2095 if (vif->type == NL80211_IFTYPE_STATION) { 2096 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 2097 break; 2098 } 2099 IWL_DEBUG_MAC80211(mld, "Use SW encryption for TKIP\n"); 2100 return -EOPNOTSUPP; 2101 case WLAN_CIPHER_SUITE_CCMP: 2102 case WLAN_CIPHER_SUITE_GCMP: 2103 case WLAN_CIPHER_SUITE_GCMP_256: 2104 case WLAN_CIPHER_SUITE_AES_CMAC: 2105 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 2106 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 2107 break; 2108 default: 2109 return -EOPNOTSUPP; 2110 } 2111 2112 if (vif->type == NL80211_IFTYPE_STATION && 2113 (keyidx == 6 || keyidx == 7)) 2114 rcu_assign_pointer(mld_vif->bigtks[keyidx - 6], key); 2115 2116 /* After exiting from RFKILL, hostapd configures GTK/ITGK before the 2117 * AP is started, but those keys can't be sent to the FW before the 2118 * MCAST/BCAST STAs are added to it (which happens upon AP start). 2119 * Store it here to be sent later when the AP is started. 2120 */ 2121 if ((vif->type == NL80211_IFTYPE_ADHOC || 2122 vif->type == NL80211_IFTYPE_AP) && !sta && 2123 !mld_vif->ap_ibss_active) 2124 return iwl_mld_store_ap_early_key(mld, key, mld_vif); 2125 2126 if (!mld->fw_status.in_hw_restart && mld_sta && 2127 key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 2128 (key->cipher == WLAN_CIPHER_SUITE_CCMP || 2129 key->cipher == WLAN_CIPHER_SUITE_GCMP || 2130 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 2131 ret = iwl_mld_alloc_ptk_pn(mld, mld_sta, key, &ptk_pn); 2132 if (ret) 2133 return ret; 2134 } 2135 2136 IWL_DEBUG_MAC80211(mld, "set hwcrypto key (sta:%pM, id:%d)\n", 2137 sta ? sta->addr : NULL, keyidx); 2138 2139 ret = iwl_mld_add_key(mld, vif, sta, key); 2140 if (ret) { 2141 IWL_WARN(mld, "set key failed (%d)\n", ret); 2142 if (ptk_pn) { 2143 RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL); 2144 kfree(ptk_pn); 2145 } 2146 2147 return -EOPNOTSUPP; 2148 } 2149 2150 return 0; 2151 } 2152 2153 static void iwl_mld_set_key_remove(struct iwl_mld *mld, 2154 struct ieee80211_vif *vif, 2155 struct ieee80211_sta *sta, 2156 struct ieee80211_key_conf *key) 2157 { 2158 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 2159 struct iwl_mld_sta *mld_sta = 2160 sta ? iwl_mld_sta_from_mac80211(sta) : NULL; 2161 int keyidx = key->keyidx; 2162 2163 if (vif->type == NL80211_IFTYPE_STATION && 2164 (keyidx == 6 || keyidx == 7)) 2165 RCU_INIT_POINTER(mld_vif->bigtks[keyidx - 6], NULL); 2166 2167 if (mld_sta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 2168 (key->cipher == WLAN_CIPHER_SUITE_CCMP || 2169 key->cipher == WLAN_CIPHER_SUITE_GCMP || 2170 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 2171 struct iwl_mld_ptk_pn *ptk_pn; 2172 2173 if (WARN_ON(keyidx >= ARRAY_SIZE(mld_sta->ptk_pn))) 2174 return; 2175 2176 ptk_pn = wiphy_dereference(mld->wiphy, 2177 mld_sta->ptk_pn[keyidx]); 2178 RCU_INIT_POINTER(mld_sta->ptk_pn[keyidx], NULL); 2179 if (!WARN_ON(!ptk_pn)) 2180 kfree_rcu(ptk_pn, rcu_head); 2181 } 2182 2183 /* if this key was stored to be added later to the FW - free it here */ 2184 if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) 2185 iwl_mld_free_ap_early_key(mld, key, mld_vif); 2186 2187 /* We already removed it */ 2188 if (key->hw_key_idx == STA_KEY_IDX_INVALID) 2189 return; 2190 2191 IWL_DEBUG_MAC80211(mld, "disable hwcrypto key\n"); 2192 2193 iwl_mld_remove_key(mld, vif, sta, key); 2194 } 2195 2196 static int iwl_mld_mac80211_set_key(struct ieee80211_hw *hw, 2197 enum set_key_cmd cmd, 2198 struct ieee80211_vif *vif, 2199 struct ieee80211_sta *sta, 2200 struct ieee80211_key_conf *key) 2201 { 2202 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2203 int ret; 2204 2205 switch (cmd) { 2206 case SET_KEY: 2207 ret = iwl_mld_set_key_add(mld, vif, sta, key); 2208 if (ret) 2209 ret = -EOPNOTSUPP; 2210 break; 2211 case DISABLE_KEY: 2212 iwl_mld_set_key_remove(mld, vif, sta, key); 2213 ret = 0; 2214 break; 2215 default: 2216 ret = -EINVAL; 2217 break; 2218 } 2219 2220 return ret; 2221 } 2222 2223 static int 2224 iwl_mld_pre_channel_switch(struct ieee80211_hw *hw, 2225 struct ieee80211_vif *vif, 2226 struct ieee80211_channel_switch *chsw) 2227 { 2228 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2229 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 2230 struct iwl_mld_link *mld_link = 2231 iwl_mld_link_dereference_check(mld_vif, chsw->link_id); 2232 u8 primary; 2233 int selected; 2234 2235 lockdep_assert_wiphy(mld->wiphy); 2236 2237 if (WARN_ON(!mld_link)) 2238 return -EINVAL; 2239 2240 IWL_DEBUG_MAC80211(mld, "pre CSA to freq %d\n", 2241 chsw->chandef.center_freq1); 2242 2243 if (!iwl_mld_emlsr_active(vif)) 2244 return 0; 2245 2246 primary = iwl_mld_get_primary_link(vif); 2247 2248 /* stay on the primary link unless it is undergoing a CSA with quiet */ 2249 if (chsw->link_id == primary && chsw->block_tx) 2250 selected = iwl_mld_get_other_link(vif, primary); 2251 else 2252 selected = primary; 2253 2254 /* Remember to tell the firmware that this link can't tx 2255 * Note that this logic seems to be unrelated to emlsr, but it 2256 * really is needed only when emlsr is active. When we have a 2257 * single link, the firmware will handle all this on its own. 2258 * In multi-link scenarios, we can learn about the CSA from 2259 * another link and this logic is too complex for the firmware 2260 * to track. 2261 * Since we want to de-activate the link that got a CSA with mode=1, 2262 * we need to tell the firmware not to send any frame on that link 2263 * as the firmware may not be aware that link is under a CSA 2264 * with mode=1 (no Tx allowed). 2265 */ 2266 mld_link->silent_deactivation = chsw->block_tx; 2267 iwl_mld_exit_emlsr(mld, vif, IWL_MLD_EMLSR_EXIT_CSA, selected); 2268 2269 return 0; 2270 } 2271 2272 static void 2273 iwl_mld_channel_switch(struct ieee80211_hw *hw, 2274 struct ieee80211_vif *vif, 2275 struct ieee80211_channel_switch *chsw) 2276 { 2277 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2278 2279 /* By implementing this operation, we prevent mac80211 from 2280 * starting its own channel switch timer, so that we can call 2281 * ieee80211_chswitch_done() ourselves at the right time 2282 * (Upon receiving the channel_switch_start notification from the fw) 2283 */ 2284 IWL_DEBUG_MAC80211(mld, 2285 "dummy channel switch op\n"); 2286 } 2287 2288 static int 2289 iwl_mld_post_channel_switch(struct ieee80211_hw *hw, 2290 struct ieee80211_vif *vif, 2291 struct ieee80211_bss_conf *link_conf) 2292 { 2293 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2294 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf); 2295 2296 lockdep_assert_wiphy(mld->wiphy); 2297 2298 WARN_ON(mld_link->silent_deactivation); 2299 2300 return 0; 2301 } 2302 2303 static void 2304 iwl_mld_abort_channel_switch(struct ieee80211_hw *hw, 2305 struct ieee80211_vif *vif, 2306 struct ieee80211_bss_conf *link_conf) 2307 { 2308 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2309 struct iwl_mld_link *mld_link = iwl_mld_link_from_mac80211(link_conf); 2310 2311 IWL_DEBUG_MAC80211(mld, 2312 "abort channel switch op\n"); 2313 mld_link->silent_deactivation = false; 2314 } 2315 2316 static int 2317 iwl_mld_switch_vif_chanctx_swap(struct ieee80211_hw *hw, 2318 struct ieee80211_vif_chanctx_switch *vifs) 2319 { 2320 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2321 int ret; 2322 2323 iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf, 2324 vifs[0].old_ctx); 2325 iwl_mld_remove_chanctx(hw, vifs[0].old_ctx); 2326 2327 ret = iwl_mld_add_chanctx(hw, vifs[0].new_ctx); 2328 if (ret) { 2329 IWL_ERR(mld, "failed to add new_ctx during channel switch\n"); 2330 goto out_reassign; 2331 } 2332 2333 ret = iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf, 2334 vifs[0].new_ctx); 2335 if (ret) { 2336 IWL_ERR(mld, 2337 "failed to assign new_ctx during channel switch\n"); 2338 goto out_remove; 2339 } 2340 2341 return 0; 2342 2343 out_remove: 2344 iwl_mld_remove_chanctx(hw, vifs[0].new_ctx); 2345 out_reassign: 2346 if (iwl_mld_add_chanctx(hw, vifs[0].old_ctx)) { 2347 IWL_ERR(mld, "failed to add old_ctx after failure\n"); 2348 return ret; 2349 } 2350 2351 if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf, 2352 vifs[0].old_ctx)) 2353 IWL_ERR(mld, "failed to reassign old_ctx after failure\n"); 2354 2355 return ret; 2356 } 2357 2358 static int 2359 iwl_mld_switch_vif_chanctx_reassign(struct ieee80211_hw *hw, 2360 struct ieee80211_vif_chanctx_switch *vifs) 2361 { 2362 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2363 int ret; 2364 2365 iwl_mld_unassign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf, 2366 vifs[0].old_ctx); 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_reassign; 2373 } 2374 2375 return 0; 2376 2377 out_reassign: 2378 if (iwl_mld_assign_vif_chanctx(hw, vifs[0].vif, vifs[0].link_conf, 2379 vifs[0].old_ctx)) 2380 IWL_ERR(mld, "failed to reassign old_ctx after failure\n"); 2381 2382 return ret; 2383 } 2384 2385 static int 2386 iwl_mld_switch_vif_chanctx(struct ieee80211_hw *hw, 2387 struct ieee80211_vif_chanctx_switch *vifs, 2388 int n_vifs, 2389 enum ieee80211_chanctx_switch_mode mode) 2390 { 2391 int ret; 2392 2393 /* we only support a single-vif right now */ 2394 if (n_vifs > 1) 2395 return -EOPNOTSUPP; 2396 2397 switch (mode) { 2398 case CHANCTX_SWMODE_SWAP_CONTEXTS: 2399 ret = iwl_mld_switch_vif_chanctx_swap(hw, vifs); 2400 break; 2401 case CHANCTX_SWMODE_REASSIGN_VIF: 2402 ret = iwl_mld_switch_vif_chanctx_reassign(hw, vifs); 2403 break; 2404 default: 2405 ret = -EOPNOTSUPP; 2406 break; 2407 } 2408 2409 return ret; 2410 } 2411 2412 static void iwl_mld_sta_pre_rcu_remove(struct ieee80211_hw *hw, 2413 struct ieee80211_vif *vif, 2414 struct ieee80211_sta *sta) 2415 { 2416 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2417 struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta); 2418 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 2419 struct iwl_mld_link_sta *mld_link_sta; 2420 u8 link_id; 2421 2422 lockdep_assert_wiphy(mld->wiphy); 2423 2424 /* This is called before mac80211 does RCU synchronisation, 2425 * so here we already invalidate our internal RCU-protected 2426 * station pointer. The rest of the code will thus no longer 2427 * be able to find the station this way, and we don't rely 2428 * on further RCU synchronisation after the sta_state() 2429 * callback deleted the station. 2430 */ 2431 for_each_mld_link_sta(mld_sta, mld_link_sta, link_id) 2432 RCU_INIT_POINTER(mld->fw_id_to_link_sta[mld_link_sta->fw_id], 2433 NULL); 2434 2435 if (sta == mld_vif->ap_sta) 2436 mld_vif->ap_sta = NULL; 2437 } 2438 2439 static void 2440 iwl_mld_mac80211_mgd_protect_tdls_discover(struct ieee80211_hw *hw, 2441 struct ieee80211_vif *vif, 2442 unsigned int link_id) 2443 { 2444 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2445 struct ieee80211_bss_conf *link_conf; 2446 u32 duration; 2447 int ret; 2448 2449 link_conf = wiphy_dereference(hw->wiphy, vif->link_conf[link_id]); 2450 if (WARN_ON_ONCE(!link_conf)) 2451 return; 2452 2453 /* Protect the session to hear the TDLS setup response on the channel */ 2454 2455 duration = 2 * link_conf->dtim_period * link_conf->beacon_int; 2456 2457 ret = iwl_mld_start_session_protection(mld, vif, duration, duration, 2458 link_id, HZ / 5); 2459 if (ret) 2460 IWL_ERR(mld, 2461 "Failed to start session protection for TDLS: %d\n", 2462 ret); 2463 } 2464 2465 static bool iwl_mld_can_activate_links(struct ieee80211_hw *hw, 2466 struct ieee80211_vif *vif, 2467 u16 desired_links) 2468 { 2469 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2470 int n_links = hweight16(desired_links); 2471 2472 /* Check if HW supports the wanted number of links */ 2473 return n_links <= iwl_mld_max_active_links(mld, vif); 2474 } 2475 2476 static int 2477 iwl_mld_change_vif_links(struct ieee80211_hw *hw, 2478 struct ieee80211_vif *vif, 2479 u16 old_links, u16 new_links, 2480 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS]) 2481 { 2482 struct iwl_mld_vif *mld_vif = iwl_mld_vif_from_mac80211(vif); 2483 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2484 struct ieee80211_bss_conf *link_conf; 2485 u16 removed = old_links & ~new_links; 2486 u16 added = new_links & ~old_links; 2487 int err; 2488 2489 lockdep_assert_wiphy(mld->wiphy); 2490 2491 /* 2492 * No bits designate non-MLO mode. We can handle MLO exit/enter by 2493 * simply mapping that to link ID zero internally. 2494 * Note that mac80211 does such a non-MLO to MLO switch during restart 2495 * if it was in MLO before. In that case, we do not have a link to 2496 * remove. 2497 */ 2498 if (old_links == 0 && !mld->fw_status.in_hw_restart) 2499 removed |= BIT(0); 2500 2501 if (new_links == 0) 2502 added |= BIT(0); 2503 2504 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 2505 if (removed & BIT(i) && !WARN_ON(!old[i])) 2506 iwl_mld_remove_link(mld, old[i]); 2507 } 2508 2509 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 2510 if (added & BIT(i)) { 2511 link_conf = link_conf_dereference_protected(vif, i); 2512 if (!link_conf) { 2513 err = -EINVAL; 2514 goto remove_added_links; 2515 } 2516 2517 err = iwl_mld_add_link(mld, link_conf); 2518 if (err) 2519 goto remove_added_links; 2520 } 2521 } 2522 2523 /* 2524 * Ensure we always have a valid primary_link. When using multiple 2525 * links the proper value is set in assign_vif_chanctx. 2526 */ 2527 mld_vif->emlsr.primary = new_links ? __ffs(new_links) : 0; 2528 2529 /* 2530 * Special MLO restart case. We did not have a link when the interface 2531 * was added, so do the power configuration now. 2532 */ 2533 if (old_links == 0 && mld->fw_status.in_hw_restart) 2534 iwl_mld_update_mac_power(mld, vif, false); 2535 2536 return 0; 2537 2538 remove_added_links: 2539 for (int i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 2540 if (!(added & BIT(i))) 2541 continue; 2542 2543 link_conf = link_conf_dereference_protected(vif, i); 2544 if (!link_conf || !iwl_mld_link_from_mac80211(link_conf)) 2545 continue; 2546 2547 iwl_mld_remove_link(mld, link_conf); 2548 } 2549 2550 if (WARN_ON(!iwl_mld_error_before_recovery(mld))) 2551 return err; 2552 2553 /* reconfig will fix us anyway */ 2554 return 0; 2555 } 2556 2557 static int iwl_mld_change_sta_links(struct ieee80211_hw *hw, 2558 struct ieee80211_vif *vif, 2559 struct ieee80211_sta *sta, 2560 u16 old_links, u16 new_links) 2561 { 2562 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2563 2564 return iwl_mld_update_link_stas(mld, vif, sta, old_links, new_links); 2565 } 2566 2567 static int iwl_mld_mac80211_join_ibss(struct ieee80211_hw *hw, 2568 struct ieee80211_vif *vif) 2569 { 2570 return iwl_mld_start_ap_ibss(hw, vif, &vif->bss_conf); 2571 } 2572 2573 static void iwl_mld_mac80211_leave_ibss(struct ieee80211_hw *hw, 2574 struct ieee80211_vif *vif) 2575 { 2576 return iwl_mld_stop_ap_ibss(hw, vif, &vif->bss_conf); 2577 } 2578 2579 static int iwl_mld_mac80211_tx_last_beacon(struct ieee80211_hw *hw) 2580 { 2581 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2582 2583 return mld->ibss_manager; 2584 } 2585 2586 static void iwl_mld_prep_add_interface(struct ieee80211_hw *hw, 2587 enum nl80211_iftype type) 2588 { 2589 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2590 2591 IWL_DEBUG_MAC80211(mld, "prep_add_interface: type=%u\n", type); 2592 2593 if (!(type == NL80211_IFTYPE_AP || 2594 type == NL80211_IFTYPE_P2P_GO || 2595 type == NL80211_IFTYPE_P2P_CLIENT)) 2596 return; 2597 2598 iwl_mld_emlsr_block_tmp_non_bss(mld); 2599 } 2600 2601 static int iwl_mld_set_hw_timestamp(struct ieee80211_hw *hw, 2602 struct ieee80211_vif *vif, 2603 struct cfg80211_set_hw_timestamp *hwts) 2604 { 2605 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2606 u32 protocols = 0; 2607 2608 /* HW timestamping is only supported for a specific station */ 2609 if (!hwts->macaddr) 2610 return -EOPNOTSUPP; 2611 2612 if (hwts->enable) 2613 protocols = 2614 IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM; 2615 2616 return iwl_mld_time_sync_config(mld, hwts->macaddr, protocols); 2617 } 2618 2619 static int iwl_mld_start_pmsr(struct ieee80211_hw *hw, 2620 struct ieee80211_vif *vif, 2621 struct cfg80211_pmsr_request *request) 2622 { 2623 struct iwl_mld *mld = IWL_MAC80211_GET_MLD(hw); 2624 2625 return iwl_mld_ftm_start(mld, vif, request); 2626 } 2627 2628 static enum ieee80211_neg_ttlm_res 2629 iwl_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 2630 struct ieee80211_neg_ttlm *neg_ttlm) 2631 { 2632 u16 map; 2633 2634 /* Verify all TIDs are mapped to the same links set */ 2635 map = neg_ttlm->downlink[0]; 2636 for (int i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 2637 if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] || 2638 neg_ttlm->uplink[i] != map) 2639 return NEG_TTLM_RES_REJECT; 2640 } 2641 2642 return NEG_TTLM_RES_ACCEPT; 2643 } 2644 2645 const struct ieee80211_ops iwl_mld_hw_ops = { 2646 .tx = iwl_mld_mac80211_tx, 2647 .start = iwl_mld_mac80211_start, 2648 .stop = iwl_mld_mac80211_stop, 2649 .config = iwl_mld_mac80211_config, 2650 .add_interface = iwl_mld_mac80211_add_interface, 2651 .remove_interface = iwl_mld_mac80211_remove_interface, 2652 .conf_tx = iwl_mld_mac80211_conf_tx, 2653 .prepare_multicast = iwl_mld_mac80211_prepare_multicast, 2654 .configure_filter = iwl_mld_mac80211_configure_filter, 2655 .reconfig_complete = iwl_mld_mac80211_reconfig_complete, 2656 .wake_tx_queue = iwl_mld_mac80211_wake_tx_queue, 2657 .add_chanctx = iwl_mld_add_chanctx, 2658 .remove_chanctx = iwl_mld_remove_chanctx, 2659 .change_chanctx = iwl_mld_change_chanctx, 2660 .assign_vif_chanctx = iwl_mld_assign_vif_chanctx, 2661 .unassign_vif_chanctx = iwl_mld_unassign_vif_chanctx, 2662 .set_rts_threshold = iwl_mld_mac80211_set_rts_threshold, 2663 .link_info_changed = iwl_mld_mac80211_link_info_changed, 2664 .vif_cfg_changed = iwl_mld_mac80211_vif_cfg_changed, 2665 .set_key = iwl_mld_mac80211_set_key, 2666 .hw_scan = iwl_mld_mac80211_hw_scan, 2667 .cancel_hw_scan = iwl_mld_mac80211_cancel_hw_scan, 2668 .sched_scan_start = iwl_mld_mac80211_sched_scan_start, 2669 .sched_scan_stop = iwl_mld_mac80211_sched_scan_stop, 2670 .mgd_prepare_tx = iwl_mld_mac80211_mgd_prepare_tx, 2671 .mgd_complete_tx = iwl_mld_mac_mgd_complete_tx, 2672 .sta_state = iwl_mld_mac80211_sta_state, 2673 .sta_statistics = iwl_mld_mac80211_sta_statistics, 2674 .flush = iwl_mld_mac80211_flush, 2675 .flush_sta = iwl_mld_mac80211_flush_sta, 2676 .ampdu_action = iwl_mld_mac80211_ampdu_action, 2677 .can_aggregate_in_amsdu = iwl_mld_mac80211_can_aggregate, 2678 .sync_rx_queues = iwl_mld_mac80211_sync_rx_queues, 2679 .link_sta_rc_update = iwl_mld_sta_rc_update, 2680 .start_ap = iwl_mld_start_ap_ibss, 2681 .stop_ap = iwl_mld_stop_ap_ibss, 2682 .pre_channel_switch = iwl_mld_pre_channel_switch, 2683 .channel_switch = iwl_mld_channel_switch, 2684 .post_channel_switch = iwl_mld_post_channel_switch, 2685 .abort_channel_switch = iwl_mld_abort_channel_switch, 2686 .switch_vif_chanctx = iwl_mld_switch_vif_chanctx, 2687 .sta_pre_rcu_remove = iwl_mld_sta_pre_rcu_remove, 2688 .remain_on_channel = iwl_mld_start_roc, 2689 .cancel_remain_on_channel = iwl_mld_cancel_roc, 2690 .can_activate_links = iwl_mld_can_activate_links, 2691 .change_vif_links = iwl_mld_change_vif_links, 2692 .change_sta_links = iwl_mld_change_sta_links, 2693 #ifdef CONFIG_PM_SLEEP 2694 .suspend = iwl_mld_suspend, 2695 .resume = iwl_mld_resume, 2696 .set_wakeup = iwl_mld_set_wakeup, 2697 .set_rekey_data = iwl_mld_set_rekey_data, 2698 #if IS_ENABLED(CONFIG_IPV6) 2699 .ipv6_addr_change = iwl_mld_ipv6_addr_change, 2700 #endif /* IS_ENABLED(CONFIG_IPV6) */ 2701 #endif /* CONFIG_PM_SLEEP */ 2702 #ifdef CONFIG_IWLWIFI_DEBUGFS 2703 .vif_add_debugfs = iwl_mld_add_vif_debugfs, 2704 .link_add_debugfs = iwl_mld_add_link_debugfs, 2705 .link_sta_add_debugfs = iwl_mld_add_link_sta_debugfs, 2706 #endif 2707 .mgd_protect_tdls_discover = iwl_mld_mac80211_mgd_protect_tdls_discover, 2708 .join_ibss = iwl_mld_mac80211_join_ibss, 2709 .leave_ibss = iwl_mld_mac80211_leave_ibss, 2710 .tx_last_beacon = iwl_mld_mac80211_tx_last_beacon, 2711 .prep_add_interface = iwl_mld_prep_add_interface, 2712 .set_hw_timestamp = iwl_mld_set_hw_timestamp, 2713 .start_pmsr = iwl_mld_start_pmsr, 2714 .can_neg_ttlm = iwl_mld_can_neg_ttlm, 2715 }; 2716