18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28e99ea8dSJohannes Berg /* 3f4eedfd8SJohannes Berg * Copyright (C) 2012-2014, 2018-2024 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); 111e9b63341SAbhishek Naik struct iwl_mcc_update_resp_v8 *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), 1410d2fc882SMukesh Sisodiya le32_to_cpu(resp->cap), resp_ver, 1420d2fc882SMukesh Sisodiya mvm->fwrt.uats_enabled); 143e705c121SKalle Valo /* Store the return source id */ 144e705c121SKalle Valo src_id = resp->source_id; 145e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 146e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 147e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 148e705c121SKalle Valo goto out; 149e705c121SKalle Valo } 150e705c121SKalle Valo 151e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 152e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 153e705c121SKalle Valo mvm->lar_regdom_set = true; 154e705c121SKalle Valo mvm->mcc_src = src_id; 155e705c121SKalle Valo 156ea5cca78SJohannes Berg /* Some kind of regulatory mess means we need to currently disallow 157ea5cca78SJohannes Berg * puncturing in the US and Canada. Do that here, at least until we 158ea5cca78SJohannes Berg * figure out the new chanctx APIs for puncturing. 159ea5cca78SJohannes Berg */ 160ea5cca78SJohannes Berg if (resp->mcc == cpu_to_le16(IWL_MCC_US) || 161ea5cca78SJohannes Berg resp->mcc == cpu_to_le16(IWL_MCC_CANADA)) 162ea5cca78SJohannes Berg ieee80211_hw_set(mvm->hw, DISALLOW_PUNCTURING); 163ea5cca78SJohannes Berg else 164ea5cca78SJohannes Berg __clear_bit(IEEE80211_HW_DISALLOW_PUNCTURING, mvm->hw->flags); 165ea5cca78SJohannes Berg 1666d19a5ebSEmmanuel Grumbach iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); 1676d19a5ebSEmmanuel Grumbach 168e705c121SKalle Valo out: 1696d19a5ebSEmmanuel Grumbach kfree(resp); 170e705c121SKalle Valo return regd; 171e705c121SKalle Valo } 172e705c121SKalle Valo 173e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 174e705c121SKalle Valo { 175e705c121SKalle Valo bool changed; 176e705c121SKalle Valo struct ieee80211_regdomain *regd; 177e705c121SKalle Valo 178e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 179e705c121SKalle Valo return; 180e705c121SKalle Valo 181e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 182e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 183e705c121SKalle Valo /* only update the regulatory core if changed */ 184e705c121SKalle Valo if (changed) 185e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 186e705c121SKalle Valo 187e705c121SKalle Valo kfree(regd); 188e705c121SKalle Valo } 189e705c121SKalle Valo } 190e705c121SKalle Valo 191e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 192e705c121SKalle Valo bool *changed) 193e705c121SKalle Valo { 194e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 195e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 196e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 197e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 198e705c121SKalle Valo } 199e705c121SKalle Valo 200ea02a208SGregory Greenman int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm, bool force_regd_sync) 201e705c121SKalle Valo { 202e705c121SKalle Valo enum iwl_mcc_source used_src; 203e705c121SKalle Valo struct ieee80211_regdomain *regd; 204e705c121SKalle Valo int ret; 205e705c121SKalle Valo bool changed; 206e705c121SKalle Valo const struct ieee80211_regdomain *r = 207a05829a7SJohannes Berg wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); 208e705c121SKalle Valo 209e705c121SKalle Valo if (!r) 210e705c121SKalle Valo return -ENOENT; 211e705c121SKalle Valo 212e705c121SKalle Valo /* save the last source in case we overwrite it below */ 213e705c121SKalle Valo used_src = mvm->mcc_src; 214e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 215e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 216e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 217e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 218e705c121SKalle Valo kfree(regd); 219e705c121SKalle Valo } 220e705c121SKalle Valo 221e705c121SKalle Valo /* Now set our last stored MCC and source */ 222e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 223e705c121SKalle Valo &changed); 224e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 225e705c121SKalle Valo return -EIO; 226e705c121SKalle Valo 227ea02a208SGregory Greenman /* update cfg80211 if the regdomain was changed or the caller explicitly 228ea02a208SGregory Greenman * asked to update regdomain 229ea02a208SGregory Greenman */ 230ea02a208SGregory Greenman if (changed || force_regd_sync) 231a05829a7SJohannes Berg ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); 232e705c121SKalle Valo else 233e705c121SKalle Valo ret = 0; 234e705c121SKalle Valo 235e705c121SKalle Valo kfree(regd); 236e705c121SKalle Valo return ret; 237e705c121SKalle Valo } 238e705c121SKalle Valo 2398e33f046SKrishnanand Prabhu /* Each capability added here should also be add to tm_if_types_ext_capa_sta */ 2407f2ea521SYueHaibing static const u8 he_if_types_ext_capa_sta[] = { 2417360f99eSEmmanuel Grumbach [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 242918cbf39SSara Sharon [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 243784d4a42SJohannes Berg [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | 244784d4a42SJohannes Berg WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, 245784d4a42SJohannes Berg [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, 2467360f99eSEmmanuel Grumbach }; 2477360f99eSEmmanuel Grumbach 2488e33f046SKrishnanand Prabhu static const u8 tm_if_types_ext_capa_sta[] = { 2498e33f046SKrishnanand Prabhu [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 2508e33f046SKrishnanand Prabhu [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT | 2518e33f046SKrishnanand Prabhu WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT, 252784d4a42SJohannes Berg [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | 253784d4a42SJohannes Berg WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, 254784d4a42SJohannes Berg [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, 2558e33f046SKrishnanand Prabhu [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, 2568e33f046SKrishnanand Prabhu }; 2578e33f046SKrishnanand Prabhu 2588e33f046SKrishnanand Prabhu /* Additional interface types for which extended capabilities are 2598e33f046SKrishnanand Prabhu * specified separately 2608e33f046SKrishnanand Prabhu */ 2616107f300SEmmanuel Grumbach 2626107f300SEmmanuel Grumbach #define IWL_MVM_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \ 2636107f300SEmmanuel Grumbach IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \ 2646107f300SEmmanuel Grumbach __bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \ 2656107f300SEmmanuel Grumbach IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \ 2666107f300SEmmanuel Grumbach __bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY)) 26780018499SAyala Beker #define IWL_MVM_MLD_CAPA_OPS FIELD_PREP_CONST( \ 26880018499SAyala Beker IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \ 26980018499SAyala Beker IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) 2706107f300SEmmanuel Grumbach 2718e33f046SKrishnanand Prabhu static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = { 2727360f99eSEmmanuel Grumbach { 2737360f99eSEmmanuel Grumbach .iftype = NL80211_IFTYPE_STATION, 2747360f99eSEmmanuel Grumbach .extended_capabilities = he_if_types_ext_capa_sta, 2757360f99eSEmmanuel Grumbach .extended_capabilities_mask = he_if_types_ext_capa_sta, 2767360f99eSEmmanuel Grumbach .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), 2776107f300SEmmanuel Grumbach /* relevant only if EHT is supported */ 2786107f300SEmmanuel Grumbach .eml_capabilities = IWL_MVM_EMLSR_CAPA, 27980018499SAyala Beker .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS, 2807360f99eSEmmanuel Grumbach }, 2818e33f046SKrishnanand Prabhu { 2828e33f046SKrishnanand Prabhu .iftype = NL80211_IFTYPE_STATION, 2838e33f046SKrishnanand Prabhu .extended_capabilities = tm_if_types_ext_capa_sta, 2848e33f046SKrishnanand Prabhu .extended_capabilities_mask = tm_if_types_ext_capa_sta, 2858e33f046SKrishnanand Prabhu .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta), 2868e33f046SKrishnanand Prabhu /* relevant only if EHT is supported */ 2876107f300SEmmanuel Grumbach .eml_capabilities = IWL_MVM_EMLSR_CAPA, 28880018499SAyala Beker .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS, 2898e33f046SKrishnanand Prabhu }, 2907360f99eSEmmanuel Grumbach }; 2917360f99eSEmmanuel Grumbach 292cbce62a3SMiri Korenblit int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 293e8503aecSBen Greear { 294e8503aecSBen Greear struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 295e8503aecSBen Greear *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); 296e8503aecSBen Greear *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); 297e8503aecSBen Greear return 0; 298e8503aecSBen Greear } 299e8503aecSBen Greear 3004ea1ed1dSEmmanuel Grumbach int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant) 3014ea1ed1dSEmmanuel Grumbach { 3024ea1ed1dSEmmanuel Grumbach struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3034ea1ed1dSEmmanuel Grumbach 3044ea1ed1dSEmmanuel Grumbach /* This has been tested on those devices only */ 3054ea1ed1dSEmmanuel Grumbach if (mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_9000 && 3064ea1ed1dSEmmanuel Grumbach mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_22000) 30796850912SAndrei Otcheretianski return -EOPNOTSUPP; 3084ea1ed1dSEmmanuel Grumbach 3094ea1ed1dSEmmanuel Grumbach if (!mvm->nvm_data) 3104ea1ed1dSEmmanuel Grumbach return -EBUSY; 3114ea1ed1dSEmmanuel Grumbach 3124ea1ed1dSEmmanuel Grumbach /* mac80211 ensures the device is not started, 3134ea1ed1dSEmmanuel Grumbach * so the firmware cannot be running 3144ea1ed1dSEmmanuel Grumbach */ 3154ea1ed1dSEmmanuel Grumbach 3164ea1ed1dSEmmanuel Grumbach mvm->set_tx_ant = tx_ant; 3174ea1ed1dSEmmanuel Grumbach mvm->set_rx_ant = rx_ant; 3184ea1ed1dSEmmanuel Grumbach 3194ea1ed1dSEmmanuel Grumbach iwl_reinit_cab(mvm->trans, mvm->nvm_data, tx_ant, rx_ant, mvm->fw); 3204ea1ed1dSEmmanuel Grumbach 3214ea1ed1dSEmmanuel Grumbach return 0; 3224ea1ed1dSEmmanuel Grumbach } 3234ea1ed1dSEmmanuel Grumbach 324e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 325e705c121SKalle Valo { 326e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 327e705c121SKalle Valo int num_mac, ret, i; 328e705c121SKalle Valo static const u32 mvm_ciphers[] = { 329e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 330e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 331e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 332e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 333e705c121SKalle Valo }; 3343f37c229SIdo Yariv #ifdef CONFIG_PM_SLEEP 3353f37c229SIdo Yariv bool unified = fw_has_capa(&mvm->fw->ucode_capa, 3363f37c229SIdo Yariv IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); 3373f37c229SIdo Yariv #endif 338a5de7de7SJohannes Berg u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 339a5de7de7SJohannes Berg u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 340e705c121SKalle Valo 341e705c121SKalle Valo /* Tell mac80211 our characteristics */ 342e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 343e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 344e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 345e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 346e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 347e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 348e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 349e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 350e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 351e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 352e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 353909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 35430433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 355520229e4SShaul Triebitz ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 356cfbc6c4cSSara Sharon ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); 357cfbc6c4cSSara Sharon ieee80211_hw_set(hw, STA_MMPDU_TXQ); 358ef2b47b8SJohannes Berg 3590120e6b3SGregory Greenman /* Set this early since we need to have it for the check below */ 360b3366330SJohannes Berg if (mvm->mld_api_is_used && mvm->nvm_data->sku_cap_11be_enable && 361b3366330SJohannes Berg !iwlwifi_mod_params.disable_11ax && 362bbd6d0f8SJohannes Berg !iwlwifi_mod_params.disable_11be) { 3630120e6b3SGregory Greenman hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; 364bbd6d0f8SJohannes Berg /* we handle this already earlier, but need it for MLO */ 365bbd6d0f8SJohannes Berg ieee80211_hw_set(hw, HANDLES_QUIET_CSA); 366bbd6d0f8SJohannes Berg } 3670120e6b3SGregory Greenman 368ef2b47b8SJohannes Berg /* With MLD FW API, it tracks timing by itself, 369ef2b47b8SJohannes Berg * no need for any timing from the host 370ef2b47b8SJohannes Berg */ 371ef2b47b8SJohannes Berg if (!mvm->mld_api_is_used) 372ef2b47b8SJohannes Berg ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 373ef2b47b8SJohannes Berg 374ef2b47b8SJohannes Berg /* We should probably have this, but mac80211 375ef2b47b8SJohannes Berg * currently doesn't support it for MLO. 376ef2b47b8SJohannes Berg */ 377ef2b47b8SJohannes Berg if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) 378ef2b47b8SJohannes Berg ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 379ef2b47b8SJohannes Berg 380cfb21b11SJohannes Berg /* 381cfb21b11SJohannes Berg * On older devices, enabling TX A-MSDU occasionally leads to 382cfb21b11SJohannes Berg * something getting messed up, the command read from the FIFO 383cfb21b11SJohannes Berg * gets out of sync and isn't a TX command, so that we have an 384cfb21b11SJohannes Berg * assert EDC. 385cfb21b11SJohannes Berg * 386cfb21b11SJohannes Berg * It's not clear where the bug is, but since we didn't used to 387cfb21b11SJohannes Berg * support A-MSDU until moving the mac80211 iTXQs, just leave it 388cfb21b11SJohannes Berg * for older devices. We also don't see this issue on any newer 389cfb21b11SJohannes Berg * devices. 390cfb21b11SJohannes Berg */ 3917d34a7d7SLuca Coelho if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) 392438af969SSara Sharon ieee80211_hw_set(hw, TX_AMSDU); 393438af969SSara Sharon ieee80211_hw_set(hw, TX_FRAG_LIST); 394ecaf71deSGregory Greenman 3954243edb4SEmmanuel Grumbach if (iwl_mvm_has_tlc_offload(mvm)) { 396ecaf71deSGregory Greenman ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 397ecaf71deSGregory Greenman ieee80211_hw_set(hw, HAS_RATE_CONTROL); 398ecaf71deSGregory Greenman } 399ecaf71deSGregory Greenman 40029fa9a98SEmmanuel Grumbach /* We want to use the mac80211's reorder buffer for 9000 */ 40129fa9a98SEmmanuel Grumbach if (iwl_mvm_has_new_rx_api(mvm) && 40229fa9a98SEmmanuel Grumbach mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_9000) 403b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 404960f864bSJohannes Berg 405960f864bSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 406960f864bSJohannes Berg IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 40765e25482SJohannes Berg ieee80211_hw_set(hw, AP_LINK_PS); 408960f864bSJohannes Berg } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 409960f864bSJohannes Berg /* 410960f864bSJohannes Berg * we absolutely need this for the new TX API since that comes 411960f864bSJohannes Berg * with many more queues than the current code can deal with 412960f864bSJohannes Berg * for station powersave 413960f864bSJohannes Berg */ 414960f864bSJohannes Berg return -EINVAL; 415960f864bSJohannes Berg } 416e705c121SKalle Valo 41780938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 41880938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 41980938abcSJohannes Berg 4202d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 4212d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 4222d7cf549SJohannes Berg 423366fc672SJohannes Berg hw->queues = IEEE80211_NUM_ACS; 424e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 425e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 426e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 427e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 428e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 429371a17edSJohannes Berg 430371a17edSJohannes Berg hw->radiotap_timestamp.units_pos = 431371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 432371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 433371a17edSJohannes Berg /* this is the case for CCK frames, it's better (only 8) for OFDM */ 434371a17edSJohannes Berg hw->radiotap_timestamp.accuracy = 22; 435371a17edSJohannes Berg 4364243edb4SEmmanuel Grumbach if (!iwl_mvm_has_tlc_offload(mvm)) 4379f66a397SGregory Greenman hw->rate_control_algorithm = RS_NAME; 4389f66a397SGregory Greenman 439e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 440e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 441438af969SSara Sharon hw->max_tx_fragments = mvm->trans->max_skb_frags; 442e705c121SKalle Valo 4438e160ab8SAyala Beker BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 444e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 445e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 446e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 447e705c121SKalle Valo 4482a53d166SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4492a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4502a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP; 4512a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4522a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4532a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP_256; 4542a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4552a53d166SAyala Beker } 4562a53d166SAyala Beker 457f4bfdc5eSEmmanuel Grumbach if (iwlwifi_mod_params.swcrypto) 458f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 459f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); 460f4bfdc5eSEmmanuel Grumbach if (!iwlwifi_mod_params.bt_coex_active) 461f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 462f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); 463f4bfdc5eSEmmanuel Grumbach 464e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 465f4bfdc5eSEmmanuel Grumbach mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; 466e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 4678e160ab8SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4688e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4698e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_128; 4708e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4718e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4728e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_256; 4738e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4748e160ab8SAyala Beker } 475e705c121SKalle Valo 476ef2e7a51SIlan Peer wiphy_ext_feature_set(hw->wiphy, 477ef2e7a51SIlan Peer NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); 478d16b96b5SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 479d16b96b5SJohannes Berg NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT); 480ef2e7a51SIlan Peer 481b73f9a4aSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 482fc36ffdaSJohannes Berg IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { 483b73f9a4aSJohannes Berg wiphy_ext_feature_set(hw->wiphy, 484b73f9a4aSJohannes Berg NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); 485fc36ffdaSJohannes Berg hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; 486fc36ffdaSJohannes Berg } 487b73f9a4aSJohannes Berg 488a5de7de7SJohannes Berg if (sec_key_ver && 489a5de7de7SJohannes Berg fw_has_capa(&mvm->fw->ucode_capa, 490a5de7de7SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT)) 491a5de7de7SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 492a5de7de7SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION); 493a5de7de7SJohannes Berg else if (fw_has_capa(&mvm->fw->ucode_capa, 494b1fdc250SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) 495b1fdc250SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 496b1fdc250SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); 497b1fdc250SJohannes Berg 498cf85123aSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 499cf85123aSAvraham Stern IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM)) 500cf85123aSAvraham Stern hw->wiphy->hw_timestamp_max_peers = 1; 501cf85123aSAvraham Stern 502c289f5cdSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 503c289f5cdSJohannes Berg IWL_UCODE_TLV_CAPA_SPP_AMSDU_SUPPORT)) 504c289f5cdSJohannes Berg wiphy_ext_feature_set(hw->wiphy, 505c289f5cdSJohannes Berg NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT); 506c289f5cdSJohannes Berg 507e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 508e705c121SKalle Valo hw->wiphy->features |= 509e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 510e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 511e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 512e705c121SKalle Valo 513e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 514e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 515e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 516cfbc6c4cSSara Sharon hw->txq_data_size = sizeof(struct iwl_mvm_txq); 517e705c121SKalle Valo 518e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 519e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 520e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 521e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 522e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 523e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 524e705c121SKalle Valo 525e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 526e47df5bdSJohannes Berg wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 52733e3fd99SAlexander Wetzel 52833e3fd99SAlexander Wetzel /* The new Tx API does not allow to pass the key or keyid of a MPDU to 52933e3fd99SAlexander Wetzel * the hw, preventing us to control which key(id) to use per MPDU. 53033e3fd99SAlexander Wetzel * Till that's fixed we can't use Extended Key ID for the newer cards. 53133e3fd99SAlexander Wetzel */ 53233e3fd99SAlexander Wetzel if (!iwl_mvm_has_new_tx_api(mvm)) 53333e3fd99SAlexander Wetzel wiphy_ext_feature_set(hw->wiphy, 53433e3fd99SAlexander Wetzel NL80211_EXT_FEATURE_EXT_KEY_ID); 535e47df5bdSJohannes Berg hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; 536e47df5bdSJohannes Berg 537e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 538e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 539e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 540e705c121SKalle Valo else 541e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 542e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 543e705c121SKalle Valo 544a1910a7fSAndrei Otcheretianski if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 545a1910a7fSAndrei Otcheretianski wiphy_ext_feature_set(hw->wiphy, 546a1910a7fSAndrei Otcheretianski NL80211_EXT_FEATURE_DFS_CONCURRENT); 547a1910a7fSAndrei Otcheretianski 548e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 549e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 550eae94cf8SLuca Coelho hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; 551e705c121SKalle Valo 552e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 553e705c121SKalle Valo hw->wiphy->n_iface_combinations = 554e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 555e705c121SKalle Valo 556e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 5574f1847cfSJohannes Berg hw->max_listen_interval = IWL_MVM_CONN_LISTEN_INTERVAL; 558e705c121SKalle Valo 559e705c121SKalle Valo /* Extract MAC address */ 560e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 561e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 562e705c121SKalle Valo hw->wiphy->n_addresses = 1; 563e705c121SKalle Valo 564e705c121SKalle Valo /* Extract additional MAC addresses if available */ 565e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 566e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 567e705c121SKalle Valo 568e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 569e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 570e705c121SKalle Valo ETH_ALEN); 571e705c121SKalle Valo mvm->addresses[i].addr[5]++; 572e705c121SKalle Valo hw->wiphy->n_addresses++; 573e705c121SKalle Valo } 574e705c121SKalle Valo 575e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 576e705c121SKalle Valo 577e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 578e705c121SKalle Valo 579e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 580e705c121SKalle Valo 581e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 582e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 583e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 584e705c121SKalle Valo 585e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 586e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 587e705c121SKalle Valo else 588e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 589e705c121SKalle Valo 59057fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 59157fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 59257fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 59357fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 59457fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 59557fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 596e705c121SKalle Valo 597e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 598e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 599e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 600e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 60157fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 602e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 603e705c121SKalle Valo } 604eae94cf8SLuca Coelho if (fw_has_capa(&mvm->fw->ucode_capa, 605eae94cf8SLuca Coelho IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && 606eae94cf8SLuca Coelho mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) 607eae94cf8SLuca Coelho hw->wiphy->bands[NL80211_BAND_6GHZ] = 608eae94cf8SLuca Coelho &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; 609e705c121SKalle Valo 610e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 611e705c121SKalle Valo 612e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 613e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 614e705c121SKalle Valo else 615e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 616e705c121SKalle Valo 617ca986ad9SArend Van Spriel hw->wiphy->max_sched_scan_reqs = 1; 618e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 6195d1234baSTova Mussai hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); 620e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 621e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 622e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 623e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 624e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 625e705c121SKalle Valo 626e705c121SKalle Valo /* 627e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 628e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 629e705c121SKalle Valo */ 630e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 631e705c121SKalle Valo 632e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 633e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 634e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 635a904a08bSPeer, Ilan NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 636e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 637e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 638e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 639e705c121SKalle Valo 640e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 641e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 642e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 643e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 644e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 645e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 646e705c121SKalle Valo 647e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 648e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 649e705c121SKalle Valo hw->wiphy->features |= 650e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 651e705c121SKalle Valo 652e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 653e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 654e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 655e705c121SKalle Valo 656971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL, 6572a42aea7SNathan Errera IWL_FW_CMD_VER_UNKNOWN) == 3) 6582a42aea7SNathan Errera hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; 6592a42aea7SNathan Errera 660aacf8f18SAvrahams Stern if (fw_has_api(&mvm->fw->ucode_capa, 661aacf8f18SAvrahams Stern IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 662aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 663aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SCAN_START_TIME); 664aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 665aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_BSS_PARENT_TSF); 666aacf8f18SAvrahams Stern } 667aacf8f18SAvrahams Stern 6688f691af9SZamir, Roee if (iwl_mvm_is_oce_supported(mvm)) { 669971cbe50SJohannes Berg u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0); 670773a042fSAvraham Stern 6718f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6728f691af9SZamir, Roee NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 6738f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6748f691af9SZamir, Roee NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 6758f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6768f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 677773a042fSAvraham Stern 678773a042fSAvraham Stern /* Old firmware also supports probe deferral and suppression */ 679773a042fSAvraham Stern if (scan_ver < 15) 680773a042fSAvraham Stern wiphy_ext_feature_set(hw->wiphy, 681773a042fSAvraham Stern NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 6828f691af9SZamir, Roee } 6838f691af9SZamir, Roee 6848e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = NULL; 6858e33f046SKrishnanand Prabhu hw->wiphy->num_iftype_ext_capab = 0; 6868e33f046SKrishnanand Prabhu 6877360f99eSEmmanuel Grumbach if (mvm->nvm_data->sku_cap_11ax_enable && 6887360f99eSEmmanuel Grumbach !iwlwifi_mod_params.disable_11ax) { 6898e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa; 6907360f99eSEmmanuel Grumbach hw->wiphy->num_iftype_ext_capab = 6918e33f046SKrishnanand Prabhu ARRAY_SIZE(add_iftypes_ext_capa) - 1; 692918cbf39SSara Sharon 693918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 694918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 6957360f99eSEmmanuel Grumbach } 6967360f99eSEmmanuel Grumbach 6978e33f046SKrishnanand Prabhu if (iwl_fw_lookup_cmd_ver(mvm->fw, 6988e33f046SKrishnanand Prabhu WIDE_ID(DATA_PATH_GROUP, 6998e33f046SKrishnanand Prabhu WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD), 7008e33f046SKrishnanand Prabhu IWL_FW_CMD_VER_UNKNOWN) >= 1) { 7018e33f046SKrishnanand Prabhu IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n"); 7028e33f046SKrishnanand Prabhu 7038e33f046SKrishnanand Prabhu if (!hw->wiphy->iftype_ext_capab) { 7048e33f046SKrishnanand Prabhu hw->wiphy->num_iftype_ext_capab = 1; 7058e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 7068e33f046SKrishnanand Prabhu ARRAY_SIZE(add_iftypes_ext_capa) - 1; 7078e33f046SKrishnanand Prabhu } else { 7088e33f046SKrishnanand Prabhu hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1; 7098e33f046SKrishnanand Prabhu } 7108e33f046SKrishnanand Prabhu } 7118e33f046SKrishnanand Prabhu 7128b720901SAvraham Stern if (iwl_fw_lookup_cmd_ver(mvm->fw, WIDE_ID(LOCATION_GROUP, 7138b720901SAvraham Stern TOF_RANGE_REQ_CMD), 7148b720901SAvraham Stern IWL_FW_CMD_VER_UNKNOWN) >= 11) { 7158b720901SAvraham Stern wiphy_ext_feature_set(hw->wiphy, 7168b720901SAvraham Stern NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE); 7174d951e26SIlan Peer 7184d951e26SIlan Peer if (fw_has_capa(&mvm->fw->ucode_capa, 7194d951e26SIlan Peer IWL_UCODE_TLV_CAPA_SECURE_LTF_SUPPORT)) 7204d951e26SIlan Peer wiphy_ext_feature_set(hw->wiphy, 7214d951e26SIlan Peer NL80211_EXT_FEATURE_SECURE_LTF); 7228b720901SAvraham Stern } 7238b720901SAvraham Stern 724e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 725e705c121SKalle Valo 726eb561c29SJohannes Berg ieee80211_hw_set(hw, DISALLOW_PUNCTURING_5GHZ); 727eb561c29SJohannes Berg 728e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 7293f37c229SIdo Yariv if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 730e705c121SKalle Valo mvm->trans->ops->d3_suspend && 731e705c121SKalle Valo mvm->trans->ops->d3_resume && 732e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 733e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 734e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 735e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 736e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 737e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 738e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 739e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 740e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 741e705c121SKalle Valo 742e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 743e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 744e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 7455d1234baSTova Mussai mvm->wowlan.max_nd_match_sets = 7465d1234baSTova Mussai iwl_umac_scan_get_max_profiles(mvm->fw); 747e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 748e705c121SKalle Valo } 749e705c121SKalle Valo #endif 750e705c121SKalle Valo 751e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 752e705c121SKalle Valo if (ret) 753e705c121SKalle Valo return ret; 754e705c121SKalle Valo 755e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 756e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 757e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 758e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 759e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 760e705c121SKalle Valo } 761e705c121SKalle Valo 762e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 763e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 764e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 765e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 766e705c121SKalle Valo } 767e705c121SKalle Valo 768e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 76959fa61f3SEmmanuel Grumbach if (!iwl_mvm_is_csum_supported(mvm)) 7706772aab7SJohannes Berg hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; 77141837ca9SEmmanuel Grumbach 77291b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 77391b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 77491b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 77591b08c2dSAviya Erenfeld 7769c11d8a9SShaul Triebitz if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 7779c11d8a9SShaul Triebitz wiphy_ext_feature_set(hw->wiphy, 7789c11d8a9SShaul Triebitz NL80211_EXT_FEATURE_PROTECTED_TWT); 7799c11d8a9SShaul Triebitz 780bfcfdb59SEmmanuel Grumbach iwl_mvm_vendor_cmds_register(mvm); 781bfcfdb59SEmmanuel Grumbach 782e8503aecSBen Greear hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 783e8503aecSBen Greear hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 784e8503aecSBen Greear 785de645e89SJohannes Berg ret = ieee80211_register_hw(mvm->hw); 786de645e89SJohannes Berg if (ret) { 787de645e89SJohannes Berg iwl_mvm_leds_exit(mvm); 788e705c121SKalle Valo } 789e705c121SKalle Valo 790e705c121SKalle Valo return ret; 791e705c121SKalle Valo } 792e705c121SKalle Valo 793df2378abSJohannes Berg static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 794df2378abSJohannes Berg struct ieee80211_sta *sta) 795df2378abSJohannes Berg { 796df2378abSJohannes Berg if (likely(sta)) { 797df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 798df2378abSJohannes Berg return; 799df2378abSJohannes Berg } else { 800df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 801df2378abSJohannes Berg return; 802df2378abSJohannes Berg } 803df2378abSJohannes Berg 804df2378abSJohannes Berg ieee80211_free_txskb(mvm->hw, skb); 805df2378abSJohannes Berg } 806df2378abSJohannes Berg 807cbce62a3SMiri Korenblit void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 808cbce62a3SMiri Korenblit struct ieee80211_tx_control *control, struct sk_buff *skb) 809e705c121SKalle Valo { 810e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 811e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 812e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 813e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 814cfbc6c4cSSara Sharon bool offchannel = IEEE80211_SKB_CB(skb)->flags & 815cfbc6c4cSSara Sharon IEEE80211_TX_CTL_TX_OFFCHAN; 81690723da6SShaul Triebitz u32 link_id = u32_get_bits(info->control.flags, 81790723da6SShaul Triebitz IEEE80211_TX_CTRL_MLO_LINK); 81890723da6SShaul Triebitz struct ieee80211_sta *tmp_sta = sta; 819e705c121SKalle Valo 820e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 821e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 822e705c121SKalle Valo goto drop; 823e705c121SKalle Valo } 824e705c121SKalle Valo 825cfbc6c4cSSara Sharon if (offchannel && 826e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 827e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 828e705c121SKalle Valo goto drop; 829e705c121SKalle Valo 83010516783SJohannes Berg /* 83110516783SJohannes Berg * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 83210516783SJohannes Berg * so we treat the others as broadcast 83310516783SJohannes Berg */ 83410516783SJohannes Berg if (ieee80211_is_mgmt(hdr->frame_control)) 835e705c121SKalle Valo sta = NULL; 836e705c121SKalle Valo 837dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 838cfbc6c4cSSara Sharon if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 839cfbc6c4cSSara Sharon !offchannel) { 840dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 841dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 842650cadb7SGregory Greenman u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id); 843dc1aca22SAndrei Otcheretianski 844be9ae34eSNathan Errera if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 845dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 846dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 847dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 848dc1aca22SAndrei Otcheretianski goto drop; 849dc1aca22SAndrei Otcheretianski } 850dc1aca22SAndrei Otcheretianski } 851dc1aca22SAndrei Otcheretianski 85290723da6SShaul Triebitz if (tmp_sta && !sta && link_id != IEEE80211_LINK_UNSPECIFIED && 85390723da6SShaul Triebitz !ieee80211_is_probe_resp(hdr->frame_control)) { 85490723da6SShaul Triebitz /* translate MLD addresses to LINK addresses */ 85590723da6SShaul Triebitz struct ieee80211_link_sta *link_sta = 85690723da6SShaul Triebitz rcu_dereference(tmp_sta->link[link_id]); 85790723da6SShaul Triebitz struct ieee80211_bss_conf *link_conf = 85890723da6SShaul Triebitz rcu_dereference(info->control.vif->link_conf[link_id]); 85990723da6SShaul Triebitz struct ieee80211_mgmt *mgmt; 86090723da6SShaul Triebitz 86190723da6SShaul Triebitz if (WARN_ON(!link_sta || !link_conf)) 86290723da6SShaul Triebitz goto drop; 86390723da6SShaul Triebitz 86490723da6SShaul Triebitz /* if sta is NULL, the frame is a management frame */ 86590723da6SShaul Triebitz mgmt = (void *)hdr; 86690723da6SShaul Triebitz memcpy(mgmt->da, link_sta->addr, ETH_ALEN); 86790723da6SShaul Triebitz memcpy(mgmt->sa, link_conf->addr, ETH_ALEN); 86890723da6SShaul Triebitz memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN); 86990723da6SShaul Triebitz } 87090723da6SShaul Triebitz 871df2378abSJohannes Berg iwl_mvm_tx_skb(mvm, skb, sta); 872e705c121SKalle Valo return; 873e705c121SKalle Valo drop: 874e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 875e705c121SKalle Valo } 876e705c121SKalle Valo 877cfbc6c4cSSara Sharon void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 878e705c121SKalle Valo { 879cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 880cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 881cfbc6c4cSSara Sharon struct sk_buff *skb = NULL; 882cfbc6c4cSSara Sharon 883fba8248eSSara Sharon /* 884fba8248eSSara Sharon * No need for threads to be pending here, they can leave the first 885fba8248eSSara Sharon * taker all the work. 886fba8248eSSara Sharon * 887fba8248eSSara Sharon * mvmtxq->tx_request logic: 888fba8248eSSara Sharon * 889fba8248eSSara Sharon * If 0, no one is currently TXing, set to 1 to indicate current thread 890fba8248eSSara Sharon * will now start TX and other threads should quit. 891fba8248eSSara Sharon * 892fba8248eSSara Sharon * If 1, another thread is currently TXing, set to 2 to indicate to 893fba8248eSSara Sharon * that thread that there was another request. Since that request may 894fba8248eSSara Sharon * have raced with the check whether the queue is empty, the TXing 895fba8248eSSara Sharon * thread should check the queue's status one more time before leaving. 896fba8248eSSara Sharon * This check is done in order to not leave any TX hanging in the queue 897fba8248eSSara Sharon * until the next TX invocation (which may not even happen). 898fba8248eSSara Sharon * 899fba8248eSSara Sharon * If 2, another thread is currently TXing, and it will already double 900fba8248eSSara Sharon * check the queue, so do nothing. 901fba8248eSSara Sharon */ 902fba8248eSSara Sharon if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 903fba8248eSSara Sharon return; 904cfbc6c4cSSara Sharon 905cfbc6c4cSSara Sharon rcu_read_lock(); 906fba8248eSSara Sharon do { 907b58e3d43SJohannes Berg while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL, 908b58e3d43SJohannes Berg &mvmtxq->state) && 909b58e3d43SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT, 910b58e3d43SJohannes Berg &mvmtxq->state) && 911bbd6d0f8SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, 912bbd6d0f8SJohannes Berg &mvmtxq->state) && 91300520b7aSEmmanuel Grumbach !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 914cfbc6c4cSSara Sharon skb = ieee80211_tx_dequeue(hw, txq); 915cfbc6c4cSSara Sharon 916f50d693bSSara Sharon if (!skb) { 917f50d693bSSara Sharon if (txq->sta) 918f50d693bSSara Sharon IWL_DEBUG_TX(mvm, 919f50d693bSSara Sharon "TXQ of sta %pM tid %d is now empty\n", 920f50d693bSSara Sharon txq->sta->addr, 921f50d693bSSara Sharon txq->tid); 922cfbc6c4cSSara Sharon break; 923f50d693bSSara Sharon } 924cfbc6c4cSSara Sharon 925cfbc6c4cSSara Sharon iwl_mvm_tx_skb(mvm, skb, txq->sta); 926cfbc6c4cSSara Sharon } 927fba8248eSSara Sharon } while (atomic_dec_return(&mvmtxq->tx_request)); 928cfbc6c4cSSara Sharon rcu_read_unlock(); 929e705c121SKalle Valo } 930e705c121SKalle Valo 931cbce62a3SMiri Korenblit void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 932cfbc6c4cSSara Sharon struct ieee80211_txq *txq) 933e705c121SKalle Valo { 934cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 935cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 936e705c121SKalle Valo 937923bf981SJohannes Berg if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) || 938923bf981SJohannes Berg !txq->sta) { 939cfbc6c4cSSara Sharon iwl_mvm_mac_itxq_xmit(hw, txq); 940cfbc6c4cSSara Sharon return; 941cfbc6c4cSSara Sharon } 942cfbc6c4cSSara Sharon 943923bf981SJohannes Berg /* iwl_mvm_mac_itxq_xmit() will later be called by the worker 944923bf981SJohannes Berg * to handle any packets we leave on the txq now 945923bf981SJohannes Berg */ 946cfbc6c4cSSara Sharon 947923bf981SJohannes Berg spin_lock_bh(&mvm->add_stream_lock); 948923bf981SJohannes Berg /* The list is being deleted only after the queue is fully allocated. */ 949923bf981SJohannes Berg if (list_empty(&mvmtxq->list) && 950923bf981SJohannes Berg /* recheck under lock */ 951923bf981SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) { 952cfbc6c4cSSara Sharon list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 953cfbc6c4cSSara Sharon schedule_work(&mvm->add_stream_wk); 954e705c121SKalle Valo } 955923bf981SJohannes Berg spin_unlock_bh(&mvm->add_stream_lock); 956923bf981SJohannes Berg } 957e705c121SKalle Valo 958e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 959e705c121SKalle Valo do { \ 960e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 961e705c121SKalle Valo break; \ 9627174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 963e705c121SKalle Valo } while (0) 964e705c121SKalle Valo 965e705c121SKalle Valo static void 966e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 967e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 968e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 969e705c121SKalle Valo { 970e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 971e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 972e705c121SKalle Valo 9736c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 9746c042d75SSara Sharon FW_DBG_TRIGGER_BA); 9756c042d75SSara Sharon if (!trig) 976e705c121SKalle Valo return; 977e705c121SKalle Valo 978e705c121SKalle Valo ba_trig = (void *)trig->data; 979e705c121SKalle Valo 980e705c121SKalle Valo switch (action) { 981e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 982e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 983e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 984e705c121SKalle Valo 985e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 986e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 987e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 988e705c121SKalle Valo break; 989e705c121SKalle Valo } 990e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 991e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 992e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 993e705c121SKalle Valo sta->addr, tid); 994e705c121SKalle Valo break; 995e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 996e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 997e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 998e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 999e705c121SKalle Valo break; 1000e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 1001e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 1002e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 1003e705c121SKalle Valo sta->addr, tid); 1004e705c121SKalle Valo break; 1005e705c121SKalle Valo default: 1006e705c121SKalle Valo break; 1007e705c121SKalle Valo } 1008e705c121SKalle Valo } 1009e705c121SKalle Valo 1010cbce62a3SMiri Korenblit int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 1011e705c121SKalle Valo struct ieee80211_vif *vif, 101250ea05efSSara Sharon struct ieee80211_ampdu_params *params) 1013e705c121SKalle Valo { 1014e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1015e705c121SKalle Valo int ret; 101650ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 101750ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 101850ea05efSSara Sharon u16 tid = params->tid; 101950ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 1020514c3069SLuca Coelho u16 buf_size = params->buf_size; 1021bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 102210b2b201SSara Sharon u16 timeout = params->timeout; 1023e705c121SKalle Valo 1024e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 1025e705c121SKalle Valo sta->addr, tid, action); 1026e705c121SKalle Valo 1027e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 1028e705c121SKalle Valo return -EACCES; 1029e705c121SKalle Valo 1030e705c121SKalle Valo mutex_lock(&mvm->mutex); 1031e705c121SKalle Valo 1032e705c121SKalle Valo switch (action) { 1033e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 1034650cadb7SGregory Greenman if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id == 1035c8ee33e1SGregory Greenman iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) { 1036b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 1037b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 1038b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 1039b0ffe455SJohannes Berg 1040b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 1041b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 1042b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 1043b0ffe455SJohannes Berg } 1044e78da25eSJohannes Berg if (!iwl_enable_rx_ampdu()) { 1045e705c121SKalle Valo ret = -EINVAL; 1046e705c121SKalle Valo break; 1047e705c121SKalle Valo } 104810b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 104910b2b201SSara Sharon timeout); 1050e705c121SKalle Valo break; 1051e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 105210b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 105310b2b201SSara Sharon timeout); 1054e705c121SKalle Valo break; 1055e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 1056e78da25eSJohannes Berg if (!iwl_enable_tx_ampdu()) { 1057e705c121SKalle Valo ret = -EINVAL; 1058e705c121SKalle Valo break; 1059e705c121SKalle Valo } 1060e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 1061e705c121SKalle Valo break; 1062e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 1063e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 1064e705c121SKalle Valo break; 1065e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 1066e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1067e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 1068e705c121SKalle Valo break; 1069e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 1070bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 1071bb81bb68SEmmanuel Grumbach buf_size, amsdu); 1072e705c121SKalle Valo break; 1073e705c121SKalle Valo default: 1074e705c121SKalle Valo WARN_ON_ONCE(1); 1075e705c121SKalle Valo ret = -EINVAL; 1076e705c121SKalle Valo break; 1077e705c121SKalle Valo } 1078e705c121SKalle Valo 1079e705c121SKalle Valo if (!ret) { 1080e705c121SKalle Valo u16 rx_ba_ssn = 0; 1081e705c121SKalle Valo 1082e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 1083e705c121SKalle Valo rx_ba_ssn = *ssn; 1084e705c121SKalle Valo 1085e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 1086e705c121SKalle Valo rx_ba_ssn, action); 1087e705c121SKalle Valo } 1088e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1089e705c121SKalle Valo 1090e705c121SKalle Valo return ret; 1091e705c121SKalle Valo } 1092e705c121SKalle Valo 1093e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 1094e705c121SKalle Valo struct ieee80211_vif *vif) 1095e705c121SKalle Valo { 1096e705c121SKalle Valo struct iwl_mvm *mvm = data; 1097e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1098bf976c81SJohannes Berg struct iwl_probe_resp_data *probe_data; 109979faae3aSGregory Greenman unsigned int link_id; 1100e705c121SKalle Valo 1101e705c121SKalle Valo mvmvif->uploaded = false; 1102e705c121SKalle Valo 1103e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 1104e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 1105e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 1106e705c121SKalle Valo 1107c1e458b9SIlan Peer mvmvif->bf_enabled = false; 1108c1e458b9SIlan Peer mvmvif->ba_enabled = false; 1109828c79d9SEmmanuel Grumbach mvmvif->ap_sta = NULL; 111079faae3aSGregory Greenman 1111*f2c2799eSBenjamin Berg mvmvif->esr_active = false; 1112*f2c2799eSBenjamin Berg vif->driver_flags &= ~IEEE80211_VIF_EML_ACTIVE; 1113*f2c2799eSBenjamin Berg 111479faae3aSGregory Greenman for_each_mvm_vif_valid_link(mvmvif, link_id) { 111579faae3aSGregory Greenman mvmvif->link[link_id]->ap_sta_id = IWL_MVM_INVALID_STA; 111679faae3aSGregory Greenman mvmvif->link[link_id]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 111779faae3aSGregory Greenman mvmvif->link[link_id]->phy_ctxt = NULL; 1118bf976c81SJohannes Berg mvmvif->link[link_id]->active = 0; 1119d615ea32SJohannes Berg mvmvif->link[link_id]->igtk = NULL; 1120c1e458b9SIlan Peer memset(&mvmvif->link[link_id]->bf_data, 0, 1121c1e458b9SIlan Peer sizeof(mvmvif->link[link_id]->bf_data)); 112279faae3aSGregory Greenman } 1123bf976c81SJohannes Berg 1124bf976c81SJohannes Berg probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 1125bf976c81SJohannes Berg lockdep_is_held(&mvm->mutex)); 1126bf976c81SJohannes Berg if (probe_data) 1127bf976c81SJohannes Berg kfree_rcu(probe_data, rcu_head); 1128bf976c81SJohannes Berg RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 1129e705c121SKalle Valo } 1130e705c121SKalle Valo 1131e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1132e705c121SKalle Valo { 1133fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1134e705c121SKalle Valo 11359bf13beeSJohannes Berg mvm->cur_aid = 0; 11369bf13beeSJohannes Berg 1137e705c121SKalle Valo mvm->scan_status = 0; 1138e705c121SKalle Valo mvm->ps_disabled = false; 1139b3500b47SEmmanuel Grumbach mvm->rfkill_safe_init_done = false; 1140e705c121SKalle Valo 1141e705c121SKalle Valo /* just in case one was running */ 1142305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 1143e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 1144e705c121SKalle Valo 1145fc36ffdaSJohannes Berg iwl_mvm_ftm_restart(mvm); 1146fc36ffdaSJohannes Berg 1147e705c121SKalle Valo /* 1148e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 1149e705c121SKalle Valo * gone down during the HW restart 1150e705c121SKalle Valo */ 1151e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1152e705c121SKalle Valo 1153e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1154e705c121SKalle Valo 1155e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 11569c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1157e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1158e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1159e705c121SKalle Valo 1160e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1161e705c121SKalle Valo 1162e705c121SKalle Valo mvm->rx_ba_sessions = 0; 11637174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 1164baf41bc3SShaul Triebitz mvm->monitor_on = false; 1165fb40cd9dSMiri Korenblit #ifdef CONFIG_IWLWIFI_DEBUGFS 1166fb40cd9dSMiri Korenblit mvm->beacon_inject_active = false; 1167fb40cd9dSMiri Korenblit #endif 1168e705c121SKalle Valo 1169e705c121SKalle Valo /* keep statistics ticking */ 1170e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1171e705c121SKalle Valo } 1172e705c121SKalle Valo 1173e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1174e705c121SKalle Valo { 1175e705c121SKalle Valo int ret; 1176e705c121SKalle Valo 1177e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1178e705c121SKalle Valo 11796d19a5ebSEmmanuel Grumbach ret = iwl_mvm_mei_get_ownership(mvm); 11806d19a5ebSEmmanuel Grumbach if (ret) 11816d19a5ebSEmmanuel Grumbach return ret; 11826d19a5ebSEmmanuel Grumbach 11836d19a5ebSEmmanuel Grumbach if (mvm->mei_nvm_data) { 11846d19a5ebSEmmanuel Grumbach /* We got the NIC, we can now free the MEI NVM data */ 11856d19a5ebSEmmanuel Grumbach kfree(mvm->mei_nvm_data); 11866d19a5ebSEmmanuel Grumbach mvm->mei_nvm_data = NULL; 11876d19a5ebSEmmanuel Grumbach 11886d19a5ebSEmmanuel Grumbach /* 11896d19a5ebSEmmanuel Grumbach * We can't free the nvm_data we allocated based on the SAP 11906d19a5ebSEmmanuel Grumbach * data because we registered to cfg80211 with the channels 11916d19a5ebSEmmanuel Grumbach * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 11926d19a5ebSEmmanuel Grumbach * just in order to be able free it later. 11936d19a5ebSEmmanuel Grumbach * NULLify nvm_data so that we will read the NVM from the 11946d19a5ebSEmmanuel Grumbach * firmware this time. 11956d19a5ebSEmmanuel Grumbach */ 11966d19a5ebSEmmanuel Grumbach mvm->temp_nvm_data = mvm->nvm_data; 11976d19a5ebSEmmanuel Grumbach mvm->nvm_data = NULL; 11986d19a5ebSEmmanuel Grumbach } 11996d19a5ebSEmmanuel Grumbach 1200bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1201bf8b286fSJohannes Berg /* 1202bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1203bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1204bf8b286fSJohannes Berg */ 1205bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1206bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1207e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1208e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1209a42b2af3SLuca Coelho } 1210e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1211e705c121SKalle Valo 1212b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1213b108d8c7SShahar S Matityahu NULL); 1214b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1215b108d8c7SShahar S Matityahu NULL); 1216da2eb669SSara Sharon 1217e8fe3b41SIlan Peer mvm->last_reset_or_resume_time_jiffies = jiffies; 1218e8fe3b41SIlan Peer 1219e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1220e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1221e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1222e705c121SKalle Valo * would do. 1223e705c121SKalle Valo */ 1224e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1225e705c121SKalle Valo } 1226e705c121SKalle Valo 1227e705c121SKalle Valo return ret; 1228e705c121SKalle Valo } 1229e705c121SKalle Valo 1230cbce62a3SMiri Korenblit int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1231e705c121SKalle Valo { 1232e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1233e705c121SKalle Valo int ret; 1234e705c121SKalle Valo 1235e705c121SKalle Valo mutex_lock(&mvm->mutex); 12365283dd67SMordechay Goodstein 12375283dd67SMordechay Goodstein /* we are starting the mac not in error flow, and restart is enabled */ 12385283dd67SMordechay Goodstein if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 12395283dd67SMordechay Goodstein iwlwifi_mod_params.fw_restart) { 12405283dd67SMordechay Goodstein /* 12415283dd67SMordechay Goodstein * This will prevent mac80211 recovery flows to trigger during 12425283dd67SMordechay Goodstein * init failures 12435283dd67SMordechay Goodstein */ 12445283dd67SMordechay Goodstein set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 12455283dd67SMordechay Goodstein } 12465283dd67SMordechay Goodstein 1247e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 12485283dd67SMordechay Goodstein clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 12495283dd67SMordechay Goodstein 1250e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1251e705c121SKalle Valo 12527ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 12537ce1f215SEmmanuel Grumbach 1254e705c121SKalle Valo return ret; 1255e705c121SKalle Valo } 1256e705c121SKalle Valo 1257e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1258e705c121SKalle Valo { 1259e705c121SKalle Valo int ret; 1260e705c121SKalle Valo 1261e705c121SKalle Valo mutex_lock(&mvm->mutex); 1262e705c121SKalle Valo 1263e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 12644d4183c4SEmmanuel Grumbach 1265e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1266e705c121SKalle Valo if (ret) 1267e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1268e705c121SKalle Valo ret); 1269e705c121SKalle Valo 1270f130bb75SMordechay Goodstein iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1271f130bb75SMordechay Goodstein 1272e705c121SKalle Valo /* 1273e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1274e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1275e705c121SKalle Valo */ 1276e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1277e705c121SKalle Valo 1278e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1279e705c121SKalle Valo } 1280e705c121SKalle Valo 1281cbce62a3SMiri Korenblit void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1282e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1283e705c121SKalle Valo { 1284e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1285e705c121SKalle Valo 1286e705c121SKalle Valo switch (reconfig_type) { 1287e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1288e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1289e705c121SKalle Valo break; 1290e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1291e705c121SKalle Valo break; 1292e705c121SKalle Valo } 1293e705c121SKalle Valo } 1294e705c121SKalle Valo 1295e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1296e705c121SKalle Valo { 1297e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1298e705c121SKalle Valo 1299b68bd2e3SIlan Peer iwl_mvm_ftm_initiator_smooth_stop(mvm); 1300b68bd2e3SIlan Peer 1301e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1302e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1303e705c121SKalle Valo */ 1304e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1305e705c121SKalle Valo 1306e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1307e705c121SKalle Valo 13081724fc78SEmmanuel Grumbach if (!iwl_mvm_has_new_station_api(mvm->fw)) 1309f327236dSSharon iwl_mvm_rm_aux_sta(mvm); 1310f327236dSSharon 1311fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1312e705c121SKalle Valo 1313e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1314e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1315e705c121SKalle Valo 1316e705c121SKalle Valo /* 1317155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1318155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1319155f7e04SEmmanuel Grumbach * won't execute the restart. 1320e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1321e705c121SKalle Valo * HW restart was requested. 1322e705c121SKalle Valo */ 1323155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1324155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1325155f7e04SEmmanuel Grumbach &mvm->status)) 1326e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1327e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1328e705c121SKalle Valo 1329e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1330e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1331e705c121SKalle Valo */ 1332e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1333e705c121SKalle Valo int i; 1334e705c121SKalle Valo 1335e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1336e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1337e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1338e705c121SKalle Valo i)) 1339e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1340e705c121SKalle Valo } 1341e705c121SKalle Valo } 1342e705c121SKalle Valo } 1343e705c121SKalle Valo 1344cbce62a3SMiri Korenblit void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1345e705c121SKalle Valo { 1346e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1347e705c121SKalle Valo 134838b3998dSIlan Peer /* Stop internal MLO scan, if running */ 134938b3998dSIlan Peer mutex_lock(&mvm->mutex); 135038b3998dSIlan Peer iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_INT_MLO, false); 135138b3998dSIlan Peer mutex_unlock(&mvm->mutex); 135238b3998dSIlan Peer 1353e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 135424afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1355771147b0SJohannes Berg 1356771147b0SJohannes Berg /* 1357771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1358771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1359771147b0SJohannes Berg * be able to proceed. This is important here because one of those 13607174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1361771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1362771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1363771147b0SJohannes Berg */ 1364771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1365771147b0SJohannes Berg 1366d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 136769e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1368e705c121SKalle Valo 1369f9084775SNathan Errera /* 1370f9084775SNathan Errera * The work item could be running or queued if the 1371f9084775SNathan Errera * ROC time event stops just as we get here. 1372f9084775SNathan Errera */ 1373f9084775SNathan Errera flush_work(&mvm->roc_done_wk); 1374f9084775SNathan Errera 13757ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 13767ce1f215SEmmanuel Grumbach 1377e705c121SKalle Valo mutex_lock(&mvm->mutex); 1378e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1379e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1380e705c121SKalle Valo 1381e705c121SKalle Valo /* 1382e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1383e705c121SKalle Valo * discover that its list is now empty. 1384e705c121SKalle Valo */ 1385e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1386fdccafadSMiri Korenblit wiphy_work_cancel(hw->wiphy, &mvm->async_handlers_wiphy_wk); 1387e705c121SKalle Valo } 1388e705c121SKalle Valo 13891ab26632SMiri Korenblit struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1390e705c121SKalle Valo { 1391e705c121SKalle Valo u16 i; 1392e705c121SKalle Valo 1393e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1394e705c121SKalle Valo 1395e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1396e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1397e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1398e705c121SKalle Valo 1399e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1400e705c121SKalle Valo return NULL; 1401e705c121SKalle Valo } 1402e705c121SKalle Valo 1403f551d013SGregory Greenman int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1404e705c121SKalle Valo s16 tx_power) 1405e705c121SKalle Valo { 1406971cbe50SJohannes Berg u32 cmd_id = REDUCE_TX_POWER_CMD; 14070791c2fcSHaim Dreyfuss int len; 1408216cdfb5SLuca Coelho struct iwl_dev_tx_power_cmd cmd = { 1409216cdfb5SLuca Coelho .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1410216cdfb5SLuca Coelho .common.mac_context_id = 1411e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1412216cdfb5SLuca Coelho .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1413e705c121SKalle Valo }; 1414971cbe50SJohannes Berg u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1415e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN); 1416e705c121SKalle Valo 1417e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1418216cdfb5SLuca Coelho cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1419e705c121SKalle Valo 14208f892e22SEmmanuel Grumbach if (cmd_ver == 8) 14218f892e22SEmmanuel Grumbach len = sizeof(cmd.v8); 14228f892e22SEmmanuel Grumbach else if (cmd_ver == 7) 1423b0aa02b3SAyala Barazani len = sizeof(cmd.v7); 1424b0aa02b3SAyala Barazani else if (cmd_ver == 6) 1425fbb7957dSLuca Coelho len = sizeof(cmd.v6); 1426fbb7957dSLuca Coelho else if (fw_has_api(&mvm->fw->ucode_capa, 14270791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 14280791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 14290791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 14300791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 14310791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 14320791c2fcSHaim Dreyfuss else 1433216cdfb5SLuca Coelho len = sizeof(cmd.v3); 1434216cdfb5SLuca Coelho 1435216cdfb5SLuca Coelho /* all structs have the same common part, add it */ 1436216cdfb5SLuca Coelho len += sizeof(cmd.common); 1437e705c121SKalle Valo 1438971cbe50SJohannes Berg return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); 1439e705c121SKalle Valo } 1440e705c121SKalle Valo 1441bbd6d0f8SJohannes Berg static void iwl_mvm_post_csa_tx(void *data, struct ieee80211_sta *sta) 1442bbd6d0f8SJohannes Berg { 1443bbd6d0f8SJohannes Berg struct ieee80211_hw *hw = data; 1444bbd6d0f8SJohannes Berg int i; 1445bbd6d0f8SJohannes Berg 1446bbd6d0f8SJohannes Berg for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 1447bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 1448bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(sta->txq[i]); 1449bbd6d0f8SJohannes Berg 1450bbd6d0f8SJohannes Berg clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1451bbd6d0f8SJohannes Berg iwl_mvm_mac_itxq_xmit(hw, sta->txq[i]); 1452bbd6d0f8SJohannes Berg } 1453bbd6d0f8SJohannes Berg } 1454bbd6d0f8SJohannes Berg 145503117f30SMiri Korenblit int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1456a469a593SEmmanuel Grumbach struct ieee80211_vif *vif, 1457a469a593SEmmanuel Grumbach struct ieee80211_bss_conf *link_conf) 1458f6780614SSara Sharon { 1459f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1460f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1461f6780614SSara Sharon int ret; 1462f6780614SSara Sharon 1463f6780614SSara Sharon mutex_lock(&mvm->mutex); 1464f6780614SSara Sharon 1465f6780614SSara Sharon if (vif->type == NL80211_IFTYPE_STATION) { 1466f6780614SSara Sharon struct iwl_mvm_sta *mvmsta; 14673723c7c5SEmmanuel Grumbach unsigned int link_id = link_conf->link_id; 14683723c7c5SEmmanuel Grumbach u8 ap_sta_id = mvmvif->link[link_id]->ap_sta_id; 1469f6780614SSara Sharon 1470f6780614SSara Sharon mvmvif->csa_bcn_pending = false; 14712964b57fSJohannes Berg mvmvif->csa_blocks_tx = false; 14723723c7c5SEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id); 1473f6780614SSara Sharon 1474f6780614SSara Sharon if (WARN_ON(!mvmsta)) { 1475f6780614SSara Sharon ret = -EIO; 1476f6780614SSara Sharon goto out_unlock; 1477f6780614SSara Sharon } 1478f6780614SSara Sharon 1479f6780614SSara Sharon iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 148003117f30SMiri Korenblit if (mvm->mld_api_is_used) 148103117f30SMiri Korenblit iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 148203117f30SMiri Korenblit else 1483f6780614SSara Sharon iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1484f6780614SSara Sharon 14850202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 14860202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 148787f5b5f2SJohannes Berg ret = iwl_mvm_enable_beacon_filter(mvm, vif); 1488f6780614SSara Sharon if (ret) 1489f6780614SSara Sharon goto out_unlock; 1490f6780614SSara Sharon 1491f6780614SSara Sharon iwl_mvm_stop_session_protection(mvm, vif); 1492f6780614SSara Sharon } 1493bbd6d0f8SJohannes Berg } else if (vif->type == NL80211_IFTYPE_AP && mvmvif->csa_blocks_tx) { 1494bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 1495bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(vif->txq); 1496bbd6d0f8SJohannes Berg 1497bbd6d0f8SJohannes Berg clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1498bbd6d0f8SJohannes Berg 1499bbd6d0f8SJohannes Berg local_bh_disable(); 1500bbd6d0f8SJohannes Berg iwl_mvm_mac_itxq_xmit(hw, vif->txq); 1501bbd6d0f8SJohannes Berg ieee80211_iterate_stations_atomic(hw, iwl_mvm_post_csa_tx, hw); 1502bbd6d0f8SJohannes Berg local_bh_enable(); 1503bbd6d0f8SJohannes Berg 1504bbd6d0f8SJohannes Berg mvmvif->csa_blocks_tx = false; 15050202bcf0SEmmanuel Grumbach } 1506f6780614SSara Sharon 1507f6780614SSara Sharon mvmvif->ps_disabled = false; 1508f6780614SSara Sharon 1509f6780614SSara Sharon ret = iwl_mvm_power_update_ps(mvm); 1510f6780614SSara Sharon 1511f6780614SSara Sharon out_unlock: 1512caf46377SSara Sharon if (mvmvif->csa_failed) 1513caf46377SSara Sharon ret = -EIO; 1514f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1515f6780614SSara Sharon 1516f6780614SSara Sharon return ret; 1517f6780614SSara Sharon } 1518f6780614SSara Sharon 1519cbce62a3SMiri Korenblit void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 15205ecd5d82SJohannes Berg struct ieee80211_vif *vif, 15215ecd5d82SJohannes Berg struct ieee80211_bss_conf *link_conf) 1522f6780614SSara Sharon { 1523f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1524f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1525f6780614SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 1526f6780614SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1527f6780614SSara Sharon mvmvif->color)), 1528f6780614SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1529f6780614SSara Sharon }; 1530f6780614SSara Sharon 1531ad12b231SNathan Errera /* 1532ad12b231SNathan Errera * In the new flow since FW is in charge of the timing, 1533ad12b231SNathan Errera * if driver has canceled the channel switch he will receive the 1534ad12b231SNathan Errera * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it 1535ad12b231SNathan Errera */ 1536ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 1537ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 1538ad12b231SNathan Errera return; 1539ad12b231SNathan Errera 1540f6780614SSara Sharon IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1541f6780614SSara Sharon 1542f6780614SSara Sharon mutex_lock(&mvm->mutex); 154358ddd9b6SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 154458ddd9b6SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 154558ddd9b6SEmmanuel Grumbach iwl_mvm_remove_csa_period(mvm, vif); 154658ddd9b6SEmmanuel Grumbach else 1547f6780614SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1548f6780614SSara Sharon WIDE_ID(MAC_CONF_GROUP, 1549f6780614SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 1550f6780614SSara Sharon 0, sizeof(cmd), &cmd)); 1551caf46377SSara Sharon mvmvif->csa_failed = true; 1552f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1553f6780614SSara Sharon 1554a469a593SEmmanuel Grumbach /* If we're here, we can't support MLD */ 1555a469a593SEmmanuel Grumbach iwl_mvm_post_channel_switch(hw, vif, &vif->bss_conf); 1556f6780614SSara Sharon } 1557f6780614SSara Sharon 15581ab26632SMiri Korenblit void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1559f6780614SSara Sharon { 1560f6780614SSara Sharon struct iwl_mvm_vif *mvmvif; 1561f6780614SSara Sharon struct ieee80211_vif *vif; 1562f6780614SSara Sharon 1563f6780614SSara Sharon mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1564f6780614SSara Sharon vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1565f6780614SSara Sharon 156670162580SShaul Triebitz /* Trigger disconnect (should clear the CSA state) */ 1567a469a593SEmmanuel Grumbach ieee80211_chswitch_done(vif, false, 0); 1568f6780614SSara Sharon } 1569f6780614SSara Sharon 15705abf3154SMordechay Goodstein static u8 15715abf3154SMordechay Goodstein iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef) 15725abf3154SMordechay Goodstein { 15735abf3154SMordechay Goodstein int data_start; 15745abf3154SMordechay Goodstein int control_start; 15755abf3154SMordechay Goodstein int bw; 15765abf3154SMordechay Goodstein 15775abf3154SMordechay Goodstein if (chandef->width == NL80211_CHAN_WIDTH_320) 15785abf3154SMordechay Goodstein bw = 320; 15795abf3154SMordechay Goodstein else if (chandef->width == NL80211_CHAN_WIDTH_160) 15805abf3154SMordechay Goodstein bw = 160; 15815abf3154SMordechay Goodstein else 15825abf3154SMordechay Goodstein return 0; 15835abf3154SMordechay Goodstein 15845abf3154SMordechay Goodstein /* data is bw wide so the start is half the width */ 15855abf3154SMordechay Goodstein data_start = chandef->center_freq1 - bw / 2; 15865abf3154SMordechay Goodstein /* control is 20Mhz width */ 15875abf3154SMordechay Goodstein control_start = chandef->chan->center_freq - 10; 15885abf3154SMordechay Goodstein 15895abf3154SMordechay Goodstein return (control_start - data_start) / 80; 15905abf3154SMordechay Goodstein } 15915abf3154SMordechay Goodstein 15921be4858eSJohannes Berg static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm, 15931be4858eSJohannes Berg struct ieee80211_vif *vif) 1594e705c121SKalle Valo { 1595e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 15961be4858eSJohannes Berg int ret; 15971ab26632SMiri Korenblit 15981ab26632SMiri Korenblit lockdep_assert_held(&mvm->mutex); 1599e705c121SKalle Valo 16001be4858eSJohannes Berg ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 16011be4858eSJohannes Berg if (ret) { 16021be4858eSJohannes Berg IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 16031be4858eSJohannes Berg return ret; 16041be4858eSJohannes Berg } 16051be4858eSJohannes Berg 16061be4858eSJohannes Berg /* Only queue for this station is the mcast queue, 16071be4858eSJohannes Berg * which shouldn't be in TFD mask anyway 16081be4858eSJohannes Berg */ 16091be4858eSJohannes Berg return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0, 16101be4858eSJohannes Berg vif->type, 16111be4858eSJohannes Berg IWL_STA_MULTICAST); 16121be4858eSJohannes Berg } 16131be4858eSJohannes Berg 16141be4858eSJohannes Berg static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 16151be4858eSJohannes Berg struct ieee80211_vif *vif) 16161be4858eSJohannes Berg { 16171be4858eSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 16181be4858eSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 16191be4858eSJohannes Berg int ret; 1620b6e3d1baSAnjaneyulu int i; 16211be4858eSJohannes Berg 16221be4858eSJohannes Berg mutex_lock(&mvm->mutex); 16231be4858eSJohannes Berg 1624e705c121SKalle Valo mvmvif->mvm = mvm; 1625650cadb7SGregory Greenman 1626650cadb7SGregory Greenman /* the first link always points to the default one */ 1627650cadb7SGregory Greenman mvmvif->link[0] = &mvmvif->deflink; 1628e705c121SKalle Valo 1629e705c121SKalle Valo /* 1630e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1631e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1632e705c121SKalle Valo * don't really have to check the types. 1633e705c121SKalle Valo */ 1634e705c121SKalle Valo 1635e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1636e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1637b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 1638b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.accu_num_beacons += 1639b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.num_beacons; 1640e705c121SKalle Valo 1641e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 16421be4858eSJohannes Berg ret = iwl_mvm_mac_ctxt_init(mvm, vif); 16431be4858eSJohannes Berg if (ret) 16441be4858eSJohannes Berg goto out; 1645e705c121SKalle Valo 1646698478c4SSara Sharon rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1647698478c4SSara Sharon 16481be4858eSJohannes Berg /* Currently not much to do for NAN */ 16491be4858eSJohannes Berg if (vif->type == NL80211_IFTYPE_NAN) { 16501be4858eSJohannes Berg ret = 0; 16511be4858eSJohannes Berg goto out; 16521be4858eSJohannes Berg } 16531be4858eSJohannes Berg 1654e705c121SKalle Valo /* 1655e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1656e705c121SKalle Valo * template is configured (which happens only in the mac80211 1657e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1658e705c121SKalle Valo * only after the binding. 1659e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1660e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1661e705c121SKalle Valo * the point where we can also add the bcast station. 1662e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1663e705c121SKalle Valo * allocating resources :) 1664e705c121SKalle Valo */ 1665e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1666e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 16673a3ef394SBenjamin Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1668c36235acSJohannes Berg iwl_mvm_vif_dbgfs_add_link(mvm, vif); 16691be4858eSJohannes Berg ret = 0; 16701be4858eSJohannes Berg goto out; 16711ab26632SMiri Korenblit } 16721ab26632SMiri Korenblit 16731ab26632SMiri Korenblit mvmvif->features |= hw->netdev_features; 1674650cadb7SGregory Greenman 1675e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1676e705c121SKalle Valo if (ret) 167798c0de7bSMiri Korenblit goto out_unlock; 1678e705c121SKalle Valo 1679e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1680e705c121SKalle Valo if (ret) 1681e705c121SKalle Valo goto out_remove_mac; 1682e705c121SKalle Valo 1683e705c121SKalle Valo /* beacon filtering */ 168487f5b5f2SJohannes Berg ret = iwl_mvm_disable_beacon_filter(mvm, vif); 1685e705c121SKalle Valo if (ret) 1686e705c121SKalle Valo goto out_remove_mac; 1687e705c121SKalle Valo 1688e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1689e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1690e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1691e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1692e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1693e705c121SKalle Valo } 1694e705c121SKalle Valo 169532a5690eSJohannes Berg if (vif->p2p || iwl_fw_lookup_cmd_ver(mvm->fw, PHY_CONTEXT_CMD, 1) < 5) 169632a5690eSJohannes Berg vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW; 169732a5690eSJohannes Berg 169884ef7cbeSIlan Peer if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 1699e705c121SKalle Valo mvm->p2p_device_vif = vif; 1700e705c121SKalle Valo 1701b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1702f6780614SSara Sharon INIT_DELAYED_WORK(&mvmvif->csa_work, 1703f6780614SSara Sharon iwl_mvm_channel_switch_disconnect_wk); 1704b0ffe455SJohannes Berg 17055abf3154SMordechay Goodstein if (vif->type == NL80211_IFTYPE_MONITOR) { 1706baf41bc3SShaul Triebitz mvm->monitor_on = true; 17075abf3154SMordechay Goodstein mvm->monitor_p80 = 17086092077aSJohannes Berg iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chanreq.oper); 17095abf3154SMordechay Goodstein } 1710baf41bc3SShaul Triebitz 17113a3ef394SBenjamin Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1712c36235acSJohannes Berg iwl_mvm_vif_dbgfs_add_link(mvm, vif); 17136d19a5ebSEmmanuel Grumbach 17146d19a5ebSEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 17156d19a5ebSEmmanuel Grumbach vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 17166d19a5ebSEmmanuel Grumbach !mvm->csme_vif && mvm->mei_registered) { 17176d19a5ebSEmmanuel Grumbach iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 17186d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 17196d19a5ebSEmmanuel Grumbach mvm->csme_vif = vif; 17206d19a5ebSEmmanuel Grumbach } 17216d19a5ebSEmmanuel Grumbach 17221ab26632SMiri Korenblit out: 17231ab26632SMiri Korenblit if (!ret && (vif->type == NL80211_IFTYPE_AP || 17241ab26632SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC)) 17251ab26632SMiri Korenblit ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif); 17261ab26632SMiri Korenblit 1727e705c121SKalle Valo goto out_unlock; 1728e705c121SKalle Valo 1729e705c121SKalle Valo out_remove_mac: 1730650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1731e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1732e705c121SKalle Valo out_unlock: 1733e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1734e705c121SKalle Valo 1735e705c121SKalle Valo return ret; 1736e705c121SKalle Valo } 1737e705c121SKalle Valo 1738cb145863SJohannes Berg void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1739e705c121SKalle Valo struct ieee80211_vif *vif) 1740e705c121SKalle Valo { 1741e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1742e705c121SKalle Valo /* 1743e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1744e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1745e705c121SKalle Valo * queue are sent in ROC session. 1746e705c121SKalle Valo */ 1747e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1748e705c121SKalle Valo } 1749e705c121SKalle Valo } 1750e705c121SKalle Valo 175160efeca1SMiri Korenblit /* This function is doing the common part of removing the interface for 175260efeca1SMiri Korenblit * both - MLD and non-MLD modes. Returns true if removing the interface 175360efeca1SMiri Korenblit * is done 175460efeca1SMiri Korenblit */ 1755cb145863SJohannes Berg static bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw, 1756e705c121SKalle Valo struct ieee80211_vif *vif) 1757e705c121SKalle Valo { 1758e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1759e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 176086e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1761e705c121SKalle Valo 1762e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1763e705c121SKalle Valo 1764b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1765b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1766b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1767b0ffe455SJohannes Berg 1768e705c121SKalle Valo mutex_lock(&mvm->mutex); 1769e705c121SKalle Valo 17706d19a5ebSEmmanuel Grumbach if (vif == mvm->csme_vif) { 17716d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(NULL); 17726d19a5ebSEmmanuel Grumbach mvm->csme_vif = NULL; 17736d19a5ebSEmmanuel Grumbach } 17746d19a5ebSEmmanuel Grumbach 1775650cadb7SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 177686e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 1777650cadb7SGregory Greenman RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 177886e177d8SGregory Greenman if (probe_data) 177986e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 178086e177d8SGregory Greenman 1781e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1782e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1783e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1784e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1785e705c121SKalle Valo } 1786e705c121SKalle Valo 1787b73f9a4aSJohannes Berg if (vif->bss_conf.ftm_responder) 1788b73f9a4aSJohannes Berg memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1789b73f9a4aSJohannes Berg 1790c36235acSJohannes Berg iwl_mvm_vif_dbgfs_rm_link(mvm, vif); 1791e705c121SKalle Valo 1792e705c121SKalle Valo /* 1793e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1794e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1795e705c121SKalle Valo */ 1796e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1797e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1798e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1799e705c121SKalle Valo if (vif == mvm->noa_vif) { 1800e705c121SKalle Valo mvm->noa_vif = NULL; 1801e705c121SKalle Valo mvm->noa_duration = 0; 1802e705c121SKalle Valo } 1803e705c121SKalle Valo #endif 180460efeca1SMiri Korenblit return true; 1805e705c121SKalle Valo } 1806e705c121SKalle Valo 180760efeca1SMiri Korenblit iwl_mvm_power_update_mac(mvm); 180860efeca1SMiri Korenblit return false; 180960efeca1SMiri Korenblit } 181060efeca1SMiri Korenblit 181160efeca1SMiri Korenblit static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 181260efeca1SMiri Korenblit struct ieee80211_vif *vif) 181360efeca1SMiri Korenblit { 181460efeca1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 181560efeca1SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 181660efeca1SMiri Korenblit 181760efeca1SMiri Korenblit if (iwl_mvm_mac_remove_interface_common(hw, vif)) 181860efeca1SMiri Korenblit goto out; 181960efeca1SMiri Korenblit 182084ef7cbeSIlan Peer /* Before the interface removal, mac80211 would cancel the ROC, and the 182184ef7cbeSIlan Peer * ROC worker would be scheduled if needed. The worker would be flushed 182284ef7cbeSIlan Peer * in iwl_mvm_prepare_mac_removal() and thus at this point there is no 182384ef7cbeSIlan Peer * binding etc. so nothing needs to be done here. 182484ef7cbeSIlan Peer */ 1825e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 182684ef7cbeSIlan Peer if (mvmvif->deflink.phy_ctxt) { 1827650cadb7SGregory Greenman iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 1828650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1829e705c121SKalle Valo } 183084ef7cbeSIlan Peer mvm->p2p_device_vif = NULL; 183184ef7cbeSIlan Peer } 1832e705c121SKalle Valo 1833e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1834e705c121SKalle Valo 1835698478c4SSara Sharon RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1836698478c4SSara Sharon 1837baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1838baf41bc3SShaul Triebitz mvm->monitor_on = false; 1839baf41bc3SShaul Triebitz 184060efeca1SMiri Korenblit out: 184160efeca1SMiri Korenblit if (vif->type == NL80211_IFTYPE_AP || 184260efeca1SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC) { 1843650cadb7SGregory Greenman iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta); 184460efeca1SMiri Korenblit iwl_mvm_dealloc_bcast_sta(mvm, vif); 1845e705c121SKalle Valo } 1846e705c121SKalle Valo 1847e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1848e705c121SKalle Valo } 1849e705c121SKalle Valo 1850e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1851e705c121SKalle Valo struct iwl_mvm *mvm; 1852e705c121SKalle Valo int port_id; 1853e705c121SKalle Valo }; 1854e705c121SKalle Valo 1855e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1856e705c121SKalle Valo struct ieee80211_vif *vif) 1857e705c121SKalle Valo { 1858e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1859e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1860e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 186197bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 186297bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 186397bce57bSLuca Coelho .flags = CMD_ASYNC, 186497bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 186597bce57bSLuca Coelho }; 1866e705c121SKalle Valo int ret, len; 1867e705c121SKalle Valo 1868e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1869e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1870e705c121SKalle Valo return; 1871e705c121SKalle Valo 1872e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1873f276e20bSJohannes Berg !vif->cfg.assoc) 1874e705c121SKalle Valo return; 1875e705c121SKalle Valo 1876e705c121SKalle Valo cmd->port_id = data->port_id++; 1877e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1878e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1879e705c121SKalle Valo 188097bce57bSLuca Coelho hcmd.len[0] = len; 188197bce57bSLuca Coelho hcmd.data[0] = cmd; 188297bce57bSLuca Coelho 188397bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1884e705c121SKalle Valo if (ret) 1885e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1886e705c121SKalle Valo } 1887e705c121SKalle Valo 1888e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1889e705c121SKalle Valo { 1890e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1891e705c121SKalle Valo .mvm = mvm, 1892e705c121SKalle Valo }; 1893db66abeeSJohannes Berg int ret; 1894e705c121SKalle Valo 1895e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1896e705c121SKalle Valo 1897e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1898e705c121SKalle Valo return; 1899e705c121SKalle Valo 1900e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1901e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1902e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1903db66abeeSJohannes Berg 1904db66abeeSJohannes Berg /* 1905db66abeeSJohannes Berg * Send a (synchronous) ech command so that we wait for the 1906db66abeeSJohannes Berg * multiple asynchronous MCAST_FILTER_CMD commands sent by 1907db66abeeSJohannes Berg * the interface iterator. Otherwise, we might get here over 1908db66abeeSJohannes Berg * and over again (by userspace just sending a lot of these) 1909db66abeeSJohannes Berg * and the CPU can send them faster than the firmware can 1910db66abeeSJohannes Berg * process them. 1911db66abeeSJohannes Berg * Note that the CPU is still faster - but with this we'll 1912db66abeeSJohannes Berg * actually send fewer commands overall because the CPU will 1913db66abeeSJohannes Berg * not schedule the work in mac80211 as frequently if it's 1914db66abeeSJohannes Berg * still running when rescheduled (possibly multiple times). 1915db66abeeSJohannes Berg */ 1916db66abeeSJohannes Berg ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1917db66abeeSJohannes Berg if (ret) 1918db66abeeSJohannes Berg IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 1919e705c121SKalle Valo } 1920e705c121SKalle Valo 1921cbce62a3SMiri Korenblit u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1922e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1923e705c121SKalle Valo { 1924e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1925e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1926e705c121SKalle Valo struct netdev_hw_addr *addr; 1927e705c121SKalle Valo int addr_count; 1928e705c121SKalle Valo bool pass_all; 1929e705c121SKalle Valo int len; 1930e705c121SKalle Valo 1931e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1932e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1933e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1934e705c121SKalle Valo if (pass_all) 1935e705c121SKalle Valo addr_count = 0; 1936e705c121SKalle Valo 1937e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1938e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1939e705c121SKalle Valo if (!cmd) 1940e705c121SKalle Valo return 0; 1941e705c121SKalle Valo 1942e705c121SKalle Valo if (pass_all) { 1943e705c121SKalle Valo cmd->pass_all = 1; 1944e705c121SKalle Valo return (u64)(unsigned long)cmd; 1945e705c121SKalle Valo } 1946e705c121SKalle Valo 1947e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1948e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1949e705c121SKalle Valo cmd->count, addr->addr); 1950e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1951e705c121SKalle Valo addr->addr, ETH_ALEN); 1952e705c121SKalle Valo cmd->count++; 1953e705c121SKalle Valo } 1954e705c121SKalle Valo 1955e705c121SKalle Valo return (u64)(unsigned long)cmd; 1956e705c121SKalle Valo } 1957e705c121SKalle Valo 1958cbce62a3SMiri Korenblit void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1959e705c121SKalle Valo unsigned int changed_flags, 1960cbce62a3SMiri Korenblit unsigned int *total_flags, u64 multicast) 1961e705c121SKalle Valo { 1962e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1963e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1964e705c121SKalle Valo 1965e705c121SKalle Valo mutex_lock(&mvm->mutex); 1966e705c121SKalle Valo 1967e705c121SKalle Valo /* replace previous configuration */ 1968e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1969e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1970e705c121SKalle Valo 1971e705c121SKalle Valo if (!cmd) 1972e705c121SKalle Valo goto out; 1973e705c121SKalle Valo 197461e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 197561e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 197661e7d91bSLuca Coelho 197761e7d91bSLuca Coelho if (cmd->pass_all) 197861e7d91bSLuca Coelho cmd->count = 0; 197961e7d91bSLuca Coelho 1980e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1981e705c121SKalle Valo out: 1982e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1983e705c121SKalle Valo *total_flags = 0; 1984e705c121SKalle Valo } 1985e705c121SKalle Valo 1986e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1987e705c121SKalle Valo struct ieee80211_vif *vif, 1988e705c121SKalle Valo unsigned int filter_flags, 1989e705c121SKalle Valo unsigned int changed_flags) 1990e705c121SKalle Valo { 1991e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1992e705c121SKalle Valo 1993e705c121SKalle Valo /* We support only filter for probe requests */ 1994e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1995e705c121SKalle Valo return; 1996e705c121SKalle Valo 1997e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1998f276e20bSJohannes Berg if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 1999e705c121SKalle Valo !vif->p2p) 2000e705c121SKalle Valo return; 2001e705c121SKalle Valo 2002e705c121SKalle Valo mutex_lock(&mvm->mutex); 2003e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2004e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2005e705c121SKalle Valo } 2006e705c121SKalle Valo 200722c58834SGregory Greenman int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 2008a07a8f37SSara Sharon { 2009a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 2010a07a8f37SSara Sharon 2011a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 2012a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 2013a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 2014a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 2015a07a8f37SSara Sharon 2016a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 2017a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 2018a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 2019a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 2020a07a8f37SSara Sharon } 2021a07a8f37SSara Sharon 2022f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 2023f92659a1SSara Sharon struct ieee80211_vif *vif) 2024f92659a1SSara Sharon { 2025d0a9123eSJohannes Berg if (vif->bss_conf.mu_mimo_owner) { 2026f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 2027f92659a1SSara Sharon 2028f92659a1SSara Sharon /* 2029f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 2030f92659a1SSara Sharon * the data received from firmware as if it came from the 2031f92659a1SSara Sharon * action frame, so no conversion is needed. 2032f92659a1SSara Sharon */ 2033afe0d181SJohannes Berg ieee80211_update_mu_groups(vif, 0, 2034f92659a1SSara Sharon (u8 *)¬if->membership_status, 2035f92659a1SSara Sharon (u8 *)¬if->user_position); 2036f92659a1SSara Sharon } 2037f92659a1SSara Sharon } 2038f92659a1SSara Sharon 2039f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 2040f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 2041f92659a1SSara Sharon { 2042f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 2043f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 2044f92659a1SSara Sharon 2045f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 2046f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2047f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 2048f92659a1SSara Sharon } 2049f92659a1SSara Sharon 2050514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 2051514c3069SLuca Coelho { 2052514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 2053514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 2054514c3069SLuca Coelho u8 residue_bits; 2055514c3069SLuca Coelho u8 res; 2056514c3069SLuca Coelho 2057514c3069SLuca Coelho if (bit_num <= 5) 2058514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 2059514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 2060514c3069SLuca Coelho 2061514c3069SLuca Coelho /* 2062514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 2063514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 2064514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 2065514c3069SLuca Coelho */ 2066514c3069SLuca Coelho 2067514c3069SLuca Coelho residue_bits = 8 - bit_num; 2068514c3069SLuca Coelho 2069514c3069SLuca Coelho res = (ppe[byte_num + 1] & 2070514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 2071514c3069SLuca Coelho residue_bits; 2072514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 2073514c3069SLuca Coelho 2074514c3069SLuca Coelho return res; 2075514c3069SLuca Coelho } 2076514c3069SLuca Coelho 2077091296d3SMiri Korenblit static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, 2078091296d3SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, 2079cb63eb43SMiri Korenblit u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit, 2080cb63eb43SMiri Korenblit bool inheritance) 2081091296d3SMiri Korenblit { 2082091296d3SMiri Korenblit int i; 2083091296d3SMiri Korenblit 2084091296d3SMiri Korenblit /* 2085091296d3SMiri Korenblit * FW currently supports only nss == MAX_HE_SUPP_NSS 2086091296d3SMiri Korenblit * 2087091296d3SMiri Korenblit * If nss > MAX: we can ignore values we don't support 2088091296d3SMiri Korenblit * If nss < MAX: we can set zeros in other streams 2089091296d3SMiri Korenblit */ 2090091296d3SMiri Korenblit if (nss > MAX_HE_SUPP_NSS) { 20914d8421f2SJason A. Donenfeld IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 2092091296d3SMiri Korenblit MAX_HE_SUPP_NSS); 2093091296d3SMiri Korenblit nss = MAX_HE_SUPP_NSS; 2094091296d3SMiri Korenblit } 2095091296d3SMiri Korenblit 2096091296d3SMiri Korenblit for (i = 0; i < nss; i++) { 2097091296d3SMiri Korenblit u8 ru_index_tmp = ru_index_bitmap << 1; 2098091296d3SMiri Korenblit u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; 2099091296d3SMiri Korenblit u8 bw; 2100091296d3SMiri Korenblit 2101091296d3SMiri Korenblit for (bw = 0; 2102091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2103091296d3SMiri Korenblit bw++) { 2104091296d3SMiri Korenblit ru_index_tmp >>= 1; 2105091296d3SMiri Korenblit 2106cb63eb43SMiri Korenblit /* 2107cb63eb43SMiri Korenblit * According to the 11be spec, if for a specific BW the PPE Thresholds 2108cb63eb43SMiri Korenblit * isn't present - it should inherit the thresholds from the last 2109cb63eb43SMiri Korenblit * BW for which we had PPE Thresholds. In 11ax though, we don't have 2110cb63eb43SMiri Korenblit * this inheritance - continue in this case 2111cb63eb43SMiri Korenblit */ 2112cb63eb43SMiri Korenblit if (!(ru_index_tmp & 1)) { 2113cb63eb43SMiri Korenblit if (inheritance) 2114cb63eb43SMiri Korenblit goto set_thresholds; 2115cb63eb43SMiri Korenblit else 2116091296d3SMiri Korenblit continue; 2117cb63eb43SMiri Korenblit } 2118091296d3SMiri Korenblit 2119091296d3SMiri Korenblit high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2120091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2121091296d3SMiri Korenblit low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2122091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2123091296d3SMiri Korenblit 2124cb63eb43SMiri Korenblit set_thresholds: 2125091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2126091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2127091296d3SMiri Korenblit } 2128091296d3SMiri Korenblit } 2129091296d3SMiri Korenblit } 2130091296d3SMiri Korenblit 2131091296d3SMiri Korenblit static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, 213257974a55SGregory Greenman struct ieee80211_link_sta *link_sta, 2133cb63eb43SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, 2134cb63eb43SMiri Korenblit bool inheritance) 2135091296d3SMiri Korenblit { 213657974a55SGregory Greenman u8 nss = (link_sta->he_cap.ppe_thres[0] & 213757974a55SGregory Greenman IEEE80211_PPE_THRES_NSS_MASK) + 1; 213857974a55SGregory Greenman u8 *ppe = &link_sta->he_cap.ppe_thres[0]; 2139091296d3SMiri Korenblit u8 ru_index_bitmap = 2140091296d3SMiri Korenblit u8_get_bits(*ppe, 2141091296d3SMiri Korenblit IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); 2142091296d3SMiri Korenblit /* Starting after PPE header */ 2143091296d3SMiri Korenblit u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; 2144091296d3SMiri Korenblit 2145cb63eb43SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit, 2146cb63eb43SMiri Korenblit inheritance); 2147091296d3SMiri Korenblit } 2148091296d3SMiri Korenblit 21494df6a075SMiri Korenblit static int 21504df6a075SMiri Korenblit iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, 21514df6a075SMiri Korenblit u8 nominal_padding) 2152091296d3SMiri Korenblit { 2153091296d3SMiri Korenblit int low_th = -1; 2154091296d3SMiri Korenblit int high_th = -1; 2155091296d3SMiri Korenblit int i; 2156091296d3SMiri Korenblit 2157cb63eb43SMiri Korenblit /* all the macros are the same for EHT and HE */ 2158091296d3SMiri Korenblit switch (nominal_padding) { 2159cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US: 2160091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2161091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2162091296d3SMiri Korenblit break; 2163cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US: 2164091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_BPSK; 2165091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2166091296d3SMiri Korenblit break; 2167cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: 2168cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US: 2169091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2170091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_BPSK; 2171091296d3SMiri Korenblit break; 2172091296d3SMiri Korenblit } 2173091296d3SMiri Korenblit 21744df6a075SMiri Korenblit if (low_th < 0 || high_th < 0) 21754df6a075SMiri Korenblit return -EINVAL; 21764df6a075SMiri Korenblit 2177091296d3SMiri Korenblit /* Set the PPE thresholds accordingly */ 2178091296d3SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2179091296d3SMiri Korenblit u8 bw; 2180091296d3SMiri Korenblit 2181091296d3SMiri Korenblit for (bw = 0; 2182091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2183091296d3SMiri Korenblit bw++) { 2184091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2185091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2186091296d3SMiri Korenblit } 2187091296d3SMiri Korenblit } 2188091296d3SMiri Korenblit 21894df6a075SMiri Korenblit return 0; 2190091296d3SMiri Korenblit } 2191091296d3SMiri Korenblit 2192cb63eb43SMiri Korenblit static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext, 2193cb63eb43SMiri Korenblit u8 nominal_padding) 2194cb63eb43SMiri Korenblit { 2195cb63eb43SMiri Korenblit int i; 2196cb63eb43SMiri Korenblit 2197cb63eb43SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2198cb63eb43SMiri Korenblit u8 bw; 2199cb63eb43SMiri Korenblit 2200cb63eb43SMiri Korenblit for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2201cb63eb43SMiri Korenblit bw++) { 2202cb63eb43SMiri Korenblit u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0]; 2203cb63eb43SMiri Korenblit 2204cb63eb43SMiri Korenblit if (nominal_padding > 2205cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2206cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2207cb63eb43SMiri Korenblit qam_th[1] = IWL_HE_PKT_EXT_4096QAM; 2208cb63eb43SMiri Korenblit else if (nominal_padding == 2209cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2210cb63eb43SMiri Korenblit qam_th[0] == IWL_HE_PKT_EXT_NONE && 2211cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2212cb63eb43SMiri Korenblit qam_th[0] = IWL_HE_PKT_EXT_4096QAM; 2213cb63eb43SMiri Korenblit } 2214cb63eb43SMiri Korenblit } 2215cb63eb43SMiri Korenblit } 2216cb63eb43SMiri Korenblit 22174df6a075SMiri Korenblit /* Set the pkt_ext field according to PPE Thresholds element */ 221857974a55SGregory Greenman int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, 221957974a55SGregory Greenman struct ieee80211_link_sta *link_sta, 22204df6a075SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext) 22214df6a075SMiri Korenblit { 22224df6a075SMiri Korenblit u8 nominal_padding; 22234df6a075SMiri Korenblit int i, ret = 0; 22244df6a075SMiri Korenblit 222557974a55SGregory Greenman if (WARN_ON(!link_sta)) 222657974a55SGregory Greenman return -EINVAL; 222757974a55SGregory Greenman 22284df6a075SMiri Korenblit /* Initialize the PPE thresholds to "None" (7), as described in Table 22294df6a075SMiri Korenblit * 9-262ac of 80211.ax/D3.0. 22304df6a075SMiri Korenblit */ 22314df6a075SMiri Korenblit memset(pkt_ext, IWL_HE_PKT_EXT_NONE, 22324df6a075SMiri Korenblit sizeof(struct iwl_he_pkt_ext_v2)); 22334df6a075SMiri Korenblit 223457974a55SGregory Greenman if (link_sta->eht_cap.has_eht) { 22354df6a075SMiri Korenblit nominal_padding = 223657974a55SGregory Greenman u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5], 22374df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK); 22384df6a075SMiri Korenblit 22394df6a075SMiri Korenblit /* If PPE Thresholds exists, parse them into a FW-familiar 22404df6a075SMiri Korenblit * format. 22414df6a075SMiri Korenblit */ 224257974a55SGregory Greenman if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] & 22434df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { 224457974a55SGregory Greenman u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] & 22454df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1; 224657974a55SGregory Greenman u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0]; 22474df6a075SMiri Korenblit u8 ru_index_bitmap = 22484df6a075SMiri Korenblit u16_get_bits(*ppe, 22494df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 22504df6a075SMiri Korenblit /* Starting after PPE header */ 22514df6a075SMiri Korenblit u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; 22524df6a075SMiri Korenblit 22534df6a075SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, 22544df6a075SMiri Korenblit ppe, ppe_pos_bit, true); 225557974a55SGregory Greenman /* EHT PPE Thresholds doesn't exist - set the API according to 225657974a55SGregory Greenman * HE PPE Tresholds 22574df6a075SMiri Korenblit */ 225857974a55SGregory Greenman } else if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 22594df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 22604df6a075SMiri Korenblit /* Even though HE Capabilities IE doesn't contain PPE 22614df6a075SMiri Korenblit * Thresholds for BW 320Mhz, thresholds for this BW will 22624df6a075SMiri Korenblit * be filled in with the same values as 160Mhz, due to 22634df6a075SMiri Korenblit * the inheritance, as required. 22644df6a075SMiri Korenblit */ 226557974a55SGregory Greenman iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 22664df6a075SMiri Korenblit true); 22674df6a075SMiri Korenblit 22684df6a075SMiri Korenblit /* According to the requirements, for MCSs 12-13 the 22694df6a075SMiri Korenblit * maximum value between HE PPE Threshold and Common 22704df6a075SMiri Korenblit * Nominal Packet Padding needs to be taken 22714df6a075SMiri Korenblit */ 22724df6a075SMiri Korenblit iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding); 22734df6a075SMiri Korenblit 22744df6a075SMiri Korenblit /* if PPE Thresholds doesn't present in both EHT IE and HE IE - 22754df6a075SMiri Korenblit * take the Thresholds from Common Nominal Packet Padding field 22764df6a075SMiri Korenblit */ 22774df6a075SMiri Korenblit } else { 22784df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 22794df6a075SMiri Korenblit nominal_padding); 22804df6a075SMiri Korenblit } 228157974a55SGregory Greenman } else if (link_sta->he_cap.has_he) { 22824df6a075SMiri Korenblit /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 228357974a55SGregory Greenman if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 22844df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 228557974a55SGregory Greenman iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 22864df6a075SMiri Korenblit false); 22874df6a075SMiri Korenblit /* PPE Thresholds doesn't exist - set the API PPE values 22884df6a075SMiri Korenblit * according to Common Nominal Packet Padding field. 22894df6a075SMiri Korenblit */ 22904df6a075SMiri Korenblit } else { 22914df6a075SMiri Korenblit nominal_padding = 229257974a55SGregory Greenman u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9], 22934df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 22944df6a075SMiri Korenblit if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) 22954df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 22964df6a075SMiri Korenblit nominal_padding); 22974df6a075SMiri Korenblit } 22984df6a075SMiri Korenblit } 22994df6a075SMiri Korenblit 23004df6a075SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 23014df6a075SMiri Korenblit int bw; 23024df6a075SMiri Korenblit 23034df6a075SMiri Korenblit for (bw = 0; 23044df6a075SMiri Korenblit bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]); 23054df6a075SMiri Korenblit bw++) { 23064df6a075SMiri Korenblit u8 *qam_th = 23074df6a075SMiri Korenblit &pkt_ext->pkt_ext_qam_th[i][bw][0]; 23084df6a075SMiri Korenblit 23094df6a075SMiri Korenblit IWL_DEBUG_HT(mvm, 23104df6a075SMiri Korenblit "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n", 23114df6a075SMiri Korenblit i, bw, qam_th[0], qam_th[1]); 23124df6a075SMiri Korenblit } 23134df6a075SMiri Korenblit } 23144df6a075SMiri Korenblit return ret; 23154df6a075SMiri Korenblit } 23164df6a075SMiri Korenblit 23179c4f15caSMiri Korenblit /* 23189c4f15caSMiri Korenblit * This function sets the MU EDCA parameters ans returns whether MU EDCA 23199c4f15caSMiri Korenblit * is enabled or not 23209c4f15caSMiri Korenblit */ 232155eb1c5fSMiri Korenblit bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, 2322e119e740SEmmanuel Grumbach const struct iwl_mvm_vif_link_info *link_info, 232355eb1c5fSMiri Korenblit struct iwl_he_backoff_conf *trig_based_txf) 23249c4f15caSMiri Korenblit { 23259c4f15caSMiri Korenblit int i; 23269c4f15caSMiri Korenblit /* Mark MU EDCA as enabled, unless none detected on some AC */ 23279c4f15caSMiri Korenblit bool mu_edca_enabled = true; 23289c4f15caSMiri Korenblit 23299c4f15caSMiri Korenblit for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2330e119e740SEmmanuel Grumbach const struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2331e119e740SEmmanuel Grumbach &link_info->queue_params[i].mu_edca_param_rec; 23329c4f15caSMiri Korenblit u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 23339c4f15caSMiri Korenblit 2334e119e740SEmmanuel Grumbach if (!link_info->queue_params[i].mu_edca) { 23359c4f15caSMiri Korenblit mu_edca_enabled = false; 23369c4f15caSMiri Korenblit break; 23379c4f15caSMiri Korenblit } 23389c4f15caSMiri Korenblit 23399c4f15caSMiri Korenblit trig_based_txf[ac].cwmin = 23409c4f15caSMiri Korenblit cpu_to_le16(mu_edca->ecw_min_max & 0xf); 23419c4f15caSMiri Korenblit trig_based_txf[ac].cwmax = 23429c4f15caSMiri Korenblit cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 23439c4f15caSMiri Korenblit trig_based_txf[ac].aifsn = 23449c4f15caSMiri Korenblit cpu_to_le16(mu_edca->aifsn & 0xf); 23459c4f15caSMiri Korenblit trig_based_txf[ac].mu_time = 23469c4f15caSMiri Korenblit cpu_to_le16(mu_edca->mu_edca_timer); 23479c4f15caSMiri Korenblit } 23489c4f15caSMiri Korenblit 23499c4f15caSMiri Korenblit return mu_edca_enabled; 23509c4f15caSMiri Korenblit } 23519c4f15caSMiri Korenblit 23529be162a7SMiri Korenblit bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 23539c4f15caSMiri Korenblit { 23549c4f15caSMiri Korenblit const struct ieee80211_supported_band *sband; 23559c4f15caSMiri Korenblit const struct ieee80211_sta_he_cap *own_he_cap = NULL; 23569c4f15caSMiri Korenblit 23579c4f15caSMiri Korenblit /* This capability is the same for all bands, 23589c4f15caSMiri Korenblit * so take it from one of them. 23599c4f15caSMiri Korenblit */ 23609c4f15caSMiri Korenblit sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 23611ec7291eSJohannes Berg own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 23629c4f15caSMiri Korenblit 23639c4f15caSMiri Korenblit return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] & 23649c4f15caSMiri Korenblit IEEE80211_HE_MAC_CAP2_ACK_EN)); 23659c4f15caSMiri Korenblit } 23669c4f15caSMiri Korenblit 236757974a55SGregory Greenman __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta, 236857974a55SGregory Greenman struct ieee80211_link_sta *link_sta) 23694df6a075SMiri Korenblit { 237057974a55SGregory Greenman u8 *mac_cap_info = 237157974a55SGregory Greenman &link_sta->he_cap.he_cap_elem.mac_cap_info[0]; 23724df6a075SMiri Korenblit __le32 htc_flags = 0; 23734df6a075SMiri Korenblit 23744df6a075SMiri Korenblit if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) 23754df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 23764df6a075SMiri Korenblit if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 23774df6a075SMiri Korenblit (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 23784df6a075SMiri Korenblit u8 link_adap = 23794df6a075SMiri Korenblit ((mac_cap_info[2] & 23804df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 23814df6a075SMiri Korenblit (mac_cap_info[1] & 23824df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 23834df6a075SMiri Korenblit 23844df6a075SMiri Korenblit if (link_adap == 2) 23854df6a075SMiri Korenblit htc_flags |= 23864df6a075SMiri Korenblit cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 23874df6a075SMiri Korenblit else if (link_adap == 3) 23884df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 23894df6a075SMiri Korenblit } 23904df6a075SMiri Korenblit if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 23914df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 23924df6a075SMiri Korenblit if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 23934df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 23944df6a075SMiri Korenblit if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 23954df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 23964df6a075SMiri Korenblit 23974df6a075SMiri Korenblit return htc_flags; 23984df6a075SMiri Korenblit } 23994df6a075SMiri Korenblit 2400514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 2401514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 2402514c3069SLuca Coelho { 2403514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 240442506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { 2405514c3069SLuca Coelho .sta_id = sta_id, 2406514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 2407dd56e902SJohn Crispin .bss_color = vif->bss_conf.he_bss_color.color, 2408514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 2409514c3069SLuca Coelho .frame_time_rts_th = 2410514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 2411514c3069SLuca Coelho }; 241242506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; 241342506dd2SJohannes Berg u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); 241442506dd2SJohannes Berg u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); 241542506dd2SJohannes Berg int size; 2416514c3069SLuca Coelho struct ieee80211_sta *sta; 2417514c3069SLuca Coelho u32 flags; 2418514c3069SLuca Coelho int i; 241942506dd2SJohannes Berg void *cmd; 242042506dd2SJohannes Berg 242142506dd2SJohannes Berg if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) 242242506dd2SJohannes Berg ver = 1; 242342506dd2SJohannes Berg 242442506dd2SJohannes Berg switch (ver) { 242542506dd2SJohannes Berg case 1: 242642506dd2SJohannes Berg /* same layout as v2 except some data at the end */ 242742506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 242842506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v1); 242942506dd2SJohannes Berg break; 243042506dd2SJohannes Berg case 2: 243142506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 243242506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v2); 243342506dd2SJohannes Berg break; 243442506dd2SJohannes Berg case 3: 243542506dd2SJohannes Berg cmd = &sta_ctxt_cmd; 243642506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v3); 243742506dd2SJohannes Berg break; 243842506dd2SJohannes Berg default: 243942506dd2SJohannes Berg IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); 244042506dd2SJohannes Berg return; 244142506dd2SJohannes Berg } 2442514c3069SLuca Coelho 2443514c3069SLuca Coelho rcu_read_lock(); 2444514c3069SLuca Coelho 2445514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 244612d47f0eSAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) { 2447514c3069SLuca Coelho rcu_read_unlock(); 2448514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 2449514c3069SLuca Coelho return; 2450514c3069SLuca Coelho } 2451514c3069SLuca Coelho 2452046d2e7cSSriram R if (!sta->deflink.he_cap.has_he) { 2453514c3069SLuca Coelho rcu_read_unlock(); 2454514c3069SLuca Coelho return; 2455514c3069SLuca Coelho } 2456514c3069SLuca Coelho 2457514c3069SLuca Coelho flags = 0; 2458514c3069SLuca Coelho 24594f58121dSIlan Peer /* Block 26-tone RU OFDMA transmissions */ 2460650cadb7SGregory Greenman if (mvmvif->deflink.he_ru_2mhz_block) 24614f58121dSIlan Peer flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 24624f58121dSIlan Peer 2463514c3069SLuca Coelho /* HTC flags */ 246457974a55SGregory Greenman sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta, &sta->deflink); 2465514c3069SLuca Coelho 24664df6a075SMiri Korenblit /* PPE Thresholds */ 246757974a55SGregory Greenman if (!iwl_mvm_set_sta_pkt_ext(mvm, &sta->deflink, &sta_ctxt_cmd.pkt_ext)) 2468cb63eb43SMiri Korenblit flags |= STA_CTXT_HE_PACKET_EXT; 246973f23d91SShaul Triebitz 2470046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 247173f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 247273f23d91SShaul Triebitz flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 247373f23d91SShaul Triebitz 2474046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 247573f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN) 247673f23d91SShaul Triebitz flags |= STA_CTXT_HE_ACK_ENABLED; 247773f23d91SShaul Triebitz 2478514c3069SLuca Coelho rcu_read_unlock(); 2479514c3069SLuca Coelho 2480e119e740SEmmanuel Grumbach if (iwl_mvm_set_fw_mu_edca_params(mvm, &mvmvif->deflink, 24819c4f15caSMiri Korenblit &sta_ctxt_cmd.trig_based_txf[0])) 2482514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 2483514c3069SLuca Coelho 2484514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2485514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2486514c3069SLuca Coelho 2487514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2488514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2489514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2490514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2491514c3069SLuca Coelho } 2492514c3069SLuca Coelho 24939c4f15caSMiri Korenblit if (!iwl_mvm_is_nic_ack_enabled(mvm, vif)) 2494ee1a02d7SShaul Triebitz flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2495ee1a02d7SShaul Triebitz 2496918cbf39SSara Sharon if (vif->bss_conf.nontransmitted) { 2497918cbf39SSara Sharon flags |= STA_CTXT_HE_REF_BSSID_VALID; 2498918cbf39SSara Sharon ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2499918cbf39SSara Sharon vif->bss_conf.transmitter_bssid); 2500d14ae796SSara Sharon sta_ctxt_cmd.max_bssid_indicator = 2501d14ae796SSara Sharon vif->bss_conf.bssid_indicator; 2502d14ae796SSara Sharon sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2503d14ae796SSara Sharon sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2504d14ae796SSara Sharon sta_ctxt_cmd.profile_periodicity = 2505d14ae796SSara Sharon vif->bss_conf.profile_periodicity; 2506918cbf39SSara Sharon } 2507514c3069SLuca Coelho 2508514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2509514c3069SLuca Coelho 251042506dd2SJohannes Berg if (ver < 3) { 251142506dd2SJohannes Berg /* fields before pkt_ext */ 251242506dd2SJohannes Berg BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != 251342506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); 251442506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, 251542506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd), pkt_ext)); 251642506dd2SJohannes Berg 251742506dd2SJohannes Berg /* pkt_ext */ 251842506dd2SJohannes Berg for (i = 0; 251942506dd2SJohannes Berg i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); 252042506dd2SJohannes Berg i++) { 252142506dd2SJohannes Berg u8 bw; 252242506dd2SJohannes Berg 252342506dd2SJohannes Berg for (bw = 0; 252442506dd2SJohannes Berg bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); 252542506dd2SJohannes Berg bw++) { 252642506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != 252742506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); 252842506dd2SJohannes Berg 252942506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], 253042506dd2SJohannes Berg &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], 253142506dd2SJohannes Berg sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); 253242506dd2SJohannes Berg } 253342506dd2SJohannes Berg } 253442506dd2SJohannes Berg 253542506dd2SJohannes Berg /* fields after pkt_ext */ 253642506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - 253742506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != 253842506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2) - 253942506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); 254042506dd2SJohannes Berg memcpy((u8 *)&sta_ctxt_cmd_v2 + 254142506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), 254242506dd2SJohannes Berg (u8 *)&sta_ctxt_cmd + 254342506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext), 254442506dd2SJohannes Berg sizeof(sta_ctxt_cmd) - 254542506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); 254642506dd2SJohannes Berg sta_ctxt_cmd_v2.reserved3 = 0; 254742506dd2SJohannes Berg } 254842506dd2SJohannes Berg 254942506dd2SJohannes Berg if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) 2550514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2551514c3069SLuca Coelho } 2552514c3069SLuca Coelho 2553660eba5aSMiri Korenblit void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 255423673041SMiri Korenblit u32 duration_override, unsigned int link_id) 2555af84ac57SJohannes Berg { 2556af84ac57SJohannes Berg u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2557af84ac57SJohannes Berg u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2558af84ac57SJohannes Berg 2559af84ac57SJohannes Berg if (duration_override > duration) 2560af84ac57SJohannes Berg duration = duration_override; 2561af84ac57SJohannes Berg 2562af84ac57SJohannes Berg /* Try really hard to protect the session and hear a beacon 2563af84ac57SJohannes Berg * The new session protection command allows us to protect the 2564af84ac57SJohannes Berg * session for a much longer time since the firmware will internally 2565af84ac57SJohannes Berg * create two events: a 300TU one with a very high priority that 2566af84ac57SJohannes Berg * won't be fragmented which should be enough for 99% of the cases, 2567af84ac57SJohannes Berg * and another one (which we configure here to be 900TU long) which 2568af84ac57SJohannes Berg * will have a slightly lower priority, but more importantly, can be 2569af84ac57SJohannes Berg * fragmented so that it'll allow other activities to run. 2570af84ac57SJohannes Berg */ 2571af84ac57SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 2572af84ac57SJohannes Berg IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2573af84ac57SJohannes Berg iwl_mvm_schedule_session_protection(mvm, vif, 900, 257423673041SMiri Korenblit min_duration, false, 257523673041SMiri Korenblit link_id); 2576af84ac57SJohannes Berg else 2577af84ac57SJohannes Berg iwl_mvm_protect_session(mvm, vif, duration, 2578af84ac57SJohannes Berg min_duration, 500, false); 2579af84ac57SJohannes Berg } 2580af84ac57SJohannes Berg 2581660eba5aSMiri Korenblit /* Handle association common part to MLD and non-MLD modes */ 2582660eba5aSMiri Korenblit void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm, 2583660eba5aSMiri Korenblit struct ieee80211_vif *vif, 2584660eba5aSMiri Korenblit u64 changes) 2585660eba5aSMiri Korenblit { 2586660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2587660eba5aSMiri Korenblit int ret; 2588c1e458b9SIlan Peer int link_id; 2589660eba5aSMiri Korenblit 2590660eba5aSMiri Korenblit /* The firmware tracks the MU-MIMO group on its own. 2591660eba5aSMiri Korenblit * However, on HW restart we should restore this data. 2592660eba5aSMiri Korenblit */ 2593660eba5aSMiri Korenblit if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2594660eba5aSMiri Korenblit (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { 2595660eba5aSMiri Korenblit ret = iwl_mvm_update_mu_groups(mvm, vif); 2596660eba5aSMiri Korenblit if (ret) 2597660eba5aSMiri Korenblit IWL_ERR(mvm, 2598660eba5aSMiri Korenblit "failed to update VHT MU_MIMO groups\n"); 2599660eba5aSMiri Korenblit } 2600660eba5aSMiri Korenblit 2601660eba5aSMiri Korenblit iwl_mvm_recalc_multicast(mvm); 2602660eba5aSMiri Korenblit 2603660eba5aSMiri Korenblit /* reset rssi values */ 2604c1e458b9SIlan Peer for_each_mvm_vif_valid_link(mvmvif, link_id) 2605c1e458b9SIlan Peer mvmvif->link[link_id]->bf_data.ave_beacon_signal = 0; 2606660eba5aSMiri Korenblit 2607660eba5aSMiri Korenblit iwl_mvm_bt_coex_vif_change(mvm); 26081a3e7039SGregory Greenman iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2609660eba5aSMiri Korenblit IEEE80211_SMPS_AUTOMATIC); 2610660eba5aSMiri Korenblit if (fw_has_capa(&mvm->fw->ucode_capa, 2611660eba5aSMiri Korenblit IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2612660eba5aSMiri Korenblit iwl_mvm_config_scan(mvm); 2613660eba5aSMiri Korenblit } 2614660eba5aSMiri Korenblit 2615660eba5aSMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 26161a3e7039SGregory Greenman void 26171a3e7039SGregory Greenman iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm, 2618660eba5aSMiri Korenblit struct ieee80211_vif *vif, 26191a3e7039SGregory Greenman struct ieee80211_bss_conf *link_conf, 2620660eba5aSMiri Korenblit u64 changes) 2621660eba5aSMiri Korenblit { 2622660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2623660eba5aSMiri Korenblit int ret; 2624660eba5aSMiri Korenblit 2625660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BEACON_INFO) { 2626660eba5aSMiri Korenblit /* We received a beacon from the associated AP so 2627660eba5aSMiri Korenblit * remove the session protection. 2628660eba5aSMiri Korenblit */ 2629660eba5aSMiri Korenblit iwl_mvm_stop_session_protection(mvm, vif); 2630660eba5aSMiri Korenblit 2631660eba5aSMiri Korenblit iwl_mvm_sf_update(mvm, vif, false); 263287f5b5f2SJohannes Berg WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 2633660eba5aSMiri Korenblit } 2634660eba5aSMiri Korenblit 2635660eba5aSMiri Korenblit if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2636660eba5aSMiri Korenblit /* Send power command on every beacon change, 2637660eba5aSMiri Korenblit * because we may have not enabled beacon abort yet. 2638660eba5aSMiri Korenblit */ 2639660eba5aSMiri Korenblit BSS_CHANGED_BEACON_INFO)) { 2640660eba5aSMiri Korenblit ret = iwl_mvm_power_update_mac(mvm); 2641660eba5aSMiri Korenblit if (ret) 2642660eba5aSMiri Korenblit IWL_ERR(mvm, "failed to update power mode\n"); 2643660eba5aSMiri Korenblit } 2644660eba5aSMiri Korenblit 2645660eba5aSMiri Korenblit if (changes & BSS_CHANGED_CQM) { 2646c1e458b9SIlan Peer struct iwl_mvm_vif_link_info *link_info = 2647c1e458b9SIlan Peer mvmvif->link[link_conf->link_id]; 2648c1e458b9SIlan Peer 2649c1e458b9SIlan Peer IWL_DEBUG_MAC80211(mvm, "CQM info_changed\n"); 2650c1e458b9SIlan Peer if (link_info) 2651c1e458b9SIlan Peer link_info->bf_data.last_cqm_event = 0; 2652c1e458b9SIlan Peer 2653c1e458b9SIlan Peer if (mvmvif->bf_enabled) { 265422c58834SGregory Greenman /* FIXME: need to update per link when FW API will 265522c58834SGregory Greenman * support it 265622c58834SGregory Greenman */ 265787f5b5f2SJohannes Berg ret = iwl_mvm_enable_beacon_filter(mvm, vif); 2658660eba5aSMiri Korenblit if (ret) 2659660eba5aSMiri Korenblit IWL_ERR(mvm, 2660660eba5aSMiri Korenblit "failed to update CQM thresholds\n"); 2661660eba5aSMiri Korenblit } 2662660eba5aSMiri Korenblit } 2663660eba5aSMiri Korenblit 2664660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BANDWIDTH) 26651a3e7039SGregory Greenman iwl_mvm_update_link_smps(vif, link_conf); 2666660eba5aSMiri Korenblit } 2667660eba5aSMiri Korenblit 2668e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2669e705c121SKalle Valo struct ieee80211_vif *vif, 2670e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 26717b7090b4SJohannes Berg u64 changes) 2672e705c121SKalle Valo { 2673e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2674e705c121SKalle Valo int ret; 2675b6e3d1baSAnjaneyulu int i; 2676e705c121SKalle Valo 2677e705c121SKalle Valo /* 2678cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend 2679cdaba917SEmmanuel Grumbach * on the beacon interval, which was not known when the station 2680cdaba917SEmmanuel Grumbach * interface was added. 2681e705c121SKalle Valo */ 2682f276e20bSJohannes Berg if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { 2683cb63eb43SMiri Korenblit if ((vif->bss_conf.he_support && 268483f57c93SJohannes Berg !iwlwifi_mod_params.disable_11ax)) 2685650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 2686514c3069SLuca Coelho 2687e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2688514c3069SLuca Coelho } 2689e705c121SKalle Valo 269040ecdd01SShaul Triebitz /* Update MU EDCA params */ 269140ecdd01SShaul Triebitz if (changes & BSS_CHANGED_QOS && mvmvif->associated && 2692cb63eb43SMiri Korenblit vif->cfg.assoc && 269383f57c93SJohannes Berg (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax)) 2694650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 269540ecdd01SShaul Triebitz 2696e705c121SKalle Valo /* 2697e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2698e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2699e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2700e705c121SKalle Valo * branch for disassociation below. 2701e705c121SKalle Valo */ 2702e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2703650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2704e705c121SKalle Valo 2705650cadb7SGregory Greenman ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid); 2706e705c121SKalle Valo if (ret) 2707e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2708e705c121SKalle Valo 2709e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2710650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2711f276e20bSJohannes Berg mvmvif->associated = vif->cfg.assoc; 2712e705c121SKalle Valo 2713e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2714f276e20bSJohannes Berg if (vif->cfg.assoc) { 2715e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2716e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2717b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 2718b6e3d1baSAnjaneyulu memset(&mvmvif->link[i]->beacon_stats, 0, 2719b6e3d1baSAnjaneyulu sizeof(mvmvif->link[i]->beacon_stats)); 2720e705c121SKalle Valo 2721e705c121SKalle Valo /* add quota for this interface */ 2722e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2723e705c121SKalle Valo if (ret) { 2724e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2725e705c121SKalle Valo return; 2726e705c121SKalle Valo } 2727e705c121SKalle Valo 2728e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2729fe959c7bSEmmanuel Grumbach &mvm->status) && 2730fe959c7bSEmmanuel Grumbach !fw_has_capa(&mvm->fw->ucode_capa, 2731fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2732e705c121SKalle Valo /* 2733e705c121SKalle Valo * If we're restarting then the firmware will 2734e705c121SKalle Valo * obviously have lost synchronisation with 2735e705c121SKalle Valo * the AP. It will attempt to synchronise by 2736e705c121SKalle Valo * itself, but we can make it more reliable by 2737e705c121SKalle Valo * scheduling a session protection time event. 2738e705c121SKalle Valo * 2739e705c121SKalle Valo * The firmware needs to receive a beacon to 2740e705c121SKalle Valo * catch up with synchronisation, use 110% of 2741e705c121SKalle Valo * the beacon interval. 2742e705c121SKalle Valo * 2743e705c121SKalle Valo * Set a large maximum delay to allow for more 2744e705c121SKalle Valo * than a single interface. 2745fe959c7bSEmmanuel Grumbach * 2746fe959c7bSEmmanuel Grumbach * For new firmware versions, rely on the 2747fe959c7bSEmmanuel Grumbach * firmware. This is relevant for DCM scenarios 2748fe959c7bSEmmanuel Grumbach * only anyway. 2749e705c121SKalle Valo */ 2750e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2751e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2752e705c121SKalle Valo 5 * dur, false); 2753af84ac57SJohannes Berg } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2754af84ac57SJohannes Berg &mvm->status) && 2755af84ac57SJohannes Berg !vif->bss_conf.dtim_period) { 2756af84ac57SJohannes Berg /* 2757af84ac57SJohannes Berg * If we're not restarting and still haven't 2758af84ac57SJohannes Berg * heard a beacon (dtim period unknown) then 2759af84ac57SJohannes Berg * make sure we still have enough minimum time 2760af84ac57SJohannes Berg * remaining in the time event, since the auth 2761af84ac57SJohannes Berg * might actually have taken quite a while 2762af84ac57SJohannes Berg * (especially for SAE) and so the remaining 2763af84ac57SJohannes Berg * time could be small without us having heard 2764af84ac57SJohannes Berg * a beacon yet. 2765af84ac57SJohannes Berg */ 276623673041SMiri Korenblit iwl_mvm_protect_assoc(mvm, vif, 0, 0); 2767e705c121SKalle Valo } 2768e705c121SKalle Valo 2769e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2770e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2771e705c121SKalle Valo if (vif->p2p) { 2772e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2773e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 27741a3e7039SGregory Greenman IEEE80211_SMPS_DYNAMIC, 0); 2775e705c121SKalle Valo } 2776650cadb7SGregory Greenman } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) { 27776d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_disassociated(mvm); 2778e705c121SKalle Valo /* 2779e705c121SKalle Valo * If update fails - SF might be running in associated 2780e705c121SKalle Valo * mode while disassociated - which is forbidden. 2781e705c121SKalle Valo */ 278269e508b4SIlan Peer ret = iwl_mvm_sf_update(mvm, vif, false); 278369e508b4SIlan Peer WARN_ONCE(ret && 278469e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 278569e508b4SIlan Peer &mvm->status), 2786e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2787e705c121SKalle Valo 27886b28f978SEmmanuel Grumbach /* 27896b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 27906b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 27916b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 27926b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 27936b28f978SEmmanuel Grumbach * associated, we would remove the station here and 27946b28f978SEmmanuel Grumbach * this would fail the recovery. 27956b28f978SEmmanuel Grumbach */ 27966b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 27976b28f978SEmmanuel Grumbach &mvm->status)) { 27985c75a208SJohannes Berg /* first remove remaining keys */ 2799ba9eef6bSGregory Greenman iwl_mvm_sec_key_remove_ap(mvm, vif, 2800072573f6SJohannes Berg &mvmvif->deflink, 0); 28015c75a208SJohannes Berg 28026b28f978SEmmanuel Grumbach /* 28036b28f978SEmmanuel Grumbach * Remove AP station now that 28046b28f978SEmmanuel Grumbach * the MAC is unassoc 28056b28f978SEmmanuel Grumbach */ 28066b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 2807650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id); 2808e705c121SKalle Valo if (ret) 28096b28f978SEmmanuel Grumbach IWL_ERR(mvm, 28106b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2811e705c121SKalle Valo 2812650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA; 28136b28f978SEmmanuel Grumbach } 28146b28f978SEmmanuel Grumbach 2815e705c121SKalle Valo /* remove quota for this interface */ 2816e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2817e705c121SKalle Valo if (ret) 2818e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2819e705c121SKalle Valo 2820e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2821e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2822e705c121SKalle Valo if (ret) 2823e705c121SKalle Valo IWL_ERR(mvm, 2824e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2825e705c121SKalle Valo vif->addr); 2826e705c121SKalle Valo } 2827e705c121SKalle Valo 2828660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes); 2829a07a8f37SSara Sharon } 2830a07a8f37SSara Sharon 28311a3e7039SGregory Greenman iwl_mvm_bss_info_changed_station_common(mvm, vif, &vif->bss_conf, 28321a3e7039SGregory Greenman changes); 2833b45242c9SAvraham Stern } 2834b45242c9SAvraham Stern 2835f947b62cSMiri Korenblit bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw, 2836f947b62cSMiri Korenblit struct ieee80211_vif *vif, 2837f947b62cSMiri Korenblit int *ret) 2838f947b62cSMiri Korenblit { 2839f947b62cSMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2840f947b62cSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2841f947b62cSMiri Korenblit int i; 2842e705c121SKalle Valo 2843f947b62cSMiri Korenblit lockdep_assert_held(&mvm->mutex); 2844f947b62cSMiri Korenblit 2845f947b62cSMiri Korenblit mvmvif->ap_assoc_sta_count = 0; 2846f947b62cSMiri Korenblit 2847f947b62cSMiri Korenblit /* must be set before quota calculations */ 2848f947b62cSMiri Korenblit mvmvif->ap_ibss_active = true; 2849f947b62cSMiri Korenblit 2850f947b62cSMiri Korenblit /* send all the early keys to the device now */ 2851f947b62cSMiri Korenblit for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2852f947b62cSMiri Korenblit struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2853f947b62cSMiri Korenblit 2854f947b62cSMiri Korenblit if (!key) 2855f947b62cSMiri Korenblit continue; 2856f947b62cSMiri Korenblit 2857f947b62cSMiri Korenblit mvmvif->ap_early_keys[i] = NULL; 2858f947b62cSMiri Korenblit 2859f947b62cSMiri Korenblit *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2860f947b62cSMiri Korenblit if (*ret) 2861f947b62cSMiri Korenblit return true; 2862e705c121SKalle Valo } 2863e705c121SKalle Valo 2864f947b62cSMiri Korenblit if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 2865f947b62cSMiri Korenblit iwl_mvm_vif_set_low_latency(mvmvif, true, 2866f947b62cSMiri Korenblit LOW_LATENCY_VIF_TYPE); 2867f947b62cSMiri Korenblit iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 2868e705c121SKalle Valo } 2869e705c121SKalle Valo 2870f947b62cSMiri Korenblit /* power updated needs to be done before quotas */ 2871f947b62cSMiri Korenblit iwl_mvm_power_update_mac(mvm); 2872e705c121SKalle Valo 2873f947b62cSMiri Korenblit return false; 2874e705c121SKalle Valo } 2875e705c121SKalle Valo 2876e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2877ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2878b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2879e705c121SKalle Valo { 2880e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2881e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2882f947b62cSMiri Korenblit int ret; 2883e705c121SKalle Valo 2884e705c121SKalle Valo mutex_lock(&mvm->mutex); 2885e705c121SKalle Valo 2886e705c121SKalle Valo /* 2887cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend on 2888cdaba917SEmmanuel Grumbach * the beacon interval, which was not known when the AP interface 2889cdaba917SEmmanuel Grumbach * was added. 2890e705c121SKalle Valo */ 2891e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2892e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2893e705c121SKalle Valo 289436cf5377SGregory Greenman /* For older devices need to send beacon template before adding mac 289536cf5377SGregory Greenman * context. For the newer, the beacon is a resource that belongs to a 289636cf5377SGregory Greenman * MAC, so need to send beacon template after adding the mac. 289736cf5377SGregory Greenman */ 289836cf5377SGregory Greenman if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) { 2899e705c121SKalle Valo /* Add the mac context */ 2900e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2901e705c121SKalle Valo if (ret) 2902e705c121SKalle Valo goto out_unlock; 2903e705c121SKalle Valo 290436cf5377SGregory Greenman /* Send the beacon template */ 290536cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 290636cf5377SGregory Greenman if (ret) 290736cf5377SGregory Greenman goto out_unlock; 290836cf5377SGregory Greenman } else { 290936cf5377SGregory Greenman /* Send the beacon template */ 291036cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 291136cf5377SGregory Greenman if (ret) 291236cf5377SGregory Greenman goto out_unlock; 2913e705c121SKalle Valo 2914e705c121SKalle Valo /* Add the mac context */ 2915e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2916e705c121SKalle Valo if (ret) 2917e705c121SKalle Valo goto out_unlock; 291836cf5377SGregory Greenman } 2919e705c121SKalle Valo 2920e705c121SKalle Valo /* Perform the binding */ 2921e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2922e705c121SKalle Valo if (ret) 2923e705c121SKalle Valo goto out_remove; 2924e705c121SKalle Valo 292563dd5d02SSara Sharon /* 292663dd5d02SSara Sharon * This is not very nice, but the simplest: 292763dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 292863dd5d02SSara Sharon * cause assert 0x2b00. 292963dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 293063dd5d02SSara Sharon * the TLV 293163dd5d02SSara Sharon */ 293263dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2933ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2934ced19f26SSara Sharon if (ret) 2935ced19f26SSara Sharon goto out_unbind; 293663dd5d02SSara Sharon /* 293763dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 293863dd5d02SSara Sharon * events are added and applied to the scheduler 293963dd5d02SSara Sharon */ 2940e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 294163dd5d02SSara Sharon if (ret) { 294263dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 294363dd5d02SSara Sharon goto out_unbind; 294463dd5d02SSara Sharon } 294563dd5d02SSara Sharon } else { 294663dd5d02SSara Sharon /* 294763dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 294863dd5d02SSara Sharon * events are added and applied to the scheduler 294963dd5d02SSara Sharon */ 295075fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2951e705c121SKalle Valo if (ret) 295263dd5d02SSara Sharon goto out_unbind; 295375fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 295463dd5d02SSara Sharon if (ret) { 295563dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 295663dd5d02SSara Sharon goto out_unbind; 295763dd5d02SSara Sharon } 295863dd5d02SSara Sharon } 295926d6c16bSSara Sharon 2960f947b62cSMiri Korenblit if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) 2961f947b62cSMiri Korenblit goto out_failed; 2962e705c121SKalle Valo 2963e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2964e705c121SKalle Valo if (ret) 2965f947b62cSMiri Korenblit goto out_failed; 2966e705c121SKalle Valo 2967e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2968e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2969e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2970e705c121SKalle Valo 2971e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2972e705c121SKalle Valo 2973e705c121SKalle Valo /* we don't support TDLS during DCM */ 2974e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2975e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2976e705c121SKalle Valo 2977fd940de7SAvraham Stern iwl_mvm_ftm_restart_responder(mvm, vif, &vif->bss_conf); 2978b73f9a4aSJohannes Berg 2979e705c121SKalle Valo goto out_unlock; 2980e705c121SKalle Valo 2981f947b62cSMiri Korenblit out_failed: 2982e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2983e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2984e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2985ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2986e705c121SKalle Valo out_unbind: 2987e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2988e705c121SKalle Valo out_remove: 2989e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2990e705c121SKalle Valo out_unlock: 2991e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2992e705c121SKalle Valo return ret; 2993e705c121SKalle Valo } 2994e705c121SKalle Valo 2995ae7ba17bSShaul Triebitz static int iwl_mvm_start_ap(struct ieee80211_hw *hw, 2996ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2997b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2998ae7ba17bSShaul Triebitz { 2999b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, link_conf); 3000ae7ba17bSShaul Triebitz } 3001ae7ba17bSShaul Triebitz 3002ae7ba17bSShaul Triebitz static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, 3003e705c121SKalle Valo struct ieee80211_vif *vif) 3004e705c121SKalle Valo { 3005b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); 3006ae7ba17bSShaul Triebitz } 3007ae7ba17bSShaul Triebitz 3008fd1a54c1SMiri Korenblit /* Common part for MLD and non-MLD ops */ 3009fd1a54c1SMiri Korenblit void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm, 3010fd1a54c1SMiri Korenblit struct ieee80211_vif *vif) 3011ae7ba17bSShaul Triebitz { 3012e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3013e705c121SKalle Valo 3014fd1a54c1SMiri Korenblit lockdep_assert_held(&mvm->mutex); 3015e705c121SKalle Valo 3016fd1a54c1SMiri Korenblit iwl_mvm_prepare_mac_removal(mvm, vif); 3017e705c121SKalle Valo 3018e705c121SKalle Valo /* Handle AP stop while in CSA */ 3019e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 3020e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 3021e705c121SKalle Valo &mvmvif->time_event_data); 3022e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 3023e705c121SKalle Valo mvmvif->csa_countdown = false; 3024e705c121SKalle Valo } 3025e705c121SKalle Valo 3026e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 3027e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 3028e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 3029e705c121SKalle Valo } 3030e705c121SKalle Valo 3031e705c121SKalle Valo mvmvif->ap_ibss_active = false; 3032e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 3033e705c121SKalle Valo 303447242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 303547242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 303647242744STova Mussai LOW_LATENCY_VIF_TYPE); 303747242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 303847242744STova Mussai } 303947242744STova Mussai 3040e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 3041fd1a54c1SMiri Korenblit } 3042fd1a54c1SMiri Korenblit 3043fd1a54c1SMiri Korenblit static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 3044fd1a54c1SMiri Korenblit struct ieee80211_vif *vif, 3045fd1a54c1SMiri Korenblit struct ieee80211_bss_conf *link_conf) 3046fd1a54c1SMiri Korenblit { 3047fd1a54c1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3048fd1a54c1SMiri Korenblit 3049fd1a54c1SMiri Korenblit mutex_lock(&mvm->mutex); 3050fd1a54c1SMiri Korenblit 3051fd1a54c1SMiri Korenblit iwl_mvm_stop_ap_ibss_common(mvm, vif); 3052e705c121SKalle Valo 3053e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 3054e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 3055e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 3056e705c121SKalle Valo 3057e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3058ced19f26SSara Sharon 3059be82ecd3SAvraham Stern iwl_mvm_ftm_responder_clear(mvm, vif); 3060be82ecd3SAvraham Stern 3061ced19f26SSara Sharon /* 3062ced19f26SSara Sharon * This is not very nice, but the simplest: 3063ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 3064ced19f26SSara Sharon * cause assert 0x2b00. 3065ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 3066ced19f26SSara Sharon * bcast station). 3067ced19f26SSara Sharon * So make the order of removal depend on the TLV 3068ced19f26SSara Sharon */ 3069ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 307026d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 3071e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 3072ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 3073ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 3074e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3075e705c121SKalle Valo 3076e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3077e705c121SKalle Valo 3078e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 3079e705c121SKalle Valo 3080e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3081e705c121SKalle Valo } 3082e705c121SKalle Valo 3083ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, 3084ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 3085b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 3086ae7ba17bSShaul Triebitz { 3087b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, link_conf); 3088ae7ba17bSShaul Triebitz } 3089ae7ba17bSShaul Triebitz 3090ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, 3091ae7ba17bSShaul Triebitz struct ieee80211_vif *vif) 3092ae7ba17bSShaul Triebitz { 3093b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); 3094ae7ba17bSShaul Triebitz } 3095ae7ba17bSShaul Triebitz 3096e705c121SKalle Valo static void 3097e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 3098e705c121SKalle Valo struct ieee80211_vif *vif, 3099e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 31007b7090b4SJohannes Berg u64 changes) 3101e705c121SKalle Valo { 3102e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3103e705c121SKalle Valo 3104e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 3105e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 3106e705c121SKalle Valo return; 3107e705c121SKalle Valo 3108e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 3109e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 3110e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 3111e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 3112e705c121SKalle Valo 3113e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 3114e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 311536cf5377SGregory Greenman iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf)) 3116e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 3117e705c121SKalle Valo 3118b73f9a4aSJohannes Berg if (changes & BSS_CHANGED_FTM_RESPONDER) { 3119fd940de7SAvraham Stern int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf); 3120b73f9a4aSJohannes Berg 3121b73f9a4aSJohannes Berg if (ret) 3122b73f9a4aSJohannes Berg IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 3123b73f9a4aSJohannes Berg ret); 3124b73f9a4aSJohannes Berg } 3125b73f9a4aSJohannes Berg 3126e705c121SKalle Valo } 3127e705c121SKalle Valo 3128e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 3129e705c121SKalle Valo struct ieee80211_vif *vif, 3130e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 31317b7090b4SJohannes Berg u64 changes) 3132e705c121SKalle Valo { 3133e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3134e705c121SKalle Valo 3135e705c121SKalle Valo mutex_lock(&mvm->mutex); 3136e705c121SKalle Valo 3137f276e20bSJohannes Berg if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 3138e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 3139e705c121SKalle Valo 3140e705c121SKalle Valo switch (vif->type) { 3141e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3142df7e3098SMiri Korenblit iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 3143e705c121SKalle Valo break; 3144e705c121SKalle Valo case NL80211_IFTYPE_AP: 3145e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3146df7e3098SMiri Korenblit iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 3147e705c121SKalle Valo break; 314891b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 314991b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 315091b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 315191b08c2dSAviya Erenfeld break; 3152e705c121SKalle Valo default: 3153e705c121SKalle Valo /* shouldn't happen */ 3154e705c121SKalle Valo WARN_ON_ONCE(1); 3155e705c121SKalle Valo } 3156e705c121SKalle Valo 31579aae43a4SJohannes Berg if (changes & BSS_CHANGED_TXPOWER) { 31589aae43a4SJohannes Berg IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 31599aae43a4SJohannes Berg bss_conf->txpower); 31609aae43a4SJohannes Berg iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 31619aae43a4SJohannes Berg } 31629aae43a4SJohannes Berg 3163e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3164e705c121SKalle Valo } 3165e705c121SKalle Valo 3166cbce62a3SMiri Korenblit int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3167e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 3168e705c121SKalle Valo { 3169e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3170e705c121SKalle Valo int ret; 3171e705c121SKalle Valo 3172e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 3173e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 3174e705c121SKalle Valo return -EINVAL; 3175e705c121SKalle Valo 3176e705c121SKalle Valo mutex_lock(&mvm->mutex); 3177e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 3178e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3179e705c121SKalle Valo 3180e705c121SKalle Valo return ret; 3181e705c121SKalle Valo } 3182e705c121SKalle Valo 3183cbce62a3SMiri Korenblit void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 3184e705c121SKalle Valo struct ieee80211_vif *vif) 3185e705c121SKalle Valo { 3186e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3187e705c121SKalle Valo 3188e705c121SKalle Valo mutex_lock(&mvm->mutex); 3189e705c121SKalle Valo 3190e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3191e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 3192e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 3193e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 3194e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 3195e705c121SKalle Valo * To handle that, simply return if the scan is not running. 3196e705c121SKalle Valo */ 3197e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 3198e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 3199e705c121SKalle Valo 3200e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3201e705c121SKalle Valo } 3202e705c121SKalle Valo 3203cbce62a3SMiri Korenblit void 3204e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 3205e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3206e705c121SKalle Valo int num_frames, 3207e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3208e705c121SKalle Valo bool more_data) 3209e705c121SKalle Valo { 3210e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3211e705c121SKalle Valo 3212e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 3213e705c121SKalle Valo 3214e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3215e705c121SKalle Valo tids, more_data, false); 3216e705c121SKalle Valo } 3217e705c121SKalle Valo 3218cbce62a3SMiri Korenblit void 3219e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 3220e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3221e705c121SKalle Valo int num_frames, 3222e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3223e705c121SKalle Valo bool more_data) 3224e705c121SKalle Valo { 3225e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3226e705c121SKalle Valo 32279a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 3228e705c121SKalle Valo 3229e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3230e705c121SKalle Valo tids, more_data, true); 3231e705c121SKalle Valo } 3232e705c121SKalle Valo 323365e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 3234e705c121SKalle Valo enum sta_notify_cmd cmd, 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 *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3239e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 3240e705c121SKalle Valo int tid; 3241e705c121SKalle Valo 3242960f864bSJohannes Berg /* 3243960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 3244960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 3245960f864bSJohannes Berg * should have firmware supporting buffer station offload. 3246960f864bSJohannes Berg */ 3247960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 3248960f864bSJohannes Berg return; 3249960f864bSJohannes Berg 3250e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 3251311590a3SEmmanuel Grumbach for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 3252e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 3253e705c121SKalle Valo 32546862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 32551c17627bSSara Sharon continue; 32561c17627bSSara Sharon 3257e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 3258e705c121SKalle Valo 3259dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 3260e705c121SKalle Valo continue; 3261e705c121SKalle Valo 3262e705c121SKalle Valo __set_bit(tid, &tids); 3263e705c121SKalle Valo } 3264e705c121SKalle Valo 3265e705c121SKalle Valo switch (cmd) { 3266e705c121SKalle Valo case STA_NOTIFY_SLEEP: 3267e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 3268e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 3269e705c121SKalle Valo 3270e705c121SKalle Valo if (txqs) 3271e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 3272e705c121SKalle Valo /* 3273e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 3274e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 3275e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 3276e705c121SKalle Valo */ 3277e705c121SKalle Valo break; 3278e705c121SKalle Valo case STA_NOTIFY_AWAKE: 3279c8ee33e1SGregory Greenman if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA)) 3280e705c121SKalle Valo break; 3281e705c121SKalle Valo 3282e705c121SKalle Valo if (txqs) 3283e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 3284e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 3285e705c121SKalle Valo break; 3286e705c121SKalle Valo default: 3287e705c121SKalle Valo break; 3288e705c121SKalle Valo } 3289e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 3290e705c121SKalle Valo } 3291e705c121SKalle Valo 3292cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3293cbce62a3SMiri Korenblit enum sta_notify_cmd cmd, struct ieee80211_sta *sta) 329465e25482SJohannes Berg { 329565e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 329665e25482SJohannes Berg } 329765e25482SJohannes Berg 329865e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 329965e25482SJohannes Berg { 330065e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 330165e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 330265e25482SJohannes Berg struct ieee80211_sta *sta; 330365e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 330465e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 330565e25482SJohannes Berg 3306be9ae34eSNathan Errera if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 330765e25482SJohannes Berg return; 330865e25482SJohannes Berg 330965e25482SJohannes Berg rcu_read_lock(); 3310a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 331165e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 331265e25482SJohannes Berg rcu_read_unlock(); 331365e25482SJohannes Berg return; 331465e25482SJohannes Berg } 331565e25482SJohannes Berg 331665e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 331765e25482SJohannes Berg 331865e25482SJohannes Berg if (!mvmsta->vif || 331965e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 332065e25482SJohannes Berg rcu_read_unlock(); 332165e25482SJohannes Berg return; 332265e25482SJohannes Berg } 332365e25482SJohannes Berg 332465e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 332565e25482SJohannes Berg mvmsta->sleeping = sleeping; 332665e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 332765e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 332865e25482SJohannes Berg sta); 332965e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 333065e25482SJohannes Berg } 333165e25482SJohannes Berg 333265e25482SJohannes Berg if (sleeping) { 333365e25482SJohannes Berg switch (notif->type) { 333465e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 333565e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 333665e25482SJohannes Berg break; 333765e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 333865e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 333965e25482SJohannes Berg break; 334065e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 334165e25482SJohannes Berg ieee80211_sta_pspoll(sta); 334265e25482SJohannes Berg break; 334365e25482SJohannes Berg default: 334465e25482SJohannes Berg break; 334565e25482SJohannes Berg } 334665e25482SJohannes Berg } 334765e25482SJohannes Berg 334865e25482SJohannes Berg rcu_read_unlock(); 334965e25482SJohannes Berg } 335065e25482SJohannes Berg 3351cbce62a3SMiri Korenblit void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 3352e705c121SKalle Valo struct ieee80211_vif *vif, 3353e705c121SKalle Valo struct ieee80211_sta *sta) 3354e705c121SKalle Valo { 3355e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3356e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 335779faae3aSGregory Greenman unsigned int link_id; 3358e705c121SKalle Valo 3359e705c121SKalle Valo /* 3360e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 3361e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 3362e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 3363e705c121SKalle Valo * be able to find the station this way, and we don't rely 3364e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 3365e705c121SKalle Valo * callback deleted the station. 336679faae3aSGregory Greenman * Since there's mvm->mutex here, no need to have RCU lock for 336779faae3aSGregory Greenman * mvm_sta->link access. 3368e705c121SKalle Valo */ 3369e705c121SKalle Valo mutex_lock(&mvm->mutex); 337079faae3aSGregory Greenman for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) { 337179faae3aSGregory Greenman struct iwl_mvm_link_sta *link_sta; 337279faae3aSGregory Greenman u32 sta_id; 3373e705c121SKalle Valo 337479faae3aSGregory Greenman if (!mvm_sta->link[link_id]) 337579faae3aSGregory Greenman continue; 337679faae3aSGregory Greenman 337779faae3aSGregory Greenman link_sta = rcu_dereference_protected(mvm_sta->link[link_id], 337879faae3aSGregory Greenman lockdep_is_held(&mvm->mutex)); 337979faae3aSGregory Greenman sta_id = link_sta->sta_id; 3380b8a85a1dSJohannes Berg if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[sta_id])) { 33813e75668bSJohannes Berg RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], 338279faae3aSGregory Greenman ERR_PTR(-ENOENT)); 3383b8a85a1dSJohannes Berg RCU_INIT_POINTER(mvm->fw_id_to_link_sta[sta_id], NULL); 3384b8a85a1dSJohannes Berg } 338579faae3aSGregory Greenman } 3386e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3387e705c121SKalle Valo } 3388e705c121SKalle Valo 3389e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 3390e705c121SKalle Valo const u8 *bssid) 3391e705c121SKalle Valo { 3392b0ffe455SJohannes Berg int i; 3393b0ffe455SJohannes Berg 3394b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3395b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 3396b0ffe455SJohannes Berg 3397b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 3398b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 3399b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 3400b0ffe455SJohannes Berg } 3401b0ffe455SJohannes Berg 3402e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 3403e705c121SKalle Valo return; 3404e705c121SKalle Valo 3405c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 3406cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3407cee5a882SAvri Altman return; 3408cee5a882SAvri Altman } 3409cee5a882SAvri Altman 341011dee0b4SEmmanuel Grumbach if (!vif->p2p && 341111dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 3412e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3413e705c121SKalle Valo return; 3414e705c121SKalle Valo } 3415e705c121SKalle Valo 3416b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 3417b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 3418b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3419b0ffe455SJohannes Berg return; 3420b0ffe455SJohannes Berg } 3421b0ffe455SJohannes Berg } 3422b0ffe455SJohannes Berg 3423e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 3424e705c121SKalle Valo } 3425e705c121SKalle Valo 34261e8f1329SGolan Ben-Ami static void 34271e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 34281e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 34291e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 34301e8f1329SGolan Ben-Ami { 34311e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 34321e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 34331e8f1329SGolan Ben-Ami 34346c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 34356c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 34366c042d75SSara Sharon if (!trig) 34371e8f1329SGolan Ben-Ami return; 34381e8f1329SGolan Ben-Ami 34391e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 34401e8f1329SGolan Ben-Ami 34411e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 34421e8f1329SGolan Ben-Ami return; 34431e8f1329SGolan Ben-Ami 34441e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 34451e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 34461e8f1329SGolan Ben-Ami return; 34471e8f1329SGolan Ben-Ami 34487174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 34491e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 34501e8f1329SGolan Ben-Ami peer_addr, action); 34511e8f1329SGolan Ben-Ami } 34521e8f1329SGolan Ben-Ami 34534f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data { 34544f58121dSIlan Peer bool tolerated; 34554f58121dSIlan Peer }; 34564f58121dSIlan Peer 34574f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 34584f58121dSIlan Peer struct cfg80211_bss *bss, 34594f58121dSIlan Peer void *_data) 34604f58121dSIlan Peer { 34614f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 34626c608cd6SJohannes Berg const struct cfg80211_bss_ies *ies; 34634f58121dSIlan Peer const struct element *elem; 34644f58121dSIlan Peer 34656c608cd6SJohannes Berg rcu_read_lock(); 34666c608cd6SJohannes Berg ies = rcu_dereference(bss->ies); 34676c608cd6SJohannes Berg elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 34686c608cd6SJohannes Berg ies->len); 34694f58121dSIlan Peer 34704f58121dSIlan Peer if (!elem || elem->datalen < 10 || 34714f58121dSIlan Peer !(elem->data[10] & 34724f58121dSIlan Peer WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 34734f58121dSIlan Peer data->tolerated = false; 34744f58121dSIlan Peer } 34756c608cd6SJohannes Berg rcu_read_unlock(); 34764f58121dSIlan Peer } 34774f58121dSIlan Peer 34786e1b5956SJohannes Berg static void 34796e1b5956SJohannes Berg iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 34806e1b5956SJohannes Berg struct ieee80211_vif *vif, 34816e1b5956SJohannes Berg unsigned int link_id, 34826e1b5956SJohannes Berg struct ieee80211_bss_conf *link_conf) 34834f58121dSIlan Peer { 34844f58121dSIlan Peer struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 34854f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 34864f58121dSIlan Peer .tolerated = true, 34874f58121dSIlan Peer }; 34884f58121dSIlan Peer 34896092077aSJohannes Berg if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan || 34906e1b5956SJohannes Berg !mvmvif->link[link_id])) 34916e1b5956SJohannes Berg return; 34926e1b5956SJohannes Berg 34936092077aSJohannes Berg if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) { 34946e1b5956SJohannes Berg mvmvif->link[link_id]->he_ru_2mhz_block = false; 34954f58121dSIlan Peer return; 34964f58121dSIlan Peer } 34974f58121dSIlan Peer 34986092077aSJohannes Berg cfg80211_bss_iter(hw->wiphy, &link_conf->chanreq.oper, 34994f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru_iter, 35004f58121dSIlan Peer &iter_data); 35014f58121dSIlan Peer 35024f58121dSIlan Peer /* 35034f58121dSIlan Peer * If there is at least one AP on radar channel that cannot 35044f58121dSIlan Peer * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 35054f58121dSIlan Peer */ 35066e1b5956SJohannes Berg mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated; 35074f58121dSIlan Peer } 35084f58121dSIlan Peer 3509f7d6ef33SJohannes Berg static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3510f7d6ef33SJohannes Berg struct ieee80211_vif *vif) 3511f7d6ef33SJohannes Berg { 3512f7d6ef33SJohannes Berg struct ieee80211_supported_band *sband; 3513f7d6ef33SJohannes Berg const struct ieee80211_sta_he_cap *he_cap; 3514f7d6ef33SJohannes Berg 3515f7d6ef33SJohannes Berg if (vif->type != NL80211_IFTYPE_STATION) 3516f7d6ef33SJohannes Berg return; 3517f7d6ef33SJohannes Berg 3518f7d6ef33SJohannes Berg if (!mvm->cca_40mhz_workaround) 3519f7d6ef33SJohannes Berg return; 3520f7d6ef33SJohannes Berg 3521f7d6ef33SJohannes Berg /* decrement and check that we reached zero */ 3522f7d6ef33SJohannes Berg mvm->cca_40mhz_workaround--; 3523f7d6ef33SJohannes Berg if (mvm->cca_40mhz_workaround) 3524f7d6ef33SJohannes Berg return; 3525f7d6ef33SJohannes Berg 3526f7d6ef33SJohannes Berg sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3527f7d6ef33SJohannes Berg 3528f7d6ef33SJohannes Berg sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3529f7d6ef33SJohannes Berg 35301ec7291eSJohannes Berg he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 3531f7d6ef33SJohannes Berg 3532f7d6ef33SJohannes Berg if (he_cap) { 3533f7d6ef33SJohannes Berg /* we know that ours is writable */ 35340301bcd5SBjoern A. Zeeb struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; 3535f7d6ef33SJohannes Berg 3536f7d6ef33SJohannes Berg he->he_cap_elem.phy_cap_info[0] |= 3537f7d6ef33SJohannes Berg IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3538f7d6ef33SJohannes Berg } 3539f7d6ef33SJohannes Berg } 3540f7d6ef33SJohannes Berg 35416d19a5ebSEmmanuel Grumbach static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 35426d19a5ebSEmmanuel Grumbach struct ieee80211_vif *vif, 35436d19a5ebSEmmanuel Grumbach struct iwl_mvm_sta *mvm_sta) 35446d19a5ebSEmmanuel Grumbach { 35456d19a5ebSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI) 35466d19a5ebSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 35476d19a5ebSEmmanuel Grumbach struct iwl_mei_conn_info conn_info = { 3548f276e20bSJohannes Berg .ssid_len = vif->cfg.ssid_len, 35496d19a5ebSEmmanuel Grumbach }; 35506d19a5ebSEmmanuel Grumbach 35516d19a5ebSEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 35526d19a5ebSEmmanuel Grumbach return; 35536d19a5ebSEmmanuel Grumbach 35546d19a5ebSEmmanuel Grumbach if (!mvm->mei_registered) 35556d19a5ebSEmmanuel Grumbach return; 35566d19a5ebSEmmanuel Grumbach 35576c07b73eSJohannes Berg /* FIXME: MEI needs to be updated for MLO */ 35586092077aSJohannes Berg if (!vif->bss_conf.chanreq.oper.chan) 35596c07b73eSJohannes Berg return; 35606c07b73eSJohannes Berg 35616092077aSJohannes Berg conn_info.channel = vif->bss_conf.chanreq.oper.chan->hw_value; 35626c07b73eSJohannes Berg 35636d19a5ebSEmmanuel Grumbach switch (mvm_sta->pairwise_cipher) { 3564e5d3a64eSAvraham Stern case WLAN_CIPHER_SUITE_TKIP: 3565e5d3a64eSAvraham Stern conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP; 3566e5d3a64eSAvraham Stern break; 35676d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_CCMP: 35686d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 35696d19a5ebSEmmanuel Grumbach break; 35706d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP: 35716d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 35726d19a5ebSEmmanuel Grumbach break; 35736d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP_256: 35746d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 35756d19a5ebSEmmanuel Grumbach break; 35766d19a5ebSEmmanuel Grumbach case 0: 35776d19a5ebSEmmanuel Grumbach /* open profile */ 35786d19a5ebSEmmanuel Grumbach break; 35796d19a5ebSEmmanuel Grumbach default: 35806d19a5ebSEmmanuel Grumbach /* cipher not supported, don't send anything to iwlmei */ 35816d19a5ebSEmmanuel Grumbach return; 35826d19a5ebSEmmanuel Grumbach } 35836d19a5ebSEmmanuel Grumbach 35846d19a5ebSEmmanuel Grumbach switch (mvmvif->rekey_data.akm) { 35856d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_SAE & 0xff: 35866d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 35876d19a5ebSEmmanuel Grumbach break; 35886d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_PSK & 0xff: 35896d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 35906d19a5ebSEmmanuel Grumbach break; 35916d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_8021X & 0xff: 35926d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 35936d19a5ebSEmmanuel Grumbach break; 35946d19a5ebSEmmanuel Grumbach case 0: 35956d19a5ebSEmmanuel Grumbach /* open profile */ 35966d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 35976d19a5ebSEmmanuel Grumbach break; 35986d19a5ebSEmmanuel Grumbach default: 35996d19a5ebSEmmanuel Grumbach /* auth method / AKM not supported */ 36006d19a5ebSEmmanuel Grumbach /* TODO: All the FT vesions of these? */ 36016d19a5ebSEmmanuel Grumbach return; 36026d19a5ebSEmmanuel Grumbach } 36036d19a5ebSEmmanuel Grumbach 3604f276e20bSJohannes Berg memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 36056d19a5ebSEmmanuel Grumbach memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 36066d19a5ebSEmmanuel Grumbach 36076d19a5ebSEmmanuel Grumbach /* TODO: add support for collocated AP data */ 36086d19a5ebSEmmanuel Grumbach iwl_mei_host_associated(&conn_info, NULL); 36096d19a5ebSEmmanuel Grumbach #endif 36106d19a5ebSEmmanuel Grumbach } 36116d19a5ebSEmmanuel Grumbach 361287f7e243SMiri Korenblit static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm, 361387f7e243SMiri Korenblit struct ieee80211_vif *vif, 361487f7e243SMiri Korenblit bool force_assoc_off) 361587f7e243SMiri Korenblit { 361687f7e243SMiri Korenblit return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL); 361787f7e243SMiri Korenblit } 361887f7e243SMiri Korenblit 3619e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3620e705c121SKalle Valo struct ieee80211_vif *vif, 3621e705c121SKalle Valo struct ieee80211_sta *sta, 3622e705c121SKalle Valo enum ieee80211_sta_state old_state, 3623e705c121SKalle Valo enum ieee80211_sta_state new_state) 3624e705c121SKalle Valo { 3625a2906ea6SJohannes Berg static const struct iwl_mvm_sta_state_ops callbacks = { 362687f7e243SMiri Korenblit .add_sta = iwl_mvm_add_sta, 362787f7e243SMiri Korenblit .update_sta = iwl_mvm_update_sta, 362887f7e243SMiri Korenblit .rm_sta = iwl_mvm_rm_sta, 362987f7e243SMiri Korenblit .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper, 363087f7e243SMiri Korenblit }; 363187f7e243SMiri Korenblit 363287f7e243SMiri Korenblit return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state, 363387f7e243SMiri Korenblit &callbacks); 363487f7e243SMiri Korenblit } 363587f7e243SMiri Korenblit 363657974a55SGregory Greenman /* FIXME: temporary making two assumptions in all sta handling functions: 363757974a55SGregory Greenman * (1) when setting sta state, the link exists and protected 363857974a55SGregory Greenman * (2) if a link is valid in sta then it's valid in vif (can 363957974a55SGregory Greenman * use same index in the link array) 364057974a55SGregory Greenman */ 3641f53be9c4SGregory Greenman static void iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm, 3642f53be9c4SGregory Greenman struct ieee80211_vif *vif, 364315d41834SJohannes Berg struct ieee80211_sta *sta) 3644f53be9c4SGregory Greenman { 3645f53be9c4SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3646f53be9c4SGregory Greenman unsigned int link_id; 364757974a55SGregory Greenman 3648f53be9c4SGregory Greenman for_each_mvm_vif_valid_link(mvmvif, link_id) { 3649f53be9c4SGregory Greenman struct ieee80211_bss_conf *conf = 3650a705a782SJohannes Berg link_conf_dereference_check(vif, link_id); 3651f53be9c4SGregory Greenman struct ieee80211_link_sta *link_sta = 3652a705a782SJohannes Berg link_sta_dereference_check(sta, link_id); 3653f53be9c4SGregory Greenman 3654f53be9c4SGregory Greenman if (!conf || !link_sta || !mvmvif->link[link_id]->phy_ctxt) 3655f53be9c4SGregory Greenman continue; 3656f53be9c4SGregory Greenman 3657c45217bdSJohannes Berg iwl_mvm_rs_rate_init(mvm, vif, sta, conf, link_sta, 365815d41834SJohannes Berg mvmvif->link[link_id]->phy_ctxt->channel->band); 3659f53be9c4SGregory Greenman } 3660f53be9c4SGregory Greenman } 366157974a55SGregory Greenman 366257974a55SGregory Greenman #define IWL_MVM_MIN_BEACON_INTERVAL_TU 16 366357974a55SGregory Greenman 366457974a55SGregory Greenman static bool iwl_mvm_vif_conf_from_sta(struct iwl_mvm *mvm, 366557974a55SGregory Greenman struct ieee80211_vif *vif, 366657974a55SGregory Greenman struct ieee80211_sta *sta) 366757974a55SGregory Greenman { 3668207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3669207be64fSMiri Korenblit unsigned int link_id; 367057974a55SGregory Greenman 367157974a55SGregory Greenman /* Beacon interval check - firmware will crash if the beacon 367257974a55SGregory Greenman * interval is less than 16. We can't avoid connecting at all, 367357974a55SGregory Greenman * so refuse the station state change, this will cause mac80211 367457974a55SGregory Greenman * to abandon attempts to connect to this AP, and eventually 367557974a55SGregory Greenman * wpa_s will blocklist the AP... 367657974a55SGregory Greenman */ 367757974a55SGregory Greenman 3678207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 367957974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3680207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 368157974a55SGregory Greenman 3682207be64fSMiri Korenblit if (!link_conf) 368357974a55SGregory Greenman continue; 368457974a55SGregory Greenman 368557974a55SGregory Greenman if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) { 368657974a55SGregory Greenman IWL_ERR(mvm, 368757974a55SGregory Greenman "Beacon interval %d for AP %pM is too small\n", 368857974a55SGregory Greenman link_conf->beacon_int, link_sta->addr); 368957974a55SGregory Greenman return false; 369057974a55SGregory Greenman } 369157974a55SGregory Greenman 369257974a55SGregory Greenman link_conf->he_support = link_sta->he_cap.has_he; 369357974a55SGregory Greenman } 369457974a55SGregory Greenman 369557974a55SGregory Greenman return true; 369657974a55SGregory Greenman } 369757974a55SGregory Greenman 369857974a55SGregory Greenman static void iwl_mvm_vif_set_he_support(struct ieee80211_hw *hw, 369957974a55SGregory Greenman struct ieee80211_vif *vif, 370057974a55SGregory Greenman struct ieee80211_sta *sta, 370157974a55SGregory Greenman bool is_sta) 370257974a55SGregory Greenman { 370357974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3704207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3705207be64fSMiri Korenblit unsigned int link_id; 370657974a55SGregory Greenman 3707207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 370857974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3709207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 371057974a55SGregory Greenman 3711207be64fSMiri Korenblit if (!link_conf || !mvmvif->link[link_id]) 371257974a55SGregory Greenman continue; 371357974a55SGregory Greenman 371457974a55SGregory Greenman link_conf->he_support = link_sta->he_cap.has_he; 371557974a55SGregory Greenman 371657974a55SGregory Greenman if (is_sta) { 3717207be64fSMiri Korenblit mvmvif->link[link_id]->he_ru_2mhz_block = false; 371857974a55SGregory Greenman if (link_sta->he_cap.has_he) 3719207be64fSMiri Korenblit iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif, 3720207be64fSMiri Korenblit link_id, 37216e1b5956SJohannes Berg link_conf); 372257974a55SGregory Greenman } 372357974a55SGregory Greenman } 372457974a55SGregory Greenman } 372557974a55SGregory Greenman 372657974a55SGregory Greenman static int 372757974a55SGregory Greenman iwl_mvm_sta_state_notexist_to_none(struct iwl_mvm *mvm, 372857974a55SGregory Greenman struct ieee80211_vif *vif, 372957974a55SGregory Greenman struct ieee80211_sta *sta, 3730a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 373157974a55SGregory Greenman { 37320c9a8f90SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3733207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 373457974a55SGregory Greenman unsigned int i; 373557974a55SGregory Greenman int ret; 373657974a55SGregory Greenman 373757974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 373857974a55SGregory Greenman 373957974a55SGregory Greenman if (vif->type == NL80211_IFTYPE_STATION && 374057974a55SGregory Greenman !iwl_mvm_vif_conf_from_sta(mvm, vif, sta)) 374157974a55SGregory Greenman return -EINVAL; 374257974a55SGregory Greenman 374357974a55SGregory Greenman if (sta->tdls && 374457974a55SGregory Greenman (vif->p2p || 374557974a55SGregory Greenman iwl_mvm_tdls_sta_count(mvm, NULL) == IWL_MVM_TDLS_STA_COUNT || 374657974a55SGregory Greenman iwl_mvm_phy_ctx_count(mvm) > 1)) { 374757974a55SGregory Greenman IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 374857974a55SGregory Greenman return -EBUSY; 374957974a55SGregory Greenman } 375057974a55SGregory Greenman 375157974a55SGregory Greenman ret = callbacks->add_sta(mvm, vif, sta); 375257974a55SGregory Greenman if (sta->tdls && ret == 0) { 375357974a55SGregory Greenman iwl_mvm_recalc_tdls_state(mvm, vif, true); 375457974a55SGregory Greenman iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 375557974a55SGregory Greenman NL80211_TDLS_SETUP); 375657974a55SGregory Greenman } 375757974a55SGregory Greenman 3758b7198383SEmmanuel Grumbach if (ret) 3759b7198383SEmmanuel Grumbach return ret; 3760b7198383SEmmanuel Grumbach 3761207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, i) 376257974a55SGregory Greenman link_sta->agg.max_rc_amsdu_len = 1; 3763207be64fSMiri Korenblit 376457974a55SGregory Greenman ieee80211_sta_recalc_aggregates(sta); 376557974a55SGregory Greenman 37660c9a8f90SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 37670c9a8f90SJohannes Berg mvmvif->ap_sta = sta; 37680c9a8f90SJohannes Berg 3769d3b2c6c6SJohannes Berg /* 3770d3b2c6c6SJohannes Berg * Initialize the rates here already - this really tells 3771d3b2c6c6SJohannes Berg * the firmware only what the supported legacy rates are 3772d3b2c6c6SJohannes Berg * (may be) since it's initialized already from what the 3773d3b2c6c6SJohannes Berg * AP advertised in the beacon/probe response. This will 3774d3b2c6c6SJohannes Berg * allow the firmware to send auth/assoc frames with one 3775d3b2c6c6SJohannes Berg * of the supported rates already, rather than having to 3776d3b2c6c6SJohannes Berg * use a mandatory rate. 3777d3b2c6c6SJohannes Berg * If we're the AP, we'll just assume mandatory rates at 3778d3b2c6c6SJohannes Berg * this point, but we know nothing about the STA anyway. 3779d3b2c6c6SJohannes Berg */ 3780d3b2c6c6SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 3781d3b2c6c6SJohannes Berg 378257974a55SGregory Greenman return 0; 378357974a55SGregory Greenman } 378457974a55SGregory Greenman 378557974a55SGregory Greenman static int 378657974a55SGregory Greenman iwl_mvm_sta_state_auth_to_assoc(struct ieee80211_hw *hw, 378757974a55SGregory Greenman struct iwl_mvm *mvm, 378857974a55SGregory Greenman struct ieee80211_vif *vif, 378957974a55SGregory Greenman struct ieee80211_sta *sta, 3790a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 379157974a55SGregory Greenman { 379257974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 379357974a55SGregory Greenman struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3794207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3795207be64fSMiri Korenblit unsigned int link_id; 379657974a55SGregory Greenman 379757974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 379857974a55SGregory Greenman 379957974a55SGregory Greenman if (vif->type == NL80211_IFTYPE_AP) { 380057974a55SGregory Greenman iwl_mvm_vif_set_he_support(hw, vif, sta, false); 380157974a55SGregory Greenman mvmvif->ap_assoc_sta_count++; 380257974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 380357974a55SGregory Greenman 380457974a55SGregory Greenman /* since the below is not for MLD API, it's ok to use 380557974a55SGregory Greenman * the default bss_conf 380657974a55SGregory Greenman */ 380757974a55SGregory Greenman if (!mvm->mld_api_is_used && 380883f57c93SJohannes Berg (vif->bss_conf.he_support && 380983f57c93SJohannes Berg !iwlwifi_mod_params.disable_11ax)) 381057974a55SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id); 381157974a55SGregory Greenman } else if (vif->type == NL80211_IFTYPE_STATION) { 381257974a55SGregory Greenman iwl_mvm_vif_set_he_support(hw, vif, sta, true); 381357974a55SGregory Greenman 381457974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 381557974a55SGregory Greenman 381657974a55SGregory Greenman if (!mvm->mld_api_is_used) 381757974a55SGregory Greenman goto out; 381857974a55SGregory Greenman 3819207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 382057974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3821207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 382257974a55SGregory Greenman 382357974a55SGregory Greenman if (WARN_ON(!link_conf)) 382457974a55SGregory Greenman return -EINVAL; 3825207be64fSMiri Korenblit if (!mvmvif->link[link_id]) 3826f14ad95aSJohannes Berg continue; 382757974a55SGregory Greenman 382857974a55SGregory Greenman iwl_mvm_link_changed(mvm, vif, link_conf, 382957974a55SGregory Greenman LINK_CONTEXT_MODIFY_ALL & 383057974a55SGregory Greenman ~LINK_CONTEXT_MODIFY_ACTIVE, 383157974a55SGregory Greenman true); 383257974a55SGregory Greenman } 383357974a55SGregory Greenman } 383457974a55SGregory Greenman 383557974a55SGregory Greenman out: 383615d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 383757974a55SGregory Greenman 383857974a55SGregory Greenman return callbacks->update_sta(mvm, vif, sta); 383957974a55SGregory Greenman } 384057974a55SGregory Greenman 384157974a55SGregory Greenman static int 384257974a55SGregory Greenman iwl_mvm_sta_state_assoc_to_authorized(struct iwl_mvm *mvm, 384357974a55SGregory Greenman struct ieee80211_vif *vif, 384457974a55SGregory Greenman struct ieee80211_sta *sta, 3845a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 384657974a55SGregory Greenman { 384757974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 384857974a55SGregory Greenman struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 384957974a55SGregory Greenman 385057974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 385157974a55SGregory Greenman 385257974a55SGregory Greenman /* we don't support TDLS during DCM */ 385357974a55SGregory Greenman if (iwl_mvm_phy_ctx_count(mvm) > 1) 385457974a55SGregory Greenman iwl_mvm_teardown_tdls_peers(mvm); 385557974a55SGregory Greenman 385657974a55SGregory Greenman if (sta->tdls) { 385757974a55SGregory Greenman iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 385857974a55SGregory Greenman NL80211_TDLS_ENABLE_LINK); 385957974a55SGregory Greenman } else { 386057974a55SGregory Greenman /* enable beacon filtering */ 386187f5b5f2SJohannes Berg WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 386257974a55SGregory Greenman 386357974a55SGregory Greenman mvmvif->authorized = 1; 386457974a55SGregory Greenman 386557974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 386657974a55SGregory Greenman iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 3867b9be67fbSIlan Peer 3868b9be67fbSIlan Peer /* when client is authorized (AP station marked as such), 3869b9be67fbSIlan Peer * try to enable more links 3870b9be67fbSIlan Peer */ 3871b9be67fbSIlan Peer if (vif->type == NL80211_IFTYPE_STATION && 3872b9be67fbSIlan Peer !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 3873b9be67fbSIlan Peer iwl_mvm_mld_select_links(mvm, vif, false); 387457974a55SGregory Greenman } 387557974a55SGregory Greenman 387615d41834SJohannes Berg mvm_sta->authorized = true; 387715d41834SJohannes Berg 38785a86dcb4SAvraham Stern /* MFP is set by default before the station is authorized. 38795a86dcb4SAvraham Stern * Clear it here in case it's not used. 38805a86dcb4SAvraham Stern */ 38810fcdf55fSEmmanuel Grumbach if (!sta->mfp) { 38820fcdf55fSEmmanuel Grumbach int ret = callbacks->update_sta(mvm, vif, sta); 38830fcdf55fSEmmanuel Grumbach 38840fcdf55fSEmmanuel Grumbach if (ret) 38850fcdf55fSEmmanuel Grumbach return ret; 38860fcdf55fSEmmanuel Grumbach } 38870fcdf55fSEmmanuel Grumbach 38880fcdf55fSEmmanuel Grumbach iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 38895a86dcb4SAvraham Stern 389057974a55SGregory Greenman return 0; 389157974a55SGregory Greenman } 389257974a55SGregory Greenman 389357974a55SGregory Greenman static int 389457974a55SGregory Greenman iwl_mvm_sta_state_authorized_to_assoc(struct iwl_mvm *mvm, 389557974a55SGregory Greenman struct ieee80211_vif *vif, 389657974a55SGregory Greenman struct ieee80211_sta *sta, 3897a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 389857974a55SGregory Greenman { 389957974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 390015d41834SJohannes Berg struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 390157974a55SGregory Greenman 390257974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 390357974a55SGregory Greenman 390415d41834SJohannes Berg mvmsta->authorized = false; 390515d41834SJohannes Berg 390657974a55SGregory Greenman /* once we move into assoc state, need to update rate scale to 390757974a55SGregory Greenman * disable using wide bandwidth 390857974a55SGregory Greenman */ 390915d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 391057974a55SGregory Greenman 391157974a55SGregory Greenman if (!sta->tdls) { 391257974a55SGregory Greenman /* Set this but don't call iwl_mvm_mac_ctxt_changed() 391357974a55SGregory Greenman * yet to avoid sending high prio again for a little 391457974a55SGregory Greenman * time. 391557974a55SGregory Greenman */ 391657974a55SGregory Greenman mvmvif->authorized = 0; 391757974a55SGregory Greenman 391857974a55SGregory Greenman /* disable beacon filtering */ 391987f5b5f2SJohannes Berg iwl_mvm_disable_beacon_filter(mvm, vif); 392057974a55SGregory Greenman } 392157974a55SGregory Greenman 392257974a55SGregory Greenman return 0; 392357974a55SGregory Greenman } 392457974a55SGregory Greenman 392587f7e243SMiri Korenblit /* Common part for MLD and non-MLD modes */ 392687f7e243SMiri Korenblit int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw, 392787f7e243SMiri Korenblit struct ieee80211_vif *vif, 392887f7e243SMiri Korenblit struct ieee80211_sta *sta, 392987f7e243SMiri Korenblit enum ieee80211_sta_state old_state, 393087f7e243SMiri Korenblit enum ieee80211_sta_state new_state, 3931a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 393287f7e243SMiri Korenblit { 3933e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3934e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 39356ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3936de107600SJohannes Berg struct ieee80211_link_sta *link_sta; 393757974a55SGregory Greenman unsigned int link_id; 3938e705c121SKalle Valo int ret; 3939e705c121SKalle Valo 3940e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 3941e705c121SKalle Valo sta->addr, old_state, new_state); 3942e705c121SKalle Valo 394324afba76SLiad Kaufman /* 394424afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 394524afba76SLiad Kaufman * 394624afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 394724afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 394824afba76SLiad Kaufman * the queues. 394924afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 395024afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 395124afba76SLiad Kaufman * of. 395224afba76SLiad Kaufman * 395324afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 395424afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 395524afba76SLiad Kaufman */ 395624afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 3957c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 395824afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 395924afba76SLiad Kaufman 396024afba76SLiad Kaufman /* 396124afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 396224afba76SLiad Kaufman * worker will already remove it if it was on 396324afba76SLiad Kaufman */ 3964f7d6ef33SJohannes Berg 3965f7d6ef33SJohannes Berg /* 3966f7d6ef33SJohannes Berg * Additionally, reset the 40 MHz capability if we disconnected 3967f7d6ef33SJohannes Berg * from the AP now. 3968f7d6ef33SJohannes Berg */ 3969f7d6ef33SJohannes Berg iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 3970783336b0SJohannes Berg 3971783336b0SJohannes Berg /* Also free dup data just in case any assertions below fail */ 3972783336b0SJohannes Berg kfree(mvm_sta->dup_data); 397324afba76SLiad Kaufman } 397424afba76SLiad Kaufman 3975e705c121SKalle Valo mutex_lock(&mvm->mutex); 397657974a55SGregory Greenman 3977828c79d9SEmmanuel Grumbach /* this would be a mac80211 bug ... but don't crash, unless we had a 3978828c79d9SEmmanuel Grumbach * firmware crash while we were activating a link, in which case it is 3979828c79d9SEmmanuel Grumbach * legit to have phy_ctxt = NULL. Don't bother not to WARN if we are in 3980828c79d9SEmmanuel Grumbach * recovery flow since we spit tons of error messages anyway. 3981828c79d9SEmmanuel Grumbach */ 3982de107600SJohannes Berg for_each_sta_active_link(vif, sta, link_sta, link_id) { 39833d6d21b2SJohannes Berg if (WARN_ON_ONCE(!mvmvif->link[link_id] || 39843d6d21b2SJohannes Berg !mvmvif->link[link_id]->phy_ctxt)) { 398557974a55SGregory Greenman mutex_unlock(&mvm->mutex); 398657974a55SGregory Greenman return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 398757974a55SGregory Greenman &mvm->status) ? 0 : -EINVAL; 398857974a55SGregory Greenman } 398957974a55SGregory Greenman } 399057974a55SGregory Greenman 39916ea29ce5SJohannes Berg /* track whether or not the station is associated */ 3992d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 39936ea29ce5SJohannes Berg 3994e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3995e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 399657974a55SGregory Greenman ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta, 399757974a55SGregory Greenman callbacks); 399857974a55SGregory Greenman if (ret < 0) 3999e705c121SKalle Valo goto out_unlock; 4000e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 4001e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 4002e705c121SKalle Valo /* 4003e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 4004e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 4005e705c121SKalle Valo */ 4006e705c121SKalle Valo mvm->last_ebs_successful = true; 4007e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 4008e705c121SKalle Valo ret = 0; 4009e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 4010e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 401157974a55SGregory Greenman ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta, 401257974a55SGregory Greenman callbacks); 4013e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 4014e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 401557974a55SGregory Greenman ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta, 401657974a55SGregory Greenman callbacks); 4017e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 4018e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 401957974a55SGregory Greenman ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta, 402057974a55SGregory Greenman callbacks); 4021e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 4022e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 40238be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 40248be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 402587f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 4026d5d8ee52SEmmanuel Grumbach } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 4027cf7a7457SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 4028e705c121SKalle Valo ret = 0; 4029e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 4030e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 4031e705c121SKalle Valo ret = 0; 4032e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 4033e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 40340c9a8f90SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) { 4035d5d8ee52SEmmanuel Grumbach iwl_mvm_stop_session_protection(mvm, vif); 40360c9a8f90SJohannes Berg mvmvif->ap_sta = NULL; 40370c9a8f90SJohannes Berg } 403887f7e243SMiri Korenblit ret = callbacks->rm_sta(mvm, vif, sta); 40391e8f1329SGolan Ben-Ami if (sta->tdls) { 4040e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 40411e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 40421e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 40431e8f1329SGolan Ben-Ami } 404434a880d8SLiad Kaufman 404544135b7cSIlan Peer if (unlikely(ret && 404644135b7cSIlan Peer test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 404744135b7cSIlan Peer &mvm->status))) 404844135b7cSIlan Peer ret = 0; 4049e705c121SKalle Valo } else { 4050e705c121SKalle Valo ret = -EIO; 4051e705c121SKalle Valo } 4052e705c121SKalle Valo out_unlock: 4053e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4054e705c121SKalle Valo 4055e705c121SKalle Valo if (sta->tdls && ret == 0) { 4056e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 4057e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 4058e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4059e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 4060e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 4061e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4062e705c121SKalle Valo } 4063e705c121SKalle Valo 4064e705c121SKalle Valo return ret; 4065e705c121SKalle Valo } 4066e705c121SKalle Valo 4067cbce62a3SMiri Korenblit int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 4068e705c121SKalle Valo { 4069e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4070e705c121SKalle Valo 4071e705c121SKalle Valo mvm->rts_threshold = value; 4072e705c121SKalle Valo 4073e705c121SKalle Valo return 0; 4074e705c121SKalle Valo } 4075e705c121SKalle Valo 4076cbce62a3SMiri Korenblit void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4077e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 4078e705c121SKalle Valo { 4079e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4080dcfe3b10SJohannes Berg 4081dcfe3b10SJohannes Berg if (changed & (IEEE80211_RC_BW_CHANGED | 4082dcfe3b10SJohannes Berg IEEE80211_RC_SUPP_RATES_CHANGED | 4083dcfe3b10SJohannes Berg IEEE80211_RC_NSS_CHANGED)) 408415d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 4085e705c121SKalle Valo 4086e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 4087e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 4088e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 4089e705c121SKalle Valo } 4090e705c121SKalle Valo 4091e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 4092b3e2130bSJohannes Berg struct ieee80211_vif *vif, 4093b3e2130bSJohannes Berg unsigned int link_id, u16 ac, 4094e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 4095e705c121SKalle Valo { 4096e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4097e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4098e705c121SKalle Valo 4099650cadb7SGregory Greenman mvmvif->deflink.queue_params[ac] = *params; 4100e705c121SKalle Valo 4101e705c121SKalle Valo /* 4102e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 4103e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 4104e705c121SKalle Valo */ 4105e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 4106e705c121SKalle Valo int ret; 4107e705c121SKalle Valo 4108e705c121SKalle Valo mutex_lock(&mvm->mutex); 4109e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4110e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4111e705c121SKalle Valo return ret; 4112e705c121SKalle Valo } 4113e705c121SKalle Valo return 0; 4114e705c121SKalle Valo } 4115e705c121SKalle Valo 4116cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 4117d4e36e55SIlan Peer struct ieee80211_vif *vif, 411815fae341SJohannes Berg struct ieee80211_prep_tx_info *info) 4119e705c121SKalle Valo { 4120e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4121d4e36e55SIlan Peer 4122e705c121SKalle Valo mutex_lock(&mvm->mutex); 412323673041SMiri Korenblit iwl_mvm_protect_assoc(mvm, vif, info->duration, info->link_id); 4124e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4125e705c121SKalle Valo } 4126e705c121SKalle Valo 4127cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 41286b1259d1SJohannes Berg struct ieee80211_vif *vif, 41296b1259d1SJohannes Berg struct ieee80211_prep_tx_info *info) 41306b1259d1SJohannes Berg { 41316b1259d1SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 41326b1259d1SJohannes Berg 41336b1259d1SJohannes Berg /* for successful cases (auth/assoc), don't cancel session protection */ 41346b1259d1SJohannes Berg if (info->success) 41356b1259d1SJohannes Berg return; 41366b1259d1SJohannes Berg 41376b1259d1SJohannes Berg mutex_lock(&mvm->mutex); 41386b1259d1SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 41396b1259d1SJohannes Berg mutex_unlock(&mvm->mutex); 41406b1259d1SJohannes Berg } 41416b1259d1SJohannes Berg 4142cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 4143e705c121SKalle Valo struct ieee80211_vif *vif, 4144e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 4145e705c121SKalle Valo struct ieee80211_scan_ies *ies) 4146e705c121SKalle Valo { 4147e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4148e705c121SKalle Valo 4149e705c121SKalle Valo int ret; 4150e705c121SKalle Valo 4151e705c121SKalle Valo mutex_lock(&mvm->mutex); 4152e705c121SKalle Valo 4153f276e20bSJohannes Berg if (!vif->cfg.idle) { 4154e705c121SKalle Valo ret = -EBUSY; 4155e705c121SKalle Valo goto out; 4156e705c121SKalle Valo } 4157e705c121SKalle Valo 4158e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 4159e705c121SKalle Valo 4160e705c121SKalle Valo out: 4161e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4162e705c121SKalle Valo return ret; 4163e705c121SKalle Valo } 4164e705c121SKalle Valo 4165cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 4166e705c121SKalle Valo struct ieee80211_vif *vif) 4167e705c121SKalle Valo { 4168e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4169e705c121SKalle Valo int ret; 4170e705c121SKalle Valo 4171e705c121SKalle Valo mutex_lock(&mvm->mutex); 4172e705c121SKalle Valo 4173e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 4174e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 4175e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 4176e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 4177e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 4178e705c121SKalle Valo * could run. To handle this, simply return if the scan is 4179e705c121SKalle Valo * not running. 4180e705c121SKalle Valo */ 4181e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 4182e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4183e705c121SKalle Valo return 0; 4184e705c121SKalle Valo } 4185e705c121SKalle Valo 4186e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 4187e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4188e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 4189e705c121SKalle Valo 4190e705c121SKalle Valo return ret; 4191e705c121SKalle Valo } 4192e705c121SKalle Valo 41936569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 4194e705c121SKalle Valo enum set_key_cmd cmd, 4195e705c121SKalle Valo struct ieee80211_vif *vif, 4196e705c121SKalle Valo struct ieee80211_sta *sta, 4197e705c121SKalle Valo struct ieee80211_key_conf *key) 4198e705c121SKalle Valo { 4199c56e00a3SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4200e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 420146c7b05aSEmmanuel Grumbach struct iwl_mvm_sta *mvmsta = NULL; 4202d066a530SJohannes Berg struct iwl_mvm_key_pn *ptk_pn = NULL; 4203f5e28eacSJohannes Berg int keyidx = key->keyidx; 42045c75a208SJohannes Berg u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 42055c75a208SJohannes Berg u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 4206c56e00a3SJohannes Berg int ret, i; 42074615fd15SEmmanuel Grumbach u8 key_offset; 4208e705c121SKalle Valo 420946c7b05aSEmmanuel Grumbach if (sta) 42106d19a5ebSEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_mac80211(sta); 42116d19a5ebSEmmanuel Grumbach 4212e705c121SKalle Valo switch (key->cipher) { 4213e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 4214286ca8ebSLuca Coelho if (!mvm->trans->trans_cfg->gen2) { 4215e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 42161ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 42177f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 42187f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 42197f768ad5SDavid Spinadel } else { 42207f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 42217f768ad5SDavid Spinadel return -EOPNOTSUPP; 42227f768ad5SDavid Spinadel } 4223e705c121SKalle Valo break; 4224e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 42252a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 42262a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 422785aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 4228e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 4229e705c121SKalle Valo break; 4230e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 42318e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 42328e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4233e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 4234e705c121SKalle Valo break; 4235e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 4236e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 4237475c6bdeSJohannes Berg if (vif->type == NL80211_IFTYPE_STATION) 4238e705c121SKalle Valo break; 4239475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 4240475c6bdeSJohannes Berg return -EOPNOTSUPP; 4241475c6bdeSJohannes Berg /* support HW crypto on TX */ 4242475c6bdeSJohannes Berg return 0; 4243e705c121SKalle Valo default: 4244e705c121SKalle Valo return -EOPNOTSUPP; 4245e705c121SKalle Valo } 4246e705c121SKalle Valo 4247e705c121SKalle Valo switch (cmd) { 4248e705c121SKalle Valo case SET_KEY: 4249a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 4250a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 4251b1fdc250SJohannes Berg rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 4252b1fdc250SJohannes Berg key); 4253b1fdc250SJohannes Berg 4254e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 4255e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 4256e705c121SKalle Valo /* 4257e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 4258e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 4259e705c121SKalle Valo * we don't support them for RX, so do the same. 4260f05d1e04SJohannes Berg * CMAC/GMAC in AP/IBSS modes must be done in software 4261f05d1e04SJohannes Berg * on older NICs. 4262a5de7de7SJohannes Berg * 4263a5de7de7SJohannes Berg * Except, of course, beacon protection - it must be 4264f05d1e04SJohannes Berg * offloaded since we just set a beacon template, and 4265f05d1e04SJohannes Berg * then we must also offload the IGTK (not just BIGTK) 4266f05d1e04SJohannes Berg * for firmware reasons. 4267f05d1e04SJohannes Berg * 4268f05d1e04SJohannes Berg * So just check for beacon protection - if we don't 4269f05d1e04SJohannes Berg * have it we cannot get here with keyidx >= 6, and 4270f05d1e04SJohannes Berg * if we do have it we need to send the key to FW in 4271f05d1e04SJohannes Berg * all cases (CMAC/GMAC). 4272e705c121SKalle Valo */ 4273f05d1e04SJohannes Berg if (!wiphy_ext_feature_isset(hw->wiphy, 4274f05d1e04SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION) && 4275a5de7de7SJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 42768e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 4277a5de7de7SJohannes Berg key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) { 427881279c49SJohannes Berg ret = -EOPNOTSUPP; 4279a1c2ff30SAndrei Otcheretianski break; 4280a1c2ff30SAndrei Otcheretianski } 428185aeb58cSDavid Spinadel 428285aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 428385aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 428485aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 4285e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 4286a1c2ff30SAndrei Otcheretianski ret = 0; 4287e705c121SKalle Valo break; 4288e705c121SKalle Valo } 4289c56e00a3SJohannes Berg 4290c56e00a3SJohannes Berg if (!mvmvif->ap_ibss_active) { 4291c56e00a3SJohannes Berg for (i = 0; 4292c56e00a3SJohannes Berg i < ARRAY_SIZE(mvmvif->ap_early_keys); 4293c56e00a3SJohannes Berg i++) { 4294c56e00a3SJohannes Berg if (!mvmvif->ap_early_keys[i]) { 4295c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = key; 4296c56e00a3SJohannes Berg break; 4297c56e00a3SJohannes Berg } 4298c56e00a3SJohannes Berg } 4299c56e00a3SJohannes Berg 4300c56e00a3SJohannes Berg if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 4301c56e00a3SJohannes Berg ret = -ENOSPC; 4302a1c2ff30SAndrei Otcheretianski else 4303a1c2ff30SAndrei Otcheretianski ret = 0; 4304c56e00a3SJohannes Berg 4305c56e00a3SJohannes Berg break; 4306c56e00a3SJohannes Berg } 430785aeb58cSDavid Spinadel } 4308e705c121SKalle Valo 4309e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 4310e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 4311e705c121SKalle Valo */ 4312e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 4313e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 4314e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 4315e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 4316e705c121SKalle Valo ret = 0; 4317e705c121SKalle Valo break; 4318e705c121SKalle Valo } 4319e705c121SKalle Valo 4320f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 432146c7b05aSEmmanuel Grumbach mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4322f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4323f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 43242a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 43252a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4326f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 4327f5e28eacSJohannes Berg int tid, q; 4328f5e28eacSJohannes Berg 4329f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 4330acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 4331acafe7e3SKees Cook mvm->trans->num_rx_queues), 4332f5e28eacSJohannes Berg GFP_KERNEL); 4333f5e28eacSJohannes Berg if (!ptk_pn) { 4334f5e28eacSJohannes Berg ret = -ENOMEM; 4335f5e28eacSJohannes Berg break; 4336f5e28eacSJohannes Berg } 4337f5e28eacSJohannes Berg 4338f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 4339f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 4340f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 4341f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 4342f5e28eacSJohannes Berg seq.ccmp.pn, 4343f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 4344f5e28eacSJohannes Berg } 4345f5e28eacSJohannes Berg 4346f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 4347f5e28eacSJohannes Berg } 4348f5e28eacSJohannes Berg 43494615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 43504615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 43514615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 43524615fd15SEmmanuel Grumbach else 43534615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 43544615fd15SEmmanuel Grumbach 435546c7b05aSEmmanuel Grumbach if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 43566d19a5ebSEmmanuel Grumbach mvmsta->pairwise_cipher = key->cipher; 43576d19a5ebSEmmanuel Grumbach 4358a5de7de7SJohannes Berg IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n", 4359a5de7de7SJohannes Berg sta ? sta->addr : NULL, key->keyidx); 43605c75a208SJohannes Berg 43615c75a208SJohannes Berg if (sec_key_ver) 43625c75a208SJohannes Berg ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); 43635c75a208SJohannes Berg else 43644615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 43655c75a208SJohannes Berg 4366e705c121SKalle Valo if (ret) { 4367e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 4368475c6bdeSJohannes Berg key->hw_key_idx = STA_KEY_IDX_INVALID; 4369d066a530SJohannes Berg if (ptk_pn) { 4370d066a530SJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4371d066a530SJohannes Berg kfree(ptk_pn); 4372d066a530SJohannes Berg } 4373e705c121SKalle Valo /* 4374e705c121SKalle Valo * can't add key for RX, but we don't need it 4375475c6bdeSJohannes Berg * in the device for TX so still return 0, 4376475c6bdeSJohannes Berg * unless we have new TX API where we cannot 4377475c6bdeSJohannes Berg * put key material into the TX_CMD 4378e705c121SKalle Valo */ 4379475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 4380475c6bdeSJohannes Berg ret = -EOPNOTSUPP; 4381475c6bdeSJohannes Berg else 4382e705c121SKalle Valo ret = 0; 4383e705c121SKalle Valo } 4384e705c121SKalle Valo 4385e705c121SKalle Valo break; 4386e705c121SKalle Valo case DISABLE_KEY: 4387a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 4388a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 4389b1fdc250SJohannes Berg RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 4390b1fdc250SJohannes Berg NULL); 4391b1fdc250SJohannes Berg 4392c56e00a3SJohannes Berg ret = -ENOENT; 4393c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 4394c56e00a3SJohannes Berg if (mvmvif->ap_early_keys[i] == key) { 4395c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 4396c56e00a3SJohannes Berg ret = 0; 4397c56e00a3SJohannes Berg } 4398c56e00a3SJohannes Berg } 4399c56e00a3SJohannes Berg 4400c56e00a3SJohannes Berg /* found in pending list - don't do anything else */ 4401c56e00a3SJohannes Berg if (ret == 0) 4402c56e00a3SJohannes Berg break; 4403c56e00a3SJohannes Berg 4404e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 4405e705c121SKalle Valo ret = 0; 4406e705c121SKalle Valo break; 4407e705c121SKalle Valo } 4408e705c121SKalle Valo 440946c7b05aSEmmanuel Grumbach if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4410f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4411f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 44122a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 44132a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4414f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 4415f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 4416f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 4417f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4418f5e28eacSJohannes Berg if (ptk_pn) 4419f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 4420f5e28eacSJohannes Berg } 4421f5e28eacSJohannes Berg 4422e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 44235c75a208SJohannes Berg if (sec_key_ver) 44245c75a208SJohannes Berg ret = iwl_mvm_sec_key_del(mvm, vif, sta, key); 44255c75a208SJohannes Berg else 4426e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 4427e705c121SKalle Valo break; 4428e705c121SKalle Valo default: 4429e705c121SKalle Valo ret = -EINVAL; 4430e705c121SKalle Valo } 4431e705c121SKalle Valo 44326569e7d3SJohannes Berg return ret; 44336569e7d3SJohannes Berg } 44346569e7d3SJohannes Berg 4435cbce62a3SMiri Korenblit int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4436cbce62a3SMiri Korenblit struct ieee80211_vif *vif, struct ieee80211_sta *sta, 44376569e7d3SJohannes Berg struct ieee80211_key_conf *key) 44386569e7d3SJohannes Berg { 44396569e7d3SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 44406569e7d3SJohannes Berg int ret; 44416569e7d3SJohannes Berg 44426569e7d3SJohannes Berg mutex_lock(&mvm->mutex); 44436569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 4444e705c121SKalle Valo mutex_unlock(&mvm->mutex); 44456569e7d3SJohannes Berg 4446e705c121SKalle Valo return ret; 4447e705c121SKalle Valo } 4448e705c121SKalle Valo 4449cbce62a3SMiri Korenblit void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 4450e705c121SKalle Valo struct ieee80211_vif *vif, 4451e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 4452e705c121SKalle Valo struct ieee80211_sta *sta, 4453e705c121SKalle Valo u32 iv32, u16 *phase1key) 4454e705c121SKalle Valo { 4455e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4456e705c121SKalle Valo 4457e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 4458e705c121SKalle Valo return; 4459e705c121SKalle Valo 4460e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 4461e705c121SKalle Valo } 4462e705c121SKalle Valo 4463e705c121SKalle Valo 4464e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 4465e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 4466e705c121SKalle Valo { 4467e705c121SKalle Valo struct iwl_mvm *mvm = 4468e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 4469e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 4470e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 4471e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 4472e705c121SKalle Valo 4473e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 4474e705c121SKalle Valo return true; 4475e705c121SKalle Valo 4476e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 4477e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 4478e705c121SKalle Valo return true; 4479e705c121SKalle Valo } 4480e705c121SKalle Valo 4481e705c121SKalle Valo resp = (void *)pkt->data; 4482e705c121SKalle Valo 4483e705c121SKalle Valo IWL_DEBUG_TE(mvm, 4484b71a9c35SColin Ian King "Aux ROC: Received response from ucode: status=%d uid=%d\n", 4485e705c121SKalle Valo resp->status, resp->event_unique_id); 4486e705c121SKalle Valo 4487e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 4488e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 4489e705c121SKalle Valo te_data->uid); 4490e705c121SKalle Valo 4491e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4492e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 4493e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4494e705c121SKalle Valo 4495e705c121SKalle Valo return true; 4496e705c121SKalle Valo } 4497e705c121SKalle Valo 4498e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 4499e705c121SKalle Valo struct ieee80211_channel *channel, 4500e705c121SKalle Valo struct ieee80211_vif *vif, 4501e705c121SKalle Valo int duration) 4502e705c121SKalle Valo { 4503afc1e3b4SAvraham Stern int res; 4504e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4505e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 4506e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 4507e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 4508dc28e12fSMatti Gottlieb u32 req_dur, delay; 4509e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 4510e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 4511e705c121SKalle Valo .id_and_color = 4512e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 4513e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 4514e705c121SKalle Valo }; 451557e861d9SDavid Spinadel struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 451657e861d9SDavid Spinadel &aux_roc_req.channel_info); 451757e861d9SDavid Spinadel u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 451857e861d9SDavid Spinadel 451957e861d9SDavid Spinadel /* Set the channel info data */ 452057e861d9SDavid Spinadel iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 45213717f91aSTova Mussai iwl_mvm_phy_band_from_nl80211(channel->band), 45227ac87575SJohannes Berg IWL_PHY_CHANNEL_MODE20, 452357e861d9SDavid Spinadel 0); 452457e861d9SDavid Spinadel 452557e861d9SDavid Spinadel /* Set the time and duration */ 4526afc1e3b4SAvraham Stern tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 4527e705c121SKalle Valo 452867ac248eSShaul Triebitz iwl_mvm_roc_duration_and_delay(vif, duration, &req_dur, &delay); 452957e861d9SDavid Spinadel tail->duration = cpu_to_le32(req_dur); 453057e861d9SDavid Spinadel tail->apply_time_max_delay = cpu_to_le32(delay); 4531dc28e12fSMatti Gottlieb 4532dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 4533903b3f9bSEmmanuel Grumbach "ROC: Requesting to remain on channel %u for %ums\n", 4534903b3f9bSEmmanuel Grumbach channel->hw_value, req_dur); 4535903b3f9bSEmmanuel Grumbach IWL_DEBUG_TE(mvm, 453667ac248eSShaul Triebitz "\t(requested = %ums, max_delay = %ums)\n", 453767ac248eSShaul Triebitz duration, delay); 4538903b3f9bSEmmanuel Grumbach 4539e705c121SKalle Valo /* Set the node address */ 454057e861d9SDavid Spinadel memcpy(tail->node_addr, vif->addr, ETH_ALEN); 4541e705c121SKalle Valo 4542e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4543e705c121SKalle Valo 4544e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4545e705c121SKalle Valo 4546e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 4547e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4548e705c121SKalle Valo return -EIO; 4549e705c121SKalle Valo } 4550e705c121SKalle Valo 4551e705c121SKalle Valo te_data->vif = vif; 4552e705c121SKalle Valo te_data->duration = duration; 4553e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 4554e705c121SKalle Valo 4555e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4556e705c121SKalle Valo 4557e705c121SKalle Valo /* 4558e705c121SKalle Valo * Use a notification wait, which really just processes the 4559e705c121SKalle Valo * command response and doesn't wait for anything, in order 4560e705c121SKalle Valo * to be able to process the response and get the UID inside 4561e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 4562e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 4563e705c121SKalle Valo * time another notification (that the time event started) 4564e705c121SKalle Valo * might already be processed unsuccessfully. 4565e705c121SKalle Valo */ 4566e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 4567e705c121SKalle Valo time_event_response, 4568e705c121SKalle Valo ARRAY_SIZE(time_event_response), 4569e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 4570e705c121SKalle Valo 457157e861d9SDavid Spinadel res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 4572e705c121SKalle Valo &aux_roc_req); 4573e705c121SKalle Valo 4574e705c121SKalle Valo if (res) { 4575e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 4576e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 4577e705c121SKalle Valo goto out_clear_te; 4578e705c121SKalle Valo } 4579e705c121SKalle Valo 4580e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 4581e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 4582e705c121SKalle Valo /* should never fail */ 4583e705c121SKalle Valo WARN_ON_ONCE(res); 4584e705c121SKalle Valo 4585e705c121SKalle Valo if (res) { 4586e705c121SKalle Valo out_clear_te: 4587e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4588e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 4589e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4590e705c121SKalle Valo } 4591e705c121SKalle Valo 4592e705c121SKalle Valo return res; 4593e705c121SKalle Valo } 4594e705c121SKalle Valo 4595feebebaeSMiri Korenblit static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id) 4596feebebaeSMiri Korenblit { 4597feebebaeSMiri Korenblit int ret = 0; 4598feebebaeSMiri Korenblit 4599feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4600feebebaeSMiri Korenblit 4601feebebaeSMiri Korenblit if (!fw_has_capa(&mvm->fw->ucode_capa, 4602feebebaeSMiri Korenblit IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 4603feebebaeSMiri Korenblit IWL_ERR(mvm, "hotspot not supported\n"); 4604feebebaeSMiri Korenblit return -EINVAL; 4605feebebaeSMiri Korenblit } 4606feebebaeSMiri Korenblit 46071724fc78SEmmanuel Grumbach if (iwl_mvm_has_new_station_api(mvm->fw)) { 4608feebebaeSMiri Korenblit ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 4609feebebaeSMiri Korenblit WARN(ret, "Failed to allocate aux station"); 4610feebebaeSMiri Korenblit } 4611feebebaeSMiri Korenblit 4612feebebaeSMiri Korenblit return ret; 4613feebebaeSMiri Korenblit } 4614feebebaeSMiri Korenblit 461584ef7cbeSIlan Peer static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 4616feebebaeSMiri Korenblit { 461784ef7cbeSIlan Peer int ret; 4618feebebaeSMiri Korenblit 4619feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4620feebebaeSMiri Korenblit 4621feebebaeSMiri Korenblit ret = iwl_mvm_binding_add_vif(mvm, vif); 462284ef7cbeSIlan Peer if (WARN(ret, "Failed binding P2P_DEVICE\n")) 4623feebebaeSMiri Korenblit return ret; 462484ef7cbeSIlan Peer 462584ef7cbeSIlan Peer /* The station and queue allocation must be done only after the binding 462684ef7cbeSIlan Peer * is done, as otherwise the FW might incorrectly configure its state. 462784ef7cbeSIlan Peer */ 462884ef7cbeSIlan Peer return iwl_mvm_add_p2p_bcast_sta(mvm, vif); 4629feebebaeSMiri Korenblit } 4630feebebaeSMiri Korenblit 4631e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 4632e705c121SKalle Valo struct ieee80211_vif *vif, 4633e705c121SKalle Valo struct ieee80211_channel *channel, 4634e705c121SKalle Valo int duration, 4635e705c121SKalle Valo enum ieee80211_roc_type type) 4636e705c121SKalle Valo { 4637a2906ea6SJohannes Berg static const struct iwl_mvm_roc_ops ops = { 4638fe8b2ad3SMiri Korenblit .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20, 463984ef7cbeSIlan Peer .link = iwl_mvm_roc_link, 4640fe8b2ad3SMiri Korenblit }; 4641fe8b2ad3SMiri Korenblit 4642fe8b2ad3SMiri Korenblit return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops); 4643fe8b2ad3SMiri Korenblit } 4644fe8b2ad3SMiri Korenblit 464567ac248eSShaul Triebitz static int iwl_mvm_roc_station(struct iwl_mvm *mvm, 464667ac248eSShaul Triebitz struct ieee80211_channel *channel, 464767ac248eSShaul Triebitz struct ieee80211_vif *vif, 464867ac248eSShaul Triebitz int duration) 464967ac248eSShaul Triebitz { 465067ac248eSShaul Triebitz int ret; 465167ac248eSShaul Triebitz u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD); 465267ac248eSShaul Triebitz u8 fw_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 465367ac248eSShaul Triebitz IWL_FW_CMD_VER_UNKNOWN); 465467ac248eSShaul Triebitz 465567ac248eSShaul Triebitz if (fw_ver == IWL_FW_CMD_VER_UNKNOWN) { 465667ac248eSShaul Triebitz ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, vif, duration); 465767ac248eSShaul Triebitz } else if (fw_ver == 3) { 465867ac248eSShaul Triebitz ret = iwl_mvm_roc_add_cmd(mvm, channel, vif, duration, 465967ac248eSShaul Triebitz ROC_ACTIVITY_HOTSPOT); 466067ac248eSShaul Triebitz } else { 466167ac248eSShaul Triebitz ret = -EOPNOTSUPP; 466267ac248eSShaul Triebitz IWL_ERR(mvm, "ROC command version %d mismatch!\n", fw_ver); 466367ac248eSShaul Triebitz } 466467ac248eSShaul Triebitz 466567ac248eSShaul Triebitz return ret; 466667ac248eSShaul Triebitz } 466767ac248eSShaul Triebitz 466834cc3a4aSEmmanuel Grumbach static int iwl_mvm_p2p_find_phy_ctxt(struct iwl_mvm *mvm, 466934cc3a4aSEmmanuel Grumbach struct ieee80211_vif *vif, 467034cc3a4aSEmmanuel Grumbach struct ieee80211_channel *channel) 467134cc3a4aSEmmanuel Grumbach { 467234cc3a4aSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 467334cc3a4aSEmmanuel Grumbach struct cfg80211_chan_def chandef; 467434cc3a4aSEmmanuel Grumbach int i; 467534cc3a4aSEmmanuel Grumbach 467634cc3a4aSEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 467734cc3a4aSEmmanuel Grumbach 467834cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt && 467934cc3a4aSEmmanuel Grumbach channel == mvmvif->deflink.phy_ctxt->channel) 468034cc3a4aSEmmanuel Grumbach return 0; 468134cc3a4aSEmmanuel Grumbach 468234cc3a4aSEmmanuel Grumbach /* Try using a PHY context that is already in use */ 468334cc3a4aSEmmanuel Grumbach for (i = 0; i < NUM_PHY_CTX; i++) { 468434cc3a4aSEmmanuel Grumbach struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[i]; 468534cc3a4aSEmmanuel Grumbach 468634cc3a4aSEmmanuel Grumbach if (!phy_ctxt->ref || mvmvif->deflink.phy_ctxt == phy_ctxt) 468734cc3a4aSEmmanuel Grumbach continue; 468834cc3a4aSEmmanuel Grumbach 468934cc3a4aSEmmanuel Grumbach if (channel == phy_ctxt->channel) { 469034cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt) 469134cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_unref(mvm, 469234cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt); 469334cc3a4aSEmmanuel Grumbach 469434cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt = phy_ctxt; 469534cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 469634cc3a4aSEmmanuel Grumbach return 0; 469734cc3a4aSEmmanuel Grumbach } 469834cc3a4aSEmmanuel Grumbach } 469934cc3a4aSEmmanuel Grumbach 470034cc3a4aSEmmanuel Grumbach /* We already have a phy_ctxt, but it's not on the right channel */ 470134cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt) 470234cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 470334cc3a4aSEmmanuel Grumbach 470434cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 470534cc3a4aSEmmanuel Grumbach if (!mvmvif->deflink.phy_ctxt) 470634cc3a4aSEmmanuel Grumbach return -ENOSPC; 470734cc3a4aSEmmanuel Grumbach 470834cc3a4aSEmmanuel Grumbach cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 470934cc3a4aSEmmanuel Grumbach 471034cc3a4aSEmmanuel Grumbach return iwl_mvm_phy_ctxt_add(mvm, mvmvif->deflink.phy_ctxt, 471132a5690eSJohannes Berg &chandef, NULL, 1, 1); 471234cc3a4aSEmmanuel Grumbach } 471334cc3a4aSEmmanuel Grumbach 4714fe8b2ad3SMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 4715fe8b2ad3SMiri Korenblit int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4716fe8b2ad3SMiri Korenblit struct ieee80211_channel *channel, int duration, 4717fe8b2ad3SMiri Korenblit enum ieee80211_roc_type type, 4718a2906ea6SJohannes Berg const struct iwl_mvm_roc_ops *ops) 4719fe8b2ad3SMiri Korenblit { 4720e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4721feebebaeSMiri Korenblit u32 lmac_id; 472234cc3a4aSEmmanuel Grumbach int ret; 4723e705c121SKalle Valo 4724e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 4725e705c121SKalle Valo duration, type); 4726e705c121SKalle Valo 47279834781cSJohannes Berg /* 47289834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 47299834781cSJohannes Berg * the work it does can complete and we can accept new frames. 47309834781cSJohannes Berg */ 4731e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 4732e705c121SKalle Valo 4733e705c121SKalle Valo mutex_lock(&mvm->mutex); 4734e705c121SKalle Valo 4735e705c121SKalle Valo switch (vif->type) { 4736e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4737d51439a6SAriel Malamud lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band); 47382c2c3647SNathan Errera 4739feebebaeSMiri Korenblit /* Use aux roc framework (HS20) */ 4740fe8b2ad3SMiri Korenblit ret = ops->add_aux_sta_for_hs20(mvm, lmac_id); 4741feebebaeSMiri Korenblit if (!ret) 474267ac248eSShaul Triebitz ret = iwl_mvm_roc_station(mvm, channel, vif, duration); 4743e705c121SKalle Valo goto out_unlock; 4744e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 4745e705c121SKalle Valo /* handle below */ 4746e705c121SKalle Valo break; 4747e705c121SKalle Valo default: 474884ef7cbeSIlan Peer IWL_ERR(mvm, "ROC: Invalid vif type=%u\n", vif->type); 4749e705c121SKalle Valo ret = -EINVAL; 4750e705c121SKalle Valo goto out_unlock; 4751e705c121SKalle Valo } 4752e705c121SKalle Valo 4753e705c121SKalle Valo 475434cc3a4aSEmmanuel Grumbach ret = iwl_mvm_p2p_find_phy_ctxt(mvm, vif, channel); 475534cc3a4aSEmmanuel Grumbach if (ret) 4756e705c121SKalle Valo goto out_unlock; 4757e705c121SKalle Valo 475884ef7cbeSIlan Peer ret = ops->link(mvm, vif); 4759feebebaeSMiri Korenblit if (ret) 4760e705c121SKalle Valo goto out_unlock; 4761e705c121SKalle Valo 4762e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4763e705c121SKalle Valo out_unlock: 4764e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4765e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4766e705c121SKalle Valo return ret; 4767e705c121SKalle Valo } 4768e705c121SKalle Valo 4769fe8b2ad3SMiri Korenblit int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 47705db4c4b9SEmmanuel Grumbach struct ieee80211_vif *vif) 4771e705c121SKalle Valo { 4772e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4773e705c121SKalle Valo 4774e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 4775e705c121SKalle Valo 4776e705c121SKalle Valo mutex_lock(&mvm->mutex); 4777fe959c7bSEmmanuel Grumbach iwl_mvm_stop_roc(mvm, vif); 4778e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4779e705c121SKalle Valo 4780e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4781e705c121SKalle Valo return 0; 4782e705c121SKalle Valo } 4783e705c121SKalle Valo 4784b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data { 4785b73f9a4aSJohannes Berg bool responder; 4786b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx; 4787b73f9a4aSJohannes Berg }; 4788b73f9a4aSJohannes Berg 4789b73f9a4aSJohannes Berg static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4790b73f9a4aSJohannes Berg struct ieee80211_vif *vif) 4791b73f9a4aSJohannes Berg { 4792b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data *data = _data; 4793b73f9a4aSJohannes Berg 4794d0a9123eSJohannes Berg if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && 4795b73f9a4aSJohannes Berg vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4796b73f9a4aSJohannes Berg data->responder = true; 4797b73f9a4aSJohannes Berg } 4798b73f9a4aSJohannes Berg 4799ce1fa3adSJohannes Berg bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4800b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx) 4801b73f9a4aSJohannes Berg { 4802b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data data = { 4803b73f9a4aSJohannes Berg .responder = false, 4804b73f9a4aSJohannes Berg .ctx = ctx, 4805b73f9a4aSJohannes Berg }; 4806b73f9a4aSJohannes Berg 4807b73f9a4aSJohannes Berg ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4808b73f9a4aSJohannes Berg IEEE80211_IFACE_ITER_NORMAL, 4809b73f9a4aSJohannes Berg iwl_mvm_ftm_responder_chanctx_iter, 4810b73f9a4aSJohannes Berg &data); 4811b73f9a4aSJohannes Berg return data.responder; 4812b73f9a4aSJohannes Berg } 4813b73f9a4aSJohannes Berg 4814e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4815e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4816e705c121SKalle Valo { 4817e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4818e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 4819ce1fa3adSJohannes Berg struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4820e705c121SKalle Valo int ret; 4821e705c121SKalle Valo 4822e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4823e705c121SKalle Valo 4824e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4825e705c121SKalle Valo 4826e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4827e705c121SKalle Valo if (!phy_ctxt) { 4828e705c121SKalle Valo ret = -ENOSPC; 4829e705c121SKalle Valo goto out; 4830e705c121SKalle Valo } 4831e705c121SKalle Valo 483232a5690eSJohannes Berg ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, def, &ctx->ap, 4833e705c121SKalle Valo ctx->rx_chains_static, 4834e705c121SKalle Valo ctx->rx_chains_dynamic); 4835e705c121SKalle Valo if (ret) { 4836e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 4837e705c121SKalle Valo goto out; 4838e705c121SKalle Valo } 4839e705c121SKalle Valo 4840e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 4841e705c121SKalle Valo out: 4842e705c121SKalle Valo return ret; 4843e705c121SKalle Valo } 4844e705c121SKalle Valo 4845cbce62a3SMiri Korenblit int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4846e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4847e705c121SKalle Valo { 4848e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4849e705c121SKalle Valo int ret; 4850e705c121SKalle Valo 4851e705c121SKalle Valo mutex_lock(&mvm->mutex); 4852e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 4853e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4854e705c121SKalle Valo 4855e705c121SKalle Valo return ret; 4856e705c121SKalle Valo } 4857e705c121SKalle Valo 4858e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4859e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4860e705c121SKalle Valo { 4861e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4862e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4863e705c121SKalle Valo 4864e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4865e705c121SKalle Valo 4866e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4867e705c121SKalle Valo } 4868e705c121SKalle Valo 4869cbce62a3SMiri Korenblit void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4870e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4871e705c121SKalle Valo { 4872e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4873e705c121SKalle Valo 4874e705c121SKalle Valo mutex_lock(&mvm->mutex); 4875e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 4876e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4877e705c121SKalle Valo } 4878e705c121SKalle Valo 4879cbce62a3SMiri Korenblit void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4880cbce62a3SMiri Korenblit struct ieee80211_chanctx_conf *ctx, u32 changed) 4881e705c121SKalle Valo { 4882e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4883e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4884e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4885ce1fa3adSJohannes Berg struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4886e705c121SKalle Valo 4887e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 4888e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4889e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4890e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 4891e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4892e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 4893e705c121SKalle Valo phy_ctxt->ref, changed)) 4894e705c121SKalle Valo return; 4895e705c121SKalle Valo 4896e705c121SKalle Valo mutex_lock(&mvm->mutex); 48977a20bcceSEmmanuel Grumbach 48987a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 48997a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 4900b73f9a4aSJohannes Berg if (phy_ctxt->width == def->width) 49017a20bcceSEmmanuel Grumbach goto out_unlock; 49027a20bcceSEmmanuel Grumbach 49037a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 49047a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 4905b73f9a4aSJohannes Berg def->width <= NL80211_CHAN_WIDTH_20) 49067a20bcceSEmmanuel Grumbach goto out_unlock; 49077a20bcceSEmmanuel Grumbach } 49087a20bcceSEmmanuel Grumbach 4909e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 491032a5690eSJohannes Berg iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, &ctx->ap, 4911e705c121SKalle Valo ctx->rx_chains_static, 4912e705c121SKalle Valo ctx->rx_chains_dynamic); 49137a20bcceSEmmanuel Grumbach 49147a20bcceSEmmanuel Grumbach out_unlock: 4915e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4916e705c121SKalle Valo } 4917e705c121SKalle Valo 49188a919a78SMiri Korenblit /* 49198a919a78SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 49208a919a78SMiri Korenblit * 49218a919a78SMiri Korenblit * Returns true if we're done assigning the chanctx 49228a919a78SMiri Korenblit * (either on failure or success) 49238a919a78SMiri Korenblit */ 49244263ac7fSGregory Greenman static bool 49254263ac7fSGregory Greenman __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, 4926e705c121SKalle Valo struct ieee80211_vif *vif, 4927e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 492850e81437SMiri Korenblit bool switching_chanctx, int *ret) 4929e705c121SKalle Valo { 4930e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4931e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4932e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4933e705c121SKalle Valo 4934e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4935e705c121SKalle Valo 4936650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = phy_ctxt; 4937e705c121SKalle Valo 4938e705c121SKalle Valo switch (vif->type) { 4939e705c121SKalle Valo case NL80211_IFTYPE_AP: 4940e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 4941e705c121SKalle Valo if (switching_chanctx) { 4942e705c121SKalle Valo mvmvif->ap_ibss_active = true; 4943e705c121SKalle Valo break; 4944e705c121SKalle Valo } 49455a2abdcaSGustavo A. R. Silva fallthrough; 4946e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4947e705c121SKalle Valo /* 4948e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 4949e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 4950e705c121SKalle Valo */ 49518a919a78SMiri Korenblit *ret = 0; 49528a919a78SMiri Korenblit return true; 4953e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4954e705c121SKalle Valo break; 4955e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4956e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 4957e705c121SKalle Valo mvmvif->ps_disabled = true; 4958e705c121SKalle Valo break; 4959e705c121SKalle Valo default: 49608a919a78SMiri Korenblit *ret = -EINVAL; 49618a919a78SMiri Korenblit return true; 4962e705c121SKalle Valo } 49638a919a78SMiri Korenblit return false; 49648a919a78SMiri Korenblit } 49658a919a78SMiri Korenblit 49668a919a78SMiri Korenblit static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 49678a919a78SMiri Korenblit struct ieee80211_vif *vif, 49684263ac7fSGregory Greenman struct ieee80211_bss_conf *link_conf, 49698a919a78SMiri Korenblit struct ieee80211_chanctx_conf *ctx, 49708a919a78SMiri Korenblit bool switching_chanctx) 49718a919a78SMiri Korenblit { 49728a919a78SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 49738a919a78SMiri Korenblit int ret; 49748a919a78SMiri Korenblit 49754263ac7fSGregory Greenman if (WARN_ON(!link_conf)) 49764263ac7fSGregory Greenman return -EINVAL; 49774263ac7fSGregory Greenman 49788a919a78SMiri Korenblit if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx, 49798a919a78SMiri Korenblit switching_chanctx, &ret)) 49808a919a78SMiri Korenblit goto out; 4981e705c121SKalle Valo 4982e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4983e705c121SKalle Valo if (ret) 4984e705c121SKalle Valo goto out; 4985e705c121SKalle Valo 4986e705c121SKalle Valo /* 4987e705c121SKalle Valo * Power state must be updated before quotas, 4988e705c121SKalle Valo * otherwise fw will complain. 4989e705c121SKalle Valo */ 4990e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4991e705c121SKalle Valo 4992e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 4993e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 4994e705c121SKalle Valo * will handle quota settings. 4995e705c121SKalle Valo */ 4996e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 4997e705c121SKalle Valo mvmvif->monitor_active = true; 4998e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 4999e705c121SKalle Valo if (ret) 5000e705c121SKalle Valo goto out_remove_binding; 50010e39eb03SChaya Rachel Ivgi 50020e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 50030e39eb03SChaya Rachel Ivgi if (ret) 50040e39eb03SChaya Rachel Ivgi goto out_remove_binding; 50050e39eb03SChaya Rachel Ivgi 5006e705c121SKalle Valo } 5007e705c121SKalle Valo 5008e705c121SKalle Valo /* Handle binding during CSA */ 5009e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 5010e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 5011e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 5012e705c121SKalle Valo } 5013e705c121SKalle Valo 50148a919a78SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION) { 50158a919a78SMiri Korenblit if (!switching_chanctx) { 50168a919a78SMiri Korenblit mvmvif->csa_bcn_pending = false; 50178a919a78SMiri Korenblit goto out; 50188a919a78SMiri Korenblit } 50198a919a78SMiri Korenblit 502074a10252SSara Sharon mvmvif->csa_bcn_pending = true; 502174a10252SSara Sharon 502274a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 502374a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 502411d0d831SJohannes Berg u32 duration = 5 * vif->bss_conf.beacon_int; 5025e705c121SKalle Valo 5026e705c121SKalle Valo /* Protect the session to make sure we hear the first 5027e705c121SKalle Valo * beacon on the new channel. 5028e705c121SKalle Valo */ 5029e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 5030e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 5031e705c121SKalle Valo true); 503274a10252SSara Sharon } 5033e705c121SKalle Valo 5034e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 5035e705c121SKalle Valo } 5036e705c121SKalle Valo 5037e705c121SKalle Valo goto out; 5038e705c121SKalle Valo 5039e705c121SKalle Valo out_remove_binding: 5040e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 5041e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 5042e705c121SKalle Valo out: 5043e705c121SKalle Valo if (ret) 5044650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 5045e705c121SKalle Valo return ret; 5046e705c121SKalle Valo } 50478a919a78SMiri Korenblit 5048e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 5049e705c121SKalle Valo struct ieee80211_vif *vif, 5050727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 5051e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 5052e705c121SKalle Valo { 5053e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5054e705c121SKalle Valo int ret; 5055e705c121SKalle Valo 5056e705c121SKalle Valo mutex_lock(&mvm->mutex); 50574263ac7fSGregory Greenman ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5058e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5059e705c121SKalle Valo 5060e705c121SKalle Valo return ret; 5061e705c121SKalle Valo } 5062e705c121SKalle Valo 5063daddfae5SMiri Korenblit /* 5064daddfae5SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 5065daddfae5SMiri Korenblit * 5066daddfae5SMiri Korenblit * Returns if chanctx unassign chanctx is done 5067daddfae5SMiri Korenblit * (either on failure or success) 5068daddfae5SMiri Korenblit */ 50694263ac7fSGregory Greenman static bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, 5070e705c121SKalle Valo struct ieee80211_vif *vif, 5071e705c121SKalle Valo bool switching_chanctx) 5072e705c121SKalle Valo { 5073e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5074e705c121SKalle Valo 5075e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 5076650cadb7SGregory Greenman iwl_mvm_remove_time_event(mvm, mvmvif, 5077650cadb7SGregory Greenman &mvmvif->time_event_data); 5078e705c121SKalle Valo 5079e705c121SKalle Valo switch (vif->type) { 5080e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 5081daddfae5SMiri Korenblit return true; 5082e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 5083e705c121SKalle Valo mvmvif->monitor_active = false; 5084e705c121SKalle Valo mvmvif->ps_disabled = false; 5085e705c121SKalle Valo break; 5086e705c121SKalle Valo case NL80211_IFTYPE_AP: 5087e705c121SKalle Valo /* This part is triggered only during CSA */ 5088e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 5089daddfae5SMiri Korenblit return true; 5090e705c121SKalle Valo 5091e705c121SKalle Valo mvmvif->csa_countdown = false; 5092e705c121SKalle Valo 5093e705c121SKalle Valo /* Set CS bit on all the stations */ 5094e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 5095e705c121SKalle Valo 5096e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 5097e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 5098e705c121SKalle Valo 5099e705c121SKalle Valo mvmvif->ap_ibss_active = false; 5100e705c121SKalle Valo break; 5101daddfae5SMiri Korenblit default: 5102e705c121SKalle Valo break; 5103daddfae5SMiri Korenblit } 5104daddfae5SMiri Korenblit return false; 5105daddfae5SMiri Korenblit } 5106e705c121SKalle Valo 5107e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 5108e705c121SKalle Valo struct ieee80211_vif *vif, 51094263ac7fSGregory Greenman struct ieee80211_bss_conf *link_conf, 5110e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 5111e705c121SKalle Valo bool switching_chanctx) 5112e705c121SKalle Valo { 5113e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5114e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 5115e705c121SKalle Valo 5116daddfae5SMiri Korenblit if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx)) 5117e705c121SKalle Valo goto out; 5118daddfae5SMiri Korenblit 5119daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_MONITOR) 5120e705c121SKalle Valo iwl_mvm_rm_snif_sta(mvm, vif); 5121e705c121SKalle Valo 5122e705c121SKalle Valo 5123daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) { 5124e705c121SKalle Valo disabled_vif = vif; 512574a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 512674a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 5127e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 5128e705c121SKalle Valo } 5129e705c121SKalle Valo 5130e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 5131e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 5132e705c121SKalle Valo 5133e705c121SKalle Valo out: 5134bf544e9aSSara Sharon if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 5135bf544e9aSSara Sharon switching_chanctx) 5136bf544e9aSSara Sharon return; 5137650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 5138e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 5139e705c121SKalle Valo } 5140e705c121SKalle Valo 5141e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 5142e705c121SKalle Valo struct ieee80211_vif *vif, 5143727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 5144e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 5145e705c121SKalle Valo { 5146e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5147e705c121SKalle Valo 5148e705c121SKalle Valo mutex_lock(&mvm->mutex); 51494263ac7fSGregory Greenman __iwl_mvm_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5150e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5151e705c121SKalle Valo } 5152e705c121SKalle Valo 5153e705c121SKalle Valo static int 5154e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 5155660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5156a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5157e705c121SKalle Valo { 5158e705c121SKalle Valo int ret; 5159e705c121SKalle Valo 5160e705c121SKalle Valo mutex_lock(&mvm->mutex); 51614263ac7fSGregory Greenman ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51624263ac7fSGregory Greenman vifs[0].old_ctx, true); 5163e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 5164e705c121SKalle Valo 5165e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 5166e705c121SKalle Valo if (ret) { 5167e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 5168e705c121SKalle Valo goto out_reassign; 5169e705c121SKalle Valo } 5170e705c121SKalle Valo 51714263ac7fSGregory Greenman ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51724263ac7fSGregory Greenman vifs[0].new_ctx, true); 5173e705c121SKalle Valo if (ret) { 5174e705c121SKalle Valo IWL_ERR(mvm, 5175e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 5176e705c121SKalle Valo goto out_remove; 5177e705c121SKalle Valo } 5178e705c121SKalle Valo 5179e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 5180e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 5181e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 5182e705c121SKalle Valo 5183e705c121SKalle Valo goto out; 5184e705c121SKalle Valo 5185e705c121SKalle Valo out_remove: 5186e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 5187e705c121SKalle Valo 5188e705c121SKalle Valo out_reassign: 5189e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 5190e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 5191e705c121SKalle Valo goto out_restart; 5192e705c121SKalle Valo } 5193e705c121SKalle Valo 51944263ac7fSGregory Greenman if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51954263ac7fSGregory Greenman vifs[0].old_ctx, true)) { 5196e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5197e705c121SKalle Valo goto out_restart; 5198e705c121SKalle Valo } 5199e705c121SKalle Valo 5200e705c121SKalle Valo goto out; 5201e705c121SKalle Valo 5202e705c121SKalle Valo out_restart: 5203e705c121SKalle Valo /* things keep failing, better restart the hw */ 5204e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 5205e705c121SKalle Valo 5206e705c121SKalle Valo out: 5207e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5208e705c121SKalle Valo 5209e705c121SKalle Valo return ret; 5210e705c121SKalle Valo } 5211e705c121SKalle Valo 5212e705c121SKalle Valo static int 5213e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 5214660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5215a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5216e705c121SKalle Valo { 5217e705c121SKalle Valo int ret; 5218e705c121SKalle Valo 5219e705c121SKalle Valo mutex_lock(&mvm->mutex); 52204263ac7fSGregory Greenman ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52214263ac7fSGregory Greenman vifs[0].old_ctx, true); 5222e705c121SKalle Valo 52234263ac7fSGregory Greenman ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52244263ac7fSGregory Greenman vifs[0].new_ctx, true); 5225e705c121SKalle Valo if (ret) { 5226e705c121SKalle Valo IWL_ERR(mvm, 5227e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 5228e705c121SKalle Valo goto out_reassign; 5229e705c121SKalle Valo } 5230e705c121SKalle Valo 5231e705c121SKalle Valo goto out; 5232e705c121SKalle Valo 5233e705c121SKalle Valo out_reassign: 52344263ac7fSGregory Greenman if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52354263ac7fSGregory Greenman vifs[0].old_ctx, true)) { 5236e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5237e705c121SKalle Valo goto out_restart; 5238e705c121SKalle Valo } 5239e705c121SKalle Valo 5240e705c121SKalle Valo goto out; 5241e705c121SKalle Valo 5242e705c121SKalle Valo out_restart: 5243e705c121SKalle Valo /* things keep failing, better restart the hw */ 5244e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 5245e705c121SKalle Valo 5246e705c121SKalle Valo out: 5247e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5248e705c121SKalle Valo 5249e705c121SKalle Valo return ret; 5250e705c121SKalle Valo } 5251e705c121SKalle Valo 5252660eba5aSMiri Korenblit /* Execute the common part for both MLD and non-MLD modes */ 5253660eba5aSMiri Korenblit int 5254660eba5aSMiri Korenblit iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw, 5255e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 5256e705c121SKalle Valo int n_vifs, 5257660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode, 5258a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5259e705c121SKalle Valo { 5260e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5261e705c121SKalle Valo int ret; 5262e705c121SKalle Valo 5263e705c121SKalle Valo /* we only support a single-vif right now */ 5264e705c121SKalle Valo if (n_vifs > 1) 5265e705c121SKalle Valo return -EOPNOTSUPP; 5266e705c121SKalle Valo 5267e705c121SKalle Valo switch (mode) { 5268e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 5269660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops); 5270e705c121SKalle Valo break; 5271e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 5272660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops); 5273e705c121SKalle Valo break; 5274e705c121SKalle Valo default: 5275e705c121SKalle Valo ret = -EOPNOTSUPP; 5276e705c121SKalle Valo break; 5277e705c121SKalle Valo } 5278e705c121SKalle Valo 5279e705c121SKalle Valo return ret; 5280e705c121SKalle Valo } 5281e705c121SKalle Valo 5282660eba5aSMiri Korenblit static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 5283660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5284660eba5aSMiri Korenblit int n_vifs, 5285660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode) 5286660eba5aSMiri Korenblit { 5287a2906ea6SJohannes Berg static const struct iwl_mvm_switch_vif_chanctx_ops ops = { 5288660eba5aSMiri Korenblit .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx, 5289660eba5aSMiri Korenblit .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx, 5290660eba5aSMiri Korenblit }; 5291660eba5aSMiri Korenblit 5292660eba5aSMiri Korenblit return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops); 5293660eba5aSMiri Korenblit } 5294660eba5aSMiri Korenblit 5295cbce62a3SMiri Korenblit int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 52962f0282dbSJohannes Berg { 52972f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 52982f0282dbSJohannes Berg 52992f0282dbSJohannes Berg return mvm->ibss_manager; 53002f0282dbSJohannes Berg } 53012f0282dbSJohannes Berg 5302a32973eeSJohannes Berg static int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 5303e705c121SKalle Valo bool set) 5304e705c121SKalle Valo { 5305e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5306e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 5307e705c121SKalle Valo 5308e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 5309e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 5310e705c121SKalle Valo return -EINVAL; 5311e705c121SKalle Valo } 5312e705c121SKalle Valo 531336cf5377SGregory Greenman return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif, 531436cf5377SGregory Greenman &mvm_sta->vif->bss_conf); 5315e705c121SKalle Valo } 5316e705c121SKalle Valo 5317e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 5318e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 5319e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 5320e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 5321e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 5322e705c121SKalle Valo }; 5323e705c121SKalle Valo 5324e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 5325e705c121SKalle Valo struct ieee80211_vif *vif, 5326e705c121SKalle Valo void *data, int len) 5327e705c121SKalle Valo { 5328e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 5329e705c121SKalle Valo int err; 5330e705c121SKalle Valo u32 noa_duration; 5331e705c121SKalle Valo 53328cb08174SJohannes Berg err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 53338cb08174SJohannes Berg iwl_mvm_tm_policy, NULL); 5334e705c121SKalle Valo if (err) 5335e705c121SKalle Valo return err; 5336e705c121SKalle Valo 5337e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 5338e705c121SKalle Valo return -EINVAL; 5339e705c121SKalle Valo 5340e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 5341e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 5342e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 5343e705c121SKalle Valo !vif->bss_conf.enable_beacon || 5344e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 5345e705c121SKalle Valo return -EINVAL; 5346e705c121SKalle Valo 5347e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 5348e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 5349e705c121SKalle Valo return -EINVAL; 5350e705c121SKalle Valo 5351e705c121SKalle Valo mvm->noa_duration = noa_duration; 5352e705c121SKalle Valo mvm->noa_vif = vif; 5353e705c121SKalle Valo 535422b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 5355e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 5356e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 5357e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 5358f276e20bSJohannes Berg !vif->cfg.assoc || !vif->bss_conf.dtim_period || 5359e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 5360e705c121SKalle Valo return -EINVAL; 5361e705c121SKalle Valo 5362e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 536387f5b5f2SJohannes Berg return iwl_mvm_enable_beacon_filter(mvm, vif); 536487f5b5f2SJohannes Berg return iwl_mvm_disable_beacon_filter(mvm, vif); 5365e705c121SKalle Valo } 5366e705c121SKalle Valo 5367e705c121SKalle Valo return -EOPNOTSUPP; 5368e705c121SKalle Valo } 5369e705c121SKalle Valo 5370cbce62a3SMiri Korenblit int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 5371e705c121SKalle Valo struct ieee80211_vif *vif, 5372e705c121SKalle Valo void *data, int len) 5373e705c121SKalle Valo { 5374e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5375e705c121SKalle Valo int err; 5376e705c121SKalle Valo 5377e705c121SKalle Valo mutex_lock(&mvm->mutex); 5378e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 5379e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5380e705c121SKalle Valo 5381e705c121SKalle Valo return err; 5382e705c121SKalle Valo } 5383e705c121SKalle Valo #endif 5384e705c121SKalle Valo 5385cbce62a3SMiri Korenblit void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5386e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5387e705c121SKalle Valo { 5388e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 5389e705c121SKalle Valo * starting its own channel switch timer, so that we can call 5390e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 5391e705c121SKalle Valo * (which is when the absence time event starts). 5392e705c121SKalle Valo */ 5393e705c121SKalle Valo 5394e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 5395e705c121SKalle Valo "dummy channel switch op\n"); 5396e705c121SKalle Valo } 5397e705c121SKalle Valo 539874a10252SSara Sharon static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 539974a10252SSara Sharon struct ieee80211_vif *vif, 540074a10252SSara Sharon struct ieee80211_channel_switch *chsw) 540174a10252SSara Sharon { 540274a10252SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 540374a10252SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 540474a10252SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 540574a10252SSara Sharon mvmvif->color)), 540674a10252SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 540774a10252SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 540874a10252SSara Sharon .cs_count = chsw->count, 540977738865SSara Sharon .cs_mode = chsw->block_tx, 541074a10252SSara Sharon }; 541174a10252SSara Sharon 541274a10252SSara Sharon lockdep_assert_held(&mvm->mutex); 541374a10252SSara Sharon 54149cfcf71cSSara Sharon if (chsw->delay) 54159cfcf71cSSara Sharon cmd.cs_delayed_bcn_count = 54169cfcf71cSSara Sharon DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 54179cfcf71cSSara Sharon 541874a10252SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 541974a10252SSara Sharon WIDE_ID(MAC_CONF_GROUP, 542074a10252SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 542174a10252SSara Sharon 0, sizeof(cmd), &cmd); 542274a10252SSara Sharon } 542374a10252SSara Sharon 54240202bcf0SEmmanuel Grumbach static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 54250202bcf0SEmmanuel Grumbach struct ieee80211_vif *vif, 54260202bcf0SEmmanuel Grumbach struct ieee80211_channel_switch *chsw) 54270202bcf0SEmmanuel Grumbach { 54280202bcf0SEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 54290202bcf0SEmmanuel Grumbach u32 apply_time; 54300202bcf0SEmmanuel Grumbach 54310202bcf0SEmmanuel Grumbach /* Schedule the time event to a bit before beacon 1, 54320202bcf0SEmmanuel Grumbach * to make sure we're in the new channel when the 54330202bcf0SEmmanuel Grumbach * GO/AP arrives. In case count <= 1 immediately schedule the 54340202bcf0SEmmanuel Grumbach * TE (this might result with some packet loss or connection 54350202bcf0SEmmanuel Grumbach * loss). 54360202bcf0SEmmanuel Grumbach */ 54370202bcf0SEmmanuel Grumbach if (chsw->count <= 1) 54380202bcf0SEmmanuel Grumbach apply_time = 0; 54390202bcf0SEmmanuel Grumbach else 54400202bcf0SEmmanuel Grumbach apply_time = chsw->device_timestamp + 54410202bcf0SEmmanuel Grumbach ((vif->bss_conf.beacon_int * (chsw->count - 1) - 54420202bcf0SEmmanuel Grumbach IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 54430202bcf0SEmmanuel Grumbach 54440202bcf0SEmmanuel Grumbach if (chsw->block_tx) 54450202bcf0SEmmanuel Grumbach iwl_mvm_csa_client_absent(mvm, vif); 54460202bcf0SEmmanuel Grumbach 5447c1e458b9SIlan Peer if (mvmvif->bf_enabled) { 544887f5b5f2SJohannes Berg int ret = iwl_mvm_disable_beacon_filter(mvm, vif); 54490202bcf0SEmmanuel Grumbach 54500202bcf0SEmmanuel Grumbach if (ret) 54510202bcf0SEmmanuel Grumbach return ret; 54520202bcf0SEmmanuel Grumbach } 54530202bcf0SEmmanuel Grumbach 54540202bcf0SEmmanuel Grumbach iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 54550202bcf0SEmmanuel Grumbach apply_time); 54560202bcf0SEmmanuel Grumbach 54570202bcf0SEmmanuel Grumbach return 0; 54580202bcf0SEmmanuel Grumbach } 54590202bcf0SEmmanuel Grumbach 5460bbd6d0f8SJohannes Berg static void iwl_mvm_csa_block_txqs(void *data, struct ieee80211_sta *sta) 5461bbd6d0f8SJohannes Berg { 5462bbd6d0f8SJohannes Berg int i; 5463bbd6d0f8SJohannes Berg 5464bbd6d0f8SJohannes Berg for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 5465bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 5466bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(sta->txq[i]); 5467bbd6d0f8SJohannes Berg 5468bbd6d0f8SJohannes Berg set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5469bbd6d0f8SJohannes Berg } 5470bbd6d0f8SJohannes Berg } 5471bbd6d0f8SJohannes Berg 5472f6780614SSara Sharon #define IWL_MAX_CSA_BLOCK_TX 1500 5473cbce62a3SMiri Korenblit int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 5474e705c121SKalle Valo struct ieee80211_vif *vif, 5475e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5476e705c121SKalle Valo { 5477e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5478e705c121SKalle Valo struct ieee80211_vif *csa_vif; 5479e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5480bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq; 5481e705c121SKalle Valo int ret; 5482e705c121SKalle Valo 5483e705c121SKalle Valo mutex_lock(&mvm->mutex); 5484e705c121SKalle Valo 5485e705c121SKalle Valo mvmvif->csa_failed = false; 54862964b57fSJohannes Berg mvmvif->csa_blocks_tx = false; 5487e705c121SKalle Valo 5488e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 5489e705c121SKalle Valo chsw->chandef.center_freq1); 5490e705c121SKalle Valo 54917174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 54927174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 54937174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 5494e705c121SKalle Valo 5495e705c121SKalle Valo switch (vif->type) { 5496e705c121SKalle Valo case NL80211_IFTYPE_AP: 5497e705c121SKalle Valo csa_vif = 5498e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 5499e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5500d0a9123eSJohannes Berg if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, 5501e705c121SKalle Valo "Another CSA is already in progress")) { 5502e705c121SKalle Valo ret = -EBUSY; 5503e705c121SKalle Valo goto out_unlock; 5504e705c121SKalle Valo } 5505e705c121SKalle Valo 5506d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 5507d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 5508d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 5509d3a108a4SAndrei Otcheretianski ret = -EBUSY; 5510d3a108a4SAndrei Otcheretianski goto out_unlock; 5511d3a108a4SAndrei Otcheretianski } 5512d3a108a4SAndrei Otcheretianski 5513e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 5514e705c121SKalle Valo 5515e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 5516e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 5517e705c121SKalle Valo ret = -EBUSY; 5518e705c121SKalle Valo goto out_unlock; 5519e705c121SKalle Valo } 5520e705c121SKalle Valo 5521d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 5522d3a108a4SAndrei Otcheretianski 5523bbd6d0f8SJohannes Berg if (!chsw->block_tx) 5524bbd6d0f8SJohannes Berg break; 5525bbd6d0f8SJohannes Berg /* don't need blocking in driver otherwise - mac80211 will do */ 5526bbd6d0f8SJohannes Berg if (!ieee80211_hw_check(mvm->hw, HANDLES_QUIET_CSA)) 5527bbd6d0f8SJohannes Berg break; 5528bbd6d0f8SJohannes Berg 5529bbd6d0f8SJohannes Berg mvmvif->csa_blocks_tx = true; 5530bbd6d0f8SJohannes Berg mvmtxq = iwl_mvm_txq_from_mac80211(vif->txq); 5531bbd6d0f8SJohannes Berg set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5532bbd6d0f8SJohannes Berg ieee80211_iterate_stations_atomic(mvm->hw, 5533bbd6d0f8SJohannes Berg iwl_mvm_csa_block_txqs, 5534bbd6d0f8SJohannes Berg NULL); 5535e705c121SKalle Valo break; 5536e705c121SKalle Valo case NL80211_IFTYPE_STATION: 55372964b57fSJohannes Berg mvmvif->csa_blocks_tx = chsw->block_tx; 55382964b57fSJohannes Berg 55392360acbdSEmmanuel Grumbach /* 5540ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there 5541ad12b231SNathan Errera * is no need for all of this 5542ad12b231SNathan Errera */ 5543ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5544ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 5545ad12b231SNathan Errera 0)) 5546ad12b231SNathan Errera break; 5547ad12b231SNathan Errera 5548ad12b231SNathan Errera /* 55492360acbdSEmmanuel Grumbach * We haven't configured the firmware to be associated yet since 55502360acbdSEmmanuel Grumbach * we don't know the dtim period. In this case, the firmware can't 55512360acbdSEmmanuel Grumbach * track the beacons. 55522360acbdSEmmanuel Grumbach */ 5553f276e20bSJohannes Berg if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) { 55542360acbdSEmmanuel Grumbach ret = -EBUSY; 55552360acbdSEmmanuel Grumbach goto out_unlock; 55562360acbdSEmmanuel Grumbach } 55572360acbdSEmmanuel Grumbach 5558aee2eac7SJohannes Berg if (chsw->delay > IWL_MAX_CSA_BLOCK_TX && 5559aee2eac7SJohannes Berg hweight16(vif->valid_links) <= 1) 556087d9564eSJohannes Berg schedule_delayed_work(&mvmvif->csa_work, 0); 556187d9564eSJohannes Berg 5562f6780614SSara Sharon if (chsw->block_tx) { 5563f6780614SSara Sharon /* 5564f6780614SSara Sharon * In case of undetermined / long time with immediate 5565f6780614SSara Sharon * quiet monitor status to gracefully disconnect 5566f6780614SSara Sharon */ 5567f6780614SSara Sharon if (!chsw->count || 5568f6780614SSara Sharon chsw->count * vif->bss_conf.beacon_int > 5569f6780614SSara Sharon IWL_MAX_CSA_BLOCK_TX) 5570f6780614SSara Sharon schedule_delayed_work(&mvmvif->csa_work, 5571f6780614SSara Sharon msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 5572f6780614SSara Sharon } 5573e705c121SKalle Valo 55740202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 55750202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 55760202bcf0SEmmanuel Grumbach ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 5577e705c121SKalle Valo if (ret) 5578e705c121SKalle Valo goto out_unlock; 55790202bcf0SEmmanuel Grumbach } else { 558074a10252SSara Sharon iwl_mvm_schedule_client_csa(mvm, vif, chsw); 55810202bcf0SEmmanuel Grumbach } 558281b4e44eSSara Sharon 558381b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 558481b4e44eSSara Sharon mvmvif->csa_misbehave = false; 5585e705c121SKalle Valo break; 5586e705c121SKalle Valo default: 5587e705c121SKalle Valo break; 5588e705c121SKalle Valo } 5589e705c121SKalle Valo 5590e705c121SKalle Valo mvmvif->ps_disabled = true; 5591e705c121SKalle Valo 5592e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 5593e705c121SKalle Valo if (ret) 5594e705c121SKalle Valo goto out_unlock; 5595e705c121SKalle Valo 5596e705c121SKalle Valo /* we won't be on this channel any longer */ 5597e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 5598e705c121SKalle Valo 5599e705c121SKalle Valo out_unlock: 5600e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5601e705c121SKalle Valo 5602e705c121SKalle Valo return ret; 5603e705c121SKalle Valo } 5604e705c121SKalle Valo 5605cbce62a3SMiri Korenblit void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 5606c37763d2SSara Sharon struct ieee80211_vif *vif, 5607c37763d2SSara Sharon struct ieee80211_channel_switch *chsw) 5608e705c121SKalle Valo { 5609e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5610c37763d2SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5611c37763d2SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 5612c37763d2SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 5613c37763d2SSara Sharon mvmvif->color)), 5614c37763d2SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 5615c37763d2SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 5616c37763d2SSara Sharon .cs_count = chsw->count, 561777738865SSara Sharon .cs_mode = chsw->block_tx, 5618c37763d2SSara Sharon }; 5619e705c121SKalle Valo 5620ad12b231SNathan Errera /* 5621ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there is no 5622ad12b231SNathan Errera * need for all of this 5623ad12b231SNathan Errera */ 5624ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5625ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 5626ad12b231SNathan Errera return; 5627ad12b231SNathan Errera 5628c37763d2SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 5629c37763d2SSara Sharon return; 5630e705c121SKalle Valo 5631c3eae059SGregory Greenman IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 5632c3eae059SGregory Greenman mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 5633c3eae059SGregory Greenman 563481b4e44eSSara Sharon if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 563581b4e44eSSara Sharon if (mvmvif->csa_misbehave) { 56365ecd5d82SJohannes Berg struct ieee80211_bss_conf *link_conf; 56375ecd5d82SJohannes Berg 563881b4e44eSSara Sharon /* Second time, give up on this AP*/ 56395ecd5d82SJohannes Berg 56405ecd5d82SJohannes Berg link_conf = wiphy_dereference(hw->wiphy, 56415ecd5d82SJohannes Berg vif->link_conf[chsw->link_id]); 56425ecd5d82SJohannes Berg if (WARN_ON(!link_conf)) 56435ecd5d82SJohannes Berg return; 56445ecd5d82SJohannes Berg 56455ecd5d82SJohannes Berg iwl_mvm_abort_channel_switch(hw, vif, link_conf); 5646a469a593SEmmanuel Grumbach ieee80211_chswitch_done(vif, false, 0); 564781b4e44eSSara Sharon mvmvif->csa_misbehave = false; 564881b4e44eSSara Sharon return; 5649e705c121SKalle Valo } 565081b4e44eSSara Sharon mvmvif->csa_misbehave = true; 5651e705c121SKalle Valo } 565281b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 5653e705c121SKalle Valo 5654caf46377SSara Sharon mutex_lock(&mvm->mutex); 5655caf46377SSara Sharon if (mvmvif->csa_failed) 5656caf46377SSara Sharon goto out_unlock; 5657e705c121SKalle Valo 5658c37763d2SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 5659c37763d2SSara Sharon WIDE_ID(MAC_CONF_GROUP, 5660c37763d2SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 5661caf46377SSara Sharon 0, sizeof(cmd), &cmd)); 5662caf46377SSara Sharon out_unlock: 5663caf46377SSara Sharon mutex_unlock(&mvm->mutex); 5664e705c121SKalle Valo } 5665e705c121SKalle Valo 56666110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 56676110d9e5SDavid Spinadel { 5668435d0827SSara Sharon int i; 5669435d0827SSara Sharon 567006195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 5671309c4848SLuca Coelho if (drop) { 5672309c4848SLuca Coelho mutex_lock(&mvm->mutex); 56736110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 5674d4e3a341SMordechay Goodstein iwl_mvm_flushable_queues(mvm) & queues); 5675309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 5676309c4848SLuca Coelho } else { 5677435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 5678309c4848SLuca Coelho } 5679435d0827SSara Sharon return; 5680435d0827SSara Sharon } 56816110d9e5SDavid Spinadel 56826110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 5683be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5684435d0827SSara Sharon struct ieee80211_sta *sta; 5685435d0827SSara Sharon 5686435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 56876110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 56886110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 56896110d9e5SDavid Spinadel continue; 56906110d9e5SDavid Spinadel 569106195639SSara Sharon if (drop) 5692d4e3a341SMordechay Goodstein iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 569306195639SSara Sharon else 56946110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 56956110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 56966110d9e5SDavid Spinadel } 56976110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 56986110d9e5SDavid Spinadel } 56996110d9e5SDavid Spinadel 5700cbce62a3SMiri Korenblit void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5701cbce62a3SMiri Korenblit u32 queues, bool drop) 5702e705c121SKalle Valo { 57032964b57fSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5704e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5705e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 5706e705c121SKalle Valo struct ieee80211_sta *sta; 5707d3f9cd61SJohannes Berg bool ap_sta_done = false; 5708e705c121SKalle Valo int i; 5709e705c121SKalle Valo u32 msk = 0; 5710e705c121SKalle Valo 57116110d9e5SDavid Spinadel if (!vif) { 57126110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 57136110d9e5SDavid Spinadel return; 57146110d9e5SDavid Spinadel } 57156110d9e5SDavid Spinadel 57162964b57fSJohannes Berg if (!drop && hweight16(vif->active_links) <= 1) { 57172964b57fSJohannes Berg int link_id = vif->active_links ? __ffs(vif->active_links) : 0; 57182964b57fSJohannes Berg struct ieee80211_bss_conf *link_conf; 57192964b57fSJohannes Berg 57202964b57fSJohannes Berg link_conf = wiphy_dereference(hw->wiphy, 57212964b57fSJohannes Berg vif->link_conf[link_id]); 57222964b57fSJohannes Berg if (WARN_ON(!link_conf)) 57232964b57fSJohannes Berg return; 57242964b57fSJohannes Berg if (link_conf->csa_active && mvmvif->csa_blocks_tx) 57252964b57fSJohannes Berg drop = true; 57262964b57fSJohannes Berg } 57272964b57fSJohannes Berg 572824afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 572924afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 573024afba76SLiad Kaufman 5731e705c121SKalle Valo mutex_lock(&mvm->mutex); 5732e705c121SKalle Valo 5733e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 5734be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5735e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 5736e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5737e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 5738e705c121SKalle Valo continue; 5739e705c121SKalle Valo 5740e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 5741e705c121SKalle Valo if (mvmsta->vif != vif) 5742e705c121SKalle Valo continue; 5743e705c121SKalle Valo 5744d3f9cd61SJohannes Berg if (sta == mvmvif->ap_sta) { 5745d3f9cd61SJohannes Berg if (ap_sta_done) 5746d3f9cd61SJohannes Berg continue; 5747d3f9cd61SJohannes Berg ap_sta_done = true; 5748d3f9cd61SJohannes Berg } 5749d3f9cd61SJohannes Berg 5750d49394a1SSara Sharon if (drop) { 575139176296SJohannes Berg if (iwl_mvm_flush_sta(mvm, mvmsta->deflink.sta_id, 575239176296SJohannes Berg mvmsta->tfd_queue_msk)) 5753d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 5754d49394a1SSara Sharon } else { 5755d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 5756d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 5757f7bd883bSJohannes Berg else /* only used for !iwl_mvm_has_new_tx_api() below */ 5758f7bd883bSJohannes Berg msk |= mvmsta->tfd_queue_msk; 5759e705c121SKalle Valo } 5760d49394a1SSara Sharon } 5761e705c121SKalle Valo 5762e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5763e705c121SKalle Valo 5764e705c121SKalle Valo /* this can take a while, and we may need/want other operations 5765e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 5766e705c121SKalle Valo */ 5767d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 5768a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 5769e705c121SKalle Valo } 5770e705c121SKalle Valo 5771a6cc6ccbSJohannes Berg void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5772a6cc6ccbSJohannes Berg struct ieee80211_sta *sta) 5773a6cc6ccbSJohannes Berg { 577443874283SJohannes Berg struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5775a6cc6ccbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 577643874283SJohannes Berg struct iwl_mvm_link_sta *mvm_link_sta; 577743874283SJohannes Berg struct ieee80211_link_sta *link_sta; 577843874283SJohannes Berg int link_id; 5779a6cc6ccbSJohannes Berg 5780a6cc6ccbSJohannes Berg mutex_lock(&mvm->mutex); 578143874283SJohannes Berg for_each_sta_active_link(vif, sta, link_sta, link_id) { 578243874283SJohannes Berg mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_id], 5783a6cc6ccbSJohannes Berg lockdep_is_held(&mvm->mutex)); 578443874283SJohannes Berg if (!mvm_link_sta) 5785a6cc6ccbSJohannes Berg continue; 5786a6cc6ccbSJohannes Berg 578743874283SJohannes Berg if (iwl_mvm_flush_sta(mvm, mvm_link_sta->sta_id, 578839176296SJohannes Berg mvmsta->tfd_queue_msk)) 5789a6cc6ccbSJohannes Berg IWL_ERR(mvm, "flush request fail\n"); 5790a6cc6ccbSJohannes Berg } 5791a6cc6ccbSJohannes Berg mutex_unlock(&mvm->mutex); 5792a6cc6ccbSJohannes Berg } 5793a6cc6ccbSJohannes Berg 5794cbce62a3SMiri Korenblit int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 5795e705c121SKalle Valo struct survey_info *survey) 5796e705c121SKalle Valo { 5797e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5798b6e3d1baSAnjaneyulu int ret = 0; 5799b6e3d1baSAnjaneyulu u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, 5800b6e3d1baSAnjaneyulu WIDE_ID(SYSTEM_GROUP, 5801b6e3d1baSAnjaneyulu SYSTEM_STATISTICS_CMD), 5802b6e3d1baSAnjaneyulu IWL_FW_CMD_VER_UNKNOWN); 5803e705c121SKalle Valo 5804e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 5805e705c121SKalle Valo 5806e705c121SKalle Valo /* only support global statistics right now */ 5807e705c121SKalle Valo if (idx != 0) 5808e705c121SKalle Valo return -ENOENT; 5809e705c121SKalle Valo 5810280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 5811e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 5812e705c121SKalle Valo return -ENOENT; 5813e705c121SKalle Valo 5814e705c121SKalle Valo mutex_lock(&mvm->mutex); 5815e705c121SKalle Valo 5816aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 5817e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 5818e705c121SKalle Valo if (ret) 5819e705c121SKalle Valo goto out; 5820e705c121SKalle Valo } 5821e705c121SKalle Valo 5822b6e3d1baSAnjaneyulu survey->filled = SURVEY_INFO_TIME_RX | 5823b6e3d1baSAnjaneyulu SURVEY_INFO_TIME_TX; 5824e705c121SKalle Valo 5825e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 5826e705c121SKalle Valo mvm->radio_stats.rx_time; 5827e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 5828e705c121SKalle Valo 5829e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 5830e705c121SKalle Valo mvm->radio_stats.tx_time; 5831e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 5832e705c121SKalle Valo 5833b6e3d1baSAnjaneyulu /* the new fw api doesn't support the following fields */ 5834b6e3d1baSAnjaneyulu if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN) 5835b6e3d1baSAnjaneyulu goto out; 5836b6e3d1baSAnjaneyulu 5837b6e3d1baSAnjaneyulu survey->filled |= SURVEY_INFO_TIME | 5838b6e3d1baSAnjaneyulu SURVEY_INFO_TIME_SCAN; 5839b6e3d1baSAnjaneyulu survey->time = mvm->accu_radio_stats.on_time_rf + 5840b6e3d1baSAnjaneyulu mvm->radio_stats.on_time_rf; 5841b6e3d1baSAnjaneyulu do_div(survey->time, USEC_PER_MSEC); 5842b6e3d1baSAnjaneyulu 5843e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 5844e705c121SKalle Valo mvm->radio_stats.on_time_scan; 5845e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 5846e705c121SKalle Valo 5847e705c121SKalle Valo out: 5848e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5849e705c121SKalle Valo return ret; 5850e705c121SKalle Valo } 5851e705c121SKalle Valo 5852ed780545SJohannes Berg static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 5853ed780545SJohannes Berg { 585482cdbd11SMiri Korenblit u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 58557138763eSJohannes Berg u32 gi_ltf; 585682cdbd11SMiri Korenblit 585782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 5858ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_20: 5859ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_20; 5860ed780545SJohannes Berg break; 5861ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_40: 5862ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_40; 5863ed780545SJohannes Berg break; 5864ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_80: 5865ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_80; 5866ed780545SJohannes Berg break; 5867ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_160: 5868ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_160; 5869ed780545SJohannes Berg break; 587023dcee94SJohannes Berg case RATE_MCS_CHAN_WIDTH_320: 587123dcee94SJohannes Berg rinfo->bw = RATE_INFO_BW_320; 587223dcee94SJohannes Berg break; 5873ed780545SJohannes Berg } 5874ed780545SJohannes Berg 587582cdbd11SMiri Korenblit if (format == RATE_MCS_CCK_MSK || 587682cdbd11SMiri Korenblit format == RATE_MCS_LEGACY_OFDM_MSK) { 587782cdbd11SMiri Korenblit int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 587882cdbd11SMiri Korenblit 587982cdbd11SMiri Korenblit /* add the offset needed to get to the legacy ofdm indices */ 588082cdbd11SMiri Korenblit if (format == RATE_MCS_LEGACY_OFDM_MSK) 588182cdbd11SMiri Korenblit rate += IWL_FIRST_OFDM_RATE; 588282cdbd11SMiri Korenblit 588382cdbd11SMiri Korenblit switch (rate) { 588482cdbd11SMiri Korenblit case IWL_RATE_1M_INDEX: 588582cdbd11SMiri Korenblit rinfo->legacy = 10; 588682cdbd11SMiri Korenblit break; 588782cdbd11SMiri Korenblit case IWL_RATE_2M_INDEX: 588882cdbd11SMiri Korenblit rinfo->legacy = 20; 588982cdbd11SMiri Korenblit break; 589082cdbd11SMiri Korenblit case IWL_RATE_5M_INDEX: 589182cdbd11SMiri Korenblit rinfo->legacy = 55; 589282cdbd11SMiri Korenblit break; 589382cdbd11SMiri Korenblit case IWL_RATE_11M_INDEX: 589482cdbd11SMiri Korenblit rinfo->legacy = 110; 589582cdbd11SMiri Korenblit break; 589682cdbd11SMiri Korenblit case IWL_RATE_6M_INDEX: 589782cdbd11SMiri Korenblit rinfo->legacy = 60; 589882cdbd11SMiri Korenblit break; 589982cdbd11SMiri Korenblit case IWL_RATE_9M_INDEX: 590082cdbd11SMiri Korenblit rinfo->legacy = 90; 590182cdbd11SMiri Korenblit break; 590282cdbd11SMiri Korenblit case IWL_RATE_12M_INDEX: 590382cdbd11SMiri Korenblit rinfo->legacy = 120; 590482cdbd11SMiri Korenblit break; 590582cdbd11SMiri Korenblit case IWL_RATE_18M_INDEX: 590682cdbd11SMiri Korenblit rinfo->legacy = 180; 590782cdbd11SMiri Korenblit break; 590882cdbd11SMiri Korenblit case IWL_RATE_24M_INDEX: 590982cdbd11SMiri Korenblit rinfo->legacy = 240; 591082cdbd11SMiri Korenblit break; 591182cdbd11SMiri Korenblit case IWL_RATE_36M_INDEX: 591282cdbd11SMiri Korenblit rinfo->legacy = 360; 591382cdbd11SMiri Korenblit break; 591482cdbd11SMiri Korenblit case IWL_RATE_48M_INDEX: 591582cdbd11SMiri Korenblit rinfo->legacy = 480; 591682cdbd11SMiri Korenblit break; 591782cdbd11SMiri Korenblit case IWL_RATE_54M_INDEX: 591882cdbd11SMiri Korenblit rinfo->legacy = 540; 591982cdbd11SMiri Korenblit } 592082cdbd11SMiri Korenblit return; 592182cdbd11SMiri Korenblit } 592282cdbd11SMiri Korenblit 5923ed780545SJohannes Berg rinfo->nss = u32_get_bits(rate_n_flags, 592482cdbd11SMiri Korenblit RATE_MCS_NSS_MSK) + 1; 592582cdbd11SMiri Korenblit rinfo->mcs = format == RATE_MCS_HT_MSK ? 592682cdbd11SMiri Korenblit RATE_HT_MCS_INDEX(rate_n_flags) : 592782cdbd11SMiri Korenblit u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 592882cdbd11SMiri Korenblit 59297138763eSJohannes Berg if (rate_n_flags & RATE_MCS_SGI_MSK) 59307138763eSJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 59317138763eSJohannes Berg 59327138763eSJohannes Berg switch (format) { 593323dcee94SJohannes Berg case RATE_MCS_EHT_MSK: 593423dcee94SJohannes Berg /* TODO: GI/LTF/RU. How does the firmware encode them? */ 593523dcee94SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; 593623dcee94SJohannes Berg break; 59377138763eSJohannes Berg case RATE_MCS_HE_MSK: 59387138763eSJohannes Berg gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK); 5939ed780545SJohannes Berg 5940ed780545SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 5941ed780545SJohannes Berg 594282cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 5943ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_HE_RU; 5944ed780545SJohannes Berg rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 5945ed780545SJohannes Berg } 5946ed780545SJohannes Berg 594782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 594882cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_SU: 594982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_EXT_SU: 5950ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5951ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5952ed780545SJohannes Berg else if (gi_ltf == 2) 5953ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 595482cdbd11SMiri Korenblit else if (gi_ltf == 3) 5955ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 595682cdbd11SMiri Korenblit else 595782cdbd11SMiri Korenblit rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5958ed780545SJohannes Berg break; 595982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_MU: 5960ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5961ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5962ed780545SJohannes Berg else if (gi_ltf == 2) 5963ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5964ed780545SJohannes Berg else 5965ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5966ed780545SJohannes Berg break; 596782cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_TRIG: 5968ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5969ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5970ed780545SJohannes Berg else 5971ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5972ed780545SJohannes Berg break; 5973ed780545SJohannes Berg } 5974ed780545SJohannes Berg 5975ed780545SJohannes Berg if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 5976ed780545SJohannes Berg rinfo->he_dcm = 1; 59777138763eSJohannes Berg break; 59787138763eSJohannes Berg case RATE_MCS_HT_MSK: 597982cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_MCS; 59807138763eSJohannes Berg break; 59817138763eSJohannes Berg case RATE_MCS_VHT_MSK: 598282cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 59837138763eSJohannes Berg break; 5984ed780545SJohannes Berg } 5985ed780545SJohannes Berg } 5986ed780545SJohannes Berg 5987cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 5988e705c121SKalle Valo struct ieee80211_vif *vif, 5989e705c121SKalle Valo struct ieee80211_sta *sta, 5990e705c121SKalle Valo struct station_info *sinfo) 5991e705c121SKalle Valo { 5992e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5993e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5994e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5995b6e3d1baSAnjaneyulu int i; 5996e705c121SKalle Valo 5997c8ee33e1SGregory Greenman if (mvmsta->deflink.avg_energy) { 5998c8ee33e1SGregory Greenman sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy; 599922d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 6000988b5968SSara Sharon } 6001988b5968SSara Sharon 6002ed780545SJohannes Berg if (iwl_mvm_has_tlc_offload(mvm)) { 6003c8ee33e1SGregory Greenman struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw; 6004ed780545SJohannes Berg 6005ed780545SJohannes Berg iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 6006ed780545SJohannes Berg sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 6007ed780545SJohannes Berg } 6008ed780545SJohannes Berg 6009e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 6010e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 6011e705c121SKalle Valo return; 6012e705c121SKalle Valo 6013f276e20bSJohannes Berg if (!vif->cfg.assoc) 6014e705c121SKalle Valo return; 6015e705c121SKalle Valo 6016e705c121SKalle Valo mutex_lock(&mvm->mutex); 6017e705c121SKalle Valo 6018c8ee33e1SGregory Greenman if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id) 6019e705c121SKalle Valo goto unlock; 6020e705c121SKalle Valo 6021e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 6022e705c121SKalle Valo goto unlock; 6023e705c121SKalle Valo 6024b6e3d1baSAnjaneyulu sinfo->rx_beacon = 0; 6025b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 6026b6e3d1baSAnjaneyulu sinfo->rx_beacon += mvmvif->link[i]->beacon_stats.num_beacons + 6027b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.accu_num_beacons; 6028b6e3d1baSAnjaneyulu 602922d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 6030650cadb7SGregory Greenman if (mvmvif->deflink.beacon_stats.avg_signal) { 6031e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 6032650cadb7SGregory Greenman sinfo->rx_beacon_signal_avg = 6033650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.avg_signal; 603422d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 6035e705c121SKalle Valo } 6036e705c121SKalle Valo unlock: 6037e705c121SKalle Valo mutex_unlock(&mvm->mutex); 6038e705c121SKalle Valo } 6039e705c121SKalle Valo 6040119c2a13SMordechay Goodstein static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 6041119c2a13SMordechay Goodstein struct ieee80211_vif *vif, 6042119c2a13SMordechay Goodstein const struct ieee80211_mlme_event *mlme) 6043119c2a13SMordechay Goodstein { 60441a81bddfSMordechay Goodstein if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 60451a81bddfSMordechay Goodstein (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 6046119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 6047119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 6048119c2a13SMordechay Goodstein NULL); 6049119c2a13SMordechay Goodstein return; 6050119c2a13SMordechay Goodstein } 6051119c2a13SMordechay Goodstein 6052119c2a13SMordechay Goodstein if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 6053119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 6054119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_DEASSOC, 6055119c2a13SMordechay Goodstein NULL); 6056119c2a13SMordechay Goodstein return; 6057119c2a13SMordechay Goodstein } 6058119c2a13SMordechay Goodstein } 6059119c2a13SMordechay Goodstein 6060e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 6061e705c121SKalle Valo struct ieee80211_vif *vif, 6062e705c121SKalle Valo const struct ieee80211_event *event) 6063e705c121SKalle Valo { 60644c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 6065e705c121SKalle Valo do { \ 60664c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 6067e705c121SKalle Valo break; \ 60687174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 6069e705c121SKalle Valo } while (0) 6070e705c121SKalle Valo 6071e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 6072e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 6073e705c121SKalle Valo 6074119c2a13SMordechay Goodstein if (iwl_trans_dbg_ini_valid(mvm->trans)) { 6075119c2a13SMordechay Goodstein iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 6076119c2a13SMordechay Goodstein return; 6077119c2a13SMordechay Goodstein } 6078119c2a13SMordechay Goodstein 60796c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 60806c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 60816c042d75SSara Sharon if (!trig) 6082e705c121SKalle Valo return; 6083e705c121SKalle Valo 6084e705c121SKalle Valo trig_mlme = (void *)trig->data; 6085e705c121SKalle Valo 6086e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 6087e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 60884c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 6089e705c121SKalle Valo "DENIED ASSOC: reason %d", 6090e705c121SKalle Valo event->u.mlme.reason); 6091e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 60924c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 6093e705c121SKalle Valo "ASSOC TIMEOUT"); 6094e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 6095e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 60964c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 6097e705c121SKalle Valo "DENIED AUTH: reason %d", 6098e705c121SKalle Valo event->u.mlme.reason); 6099e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 61004c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 6101e705c121SKalle Valo "AUTH TIMEOUT"); 6102e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 61034c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 6104e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 6105e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 61064c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 6107e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 6108e705c121SKalle Valo } 6109e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 6110e705c121SKalle Valo } 6111e705c121SKalle Valo 6112e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 6113e705c121SKalle Valo struct ieee80211_vif *vif, 6114e705c121SKalle Valo const struct ieee80211_event *event) 6115e705c121SKalle Valo { 6116e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 6117e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 6118e705c121SKalle Valo 61196c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 61206c042d75SSara Sharon FW_DBG_TRIGGER_BA); 61216c042d75SSara Sharon if (!trig) 6122e705c121SKalle Valo return; 6123e705c121SKalle Valo 6124e705c121SKalle Valo ba_trig = (void *)trig->data; 6125e705c121SKalle Valo 6126e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 6127e705c121SKalle Valo return; 6128e705c121SKalle Valo 61297174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 6130e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 6131e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 6132e705c121SKalle Valo event->u.ba.ssn); 6133e705c121SKalle Valo } 6134e705c121SKalle Valo 6135cbce62a3SMiri Korenblit void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 6136e705c121SKalle Valo struct ieee80211_vif *vif, 6137e705c121SKalle Valo const struct ieee80211_event *event) 6138e705c121SKalle Valo { 6139e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6140e705c121SKalle Valo 6141e705c121SKalle Valo switch (event->type) { 6142e705c121SKalle Valo case MLME_EVENT: 6143e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 6144e705c121SKalle Valo break; 6145e705c121SKalle Valo case BAR_RX_EVENT: 6146e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 6147e705c121SKalle Valo break; 6148e705c121SKalle Valo case BA_FRAME_TIMEOUT: 6149528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 6150528a542aSEmmanuel Grumbach event->u.ba.tid); 6151e705c121SKalle Valo break; 6152e705c121SKalle Valo default: 6153e705c121SKalle Valo break; 6154e705c121SKalle Valo } 6155e705c121SKalle Valo } 6156e705c121SKalle Valo 615787f690f5SShaul Triebitz #define SYNC_RX_QUEUE_TIMEOUT (HZ) 6158d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 61595e1688ceSJohannes Berg enum iwl_mvm_rxq_notif_type type, 61605e1688ceSJohannes Berg bool sync, 61615e1688ceSJohannes Berg const void *data, u32 size) 61620636b938SSara Sharon { 61635e1688ceSJohannes Berg struct { 61645e1688ceSJohannes Berg struct iwl_rxq_sync_cmd cmd; 61655e1688ceSJohannes Berg struct iwl_mvm_internal_rxq_notif notif; 61665e1688ceSJohannes Berg } __packed cmd = { 61675e1688ceSJohannes Berg .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 61685e1688ceSJohannes Berg .cmd.count = 61695e1688ceSJohannes Berg cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 61705e1688ceSJohannes Berg size), 61715e1688ceSJohannes Berg .notif.type = type, 61725e1688ceSJohannes Berg .notif.sync = sync, 61735e1688ceSJohannes Berg }; 61745e1688ceSJohannes Berg struct iwl_host_cmd hcmd = { 61755e1688ceSJohannes Berg .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 61765e1688ceSJohannes Berg .data[0] = &cmd, 61775e1688ceSJohannes Berg .len[0] = sizeof(cmd), 61785e1688ceSJohannes Berg .data[1] = data, 61795e1688ceSJohannes Berg .len[1] = size, 61805e1688ceSJohannes Berg .flags = sync ? 0 : CMD_ASYNC, 61815e1688ceSJohannes Berg }; 61820636b938SSara Sharon int ret; 61830636b938SSara Sharon 61845e1688ceSJohannes Berg /* size must be a multiple of DWORD */ 61855e1688ceSJohannes Berg if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 61865e1688ceSJohannes Berg return; 61870636b938SSara Sharon 6188cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 61890636b938SSara Sharon return; 61900636b938SSara Sharon 61915e1688ceSJohannes Berg if (sync) { 61925e1688ceSJohannes Berg cmd.notif.cookie = mvm->queue_sync_cookie; 61932f7a04c7SJohannes Berg mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 6194a2113cc4SNaftali Goldstein } 6195d0ff5d22SSara Sharon 61965e1688ceSJohannes Berg ret = iwl_mvm_send_cmd(mvm, &hcmd); 61970636b938SSara Sharon if (ret) { 61980636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 61990636b938SSara Sharon goto out; 62000636b938SSara Sharon } 6201d0ff5d22SSara Sharon 62025e1688ceSJohannes Berg if (sync) { 62033c514bf8SEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 62043a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 62052f7a04c7SJohannes Berg READ_ONCE(mvm->queue_sync_state) == 0 || 62060dd2b42cSJohannes Berg iwl_mvm_is_radio_hw_killed(mvm), 620787f690f5SShaul Triebitz SYNC_RX_QUEUE_TIMEOUT); 62080dd2b42cSJohannes Berg WARN_ONCE(!ret && !iwl_mvm_is_radio_hw_killed(mvm), 6209f4eedfd8SJohannes Berg "queue sync: failed to sync, state is 0x%lx, cookie %d\n", 6210f4eedfd8SJohannes Berg mvm->queue_sync_state, 6211f4eedfd8SJohannes Berg mvm->queue_sync_cookie); 62126ad04359SJohannes Berg } 62130636b938SSara Sharon 62140636b938SSara Sharon out: 62155e1688ceSJohannes Berg if (sync) { 62162f7a04c7SJohannes Berg mvm->queue_sync_state = 0; 62170636b938SSara Sharon mvm->queue_sync_cookie++; 62180636b938SSara Sharon } 62195f8a3561SJohannes Berg } 62200636b938SSara Sharon 6221cbce62a3SMiri Korenblit void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 62220636b938SSara Sharon { 62230636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 62240636b938SSara Sharon 62250636b938SSara Sharon mutex_lock(&mvm->mutex); 62265e1688ceSJohannes Berg iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 62270636b938SSara Sharon mutex_unlock(&mvm->mutex); 62280636b938SSara Sharon } 62290636b938SSara Sharon 6230cbce62a3SMiri Korenblit int 6231b73f9a4aSJohannes Berg iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 6232b73f9a4aSJohannes Berg struct ieee80211_vif *vif, 6233b73f9a4aSJohannes Berg struct cfg80211_ftm_responder_stats *stats) 6234b73f9a4aSJohannes Berg { 6235b73f9a4aSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6236b73f9a4aSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 6237b73f9a4aSJohannes Berg 6238b73f9a4aSJohannes Berg if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 6239b73f9a4aSJohannes Berg !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 6240b73f9a4aSJohannes Berg return -EINVAL; 6241b73f9a4aSJohannes Berg 6242b73f9a4aSJohannes Berg mutex_lock(&mvm->mutex); 6243b73f9a4aSJohannes Berg *stats = mvm->ftm_resp_stats; 6244b73f9a4aSJohannes Berg mutex_unlock(&mvm->mutex); 6245b73f9a4aSJohannes Berg 6246b73f9a4aSJohannes Berg stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 6247b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 6248b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_FAILED_NUM) | 6249b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_ASAP_NUM) | 6250b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 6251b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 6252b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 6253b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 6254b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 6255b73f9a4aSJohannes Berg 6256b73f9a4aSJohannes Berg return 0; 6257b73f9a4aSJohannes Berg } 6258b73f9a4aSJohannes Berg 6259cbce62a3SMiri Korenblit int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6260fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 6261fc36ffdaSJohannes Berg { 6262fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6263fc36ffdaSJohannes Berg int ret; 6264fc36ffdaSJohannes Berg 6265fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 6266fc36ffdaSJohannes Berg ret = iwl_mvm_ftm_start(mvm, vif, request); 6267fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 6268fc36ffdaSJohannes Berg 6269fc36ffdaSJohannes Berg return ret; 6270fc36ffdaSJohannes Berg } 6271fc36ffdaSJohannes Berg 6272cbce62a3SMiri Korenblit void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6273fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 6274fc36ffdaSJohannes Berg { 6275fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6276fc36ffdaSJohannes Berg 6277fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 6278fc36ffdaSJohannes Berg iwl_mvm_ftm_abort(mvm, request); 6279fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 6280fc36ffdaSJohannes Berg } 6281fc36ffdaSJohannes Berg 6282438af969SSara Sharon static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 6283438af969SSara Sharon { 6284438af969SSara Sharon u8 protocol = ip_hdr(skb)->protocol; 6285438af969SSara Sharon 6286438af969SSara Sharon if (!IS_ENABLED(CONFIG_INET)) 6287438af969SSara Sharon return false; 6288438af969SSara Sharon 6289438af969SSara Sharon return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 6290438af969SSara Sharon } 6291438af969SSara Sharon 6292438af969SSara Sharon static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 6293438af969SSara Sharon struct sk_buff *head, 6294438af969SSara Sharon struct sk_buff *skb) 6295438af969SSara Sharon { 6296438af969SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6297438af969SSara Sharon 6298438af969SSara Sharon /* For now don't aggregate IPv6 in AMSDU */ 6299438af969SSara Sharon if (skb->protocol != htons(ETH_P_IP)) 6300438af969SSara Sharon return false; 6301438af969SSara Sharon 6302438af969SSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) 6303438af969SSara Sharon return true; 6304438af969SSara Sharon 6305438af969SSara Sharon return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 6306438af969SSara Sharon } 6307438af969SSara Sharon 6308be8897e2SAvraham Stern int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw, 6309cf85123aSAvraham Stern struct ieee80211_vif *vif, 6310cf85123aSAvraham Stern struct cfg80211_set_hw_timestamp *hwts) 6311cf85123aSAvraham Stern { 6312cf85123aSAvraham Stern struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6313cf85123aSAvraham Stern u32 protocols = 0; 6314cf85123aSAvraham Stern int ret; 6315cf85123aSAvraham Stern 6316cf85123aSAvraham Stern /* HW timestamping is only supported for a specific station */ 6317cf85123aSAvraham Stern if (!hwts->macaddr) 6318cf85123aSAvraham Stern return -EOPNOTSUPP; 6319cf85123aSAvraham Stern 6320cf85123aSAvraham Stern if (hwts->enable) 6321cf85123aSAvraham Stern protocols = 6322cf85123aSAvraham Stern IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM; 6323cf85123aSAvraham Stern 6324cf85123aSAvraham Stern mutex_lock(&mvm->mutex); 6325cf85123aSAvraham Stern ret = iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols); 6326cf85123aSAvraham Stern mutex_unlock(&mvm->mutex); 6327cf85123aSAvraham Stern 6328cf85123aSAvraham Stern return ret; 6329cf85123aSAvraham Stern } 6330cf85123aSAvraham Stern 6331e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 6332e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 6333cfbc6c4cSSara Sharon .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 6334e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 6335e8503aecSBen Greear .get_antenna = iwl_mvm_op_get_antenna, 63364ea1ed1dSEmmanuel Grumbach .set_antenna = iwl_mvm_op_set_antenna, 6337e705c121SKalle Valo .start = iwl_mvm_mac_start, 6338e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 6339e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 6340e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 6341e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 6342e705c121SKalle Valo .config = iwl_mvm_mac_config, 6343e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 6344e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 6345e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 6346e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 6347e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 6348e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 6349e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 6350e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 6351e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 6352e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 6353e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 6354e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 6355e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 6356e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 6357e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 63586b1259d1SJohannes Berg .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 6359e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 6360e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 6361a6cc6ccbSJohannes Berg .flush_sta = iwl_mvm_mac_flush_sta, 6362e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 6363e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 6364e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 6365e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 6366e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 6367e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 6368e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 6369e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 6370e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 6371e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 6372e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 6373e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 6374e705c121SKalle Valo 6375ae7ba17bSShaul Triebitz .start_ap = iwl_mvm_start_ap, 6376ae7ba17bSShaul Triebitz .stop_ap = iwl_mvm_stop_ap, 6377ae7ba17bSShaul Triebitz .join_ibss = iwl_mvm_start_ibss, 6378ae7ba17bSShaul Triebitz .leave_ibss = iwl_mvm_stop_ibss, 6379e705c121SKalle Valo 63802f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 63812f0282dbSJohannes Berg 6382e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 6383e705c121SKalle Valo 6384e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 6385e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 6386e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 638779221126SSara Sharon .abort_channel_switch = iwl_mvm_abort_channel_switch, 6388c37763d2SSara Sharon .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 6389e705c121SKalle Valo 6390e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 6391e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 6392e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 6393e705c121SKalle Valo 6394e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 6395e705c121SKalle Valo 63960636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 63970636b938SSara Sharon 6398e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 6399e705c121SKalle Valo 6400e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 6401e705c121SKalle Valo /* look at d3.c */ 6402e705c121SKalle Valo .suspend = iwl_mvm_suspend, 6403e705c121SKalle Valo .resume = iwl_mvm_resume, 6404e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 6405e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 6406e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 6407e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 6408e705c121SKalle Valo #endif 6409e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 6410e705c121SKalle Valo #endif 6411e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 6412e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 6413b73f9a4aSJohannes Berg .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 6414fc36ffdaSJohannes Berg .start_pmsr = iwl_mvm_start_pmsr, 6415fc36ffdaSJohannes Berg .abort_pmsr = iwl_mvm_abort_pmsr, 6416b73f9a4aSJohannes Berg 6417438af969SSara Sharon .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 6418177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 6419c36235acSJohannes Berg .vif_add_debugfs = iwl_mvm_vif_add_debugfs, 64203f244876SBenjamin Berg .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs, 6421177a11cfSGregory Greenman #endif 6422cf85123aSAvraham Stern .set_hw_timestamp = iwl_mvm_set_hw_timestamp, 6423e705c121SKalle Valo }; 6424