1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2022-2025 Intel Corporation 4 */ 5 #include "mvm.h" 6 7 static int iwl_mvm_mld_mac_add_interface(struct ieee80211_hw *hw, 8 struct ieee80211_vif *vif) 9 { 10 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 11 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 12 int ret; 13 int i; 14 15 guard(mvm)(mvm); 16 17 iwl_mvm_mac_init_mvmvif(mvm, mvmvif); 18 19 mvmvif->mvm = mvm; 20 21 vif->driver_flags |= IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC; 22 23 /* Not much to do here. The stack will not allow interface 24 * types or combinations that we didn't advertise, so we 25 * don't really have to check the types. 26 */ 27 28 /* make sure that beacon statistics don't go backwards with FW reset */ 29 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 30 for_each_mvm_vif_valid_link(mvmvif, i) 31 mvmvif->link[i]->beacon_stats.accu_num_beacons += 32 mvmvif->link[i]->beacon_stats.num_beacons; 33 34 /* Allocate resources for the MAC context, and add it to the fw */ 35 ret = iwl_mvm_mac_ctxt_init(mvm, vif); 36 if (ret) 37 return ret; 38 39 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 40 41 mvmvif->features |= hw->netdev_features; 42 43 /* reset deflink MLO parameters */ 44 mvmvif->deflink.fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 45 mvmvif->deflink.active = 0; 46 47 ret = iwl_mvm_mld_mac_ctxt_add(mvm, vif); 48 if (ret) 49 return ret; 50 51 /* beacon filtering */ 52 ret = iwl_mvm_disable_beacon_filter(mvm, vif); 53 if (ret) 54 goto out_remove_mac; 55 56 if (!mvm->bf_allowed_vif && 57 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 58 mvm->bf_allowed_vif = mvmvif; 59 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 60 IEEE80211_VIF_SUPPORTS_CQM_RSSI; 61 } 62 63 /* We want link[0] to point to the default link, unless we have MLO and 64 * in this case this will be modified later by .change_vif_links() 65 * If we are in the restart flow with an MLD connection, we will wait 66 * to .change_vif_links() to setup the links. 67 */ 68 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 69 !ieee80211_vif_is_mld(vif)) { 70 mvmvif->link[0] = &mvmvif->deflink; 71 72 ret = iwl_mvm_add_link(mvm, vif, &vif->bss_conf); 73 if (ret) 74 goto out_free_bf; 75 } 76 77 /* Save a pointer to p2p device vif, so it can later be used to 78 * update the p2p device MAC when a GO is started/stopped 79 */ 80 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 81 mvm->p2p_device_vif = vif; 82 83 ret = iwl_mvm_power_update_mac(mvm); 84 if (ret) 85 goto out_free_bf; 86 87 iwl_mvm_tcm_add_vif(mvm, vif); 88 89 if (vif->type == NL80211_IFTYPE_MONITOR) { 90 mvm->monitor_on = true; 91 ieee80211_hw_set(mvm->hw, RX_INCLUDES_FCS); 92 } 93 94 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 95 iwl_mvm_vif_dbgfs_add_link(mvm, vif); 96 97 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 98 vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 99 !mvm->csme_vif && mvm->mei_registered) { 100 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 101 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 102 mvm->csme_vif = vif; 103 } 104 105 if (vif->p2p || iwl_fw_lookup_cmd_ver(mvm->fw, PHY_CONTEXT_CMD, 1) < 5) 106 vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW; 107 108 return 0; 109 110 out_free_bf: 111 if (mvm->bf_allowed_vif == mvmvif) { 112 mvm->bf_allowed_vif = NULL; 113 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 114 IEEE80211_VIF_SUPPORTS_CQM_RSSI); 115 } 116 out_remove_mac: 117 mvmvif->link[0] = NULL; 118 iwl_mvm_mld_mac_ctxt_remove(mvm, vif); 119 return ret; 120 } 121 122 static void iwl_mvm_mld_mac_remove_interface(struct ieee80211_hw *hw, 123 struct ieee80211_vif *vif) 124 { 125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 126 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 127 struct iwl_probe_resp_data *probe_data; 128 129 iwl_mvm_prepare_mac_removal(mvm, vif); 130 131 if (!(vif->type == NL80211_IFTYPE_AP || 132 vif->type == NL80211_IFTYPE_ADHOC)) 133 iwl_mvm_tcm_rm_vif(mvm, vif); 134 135 guard(mvm)(mvm); 136 137 if (vif == mvm->csme_vif) { 138 iwl_mei_set_netdev(NULL); 139 mvm->csme_vif = NULL; 140 } 141 142 if (mvm->bf_allowed_vif == mvmvif) { 143 mvm->bf_allowed_vif = NULL; 144 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 145 IEEE80211_VIF_SUPPORTS_CQM_RSSI); 146 } 147 148 if (vif->bss_conf.ftm_responder) 149 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 150 151 iwl_mvm_vif_dbgfs_rm_link(mvm, vif); 152 153 /* For AP/GO interface, the tear down of the resources allocated to the 154 * interface is be handled as part of the stop_ap flow. 155 */ 156 if (vif->type == NL80211_IFTYPE_AP || 157 vif->type == NL80211_IFTYPE_ADHOC) { 158 #ifdef CONFIG_NL80211_TESTMODE 159 if (vif == mvm->noa_vif) { 160 mvm->noa_vif = NULL; 161 mvm->noa_duration = 0; 162 } 163 #endif 164 } 165 166 iwl_mvm_power_update_mac(mvm); 167 168 /* Before the interface removal, mac80211 would cancel the ROC, and the 169 * ROC worker would be scheduled if needed. The worker would be flushed 170 * in iwl_mvm_prepare_mac_removal() and thus at this point the link is 171 * not active. So need only to remove the link. 172 */ 173 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 174 if (mvmvif->deflink.phy_ctxt) { 175 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 176 mvmvif->deflink.phy_ctxt = NULL; 177 } 178 mvm->p2p_device_vif = NULL; 179 iwl_mvm_remove_link(mvm, vif, &vif->bss_conf); 180 } else { 181 iwl_mvm_disable_link(mvm, vif, &vif->bss_conf); 182 } 183 184 iwl_mvm_mld_mac_ctxt_remove(mvm, vif); 185 186 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 187 188 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 189 lockdep_is_held(&mvm->mutex)); 190 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 191 if (probe_data) 192 kfree_rcu(probe_data, rcu_head); 193 194 if (vif->type == NL80211_IFTYPE_MONITOR) { 195 mvm->monitor_on = false; 196 __clear_bit(IEEE80211_HW_RX_INCLUDES_FCS, mvm->hw->flags); 197 } 198 } 199 200 static unsigned int iwl_mvm_mld_count_active_links(struct iwl_mvm_vif *mvmvif) 201 { 202 unsigned int n_active = 0; 203 int i; 204 205 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 206 if (mvmvif->link[i] && mvmvif->link[i]->phy_ctxt) 207 n_active++; 208 } 209 210 return n_active; 211 } 212 213 static int iwl_mvm_esr_mode_active(struct iwl_mvm *mvm, 214 struct ieee80211_vif *vif) 215 { 216 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 217 int link_id, ret = 0; 218 219 mvmvif->esr_active = true; 220 221 /* Indicate to mac80211 that EML is enabled */ 222 vif->driver_flags |= IEEE80211_VIF_EML_ACTIVE; 223 224 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_FW, 225 IEEE80211_SMPS_OFF); 226 227 for_each_mvm_vif_valid_link(mvmvif, link_id) { 228 struct iwl_mvm_vif_link_info *link = mvmvif->link[link_id]; 229 230 if (!link->phy_ctxt) 231 continue; 232 233 ret = iwl_mvm_phy_send_rlc(mvm, link->phy_ctxt, 2, 2); 234 if (ret) 235 break; 236 237 link->phy_ctxt->rlc_disabled = true; 238 } 239 240 if (vif->active_links == mvmvif->link_selection_res && 241 !WARN_ON(!(vif->active_links & BIT(mvmvif->link_selection_primary)))) 242 mvmvif->primary_link = mvmvif->link_selection_primary; 243 else 244 mvmvif->primary_link = __ffs(vif->active_links); 245 246 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_ESR_LINK_UP, 247 NULL); 248 249 return ret; 250 } 251 252 static int 253 __iwl_mvm_mld_assign_vif_chanctx(struct iwl_mvm *mvm, 254 struct ieee80211_vif *vif, 255 struct ieee80211_bss_conf *link_conf, 256 struct ieee80211_chanctx_conf *ctx, 257 bool switching_chanctx) 258 { 259 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 260 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 261 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 262 unsigned int n_active = iwl_mvm_mld_count_active_links(mvmvif); 263 unsigned int link_id = link_conf->link_id; 264 int ret; 265 266 if (WARN_ON_ONCE(!mvmvif->link[link_id])) 267 return -EINVAL; 268 269 /* if the assigned one was not counted yet, count it now */ 270 if (!mvmvif->link[link_id]->phy_ctxt) 271 n_active++; 272 273 /* mac parameters such as HE support can change at this stage 274 * For sta, need first to configure correct state from drv_sta_state 275 * and only after that update mac config. 276 */ 277 if (vif->type == NL80211_IFTYPE_AP) { 278 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 279 if (ret) { 280 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 281 return -EINVAL; 282 } 283 } 284 285 mvmvif->link[link_id]->phy_ctxt = phy_ctxt; 286 287 if (iwl_mvm_is_esr_supported(mvm->fwrt.trans) && n_active > 1) { 288 mvmvif->link[link_id]->listen_lmac = true; 289 ret = iwl_mvm_esr_mode_active(mvm, vif); 290 if (ret) { 291 IWL_ERR(mvm, "failed to activate ESR mode (%d)\n", ret); 292 goto out; 293 } 294 } 295 296 if (switching_chanctx) { 297 /* reactivate if we turned this off during channel switch */ 298 if (vif->type == NL80211_IFTYPE_AP) 299 mvmvif->ap_ibss_active = true; 300 } 301 302 /* send it first with phy context ID */ 303 ret = iwl_mvm_link_changed(mvm, vif, link_conf, 0, false); 304 if (ret) 305 goto out; 306 307 /* 308 * if link switching (link not active yet) we'll activate it in 309 * firmware later on link-info change, which mac80211 guarantees 310 * for link switch after the stations are set up 311 */ 312 if (ieee80211_vif_link_active(vif, link_conf->link_id)) { 313 ret = iwl_mvm_link_changed(mvm, vif, link_conf, 314 LINK_CONTEXT_MODIFY_ACTIVE | 315 LINK_CONTEXT_MODIFY_RATES_INFO, 316 true); 317 if (ret) 318 goto out; 319 } 320 321 if (vif->type == NL80211_IFTYPE_STATION) 322 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif, 323 link_conf, 324 false); 325 326 /* 327 * Power state must be updated before quotas, 328 * otherwise fw will complain. 329 */ 330 iwl_mvm_power_update_mac(mvm); 331 332 if (vif->type == NL80211_IFTYPE_MONITOR) { 333 ret = iwl_mvm_mld_add_snif_sta(mvm, vif, link_conf); 334 if (ret) 335 goto deactivate; 336 } 337 338 return 0; 339 340 deactivate: 341 iwl_mvm_link_changed(mvm, vif, link_conf, LINK_CONTEXT_MODIFY_ACTIVE, 342 false); 343 out: 344 mvmvif->link[link_id]->phy_ctxt = NULL; 345 iwl_mvm_power_update_mac(mvm); 346 return ret; 347 } 348 349 static int iwl_mvm_mld_assign_vif_chanctx(struct ieee80211_hw *hw, 350 struct ieee80211_vif *vif, 351 struct ieee80211_bss_conf *link_conf, 352 struct ieee80211_chanctx_conf *ctx) 353 { 354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 355 356 /* update EMLSR mode */ 357 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) { 358 int ret; 359 360 ret = iwl_mvm_esr_non_bss_link(mvm, vif, link_conf->link_id, 361 true); 362 /* 363 * Don't activate this link if failed to exit EMLSR in 364 * the BSS interface 365 */ 366 if (ret) 367 return ret; 368 } 369 370 guard(mvm)(mvm); 371 return __iwl_mvm_mld_assign_vif_chanctx(mvm, vif, link_conf, ctx, false); 372 } 373 374 static int iwl_mvm_esr_mode_inactive(struct iwl_mvm *mvm, 375 struct ieee80211_vif *vif) 376 { 377 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 378 struct ieee80211_bss_conf *link_conf; 379 int link_id, ret = 0; 380 381 mvmvif->esr_active = false; 382 383 vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE; 384 385 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_FW, 386 IEEE80211_SMPS_AUTOMATIC); 387 388 for_each_vif_active_link(vif, link_conf, link_id) { 389 struct ieee80211_chanctx_conf *chanctx_conf; 390 struct iwl_mvm_phy_ctxt *phy_ctxt; 391 u8 static_chains, dynamic_chains; 392 393 mvmvif->link[link_id]->listen_lmac = false; 394 395 rcu_read_lock(); 396 397 chanctx_conf = rcu_dereference(link_conf->chanctx_conf); 398 phy_ctxt = mvmvif->link[link_id]->phy_ctxt; 399 400 if (!chanctx_conf || !phy_ctxt) { 401 rcu_read_unlock(); 402 continue; 403 } 404 405 phy_ctxt->rlc_disabled = false; 406 static_chains = chanctx_conf->rx_chains_static; 407 dynamic_chains = chanctx_conf->rx_chains_dynamic; 408 409 rcu_read_unlock(); 410 411 ret = iwl_mvm_phy_send_rlc(mvm, phy_ctxt, static_chains, 412 dynamic_chains); 413 if (ret) 414 break; 415 } 416 417 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_ESR_LINK_DOWN, 418 NULL); 419 420 return ret; 421 } 422 423 static void 424 __iwl_mvm_mld_unassign_vif_chanctx(struct iwl_mvm *mvm, 425 struct ieee80211_vif *vif, 426 struct ieee80211_bss_conf *link_conf, 427 struct ieee80211_chanctx_conf *ctx, 428 bool switching_chanctx) 429 430 { 431 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 432 unsigned int n_active = iwl_mvm_mld_count_active_links(mvmvif); 433 unsigned int link_id = link_conf->link_id; 434 435 /* shouldn't happen, but verify link_id is valid before accessing */ 436 if (WARN_ON_ONCE(!mvmvif->link[link_id])) 437 return; 438 439 if (vif->type == NL80211_IFTYPE_AP && switching_chanctx) { 440 mvmvif->csa_countdown = false; 441 442 /* Set CS bit on all the stations */ 443 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 444 445 /* Save blocked iface, the timeout is set on the next beacon */ 446 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 447 448 mvmvif->ap_ibss_active = false; 449 } 450 451 iwl_mvm_link_changed(mvm, vif, link_conf, 452 LINK_CONTEXT_MODIFY_ACTIVE, false); 453 454 if (iwl_mvm_is_esr_supported(mvm->fwrt.trans) && n_active > 1) { 455 int ret = iwl_mvm_esr_mode_inactive(mvm, vif); 456 457 if (ret) 458 IWL_ERR(mvm, "failed to deactivate ESR mode (%d)\n", 459 ret); 460 } 461 462 if (vif->type == NL80211_IFTYPE_MONITOR) 463 iwl_mvm_mld_rm_snif_sta(mvm, vif); 464 465 if (switching_chanctx) 466 return; 467 mvmvif->link[link_id]->phy_ctxt = NULL; 468 iwl_mvm_power_update_mac(mvm); 469 } 470 471 static void iwl_mvm_mld_unassign_vif_chanctx(struct ieee80211_hw *hw, 472 struct ieee80211_vif *vif, 473 struct ieee80211_bss_conf *link_conf, 474 struct ieee80211_chanctx_conf *ctx) 475 { 476 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 478 479 mutex_lock(&mvm->mutex); 480 __iwl_mvm_mld_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false); 481 /* in the non-MLD case, remove/re-add the link to clean up FW state */ 482 if (!ieee80211_vif_is_mld(vif) && !mvmvif->ap_sta && 483 !WARN_ON_ONCE(vif->cfg.assoc)) { 484 iwl_mvm_remove_link(mvm, vif, link_conf); 485 iwl_mvm_add_link(mvm, vif, link_conf); 486 } 487 mutex_unlock(&mvm->mutex); 488 489 /* update EMLSR mode */ 490 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) 491 iwl_mvm_esr_non_bss_link(mvm, vif, link_conf->link_id, false); 492 } 493 494 static void 495 iwl_mvm_tpe_sta_cmd_data(struct iwl_txpower_constraints_cmd *cmd, 496 const struct ieee80211_bss_conf *bss_info) 497 { 498 u8 i; 499 500 /* 501 * NOTE: the 0 here is IEEE80211_TPE_CAT_6GHZ_DEFAULT, 502 * we fully ignore IEEE80211_TPE_CAT_6GHZ_SUBORDINATE 503 */ 504 505 BUILD_BUG_ON(ARRAY_SIZE(cmd->psd_pwr) != 506 ARRAY_SIZE(bss_info->tpe.psd_local[0].power)); 507 508 /* if not valid, mac80211 puts default (max value) */ 509 for (i = 0; i < ARRAY_SIZE(cmd->psd_pwr); i++) 510 cmd->psd_pwr[i] = min(bss_info->tpe.psd_local[0].power[i], 511 bss_info->tpe.psd_reg_client[0].power[i]); 512 513 BUILD_BUG_ON(ARRAY_SIZE(cmd->eirp_pwr) != 514 ARRAY_SIZE(bss_info->tpe.max_local[0].power)); 515 516 for (i = 0; i < ARRAY_SIZE(cmd->eirp_pwr); i++) 517 cmd->eirp_pwr[i] = min(bss_info->tpe.max_local[0].power[i], 518 bss_info->tpe.max_reg_client[0].power[i]); 519 } 520 521 void 522 iwl_mvm_send_ap_tx_power_constraint_cmd(struct iwl_mvm *mvm, 523 struct ieee80211_vif *vif, 524 struct ieee80211_bss_conf *bss_conf, 525 bool is_ap) 526 { 527 struct iwl_txpower_constraints_cmd cmd = {}; 528 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 529 struct iwl_mvm_vif_link_info *link_info = 530 mvmvif->link[bss_conf->link_id]; 531 u32 cmd_id = WIDE_ID(PHY_OPS_GROUP, AP_TX_POWER_CONSTRAINTS_CMD); 532 u32 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 533 IWL_FW_CMD_VER_UNKNOWN); 534 int ret; 535 536 lockdep_assert_held(&mvm->mutex); 537 538 if (cmd_ver == IWL_FW_CMD_VER_UNKNOWN) 539 return; 540 541 if (!link_info->active || 542 link_info->fw_link_id == IWL_MVM_FW_LINK_ID_INVALID) 543 return; 544 545 if (bss_conf->chanreq.oper.chan->band != NL80211_BAND_6GHZ) 546 return; 547 548 cmd.link_id = cpu_to_le16(link_info->fw_link_id); 549 memset(cmd.psd_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.psd_pwr)); 550 memset(cmd.eirp_pwr, DEFAULT_TPE_TX_POWER, sizeof(cmd.eirp_pwr)); 551 552 if (is_ap) { 553 cmd.ap_type = cpu_to_le16(IWL_6GHZ_AP_TYPE_VLP); 554 } else if (bss_conf->power_type == IEEE80211_REG_UNSET_AP) { 555 return; 556 } else { 557 cmd.ap_type = cpu_to_le16(bss_conf->power_type - 1); 558 iwl_mvm_tpe_sta_cmd_data(&cmd, bss_conf); 559 } 560 561 ret = iwl_mvm_send_cmd_pdu(mvm, 562 WIDE_ID(PHY_OPS_GROUP, 563 AP_TX_POWER_CONSTRAINTS_CMD), 564 0, sizeof(cmd), &cmd); 565 if (ret) 566 IWL_ERR(mvm, 567 "failed to send AP_TX_POWER_CONSTRAINTS_CMD (%d)\n", 568 ret); 569 } 570 571 static int iwl_mvm_mld_start_ap_ibss(struct ieee80211_hw *hw, 572 struct ieee80211_vif *vif, 573 struct ieee80211_bss_conf *link_conf) 574 { 575 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 576 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 577 int ret; 578 579 guard(mvm)(mvm); 580 581 if (vif->type == NL80211_IFTYPE_AP) 582 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif, 583 link_conf, true); 584 585 /* Send the beacon template */ 586 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 587 if (ret) 588 return ret; 589 590 /* the link should be already activated when assigning chan context */ 591 ret = iwl_mvm_link_changed(mvm, vif, link_conf, 592 LINK_CONTEXT_MODIFY_ALL & 593 ~LINK_CONTEXT_MODIFY_ACTIVE, 594 true); 595 if (ret) 596 return ret; 597 598 ret = iwl_mvm_mld_add_mcast_sta(mvm, vif, link_conf); 599 if (ret) 600 return ret; 601 602 /* Send the bcast station. At this stage the TBTT and DTIM time 603 * events are added and applied to the scheduler 604 */ 605 ret = iwl_mvm_mld_add_bcast_sta(mvm, vif, link_conf); 606 if (ret) 607 goto out_rm_mcast; 608 609 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) 610 goto out_failed; 611 612 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 613 if (vif->p2p && mvm->p2p_device_vif) 614 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false); 615 616 iwl_mvm_bt_coex_vif_change(mvm); 617 618 /* we don't support TDLS during DCM */ 619 if (iwl_mvm_phy_ctx_count(mvm) > 1) 620 iwl_mvm_teardown_tdls_peers(mvm); 621 622 iwl_mvm_ftm_restart_responder(mvm, vif, link_conf); 623 624 return 0; 625 626 out_failed: 627 iwl_mvm_power_update_mac(mvm); 628 mvmvif->ap_ibss_active = false; 629 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf); 630 out_rm_mcast: 631 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf); 632 return ret; 633 } 634 635 static int iwl_mvm_mld_start_ap(struct ieee80211_hw *hw, 636 struct ieee80211_vif *vif, 637 struct ieee80211_bss_conf *link_conf) 638 { 639 return iwl_mvm_mld_start_ap_ibss(hw, vif, link_conf); 640 } 641 642 static int iwl_mvm_mld_start_ibss(struct ieee80211_hw *hw, 643 struct ieee80211_vif *vif) 644 { 645 return iwl_mvm_mld_start_ap_ibss(hw, vif, &vif->bss_conf); 646 } 647 648 static void iwl_mvm_mld_stop_ap_ibss(struct ieee80211_hw *hw, 649 struct ieee80211_vif *vif, 650 struct ieee80211_bss_conf *link_conf) 651 { 652 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 653 654 guard(mvm)(mvm); 655 656 iwl_mvm_stop_ap_ibss_common(mvm, vif); 657 658 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 659 if (vif->p2p && mvm->p2p_device_vif) 660 iwl_mvm_mld_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false); 661 662 iwl_mvm_ftm_responder_clear(mvm, vif); 663 664 iwl_mvm_mld_rm_bcast_sta(mvm, vif, link_conf); 665 iwl_mvm_mld_rm_mcast_sta(mvm, vif, link_conf); 666 667 iwl_mvm_power_update_mac(mvm); 668 } 669 670 static void iwl_mvm_mld_stop_ap(struct ieee80211_hw *hw, 671 struct ieee80211_vif *vif, 672 struct ieee80211_bss_conf *link_conf) 673 { 674 iwl_mvm_mld_stop_ap_ibss(hw, vif, link_conf); 675 } 676 677 static void iwl_mvm_mld_stop_ibss(struct ieee80211_hw *hw, 678 struct ieee80211_vif *vif) 679 { 680 iwl_mvm_mld_stop_ap_ibss(hw, vif, &vif->bss_conf); 681 } 682 683 static int iwl_mvm_mld_mac_sta_state(struct ieee80211_hw *hw, 684 struct ieee80211_vif *vif, 685 struct ieee80211_sta *sta, 686 enum ieee80211_sta_state old_state, 687 enum ieee80211_sta_state new_state) 688 { 689 static const struct iwl_mvm_sta_state_ops callbacks = { 690 .add_sta = iwl_mvm_mld_add_sta, 691 .update_sta = iwl_mvm_mld_update_sta, 692 .rm_sta = iwl_mvm_mld_rm_sta, 693 .mac_ctxt_changed = iwl_mvm_mld_mac_ctxt_changed, 694 }; 695 696 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state, 697 &callbacks); 698 } 699 700 static bool iwl_mvm_esr_bw_criteria(struct iwl_mvm *mvm, 701 struct ieee80211_vif *vif, 702 struct ieee80211_bss_conf *link_conf) 703 { 704 struct ieee80211_bss_conf *other_link; 705 int link_id; 706 707 /* Exit EMLSR if links don't have equal bandwidths */ 708 for_each_vif_active_link(vif, other_link, link_id) { 709 if (link_id == link_conf->link_id) 710 continue; 711 if (link_conf->chanreq.oper.width == 712 other_link->chanreq.oper.width) 713 return true; 714 } 715 716 return false; 717 } 718 719 static void 720 iwl_mvm_mld_link_info_changed_station(struct iwl_mvm *mvm, 721 struct ieee80211_vif *vif, 722 struct ieee80211_bss_conf *link_conf, 723 u64 changes) 724 { 725 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 726 bool has_he, has_eht; 727 u32 link_changes = 0; 728 int ret; 729 730 if (WARN_ON_ONCE(!mvmvif->link[link_conf->link_id])) 731 return; 732 733 /* not yet marked active in vif means during link switch */ 734 if (!ieee80211_vif_link_active(vif, link_conf->link_id) && 735 vif->cfg.assoc && mvmvif->link[link_conf->link_id]->phy_ctxt) 736 link_changes |= LINK_CONTEXT_MODIFY_ACTIVE; 737 738 has_he = link_conf->he_support && !iwlwifi_mod_params.disable_11ax; 739 has_eht = link_conf->eht_support && !iwlwifi_mod_params.disable_11be; 740 741 /* Update EDCA params */ 742 if (changes & BSS_CHANGED_QOS && vif->cfg.assoc && link_conf->qos) 743 link_changes |= LINK_CONTEXT_MODIFY_QOS_PARAMS; 744 745 if (changes & BSS_CHANGED_ERP_SLOT) 746 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO; 747 748 if (vif->cfg.assoc && (has_he || has_eht)) { 749 IWL_DEBUG_MAC80211(mvm, "Associated in HE mode\n"); 750 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS; 751 } 752 753 if ((changes & BSS_CHANGED_BANDWIDTH) && 754 ieee80211_vif_link_active(vif, link_conf->link_id) && 755 mvmvif->esr_active && 756 !iwl_mvm_esr_bw_criteria(mvm, vif, link_conf)) 757 iwl_mvm_exit_esr(mvm, vif, 758 IWL_MVM_ESR_EXIT_BANDWIDTH, 759 iwl_mvm_get_primary_link(vif)); 760 761 /* if associated, maybe puncturing changed - we'll check later */ 762 if (vif->cfg.assoc) 763 link_changes |= LINK_CONTEXT_MODIFY_EHT_PARAMS; 764 765 if (link_changes) { 766 ret = iwl_mvm_link_changed(mvm, vif, link_conf, link_changes, 767 true); 768 if (ret) 769 IWL_ERR(mvm, "failed to update link\n"); 770 } 771 772 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 773 if (ret) 774 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 775 776 memcpy(mvmvif->link[link_conf->link_id]->bssid, link_conf->bssid, 777 ETH_ALEN); 778 779 iwl_mvm_bss_info_changed_station_common(mvm, vif, link_conf, changes); 780 } 781 782 static bool iwl_mvm_mld_vif_have_valid_ap_sta(struct iwl_mvm_vif *mvmvif) 783 { 784 int i; 785 786 for_each_mvm_vif_valid_link(mvmvif, i) { 787 if (mvmvif->link[i]->ap_sta_id != IWL_INVALID_STA) 788 return true; 789 } 790 791 return false; 792 } 793 794 static void iwl_mvm_mld_vif_cfg_changed_station(struct iwl_mvm *mvm, 795 struct ieee80211_vif *vif, 796 u64 changes) 797 { 798 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 799 struct ieee80211_bss_conf *link_conf; 800 bool protect = false; 801 unsigned int i; 802 int ret; 803 804 /* This might get called without active links during the 805 * chanctx switch, but we don't care about it anyway. 806 */ 807 if (changes == BSS_CHANGED_IDLE) 808 return; 809 810 ret = iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 811 if (ret) 812 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 813 814 mvmvif->associated = vif->cfg.assoc; 815 816 if (changes & BSS_CHANGED_ASSOC) { 817 if (vif->cfg.assoc) { 818 mvmvif->session_prot_connection_loss = false; 819 820 /* 821 * Clear statistics to get clean beacon counter, and ask for 822 * periodic statistics, as they are needed for link 823 * selection and RX OMI decisions. 824 */ 825 iwl_mvm_request_statistics(mvm, true); 826 iwl_mvm_request_periodic_system_statistics(mvm, true); 827 iwl_mvm_sf_update(mvm, vif, false); 828 iwl_mvm_power_vif_assoc(mvm, vif); 829 830 for_each_mvm_vif_valid_link(mvmvif, i) { 831 memset(&mvmvif->link[i]->beacon_stats, 0, 832 sizeof(mvmvif->link[i]->beacon_stats)); 833 834 if (vif->p2p) { 835 iwl_mvm_update_smps(mvm, vif, 836 IWL_MVM_SMPS_REQ_PROT, 837 IEEE80211_SMPS_DYNAMIC, i); 838 } 839 840 rcu_read_lock(); 841 link_conf = rcu_dereference(vif->link_conf[i]); 842 if (link_conf && !link_conf->dtim_period) 843 protect = true; 844 rcu_read_unlock(); 845 } 846 847 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 848 protect) { 849 /* We are in assoc so only one link is active- 850 * The association link 851 */ 852 unsigned int link_id = 853 ffs(vif->active_links) - 1; 854 855 /* If we're not restarting and still haven't 856 * heard a beacon (dtim period unknown) then 857 * make sure we still have enough minimum time 858 * remaining in the time event, since the auth 859 * might actually have taken quite a while 860 * (especially for SAE) and so the remaining 861 * time could be small without us having heard 862 * a beacon yet. 863 */ 864 iwl_mvm_protect_assoc(mvm, vif, 0, link_id); 865 } 866 867 iwl_mvm_sf_update(mvm, vif, false); 868 869 /* FIXME: need to decide about misbehaving AP handling */ 870 iwl_mvm_power_vif_assoc(mvm, vif); 871 } else if (iwl_mvm_mld_vif_have_valid_ap_sta(mvmvif)) { 872 iwl_mvm_mei_host_disassociated(mvm); 873 874 iwl_mvm_request_periodic_system_statistics(mvm, false); 875 876 /* If update fails - SF might be running in associated 877 * mode while disassociated - which is forbidden. 878 */ 879 ret = iwl_mvm_sf_update(mvm, vif, false); 880 WARN_ONCE(ret && 881 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 882 &mvm->status), 883 "Failed to update SF upon disassociation\n"); 884 } 885 886 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes); 887 } 888 889 if (changes & BSS_CHANGED_PS) { 890 iwl_mvm_smps_workaround(mvm, vif, false); 891 ret = iwl_mvm_power_update_mac(mvm); 892 if (ret) 893 IWL_ERR(mvm, "failed to update power mode\n"); 894 } 895 896 if (changes & (BSS_CHANGED_MLD_VALID_LINKS | BSS_CHANGED_MLD_TTLM) && 897 ieee80211_vif_is_mld(vif) && mvmvif->authorized) 898 wiphy_delayed_work_queue(mvm->hw->wiphy, 899 &mvmvif->mlo_int_scan_wk, 0); 900 } 901 902 static void 903 iwl_mvm_mld_link_info_changed_ap_ibss(struct iwl_mvm *mvm, 904 struct ieee80211_vif *vif, 905 struct ieee80211_bss_conf *link_conf, 906 u64 changes) 907 { 908 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 909 u32 link_changes = LINK_CONTEXT_MODIFY_PROTECT_FLAGS | 910 LINK_CONTEXT_MODIFY_QOS_PARAMS; 911 912 /* Changes will be applied when the AP/IBSS is started */ 913 if (!mvmvif->ap_ibss_active) 914 return; 915 916 if (link_conf->he_support) 917 link_changes |= LINK_CONTEXT_MODIFY_HE_PARAMS; 918 919 if (changes & BSS_CHANGED_ERP_SLOT) 920 link_changes |= LINK_CONTEXT_MODIFY_RATES_INFO; 921 922 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_ERP_SLOT | 923 BSS_CHANGED_HT | 924 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS | 925 BSS_CHANGED_HE_BSS_COLOR) && 926 iwl_mvm_link_changed(mvm, vif, link_conf, 927 link_changes, true)) 928 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 929 930 /* Need to send a new beacon template to the FW */ 931 if (changes & BSS_CHANGED_BEACON && 932 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf)) 933 IWL_WARN(mvm, "Failed updating beacon data\n"); 934 935 /* FIXME: need to decide if we need FTM responder per link */ 936 if (changes & BSS_CHANGED_FTM_RESPONDER) { 937 int ret = iwl_mvm_ftm_start_responder(mvm, vif, link_conf); 938 939 if (ret) 940 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 941 ret); 942 } 943 } 944 945 static void iwl_mvm_mld_link_info_changed(struct ieee80211_hw *hw, 946 struct ieee80211_vif *vif, 947 struct ieee80211_bss_conf *link_conf, 948 u64 changes) 949 { 950 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 951 952 guard(mvm)(mvm); 953 954 switch (vif->type) { 955 case NL80211_IFTYPE_STATION: 956 iwl_mvm_mld_link_info_changed_station(mvm, vif, link_conf, 957 changes); 958 break; 959 case NL80211_IFTYPE_AP: 960 case NL80211_IFTYPE_ADHOC: 961 iwl_mvm_mld_link_info_changed_ap_ibss(mvm, vif, link_conf, 962 changes); 963 break; 964 case NL80211_IFTYPE_MONITOR: 965 if (changes & BSS_CHANGED_MU_GROUPS) 966 iwl_mvm_update_mu_groups(mvm, vif); 967 break; 968 default: 969 /* shouldn't happen */ 970 WARN_ON_ONCE(1); 971 } 972 973 if (changes & BSS_CHANGED_TXPOWER) { 974 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 975 link_conf->txpower); 976 iwl_mvm_set_tx_power(mvm, link_conf, link_conf->txpower); 977 } 978 } 979 980 static void iwl_mvm_mld_vif_cfg_changed(struct ieee80211_hw *hw, 981 struct ieee80211_vif *vif, 982 u64 changes) 983 { 984 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 985 986 guard(mvm)(mvm); 987 988 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 989 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 990 991 if (vif->type == NL80211_IFTYPE_STATION) 992 iwl_mvm_mld_vif_cfg_changed_station(mvm, vif, changes); 993 } 994 995 static int 996 iwl_mvm_mld_switch_vif_chanctx(struct ieee80211_hw *hw, 997 struct ieee80211_vif_chanctx_switch *vifs, 998 int n_vifs, 999 enum ieee80211_chanctx_switch_mode mode) 1000 { 1001 static const struct iwl_mvm_switch_vif_chanctx_ops ops = { 1002 .__assign_vif_chanctx = __iwl_mvm_mld_assign_vif_chanctx, 1003 .__unassign_vif_chanctx = __iwl_mvm_mld_unassign_vif_chanctx, 1004 }; 1005 1006 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops); 1007 } 1008 1009 static void iwl_mvm_mld_config_iface_filter(struct ieee80211_hw *hw, 1010 struct ieee80211_vif *vif, 1011 unsigned int filter_flags, 1012 unsigned int changed_flags) 1013 { 1014 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1015 1016 /* We support only filter for probe requests */ 1017 if (!(changed_flags & FIF_PROBE_REQ)) 1018 return; 1019 1020 /* Supported only for p2p client interfaces */ 1021 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 1022 !vif->p2p) 1023 return; 1024 1025 guard(mvm)(mvm); 1026 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 1027 } 1028 1029 static int 1030 iwl_mvm_mld_mac_conf_tx(struct ieee80211_hw *hw, 1031 struct ieee80211_vif *vif, 1032 unsigned int link_id, u16 ac, 1033 const struct ieee80211_tx_queue_params *params) 1034 { 1035 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1036 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1037 struct iwl_mvm_vif_link_info *mvm_link = mvmvif->link[link_id]; 1038 1039 if (!mvm_link) 1040 return -EINVAL; 1041 1042 mvm_link->queue_params[ac] = *params; 1043 1044 /* No need to update right away, we'll get BSS_CHANGED_QOS 1045 * The exception is P2P_DEVICE interface which needs immediate update. 1046 */ 1047 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1048 guard(mvm)(mvm); 1049 return iwl_mvm_link_changed(mvm, vif, &vif->bss_conf, 1050 LINK_CONTEXT_MODIFY_QOS_PARAMS, 1051 true); 1052 } 1053 return 0; 1054 } 1055 1056 static int iwl_mvm_mld_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1057 { 1058 int ret; 1059 1060 lockdep_assert_held(&mvm->mutex); 1061 1062 /* The PHY context ID might have changed so need to set it */ 1063 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf, 0, false); 1064 if (WARN(ret, "Failed to set PHY context ID\n")) 1065 return ret; 1066 1067 ret = iwl_mvm_link_changed(mvm, vif, &vif->bss_conf, 1068 LINK_CONTEXT_MODIFY_ACTIVE | 1069 LINK_CONTEXT_MODIFY_RATES_INFO, 1070 true); 1071 1072 if (WARN(ret, "Failed linking P2P_DEVICE\n")) 1073 return ret; 1074 1075 /* The station and queue allocation must be done only after the linking 1076 * is done, as otherwise the FW might incorrectly configure its state. 1077 */ 1078 return iwl_mvm_mld_add_bcast_sta(mvm, vif, &vif->bss_conf); 1079 } 1080 1081 static int iwl_mvm_mld_roc(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1082 struct ieee80211_channel *channel, int duration, 1083 enum ieee80211_roc_type type) 1084 { 1085 static const struct iwl_mvm_roc_ops ops = { 1086 .add_aux_sta_for_hs20 = iwl_mvm_mld_add_aux_sta, 1087 .link = iwl_mvm_mld_roc_link, 1088 }; 1089 1090 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops); 1091 } 1092 1093 static int 1094 iwl_mvm_mld_change_vif_links(struct ieee80211_hw *hw, 1095 struct ieee80211_vif *vif, 1096 u16 old_links, u16 new_links, 1097 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS]) 1098 { 1099 struct iwl_mvm_vif_link_info *new_link[IEEE80211_MLD_MAX_NUM_LINKS] = {}; 1100 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1101 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1102 u16 removed = old_links & ~new_links; 1103 u16 added = new_links & ~old_links; 1104 int err, i; 1105 1106 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 1107 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1108 break; 1109 1110 if (!(added & BIT(i))) 1111 continue; 1112 new_link[i] = kzalloc(sizeof(*new_link[i]), GFP_KERNEL); 1113 if (!new_link[i]) { 1114 err = -ENOMEM; 1115 goto free; 1116 } 1117 1118 new_link[i]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 1119 iwl_mvm_init_link(new_link[i]); 1120 } 1121 1122 mutex_lock(&mvm->mutex); 1123 1124 /* If we're in RESTART flow, the default link wasn't added in 1125 * drv_add_interface(), and link[0] doesn't point to it. 1126 */ 1127 if (old_links == 0 && !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 1128 &mvm->status)) { 1129 err = iwl_mvm_disable_link(mvm, vif, &vif->bss_conf); 1130 if (err) 1131 goto out_err; 1132 mvmvif->link[0] = NULL; 1133 } 1134 1135 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) { 1136 if (removed & BIT(i)) { 1137 struct ieee80211_bss_conf *link_conf = old[i]; 1138 1139 err = iwl_mvm_disable_link(mvm, vif, link_conf); 1140 if (err) 1141 goto out_err; 1142 kfree(mvmvif->link[i]); 1143 mvmvif->link[i] = NULL; 1144 } else if (added & BIT(i)) { 1145 struct ieee80211_bss_conf *link_conf; 1146 1147 link_conf = link_conf_dereference_protected(vif, i); 1148 if (WARN_ON(!link_conf)) 1149 continue; 1150 1151 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 1152 &mvm->status)) 1153 mvmvif->link[i] = new_link[i]; 1154 new_link[i] = NULL; 1155 err = iwl_mvm_add_link(mvm, vif, link_conf); 1156 if (err) 1157 goto out_err; 1158 } 1159 } 1160 1161 err = 0; 1162 if (new_links == 0) { 1163 mvmvif->link[0] = &mvmvif->deflink; 1164 err = iwl_mvm_add_link(mvm, vif, &vif->bss_conf); 1165 if (err == 0) 1166 mvmvif->primary_link = 0; 1167 } else if (!(new_links & BIT(mvmvif->primary_link))) { 1168 /* 1169 * Ensure we always have a valid primary_link, the real 1170 * decision happens later when PHY is activated. 1171 */ 1172 mvmvif->primary_link = __ffs(new_links); 1173 } 1174 1175 out_err: 1176 /* we really don't have a good way to roll back here ... */ 1177 mutex_unlock(&mvm->mutex); 1178 1179 free: 1180 for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) 1181 kfree(new_link[i]); 1182 return err; 1183 } 1184 1185 static int 1186 iwl_mvm_mld_change_sta_links(struct ieee80211_hw *hw, 1187 struct ieee80211_vif *vif, 1188 struct ieee80211_sta *sta, 1189 u16 old_links, u16 new_links) 1190 { 1191 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1192 1193 guard(mvm)(mvm); 1194 return iwl_mvm_mld_update_sta_links(mvm, vif, sta, old_links, new_links); 1195 } 1196 1197 bool iwl_mvm_vif_has_esr_cap(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1198 { 1199 const struct wiphy_iftype_ext_capab *ext_capa; 1200 1201 lockdep_assert_held(&mvm->mutex); 1202 1203 if (!ieee80211_vif_is_mld(vif) || !vif->cfg.assoc || 1204 hweight16(ieee80211_vif_usable_links(vif)) == 1) 1205 return false; 1206 1207 if (!(vif->cfg.eml_cap & IEEE80211_EML_CAP_EMLSR_SUPP)) 1208 return false; 1209 1210 ext_capa = cfg80211_get_iftype_ext_capa(mvm->hw->wiphy, 1211 ieee80211_vif_type_p2p(vif)); 1212 return (ext_capa && 1213 (ext_capa->eml_capabilities & IEEE80211_EML_CAP_EMLSR_SUPP)); 1214 } 1215 1216 static bool iwl_mvm_mld_can_activate_links(struct ieee80211_hw *hw, 1217 struct ieee80211_vif *vif, 1218 u16 desired_links) 1219 { 1220 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1221 int n_links = hweight16(desired_links); 1222 1223 if (n_links <= 1) 1224 return true; 1225 1226 guard(mvm)(mvm); 1227 1228 /* Check if HW supports the wanted number of links */ 1229 if (n_links > iwl_mvm_max_active_links(mvm, vif)) 1230 return false; 1231 1232 /* If it is an eSR device, check that we can enter eSR */ 1233 return iwl_mvm_is_esr_supported(mvm->fwrt.trans) && 1234 iwl_mvm_vif_has_esr_cap(mvm, vif); 1235 } 1236 1237 static enum ieee80211_neg_ttlm_res 1238 iwl_mvm_mld_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 1239 struct ieee80211_neg_ttlm *neg_ttlm) 1240 { 1241 u16 map; 1242 u8 i; 1243 1244 /* Verify all TIDs are mapped to the same links set */ 1245 map = neg_ttlm->downlink[0]; 1246 for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { 1247 if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] || 1248 neg_ttlm->uplink[i] != map) 1249 return NEG_TTLM_RES_REJECT; 1250 } 1251 1252 return NEG_TTLM_RES_ACCEPT; 1253 } 1254 1255 static int 1256 iwl_mvm_mld_mac_pre_channel_switch(struct ieee80211_hw *hw, 1257 struct ieee80211_vif *vif, 1258 struct ieee80211_channel_switch *chsw) 1259 { 1260 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1262 int ret; 1263 1264 mutex_lock(&mvm->mutex); 1265 if (mvmvif->esr_active) { 1266 u8 primary = iwl_mvm_get_primary_link(vif); 1267 int selected; 1268 1269 /* prefer primary unless quiet CSA on it */ 1270 if (chsw->link_id == primary && chsw->block_tx) 1271 selected = iwl_mvm_get_other_link(vif, primary); 1272 else 1273 selected = primary; 1274 1275 /* 1276 * remembers to tell the firmware that this link can't tx 1277 * Note that this logic seems to be unrelated to esr, but it 1278 * really is needed only when esr is active. When we have a 1279 * single link, the firmware will handle all this on its own. 1280 * In multi-link scenarios, we can learn about the CSA from 1281 * another link and this logic is too complex for the firmware 1282 * to track. 1283 * Since we want to de-activate the link that got a CSA, we 1284 * need to tell the firmware not to send any frame on that link 1285 * as the firmware may not be aware that link is under a CSA 1286 * with mode=1 (no Tx allowed). 1287 */ 1288 if (chsw->block_tx && mvmvif->link[chsw->link_id]) 1289 mvmvif->link[chsw->link_id]->csa_block_tx = true; 1290 1291 iwl_mvm_exit_esr(mvm, vif, IWL_MVM_ESR_EXIT_CSA, selected); 1292 mutex_unlock(&mvm->mutex); 1293 1294 /* 1295 * If we've not kept the link active that's doing the CSA 1296 * then we don't need to do anything else, just return. 1297 */ 1298 if (selected != chsw->link_id) 1299 return 0; 1300 1301 mutex_lock(&mvm->mutex); 1302 } 1303 1304 ret = iwl_mvm_pre_channel_switch(mvm, vif, chsw); 1305 mutex_unlock(&mvm->mutex); 1306 1307 return ret; 1308 } 1309 1310 #define IWL_MVM_MLD_UNBLOCK_ESR_NON_BSS_TIMEOUT (5 * HZ) 1311 1312 static void iwl_mvm_mld_prep_add_interface(struct ieee80211_hw *hw, 1313 enum nl80211_iftype type) 1314 { 1315 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1316 struct ieee80211_vif *bss_vif = iwl_mvm_get_bss_vif(mvm); 1317 struct iwl_mvm_vif *mvmvif; 1318 int ret; 1319 1320 IWL_DEBUG_MAC80211(mvm, "prep_add_interface: type=%u\n", 1321 type); 1322 1323 if (IS_ERR_OR_NULL(bss_vif) || 1324 !(type == NL80211_IFTYPE_AP || 1325 type == NL80211_IFTYPE_P2P_GO || 1326 type == NL80211_IFTYPE_P2P_CLIENT)) 1327 return; 1328 1329 mvmvif = iwl_mvm_vif_from_mac80211(bss_vif); 1330 ret = iwl_mvm_block_esr_sync(mvm, bss_vif, 1331 IWL_MVM_ESR_BLOCKED_TMP_NON_BSS); 1332 if (ret) 1333 return; 1334 1335 wiphy_delayed_work_queue(mvmvif->mvm->hw->wiphy, 1336 &mvmvif->unblock_esr_tmp_non_bss_wk, 1337 IWL_MVM_MLD_UNBLOCK_ESR_NON_BSS_TIMEOUT); 1338 } 1339 1340 const struct ieee80211_ops iwl_mvm_mld_hw_ops = { 1341 .tx = iwl_mvm_mac_tx, 1342 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 1343 .ampdu_action = iwl_mvm_mac_ampdu_action, 1344 .get_antenna = iwl_mvm_op_get_antenna, 1345 .set_antenna = iwl_mvm_op_set_antenna, 1346 .start = iwl_mvm_mac_start, 1347 .reconfig_complete = iwl_mvm_mac_reconfig_complete, 1348 .stop = iwl_mvm_mac_stop, 1349 .add_interface = iwl_mvm_mld_mac_add_interface, 1350 .remove_interface = iwl_mvm_mld_mac_remove_interface, 1351 .config = iwl_mvm_mac_config, 1352 .prepare_multicast = iwl_mvm_prepare_multicast, 1353 .configure_filter = iwl_mvm_configure_filter, 1354 .config_iface_filter = iwl_mvm_mld_config_iface_filter, 1355 .link_info_changed = iwl_mvm_mld_link_info_changed, 1356 .vif_cfg_changed = iwl_mvm_mld_vif_cfg_changed, 1357 .hw_scan = iwl_mvm_mac_hw_scan, 1358 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 1359 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 1360 .sta_state = iwl_mvm_mld_mac_sta_state, 1361 .sta_notify = iwl_mvm_mac_sta_notify, 1362 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 1363 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 1364 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 1365 .link_sta_rc_update = iwl_mvm_sta_rc_update, 1366 .conf_tx = iwl_mvm_mld_mac_conf_tx, 1367 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 1368 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 1369 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 1370 .flush = iwl_mvm_mac_flush, 1371 .flush_sta = iwl_mvm_mac_flush_sta, 1372 .sched_scan_start = iwl_mvm_mac_sched_scan_start, 1373 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 1374 .set_key = iwl_mvm_mac_set_key, 1375 .update_tkip_key = iwl_mvm_mac_update_tkip_key, 1376 .remain_on_channel = iwl_mvm_mld_roc, 1377 .cancel_remain_on_channel = iwl_mvm_cancel_roc, 1378 .add_chanctx = iwl_mvm_add_chanctx, 1379 .remove_chanctx = iwl_mvm_remove_chanctx, 1380 .change_chanctx = iwl_mvm_change_chanctx, 1381 .assign_vif_chanctx = iwl_mvm_mld_assign_vif_chanctx, 1382 .unassign_vif_chanctx = iwl_mvm_mld_unassign_vif_chanctx, 1383 .switch_vif_chanctx = iwl_mvm_mld_switch_vif_chanctx, 1384 1385 .start_ap = iwl_mvm_mld_start_ap, 1386 .stop_ap = iwl_mvm_mld_stop_ap, 1387 .join_ibss = iwl_mvm_mld_start_ibss, 1388 .leave_ibss = iwl_mvm_mld_stop_ibss, 1389 1390 .tx_last_beacon = iwl_mvm_tx_last_beacon, 1391 1392 .channel_switch = iwl_mvm_channel_switch, 1393 .pre_channel_switch = iwl_mvm_mld_mac_pre_channel_switch, 1394 .post_channel_switch = iwl_mvm_post_channel_switch, 1395 .abort_channel_switch = iwl_mvm_abort_channel_switch, 1396 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 1397 1398 .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 1399 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 1400 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 1401 1402 .event_callback = iwl_mvm_mac_event_callback, 1403 1404 .sync_rx_queues = iwl_mvm_sync_rx_queues, 1405 1406 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 1407 1408 #ifdef CONFIG_PM_SLEEP 1409 /* look at d3.c */ 1410 .suspend = iwl_mvm_suspend, 1411 .resume = iwl_mvm_resume, 1412 .set_wakeup = iwl_mvm_set_wakeup, 1413 .set_rekey_data = iwl_mvm_set_rekey_data, 1414 #if IS_ENABLED(CONFIG_IPV6) 1415 .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 1416 #endif 1417 .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 1418 #endif 1419 .get_survey = iwl_mvm_mac_get_survey, 1420 .sta_statistics = iwl_mvm_mac_sta_statistics, 1421 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 1422 .start_pmsr = iwl_mvm_start_pmsr, 1423 .abort_pmsr = iwl_mvm_abort_pmsr, 1424 1425 #ifdef CONFIG_IWLWIFI_DEBUGFS 1426 .vif_add_debugfs = iwl_mvm_vif_add_debugfs, 1427 .link_add_debugfs = iwl_mvm_link_add_debugfs, 1428 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs, 1429 #endif 1430 .set_hw_timestamp = iwl_mvm_set_hw_timestamp, 1431 1432 .change_vif_links = iwl_mvm_mld_change_vif_links, 1433 .change_sta_links = iwl_mvm_mld_change_sta_links, 1434 .can_activate_links = iwl_mvm_mld_can_activate_links, 1435 .can_neg_ttlm = iwl_mvm_mld_can_neg_ttlm, 1436 .prep_add_interface = iwl_mvm_mld_prep_add_interface, 1437 }; 1438