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