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