1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2012-2014, 2018-2024 Intel Corporation 4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 5 * Copyright (C) 2016-2017 Intel Deutschland GmbH 6 */ 7 #include <linux/kernel.h> 8 #include <linux/slab.h> 9 #include <linux/skbuff.h> 10 #include <linux/netdevice.h> 11 #include <linux/etherdevice.h> 12 #include <linux/ip.h> 13 #include <linux/if_arp.h> 14 #include <linux/time.h> 15 #include <net/mac80211.h> 16 #include <net/ieee80211_radiotap.h> 17 #include <net/tcp.h> 18 19 #include "iwl-drv.h" 20 #include "iwl-op-mode.h" 21 #include "iwl-io.h" 22 #include "mvm.h" 23 #include "sta.h" 24 #include "time-event.h" 25 #include "iwl-nvm-utils.h" 26 #include "iwl-phy-db.h" 27 #include "testmode.h" 28 #include "fw/error-dump.h" 29 #include "iwl-prph.h" 30 #include "iwl-nvm-parse.h" 31 #include "time-sync.h" 32 33 static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 34 { 35 .max = 1, 36 .types = BIT(NL80211_IFTYPE_STATION), 37 }, 38 { 39 .max = 1, 40 .types = BIT(NL80211_IFTYPE_AP) | 41 BIT(NL80211_IFTYPE_P2P_CLIENT) | 42 BIT(NL80211_IFTYPE_P2P_GO), 43 }, 44 { 45 .max = 1, 46 .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 47 }, 48 }; 49 50 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 51 { 52 .num_different_channels = 2, 53 .max_interfaces = 3, 54 .limits = iwl_mvm_limits, 55 .n_limits = ARRAY_SIZE(iwl_mvm_limits), 56 }, 57 }; 58 59 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { 60 .max_peers = IWL_MVM_TOF_MAX_APS, 61 .report_ap_tsf = 1, 62 .randomize_mac_addr = 1, 63 64 .ftm = { 65 .supported = 1, 66 .asap = 1, 67 .non_asap = 1, 68 .request_lci = 1, 69 .request_civicloc = 1, 70 .trigger_based = 1, 71 .non_trigger_based = 1, 72 .max_bursts_exponent = -1, /* all supported */ 73 .max_ftms_per_burst = 0, /* no limits */ 74 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 75 BIT(NL80211_CHAN_WIDTH_20) | 76 BIT(NL80211_CHAN_WIDTH_40) | 77 BIT(NL80211_CHAN_WIDTH_80) | 78 BIT(NL80211_CHAN_WIDTH_160), 79 .preambles = BIT(NL80211_PREAMBLE_LEGACY) | 80 BIT(NL80211_PREAMBLE_HT) | 81 BIT(NL80211_PREAMBLE_VHT) | 82 BIT(NL80211_PREAMBLE_HE), 83 }, 84 }; 85 86 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 87 enum set_key_cmd cmd, 88 struct ieee80211_vif *vif, 89 struct ieee80211_sta *sta, 90 struct ieee80211_key_conf *key); 91 92 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 93 { 94 int i; 95 96 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 97 for (i = 0; i < NUM_PHY_CTX; i++) { 98 mvm->phy_ctxts[i].id = i; 99 mvm->phy_ctxts[i].ref = 0; 100 } 101 } 102 103 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 104 const char *alpha2, 105 enum iwl_mcc_source src_id, 106 bool *changed) 107 { 108 struct ieee80211_regdomain *regd = NULL; 109 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 111 struct iwl_mcc_update_resp_v8 *resp; 112 u8 resp_ver; 113 114 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 115 116 lockdep_assert_held(&mvm->mutex); 117 118 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 119 if (IS_ERR_OR_NULL(resp)) { 120 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 121 PTR_ERR_OR_ZERO(resp)); 122 resp = NULL; 123 goto out; 124 } 125 126 if (changed) { 127 u32 status = le32_to_cpu(resp->status); 128 129 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || 130 status == MCC_RESP_ILLEGAL); 131 } 132 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, 133 MCC_UPDATE_CMD, 0); 134 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver); 135 136 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 137 __le32_to_cpu(resp->n_channels), 138 resp->channels, 139 __le16_to_cpu(resp->mcc), 140 __le16_to_cpu(resp->geo_info), 141 le32_to_cpu(resp->cap), resp_ver, 142 mvm->fwrt.uats_enabled); 143 /* Store the return source id */ 144 src_id = resp->source_id; 145 if (IS_ERR_OR_NULL(regd)) { 146 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 147 PTR_ERR_OR_ZERO(regd)); 148 goto out; 149 } 150 151 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 152 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 153 mvm->lar_regdom_set = true; 154 mvm->mcc_src = src_id; 155 156 /* Some kind of regulatory mess means we need to currently disallow 157 * puncturing in the US and Canada. Do that here, at least until we 158 * figure out the new chanctx APIs for puncturing. 159 */ 160 if (resp->mcc == cpu_to_le16(IWL_MCC_US) || 161 resp->mcc == cpu_to_le16(IWL_MCC_CANADA)) 162 ieee80211_hw_set(mvm->hw, DISALLOW_PUNCTURING); 163 else 164 __clear_bit(IEEE80211_HW_DISALLOW_PUNCTURING, mvm->hw->flags); 165 166 iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); 167 168 out: 169 kfree(resp); 170 return regd; 171 } 172 173 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 174 { 175 bool changed; 176 struct ieee80211_regdomain *regd; 177 178 if (!iwl_mvm_is_lar_supported(mvm)) 179 return; 180 181 regd = iwl_mvm_get_current_regdomain(mvm, &changed); 182 if (!IS_ERR_OR_NULL(regd)) { 183 /* only update the regulatory core if changed */ 184 if (changed) 185 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 186 187 kfree(regd); 188 } 189 } 190 191 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 192 bool *changed) 193 { 194 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 195 iwl_mvm_is_wifi_mcc_supported(mvm) ? 196 MCC_SOURCE_GET_CURRENT : 197 MCC_SOURCE_OLD_FW, changed); 198 } 199 200 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm, bool force_regd_sync) 201 { 202 enum iwl_mcc_source used_src; 203 struct ieee80211_regdomain *regd; 204 int ret; 205 bool changed; 206 const struct ieee80211_regdomain *r = 207 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); 208 209 if (!r) 210 return -ENOENT; 211 212 /* save the last source in case we overwrite it below */ 213 used_src = mvm->mcc_src; 214 if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 215 /* Notify the firmware we support wifi location updates */ 216 regd = iwl_mvm_get_current_regdomain(mvm, NULL); 217 if (!IS_ERR_OR_NULL(regd)) 218 kfree(regd); 219 } 220 221 /* Now set our last stored MCC and source */ 222 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 223 &changed); 224 if (IS_ERR_OR_NULL(regd)) 225 return -EIO; 226 227 /* update cfg80211 if the regdomain was changed or the caller explicitly 228 * asked to update regdomain 229 */ 230 if (changed || force_regd_sync) 231 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); 232 else 233 ret = 0; 234 235 kfree(regd); 236 return ret; 237 } 238 239 /* Each capability added here should also be add to tm_if_types_ext_capa_sta */ 240 static const u8 he_if_types_ext_capa_sta[] = { 241 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 242 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 243 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | 244 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, 245 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, 246 }; 247 248 static const u8 tm_if_types_ext_capa_sta[] = { 249 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 250 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT | 251 WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT, 252 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | 253 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, 254 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, 255 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, 256 }; 257 258 /* Additional interface types for which extended capabilities are 259 * specified separately 260 */ 261 262 #define IWL_MVM_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \ 263 IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \ 264 __bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \ 265 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \ 266 __bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY)) 267 #define IWL_MVM_MLD_CAPA_OPS FIELD_PREP_CONST( \ 268 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \ 269 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) 270 271 static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = { 272 { 273 .iftype = NL80211_IFTYPE_STATION, 274 .extended_capabilities = he_if_types_ext_capa_sta, 275 .extended_capabilities_mask = he_if_types_ext_capa_sta, 276 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), 277 /* relevant only if EHT is supported */ 278 .eml_capabilities = IWL_MVM_EMLSR_CAPA, 279 .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS, 280 }, 281 { 282 .iftype = NL80211_IFTYPE_STATION, 283 .extended_capabilities = tm_if_types_ext_capa_sta, 284 .extended_capabilities_mask = tm_if_types_ext_capa_sta, 285 .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta), 286 /* relevant only if EHT is supported */ 287 .eml_capabilities = IWL_MVM_EMLSR_CAPA, 288 .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS, 289 }, 290 }; 291 292 int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 293 { 294 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 295 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); 296 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); 297 return 0; 298 } 299 300 int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 301 { 302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 303 304 /* This has been tested on those devices only */ 305 if (mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_9000 && 306 mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_22000) 307 return -EOPNOTSUPP; 308 309 if (!mvm->nvm_data) 310 return -EBUSY; 311 312 /* mac80211 ensures the device is not started, 313 * so the firmware cannot be running 314 */ 315 316 mvm->set_tx_ant = tx_ant; 317 mvm->set_rx_ant = rx_ant; 318 319 iwl_reinit_cab(mvm->trans, mvm->nvm_data, tx_ant, rx_ant, mvm->fw); 320 321 return 0; 322 } 323 324 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 325 { 326 struct ieee80211_hw *hw = mvm->hw; 327 int num_mac, ret, i; 328 static const u32 mvm_ciphers[] = { 329 WLAN_CIPHER_SUITE_WEP40, 330 WLAN_CIPHER_SUITE_WEP104, 331 WLAN_CIPHER_SUITE_TKIP, 332 WLAN_CIPHER_SUITE_CCMP, 333 }; 334 #ifdef CONFIG_PM_SLEEP 335 bool unified = fw_has_capa(&mvm->fw->ucode_capa, 336 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); 337 #endif 338 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 339 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 340 341 /* Tell mac80211 our characteristics */ 342 ieee80211_hw_set(hw, SIGNAL_DBM); 343 ieee80211_hw_set(hw, SPECTRUM_MGMT); 344 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 345 ieee80211_hw_set(hw, WANT_MONITOR_VIF); 346 ieee80211_hw_set(hw, SUPPORTS_PS); 347 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 348 ieee80211_hw_set(hw, AMPDU_AGGREGATION); 349 ieee80211_hw_set(hw, CONNECTION_MONITOR); 350 ieee80211_hw_set(hw, CHANCTX_STA_CSA); 351 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 352 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 353 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 354 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 355 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 356 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); 357 ieee80211_hw_set(hw, STA_MMPDU_TXQ); 358 359 /* Set this early since we need to have it for the check below */ 360 if (mvm->mld_api_is_used && mvm->nvm_data->sku_cap_11be_enable && 361 !iwlwifi_mod_params.disable_11ax && 362 !iwlwifi_mod_params.disable_11be) { 363 hw->wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT; 364 /* we handle this already earlier, but need it for MLO */ 365 ieee80211_hw_set(hw, HANDLES_QUIET_CSA); 366 } 367 368 /* With MLD FW API, it tracks timing by itself, 369 * no need for any timing from the host 370 */ 371 if (!mvm->mld_api_is_used) 372 ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 373 374 /* We should probably have this, but mac80211 375 * currently doesn't support it for MLO. 376 */ 377 if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) 378 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 379 380 /* 381 * On older devices, enabling TX A-MSDU occasionally leads to 382 * something getting messed up, the command read from the FIFO 383 * gets out of sync and isn't a TX command, so that we have an 384 * assert EDC. 385 * 386 * It's not clear where the bug is, but since we didn't used to 387 * support A-MSDU until moving the mac80211 iTXQs, just leave it 388 * for older devices. We also don't see this issue on any newer 389 * devices. 390 */ 391 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) 392 ieee80211_hw_set(hw, TX_AMSDU); 393 ieee80211_hw_set(hw, TX_FRAG_LIST); 394 395 if (iwl_mvm_has_tlc_offload(mvm)) { 396 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 397 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 398 } 399 400 /* We want to use the mac80211's reorder buffer for 9000 */ 401 if (iwl_mvm_has_new_rx_api(mvm) && 402 mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_9000) 403 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 404 405 if (fw_has_capa(&mvm->fw->ucode_capa, 406 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 407 ieee80211_hw_set(hw, AP_LINK_PS); 408 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 409 /* 410 * we absolutely need this for the new TX API since that comes 411 * with many more queues than the current code can deal with 412 * for station powersave 413 */ 414 return -EINVAL; 415 } 416 417 if (mvm->trans->num_rx_queues > 1) 418 ieee80211_hw_set(hw, USES_RSS); 419 420 if (mvm->trans->max_skb_frags) 421 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 422 423 hw->queues = IEEE80211_NUM_ACS; 424 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 425 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 426 IEEE80211_RADIOTAP_MCS_HAVE_STBC; 427 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 428 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 429 430 hw->radiotap_timestamp.units_pos = 431 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 432 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 433 /* this is the case for CCK frames, it's better (only 8) for OFDM */ 434 hw->radiotap_timestamp.accuracy = 22; 435 436 if (!iwl_mvm_has_tlc_offload(mvm)) 437 hw->rate_control_algorithm = RS_NAME; 438 439 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 440 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 441 hw->max_tx_fragments = mvm->trans->max_skb_frags; 442 443 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 444 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 445 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 446 hw->wiphy->cipher_suites = mvm->ciphers; 447 448 if (iwl_mvm_has_new_rx_api(mvm)) { 449 mvm->ciphers[hw->wiphy->n_cipher_suites] = 450 WLAN_CIPHER_SUITE_GCMP; 451 hw->wiphy->n_cipher_suites++; 452 mvm->ciphers[hw->wiphy->n_cipher_suites] = 453 WLAN_CIPHER_SUITE_GCMP_256; 454 hw->wiphy->n_cipher_suites++; 455 } 456 457 if (iwlwifi_mod_params.swcrypto) 458 IWL_ERR(mvm, 459 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); 460 if (!iwlwifi_mod_params.bt_coex_active) 461 IWL_ERR(mvm, 462 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); 463 464 ieee80211_hw_set(hw, MFP_CAPABLE); 465 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; 466 hw->wiphy->n_cipher_suites++; 467 if (iwl_mvm_has_new_rx_api(mvm)) { 468 mvm->ciphers[hw->wiphy->n_cipher_suites] = 469 WLAN_CIPHER_SUITE_BIP_GMAC_128; 470 hw->wiphy->n_cipher_suites++; 471 mvm->ciphers[hw->wiphy->n_cipher_suites] = 472 WLAN_CIPHER_SUITE_BIP_GMAC_256; 473 hw->wiphy->n_cipher_suites++; 474 } 475 476 wiphy_ext_feature_set(hw->wiphy, 477 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); 478 wiphy_ext_feature_set(hw->wiphy, 479 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT); 480 481 if (fw_has_capa(&mvm->fw->ucode_capa, 482 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { 483 wiphy_ext_feature_set(hw->wiphy, 484 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); 485 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; 486 } 487 488 if (sec_key_ver && 489 fw_has_capa(&mvm->fw->ucode_capa, 490 IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT)) 491 wiphy_ext_feature_set(hw->wiphy, 492 NL80211_EXT_FEATURE_BEACON_PROTECTION); 493 else if (fw_has_capa(&mvm->fw->ucode_capa, 494 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) 495 wiphy_ext_feature_set(hw->wiphy, 496 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); 497 498 if (fw_has_capa(&mvm->fw->ucode_capa, 499 IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM)) 500 hw->wiphy->hw_timestamp_max_peers = 1; 501 502 if (fw_has_capa(&mvm->fw->ucode_capa, 503 IWL_UCODE_TLV_CAPA_SPP_AMSDU_SUPPORT)) 504 wiphy_ext_feature_set(hw->wiphy, 505 NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT); 506 507 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 508 hw->wiphy->features |= 509 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 510 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 511 NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 512 513 hw->sta_data_size = sizeof(struct iwl_mvm_sta); 514 hw->vif_data_size = sizeof(struct iwl_mvm_vif); 515 hw->chanctx_data_size = sizeof(u16); 516 hw->txq_data_size = sizeof(struct iwl_mvm_txq); 517 518 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 519 BIT(NL80211_IFTYPE_P2P_CLIENT) | 520 BIT(NL80211_IFTYPE_AP) | 521 BIT(NL80211_IFTYPE_P2P_GO) | 522 BIT(NL80211_IFTYPE_P2P_DEVICE) | 523 BIT(NL80211_IFTYPE_ADHOC); 524 525 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 526 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 527 528 /* The new Tx API does not allow to pass the key or keyid of a MPDU to 529 * the hw, preventing us to control which key(id) to use per MPDU. 530 * Till that's fixed we can't use Extended Key ID for the newer cards. 531 */ 532 if (!iwl_mvm_has_new_tx_api(mvm)) 533 wiphy_ext_feature_set(hw->wiphy, 534 NL80211_EXT_FEATURE_EXT_KEY_ID); 535 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; 536 537 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 538 if (iwl_mvm_is_lar_supported(mvm)) 539 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 540 else 541 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 542 REGULATORY_DISABLE_BEACON_HINTS; 543 544 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 545 wiphy_ext_feature_set(hw->wiphy, 546 NL80211_EXT_FEATURE_DFS_CONCURRENT); 547 548 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 549 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 550 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; 551 552 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 553 hw->wiphy->n_iface_combinations = 554 ARRAY_SIZE(iwl_mvm_iface_combinations); 555 556 hw->wiphy->max_remain_on_channel_duration = 10000; 557 hw->max_listen_interval = IWL_MVM_CONN_LISTEN_INTERVAL; 558 559 /* Extract MAC address */ 560 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 561 hw->wiphy->addresses = mvm->addresses; 562 hw->wiphy->n_addresses = 1; 563 564 /* Extract additional MAC addresses if available */ 565 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 566 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 567 568 for (i = 1; i < num_mac; i++) { 569 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 570 ETH_ALEN); 571 mvm->addresses[i].addr[5]++; 572 hw->wiphy->n_addresses++; 573 } 574 575 iwl_mvm_reset_phy_ctxts(mvm); 576 577 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 578 579 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 580 581 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 582 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 583 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 584 585 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 586 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 587 else 588 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 589 590 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 591 hw->wiphy->bands[NL80211_BAND_2GHZ] = 592 &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 593 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 594 hw->wiphy->bands[NL80211_BAND_5GHZ] = 595 &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 596 597 if (fw_has_capa(&mvm->fw->ucode_capa, 598 IWL_UCODE_TLV_CAPA_BEAMFORMER) && 599 fw_has_api(&mvm->fw->ucode_capa, 600 IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 601 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 602 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 603 } 604 if (fw_has_capa(&mvm->fw->ucode_capa, 605 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && 606 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) 607 hw->wiphy->bands[NL80211_BAND_6GHZ] = 608 &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; 609 610 hw->wiphy->hw_version = mvm->trans->hw_id; 611 612 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 613 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 614 else 615 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 616 617 hw->wiphy->max_sched_scan_reqs = 1; 618 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 619 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); 620 /* we create the 802.11 header and zero length SSID IE. */ 621 hw->wiphy->max_sched_scan_ie_len = 622 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 623 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 624 hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 625 626 /* 627 * the firmware uses u8 for num of iterations, but 0xff is saved for 628 * infinite loop, so the maximum number of iterations is actually 254. 629 */ 630 hw->wiphy->max_sched_scan_plan_iterations = 254; 631 632 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 633 NL80211_FEATURE_LOW_PRIORITY_SCAN | 634 NL80211_FEATURE_P2P_GO_OPPPS | 635 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 636 NL80211_FEATURE_DYNAMIC_SMPS | 637 NL80211_FEATURE_STATIC_SMPS | 638 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 639 640 if (fw_has_capa(&mvm->fw->ucode_capa, 641 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 642 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 643 if (fw_has_capa(&mvm->fw->ucode_capa, 644 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 645 hw->wiphy->features |= NL80211_FEATURE_QUIET; 646 647 if (fw_has_capa(&mvm->fw->ucode_capa, 648 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 649 hw->wiphy->features |= 650 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 651 652 if (fw_has_capa(&mvm->fw->ucode_capa, 653 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 654 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 655 656 if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL, 657 IWL_FW_CMD_VER_UNKNOWN) == 3) 658 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; 659 660 if (fw_has_api(&mvm->fw->ucode_capa, 661 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 662 wiphy_ext_feature_set(hw->wiphy, 663 NL80211_EXT_FEATURE_SCAN_START_TIME); 664 wiphy_ext_feature_set(hw->wiphy, 665 NL80211_EXT_FEATURE_BSS_PARENT_TSF); 666 } 667 668 if (iwl_mvm_is_oce_supported(mvm)) { 669 u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0); 670 671 wiphy_ext_feature_set(hw->wiphy, 672 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 673 wiphy_ext_feature_set(hw->wiphy, 674 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 675 wiphy_ext_feature_set(hw->wiphy, 676 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 677 678 /* Old firmware also supports probe deferral and suppression */ 679 if (scan_ver < 15) 680 wiphy_ext_feature_set(hw->wiphy, 681 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 682 } 683 684 hw->wiphy->iftype_ext_capab = NULL; 685 hw->wiphy->num_iftype_ext_capab = 0; 686 687 if (mvm->nvm_data->sku_cap_11ax_enable && 688 !iwlwifi_mod_params.disable_11ax) { 689 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa; 690 hw->wiphy->num_iftype_ext_capab = 691 ARRAY_SIZE(add_iftypes_ext_capa) - 1; 692 693 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 694 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 695 } 696 697 if (iwl_fw_lookup_cmd_ver(mvm->fw, 698 WIDE_ID(DATA_PATH_GROUP, 699 WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD), 700 IWL_FW_CMD_VER_UNKNOWN) >= 1) { 701 IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n"); 702 703 if (!hw->wiphy->iftype_ext_capab) { 704 hw->wiphy->num_iftype_ext_capab = 1; 705 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 706 ARRAY_SIZE(add_iftypes_ext_capa) - 1; 707 } else { 708 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1; 709 } 710 } 711 712 if (iwl_fw_lookup_cmd_ver(mvm->fw, WIDE_ID(LOCATION_GROUP, 713 TOF_RANGE_REQ_CMD), 714 IWL_FW_CMD_VER_UNKNOWN) >= 11) { 715 wiphy_ext_feature_set(hw->wiphy, 716 NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE); 717 718 if (fw_has_capa(&mvm->fw->ucode_capa, 719 IWL_UCODE_TLV_CAPA_SECURE_LTF_SUPPORT)) 720 wiphy_ext_feature_set(hw->wiphy, 721 NL80211_EXT_FEATURE_SECURE_LTF); 722 } 723 724 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 725 726 ieee80211_hw_set(hw, DISALLOW_PUNCTURING_5GHZ); 727 728 #ifdef CONFIG_PM_SLEEP 729 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 730 mvm->trans->ops->d3_suspend && 731 mvm->trans->ops->d3_resume && 732 device_can_wakeup(mvm->trans->dev)) { 733 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 734 WIPHY_WOWLAN_DISCONNECT | 735 WIPHY_WOWLAN_EAP_IDENTITY_REQ | 736 WIPHY_WOWLAN_RFKILL_RELEASE | 737 WIPHY_WOWLAN_NET_DETECT; 738 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 739 WIPHY_WOWLAN_GTK_REKEY_FAILURE | 740 WIPHY_WOWLAN_4WAY_HANDSHAKE; 741 742 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 743 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 744 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 745 mvm->wowlan.max_nd_match_sets = 746 iwl_umac_scan_get_max_profiles(mvm->fw); 747 hw->wiphy->wowlan = &mvm->wowlan; 748 } 749 #endif 750 751 ret = iwl_mvm_leds_init(mvm); 752 if (ret) 753 return ret; 754 755 if (fw_has_capa(&mvm->fw->ucode_capa, 756 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 757 IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 758 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 759 ieee80211_hw_set(hw, TDLS_WIDER_BW); 760 } 761 762 if (fw_has_capa(&mvm->fw->ucode_capa, 763 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 764 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 765 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 766 } 767 768 hw->netdev_features |= mvm->cfg->features; 769 if (!iwl_mvm_is_csum_supported(mvm)) 770 hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; 771 772 if (mvm->cfg->vht_mu_mimo_supported) 773 wiphy_ext_feature_set(hw->wiphy, 774 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 775 776 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 777 wiphy_ext_feature_set(hw->wiphy, 778 NL80211_EXT_FEATURE_PROTECTED_TWT); 779 780 iwl_mvm_vendor_cmds_register(mvm); 781 782 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 783 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 784 785 ret = ieee80211_register_hw(mvm->hw); 786 if (ret) { 787 iwl_mvm_leds_exit(mvm); 788 } 789 790 return ret; 791 } 792 793 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 794 struct ieee80211_sta *sta) 795 { 796 if (likely(sta)) { 797 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 798 return; 799 } else { 800 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 801 return; 802 } 803 804 ieee80211_free_txskb(mvm->hw, skb); 805 } 806 807 void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 808 struct ieee80211_tx_control *control, struct sk_buff *skb) 809 { 810 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 811 struct ieee80211_sta *sta = control->sta; 812 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 813 struct ieee80211_hdr *hdr = (void *)skb->data; 814 bool offchannel = IEEE80211_SKB_CB(skb)->flags & 815 IEEE80211_TX_CTL_TX_OFFCHAN; 816 u32 link_id = u32_get_bits(info->control.flags, 817 IEEE80211_TX_CTRL_MLO_LINK); 818 struct ieee80211_sta *tmp_sta = sta; 819 820 if (iwl_mvm_is_radio_killed(mvm)) { 821 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 822 goto drop; 823 } 824 825 if (offchannel && 826 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 827 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 828 goto drop; 829 830 /* 831 * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 832 * so we treat the others as broadcast 833 */ 834 if (ieee80211_is_mgmt(hdr->frame_control)) 835 sta = NULL; 836 837 /* If there is no sta, and it's not offchannel - send through AP */ 838 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 839 !offchannel) { 840 struct iwl_mvm_vif *mvmvif = 841 iwl_mvm_vif_from_mac80211(info->control.vif); 842 u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id); 843 844 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 845 /* mac80211 holds rcu read lock */ 846 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 847 if (IS_ERR_OR_NULL(sta)) 848 goto drop; 849 } 850 } 851 852 if (tmp_sta && !sta && link_id != IEEE80211_LINK_UNSPECIFIED && 853 !ieee80211_is_probe_resp(hdr->frame_control)) { 854 /* translate MLD addresses to LINK addresses */ 855 struct ieee80211_link_sta *link_sta = 856 rcu_dereference(tmp_sta->link[link_id]); 857 struct ieee80211_bss_conf *link_conf = 858 rcu_dereference(info->control.vif->link_conf[link_id]); 859 struct ieee80211_mgmt *mgmt; 860 861 if (WARN_ON(!link_sta || !link_conf)) 862 goto drop; 863 864 /* if sta is NULL, the frame is a management frame */ 865 mgmt = (void *)hdr; 866 memcpy(mgmt->da, link_sta->addr, ETH_ALEN); 867 memcpy(mgmt->sa, link_conf->addr, ETH_ALEN); 868 memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN); 869 } 870 871 iwl_mvm_tx_skb(mvm, skb, sta); 872 return; 873 drop: 874 ieee80211_free_txskb(hw, skb); 875 } 876 877 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 878 { 879 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 880 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 881 struct sk_buff *skb = NULL; 882 883 /* 884 * No need for threads to be pending here, they can leave the first 885 * taker all the work. 886 * 887 * mvmtxq->tx_request logic: 888 * 889 * If 0, no one is currently TXing, set to 1 to indicate current thread 890 * will now start TX and other threads should quit. 891 * 892 * If 1, another thread is currently TXing, set to 2 to indicate to 893 * that thread that there was another request. Since that request may 894 * have raced with the check whether the queue is empty, the TXing 895 * thread should check the queue's status one more time before leaving. 896 * This check is done in order to not leave any TX hanging in the queue 897 * until the next TX invocation (which may not even happen). 898 * 899 * If 2, another thread is currently TXing, and it will already double 900 * check the queue, so do nothing. 901 */ 902 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 903 return; 904 905 rcu_read_lock(); 906 do { 907 while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL, 908 &mvmtxq->state) && 909 !test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT, 910 &mvmtxq->state) && 911 !test_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, 912 &mvmtxq->state) && 913 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 914 skb = ieee80211_tx_dequeue(hw, txq); 915 916 if (!skb) { 917 if (txq->sta) 918 IWL_DEBUG_TX(mvm, 919 "TXQ of sta %pM tid %d is now empty\n", 920 txq->sta->addr, 921 txq->tid); 922 break; 923 } 924 925 iwl_mvm_tx_skb(mvm, skb, txq->sta); 926 } 927 } while (atomic_dec_return(&mvmtxq->tx_request)); 928 rcu_read_unlock(); 929 } 930 931 void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 932 struct ieee80211_txq *txq) 933 { 934 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 935 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 936 937 if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) || 938 !txq->sta) { 939 iwl_mvm_mac_itxq_xmit(hw, txq); 940 return; 941 } 942 943 /* iwl_mvm_mac_itxq_xmit() will later be called by the worker 944 * to handle any packets we leave on the txq now 945 */ 946 947 spin_lock_bh(&mvm->add_stream_lock); 948 /* The list is being deleted only after the queue is fully allocated. */ 949 if (list_empty(&mvmtxq->list) && 950 /* recheck under lock */ 951 !test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) { 952 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 953 schedule_work(&mvm->add_stream_wk); 954 } 955 spin_unlock_bh(&mvm->add_stream_lock); 956 } 957 958 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 959 do { \ 960 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 961 break; \ 962 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 963 } while (0) 964 965 static void 966 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 967 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 968 enum ieee80211_ampdu_mlme_action action) 969 { 970 struct iwl_fw_dbg_trigger_tlv *trig; 971 struct iwl_fw_dbg_trigger_ba *ba_trig; 972 973 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 974 FW_DBG_TRIGGER_BA); 975 if (!trig) 976 return; 977 978 ba_trig = (void *)trig->data; 979 980 switch (action) { 981 case IEEE80211_AMPDU_TX_OPERATIONAL: { 982 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 983 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 984 985 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 986 "TX AGG START: MAC %pM tid %d ssn %d\n", 987 sta->addr, tid, tid_data->ssn); 988 break; 989 } 990 case IEEE80211_AMPDU_TX_STOP_CONT: 991 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 992 "TX AGG STOP: MAC %pM tid %d\n", 993 sta->addr, tid); 994 break; 995 case IEEE80211_AMPDU_RX_START: 996 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 997 "RX AGG START: MAC %pM tid %d ssn %d\n", 998 sta->addr, tid, rx_ba_ssn); 999 break; 1000 case IEEE80211_AMPDU_RX_STOP: 1001 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 1002 "RX AGG STOP: MAC %pM tid %d\n", 1003 sta->addr, tid); 1004 break; 1005 default: 1006 break; 1007 } 1008 } 1009 1010 int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 1011 struct ieee80211_vif *vif, 1012 struct ieee80211_ampdu_params *params) 1013 { 1014 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1015 int ret; 1016 struct ieee80211_sta *sta = params->sta; 1017 enum ieee80211_ampdu_mlme_action action = params->action; 1018 u16 tid = params->tid; 1019 u16 *ssn = ¶ms->ssn; 1020 u16 buf_size = params->buf_size; 1021 bool amsdu = params->amsdu; 1022 u16 timeout = params->timeout; 1023 1024 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 1025 sta->addr, tid, action); 1026 1027 if (!(mvm->nvm_data->sku_cap_11n_enable)) 1028 return -EACCES; 1029 1030 mutex_lock(&mvm->mutex); 1031 1032 switch (action) { 1033 case IEEE80211_AMPDU_RX_START: 1034 if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id == 1035 iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) { 1036 struct iwl_mvm_vif *mvmvif; 1037 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 1038 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 1039 1040 mdata->opened_rx_ba_sessions = true; 1041 mvmvif = iwl_mvm_vif_from_mac80211(vif); 1042 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 1043 } 1044 if (!iwl_enable_rx_ampdu()) { 1045 ret = -EINVAL; 1046 break; 1047 } 1048 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 1049 timeout); 1050 break; 1051 case IEEE80211_AMPDU_RX_STOP: 1052 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 1053 timeout); 1054 break; 1055 case IEEE80211_AMPDU_TX_START: 1056 if (!iwl_enable_tx_ampdu()) { 1057 ret = -EINVAL; 1058 break; 1059 } 1060 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 1061 break; 1062 case IEEE80211_AMPDU_TX_STOP_CONT: 1063 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 1064 break; 1065 case IEEE80211_AMPDU_TX_STOP_FLUSH: 1066 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1067 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 1068 break; 1069 case IEEE80211_AMPDU_TX_OPERATIONAL: 1070 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 1071 buf_size, amsdu); 1072 break; 1073 default: 1074 WARN_ON_ONCE(1); 1075 ret = -EINVAL; 1076 break; 1077 } 1078 1079 if (!ret) { 1080 u16 rx_ba_ssn = 0; 1081 1082 if (action == IEEE80211_AMPDU_RX_START) 1083 rx_ba_ssn = *ssn; 1084 1085 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 1086 rx_ba_ssn, action); 1087 } 1088 mutex_unlock(&mvm->mutex); 1089 1090 return ret; 1091 } 1092 1093 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 1094 struct ieee80211_vif *vif) 1095 { 1096 struct iwl_mvm *mvm = data; 1097 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1098 struct iwl_probe_resp_data *probe_data; 1099 unsigned int link_id; 1100 1101 mvmvif->uploaded = false; 1102 1103 spin_lock_bh(&mvm->time_event_lock); 1104 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 1105 spin_unlock_bh(&mvm->time_event_lock); 1106 1107 mvmvif->bf_enabled = false; 1108 mvmvif->ba_enabled = false; 1109 mvmvif->ap_sta = NULL; 1110 1111 mvmvif->esr_active = false; 1112 vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE; 1113 1114 for_each_mvm_vif_valid_link(mvmvif, link_id) { 1115 mvmvif->link[link_id]->ap_sta_id = IWL_MVM_INVALID_STA; 1116 mvmvif->link[link_id]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 1117 mvmvif->link[link_id]->phy_ctxt = NULL; 1118 mvmvif->link[link_id]->active = 0; 1119 mvmvif->link[link_id]->igtk = NULL; 1120 memset(&mvmvif->link[link_id]->bf_data, 0, 1121 sizeof(mvmvif->link[link_id]->bf_data)); 1122 } 1123 1124 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 1125 lockdep_is_held(&mvm->mutex)); 1126 if (probe_data) 1127 kfree_rcu(probe_data, rcu_head); 1128 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 1129 } 1130 1131 static void iwl_mvm_cleanup_sta_iterator(void *data, struct ieee80211_sta *sta) 1132 { 1133 struct iwl_mvm *mvm = data; 1134 struct iwl_mvm_sta *mvm_sta; 1135 struct ieee80211_vif *vif; 1136 int link_id; 1137 1138 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 1139 vif = mvm_sta->vif; 1140 1141 if (!sta->valid_links) 1142 return; 1143 1144 for (link_id = 0; link_id < ARRAY_SIZE((sta)->link); link_id++) { 1145 struct iwl_mvm_link_sta *mvm_link_sta; 1146 1147 mvm_link_sta = 1148 rcu_dereference_check(mvm_sta->link[link_id], 1149 lockdep_is_held(&mvm->mutex)); 1150 if (mvm_link_sta && !(vif->active_links & BIT(link_id))) { 1151 /* 1152 * We have a link STA but the link is inactive in 1153 * mac80211. This will happen if we failed to 1154 * deactivate the link but mac80211 roll back the 1155 * deactivation of the link. 1156 * Delete the stale data to avoid issues later on. 1157 */ 1158 iwl_mvm_mld_free_sta_link(mvm, mvm_sta, mvm_link_sta, 1159 link_id, false); 1160 } 1161 } 1162 } 1163 1164 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1165 { 1166 iwl_mvm_stop_device(mvm); 1167 1168 mvm->cur_aid = 0; 1169 1170 mvm->scan_status = 0; 1171 mvm->ps_disabled = false; 1172 mvm->rfkill_safe_init_done = false; 1173 1174 /* just in case one was running */ 1175 iwl_mvm_cleanup_roc_te(mvm); 1176 ieee80211_remain_on_channel_expired(mvm->hw); 1177 1178 iwl_mvm_ftm_restart(mvm); 1179 1180 /* 1181 * cleanup all interfaces, even inactive ones, as some might have 1182 * gone down during the HW restart 1183 */ 1184 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1185 1186 /* cleanup stations as links may be gone after restart */ 1187 ieee80211_iterate_stations_atomic(mvm->hw, 1188 iwl_mvm_cleanup_sta_iterator, mvm); 1189 1190 mvm->p2p_device_vif = NULL; 1191 1192 iwl_mvm_reset_phy_ctxts(mvm); 1193 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1194 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1195 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1196 1197 ieee80211_wake_queues(mvm->hw); 1198 1199 mvm->rx_ba_sessions = 0; 1200 mvm->fwrt.dump.conf = FW_DBG_INVALID; 1201 mvm->monitor_on = false; 1202 #ifdef CONFIG_IWLWIFI_DEBUGFS 1203 mvm->beacon_inject_active = false; 1204 #endif 1205 1206 /* keep statistics ticking */ 1207 iwl_mvm_accu_radio_stats(mvm); 1208 } 1209 1210 int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1211 { 1212 int ret; 1213 1214 lockdep_assert_held(&mvm->mutex); 1215 1216 ret = iwl_mvm_mei_get_ownership(mvm); 1217 if (ret) 1218 return ret; 1219 1220 if (mvm->mei_nvm_data) { 1221 /* We got the NIC, we can now free the MEI NVM data */ 1222 kfree(mvm->mei_nvm_data); 1223 mvm->mei_nvm_data = NULL; 1224 1225 /* 1226 * We can't free the nvm_data we allocated based on the SAP 1227 * data because we registered to cfg80211 with the channels 1228 * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 1229 * just in order to be able free it later. 1230 * NULLify nvm_data so that we will read the NVM from the 1231 * firmware this time. 1232 */ 1233 mvm->temp_nvm_data = mvm->nvm_data; 1234 mvm->nvm_data = NULL; 1235 } 1236 1237 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1238 /* 1239 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1240 * so later code will - from now on - see that we're doing it. 1241 */ 1242 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1243 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1244 /* Clean up some internal and mac80211 state on restart */ 1245 iwl_mvm_restart_cleanup(mvm); 1246 } 1247 ret = iwl_mvm_up(mvm); 1248 1249 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1250 NULL); 1251 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1252 NULL); 1253 1254 mvm->last_reset_or_resume_time_jiffies = jiffies; 1255 1256 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1257 /* Something went wrong - we need to finish some cleanup 1258 * that normally iwl_mvm_mac_restart_complete() below 1259 * would do. 1260 */ 1261 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1262 } 1263 1264 return ret; 1265 } 1266 1267 int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1268 { 1269 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1270 int ret; 1271 1272 mutex_lock(&mvm->mutex); 1273 1274 /* we are starting the mac not in error flow, and restart is enabled */ 1275 if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 1276 iwlwifi_mod_params.fw_restart) { 1277 /* 1278 * This will prevent mac80211 recovery flows to trigger during 1279 * init failures 1280 */ 1281 set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 1282 } 1283 1284 ret = __iwl_mvm_mac_start(mvm); 1285 clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 1286 1287 mutex_unlock(&mvm->mutex); 1288 1289 iwl_mvm_mei_set_sw_rfkill_state(mvm); 1290 1291 return ret; 1292 } 1293 1294 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1295 { 1296 int ret; 1297 1298 guard(mvm)(mvm); 1299 1300 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1301 1302 ret = iwl_mvm_update_quotas(mvm, true, NULL); 1303 if (ret) 1304 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1305 ret); 1306 1307 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1308 1309 /* 1310 * If we have TDLS peers, remove them. We don't know the last seqno/PN 1311 * of packets the FW sent out, so we must reconnect. 1312 */ 1313 iwl_mvm_teardown_tdls_peers(mvm); 1314 } 1315 1316 void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1317 enum ieee80211_reconfig_type reconfig_type) 1318 { 1319 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1320 1321 switch (reconfig_type) { 1322 case IEEE80211_RECONFIG_TYPE_RESTART: 1323 iwl_mvm_restart_complete(mvm); 1324 break; 1325 case IEEE80211_RECONFIG_TYPE_SUSPEND: 1326 break; 1327 } 1328 } 1329 1330 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1331 { 1332 lockdep_assert_held(&mvm->mutex); 1333 1334 iwl_mvm_ftm_initiator_smooth_stop(mvm); 1335 1336 /* firmware counters are obviously reset now, but we shouldn't 1337 * partially track so also clear the fw_reset_accu counters. 1338 */ 1339 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1340 1341 /* async_handlers_wk is now blocked */ 1342 1343 if (!iwl_mvm_has_new_station_api(mvm->fw)) 1344 iwl_mvm_rm_aux_sta(mvm); 1345 1346 iwl_mvm_stop_device(mvm); 1347 1348 iwl_mvm_async_handlers_purge(mvm); 1349 /* async_handlers_list is empty and will stay empty: HW is stopped */ 1350 1351 /* 1352 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1353 * hw (as restart_complete() won't be called in this case) and mac80211 1354 * won't execute the restart. 1355 * But make sure to cleanup interfaces that have gone down before/during 1356 * HW restart was requested. 1357 */ 1358 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1359 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1360 &mvm->status)) 1361 ieee80211_iterate_interfaces(mvm->hw, 0, 1362 iwl_mvm_cleanup_iterator, mvm); 1363 1364 /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1365 * make sure there's nothing left there and warn if any is found. 1366 */ 1367 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1368 int i; 1369 1370 for (i = 0; i < mvm->max_scans; i++) { 1371 if (WARN_ONCE(mvm->scan_uid_status[i], 1372 "UMAC scan UID %d status was not cleaned\n", 1373 i)) 1374 mvm->scan_uid_status[i] = 0; 1375 } 1376 } 1377 } 1378 1379 void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1380 { 1381 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1382 1383 /* Stop internal MLO scan, if running */ 1384 mutex_lock(&mvm->mutex); 1385 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_INT_MLO, false); 1386 mutex_unlock(&mvm->mutex); 1387 1388 wiphy_work_cancel(mvm->hw->wiphy, &mvm->trig_link_selection_wk); 1389 wiphy_work_flush(mvm->hw->wiphy, &mvm->async_handlers_wiphy_wk); 1390 flush_work(&mvm->async_handlers_wk); 1391 flush_work(&mvm->add_stream_wk); 1392 1393 /* 1394 * Lock and clear the firmware running bit here already, so that 1395 * new commands coming in elsewhere, e.g. from debugfs, will not 1396 * be able to proceed. This is important here because one of those 1397 * debugfs files causes the firmware dump to be triggered, and if we 1398 * don't stop debugfs accesses before canceling that it could be 1399 * retriggered after we flush it but before we've cleared the bit. 1400 */ 1401 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1402 1403 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 1404 cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1405 1406 /* 1407 * The work item could be running or queued if the 1408 * ROC time event stops just as we get here. 1409 */ 1410 flush_work(&mvm->roc_done_wk); 1411 1412 iwl_mvm_mei_set_sw_rfkill_state(mvm); 1413 1414 mutex_lock(&mvm->mutex); 1415 __iwl_mvm_mac_stop(mvm); 1416 mutex_unlock(&mvm->mutex); 1417 1418 /* 1419 * The worker might have been waiting for the mutex, let it run and 1420 * discover that its list is now empty. 1421 */ 1422 cancel_work_sync(&mvm->async_handlers_wk); 1423 wiphy_work_cancel(hw->wiphy, &mvm->async_handlers_wiphy_wk); 1424 } 1425 1426 struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1427 { 1428 u16 i; 1429 1430 lockdep_assert_held(&mvm->mutex); 1431 1432 for (i = 0; i < NUM_PHY_CTX; i++) 1433 if (!mvm->phy_ctxts[i].ref) 1434 return &mvm->phy_ctxts[i]; 1435 1436 IWL_ERR(mvm, "No available PHY context\n"); 1437 return NULL; 1438 } 1439 1440 int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1441 s16 tx_power) 1442 { 1443 u32 cmd_id = REDUCE_TX_POWER_CMD; 1444 int len; 1445 struct iwl_dev_tx_power_cmd cmd = { 1446 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1447 .common.mac_context_id = 1448 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1449 .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1450 }; 1451 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1452 IWL_FW_CMD_VER_UNKNOWN); 1453 1454 if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1455 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1456 1457 if (cmd_ver == 8) 1458 len = sizeof(cmd.v8); 1459 else if (cmd_ver == 7) 1460 len = sizeof(cmd.v7); 1461 else if (cmd_ver == 6) 1462 len = sizeof(cmd.v6); 1463 else if (fw_has_api(&mvm->fw->ucode_capa, 1464 IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 1465 len = sizeof(cmd.v5); 1466 else if (fw_has_capa(&mvm->fw->ucode_capa, 1467 IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 1468 len = sizeof(cmd.v4); 1469 else 1470 len = sizeof(cmd.v3); 1471 1472 /* all structs have the same common part, add it */ 1473 len += sizeof(cmd.common); 1474 1475 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); 1476 } 1477 1478 static void iwl_mvm_post_csa_tx(void *data, struct ieee80211_sta *sta) 1479 { 1480 struct ieee80211_hw *hw = data; 1481 int i; 1482 1483 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 1484 struct iwl_mvm_txq *mvmtxq = 1485 iwl_mvm_txq_from_mac80211(sta->txq[i]); 1486 1487 clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1488 iwl_mvm_mac_itxq_xmit(hw, sta->txq[i]); 1489 } 1490 } 1491 1492 int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1493 struct ieee80211_vif *vif, 1494 struct ieee80211_bss_conf *link_conf) 1495 { 1496 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1497 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1498 int ret; 1499 1500 mutex_lock(&mvm->mutex); 1501 1502 if (vif->type == NL80211_IFTYPE_STATION) { 1503 struct iwl_mvm_sta *mvmsta; 1504 unsigned int link_id = link_conf->link_id; 1505 u8 ap_sta_id = mvmvif->link[link_id]->ap_sta_id; 1506 1507 mvmvif->csa_bcn_pending = false; 1508 mvmvif->csa_blocks_tx = false; 1509 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id); 1510 1511 if (WARN_ON(!mvmsta)) { 1512 ret = -EIO; 1513 goto out_unlock; 1514 } 1515 1516 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 1517 if (mvm->mld_api_is_used) 1518 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 1519 else 1520 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1521 1522 if (!fw_has_capa(&mvm->fw->ucode_capa, 1523 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 1524 ret = iwl_mvm_enable_beacon_filter(mvm, vif); 1525 if (ret) 1526 goto out_unlock; 1527 1528 iwl_mvm_stop_session_protection(mvm, vif); 1529 } 1530 } else if (vif->type == NL80211_IFTYPE_AP && mvmvif->csa_blocks_tx) { 1531 struct iwl_mvm_txq *mvmtxq = 1532 iwl_mvm_txq_from_mac80211(vif->txq); 1533 1534 clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1535 1536 local_bh_disable(); 1537 iwl_mvm_mac_itxq_xmit(hw, vif->txq); 1538 ieee80211_iterate_stations_atomic(hw, iwl_mvm_post_csa_tx, hw); 1539 local_bh_enable(); 1540 1541 mvmvif->csa_blocks_tx = false; 1542 } 1543 1544 mvmvif->ps_disabled = false; 1545 1546 ret = iwl_mvm_power_update_ps(mvm); 1547 1548 out_unlock: 1549 if (mvmvif->csa_failed) 1550 ret = -EIO; 1551 mutex_unlock(&mvm->mutex); 1552 1553 return ret; 1554 } 1555 1556 void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 1557 struct ieee80211_vif *vif, 1558 struct ieee80211_bss_conf *link_conf) 1559 { 1560 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1561 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1562 struct iwl_chan_switch_te_cmd cmd = { 1563 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1564 mvmvif->color)), 1565 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1566 }; 1567 1568 /* 1569 * In the new flow since FW is in charge of the timing, 1570 * if driver has canceled the channel switch he will receive the 1571 * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it 1572 */ 1573 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 1574 CHANNEL_SWITCH_ERROR_NOTIF, 0)) 1575 return; 1576 1577 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1578 1579 mutex_lock(&mvm->mutex); 1580 if (!fw_has_capa(&mvm->fw->ucode_capa, 1581 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 1582 iwl_mvm_remove_csa_period(mvm, vif); 1583 else 1584 WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1585 WIDE_ID(MAC_CONF_GROUP, 1586 CHANNEL_SWITCH_TIME_EVENT_CMD), 1587 0, sizeof(cmd), &cmd)); 1588 mvmvif->csa_failed = true; 1589 mutex_unlock(&mvm->mutex); 1590 1591 /* If we're here, we can't support MLD */ 1592 iwl_mvm_post_channel_switch(hw, vif, &vif->bss_conf); 1593 } 1594 1595 void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1596 { 1597 struct iwl_mvm_vif *mvmvif; 1598 struct ieee80211_vif *vif; 1599 1600 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1601 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1602 1603 /* Trigger disconnect (should clear the CSA state) */ 1604 ieee80211_chswitch_done(vif, false, 0); 1605 } 1606 1607 static u8 1608 iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef) 1609 { 1610 int data_start; 1611 int control_start; 1612 int bw; 1613 1614 if (chandef->width == NL80211_CHAN_WIDTH_320) 1615 bw = 320; 1616 else if (chandef->width == NL80211_CHAN_WIDTH_160) 1617 bw = 160; 1618 else 1619 return 0; 1620 1621 /* data is bw wide so the start is half the width */ 1622 data_start = chandef->center_freq1 - bw / 2; 1623 /* control is 20Mhz width */ 1624 control_start = chandef->chan->center_freq - 10; 1625 1626 return (control_start - data_start) / 80; 1627 } 1628 1629 static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm, 1630 struct ieee80211_vif *vif) 1631 { 1632 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1633 int ret; 1634 1635 lockdep_assert_held(&mvm->mutex); 1636 1637 ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1638 if (ret) { 1639 IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 1640 return ret; 1641 } 1642 1643 /* Only queue for this station is the mcast queue, 1644 * which shouldn't be in TFD mask anyway 1645 */ 1646 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0, 1647 vif->type, 1648 IWL_STA_MULTICAST); 1649 } 1650 1651 static void iwl_mvm_prevent_esr_done_wk(struct wiphy *wiphy, 1652 struct wiphy_work *wk) 1653 { 1654 struct iwl_mvm_vif *mvmvif = 1655 container_of(wk, struct iwl_mvm_vif, prevent_esr_done_wk.work); 1656 struct iwl_mvm *mvm = mvmvif->mvm; 1657 struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm); 1658 1659 guard(mvm)(mvm); 1660 iwl_mvm_unblock_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_PREVENTION); 1661 } 1662 1663 static void iwl_mvm_mlo_int_scan_wk(struct wiphy *wiphy, struct wiphy_work *wk) 1664 { 1665 struct iwl_mvm_vif *mvmvif = container_of(wk, struct iwl_mvm_vif, 1666 mlo_int_scan_wk.work); 1667 struct ieee80211_vif *vif = 1668 container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1669 1670 guard(mvm)(mvmvif->mvm); 1671 iwl_mvm_int_mlo_scan(mvmvif->mvm, vif); 1672 } 1673 1674 static void iwl_mvm_unblock_esr_tpt(struct wiphy *wiphy, struct wiphy_work *wk) 1675 { 1676 struct iwl_mvm_vif *mvmvif = 1677 container_of(wk, struct iwl_mvm_vif, unblock_esr_tpt_wk); 1678 struct iwl_mvm *mvm = mvmvif->mvm; 1679 struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm); 1680 1681 guard(mvm)(mvm); 1682 iwl_mvm_unblock_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_TPT); 1683 } 1684 1685 void iwl_mvm_mac_init_mvmvif(struct iwl_mvm *mvm, struct iwl_mvm_vif *mvmvif) 1686 { 1687 lockdep_assert_held(&mvm->mutex); 1688 1689 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1690 return; 1691 1692 INIT_DELAYED_WORK(&mvmvif->csa_work, 1693 iwl_mvm_channel_switch_disconnect_wk); 1694 1695 wiphy_delayed_work_init(&mvmvif->prevent_esr_done_wk, 1696 iwl_mvm_prevent_esr_done_wk); 1697 1698 wiphy_delayed_work_init(&mvmvif->mlo_int_scan_wk, 1699 iwl_mvm_mlo_int_scan_wk); 1700 1701 wiphy_work_init(&mvmvif->unblock_esr_tpt_wk, 1702 iwl_mvm_unblock_esr_tpt); 1703 } 1704 1705 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1706 struct ieee80211_vif *vif) 1707 { 1708 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1709 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1710 int ret; 1711 int i; 1712 1713 mutex_lock(&mvm->mutex); 1714 1715 iwl_mvm_mac_init_mvmvif(mvm, mvmvif); 1716 1717 mvmvif->mvm = mvm; 1718 1719 /* the first link always points to the default one */ 1720 mvmvif->deflink.fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 1721 mvmvif->deflink.active = 0; 1722 mvmvif->link[0] = &mvmvif->deflink; 1723 1724 ret = iwl_mvm_set_link_mapping(mvm, vif, &vif->bss_conf); 1725 if (ret) 1726 goto out; 1727 1728 /* 1729 * Not much to do here. The stack will not allow interface 1730 * types or combinations that we didn't advertise, so we 1731 * don't really have to check the types. 1732 */ 1733 1734 /* make sure that beacon statistics don't go backwards with FW reset */ 1735 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1736 for_each_mvm_vif_valid_link(mvmvif, i) 1737 mvmvif->link[i]->beacon_stats.accu_num_beacons += 1738 mvmvif->link[i]->beacon_stats.num_beacons; 1739 1740 /* Allocate resources for the MAC context, and add it to the fw */ 1741 ret = iwl_mvm_mac_ctxt_init(mvm, vif); 1742 if (ret) 1743 goto out; 1744 1745 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1746 1747 /* Currently not much to do for NAN */ 1748 if (vif->type == NL80211_IFTYPE_NAN) { 1749 ret = 0; 1750 goto out; 1751 } 1752 1753 /* 1754 * The AP binding flow can be done only after the beacon 1755 * template is configured (which happens only in the mac80211 1756 * start_ap() flow), and adding the broadcast station can happen 1757 * only after the binding. 1758 * In addition, since modifying the MAC before adding a bcast 1759 * station is not allowed by the FW, delay the adding of MAC context to 1760 * the point where we can also add the bcast station. 1761 * In short: there's not much we can do at this point, other than 1762 * allocating resources :) 1763 */ 1764 if (vif->type == NL80211_IFTYPE_AP || 1765 vif->type == NL80211_IFTYPE_ADHOC) { 1766 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1767 iwl_mvm_vif_dbgfs_add_link(mvm, vif); 1768 ret = 0; 1769 goto out; 1770 } 1771 1772 mvmvif->features |= hw->netdev_features; 1773 1774 ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1775 if (ret) 1776 goto out_unlock; 1777 1778 ret = iwl_mvm_power_update_mac(mvm); 1779 if (ret) 1780 goto out_remove_mac; 1781 1782 /* beacon filtering */ 1783 ret = iwl_mvm_disable_beacon_filter(mvm, vif); 1784 if (ret) 1785 goto out_remove_mac; 1786 1787 if (!mvm->bf_allowed_vif && 1788 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1789 mvm->bf_allowed_vif = mvmvif; 1790 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1791 IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1792 } 1793 1794 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 1795 mvm->p2p_device_vif = vif; 1796 1797 iwl_mvm_tcm_add_vif(mvm, vif); 1798 1799 if (vif->type == NL80211_IFTYPE_MONITOR) { 1800 mvm->monitor_on = true; 1801 mvm->monitor_p80 = 1802 iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chanreq.oper); 1803 } 1804 1805 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1806 iwl_mvm_vif_dbgfs_add_link(mvm, vif); 1807 1808 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 1809 vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 1810 !mvm->csme_vif && mvm->mei_registered) { 1811 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 1812 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 1813 mvm->csme_vif = vif; 1814 } 1815 1816 out: 1817 if (!ret && (vif->type == NL80211_IFTYPE_AP || 1818 vif->type == NL80211_IFTYPE_ADHOC)) 1819 ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif); 1820 1821 goto out_unlock; 1822 1823 out_remove_mac: 1824 mvmvif->deflink.phy_ctxt = NULL; 1825 iwl_mvm_mac_ctxt_remove(mvm, vif); 1826 out_unlock: 1827 mutex_unlock(&mvm->mutex); 1828 1829 return ret; 1830 } 1831 1832 void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1833 struct ieee80211_vif *vif) 1834 { 1835 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1836 1837 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1838 /* 1839 * Flush the ROC worker which will flush the OFFCHANNEL queue. 1840 * We assume here that all the packets sent to the OFFCHANNEL 1841 * queue are sent in ROC session. 1842 */ 1843 flush_work(&mvm->roc_done_wk); 1844 } 1845 1846 wiphy_delayed_work_cancel(mvm->hw->wiphy, 1847 &mvmvif->prevent_esr_done_wk); 1848 1849 wiphy_delayed_work_cancel(mvm->hw->wiphy, 1850 &mvmvif->mlo_int_scan_wk); 1851 1852 wiphy_work_cancel(mvm->hw->wiphy, &mvmvif->unblock_esr_tpt_wk); 1853 1854 cancel_delayed_work_sync(&mvmvif->csa_work); 1855 } 1856 1857 /* This function is doing the common part of removing the interface for 1858 * both - MLD and non-MLD modes. Returns true if removing the interface 1859 * is done 1860 */ 1861 static bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw, 1862 struct ieee80211_vif *vif) 1863 { 1864 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1865 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1866 struct iwl_probe_resp_data *probe_data; 1867 1868 iwl_mvm_prepare_mac_removal(mvm, vif); 1869 1870 if (!(vif->type == NL80211_IFTYPE_AP || 1871 vif->type == NL80211_IFTYPE_ADHOC)) 1872 iwl_mvm_tcm_rm_vif(mvm, vif); 1873 1874 mutex_lock(&mvm->mutex); 1875 1876 if (vif == mvm->csme_vif) { 1877 iwl_mei_set_netdev(NULL); 1878 mvm->csme_vif = NULL; 1879 } 1880 1881 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 1882 lockdep_is_held(&mvm->mutex)); 1883 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 1884 if (probe_data) 1885 kfree_rcu(probe_data, rcu_head); 1886 1887 if (mvm->bf_allowed_vif == mvmvif) { 1888 mvm->bf_allowed_vif = NULL; 1889 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1890 IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1891 } 1892 1893 if (vif->bss_conf.ftm_responder) 1894 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1895 1896 iwl_mvm_vif_dbgfs_rm_link(mvm, vif); 1897 1898 /* 1899 * For AP/GO interface, the tear down of the resources allocated to the 1900 * interface is be handled as part of the stop_ap flow. 1901 */ 1902 if (vif->type == NL80211_IFTYPE_AP || 1903 vif->type == NL80211_IFTYPE_ADHOC) { 1904 #ifdef CONFIG_NL80211_TESTMODE 1905 if (vif == mvm->noa_vif) { 1906 mvm->noa_vif = NULL; 1907 mvm->noa_duration = 0; 1908 } 1909 #endif 1910 return true; 1911 } 1912 1913 iwl_mvm_power_update_mac(mvm); 1914 return false; 1915 } 1916 1917 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 1918 struct ieee80211_vif *vif) 1919 { 1920 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1921 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1922 1923 if (iwl_mvm_mac_remove_interface_common(hw, vif)) 1924 goto out; 1925 1926 /* Before the interface removal, mac80211 would cancel the ROC, and the 1927 * ROC worker would be scheduled if needed. The worker would be flushed 1928 * in iwl_mvm_prepare_mac_removal() and thus at this point there is no 1929 * binding etc. so nothing needs to be done here. 1930 */ 1931 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1932 if (mvmvif->deflink.phy_ctxt) { 1933 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 1934 mvmvif->deflink.phy_ctxt = NULL; 1935 } 1936 mvm->p2p_device_vif = NULL; 1937 } 1938 1939 iwl_mvm_unset_link_mapping(mvm, vif, &vif->bss_conf); 1940 iwl_mvm_mac_ctxt_remove(mvm, vif); 1941 1942 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1943 1944 if (vif->type == NL80211_IFTYPE_MONITOR) 1945 mvm->monitor_on = false; 1946 1947 out: 1948 if (vif->type == NL80211_IFTYPE_AP || 1949 vif->type == NL80211_IFTYPE_ADHOC) { 1950 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta); 1951 iwl_mvm_dealloc_bcast_sta(mvm, vif); 1952 } 1953 1954 mutex_unlock(&mvm->mutex); 1955 } 1956 1957 struct iwl_mvm_mc_iter_data { 1958 struct iwl_mvm *mvm; 1959 int port_id; 1960 }; 1961 1962 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1963 struct ieee80211_vif *vif) 1964 { 1965 struct iwl_mvm_mc_iter_data *data = _data; 1966 struct iwl_mvm *mvm = data->mvm; 1967 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 1968 struct iwl_host_cmd hcmd = { 1969 .id = MCAST_FILTER_CMD, 1970 .flags = CMD_ASYNC, 1971 .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 1972 }; 1973 int ret, len; 1974 1975 /* if we don't have free ports, mcast frames will be dropped */ 1976 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1977 return; 1978 1979 if (vif->type != NL80211_IFTYPE_STATION || 1980 !vif->cfg.assoc) 1981 return; 1982 1983 cmd->port_id = data->port_id++; 1984 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1985 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1986 1987 hcmd.len[0] = len; 1988 hcmd.data[0] = cmd; 1989 1990 ret = iwl_mvm_send_cmd(mvm, &hcmd); 1991 if (ret) 1992 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1993 } 1994 1995 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1996 { 1997 struct iwl_mvm_mc_iter_data iter_data = { 1998 .mvm = mvm, 1999 }; 2000 int ret; 2001 2002 lockdep_assert_held(&mvm->mutex); 2003 2004 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 2005 return; 2006 2007 ieee80211_iterate_active_interfaces_atomic( 2008 mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2009 iwl_mvm_mc_iface_iterator, &iter_data); 2010 2011 /* 2012 * Send a (synchronous) ech command so that we wait for the 2013 * multiple asynchronous MCAST_FILTER_CMD commands sent by 2014 * the interface iterator. Otherwise, we might get here over 2015 * and over again (by userspace just sending a lot of these) 2016 * and the CPU can send them faster than the firmware can 2017 * process them. 2018 * Note that the CPU is still faster - but with this we'll 2019 * actually send fewer commands overall because the CPU will 2020 * not schedule the work in mac80211 as frequently if it's 2021 * still running when rescheduled (possibly multiple times). 2022 */ 2023 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 2024 if (ret) 2025 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 2026 } 2027 2028 u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 2029 struct netdev_hw_addr_list *mc_list) 2030 { 2031 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2032 struct iwl_mcast_filter_cmd *cmd; 2033 struct netdev_hw_addr *addr; 2034 int addr_count; 2035 bool pass_all; 2036 int len; 2037 2038 addr_count = netdev_hw_addr_list_count(mc_list); 2039 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 2040 IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 2041 if (pass_all) 2042 addr_count = 0; 2043 2044 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 2045 cmd = kzalloc(len, GFP_ATOMIC); 2046 if (!cmd) 2047 return 0; 2048 2049 if (pass_all) { 2050 cmd->pass_all = 1; 2051 return (u64)(unsigned long)cmd; 2052 } 2053 2054 netdev_hw_addr_list_for_each(addr, mc_list) { 2055 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 2056 cmd->count, addr->addr); 2057 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 2058 addr->addr, ETH_ALEN); 2059 cmd->count++; 2060 } 2061 2062 return (u64)(unsigned long)cmd; 2063 } 2064 2065 void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 2066 unsigned int changed_flags, 2067 unsigned int *total_flags, u64 multicast) 2068 { 2069 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2070 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 2071 2072 guard(mvm)(mvm); 2073 2074 /* replace previous configuration */ 2075 kfree(mvm->mcast_filter_cmd); 2076 mvm->mcast_filter_cmd = cmd; 2077 2078 if (!cmd) 2079 goto out; 2080 2081 if (changed_flags & FIF_ALLMULTI) 2082 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 2083 2084 if (cmd->pass_all) 2085 cmd->count = 0; 2086 2087 iwl_mvm_recalc_multicast(mvm); 2088 out: 2089 *total_flags = 0; 2090 } 2091 2092 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 2093 struct ieee80211_vif *vif, 2094 unsigned int filter_flags, 2095 unsigned int changed_flags) 2096 { 2097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2098 2099 /* We support only filter for probe requests */ 2100 if (!(changed_flags & FIF_PROBE_REQ)) 2101 return; 2102 2103 /* Supported only for p2p client interfaces */ 2104 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 2105 !vif->p2p) 2106 return; 2107 2108 guard(mvm)(mvm); 2109 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2110 } 2111 2112 int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 2113 { 2114 struct iwl_mu_group_mgmt_cmd cmd = {}; 2115 2116 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 2117 WLAN_MEMBERSHIP_LEN); 2118 memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 2119 WLAN_USER_POSITION_LEN); 2120 2121 return iwl_mvm_send_cmd_pdu(mvm, 2122 WIDE_ID(DATA_PATH_GROUP, 2123 UPDATE_MU_GROUPS_CMD), 2124 0, sizeof(cmd), &cmd); 2125 } 2126 2127 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 2128 struct ieee80211_vif *vif) 2129 { 2130 if (vif->bss_conf.mu_mimo_owner) { 2131 struct iwl_mu_group_mgmt_notif *notif = _data; 2132 2133 /* 2134 * MU-MIMO Group Id action frame is little endian. We treat 2135 * the data received from firmware as if it came from the 2136 * action frame, so no conversion is needed. 2137 */ 2138 ieee80211_update_mu_groups(vif, 0, 2139 (u8 *)¬if->membership_status, 2140 (u8 *)¬if->user_position); 2141 } 2142 } 2143 2144 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 2145 struct iwl_rx_cmd_buffer *rxb) 2146 { 2147 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2148 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 2149 2150 ieee80211_iterate_active_interfaces_atomic( 2151 mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2152 iwl_mvm_mu_mimo_iface_iterator, notif); 2153 } 2154 2155 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 2156 { 2157 u8 byte_num = ppe_pos_bit / 8; 2158 u8 bit_num = ppe_pos_bit % 8; 2159 u8 residue_bits; 2160 u8 res; 2161 2162 if (bit_num <= 5) 2163 return (ppe[byte_num] >> bit_num) & 2164 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 2165 2166 /* 2167 * If bit_num > 5, we have to combine bits with next byte. 2168 * Calculate how many bits we need to take from current byte (called 2169 * here "residue_bits"), and add them to bits from next byte. 2170 */ 2171 2172 residue_bits = 8 - bit_num; 2173 2174 res = (ppe[byte_num + 1] & 2175 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 2176 residue_bits; 2177 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 2178 2179 return res; 2180 } 2181 2182 static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, 2183 struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, 2184 u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit, 2185 bool inheritance) 2186 { 2187 int i; 2188 2189 /* 2190 * FW currently supports only nss == MAX_HE_SUPP_NSS 2191 * 2192 * If nss > MAX: we can ignore values we don't support 2193 * If nss < MAX: we can set zeros in other streams 2194 */ 2195 if (nss > MAX_HE_SUPP_NSS) { 2196 IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 2197 MAX_HE_SUPP_NSS); 2198 nss = MAX_HE_SUPP_NSS; 2199 } 2200 2201 for (i = 0; i < nss; i++) { 2202 u8 ru_index_tmp = ru_index_bitmap << 1; 2203 u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; 2204 u8 bw; 2205 2206 for (bw = 0; 2207 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2208 bw++) { 2209 ru_index_tmp >>= 1; 2210 2211 /* 2212 * According to the 11be spec, if for a specific BW the PPE Thresholds 2213 * isn't present - it should inherit the thresholds from the last 2214 * BW for which we had PPE Thresholds. In 11ax though, we don't have 2215 * this inheritance - continue in this case 2216 */ 2217 if (!(ru_index_tmp & 1)) { 2218 if (inheritance) 2219 goto set_thresholds; 2220 else 2221 continue; 2222 } 2223 2224 high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2225 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2226 low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2227 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2228 2229 set_thresholds: 2230 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2231 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2232 } 2233 } 2234 } 2235 2236 static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, 2237 struct ieee80211_link_sta *link_sta, 2238 struct iwl_he_pkt_ext_v2 *pkt_ext, 2239 bool inheritance) 2240 { 2241 u8 nss = (link_sta->he_cap.ppe_thres[0] & 2242 IEEE80211_PPE_THRES_NSS_MASK) + 1; 2243 u8 *ppe = &link_sta->he_cap.ppe_thres[0]; 2244 u8 ru_index_bitmap = 2245 u8_get_bits(*ppe, 2246 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); 2247 /* Starting after PPE header */ 2248 u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; 2249 2250 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit, 2251 inheritance); 2252 } 2253 2254 static int 2255 iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, 2256 u8 nominal_padding) 2257 { 2258 int low_th = -1; 2259 int high_th = -1; 2260 int i; 2261 2262 /* all the macros are the same for EHT and HE */ 2263 switch (nominal_padding) { 2264 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US: 2265 low_th = IWL_HE_PKT_EXT_NONE; 2266 high_th = IWL_HE_PKT_EXT_NONE; 2267 break; 2268 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US: 2269 low_th = IWL_HE_PKT_EXT_BPSK; 2270 high_th = IWL_HE_PKT_EXT_NONE; 2271 break; 2272 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: 2273 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US: 2274 low_th = IWL_HE_PKT_EXT_NONE; 2275 high_th = IWL_HE_PKT_EXT_BPSK; 2276 break; 2277 } 2278 2279 if (low_th < 0 || high_th < 0) 2280 return -EINVAL; 2281 2282 /* Set the PPE thresholds accordingly */ 2283 for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2284 u8 bw; 2285 2286 for (bw = 0; 2287 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2288 bw++) { 2289 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2290 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2291 } 2292 } 2293 2294 return 0; 2295 } 2296 2297 static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext, 2298 u8 nominal_padding) 2299 { 2300 int i; 2301 2302 for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2303 u8 bw; 2304 2305 for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2306 bw++) { 2307 u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0]; 2308 2309 if (nominal_padding > 2310 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2311 qam_th[1] == IWL_HE_PKT_EXT_NONE) 2312 qam_th[1] = IWL_HE_PKT_EXT_4096QAM; 2313 else if (nominal_padding == 2314 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2315 qam_th[0] == IWL_HE_PKT_EXT_NONE && 2316 qam_th[1] == IWL_HE_PKT_EXT_NONE) 2317 qam_th[0] = IWL_HE_PKT_EXT_4096QAM; 2318 } 2319 } 2320 } 2321 2322 /* Set the pkt_ext field according to PPE Thresholds element */ 2323 int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, 2324 struct ieee80211_link_sta *link_sta, 2325 struct iwl_he_pkt_ext_v2 *pkt_ext) 2326 { 2327 u8 nominal_padding; 2328 int i, ret = 0; 2329 2330 if (WARN_ON(!link_sta)) 2331 return -EINVAL; 2332 2333 /* Initialize the PPE thresholds to "None" (7), as described in Table 2334 * 9-262ac of 80211.ax/D3.0. 2335 */ 2336 memset(pkt_ext, IWL_HE_PKT_EXT_NONE, 2337 sizeof(struct iwl_he_pkt_ext_v2)); 2338 2339 if (link_sta->eht_cap.has_eht) { 2340 nominal_padding = 2341 u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5], 2342 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK); 2343 2344 /* If PPE Thresholds exists, parse them into a FW-familiar 2345 * format. 2346 */ 2347 if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] & 2348 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { 2349 u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] & 2350 IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1; 2351 u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0]; 2352 u8 ru_index_bitmap = 2353 u16_get_bits(*ppe, 2354 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 2355 /* Starting after PPE header */ 2356 u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; 2357 2358 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, 2359 ppe, ppe_pos_bit, true); 2360 /* EHT PPE Thresholds doesn't exist - set the API according to 2361 * HE PPE Tresholds 2362 */ 2363 } else if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 2364 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2365 /* Even though HE Capabilities IE doesn't contain PPE 2366 * Thresholds for BW 320Mhz, thresholds for this BW will 2367 * be filled in with the same values as 160Mhz, due to 2368 * the inheritance, as required. 2369 */ 2370 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 2371 true); 2372 2373 /* According to the requirements, for MCSs 12-13 the 2374 * maximum value between HE PPE Threshold and Common 2375 * Nominal Packet Padding needs to be taken 2376 */ 2377 iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding); 2378 2379 /* if PPE Thresholds doesn't present in both EHT IE and HE IE - 2380 * take the Thresholds from Common Nominal Packet Padding field 2381 */ 2382 } else { 2383 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 2384 nominal_padding); 2385 } 2386 } else if (link_sta->he_cap.has_he) { 2387 /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 2388 if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 2389 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2390 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 2391 false); 2392 /* PPE Thresholds doesn't exist - set the API PPE values 2393 * according to Common Nominal Packet Padding field. 2394 */ 2395 } else { 2396 nominal_padding = 2397 u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9], 2398 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 2399 if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) 2400 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 2401 nominal_padding); 2402 } 2403 } 2404 2405 for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2406 int bw; 2407 2408 for (bw = 0; 2409 bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]); 2410 bw++) { 2411 u8 *qam_th = 2412 &pkt_ext->pkt_ext_qam_th[i][bw][0]; 2413 2414 IWL_DEBUG_HT(mvm, 2415 "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n", 2416 i, bw, qam_th[0], qam_th[1]); 2417 } 2418 } 2419 return ret; 2420 } 2421 2422 /* 2423 * This function sets the MU EDCA parameters ans returns whether MU EDCA 2424 * is enabled or not 2425 */ 2426 bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, 2427 const struct iwl_mvm_vif_link_info *link_info, 2428 struct iwl_he_backoff_conf *trig_based_txf) 2429 { 2430 int i; 2431 /* Mark MU EDCA as enabled, unless none detected on some AC */ 2432 bool mu_edca_enabled = true; 2433 2434 for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2435 const struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2436 &link_info->queue_params[i].mu_edca_param_rec; 2437 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 2438 2439 if (!link_info->queue_params[i].mu_edca) { 2440 mu_edca_enabled = false; 2441 break; 2442 } 2443 2444 trig_based_txf[ac].cwmin = 2445 cpu_to_le16(mu_edca->ecw_min_max & 0xf); 2446 trig_based_txf[ac].cwmax = 2447 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 2448 trig_based_txf[ac].aifsn = 2449 cpu_to_le16(mu_edca->aifsn & 0xf); 2450 trig_based_txf[ac].mu_time = 2451 cpu_to_le16(mu_edca->mu_edca_timer); 2452 } 2453 2454 return mu_edca_enabled; 2455 } 2456 2457 bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 2458 { 2459 const struct ieee80211_supported_band *sband; 2460 const struct ieee80211_sta_he_cap *own_he_cap = NULL; 2461 2462 /* This capability is the same for all bands, 2463 * so take it from one of them. 2464 */ 2465 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 2466 own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 2467 2468 return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] & 2469 IEEE80211_HE_MAC_CAP2_ACK_EN)); 2470 } 2471 2472 __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta, 2473 struct ieee80211_link_sta *link_sta) 2474 { 2475 u8 *mac_cap_info = 2476 &link_sta->he_cap.he_cap_elem.mac_cap_info[0]; 2477 __le32 htc_flags = 0; 2478 2479 if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) 2480 htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 2481 if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 2482 (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 2483 u8 link_adap = 2484 ((mac_cap_info[2] & 2485 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 2486 (mac_cap_info[1] & 2487 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 2488 2489 if (link_adap == 2) 2490 htc_flags |= 2491 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 2492 else if (link_adap == 3) 2493 htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 2494 } 2495 if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 2496 htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 2497 if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 2498 htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 2499 if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 2500 htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 2501 2502 return htc_flags; 2503 } 2504 2505 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 2506 struct ieee80211_vif *vif, u8 sta_id) 2507 { 2508 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2509 struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { 2510 .sta_id = sta_id, 2511 .tid_limit = IWL_MAX_TID_COUNT, 2512 .bss_color = vif->bss_conf.he_bss_color.color, 2513 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 2514 .frame_time_rts_th = 2515 cpu_to_le16(vif->bss_conf.frame_time_rts_th), 2516 }; 2517 struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; 2518 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); 2519 u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); 2520 int size; 2521 struct ieee80211_sta *sta; 2522 u32 flags; 2523 int i; 2524 void *cmd; 2525 2526 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) 2527 ver = 1; 2528 2529 switch (ver) { 2530 case 1: 2531 /* same layout as v2 except some data at the end */ 2532 cmd = &sta_ctxt_cmd_v2; 2533 size = sizeof(struct iwl_he_sta_context_cmd_v1); 2534 break; 2535 case 2: 2536 cmd = &sta_ctxt_cmd_v2; 2537 size = sizeof(struct iwl_he_sta_context_cmd_v2); 2538 break; 2539 case 3: 2540 cmd = &sta_ctxt_cmd; 2541 size = sizeof(struct iwl_he_sta_context_cmd_v3); 2542 break; 2543 default: 2544 IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); 2545 return; 2546 } 2547 2548 rcu_read_lock(); 2549 2550 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 2551 if (IS_ERR_OR_NULL(sta)) { 2552 rcu_read_unlock(); 2553 WARN(1, "Can't find STA to configure HE\n"); 2554 return; 2555 } 2556 2557 if (!sta->deflink.he_cap.has_he) { 2558 rcu_read_unlock(); 2559 return; 2560 } 2561 2562 flags = 0; 2563 2564 /* Block 26-tone RU OFDMA transmissions */ 2565 if (mvmvif->deflink.he_ru_2mhz_block) 2566 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 2567 2568 /* HTC flags */ 2569 sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta, &sta->deflink); 2570 2571 /* PPE Thresholds */ 2572 if (!iwl_mvm_set_sta_pkt_ext(mvm, &sta->deflink, &sta_ctxt_cmd.pkt_ext)) 2573 flags |= STA_CTXT_HE_PACKET_EXT; 2574 2575 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 2576 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 2577 flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 2578 2579 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 2580 IEEE80211_HE_MAC_CAP2_ACK_EN) 2581 flags |= STA_CTXT_HE_ACK_ENABLED; 2582 2583 rcu_read_unlock(); 2584 2585 if (iwl_mvm_set_fw_mu_edca_params(mvm, &mvmvif->deflink, 2586 &sta_ctxt_cmd.trig_based_txf[0])) 2587 flags |= STA_CTXT_HE_MU_EDCA_CW; 2588 2589 if (vif->bss_conf.uora_exists) { 2590 flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2591 2592 sta_ctxt_cmd.rand_alloc_ecwmin = 2593 vif->bss_conf.uora_ocw_range & 0x7; 2594 sta_ctxt_cmd.rand_alloc_ecwmax = 2595 (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2596 } 2597 2598 if (!iwl_mvm_is_nic_ack_enabled(mvm, vif)) 2599 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2600 2601 if (vif->bss_conf.nontransmitted) { 2602 flags |= STA_CTXT_HE_REF_BSSID_VALID; 2603 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2604 vif->bss_conf.transmitter_bssid); 2605 sta_ctxt_cmd.max_bssid_indicator = 2606 vif->bss_conf.bssid_indicator; 2607 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2608 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2609 sta_ctxt_cmd.profile_periodicity = 2610 vif->bss_conf.profile_periodicity; 2611 } 2612 2613 sta_ctxt_cmd.flags = cpu_to_le32(flags); 2614 2615 if (ver < 3) { 2616 /* fields before pkt_ext */ 2617 BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != 2618 offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); 2619 memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, 2620 offsetof(typeof(sta_ctxt_cmd), pkt_ext)); 2621 2622 /* pkt_ext */ 2623 for (i = 0; 2624 i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); 2625 i++) { 2626 u8 bw; 2627 2628 for (bw = 0; 2629 bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); 2630 bw++) { 2631 BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != 2632 sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); 2633 2634 memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], 2635 &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], 2636 sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); 2637 } 2638 } 2639 2640 /* fields after pkt_ext */ 2641 BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - 2642 offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != 2643 sizeof(sta_ctxt_cmd_v2) - 2644 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); 2645 memcpy((u8 *)&sta_ctxt_cmd_v2 + 2646 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), 2647 (u8 *)&sta_ctxt_cmd + 2648 offsetofend(typeof(sta_ctxt_cmd), pkt_ext), 2649 sizeof(sta_ctxt_cmd) - 2650 offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); 2651 sta_ctxt_cmd_v2.reserved3 = 0; 2652 } 2653 2654 if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) 2655 IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2656 } 2657 2658 void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2659 u32 duration_override, unsigned int link_id) 2660 { 2661 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2662 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2663 2664 if (duration_override > duration) 2665 duration = duration_override; 2666 2667 /* Try really hard to protect the session and hear a beacon 2668 * The new session protection command allows us to protect the 2669 * session for a much longer time since the firmware will internally 2670 * create two events: a 300TU one with a very high priority that 2671 * won't be fragmented which should be enough for 99% of the cases, 2672 * and another one (which we configure here to be 900TU long) which 2673 * will have a slightly lower priority, but more importantly, can be 2674 * fragmented so that it'll allow other activities to run. 2675 */ 2676 if (fw_has_capa(&mvm->fw->ucode_capa, 2677 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2678 iwl_mvm_schedule_session_protection(mvm, vif, 900, 2679 min_duration, false, 2680 link_id); 2681 else 2682 iwl_mvm_protect_session(mvm, vif, duration, 2683 min_duration, 500, false); 2684 } 2685 2686 /* Handle association common part to MLD and non-MLD modes */ 2687 void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm, 2688 struct ieee80211_vif *vif, 2689 u64 changes) 2690 { 2691 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2692 int ret; 2693 int link_id; 2694 2695 /* The firmware tracks the MU-MIMO group on its own. 2696 * However, on HW restart we should restore this data. 2697 */ 2698 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2699 (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { 2700 ret = iwl_mvm_update_mu_groups(mvm, vif); 2701 if (ret) 2702 IWL_ERR(mvm, 2703 "failed to update VHT MU_MIMO groups\n"); 2704 } 2705 2706 iwl_mvm_recalc_multicast(mvm); 2707 2708 /* reset rssi values */ 2709 for_each_mvm_vif_valid_link(mvmvif, link_id) 2710 mvmvif->link[link_id]->bf_data.ave_beacon_signal = 0; 2711 2712 iwl_mvm_bt_coex_vif_change(mvm); 2713 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2714 IEEE80211_SMPS_AUTOMATIC); 2715 if (fw_has_capa(&mvm->fw->ucode_capa, 2716 IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2717 iwl_mvm_config_scan(mvm); 2718 } 2719 2720 /* Execute the common part for MLD and non-MLD modes */ 2721 void 2722 iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm, 2723 struct ieee80211_vif *vif, 2724 struct ieee80211_bss_conf *link_conf, 2725 u64 changes) 2726 { 2727 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2728 int ret; 2729 2730 if (changes & BSS_CHANGED_BEACON_INFO) { 2731 /* We received a beacon from the associated AP so 2732 * remove the session protection. 2733 */ 2734 iwl_mvm_stop_session_protection(mvm, vif); 2735 2736 iwl_mvm_sf_update(mvm, vif, false); 2737 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 2738 } 2739 2740 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2741 /* Send power command on every beacon change, 2742 * because we may have not enabled beacon abort yet. 2743 */ 2744 BSS_CHANGED_BEACON_INFO)) { 2745 ret = iwl_mvm_power_update_mac(mvm); 2746 if (ret) 2747 IWL_ERR(mvm, "failed to update power mode\n"); 2748 } 2749 2750 if (changes & BSS_CHANGED_CQM) { 2751 struct iwl_mvm_vif_link_info *link_info = 2752 mvmvif->link[link_conf->link_id]; 2753 2754 IWL_DEBUG_MAC80211(mvm, "CQM info_changed\n"); 2755 if (link_info) 2756 link_info->bf_data.last_cqm_event = 0; 2757 2758 if (mvmvif->bf_enabled) { 2759 /* FIXME: need to update per link when FW API will 2760 * support it 2761 */ 2762 ret = iwl_mvm_enable_beacon_filter(mvm, vif); 2763 if (ret) 2764 IWL_ERR(mvm, 2765 "failed to update CQM thresholds\n"); 2766 } 2767 } 2768 2769 if (changes & BSS_CHANGED_BANDWIDTH) 2770 iwl_mvm_update_link_smps(vif, link_conf); 2771 2772 if (changes & BSS_CHANGED_TPE) { 2773 IWL_DEBUG_CALIB(mvm, "Changing TPE\n"); 2774 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif, 2775 link_conf, 2776 false); 2777 } 2778 } 2779 2780 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2781 struct ieee80211_vif *vif, 2782 struct ieee80211_bss_conf *bss_conf, 2783 u64 changes) 2784 { 2785 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2786 int ret; 2787 int i; 2788 2789 /* 2790 * Re-calculate the tsf id, as the leader-follower relations depend 2791 * on the beacon interval, which was not known when the station 2792 * interface was added. 2793 */ 2794 if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { 2795 if ((vif->bss_conf.he_support && 2796 !iwlwifi_mod_params.disable_11ax)) 2797 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 2798 2799 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2800 } 2801 2802 /* Update MU EDCA params */ 2803 if (changes & BSS_CHANGED_QOS && mvmvif->associated && 2804 vif->cfg.assoc && 2805 (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax)) 2806 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 2807 2808 /* 2809 * If we're not associated yet, take the (new) BSSID before associating 2810 * so the firmware knows. If we're already associated, then use the old 2811 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2812 * branch for disassociation below. 2813 */ 2814 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2815 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2816 2817 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid); 2818 if (ret) 2819 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2820 2821 /* after sending it once, adopt mac80211 data */ 2822 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2823 mvmvif->associated = vif->cfg.assoc; 2824 2825 if (changes & BSS_CHANGED_ASSOC) { 2826 if (vif->cfg.assoc) { 2827 /* clear statistics to get clean beacon counter */ 2828 iwl_mvm_request_statistics(mvm, true); 2829 for_each_mvm_vif_valid_link(mvmvif, i) 2830 memset(&mvmvif->link[i]->beacon_stats, 0, 2831 sizeof(mvmvif->link[i]->beacon_stats)); 2832 2833 /* add quota for this interface */ 2834 ret = iwl_mvm_update_quotas(mvm, true, NULL); 2835 if (ret) { 2836 IWL_ERR(mvm, "failed to update quotas\n"); 2837 return; 2838 } 2839 2840 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2841 &mvm->status) && 2842 !fw_has_capa(&mvm->fw->ucode_capa, 2843 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2844 /* 2845 * If we're restarting then the firmware will 2846 * obviously have lost synchronisation with 2847 * the AP. It will attempt to synchronise by 2848 * itself, but we can make it more reliable by 2849 * scheduling a session protection time event. 2850 * 2851 * The firmware needs to receive a beacon to 2852 * catch up with synchronisation, use 110% of 2853 * the beacon interval. 2854 * 2855 * Set a large maximum delay to allow for more 2856 * than a single interface. 2857 * 2858 * For new firmware versions, rely on the 2859 * firmware. This is relevant for DCM scenarios 2860 * only anyway. 2861 */ 2862 u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2863 iwl_mvm_protect_session(mvm, vif, dur, dur, 2864 5 * dur, false); 2865 } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2866 &mvm->status) && 2867 !vif->bss_conf.dtim_period) { 2868 /* 2869 * If we're not restarting and still haven't 2870 * heard a beacon (dtim period unknown) then 2871 * make sure we still have enough minimum time 2872 * remaining in the time event, since the auth 2873 * might actually have taken quite a while 2874 * (especially for SAE) and so the remaining 2875 * time could be small without us having heard 2876 * a beacon yet. 2877 */ 2878 iwl_mvm_protect_assoc(mvm, vif, 0, 0); 2879 } 2880 2881 iwl_mvm_sf_update(mvm, vif, false); 2882 iwl_mvm_power_vif_assoc(mvm, vif); 2883 if (vif->p2p) { 2884 iwl_mvm_update_smps(mvm, vif, 2885 IWL_MVM_SMPS_REQ_PROT, 2886 IEEE80211_SMPS_DYNAMIC, 0); 2887 } 2888 } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) { 2889 iwl_mvm_mei_host_disassociated(mvm); 2890 /* 2891 * If update fails - SF might be running in associated 2892 * mode while disassociated - which is forbidden. 2893 */ 2894 ret = iwl_mvm_sf_update(mvm, vif, false); 2895 WARN_ONCE(ret && 2896 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 2897 &mvm->status), 2898 "Failed to update SF upon disassociation\n"); 2899 2900 /* 2901 * If we get an assert during the connection (after the 2902 * station has been added, but before the vif is set 2903 * to associated), mac80211 will re-add the station and 2904 * then configure the vif. Since the vif is not 2905 * associated, we would remove the station here and 2906 * this would fail the recovery. 2907 */ 2908 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2909 &mvm->status)) { 2910 /* first remove remaining keys */ 2911 iwl_mvm_sec_key_remove_ap(mvm, vif, 2912 &mvmvif->deflink, 0); 2913 2914 /* 2915 * Remove AP station now that 2916 * the MAC is unassoc 2917 */ 2918 ret = iwl_mvm_rm_sta_id(mvm, vif, 2919 mvmvif->deflink.ap_sta_id); 2920 if (ret) 2921 IWL_ERR(mvm, 2922 "failed to remove AP station\n"); 2923 2924 mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA; 2925 } 2926 2927 /* remove quota for this interface */ 2928 ret = iwl_mvm_update_quotas(mvm, false, NULL); 2929 if (ret) 2930 IWL_ERR(mvm, "failed to update quotas\n"); 2931 2932 /* this will take the cleared BSSID from bss_conf */ 2933 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2934 if (ret) 2935 IWL_ERR(mvm, 2936 "failed to update MAC %pM (clear after unassoc)\n", 2937 vif->addr); 2938 } 2939 2940 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes); 2941 } 2942 2943 iwl_mvm_bss_info_changed_station_common(mvm, vif, &vif->bss_conf, 2944 changes); 2945 } 2946 2947 bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw, 2948 struct ieee80211_vif *vif, 2949 int *ret) 2950 { 2951 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2952 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2953 int i; 2954 2955 lockdep_assert_held(&mvm->mutex); 2956 2957 mvmvif->ap_assoc_sta_count = 0; 2958 2959 /* must be set before quota calculations */ 2960 mvmvif->ap_ibss_active = true; 2961 2962 /* send all the early keys to the device now */ 2963 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2964 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2965 2966 if (!key) 2967 continue; 2968 2969 mvmvif->ap_early_keys[i] = NULL; 2970 2971 *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2972 if (*ret) 2973 return true; 2974 } 2975 2976 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 2977 iwl_mvm_vif_set_low_latency(mvmvif, true, 2978 LOW_LATENCY_VIF_TYPE); 2979 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 2980 } 2981 2982 /* power updated needs to be done before quotas */ 2983 iwl_mvm_power_update_mac(mvm); 2984 2985 return false; 2986 } 2987 2988 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2989 struct ieee80211_vif *vif, 2990 struct ieee80211_bss_conf *link_conf) 2991 { 2992 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2993 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2994 int ret; 2995 2996 mutex_lock(&mvm->mutex); 2997 2998 /* 2999 * Re-calculate the tsf id, as the leader-follower relations depend on 3000 * the beacon interval, which was not known when the AP interface 3001 * was added. 3002 */ 3003 if (vif->type == NL80211_IFTYPE_AP) 3004 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 3005 3006 /* For older devices need to send beacon template before adding mac 3007 * context. For the newer, the beacon is a resource that belongs to a 3008 * MAC, so need to send beacon template after adding the mac. 3009 */ 3010 if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) { 3011 /* Add the mac context */ 3012 ret = iwl_mvm_mac_ctxt_add(mvm, vif); 3013 if (ret) 3014 goto out_unlock; 3015 3016 /* Send the beacon template */ 3017 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 3018 if (ret) 3019 goto out_unlock; 3020 } else { 3021 /* Send the beacon template */ 3022 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 3023 if (ret) 3024 goto out_unlock; 3025 3026 /* Add the mac context */ 3027 ret = iwl_mvm_mac_ctxt_add(mvm, vif); 3028 if (ret) 3029 goto out_unlock; 3030 } 3031 3032 /* Perform the binding */ 3033 ret = iwl_mvm_binding_add_vif(mvm, vif); 3034 if (ret) 3035 goto out_remove; 3036 3037 /* 3038 * This is not very nice, but the simplest: 3039 * For older FWs adding the mcast sta before the bcast station may 3040 * cause assert 0x2b00. 3041 * This is fixed in later FW so make the order of removal depend on 3042 * the TLV 3043 */ 3044 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 3045 ret = iwl_mvm_add_mcast_sta(mvm, vif); 3046 if (ret) 3047 goto out_unbind; 3048 /* 3049 * Send the bcast station. At this stage the TBTT and DTIM time 3050 * events are added and applied to the scheduler 3051 */ 3052 ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 3053 if (ret) { 3054 iwl_mvm_rm_mcast_sta(mvm, vif); 3055 goto out_unbind; 3056 } 3057 } else { 3058 /* 3059 * Send the bcast station. At this stage the TBTT and DTIM time 3060 * events are added and applied to the scheduler 3061 */ 3062 ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 3063 if (ret) 3064 goto out_unbind; 3065 ret = iwl_mvm_add_mcast_sta(mvm, vif); 3066 if (ret) { 3067 iwl_mvm_send_rm_bcast_sta(mvm, vif); 3068 goto out_unbind; 3069 } 3070 } 3071 3072 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) 3073 goto out_failed; 3074 3075 ret = iwl_mvm_update_quotas(mvm, false, NULL); 3076 if (ret) 3077 goto out_failed; 3078 3079 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 3080 if (vif->p2p && mvm->p2p_device_vif) 3081 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 3082 3083 iwl_mvm_bt_coex_vif_change(mvm); 3084 3085 /* we don't support TDLS during DCM */ 3086 if (iwl_mvm_phy_ctx_count(mvm) > 1) 3087 iwl_mvm_teardown_tdls_peers(mvm); 3088 3089 iwl_mvm_ftm_restart_responder(mvm, vif, &vif->bss_conf); 3090 3091 goto out_unlock; 3092 3093 out_failed: 3094 iwl_mvm_power_update_mac(mvm); 3095 mvmvif->ap_ibss_active = false; 3096 iwl_mvm_send_rm_bcast_sta(mvm, vif); 3097 iwl_mvm_rm_mcast_sta(mvm, vif); 3098 out_unbind: 3099 iwl_mvm_binding_remove_vif(mvm, vif); 3100 out_remove: 3101 iwl_mvm_mac_ctxt_remove(mvm, vif); 3102 out_unlock: 3103 mutex_unlock(&mvm->mutex); 3104 return ret; 3105 } 3106 3107 static int iwl_mvm_start_ap(struct ieee80211_hw *hw, 3108 struct ieee80211_vif *vif, 3109 struct ieee80211_bss_conf *link_conf) 3110 { 3111 return iwl_mvm_start_ap_ibss(hw, vif, link_conf); 3112 } 3113 3114 static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, 3115 struct ieee80211_vif *vif) 3116 { 3117 return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); 3118 } 3119 3120 /* Common part for MLD and non-MLD ops */ 3121 void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm, 3122 struct ieee80211_vif *vif) 3123 { 3124 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3125 3126 lockdep_assert_held(&mvm->mutex); 3127 3128 iwl_mvm_prepare_mac_removal(mvm, vif); 3129 3130 /* Handle AP stop while in CSA */ 3131 if (rcu_access_pointer(mvm->csa_vif) == vif) { 3132 iwl_mvm_remove_time_event(mvm, mvmvif, 3133 &mvmvif->time_event_data); 3134 RCU_INIT_POINTER(mvm->csa_vif, NULL); 3135 mvmvif->csa_countdown = false; 3136 } 3137 3138 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 3139 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 3140 mvm->csa_tx_block_bcn_timeout = 0; 3141 } 3142 3143 mvmvif->ap_ibss_active = false; 3144 mvm->ap_last_beacon_gp2 = 0; 3145 3146 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 3147 iwl_mvm_vif_set_low_latency(mvmvif, false, 3148 LOW_LATENCY_VIF_TYPE); 3149 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 3150 } 3151 3152 iwl_mvm_bt_coex_vif_change(mvm); 3153 } 3154 3155 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 3156 struct ieee80211_vif *vif, 3157 struct ieee80211_bss_conf *link_conf) 3158 { 3159 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3160 3161 guard(mvm)(mvm); 3162 3163 iwl_mvm_stop_ap_ibss_common(mvm, vif); 3164 3165 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 3166 if (vif->p2p && mvm->p2p_device_vif) 3167 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 3168 3169 iwl_mvm_update_quotas(mvm, false, NULL); 3170 3171 iwl_mvm_ftm_responder_clear(mvm, vif); 3172 3173 /* 3174 * This is not very nice, but the simplest: 3175 * For older FWs removing the mcast sta before the bcast station may 3176 * cause assert 0x2b00. 3177 * This is fixed in later FW (which will stop beaconing when removing 3178 * bcast station). 3179 * So make the order of removal depend on the TLV 3180 */ 3181 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 3182 iwl_mvm_rm_mcast_sta(mvm, vif); 3183 iwl_mvm_send_rm_bcast_sta(mvm, vif); 3184 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 3185 iwl_mvm_rm_mcast_sta(mvm, vif); 3186 iwl_mvm_binding_remove_vif(mvm, vif); 3187 3188 iwl_mvm_power_update_mac(mvm); 3189 3190 iwl_mvm_mac_ctxt_remove(mvm, vif); 3191 } 3192 3193 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, 3194 struct ieee80211_vif *vif, 3195 struct ieee80211_bss_conf *link_conf) 3196 { 3197 iwl_mvm_stop_ap_ibss(hw, vif, link_conf); 3198 } 3199 3200 static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, 3201 struct ieee80211_vif *vif) 3202 { 3203 iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); 3204 } 3205 3206 static void 3207 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 3208 struct ieee80211_vif *vif, 3209 struct ieee80211_bss_conf *bss_conf, 3210 u64 changes) 3211 { 3212 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3213 3214 /* Changes will be applied when the AP/IBSS is started */ 3215 if (!mvmvif->ap_ibss_active) 3216 return; 3217 3218 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 3219 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 3220 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 3221 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 3222 3223 /* Need to send a new beacon template to the FW */ 3224 if (changes & BSS_CHANGED_BEACON && 3225 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf)) 3226 IWL_WARN(mvm, "Failed updating beacon data\n"); 3227 3228 if (changes & BSS_CHANGED_FTM_RESPONDER) { 3229 int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf); 3230 3231 if (ret) 3232 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 3233 ret); 3234 } 3235 3236 } 3237 3238 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 3239 struct ieee80211_vif *vif, 3240 struct ieee80211_bss_conf *bss_conf, 3241 u64 changes) 3242 { 3243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3244 3245 guard(mvm)(mvm); 3246 3247 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 3248 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 3249 3250 switch (vif->type) { 3251 case NL80211_IFTYPE_STATION: 3252 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 3253 break; 3254 case NL80211_IFTYPE_AP: 3255 case NL80211_IFTYPE_ADHOC: 3256 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 3257 break; 3258 case NL80211_IFTYPE_MONITOR: 3259 if (changes & BSS_CHANGED_MU_GROUPS) 3260 iwl_mvm_update_mu_groups(mvm, vif); 3261 break; 3262 default: 3263 /* shouldn't happen */ 3264 WARN_ON_ONCE(1); 3265 } 3266 3267 if (changes & BSS_CHANGED_TXPOWER) { 3268 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 3269 bss_conf->txpower); 3270 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 3271 } 3272 } 3273 3274 int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3275 struct ieee80211_scan_request *hw_req) 3276 { 3277 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3278 3279 if (hw_req->req.n_channels == 0 || 3280 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 3281 return -EINVAL; 3282 3283 guard(mvm)(mvm); 3284 return iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 3285 } 3286 3287 void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 3288 struct ieee80211_vif *vif) 3289 { 3290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3291 3292 guard(mvm)(mvm); 3293 3294 /* Due to a race condition, it's possible that mac80211 asks 3295 * us to stop a hw_scan when it's already stopped. This can 3296 * happen, for instance, if we stopped the scan ourselves, 3297 * called ieee80211_scan_completed() and the userspace called 3298 * cancel scan scan before ieee80211_scan_work() could run. 3299 * To handle that, simply return if the scan is not running. 3300 */ 3301 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 3302 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 3303 } 3304 3305 void 3306 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 3307 struct ieee80211_sta *sta, u16 tids, 3308 int num_frames, 3309 enum ieee80211_frame_release_type reason, 3310 bool more_data) 3311 { 3312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3313 3314 /* Called when we need to transmit (a) frame(s) from mac80211 */ 3315 3316 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3317 tids, more_data, false); 3318 } 3319 3320 void 3321 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 3322 struct ieee80211_sta *sta, u16 tids, 3323 int num_frames, 3324 enum ieee80211_frame_release_type reason, 3325 bool more_data) 3326 { 3327 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3328 3329 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 3330 3331 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3332 tids, more_data, true); 3333 } 3334 3335 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 3336 enum sta_notify_cmd cmd, 3337 struct ieee80211_sta *sta) 3338 { 3339 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3340 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3341 unsigned long txqs = 0, tids = 0; 3342 int tid; 3343 3344 /* 3345 * If we have TVQM then we get too high queue numbers - luckily 3346 * we really shouldn't get here with that because such hardware 3347 * should have firmware supporting buffer station offload. 3348 */ 3349 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 3350 return; 3351 3352 spin_lock_bh(&mvmsta->lock); 3353 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 3354 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 3355 3356 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 3357 continue; 3358 3359 __set_bit(tid_data->txq_id, &txqs); 3360 3361 if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 3362 continue; 3363 3364 __set_bit(tid, &tids); 3365 } 3366 3367 switch (cmd) { 3368 case STA_NOTIFY_SLEEP: 3369 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 3370 ieee80211_sta_set_buffered(sta, tid, true); 3371 3372 if (txqs) 3373 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 3374 /* 3375 * The fw updates the STA to be asleep. Tx packets on the Tx 3376 * queues to this station will not be transmitted. The fw will 3377 * send a Tx response with TX_STATUS_FAIL_DEST_PS. 3378 */ 3379 break; 3380 case STA_NOTIFY_AWAKE: 3381 if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA)) 3382 break; 3383 3384 if (txqs) 3385 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 3386 iwl_mvm_sta_modify_ps_wake(mvm, sta); 3387 break; 3388 default: 3389 break; 3390 } 3391 spin_unlock_bh(&mvmsta->lock); 3392 } 3393 3394 void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3395 enum sta_notify_cmd cmd, struct ieee80211_sta *sta) 3396 { 3397 __iwl_mvm_mac_sta_notify(hw, cmd, sta); 3398 } 3399 3400 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 3401 { 3402 struct iwl_rx_packet *pkt = rxb_addr(rxb); 3403 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 3404 struct ieee80211_sta *sta; 3405 struct iwl_mvm_sta *mvmsta; 3406 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 3407 3408 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 3409 return; 3410 3411 rcu_read_lock(); 3412 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 3413 if (WARN_ON(IS_ERR_OR_NULL(sta))) { 3414 rcu_read_unlock(); 3415 return; 3416 } 3417 3418 mvmsta = iwl_mvm_sta_from_mac80211(sta); 3419 3420 if (!mvmsta->vif || 3421 mvmsta->vif->type != NL80211_IFTYPE_AP) { 3422 rcu_read_unlock(); 3423 return; 3424 } 3425 3426 if (mvmsta->sleeping != sleeping) { 3427 mvmsta->sleeping = sleeping; 3428 __iwl_mvm_mac_sta_notify(mvm->hw, 3429 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 3430 sta); 3431 ieee80211_sta_ps_transition(sta, sleeping); 3432 } 3433 3434 if (sleeping) { 3435 switch (notif->type) { 3436 case IWL_MVM_PM_EVENT_AWAKE: 3437 case IWL_MVM_PM_EVENT_ASLEEP: 3438 break; 3439 case IWL_MVM_PM_EVENT_UAPSD: 3440 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 3441 break; 3442 case IWL_MVM_PM_EVENT_PS_POLL: 3443 ieee80211_sta_pspoll(sta); 3444 break; 3445 default: 3446 break; 3447 } 3448 } 3449 3450 rcu_read_unlock(); 3451 } 3452 3453 void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 3454 struct ieee80211_vif *vif, 3455 struct ieee80211_sta *sta) 3456 { 3457 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3458 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3459 unsigned int link_id; 3460 3461 /* 3462 * This is called before mac80211 does RCU synchronisation, 3463 * so here we already invalidate our internal RCU-protected 3464 * station pointer. The rest of the code will thus no longer 3465 * be able to find the station this way, and we don't rely 3466 * on further RCU synchronisation after the sta_state() 3467 * callback deleted the station. 3468 * Since there's mvm->mutex here, no need to have RCU lock for 3469 * mvm_sta->link access. 3470 */ 3471 guard(mvm)(mvm); 3472 for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) { 3473 struct iwl_mvm_link_sta *link_sta; 3474 u32 sta_id; 3475 3476 if (!mvm_sta->link[link_id]) 3477 continue; 3478 3479 link_sta = rcu_dereference_protected(mvm_sta->link[link_id], 3480 lockdep_is_held(&mvm->mutex)); 3481 sta_id = link_sta->sta_id; 3482 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[sta_id])) { 3483 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], 3484 ERR_PTR(-ENOENT)); 3485 RCU_INIT_POINTER(mvm->fw_id_to_link_sta[sta_id], NULL); 3486 } 3487 } 3488 } 3489 3490 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 3491 const u8 *bssid) 3492 { 3493 int i; 3494 3495 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3496 struct iwl_mvm_tcm_mac *mdata; 3497 3498 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 3499 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 3500 mdata->opened_rx_ba_sessions = false; 3501 } 3502 3503 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 3504 return; 3505 3506 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 3507 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3508 return; 3509 } 3510 3511 if (!vif->p2p && 3512 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 3513 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3514 return; 3515 } 3516 3517 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 3518 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 3519 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3520 return; 3521 } 3522 } 3523 3524 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 3525 } 3526 3527 static void 3528 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 3529 struct ieee80211_vif *vif, u8 *peer_addr, 3530 enum nl80211_tdls_operation action) 3531 { 3532 struct iwl_fw_dbg_trigger_tlv *trig; 3533 struct iwl_fw_dbg_trigger_tdls *tdls_trig; 3534 3535 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 3536 FW_DBG_TRIGGER_TDLS); 3537 if (!trig) 3538 return; 3539 3540 tdls_trig = (void *)trig->data; 3541 3542 if (!(tdls_trig->action_bitmap & BIT(action))) 3543 return; 3544 3545 if (tdls_trig->peer_mode && 3546 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 3547 return; 3548 3549 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 3550 "TDLS event occurred, peer %pM, action %d", 3551 peer_addr, action); 3552 } 3553 3554 struct iwl_mvm_he_obss_narrow_bw_ru_data { 3555 bool tolerated; 3556 }; 3557 3558 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 3559 struct cfg80211_bss *bss, 3560 void *_data) 3561 { 3562 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 3563 const struct cfg80211_bss_ies *ies; 3564 const struct element *elem; 3565 3566 rcu_read_lock(); 3567 ies = rcu_dereference(bss->ies); 3568 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 3569 ies->len); 3570 3571 if (!elem || elem->datalen < 10 || 3572 !(elem->data[10] & 3573 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 3574 data->tolerated = false; 3575 } 3576 rcu_read_unlock(); 3577 } 3578 3579 static void 3580 iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 3581 struct ieee80211_vif *vif, 3582 unsigned int link_id, 3583 struct ieee80211_bss_conf *link_conf) 3584 { 3585 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3586 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 3587 .tolerated = true, 3588 }; 3589 3590 if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan || 3591 !mvmvif->link[link_id])) 3592 return; 3593 3594 if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) { 3595 mvmvif->link[link_id]->he_ru_2mhz_block = false; 3596 return; 3597 } 3598 3599 cfg80211_bss_iter(hw->wiphy, &link_conf->chanreq.oper, 3600 iwl_mvm_check_he_obss_narrow_bw_ru_iter, 3601 &iter_data); 3602 3603 /* 3604 * If there is at least one AP on radar channel that cannot 3605 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 3606 */ 3607 mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated; 3608 } 3609 3610 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3611 struct ieee80211_vif *vif) 3612 { 3613 struct ieee80211_supported_band *sband; 3614 const struct ieee80211_sta_he_cap *he_cap; 3615 3616 if (vif->type != NL80211_IFTYPE_STATION) 3617 return; 3618 3619 if (!mvm->cca_40mhz_workaround) 3620 return; 3621 3622 /* decrement and check that we reached zero */ 3623 mvm->cca_40mhz_workaround--; 3624 if (mvm->cca_40mhz_workaround) 3625 return; 3626 3627 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3628 3629 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3630 3631 he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 3632 3633 if (he_cap) { 3634 /* we know that ours is writable */ 3635 struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; 3636 3637 he->he_cap_elem.phy_cap_info[0] |= 3638 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3639 } 3640 } 3641 3642 static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 3643 struct ieee80211_vif *vif, 3644 struct iwl_mvm_sta *mvm_sta) 3645 { 3646 #if IS_ENABLED(CONFIG_IWLMEI) 3647 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3648 struct iwl_mei_conn_info conn_info = { 3649 .ssid_len = vif->cfg.ssid_len, 3650 }; 3651 3652 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 3653 return; 3654 3655 if (!mvm->mei_registered) 3656 return; 3657 3658 /* FIXME: MEI needs to be updated for MLO */ 3659 if (!vif->bss_conf.chanreq.oper.chan) 3660 return; 3661 3662 conn_info.channel = vif->bss_conf.chanreq.oper.chan->hw_value; 3663 3664 switch (mvm_sta->pairwise_cipher) { 3665 case WLAN_CIPHER_SUITE_TKIP: 3666 conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP; 3667 break; 3668 case WLAN_CIPHER_SUITE_CCMP: 3669 conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 3670 break; 3671 case WLAN_CIPHER_SUITE_GCMP: 3672 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 3673 break; 3674 case WLAN_CIPHER_SUITE_GCMP_256: 3675 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 3676 break; 3677 case 0: 3678 /* open profile */ 3679 break; 3680 default: 3681 /* cipher not supported, don't send anything to iwlmei */ 3682 return; 3683 } 3684 3685 switch (mvmvif->rekey_data.akm) { 3686 case WLAN_AKM_SUITE_SAE & 0xff: 3687 conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 3688 break; 3689 case WLAN_AKM_SUITE_PSK & 0xff: 3690 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 3691 break; 3692 case WLAN_AKM_SUITE_8021X & 0xff: 3693 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 3694 break; 3695 case 0: 3696 /* open profile */ 3697 conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 3698 break; 3699 default: 3700 /* auth method / AKM not supported */ 3701 /* TODO: All the FT vesions of these? */ 3702 return; 3703 } 3704 3705 memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 3706 memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 3707 3708 /* TODO: add support for collocated AP data */ 3709 iwl_mei_host_associated(&conn_info, NULL); 3710 #endif 3711 } 3712 3713 static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm, 3714 struct ieee80211_vif *vif, 3715 bool force_assoc_off) 3716 { 3717 return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL); 3718 } 3719 3720 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3721 struct ieee80211_vif *vif, 3722 struct ieee80211_sta *sta, 3723 enum ieee80211_sta_state old_state, 3724 enum ieee80211_sta_state new_state) 3725 { 3726 static const struct iwl_mvm_sta_state_ops callbacks = { 3727 .add_sta = iwl_mvm_add_sta, 3728 .update_sta = iwl_mvm_update_sta, 3729 .rm_sta = iwl_mvm_rm_sta, 3730 .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper, 3731 }; 3732 3733 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state, 3734 &callbacks); 3735 } 3736 3737 /* FIXME: temporary making two assumptions in all sta handling functions: 3738 * (1) when setting sta state, the link exists and protected 3739 * (2) if a link is valid in sta then it's valid in vif (can 3740 * use same index in the link array) 3741 */ 3742 static void iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm, 3743 struct ieee80211_vif *vif, 3744 struct ieee80211_sta *sta) 3745 { 3746 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3747 unsigned int link_id; 3748 3749 for_each_mvm_vif_valid_link(mvmvif, link_id) { 3750 struct ieee80211_bss_conf *conf = 3751 link_conf_dereference_check(vif, link_id); 3752 struct ieee80211_link_sta *link_sta = 3753 link_sta_dereference_check(sta, link_id); 3754 3755 if (!conf || !link_sta || !mvmvif->link[link_id]->phy_ctxt) 3756 continue; 3757 3758 iwl_mvm_rs_rate_init(mvm, vif, sta, conf, link_sta, 3759 mvmvif->link[link_id]->phy_ctxt->channel->band); 3760 } 3761 } 3762 3763 static bool iwl_mvm_vif_conf_from_sta(struct iwl_mvm *mvm, 3764 struct ieee80211_vif *vif, 3765 struct ieee80211_sta *sta) 3766 { 3767 struct ieee80211_link_sta *link_sta; 3768 unsigned int link_id; 3769 3770 /* Beacon interval check - firmware will crash if the beacon 3771 * interval is less than 16. We can't avoid connecting at all, 3772 * so refuse the station state change, this will cause mac80211 3773 * to abandon attempts to connect to this AP, and eventually 3774 * wpa_s will blocklist the AP... 3775 */ 3776 3777 for_each_sta_active_link(vif, sta, link_sta, link_id) { 3778 struct ieee80211_bss_conf *link_conf = 3779 link_conf_dereference_protected(vif, link_id); 3780 3781 if (!link_conf) 3782 continue; 3783 3784 if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) { 3785 IWL_ERR(mvm, 3786 "Beacon interval %d for AP %pM is too small\n", 3787 link_conf->beacon_int, link_sta->addr); 3788 return false; 3789 } 3790 3791 link_conf->he_support = link_sta->he_cap.has_he; 3792 } 3793 3794 return true; 3795 } 3796 3797 static void iwl_mvm_vif_set_he_support(struct ieee80211_hw *hw, 3798 struct ieee80211_vif *vif, 3799 struct ieee80211_sta *sta, 3800 bool is_sta) 3801 { 3802 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3803 struct ieee80211_link_sta *link_sta; 3804 unsigned int link_id; 3805 3806 for_each_sta_active_link(vif, sta, link_sta, link_id) { 3807 struct ieee80211_bss_conf *link_conf = 3808 link_conf_dereference_protected(vif, link_id); 3809 3810 if (!link_conf || !mvmvif->link[link_id]) 3811 continue; 3812 3813 link_conf->he_support = link_sta->he_cap.has_he; 3814 3815 if (is_sta) { 3816 mvmvif->link[link_id]->he_ru_2mhz_block = false; 3817 if (link_sta->he_cap.has_he) 3818 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif, 3819 link_id, 3820 link_conf); 3821 } 3822 } 3823 } 3824 3825 static int 3826 iwl_mvm_sta_state_notexist_to_none(struct iwl_mvm *mvm, 3827 struct ieee80211_vif *vif, 3828 struct ieee80211_sta *sta, 3829 const struct iwl_mvm_sta_state_ops *callbacks) 3830 { 3831 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3832 struct ieee80211_link_sta *link_sta; 3833 unsigned int i; 3834 int ret; 3835 3836 lockdep_assert_held(&mvm->mutex); 3837 3838 if (vif->type == NL80211_IFTYPE_STATION && 3839 !iwl_mvm_vif_conf_from_sta(mvm, vif, sta)) 3840 return -EINVAL; 3841 3842 if (sta->tdls && 3843 (vif->p2p || 3844 iwl_mvm_tdls_sta_count(mvm, NULL) == IWL_MVM_TDLS_STA_COUNT || 3845 iwl_mvm_phy_ctx_count(mvm) > 1)) { 3846 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 3847 return -EBUSY; 3848 } 3849 3850 ret = callbacks->add_sta(mvm, vif, sta); 3851 if (sta->tdls && ret == 0) { 3852 iwl_mvm_recalc_tdls_state(mvm, vif, true); 3853 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 3854 NL80211_TDLS_SETUP); 3855 } 3856 3857 if (ret) 3858 return ret; 3859 3860 for_each_sta_active_link(vif, sta, link_sta, i) 3861 link_sta->agg.max_rc_amsdu_len = 1; 3862 3863 ieee80211_sta_recalc_aggregates(sta); 3864 3865 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3866 mvmvif->ap_sta = sta; 3867 3868 /* 3869 * Initialize the rates here already - this really tells 3870 * the firmware only what the supported legacy rates are 3871 * (may be) since it's initialized already from what the 3872 * AP advertised in the beacon/probe response. This will 3873 * allow the firmware to send auth/assoc frames with one 3874 * of the supported rates already, rather than having to 3875 * use a mandatory rate. 3876 * If we're the AP, we'll just assume mandatory rates at 3877 * this point, but we know nothing about the STA anyway. 3878 */ 3879 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 3880 3881 return 0; 3882 } 3883 3884 static int 3885 iwl_mvm_sta_state_auth_to_assoc(struct ieee80211_hw *hw, 3886 struct iwl_mvm *mvm, 3887 struct ieee80211_vif *vif, 3888 struct ieee80211_sta *sta, 3889 const struct iwl_mvm_sta_state_ops *callbacks) 3890 { 3891 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3892 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3893 struct ieee80211_link_sta *link_sta; 3894 unsigned int link_id; 3895 3896 lockdep_assert_held(&mvm->mutex); 3897 3898 if (vif->type == NL80211_IFTYPE_AP) { 3899 iwl_mvm_vif_set_he_support(hw, vif, sta, false); 3900 mvmvif->ap_assoc_sta_count++; 3901 callbacks->mac_ctxt_changed(mvm, vif, false); 3902 3903 /* since the below is not for MLD API, it's ok to use 3904 * the default bss_conf 3905 */ 3906 if (!mvm->mld_api_is_used && 3907 (vif->bss_conf.he_support && 3908 !iwlwifi_mod_params.disable_11ax)) 3909 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id); 3910 } else if (vif->type == NL80211_IFTYPE_STATION) { 3911 iwl_mvm_vif_set_he_support(hw, vif, sta, true); 3912 3913 callbacks->mac_ctxt_changed(mvm, vif, false); 3914 3915 if (!mvm->mld_api_is_used) 3916 goto out; 3917 3918 for_each_sta_active_link(vif, sta, link_sta, link_id) { 3919 struct ieee80211_bss_conf *link_conf = 3920 link_conf_dereference_protected(vif, link_id); 3921 3922 if (WARN_ON(!link_conf)) 3923 return -EINVAL; 3924 if (!mvmvif->link[link_id]) 3925 continue; 3926 3927 iwl_mvm_link_changed(mvm, vif, link_conf, 3928 LINK_CONTEXT_MODIFY_ALL & 3929 ~LINK_CONTEXT_MODIFY_ACTIVE, 3930 true); 3931 } 3932 } 3933 3934 out: 3935 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 3936 3937 return callbacks->update_sta(mvm, vif, sta); 3938 } 3939 3940 static int 3941 iwl_mvm_sta_state_assoc_to_authorized(struct iwl_mvm *mvm, 3942 struct ieee80211_vif *vif, 3943 struct ieee80211_sta *sta, 3944 const struct iwl_mvm_sta_state_ops *callbacks) 3945 { 3946 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3947 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3948 3949 lockdep_assert_held(&mvm->mutex); 3950 3951 /* we don't support TDLS during DCM */ 3952 if (iwl_mvm_phy_ctx_count(mvm) > 1) 3953 iwl_mvm_teardown_tdls_peers(mvm); 3954 3955 if (sta->tdls) { 3956 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 3957 NL80211_TDLS_ENABLE_LINK); 3958 } else { 3959 /* enable beacon filtering */ 3960 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 3961 3962 mvmvif->authorized = 1; 3963 3964 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3965 mvmvif->link_selection_res = vif->active_links; 3966 mvmvif->link_selection_primary = 3967 vif->active_links ? __ffs(vif->active_links) : 0; 3968 } 3969 3970 callbacks->mac_ctxt_changed(mvm, vif, false); 3971 iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 3972 3973 memset(&mvmvif->last_esr_exit, 0, 3974 sizeof(mvmvif->last_esr_exit)); 3975 3976 iwl_mvm_block_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_TPT, 0); 3977 3978 /* Block until FW notif will arrive */ 3979 iwl_mvm_block_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW, 0); 3980 3981 /* when client is authorized (AP station marked as such), 3982 * try to enable the best link(s). 3983 */ 3984 if (vif->type == NL80211_IFTYPE_STATION && 3985 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 3986 iwl_mvm_select_links(mvm, vif); 3987 } 3988 3989 mvm_sta->authorized = true; 3990 3991 /* MFP is set by default before the station is authorized. 3992 * Clear it here in case it's not used. 3993 */ 3994 if (!sta->mfp) { 3995 int ret = callbacks->update_sta(mvm, vif, sta); 3996 3997 if (ret) 3998 return ret; 3999 } 4000 4001 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 4002 4003 return 0; 4004 } 4005 4006 static int 4007 iwl_mvm_sta_state_authorized_to_assoc(struct iwl_mvm *mvm, 4008 struct ieee80211_vif *vif, 4009 struct ieee80211_sta *sta, 4010 const struct iwl_mvm_sta_state_ops *callbacks) 4011 { 4012 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4013 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 4014 4015 lockdep_assert_held(&mvm->mutex); 4016 4017 mvmsta->authorized = false; 4018 4019 /* once we move into assoc state, need to update rate scale to 4020 * disable using wide bandwidth 4021 */ 4022 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 4023 4024 if (!sta->tdls) { 4025 /* Set this but don't call iwl_mvm_mac_ctxt_changed() 4026 * yet to avoid sending high prio again for a little 4027 * time. 4028 */ 4029 mvmvif->authorized = 0; 4030 mvmvif->link_selection_res = 0; 4031 4032 /* disable beacon filtering */ 4033 iwl_mvm_disable_beacon_filter(mvm, vif); 4034 4035 wiphy_delayed_work_cancel(mvm->hw->wiphy, 4036 &mvmvif->prevent_esr_done_wk); 4037 4038 wiphy_delayed_work_cancel(mvm->hw->wiphy, 4039 &mvmvif->mlo_int_scan_wk); 4040 4041 wiphy_work_cancel(mvm->hw->wiphy, &mvmvif->unblock_esr_tpt_wk); 4042 4043 /* No need for the periodic statistics anymore */ 4044 if (ieee80211_vif_is_mld(vif) && mvmvif->esr_active) 4045 iwl_mvm_request_periodic_system_statistics(mvm, false); 4046 } 4047 4048 return 0; 4049 } 4050 4051 /* Common part for MLD and non-MLD modes */ 4052 int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw, 4053 struct ieee80211_vif *vif, 4054 struct ieee80211_sta *sta, 4055 enum ieee80211_sta_state old_state, 4056 enum ieee80211_sta_state new_state, 4057 const struct iwl_mvm_sta_state_ops *callbacks) 4058 { 4059 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4060 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4061 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 4062 struct ieee80211_link_sta *link_sta; 4063 unsigned int link_id; 4064 int ret; 4065 4066 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 4067 sta->addr, old_state, new_state); 4068 4069 /* 4070 * If we are in a STA removal flow and in DQA mode: 4071 * 4072 * This is after the sync_rcu part, so the queues have already been 4073 * flushed. No more TXs on their way in mac80211's path, and no more in 4074 * the queues. 4075 * Also, we won't be getting any new TX frames for this station. 4076 * What we might have are deferred TX frames that need to be taken care 4077 * of. 4078 * 4079 * Drop any still-queued deferred-frame before removing the STA, and 4080 * make sure the worker is no longer handling frames for this STA. 4081 */ 4082 if (old_state == IEEE80211_STA_NONE && 4083 new_state == IEEE80211_STA_NOTEXIST) { 4084 flush_work(&mvm->add_stream_wk); 4085 4086 /* 4087 * No need to make sure deferred TX indication is off since the 4088 * worker will already remove it if it was on 4089 */ 4090 4091 /* 4092 * Additionally, reset the 40 MHz capability if we disconnected 4093 * from the AP now. 4094 */ 4095 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 4096 4097 /* Also free dup data just in case any assertions below fail */ 4098 kfree(mvm_sta->dup_data); 4099 } 4100 4101 mutex_lock(&mvm->mutex); 4102 4103 /* this would be a mac80211 bug ... but don't crash, unless we had a 4104 * firmware crash while we were activating a link, in which case it is 4105 * legit to have phy_ctxt = NULL. Don't bother not to WARN if we are in 4106 * recovery flow since we spit tons of error messages anyway. 4107 */ 4108 for_each_sta_active_link(vif, sta, link_sta, link_id) { 4109 if (WARN_ON_ONCE(!mvmvif->link[link_id] || 4110 !mvmvif->link[link_id]->phy_ctxt)) { 4111 mutex_unlock(&mvm->mutex); 4112 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 4113 &mvm->status) ? 0 : -EINVAL; 4114 } 4115 } 4116 4117 /* track whether or not the station is associated */ 4118 mvm_sta->sta_state = new_state; 4119 4120 if (old_state == IEEE80211_STA_NOTEXIST && 4121 new_state == IEEE80211_STA_NONE) { 4122 ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta, 4123 callbacks); 4124 if (ret < 0) 4125 goto out_unlock; 4126 } else if (old_state == IEEE80211_STA_NONE && 4127 new_state == IEEE80211_STA_AUTH) { 4128 /* 4129 * EBS may be disabled due to previous failures reported by FW. 4130 * Reset EBS status here assuming environment has been changed. 4131 */ 4132 mvm->last_ebs_successful = true; 4133 iwl_mvm_check_uapsd(mvm, vif, sta->addr); 4134 ret = 0; 4135 } else if (old_state == IEEE80211_STA_AUTH && 4136 new_state == IEEE80211_STA_ASSOC) { 4137 ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta, 4138 callbacks); 4139 } else if (old_state == IEEE80211_STA_ASSOC && 4140 new_state == IEEE80211_STA_AUTHORIZED) { 4141 ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta, 4142 callbacks); 4143 } else if (old_state == IEEE80211_STA_AUTHORIZED && 4144 new_state == IEEE80211_STA_ASSOC) { 4145 ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta, 4146 callbacks); 4147 } else if (old_state == IEEE80211_STA_ASSOC && 4148 new_state == IEEE80211_STA_AUTH) { 4149 if (vif->type == NL80211_IFTYPE_AP) { 4150 mvmvif->ap_assoc_sta_count--; 4151 callbacks->mac_ctxt_changed(mvm, vif, false); 4152 } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 4153 iwl_mvm_stop_session_protection(mvm, vif); 4154 ret = 0; 4155 } else if (old_state == IEEE80211_STA_AUTH && 4156 new_state == IEEE80211_STA_NONE) { 4157 ret = 0; 4158 } else if (old_state == IEEE80211_STA_NONE && 4159 new_state == IEEE80211_STA_NOTEXIST) { 4160 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) { 4161 iwl_mvm_stop_session_protection(mvm, vif); 4162 mvmvif->ap_sta = NULL; 4163 } 4164 ret = callbacks->rm_sta(mvm, vif, sta); 4165 if (sta->tdls) { 4166 iwl_mvm_recalc_tdls_state(mvm, vif, false); 4167 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 4168 NL80211_TDLS_DISABLE_LINK); 4169 } 4170 4171 if (unlikely(ret && 4172 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 4173 &mvm->status))) 4174 ret = 0; 4175 } else { 4176 ret = -EIO; 4177 } 4178 out_unlock: 4179 mutex_unlock(&mvm->mutex); 4180 4181 if (sta->tdls && ret == 0) { 4182 if (old_state == IEEE80211_STA_NOTEXIST && 4183 new_state == IEEE80211_STA_NONE) 4184 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4185 else if (old_state == IEEE80211_STA_NONE && 4186 new_state == IEEE80211_STA_NOTEXIST) 4187 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4188 } 4189 4190 return ret; 4191 } 4192 4193 int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 4194 { 4195 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4196 4197 mvm->rts_threshold = value; 4198 4199 return 0; 4200 } 4201 4202 void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4203 struct ieee80211_sta *sta, u32 changed) 4204 { 4205 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4206 4207 if (changed & (IEEE80211_RC_BW_CHANGED | 4208 IEEE80211_RC_SUPP_RATES_CHANGED | 4209 IEEE80211_RC_NSS_CHANGED)) 4210 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 4211 4212 if (vif->type == NL80211_IFTYPE_STATION && 4213 changed & IEEE80211_RC_NSS_CHANGED) 4214 iwl_mvm_sf_update(mvm, vif, false); 4215 } 4216 4217 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 4218 struct ieee80211_vif *vif, 4219 unsigned int link_id, u16 ac, 4220 const struct ieee80211_tx_queue_params *params) 4221 { 4222 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4223 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4224 4225 mvmvif->deflink.queue_params[ac] = *params; 4226 4227 /* 4228 * No need to update right away, we'll get BSS_CHANGED_QOS 4229 * The exception is P2P_DEVICE interface which needs immediate update. 4230 */ 4231 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 4232 guard(mvm)(mvm); 4233 return iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4234 } 4235 return 0; 4236 } 4237 4238 void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 4239 struct ieee80211_vif *vif, 4240 struct ieee80211_prep_tx_info *info) 4241 { 4242 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4243 4244 guard(mvm)(mvm); 4245 iwl_mvm_protect_assoc(mvm, vif, info->duration, info->link_id); 4246 } 4247 4248 void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 4249 struct ieee80211_vif *vif, 4250 struct ieee80211_prep_tx_info *info) 4251 { 4252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4253 4254 /* for successful cases (auth/assoc), don't cancel session protection */ 4255 if (info->success) 4256 return; 4257 4258 guard(mvm)(mvm); 4259 iwl_mvm_stop_session_protection(mvm, vif); 4260 } 4261 4262 int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 4263 struct ieee80211_vif *vif, 4264 struct cfg80211_sched_scan_request *req, 4265 struct ieee80211_scan_ies *ies) 4266 { 4267 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4268 4269 guard(mvm)(mvm); 4270 4271 if (!vif->cfg.idle) 4272 return -EBUSY; 4273 4274 return iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 4275 } 4276 4277 int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 4278 struct ieee80211_vif *vif) 4279 { 4280 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4281 int ret; 4282 4283 mutex_lock(&mvm->mutex); 4284 4285 /* Due to a race condition, it's possible that mac80211 asks 4286 * us to stop a sched_scan when it's already stopped. This 4287 * can happen, for instance, if we stopped the scan ourselves, 4288 * called ieee80211_sched_scan_stopped() and the userspace called 4289 * stop sched scan scan before ieee80211_sched_scan_stopped_work() 4290 * could run. To handle this, simply return if the scan is 4291 * not running. 4292 */ 4293 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 4294 mutex_unlock(&mvm->mutex); 4295 return 0; 4296 } 4297 4298 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 4299 mutex_unlock(&mvm->mutex); 4300 iwl_mvm_wait_for_async_handlers(mvm); 4301 4302 return ret; 4303 } 4304 4305 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 4306 enum set_key_cmd cmd, 4307 struct ieee80211_vif *vif, 4308 struct ieee80211_sta *sta, 4309 struct ieee80211_key_conf *key) 4310 { 4311 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4313 struct iwl_mvm_sta *mvmsta = NULL; 4314 struct iwl_mvm_key_pn *ptk_pn = NULL; 4315 int keyidx = key->keyidx; 4316 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 4317 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 4318 int ret, i; 4319 u8 key_offset; 4320 4321 if (sta) 4322 mvmsta = iwl_mvm_sta_from_mac80211(sta); 4323 4324 switch (key->cipher) { 4325 case WLAN_CIPHER_SUITE_TKIP: 4326 if (!mvm->trans->trans_cfg->gen2) { 4327 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 4328 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 4329 } else if (vif->type == NL80211_IFTYPE_STATION) { 4330 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 4331 } else { 4332 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 4333 return -EOPNOTSUPP; 4334 } 4335 break; 4336 case WLAN_CIPHER_SUITE_CCMP: 4337 case WLAN_CIPHER_SUITE_GCMP: 4338 case WLAN_CIPHER_SUITE_GCMP_256: 4339 if (!iwl_mvm_has_new_tx_api(mvm)) 4340 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 4341 break; 4342 case WLAN_CIPHER_SUITE_AES_CMAC: 4343 case WLAN_CIPHER_SUITE_BIP_GMAC_128: 4344 case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4345 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 4346 break; 4347 case WLAN_CIPHER_SUITE_WEP40: 4348 case WLAN_CIPHER_SUITE_WEP104: 4349 if (vif->type == NL80211_IFTYPE_STATION) 4350 break; 4351 if (iwl_mvm_has_new_tx_api(mvm)) 4352 return -EOPNOTSUPP; 4353 /* support HW crypto on TX */ 4354 return 0; 4355 default: 4356 return -EOPNOTSUPP; 4357 } 4358 4359 switch (cmd) { 4360 case SET_KEY: 4361 if (vif->type == NL80211_IFTYPE_STATION && 4362 (keyidx == 6 || keyidx == 7)) 4363 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 4364 key); 4365 4366 if ((vif->type == NL80211_IFTYPE_ADHOC || 4367 vif->type == NL80211_IFTYPE_AP) && !sta) { 4368 /* 4369 * GTK on AP interface is a TX-only key, return 0; 4370 * on IBSS they're per-station and because we're lazy 4371 * we don't support them for RX, so do the same. 4372 * CMAC/GMAC in AP/IBSS modes must be done in software 4373 * on older NICs. 4374 * 4375 * Except, of course, beacon protection - it must be 4376 * offloaded since we just set a beacon template, and 4377 * then we must also offload the IGTK (not just BIGTK) 4378 * for firmware reasons. 4379 * 4380 * So just check for beacon protection - if we don't 4381 * have it we cannot get here with keyidx >= 6, and 4382 * if we do have it we need to send the key to FW in 4383 * all cases (CMAC/GMAC). 4384 */ 4385 if (!wiphy_ext_feature_isset(hw->wiphy, 4386 NL80211_EXT_FEATURE_BEACON_PROTECTION) && 4387 (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 4388 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 4389 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) { 4390 ret = -EOPNOTSUPP; 4391 break; 4392 } 4393 4394 if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 4395 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 4396 !iwl_mvm_has_new_tx_api(mvm)) { 4397 key->hw_key_idx = STA_KEY_IDX_INVALID; 4398 ret = 0; 4399 break; 4400 } 4401 4402 if (!mvmvif->ap_ibss_active) { 4403 for (i = 0; 4404 i < ARRAY_SIZE(mvmvif->ap_early_keys); 4405 i++) { 4406 if (!mvmvif->ap_early_keys[i]) { 4407 mvmvif->ap_early_keys[i] = key; 4408 break; 4409 } 4410 } 4411 4412 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 4413 ret = -ENOSPC; 4414 else 4415 ret = 0; 4416 4417 break; 4418 } 4419 } 4420 4421 /* During FW restart, in order to restore the state as it was, 4422 * don't try to reprogram keys we previously failed for. 4423 */ 4424 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 4425 key->hw_key_idx == STA_KEY_IDX_INVALID) { 4426 IWL_DEBUG_MAC80211(mvm, 4427 "skip invalid idx key programming during restart\n"); 4428 ret = 0; 4429 break; 4430 } 4431 4432 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 4433 mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4434 key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4435 (key->cipher == WLAN_CIPHER_SUITE_CCMP || 4436 key->cipher == WLAN_CIPHER_SUITE_GCMP || 4437 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4438 struct ieee80211_key_seq seq; 4439 int tid, q; 4440 4441 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 4442 ptk_pn = kzalloc(struct_size(ptk_pn, q, 4443 mvm->trans->num_rx_queues), 4444 GFP_KERNEL); 4445 if (!ptk_pn) { 4446 ret = -ENOMEM; 4447 break; 4448 } 4449 4450 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 4451 ieee80211_get_key_rx_seq(key, tid, &seq); 4452 for (q = 0; q < mvm->trans->num_rx_queues; q++) 4453 memcpy(ptk_pn->q[q].pn[tid], 4454 seq.ccmp.pn, 4455 IEEE80211_CCMP_PN_LEN); 4456 } 4457 4458 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 4459 } 4460 4461 /* in HW restart reuse the index, otherwise request a new one */ 4462 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 4463 key_offset = key->hw_key_idx; 4464 else 4465 key_offset = STA_KEY_IDX_INVALID; 4466 4467 if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 4468 mvmsta->pairwise_cipher = key->cipher; 4469 4470 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n", 4471 sta ? sta->addr : NULL, key->keyidx); 4472 4473 if (sec_key_ver) 4474 ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); 4475 else 4476 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 4477 4478 if (ret) { 4479 IWL_WARN(mvm, "set key failed\n"); 4480 key->hw_key_idx = STA_KEY_IDX_INVALID; 4481 if (ptk_pn) { 4482 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4483 kfree(ptk_pn); 4484 } 4485 /* 4486 * can't add key for RX, but we don't need it 4487 * in the device for TX so still return 0, 4488 * unless we have new TX API where we cannot 4489 * put key material into the TX_CMD 4490 */ 4491 if (iwl_mvm_has_new_tx_api(mvm)) 4492 ret = -EOPNOTSUPP; 4493 else 4494 ret = 0; 4495 } 4496 4497 break; 4498 case DISABLE_KEY: 4499 if (vif->type == NL80211_IFTYPE_STATION && 4500 (keyidx == 6 || keyidx == 7)) 4501 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 4502 NULL); 4503 4504 ret = -ENOENT; 4505 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 4506 if (mvmvif->ap_early_keys[i] == key) { 4507 mvmvif->ap_early_keys[i] = NULL; 4508 ret = 0; 4509 } 4510 } 4511 4512 /* found in pending list - don't do anything else */ 4513 if (ret == 0) 4514 break; 4515 4516 if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 4517 ret = 0; 4518 break; 4519 } 4520 4521 if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4522 key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4523 (key->cipher == WLAN_CIPHER_SUITE_CCMP || 4524 key->cipher == WLAN_CIPHER_SUITE_GCMP || 4525 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4526 ptk_pn = rcu_dereference_protected( 4527 mvmsta->ptk_pn[keyidx], 4528 lockdep_is_held(&mvm->mutex)); 4529 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4530 if (ptk_pn) 4531 kfree_rcu(ptk_pn, rcu_head); 4532 } 4533 4534 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 4535 if (sec_key_ver) 4536 ret = iwl_mvm_sec_key_del(mvm, vif, sta, key); 4537 else 4538 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 4539 break; 4540 default: 4541 ret = -EINVAL; 4542 } 4543 4544 return ret; 4545 } 4546 4547 int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4548 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 4549 struct ieee80211_key_conf *key) 4550 { 4551 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4552 4553 guard(mvm)(mvm); 4554 return __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 4555 } 4556 4557 void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 4558 struct ieee80211_vif *vif, 4559 struct ieee80211_key_conf *keyconf, 4560 struct ieee80211_sta *sta, 4561 u32 iv32, u16 *phase1key) 4562 { 4563 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4564 4565 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 4566 return; 4567 4568 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 4569 } 4570 4571 4572 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 4573 struct iwl_rx_packet *pkt, void *data) 4574 { 4575 struct iwl_mvm *mvm = 4576 container_of(notif_wait, struct iwl_mvm, notif_wait); 4577 struct iwl_hs20_roc_res *resp; 4578 int resp_len = iwl_rx_packet_payload_len(pkt); 4579 struct iwl_mvm_time_event_data *te_data = data; 4580 4581 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 4582 return true; 4583 4584 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 4585 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 4586 return true; 4587 } 4588 4589 resp = (void *)pkt->data; 4590 4591 IWL_DEBUG_TE(mvm, 4592 "Aux ROC: Received response from ucode: status=%d uid=%d\n", 4593 resp->status, resp->event_unique_id); 4594 4595 te_data->uid = le32_to_cpu(resp->event_unique_id); 4596 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 4597 te_data->uid); 4598 4599 spin_lock_bh(&mvm->time_event_lock); 4600 list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 4601 spin_unlock_bh(&mvm->time_event_lock); 4602 4603 return true; 4604 } 4605 4606 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 4607 struct ieee80211_channel *channel, 4608 struct ieee80211_vif *vif, 4609 int duration) 4610 { 4611 int res; 4612 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4613 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 4614 static const u16 time_event_response[] = { HOT_SPOT_CMD }; 4615 struct iwl_notification_wait wait_time_event; 4616 u32 req_dur, delay; 4617 struct iwl_hs20_roc_req aux_roc_req = { 4618 .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 4619 .id_and_color = 4620 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 4621 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 4622 }; 4623 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 4624 &aux_roc_req.channel_info); 4625 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 4626 4627 /* Set the channel info data */ 4628 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 4629 iwl_mvm_phy_band_from_nl80211(channel->band), 4630 IWL_PHY_CHANNEL_MODE20, 4631 0); 4632 4633 /* Set the time and duration */ 4634 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 4635 4636 iwl_mvm_roc_duration_and_delay(vif, duration, &req_dur, &delay); 4637 tail->duration = cpu_to_le32(req_dur); 4638 tail->apply_time_max_delay = cpu_to_le32(delay); 4639 4640 IWL_DEBUG_TE(mvm, 4641 "ROC: Requesting to remain on channel %u for %ums\n", 4642 channel->hw_value, req_dur); 4643 IWL_DEBUG_TE(mvm, 4644 "\t(requested = %ums, max_delay = %ums)\n", 4645 duration, delay); 4646 4647 /* Set the node address */ 4648 memcpy(tail->node_addr, vif->addr, ETH_ALEN); 4649 4650 lockdep_assert_held(&mvm->mutex); 4651 4652 spin_lock_bh(&mvm->time_event_lock); 4653 4654 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 4655 spin_unlock_bh(&mvm->time_event_lock); 4656 return -EIO; 4657 } 4658 4659 te_data->vif = vif; 4660 te_data->duration = duration; 4661 te_data->id = HOT_SPOT_CMD; 4662 4663 spin_unlock_bh(&mvm->time_event_lock); 4664 4665 /* 4666 * Use a notification wait, which really just processes the 4667 * command response and doesn't wait for anything, in order 4668 * to be able to process the response and get the UID inside 4669 * the RX path. Using CMD_WANT_SKB doesn't work because it 4670 * stores the buffer and then wakes up this thread, by which 4671 * time another notification (that the time event started) 4672 * might already be processed unsuccessfully. 4673 */ 4674 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 4675 time_event_response, 4676 ARRAY_SIZE(time_event_response), 4677 iwl_mvm_rx_aux_roc, te_data); 4678 4679 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 4680 &aux_roc_req); 4681 4682 if (res) { 4683 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 4684 iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 4685 goto out_clear_te; 4686 } 4687 4688 /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 4689 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 4690 /* should never fail */ 4691 WARN_ON_ONCE(res); 4692 4693 if (res) { 4694 out_clear_te: 4695 spin_lock_bh(&mvm->time_event_lock); 4696 iwl_mvm_te_clear_data(mvm, te_data); 4697 spin_unlock_bh(&mvm->time_event_lock); 4698 } 4699 4700 return res; 4701 } 4702 4703 static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id) 4704 { 4705 int ret = 0; 4706 4707 lockdep_assert_held(&mvm->mutex); 4708 4709 if (!fw_has_capa(&mvm->fw->ucode_capa, 4710 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 4711 IWL_ERR(mvm, "hotspot not supported\n"); 4712 return -EINVAL; 4713 } 4714 4715 if (iwl_mvm_has_new_station_api(mvm->fw)) { 4716 ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 4717 WARN(ret, "Failed to allocate aux station"); 4718 } 4719 4720 return ret; 4721 } 4722 4723 static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 4724 { 4725 int ret; 4726 4727 lockdep_assert_held(&mvm->mutex); 4728 4729 ret = iwl_mvm_binding_add_vif(mvm, vif); 4730 if (WARN(ret, "Failed binding P2P_DEVICE\n")) 4731 return ret; 4732 4733 /* The station and queue allocation must be done only after the binding 4734 * is done, as otherwise the FW might incorrectly configure its state. 4735 */ 4736 return iwl_mvm_add_p2p_bcast_sta(mvm, vif); 4737 } 4738 4739 static int iwl_mvm_roc(struct ieee80211_hw *hw, 4740 struct ieee80211_vif *vif, 4741 struct ieee80211_channel *channel, 4742 int duration, 4743 enum ieee80211_roc_type type) 4744 { 4745 static const struct iwl_mvm_roc_ops ops = { 4746 .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20, 4747 .link = iwl_mvm_roc_link, 4748 }; 4749 4750 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops); 4751 } 4752 4753 static int iwl_mvm_roc_station(struct iwl_mvm *mvm, 4754 struct ieee80211_channel *channel, 4755 struct ieee80211_vif *vif, 4756 int duration) 4757 { 4758 int ret; 4759 u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD); 4760 u8 fw_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 4761 IWL_FW_CMD_VER_UNKNOWN); 4762 4763 if (fw_ver == IWL_FW_CMD_VER_UNKNOWN) { 4764 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, vif, duration); 4765 } else if (fw_ver >= 3) { 4766 ret = iwl_mvm_roc_add_cmd(mvm, channel, vif, duration, 4767 ROC_ACTIVITY_HOTSPOT); 4768 } else { 4769 ret = -EOPNOTSUPP; 4770 IWL_ERR(mvm, "ROC command version %d mismatch!\n", fw_ver); 4771 } 4772 4773 return ret; 4774 } 4775 4776 static int iwl_mvm_p2p_find_phy_ctxt(struct iwl_mvm *mvm, 4777 struct ieee80211_vif *vif, 4778 struct ieee80211_channel *channel) 4779 { 4780 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4781 struct cfg80211_chan_def chandef; 4782 int i; 4783 4784 lockdep_assert_held(&mvm->mutex); 4785 4786 if (mvmvif->deflink.phy_ctxt && 4787 channel == mvmvif->deflink.phy_ctxt->channel) 4788 return 0; 4789 4790 /* Try using a PHY context that is already in use */ 4791 for (i = 0; i < NUM_PHY_CTX; i++) { 4792 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[i]; 4793 4794 if (!phy_ctxt->ref || mvmvif->deflink.phy_ctxt == phy_ctxt) 4795 continue; 4796 4797 if (channel == phy_ctxt->channel) { 4798 if (mvmvif->deflink.phy_ctxt) 4799 iwl_mvm_phy_ctxt_unref(mvm, 4800 mvmvif->deflink.phy_ctxt); 4801 4802 mvmvif->deflink.phy_ctxt = phy_ctxt; 4803 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 4804 return 0; 4805 } 4806 } 4807 4808 /* We already have a phy_ctxt, but it's not on the right channel */ 4809 if (mvmvif->deflink.phy_ctxt) 4810 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 4811 4812 mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4813 if (!mvmvif->deflink.phy_ctxt) 4814 return -ENOSPC; 4815 4816 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 4817 4818 return iwl_mvm_phy_ctxt_add(mvm, mvmvif->deflink.phy_ctxt, 4819 &chandef, NULL, 1, 1); 4820 } 4821 4822 /* Execute the common part for MLD and non-MLD modes */ 4823 int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4824 struct ieee80211_channel *channel, int duration, 4825 enum ieee80211_roc_type type, 4826 const struct iwl_mvm_roc_ops *ops) 4827 { 4828 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4829 u32 lmac_id; 4830 int ret; 4831 4832 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 4833 duration, type); 4834 4835 /* 4836 * Flush the done work, just in case it's still pending, so that 4837 * the work it does can complete and we can accept new frames. 4838 */ 4839 flush_work(&mvm->roc_done_wk); 4840 4841 ret = iwl_mvm_esr_non_bss_link(mvm, vif, 0, true); 4842 if (ret) 4843 return ret; 4844 4845 guard(mvm)(mvm); 4846 4847 switch (vif->type) { 4848 case NL80211_IFTYPE_STATION: 4849 lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band); 4850 4851 /* Use aux roc framework (HS20) */ 4852 ret = ops->add_aux_sta_for_hs20(mvm, lmac_id); 4853 if (!ret) 4854 ret = iwl_mvm_roc_station(mvm, channel, vif, duration); 4855 return ret; 4856 case NL80211_IFTYPE_P2P_DEVICE: 4857 /* handle below */ 4858 break; 4859 default: 4860 IWL_ERR(mvm, "ROC: Invalid vif type=%u\n", vif->type); 4861 return -EINVAL; 4862 } 4863 4864 4865 ret = iwl_mvm_p2p_find_phy_ctxt(mvm, vif, channel); 4866 if (ret) 4867 return ret; 4868 4869 ret = ops->link(mvm, vif); 4870 if (ret) 4871 return ret; 4872 4873 return iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4874 } 4875 4876 int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 4877 struct ieee80211_vif *vif) 4878 { 4879 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4880 4881 IWL_DEBUG_MAC80211(mvm, "enter\n"); 4882 4883 iwl_mvm_stop_roc(mvm, vif); 4884 4885 IWL_DEBUG_MAC80211(mvm, "leave\n"); 4886 return 0; 4887 } 4888 4889 struct iwl_mvm_ftm_responder_iter_data { 4890 bool responder; 4891 struct ieee80211_chanctx_conf *ctx; 4892 }; 4893 4894 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4895 struct ieee80211_vif *vif) 4896 { 4897 struct iwl_mvm_ftm_responder_iter_data *data = _data; 4898 4899 if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && 4900 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4901 data->responder = true; 4902 } 4903 4904 bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4905 struct ieee80211_chanctx_conf *ctx) 4906 { 4907 struct iwl_mvm_ftm_responder_iter_data data = { 4908 .responder = false, 4909 .ctx = ctx, 4910 }; 4911 4912 ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4913 IEEE80211_IFACE_ITER_NORMAL, 4914 iwl_mvm_ftm_responder_chanctx_iter, 4915 &data); 4916 return data.responder; 4917 } 4918 4919 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4920 struct ieee80211_chanctx_conf *ctx) 4921 { 4922 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4923 struct iwl_mvm_phy_ctxt *phy_ctxt; 4924 struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4925 int ret; 4926 4927 lockdep_assert_held(&mvm->mutex); 4928 4929 IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4930 4931 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4932 if (!phy_ctxt) { 4933 ret = -ENOSPC; 4934 goto out; 4935 } 4936 4937 ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, def, &ctx->ap, 4938 ctx->rx_chains_static, 4939 ctx->rx_chains_dynamic); 4940 if (ret) { 4941 IWL_ERR(mvm, "Failed to add PHY context\n"); 4942 goto out; 4943 } 4944 4945 *phy_ctxt_id = phy_ctxt->id; 4946 out: 4947 return ret; 4948 } 4949 4950 int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4951 struct ieee80211_chanctx_conf *ctx) 4952 { 4953 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4954 4955 guard(mvm)(mvm); 4956 return __iwl_mvm_add_chanctx(mvm, ctx); 4957 } 4958 4959 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4960 struct ieee80211_chanctx_conf *ctx) 4961 { 4962 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4963 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4964 4965 lockdep_assert_held(&mvm->mutex); 4966 4967 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4968 } 4969 4970 void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4971 struct ieee80211_chanctx_conf *ctx) 4972 { 4973 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4974 4975 guard(mvm)(mvm); 4976 __iwl_mvm_remove_chanctx(mvm, ctx); 4977 } 4978 4979 void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4980 struct ieee80211_chanctx_conf *ctx, u32 changed) 4981 { 4982 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4983 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4984 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4985 struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4986 4987 if (WARN_ONCE((phy_ctxt->ref > 1) && 4988 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4989 IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4990 IEEE80211_CHANCTX_CHANGE_RADAR | 4991 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4992 "Cannot change PHY. Ref=%d, changed=0x%X\n", 4993 phy_ctxt->ref, changed)) 4994 return; 4995 4996 guard(mvm)(mvm); 4997 4998 /* we are only changing the min_width, may be a noop */ 4999 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 5000 if (phy_ctxt->width == def->width) 5001 return; 5002 5003 /* we are just toggling between 20_NOHT and 20 */ 5004 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 5005 def->width <= NL80211_CHAN_WIDTH_20) 5006 return; 5007 } 5008 5009 iwl_mvm_bt_coex_vif_change(mvm); 5010 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, &ctx->ap, 5011 ctx->rx_chains_static, 5012 ctx->rx_chains_dynamic); 5013 } 5014 5015 /* 5016 * This function executes the common part for MLD and non-MLD modes. 5017 * 5018 * Returns true if we're done assigning the chanctx 5019 * (either on failure or success) 5020 */ 5021 static bool 5022 __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, 5023 struct ieee80211_vif *vif, 5024 struct ieee80211_chanctx_conf *ctx, 5025 bool switching_chanctx, int *ret) 5026 { 5027 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 5028 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 5029 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5030 5031 lockdep_assert_held(&mvm->mutex); 5032 5033 mvmvif->deflink.phy_ctxt = phy_ctxt; 5034 5035 switch (vif->type) { 5036 case NL80211_IFTYPE_AP: 5037 /* only needed if we're switching chanctx (i.e. during CSA) */ 5038 if (switching_chanctx) { 5039 mvmvif->ap_ibss_active = true; 5040 break; 5041 } 5042 fallthrough; 5043 case NL80211_IFTYPE_ADHOC: 5044 /* 5045 * The AP binding flow is handled as part of the start_ap flow 5046 * (in bss_info_changed), similarly for IBSS. 5047 */ 5048 *ret = 0; 5049 return true; 5050 case NL80211_IFTYPE_STATION: 5051 break; 5052 case NL80211_IFTYPE_MONITOR: 5053 /* always disable PS when a monitor interface is active */ 5054 mvmvif->ps_disabled = true; 5055 break; 5056 default: 5057 *ret = -EINVAL; 5058 return true; 5059 } 5060 return false; 5061 } 5062 5063 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 5064 struct ieee80211_vif *vif, 5065 struct ieee80211_bss_conf *link_conf, 5066 struct ieee80211_chanctx_conf *ctx, 5067 bool switching_chanctx) 5068 { 5069 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5070 int ret; 5071 5072 if (WARN_ON(!link_conf)) 5073 return -EINVAL; 5074 5075 if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx, 5076 switching_chanctx, &ret)) 5077 goto out; 5078 5079 ret = iwl_mvm_binding_add_vif(mvm, vif); 5080 if (ret) 5081 goto out; 5082 5083 /* 5084 * Power state must be updated before quotas, 5085 * otherwise fw will complain. 5086 */ 5087 iwl_mvm_power_update_mac(mvm); 5088 5089 /* Setting the quota at this stage is only required for monitor 5090 * interfaces. For the other types, the bss_info changed flow 5091 * will handle quota settings. 5092 */ 5093 if (vif->type == NL80211_IFTYPE_MONITOR) { 5094 mvmvif->monitor_active = true; 5095 ret = iwl_mvm_update_quotas(mvm, false, NULL); 5096 if (ret) 5097 goto out_remove_binding; 5098 5099 ret = iwl_mvm_add_snif_sta(mvm, vif); 5100 if (ret) 5101 goto out_remove_binding; 5102 5103 } 5104 5105 /* Handle binding during CSA */ 5106 if (vif->type == NL80211_IFTYPE_AP) { 5107 iwl_mvm_update_quotas(mvm, false, NULL); 5108 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 5109 } 5110 5111 if (vif->type == NL80211_IFTYPE_STATION) { 5112 if (!switching_chanctx) { 5113 mvmvif->csa_bcn_pending = false; 5114 goto out; 5115 } 5116 5117 mvmvif->csa_bcn_pending = true; 5118 5119 if (!fw_has_capa(&mvm->fw->ucode_capa, 5120 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 5121 u32 duration = 5 * vif->bss_conf.beacon_int; 5122 5123 /* Protect the session to make sure we hear the first 5124 * beacon on the new channel. 5125 */ 5126 iwl_mvm_protect_session(mvm, vif, duration, duration, 5127 vif->bss_conf.beacon_int / 2, 5128 true); 5129 } 5130 5131 iwl_mvm_update_quotas(mvm, false, NULL); 5132 5133 iwl_mvm_send_ap_tx_power_constraint_cmd(mvm, vif, 5134 link_conf, 5135 false); 5136 } 5137 5138 goto out; 5139 5140 out_remove_binding: 5141 iwl_mvm_binding_remove_vif(mvm, vif); 5142 iwl_mvm_power_update_mac(mvm); 5143 out: 5144 if (ret) 5145 mvmvif->deflink.phy_ctxt = NULL; 5146 return ret; 5147 } 5148 5149 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 5150 struct ieee80211_vif *vif, 5151 struct ieee80211_bss_conf *link_conf, 5152 struct ieee80211_chanctx_conf *ctx) 5153 { 5154 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5155 5156 guard(mvm)(mvm); 5157 return __iwl_mvm_assign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5158 } 5159 5160 /* 5161 * This function executes the common part for MLD and non-MLD modes. 5162 * 5163 * Returns if chanctx unassign chanctx is done 5164 * (either on failure or success) 5165 */ 5166 static bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, 5167 struct ieee80211_vif *vif, 5168 bool switching_chanctx) 5169 { 5170 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5171 5172 lockdep_assert_held(&mvm->mutex); 5173 iwl_mvm_remove_time_event(mvm, mvmvif, 5174 &mvmvif->time_event_data); 5175 5176 switch (vif->type) { 5177 case NL80211_IFTYPE_ADHOC: 5178 return true; 5179 case NL80211_IFTYPE_MONITOR: 5180 mvmvif->monitor_active = false; 5181 mvmvif->ps_disabled = false; 5182 break; 5183 case NL80211_IFTYPE_AP: 5184 /* This part is triggered only during CSA */ 5185 if (!switching_chanctx || !mvmvif->ap_ibss_active) 5186 return true; 5187 5188 mvmvif->csa_countdown = false; 5189 5190 /* Set CS bit on all the stations */ 5191 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 5192 5193 /* Save blocked iface, the timeout is set on the next beacon */ 5194 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 5195 5196 mvmvif->ap_ibss_active = false; 5197 break; 5198 default: 5199 break; 5200 } 5201 return false; 5202 } 5203 5204 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 5205 struct ieee80211_vif *vif, 5206 struct ieee80211_bss_conf *link_conf, 5207 struct ieee80211_chanctx_conf *ctx, 5208 bool switching_chanctx) 5209 { 5210 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5211 struct ieee80211_vif *disabled_vif = NULL; 5212 5213 if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx)) 5214 goto out; 5215 5216 if (vif->type == NL80211_IFTYPE_MONITOR) 5217 iwl_mvm_rm_snif_sta(mvm, vif); 5218 5219 5220 if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) { 5221 disabled_vif = vif; 5222 if (!fw_has_capa(&mvm->fw->ucode_capa, 5223 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 5224 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 5225 } 5226 5227 iwl_mvm_update_quotas(mvm, false, disabled_vif); 5228 iwl_mvm_binding_remove_vif(mvm, vif); 5229 5230 out: 5231 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 5232 switching_chanctx) 5233 return; 5234 mvmvif->deflink.phy_ctxt = NULL; 5235 iwl_mvm_power_update_mac(mvm); 5236 } 5237 5238 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 5239 struct ieee80211_vif *vif, 5240 struct ieee80211_bss_conf *link_conf, 5241 struct ieee80211_chanctx_conf *ctx) 5242 { 5243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5244 5245 guard(mvm)(mvm); 5246 __iwl_mvm_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5247 } 5248 5249 static int 5250 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 5251 struct ieee80211_vif_chanctx_switch *vifs, 5252 const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5253 { 5254 int ret; 5255 5256 guard(mvm)(mvm); 5257 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5258 vifs[0].old_ctx, true); 5259 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 5260 5261 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 5262 if (ret) { 5263 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 5264 goto out_reassign; 5265 } 5266 5267 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5268 vifs[0].new_ctx, true); 5269 if (ret) { 5270 IWL_ERR(mvm, 5271 "failed to assign new_ctx during channel switch\n"); 5272 goto out_remove; 5273 } 5274 5275 /* we don't support TDLS during DCM - can be caused by channel switch */ 5276 if (iwl_mvm_phy_ctx_count(mvm) > 1) 5277 iwl_mvm_teardown_tdls_peers(mvm); 5278 5279 return 0; 5280 5281 out_remove: 5282 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 5283 5284 out_reassign: 5285 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 5286 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 5287 goto out_restart; 5288 } 5289 5290 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5291 vifs[0].old_ctx, true)) { 5292 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5293 goto out_restart; 5294 } 5295 5296 return ret; 5297 5298 out_restart: 5299 /* things keep failing, better restart the hw */ 5300 iwl_mvm_nic_restart(mvm, false); 5301 return ret; 5302 } 5303 5304 static int 5305 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 5306 struct ieee80211_vif_chanctx_switch *vifs, 5307 const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5308 { 5309 int ret; 5310 5311 guard(mvm)(mvm); 5312 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5313 vifs[0].old_ctx, true); 5314 5315 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5316 vifs[0].new_ctx, true); 5317 if (ret) { 5318 IWL_ERR(mvm, 5319 "failed to assign new_ctx during channel switch\n"); 5320 goto out_reassign; 5321 } 5322 5323 return 0; 5324 5325 out_reassign: 5326 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 5327 vifs[0].old_ctx, true)) { 5328 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5329 goto out_restart; 5330 } 5331 5332 return ret; 5333 5334 out_restart: 5335 /* things keep failing, better restart the hw */ 5336 iwl_mvm_nic_restart(mvm, false); 5337 return ret; 5338 } 5339 5340 /* Execute the common part for both MLD and non-MLD modes */ 5341 int 5342 iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw, 5343 struct ieee80211_vif_chanctx_switch *vifs, 5344 int n_vifs, 5345 enum ieee80211_chanctx_switch_mode mode, 5346 const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5347 { 5348 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5349 int ret; 5350 5351 /* we only support a single-vif right now */ 5352 if (n_vifs > 1) 5353 return -EOPNOTSUPP; 5354 5355 switch (mode) { 5356 case CHANCTX_SWMODE_SWAP_CONTEXTS: 5357 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops); 5358 break; 5359 case CHANCTX_SWMODE_REASSIGN_VIF: 5360 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops); 5361 break; 5362 default: 5363 ret = -EOPNOTSUPP; 5364 break; 5365 } 5366 5367 return ret; 5368 } 5369 5370 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 5371 struct ieee80211_vif_chanctx_switch *vifs, 5372 int n_vifs, 5373 enum ieee80211_chanctx_switch_mode mode) 5374 { 5375 static const struct iwl_mvm_switch_vif_chanctx_ops ops = { 5376 .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx, 5377 .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx, 5378 }; 5379 5380 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops); 5381 } 5382 5383 int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 5384 { 5385 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5386 5387 return mvm->ibss_manager; 5388 } 5389 5390 static int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 5391 bool set) 5392 { 5393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5394 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 5395 5396 if (!mvm_sta || !mvm_sta->vif) { 5397 IWL_ERR(mvm, "Station is not associated to a vif\n"); 5398 return -EINVAL; 5399 } 5400 5401 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif, 5402 &mvm_sta->vif->bss_conf); 5403 } 5404 5405 #ifdef CONFIG_NL80211_TESTMODE 5406 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 5407 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 5408 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 5409 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 5410 }; 5411 5412 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 5413 struct ieee80211_vif *vif, 5414 void *data, int len) 5415 { 5416 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 5417 int err; 5418 u32 noa_duration; 5419 5420 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 5421 iwl_mvm_tm_policy, NULL); 5422 if (err) 5423 return err; 5424 5425 if (!tb[IWL_MVM_TM_ATTR_CMD]) 5426 return -EINVAL; 5427 5428 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 5429 case IWL_MVM_TM_CMD_SET_NOA: 5430 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 5431 !vif->bss_conf.enable_beacon || 5432 !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 5433 return -EINVAL; 5434 5435 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 5436 if (noa_duration >= vif->bss_conf.beacon_int) 5437 return -EINVAL; 5438 5439 mvm->noa_duration = noa_duration; 5440 mvm->noa_vif = vif; 5441 5442 return iwl_mvm_update_quotas(mvm, true, NULL); 5443 case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 5444 /* must be associated client vif - ignore authorized */ 5445 if (!vif || vif->type != NL80211_IFTYPE_STATION || 5446 !vif->cfg.assoc || !vif->bss_conf.dtim_period || 5447 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 5448 return -EINVAL; 5449 5450 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 5451 return iwl_mvm_enable_beacon_filter(mvm, vif); 5452 return iwl_mvm_disable_beacon_filter(mvm, vif); 5453 } 5454 5455 return -EOPNOTSUPP; 5456 } 5457 5458 int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 5459 struct ieee80211_vif *vif, 5460 void *data, int len) 5461 { 5462 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5463 5464 guard(mvm)(mvm); 5465 return __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 5466 } 5467 #endif 5468 5469 void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5470 struct ieee80211_channel_switch *chsw) 5471 { 5472 /* By implementing this operation, we prevent mac80211 from 5473 * starting its own channel switch timer, so that we can call 5474 * ieee80211_chswitch_done() ourselves at the right time 5475 * (which is when the absence time event starts). 5476 */ 5477 5478 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 5479 "dummy channel switch op\n"); 5480 } 5481 5482 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 5483 struct ieee80211_vif *vif, 5484 struct ieee80211_channel_switch *chsw) 5485 { 5486 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5487 struct iwl_chan_switch_te_cmd cmd = { 5488 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 5489 mvmvif->color)), 5490 .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 5491 .tsf = cpu_to_le32(chsw->timestamp), 5492 .cs_count = chsw->count, 5493 .cs_mode = chsw->block_tx, 5494 }; 5495 5496 lockdep_assert_held(&mvm->mutex); 5497 5498 if (chsw->delay) 5499 cmd.cs_delayed_bcn_count = 5500 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 5501 5502 return iwl_mvm_send_cmd_pdu(mvm, 5503 WIDE_ID(MAC_CONF_GROUP, 5504 CHANNEL_SWITCH_TIME_EVENT_CMD), 5505 0, sizeof(cmd), &cmd); 5506 } 5507 5508 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 5509 struct ieee80211_vif *vif, 5510 struct ieee80211_channel_switch *chsw) 5511 { 5512 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5513 u32 apply_time; 5514 5515 /* Schedule the time event to a bit before beacon 1, 5516 * to make sure we're in the new channel when the 5517 * GO/AP arrives. In case count <= 1 immediately schedule the 5518 * TE (this might result with some packet loss or connection 5519 * loss). 5520 */ 5521 if (chsw->count <= 1) 5522 apply_time = 0; 5523 else 5524 apply_time = chsw->device_timestamp + 5525 ((vif->bss_conf.beacon_int * (chsw->count - 1) - 5526 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 5527 5528 if (chsw->block_tx) 5529 iwl_mvm_csa_client_absent(mvm, vif); 5530 5531 if (mvmvif->bf_enabled) { 5532 int ret = iwl_mvm_disable_beacon_filter(mvm, vif); 5533 5534 if (ret) 5535 return ret; 5536 } 5537 5538 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 5539 apply_time); 5540 5541 return 0; 5542 } 5543 5544 static void iwl_mvm_csa_block_txqs(void *data, struct ieee80211_sta *sta) 5545 { 5546 int i; 5547 5548 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 5549 struct iwl_mvm_txq *mvmtxq = 5550 iwl_mvm_txq_from_mac80211(sta->txq[i]); 5551 5552 set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5553 } 5554 } 5555 5556 #define IWL_MAX_CSA_BLOCK_TX 1500 5557 int iwl_mvm_pre_channel_switch(struct iwl_mvm *mvm, 5558 struct ieee80211_vif *vif, 5559 struct ieee80211_channel_switch *chsw) 5560 { 5561 struct ieee80211_vif *csa_vif; 5562 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5563 struct iwl_mvm_txq *mvmtxq; 5564 int ret; 5565 5566 lockdep_assert_held(&mvm->mutex); 5567 5568 mvmvif->csa_failed = false; 5569 mvmvif->csa_blocks_tx = false; 5570 5571 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 5572 chsw->chandef.center_freq1); 5573 5574 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 5575 ieee80211_vif_to_wdev(vif), 5576 FW_DBG_TRIGGER_CHANNEL_SWITCH); 5577 5578 switch (vif->type) { 5579 case NL80211_IFTYPE_AP: 5580 csa_vif = 5581 rcu_dereference_protected(mvm->csa_vif, 5582 lockdep_is_held(&mvm->mutex)); 5583 if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, 5584 "Another CSA is already in progress")) 5585 return -EBUSY; 5586 5587 /* we still didn't unblock tx. prevent new CS meanwhile */ 5588 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 5589 lockdep_is_held(&mvm->mutex))) 5590 return -EBUSY; 5591 5592 rcu_assign_pointer(mvm->csa_vif, vif); 5593 5594 if (WARN_ONCE(mvmvif->csa_countdown, 5595 "Previous CSA countdown didn't complete")) 5596 return -EBUSY; 5597 5598 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 5599 5600 if (!chsw->block_tx) 5601 break; 5602 /* don't need blocking in driver otherwise - mac80211 will do */ 5603 if (!ieee80211_hw_check(mvm->hw, HANDLES_QUIET_CSA)) 5604 break; 5605 5606 mvmvif->csa_blocks_tx = true; 5607 mvmtxq = iwl_mvm_txq_from_mac80211(vif->txq); 5608 set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5609 ieee80211_iterate_stations_atomic(mvm->hw, 5610 iwl_mvm_csa_block_txqs, 5611 NULL); 5612 break; 5613 case NL80211_IFTYPE_STATION: 5614 mvmvif->csa_blocks_tx = chsw->block_tx; 5615 5616 /* 5617 * In the new flow FW is in charge of timing the switch so there 5618 * is no need for all of this 5619 */ 5620 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5621 CHANNEL_SWITCH_ERROR_NOTIF, 5622 0)) 5623 break; 5624 5625 /* 5626 * We haven't configured the firmware to be associated yet since 5627 * we don't know the dtim period. In this case, the firmware can't 5628 * track the beacons. 5629 */ 5630 if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) 5631 return -EBUSY; 5632 5633 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX && 5634 hweight16(vif->valid_links) <= 1) 5635 schedule_delayed_work(&mvmvif->csa_work, 0); 5636 5637 if (chsw->block_tx) { 5638 /* 5639 * In case of undetermined / long time with immediate 5640 * quiet monitor status to gracefully disconnect 5641 */ 5642 if (!chsw->count || 5643 chsw->count * vif->bss_conf.beacon_int > 5644 IWL_MAX_CSA_BLOCK_TX) 5645 schedule_delayed_work(&mvmvif->csa_work, 5646 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 5647 } 5648 5649 if (!fw_has_capa(&mvm->fw->ucode_capa, 5650 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 5651 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 5652 if (ret) 5653 return ret; 5654 } else { 5655 iwl_mvm_schedule_client_csa(mvm, vif, chsw); 5656 } 5657 5658 mvmvif->csa_count = chsw->count; 5659 mvmvif->csa_misbehave = false; 5660 break; 5661 default: 5662 break; 5663 } 5664 5665 mvmvif->ps_disabled = true; 5666 5667 ret = iwl_mvm_power_update_ps(mvm); 5668 if (ret) 5669 return ret; 5670 5671 /* we won't be on this channel any longer */ 5672 iwl_mvm_teardown_tdls_peers(mvm); 5673 5674 return ret; 5675 } 5676 5677 static int iwl_mvm_mac_pre_channel_switch(struct ieee80211_hw *hw, 5678 struct ieee80211_vif *vif, 5679 struct ieee80211_channel_switch *chsw) 5680 { 5681 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5682 5683 guard(mvm)(mvm); 5684 return iwl_mvm_pre_channel_switch(mvm, vif, chsw); 5685 } 5686 5687 void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 5688 struct ieee80211_vif *vif, 5689 struct ieee80211_channel_switch *chsw) 5690 { 5691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5692 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5693 struct iwl_chan_switch_te_cmd cmd = { 5694 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 5695 mvmvif->color)), 5696 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 5697 .tsf = cpu_to_le32(chsw->timestamp), 5698 .cs_count = chsw->count, 5699 .cs_mode = chsw->block_tx, 5700 }; 5701 5702 /* 5703 * In the new flow FW is in charge of timing the switch so there is no 5704 * need for all of this 5705 */ 5706 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5707 CHANNEL_SWITCH_ERROR_NOTIF, 0)) 5708 return; 5709 5710 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 5711 return; 5712 5713 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 5714 mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 5715 5716 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 5717 if (mvmvif->csa_misbehave) { 5718 struct ieee80211_bss_conf *link_conf; 5719 5720 /* Second time, give up on this AP*/ 5721 5722 link_conf = wiphy_dereference(hw->wiphy, 5723 vif->link_conf[chsw->link_id]); 5724 if (WARN_ON(!link_conf)) 5725 return; 5726 5727 iwl_mvm_abort_channel_switch(hw, vif, link_conf); 5728 ieee80211_chswitch_done(vif, false, 0); 5729 mvmvif->csa_misbehave = false; 5730 return; 5731 } 5732 mvmvif->csa_misbehave = true; 5733 } 5734 mvmvif->csa_count = chsw->count; 5735 5736 guard(mvm)(mvm); 5737 if (mvmvif->csa_failed) 5738 return; 5739 5740 WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 5741 WIDE_ID(MAC_CONF_GROUP, 5742 CHANNEL_SWITCH_TIME_EVENT_CMD), 5743 0, sizeof(cmd), &cmd)); 5744 } 5745 5746 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 5747 { 5748 int i; 5749 5750 if (!iwl_mvm_has_new_tx_api(mvm)) { 5751 if (drop) { 5752 guard(mvm)(mvm); 5753 iwl_mvm_flush_tx_path(mvm, 5754 iwl_mvm_flushable_queues(mvm) & queues); 5755 } else { 5756 iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 5757 } 5758 return; 5759 } 5760 5761 guard(mvm)(mvm); 5762 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5763 struct ieee80211_sta *sta; 5764 5765 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 5766 lockdep_is_held(&mvm->mutex)); 5767 if (IS_ERR_OR_NULL(sta)) 5768 continue; 5769 5770 if (drop) 5771 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 5772 else 5773 iwl_mvm_wait_sta_queues_empty(mvm, 5774 iwl_mvm_sta_from_mac80211(sta)); 5775 } 5776 } 5777 5778 void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5779 u32 queues, bool drop) 5780 { 5781 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5782 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5783 struct iwl_mvm_sta *mvmsta; 5784 struct ieee80211_sta *sta; 5785 bool ap_sta_done = false; 5786 int i; 5787 u32 msk = 0; 5788 5789 if (!vif) { 5790 iwl_mvm_flush_no_vif(mvm, queues, drop); 5791 return; 5792 } 5793 5794 if (!drop && hweight16(vif->active_links) <= 1) { 5795 int link_id = vif->active_links ? __ffs(vif->active_links) : 0; 5796 struct ieee80211_bss_conf *link_conf; 5797 5798 link_conf = wiphy_dereference(hw->wiphy, 5799 vif->link_conf[link_id]); 5800 if (WARN_ON(!link_conf)) 5801 return; 5802 if (link_conf->csa_active && mvmvif->csa_blocks_tx) 5803 drop = true; 5804 } 5805 5806 /* Make sure we're done with the deferred traffic before flushing */ 5807 flush_work(&mvm->add_stream_wk); 5808 5809 mutex_lock(&mvm->mutex); 5810 5811 /* flush the AP-station and all TDLS peers */ 5812 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5813 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 5814 lockdep_is_held(&mvm->mutex)); 5815 if (IS_ERR_OR_NULL(sta)) 5816 continue; 5817 5818 mvmsta = iwl_mvm_sta_from_mac80211(sta); 5819 if (mvmsta->vif != vif) 5820 continue; 5821 5822 if (sta == mvmvif->ap_sta) { 5823 if (ap_sta_done) 5824 continue; 5825 ap_sta_done = true; 5826 } 5827 5828 if (drop) { 5829 if (iwl_mvm_flush_sta(mvm, mvmsta->deflink.sta_id, 5830 mvmsta->tfd_queue_msk)) 5831 IWL_ERR(mvm, "flush request fail\n"); 5832 } else { 5833 if (iwl_mvm_has_new_tx_api(mvm)) 5834 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 5835 else /* only used for !iwl_mvm_has_new_tx_api() below */ 5836 msk |= mvmsta->tfd_queue_msk; 5837 } 5838 } 5839 5840 mutex_unlock(&mvm->mutex); 5841 5842 /* this can take a while, and we may need/want other operations 5843 * to succeed while doing this, so do it without the mutex held 5844 */ 5845 if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 5846 iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 5847 } 5848 5849 void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5850 struct ieee80211_sta *sta) 5851 { 5852 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5853 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5854 struct iwl_mvm_link_sta *mvm_link_sta; 5855 struct ieee80211_link_sta *link_sta; 5856 int link_id; 5857 5858 guard(mvm)(mvm); 5859 for_each_sta_active_link(vif, sta, link_sta, link_id) { 5860 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_id], 5861 lockdep_is_held(&mvm->mutex)); 5862 if (!mvm_link_sta) 5863 continue; 5864 5865 if (iwl_mvm_flush_sta(mvm, mvm_link_sta->sta_id, 5866 mvmsta->tfd_queue_msk)) 5867 IWL_ERR(mvm, "flush request fail\n"); 5868 } 5869 } 5870 5871 static int iwl_mvm_mac_get_acs_survey(struct iwl_mvm *mvm, int idx, 5872 struct survey_info *survey) 5873 { 5874 int chan_idx; 5875 enum nl80211_band band; 5876 int ret; 5877 5878 mutex_lock(&mvm->mutex); 5879 5880 if (!mvm->acs_survey) { 5881 ret = -ENOENT; 5882 goto out; 5883 } 5884 5885 /* Find and return the next entry that has a non-zero active time */ 5886 for (band = 0; band < NUM_NL80211_BANDS; band++) { 5887 struct ieee80211_supported_band *sband = 5888 mvm->hw->wiphy->bands[band]; 5889 5890 if (!sband) 5891 continue; 5892 5893 for (chan_idx = 0; chan_idx < sband->n_channels; chan_idx++) { 5894 struct iwl_mvm_acs_survey_channel *info = 5895 &mvm->acs_survey->bands[band][chan_idx]; 5896 5897 if (!info->time) 5898 continue; 5899 5900 /* Found (the next) channel to report */ 5901 survey->channel = &sband->channels[chan_idx]; 5902 survey->filled = SURVEY_INFO_TIME | 5903 SURVEY_INFO_TIME_BUSY | 5904 SURVEY_INFO_TIME_RX | 5905 SURVEY_INFO_TIME_TX; 5906 survey->time = info->time; 5907 survey->time_busy = info->time_busy; 5908 survey->time_rx = info->time_rx; 5909 survey->time_tx = info->time_tx; 5910 survey->noise = info->noise; 5911 if (survey->noise < 0) 5912 survey->filled |= SURVEY_INFO_NOISE_DBM; 5913 5914 /* Clear time so that channel is only reported once */ 5915 info->time = 0; 5916 5917 ret = 0; 5918 goto out; 5919 } 5920 } 5921 5922 ret = -ENOENT; 5923 5924 out: 5925 mutex_unlock(&mvm->mutex); 5926 5927 return ret; 5928 } 5929 5930 int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 5931 struct survey_info *survey) 5932 { 5933 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5934 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, 5935 WIDE_ID(SYSTEM_GROUP, 5936 SYSTEM_STATISTICS_CMD), 5937 IWL_FW_CMD_VER_UNKNOWN); 5938 5939 memset(survey, 0, sizeof(*survey)); 5940 5941 if (!fw_has_capa(&mvm->fw->ucode_capa, 5942 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 5943 return -ENOENT; 5944 5945 /* 5946 * Return the beacon stats at index zero and pass on following indices 5947 * to the function returning the full survey, most likely for ACS 5948 * (Automatic Channel Selection). 5949 */ 5950 if (idx > 0) 5951 return iwl_mvm_mac_get_acs_survey(mvm, idx - 1, survey); 5952 5953 guard(mvm)(mvm); 5954 5955 if (iwl_mvm_firmware_running(mvm)) { 5956 int ret = iwl_mvm_request_statistics(mvm, false); 5957 5958 if (ret) 5959 return ret; 5960 } 5961 5962 survey->filled = SURVEY_INFO_TIME_RX | 5963 SURVEY_INFO_TIME_TX; 5964 5965 survey->time_rx = mvm->accu_radio_stats.rx_time + 5966 mvm->radio_stats.rx_time; 5967 do_div(survey->time_rx, USEC_PER_MSEC); 5968 5969 survey->time_tx = mvm->accu_radio_stats.tx_time + 5970 mvm->radio_stats.tx_time; 5971 do_div(survey->time_tx, USEC_PER_MSEC); 5972 5973 /* the new fw api doesn't support the following fields */ 5974 if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN) 5975 return 0; 5976 5977 survey->filled |= SURVEY_INFO_TIME | 5978 SURVEY_INFO_TIME_SCAN; 5979 survey->time = mvm->accu_radio_stats.on_time_rf + 5980 mvm->radio_stats.on_time_rf; 5981 do_div(survey->time, USEC_PER_MSEC); 5982 5983 survey->time_scan = mvm->accu_radio_stats.on_time_scan + 5984 mvm->radio_stats.on_time_scan; 5985 do_div(survey->time_scan, USEC_PER_MSEC); 5986 5987 return 0; 5988 } 5989 5990 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 5991 { 5992 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 5993 u32 gi_ltf; 5994 5995 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 5996 case RATE_MCS_CHAN_WIDTH_20: 5997 rinfo->bw = RATE_INFO_BW_20; 5998 break; 5999 case RATE_MCS_CHAN_WIDTH_40: 6000 rinfo->bw = RATE_INFO_BW_40; 6001 break; 6002 case RATE_MCS_CHAN_WIDTH_80: 6003 rinfo->bw = RATE_INFO_BW_80; 6004 break; 6005 case RATE_MCS_CHAN_WIDTH_160: 6006 rinfo->bw = RATE_INFO_BW_160; 6007 break; 6008 case RATE_MCS_CHAN_WIDTH_320: 6009 rinfo->bw = RATE_INFO_BW_320; 6010 break; 6011 } 6012 6013 if (format == RATE_MCS_CCK_MSK || 6014 format == RATE_MCS_LEGACY_OFDM_MSK) { 6015 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 6016 6017 /* add the offset needed to get to the legacy ofdm indices */ 6018 if (format == RATE_MCS_LEGACY_OFDM_MSK) 6019 rate += IWL_FIRST_OFDM_RATE; 6020 6021 switch (rate) { 6022 case IWL_RATE_1M_INDEX: 6023 rinfo->legacy = 10; 6024 break; 6025 case IWL_RATE_2M_INDEX: 6026 rinfo->legacy = 20; 6027 break; 6028 case IWL_RATE_5M_INDEX: 6029 rinfo->legacy = 55; 6030 break; 6031 case IWL_RATE_11M_INDEX: 6032 rinfo->legacy = 110; 6033 break; 6034 case IWL_RATE_6M_INDEX: 6035 rinfo->legacy = 60; 6036 break; 6037 case IWL_RATE_9M_INDEX: 6038 rinfo->legacy = 90; 6039 break; 6040 case IWL_RATE_12M_INDEX: 6041 rinfo->legacy = 120; 6042 break; 6043 case IWL_RATE_18M_INDEX: 6044 rinfo->legacy = 180; 6045 break; 6046 case IWL_RATE_24M_INDEX: 6047 rinfo->legacy = 240; 6048 break; 6049 case IWL_RATE_36M_INDEX: 6050 rinfo->legacy = 360; 6051 break; 6052 case IWL_RATE_48M_INDEX: 6053 rinfo->legacy = 480; 6054 break; 6055 case IWL_RATE_54M_INDEX: 6056 rinfo->legacy = 540; 6057 } 6058 return; 6059 } 6060 6061 rinfo->nss = u32_get_bits(rate_n_flags, 6062 RATE_MCS_NSS_MSK) + 1; 6063 rinfo->mcs = format == RATE_MCS_HT_MSK ? 6064 RATE_HT_MCS_INDEX(rate_n_flags) : 6065 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 6066 6067 if (rate_n_flags & RATE_MCS_SGI_MSK) 6068 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 6069 6070 switch (format) { 6071 case RATE_MCS_EHT_MSK: 6072 /* TODO: GI/LTF/RU. How does the firmware encode them? */ 6073 rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; 6074 break; 6075 case RATE_MCS_HE_MSK: 6076 gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK); 6077 6078 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 6079 6080 if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 6081 rinfo->bw = RATE_INFO_BW_HE_RU; 6082 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 6083 } 6084 6085 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 6086 case RATE_MCS_HE_TYPE_SU: 6087 case RATE_MCS_HE_TYPE_EXT_SU: 6088 if (gi_ltf == 0 || gi_ltf == 1) 6089 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 6090 else if (gi_ltf == 2) 6091 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 6092 else if (gi_ltf == 3) 6093 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 6094 else 6095 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 6096 break; 6097 case RATE_MCS_HE_TYPE_MU: 6098 if (gi_ltf == 0 || gi_ltf == 1) 6099 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 6100 else if (gi_ltf == 2) 6101 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 6102 else 6103 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 6104 break; 6105 case RATE_MCS_HE_TYPE_TRIG: 6106 if (gi_ltf == 0 || gi_ltf == 1) 6107 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 6108 else 6109 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 6110 break; 6111 } 6112 6113 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 6114 rinfo->he_dcm = 1; 6115 break; 6116 case RATE_MCS_HT_MSK: 6117 rinfo->flags |= RATE_INFO_FLAGS_MCS; 6118 break; 6119 case RATE_MCS_VHT_MSK: 6120 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 6121 break; 6122 } 6123 } 6124 6125 void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 6126 struct ieee80211_vif *vif, 6127 struct ieee80211_sta *sta, 6128 struct station_info *sinfo) 6129 { 6130 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6131 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 6132 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 6133 int i; 6134 6135 if (mvmsta->deflink.avg_energy) { 6136 sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy; 6137 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 6138 } 6139 6140 if (iwl_mvm_has_tlc_offload(mvm)) { 6141 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw; 6142 6143 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 6144 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 6145 } 6146 6147 /* if beacon filtering isn't on mac80211 does it anyway */ 6148 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 6149 return; 6150 6151 if (!vif->cfg.assoc) 6152 return; 6153 6154 guard(mvm)(mvm); 6155 6156 if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id) 6157 return; 6158 6159 if (iwl_mvm_request_statistics(mvm, false)) 6160 return; 6161 6162 sinfo->rx_beacon = 0; 6163 for_each_mvm_vif_valid_link(mvmvif, i) 6164 sinfo->rx_beacon += mvmvif->link[i]->beacon_stats.num_beacons + 6165 mvmvif->link[i]->beacon_stats.accu_num_beacons; 6166 6167 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 6168 if (mvmvif->deflink.beacon_stats.avg_signal) { 6169 /* firmware only reports a value after RXing a few beacons */ 6170 sinfo->rx_beacon_signal_avg = 6171 mvmvif->deflink.beacon_stats.avg_signal; 6172 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 6173 } 6174 } 6175 6176 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 6177 struct ieee80211_vif *vif, 6178 const struct ieee80211_mlme_event *mlme) 6179 { 6180 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 6181 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 6182 iwl_dbg_tlv_time_point(&mvm->fwrt, 6183 IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 6184 NULL); 6185 return; 6186 } 6187 6188 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 6189 iwl_dbg_tlv_time_point(&mvm->fwrt, 6190 IWL_FW_INI_TIME_POINT_DEASSOC, 6191 NULL); 6192 return; 6193 } 6194 } 6195 6196 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 6197 struct ieee80211_vif *vif, 6198 const struct ieee80211_event *event) 6199 { 6200 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 6201 do { \ 6202 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 6203 break; \ 6204 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 6205 } while (0) 6206 6207 struct iwl_fw_dbg_trigger_tlv *trig; 6208 struct iwl_fw_dbg_trigger_mlme *trig_mlme; 6209 6210 if (iwl_trans_dbg_ini_valid(mvm->trans)) { 6211 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 6212 return; 6213 } 6214 6215 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 6216 FW_DBG_TRIGGER_MLME); 6217 if (!trig) 6218 return; 6219 6220 trig_mlme = (void *)trig->data; 6221 6222 if (event->u.mlme.data == ASSOC_EVENT) { 6223 if (event->u.mlme.status == MLME_DENIED) 6224 CHECK_MLME_TRIGGER(stop_assoc_denied, 6225 "DENIED ASSOC: reason %d", 6226 event->u.mlme.reason); 6227 else if (event->u.mlme.status == MLME_TIMEOUT) 6228 CHECK_MLME_TRIGGER(stop_assoc_timeout, 6229 "ASSOC TIMEOUT"); 6230 } else if (event->u.mlme.data == AUTH_EVENT) { 6231 if (event->u.mlme.status == MLME_DENIED) 6232 CHECK_MLME_TRIGGER(stop_auth_denied, 6233 "DENIED AUTH: reason %d", 6234 event->u.mlme.reason); 6235 else if (event->u.mlme.status == MLME_TIMEOUT) 6236 CHECK_MLME_TRIGGER(stop_auth_timeout, 6237 "AUTH TIMEOUT"); 6238 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 6239 CHECK_MLME_TRIGGER(stop_rx_deauth, 6240 "DEAUTH RX %d", event->u.mlme.reason); 6241 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 6242 CHECK_MLME_TRIGGER(stop_tx_deauth, 6243 "DEAUTH TX %d", event->u.mlme.reason); 6244 } 6245 #undef CHECK_MLME_TRIGGER 6246 } 6247 6248 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 6249 struct ieee80211_vif *vif, 6250 const struct ieee80211_event *event) 6251 { 6252 struct iwl_fw_dbg_trigger_tlv *trig; 6253 struct iwl_fw_dbg_trigger_ba *ba_trig; 6254 6255 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 6256 FW_DBG_TRIGGER_BA); 6257 if (!trig) 6258 return; 6259 6260 ba_trig = (void *)trig->data; 6261 6262 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 6263 return; 6264 6265 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 6266 "BAR received from %pM, tid %d, ssn %d", 6267 event->u.ba.sta->addr, event->u.ba.tid, 6268 event->u.ba.ssn); 6269 } 6270 6271 void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 6272 struct ieee80211_vif *vif, 6273 const struct ieee80211_event *event) 6274 { 6275 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6276 6277 switch (event->type) { 6278 case MLME_EVENT: 6279 iwl_mvm_event_mlme_callback(mvm, vif, event); 6280 break; 6281 case BAR_RX_EVENT: 6282 iwl_mvm_event_bar_rx_callback(mvm, vif, event); 6283 break; 6284 case BA_FRAME_TIMEOUT: 6285 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 6286 event->u.ba.tid); 6287 break; 6288 default: 6289 break; 6290 } 6291 } 6292 6293 #define SYNC_RX_QUEUE_TIMEOUT (HZ) 6294 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 6295 enum iwl_mvm_rxq_notif_type type, 6296 bool sync, 6297 const void *data, u32 size) 6298 { 6299 struct { 6300 struct iwl_rxq_sync_cmd cmd; 6301 struct iwl_mvm_internal_rxq_notif notif; 6302 } __packed cmd = { 6303 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 6304 .cmd.count = 6305 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 6306 size), 6307 .notif.type = type, 6308 .notif.sync = sync, 6309 }; 6310 struct iwl_host_cmd hcmd = { 6311 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 6312 .data[0] = &cmd, 6313 .len[0] = sizeof(cmd), 6314 .data[1] = data, 6315 .len[1] = size, 6316 .flags = CMD_SEND_IN_RFKILL | (sync ? 0 : CMD_ASYNC), 6317 }; 6318 int ret; 6319 6320 /* size must be a multiple of DWORD */ 6321 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 6322 return; 6323 6324 if (!iwl_mvm_has_new_rx_api(mvm)) 6325 return; 6326 6327 if (sync) { 6328 cmd.notif.cookie = mvm->queue_sync_cookie; 6329 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 6330 } 6331 6332 ret = iwl_mvm_send_cmd(mvm, &hcmd); 6333 if (ret) { 6334 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 6335 goto out; 6336 } 6337 6338 if (sync) { 6339 lockdep_assert_held(&mvm->mutex); 6340 ret = wait_event_timeout(mvm->rx_sync_waitq, 6341 READ_ONCE(mvm->queue_sync_state) == 0 || 6342 iwl_mvm_is_radio_hw_killed(mvm), 6343 SYNC_RX_QUEUE_TIMEOUT); 6344 WARN_ONCE(!ret && !iwl_mvm_is_radio_hw_killed(mvm), 6345 "queue sync: failed to sync, state is 0x%lx, cookie %d\n", 6346 mvm->queue_sync_state, 6347 mvm->queue_sync_cookie); 6348 } 6349 6350 out: 6351 if (sync) { 6352 mvm->queue_sync_state = 0; 6353 mvm->queue_sync_cookie++; 6354 } 6355 } 6356 6357 void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 6358 { 6359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6360 6361 guard(mvm)(mvm); 6362 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 6363 } 6364 6365 int 6366 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 6367 struct ieee80211_vif *vif, 6368 struct cfg80211_ftm_responder_stats *stats) 6369 { 6370 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6371 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 6372 6373 if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 6374 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 6375 return -EINVAL; 6376 6377 mutex_lock(&mvm->mutex); 6378 *stats = mvm->ftm_resp_stats; 6379 mutex_unlock(&mvm->mutex); 6380 6381 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 6382 BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 6383 BIT(NL80211_FTM_STATS_FAILED_NUM) | 6384 BIT(NL80211_FTM_STATS_ASAP_NUM) | 6385 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 6386 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 6387 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 6388 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 6389 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 6390 6391 return 0; 6392 } 6393 6394 int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6395 struct cfg80211_pmsr_request *request) 6396 { 6397 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6398 6399 guard(mvm)(mvm); 6400 return iwl_mvm_ftm_start(mvm, vif, request); 6401 } 6402 6403 void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6404 struct cfg80211_pmsr_request *request) 6405 { 6406 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6407 6408 guard(mvm)(mvm); 6409 iwl_mvm_ftm_abort(mvm, request); 6410 } 6411 6412 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 6413 { 6414 u8 protocol = ip_hdr(skb)->protocol; 6415 6416 if (!IS_ENABLED(CONFIG_INET)) 6417 return false; 6418 6419 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 6420 } 6421 6422 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 6423 struct sk_buff *head, 6424 struct sk_buff *skb) 6425 { 6426 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6427 6428 /* For now don't aggregate IPv6 in AMSDU */ 6429 if (skb->protocol != htons(ETH_P_IP)) 6430 return false; 6431 6432 if (!iwl_mvm_is_csum_supported(mvm)) 6433 return true; 6434 6435 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 6436 } 6437 6438 int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw, 6439 struct ieee80211_vif *vif, 6440 struct cfg80211_set_hw_timestamp *hwts) 6441 { 6442 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6443 u32 protocols = 0; 6444 6445 /* HW timestamping is only supported for a specific station */ 6446 if (!hwts->macaddr) 6447 return -EOPNOTSUPP; 6448 6449 if (hwts->enable) 6450 protocols = 6451 IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM; 6452 6453 guard(mvm)(mvm); 6454 return iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols); 6455 } 6456 6457 const struct ieee80211_ops iwl_mvm_hw_ops = { 6458 .tx = iwl_mvm_mac_tx, 6459 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 6460 .ampdu_action = iwl_mvm_mac_ampdu_action, 6461 .get_antenna = iwl_mvm_op_get_antenna, 6462 .set_antenna = iwl_mvm_op_set_antenna, 6463 .start = iwl_mvm_mac_start, 6464 .reconfig_complete = iwl_mvm_mac_reconfig_complete, 6465 .stop = iwl_mvm_mac_stop, 6466 .add_interface = iwl_mvm_mac_add_interface, 6467 .remove_interface = iwl_mvm_mac_remove_interface, 6468 .config = iwl_mvm_mac_config, 6469 .prepare_multicast = iwl_mvm_prepare_multicast, 6470 .configure_filter = iwl_mvm_configure_filter, 6471 .config_iface_filter = iwl_mvm_config_iface_filter, 6472 .bss_info_changed = iwl_mvm_bss_info_changed, 6473 .hw_scan = iwl_mvm_mac_hw_scan, 6474 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 6475 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 6476 .sta_state = iwl_mvm_mac_sta_state, 6477 .sta_notify = iwl_mvm_mac_sta_notify, 6478 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 6479 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 6480 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 6481 .sta_rc_update = iwl_mvm_sta_rc_update, 6482 .conf_tx = iwl_mvm_mac_conf_tx, 6483 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 6484 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 6485 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 6486 .flush = iwl_mvm_mac_flush, 6487 .flush_sta = iwl_mvm_mac_flush_sta, 6488 .sched_scan_start = iwl_mvm_mac_sched_scan_start, 6489 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 6490 .set_key = iwl_mvm_mac_set_key, 6491 .update_tkip_key = iwl_mvm_mac_update_tkip_key, 6492 .remain_on_channel = iwl_mvm_roc, 6493 .cancel_remain_on_channel = iwl_mvm_cancel_roc, 6494 .add_chanctx = iwl_mvm_add_chanctx, 6495 .remove_chanctx = iwl_mvm_remove_chanctx, 6496 .change_chanctx = iwl_mvm_change_chanctx, 6497 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 6498 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 6499 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 6500 6501 .start_ap = iwl_mvm_start_ap, 6502 .stop_ap = iwl_mvm_stop_ap, 6503 .join_ibss = iwl_mvm_start_ibss, 6504 .leave_ibss = iwl_mvm_stop_ibss, 6505 6506 .tx_last_beacon = iwl_mvm_tx_last_beacon, 6507 6508 .set_tim = iwl_mvm_set_tim, 6509 6510 .channel_switch = iwl_mvm_channel_switch, 6511 .pre_channel_switch = iwl_mvm_mac_pre_channel_switch, 6512 .post_channel_switch = iwl_mvm_post_channel_switch, 6513 .abort_channel_switch = iwl_mvm_abort_channel_switch, 6514 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 6515 6516 .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 6517 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 6518 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 6519 6520 .event_callback = iwl_mvm_mac_event_callback, 6521 6522 .sync_rx_queues = iwl_mvm_sync_rx_queues, 6523 6524 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 6525 6526 #ifdef CONFIG_PM_SLEEP 6527 /* look at d3.c */ 6528 .suspend = iwl_mvm_suspend, 6529 .resume = iwl_mvm_resume, 6530 .set_wakeup = iwl_mvm_set_wakeup, 6531 .set_rekey_data = iwl_mvm_set_rekey_data, 6532 #if IS_ENABLED(CONFIG_IPV6) 6533 .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 6534 #endif 6535 .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 6536 #endif 6537 .get_survey = iwl_mvm_mac_get_survey, 6538 .sta_statistics = iwl_mvm_mac_sta_statistics, 6539 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 6540 .start_pmsr = iwl_mvm_start_pmsr, 6541 .abort_pmsr = iwl_mvm_abort_pmsr, 6542 6543 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 6544 #ifdef CONFIG_IWLWIFI_DEBUGFS 6545 .vif_add_debugfs = iwl_mvm_vif_add_debugfs, 6546 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs, 6547 #endif 6548 .set_hw_timestamp = iwl_mvm_set_hw_timestamp, 6549 }; 6550