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