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