18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28e99ea8dSJohannes Berg /* 3091296d3SMiri Korenblit * Copyright (C) 2012-2014, 2018-2022 Intel Corporation 48e99ea8dSJohannes Berg * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 58e99ea8dSJohannes Berg * Copyright (C) 2016-2017 Intel Deutschland GmbH 68e99ea8dSJohannes Berg */ 7e705c121SKalle Valo #include <linux/kernel.h> 8e705c121SKalle Valo #include <linux/slab.h> 9e705c121SKalle Valo #include <linux/skbuff.h> 10e705c121SKalle Valo #include <linux/netdevice.h> 11e705c121SKalle Valo #include <linux/etherdevice.h> 12e705c121SKalle Valo #include <linux/ip.h> 13e705c121SKalle Valo #include <linux/if_arp.h> 142f89a5d7SGolan Ben-Ami #include <linux/time.h> 15e705c121SKalle Valo #include <net/mac80211.h> 16e705c121SKalle Valo #include <net/ieee80211_radiotap.h> 17e705c121SKalle Valo #include <net/tcp.h> 18e705c121SKalle Valo 195283dd67SMordechay Goodstein #include "iwl-drv.h" 20e705c121SKalle Valo #include "iwl-op-mode.h" 21e705c121SKalle Valo #include "iwl-io.h" 22e705c121SKalle Valo #include "mvm.h" 23e705c121SKalle Valo #include "sta.h" 24e705c121SKalle Valo #include "time-event.h" 25e705c121SKalle Valo #include "iwl-eeprom-parse.h" 26e705c121SKalle Valo #include "iwl-phy-db.h" 27e705c121SKalle Valo #include "testmode.h" 28d962f9b1SJohannes Berg #include "fw/error-dump.h" 29e705c121SKalle Valo #include "iwl-prph.h" 30e705c121SKalle Valo #include "iwl-nvm-parse.h" 31cf85123aSAvraham Stern #include "time-sync.h" 32e705c121SKalle Valo 33e705c121SKalle Valo static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 34e705c121SKalle Valo { 35e705c121SKalle Valo .max = 1, 36e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_STATION), 37e705c121SKalle Valo }, 38e705c121SKalle Valo { 39e705c121SKalle Valo .max = 1, 40e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_AP) | 41e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 42e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO), 43e705c121SKalle Valo }, 44e705c121SKalle Valo { 45e705c121SKalle Valo .max = 1, 46e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 47e705c121SKalle Valo }, 48e705c121SKalle Valo }; 49e705c121SKalle Valo 50e705c121SKalle Valo static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 51e705c121SKalle Valo { 52e705c121SKalle Valo .num_different_channels = 2, 53e705c121SKalle Valo .max_interfaces = 3, 54e705c121SKalle Valo .limits = iwl_mvm_limits, 55e705c121SKalle Valo .n_limits = ARRAY_SIZE(iwl_mvm_limits), 56e705c121SKalle Valo }, 57e705c121SKalle Valo }; 58e705c121SKalle Valo 59fc36ffdaSJohannes Berg static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { 60fc36ffdaSJohannes Berg .max_peers = IWL_MVM_TOF_MAX_APS, 61fc36ffdaSJohannes Berg .report_ap_tsf = 1, 62fc36ffdaSJohannes Berg .randomize_mac_addr = 1, 63fc36ffdaSJohannes Berg 64fc36ffdaSJohannes Berg .ftm = { 65fc36ffdaSJohannes Berg .supported = 1, 66fc36ffdaSJohannes Berg .asap = 1, 67fc36ffdaSJohannes Berg .non_asap = 1, 68fc36ffdaSJohannes Berg .request_lci = 1, 69fc36ffdaSJohannes Berg .request_civicloc = 1, 706815e3d0SAvraham Stern .trigger_based = 1, 716815e3d0SAvraham Stern .non_trigger_based = 1, 72fc36ffdaSJohannes Berg .max_bursts_exponent = -1, /* all supported */ 73fc36ffdaSJohannes Berg .max_ftms_per_burst = 0, /* no limits */ 74fc36ffdaSJohannes Berg .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 75fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_20) | 76fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_40) | 778a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_80) | 788a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_160), 79fc36ffdaSJohannes Berg .preambles = BIT(NL80211_PREAMBLE_LEGACY) | 80fc36ffdaSJohannes Berg BIT(NL80211_PREAMBLE_HT) | 816815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_VHT) | 826815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_HE), 83fc36ffdaSJohannes Berg }, 84fc36ffdaSJohannes Berg }; 85fc36ffdaSJohannes Berg 866569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 87c56e00a3SJohannes Berg enum set_key_cmd cmd, 88c56e00a3SJohannes Berg struct ieee80211_vif *vif, 89c56e00a3SJohannes Berg struct ieee80211_sta *sta, 90c56e00a3SJohannes Berg struct ieee80211_key_conf *key); 91c56e00a3SJohannes Berg 92e705c121SKalle Valo static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 93e705c121SKalle Valo { 94e705c121SKalle Valo int i; 95e705c121SKalle Valo 96e705c121SKalle Valo memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 97e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 98e705c121SKalle Valo mvm->phy_ctxts[i].id = i; 99e705c121SKalle Valo mvm->phy_ctxts[i].ref = 0; 100e705c121SKalle Valo } 101e705c121SKalle Valo } 102e705c121SKalle Valo 103e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 104e705c121SKalle Valo const char *alpha2, 105e705c121SKalle Valo enum iwl_mcc_source src_id, 106e705c121SKalle Valo bool *changed) 107e705c121SKalle Valo { 108e705c121SKalle Valo struct ieee80211_regdomain *regd = NULL; 109e705c121SKalle Valo struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 110e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 111e705c121SKalle Valo struct iwl_mcc_update_resp *resp; 112e27c506aSGil Adam u8 resp_ver; 113e705c121SKalle Valo 114e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 115e705c121SKalle Valo 116e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 117e705c121SKalle Valo 118e705c121SKalle Valo resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 119e705c121SKalle Valo if (IS_ERR_OR_NULL(resp)) { 120e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 121e705c121SKalle Valo PTR_ERR_OR_ZERO(resp)); 1226d19a5ebSEmmanuel Grumbach resp = NULL; 123e705c121SKalle Valo goto out; 124e705c121SKalle Valo } 125e705c121SKalle Valo 12682715ac7SEmmanuel Grumbach if (changed) { 12782715ac7SEmmanuel Grumbach u32 status = le32_to_cpu(resp->status); 12882715ac7SEmmanuel Grumbach 12982715ac7SEmmanuel Grumbach *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || 13082715ac7SEmmanuel Grumbach status == MCC_RESP_ILLEGAL); 13182715ac7SEmmanuel Grumbach } 132e27c506aSGil Adam resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, 133e27c506aSGil Adam MCC_UPDATE_CMD, 0); 134e27c506aSGil Adam IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver); 135e705c121SKalle Valo 136e705c121SKalle Valo regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 137e705c121SKalle Valo __le32_to_cpu(resp->n_channels), 138e705c121SKalle Valo resp->channels, 13977e30e10SHaim Dreyfuss __le16_to_cpu(resp->mcc), 1402763bba6SHaim Dreyfuss __le16_to_cpu(resp->geo_info), 141e27c506aSGil Adam __le16_to_cpu(resp->cap), resp_ver); 142e705c121SKalle Valo /* Store the return source id */ 143e705c121SKalle Valo src_id = resp->source_id; 144e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 145e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 146e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 147e705c121SKalle Valo goto out; 148e705c121SKalle Valo } 149e705c121SKalle Valo 150e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 151e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 152e705c121SKalle Valo mvm->lar_regdom_set = true; 153e705c121SKalle Valo mvm->mcc_src = src_id; 154e705c121SKalle Valo 1556d19a5ebSEmmanuel Grumbach iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); 1566d19a5ebSEmmanuel Grumbach 157e705c121SKalle Valo out: 1586d19a5ebSEmmanuel Grumbach kfree(resp); 159e705c121SKalle Valo return regd; 160e705c121SKalle Valo } 161e705c121SKalle Valo 162e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 163e705c121SKalle Valo { 164e705c121SKalle Valo bool changed; 165e705c121SKalle Valo struct ieee80211_regdomain *regd; 166e705c121SKalle Valo 167e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 168e705c121SKalle Valo return; 169e705c121SKalle Valo 170e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 171e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 172e705c121SKalle Valo /* only update the regulatory core if changed */ 173e705c121SKalle Valo if (changed) 174e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 175e705c121SKalle Valo 176e705c121SKalle Valo kfree(regd); 177e705c121SKalle Valo } 178e705c121SKalle Valo } 179e705c121SKalle Valo 180e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 181e705c121SKalle Valo bool *changed) 182e705c121SKalle Valo { 183e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 184e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 185e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 186e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 187e705c121SKalle Valo } 188e705c121SKalle Valo 189e705c121SKalle Valo int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) 190e705c121SKalle Valo { 191e705c121SKalle Valo enum iwl_mcc_source used_src; 192e705c121SKalle Valo struct ieee80211_regdomain *regd; 193e705c121SKalle Valo int ret; 194e705c121SKalle Valo bool changed; 195e705c121SKalle Valo const struct ieee80211_regdomain *r = 196a05829a7SJohannes Berg wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); 197e705c121SKalle Valo 198e705c121SKalle Valo if (!r) 199e705c121SKalle Valo return -ENOENT; 200e705c121SKalle Valo 201e705c121SKalle Valo /* save the last source in case we overwrite it below */ 202e705c121SKalle Valo used_src = mvm->mcc_src; 203e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 204e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 205e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 206e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 207e705c121SKalle Valo kfree(regd); 208e705c121SKalle Valo } 209e705c121SKalle Valo 210e705c121SKalle Valo /* Now set our last stored MCC and source */ 211e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 212e705c121SKalle Valo &changed); 213e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 214e705c121SKalle Valo return -EIO; 215e705c121SKalle Valo 216e705c121SKalle Valo /* update cfg80211 if the regdomain was changed */ 217e705c121SKalle Valo if (changed) 218a05829a7SJohannes Berg ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); 219e705c121SKalle Valo else 220e705c121SKalle Valo ret = 0; 221e705c121SKalle Valo 222e705c121SKalle Valo kfree(regd); 223e705c121SKalle Valo return ret; 224e705c121SKalle Valo } 225e705c121SKalle Valo 2268e33f046SKrishnanand Prabhu /* Each capability added here should also be add to tm_if_types_ext_capa_sta */ 2277f2ea521SYueHaibing static const u8 he_if_types_ext_capa_sta[] = { 2287360f99eSEmmanuel Grumbach [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 229918cbf39SSara Sharon [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 2307360f99eSEmmanuel Grumbach [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 2317360f99eSEmmanuel Grumbach }; 2327360f99eSEmmanuel Grumbach 2338e33f046SKrishnanand Prabhu static const u8 tm_if_types_ext_capa_sta[] = { 2348e33f046SKrishnanand Prabhu [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 2358e33f046SKrishnanand Prabhu [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT | 2368e33f046SKrishnanand Prabhu WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT, 2378e33f046SKrishnanand Prabhu [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 2388e33f046SKrishnanand Prabhu [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, 2398e33f046SKrishnanand Prabhu }; 2408e33f046SKrishnanand Prabhu 2418e33f046SKrishnanand Prabhu /* Additional interface types for which extended capabilities are 2428e33f046SKrishnanand Prabhu * specified separately 2438e33f046SKrishnanand Prabhu */ 2448e33f046SKrishnanand Prabhu static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = { 2457360f99eSEmmanuel Grumbach { 2467360f99eSEmmanuel Grumbach .iftype = NL80211_IFTYPE_STATION, 2477360f99eSEmmanuel Grumbach .extended_capabilities = he_if_types_ext_capa_sta, 2487360f99eSEmmanuel Grumbach .extended_capabilities_mask = he_if_types_ext_capa_sta, 2497360f99eSEmmanuel Grumbach .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), 2507360f99eSEmmanuel Grumbach }, 2518e33f046SKrishnanand Prabhu { 2528e33f046SKrishnanand Prabhu .iftype = NL80211_IFTYPE_STATION, 2538e33f046SKrishnanand Prabhu .extended_capabilities = tm_if_types_ext_capa_sta, 2548e33f046SKrishnanand Prabhu .extended_capabilities_mask = tm_if_types_ext_capa_sta, 2558e33f046SKrishnanand Prabhu .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta), 2568e33f046SKrishnanand Prabhu /* relevant only if EHT is supported */ 2578e33f046SKrishnanand Prabhu .eml_capabilities = IEEE80211_EML_CAP_EMLSR_SUPP, 2588e33f046SKrishnanand Prabhu }, 2597360f99eSEmmanuel Grumbach }; 2607360f99eSEmmanuel Grumbach 261cbce62a3SMiri Korenblit int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 262e8503aecSBen Greear { 263e8503aecSBen Greear struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 264e8503aecSBen Greear *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); 265e8503aecSBen Greear *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); 266e8503aecSBen Greear return 0; 267e8503aecSBen Greear } 268e8503aecSBen Greear 269e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 270e705c121SKalle Valo { 271e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 272e705c121SKalle Valo int num_mac, ret, i; 273e705c121SKalle Valo static const u32 mvm_ciphers[] = { 274e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 275e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 276e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 277e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 278e705c121SKalle Valo }; 2793f37c229SIdo Yariv #ifdef CONFIG_PM_SLEEP 2803f37c229SIdo Yariv bool unified = fw_has_capa(&mvm->fw->ucode_capa, 2813f37c229SIdo Yariv IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); 2823f37c229SIdo Yariv #endif 283a5de7de7SJohannes Berg u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 284a5de7de7SJohannes Berg u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 285e705c121SKalle Valo 286e705c121SKalle Valo /* Tell mac80211 our characteristics */ 287e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 288e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 289e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 290e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 291e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 292e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 293e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 294e705c121SKalle Valo ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 295e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 296e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 297e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 298e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 299909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 30030433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 301d270e7b8SIlan Peer ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 302520229e4SShaul Triebitz ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 303cfbc6c4cSSara Sharon ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); 304cfbc6c4cSSara Sharon ieee80211_hw_set(hw, STA_MMPDU_TXQ); 305cfb21b11SJohannes Berg /* 306cfb21b11SJohannes Berg * On older devices, enabling TX A-MSDU occasionally leads to 307cfb21b11SJohannes Berg * something getting messed up, the command read from the FIFO 308cfb21b11SJohannes Berg * gets out of sync and isn't a TX command, so that we have an 309cfb21b11SJohannes Berg * assert EDC. 310cfb21b11SJohannes Berg * 311cfb21b11SJohannes Berg * It's not clear where the bug is, but since we didn't used to 312cfb21b11SJohannes Berg * support A-MSDU until moving the mac80211 iTXQs, just leave it 313cfb21b11SJohannes Berg * for older devices. We also don't see this issue on any newer 314cfb21b11SJohannes Berg * devices. 315cfb21b11SJohannes Berg */ 3167d34a7d7SLuca Coelho if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) 317438af969SSara Sharon ieee80211_hw_set(hw, TX_AMSDU); 318438af969SSara Sharon ieee80211_hw_set(hw, TX_FRAG_LIST); 319ecaf71deSGregory Greenman 3204243edb4SEmmanuel Grumbach if (iwl_mvm_has_tlc_offload(mvm)) { 321ecaf71deSGregory Greenman ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 322ecaf71deSGregory Greenman ieee80211_hw_set(hw, HAS_RATE_CONTROL); 323ecaf71deSGregory Greenman } 324ecaf71deSGregory Greenman 325b915c101SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 326b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 327960f864bSJohannes Berg 328960f864bSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 329960f864bSJohannes Berg IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 33065e25482SJohannes Berg ieee80211_hw_set(hw, AP_LINK_PS); 331960f864bSJohannes Berg } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 332960f864bSJohannes Berg /* 333960f864bSJohannes Berg * we absolutely need this for the new TX API since that comes 334960f864bSJohannes Berg * with many more queues than the current code can deal with 335960f864bSJohannes Berg * for station powersave 336960f864bSJohannes Berg */ 337960f864bSJohannes Berg return -EINVAL; 338960f864bSJohannes Berg } 339e705c121SKalle Valo 34080938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 34180938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 34280938abcSJohannes Berg 3432d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 3442d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 3452d7cf549SJohannes Berg 346366fc672SJohannes Berg hw->queues = IEEE80211_NUM_ACS; 347e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 348e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 349e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 350e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 351e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 352371a17edSJohannes Berg 353371a17edSJohannes Berg hw->radiotap_timestamp.units_pos = 354371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 355371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 356371a17edSJohannes Berg /* this is the case for CCK frames, it's better (only 8) for OFDM */ 357371a17edSJohannes Berg hw->radiotap_timestamp.accuracy = 22; 358371a17edSJohannes Berg 3594243edb4SEmmanuel Grumbach if (!iwl_mvm_has_tlc_offload(mvm)) 3609f66a397SGregory Greenman hw->rate_control_algorithm = RS_NAME; 3619f66a397SGregory Greenman 362e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 363e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 364438af969SSara Sharon hw->max_tx_fragments = mvm->trans->max_skb_frags; 365e705c121SKalle Valo 3668e160ab8SAyala Beker BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 367e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 368e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 369e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 370e705c121SKalle Valo 3712a53d166SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 3722a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3732a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP; 3742a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 3752a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3762a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP_256; 3772a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 3782a53d166SAyala Beker } 3792a53d166SAyala Beker 380f4bfdc5eSEmmanuel Grumbach if (iwlwifi_mod_params.swcrypto) 381f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 382f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); 383f4bfdc5eSEmmanuel Grumbach if (!iwlwifi_mod_params.bt_coex_active) 384f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 385f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); 386f4bfdc5eSEmmanuel Grumbach 387e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 388f4bfdc5eSEmmanuel Grumbach mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; 389e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 3908e160ab8SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 3918e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3928e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_128; 3938e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 3948e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3958e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_256; 3968e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 3978e160ab8SAyala Beker } 398e705c121SKalle Valo 399ef2e7a51SIlan Peer wiphy_ext_feature_set(hw->wiphy, 400ef2e7a51SIlan Peer NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); 401ef2e7a51SIlan Peer 402b73f9a4aSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 403fc36ffdaSJohannes Berg IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { 404b73f9a4aSJohannes Berg wiphy_ext_feature_set(hw->wiphy, 405b73f9a4aSJohannes Berg NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); 406fc36ffdaSJohannes Berg hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; 407fc36ffdaSJohannes Berg } 408b73f9a4aSJohannes Berg 409a5de7de7SJohannes Berg if (sec_key_ver && 410a5de7de7SJohannes Berg fw_has_capa(&mvm->fw->ucode_capa, 411a5de7de7SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT)) 412a5de7de7SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 413a5de7de7SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION); 414a5de7de7SJohannes Berg else if (fw_has_capa(&mvm->fw->ucode_capa, 415b1fdc250SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) 416b1fdc250SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 417b1fdc250SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); 418b1fdc250SJohannes Berg 419cf85123aSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 420cf85123aSAvraham Stern IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM)) 421cf85123aSAvraham Stern hw->wiphy->hw_timestamp_max_peers = 1; 422cf85123aSAvraham Stern 423e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 424e705c121SKalle Valo hw->wiphy->features |= 425e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 426e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 427e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 428e705c121SKalle Valo 429e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 430e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 431e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 432cfbc6c4cSSara Sharon hw->txq_data_size = sizeof(struct iwl_mvm_txq); 433e705c121SKalle Valo 434e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 435e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 436e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 437e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 438e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 439e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 440e705c121SKalle Valo 441e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 442e47df5bdSJohannes Berg wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 44333e3fd99SAlexander Wetzel 44433e3fd99SAlexander Wetzel /* The new Tx API does not allow to pass the key or keyid of a MPDU to 44533e3fd99SAlexander Wetzel * the hw, preventing us to control which key(id) to use per MPDU. 44633e3fd99SAlexander Wetzel * Till that's fixed we can't use Extended Key ID for the newer cards. 44733e3fd99SAlexander Wetzel */ 44833e3fd99SAlexander Wetzel if (!iwl_mvm_has_new_tx_api(mvm)) 44933e3fd99SAlexander Wetzel wiphy_ext_feature_set(hw->wiphy, 45033e3fd99SAlexander Wetzel NL80211_EXT_FEATURE_EXT_KEY_ID); 451e47df5bdSJohannes Berg hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; 452e47df5bdSJohannes Berg 453e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 454e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 455e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 456e705c121SKalle Valo else 457e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 458e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 459e705c121SKalle Valo 460e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 461e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 462eae94cf8SLuca Coelho hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; 463e705c121SKalle Valo 464e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 465e705c121SKalle Valo hw->wiphy->n_iface_combinations = 466e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 467e705c121SKalle Valo 468e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 469e705c121SKalle Valo hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 470e705c121SKalle Valo 471e705c121SKalle Valo /* Extract MAC address */ 472e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 473e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 474e705c121SKalle Valo hw->wiphy->n_addresses = 1; 475e705c121SKalle Valo 476e705c121SKalle Valo /* Extract additional MAC addresses if available */ 477e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 478e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 479e705c121SKalle Valo 480e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 481e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 482e705c121SKalle Valo ETH_ALEN); 483e705c121SKalle Valo mvm->addresses[i].addr[5]++; 484e705c121SKalle Valo hw->wiphy->n_addresses++; 485e705c121SKalle Valo } 486e705c121SKalle Valo 487e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 488e705c121SKalle Valo 489e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 490e705c121SKalle Valo 491e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 492e705c121SKalle Valo 493e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 494e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 495e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 496e705c121SKalle Valo 497e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 498e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 499e705c121SKalle Valo else 500e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 501e705c121SKalle Valo 50257fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 50357fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 50457fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 50557fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 50657fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 50757fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 508e705c121SKalle Valo 509e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 510e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 511e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 512e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 51357fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 514e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 515e705c121SKalle Valo } 516eae94cf8SLuca Coelho if (fw_has_capa(&mvm->fw->ucode_capa, 517eae94cf8SLuca Coelho IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && 518eae94cf8SLuca Coelho mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) 519eae94cf8SLuca Coelho hw->wiphy->bands[NL80211_BAND_6GHZ] = 520eae94cf8SLuca Coelho &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; 521e705c121SKalle Valo 522e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 523e705c121SKalle Valo 524e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 525e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 526e705c121SKalle Valo else 527e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 528e705c121SKalle Valo 529ca986ad9SArend Van Spriel hw->wiphy->max_sched_scan_reqs = 1; 530e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 5315d1234baSTova Mussai hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); 532e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 533e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 534e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 535e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 536e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 537e705c121SKalle Valo 538e705c121SKalle Valo /* 539e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 540e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 541e705c121SKalle Valo */ 542e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 543e705c121SKalle Valo 544e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 545e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 546e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 547a904a08bSPeer, Ilan NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 548e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 549e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 550e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 551e705c121SKalle Valo 552e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 553e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 554e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 555e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 556e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 557e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 558e705c121SKalle Valo 559e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 560e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 561e705c121SKalle Valo hw->wiphy->features |= 562e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 563e705c121SKalle Valo 564e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 565e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 566e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 567e705c121SKalle Valo 568971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL, 5692a42aea7SNathan Errera IWL_FW_CMD_VER_UNKNOWN) == 3) 5702a42aea7SNathan Errera hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; 5712a42aea7SNathan Errera 572aacf8f18SAvrahams Stern if (fw_has_api(&mvm->fw->ucode_capa, 573aacf8f18SAvrahams Stern IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 574aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 575aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SCAN_START_TIME); 576aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 577aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_BSS_PARENT_TSF); 578aacf8f18SAvrahams Stern } 579aacf8f18SAvrahams Stern 5808f691af9SZamir, Roee if (iwl_mvm_is_oce_supported(mvm)) { 581971cbe50SJohannes Berg u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0); 582773a042fSAvraham Stern 5838f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5848f691af9SZamir, Roee NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 5858f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5868f691af9SZamir, Roee NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 5878f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5888f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 589773a042fSAvraham Stern 590773a042fSAvraham Stern /* Old firmware also supports probe deferral and suppression */ 591773a042fSAvraham Stern if (scan_ver < 15) 592773a042fSAvraham Stern wiphy_ext_feature_set(hw->wiphy, 593773a042fSAvraham Stern NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 5948f691af9SZamir, Roee } 5958f691af9SZamir, Roee 5968e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = NULL; 5978e33f046SKrishnanand Prabhu hw->wiphy->num_iftype_ext_capab = 0; 5988e33f046SKrishnanand Prabhu 5997360f99eSEmmanuel Grumbach if (mvm->nvm_data->sku_cap_11ax_enable && 6007360f99eSEmmanuel Grumbach !iwlwifi_mod_params.disable_11ax) { 6018e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa; 6027360f99eSEmmanuel Grumbach hw->wiphy->num_iftype_ext_capab = 6038e33f046SKrishnanand Prabhu ARRAY_SIZE(add_iftypes_ext_capa) - 1; 604918cbf39SSara Sharon 605918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 606918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 6077360f99eSEmmanuel Grumbach } 6087360f99eSEmmanuel Grumbach 6098e33f046SKrishnanand Prabhu if (iwl_fw_lookup_cmd_ver(mvm->fw, 6108e33f046SKrishnanand Prabhu WIDE_ID(DATA_PATH_GROUP, 6118e33f046SKrishnanand Prabhu WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD), 6128e33f046SKrishnanand Prabhu IWL_FW_CMD_VER_UNKNOWN) >= 1) { 6138e33f046SKrishnanand Prabhu IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n"); 6148e33f046SKrishnanand Prabhu 6158e33f046SKrishnanand Prabhu if (!hw->wiphy->iftype_ext_capab) { 6168e33f046SKrishnanand Prabhu hw->wiphy->num_iftype_ext_capab = 1; 6178e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 6188e33f046SKrishnanand Prabhu ARRAY_SIZE(add_iftypes_ext_capa) - 1; 6198e33f046SKrishnanand Prabhu } else { 6208e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1; 6218e33f046SKrishnanand Prabhu } 6228e33f046SKrishnanand Prabhu } 6238e33f046SKrishnanand Prabhu 624e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 625e705c121SKalle Valo 626e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 6273f37c229SIdo Yariv if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 628e705c121SKalle Valo mvm->trans->ops->d3_suspend && 629e705c121SKalle Valo mvm->trans->ops->d3_resume && 630e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 631e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 632e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 633e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 634e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 635e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 636e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 637e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 638e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 639e705c121SKalle Valo 640e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 641e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 642e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 6435d1234baSTova Mussai mvm->wowlan.max_nd_match_sets = 6445d1234baSTova Mussai iwl_umac_scan_get_max_profiles(mvm->fw); 645e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 646e705c121SKalle Valo } 647e705c121SKalle Valo #endif 648e705c121SKalle Valo 649e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 650e705c121SKalle Valo if (ret) 651e705c121SKalle Valo return ret; 652e705c121SKalle Valo 653e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 654e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 655e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 656e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 657e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 658e705c121SKalle Valo } 659e705c121SKalle Valo 660e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 661e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 662e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 663e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 664e705c121SKalle Valo } 665e705c121SKalle Valo 666e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 66759fa61f3SEmmanuel Grumbach if (!iwl_mvm_is_csum_supported(mvm)) 6686772aab7SJohannes Berg hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; 66941837ca9SEmmanuel Grumbach 67091b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 67191b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 67291b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 67391b08c2dSAviya Erenfeld 6749c11d8a9SShaul Triebitz if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 6759c11d8a9SShaul Triebitz wiphy_ext_feature_set(hw->wiphy, 6769c11d8a9SShaul Triebitz NL80211_EXT_FEATURE_PROTECTED_TWT); 6779c11d8a9SShaul Triebitz 678bfcfdb59SEmmanuel Grumbach iwl_mvm_vendor_cmds_register(mvm); 679bfcfdb59SEmmanuel Grumbach 680e8503aecSBen Greear hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 681e8503aecSBen Greear hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 682e8503aecSBen Greear 683de645e89SJohannes Berg ret = ieee80211_register_hw(mvm->hw); 684de645e89SJohannes Berg if (ret) { 685de645e89SJohannes Berg iwl_mvm_leds_exit(mvm); 686e705c121SKalle Valo } 687e705c121SKalle Valo 688e705c121SKalle Valo return ret; 689e705c121SKalle Valo } 690e705c121SKalle Valo 691df2378abSJohannes Berg static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 692df2378abSJohannes Berg struct ieee80211_sta *sta) 693df2378abSJohannes Berg { 694df2378abSJohannes Berg if (likely(sta)) { 695df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 696df2378abSJohannes Berg return; 697df2378abSJohannes Berg } else { 698df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 699df2378abSJohannes Berg return; 700df2378abSJohannes Berg } 701df2378abSJohannes Berg 702df2378abSJohannes Berg ieee80211_free_txskb(mvm->hw, skb); 703df2378abSJohannes Berg } 704df2378abSJohannes Berg 705cbce62a3SMiri Korenblit void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 706cbce62a3SMiri Korenblit struct ieee80211_tx_control *control, struct sk_buff *skb) 707e705c121SKalle Valo { 708e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 709e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 710e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 711e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 712cfbc6c4cSSara Sharon bool offchannel = IEEE80211_SKB_CB(skb)->flags & 713cfbc6c4cSSara Sharon IEEE80211_TX_CTL_TX_OFFCHAN; 714e705c121SKalle Valo 715e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 716e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 717e705c121SKalle Valo goto drop; 718e705c121SKalle Valo } 719e705c121SKalle Valo 720cfbc6c4cSSara Sharon if (offchannel && 721e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 722e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 723e705c121SKalle Valo goto drop; 724e705c121SKalle Valo 72510516783SJohannes Berg /* 72610516783SJohannes Berg * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 72710516783SJohannes Berg * so we treat the others as broadcast 72810516783SJohannes Berg */ 72910516783SJohannes Berg if (ieee80211_is_mgmt(hdr->frame_control)) 730e705c121SKalle Valo sta = NULL; 731e705c121SKalle Valo 732dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 733cfbc6c4cSSara Sharon if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 734cfbc6c4cSSara Sharon !offchannel) { 735dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 736dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 737650cadb7SGregory Greenman u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id); 738dc1aca22SAndrei Otcheretianski 739be9ae34eSNathan Errera if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 740dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 741dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 742dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 743dc1aca22SAndrei Otcheretianski goto drop; 744dc1aca22SAndrei Otcheretianski } 745dc1aca22SAndrei Otcheretianski } 746dc1aca22SAndrei Otcheretianski 747df2378abSJohannes Berg iwl_mvm_tx_skb(mvm, skb, sta); 748e705c121SKalle Valo return; 749e705c121SKalle Valo drop: 750e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 751e705c121SKalle Valo } 752e705c121SKalle Valo 753cfbc6c4cSSara Sharon void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 754e705c121SKalle Valo { 755cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 756cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 757cfbc6c4cSSara Sharon struct sk_buff *skb = NULL; 758cfbc6c4cSSara Sharon 759fba8248eSSara Sharon /* 760fba8248eSSara Sharon * No need for threads to be pending here, they can leave the first 761fba8248eSSara Sharon * taker all the work. 762fba8248eSSara Sharon * 763fba8248eSSara Sharon * mvmtxq->tx_request logic: 764fba8248eSSara Sharon * 765fba8248eSSara Sharon * If 0, no one is currently TXing, set to 1 to indicate current thread 766fba8248eSSara Sharon * will now start TX and other threads should quit. 767fba8248eSSara Sharon * 768fba8248eSSara Sharon * If 1, another thread is currently TXing, set to 2 to indicate to 769fba8248eSSara Sharon * that thread that there was another request. Since that request may 770fba8248eSSara Sharon * have raced with the check whether the queue is empty, the TXing 771fba8248eSSara Sharon * thread should check the queue's status one more time before leaving. 772fba8248eSSara Sharon * This check is done in order to not leave any TX hanging in the queue 773fba8248eSSara Sharon * until the next TX invocation (which may not even happen). 774fba8248eSSara Sharon * 775fba8248eSSara Sharon * If 2, another thread is currently TXing, and it will already double 776fba8248eSSara Sharon * check the queue, so do nothing. 777fba8248eSSara Sharon */ 778fba8248eSSara Sharon if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 779fba8248eSSara Sharon return; 780cfbc6c4cSSara Sharon 781cfbc6c4cSSara Sharon rcu_read_lock(); 782fba8248eSSara Sharon do { 783cfbc6c4cSSara Sharon while (likely(!mvmtxq->stopped && 78400520b7aSEmmanuel Grumbach !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 785cfbc6c4cSSara Sharon skb = ieee80211_tx_dequeue(hw, txq); 786cfbc6c4cSSara Sharon 787f50d693bSSara Sharon if (!skb) { 788f50d693bSSara Sharon if (txq->sta) 789f50d693bSSara Sharon IWL_DEBUG_TX(mvm, 790f50d693bSSara Sharon "TXQ of sta %pM tid %d is now empty\n", 791f50d693bSSara Sharon txq->sta->addr, 792f50d693bSSara Sharon txq->tid); 793cfbc6c4cSSara Sharon break; 794f50d693bSSara Sharon } 795cfbc6c4cSSara Sharon 796cfbc6c4cSSara Sharon iwl_mvm_tx_skb(mvm, skb, txq->sta); 797cfbc6c4cSSara Sharon } 798fba8248eSSara Sharon } while (atomic_dec_return(&mvmtxq->tx_request)); 799cfbc6c4cSSara Sharon rcu_read_unlock(); 800e705c121SKalle Valo } 801e705c121SKalle Valo 802cbce62a3SMiri Korenblit void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 803cfbc6c4cSSara Sharon struct ieee80211_txq *txq) 804e705c121SKalle Valo { 805cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 806cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 807e705c121SKalle Valo 808cfbc6c4cSSara Sharon /* 809cfbc6c4cSSara Sharon * Please note that racing is handled very carefully here: 810cfbc6c4cSSara Sharon * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is 811cfbc6c4cSSara Sharon * deleted afterwards. 812cfbc6c4cSSara Sharon * This means that if: 813cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list): 814cfbc6c4cSSara Sharon * queue is allocated and we can TX. 815cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list): 816cfbc6c4cSSara Sharon * a race, should defer the frame. 817cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list): 818cfbc6c4cSSara Sharon * need to allocate the queue and defer the frame. 819cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list): 820cfbc6c4cSSara Sharon * queue is already scheduled for allocation, no need to allocate, 821cfbc6c4cSSara Sharon * should defer the frame. 822cfbc6c4cSSara Sharon */ 823cfbc6c4cSSara Sharon 824cfbc6c4cSSara Sharon /* If the queue is allocated TX and return. */ 825cfbc6c4cSSara Sharon if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) { 826cfbc6c4cSSara Sharon /* 827cfbc6c4cSSara Sharon * Check that list is empty to avoid a race where txq_id is 828cfbc6c4cSSara Sharon * already updated, but the queue allocation work wasn't 829cfbc6c4cSSara Sharon * finished 830cfbc6c4cSSara Sharon */ 831cfbc6c4cSSara Sharon if (unlikely(txq->sta && !list_empty(&mvmtxq->list))) 832cfbc6c4cSSara Sharon return; 833cfbc6c4cSSara Sharon 834cfbc6c4cSSara Sharon iwl_mvm_mac_itxq_xmit(hw, txq); 835cfbc6c4cSSara Sharon return; 836cfbc6c4cSSara Sharon } 837cfbc6c4cSSara Sharon 838cfbc6c4cSSara Sharon /* The list is being deleted only after the queue is fully allocated. */ 839cfbc6c4cSSara Sharon if (!list_empty(&mvmtxq->list)) 840cfbc6c4cSSara Sharon return; 841cfbc6c4cSSara Sharon 842cfbc6c4cSSara Sharon list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 843cfbc6c4cSSara Sharon schedule_work(&mvm->add_stream_wk); 844e705c121SKalle Valo } 845e705c121SKalle Valo 846e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 847e705c121SKalle Valo do { \ 848e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 849e705c121SKalle Valo break; \ 8507174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 851e705c121SKalle Valo } while (0) 852e705c121SKalle Valo 853e705c121SKalle Valo static void 854e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 855e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 856e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 857e705c121SKalle Valo { 858e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 859e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 860e705c121SKalle Valo 8616c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 8626c042d75SSara Sharon FW_DBG_TRIGGER_BA); 8636c042d75SSara Sharon if (!trig) 864e705c121SKalle Valo return; 865e705c121SKalle Valo 866e705c121SKalle Valo ba_trig = (void *)trig->data; 867e705c121SKalle Valo 868e705c121SKalle Valo switch (action) { 869e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 870e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 871e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 872e705c121SKalle Valo 873e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 874e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 875e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 876e705c121SKalle Valo break; 877e705c121SKalle Valo } 878e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 879e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 880e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 881e705c121SKalle Valo sta->addr, tid); 882e705c121SKalle Valo break; 883e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 884e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 885e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 886e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 887e705c121SKalle Valo break; 888e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 889e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 890e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 891e705c121SKalle Valo sta->addr, tid); 892e705c121SKalle Valo break; 893e705c121SKalle Valo default: 894e705c121SKalle Valo break; 895e705c121SKalle Valo } 896e705c121SKalle Valo } 897e705c121SKalle Valo 898cbce62a3SMiri Korenblit int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 899e705c121SKalle Valo struct ieee80211_vif *vif, 90050ea05efSSara Sharon struct ieee80211_ampdu_params *params) 901e705c121SKalle Valo { 902e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 903e705c121SKalle Valo int ret; 90450ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 90550ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 90650ea05efSSara Sharon u16 tid = params->tid; 90750ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 908514c3069SLuca Coelho u16 buf_size = params->buf_size; 909bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 91010b2b201SSara Sharon u16 timeout = params->timeout; 911e705c121SKalle Valo 912e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 913e705c121SKalle Valo sta->addr, tid, action); 914e705c121SKalle Valo 915e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 916e705c121SKalle Valo return -EACCES; 917e705c121SKalle Valo 918e705c121SKalle Valo mutex_lock(&mvm->mutex); 919e705c121SKalle Valo 920e705c121SKalle Valo switch (action) { 921e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 922650cadb7SGregory Greenman if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id == 923c8ee33e1SGregory Greenman iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) { 924b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 925b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 926b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 927b0ffe455SJohannes Berg 928b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 929b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 930b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 931b0ffe455SJohannes Berg } 932e78da25eSJohannes Berg if (!iwl_enable_rx_ampdu()) { 933e705c121SKalle Valo ret = -EINVAL; 934e705c121SKalle Valo break; 935e705c121SKalle Valo } 93610b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 93710b2b201SSara Sharon timeout); 938e705c121SKalle Valo break; 939e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 94010b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 94110b2b201SSara Sharon timeout); 942e705c121SKalle Valo break; 943e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 944e78da25eSJohannes Berg if (!iwl_enable_tx_ampdu()) { 945e705c121SKalle Valo ret = -EINVAL; 946e705c121SKalle Valo break; 947e705c121SKalle Valo } 948e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 949e705c121SKalle Valo break; 950e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 951e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 952e705c121SKalle Valo break; 953e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 954e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 955e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 956e705c121SKalle Valo break; 957e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 958bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 959bb81bb68SEmmanuel Grumbach buf_size, amsdu); 960e705c121SKalle Valo break; 961e705c121SKalle Valo default: 962e705c121SKalle Valo WARN_ON_ONCE(1); 963e705c121SKalle Valo ret = -EINVAL; 964e705c121SKalle Valo break; 965e705c121SKalle Valo } 966e705c121SKalle Valo 967e705c121SKalle Valo if (!ret) { 968e705c121SKalle Valo u16 rx_ba_ssn = 0; 969e705c121SKalle Valo 970e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 971e705c121SKalle Valo rx_ba_ssn = *ssn; 972e705c121SKalle Valo 973e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 974e705c121SKalle Valo rx_ba_ssn, action); 975e705c121SKalle Valo } 976e705c121SKalle Valo mutex_unlock(&mvm->mutex); 977e705c121SKalle Valo 978e705c121SKalle Valo return ret; 979e705c121SKalle Valo } 980e705c121SKalle Valo 981e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 982e705c121SKalle Valo struct ieee80211_vif *vif) 983e705c121SKalle Valo { 984e705c121SKalle Valo struct iwl_mvm *mvm = data; 985e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 986e705c121SKalle Valo 987e705c121SKalle Valo mvmvif->uploaded = false; 988650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA; 989e705c121SKalle Valo 990e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 991e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 992e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 993e705c121SKalle Valo 994650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 995e705c121SKalle Valo memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 996650cadb7SGregory Greenman memset(&mvmvif->deflink.probe_resp_data, 0, 997650cadb7SGregory Greenman sizeof(mvmvif->deflink.probe_resp_data)); 998e705c121SKalle Valo } 999e705c121SKalle Valo 1000e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1001e705c121SKalle Valo { 1002fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1003e705c121SKalle Valo 10049bf13beeSJohannes Berg mvm->cur_aid = 0; 10059bf13beeSJohannes Berg 1006e705c121SKalle Valo mvm->scan_status = 0; 1007e705c121SKalle Valo mvm->ps_disabled = false; 1008b3500b47SEmmanuel Grumbach mvm->rfkill_safe_init_done = false; 1009e705c121SKalle Valo 1010e705c121SKalle Valo /* just in case one was running */ 1011305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 1012e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 1013e705c121SKalle Valo 1014fc36ffdaSJohannes Berg iwl_mvm_ftm_restart(mvm); 1015fc36ffdaSJohannes Berg 1016e705c121SKalle Valo /* 1017e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 1018e705c121SKalle Valo * gone down during the HW restart 1019e705c121SKalle Valo */ 1020e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1021e705c121SKalle Valo 1022e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1023e705c121SKalle Valo 1024e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 10259c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1026e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1027e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1028e705c121SKalle Valo 1029e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1030e705c121SKalle Valo 1031e705c121SKalle Valo mvm->rx_ba_sessions = 0; 10327174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 1033baf41bc3SShaul Triebitz mvm->monitor_on = false; 1034e705c121SKalle Valo 1035e705c121SKalle Valo /* keep statistics ticking */ 1036e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1037e705c121SKalle Valo } 1038e705c121SKalle Valo 1039e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1040e705c121SKalle Valo { 1041e705c121SKalle Valo int ret; 1042e705c121SKalle Valo 1043e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1044e705c121SKalle Valo 10456d19a5ebSEmmanuel Grumbach ret = iwl_mvm_mei_get_ownership(mvm); 10466d19a5ebSEmmanuel Grumbach if (ret) 10476d19a5ebSEmmanuel Grumbach return ret; 10486d19a5ebSEmmanuel Grumbach 10496d19a5ebSEmmanuel Grumbach if (mvm->mei_nvm_data) { 10506d19a5ebSEmmanuel Grumbach /* We got the NIC, we can now free the MEI NVM data */ 10516d19a5ebSEmmanuel Grumbach kfree(mvm->mei_nvm_data); 10526d19a5ebSEmmanuel Grumbach mvm->mei_nvm_data = NULL; 10536d19a5ebSEmmanuel Grumbach 10546d19a5ebSEmmanuel Grumbach /* 10556d19a5ebSEmmanuel Grumbach * We can't free the nvm_data we allocated based on the SAP 10566d19a5ebSEmmanuel Grumbach * data because we registered to cfg80211 with the channels 10576d19a5ebSEmmanuel Grumbach * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 10586d19a5ebSEmmanuel Grumbach * just in order to be able free it later. 10596d19a5ebSEmmanuel Grumbach * NULLify nvm_data so that we will read the NVM from the 10606d19a5ebSEmmanuel Grumbach * firmware this time. 10616d19a5ebSEmmanuel Grumbach */ 10626d19a5ebSEmmanuel Grumbach mvm->temp_nvm_data = mvm->nvm_data; 10636d19a5ebSEmmanuel Grumbach mvm->nvm_data = NULL; 10646d19a5ebSEmmanuel Grumbach } 10656d19a5ebSEmmanuel Grumbach 1066bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1067bf8b286fSJohannes Berg /* 1068bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1069bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1070bf8b286fSJohannes Berg */ 1071bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1072bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1073e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1074e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1075a42b2af3SLuca Coelho } 1076e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1077e705c121SKalle Valo 1078b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1079b108d8c7SShahar S Matityahu NULL); 1080b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1081b108d8c7SShahar S Matityahu NULL); 1082da2eb669SSara Sharon 1083e8fe3b41SIlan Peer mvm->last_reset_or_resume_time_jiffies = jiffies; 1084e8fe3b41SIlan Peer 1085e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1086e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1087e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1088e705c121SKalle Valo * would do. 1089e705c121SKalle Valo */ 1090e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1091e705c121SKalle Valo } 1092e705c121SKalle Valo 1093e705c121SKalle Valo return ret; 1094e705c121SKalle Valo } 1095e705c121SKalle Valo 1096cbce62a3SMiri Korenblit int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1097e705c121SKalle Valo { 1098e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1099e705c121SKalle Valo int ret; 11005283dd67SMordechay Goodstein int retry, max_retry = 0; 1101e705c121SKalle Valo 1102e705c121SKalle Valo mutex_lock(&mvm->mutex); 11035283dd67SMordechay Goodstein 11045283dd67SMordechay Goodstein /* we are starting the mac not in error flow, and restart is enabled */ 11055283dd67SMordechay Goodstein if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 11065283dd67SMordechay Goodstein iwlwifi_mod_params.fw_restart) { 11075283dd67SMordechay Goodstein max_retry = IWL_MAX_INIT_RETRY; 11085283dd67SMordechay Goodstein /* 11095283dd67SMordechay Goodstein * This will prevent mac80211 recovery flows to trigger during 11105283dd67SMordechay Goodstein * init failures 11115283dd67SMordechay Goodstein */ 11125283dd67SMordechay Goodstein set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 11135283dd67SMordechay Goodstein } 11145283dd67SMordechay Goodstein 11155283dd67SMordechay Goodstein for (retry = 0; retry <= max_retry; retry++) { 1116e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 11175283dd67SMordechay Goodstein if (!ret) 11185283dd67SMordechay Goodstein break; 11195283dd67SMordechay Goodstein 1120b8133439SAvraham Stern /* 1121b8133439SAvraham Stern * In PLDR sync PCI re-enumeration is needed. no point to retry 1122b8133439SAvraham Stern * mac start before that. 1123b8133439SAvraham Stern */ 1124b8133439SAvraham Stern if (mvm->pldr_sync) { 1125b8133439SAvraham Stern iwl_mei_alive_notif(false); 1126b8133439SAvraham Stern iwl_trans_pcie_remove(mvm->trans, true); 1127b8133439SAvraham Stern break; 1128b8133439SAvraham Stern } 1129b8133439SAvraham Stern 11305283dd67SMordechay Goodstein IWL_ERR(mvm, "mac start retry %d\n", retry); 11315283dd67SMordechay Goodstein } 11325283dd67SMordechay Goodstein clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 11335283dd67SMordechay Goodstein 1134e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1135e705c121SKalle Valo 11367ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 11377ce1f215SEmmanuel Grumbach 1138e705c121SKalle Valo return ret; 1139e705c121SKalle Valo } 1140e705c121SKalle Valo 1141e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1142e705c121SKalle Valo { 1143e705c121SKalle Valo int ret; 1144e705c121SKalle Valo 1145e705c121SKalle Valo mutex_lock(&mvm->mutex); 1146e705c121SKalle Valo 1147e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 11484d4183c4SEmmanuel Grumbach 1149e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1150e705c121SKalle Valo if (ret) 1151e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1152e705c121SKalle Valo ret); 1153e705c121SKalle Valo 1154f130bb75SMordechay Goodstein iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1155f130bb75SMordechay Goodstein 1156e705c121SKalle Valo /* 1157e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1158e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1159e705c121SKalle Valo */ 1160e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1161e705c121SKalle Valo 1162e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1163e705c121SKalle Valo } 1164e705c121SKalle Valo 1165cbce62a3SMiri Korenblit void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1166e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1167e705c121SKalle Valo { 1168e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1169e705c121SKalle Valo 1170e705c121SKalle Valo switch (reconfig_type) { 1171e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1172e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1173e705c121SKalle Valo break; 1174e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1175e705c121SKalle Valo break; 1176e705c121SKalle Valo } 1177e705c121SKalle Valo } 1178e705c121SKalle Valo 1179e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1180e705c121SKalle Valo { 1181e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1182e705c121SKalle Valo 1183b68bd2e3SIlan Peer iwl_mvm_ftm_initiator_smooth_stop(mvm); 1184b68bd2e3SIlan Peer 1185e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1186e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1187e705c121SKalle Valo */ 1188e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1189e705c121SKalle Valo 1190e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1191e705c121SKalle Valo 1192971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12) 1193f327236dSSharon iwl_mvm_rm_aux_sta(mvm); 1194f327236dSSharon 1195fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1196e705c121SKalle Valo 1197e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1198e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1199e705c121SKalle Valo 1200e705c121SKalle Valo /* 1201155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1202155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1203155f7e04SEmmanuel Grumbach * won't execute the restart. 1204e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1205e705c121SKalle Valo * HW restart was requested. 1206e705c121SKalle Valo */ 1207155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1208155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1209155f7e04SEmmanuel Grumbach &mvm->status)) 1210e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1211e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1212e705c121SKalle Valo 1213e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1214e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1215e705c121SKalle Valo */ 1216e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1217e705c121SKalle Valo int i; 1218e705c121SKalle Valo 1219e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1220e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1221e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1222e705c121SKalle Valo i)) 1223e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1224e705c121SKalle Valo } 1225e705c121SKalle Valo } 1226e705c121SKalle Valo } 1227e705c121SKalle Valo 1228cbce62a3SMiri Korenblit void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1229e705c121SKalle Valo { 1230e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1231e705c121SKalle Valo 1232e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 123324afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1234771147b0SJohannes Berg 1235771147b0SJohannes Berg /* 1236771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1237771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1238771147b0SJohannes Berg * be able to proceed. This is important here because one of those 12397174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1240771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1241771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1242771147b0SJohannes Berg */ 1243771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1244771147b0SJohannes Berg 1245d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 124669e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1247e705c121SKalle Valo 1248f9084775SNathan Errera /* 1249f9084775SNathan Errera * The work item could be running or queued if the 1250f9084775SNathan Errera * ROC time event stops just as we get here. 1251f9084775SNathan Errera */ 1252f9084775SNathan Errera flush_work(&mvm->roc_done_wk); 1253f9084775SNathan Errera 12547ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 12557ce1f215SEmmanuel Grumbach 1256e705c121SKalle Valo mutex_lock(&mvm->mutex); 1257e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1258e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1259e705c121SKalle Valo 1260e705c121SKalle Valo /* 1261e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1262e705c121SKalle Valo * discover that its list is now empty. 1263e705c121SKalle Valo */ 1264e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1265e705c121SKalle Valo } 1266e705c121SKalle Valo 12671ab26632SMiri Korenblit struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1268e705c121SKalle Valo { 1269e705c121SKalle Valo u16 i; 1270e705c121SKalle Valo 1271e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1272e705c121SKalle Valo 1273e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1274e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1275e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1276e705c121SKalle Valo 1277e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1278e705c121SKalle Valo return NULL; 1279e705c121SKalle Valo } 1280e705c121SKalle Valo 1281e705c121SKalle Valo static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1282e705c121SKalle Valo s16 tx_power) 1283e705c121SKalle Valo { 1284971cbe50SJohannes Berg u32 cmd_id = REDUCE_TX_POWER_CMD; 12850791c2fcSHaim Dreyfuss int len; 1286216cdfb5SLuca Coelho struct iwl_dev_tx_power_cmd cmd = { 1287216cdfb5SLuca Coelho .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1288216cdfb5SLuca Coelho .common.mac_context_id = 1289e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1290216cdfb5SLuca Coelho .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1291e705c121SKalle Valo }; 1292971cbe50SJohannes Berg u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1293e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN); 1294e705c121SKalle Valo 1295e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1296216cdfb5SLuca Coelho cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1297e705c121SKalle Valo 1298b0aa02b3SAyala Barazani if (cmd_ver == 7) 1299b0aa02b3SAyala Barazani len = sizeof(cmd.v7); 1300b0aa02b3SAyala Barazani else if (cmd_ver == 6) 1301fbb7957dSLuca Coelho len = sizeof(cmd.v6); 1302fbb7957dSLuca Coelho else if (fw_has_api(&mvm->fw->ucode_capa, 13030791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 13040791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 13050791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 13060791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 13070791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 13080791c2fcSHaim Dreyfuss else 1309216cdfb5SLuca Coelho len = sizeof(cmd.v3); 1310216cdfb5SLuca Coelho 1311216cdfb5SLuca Coelho /* all structs have the same common part, add it */ 1312216cdfb5SLuca Coelho len += sizeof(cmd.common); 1313e705c121SKalle Valo 1314971cbe50SJohannes Berg return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); 1315e705c121SKalle Valo } 1316e705c121SKalle Valo 131703117f30SMiri Korenblit int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1318f6780614SSara Sharon struct ieee80211_vif *vif) 1319f6780614SSara Sharon { 1320f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1321f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1322f6780614SSara Sharon int ret; 1323f6780614SSara Sharon 1324f6780614SSara Sharon mutex_lock(&mvm->mutex); 1325f6780614SSara Sharon 1326f6780614SSara Sharon if (vif->type == NL80211_IFTYPE_STATION) { 1327f6780614SSara Sharon struct iwl_mvm_sta *mvmsta; 1328f6780614SSara Sharon 1329f6780614SSara Sharon mvmvif->csa_bcn_pending = false; 1330f6780614SSara Sharon mvmsta = iwl_mvm_sta_from_staid_protected(mvm, 1331650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id); 1332f6780614SSara Sharon 1333f6780614SSara Sharon if (WARN_ON(!mvmsta)) { 1334f6780614SSara Sharon ret = -EIO; 1335f6780614SSara Sharon goto out_unlock; 1336f6780614SSara Sharon } 1337f6780614SSara Sharon 1338f6780614SSara Sharon iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 133903117f30SMiri Korenblit if (mvm->mld_api_is_used) 134003117f30SMiri Korenblit iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 134103117f30SMiri Korenblit else 1342f6780614SSara Sharon iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1343f6780614SSara Sharon 13440202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 13450202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 1346f6780614SSara Sharon ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 1347f6780614SSara Sharon if (ret) 1348f6780614SSara Sharon goto out_unlock; 1349f6780614SSara Sharon 1350f6780614SSara Sharon iwl_mvm_stop_session_protection(mvm, vif); 1351f6780614SSara Sharon } 13520202bcf0SEmmanuel Grumbach } 1353f6780614SSara Sharon 1354f6780614SSara Sharon mvmvif->ps_disabled = false; 1355f6780614SSara Sharon 1356f6780614SSara Sharon ret = iwl_mvm_power_update_ps(mvm); 1357f6780614SSara Sharon 1358f6780614SSara Sharon out_unlock: 1359caf46377SSara Sharon if (mvmvif->csa_failed) 1360caf46377SSara Sharon ret = -EIO; 1361f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1362f6780614SSara Sharon 1363f6780614SSara Sharon return ret; 1364f6780614SSara Sharon } 1365f6780614SSara Sharon 1366cbce62a3SMiri Korenblit void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 1367f6780614SSara Sharon struct ieee80211_vif *vif) 1368f6780614SSara Sharon { 1369f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1370f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1371f6780614SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 1372f6780614SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1373f6780614SSara Sharon mvmvif->color)), 1374f6780614SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1375f6780614SSara Sharon }; 1376f6780614SSara Sharon 1377ad12b231SNathan Errera /* 1378ad12b231SNathan Errera * In the new flow since FW is in charge of the timing, 1379ad12b231SNathan Errera * if driver has canceled the channel switch he will receive the 1380ad12b231SNathan Errera * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it 1381ad12b231SNathan Errera */ 1382ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 1383ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 1384ad12b231SNathan Errera return; 1385ad12b231SNathan Errera 1386f6780614SSara Sharon IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1387f6780614SSara Sharon 1388f6780614SSara Sharon mutex_lock(&mvm->mutex); 138958ddd9b6SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 139058ddd9b6SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 139158ddd9b6SEmmanuel Grumbach iwl_mvm_remove_csa_period(mvm, vif); 139258ddd9b6SEmmanuel Grumbach else 1393f6780614SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1394f6780614SSara Sharon WIDE_ID(MAC_CONF_GROUP, 1395f6780614SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 1396f6780614SSara Sharon 0, sizeof(cmd), &cmd)); 1397caf46377SSara Sharon mvmvif->csa_failed = true; 1398f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1399f6780614SSara Sharon 1400caf46377SSara Sharon iwl_mvm_post_channel_switch(hw, vif); 1401f6780614SSara Sharon } 1402f6780614SSara Sharon 14031ab26632SMiri Korenblit void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1404f6780614SSara Sharon { 1405f6780614SSara Sharon struct iwl_mvm_vif *mvmvif; 1406f6780614SSara Sharon struct ieee80211_vif *vif; 1407f6780614SSara Sharon 1408f6780614SSara Sharon mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1409f6780614SSara Sharon vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1410f6780614SSara Sharon 141170162580SShaul Triebitz /* Trigger disconnect (should clear the CSA state) */ 1412f6780614SSara Sharon ieee80211_chswitch_done(vif, false); 1413f6780614SSara Sharon } 1414f6780614SSara Sharon 14155abf3154SMordechay Goodstein static u8 14165abf3154SMordechay Goodstein iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef) 14175abf3154SMordechay Goodstein { 14185abf3154SMordechay Goodstein int data_start; 14195abf3154SMordechay Goodstein int control_start; 14205abf3154SMordechay Goodstein int bw; 14215abf3154SMordechay Goodstein 14225abf3154SMordechay Goodstein if (chandef->width == NL80211_CHAN_WIDTH_320) 14235abf3154SMordechay Goodstein bw = 320; 14245abf3154SMordechay Goodstein else if (chandef->width == NL80211_CHAN_WIDTH_160) 14255abf3154SMordechay Goodstein bw = 160; 14265abf3154SMordechay Goodstein else 14275abf3154SMordechay Goodstein return 0; 14285abf3154SMordechay Goodstein 14295abf3154SMordechay Goodstein /* data is bw wide so the start is half the width */ 14305abf3154SMordechay Goodstein data_start = chandef->center_freq1 - bw / 2; 14315abf3154SMordechay Goodstein /* control is 20Mhz width */ 14325abf3154SMordechay Goodstein control_start = chandef->chan->center_freq - 10; 14335abf3154SMordechay Goodstein 14345abf3154SMordechay Goodstein return (control_start - data_start) / 80; 14355abf3154SMordechay Goodstein } 14365abf3154SMordechay Goodstein 14371ab26632SMiri Korenblit /* 14381ab26632SMiri Korenblit * Returns true if addding the interface is done 14391ab26632SMiri Korenblit * (either with success or failure) 14401ab26632SMiri Korenblit */ 14411ab26632SMiri Korenblit bool iwl_mvm_mac_add_interface_common(struct iwl_mvm *mvm, 14421ab26632SMiri Korenblit struct ieee80211_hw *hw, 14431ab26632SMiri Korenblit struct ieee80211_vif *vif, int *ret) 1444e705c121SKalle Valo { 1445e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 14461ab26632SMiri Korenblit 14471ab26632SMiri Korenblit lockdep_assert_held(&mvm->mutex); 1448e705c121SKalle Valo 1449e705c121SKalle Valo mvmvif->mvm = mvm; 1450650cadb7SGregory Greenman RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 1451650cadb7SGregory Greenman 1452650cadb7SGregory Greenman /* the first link always points to the default one */ 1453650cadb7SGregory Greenman mvmvif->link[0] = &mvmvif->deflink; 1454e705c121SKalle Valo 1455e705c121SKalle Valo /* 1456e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1457e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1458e705c121SKalle Valo * don't really have to check the types. 1459e705c121SKalle Valo */ 1460e705c121SKalle Valo 1461e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1462e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1463650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.accu_num_beacons += 1464650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.num_beacons; 1465e705c121SKalle Valo 1466e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 14671ab26632SMiri Korenblit *ret = iwl_mvm_mac_ctxt_init(mvm, vif); 14681ab26632SMiri Korenblit if (*ret) 14691ab26632SMiri Korenblit return true; 1470e705c121SKalle Valo 1471698478c4SSara Sharon rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1472698478c4SSara Sharon 1473e705c121SKalle Valo /* 1474e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1475e705c121SKalle Valo * template is configured (which happens only in the mac80211 1476e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1477e705c121SKalle Valo * only after the binding. 1478e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1479e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1480e705c121SKalle Valo * the point where we can also add the bcast station. 1481e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1482e705c121SKalle Valo * allocating resources :) 1483e705c121SKalle Valo */ 1484e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1485e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 14861ab26632SMiri Korenblit iwl_mvm_vif_dbgfs_register(mvm, vif); 14871ab26632SMiri Korenblit return true; 14881ab26632SMiri Korenblit } 14891ab26632SMiri Korenblit 14901ab26632SMiri Korenblit mvmvif->features |= hw->netdev_features; 1491650cadb7SGregory Greenman 14921ab26632SMiri Korenblit return false; 14931ab26632SMiri Korenblit } 14941ab26632SMiri Korenblit 14951ab26632SMiri Korenblit static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm, 14961ab26632SMiri Korenblit struct ieee80211_vif *vif) 14971ab26632SMiri Korenblit { 14981ab26632SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 14991ab26632SMiri Korenblit int ret; 15001ab26632SMiri Korenblit 15011ab26632SMiri Korenblit lockdep_assert_held(&mvm->mutex); 15021ab26632SMiri Korenblit 1503e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1504e705c121SKalle Valo if (ret) { 1505e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 15061ab26632SMiri Korenblit return ret; 1507e705c121SKalle Valo } 1508e705c121SKalle Valo 150926d6c16bSSara Sharon /* 151026d6c16bSSara Sharon * Only queue for this station is the mcast queue, 151126d6c16bSSara Sharon * which shouldn't be in TFD mask anyway 151226d6c16bSSara Sharon */ 1513650cadb7SGregory Greenman return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0, 1514650cadb7SGregory Greenman vif->type, 1515ced19f26SSara Sharon IWL_STA_MULTICAST); 1516e705c121SKalle Valo } 1517e705c121SKalle Valo 15181ab26632SMiri Korenblit static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 15191ab26632SMiri Korenblit struct ieee80211_vif *vif) 15201ab26632SMiri Korenblit { 15211ab26632SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 15221ab26632SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 15231ab26632SMiri Korenblit int ret; 15241ab26632SMiri Korenblit 15251ab26632SMiri Korenblit mutex_lock(&mvm->mutex); 15261ab26632SMiri Korenblit 15271ab26632SMiri Korenblit /* Common for MLD and non-MLD API */ 15281ab26632SMiri Korenblit if (iwl_mvm_mac_add_interface_common(mvm, hw, vif, &ret)) 15291ab26632SMiri Korenblit goto out; 1530e705c121SKalle Valo 1531e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1532e705c121SKalle Valo if (ret) 153398c0de7bSMiri Korenblit goto out_unlock; 1534e705c121SKalle Valo 1535e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1536e705c121SKalle Valo if (ret) 1537e705c121SKalle Valo goto out_remove_mac; 1538e705c121SKalle Valo 1539e705c121SKalle Valo /* beacon filtering */ 1540e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 1541e705c121SKalle Valo if (ret) 1542e705c121SKalle Valo goto out_remove_mac; 1543e705c121SKalle Valo 1544e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1545e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1546e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1547e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1548e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1549e705c121SKalle Valo } 1550e705c121SKalle Valo 1551e705c121SKalle Valo /* 1552e705c121SKalle Valo * P2P_DEVICE interface does not have a channel context assigned to it, 1553e705c121SKalle Valo * so a dedicated PHY context is allocated to it and the corresponding 1554e705c121SKalle Valo * MAC context is bound to it at this stage. 1555e705c121SKalle Valo */ 1556e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1557e705c121SKalle Valo 1558650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 1559650cadb7SGregory Greenman if (!mvmvif->deflink.phy_ctxt) { 1560e705c121SKalle Valo ret = -ENOSPC; 1561e705c121SKalle Valo goto out_free_bf; 1562e705c121SKalle Valo } 1563e705c121SKalle Valo 1564650cadb7SGregory Greenman iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 1565e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 1566e705c121SKalle Valo if (ret) 1567e705c121SKalle Valo goto out_unref_phy; 1568e705c121SKalle Valo 1569d197358bSLuca Coelho ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); 1570e705c121SKalle Valo if (ret) 1571e705c121SKalle Valo goto out_unbind; 1572e705c121SKalle Valo 1573e705c121SKalle Valo /* Save a pointer to p2p device vif, so it can later be used to 1574e705c121SKalle Valo * update the p2p device MAC when a GO is started/stopped */ 1575e705c121SKalle Valo mvm->p2p_device_vif = vif; 1576e705c121SKalle Valo } 1577e705c121SKalle Valo 1578b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1579f6780614SSara Sharon INIT_DELAYED_WORK(&mvmvif->csa_work, 1580f6780614SSara Sharon iwl_mvm_channel_switch_disconnect_wk); 1581b0ffe455SJohannes Berg 15825abf3154SMordechay Goodstein if (vif->type == NL80211_IFTYPE_MONITOR) { 1583baf41bc3SShaul Triebitz mvm->monitor_on = true; 15845abf3154SMordechay Goodstein mvm->monitor_p80 = 15855abf3154SMordechay Goodstein iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chandef); 15865abf3154SMordechay Goodstein } 1587baf41bc3SShaul Triebitz 1588e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 15896d19a5ebSEmmanuel Grumbach 15906d19a5ebSEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 15916d19a5ebSEmmanuel Grumbach vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 15926d19a5ebSEmmanuel Grumbach !mvm->csme_vif && mvm->mei_registered) { 15936d19a5ebSEmmanuel Grumbach iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 15946d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 15956d19a5ebSEmmanuel Grumbach mvm->csme_vif = vif; 15966d19a5ebSEmmanuel Grumbach } 15976d19a5ebSEmmanuel Grumbach 15981ab26632SMiri Korenblit out: 15991ab26632SMiri Korenblit if (!ret && (vif->type == NL80211_IFTYPE_AP || 16001ab26632SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC)) 16011ab26632SMiri Korenblit ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif); 16021ab26632SMiri Korenblit 1603e705c121SKalle Valo goto out_unlock; 1604e705c121SKalle Valo 1605e705c121SKalle Valo out_unbind: 1606e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1607e705c121SKalle Valo out_unref_phy: 1608650cadb7SGregory Greenman iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 1609e705c121SKalle Valo out_free_bf: 1610e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1611e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1612e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1613e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1614e705c121SKalle Valo } 1615e705c121SKalle Valo out_remove_mac: 1616650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1617e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1618e705c121SKalle Valo out_unlock: 1619e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1620e705c121SKalle Valo 1621e705c121SKalle Valo return ret; 1622e705c121SKalle Valo } 1623e705c121SKalle Valo 1624e705c121SKalle Valo static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1625e705c121SKalle Valo struct ieee80211_vif *vif) 1626e705c121SKalle Valo { 1627e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1628e705c121SKalle Valo /* 1629e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1630e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1631e705c121SKalle Valo * queue are sent in ROC session. 1632e705c121SKalle Valo */ 1633e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1634e705c121SKalle Valo } 1635e705c121SKalle Valo } 1636e705c121SKalle Valo 163760efeca1SMiri Korenblit /* This function is doing the common part of removing the interface for 163860efeca1SMiri Korenblit * both - MLD and non-MLD modes. Returns true if removing the interface 163960efeca1SMiri Korenblit * is done 164060efeca1SMiri Korenblit */ 164160efeca1SMiri Korenblit bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw, 1642e705c121SKalle Valo struct ieee80211_vif *vif) 1643e705c121SKalle Valo { 1644e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1645e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 164686e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1647e705c121SKalle Valo 1648e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1649e705c121SKalle Valo 1650b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1651b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1652b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1653b0ffe455SJohannes Berg 1654e705c121SKalle Valo mutex_lock(&mvm->mutex); 1655e705c121SKalle Valo 16566d19a5ebSEmmanuel Grumbach if (vif == mvm->csme_vif) { 16576d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(NULL); 16586d19a5ebSEmmanuel Grumbach mvm->csme_vif = NULL; 16596d19a5ebSEmmanuel Grumbach } 16606d19a5ebSEmmanuel Grumbach 1661650cadb7SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 166286e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 1663650cadb7SGregory Greenman RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 166486e177d8SGregory Greenman if (probe_data) 166586e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 166686e177d8SGregory Greenman 1667e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1668e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1669e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1670e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1671e705c121SKalle Valo } 1672e705c121SKalle Valo 1673b73f9a4aSJohannes Berg if (vif->bss_conf.ftm_responder) 1674b73f9a4aSJohannes Berg memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1675b73f9a4aSJohannes Berg 1676e705c121SKalle Valo iwl_mvm_vif_dbgfs_clean(mvm, vif); 1677e705c121SKalle Valo 1678e705c121SKalle Valo /* 1679e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1680e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1681e705c121SKalle Valo */ 1682e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1683e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1684e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1685e705c121SKalle Valo if (vif == mvm->noa_vif) { 1686e705c121SKalle Valo mvm->noa_vif = NULL; 1687e705c121SKalle Valo mvm->noa_duration = 0; 1688e705c121SKalle Valo } 1689e705c121SKalle Valo #endif 169060efeca1SMiri Korenblit return true; 1691e705c121SKalle Valo } 1692e705c121SKalle Valo 169360efeca1SMiri Korenblit iwl_mvm_power_update_mac(mvm); 169460efeca1SMiri Korenblit return false; 169560efeca1SMiri Korenblit } 169660efeca1SMiri Korenblit 169760efeca1SMiri Korenblit static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 169860efeca1SMiri Korenblit struct ieee80211_vif *vif) 169960efeca1SMiri Korenblit { 170060efeca1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 170160efeca1SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 170260efeca1SMiri Korenblit 170360efeca1SMiri Korenblit if (iwl_mvm_mac_remove_interface_common(hw, vif)) 170460efeca1SMiri Korenblit goto out; 170560efeca1SMiri Korenblit 1706e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1707e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1708d197358bSLuca Coelho iwl_mvm_rm_p2p_bcast_sta(mvm, vif); 1709e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1710650cadb7SGregory Greenman iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 1711650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1712e705c121SKalle Valo } 1713e705c121SKalle Valo 1714e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1715e705c121SKalle Valo 1716698478c4SSara Sharon RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1717698478c4SSara Sharon 1718baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1719baf41bc3SShaul Triebitz mvm->monitor_on = false; 1720baf41bc3SShaul Triebitz 172160efeca1SMiri Korenblit out: 172260efeca1SMiri Korenblit if (vif->type == NL80211_IFTYPE_AP || 172360efeca1SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC) { 1724650cadb7SGregory Greenman iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta); 172560efeca1SMiri Korenblit iwl_mvm_dealloc_bcast_sta(mvm, vif); 172660efeca1SMiri Korenblit } 172760efeca1SMiri Korenblit 1728e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1729e705c121SKalle Valo } 1730e705c121SKalle Valo 1731e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1732e705c121SKalle Valo struct iwl_mvm *mvm; 1733e705c121SKalle Valo int port_id; 1734e705c121SKalle Valo }; 1735e705c121SKalle Valo 1736e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1737e705c121SKalle Valo struct ieee80211_vif *vif) 1738e705c121SKalle Valo { 1739e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1740e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1741e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 174297bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 174397bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 174497bce57bSLuca Coelho .flags = CMD_ASYNC, 174597bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 174697bce57bSLuca Coelho }; 1747e705c121SKalle Valo int ret, len; 1748e705c121SKalle Valo 1749e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1750e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1751e705c121SKalle Valo return; 1752e705c121SKalle Valo 1753e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1754f276e20bSJohannes Berg !vif->cfg.assoc) 1755e705c121SKalle Valo return; 1756e705c121SKalle Valo 1757e705c121SKalle Valo cmd->port_id = data->port_id++; 1758e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1759e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1760e705c121SKalle Valo 176197bce57bSLuca Coelho hcmd.len[0] = len; 176297bce57bSLuca Coelho hcmd.data[0] = cmd; 176397bce57bSLuca Coelho 176497bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1765e705c121SKalle Valo if (ret) 1766e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1767e705c121SKalle Valo } 1768e705c121SKalle Valo 1769e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1770e705c121SKalle Valo { 1771e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1772e705c121SKalle Valo .mvm = mvm, 1773e705c121SKalle Valo }; 1774db66abeeSJohannes Berg int ret; 1775e705c121SKalle Valo 1776e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1777e705c121SKalle Valo 1778e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1779e705c121SKalle Valo return; 1780e705c121SKalle Valo 1781e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1782e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1783e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1784db66abeeSJohannes Berg 1785db66abeeSJohannes Berg /* 1786db66abeeSJohannes Berg * Send a (synchronous) ech command so that we wait for the 1787db66abeeSJohannes Berg * multiple asynchronous MCAST_FILTER_CMD commands sent by 1788db66abeeSJohannes Berg * the interface iterator. Otherwise, we might get here over 1789db66abeeSJohannes Berg * and over again (by userspace just sending a lot of these) 1790db66abeeSJohannes Berg * and the CPU can send them faster than the firmware can 1791db66abeeSJohannes Berg * process them. 1792db66abeeSJohannes Berg * Note that the CPU is still faster - but with this we'll 1793db66abeeSJohannes Berg * actually send fewer commands overall because the CPU will 1794db66abeeSJohannes Berg * not schedule the work in mac80211 as frequently if it's 1795db66abeeSJohannes Berg * still running when rescheduled (possibly multiple times). 1796db66abeeSJohannes Berg */ 1797db66abeeSJohannes Berg ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1798db66abeeSJohannes Berg if (ret) 1799db66abeeSJohannes Berg IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 1800e705c121SKalle Valo } 1801e705c121SKalle Valo 1802cbce62a3SMiri Korenblit u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1803e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1804e705c121SKalle Valo { 1805e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1806e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1807e705c121SKalle Valo struct netdev_hw_addr *addr; 1808e705c121SKalle Valo int addr_count; 1809e705c121SKalle Valo bool pass_all; 1810e705c121SKalle Valo int len; 1811e705c121SKalle Valo 1812e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1813e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1814e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1815e705c121SKalle Valo if (pass_all) 1816e705c121SKalle Valo addr_count = 0; 1817e705c121SKalle Valo 1818e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1819e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1820e705c121SKalle Valo if (!cmd) 1821e705c121SKalle Valo return 0; 1822e705c121SKalle Valo 1823e705c121SKalle Valo if (pass_all) { 1824e705c121SKalle Valo cmd->pass_all = 1; 1825e705c121SKalle Valo return (u64)(unsigned long)cmd; 1826e705c121SKalle Valo } 1827e705c121SKalle Valo 1828e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1829e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1830e705c121SKalle Valo cmd->count, addr->addr); 1831e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1832e705c121SKalle Valo addr->addr, ETH_ALEN); 1833e705c121SKalle Valo cmd->count++; 1834e705c121SKalle Valo } 1835e705c121SKalle Valo 1836e705c121SKalle Valo return (u64)(unsigned long)cmd; 1837e705c121SKalle Valo } 1838e705c121SKalle Valo 1839cbce62a3SMiri Korenblit void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1840e705c121SKalle Valo unsigned int changed_flags, 1841cbce62a3SMiri Korenblit unsigned int *total_flags, u64 multicast) 1842e705c121SKalle Valo { 1843e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1844e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1845e705c121SKalle Valo 1846e705c121SKalle Valo mutex_lock(&mvm->mutex); 1847e705c121SKalle Valo 1848e705c121SKalle Valo /* replace previous configuration */ 1849e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1850e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1851e705c121SKalle Valo 1852e705c121SKalle Valo if (!cmd) 1853e705c121SKalle Valo goto out; 1854e705c121SKalle Valo 185561e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 185661e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 185761e7d91bSLuca Coelho 185861e7d91bSLuca Coelho if (cmd->pass_all) 185961e7d91bSLuca Coelho cmd->count = 0; 186061e7d91bSLuca Coelho 1861e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1862e705c121SKalle Valo out: 1863e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1864e705c121SKalle Valo *total_flags = 0; 1865e705c121SKalle Valo } 1866e705c121SKalle Valo 1867e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1868e705c121SKalle Valo struct ieee80211_vif *vif, 1869e705c121SKalle Valo unsigned int filter_flags, 1870e705c121SKalle Valo unsigned int changed_flags) 1871e705c121SKalle Valo { 1872e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1873e705c121SKalle Valo 1874e705c121SKalle Valo /* We support only filter for probe requests */ 1875e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1876e705c121SKalle Valo return; 1877e705c121SKalle Valo 1878e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1879f276e20bSJohannes Berg if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 1880e705c121SKalle Valo !vif->p2p) 1881e705c121SKalle Valo return; 1882e705c121SKalle Valo 1883e705c121SKalle Valo mutex_lock(&mvm->mutex); 1884e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1885e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1886e705c121SKalle Valo } 1887e705c121SKalle Valo 1888a07a8f37SSara Sharon static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, 1889a07a8f37SSara Sharon struct ieee80211_vif *vif) 1890a07a8f37SSara Sharon { 1891a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1892a07a8f37SSara Sharon 1893a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 1894a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 1895a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 1896a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 1897a07a8f37SSara Sharon 1898a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 1899a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 1900a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 1901a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 1902a07a8f37SSara Sharon } 1903a07a8f37SSara Sharon 1904f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 1905f92659a1SSara Sharon struct ieee80211_vif *vif) 1906f92659a1SSara Sharon { 1907d0a9123eSJohannes Berg if (vif->bss_conf.mu_mimo_owner) { 1908f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 1909f92659a1SSara Sharon 1910f92659a1SSara Sharon /* 1911f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 1912f92659a1SSara Sharon * the data received from firmware as if it came from the 1913f92659a1SSara Sharon * action frame, so no conversion is needed. 1914f92659a1SSara Sharon */ 1915afe0d181SJohannes Berg ieee80211_update_mu_groups(vif, 0, 1916f92659a1SSara Sharon (u8 *)¬if->membership_status, 1917f92659a1SSara Sharon (u8 *)¬if->user_position); 1918f92659a1SSara Sharon } 1919f92659a1SSara Sharon } 1920f92659a1SSara Sharon 1921f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 1922f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 1923f92659a1SSara Sharon { 1924f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 1925f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 1926f92659a1SSara Sharon 1927f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 1928f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1929f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 1930f92659a1SSara Sharon } 1931f92659a1SSara Sharon 1932514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 1933514c3069SLuca Coelho { 1934514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 1935514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 1936514c3069SLuca Coelho u8 residue_bits; 1937514c3069SLuca Coelho u8 res; 1938514c3069SLuca Coelho 1939514c3069SLuca Coelho if (bit_num <= 5) 1940514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 1941514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 1942514c3069SLuca Coelho 1943514c3069SLuca Coelho /* 1944514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 1945514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 1946514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 1947514c3069SLuca Coelho */ 1948514c3069SLuca Coelho 1949514c3069SLuca Coelho residue_bits = 8 - bit_num; 1950514c3069SLuca Coelho 1951514c3069SLuca Coelho res = (ppe[byte_num + 1] & 1952514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 1953514c3069SLuca Coelho residue_bits; 1954514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 1955514c3069SLuca Coelho 1956514c3069SLuca Coelho return res; 1957514c3069SLuca Coelho } 1958514c3069SLuca Coelho 1959091296d3SMiri Korenblit static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, 1960091296d3SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, 1961cb63eb43SMiri Korenblit u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit, 1962cb63eb43SMiri Korenblit bool inheritance) 1963091296d3SMiri Korenblit { 1964091296d3SMiri Korenblit int i; 1965091296d3SMiri Korenblit 1966091296d3SMiri Korenblit /* 1967091296d3SMiri Korenblit * FW currently supports only nss == MAX_HE_SUPP_NSS 1968091296d3SMiri Korenblit * 1969091296d3SMiri Korenblit * If nss > MAX: we can ignore values we don't support 1970091296d3SMiri Korenblit * If nss < MAX: we can set zeros in other streams 1971091296d3SMiri Korenblit */ 1972091296d3SMiri Korenblit if (nss > MAX_HE_SUPP_NSS) { 19734d8421f2SJason A. Donenfeld IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 1974091296d3SMiri Korenblit MAX_HE_SUPP_NSS); 1975091296d3SMiri Korenblit nss = MAX_HE_SUPP_NSS; 1976091296d3SMiri Korenblit } 1977091296d3SMiri Korenblit 1978091296d3SMiri Korenblit for (i = 0; i < nss; i++) { 1979091296d3SMiri Korenblit u8 ru_index_tmp = ru_index_bitmap << 1; 1980091296d3SMiri Korenblit u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; 1981091296d3SMiri Korenblit u8 bw; 1982091296d3SMiri Korenblit 1983091296d3SMiri Korenblit for (bw = 0; 1984091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 1985091296d3SMiri Korenblit bw++) { 1986091296d3SMiri Korenblit ru_index_tmp >>= 1; 1987091296d3SMiri Korenblit 1988cb63eb43SMiri Korenblit /* 1989cb63eb43SMiri Korenblit * According to the 11be spec, if for a specific BW the PPE Thresholds 1990cb63eb43SMiri Korenblit * isn't present - it should inherit the thresholds from the last 1991cb63eb43SMiri Korenblit * BW for which we had PPE Thresholds. In 11ax though, we don't have 1992cb63eb43SMiri Korenblit * this inheritance - continue in this case 1993cb63eb43SMiri Korenblit */ 1994cb63eb43SMiri Korenblit if (!(ru_index_tmp & 1)) { 1995cb63eb43SMiri Korenblit if (inheritance) 1996cb63eb43SMiri Korenblit goto set_thresholds; 1997cb63eb43SMiri Korenblit else 1998091296d3SMiri Korenblit continue; 1999cb63eb43SMiri Korenblit } 2000091296d3SMiri Korenblit 2001091296d3SMiri Korenblit high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2002091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2003091296d3SMiri Korenblit low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2004091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2005091296d3SMiri Korenblit 2006cb63eb43SMiri Korenblit set_thresholds: 2007091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2008091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2009091296d3SMiri Korenblit } 2010091296d3SMiri Korenblit } 2011091296d3SMiri Korenblit } 2012091296d3SMiri Korenblit 2013091296d3SMiri Korenblit static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, 2014091296d3SMiri Korenblit struct ieee80211_sta *sta, 2015cb63eb43SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, 2016cb63eb43SMiri Korenblit bool inheritance) 2017091296d3SMiri Korenblit { 2018046d2e7cSSriram R u8 nss = (sta->deflink.he_cap.ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) + 1; 2019046d2e7cSSriram R u8 *ppe = &sta->deflink.he_cap.ppe_thres[0]; 2020091296d3SMiri Korenblit u8 ru_index_bitmap = 2021091296d3SMiri Korenblit u8_get_bits(*ppe, 2022091296d3SMiri Korenblit IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); 2023091296d3SMiri Korenblit /* Starting after PPE header */ 2024091296d3SMiri Korenblit u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; 2025091296d3SMiri Korenblit 2026cb63eb43SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit, 2027cb63eb43SMiri Korenblit inheritance); 2028091296d3SMiri Korenblit } 2029091296d3SMiri Korenblit 20304df6a075SMiri Korenblit static int 20314df6a075SMiri Korenblit iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, 20324df6a075SMiri Korenblit u8 nominal_padding) 2033091296d3SMiri Korenblit { 2034091296d3SMiri Korenblit int low_th = -1; 2035091296d3SMiri Korenblit int high_th = -1; 2036091296d3SMiri Korenblit int i; 2037091296d3SMiri Korenblit 2038cb63eb43SMiri Korenblit /* all the macros are the same for EHT and HE */ 2039091296d3SMiri Korenblit switch (nominal_padding) { 2040cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US: 2041091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2042091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2043091296d3SMiri Korenblit break; 2044cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US: 2045091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_BPSK; 2046091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2047091296d3SMiri Korenblit break; 2048cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: 2049cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US: 2050091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2051091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_BPSK; 2052091296d3SMiri Korenblit break; 2053091296d3SMiri Korenblit } 2054091296d3SMiri Korenblit 20554df6a075SMiri Korenblit if (low_th < 0 || high_th < 0) 20564df6a075SMiri Korenblit return -EINVAL; 20574df6a075SMiri Korenblit 2058091296d3SMiri Korenblit /* Set the PPE thresholds accordingly */ 2059091296d3SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2060091296d3SMiri Korenblit u8 bw; 2061091296d3SMiri Korenblit 2062091296d3SMiri Korenblit for (bw = 0; 2063091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2064091296d3SMiri Korenblit bw++) { 2065091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2066091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2067091296d3SMiri Korenblit } 2068091296d3SMiri Korenblit } 2069091296d3SMiri Korenblit 20704df6a075SMiri Korenblit return 0; 2071091296d3SMiri Korenblit } 2072091296d3SMiri Korenblit 2073cb63eb43SMiri Korenblit static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext, 2074cb63eb43SMiri Korenblit u8 nominal_padding) 2075cb63eb43SMiri Korenblit { 2076cb63eb43SMiri Korenblit int i; 2077cb63eb43SMiri Korenblit 2078cb63eb43SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2079cb63eb43SMiri Korenblit u8 bw; 2080cb63eb43SMiri Korenblit 2081cb63eb43SMiri Korenblit for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2082cb63eb43SMiri Korenblit bw++) { 2083cb63eb43SMiri Korenblit u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0]; 2084cb63eb43SMiri Korenblit 2085cb63eb43SMiri Korenblit if (nominal_padding > 2086cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2087cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2088cb63eb43SMiri Korenblit qam_th[1] = IWL_HE_PKT_EXT_4096QAM; 2089cb63eb43SMiri Korenblit else if (nominal_padding == 2090cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2091cb63eb43SMiri Korenblit qam_th[0] == IWL_HE_PKT_EXT_NONE && 2092cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2093cb63eb43SMiri Korenblit qam_th[0] = IWL_HE_PKT_EXT_4096QAM; 2094cb63eb43SMiri Korenblit } 2095cb63eb43SMiri Korenblit } 2096cb63eb43SMiri Korenblit } 2097cb63eb43SMiri Korenblit 20984df6a075SMiri Korenblit /* Set the pkt_ext field according to PPE Thresholds element */ 209987f7e243SMiri Korenblit int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 21004df6a075SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext) 21014df6a075SMiri Korenblit { 21024df6a075SMiri Korenblit u8 nominal_padding; 21034df6a075SMiri Korenblit int i, ret = 0; 21044df6a075SMiri Korenblit 21054df6a075SMiri Korenblit /* Initialize the PPE thresholds to "None" (7), as described in Table 21064df6a075SMiri Korenblit * 9-262ac of 80211.ax/D3.0. 21074df6a075SMiri Korenblit */ 21084df6a075SMiri Korenblit memset(pkt_ext, IWL_HE_PKT_EXT_NONE, 21094df6a075SMiri Korenblit sizeof(struct iwl_he_pkt_ext_v2)); 21104df6a075SMiri Korenblit 21114df6a075SMiri Korenblit if (sta->deflink.eht_cap.has_eht) { 21124df6a075SMiri Korenblit nominal_padding = 21134df6a075SMiri Korenblit u8_get_bits(sta->deflink.eht_cap.eht_cap_elem.phy_cap_info[5], 21144df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK); 21154df6a075SMiri Korenblit 21164df6a075SMiri Korenblit /* If PPE Thresholds exists, parse them into a FW-familiar 21174df6a075SMiri Korenblit * format. 21184df6a075SMiri Korenblit */ 21194df6a075SMiri Korenblit if (sta->deflink.eht_cap.eht_cap_elem.phy_cap_info[5] & 21204df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { 21214df6a075SMiri Korenblit u8 nss = (sta->deflink.eht_cap.eht_ppe_thres[0] & 21224df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1; 21234df6a075SMiri Korenblit u8 *ppe = &sta->deflink.eht_cap.eht_ppe_thres[0]; 21244df6a075SMiri Korenblit u8 ru_index_bitmap = 21254df6a075SMiri Korenblit u16_get_bits(*ppe, 21264df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 21274df6a075SMiri Korenblit /* Starting after PPE header */ 21284df6a075SMiri Korenblit u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; 21294df6a075SMiri Korenblit 21304df6a075SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, 21314df6a075SMiri Korenblit ppe, ppe_pos_bit, true); 21324df6a075SMiri Korenblit /* EHT PPE Thresholds doesn't exist - set the API according 21334df6a075SMiri Korenblit * to HE PPE Tresholds 21344df6a075SMiri Korenblit */ 21354df6a075SMiri Korenblit } else if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] & 21364df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 21374df6a075SMiri Korenblit /* Even though HE Capabilities IE doesn't contain PPE 21384df6a075SMiri Korenblit * Thresholds for BW 320Mhz, thresholds for this BW will 21394df6a075SMiri Korenblit * be filled in with the same values as 160Mhz, due to 21404df6a075SMiri Korenblit * the inheritance, as required. 21414df6a075SMiri Korenblit */ 21424df6a075SMiri Korenblit iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta, pkt_ext, 21434df6a075SMiri Korenblit true); 21444df6a075SMiri Korenblit 21454df6a075SMiri Korenblit /* According to the requirements, for MCSs 12-13 the 21464df6a075SMiri Korenblit * maximum value between HE PPE Threshold and Common 21474df6a075SMiri Korenblit * Nominal Packet Padding needs to be taken 21484df6a075SMiri Korenblit */ 21494df6a075SMiri Korenblit iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding); 21504df6a075SMiri Korenblit 21514df6a075SMiri Korenblit /* if PPE Thresholds doesn't present in both EHT IE and HE IE - 21524df6a075SMiri Korenblit * take the Thresholds from Common Nominal Packet Padding field 21534df6a075SMiri Korenblit */ 21544df6a075SMiri Korenblit } else { 21554df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 21564df6a075SMiri Korenblit nominal_padding); 21574df6a075SMiri Korenblit } 21584df6a075SMiri Korenblit } else if (sta->deflink.he_cap.has_he) { 21594df6a075SMiri Korenblit /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 21604df6a075SMiri Korenblit if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] & 21614df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 21624df6a075SMiri Korenblit iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta, pkt_ext, 21634df6a075SMiri Korenblit false); 21644df6a075SMiri Korenblit /* PPE Thresholds doesn't exist - set the API PPE values 21654df6a075SMiri Korenblit * according to Common Nominal Packet Padding field. 21664df6a075SMiri Korenblit */ 21674df6a075SMiri Korenblit } else { 21684df6a075SMiri Korenblit nominal_padding = 21694df6a075SMiri Korenblit u8_get_bits(sta->deflink.he_cap.he_cap_elem.phy_cap_info[9], 21704df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 21714df6a075SMiri Korenblit if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) 21724df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 21734df6a075SMiri Korenblit nominal_padding); 21744df6a075SMiri Korenblit } 21754df6a075SMiri Korenblit } 21764df6a075SMiri Korenblit 21774df6a075SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 21784df6a075SMiri Korenblit int bw; 21794df6a075SMiri Korenblit 21804df6a075SMiri Korenblit for (bw = 0; 21814df6a075SMiri Korenblit bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]); 21824df6a075SMiri Korenblit bw++) { 21834df6a075SMiri Korenblit u8 *qam_th = 21844df6a075SMiri Korenblit &pkt_ext->pkt_ext_qam_th[i][bw][0]; 21854df6a075SMiri Korenblit 21864df6a075SMiri Korenblit IWL_DEBUG_HT(mvm, 21874df6a075SMiri Korenblit "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n", 21884df6a075SMiri Korenblit i, bw, qam_th[0], qam_th[1]); 21894df6a075SMiri Korenblit } 21904df6a075SMiri Korenblit } 21914df6a075SMiri Korenblit return ret; 21924df6a075SMiri Korenblit } 21934df6a075SMiri Korenblit 21949c4f15caSMiri Korenblit /* 21959c4f15caSMiri Korenblit * This function sets the MU EDCA parameters ans returns whether MU EDCA 21969c4f15caSMiri Korenblit * is enabled or not 21979c4f15caSMiri Korenblit */ 219855eb1c5fSMiri Korenblit bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, 21999c4f15caSMiri Korenblit struct iwl_mvm_vif *mvmvif, 220055eb1c5fSMiri Korenblit struct iwl_he_backoff_conf *trig_based_txf) 22019c4f15caSMiri Korenblit { 22029c4f15caSMiri Korenblit int i; 22039c4f15caSMiri Korenblit /* Mark MU EDCA as enabled, unless none detected on some AC */ 22049c4f15caSMiri Korenblit bool mu_edca_enabled = true; 22059c4f15caSMiri Korenblit 22069c4f15caSMiri Korenblit for (i = 0; i < IEEE80211_NUM_ACS; i++) { 22079c4f15caSMiri Korenblit struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2208650cadb7SGregory Greenman &mvmvif->deflink.queue_params[i].mu_edca_param_rec; 22099c4f15caSMiri Korenblit u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 22109c4f15caSMiri Korenblit 2211650cadb7SGregory Greenman if (!mvmvif->deflink.queue_params[i].mu_edca) { 22129c4f15caSMiri Korenblit mu_edca_enabled = false; 22139c4f15caSMiri Korenblit break; 22149c4f15caSMiri Korenblit } 22159c4f15caSMiri Korenblit 22169c4f15caSMiri Korenblit trig_based_txf[ac].cwmin = 22179c4f15caSMiri Korenblit cpu_to_le16(mu_edca->ecw_min_max & 0xf); 22189c4f15caSMiri Korenblit trig_based_txf[ac].cwmax = 22199c4f15caSMiri Korenblit cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 22209c4f15caSMiri Korenblit trig_based_txf[ac].aifsn = 22219c4f15caSMiri Korenblit cpu_to_le16(mu_edca->aifsn & 0xf); 22229c4f15caSMiri Korenblit trig_based_txf[ac].mu_time = 22239c4f15caSMiri Korenblit cpu_to_le16(mu_edca->mu_edca_timer); 22249c4f15caSMiri Korenblit } 22259c4f15caSMiri Korenblit 22269c4f15caSMiri Korenblit return mu_edca_enabled; 22279c4f15caSMiri Korenblit } 22289c4f15caSMiri Korenblit 22299be162a7SMiri Korenblit bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 22309c4f15caSMiri Korenblit { 22319c4f15caSMiri Korenblit const struct ieee80211_supported_band *sband; 22329c4f15caSMiri Korenblit const struct ieee80211_sta_he_cap *own_he_cap = NULL; 22339c4f15caSMiri Korenblit 22349c4f15caSMiri Korenblit /* This capability is the same for all bands, 22359c4f15caSMiri Korenblit * so take it from one of them. 22369c4f15caSMiri Korenblit */ 22379c4f15caSMiri Korenblit sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 22389c4f15caSMiri Korenblit own_he_cap = ieee80211_get_he_iftype_cap(sband, 22399c4f15caSMiri Korenblit ieee80211_vif_type_p2p(vif)); 22409c4f15caSMiri Korenblit 22419c4f15caSMiri Korenblit return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] & 22429c4f15caSMiri Korenblit IEEE80211_HE_MAC_CAP2_ACK_EN)); 22439c4f15caSMiri Korenblit } 22449c4f15caSMiri Korenblit 224587f7e243SMiri Korenblit __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta) 22464df6a075SMiri Korenblit { 22474df6a075SMiri Korenblit u8 *mac_cap_info = &sta->deflink.he_cap.he_cap_elem.mac_cap_info[0]; 22484df6a075SMiri Korenblit __le32 htc_flags = 0; 22494df6a075SMiri Korenblit 22504df6a075SMiri Korenblit if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) 22514df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 22524df6a075SMiri Korenblit if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 22534df6a075SMiri Korenblit (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 22544df6a075SMiri Korenblit u8 link_adap = 22554df6a075SMiri Korenblit ((mac_cap_info[2] & 22564df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 22574df6a075SMiri Korenblit (mac_cap_info[1] & 22584df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 22594df6a075SMiri Korenblit 22604df6a075SMiri Korenblit if (link_adap == 2) 22614df6a075SMiri Korenblit htc_flags |= 22624df6a075SMiri Korenblit cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 22634df6a075SMiri Korenblit else if (link_adap == 3) 22644df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 22654df6a075SMiri Korenblit } 22664df6a075SMiri Korenblit if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 22674df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 22684df6a075SMiri Korenblit if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 22694df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 22704df6a075SMiri Korenblit if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 22714df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 22724df6a075SMiri Korenblit 22734df6a075SMiri Korenblit return htc_flags; 22744df6a075SMiri Korenblit } 22754df6a075SMiri Korenblit 2276514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 2277514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 2278514c3069SLuca Coelho { 2279514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 228042506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { 2281514c3069SLuca Coelho .sta_id = sta_id, 2282514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 2283dd56e902SJohn Crispin .bss_color = vif->bss_conf.he_bss_color.color, 2284514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 2285514c3069SLuca Coelho .frame_time_rts_th = 2286514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 2287514c3069SLuca Coelho }; 228842506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; 228942506dd2SJohannes Berg u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); 229042506dd2SJohannes Berg u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); 229142506dd2SJohannes Berg int size; 2292514c3069SLuca Coelho struct ieee80211_sta *sta; 2293514c3069SLuca Coelho u32 flags; 2294514c3069SLuca Coelho int i; 229542506dd2SJohannes Berg void *cmd; 229642506dd2SJohannes Berg 229742506dd2SJohannes Berg if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) 229842506dd2SJohannes Berg ver = 1; 229942506dd2SJohannes Berg 230042506dd2SJohannes Berg switch (ver) { 230142506dd2SJohannes Berg case 1: 230242506dd2SJohannes Berg /* same layout as v2 except some data at the end */ 230342506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 230442506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v1); 230542506dd2SJohannes Berg break; 230642506dd2SJohannes Berg case 2: 230742506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 230842506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v2); 230942506dd2SJohannes Berg break; 231042506dd2SJohannes Berg case 3: 231142506dd2SJohannes Berg cmd = &sta_ctxt_cmd; 231242506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v3); 231342506dd2SJohannes Berg break; 231442506dd2SJohannes Berg default: 231542506dd2SJohannes Berg IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); 231642506dd2SJohannes Berg return; 231742506dd2SJohannes Berg } 2318514c3069SLuca Coelho 2319514c3069SLuca Coelho rcu_read_lock(); 2320514c3069SLuca Coelho 2321514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 232212d47f0eSAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) { 2323514c3069SLuca Coelho rcu_read_unlock(); 2324514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 2325514c3069SLuca Coelho return; 2326514c3069SLuca Coelho } 2327514c3069SLuca Coelho 2328046d2e7cSSriram R if (!sta->deflink.he_cap.has_he) { 2329514c3069SLuca Coelho rcu_read_unlock(); 2330514c3069SLuca Coelho return; 2331514c3069SLuca Coelho } 2332514c3069SLuca Coelho 2333514c3069SLuca Coelho flags = 0; 2334514c3069SLuca Coelho 23354f58121dSIlan Peer /* Block 26-tone RU OFDMA transmissions */ 2336650cadb7SGregory Greenman if (mvmvif->deflink.he_ru_2mhz_block) 23374f58121dSIlan Peer flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 23384f58121dSIlan Peer 2339514c3069SLuca Coelho /* HTC flags */ 23404df6a075SMiri Korenblit sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta); 2341514c3069SLuca Coelho 23424df6a075SMiri Korenblit /* PPE Thresholds */ 23434df6a075SMiri Korenblit if (!iwl_mvm_set_sta_pkt_ext(mvm, sta, &sta_ctxt_cmd.pkt_ext)) 2344cb63eb43SMiri Korenblit flags |= STA_CTXT_HE_PACKET_EXT; 234573f23d91SShaul Triebitz 2346046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 234773f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 234873f23d91SShaul Triebitz flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 234973f23d91SShaul Triebitz 2350046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 235173f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN) 235273f23d91SShaul Triebitz flags |= STA_CTXT_HE_ACK_ENABLED; 235373f23d91SShaul Triebitz 2354514c3069SLuca Coelho rcu_read_unlock(); 2355514c3069SLuca Coelho 23569c4f15caSMiri Korenblit if (iwl_mvm_set_fw_mu_edca_params(mvm, mvmvif, 23579c4f15caSMiri Korenblit &sta_ctxt_cmd.trig_based_txf[0])) 2358514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 2359514c3069SLuca Coelho 2360514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2361514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2362514c3069SLuca Coelho 2363514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2364514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2365514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2366514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2367514c3069SLuca Coelho } 2368514c3069SLuca Coelho 23699c4f15caSMiri Korenblit if (!iwl_mvm_is_nic_ack_enabled(mvm, vif)) 2370ee1a02d7SShaul Triebitz flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2371ee1a02d7SShaul Triebitz 2372918cbf39SSara Sharon if (vif->bss_conf.nontransmitted) { 2373918cbf39SSara Sharon flags |= STA_CTXT_HE_REF_BSSID_VALID; 2374918cbf39SSara Sharon ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2375918cbf39SSara Sharon vif->bss_conf.transmitter_bssid); 2376d14ae796SSara Sharon sta_ctxt_cmd.max_bssid_indicator = 2377d14ae796SSara Sharon vif->bss_conf.bssid_indicator; 2378d14ae796SSara Sharon sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2379d14ae796SSara Sharon sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2380d14ae796SSara Sharon sta_ctxt_cmd.profile_periodicity = 2381d14ae796SSara Sharon vif->bss_conf.profile_periodicity; 2382918cbf39SSara Sharon } 2383514c3069SLuca Coelho 2384514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2385514c3069SLuca Coelho 238642506dd2SJohannes Berg if (ver < 3) { 238742506dd2SJohannes Berg /* fields before pkt_ext */ 238842506dd2SJohannes Berg BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != 238942506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); 239042506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, 239142506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd), pkt_ext)); 239242506dd2SJohannes Berg 239342506dd2SJohannes Berg /* pkt_ext */ 239442506dd2SJohannes Berg for (i = 0; 239542506dd2SJohannes Berg i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); 239642506dd2SJohannes Berg i++) { 239742506dd2SJohannes Berg u8 bw; 239842506dd2SJohannes Berg 239942506dd2SJohannes Berg for (bw = 0; 240042506dd2SJohannes Berg bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); 240142506dd2SJohannes Berg bw++) { 240242506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != 240342506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); 240442506dd2SJohannes Berg 240542506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], 240642506dd2SJohannes Berg &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], 240742506dd2SJohannes Berg sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); 240842506dd2SJohannes Berg } 240942506dd2SJohannes Berg } 241042506dd2SJohannes Berg 241142506dd2SJohannes Berg /* fields after pkt_ext */ 241242506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - 241342506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != 241442506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2) - 241542506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); 241642506dd2SJohannes Berg memcpy((u8 *)&sta_ctxt_cmd_v2 + 241742506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), 241842506dd2SJohannes Berg (u8 *)&sta_ctxt_cmd + 241942506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext), 242042506dd2SJohannes Berg sizeof(sta_ctxt_cmd) - 242142506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); 242242506dd2SJohannes Berg sta_ctxt_cmd_v2.reserved3 = 0; 242342506dd2SJohannes Berg } 242442506dd2SJohannes Berg 242542506dd2SJohannes Berg if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) 2426514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2427514c3069SLuca Coelho } 2428514c3069SLuca Coelho 2429660eba5aSMiri Korenblit void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2430af84ac57SJohannes Berg u32 duration_override) 2431af84ac57SJohannes Berg { 2432af84ac57SJohannes Berg u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2433af84ac57SJohannes Berg u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2434af84ac57SJohannes Berg 2435af84ac57SJohannes Berg if (duration_override > duration) 2436af84ac57SJohannes Berg duration = duration_override; 2437af84ac57SJohannes Berg 2438af84ac57SJohannes Berg /* Try really hard to protect the session and hear a beacon 2439af84ac57SJohannes Berg * The new session protection command allows us to protect the 2440af84ac57SJohannes Berg * session for a much longer time since the firmware will internally 2441af84ac57SJohannes Berg * create two events: a 300TU one with a very high priority that 2442af84ac57SJohannes Berg * won't be fragmented which should be enough for 99% of the cases, 2443af84ac57SJohannes Berg * and another one (which we configure here to be 900TU long) which 2444af84ac57SJohannes Berg * will have a slightly lower priority, but more importantly, can be 2445af84ac57SJohannes Berg * fragmented so that it'll allow other activities to run. 2446af84ac57SJohannes Berg */ 2447af84ac57SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 2448af84ac57SJohannes Berg IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2449af84ac57SJohannes Berg iwl_mvm_schedule_session_protection(mvm, vif, 900, 2450af84ac57SJohannes Berg min_duration, false); 2451af84ac57SJohannes Berg else 2452af84ac57SJohannes Berg iwl_mvm_protect_session(mvm, vif, duration, 2453af84ac57SJohannes Berg min_duration, 500, false); 2454af84ac57SJohannes Berg } 2455af84ac57SJohannes Berg 2456660eba5aSMiri Korenblit /* Handle association common part to MLD and non-MLD modes */ 2457660eba5aSMiri Korenblit void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm, 2458660eba5aSMiri Korenblit struct ieee80211_vif *vif, 2459660eba5aSMiri Korenblit u64 changes) 2460660eba5aSMiri Korenblit { 2461660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2462660eba5aSMiri Korenblit int ret; 2463660eba5aSMiri Korenblit 2464660eba5aSMiri Korenblit /* The firmware tracks the MU-MIMO group on its own. 2465660eba5aSMiri Korenblit * However, on HW restart we should restore this data. 2466660eba5aSMiri Korenblit */ 2467660eba5aSMiri Korenblit if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2468660eba5aSMiri Korenblit (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { 2469660eba5aSMiri Korenblit ret = iwl_mvm_update_mu_groups(mvm, vif); 2470660eba5aSMiri Korenblit if (ret) 2471660eba5aSMiri Korenblit IWL_ERR(mvm, 2472660eba5aSMiri Korenblit "failed to update VHT MU_MIMO groups\n"); 2473660eba5aSMiri Korenblit } 2474660eba5aSMiri Korenblit 2475660eba5aSMiri Korenblit iwl_mvm_recalc_multicast(mvm); 2476660eba5aSMiri Korenblit 2477660eba5aSMiri Korenblit /* reset rssi values */ 2478660eba5aSMiri Korenblit mvmvif->bf_data.ave_beacon_signal = 0; 2479660eba5aSMiri Korenblit 2480660eba5aSMiri Korenblit iwl_mvm_bt_coex_vif_change(mvm); 2481660eba5aSMiri Korenblit iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2482660eba5aSMiri Korenblit IEEE80211_SMPS_AUTOMATIC); 2483660eba5aSMiri Korenblit if (fw_has_capa(&mvm->fw->ucode_capa, 2484660eba5aSMiri Korenblit IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2485660eba5aSMiri Korenblit iwl_mvm_config_scan(mvm); 2486660eba5aSMiri Korenblit } 2487660eba5aSMiri Korenblit 2488660eba5aSMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 2489660eba5aSMiri Korenblit void iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm, 2490660eba5aSMiri Korenblit struct ieee80211_vif *vif, 2491660eba5aSMiri Korenblit u64 changes) 2492660eba5aSMiri Korenblit { 2493660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2494660eba5aSMiri Korenblit int ret; 2495660eba5aSMiri Korenblit 2496660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BEACON_INFO) { 2497660eba5aSMiri Korenblit /* We received a beacon from the associated AP so 2498660eba5aSMiri Korenblit * remove the session protection. 2499660eba5aSMiri Korenblit */ 2500660eba5aSMiri Korenblit iwl_mvm_stop_session_protection(mvm, vif); 2501660eba5aSMiri Korenblit 2502660eba5aSMiri Korenblit iwl_mvm_sf_update(mvm, vif, false); 2503660eba5aSMiri Korenblit WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2504660eba5aSMiri Korenblit } 2505660eba5aSMiri Korenblit 2506660eba5aSMiri Korenblit if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2507660eba5aSMiri Korenblit /* Send power command on every beacon change, 2508660eba5aSMiri Korenblit * because we may have not enabled beacon abort yet. 2509660eba5aSMiri Korenblit */ 2510660eba5aSMiri Korenblit BSS_CHANGED_BEACON_INFO)) { 2511660eba5aSMiri Korenblit ret = iwl_mvm_power_update_mac(mvm); 2512660eba5aSMiri Korenblit if (ret) 2513660eba5aSMiri Korenblit IWL_ERR(mvm, "failed to update power mode\n"); 2514660eba5aSMiri Korenblit } 2515660eba5aSMiri Korenblit 2516660eba5aSMiri Korenblit if (changes & BSS_CHANGED_CQM) { 2517660eba5aSMiri Korenblit IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); 2518660eba5aSMiri Korenblit /* reset cqm events tracking */ 2519660eba5aSMiri Korenblit mvmvif->bf_data.last_cqm_event = 0; 2520660eba5aSMiri Korenblit if (mvmvif->bf_data.bf_enabled) { 2521660eba5aSMiri Korenblit ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 2522660eba5aSMiri Korenblit if (ret) 2523660eba5aSMiri Korenblit IWL_ERR(mvm, 2524660eba5aSMiri Korenblit "failed to update CQM thresholds\n"); 2525660eba5aSMiri Korenblit } 2526660eba5aSMiri Korenblit } 2527660eba5aSMiri Korenblit 2528660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BANDWIDTH) 2529660eba5aSMiri Korenblit iwl_mvm_apply_fw_smps_request(vif); 2530660eba5aSMiri Korenblit } 2531660eba5aSMiri Korenblit 2532e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2533e705c121SKalle Valo struct ieee80211_vif *vif, 2534e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 25357b7090b4SJohannes Berg u64 changes) 2536e705c121SKalle Valo { 2537e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2538e705c121SKalle Valo int ret; 2539e705c121SKalle Valo 2540e705c121SKalle Valo /* 2541cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend 2542cdaba917SEmmanuel Grumbach * on the beacon interval, which was not known when the station 2543cdaba917SEmmanuel Grumbach * interface was added. 2544e705c121SKalle Valo */ 2545f276e20bSJohannes Berg if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { 2546cb63eb43SMiri Korenblit if ((vif->bss_conf.he_support && 2547cb63eb43SMiri Korenblit !iwlwifi_mod_params.disable_11ax) || 2548cb63eb43SMiri Korenblit (vif->bss_conf.eht_support && 2549cb63eb43SMiri Korenblit !iwlwifi_mod_params.disable_11be)) 2550650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 2551514c3069SLuca Coelho 2552e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2553514c3069SLuca Coelho } 2554e705c121SKalle Valo 255540ecdd01SShaul Triebitz /* Update MU EDCA params */ 255640ecdd01SShaul Triebitz if (changes & BSS_CHANGED_QOS && mvmvif->associated && 2557cb63eb43SMiri Korenblit vif->cfg.assoc && 2558cb63eb43SMiri Korenblit ((vif->bss_conf.he_support && 2559cb63eb43SMiri Korenblit !iwlwifi_mod_params.disable_11ax) || 2560cb63eb43SMiri Korenblit (vif->bss_conf.eht_support && 2561cb63eb43SMiri Korenblit !iwlwifi_mod_params.disable_11be))) 2562650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 256340ecdd01SShaul Triebitz 2564e705c121SKalle Valo /* 2565e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2566e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2567e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2568e705c121SKalle Valo * branch for disassociation below. 2569e705c121SKalle Valo */ 2570e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2571650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2572e705c121SKalle Valo 2573650cadb7SGregory Greenman ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid); 2574e705c121SKalle Valo if (ret) 2575e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2576e705c121SKalle Valo 2577e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2578650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2579f276e20bSJohannes Berg mvmvif->associated = vif->cfg.assoc; 2580e705c121SKalle Valo 2581e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2582f276e20bSJohannes Berg if (vif->cfg.assoc) { 2583e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2584e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2585650cadb7SGregory Greenman memset(&mvmvif->deflink.beacon_stats, 0, 2586650cadb7SGregory Greenman sizeof(mvmvif->deflink.beacon_stats)); 2587e705c121SKalle Valo 2588e705c121SKalle Valo /* add quota for this interface */ 2589e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2590e705c121SKalle Valo if (ret) { 2591e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2592e705c121SKalle Valo return; 2593e705c121SKalle Valo } 2594e705c121SKalle Valo 2595e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2596fe959c7bSEmmanuel Grumbach &mvm->status) && 2597fe959c7bSEmmanuel Grumbach !fw_has_capa(&mvm->fw->ucode_capa, 2598fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2599e705c121SKalle Valo /* 2600e705c121SKalle Valo * If we're restarting then the firmware will 2601e705c121SKalle Valo * obviously have lost synchronisation with 2602e705c121SKalle Valo * the AP. It will attempt to synchronise by 2603e705c121SKalle Valo * itself, but we can make it more reliable by 2604e705c121SKalle Valo * scheduling a session protection time event. 2605e705c121SKalle Valo * 2606e705c121SKalle Valo * The firmware needs to receive a beacon to 2607e705c121SKalle Valo * catch up with synchronisation, use 110% of 2608e705c121SKalle Valo * the beacon interval. 2609e705c121SKalle Valo * 2610e705c121SKalle Valo * Set a large maximum delay to allow for more 2611e705c121SKalle Valo * than a single interface. 2612fe959c7bSEmmanuel Grumbach * 2613fe959c7bSEmmanuel Grumbach * For new firmware versions, rely on the 2614fe959c7bSEmmanuel Grumbach * firmware. This is relevant for DCM scenarios 2615fe959c7bSEmmanuel Grumbach * only anyway. 2616e705c121SKalle Valo */ 2617e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2618e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2619e705c121SKalle Valo 5 * dur, false); 2620af84ac57SJohannes Berg } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2621af84ac57SJohannes Berg &mvm->status) && 2622af84ac57SJohannes Berg !vif->bss_conf.dtim_period) { 2623af84ac57SJohannes Berg /* 2624af84ac57SJohannes Berg * If we're not restarting and still haven't 2625af84ac57SJohannes Berg * heard a beacon (dtim period unknown) then 2626af84ac57SJohannes Berg * make sure we still have enough minimum time 2627af84ac57SJohannes Berg * remaining in the time event, since the auth 2628af84ac57SJohannes Berg * might actually have taken quite a while 2629af84ac57SJohannes Berg * (especially for SAE) and so the remaining 2630af84ac57SJohannes Berg * time could be small without us having heard 2631af84ac57SJohannes Berg * a beacon yet. 2632af84ac57SJohannes Berg */ 2633af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, 0); 2634e705c121SKalle Valo } 2635e705c121SKalle Valo 2636e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2637e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2638e705c121SKalle Valo if (vif->p2p) { 2639e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2640e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 2641e705c121SKalle Valo IEEE80211_SMPS_DYNAMIC); 2642e705c121SKalle Valo } 2643650cadb7SGregory Greenman } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) { 26446d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_disassociated(mvm); 2645e705c121SKalle Valo /* 2646e705c121SKalle Valo * If update fails - SF might be running in associated 2647e705c121SKalle Valo * mode while disassociated - which is forbidden. 2648e705c121SKalle Valo */ 264969e508b4SIlan Peer ret = iwl_mvm_sf_update(mvm, vif, false); 265069e508b4SIlan Peer WARN_ONCE(ret && 265169e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 265269e508b4SIlan Peer &mvm->status), 2653e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2654e705c121SKalle Valo 26556b28f978SEmmanuel Grumbach /* 26566b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 26576b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 26586b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 26596b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 26606b28f978SEmmanuel Grumbach * associated, we would remove the station here and 26616b28f978SEmmanuel Grumbach * this would fail the recovery. 26626b28f978SEmmanuel Grumbach */ 26636b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 26646b28f978SEmmanuel Grumbach &mvm->status)) { 26655c75a208SJohannes Berg /* first remove remaining keys */ 26665c75a208SJohannes Berg iwl_mvm_sec_key_remove_ap(mvm, vif); 26675c75a208SJohannes Berg 26686b28f978SEmmanuel Grumbach /* 26696b28f978SEmmanuel Grumbach * Remove AP station now that 26706b28f978SEmmanuel Grumbach * the MAC is unassoc 26716b28f978SEmmanuel Grumbach */ 26726b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 2673650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id); 2674e705c121SKalle Valo if (ret) 26756b28f978SEmmanuel Grumbach IWL_ERR(mvm, 26766b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2677e705c121SKalle Valo 2678650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA; 26796b28f978SEmmanuel Grumbach } 26806b28f978SEmmanuel Grumbach 2681e705c121SKalle Valo /* remove quota for this interface */ 2682e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2683e705c121SKalle Valo if (ret) 2684e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2685e705c121SKalle Valo 2686e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2687e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2688e705c121SKalle Valo if (ret) 2689e705c121SKalle Valo IWL_ERR(mvm, 2690e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2691e705c121SKalle Valo vif->addr); 2692e705c121SKalle Valo } 2693e705c121SKalle Valo 2694660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes); 2695a07a8f37SSara Sharon } 2696a07a8f37SSara Sharon 2697660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_station_common(mvm, vif, changes); 2698e705c121SKalle Valo } 2699e705c121SKalle Valo 2700f947b62cSMiri Korenblit bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw, 2701f947b62cSMiri Korenblit struct ieee80211_vif *vif, 2702f947b62cSMiri Korenblit int *ret) 2703f947b62cSMiri Korenblit { 2704f947b62cSMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2705f947b62cSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2706f947b62cSMiri Korenblit int i; 2707f947b62cSMiri Korenblit 2708f947b62cSMiri Korenblit lockdep_assert_held(&mvm->mutex); 2709f947b62cSMiri Korenblit 2710f947b62cSMiri Korenblit mvmvif->ap_assoc_sta_count = 0; 2711f947b62cSMiri Korenblit 2712f947b62cSMiri Korenblit /* must be set before quota calculations */ 2713f947b62cSMiri Korenblit mvmvif->ap_ibss_active = true; 2714f947b62cSMiri Korenblit 2715f947b62cSMiri Korenblit /* send all the early keys to the device now */ 2716f947b62cSMiri Korenblit for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2717f947b62cSMiri Korenblit struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2718f947b62cSMiri Korenblit 2719f947b62cSMiri Korenblit if (!key) 2720f947b62cSMiri Korenblit continue; 2721f947b62cSMiri Korenblit 2722f947b62cSMiri Korenblit mvmvif->ap_early_keys[i] = NULL; 2723f947b62cSMiri Korenblit 2724f947b62cSMiri Korenblit *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2725f947b62cSMiri Korenblit if (*ret) 2726f947b62cSMiri Korenblit return true; 2727f947b62cSMiri Korenblit } 2728f947b62cSMiri Korenblit 2729f947b62cSMiri Korenblit if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 2730f947b62cSMiri Korenblit iwl_mvm_vif_set_low_latency(mvmvif, true, 2731f947b62cSMiri Korenblit LOW_LATENCY_VIF_TYPE); 2732f947b62cSMiri Korenblit iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 2733f947b62cSMiri Korenblit } 2734f947b62cSMiri Korenblit 2735f947b62cSMiri Korenblit /* power updated needs to be done before quotas */ 2736f947b62cSMiri Korenblit iwl_mvm_power_update_mac(mvm); 2737f947b62cSMiri Korenblit 2738f947b62cSMiri Korenblit return false; 2739f947b62cSMiri Korenblit } 2740f947b62cSMiri Korenblit 2741e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2742ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2743b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2744e705c121SKalle Valo { 2745e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2746e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2747f947b62cSMiri Korenblit int ret; 2748e705c121SKalle Valo 2749e705c121SKalle Valo mutex_lock(&mvm->mutex); 2750e705c121SKalle Valo 2751e705c121SKalle Valo /* 2752cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend on 2753cdaba917SEmmanuel Grumbach * the beacon interval, which was not known when the AP interface 2754cdaba917SEmmanuel Grumbach * was added. 2755e705c121SKalle Valo */ 2756e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2757e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2758e705c121SKalle Valo 2759*36cf5377SGregory Greenman /* For older devices need to send beacon template before adding mac 2760*36cf5377SGregory Greenman * context. For the newer, the beacon is a resource that belongs to a 2761*36cf5377SGregory Greenman * MAC, so need to send beacon template after adding the mac. 2762*36cf5377SGregory Greenman */ 2763*36cf5377SGregory Greenman if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) { 2764e705c121SKalle Valo /* Add the mac context */ 2765e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2766e705c121SKalle Valo if (ret) 2767e705c121SKalle Valo goto out_unlock; 2768e705c121SKalle Valo 2769*36cf5377SGregory Greenman /* Send the beacon template */ 2770*36cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 2771*36cf5377SGregory Greenman if (ret) 2772*36cf5377SGregory Greenman goto out_unlock; 2773*36cf5377SGregory Greenman } else { 2774*36cf5377SGregory Greenman /* Send the beacon template */ 2775*36cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 2776*36cf5377SGregory Greenman if (ret) 2777*36cf5377SGregory Greenman goto out_unlock; 2778*36cf5377SGregory Greenman 2779*36cf5377SGregory Greenman /* Add the mac context */ 2780*36cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2781*36cf5377SGregory Greenman if (ret) 2782*36cf5377SGregory Greenman goto out_unlock; 2783*36cf5377SGregory Greenman } 2784*36cf5377SGregory Greenman 2785e705c121SKalle Valo /* Perform the binding */ 2786e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2787e705c121SKalle Valo if (ret) 2788e705c121SKalle Valo goto out_remove; 2789e705c121SKalle Valo 279063dd5d02SSara Sharon /* 279163dd5d02SSara Sharon * This is not very nice, but the simplest: 279263dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 279363dd5d02SSara Sharon * cause assert 0x2b00. 279463dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 279563dd5d02SSara Sharon * the TLV 279663dd5d02SSara Sharon */ 279763dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2798ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2799ced19f26SSara Sharon if (ret) 2800ced19f26SSara Sharon goto out_unbind; 280163dd5d02SSara Sharon /* 280263dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 280363dd5d02SSara Sharon * events are added and applied to the scheduler 280463dd5d02SSara Sharon */ 2805e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 280663dd5d02SSara Sharon if (ret) { 280763dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 280863dd5d02SSara Sharon goto out_unbind; 280963dd5d02SSara Sharon } 281063dd5d02SSara Sharon } else { 281163dd5d02SSara Sharon /* 281263dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 281363dd5d02SSara Sharon * events are added and applied to the scheduler 281463dd5d02SSara Sharon */ 281575fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2816e705c121SKalle Valo if (ret) 281763dd5d02SSara Sharon goto out_unbind; 281875fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 281963dd5d02SSara Sharon if (ret) { 282063dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 282163dd5d02SSara Sharon goto out_unbind; 282263dd5d02SSara Sharon } 282363dd5d02SSara Sharon } 282426d6c16bSSara Sharon 2825f947b62cSMiri Korenblit if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) 2826f947b62cSMiri Korenblit goto out_failed; 2827e705c121SKalle Valo 2828e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2829e705c121SKalle Valo if (ret) 2830f947b62cSMiri Korenblit goto out_failed; 2831e705c121SKalle Valo 2832e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2833e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2834e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2835e705c121SKalle Valo 2836e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2837e705c121SKalle Valo 2838e705c121SKalle Valo /* we don't support TDLS during DCM */ 2839e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2840e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2841e705c121SKalle Valo 2842b73f9a4aSJohannes Berg iwl_mvm_ftm_restart_responder(mvm, vif); 2843b73f9a4aSJohannes Berg 2844e705c121SKalle Valo goto out_unlock; 2845e705c121SKalle Valo 2846f947b62cSMiri Korenblit out_failed: 2847e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2848e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2849e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2850ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2851e705c121SKalle Valo out_unbind: 2852e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2853e705c121SKalle Valo out_remove: 2854e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2855e705c121SKalle Valo out_unlock: 2856e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2857e705c121SKalle Valo return ret; 2858e705c121SKalle Valo } 2859e705c121SKalle Valo 2860ae7ba17bSShaul Triebitz static int iwl_mvm_start_ap(struct ieee80211_hw *hw, 2861ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2862b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2863ae7ba17bSShaul Triebitz { 2864b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, link_conf); 2865ae7ba17bSShaul Triebitz } 2866ae7ba17bSShaul Triebitz 2867ae7ba17bSShaul Triebitz static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, 2868e705c121SKalle Valo struct ieee80211_vif *vif) 2869e705c121SKalle Valo { 2870b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); 2871ae7ba17bSShaul Triebitz } 2872ae7ba17bSShaul Triebitz 2873fd1a54c1SMiri Korenblit /* Common part for MLD and non-MLD ops */ 2874fd1a54c1SMiri Korenblit void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm, 2875fd1a54c1SMiri Korenblit struct ieee80211_vif *vif) 2876ae7ba17bSShaul Triebitz { 2877e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2878e705c121SKalle Valo 2879fd1a54c1SMiri Korenblit lockdep_assert_held(&mvm->mutex); 2880e705c121SKalle Valo 2881fd1a54c1SMiri Korenblit iwl_mvm_prepare_mac_removal(mvm, vif); 2882e705c121SKalle Valo 2883e705c121SKalle Valo /* Handle AP stop while in CSA */ 2884e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 2885e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 2886e705c121SKalle Valo &mvmvif->time_event_data); 2887e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 2888e705c121SKalle Valo mvmvif->csa_countdown = false; 2889e705c121SKalle Valo } 2890e705c121SKalle Valo 2891e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 2892e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2893e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 2894e705c121SKalle Valo } 2895e705c121SKalle Valo 2896e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2897e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 2898e705c121SKalle Valo 289947242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 290047242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 290147242744STova Mussai LOW_LATENCY_VIF_TYPE); 290247242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 290347242744STova Mussai } 290447242744STova Mussai 2905e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2906fd1a54c1SMiri Korenblit } 2907fd1a54c1SMiri Korenblit 2908fd1a54c1SMiri Korenblit static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 2909fd1a54c1SMiri Korenblit struct ieee80211_vif *vif, 2910fd1a54c1SMiri Korenblit struct ieee80211_bss_conf *link_conf) 2911fd1a54c1SMiri Korenblit { 2912fd1a54c1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2913fd1a54c1SMiri Korenblit 2914fd1a54c1SMiri Korenblit mutex_lock(&mvm->mutex); 2915fd1a54c1SMiri Korenblit 2916fd1a54c1SMiri Korenblit iwl_mvm_stop_ap_ibss_common(mvm, vif); 2917e705c121SKalle Valo 2918e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2919e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2920e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2921e705c121SKalle Valo 2922e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 2923ced19f26SSara Sharon 2924be82ecd3SAvraham Stern iwl_mvm_ftm_responder_clear(mvm, vif); 2925be82ecd3SAvraham Stern 2926ced19f26SSara Sharon /* 2927ced19f26SSara Sharon * This is not very nice, but the simplest: 2928ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 2929ced19f26SSara Sharon * cause assert 0x2b00. 2930ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 2931ced19f26SSara Sharon * bcast station). 2932ced19f26SSara Sharon * So make the order of removal depend on the TLV 2933ced19f26SSara Sharon */ 2934ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 293526d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2936e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2937ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 2938ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2939e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2940e705c121SKalle Valo 2941e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2942e705c121SKalle Valo 2943e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2944e705c121SKalle Valo 2945e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2946e705c121SKalle Valo } 2947e705c121SKalle Valo 2948ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, 2949ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2950b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2951ae7ba17bSShaul Triebitz { 2952b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, link_conf); 2953ae7ba17bSShaul Triebitz } 2954ae7ba17bSShaul Triebitz 2955ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, 2956ae7ba17bSShaul Triebitz struct ieee80211_vif *vif) 2957ae7ba17bSShaul Triebitz { 2958b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); 2959ae7ba17bSShaul Triebitz } 2960ae7ba17bSShaul Triebitz 2961e705c121SKalle Valo static void 2962e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 2963e705c121SKalle Valo struct ieee80211_vif *vif, 2964e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 29657b7090b4SJohannes Berg u64 changes) 2966e705c121SKalle Valo { 2967e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2968e705c121SKalle Valo 2969e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 2970e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 2971e705c121SKalle Valo return; 2972e705c121SKalle Valo 2973e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 2974e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 2975e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 2976e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2977e705c121SKalle Valo 2978e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 2979e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 2980*36cf5377SGregory Greenman iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf)) 2981e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 2982e705c121SKalle Valo 2983b73f9a4aSJohannes Berg if (changes & BSS_CHANGED_FTM_RESPONDER) { 2984b73f9a4aSJohannes Berg int ret = iwl_mvm_ftm_start_responder(mvm, vif); 2985b73f9a4aSJohannes Berg 2986b73f9a4aSJohannes Berg if (ret) 2987b73f9a4aSJohannes Berg IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 2988b73f9a4aSJohannes Berg ret); 2989b73f9a4aSJohannes Berg } 2990b73f9a4aSJohannes Berg 2991e705c121SKalle Valo } 2992e705c121SKalle Valo 2993e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 2994e705c121SKalle Valo struct ieee80211_vif *vif, 2995e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 29967b7090b4SJohannes Berg u64 changes) 2997e705c121SKalle Valo { 2998660eba5aSMiri Korenblit struct iwl_mvm_bss_info_changed_ops callbacks = { 2999660eba5aSMiri Korenblit .bss_info_changed_sta = iwl_mvm_bss_info_changed_station, 3000660eba5aSMiri Korenblit .bss_info_changed_ap_ibss = iwl_mvm_bss_info_changed_ap_ibss, 3001660eba5aSMiri Korenblit }; 3002660eba5aSMiri Korenblit 3003660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_common(hw, vif, bss_conf, &callbacks, 3004660eba5aSMiri Korenblit changes); 3005660eba5aSMiri Korenblit } 3006660eba5aSMiri Korenblit 3007660eba5aSMiri Korenblit void 3008660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_common(struct ieee80211_hw *hw, 3009660eba5aSMiri Korenblit struct ieee80211_vif *vif, 3010660eba5aSMiri Korenblit struct ieee80211_bss_conf *bss_conf, 3011660eba5aSMiri Korenblit struct iwl_mvm_bss_info_changed_ops *callbacks, 3012660eba5aSMiri Korenblit u64 changes) 3013660eba5aSMiri Korenblit { 3014e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3015e705c121SKalle Valo 3016e705c121SKalle Valo mutex_lock(&mvm->mutex); 3017e705c121SKalle Valo 3018f276e20bSJohannes Berg if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 3019e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 3020e705c121SKalle Valo 3021e705c121SKalle Valo switch (vif->type) { 3022e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3023660eba5aSMiri Korenblit callbacks->bss_info_changed_sta(mvm, vif, bss_conf, changes); 3024e705c121SKalle Valo break; 3025e705c121SKalle Valo case NL80211_IFTYPE_AP: 3026e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3027660eba5aSMiri Korenblit callbacks->bss_info_changed_ap_ibss(mvm, vif, bss_conf, 3028660eba5aSMiri Korenblit changes); 3029e705c121SKalle Valo break; 303091b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 303191b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 303291b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 303391b08c2dSAviya Erenfeld break; 3034e705c121SKalle Valo default: 3035e705c121SKalle Valo /* shouldn't happen */ 3036e705c121SKalle Valo WARN_ON_ONCE(1); 3037e705c121SKalle Valo } 3038e705c121SKalle Valo 30399aae43a4SJohannes Berg if (changes & BSS_CHANGED_TXPOWER) { 30409aae43a4SJohannes Berg IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 30419aae43a4SJohannes Berg bss_conf->txpower); 30429aae43a4SJohannes Berg iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 30439aae43a4SJohannes Berg } 30449aae43a4SJohannes Berg 3045e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3046e705c121SKalle Valo } 3047e705c121SKalle Valo 3048cbce62a3SMiri Korenblit int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3049e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 3050e705c121SKalle Valo { 3051e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3052e705c121SKalle Valo int ret; 3053e705c121SKalle Valo 3054e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 3055e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 3056e705c121SKalle Valo return -EINVAL; 3057e705c121SKalle Valo 3058e705c121SKalle Valo mutex_lock(&mvm->mutex); 3059e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 3060e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3061e705c121SKalle Valo 3062e705c121SKalle Valo return ret; 3063e705c121SKalle Valo } 3064e705c121SKalle Valo 3065cbce62a3SMiri Korenblit void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 3066e705c121SKalle Valo struct ieee80211_vif *vif) 3067e705c121SKalle Valo { 3068e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3069e705c121SKalle Valo 3070e705c121SKalle Valo mutex_lock(&mvm->mutex); 3071e705c121SKalle Valo 3072e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3073e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 3074e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 3075e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 3076e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 3077e705c121SKalle Valo * To handle that, simply return if the scan is not running. 3078e705c121SKalle Valo */ 3079e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 3080e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 3081e705c121SKalle Valo 3082e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3083e705c121SKalle Valo } 3084e705c121SKalle Valo 3085cbce62a3SMiri Korenblit void 3086e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 3087e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3088e705c121SKalle Valo int num_frames, 3089e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3090e705c121SKalle Valo bool more_data) 3091e705c121SKalle Valo { 3092e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3093e705c121SKalle Valo 3094e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 3095e705c121SKalle Valo 3096e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3097e705c121SKalle Valo tids, more_data, false); 3098e705c121SKalle Valo } 3099e705c121SKalle Valo 3100cbce62a3SMiri Korenblit void 3101e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 3102e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3103e705c121SKalle Valo int num_frames, 3104e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3105e705c121SKalle Valo bool more_data) 3106e705c121SKalle Valo { 3107e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3108e705c121SKalle Valo 31099a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 3110e705c121SKalle Valo 3111e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3112e705c121SKalle Valo tids, more_data, true); 3113e705c121SKalle Valo } 3114e705c121SKalle Valo 311565e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 3116e705c121SKalle Valo enum sta_notify_cmd cmd, 3117e705c121SKalle Valo struct ieee80211_sta *sta) 3118e705c121SKalle Valo { 3119e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3120e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3121e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 3122e705c121SKalle Valo int tid; 3123e705c121SKalle Valo 3124960f864bSJohannes Berg /* 3125960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 3126960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 3127960f864bSJohannes Berg * should have firmware supporting buffer station offload. 3128960f864bSJohannes Berg */ 3129960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 3130960f864bSJohannes Berg return; 3131960f864bSJohannes Berg 3132e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 3133311590a3SEmmanuel Grumbach for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 3134e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 3135e705c121SKalle Valo 31366862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 31371c17627bSSara Sharon continue; 31381c17627bSSara Sharon 3139e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 3140e705c121SKalle Valo 3141dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 3142e705c121SKalle Valo continue; 3143e705c121SKalle Valo 3144e705c121SKalle Valo __set_bit(tid, &tids); 3145e705c121SKalle Valo } 3146e705c121SKalle Valo 3147e705c121SKalle Valo switch (cmd) { 3148e705c121SKalle Valo case STA_NOTIFY_SLEEP: 3149e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 3150e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 3151e705c121SKalle Valo 3152e705c121SKalle Valo if (txqs) 3153e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 3154e705c121SKalle Valo /* 3155e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 3156e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 3157e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 3158e705c121SKalle Valo */ 3159e705c121SKalle Valo break; 3160e705c121SKalle Valo case STA_NOTIFY_AWAKE: 3161c8ee33e1SGregory Greenman if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA)) 3162e705c121SKalle Valo break; 3163e705c121SKalle Valo 3164e705c121SKalle Valo if (txqs) 3165e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 3166e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 3167e705c121SKalle Valo break; 3168e705c121SKalle Valo default: 3169e705c121SKalle Valo break; 3170e705c121SKalle Valo } 3171e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 3172e705c121SKalle Valo } 3173e705c121SKalle Valo 3174cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3175cbce62a3SMiri Korenblit enum sta_notify_cmd cmd, struct ieee80211_sta *sta) 317665e25482SJohannes Berg { 317765e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 317865e25482SJohannes Berg } 317965e25482SJohannes Berg 318065e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 318165e25482SJohannes Berg { 318265e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 318365e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 318465e25482SJohannes Berg struct ieee80211_sta *sta; 318565e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 318665e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 318765e25482SJohannes Berg 3188be9ae34eSNathan Errera if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 318965e25482SJohannes Berg return; 319065e25482SJohannes Berg 319165e25482SJohannes Berg rcu_read_lock(); 3192a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 319365e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 319465e25482SJohannes Berg rcu_read_unlock(); 319565e25482SJohannes Berg return; 319665e25482SJohannes Berg } 319765e25482SJohannes Berg 319865e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 319965e25482SJohannes Berg 320065e25482SJohannes Berg if (!mvmsta->vif || 320165e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 320265e25482SJohannes Berg rcu_read_unlock(); 320365e25482SJohannes Berg return; 320465e25482SJohannes Berg } 320565e25482SJohannes Berg 320665e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 320765e25482SJohannes Berg mvmsta->sleeping = sleeping; 320865e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 320965e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 321065e25482SJohannes Berg sta); 321165e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 321265e25482SJohannes Berg } 321365e25482SJohannes Berg 321465e25482SJohannes Berg if (sleeping) { 321565e25482SJohannes Berg switch (notif->type) { 321665e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 321765e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 321865e25482SJohannes Berg break; 321965e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 322065e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 322165e25482SJohannes Berg break; 322265e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 322365e25482SJohannes Berg ieee80211_sta_pspoll(sta); 322465e25482SJohannes Berg break; 322565e25482SJohannes Berg default: 322665e25482SJohannes Berg break; 322765e25482SJohannes Berg } 322865e25482SJohannes Berg } 322965e25482SJohannes Berg 323065e25482SJohannes Berg rcu_read_unlock(); 323165e25482SJohannes Berg } 323265e25482SJohannes Berg 3233cbce62a3SMiri Korenblit void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 3234e705c121SKalle Valo struct ieee80211_vif *vif, 3235e705c121SKalle Valo struct ieee80211_sta *sta) 3236e705c121SKalle Valo { 3237e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3238e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3239e705c121SKalle Valo 3240e705c121SKalle Valo /* 3241e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 3242e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 3243e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 3244e705c121SKalle Valo * be able to find the station this way, and we don't rely 3245e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 3246e705c121SKalle Valo * callback deleted the station. 3247e705c121SKalle Valo */ 3248e705c121SKalle Valo mutex_lock(&mvm->mutex); 3249c8ee33e1SGregory Greenman if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->deflink.sta_id])) 3250c8ee33e1SGregory Greenman rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->deflink.sta_id], 3251e705c121SKalle Valo ERR_PTR(-ENOENT)); 3252e705c121SKalle Valo 3253e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3254e705c121SKalle Valo } 3255e705c121SKalle Valo 3256e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 3257e705c121SKalle Valo const u8 *bssid) 3258e705c121SKalle Valo { 3259b0ffe455SJohannes Berg int i; 3260b0ffe455SJohannes Berg 3261b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3262b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 3263b0ffe455SJohannes Berg 3264b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 3265b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 3266b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 3267b0ffe455SJohannes Berg } 3268b0ffe455SJohannes Berg 3269e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 3270e705c121SKalle Valo return; 3271e705c121SKalle Valo 3272c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 3273cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3274cee5a882SAvri Altman return; 3275cee5a882SAvri Altman } 3276cee5a882SAvri Altman 327711dee0b4SEmmanuel Grumbach if (!vif->p2p && 327811dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 3279e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3280e705c121SKalle Valo return; 3281e705c121SKalle Valo } 3282e705c121SKalle Valo 3283b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 3284b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 3285b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3286b0ffe455SJohannes Berg return; 3287b0ffe455SJohannes Berg } 3288b0ffe455SJohannes Berg } 3289b0ffe455SJohannes Berg 3290e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 3291e705c121SKalle Valo } 3292e705c121SKalle Valo 32931e8f1329SGolan Ben-Ami static void 32941e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 32951e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 32961e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 32971e8f1329SGolan Ben-Ami { 32981e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 32991e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 33001e8f1329SGolan Ben-Ami 33016c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 33026c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 33036c042d75SSara Sharon if (!trig) 33041e8f1329SGolan Ben-Ami return; 33051e8f1329SGolan Ben-Ami 33061e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 33071e8f1329SGolan Ben-Ami 33081e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 33091e8f1329SGolan Ben-Ami return; 33101e8f1329SGolan Ben-Ami 33111e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 33121e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 33131e8f1329SGolan Ben-Ami return; 33141e8f1329SGolan Ben-Ami 33157174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 33161e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 33171e8f1329SGolan Ben-Ami peer_addr, action); 33181e8f1329SGolan Ben-Ami } 33191e8f1329SGolan Ben-Ami 33204f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data { 33214f58121dSIlan Peer bool tolerated; 33224f58121dSIlan Peer }; 33234f58121dSIlan Peer 33244f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 33254f58121dSIlan Peer struct cfg80211_bss *bss, 33264f58121dSIlan Peer void *_data) 33274f58121dSIlan Peer { 33284f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 33296c608cd6SJohannes Berg const struct cfg80211_bss_ies *ies; 33304f58121dSIlan Peer const struct element *elem; 33314f58121dSIlan Peer 33326c608cd6SJohannes Berg rcu_read_lock(); 33336c608cd6SJohannes Berg ies = rcu_dereference(bss->ies); 33346c608cd6SJohannes Berg elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 33356c608cd6SJohannes Berg ies->len); 33364f58121dSIlan Peer 33374f58121dSIlan Peer if (!elem || elem->datalen < 10 || 33384f58121dSIlan Peer !(elem->data[10] & 33394f58121dSIlan Peer WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 33404f58121dSIlan Peer data->tolerated = false; 33414f58121dSIlan Peer } 33426c608cd6SJohannes Berg rcu_read_unlock(); 33434f58121dSIlan Peer } 33444f58121dSIlan Peer 33454f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 33464f58121dSIlan Peer struct ieee80211_vif *vif) 33474f58121dSIlan Peer { 33484f58121dSIlan Peer struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 33494f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 33504f58121dSIlan Peer .tolerated = true, 33514f58121dSIlan Peer }; 33524f58121dSIlan Peer 33534f58121dSIlan Peer if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) { 3354650cadb7SGregory Greenman mvmvif->deflink.he_ru_2mhz_block = false; 33554f58121dSIlan Peer return; 33564f58121dSIlan Peer } 33574f58121dSIlan Peer 33584f58121dSIlan Peer cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, 33594f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru_iter, 33604f58121dSIlan Peer &iter_data); 33614f58121dSIlan Peer 33624f58121dSIlan Peer /* 33634f58121dSIlan Peer * If there is at least one AP on radar channel that cannot 33644f58121dSIlan Peer * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 33654f58121dSIlan Peer */ 3366650cadb7SGregory Greenman mvmvif->deflink.he_ru_2mhz_block = !iter_data.tolerated; 33674f58121dSIlan Peer } 33684f58121dSIlan Peer 3369f7d6ef33SJohannes Berg static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3370f7d6ef33SJohannes Berg struct ieee80211_vif *vif) 3371f7d6ef33SJohannes Berg { 3372f7d6ef33SJohannes Berg struct ieee80211_supported_band *sband; 3373f7d6ef33SJohannes Berg const struct ieee80211_sta_he_cap *he_cap; 3374f7d6ef33SJohannes Berg 3375f7d6ef33SJohannes Berg if (vif->type != NL80211_IFTYPE_STATION) 3376f7d6ef33SJohannes Berg return; 3377f7d6ef33SJohannes Berg 3378f7d6ef33SJohannes Berg if (!mvm->cca_40mhz_workaround) 3379f7d6ef33SJohannes Berg return; 3380f7d6ef33SJohannes Berg 3381f7d6ef33SJohannes Berg /* decrement and check that we reached zero */ 3382f7d6ef33SJohannes Berg mvm->cca_40mhz_workaround--; 3383f7d6ef33SJohannes Berg if (mvm->cca_40mhz_workaround) 3384f7d6ef33SJohannes Berg return; 3385f7d6ef33SJohannes Berg 3386f7d6ef33SJohannes Berg sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3387f7d6ef33SJohannes Berg 3388f7d6ef33SJohannes Berg sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3389f7d6ef33SJohannes Berg 3390f7d6ef33SJohannes Berg he_cap = ieee80211_get_he_iftype_cap(sband, 3391f7d6ef33SJohannes Berg ieee80211_vif_type_p2p(vif)); 3392f7d6ef33SJohannes Berg 3393f7d6ef33SJohannes Berg if (he_cap) { 3394f7d6ef33SJohannes Berg /* we know that ours is writable */ 33950301bcd5SBjoern A. Zeeb struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; 3396f7d6ef33SJohannes Berg 3397f7d6ef33SJohannes Berg he->he_cap_elem.phy_cap_info[0] |= 3398f7d6ef33SJohannes Berg IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3399f7d6ef33SJohannes Berg } 3400f7d6ef33SJohannes Berg } 3401f7d6ef33SJohannes Berg 34026d19a5ebSEmmanuel Grumbach static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 34036d19a5ebSEmmanuel Grumbach struct ieee80211_vif *vif, 34046d19a5ebSEmmanuel Grumbach struct iwl_mvm_sta *mvm_sta) 34056d19a5ebSEmmanuel Grumbach { 34066d19a5ebSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI) 34076d19a5ebSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 34086d19a5ebSEmmanuel Grumbach struct iwl_mei_conn_info conn_info = { 3409f276e20bSJohannes Berg .ssid_len = vif->cfg.ssid_len, 34106d19a5ebSEmmanuel Grumbach .channel = vif->bss_conf.chandef.chan->hw_value, 34116d19a5ebSEmmanuel Grumbach }; 34126d19a5ebSEmmanuel Grumbach 34136d19a5ebSEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 34146d19a5ebSEmmanuel Grumbach return; 34156d19a5ebSEmmanuel Grumbach 34166d19a5ebSEmmanuel Grumbach if (!mvm->mei_registered) 34176d19a5ebSEmmanuel Grumbach return; 34186d19a5ebSEmmanuel Grumbach 34196d19a5ebSEmmanuel Grumbach switch (mvm_sta->pairwise_cipher) { 3420e5d3a64eSAvraham Stern case WLAN_CIPHER_SUITE_TKIP: 3421e5d3a64eSAvraham Stern conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP; 3422e5d3a64eSAvraham Stern break; 34236d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_CCMP: 34246d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 34256d19a5ebSEmmanuel Grumbach break; 34266d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP: 34276d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 34286d19a5ebSEmmanuel Grumbach break; 34296d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP_256: 34306d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 34316d19a5ebSEmmanuel Grumbach break; 34326d19a5ebSEmmanuel Grumbach case 0: 34336d19a5ebSEmmanuel Grumbach /* open profile */ 34346d19a5ebSEmmanuel Grumbach break; 34356d19a5ebSEmmanuel Grumbach default: 34366d19a5ebSEmmanuel Grumbach /* cipher not supported, don't send anything to iwlmei */ 34376d19a5ebSEmmanuel Grumbach return; 34386d19a5ebSEmmanuel Grumbach } 34396d19a5ebSEmmanuel Grumbach 34406d19a5ebSEmmanuel Grumbach switch (mvmvif->rekey_data.akm) { 34416d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_SAE & 0xff: 34426d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 34436d19a5ebSEmmanuel Grumbach break; 34446d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_PSK & 0xff: 34456d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 34466d19a5ebSEmmanuel Grumbach break; 34476d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_8021X & 0xff: 34486d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 34496d19a5ebSEmmanuel Grumbach break; 34506d19a5ebSEmmanuel Grumbach case 0: 34516d19a5ebSEmmanuel Grumbach /* open profile */ 34526d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 34536d19a5ebSEmmanuel Grumbach break; 34546d19a5ebSEmmanuel Grumbach default: 34556d19a5ebSEmmanuel Grumbach /* auth method / AKM not supported */ 34566d19a5ebSEmmanuel Grumbach /* TODO: All the FT vesions of these? */ 34576d19a5ebSEmmanuel Grumbach return; 34586d19a5ebSEmmanuel Grumbach } 34596d19a5ebSEmmanuel Grumbach 3460f276e20bSJohannes Berg memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 34616d19a5ebSEmmanuel Grumbach memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 34626d19a5ebSEmmanuel Grumbach 34636d19a5ebSEmmanuel Grumbach /* TODO: add support for collocated AP data */ 34646d19a5ebSEmmanuel Grumbach iwl_mei_host_associated(&conn_info, NULL); 34656d19a5ebSEmmanuel Grumbach #endif 34666d19a5ebSEmmanuel Grumbach } 34676d19a5ebSEmmanuel Grumbach 346887f7e243SMiri Korenblit static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm, 346987f7e243SMiri Korenblit struct ieee80211_vif *vif, 347087f7e243SMiri Korenblit bool force_assoc_off) 347187f7e243SMiri Korenblit { 347287f7e243SMiri Korenblit return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL); 347387f7e243SMiri Korenblit } 347487f7e243SMiri Korenblit 3475e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3476e705c121SKalle Valo struct ieee80211_vif *vif, 3477e705c121SKalle Valo struct ieee80211_sta *sta, 3478e705c121SKalle Valo enum ieee80211_sta_state old_state, 3479e705c121SKalle Valo enum ieee80211_sta_state new_state) 3480e705c121SKalle Valo { 348187f7e243SMiri Korenblit struct iwl_mvm_sta_state_ops callbacks = { 348287f7e243SMiri Korenblit .add_sta = iwl_mvm_add_sta, 348387f7e243SMiri Korenblit .update_sta = iwl_mvm_update_sta, 348487f7e243SMiri Korenblit .rm_sta = iwl_mvm_rm_sta, 348587f7e243SMiri Korenblit .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper, 348687f7e243SMiri Korenblit }; 348787f7e243SMiri Korenblit 348887f7e243SMiri Korenblit return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state, 348987f7e243SMiri Korenblit &callbacks); 349087f7e243SMiri Korenblit } 349187f7e243SMiri Korenblit 349287f7e243SMiri Korenblit /* Common part for MLD and non-MLD modes */ 349387f7e243SMiri Korenblit int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw, 349487f7e243SMiri Korenblit struct ieee80211_vif *vif, 349587f7e243SMiri Korenblit struct ieee80211_sta *sta, 349687f7e243SMiri Korenblit enum ieee80211_sta_state old_state, 349787f7e243SMiri Korenblit enum ieee80211_sta_state new_state, 349887f7e243SMiri Korenblit struct iwl_mvm_sta_state_ops *callbacks) 349987f7e243SMiri Korenblit { 3500e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3501e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 35026ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3503e705c121SKalle Valo int ret; 3504e705c121SKalle Valo 3505e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 3506e705c121SKalle Valo sta->addr, old_state, new_state); 3507e705c121SKalle Valo 3508e705c121SKalle Valo /* this would be a mac80211 bug ... but don't crash */ 3509650cadb7SGregory Greenman if (WARN_ON_ONCE(!mvmvif->deflink.phy_ctxt)) 3510fe56d05eSSara Sharon return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL; 3511e705c121SKalle Valo 351224afba76SLiad Kaufman /* 351324afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 351424afba76SLiad Kaufman * 351524afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 351624afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 351724afba76SLiad Kaufman * the queues. 351824afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 351924afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 352024afba76SLiad Kaufman * of. 352124afba76SLiad Kaufman * 352224afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 352324afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 352424afba76SLiad Kaufman */ 352524afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 3526c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 352724afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 352824afba76SLiad Kaufman 352924afba76SLiad Kaufman /* 353024afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 353124afba76SLiad Kaufman * worker will already remove it if it was on 353224afba76SLiad Kaufman */ 3533f7d6ef33SJohannes Berg 3534f7d6ef33SJohannes Berg /* 3535f7d6ef33SJohannes Berg * Additionally, reset the 40 MHz capability if we disconnected 3536f7d6ef33SJohannes Berg * from the AP now. 3537f7d6ef33SJohannes Berg */ 3538f7d6ef33SJohannes Berg iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 353924afba76SLiad Kaufman } 354024afba76SLiad Kaufman 3541e705c121SKalle Valo mutex_lock(&mvm->mutex); 35426ea29ce5SJohannes Berg /* track whether or not the station is associated */ 3543d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 35446ea29ce5SJohannes Berg 3545e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3546e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3547e705c121SKalle Valo /* 3548e705c121SKalle Valo * Firmware bug - it'll crash if the beacon interval is less 3549e705c121SKalle Valo * than 16. We can't avoid connecting at all, so refuse the 3550e705c121SKalle Valo * station state change, this will cause mac80211 to abandon 3551e705c121SKalle Valo * attempts to connect to this AP, and eventually wpa_s will 3552cdaba917SEmmanuel Grumbach * blocklist the AP... 3553e705c121SKalle Valo */ 3554e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3555e705c121SKalle Valo vif->bss_conf.beacon_int < 16) { 3556e705c121SKalle Valo IWL_ERR(mvm, 3557e705c121SKalle Valo "AP %pM beacon interval is %d, refusing due to firmware bug!\n", 3558e705c121SKalle Valo sta->addr, vif->bss_conf.beacon_int); 3559e705c121SKalle Valo ret = -EINVAL; 3560e705c121SKalle Valo goto out_unlock; 3561e705c121SKalle Valo } 3562e705c121SKalle Valo 356397cc1694SAvraham Stern if (vif->type == NL80211_IFTYPE_STATION) 3564046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 356597cc1694SAvraham Stern 3566e705c121SKalle Valo if (sta->tdls && 3567e705c121SKalle Valo (vif->p2p || 3568e705c121SKalle Valo iwl_mvm_tdls_sta_count(mvm, NULL) == 3569e705c121SKalle Valo IWL_MVM_TDLS_STA_COUNT || 3570e705c121SKalle Valo iwl_mvm_phy_ctx_count(mvm) > 1)) { 3571e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 3572e705c121SKalle Valo ret = -EBUSY; 3573e705c121SKalle Valo goto out_unlock; 3574e705c121SKalle Valo } 3575e705c121SKalle Valo 357687f7e243SMiri Korenblit ret = callbacks->add_sta(mvm, vif, sta); 35771e8f1329SGolan Ben-Ami if (sta->tdls && ret == 0) { 3578e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, true); 35791e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 35801e8f1329SGolan Ben-Ami NL80211_TDLS_SETUP); 35811e8f1329SGolan Ben-Ami } 3582438af969SSara Sharon 35834c51541dSBenjamin Berg sta->deflink.agg.max_rc_amsdu_len = 1; 3584e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3585e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 3586e705c121SKalle Valo /* 3587e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 3588e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 3589e705c121SKalle Valo */ 3590e705c121SKalle Valo mvm->last_ebs_successful = true; 3591e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 3592e705c121SKalle Valo ret = 0; 3593e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3594e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 35958be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 3596046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 35978be30c13SAyala Beker mvmvif->ap_assoc_sta_count++; 359887f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 359987f7e243SMiri Korenblit if (!mvm->mld_api_is_used && 360087f7e243SMiri Korenblit ((vif->bss_conf.he_support && 3601cb63eb43SMiri Korenblit !iwlwifi_mod_params.disable_11ax) || 3602cb63eb43SMiri Korenblit (vif->bss_conf.eht_support && 360387f7e243SMiri Korenblit !iwlwifi_mod_params.disable_11be))) 3604c8ee33e1SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, 3605c8ee33e1SGregory Greenman mvm_sta->deflink.sta_id); 36069394662aSLiad Kaufman } else if (vif->type == NL80211_IFTYPE_STATION) { 3607046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 36084f58121dSIlan Peer 3609650cadb7SGregory Greenman mvmvif->deflink.he_ru_2mhz_block = false; 3610046d2e7cSSriram R if (sta->deflink.he_cap.has_he) 36114f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif); 36124f58121dSIlan Peer 361387f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 361487f7e243SMiri Korenblit 361587f7e243SMiri Korenblit if (mvm->mld_api_is_used) 361687f7e243SMiri Korenblit iwl_mvm_link_changed(mvm, vif, 361787f7e243SMiri Korenblit LINK_CONTEXT_MODIFY_ALL & 361887f7e243SMiri Korenblit ~LINK_CONTEXT_MODIFY_ACTIVE, 361987f7e243SMiri Korenblit true); 36208be30c13SAyala Beker } 3621735a0045SGoodstein, Mordechay 3622650cadb7SGregory Greenman iwl_mvm_rs_rate_init(mvm, sta, 3623650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt->channel->band, 36243baf7528SAvraham Stern false); 362587f7e243SMiri Korenblit ret = callbacks->update_sta(mvm, vif, sta); 3626e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3627e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 362828916a16SEmmanuel Grumbach ret = 0; 3629e705c121SKalle Valo 3630e705c121SKalle Valo /* we don't support TDLS during DCM */ 3631e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 3632e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3633e705c121SKalle Valo 36344634b176SJohannes Berg if (sta->tdls) { 36351e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 36361e8f1329SGolan Ben-Ami NL80211_TDLS_ENABLE_LINK); 36374634b176SJohannes Berg } else { 3638e705c121SKalle Valo /* enable beacon filtering */ 3639e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 36406b7a5aeaSNaftali Goldstein 36418b75858cSJohannes Berg mvmvif->authorized = 1; 36428b75858cSJohannes Berg 364387f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 36446d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 36454634b176SJohannes Berg } 364650f56044SIlan Peer 3647650cadb7SGregory Greenman iwl_mvm_rs_rate_init(mvm, sta, 3648650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt->channel->band, 36493baf7528SAvraham Stern true); 3650e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 3651e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 3652d9e95e35SMordechay Goodstein /* once we move into assoc state, need to update rate scale to 3653d9e95e35SMordechay Goodstein * disable using wide bandwidth 3654d9e95e35SMordechay Goodstein */ 3655650cadb7SGregory Greenman iwl_mvm_rs_rate_init(mvm, sta, 3656650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt->channel->band, 3657d9e95e35SMordechay Goodstein false); 36584634b176SJohannes Berg if (!sta->tdls) { 36598b75858cSJohannes Berg /* 3660f5034bcfSMiri Korenblit * Set this but don't call iwl_mvm_mac_ctxt_changed() 3661f5034bcfSMiri Korenblit * yet to avoid sending high prio again for a little 3662f5034bcfSMiri Korenblit * time. 36638b75858cSJohannes Berg */ 36648b75858cSJohannes Berg mvmvif->authorized = 0; 36658b75858cSJohannes Berg 3666e705c121SKalle Valo /* disable beacon filtering */ 366769e508b4SIlan Peer ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 366869e508b4SIlan Peer WARN_ON(ret && 366969e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 367069e508b4SIlan Peer &mvm->status)); 36714634b176SJohannes Berg } 3672e705c121SKalle Valo ret = 0; 3673e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3674e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 36758be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 36768be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 367787f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 3678d5d8ee52SEmmanuel Grumbach } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3679cf7a7457SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 3680e705c121SKalle Valo ret = 0; 3681e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3682e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3683e705c121SKalle Valo ret = 0; 3684e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3685e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 3686d5d8ee52SEmmanuel Grumbach if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3687d5d8ee52SEmmanuel Grumbach iwl_mvm_stop_session_protection(mvm, vif); 368887f7e243SMiri Korenblit ret = callbacks->rm_sta(mvm, vif, sta); 36891e8f1329SGolan Ben-Ami if (sta->tdls) { 3690e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 36911e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 36921e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 36931e8f1329SGolan Ben-Ami } 369434a880d8SLiad Kaufman 369544135b7cSIlan Peer if (unlikely(ret && 369644135b7cSIlan Peer test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 369744135b7cSIlan Peer &mvm->status))) 369844135b7cSIlan Peer ret = 0; 3699e705c121SKalle Valo } else { 3700e705c121SKalle Valo ret = -EIO; 3701e705c121SKalle Valo } 3702e705c121SKalle Valo out_unlock: 3703e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3704e705c121SKalle Valo 3705e705c121SKalle Valo if (sta->tdls && ret == 0) { 3706e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3707e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 3708e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3709e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 3710e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 3711e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3712e705c121SKalle Valo } 3713e705c121SKalle Valo 3714e705c121SKalle Valo return ret; 3715e705c121SKalle Valo } 3716e705c121SKalle Valo 3717cbce62a3SMiri Korenblit int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3718e705c121SKalle Valo { 3719e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3720e705c121SKalle Valo 3721e705c121SKalle Valo mvm->rts_threshold = value; 3722e705c121SKalle Valo 3723e705c121SKalle Valo return 0; 3724e705c121SKalle Valo } 3725e705c121SKalle Valo 3726cbce62a3SMiri Korenblit void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3727e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 3728e705c121SKalle Valo { 3729e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3730dcfe3b10SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3731dcfe3b10SJohannes Berg 3732dcfe3b10SJohannes Berg if (changed & (IEEE80211_RC_BW_CHANGED | 3733dcfe3b10SJohannes Berg IEEE80211_RC_SUPP_RATES_CHANGED | 3734dcfe3b10SJohannes Berg IEEE80211_RC_NSS_CHANGED)) 3735650cadb7SGregory Greenman iwl_mvm_rs_rate_init(mvm, sta, 3736650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt->channel->band, 3737dcfe3b10SJohannes Berg true); 3738e705c121SKalle Valo 3739e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3740e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 3741e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 3742e705c121SKalle Valo } 3743e705c121SKalle Valo 3744e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 3745b3e2130bSJohannes Berg struct ieee80211_vif *vif, 3746b3e2130bSJohannes Berg unsigned int link_id, u16 ac, 3747e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 3748e705c121SKalle Valo { 3749e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3750e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3751e705c121SKalle Valo 3752650cadb7SGregory Greenman mvmvif->deflink.queue_params[ac] = *params; 3753e705c121SKalle Valo 3754e705c121SKalle Valo /* 3755e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 3756e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 3757e705c121SKalle Valo */ 3758e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 3759e705c121SKalle Valo int ret; 3760e705c121SKalle Valo 3761e705c121SKalle Valo mutex_lock(&mvm->mutex); 3762e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3763e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3764e705c121SKalle Valo return ret; 3765e705c121SKalle Valo } 3766e705c121SKalle Valo return 0; 3767e705c121SKalle Valo } 3768e705c121SKalle Valo 3769cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 3770d4e36e55SIlan Peer struct ieee80211_vif *vif, 377115fae341SJohannes Berg struct ieee80211_prep_tx_info *info) 3772e705c121SKalle Valo { 3773e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3774d4e36e55SIlan Peer 3775e705c121SKalle Valo mutex_lock(&mvm->mutex); 3776af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, info->duration); 3777e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3778e705c121SKalle Valo } 3779e705c121SKalle Valo 3780cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 37816b1259d1SJohannes Berg struct ieee80211_vif *vif, 37826b1259d1SJohannes Berg struct ieee80211_prep_tx_info *info) 37836b1259d1SJohannes Berg { 37846b1259d1SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 37856b1259d1SJohannes Berg 37866b1259d1SJohannes Berg /* for successful cases (auth/assoc), don't cancel session protection */ 37876b1259d1SJohannes Berg if (info->success) 37886b1259d1SJohannes Berg return; 37896b1259d1SJohannes Berg 37906b1259d1SJohannes Berg mutex_lock(&mvm->mutex); 37916b1259d1SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 37926b1259d1SJohannes Berg mutex_unlock(&mvm->mutex); 37936b1259d1SJohannes Berg } 37946b1259d1SJohannes Berg 3795cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 3796e705c121SKalle Valo struct ieee80211_vif *vif, 3797e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 3798e705c121SKalle Valo struct ieee80211_scan_ies *ies) 3799e705c121SKalle Valo { 3800e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3801e705c121SKalle Valo 3802e705c121SKalle Valo int ret; 3803e705c121SKalle Valo 3804e705c121SKalle Valo mutex_lock(&mvm->mutex); 3805e705c121SKalle Valo 3806f276e20bSJohannes Berg if (!vif->cfg.idle) { 3807e705c121SKalle Valo ret = -EBUSY; 3808e705c121SKalle Valo goto out; 3809e705c121SKalle Valo } 3810e705c121SKalle Valo 3811e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 3812e705c121SKalle Valo 3813e705c121SKalle Valo out: 3814e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3815e705c121SKalle Valo return ret; 3816e705c121SKalle Valo } 3817e705c121SKalle Valo 3818cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 3819e705c121SKalle Valo struct ieee80211_vif *vif) 3820e705c121SKalle Valo { 3821e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3822e705c121SKalle Valo int ret; 3823e705c121SKalle Valo 3824e705c121SKalle Valo mutex_lock(&mvm->mutex); 3825e705c121SKalle Valo 3826e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3827e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 3828e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 3829e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 3830e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 3831e705c121SKalle Valo * could run. To handle this, simply return if the scan is 3832e705c121SKalle Valo * not running. 3833e705c121SKalle Valo */ 3834e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 3835e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3836e705c121SKalle Valo return 0; 3837e705c121SKalle Valo } 3838e705c121SKalle Valo 3839e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 3840e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3841e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 3842e705c121SKalle Valo 3843e705c121SKalle Valo return ret; 3844e705c121SKalle Valo } 3845e705c121SKalle Valo 38466569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 3847e705c121SKalle Valo enum set_key_cmd cmd, 3848e705c121SKalle Valo struct ieee80211_vif *vif, 3849e705c121SKalle Valo struct ieee80211_sta *sta, 3850e705c121SKalle Valo struct ieee80211_key_conf *key) 3851e705c121SKalle Valo { 3852c56e00a3SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3853e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 385446c7b05aSEmmanuel Grumbach struct iwl_mvm_sta *mvmsta = NULL; 3855f5e28eacSJohannes Berg struct iwl_mvm_key_pn *ptk_pn; 3856f5e28eacSJohannes Berg int keyidx = key->keyidx; 38575c75a208SJohannes Berg u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 38585c75a208SJohannes Berg u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 3859c56e00a3SJohannes Berg int ret, i; 38604615fd15SEmmanuel Grumbach u8 key_offset; 3861e705c121SKalle Valo 386246c7b05aSEmmanuel Grumbach if (sta) 38636d19a5ebSEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_mac80211(sta); 38646d19a5ebSEmmanuel Grumbach 3865e705c121SKalle Valo switch (key->cipher) { 3866e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 3867286ca8ebSLuca Coelho if (!mvm->trans->trans_cfg->gen2) { 3868e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 38691ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 38707f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 38717f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 38727f768ad5SDavid Spinadel } else { 38737f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 38747f768ad5SDavid Spinadel return -EOPNOTSUPP; 38757f768ad5SDavid Spinadel } 3876e705c121SKalle Valo break; 3877e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 38782a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 38792a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 388085aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 3881e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3882e705c121SKalle Valo break; 3883e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 38848e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 38858e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3886e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 3887e705c121SKalle Valo break; 3888e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 3889e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 3890475c6bdeSJohannes Berg if (vif->type == NL80211_IFTYPE_STATION) 3891e705c121SKalle Valo break; 3892475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 3893475c6bdeSJohannes Berg return -EOPNOTSUPP; 3894475c6bdeSJohannes Berg /* support HW crypto on TX */ 3895475c6bdeSJohannes Berg return 0; 3896e705c121SKalle Valo default: 3897e705c121SKalle Valo return -EOPNOTSUPP; 3898e705c121SKalle Valo } 3899e705c121SKalle Valo 3900e705c121SKalle Valo switch (cmd) { 3901e705c121SKalle Valo case SET_KEY: 3902a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 3903a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 3904b1fdc250SJohannes Berg rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 3905b1fdc250SJohannes Berg key); 3906b1fdc250SJohannes Berg 3907e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 3908e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 3909e705c121SKalle Valo /* 3910e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 3911e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 3912e705c121SKalle Valo * we don't support them for RX, so do the same. 39138e160ab8SAyala Beker * CMAC/GMAC in AP/IBSS modes must be done in software. 3914a5de7de7SJohannes Berg * 3915a5de7de7SJohannes Berg * Except, of course, beacon protection - it must be 3916a5de7de7SJohannes Berg * offloaded since we just set a beacon template. 3917e705c121SKalle Valo */ 3918a5de7de7SJohannes Berg if (keyidx < 6 && 3919a5de7de7SJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 39208e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 3921a5de7de7SJohannes Berg key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) { 392281279c49SJohannes Berg ret = -EOPNOTSUPP; 3923a1c2ff30SAndrei Otcheretianski break; 3924a1c2ff30SAndrei Otcheretianski } 392585aeb58cSDavid Spinadel 392685aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 392785aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 392885aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 3929e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 3930a1c2ff30SAndrei Otcheretianski ret = 0; 3931e705c121SKalle Valo break; 3932e705c121SKalle Valo } 3933c56e00a3SJohannes Berg 3934c56e00a3SJohannes Berg if (!mvmvif->ap_ibss_active) { 3935c56e00a3SJohannes Berg for (i = 0; 3936c56e00a3SJohannes Berg i < ARRAY_SIZE(mvmvif->ap_early_keys); 3937c56e00a3SJohannes Berg i++) { 3938c56e00a3SJohannes Berg if (!mvmvif->ap_early_keys[i]) { 3939c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = key; 3940c56e00a3SJohannes Berg break; 3941c56e00a3SJohannes Berg } 3942c56e00a3SJohannes Berg } 3943c56e00a3SJohannes Berg 3944c56e00a3SJohannes Berg if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 3945c56e00a3SJohannes Berg ret = -ENOSPC; 3946a1c2ff30SAndrei Otcheretianski else 3947a1c2ff30SAndrei Otcheretianski ret = 0; 3948c56e00a3SJohannes Berg 3949c56e00a3SJohannes Berg break; 3950c56e00a3SJohannes Berg } 395185aeb58cSDavid Spinadel } 3952e705c121SKalle Valo 3953e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 3954e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 3955e705c121SKalle Valo */ 3956e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 3957e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 3958e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 3959e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 3960e705c121SKalle Valo ret = 0; 3961e705c121SKalle Valo break; 3962e705c121SKalle Valo } 3963e705c121SKalle Valo 3964f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 396546c7b05aSEmmanuel Grumbach mvmsta && iwl_mvm_has_new_rx_api(mvm) && 3966f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3967f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 39682a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 39692a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3970f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 3971f5e28eacSJohannes Berg int tid, q; 3972f5e28eacSJohannes Berg 3973f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 3974acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 3975acafe7e3SKees Cook mvm->trans->num_rx_queues), 3976f5e28eacSJohannes Berg GFP_KERNEL); 3977f5e28eacSJohannes Berg if (!ptk_pn) { 3978f5e28eacSJohannes Berg ret = -ENOMEM; 3979f5e28eacSJohannes Berg break; 3980f5e28eacSJohannes Berg } 3981f5e28eacSJohannes Berg 3982f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 3983f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 3984f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 3985f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 3986f5e28eacSJohannes Berg seq.ccmp.pn, 3987f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 3988f5e28eacSJohannes Berg } 3989f5e28eacSJohannes Berg 3990f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 3991f5e28eacSJohannes Berg } 3992f5e28eacSJohannes Berg 39934615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 39944615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 39954615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 39964615fd15SEmmanuel Grumbach else 39974615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 39984615fd15SEmmanuel Grumbach 399946c7b05aSEmmanuel Grumbach if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 40006d19a5ebSEmmanuel Grumbach mvmsta->pairwise_cipher = key->cipher; 40016d19a5ebSEmmanuel Grumbach 4002a5de7de7SJohannes Berg IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n", 4003a5de7de7SJohannes Berg sta ? sta->addr : NULL, key->keyidx); 40045c75a208SJohannes Berg 40055c75a208SJohannes Berg if (sec_key_ver) 40065c75a208SJohannes Berg ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); 40075c75a208SJohannes Berg else 40084615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 40095c75a208SJohannes Berg 4010e705c121SKalle Valo if (ret) { 4011e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 4012475c6bdeSJohannes Berg key->hw_key_idx = STA_KEY_IDX_INVALID; 4013e705c121SKalle Valo /* 4014e705c121SKalle Valo * can't add key for RX, but we don't need it 4015475c6bdeSJohannes Berg * in the device for TX so still return 0, 4016475c6bdeSJohannes Berg * unless we have new TX API where we cannot 4017475c6bdeSJohannes Berg * put key material into the TX_CMD 4018e705c121SKalle Valo */ 4019475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 4020475c6bdeSJohannes Berg ret = -EOPNOTSUPP; 4021475c6bdeSJohannes Berg else 4022e705c121SKalle Valo ret = 0; 4023e705c121SKalle Valo } 4024e705c121SKalle Valo 4025e705c121SKalle Valo break; 4026e705c121SKalle Valo case DISABLE_KEY: 4027a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 4028a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 4029b1fdc250SJohannes Berg RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 4030b1fdc250SJohannes Berg NULL); 4031b1fdc250SJohannes Berg 4032c56e00a3SJohannes Berg ret = -ENOENT; 4033c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 4034c56e00a3SJohannes Berg if (mvmvif->ap_early_keys[i] == key) { 4035c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 4036c56e00a3SJohannes Berg ret = 0; 4037c56e00a3SJohannes Berg } 4038c56e00a3SJohannes Berg } 4039c56e00a3SJohannes Berg 4040c56e00a3SJohannes Berg /* found in pending list - don't do anything else */ 4041c56e00a3SJohannes Berg if (ret == 0) 4042c56e00a3SJohannes Berg break; 4043c56e00a3SJohannes Berg 4044e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 4045e705c121SKalle Valo ret = 0; 4046e705c121SKalle Valo break; 4047e705c121SKalle Valo } 4048e705c121SKalle Valo 404946c7b05aSEmmanuel Grumbach if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4050f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4051f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 40522a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 40532a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4054f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 4055f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 4056f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 4057f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4058f5e28eacSJohannes Berg if (ptk_pn) 4059f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 4060f5e28eacSJohannes Berg } 4061f5e28eacSJohannes Berg 4062e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 40635c75a208SJohannes Berg if (sec_key_ver) 40645c75a208SJohannes Berg ret = iwl_mvm_sec_key_del(mvm, vif, sta, key); 40655c75a208SJohannes Berg else 4066e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 4067e705c121SKalle Valo break; 4068e705c121SKalle Valo default: 4069e705c121SKalle Valo ret = -EINVAL; 4070e705c121SKalle Valo } 4071e705c121SKalle Valo 40726569e7d3SJohannes Berg return ret; 40736569e7d3SJohannes Berg } 40746569e7d3SJohannes Berg 4075cbce62a3SMiri Korenblit int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4076cbce62a3SMiri Korenblit struct ieee80211_vif *vif, struct ieee80211_sta *sta, 40776569e7d3SJohannes Berg struct ieee80211_key_conf *key) 40786569e7d3SJohannes Berg { 40796569e7d3SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 40806569e7d3SJohannes Berg int ret; 40816569e7d3SJohannes Berg 40826569e7d3SJohannes Berg mutex_lock(&mvm->mutex); 40836569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 4084e705c121SKalle Valo mutex_unlock(&mvm->mutex); 40856569e7d3SJohannes Berg 4086e705c121SKalle Valo return ret; 4087e705c121SKalle Valo } 4088e705c121SKalle Valo 4089cbce62a3SMiri Korenblit void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 4090e705c121SKalle Valo struct ieee80211_vif *vif, 4091e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 4092e705c121SKalle Valo struct ieee80211_sta *sta, 4093e705c121SKalle Valo u32 iv32, u16 *phase1key) 4094e705c121SKalle Valo { 4095e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4096e705c121SKalle Valo 4097e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 4098e705c121SKalle Valo return; 4099e705c121SKalle Valo 4100e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 4101e705c121SKalle Valo } 4102e705c121SKalle Valo 4103e705c121SKalle Valo 4104e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 4105e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 4106e705c121SKalle Valo { 4107e705c121SKalle Valo struct iwl_mvm *mvm = 4108e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 4109e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 4110e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 4111e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 4112e705c121SKalle Valo 4113e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 4114e705c121SKalle Valo return true; 4115e705c121SKalle Valo 4116e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 4117e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 4118e705c121SKalle Valo return true; 4119e705c121SKalle Valo } 4120e705c121SKalle Valo 4121e705c121SKalle Valo resp = (void *)pkt->data; 4122e705c121SKalle Valo 4123e705c121SKalle Valo IWL_DEBUG_TE(mvm, 4124b71a9c35SColin Ian King "Aux ROC: Received response from ucode: status=%d uid=%d\n", 4125e705c121SKalle Valo resp->status, resp->event_unique_id); 4126e705c121SKalle Valo 4127e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 4128e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 4129e705c121SKalle Valo te_data->uid); 4130e705c121SKalle Valo 4131e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4132e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 4133e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4134e705c121SKalle Valo 4135e705c121SKalle Valo return true; 4136e705c121SKalle Valo } 4137e705c121SKalle Valo 4138dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) 4139dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) 4140dc28e12fSMatti Gottlieb #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) 4141dc28e12fSMatti Gottlieb #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) 4142dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) 4143e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 4144e705c121SKalle Valo struct ieee80211_channel *channel, 4145e705c121SKalle Valo struct ieee80211_vif *vif, 4146e705c121SKalle Valo int duration) 4147e705c121SKalle Valo { 4148afc1e3b4SAvraham Stern int res; 4149e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4150e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 4151e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 4152e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 4153dc28e12fSMatti Gottlieb u32 dtim_interval = vif->bss_conf.dtim_period * 4154dc28e12fSMatti Gottlieb vif->bss_conf.beacon_int; 4155dc28e12fSMatti Gottlieb u32 req_dur, delay; 4156e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 4157e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 4158e705c121SKalle Valo .id_and_color = 4159e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 4160e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 4161e705c121SKalle Valo }; 416257e861d9SDavid Spinadel struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 416357e861d9SDavid Spinadel &aux_roc_req.channel_info); 416457e861d9SDavid Spinadel u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 416557e861d9SDavid Spinadel 416657e861d9SDavid Spinadel /* Set the channel info data */ 416757e861d9SDavid Spinadel iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 41683717f91aSTova Mussai iwl_mvm_phy_band_from_nl80211(channel->band), 41697ac87575SJohannes Berg IWL_PHY_CHANNEL_MODE20, 417057e861d9SDavid Spinadel 0); 417157e861d9SDavid Spinadel 417257e861d9SDavid Spinadel /* Set the time and duration */ 4173afc1e3b4SAvraham Stern tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 4174e705c121SKalle Valo 4175dc28e12fSMatti Gottlieb delay = AUX_ROC_MIN_DELAY; 4176dc28e12fSMatti Gottlieb req_dur = MSEC_TO_TU(duration); 4177dc28e12fSMatti Gottlieb 4178dc28e12fSMatti Gottlieb /* 4179dc28e12fSMatti Gottlieb * If we are associated we want the delay time to be at least one 4180dc28e12fSMatti Gottlieb * dtim interval so that the FW can wait until after the DTIM and 4181dc28e12fSMatti Gottlieb * then start the time event, this will potentially allow us to 4182dc28e12fSMatti Gottlieb * remain off-channel for the max duration. 4183dc28e12fSMatti Gottlieb * Since we want to use almost a whole dtim interval we would also 4184dc28e12fSMatti Gottlieb * like the delay to be for 2-3 dtim intervals, in case there are 4185dc28e12fSMatti Gottlieb * other time events with higher priority. 4186dc28e12fSMatti Gottlieb */ 4187f276e20bSJohannes Berg if (vif->cfg.assoc) { 4188dc28e12fSMatti Gottlieb delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); 4189dc28e12fSMatti Gottlieb /* We cannot remain off-channel longer than the DTIM interval */ 4190dc28e12fSMatti Gottlieb if (dtim_interval <= req_dur) { 4191dc28e12fSMatti Gottlieb req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; 4192dc28e12fSMatti Gottlieb if (req_dur <= AUX_ROC_MIN_DURATION) 4193dc28e12fSMatti Gottlieb req_dur = dtim_interval - 4194dc28e12fSMatti Gottlieb AUX_ROC_MIN_SAFETY_BUFFER; 4195dc28e12fSMatti Gottlieb } 4196dc28e12fSMatti Gottlieb } 4197dc28e12fSMatti Gottlieb 419857e861d9SDavid Spinadel tail->duration = cpu_to_le32(req_dur); 419957e861d9SDavid Spinadel tail->apply_time_max_delay = cpu_to_le32(delay); 4200dc28e12fSMatti Gottlieb 4201dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 4202903b3f9bSEmmanuel Grumbach "ROC: Requesting to remain on channel %u for %ums\n", 4203903b3f9bSEmmanuel Grumbach channel->hw_value, req_dur); 4204903b3f9bSEmmanuel Grumbach IWL_DEBUG_TE(mvm, 4205903b3f9bSEmmanuel Grumbach "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", 4206903b3f9bSEmmanuel Grumbach duration, delay, dtim_interval); 4207903b3f9bSEmmanuel Grumbach 4208e705c121SKalle Valo /* Set the node address */ 420957e861d9SDavid Spinadel memcpy(tail->node_addr, vif->addr, ETH_ALEN); 4210e705c121SKalle Valo 4211e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4212e705c121SKalle Valo 4213e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4214e705c121SKalle Valo 4215e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 4216e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4217e705c121SKalle Valo return -EIO; 4218e705c121SKalle Valo } 4219e705c121SKalle Valo 4220e705c121SKalle Valo te_data->vif = vif; 4221e705c121SKalle Valo te_data->duration = duration; 4222e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 4223e705c121SKalle Valo 4224e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4225e705c121SKalle Valo 4226e705c121SKalle Valo /* 4227e705c121SKalle Valo * Use a notification wait, which really just processes the 4228e705c121SKalle Valo * command response and doesn't wait for anything, in order 4229e705c121SKalle Valo * to be able to process the response and get the UID inside 4230e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 4231e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 4232e705c121SKalle Valo * time another notification (that the time event started) 4233e705c121SKalle Valo * might already be processed unsuccessfully. 4234e705c121SKalle Valo */ 4235e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 4236e705c121SKalle Valo time_event_response, 4237e705c121SKalle Valo ARRAY_SIZE(time_event_response), 4238e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 4239e705c121SKalle Valo 424057e861d9SDavid Spinadel res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 4241e705c121SKalle Valo &aux_roc_req); 4242e705c121SKalle Valo 4243e705c121SKalle Valo if (res) { 4244e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 4245e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 4246e705c121SKalle Valo goto out_clear_te; 4247e705c121SKalle Valo } 4248e705c121SKalle Valo 4249e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 4250e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 4251e705c121SKalle Valo /* should never fail */ 4252e705c121SKalle Valo WARN_ON_ONCE(res); 4253e705c121SKalle Valo 4254e705c121SKalle Valo if (res) { 4255e705c121SKalle Valo out_clear_te: 4256e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4257e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 4258e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4259e705c121SKalle Valo } 4260e705c121SKalle Valo 4261e705c121SKalle Valo return res; 4262e705c121SKalle Valo } 4263e705c121SKalle Valo 4264feebebaeSMiri Korenblit static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id) 4265feebebaeSMiri Korenblit { 4266feebebaeSMiri Korenblit int ret = 0; 4267feebebaeSMiri Korenblit 4268feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4269feebebaeSMiri Korenblit 4270feebebaeSMiri Korenblit if (!fw_has_capa(&mvm->fw->ucode_capa, 4271feebebaeSMiri Korenblit IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 4272feebebaeSMiri Korenblit IWL_ERR(mvm, "hotspot not supported\n"); 4273feebebaeSMiri Korenblit return -EINVAL; 4274feebebaeSMiri Korenblit } 4275feebebaeSMiri Korenblit 4276feebebaeSMiri Korenblit if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) >= 12) { 4277feebebaeSMiri Korenblit ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 4278feebebaeSMiri Korenblit WARN(ret, "Failed to allocate aux station"); 4279feebebaeSMiri Korenblit } 4280feebebaeSMiri Korenblit 4281feebebaeSMiri Korenblit return ret; 4282feebebaeSMiri Korenblit } 4283feebebaeSMiri Korenblit 4284feebebaeSMiri Korenblit static int iwl_mvm_roc_switch_binding(struct iwl_mvm *mvm, 4285feebebaeSMiri Korenblit struct ieee80211_vif *vif, 4286feebebaeSMiri Korenblit struct iwl_mvm_phy_ctxt *new_phy_ctxt) 4287feebebaeSMiri Korenblit { 4288feebebaeSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4289feebebaeSMiri Korenblit int ret = 0; 4290feebebaeSMiri Korenblit 4291feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4292feebebaeSMiri Korenblit 4293feebebaeSMiri Korenblit /* Unbind the P2P_DEVICE from the current PHY context, 4294feebebaeSMiri Korenblit * and if the PHY context is not used remove it. 4295feebebaeSMiri Korenblit */ 4296feebebaeSMiri Korenblit ret = iwl_mvm_binding_remove_vif(mvm, vif); 4297feebebaeSMiri Korenblit if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 4298feebebaeSMiri Korenblit return ret; 4299feebebaeSMiri Korenblit 4300feebebaeSMiri Korenblit iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 4301feebebaeSMiri Korenblit 4302feebebaeSMiri Korenblit /* Bind the P2P_DEVICE to the current PHY Context */ 4303feebebaeSMiri Korenblit mvmvif->deflink.phy_ctxt = new_phy_ctxt; 4304feebebaeSMiri Korenblit 4305feebebaeSMiri Korenblit ret = iwl_mvm_binding_add_vif(mvm, vif); 4306feebebaeSMiri Korenblit WARN(ret, "Failed binding P2P_DEVICE\n"); 4307feebebaeSMiri Korenblit return ret; 4308feebebaeSMiri Korenblit } 4309feebebaeSMiri Korenblit 4310e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 4311e705c121SKalle Valo struct ieee80211_vif *vif, 4312e705c121SKalle Valo struct ieee80211_channel *channel, 4313e705c121SKalle Valo int duration, 4314e705c121SKalle Valo enum ieee80211_roc_type type) 4315e705c121SKalle Valo { 4316fe8b2ad3SMiri Korenblit struct iwl_mvm_roc_ops ops = { 4317fe8b2ad3SMiri Korenblit .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20, 4318fe8b2ad3SMiri Korenblit .switch_phy_ctxt = iwl_mvm_roc_switch_binding, 4319fe8b2ad3SMiri Korenblit }; 4320fe8b2ad3SMiri Korenblit 4321fe8b2ad3SMiri Korenblit return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops); 4322fe8b2ad3SMiri Korenblit } 4323fe8b2ad3SMiri Korenblit 4324fe8b2ad3SMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 4325fe8b2ad3SMiri Korenblit int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4326fe8b2ad3SMiri Korenblit struct ieee80211_channel *channel, int duration, 4327fe8b2ad3SMiri Korenblit enum ieee80211_roc_type type, 4328fe8b2ad3SMiri Korenblit struct iwl_mvm_roc_ops *ops) 4329fe8b2ad3SMiri Korenblit { 4330e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4331e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4332e705c121SKalle Valo struct cfg80211_chan_def chandef; 4333e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 43348835a64fSJohannes Berg bool band_change_removal; 4335e705c121SKalle Valo int ret, i; 4336feebebaeSMiri Korenblit u32 lmac_id; 4337e705c121SKalle Valo 4338e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 4339e705c121SKalle Valo duration, type); 4340e705c121SKalle Valo 43419834781cSJohannes Berg /* 43429834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 43439834781cSJohannes Berg * the work it does can complete and we can accept new frames. 43449834781cSJohannes Berg */ 4345e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 4346e705c121SKalle Valo 4347e705c121SKalle Valo mutex_lock(&mvm->mutex); 4348e705c121SKalle Valo 4349e705c121SKalle Valo switch (vif->type) { 4350e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4351feebebaeSMiri Korenblit lmac_id = iwl_mvm_get_lmac_id(mvm->fw, channel->band); 43522c2c3647SNathan Errera 4353feebebaeSMiri Korenblit /* Use aux roc framework (HS20) */ 4354fe8b2ad3SMiri Korenblit ret = ops->add_aux_sta_for_hs20(mvm, lmac_id); 4355feebebaeSMiri Korenblit if (!ret) 4356e705c121SKalle Valo ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 4357e705c121SKalle Valo vif, duration); 4358e705c121SKalle Valo goto out_unlock; 4359e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 4360e705c121SKalle Valo /* handle below */ 4361e705c121SKalle Valo break; 4362e705c121SKalle Valo default: 4363e705c121SKalle Valo IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); 4364e705c121SKalle Valo ret = -EINVAL; 4365e705c121SKalle Valo goto out_unlock; 4366e705c121SKalle Valo } 4367e705c121SKalle Valo 4368e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 4369e705c121SKalle Valo phy_ctxt = &mvm->phy_ctxts[i]; 4370650cadb7SGregory Greenman if (phy_ctxt->ref == 0 || mvmvif->deflink.phy_ctxt == phy_ctxt) 4371e705c121SKalle Valo continue; 4372e705c121SKalle Valo 4373e705c121SKalle Valo if (phy_ctxt->ref && channel == phy_ctxt->channel) { 4374fe8b2ad3SMiri Korenblit ret = ops->switch_phy_ctxt(mvm, vif, phy_ctxt); 4375feebebaeSMiri Korenblit if (ret) 4376e705c121SKalle Valo goto out_unlock; 4377e705c121SKalle Valo 4378650cadb7SGregory Greenman iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 4379e705c121SKalle Valo goto schedule_time_event; 4380e705c121SKalle Valo } 4381e705c121SKalle Valo } 4382e705c121SKalle Valo 4383e705c121SKalle Valo /* Need to update the PHY context only if the ROC channel changed */ 4384650cadb7SGregory Greenman if (channel == mvmvif->deflink.phy_ctxt->channel) 4385e705c121SKalle Valo goto schedule_time_event; 4386e705c121SKalle Valo 4387e705c121SKalle Valo cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 4388e705c121SKalle Valo 4389e705c121SKalle Valo /* 43908835a64fSJohannes Berg * Check if the remain-on-channel is on a different band and that 43918835a64fSJohannes Berg * requires context removal, see iwl_mvm_phy_ctxt_changed(). If 43928835a64fSJohannes Berg * so, we'll need to release and then re-configure here, since we 43938835a64fSJohannes Berg * must not remove a PHY context that's part of a binding. 4394e705c121SKalle Valo */ 43958835a64fSJohannes Berg band_change_removal = 43968835a64fSJohannes Berg fw_has_capa(&mvm->fw->ucode_capa, 43978835a64fSJohannes Berg IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) && 4398650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt->channel->band != chandef.chan->band; 43998835a64fSJohannes Berg 4400650cadb7SGregory Greenman if (mvmvif->deflink.phy_ctxt->ref == 1 && !band_change_removal) { 44018835a64fSJohannes Berg /* 44028835a64fSJohannes Berg * Change the PHY context configuration as it is currently 44038835a64fSJohannes Berg * referenced only by the P2P Device MAC (and we can modify it) 44048835a64fSJohannes Berg */ 4405650cadb7SGregory Greenman ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->deflink.phy_ctxt, 4406e705c121SKalle Valo &chandef, 1, 1); 4407e705c121SKalle Valo if (ret) 4408e705c121SKalle Valo goto out_unlock; 4409e705c121SKalle Valo } else { 4410e705c121SKalle Valo /* 44118835a64fSJohannes Berg * The PHY context is shared with other MACs (or we're trying to 44128835a64fSJohannes Berg * switch bands), so remove the P2P Device from the binding, 44138835a64fSJohannes Berg * allocate an new PHY context and create a new binding. 4414e705c121SKalle Valo */ 4415e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4416e705c121SKalle Valo if (!phy_ctxt) { 4417e705c121SKalle Valo ret = -ENOSPC; 4418e705c121SKalle Valo goto out_unlock; 4419e705c121SKalle Valo } 4420e705c121SKalle Valo 4421e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, 4422e705c121SKalle Valo 1, 1); 4423e705c121SKalle Valo if (ret) { 4424e705c121SKalle Valo IWL_ERR(mvm, "Failed to change PHY context\n"); 4425e705c121SKalle Valo goto out_unlock; 4426e705c121SKalle Valo } 4427e705c121SKalle Valo 4428fe8b2ad3SMiri Korenblit ret = ops->switch_phy_ctxt(mvm, vif, phy_ctxt); 4429feebebaeSMiri Korenblit if (ret) 4430e705c121SKalle Valo goto out_unlock; 4431e705c121SKalle Valo 4432650cadb7SGregory Greenman iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 4433e705c121SKalle Valo } 4434e705c121SKalle Valo 4435e705c121SKalle Valo schedule_time_event: 4436e705c121SKalle Valo /* Schedule the time events */ 4437e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4438e705c121SKalle Valo 4439e705c121SKalle Valo out_unlock: 4440e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4441e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4442e705c121SKalle Valo return ret; 4443e705c121SKalle Valo } 4444e705c121SKalle Valo 4445fe8b2ad3SMiri Korenblit int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 44465db4c4b9SEmmanuel Grumbach struct ieee80211_vif *vif) 4447e705c121SKalle Valo { 4448e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4449e705c121SKalle Valo 4450e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 4451e705c121SKalle Valo 4452e705c121SKalle Valo mutex_lock(&mvm->mutex); 4453fe959c7bSEmmanuel Grumbach iwl_mvm_stop_roc(mvm, vif); 4454e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4455e705c121SKalle Valo 4456e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4457e705c121SKalle Valo return 0; 4458e705c121SKalle Valo } 4459e705c121SKalle Valo 4460b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data { 4461b73f9a4aSJohannes Berg bool responder; 4462b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx; 4463b73f9a4aSJohannes Berg }; 4464b73f9a4aSJohannes Berg 4465b73f9a4aSJohannes Berg static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4466b73f9a4aSJohannes Berg struct ieee80211_vif *vif) 4467b73f9a4aSJohannes Berg { 4468b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data *data = _data; 4469b73f9a4aSJohannes Berg 4470d0a9123eSJohannes Berg if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && 4471b73f9a4aSJohannes Berg vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4472b73f9a4aSJohannes Berg data->responder = true; 4473b73f9a4aSJohannes Berg } 4474b73f9a4aSJohannes Berg 4475b73f9a4aSJohannes Berg static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4476b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx) 4477b73f9a4aSJohannes Berg { 4478b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data data = { 4479b73f9a4aSJohannes Berg .responder = false, 4480b73f9a4aSJohannes Berg .ctx = ctx, 4481b73f9a4aSJohannes Berg }; 4482b73f9a4aSJohannes Berg 4483b73f9a4aSJohannes Berg ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4484b73f9a4aSJohannes Berg IEEE80211_IFACE_ITER_NORMAL, 4485b73f9a4aSJohannes Berg iwl_mvm_ftm_responder_chanctx_iter, 4486b73f9a4aSJohannes Berg &data); 4487b73f9a4aSJohannes Berg return data.responder; 4488b73f9a4aSJohannes Berg } 4489b73f9a4aSJohannes Berg 4490e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4491e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4492e705c121SKalle Valo { 4493e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4494e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 4495b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4496b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4497e705c121SKalle Valo int ret; 4498e705c121SKalle Valo 4499e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4500e705c121SKalle Valo 4501e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4502e705c121SKalle Valo 4503e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4504e705c121SKalle Valo if (!phy_ctxt) { 4505e705c121SKalle Valo ret = -ENOSPC; 4506e705c121SKalle Valo goto out; 4507e705c121SKalle Valo } 4508e705c121SKalle Valo 4509b73f9a4aSJohannes Berg ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4510e705c121SKalle Valo ctx->rx_chains_static, 4511e705c121SKalle Valo ctx->rx_chains_dynamic); 4512e705c121SKalle Valo if (ret) { 4513e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 4514e705c121SKalle Valo goto out; 4515e705c121SKalle Valo } 4516e705c121SKalle Valo 4517e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); 4518e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 4519e705c121SKalle Valo out: 4520e705c121SKalle Valo return ret; 4521e705c121SKalle Valo } 4522e705c121SKalle Valo 4523cbce62a3SMiri Korenblit int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4524e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4525e705c121SKalle Valo { 4526e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4527e705c121SKalle Valo int ret; 4528e705c121SKalle Valo 4529e705c121SKalle Valo mutex_lock(&mvm->mutex); 4530e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 4531e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4532e705c121SKalle Valo 4533e705c121SKalle Valo return ret; 4534e705c121SKalle Valo } 4535e705c121SKalle Valo 4536e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4537e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4538e705c121SKalle Valo { 4539e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4540e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4541e705c121SKalle Valo 4542e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4543e705c121SKalle Valo 4544e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4545e705c121SKalle Valo } 4546e705c121SKalle Valo 4547cbce62a3SMiri Korenblit void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4548e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4549e705c121SKalle Valo { 4550e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4551e705c121SKalle Valo 4552e705c121SKalle Valo mutex_lock(&mvm->mutex); 4553e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 4554e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4555e705c121SKalle Valo } 4556e705c121SKalle Valo 4557cbce62a3SMiri Korenblit void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4558cbce62a3SMiri Korenblit struct ieee80211_chanctx_conf *ctx, u32 changed) 4559e705c121SKalle Valo { 4560e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4561e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4562e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4563b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4564b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4565e705c121SKalle Valo 4566e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 4567e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4568e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4569e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 4570e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4571e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 4572e705c121SKalle Valo phy_ctxt->ref, changed)) 4573e705c121SKalle Valo return; 4574e705c121SKalle Valo 4575e705c121SKalle Valo mutex_lock(&mvm->mutex); 45767a20bcceSEmmanuel Grumbach 45777a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 45787a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 4579b73f9a4aSJohannes Berg if (phy_ctxt->width == def->width) 45807a20bcceSEmmanuel Grumbach goto out_unlock; 45817a20bcceSEmmanuel Grumbach 45827a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 45837a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 4584b73f9a4aSJohannes Berg def->width <= NL80211_CHAN_WIDTH_20) 45857a20bcceSEmmanuel Grumbach goto out_unlock; 45867a20bcceSEmmanuel Grumbach } 45877a20bcceSEmmanuel Grumbach 4588e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 4589b73f9a4aSJohannes Berg iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4590e705c121SKalle Valo ctx->rx_chains_static, 4591e705c121SKalle Valo ctx->rx_chains_dynamic); 45927a20bcceSEmmanuel Grumbach 45937a20bcceSEmmanuel Grumbach out_unlock: 4594e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4595e705c121SKalle Valo } 4596e705c121SKalle Valo 45978a919a78SMiri Korenblit /* 45988a919a78SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 45998a919a78SMiri Korenblit * 46008a919a78SMiri Korenblit * Returns true if we're done assigning the chanctx 46018a919a78SMiri Korenblit * (either on failure or success) 46028a919a78SMiri Korenblit */ 460350e81437SMiri Korenblit bool __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, 4604e705c121SKalle Valo struct ieee80211_vif *vif, 4605e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 460650e81437SMiri Korenblit bool switching_chanctx, int *ret) 4607e705c121SKalle Valo { 4608e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4609e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4610e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4611e705c121SKalle Valo 4612e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4613e705c121SKalle Valo 4614650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = phy_ctxt; 4615e705c121SKalle Valo 4616e705c121SKalle Valo switch (vif->type) { 4617e705c121SKalle Valo case NL80211_IFTYPE_AP: 4618e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 4619e705c121SKalle Valo if (switching_chanctx) { 4620e705c121SKalle Valo mvmvif->ap_ibss_active = true; 4621e705c121SKalle Valo break; 4622e705c121SKalle Valo } 46235a2abdcaSGustavo A. R. Silva fallthrough; 4624e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4625e705c121SKalle Valo /* 4626e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 4627e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 4628e705c121SKalle Valo */ 46298a919a78SMiri Korenblit *ret = 0; 46308a919a78SMiri Korenblit return true; 4631e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4632e705c121SKalle Valo break; 4633e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4634e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 4635e705c121SKalle Valo mvmvif->ps_disabled = true; 4636e705c121SKalle Valo break; 4637e705c121SKalle Valo default: 46388a919a78SMiri Korenblit *ret = -EINVAL; 46398a919a78SMiri Korenblit return true; 4640e705c121SKalle Valo } 46418a919a78SMiri Korenblit return false; 46428a919a78SMiri Korenblit } 46438a919a78SMiri Korenblit 46448a919a78SMiri Korenblit static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 46458a919a78SMiri Korenblit struct ieee80211_vif *vif, 46468a919a78SMiri Korenblit struct ieee80211_chanctx_conf *ctx, 46478a919a78SMiri Korenblit bool switching_chanctx) 46488a919a78SMiri Korenblit { 46498a919a78SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 46508a919a78SMiri Korenblit int ret; 46518a919a78SMiri Korenblit 46528a919a78SMiri Korenblit if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx, 46538a919a78SMiri Korenblit switching_chanctx, &ret)) 46548a919a78SMiri Korenblit goto out; 4655e705c121SKalle Valo 4656e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4657e705c121SKalle Valo if (ret) 4658e705c121SKalle Valo goto out; 4659e705c121SKalle Valo 4660e705c121SKalle Valo /* 4661e705c121SKalle Valo * Power state must be updated before quotas, 4662e705c121SKalle Valo * otherwise fw will complain. 4663e705c121SKalle Valo */ 4664e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4665e705c121SKalle Valo 4666e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 4667e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 4668e705c121SKalle Valo * will handle quota settings. 4669e705c121SKalle Valo */ 4670e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 4671e705c121SKalle Valo mvmvif->monitor_active = true; 4672e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 4673e705c121SKalle Valo if (ret) 4674e705c121SKalle Valo goto out_remove_binding; 46750e39eb03SChaya Rachel Ivgi 46760e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 46770e39eb03SChaya Rachel Ivgi if (ret) 46780e39eb03SChaya Rachel Ivgi goto out_remove_binding; 46790e39eb03SChaya Rachel Ivgi 4680e705c121SKalle Valo } 4681e705c121SKalle Valo 4682e705c121SKalle Valo /* Handle binding during CSA */ 4683e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 4684e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4685e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4686e705c121SKalle Valo } 4687e705c121SKalle Valo 46888a919a78SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION) { 46898a919a78SMiri Korenblit if (!switching_chanctx) { 46908a919a78SMiri Korenblit mvmvif->csa_bcn_pending = false; 46918a919a78SMiri Korenblit goto out; 46928a919a78SMiri Korenblit } 46938a919a78SMiri Korenblit 469474a10252SSara Sharon mvmvif->csa_bcn_pending = true; 469574a10252SSara Sharon 469674a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 469774a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 469819125cb0SAndrei Otcheretianski u32 duration = 3 * vif->bss_conf.beacon_int; 4699e705c121SKalle Valo 4700e705c121SKalle Valo /* Protect the session to make sure we hear the first 4701e705c121SKalle Valo * beacon on the new channel. 4702e705c121SKalle Valo */ 4703e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 4704e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 4705e705c121SKalle Valo true); 470674a10252SSara Sharon } 4707e705c121SKalle Valo 4708e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4709e705c121SKalle Valo } 4710e705c121SKalle Valo 4711e705c121SKalle Valo goto out; 4712e705c121SKalle Valo 4713e705c121SKalle Valo out_remove_binding: 4714e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4715e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4716e705c121SKalle Valo out: 4717e705c121SKalle Valo if (ret) 4718650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 4719e705c121SKalle Valo return ret; 4720e705c121SKalle Valo } 47218a919a78SMiri Korenblit 4722e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 4723e705c121SKalle Valo struct ieee80211_vif *vif, 4724727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 4725e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4726e705c121SKalle Valo { 4727e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4728e705c121SKalle Valo int ret; 4729e705c121SKalle Valo 4730e705c121SKalle Valo mutex_lock(&mvm->mutex); 4731e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); 4732e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4733e705c121SKalle Valo 4734e705c121SKalle Valo return ret; 4735e705c121SKalle Valo } 4736e705c121SKalle Valo 4737daddfae5SMiri Korenblit /* 4738daddfae5SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 4739daddfae5SMiri Korenblit * 4740daddfae5SMiri Korenblit * Returns if chanctx unassign chanctx is done 4741daddfae5SMiri Korenblit * (either on failure or success) 4742daddfae5SMiri Korenblit */ 47436f71e90eSMiri Korenblit bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, 4744daddfae5SMiri Korenblit struct ieee80211_vif *vif, 4745daddfae5SMiri Korenblit bool switching_chanctx) 4746daddfae5SMiri Korenblit { 4747daddfae5SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4748daddfae5SMiri Korenblit 4749daddfae5SMiri Korenblit lockdep_assert_held(&mvm->mutex); 4750650cadb7SGregory Greenman iwl_mvm_remove_time_event(mvm, mvmvif, 4751650cadb7SGregory Greenman &mvmvif->time_event_data); 4752daddfae5SMiri Korenblit 4753daddfae5SMiri Korenblit switch (vif->type) { 4754daddfae5SMiri Korenblit case NL80211_IFTYPE_ADHOC: 4755daddfae5SMiri Korenblit return true; 4756daddfae5SMiri Korenblit case NL80211_IFTYPE_MONITOR: 4757daddfae5SMiri Korenblit mvmvif->monitor_active = false; 4758daddfae5SMiri Korenblit mvmvif->ps_disabled = false; 4759daddfae5SMiri Korenblit break; 4760daddfae5SMiri Korenblit case NL80211_IFTYPE_AP: 4761daddfae5SMiri Korenblit /* This part is triggered only during CSA */ 4762daddfae5SMiri Korenblit if (!switching_chanctx || !mvmvif->ap_ibss_active) 4763daddfae5SMiri Korenblit return true; 4764daddfae5SMiri Korenblit 4765daddfae5SMiri Korenblit mvmvif->csa_countdown = false; 4766daddfae5SMiri Korenblit 476756f4f12bSMiri Korenblit /* Set CS bit on all the stations */ 476856f4f12bSMiri Korenblit iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 476956f4f12bSMiri Korenblit 4770daddfae5SMiri Korenblit /* Save blocked iface, the timeout is set on the next beacon */ 4771daddfae5SMiri Korenblit rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 4772daddfae5SMiri Korenblit 4773daddfae5SMiri Korenblit mvmvif->ap_ibss_active = false; 4774daddfae5SMiri Korenblit break; 4775daddfae5SMiri Korenblit default: 4776daddfae5SMiri Korenblit break; 4777daddfae5SMiri Korenblit } 4778daddfae5SMiri Korenblit return false; 4779daddfae5SMiri Korenblit } 4780daddfae5SMiri Korenblit 4781e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 4782e705c121SKalle Valo struct ieee80211_vif *vif, 4783e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4784e705c121SKalle Valo bool switching_chanctx) 4785e705c121SKalle Valo { 4786e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4787e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 4788e705c121SKalle Valo 4789daddfae5SMiri Korenblit if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx)) 4790e705c121SKalle Valo goto out; 4791daddfae5SMiri Korenblit 4792daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_MONITOR) 47930e39eb03SChaya Rachel Ivgi iwl_mvm_rm_snif_sta(mvm, vif); 4794e705c121SKalle Valo 4795e705c121SKalle Valo 4796daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) { 4797e705c121SKalle Valo disabled_vif = vif; 479874a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 479974a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 4800e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 4801e705c121SKalle Valo } 4802e705c121SKalle Valo 4803e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 4804e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4805e705c121SKalle Valo 4806e705c121SKalle Valo out: 4807bf544e9aSSara Sharon if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 4808bf544e9aSSara Sharon switching_chanctx) 4809bf544e9aSSara Sharon return; 4810650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 4811e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4812e705c121SKalle Valo } 4813e705c121SKalle Valo 4814e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 4815e705c121SKalle Valo struct ieee80211_vif *vif, 4816727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 4817e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4818e705c121SKalle Valo { 4819e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4820e705c121SKalle Valo 4821e705c121SKalle Valo mutex_lock(&mvm->mutex); 4822e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); 4823e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4824e705c121SKalle Valo } 4825e705c121SKalle Valo 4826e705c121SKalle Valo static int 4827e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 4828660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 4829660eba5aSMiri Korenblit struct iwl_mvm_switch_vif_chanctx_ops *ops) 4830e705c121SKalle Valo { 4831e705c121SKalle Valo int ret; 4832e705c121SKalle Valo 4833e705c121SKalle Valo mutex_lock(&mvm->mutex); 4834660eba5aSMiri Korenblit ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4835e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 4836e705c121SKalle Valo 4837e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 4838e705c121SKalle Valo if (ret) { 4839e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 4840e705c121SKalle Valo goto out_reassign; 4841e705c121SKalle Valo } 4842e705c121SKalle Valo 4843660eba5aSMiri Korenblit ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4844e705c121SKalle Valo true); 4845e705c121SKalle Valo if (ret) { 4846e705c121SKalle Valo IWL_ERR(mvm, 4847e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4848e705c121SKalle Valo goto out_remove; 4849e705c121SKalle Valo } 4850e705c121SKalle Valo 4851e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 4852e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 4853e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4854e705c121SKalle Valo 4855e705c121SKalle Valo goto out; 4856e705c121SKalle Valo 4857e705c121SKalle Valo out_remove: 4858e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 4859e705c121SKalle Valo 4860e705c121SKalle Valo out_reassign: 4861e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 4862e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 4863e705c121SKalle Valo goto out_restart; 4864e705c121SKalle Valo } 4865e705c121SKalle Valo 4866660eba5aSMiri Korenblit if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4867e705c121SKalle Valo true)) { 4868e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4869e705c121SKalle Valo goto out_restart; 4870e705c121SKalle Valo } 4871e705c121SKalle Valo 4872e705c121SKalle Valo goto out; 4873e705c121SKalle Valo 4874e705c121SKalle Valo out_restart: 4875e705c121SKalle Valo /* things keep failing, better restart the hw */ 4876e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4877e705c121SKalle Valo 4878e705c121SKalle Valo out: 4879e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4880e705c121SKalle Valo 4881e705c121SKalle Valo return ret; 4882e705c121SKalle Valo } 4883e705c121SKalle Valo 4884e705c121SKalle Valo static int 4885e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 4886660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 4887660eba5aSMiri Korenblit struct iwl_mvm_switch_vif_chanctx_ops *ops) 4888e705c121SKalle Valo { 4889e705c121SKalle Valo int ret; 4890e705c121SKalle Valo 4891e705c121SKalle Valo mutex_lock(&mvm->mutex); 4892660eba5aSMiri Korenblit ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4893e705c121SKalle Valo 4894660eba5aSMiri Korenblit ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4895e705c121SKalle Valo true); 4896e705c121SKalle Valo if (ret) { 4897e705c121SKalle Valo IWL_ERR(mvm, 4898e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4899e705c121SKalle Valo goto out_reassign; 4900e705c121SKalle Valo } 4901e705c121SKalle Valo 4902e705c121SKalle Valo goto out; 4903e705c121SKalle Valo 4904e705c121SKalle Valo out_reassign: 4905660eba5aSMiri Korenblit if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4906e705c121SKalle Valo true)) { 4907e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4908e705c121SKalle Valo goto out_restart; 4909e705c121SKalle Valo } 4910e705c121SKalle Valo 4911e705c121SKalle Valo goto out; 4912e705c121SKalle Valo 4913e705c121SKalle Valo out_restart: 4914e705c121SKalle Valo /* things keep failing, better restart the hw */ 4915e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4916e705c121SKalle Valo 4917e705c121SKalle Valo out: 4918e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4919e705c121SKalle Valo 4920e705c121SKalle Valo return ret; 4921e705c121SKalle Valo } 4922e705c121SKalle Valo 4923660eba5aSMiri Korenblit /* Execute the common part for both MLD and non-MLD modes */ 4924660eba5aSMiri Korenblit int 4925660eba5aSMiri Korenblit iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw, 4926e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 4927e705c121SKalle Valo int n_vifs, 4928660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode, 4929660eba5aSMiri Korenblit struct iwl_mvm_switch_vif_chanctx_ops *ops) 4930e705c121SKalle Valo { 4931e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4932e705c121SKalle Valo int ret; 4933e705c121SKalle Valo 4934e705c121SKalle Valo /* we only support a single-vif right now */ 4935e705c121SKalle Valo if (n_vifs > 1) 4936e705c121SKalle Valo return -EOPNOTSUPP; 4937e705c121SKalle Valo 4938e705c121SKalle Valo switch (mode) { 4939e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 4940660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops); 4941e705c121SKalle Valo break; 4942e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 4943660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops); 4944e705c121SKalle Valo break; 4945e705c121SKalle Valo default: 4946e705c121SKalle Valo ret = -EOPNOTSUPP; 4947e705c121SKalle Valo break; 4948e705c121SKalle Valo } 4949e705c121SKalle Valo 4950e705c121SKalle Valo return ret; 4951e705c121SKalle Valo } 4952e705c121SKalle Valo 4953660eba5aSMiri Korenblit static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 4954660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 4955660eba5aSMiri Korenblit int n_vifs, 4956660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode) 4957660eba5aSMiri Korenblit { 4958660eba5aSMiri Korenblit struct iwl_mvm_switch_vif_chanctx_ops ops = { 4959660eba5aSMiri Korenblit .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx, 4960660eba5aSMiri Korenblit .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx, 4961660eba5aSMiri Korenblit }; 4962660eba5aSMiri Korenblit 4963660eba5aSMiri Korenblit return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops); 4964660eba5aSMiri Korenblit } 4965660eba5aSMiri Korenblit 4966cbce62a3SMiri Korenblit int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 49672f0282dbSJohannes Berg { 49682f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 49692f0282dbSJohannes Berg 49702f0282dbSJohannes Berg return mvm->ibss_manager; 49712f0282dbSJohannes Berg } 49722f0282dbSJohannes Berg 4973cbce62a3SMiri Korenblit int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 4974e705c121SKalle Valo bool set) 4975e705c121SKalle Valo { 4976e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4977e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 4978e705c121SKalle Valo 4979e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 4980e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 4981e705c121SKalle Valo return -EINVAL; 4982e705c121SKalle Valo } 4983e705c121SKalle Valo 4984*36cf5377SGregory Greenman return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif, 4985*36cf5377SGregory Greenman &mvm_sta->vif->bss_conf); 4986e705c121SKalle Valo } 4987e705c121SKalle Valo 4988e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 4989e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 4990e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 4991e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 4992e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 4993e705c121SKalle Valo }; 4994e705c121SKalle Valo 4995e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 4996e705c121SKalle Valo struct ieee80211_vif *vif, 4997e705c121SKalle Valo void *data, int len) 4998e705c121SKalle Valo { 4999e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 5000e705c121SKalle Valo int err; 5001e705c121SKalle Valo u32 noa_duration; 5002e705c121SKalle Valo 50038cb08174SJohannes Berg err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 50048cb08174SJohannes Berg iwl_mvm_tm_policy, NULL); 5005e705c121SKalle Valo if (err) 5006e705c121SKalle Valo return err; 5007e705c121SKalle Valo 5008e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 5009e705c121SKalle Valo return -EINVAL; 5010e705c121SKalle Valo 5011e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 5012e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 5013e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 5014e705c121SKalle Valo !vif->bss_conf.enable_beacon || 5015e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 5016e705c121SKalle Valo return -EINVAL; 5017e705c121SKalle Valo 5018e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 5019e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 5020e705c121SKalle Valo return -EINVAL; 5021e705c121SKalle Valo 5022e705c121SKalle Valo mvm->noa_duration = noa_duration; 5023e705c121SKalle Valo mvm->noa_vif = vif; 5024e705c121SKalle Valo 502522b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 5026e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 5027e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 5028e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 5029f276e20bSJohannes Berg !vif->cfg.assoc || !vif->bss_conf.dtim_period || 5030e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 5031e705c121SKalle Valo return -EINVAL; 5032e705c121SKalle Valo 5033e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 5034e705c121SKalle Valo return iwl_mvm_enable_beacon_filter(mvm, vif, 0); 5035e705c121SKalle Valo return iwl_mvm_disable_beacon_filter(mvm, vif, 0); 5036e705c121SKalle Valo } 5037e705c121SKalle Valo 5038e705c121SKalle Valo return -EOPNOTSUPP; 5039e705c121SKalle Valo } 5040e705c121SKalle Valo 5041cbce62a3SMiri Korenblit int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 5042e705c121SKalle Valo struct ieee80211_vif *vif, 5043e705c121SKalle Valo void *data, int len) 5044e705c121SKalle Valo { 5045e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5046e705c121SKalle Valo int err; 5047e705c121SKalle Valo 5048e705c121SKalle Valo mutex_lock(&mvm->mutex); 5049e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 5050e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5051e705c121SKalle Valo 5052e705c121SKalle Valo return err; 5053e705c121SKalle Valo } 5054e705c121SKalle Valo #endif 5055e705c121SKalle Valo 5056cbce62a3SMiri Korenblit void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5057e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5058e705c121SKalle Valo { 5059e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 5060e705c121SKalle Valo * starting its own channel switch timer, so that we can call 5061e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 5062e705c121SKalle Valo * (which is when the absence time event starts). 5063e705c121SKalle Valo */ 5064e705c121SKalle Valo 5065e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 5066e705c121SKalle Valo "dummy channel switch op\n"); 5067e705c121SKalle Valo } 5068e705c121SKalle Valo 506974a10252SSara Sharon static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 507074a10252SSara Sharon struct ieee80211_vif *vif, 507174a10252SSara Sharon struct ieee80211_channel_switch *chsw) 507274a10252SSara Sharon { 507374a10252SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 507474a10252SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 507574a10252SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 507674a10252SSara Sharon mvmvif->color)), 507774a10252SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 507874a10252SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 507974a10252SSara Sharon .cs_count = chsw->count, 508077738865SSara Sharon .cs_mode = chsw->block_tx, 508174a10252SSara Sharon }; 508274a10252SSara Sharon 508374a10252SSara Sharon lockdep_assert_held(&mvm->mutex); 508474a10252SSara Sharon 50859cfcf71cSSara Sharon if (chsw->delay) 50869cfcf71cSSara Sharon cmd.cs_delayed_bcn_count = 50879cfcf71cSSara Sharon DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 50889cfcf71cSSara Sharon 508974a10252SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 509074a10252SSara Sharon WIDE_ID(MAC_CONF_GROUP, 509174a10252SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 509274a10252SSara Sharon 0, sizeof(cmd), &cmd); 509374a10252SSara Sharon } 509474a10252SSara Sharon 50950202bcf0SEmmanuel Grumbach static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 50960202bcf0SEmmanuel Grumbach struct ieee80211_vif *vif, 50970202bcf0SEmmanuel Grumbach struct ieee80211_channel_switch *chsw) 50980202bcf0SEmmanuel Grumbach { 50990202bcf0SEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 51000202bcf0SEmmanuel Grumbach u32 apply_time; 51010202bcf0SEmmanuel Grumbach 51020202bcf0SEmmanuel Grumbach /* Schedule the time event to a bit before beacon 1, 51030202bcf0SEmmanuel Grumbach * to make sure we're in the new channel when the 51040202bcf0SEmmanuel Grumbach * GO/AP arrives. In case count <= 1 immediately schedule the 51050202bcf0SEmmanuel Grumbach * TE (this might result with some packet loss or connection 51060202bcf0SEmmanuel Grumbach * loss). 51070202bcf0SEmmanuel Grumbach */ 51080202bcf0SEmmanuel Grumbach if (chsw->count <= 1) 51090202bcf0SEmmanuel Grumbach apply_time = 0; 51100202bcf0SEmmanuel Grumbach else 51110202bcf0SEmmanuel Grumbach apply_time = chsw->device_timestamp + 51120202bcf0SEmmanuel Grumbach ((vif->bss_conf.beacon_int * (chsw->count - 1) - 51130202bcf0SEmmanuel Grumbach IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 51140202bcf0SEmmanuel Grumbach 51150202bcf0SEmmanuel Grumbach if (chsw->block_tx) 51160202bcf0SEmmanuel Grumbach iwl_mvm_csa_client_absent(mvm, vif); 51170202bcf0SEmmanuel Grumbach 51180202bcf0SEmmanuel Grumbach if (mvmvif->bf_data.bf_enabled) { 51190202bcf0SEmmanuel Grumbach int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 51200202bcf0SEmmanuel Grumbach 51210202bcf0SEmmanuel Grumbach if (ret) 51220202bcf0SEmmanuel Grumbach return ret; 51230202bcf0SEmmanuel Grumbach } 51240202bcf0SEmmanuel Grumbach 51250202bcf0SEmmanuel Grumbach iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 51260202bcf0SEmmanuel Grumbach apply_time); 51270202bcf0SEmmanuel Grumbach 51280202bcf0SEmmanuel Grumbach return 0; 51290202bcf0SEmmanuel Grumbach } 51300202bcf0SEmmanuel Grumbach 5131f6780614SSara Sharon #define IWL_MAX_CSA_BLOCK_TX 1500 5132cbce62a3SMiri Korenblit int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 5133e705c121SKalle Valo struct ieee80211_vif *vif, 5134e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5135e705c121SKalle Valo { 5136e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5137e705c121SKalle Valo struct ieee80211_vif *csa_vif; 5138e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5139e705c121SKalle Valo int ret; 5140e705c121SKalle Valo 5141e705c121SKalle Valo mutex_lock(&mvm->mutex); 5142e705c121SKalle Valo 5143e705c121SKalle Valo mvmvif->csa_failed = false; 5144e705c121SKalle Valo 5145e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 5146e705c121SKalle Valo chsw->chandef.center_freq1); 5147e705c121SKalle Valo 51487174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 51497174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 51507174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 5151e705c121SKalle Valo 5152e705c121SKalle Valo switch (vif->type) { 5153e705c121SKalle Valo case NL80211_IFTYPE_AP: 5154e705c121SKalle Valo csa_vif = 5155e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 5156e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5157d0a9123eSJohannes Berg if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, 5158e705c121SKalle Valo "Another CSA is already in progress")) { 5159e705c121SKalle Valo ret = -EBUSY; 5160e705c121SKalle Valo goto out_unlock; 5161e705c121SKalle Valo } 5162e705c121SKalle Valo 5163d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 5164d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 5165d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 5166d3a108a4SAndrei Otcheretianski ret = -EBUSY; 5167d3a108a4SAndrei Otcheretianski goto out_unlock; 5168d3a108a4SAndrei Otcheretianski } 5169d3a108a4SAndrei Otcheretianski 5170e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 5171e705c121SKalle Valo 5172e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 5173e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 5174e705c121SKalle Valo ret = -EBUSY; 5175e705c121SKalle Valo goto out_unlock; 5176e705c121SKalle Valo } 5177e705c121SKalle Valo 5178d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 5179d3a108a4SAndrei Otcheretianski 5180e705c121SKalle Valo break; 5181e705c121SKalle Valo case NL80211_IFTYPE_STATION: 51822360acbdSEmmanuel Grumbach /* 5183ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there 5184ad12b231SNathan Errera * is no need for all of this 5185ad12b231SNathan Errera */ 5186ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5187ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 5188ad12b231SNathan Errera 0)) 5189ad12b231SNathan Errera break; 5190ad12b231SNathan Errera 5191ad12b231SNathan Errera /* 51922360acbdSEmmanuel Grumbach * We haven't configured the firmware to be associated yet since 51932360acbdSEmmanuel Grumbach * we don't know the dtim period. In this case, the firmware can't 51942360acbdSEmmanuel Grumbach * track the beacons. 51952360acbdSEmmanuel Grumbach */ 5196f276e20bSJohannes Berg if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) { 51972360acbdSEmmanuel Grumbach ret = -EBUSY; 51982360acbdSEmmanuel Grumbach goto out_unlock; 51992360acbdSEmmanuel Grumbach } 52002360acbdSEmmanuel Grumbach 520187d9564eSJohannes Berg if (chsw->delay > IWL_MAX_CSA_BLOCK_TX) 520287d9564eSJohannes Berg schedule_delayed_work(&mvmvif->csa_work, 0); 520387d9564eSJohannes Berg 5204f6780614SSara Sharon if (chsw->block_tx) { 5205f6780614SSara Sharon /* 5206f6780614SSara Sharon * In case of undetermined / long time with immediate 5207f6780614SSara Sharon * quiet monitor status to gracefully disconnect 5208f6780614SSara Sharon */ 5209f6780614SSara Sharon if (!chsw->count || 5210f6780614SSara Sharon chsw->count * vif->bss_conf.beacon_int > 5211f6780614SSara Sharon IWL_MAX_CSA_BLOCK_TX) 5212f6780614SSara Sharon schedule_delayed_work(&mvmvif->csa_work, 5213f6780614SSara Sharon msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 5214f6780614SSara Sharon } 5215e705c121SKalle Valo 52160202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 52170202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 52180202bcf0SEmmanuel Grumbach ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 5219e705c121SKalle Valo if (ret) 5220e705c121SKalle Valo goto out_unlock; 52210202bcf0SEmmanuel Grumbach } else { 522274a10252SSara Sharon iwl_mvm_schedule_client_csa(mvm, vif, chsw); 52230202bcf0SEmmanuel Grumbach } 522481b4e44eSSara Sharon 522581b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 522681b4e44eSSara Sharon mvmvif->csa_misbehave = false; 5227e705c121SKalle Valo break; 5228e705c121SKalle Valo default: 5229e705c121SKalle Valo break; 5230e705c121SKalle Valo } 5231e705c121SKalle Valo 5232e705c121SKalle Valo mvmvif->ps_disabled = true; 5233e705c121SKalle Valo 5234e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 5235e705c121SKalle Valo if (ret) 5236e705c121SKalle Valo goto out_unlock; 5237e705c121SKalle Valo 5238e705c121SKalle Valo /* we won't be on this channel any longer */ 5239e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 5240e705c121SKalle Valo 5241e705c121SKalle Valo out_unlock: 5242e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5243e705c121SKalle Valo 5244e705c121SKalle Valo return ret; 5245e705c121SKalle Valo } 5246e705c121SKalle Valo 5247cbce62a3SMiri Korenblit void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 5248c37763d2SSara Sharon struct ieee80211_vif *vif, 5249c37763d2SSara Sharon struct ieee80211_channel_switch *chsw) 5250e705c121SKalle Valo { 5251e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5252c37763d2SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5253c37763d2SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 5254c37763d2SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 5255c37763d2SSara Sharon mvmvif->color)), 5256c37763d2SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 5257c37763d2SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 5258c37763d2SSara Sharon .cs_count = chsw->count, 525977738865SSara Sharon .cs_mode = chsw->block_tx, 5260c37763d2SSara Sharon }; 5261e705c121SKalle Valo 5262ad12b231SNathan Errera /* 5263ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there is no 5264ad12b231SNathan Errera * need for all of this 5265ad12b231SNathan Errera */ 5266ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5267ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 5268ad12b231SNathan Errera return; 5269ad12b231SNathan Errera 5270c37763d2SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 5271c37763d2SSara Sharon return; 5272e705c121SKalle Valo 5273c3eae059SGregory Greenman IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 5274c3eae059SGregory Greenman mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 5275c3eae059SGregory Greenman 527681b4e44eSSara Sharon if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 527781b4e44eSSara Sharon if (mvmvif->csa_misbehave) { 527881b4e44eSSara Sharon /* Second time, give up on this AP*/ 527981b4e44eSSara Sharon iwl_mvm_abort_channel_switch(hw, vif); 528081b4e44eSSara Sharon ieee80211_chswitch_done(vif, false); 528181b4e44eSSara Sharon mvmvif->csa_misbehave = false; 528281b4e44eSSara Sharon return; 5283e705c121SKalle Valo } 528481b4e44eSSara Sharon mvmvif->csa_misbehave = true; 5285e705c121SKalle Valo } 528681b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 5287e705c121SKalle Valo 5288caf46377SSara Sharon mutex_lock(&mvm->mutex); 5289caf46377SSara Sharon if (mvmvif->csa_failed) 5290caf46377SSara Sharon goto out_unlock; 5291e705c121SKalle Valo 5292c37763d2SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 5293c37763d2SSara Sharon WIDE_ID(MAC_CONF_GROUP, 5294c37763d2SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 5295caf46377SSara Sharon 0, sizeof(cmd), &cmd)); 5296caf46377SSara Sharon out_unlock: 5297caf46377SSara Sharon mutex_unlock(&mvm->mutex); 5298e705c121SKalle Valo } 5299e705c121SKalle Valo 53006110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 53016110d9e5SDavid Spinadel { 5302435d0827SSara Sharon int i; 5303435d0827SSara Sharon 530406195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 5305309c4848SLuca Coelho if (drop) { 5306309c4848SLuca Coelho mutex_lock(&mvm->mutex); 53076110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 5308d4e3a341SMordechay Goodstein iwl_mvm_flushable_queues(mvm) & queues); 5309309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 5310309c4848SLuca Coelho } else { 5311435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 5312309c4848SLuca Coelho } 5313435d0827SSara Sharon return; 5314435d0827SSara Sharon } 53156110d9e5SDavid Spinadel 53166110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 5317be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5318435d0827SSara Sharon struct ieee80211_sta *sta; 5319435d0827SSara Sharon 5320435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 53216110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 53226110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 53236110d9e5SDavid Spinadel continue; 53246110d9e5SDavid Spinadel 532506195639SSara Sharon if (drop) 5326d4e3a341SMordechay Goodstein iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 532706195639SSara Sharon else 53286110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 53296110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 53306110d9e5SDavid Spinadel } 53316110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 53326110d9e5SDavid Spinadel } 53336110d9e5SDavid Spinadel 5334cbce62a3SMiri Korenblit void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5335cbce62a3SMiri Korenblit u32 queues, bool drop) 5336e705c121SKalle Valo { 5337e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5338e705c121SKalle Valo struct iwl_mvm_vif *mvmvif; 5339e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 5340e705c121SKalle Valo struct ieee80211_sta *sta; 5341e705c121SKalle Valo int i; 5342e705c121SKalle Valo u32 msk = 0; 5343e705c121SKalle Valo 53446110d9e5SDavid Spinadel if (!vif) { 53456110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 53466110d9e5SDavid Spinadel return; 53476110d9e5SDavid Spinadel } 53486110d9e5SDavid Spinadel 53496110d9e5SDavid Spinadel if (vif->type != NL80211_IFTYPE_STATION) 5350e705c121SKalle Valo return; 5351e705c121SKalle Valo 535224afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 535324afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 535424afba76SLiad Kaufman 5355e705c121SKalle Valo mutex_lock(&mvm->mutex); 5356e705c121SKalle Valo mvmvif = iwl_mvm_vif_from_mac80211(vif); 5357e705c121SKalle Valo 5358e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 5359be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5360e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 5361e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5362e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 5363e705c121SKalle Valo continue; 5364e705c121SKalle Valo 5365e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 5366e705c121SKalle Valo if (mvmsta->vif != vif) 5367e705c121SKalle Valo continue; 5368e705c121SKalle Valo 5369e705c121SKalle Valo /* make sure only TDLS peers or the AP are flushed */ 5370650cadb7SGregory Greenman WARN_ON(i != mvmvif->deflink.ap_sta_id && !sta->tdls); 5371e705c121SKalle Valo 5372d49394a1SSara Sharon if (drop) { 5373f9084775SNathan Errera if (iwl_mvm_flush_sta(mvm, mvmsta, false)) 5374d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 5375d49394a1SSara Sharon } else { 5376d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 5377d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 5378f7bd883bSJohannes Berg else /* only used for !iwl_mvm_has_new_tx_api() below */ 5379f7bd883bSJohannes Berg msk |= mvmsta->tfd_queue_msk; 5380e705c121SKalle Valo } 5381d49394a1SSara Sharon } 5382e705c121SKalle Valo 5383e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5384e705c121SKalle Valo 5385e705c121SKalle Valo /* this can take a while, and we may need/want other operations 5386e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 5387e705c121SKalle Valo */ 5388d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 5389a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 5390e705c121SKalle Valo } 5391e705c121SKalle Valo 5392cbce62a3SMiri Korenblit int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 5393e705c121SKalle Valo struct survey_info *survey) 5394e705c121SKalle Valo { 5395e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5396e705c121SKalle Valo int ret; 5397e705c121SKalle Valo 5398e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 5399e705c121SKalle Valo 5400e705c121SKalle Valo /* only support global statistics right now */ 5401e705c121SKalle Valo if (idx != 0) 5402e705c121SKalle Valo return -ENOENT; 5403e705c121SKalle Valo 5404280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 5405e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 5406e705c121SKalle Valo return -ENOENT; 5407e705c121SKalle Valo 5408e705c121SKalle Valo mutex_lock(&mvm->mutex); 5409e705c121SKalle Valo 5410aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 5411e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 5412e705c121SKalle Valo if (ret) 5413e705c121SKalle Valo goto out; 5414e705c121SKalle Valo } 5415e705c121SKalle Valo 5416e705c121SKalle Valo survey->filled = SURVEY_INFO_TIME | 5417e705c121SKalle Valo SURVEY_INFO_TIME_RX | 5418e705c121SKalle Valo SURVEY_INFO_TIME_TX | 5419e705c121SKalle Valo SURVEY_INFO_TIME_SCAN; 5420e705c121SKalle Valo survey->time = mvm->accu_radio_stats.on_time_rf + 5421e705c121SKalle Valo mvm->radio_stats.on_time_rf; 5422e705c121SKalle Valo do_div(survey->time, USEC_PER_MSEC); 5423e705c121SKalle Valo 5424e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 5425e705c121SKalle Valo mvm->radio_stats.rx_time; 5426e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 5427e705c121SKalle Valo 5428e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 5429e705c121SKalle Valo mvm->radio_stats.tx_time; 5430e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 5431e705c121SKalle Valo 5432e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 5433e705c121SKalle Valo mvm->radio_stats.on_time_scan; 5434e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 5435e705c121SKalle Valo 5436e705c121SKalle Valo ret = 0; 5437e705c121SKalle Valo out: 5438e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5439e705c121SKalle Valo return ret; 5440e705c121SKalle Valo } 5441e705c121SKalle Valo 5442ed780545SJohannes Berg static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 5443ed780545SJohannes Berg { 544482cdbd11SMiri Korenblit u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 54457138763eSJohannes Berg u32 gi_ltf; 544682cdbd11SMiri Korenblit 544782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 5448ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_20: 5449ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_20; 5450ed780545SJohannes Berg break; 5451ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_40: 5452ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_40; 5453ed780545SJohannes Berg break; 5454ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_80: 5455ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_80; 5456ed780545SJohannes Berg break; 5457ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_160: 5458ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_160; 5459ed780545SJohannes Berg break; 546023dcee94SJohannes Berg case RATE_MCS_CHAN_WIDTH_320: 546123dcee94SJohannes Berg rinfo->bw = RATE_INFO_BW_320; 546223dcee94SJohannes Berg break; 5463ed780545SJohannes Berg } 5464ed780545SJohannes Berg 546582cdbd11SMiri Korenblit if (format == RATE_MCS_CCK_MSK || 546682cdbd11SMiri Korenblit format == RATE_MCS_LEGACY_OFDM_MSK) { 546782cdbd11SMiri Korenblit int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 546882cdbd11SMiri Korenblit 546982cdbd11SMiri Korenblit /* add the offset needed to get to the legacy ofdm indices */ 547082cdbd11SMiri Korenblit if (format == RATE_MCS_LEGACY_OFDM_MSK) 547182cdbd11SMiri Korenblit rate += IWL_FIRST_OFDM_RATE; 547282cdbd11SMiri Korenblit 547382cdbd11SMiri Korenblit switch (rate) { 547482cdbd11SMiri Korenblit case IWL_RATE_1M_INDEX: 547582cdbd11SMiri Korenblit rinfo->legacy = 10; 547682cdbd11SMiri Korenblit break; 547782cdbd11SMiri Korenblit case IWL_RATE_2M_INDEX: 547882cdbd11SMiri Korenblit rinfo->legacy = 20; 547982cdbd11SMiri Korenblit break; 548082cdbd11SMiri Korenblit case IWL_RATE_5M_INDEX: 548182cdbd11SMiri Korenblit rinfo->legacy = 55; 548282cdbd11SMiri Korenblit break; 548382cdbd11SMiri Korenblit case IWL_RATE_11M_INDEX: 548482cdbd11SMiri Korenblit rinfo->legacy = 110; 548582cdbd11SMiri Korenblit break; 548682cdbd11SMiri Korenblit case IWL_RATE_6M_INDEX: 548782cdbd11SMiri Korenblit rinfo->legacy = 60; 548882cdbd11SMiri Korenblit break; 548982cdbd11SMiri Korenblit case IWL_RATE_9M_INDEX: 549082cdbd11SMiri Korenblit rinfo->legacy = 90; 549182cdbd11SMiri Korenblit break; 549282cdbd11SMiri Korenblit case IWL_RATE_12M_INDEX: 549382cdbd11SMiri Korenblit rinfo->legacy = 120; 549482cdbd11SMiri Korenblit break; 549582cdbd11SMiri Korenblit case IWL_RATE_18M_INDEX: 549682cdbd11SMiri Korenblit rinfo->legacy = 180; 549782cdbd11SMiri Korenblit break; 549882cdbd11SMiri Korenblit case IWL_RATE_24M_INDEX: 549982cdbd11SMiri Korenblit rinfo->legacy = 240; 550082cdbd11SMiri Korenblit break; 550182cdbd11SMiri Korenblit case IWL_RATE_36M_INDEX: 550282cdbd11SMiri Korenblit rinfo->legacy = 360; 550382cdbd11SMiri Korenblit break; 550482cdbd11SMiri Korenblit case IWL_RATE_48M_INDEX: 550582cdbd11SMiri Korenblit rinfo->legacy = 480; 550682cdbd11SMiri Korenblit break; 550782cdbd11SMiri Korenblit case IWL_RATE_54M_INDEX: 550882cdbd11SMiri Korenblit rinfo->legacy = 540; 550982cdbd11SMiri Korenblit } 551082cdbd11SMiri Korenblit return; 551182cdbd11SMiri Korenblit } 551282cdbd11SMiri Korenblit 5513ed780545SJohannes Berg rinfo->nss = u32_get_bits(rate_n_flags, 551482cdbd11SMiri Korenblit RATE_MCS_NSS_MSK) + 1; 551582cdbd11SMiri Korenblit rinfo->mcs = format == RATE_MCS_HT_MSK ? 551682cdbd11SMiri Korenblit RATE_HT_MCS_INDEX(rate_n_flags) : 551782cdbd11SMiri Korenblit u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 551882cdbd11SMiri Korenblit 55197138763eSJohannes Berg if (rate_n_flags & RATE_MCS_SGI_MSK) 55207138763eSJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 55217138763eSJohannes Berg 55227138763eSJohannes Berg switch (format) { 552323dcee94SJohannes Berg case RATE_MCS_EHT_MSK: 552423dcee94SJohannes Berg /* TODO: GI/LTF/RU. How does the firmware encode them? */ 552523dcee94SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; 552623dcee94SJohannes Berg break; 55277138763eSJohannes Berg case RATE_MCS_HE_MSK: 55287138763eSJohannes Berg gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK); 5529ed780545SJohannes Berg 5530ed780545SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 5531ed780545SJohannes Berg 553282cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 5533ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_HE_RU; 5534ed780545SJohannes Berg rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 5535ed780545SJohannes Berg } 5536ed780545SJohannes Berg 553782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 553882cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_SU: 553982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_EXT_SU: 5540ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5541ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5542ed780545SJohannes Berg else if (gi_ltf == 2) 5543ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 554482cdbd11SMiri Korenblit else if (gi_ltf == 3) 5545ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 554682cdbd11SMiri Korenblit else 554782cdbd11SMiri Korenblit rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5548ed780545SJohannes Berg break; 554982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_MU: 5550ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5551ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5552ed780545SJohannes Berg else if (gi_ltf == 2) 5553ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5554ed780545SJohannes Berg else 5555ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5556ed780545SJohannes Berg break; 555782cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_TRIG: 5558ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5559ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5560ed780545SJohannes Berg else 5561ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5562ed780545SJohannes Berg break; 5563ed780545SJohannes Berg } 5564ed780545SJohannes Berg 5565ed780545SJohannes Berg if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 5566ed780545SJohannes Berg rinfo->he_dcm = 1; 55677138763eSJohannes Berg break; 55687138763eSJohannes Berg case RATE_MCS_HT_MSK: 556982cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_MCS; 55707138763eSJohannes Berg break; 55717138763eSJohannes Berg case RATE_MCS_VHT_MSK: 557282cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 55737138763eSJohannes Berg break; 5574ed780545SJohannes Berg } 5575ed780545SJohannes Berg } 5576ed780545SJohannes Berg 5577cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 5578e705c121SKalle Valo struct ieee80211_vif *vif, 5579e705c121SKalle Valo struct ieee80211_sta *sta, 5580e705c121SKalle Valo struct station_info *sinfo) 5581e705c121SKalle Valo { 5582e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5583e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5584e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5585e705c121SKalle Valo 5586c8ee33e1SGregory Greenman if (mvmsta->deflink.avg_energy) { 5587c8ee33e1SGregory Greenman sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy; 558822d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 5589988b5968SSara Sharon } 5590988b5968SSara Sharon 5591ed780545SJohannes Berg if (iwl_mvm_has_tlc_offload(mvm)) { 5592c8ee33e1SGregory Greenman struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw; 5593ed780545SJohannes Berg 5594ed780545SJohannes Berg iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 5595ed780545SJohannes Berg sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 5596ed780545SJohannes Berg } 5597ed780545SJohannes Berg 5598e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 5599e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 5600e705c121SKalle Valo return; 5601e705c121SKalle Valo 5602f276e20bSJohannes Berg if (!vif->cfg.assoc) 5603e705c121SKalle Valo return; 5604e705c121SKalle Valo 5605e705c121SKalle Valo mutex_lock(&mvm->mutex); 5606e705c121SKalle Valo 5607c8ee33e1SGregory Greenman if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id) 5608e705c121SKalle Valo goto unlock; 5609e705c121SKalle Valo 5610e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 5611e705c121SKalle Valo goto unlock; 5612e705c121SKalle Valo 5613650cadb7SGregory Greenman sinfo->rx_beacon = mvmvif->deflink.beacon_stats.num_beacons + 5614650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.accu_num_beacons; 561522d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 5616650cadb7SGregory Greenman if (mvmvif->deflink.beacon_stats.avg_signal) { 5617e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 5618650cadb7SGregory Greenman sinfo->rx_beacon_signal_avg = 5619650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.avg_signal; 562022d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 5621e705c121SKalle Valo } 5622e705c121SKalle Valo unlock: 5623e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5624e705c121SKalle Valo } 5625e705c121SKalle Valo 5626119c2a13SMordechay Goodstein static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 5627119c2a13SMordechay Goodstein struct ieee80211_vif *vif, 5628119c2a13SMordechay Goodstein const struct ieee80211_mlme_event *mlme) 5629119c2a13SMordechay Goodstein { 56301a81bddfSMordechay Goodstein if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 56311a81bddfSMordechay Goodstein (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 5632119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5633119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 5634119c2a13SMordechay Goodstein NULL); 5635119c2a13SMordechay Goodstein return; 5636119c2a13SMordechay Goodstein } 5637119c2a13SMordechay Goodstein 5638119c2a13SMordechay Goodstein if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 5639119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5640119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_DEASSOC, 5641119c2a13SMordechay Goodstein NULL); 5642119c2a13SMordechay Goodstein return; 5643119c2a13SMordechay Goodstein } 5644119c2a13SMordechay Goodstein } 5645119c2a13SMordechay Goodstein 5646e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 5647e705c121SKalle Valo struct ieee80211_vif *vif, 5648e705c121SKalle Valo const struct ieee80211_event *event) 5649e705c121SKalle Valo { 56504c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 5651e705c121SKalle Valo do { \ 56524c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 5653e705c121SKalle Valo break; \ 56547174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 5655e705c121SKalle Valo } while (0) 5656e705c121SKalle Valo 5657e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5658e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 5659e705c121SKalle Valo 5660119c2a13SMordechay Goodstein if (iwl_trans_dbg_ini_valid(mvm->trans)) { 5661119c2a13SMordechay Goodstein iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 5662119c2a13SMordechay Goodstein return; 5663119c2a13SMordechay Goodstein } 5664119c2a13SMordechay Goodstein 56656c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 56666c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 56676c042d75SSara Sharon if (!trig) 5668e705c121SKalle Valo return; 5669e705c121SKalle Valo 5670e705c121SKalle Valo trig_mlme = (void *)trig->data; 5671e705c121SKalle Valo 5672e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 5673e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 56744c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 5675e705c121SKalle Valo "DENIED ASSOC: reason %d", 5676e705c121SKalle Valo event->u.mlme.reason); 5677e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 56784c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 5679e705c121SKalle Valo "ASSOC TIMEOUT"); 5680e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 5681e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 56824c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 5683e705c121SKalle Valo "DENIED AUTH: reason %d", 5684e705c121SKalle Valo event->u.mlme.reason); 5685e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 56864c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 5687e705c121SKalle Valo "AUTH TIMEOUT"); 5688e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 56894c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 5690e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 5691e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 56924c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 5693e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 5694e705c121SKalle Valo } 5695e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 5696e705c121SKalle Valo } 5697e705c121SKalle Valo 5698e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 5699e705c121SKalle Valo struct ieee80211_vif *vif, 5700e705c121SKalle Valo const struct ieee80211_event *event) 5701e705c121SKalle Valo { 5702e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5703e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 5704e705c121SKalle Valo 57056c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 57066c042d75SSara Sharon FW_DBG_TRIGGER_BA); 57076c042d75SSara Sharon if (!trig) 5708e705c121SKalle Valo return; 5709e705c121SKalle Valo 5710e705c121SKalle Valo ba_trig = (void *)trig->data; 5711e705c121SKalle Valo 5712e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 5713e705c121SKalle Valo return; 5714e705c121SKalle Valo 57157174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 5716e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 5717e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 5718e705c121SKalle Valo event->u.ba.ssn); 5719e705c121SKalle Valo } 5720e705c121SKalle Valo 5721cbce62a3SMiri Korenblit void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 5722e705c121SKalle Valo struct ieee80211_vif *vif, 5723e705c121SKalle Valo const struct ieee80211_event *event) 5724e705c121SKalle Valo { 5725e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5726e705c121SKalle Valo 5727e705c121SKalle Valo switch (event->type) { 5728e705c121SKalle Valo case MLME_EVENT: 5729e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 5730e705c121SKalle Valo break; 5731e705c121SKalle Valo case BAR_RX_EVENT: 5732e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 5733e705c121SKalle Valo break; 5734e705c121SKalle Valo case BA_FRAME_TIMEOUT: 5735528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 5736528a542aSEmmanuel Grumbach event->u.ba.tid); 5737e705c121SKalle Valo break; 5738e705c121SKalle Valo default: 5739e705c121SKalle Valo break; 5740e705c121SKalle Valo } 5741e705c121SKalle Valo } 5742e705c121SKalle Valo 5743d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 57445e1688ceSJohannes Berg enum iwl_mvm_rxq_notif_type type, 57455e1688ceSJohannes Berg bool sync, 57465e1688ceSJohannes Berg const void *data, u32 size) 57470636b938SSara Sharon { 57485e1688ceSJohannes Berg struct { 57495e1688ceSJohannes Berg struct iwl_rxq_sync_cmd cmd; 57505e1688ceSJohannes Berg struct iwl_mvm_internal_rxq_notif notif; 57515e1688ceSJohannes Berg } __packed cmd = { 57525e1688ceSJohannes Berg .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 57535e1688ceSJohannes Berg .cmd.count = 57545e1688ceSJohannes Berg cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 57555e1688ceSJohannes Berg size), 57565e1688ceSJohannes Berg .notif.type = type, 57575e1688ceSJohannes Berg .notif.sync = sync, 57585e1688ceSJohannes Berg }; 57595e1688ceSJohannes Berg struct iwl_host_cmd hcmd = { 57605e1688ceSJohannes Berg .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 57615e1688ceSJohannes Berg .data[0] = &cmd, 57625e1688ceSJohannes Berg .len[0] = sizeof(cmd), 57635e1688ceSJohannes Berg .data[1] = data, 57645e1688ceSJohannes Berg .len[1] = size, 57655e1688ceSJohannes Berg .flags = sync ? 0 : CMD_ASYNC, 57665e1688ceSJohannes Berg }; 57670636b938SSara Sharon int ret; 57680636b938SSara Sharon 57695e1688ceSJohannes Berg /* size must be a multiple of DWORD */ 57705e1688ceSJohannes Berg if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 57715e1688ceSJohannes Berg return; 57720636b938SSara Sharon 5773cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 57740636b938SSara Sharon return; 57750636b938SSara Sharon 57765e1688ceSJohannes Berg if (sync) { 57775e1688ceSJohannes Berg cmd.notif.cookie = mvm->queue_sync_cookie; 57782f7a04c7SJohannes Berg mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 5779a2113cc4SNaftali Goldstein } 5780d0ff5d22SSara Sharon 57815e1688ceSJohannes Berg ret = iwl_mvm_send_cmd(mvm, &hcmd); 57820636b938SSara Sharon if (ret) { 57830636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 57840636b938SSara Sharon goto out; 57850636b938SSara Sharon } 5786d0ff5d22SSara Sharon 57875e1688ceSJohannes Berg if (sync) { 57883c514bf8SEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 57893a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 57902f7a04c7SJohannes Berg READ_ONCE(mvm->queue_sync_state) == 0 || 57916ad04359SJohannes Berg iwl_mvm_is_radio_killed(mvm), 57920636b938SSara Sharon HZ); 57932f7a04c7SJohannes Berg WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm), 57942f7a04c7SJohannes Berg "queue sync: failed to sync, state is 0x%lx\n", 57952f7a04c7SJohannes Berg mvm->queue_sync_state); 57966ad04359SJohannes Berg } 57970636b938SSara Sharon 57980636b938SSara Sharon out: 57995e1688ceSJohannes Berg if (sync) { 58002f7a04c7SJohannes Berg mvm->queue_sync_state = 0; 58010636b938SSara Sharon mvm->queue_sync_cookie++; 58020636b938SSara Sharon } 58035f8a3561SJohannes Berg } 58040636b938SSara Sharon 5805cbce62a3SMiri Korenblit void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 58060636b938SSara Sharon { 58070636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 58080636b938SSara Sharon 58090636b938SSara Sharon mutex_lock(&mvm->mutex); 58105e1688ceSJohannes Berg iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 58110636b938SSara Sharon mutex_unlock(&mvm->mutex); 58120636b938SSara Sharon } 58130636b938SSara Sharon 5814cbce62a3SMiri Korenblit int 5815b73f9a4aSJohannes Berg iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 5816b73f9a4aSJohannes Berg struct ieee80211_vif *vif, 5817b73f9a4aSJohannes Berg struct cfg80211_ftm_responder_stats *stats) 5818b73f9a4aSJohannes Berg { 5819b73f9a4aSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5820b73f9a4aSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5821b73f9a4aSJohannes Berg 5822b73f9a4aSJohannes Berg if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 5823b73f9a4aSJohannes Berg !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 5824b73f9a4aSJohannes Berg return -EINVAL; 5825b73f9a4aSJohannes Berg 5826b73f9a4aSJohannes Berg mutex_lock(&mvm->mutex); 5827b73f9a4aSJohannes Berg *stats = mvm->ftm_resp_stats; 5828b73f9a4aSJohannes Berg mutex_unlock(&mvm->mutex); 5829b73f9a4aSJohannes Berg 5830b73f9a4aSJohannes Berg stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 5831b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 5832b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_FAILED_NUM) | 5833b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_ASAP_NUM) | 5834b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 5835b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 5836b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 5837b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 5838b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 5839b73f9a4aSJohannes Berg 5840b73f9a4aSJohannes Berg return 0; 5841b73f9a4aSJohannes Berg } 5842b73f9a4aSJohannes Berg 5843cbce62a3SMiri Korenblit int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5844fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5845fc36ffdaSJohannes Berg { 5846fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5847fc36ffdaSJohannes Berg int ret; 5848fc36ffdaSJohannes Berg 5849fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5850fc36ffdaSJohannes Berg ret = iwl_mvm_ftm_start(mvm, vif, request); 5851fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5852fc36ffdaSJohannes Berg 5853fc36ffdaSJohannes Berg return ret; 5854fc36ffdaSJohannes Berg } 5855fc36ffdaSJohannes Berg 5856cbce62a3SMiri Korenblit void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5857fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5858fc36ffdaSJohannes Berg { 5859fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5860fc36ffdaSJohannes Berg 5861fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5862fc36ffdaSJohannes Berg iwl_mvm_ftm_abort(mvm, request); 5863fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5864fc36ffdaSJohannes Berg } 5865fc36ffdaSJohannes Berg 5866438af969SSara Sharon static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 5867438af969SSara Sharon { 5868438af969SSara Sharon u8 protocol = ip_hdr(skb)->protocol; 5869438af969SSara Sharon 5870438af969SSara Sharon if (!IS_ENABLED(CONFIG_INET)) 5871438af969SSara Sharon return false; 5872438af969SSara Sharon 5873438af969SSara Sharon return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 5874438af969SSara Sharon } 5875438af969SSara Sharon 5876438af969SSara Sharon static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 5877438af969SSara Sharon struct sk_buff *head, 5878438af969SSara Sharon struct sk_buff *skb) 5879438af969SSara Sharon { 5880438af969SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5881438af969SSara Sharon 58820792df68SJohannes Berg if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) 58830792df68SJohannes Berg return iwl_mvm_tx_csum_bz(mvm, head, true) == 58840792df68SJohannes Berg iwl_mvm_tx_csum_bz(mvm, skb, true); 58850792df68SJohannes Berg 5886438af969SSara Sharon /* For now don't aggregate IPv6 in AMSDU */ 5887438af969SSara Sharon if (skb->protocol != htons(ETH_P_IP)) 5888438af969SSara Sharon return false; 5889438af969SSara Sharon 5890438af969SSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) 5891438af969SSara Sharon return true; 5892438af969SSara Sharon 5893438af969SSara Sharon return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 5894438af969SSara Sharon } 5895438af969SSara Sharon 5896cf85123aSAvraham Stern static int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw, 5897cf85123aSAvraham Stern struct ieee80211_vif *vif, 5898cf85123aSAvraham Stern struct cfg80211_set_hw_timestamp *hwts) 5899cf85123aSAvraham Stern { 5900cf85123aSAvraham Stern struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5901cf85123aSAvraham Stern u32 protocols = 0; 5902cf85123aSAvraham Stern int ret; 5903cf85123aSAvraham Stern 5904cf85123aSAvraham Stern /* HW timestamping is only supported for a specific station */ 5905cf85123aSAvraham Stern if (!hwts->macaddr) 5906cf85123aSAvraham Stern return -EOPNOTSUPP; 5907cf85123aSAvraham Stern 5908cf85123aSAvraham Stern if (hwts->enable) 5909cf85123aSAvraham Stern protocols = 5910cf85123aSAvraham Stern IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM; 5911cf85123aSAvraham Stern 5912cf85123aSAvraham Stern mutex_lock(&mvm->mutex); 5913cf85123aSAvraham Stern ret = iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols); 5914cf85123aSAvraham Stern mutex_unlock(&mvm->mutex); 5915cf85123aSAvraham Stern 5916cf85123aSAvraham Stern return ret; 5917cf85123aSAvraham Stern } 5918cf85123aSAvraham Stern 5919e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 5920e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 5921cfbc6c4cSSara Sharon .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 5922e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 5923e8503aecSBen Greear .get_antenna = iwl_mvm_op_get_antenna, 5924e705c121SKalle Valo .start = iwl_mvm_mac_start, 5925e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 5926e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 5927e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 5928e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 5929e705c121SKalle Valo .config = iwl_mvm_mac_config, 5930e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 5931e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 5932e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 5933e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 5934e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 5935e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 5936e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 5937e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 5938e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 5939e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 5940e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 5941e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 5942e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 5943e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 5944e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 59456b1259d1SJohannes Berg .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 5946e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 5947e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 5948e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 5949e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 5950e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 5951e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 5952e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 5953e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 5954e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 5955e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 5956e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 5957e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 5958e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 5959e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 5960e705c121SKalle Valo 5961ae7ba17bSShaul Triebitz .start_ap = iwl_mvm_start_ap, 5962ae7ba17bSShaul Triebitz .stop_ap = iwl_mvm_stop_ap, 5963ae7ba17bSShaul Triebitz .join_ibss = iwl_mvm_start_ibss, 5964ae7ba17bSShaul Triebitz .leave_ibss = iwl_mvm_stop_ibss, 5965e705c121SKalle Valo 59662f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 59672f0282dbSJohannes Berg 5968e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 5969e705c121SKalle Valo 5970e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 5971e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 5972e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 597379221126SSara Sharon .abort_channel_switch = iwl_mvm_abort_channel_switch, 5974c37763d2SSara Sharon .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 5975e705c121SKalle Valo 5976e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 5977e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 5978e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 5979e705c121SKalle Valo 5980e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 5981e705c121SKalle Valo 59820636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 59830636b938SSara Sharon 5984e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 5985e705c121SKalle Valo 5986e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 5987e705c121SKalle Valo /* look at d3.c */ 5988e705c121SKalle Valo .suspend = iwl_mvm_suspend, 5989e705c121SKalle Valo .resume = iwl_mvm_resume, 5990e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 5991e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 5992e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 5993e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 5994e705c121SKalle Valo #endif 5995e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 5996e705c121SKalle Valo #endif 5997e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 5998e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 5999b73f9a4aSJohannes Berg .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 6000fc36ffdaSJohannes Berg .start_pmsr = iwl_mvm_start_pmsr, 6001fc36ffdaSJohannes Berg .abort_pmsr = iwl_mvm_abort_pmsr, 6002b73f9a4aSJohannes Berg 6003438af969SSara Sharon .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 6004177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 6005177a11cfSGregory Greenman .sta_add_debugfs = iwl_mvm_sta_add_debugfs, 6006177a11cfSGregory Greenman #endif 6007cf85123aSAvraham Stern .set_hw_timestamp = iwl_mvm_set_hw_timestamp, 6008e705c121SKalle Valo }; 6009