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 && 362*bbd6d0f8SJohannes Berg !iwlwifi_mod_params.disable_11be) { 3630120e6b3SGregory Greenman hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; 364*bbd6d0f8SJohannes Berg /* we handle this already earlier, but need it for MLO */ 365*bbd6d0f8SJohannes Berg ieee80211_hw_set(hw, HANDLES_QUIET_CSA); 366*bbd6d0f8SJohannes 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 726e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 7273f37c229SIdo Yariv if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 728e705c121SKalle Valo mvm->trans->ops->d3_suspend && 729e705c121SKalle Valo mvm->trans->ops->d3_resume && 730e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 731e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 732e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 733e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 734e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 735e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 736e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 737e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 738e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 739e705c121SKalle Valo 740e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 741e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 742e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 7435d1234baSTova Mussai mvm->wowlan.max_nd_match_sets = 7445d1234baSTova Mussai iwl_umac_scan_get_max_profiles(mvm->fw); 745e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 746e705c121SKalle Valo } 747e705c121SKalle Valo #endif 748e705c121SKalle Valo 749e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 750e705c121SKalle Valo if (ret) 751e705c121SKalle Valo return ret; 752e705c121SKalle Valo 753e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 754e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 755e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 756e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 757e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 758e705c121SKalle Valo } 759e705c121SKalle Valo 760e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 761e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 762e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 763e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 764e705c121SKalle Valo } 765e705c121SKalle Valo 766e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 76759fa61f3SEmmanuel Grumbach if (!iwl_mvm_is_csum_supported(mvm)) 7686772aab7SJohannes Berg hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; 76941837ca9SEmmanuel Grumbach 77091b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 77191b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 77291b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 77391b08c2dSAviya Erenfeld 7749c11d8a9SShaul Triebitz if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 7759c11d8a9SShaul Triebitz wiphy_ext_feature_set(hw->wiphy, 7769c11d8a9SShaul Triebitz NL80211_EXT_FEATURE_PROTECTED_TWT); 7779c11d8a9SShaul Triebitz 778bfcfdb59SEmmanuel Grumbach iwl_mvm_vendor_cmds_register(mvm); 779bfcfdb59SEmmanuel Grumbach 780e8503aecSBen Greear hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 781e8503aecSBen Greear hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 782e8503aecSBen Greear 783de645e89SJohannes Berg ret = ieee80211_register_hw(mvm->hw); 784de645e89SJohannes Berg if (ret) { 785de645e89SJohannes Berg iwl_mvm_leds_exit(mvm); 786e705c121SKalle Valo } 787e705c121SKalle Valo 788e705c121SKalle Valo return ret; 789e705c121SKalle Valo } 790e705c121SKalle Valo 791df2378abSJohannes Berg static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 792df2378abSJohannes Berg struct ieee80211_sta *sta) 793df2378abSJohannes Berg { 794df2378abSJohannes Berg if (likely(sta)) { 795df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 796df2378abSJohannes Berg return; 797df2378abSJohannes Berg } else { 798df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 799df2378abSJohannes Berg return; 800df2378abSJohannes Berg } 801df2378abSJohannes Berg 802df2378abSJohannes Berg ieee80211_free_txskb(mvm->hw, skb); 803df2378abSJohannes Berg } 804df2378abSJohannes Berg 805cbce62a3SMiri Korenblit void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 806cbce62a3SMiri Korenblit struct ieee80211_tx_control *control, struct sk_buff *skb) 807e705c121SKalle Valo { 808e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 809e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 810e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 811e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 812cfbc6c4cSSara Sharon bool offchannel = IEEE80211_SKB_CB(skb)->flags & 813cfbc6c4cSSara Sharon IEEE80211_TX_CTL_TX_OFFCHAN; 81490723da6SShaul Triebitz u32 link_id = u32_get_bits(info->control.flags, 81590723da6SShaul Triebitz IEEE80211_TX_CTRL_MLO_LINK); 81690723da6SShaul Triebitz struct ieee80211_sta *tmp_sta = sta; 817e705c121SKalle Valo 818e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 819e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 820e705c121SKalle Valo goto drop; 821e705c121SKalle Valo } 822e705c121SKalle Valo 823cfbc6c4cSSara Sharon if (offchannel && 824e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 825e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 826e705c121SKalle Valo goto drop; 827e705c121SKalle Valo 82810516783SJohannes Berg /* 82910516783SJohannes Berg * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 83010516783SJohannes Berg * so we treat the others as broadcast 83110516783SJohannes Berg */ 83210516783SJohannes Berg if (ieee80211_is_mgmt(hdr->frame_control)) 833e705c121SKalle Valo sta = NULL; 834e705c121SKalle Valo 835dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 836cfbc6c4cSSara Sharon if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 837cfbc6c4cSSara Sharon !offchannel) { 838dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 839dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 840650cadb7SGregory Greenman u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id); 841dc1aca22SAndrei Otcheretianski 842be9ae34eSNathan Errera if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 843dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 844dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 845dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 846dc1aca22SAndrei Otcheretianski goto drop; 847dc1aca22SAndrei Otcheretianski } 848dc1aca22SAndrei Otcheretianski } 849dc1aca22SAndrei Otcheretianski 85090723da6SShaul Triebitz if (tmp_sta && !sta && link_id != IEEE80211_LINK_UNSPECIFIED && 85190723da6SShaul Triebitz !ieee80211_is_probe_resp(hdr->frame_control)) { 85290723da6SShaul Triebitz /* translate MLD addresses to LINK addresses */ 85390723da6SShaul Triebitz struct ieee80211_link_sta *link_sta = 85490723da6SShaul Triebitz rcu_dereference(tmp_sta->link[link_id]); 85590723da6SShaul Triebitz struct ieee80211_bss_conf *link_conf = 85690723da6SShaul Triebitz rcu_dereference(info->control.vif->link_conf[link_id]); 85790723da6SShaul Triebitz struct ieee80211_mgmt *mgmt; 85890723da6SShaul Triebitz 85990723da6SShaul Triebitz if (WARN_ON(!link_sta || !link_conf)) 86090723da6SShaul Triebitz goto drop; 86190723da6SShaul Triebitz 86290723da6SShaul Triebitz /* if sta is NULL, the frame is a management frame */ 86390723da6SShaul Triebitz mgmt = (void *)hdr; 86490723da6SShaul Triebitz memcpy(mgmt->da, link_sta->addr, ETH_ALEN); 86590723da6SShaul Triebitz memcpy(mgmt->sa, link_conf->addr, ETH_ALEN); 86690723da6SShaul Triebitz memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN); 86790723da6SShaul Triebitz } 86890723da6SShaul Triebitz 869df2378abSJohannes Berg iwl_mvm_tx_skb(mvm, skb, sta); 870e705c121SKalle Valo return; 871e705c121SKalle Valo drop: 872e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 873e705c121SKalle Valo } 874e705c121SKalle Valo 875cfbc6c4cSSara Sharon void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 876e705c121SKalle Valo { 877cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 878cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 879cfbc6c4cSSara Sharon struct sk_buff *skb = NULL; 880cfbc6c4cSSara Sharon 881fba8248eSSara Sharon /* 882fba8248eSSara Sharon * No need for threads to be pending here, they can leave the first 883fba8248eSSara Sharon * taker all the work. 884fba8248eSSara Sharon * 885fba8248eSSara Sharon * mvmtxq->tx_request logic: 886fba8248eSSara Sharon * 887fba8248eSSara Sharon * If 0, no one is currently TXing, set to 1 to indicate current thread 888fba8248eSSara Sharon * will now start TX and other threads should quit. 889fba8248eSSara Sharon * 890fba8248eSSara Sharon * If 1, another thread is currently TXing, set to 2 to indicate to 891fba8248eSSara Sharon * that thread that there was another request. Since that request may 892fba8248eSSara Sharon * have raced with the check whether the queue is empty, the TXing 893fba8248eSSara Sharon * thread should check the queue's status one more time before leaving. 894fba8248eSSara Sharon * This check is done in order to not leave any TX hanging in the queue 895fba8248eSSara Sharon * until the next TX invocation (which may not even happen). 896fba8248eSSara Sharon * 897fba8248eSSara Sharon * If 2, another thread is currently TXing, and it will already double 898fba8248eSSara Sharon * check the queue, so do nothing. 899fba8248eSSara Sharon */ 900fba8248eSSara Sharon if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 901fba8248eSSara Sharon return; 902cfbc6c4cSSara Sharon 903cfbc6c4cSSara Sharon rcu_read_lock(); 904fba8248eSSara Sharon do { 905b58e3d43SJohannes Berg while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL, 906b58e3d43SJohannes Berg &mvmtxq->state) && 907b58e3d43SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT, 908b58e3d43SJohannes Berg &mvmtxq->state) && 909*bbd6d0f8SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, 910*bbd6d0f8SJohannes Berg &mvmtxq->state) && 91100520b7aSEmmanuel Grumbach !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 912cfbc6c4cSSara Sharon skb = ieee80211_tx_dequeue(hw, txq); 913cfbc6c4cSSara Sharon 914f50d693bSSara Sharon if (!skb) { 915f50d693bSSara Sharon if (txq->sta) 916f50d693bSSara Sharon IWL_DEBUG_TX(mvm, 917f50d693bSSara Sharon "TXQ of sta %pM tid %d is now empty\n", 918f50d693bSSara Sharon txq->sta->addr, 919f50d693bSSara Sharon txq->tid); 920cfbc6c4cSSara Sharon break; 921f50d693bSSara Sharon } 922cfbc6c4cSSara Sharon 923cfbc6c4cSSara Sharon iwl_mvm_tx_skb(mvm, skb, txq->sta); 924cfbc6c4cSSara Sharon } 925fba8248eSSara Sharon } while (atomic_dec_return(&mvmtxq->tx_request)); 926cfbc6c4cSSara Sharon rcu_read_unlock(); 927e705c121SKalle Valo } 928e705c121SKalle Valo 929cbce62a3SMiri Korenblit void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 930cfbc6c4cSSara Sharon struct ieee80211_txq *txq) 931e705c121SKalle Valo { 932cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 933cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 934e705c121SKalle Valo 935923bf981SJohannes Berg if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) || 936923bf981SJohannes Berg !txq->sta) { 937cfbc6c4cSSara Sharon iwl_mvm_mac_itxq_xmit(hw, txq); 938cfbc6c4cSSara Sharon return; 939cfbc6c4cSSara Sharon } 940cfbc6c4cSSara Sharon 941923bf981SJohannes Berg /* iwl_mvm_mac_itxq_xmit() will later be called by the worker 942923bf981SJohannes Berg * to handle any packets we leave on the txq now 943923bf981SJohannes Berg */ 944cfbc6c4cSSara Sharon 945923bf981SJohannes Berg spin_lock_bh(&mvm->add_stream_lock); 946923bf981SJohannes Berg /* The list is being deleted only after the queue is fully allocated. */ 947923bf981SJohannes Berg if (list_empty(&mvmtxq->list) && 948923bf981SJohannes Berg /* recheck under lock */ 949923bf981SJohannes Berg !test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) { 950cfbc6c4cSSara Sharon list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 951cfbc6c4cSSara Sharon schedule_work(&mvm->add_stream_wk); 952e705c121SKalle Valo } 953923bf981SJohannes Berg spin_unlock_bh(&mvm->add_stream_lock); 954923bf981SJohannes Berg } 955e705c121SKalle Valo 956e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 957e705c121SKalle Valo do { \ 958e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 959e705c121SKalle Valo break; \ 9607174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 961e705c121SKalle Valo } while (0) 962e705c121SKalle Valo 963e705c121SKalle Valo static void 964e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 965e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 966e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 967e705c121SKalle Valo { 968e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 969e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 970e705c121SKalle Valo 9716c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 9726c042d75SSara Sharon FW_DBG_TRIGGER_BA); 9736c042d75SSara Sharon if (!trig) 974e705c121SKalle Valo return; 975e705c121SKalle Valo 976e705c121SKalle Valo ba_trig = (void *)trig->data; 977e705c121SKalle Valo 978e705c121SKalle Valo switch (action) { 979e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 980e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 981e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 982e705c121SKalle Valo 983e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 984e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 985e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 986e705c121SKalle Valo break; 987e705c121SKalle Valo } 988e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 989e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 990e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 991e705c121SKalle Valo sta->addr, tid); 992e705c121SKalle Valo break; 993e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 994e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 995e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 996e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 997e705c121SKalle Valo break; 998e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 999e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 1000e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 1001e705c121SKalle Valo sta->addr, tid); 1002e705c121SKalle Valo break; 1003e705c121SKalle Valo default: 1004e705c121SKalle Valo break; 1005e705c121SKalle Valo } 1006e705c121SKalle Valo } 1007e705c121SKalle Valo 1008cbce62a3SMiri Korenblit int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 1009e705c121SKalle Valo struct ieee80211_vif *vif, 101050ea05efSSara Sharon struct ieee80211_ampdu_params *params) 1011e705c121SKalle Valo { 1012e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1013e705c121SKalle Valo int ret; 101450ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 101550ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 101650ea05efSSara Sharon u16 tid = params->tid; 101750ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 1018514c3069SLuca Coelho u16 buf_size = params->buf_size; 1019bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 102010b2b201SSara Sharon u16 timeout = params->timeout; 1021e705c121SKalle Valo 1022e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 1023e705c121SKalle Valo sta->addr, tid, action); 1024e705c121SKalle Valo 1025e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 1026e705c121SKalle Valo return -EACCES; 1027e705c121SKalle Valo 1028e705c121SKalle Valo mutex_lock(&mvm->mutex); 1029e705c121SKalle Valo 1030e705c121SKalle Valo switch (action) { 1031e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 1032650cadb7SGregory Greenman if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id == 1033c8ee33e1SGregory Greenman iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) { 1034b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 1035b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 1036b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 1037b0ffe455SJohannes Berg 1038b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 1039b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 1040b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 1041b0ffe455SJohannes Berg } 1042e78da25eSJohannes Berg if (!iwl_enable_rx_ampdu()) { 1043e705c121SKalle Valo ret = -EINVAL; 1044e705c121SKalle Valo break; 1045e705c121SKalle Valo } 104610b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 104710b2b201SSara Sharon timeout); 1048e705c121SKalle Valo break; 1049e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 105010b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 105110b2b201SSara Sharon timeout); 1052e705c121SKalle Valo break; 1053e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 1054e78da25eSJohannes Berg if (!iwl_enable_tx_ampdu()) { 1055e705c121SKalle Valo ret = -EINVAL; 1056e705c121SKalle Valo break; 1057e705c121SKalle Valo } 1058e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 1059e705c121SKalle Valo break; 1060e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 1061e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 1062e705c121SKalle Valo break; 1063e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 1064e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1065e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 1066e705c121SKalle Valo break; 1067e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 1068bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 1069bb81bb68SEmmanuel Grumbach buf_size, amsdu); 1070e705c121SKalle Valo break; 1071e705c121SKalle Valo default: 1072e705c121SKalle Valo WARN_ON_ONCE(1); 1073e705c121SKalle Valo ret = -EINVAL; 1074e705c121SKalle Valo break; 1075e705c121SKalle Valo } 1076e705c121SKalle Valo 1077e705c121SKalle Valo if (!ret) { 1078e705c121SKalle Valo u16 rx_ba_ssn = 0; 1079e705c121SKalle Valo 1080e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 1081e705c121SKalle Valo rx_ba_ssn = *ssn; 1082e705c121SKalle Valo 1083e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 1084e705c121SKalle Valo rx_ba_ssn, action); 1085e705c121SKalle Valo } 1086e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1087e705c121SKalle Valo 1088e705c121SKalle Valo return ret; 1089e705c121SKalle Valo } 1090e705c121SKalle Valo 1091e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 1092e705c121SKalle Valo struct ieee80211_vif *vif) 1093e705c121SKalle Valo { 1094e705c121SKalle Valo struct iwl_mvm *mvm = data; 1095e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1096bf976c81SJohannes Berg struct iwl_probe_resp_data *probe_data; 109779faae3aSGregory Greenman unsigned int link_id; 1098e705c121SKalle Valo 1099e705c121SKalle Valo mvmvif->uploaded = false; 1100e705c121SKalle Valo 1101e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 1102e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 1103e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 1104e705c121SKalle Valo 1105c1e458b9SIlan Peer mvmvif->bf_enabled = false; 1106c1e458b9SIlan Peer mvmvif->ba_enabled = false; 1107828c79d9SEmmanuel Grumbach mvmvif->ap_sta = NULL; 110879faae3aSGregory Greenman 110979faae3aSGregory Greenman for_each_mvm_vif_valid_link(mvmvif, link_id) { 111079faae3aSGregory Greenman mvmvif->link[link_id]->ap_sta_id = IWL_MVM_INVALID_STA; 111179faae3aSGregory Greenman mvmvif->link[link_id]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID; 111279faae3aSGregory Greenman mvmvif->link[link_id]->phy_ctxt = NULL; 1113bf976c81SJohannes Berg mvmvif->link[link_id]->active = 0; 1114d615ea32SJohannes Berg mvmvif->link[link_id]->igtk = NULL; 1115c1e458b9SIlan Peer memset(&mvmvif->link[link_id]->bf_data, 0, 1116c1e458b9SIlan Peer sizeof(mvmvif->link[link_id]->bf_data)); 111779faae3aSGregory Greenman } 1118bf976c81SJohannes Berg 1119bf976c81SJohannes Berg probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 1120bf976c81SJohannes Berg lockdep_is_held(&mvm->mutex)); 1121bf976c81SJohannes Berg if (probe_data) 1122bf976c81SJohannes Berg kfree_rcu(probe_data, rcu_head); 1123bf976c81SJohannes Berg RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 1124e705c121SKalle Valo } 1125e705c121SKalle Valo 1126e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1127e705c121SKalle Valo { 1128fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1129e705c121SKalle Valo 11309bf13beeSJohannes Berg mvm->cur_aid = 0; 11319bf13beeSJohannes Berg 1132e705c121SKalle Valo mvm->scan_status = 0; 1133e705c121SKalle Valo mvm->ps_disabled = false; 1134b3500b47SEmmanuel Grumbach mvm->rfkill_safe_init_done = false; 1135e705c121SKalle Valo 1136e705c121SKalle Valo /* just in case one was running */ 1137305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 1138e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 1139e705c121SKalle Valo 1140fc36ffdaSJohannes Berg iwl_mvm_ftm_restart(mvm); 1141fc36ffdaSJohannes Berg 1142e705c121SKalle Valo /* 1143e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 1144e705c121SKalle Valo * gone down during the HW restart 1145e705c121SKalle Valo */ 1146e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1147e705c121SKalle Valo 1148e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1149e705c121SKalle Valo 1150e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 11519c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1152e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1153e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1154e705c121SKalle Valo 1155e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1156e705c121SKalle Valo 1157e705c121SKalle Valo mvm->rx_ba_sessions = 0; 11587174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 1159baf41bc3SShaul Triebitz mvm->monitor_on = false; 1160fb40cd9dSMiri Korenblit #ifdef CONFIG_IWLWIFI_DEBUGFS 1161fb40cd9dSMiri Korenblit mvm->beacon_inject_active = false; 1162fb40cd9dSMiri Korenblit #endif 1163e705c121SKalle Valo 1164e705c121SKalle Valo /* keep statistics ticking */ 1165e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1166e705c121SKalle Valo } 1167e705c121SKalle Valo 1168e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1169e705c121SKalle Valo { 1170e705c121SKalle Valo int ret; 1171e705c121SKalle Valo 1172e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1173e705c121SKalle Valo 11746d19a5ebSEmmanuel Grumbach ret = iwl_mvm_mei_get_ownership(mvm); 11756d19a5ebSEmmanuel Grumbach if (ret) 11766d19a5ebSEmmanuel Grumbach return ret; 11776d19a5ebSEmmanuel Grumbach 11786d19a5ebSEmmanuel Grumbach if (mvm->mei_nvm_data) { 11796d19a5ebSEmmanuel Grumbach /* We got the NIC, we can now free the MEI NVM data */ 11806d19a5ebSEmmanuel Grumbach kfree(mvm->mei_nvm_data); 11816d19a5ebSEmmanuel Grumbach mvm->mei_nvm_data = NULL; 11826d19a5ebSEmmanuel Grumbach 11836d19a5ebSEmmanuel Grumbach /* 11846d19a5ebSEmmanuel Grumbach * We can't free the nvm_data we allocated based on the SAP 11856d19a5ebSEmmanuel Grumbach * data because we registered to cfg80211 with the channels 11866d19a5ebSEmmanuel Grumbach * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 11876d19a5ebSEmmanuel Grumbach * just in order to be able free it later. 11886d19a5ebSEmmanuel Grumbach * NULLify nvm_data so that we will read the NVM from the 11896d19a5ebSEmmanuel Grumbach * firmware this time. 11906d19a5ebSEmmanuel Grumbach */ 11916d19a5ebSEmmanuel Grumbach mvm->temp_nvm_data = mvm->nvm_data; 11926d19a5ebSEmmanuel Grumbach mvm->nvm_data = NULL; 11936d19a5ebSEmmanuel Grumbach } 11946d19a5ebSEmmanuel Grumbach 1195bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1196bf8b286fSJohannes Berg /* 1197bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1198bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1199bf8b286fSJohannes Berg */ 1200bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1201bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1202e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1203e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1204a42b2af3SLuca Coelho } 1205e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1206e705c121SKalle Valo 1207b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1208b108d8c7SShahar S Matityahu NULL); 1209b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1210b108d8c7SShahar S Matityahu NULL); 1211da2eb669SSara Sharon 1212e8fe3b41SIlan Peer mvm->last_reset_or_resume_time_jiffies = jiffies; 1213e8fe3b41SIlan Peer 1214e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1215e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1216e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1217e705c121SKalle Valo * would do. 1218e705c121SKalle Valo */ 1219e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1220e705c121SKalle Valo } 1221e705c121SKalle Valo 1222e705c121SKalle Valo return ret; 1223e705c121SKalle Valo } 1224e705c121SKalle Valo 1225cbce62a3SMiri Korenblit int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1226e705c121SKalle Valo { 1227e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1228e705c121SKalle Valo int ret; 1229e705c121SKalle Valo 1230e705c121SKalle Valo mutex_lock(&mvm->mutex); 12315283dd67SMordechay Goodstein 12325283dd67SMordechay Goodstein /* we are starting the mac not in error flow, and restart is enabled */ 12335283dd67SMordechay Goodstein if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 12345283dd67SMordechay Goodstein iwlwifi_mod_params.fw_restart) { 12355283dd67SMordechay Goodstein /* 12365283dd67SMordechay Goodstein * This will prevent mac80211 recovery flows to trigger during 12375283dd67SMordechay Goodstein * init failures 12385283dd67SMordechay Goodstein */ 12395283dd67SMordechay Goodstein set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 12405283dd67SMordechay Goodstein } 12415283dd67SMordechay Goodstein 1242e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 12435283dd67SMordechay Goodstein clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 12445283dd67SMordechay Goodstein 1245e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1246e705c121SKalle Valo 12477ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 12487ce1f215SEmmanuel Grumbach 1249e705c121SKalle Valo return ret; 1250e705c121SKalle Valo } 1251e705c121SKalle Valo 1252e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1253e705c121SKalle Valo { 1254e705c121SKalle Valo int ret; 1255e705c121SKalle Valo 1256e705c121SKalle Valo mutex_lock(&mvm->mutex); 1257e705c121SKalle Valo 1258e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 12594d4183c4SEmmanuel Grumbach 1260e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1261e705c121SKalle Valo if (ret) 1262e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1263e705c121SKalle Valo ret); 1264e705c121SKalle Valo 1265f130bb75SMordechay Goodstein iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1266f130bb75SMordechay Goodstein 1267e705c121SKalle Valo /* 1268e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1269e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1270e705c121SKalle Valo */ 1271e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1272e705c121SKalle Valo 1273e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1274e705c121SKalle Valo } 1275e705c121SKalle Valo 1276cbce62a3SMiri Korenblit void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1277e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1278e705c121SKalle Valo { 1279e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1280e705c121SKalle Valo 1281e705c121SKalle Valo switch (reconfig_type) { 1282e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1283e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1284e705c121SKalle Valo break; 1285e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1286e705c121SKalle Valo break; 1287e705c121SKalle Valo } 1288e705c121SKalle Valo } 1289e705c121SKalle Valo 1290e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1291e705c121SKalle Valo { 1292e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1293e705c121SKalle Valo 1294b68bd2e3SIlan Peer iwl_mvm_ftm_initiator_smooth_stop(mvm); 1295b68bd2e3SIlan Peer 1296e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1297e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1298e705c121SKalle Valo */ 1299e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1300e705c121SKalle Valo 1301e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1302e705c121SKalle Valo 13031724fc78SEmmanuel Grumbach if (!iwl_mvm_has_new_station_api(mvm->fw)) 1304f327236dSSharon iwl_mvm_rm_aux_sta(mvm); 1305f327236dSSharon 1306fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1307e705c121SKalle Valo 1308e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1309e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1310e705c121SKalle Valo 1311e705c121SKalle Valo /* 1312155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1313155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1314155f7e04SEmmanuel Grumbach * won't execute the restart. 1315e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1316e705c121SKalle Valo * HW restart was requested. 1317e705c121SKalle Valo */ 1318155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1319155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1320155f7e04SEmmanuel Grumbach &mvm->status)) 1321e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1322e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1323e705c121SKalle Valo 1324e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1325e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1326e705c121SKalle Valo */ 1327e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1328e705c121SKalle Valo int i; 1329e705c121SKalle Valo 1330e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1331e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1332e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1333e705c121SKalle Valo i)) 1334e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1335e705c121SKalle Valo } 1336e705c121SKalle Valo } 1337e705c121SKalle Valo } 1338e705c121SKalle Valo 1339cbce62a3SMiri Korenblit void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1340e705c121SKalle Valo { 1341e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1342e705c121SKalle Valo 1343e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 134424afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1345771147b0SJohannes Berg 1346771147b0SJohannes Berg /* 1347771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1348771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1349771147b0SJohannes Berg * be able to proceed. This is important here because one of those 13507174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1351771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1352771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1353771147b0SJohannes Berg */ 1354771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1355771147b0SJohannes Berg 1356d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 135769e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1358e705c121SKalle Valo 1359f9084775SNathan Errera /* 1360f9084775SNathan Errera * The work item could be running or queued if the 1361f9084775SNathan Errera * ROC time event stops just as we get here. 1362f9084775SNathan Errera */ 1363f9084775SNathan Errera flush_work(&mvm->roc_done_wk); 1364f9084775SNathan Errera 13657ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 13667ce1f215SEmmanuel Grumbach 1367e705c121SKalle Valo mutex_lock(&mvm->mutex); 1368e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1369e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1370e705c121SKalle Valo 1371e705c121SKalle Valo /* 1372e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1373e705c121SKalle Valo * discover that its list is now empty. 1374e705c121SKalle Valo */ 1375e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1376fdccafadSMiri Korenblit wiphy_work_cancel(hw->wiphy, &mvm->async_handlers_wiphy_wk); 1377e705c121SKalle Valo } 1378e705c121SKalle Valo 13791ab26632SMiri Korenblit struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1380e705c121SKalle Valo { 1381e705c121SKalle Valo u16 i; 1382e705c121SKalle Valo 1383e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1384e705c121SKalle Valo 1385e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1386e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1387e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1388e705c121SKalle Valo 1389e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1390e705c121SKalle Valo return NULL; 1391e705c121SKalle Valo } 1392e705c121SKalle Valo 1393f551d013SGregory Greenman int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1394e705c121SKalle Valo s16 tx_power) 1395e705c121SKalle Valo { 1396971cbe50SJohannes Berg u32 cmd_id = REDUCE_TX_POWER_CMD; 13970791c2fcSHaim Dreyfuss int len; 1398216cdfb5SLuca Coelho struct iwl_dev_tx_power_cmd cmd = { 1399216cdfb5SLuca Coelho .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1400216cdfb5SLuca Coelho .common.mac_context_id = 1401e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1402216cdfb5SLuca Coelho .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1403e705c121SKalle Valo }; 1404971cbe50SJohannes Berg u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1405e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN); 1406e705c121SKalle Valo 1407e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1408216cdfb5SLuca Coelho cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1409e705c121SKalle Valo 1410b0aa02b3SAyala Barazani if (cmd_ver == 7) 1411b0aa02b3SAyala Barazani len = sizeof(cmd.v7); 1412b0aa02b3SAyala Barazani else if (cmd_ver == 6) 1413fbb7957dSLuca Coelho len = sizeof(cmd.v6); 1414fbb7957dSLuca Coelho else if (fw_has_api(&mvm->fw->ucode_capa, 14150791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 14160791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 14170791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 14180791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 14190791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 14200791c2fcSHaim Dreyfuss else 1421216cdfb5SLuca Coelho len = sizeof(cmd.v3); 1422216cdfb5SLuca Coelho 1423216cdfb5SLuca Coelho /* all structs have the same common part, add it */ 1424216cdfb5SLuca Coelho len += sizeof(cmd.common); 1425e705c121SKalle Valo 1426971cbe50SJohannes Berg return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); 1427e705c121SKalle Valo } 1428e705c121SKalle Valo 1429*bbd6d0f8SJohannes Berg static void iwl_mvm_post_csa_tx(void *data, struct ieee80211_sta *sta) 1430*bbd6d0f8SJohannes Berg { 1431*bbd6d0f8SJohannes Berg struct ieee80211_hw *hw = data; 1432*bbd6d0f8SJohannes Berg int i; 1433*bbd6d0f8SJohannes Berg 1434*bbd6d0f8SJohannes Berg for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 1435*bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 1436*bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(sta->txq[i]); 1437*bbd6d0f8SJohannes Berg 1438*bbd6d0f8SJohannes Berg clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1439*bbd6d0f8SJohannes Berg iwl_mvm_mac_itxq_xmit(hw, sta->txq[i]); 1440*bbd6d0f8SJohannes Berg } 1441*bbd6d0f8SJohannes Berg } 1442*bbd6d0f8SJohannes Berg 144303117f30SMiri Korenblit int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1444a469a593SEmmanuel Grumbach struct ieee80211_vif *vif, 1445a469a593SEmmanuel Grumbach struct ieee80211_bss_conf *link_conf) 1446f6780614SSara Sharon { 1447f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1448f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1449f6780614SSara Sharon int ret; 1450f6780614SSara Sharon 1451f6780614SSara Sharon mutex_lock(&mvm->mutex); 1452f6780614SSara Sharon 1453f6780614SSara Sharon if (vif->type == NL80211_IFTYPE_STATION) { 1454f6780614SSara Sharon struct iwl_mvm_sta *mvmsta; 14553723c7c5SEmmanuel Grumbach unsigned int link_id = link_conf->link_id; 14563723c7c5SEmmanuel Grumbach u8 ap_sta_id = mvmvif->link[link_id]->ap_sta_id; 1457f6780614SSara Sharon 1458f6780614SSara Sharon mvmvif->csa_bcn_pending = false; 14592964b57fSJohannes Berg mvmvif->csa_blocks_tx = false; 14603723c7c5SEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id); 1461f6780614SSara Sharon 1462f6780614SSara Sharon if (WARN_ON(!mvmsta)) { 1463f6780614SSara Sharon ret = -EIO; 1464f6780614SSara Sharon goto out_unlock; 1465f6780614SSara Sharon } 1466f6780614SSara Sharon 1467f6780614SSara Sharon iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 146803117f30SMiri Korenblit if (mvm->mld_api_is_used) 146903117f30SMiri Korenblit iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false); 147003117f30SMiri Korenblit else 1471f6780614SSara Sharon iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1472f6780614SSara Sharon 14730202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 14740202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 147587f5b5f2SJohannes Berg ret = iwl_mvm_enable_beacon_filter(mvm, vif); 1476f6780614SSara Sharon if (ret) 1477f6780614SSara Sharon goto out_unlock; 1478f6780614SSara Sharon 1479f6780614SSara Sharon iwl_mvm_stop_session_protection(mvm, vif); 1480f6780614SSara Sharon } 1481*bbd6d0f8SJohannes Berg } else if (vif->type == NL80211_IFTYPE_AP && mvmvif->csa_blocks_tx) { 1482*bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 1483*bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(vif->txq); 1484*bbd6d0f8SJohannes Berg 1485*bbd6d0f8SJohannes Berg clear_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 1486*bbd6d0f8SJohannes Berg 1487*bbd6d0f8SJohannes Berg local_bh_disable(); 1488*bbd6d0f8SJohannes Berg iwl_mvm_mac_itxq_xmit(hw, vif->txq); 1489*bbd6d0f8SJohannes Berg ieee80211_iterate_stations_atomic(hw, iwl_mvm_post_csa_tx, hw); 1490*bbd6d0f8SJohannes Berg local_bh_enable(); 1491*bbd6d0f8SJohannes Berg 1492*bbd6d0f8SJohannes Berg mvmvif->csa_blocks_tx = false; 14930202bcf0SEmmanuel Grumbach } 1494f6780614SSara Sharon 1495f6780614SSara Sharon mvmvif->ps_disabled = false; 1496f6780614SSara Sharon 1497f6780614SSara Sharon ret = iwl_mvm_power_update_ps(mvm); 1498f6780614SSara Sharon 1499f6780614SSara Sharon out_unlock: 1500caf46377SSara Sharon if (mvmvif->csa_failed) 1501caf46377SSara Sharon ret = -EIO; 1502f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1503f6780614SSara Sharon 1504f6780614SSara Sharon return ret; 1505f6780614SSara Sharon } 1506f6780614SSara Sharon 1507cbce62a3SMiri Korenblit void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 15085ecd5d82SJohannes Berg struct ieee80211_vif *vif, 15095ecd5d82SJohannes Berg struct ieee80211_bss_conf *link_conf) 1510f6780614SSara Sharon { 1511f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1512f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1513f6780614SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 1514f6780614SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1515f6780614SSara Sharon mvmvif->color)), 1516f6780614SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1517f6780614SSara Sharon }; 1518f6780614SSara Sharon 1519ad12b231SNathan Errera /* 1520ad12b231SNathan Errera * In the new flow since FW is in charge of the timing, 1521ad12b231SNathan Errera * if driver has canceled the channel switch he will receive the 1522ad12b231SNathan Errera * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it 1523ad12b231SNathan Errera */ 1524ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 1525ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 1526ad12b231SNathan Errera return; 1527ad12b231SNathan Errera 1528f6780614SSara Sharon IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1529f6780614SSara Sharon 1530f6780614SSara Sharon mutex_lock(&mvm->mutex); 153158ddd9b6SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 153258ddd9b6SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 153358ddd9b6SEmmanuel Grumbach iwl_mvm_remove_csa_period(mvm, vif); 153458ddd9b6SEmmanuel Grumbach else 1535f6780614SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1536f6780614SSara Sharon WIDE_ID(MAC_CONF_GROUP, 1537f6780614SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 1538f6780614SSara Sharon 0, sizeof(cmd), &cmd)); 1539caf46377SSara Sharon mvmvif->csa_failed = true; 1540f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1541f6780614SSara Sharon 1542a469a593SEmmanuel Grumbach /* If we're here, we can't support MLD */ 1543a469a593SEmmanuel Grumbach iwl_mvm_post_channel_switch(hw, vif, &vif->bss_conf); 1544f6780614SSara Sharon } 1545f6780614SSara Sharon 15461ab26632SMiri Korenblit void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1547f6780614SSara Sharon { 1548f6780614SSara Sharon struct iwl_mvm_vif *mvmvif; 1549f6780614SSara Sharon struct ieee80211_vif *vif; 1550f6780614SSara Sharon 1551f6780614SSara Sharon mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1552f6780614SSara Sharon vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1553f6780614SSara Sharon 155470162580SShaul Triebitz /* Trigger disconnect (should clear the CSA state) */ 1555a469a593SEmmanuel Grumbach ieee80211_chswitch_done(vif, false, 0); 1556f6780614SSara Sharon } 1557f6780614SSara Sharon 15585abf3154SMordechay Goodstein static u8 15595abf3154SMordechay Goodstein iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef) 15605abf3154SMordechay Goodstein { 15615abf3154SMordechay Goodstein int data_start; 15625abf3154SMordechay Goodstein int control_start; 15635abf3154SMordechay Goodstein int bw; 15645abf3154SMordechay Goodstein 15655abf3154SMordechay Goodstein if (chandef->width == NL80211_CHAN_WIDTH_320) 15665abf3154SMordechay Goodstein bw = 320; 15675abf3154SMordechay Goodstein else if (chandef->width == NL80211_CHAN_WIDTH_160) 15685abf3154SMordechay Goodstein bw = 160; 15695abf3154SMordechay Goodstein else 15705abf3154SMordechay Goodstein return 0; 15715abf3154SMordechay Goodstein 15725abf3154SMordechay Goodstein /* data is bw wide so the start is half the width */ 15735abf3154SMordechay Goodstein data_start = chandef->center_freq1 - bw / 2; 15745abf3154SMordechay Goodstein /* control is 20Mhz width */ 15755abf3154SMordechay Goodstein control_start = chandef->chan->center_freq - 10; 15765abf3154SMordechay Goodstein 15775abf3154SMordechay Goodstein return (control_start - data_start) / 80; 15785abf3154SMordechay Goodstein } 15795abf3154SMordechay Goodstein 15801be4858eSJohannes Berg static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm, 15811be4858eSJohannes Berg struct ieee80211_vif *vif) 1582e705c121SKalle Valo { 1583e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 15841be4858eSJohannes Berg int ret; 15851ab26632SMiri Korenblit 15861ab26632SMiri Korenblit lockdep_assert_held(&mvm->mutex); 1587e705c121SKalle Valo 15881be4858eSJohannes Berg ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 15891be4858eSJohannes Berg if (ret) { 15901be4858eSJohannes Berg IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 15911be4858eSJohannes Berg return ret; 15921be4858eSJohannes Berg } 15931be4858eSJohannes Berg 15941be4858eSJohannes Berg /* Only queue for this station is the mcast queue, 15951be4858eSJohannes Berg * which shouldn't be in TFD mask anyway 15961be4858eSJohannes Berg */ 15971be4858eSJohannes Berg return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0, 15981be4858eSJohannes Berg vif->type, 15991be4858eSJohannes Berg IWL_STA_MULTICAST); 16001be4858eSJohannes Berg } 16011be4858eSJohannes Berg 16021be4858eSJohannes Berg static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 16031be4858eSJohannes Berg struct ieee80211_vif *vif) 16041be4858eSJohannes Berg { 16051be4858eSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 16061be4858eSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 16071be4858eSJohannes Berg int ret; 1608b6e3d1baSAnjaneyulu int i; 16091be4858eSJohannes Berg 16101be4858eSJohannes Berg mutex_lock(&mvm->mutex); 16111be4858eSJohannes Berg 1612e705c121SKalle Valo mvmvif->mvm = mvm; 1613650cadb7SGregory Greenman 1614650cadb7SGregory Greenman /* the first link always points to the default one */ 1615650cadb7SGregory Greenman mvmvif->link[0] = &mvmvif->deflink; 1616e705c121SKalle Valo 1617e705c121SKalle Valo /* 1618e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1619e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1620e705c121SKalle Valo * don't really have to check the types. 1621e705c121SKalle Valo */ 1622e705c121SKalle Valo 1623e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1624e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1625b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 1626b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.accu_num_beacons += 1627b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.num_beacons; 1628e705c121SKalle Valo 1629e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 16301be4858eSJohannes Berg ret = iwl_mvm_mac_ctxt_init(mvm, vif); 16311be4858eSJohannes Berg if (ret) 16321be4858eSJohannes Berg goto out; 1633e705c121SKalle Valo 1634698478c4SSara Sharon rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1635698478c4SSara Sharon 16361be4858eSJohannes Berg /* Currently not much to do for NAN */ 16371be4858eSJohannes Berg if (vif->type == NL80211_IFTYPE_NAN) { 16381be4858eSJohannes Berg ret = 0; 16391be4858eSJohannes Berg goto out; 16401be4858eSJohannes Berg } 16411be4858eSJohannes Berg 1642e705c121SKalle Valo /* 1643e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1644e705c121SKalle Valo * template is configured (which happens only in the mac80211 1645e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1646e705c121SKalle Valo * only after the binding. 1647e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1648e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1649e705c121SKalle Valo * the point where we can also add the bcast station. 1650e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1651e705c121SKalle Valo * allocating resources :) 1652e705c121SKalle Valo */ 1653e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1654e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 16553a3ef394SBenjamin Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1656c36235acSJohannes Berg iwl_mvm_vif_dbgfs_add_link(mvm, vif); 16571be4858eSJohannes Berg ret = 0; 16581be4858eSJohannes Berg goto out; 16591ab26632SMiri Korenblit } 16601ab26632SMiri Korenblit 16611ab26632SMiri Korenblit mvmvif->features |= hw->netdev_features; 1662650cadb7SGregory Greenman 1663e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1664e705c121SKalle Valo if (ret) 166598c0de7bSMiri Korenblit goto out_unlock; 1666e705c121SKalle Valo 1667e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1668e705c121SKalle Valo if (ret) 1669e705c121SKalle Valo goto out_remove_mac; 1670e705c121SKalle Valo 1671e705c121SKalle Valo /* beacon filtering */ 167287f5b5f2SJohannes Berg ret = iwl_mvm_disable_beacon_filter(mvm, vif); 1673e705c121SKalle Valo if (ret) 1674e705c121SKalle Valo goto out_remove_mac; 1675e705c121SKalle Valo 1676e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1677e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1678e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1679e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1680e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1681e705c121SKalle Valo } 1682e705c121SKalle Valo 168332a5690eSJohannes Berg if (vif->p2p || iwl_fw_lookup_cmd_ver(mvm->fw, PHY_CONTEXT_CMD, 1) < 5) 168432a5690eSJohannes Berg vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW; 168532a5690eSJohannes Berg 168684ef7cbeSIlan Peer if (vif->type == NL80211_IFTYPE_P2P_DEVICE) 1687e705c121SKalle Valo mvm->p2p_device_vif = vif; 1688e705c121SKalle Valo 1689b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1690f6780614SSara Sharon INIT_DELAYED_WORK(&mvmvif->csa_work, 1691f6780614SSara Sharon iwl_mvm_channel_switch_disconnect_wk); 1692b0ffe455SJohannes Berg 16935abf3154SMordechay Goodstein if (vif->type == NL80211_IFTYPE_MONITOR) { 1694baf41bc3SShaul Triebitz mvm->monitor_on = true; 16955abf3154SMordechay Goodstein mvm->monitor_p80 = 16966092077aSJohannes Berg iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chanreq.oper); 16975abf3154SMordechay Goodstein } 1698baf41bc3SShaul Triebitz 16993a3ef394SBenjamin Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1700c36235acSJohannes Berg iwl_mvm_vif_dbgfs_add_link(mvm, vif); 17016d19a5ebSEmmanuel Grumbach 17026d19a5ebSEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 17036d19a5ebSEmmanuel Grumbach vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 17046d19a5ebSEmmanuel Grumbach !mvm->csme_vif && mvm->mei_registered) { 17056d19a5ebSEmmanuel Grumbach iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 17066d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 17076d19a5ebSEmmanuel Grumbach mvm->csme_vif = vif; 17086d19a5ebSEmmanuel Grumbach } 17096d19a5ebSEmmanuel Grumbach 17101ab26632SMiri Korenblit out: 17111ab26632SMiri Korenblit if (!ret && (vif->type == NL80211_IFTYPE_AP || 17121ab26632SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC)) 17131ab26632SMiri Korenblit ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif); 17141ab26632SMiri Korenblit 1715e705c121SKalle Valo goto out_unlock; 1716e705c121SKalle Valo 1717e705c121SKalle Valo out_remove_mac: 1718650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1719e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1720e705c121SKalle Valo out_unlock: 1721e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1722e705c121SKalle Valo 1723e705c121SKalle Valo return ret; 1724e705c121SKalle Valo } 1725e705c121SKalle Valo 1726cb145863SJohannes Berg void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1727e705c121SKalle Valo struct ieee80211_vif *vif) 1728e705c121SKalle Valo { 1729e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1730e705c121SKalle Valo /* 1731e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1732e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1733e705c121SKalle Valo * queue are sent in ROC session. 1734e705c121SKalle Valo */ 1735e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1736e705c121SKalle Valo } 1737e705c121SKalle Valo } 1738e705c121SKalle Valo 173960efeca1SMiri Korenblit /* This function is doing the common part of removing the interface for 174060efeca1SMiri Korenblit * both - MLD and non-MLD modes. Returns true if removing the interface 174160efeca1SMiri Korenblit * is done 174260efeca1SMiri Korenblit */ 1743cb145863SJohannes Berg static bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw, 1744e705c121SKalle Valo struct ieee80211_vif *vif) 1745e705c121SKalle Valo { 1746e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1747e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 174886e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1749e705c121SKalle Valo 1750e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1751e705c121SKalle Valo 1752b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1753b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1754b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1755b0ffe455SJohannes Berg 1756e705c121SKalle Valo mutex_lock(&mvm->mutex); 1757e705c121SKalle Valo 17586d19a5ebSEmmanuel Grumbach if (vif == mvm->csme_vif) { 17596d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(NULL); 17606d19a5ebSEmmanuel Grumbach mvm->csme_vif = NULL; 17616d19a5ebSEmmanuel Grumbach } 17626d19a5ebSEmmanuel Grumbach 1763650cadb7SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data, 176486e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 1765650cadb7SGregory Greenman RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL); 176686e177d8SGregory Greenman if (probe_data) 176786e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 176886e177d8SGregory Greenman 1769e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1770e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1771e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1772e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1773e705c121SKalle Valo } 1774e705c121SKalle Valo 1775b73f9a4aSJohannes Berg if (vif->bss_conf.ftm_responder) 1776b73f9a4aSJohannes Berg memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1777b73f9a4aSJohannes Berg 1778c36235acSJohannes Berg iwl_mvm_vif_dbgfs_rm_link(mvm, vif); 1779e705c121SKalle Valo 1780e705c121SKalle Valo /* 1781e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1782e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1783e705c121SKalle Valo */ 1784e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1785e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1786e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1787e705c121SKalle Valo if (vif == mvm->noa_vif) { 1788e705c121SKalle Valo mvm->noa_vif = NULL; 1789e705c121SKalle Valo mvm->noa_duration = 0; 1790e705c121SKalle Valo } 1791e705c121SKalle Valo #endif 179260efeca1SMiri Korenblit return true; 1793e705c121SKalle Valo } 1794e705c121SKalle Valo 179560efeca1SMiri Korenblit iwl_mvm_power_update_mac(mvm); 179660efeca1SMiri Korenblit return false; 179760efeca1SMiri Korenblit } 179860efeca1SMiri Korenblit 179960efeca1SMiri Korenblit static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 180060efeca1SMiri Korenblit struct ieee80211_vif *vif) 180160efeca1SMiri Korenblit { 180260efeca1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 180360efeca1SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 180460efeca1SMiri Korenblit 180560efeca1SMiri Korenblit if (iwl_mvm_mac_remove_interface_common(hw, vif)) 180660efeca1SMiri Korenblit goto out; 180760efeca1SMiri Korenblit 180884ef7cbeSIlan Peer /* Before the interface removal, mac80211 would cancel the ROC, and the 180984ef7cbeSIlan Peer * ROC worker would be scheduled if needed. The worker would be flushed 181084ef7cbeSIlan Peer * in iwl_mvm_prepare_mac_removal() and thus at this point there is no 181184ef7cbeSIlan Peer * binding etc. so nothing needs to be done here. 181284ef7cbeSIlan Peer */ 1813e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 181484ef7cbeSIlan Peer if (mvmvif->deflink.phy_ctxt) { 1815650cadb7SGregory Greenman iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 1816650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 1817e705c121SKalle Valo } 181884ef7cbeSIlan Peer mvm->p2p_device_vif = NULL; 181984ef7cbeSIlan Peer } 1820e705c121SKalle Valo 1821e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1822e705c121SKalle Valo 1823698478c4SSara Sharon RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1824698478c4SSara Sharon 1825baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1826baf41bc3SShaul Triebitz mvm->monitor_on = false; 1827baf41bc3SShaul Triebitz 182860efeca1SMiri Korenblit out: 182960efeca1SMiri Korenblit if (vif->type == NL80211_IFTYPE_AP || 183060efeca1SMiri Korenblit vif->type == NL80211_IFTYPE_ADHOC) { 1831650cadb7SGregory Greenman iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta); 183260efeca1SMiri Korenblit iwl_mvm_dealloc_bcast_sta(mvm, vif); 1833e705c121SKalle Valo } 1834e705c121SKalle Valo 1835e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1836e705c121SKalle Valo } 1837e705c121SKalle Valo 1838e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1839e705c121SKalle Valo struct iwl_mvm *mvm; 1840e705c121SKalle Valo int port_id; 1841e705c121SKalle Valo }; 1842e705c121SKalle Valo 1843e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1844e705c121SKalle Valo struct ieee80211_vif *vif) 1845e705c121SKalle Valo { 1846e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1847e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1848e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 184997bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 185097bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 185197bce57bSLuca Coelho .flags = CMD_ASYNC, 185297bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 185397bce57bSLuca Coelho }; 1854e705c121SKalle Valo int ret, len; 1855e705c121SKalle Valo 1856e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1857e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1858e705c121SKalle Valo return; 1859e705c121SKalle Valo 1860e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1861f276e20bSJohannes Berg !vif->cfg.assoc) 1862e705c121SKalle Valo return; 1863e705c121SKalle Valo 1864e705c121SKalle Valo cmd->port_id = data->port_id++; 1865e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1866e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1867e705c121SKalle Valo 186897bce57bSLuca Coelho hcmd.len[0] = len; 186997bce57bSLuca Coelho hcmd.data[0] = cmd; 187097bce57bSLuca Coelho 187197bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1872e705c121SKalle Valo if (ret) 1873e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1874e705c121SKalle Valo } 1875e705c121SKalle Valo 1876e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1877e705c121SKalle Valo { 1878e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1879e705c121SKalle Valo .mvm = mvm, 1880e705c121SKalle Valo }; 1881db66abeeSJohannes Berg int ret; 1882e705c121SKalle Valo 1883e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1884e705c121SKalle Valo 1885e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1886e705c121SKalle Valo return; 1887e705c121SKalle Valo 1888e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1889e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1890e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1891db66abeeSJohannes Berg 1892db66abeeSJohannes Berg /* 1893db66abeeSJohannes Berg * Send a (synchronous) ech command so that we wait for the 1894db66abeeSJohannes Berg * multiple asynchronous MCAST_FILTER_CMD commands sent by 1895db66abeeSJohannes Berg * the interface iterator. Otherwise, we might get here over 1896db66abeeSJohannes Berg * and over again (by userspace just sending a lot of these) 1897db66abeeSJohannes Berg * and the CPU can send them faster than the firmware can 1898db66abeeSJohannes Berg * process them. 1899db66abeeSJohannes Berg * Note that the CPU is still faster - but with this we'll 1900db66abeeSJohannes Berg * actually send fewer commands overall because the CPU will 1901db66abeeSJohannes Berg * not schedule the work in mac80211 as frequently if it's 1902db66abeeSJohannes Berg * still running when rescheduled (possibly multiple times). 1903db66abeeSJohannes Berg */ 1904db66abeeSJohannes Berg ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1905db66abeeSJohannes Berg if (ret) 1906db66abeeSJohannes Berg IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 1907e705c121SKalle Valo } 1908e705c121SKalle Valo 1909cbce62a3SMiri Korenblit u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1910e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1911e705c121SKalle Valo { 1912e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1913e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1914e705c121SKalle Valo struct netdev_hw_addr *addr; 1915e705c121SKalle Valo int addr_count; 1916e705c121SKalle Valo bool pass_all; 1917e705c121SKalle Valo int len; 1918e705c121SKalle Valo 1919e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1920e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1921e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1922e705c121SKalle Valo if (pass_all) 1923e705c121SKalle Valo addr_count = 0; 1924e705c121SKalle Valo 1925e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1926e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1927e705c121SKalle Valo if (!cmd) 1928e705c121SKalle Valo return 0; 1929e705c121SKalle Valo 1930e705c121SKalle Valo if (pass_all) { 1931e705c121SKalle Valo cmd->pass_all = 1; 1932e705c121SKalle Valo return (u64)(unsigned long)cmd; 1933e705c121SKalle Valo } 1934e705c121SKalle Valo 1935e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1936e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1937e705c121SKalle Valo cmd->count, addr->addr); 1938e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1939e705c121SKalle Valo addr->addr, ETH_ALEN); 1940e705c121SKalle Valo cmd->count++; 1941e705c121SKalle Valo } 1942e705c121SKalle Valo 1943e705c121SKalle Valo return (u64)(unsigned long)cmd; 1944e705c121SKalle Valo } 1945e705c121SKalle Valo 1946cbce62a3SMiri Korenblit void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1947e705c121SKalle Valo unsigned int changed_flags, 1948cbce62a3SMiri Korenblit unsigned int *total_flags, u64 multicast) 1949e705c121SKalle Valo { 1950e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1951e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1952e705c121SKalle Valo 1953e705c121SKalle Valo mutex_lock(&mvm->mutex); 1954e705c121SKalle Valo 1955e705c121SKalle Valo /* replace previous configuration */ 1956e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1957e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1958e705c121SKalle Valo 1959e705c121SKalle Valo if (!cmd) 1960e705c121SKalle Valo goto out; 1961e705c121SKalle Valo 196261e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 196361e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 196461e7d91bSLuca Coelho 196561e7d91bSLuca Coelho if (cmd->pass_all) 196661e7d91bSLuca Coelho cmd->count = 0; 196761e7d91bSLuca Coelho 1968e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1969e705c121SKalle Valo out: 1970e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1971e705c121SKalle Valo *total_flags = 0; 1972e705c121SKalle Valo } 1973e705c121SKalle Valo 1974e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1975e705c121SKalle Valo struct ieee80211_vif *vif, 1976e705c121SKalle Valo unsigned int filter_flags, 1977e705c121SKalle Valo unsigned int changed_flags) 1978e705c121SKalle Valo { 1979e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1980e705c121SKalle Valo 1981e705c121SKalle Valo /* We support only filter for probe requests */ 1982e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1983e705c121SKalle Valo return; 1984e705c121SKalle Valo 1985e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1986f276e20bSJohannes Berg if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 1987e705c121SKalle Valo !vif->p2p) 1988e705c121SKalle Valo return; 1989e705c121SKalle Valo 1990e705c121SKalle Valo mutex_lock(&mvm->mutex); 1991e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1992e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1993e705c121SKalle Valo } 1994e705c121SKalle Valo 199522c58834SGregory Greenman int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1996a07a8f37SSara Sharon { 1997a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1998a07a8f37SSara Sharon 1999a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 2000a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 2001a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 2002a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 2003a07a8f37SSara Sharon 2004a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 2005a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 2006a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 2007a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 2008a07a8f37SSara Sharon } 2009a07a8f37SSara Sharon 2010f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 2011f92659a1SSara Sharon struct ieee80211_vif *vif) 2012f92659a1SSara Sharon { 2013d0a9123eSJohannes Berg if (vif->bss_conf.mu_mimo_owner) { 2014f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 2015f92659a1SSara Sharon 2016f92659a1SSara Sharon /* 2017f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 2018f92659a1SSara Sharon * the data received from firmware as if it came from the 2019f92659a1SSara Sharon * action frame, so no conversion is needed. 2020f92659a1SSara Sharon */ 2021afe0d181SJohannes Berg ieee80211_update_mu_groups(vif, 0, 2022f92659a1SSara Sharon (u8 *)¬if->membership_status, 2023f92659a1SSara Sharon (u8 *)¬if->user_position); 2024f92659a1SSara Sharon } 2025f92659a1SSara Sharon } 2026f92659a1SSara Sharon 2027f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 2028f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 2029f92659a1SSara Sharon { 2030f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 2031f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 2032f92659a1SSara Sharon 2033f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 2034f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2035f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 2036f92659a1SSara Sharon } 2037f92659a1SSara Sharon 2038514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 2039514c3069SLuca Coelho { 2040514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 2041514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 2042514c3069SLuca Coelho u8 residue_bits; 2043514c3069SLuca Coelho u8 res; 2044514c3069SLuca Coelho 2045514c3069SLuca Coelho if (bit_num <= 5) 2046514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 2047514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 2048514c3069SLuca Coelho 2049514c3069SLuca Coelho /* 2050514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 2051514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 2052514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 2053514c3069SLuca Coelho */ 2054514c3069SLuca Coelho 2055514c3069SLuca Coelho residue_bits = 8 - bit_num; 2056514c3069SLuca Coelho 2057514c3069SLuca Coelho res = (ppe[byte_num + 1] & 2058514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 2059514c3069SLuca Coelho residue_bits; 2060514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 2061514c3069SLuca Coelho 2062514c3069SLuca Coelho return res; 2063514c3069SLuca Coelho } 2064514c3069SLuca Coelho 2065091296d3SMiri Korenblit static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, 2066091296d3SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, 2067cb63eb43SMiri Korenblit u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit, 2068cb63eb43SMiri Korenblit bool inheritance) 2069091296d3SMiri Korenblit { 2070091296d3SMiri Korenblit int i; 2071091296d3SMiri Korenblit 2072091296d3SMiri Korenblit /* 2073091296d3SMiri Korenblit * FW currently supports only nss == MAX_HE_SUPP_NSS 2074091296d3SMiri Korenblit * 2075091296d3SMiri Korenblit * If nss > MAX: we can ignore values we don't support 2076091296d3SMiri Korenblit * If nss < MAX: we can set zeros in other streams 2077091296d3SMiri Korenblit */ 2078091296d3SMiri Korenblit if (nss > MAX_HE_SUPP_NSS) { 20794d8421f2SJason A. Donenfeld IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 2080091296d3SMiri Korenblit MAX_HE_SUPP_NSS); 2081091296d3SMiri Korenblit nss = MAX_HE_SUPP_NSS; 2082091296d3SMiri Korenblit } 2083091296d3SMiri Korenblit 2084091296d3SMiri Korenblit for (i = 0; i < nss; i++) { 2085091296d3SMiri Korenblit u8 ru_index_tmp = ru_index_bitmap << 1; 2086091296d3SMiri Korenblit u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; 2087091296d3SMiri Korenblit u8 bw; 2088091296d3SMiri Korenblit 2089091296d3SMiri Korenblit for (bw = 0; 2090091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2091091296d3SMiri Korenblit bw++) { 2092091296d3SMiri Korenblit ru_index_tmp >>= 1; 2093091296d3SMiri Korenblit 2094cb63eb43SMiri Korenblit /* 2095cb63eb43SMiri Korenblit * According to the 11be spec, if for a specific BW the PPE Thresholds 2096cb63eb43SMiri Korenblit * isn't present - it should inherit the thresholds from the last 2097cb63eb43SMiri Korenblit * BW for which we had PPE Thresholds. In 11ax though, we don't have 2098cb63eb43SMiri Korenblit * this inheritance - continue in this case 2099cb63eb43SMiri Korenblit */ 2100cb63eb43SMiri Korenblit if (!(ru_index_tmp & 1)) { 2101cb63eb43SMiri Korenblit if (inheritance) 2102cb63eb43SMiri Korenblit goto set_thresholds; 2103cb63eb43SMiri Korenblit else 2104091296d3SMiri Korenblit continue; 2105cb63eb43SMiri Korenblit } 2106091296d3SMiri Korenblit 2107091296d3SMiri Korenblit high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2108091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2109091296d3SMiri Korenblit low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 2110091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2111091296d3SMiri Korenblit 2112cb63eb43SMiri Korenblit set_thresholds: 2113091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2114091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2115091296d3SMiri Korenblit } 2116091296d3SMiri Korenblit } 2117091296d3SMiri Korenblit } 2118091296d3SMiri Korenblit 2119091296d3SMiri Korenblit static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, 212057974a55SGregory Greenman struct ieee80211_link_sta *link_sta, 2121cb63eb43SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, 2122cb63eb43SMiri Korenblit bool inheritance) 2123091296d3SMiri Korenblit { 212457974a55SGregory Greenman u8 nss = (link_sta->he_cap.ppe_thres[0] & 212557974a55SGregory Greenman IEEE80211_PPE_THRES_NSS_MASK) + 1; 212657974a55SGregory Greenman u8 *ppe = &link_sta->he_cap.ppe_thres[0]; 2127091296d3SMiri Korenblit u8 ru_index_bitmap = 2128091296d3SMiri Korenblit u8_get_bits(*ppe, 2129091296d3SMiri Korenblit IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); 2130091296d3SMiri Korenblit /* Starting after PPE header */ 2131091296d3SMiri Korenblit u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; 2132091296d3SMiri Korenblit 2133cb63eb43SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit, 2134cb63eb43SMiri Korenblit inheritance); 2135091296d3SMiri Korenblit } 2136091296d3SMiri Korenblit 21374df6a075SMiri Korenblit static int 21384df6a075SMiri Korenblit iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, 21394df6a075SMiri Korenblit u8 nominal_padding) 2140091296d3SMiri Korenblit { 2141091296d3SMiri Korenblit int low_th = -1; 2142091296d3SMiri Korenblit int high_th = -1; 2143091296d3SMiri Korenblit int i; 2144091296d3SMiri Korenblit 2145cb63eb43SMiri Korenblit /* all the macros are the same for EHT and HE */ 2146091296d3SMiri Korenblit switch (nominal_padding) { 2147cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US: 2148091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2149091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2150091296d3SMiri Korenblit break; 2151cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US: 2152091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_BPSK; 2153091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 2154091296d3SMiri Korenblit break; 2155cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: 2156cb63eb43SMiri Korenblit case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US: 2157091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 2158091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_BPSK; 2159091296d3SMiri Korenblit break; 2160091296d3SMiri Korenblit } 2161091296d3SMiri Korenblit 21624df6a075SMiri Korenblit if (low_th < 0 || high_th < 0) 21634df6a075SMiri Korenblit return -EINVAL; 21644df6a075SMiri Korenblit 2165091296d3SMiri Korenblit /* Set the PPE thresholds accordingly */ 2166091296d3SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2167091296d3SMiri Korenblit u8 bw; 2168091296d3SMiri Korenblit 2169091296d3SMiri Korenblit for (bw = 0; 2170091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2171091296d3SMiri Korenblit bw++) { 2172091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 2173091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 2174091296d3SMiri Korenblit } 2175091296d3SMiri Korenblit } 2176091296d3SMiri Korenblit 21774df6a075SMiri Korenblit return 0; 2178091296d3SMiri Korenblit } 2179091296d3SMiri Korenblit 2180cb63eb43SMiri Korenblit static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext, 2181cb63eb43SMiri Korenblit u8 nominal_padding) 2182cb63eb43SMiri Korenblit { 2183cb63eb43SMiri Korenblit int i; 2184cb63eb43SMiri Korenblit 2185cb63eb43SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 2186cb63eb43SMiri Korenblit u8 bw; 2187cb63eb43SMiri Korenblit 2188cb63eb43SMiri Korenblit for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 2189cb63eb43SMiri Korenblit bw++) { 2190cb63eb43SMiri Korenblit u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0]; 2191cb63eb43SMiri Korenblit 2192cb63eb43SMiri Korenblit if (nominal_padding > 2193cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2194cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2195cb63eb43SMiri Korenblit qam_th[1] = IWL_HE_PKT_EXT_4096QAM; 2196cb63eb43SMiri Korenblit else if (nominal_padding == 2197cb63eb43SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US && 2198cb63eb43SMiri Korenblit qam_th[0] == IWL_HE_PKT_EXT_NONE && 2199cb63eb43SMiri Korenblit qam_th[1] == IWL_HE_PKT_EXT_NONE) 2200cb63eb43SMiri Korenblit qam_th[0] = IWL_HE_PKT_EXT_4096QAM; 2201cb63eb43SMiri Korenblit } 2202cb63eb43SMiri Korenblit } 2203cb63eb43SMiri Korenblit } 2204cb63eb43SMiri Korenblit 22054df6a075SMiri Korenblit /* Set the pkt_ext field according to PPE Thresholds element */ 220657974a55SGregory Greenman int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, 220757974a55SGregory Greenman struct ieee80211_link_sta *link_sta, 22084df6a075SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext) 22094df6a075SMiri Korenblit { 22104df6a075SMiri Korenblit u8 nominal_padding; 22114df6a075SMiri Korenblit int i, ret = 0; 22124df6a075SMiri Korenblit 221357974a55SGregory Greenman if (WARN_ON(!link_sta)) 221457974a55SGregory Greenman return -EINVAL; 221557974a55SGregory Greenman 22164df6a075SMiri Korenblit /* Initialize the PPE thresholds to "None" (7), as described in Table 22174df6a075SMiri Korenblit * 9-262ac of 80211.ax/D3.0. 22184df6a075SMiri Korenblit */ 22194df6a075SMiri Korenblit memset(pkt_ext, IWL_HE_PKT_EXT_NONE, 22204df6a075SMiri Korenblit sizeof(struct iwl_he_pkt_ext_v2)); 22214df6a075SMiri Korenblit 222257974a55SGregory Greenman if (link_sta->eht_cap.has_eht) { 22234df6a075SMiri Korenblit nominal_padding = 222457974a55SGregory Greenman u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5], 22254df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK); 22264df6a075SMiri Korenblit 22274df6a075SMiri Korenblit /* If PPE Thresholds exists, parse them into a FW-familiar 22284df6a075SMiri Korenblit * format. 22294df6a075SMiri Korenblit */ 223057974a55SGregory Greenman if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] & 22314df6a075SMiri Korenblit IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) { 223257974a55SGregory Greenman u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] & 22334df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1; 223457974a55SGregory Greenman u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0]; 22354df6a075SMiri Korenblit u8 ru_index_bitmap = 22364df6a075SMiri Korenblit u16_get_bits(*ppe, 22374df6a075SMiri Korenblit IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); 22384df6a075SMiri Korenblit /* Starting after PPE header */ 22394df6a075SMiri Korenblit u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE; 22404df6a075SMiri Korenblit 22414df6a075SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, 22424df6a075SMiri Korenblit ppe, ppe_pos_bit, true); 224357974a55SGregory Greenman /* EHT PPE Thresholds doesn't exist - set the API according to 224457974a55SGregory Greenman * HE PPE Tresholds 22454df6a075SMiri Korenblit */ 224657974a55SGregory Greenman } else if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 22474df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 22484df6a075SMiri Korenblit /* Even though HE Capabilities IE doesn't contain PPE 22494df6a075SMiri Korenblit * Thresholds for BW 320Mhz, thresholds for this BW will 22504df6a075SMiri Korenblit * be filled in with the same values as 160Mhz, due to 22514df6a075SMiri Korenblit * the inheritance, as required. 22524df6a075SMiri Korenblit */ 225357974a55SGregory Greenman iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 22544df6a075SMiri Korenblit true); 22554df6a075SMiri Korenblit 22564df6a075SMiri Korenblit /* According to the requirements, for MCSs 12-13 the 22574df6a075SMiri Korenblit * maximum value between HE PPE Threshold and Common 22584df6a075SMiri Korenblit * Nominal Packet Padding needs to be taken 22594df6a075SMiri Korenblit */ 22604df6a075SMiri Korenblit iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding); 22614df6a075SMiri Korenblit 22624df6a075SMiri Korenblit /* if PPE Thresholds doesn't present in both EHT IE and HE IE - 22634df6a075SMiri Korenblit * take the Thresholds from Common Nominal Packet Padding field 22644df6a075SMiri Korenblit */ 22654df6a075SMiri Korenblit } else { 22664df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 22674df6a075SMiri Korenblit nominal_padding); 22684df6a075SMiri Korenblit } 226957974a55SGregory Greenman } else if (link_sta->he_cap.has_he) { 22704df6a075SMiri Korenblit /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 227157974a55SGregory Greenman if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] & 22724df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 227357974a55SGregory Greenman iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, 22744df6a075SMiri Korenblit false); 22754df6a075SMiri Korenblit /* PPE Thresholds doesn't exist - set the API PPE values 22764df6a075SMiri Korenblit * according to Common Nominal Packet Padding field. 22774df6a075SMiri Korenblit */ 22784df6a075SMiri Korenblit } else { 22794df6a075SMiri Korenblit nominal_padding = 228057974a55SGregory Greenman u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9], 22814df6a075SMiri Korenblit IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 22824df6a075SMiri Korenblit if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) 22834df6a075SMiri Korenblit ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext, 22844df6a075SMiri Korenblit nominal_padding); 22854df6a075SMiri Korenblit } 22864df6a075SMiri Korenblit } 22874df6a075SMiri Korenblit 22884df6a075SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 22894df6a075SMiri Korenblit int bw; 22904df6a075SMiri Korenblit 22914df6a075SMiri Korenblit for (bw = 0; 22924df6a075SMiri Korenblit bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]); 22934df6a075SMiri Korenblit bw++) { 22944df6a075SMiri Korenblit u8 *qam_th = 22954df6a075SMiri Korenblit &pkt_ext->pkt_ext_qam_th[i][bw][0]; 22964df6a075SMiri Korenblit 22974df6a075SMiri Korenblit IWL_DEBUG_HT(mvm, 22984df6a075SMiri Korenblit "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n", 22994df6a075SMiri Korenblit i, bw, qam_th[0], qam_th[1]); 23004df6a075SMiri Korenblit } 23014df6a075SMiri Korenblit } 23024df6a075SMiri Korenblit return ret; 23034df6a075SMiri Korenblit } 23044df6a075SMiri Korenblit 23059c4f15caSMiri Korenblit /* 23069c4f15caSMiri Korenblit * This function sets the MU EDCA parameters ans returns whether MU EDCA 23079c4f15caSMiri Korenblit * is enabled or not 23089c4f15caSMiri Korenblit */ 230955eb1c5fSMiri Korenblit bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, 2310e119e740SEmmanuel Grumbach const struct iwl_mvm_vif_link_info *link_info, 231155eb1c5fSMiri Korenblit struct iwl_he_backoff_conf *trig_based_txf) 23129c4f15caSMiri Korenblit { 23139c4f15caSMiri Korenblit int i; 23149c4f15caSMiri Korenblit /* Mark MU EDCA as enabled, unless none detected on some AC */ 23159c4f15caSMiri Korenblit bool mu_edca_enabled = true; 23169c4f15caSMiri Korenblit 23179c4f15caSMiri Korenblit for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2318e119e740SEmmanuel Grumbach const struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2319e119e740SEmmanuel Grumbach &link_info->queue_params[i].mu_edca_param_rec; 23209c4f15caSMiri Korenblit u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 23219c4f15caSMiri Korenblit 2322e119e740SEmmanuel Grumbach if (!link_info->queue_params[i].mu_edca) { 23239c4f15caSMiri Korenblit mu_edca_enabled = false; 23249c4f15caSMiri Korenblit break; 23259c4f15caSMiri Korenblit } 23269c4f15caSMiri Korenblit 23279c4f15caSMiri Korenblit trig_based_txf[ac].cwmin = 23289c4f15caSMiri Korenblit cpu_to_le16(mu_edca->ecw_min_max & 0xf); 23299c4f15caSMiri Korenblit trig_based_txf[ac].cwmax = 23309c4f15caSMiri Korenblit cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 23319c4f15caSMiri Korenblit trig_based_txf[ac].aifsn = 23329c4f15caSMiri Korenblit cpu_to_le16(mu_edca->aifsn & 0xf); 23339c4f15caSMiri Korenblit trig_based_txf[ac].mu_time = 23349c4f15caSMiri Korenblit cpu_to_le16(mu_edca->mu_edca_timer); 23359c4f15caSMiri Korenblit } 23369c4f15caSMiri Korenblit 23379c4f15caSMiri Korenblit return mu_edca_enabled; 23389c4f15caSMiri Korenblit } 23399c4f15caSMiri Korenblit 23409be162a7SMiri Korenblit bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 23419c4f15caSMiri Korenblit { 23429c4f15caSMiri Korenblit const struct ieee80211_supported_band *sband; 23439c4f15caSMiri Korenblit const struct ieee80211_sta_he_cap *own_he_cap = NULL; 23449c4f15caSMiri Korenblit 23459c4f15caSMiri Korenblit /* This capability is the same for all bands, 23469c4f15caSMiri Korenblit * so take it from one of them. 23479c4f15caSMiri Korenblit */ 23489c4f15caSMiri Korenblit sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 23491ec7291eSJohannes Berg own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 23509c4f15caSMiri Korenblit 23519c4f15caSMiri Korenblit return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] & 23529c4f15caSMiri Korenblit IEEE80211_HE_MAC_CAP2_ACK_EN)); 23539c4f15caSMiri Korenblit } 23549c4f15caSMiri Korenblit 235557974a55SGregory Greenman __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta, 235657974a55SGregory Greenman struct ieee80211_link_sta *link_sta) 23574df6a075SMiri Korenblit { 235857974a55SGregory Greenman u8 *mac_cap_info = 235957974a55SGregory Greenman &link_sta->he_cap.he_cap_elem.mac_cap_info[0]; 23604df6a075SMiri Korenblit __le32 htc_flags = 0; 23614df6a075SMiri Korenblit 23624df6a075SMiri Korenblit if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) 23634df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 23644df6a075SMiri Korenblit if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 23654df6a075SMiri Korenblit (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 23664df6a075SMiri Korenblit u8 link_adap = 23674df6a075SMiri Korenblit ((mac_cap_info[2] & 23684df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 23694df6a075SMiri Korenblit (mac_cap_info[1] & 23704df6a075SMiri Korenblit IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 23714df6a075SMiri Korenblit 23724df6a075SMiri Korenblit if (link_adap == 2) 23734df6a075SMiri Korenblit htc_flags |= 23744df6a075SMiri Korenblit cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 23754df6a075SMiri Korenblit else if (link_adap == 3) 23764df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 23774df6a075SMiri Korenblit } 23784df6a075SMiri Korenblit if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 23794df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 23804df6a075SMiri Korenblit if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 23814df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 23824df6a075SMiri Korenblit if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 23834df6a075SMiri Korenblit htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 23844df6a075SMiri Korenblit 23854df6a075SMiri Korenblit return htc_flags; 23864df6a075SMiri Korenblit } 23874df6a075SMiri Korenblit 2388514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 2389514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 2390514c3069SLuca Coelho { 2391514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 239242506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { 2393514c3069SLuca Coelho .sta_id = sta_id, 2394514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 2395dd56e902SJohn Crispin .bss_color = vif->bss_conf.he_bss_color.color, 2396514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 2397514c3069SLuca Coelho .frame_time_rts_th = 2398514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 2399514c3069SLuca Coelho }; 240042506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; 240142506dd2SJohannes Berg u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); 240242506dd2SJohannes Berg u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); 240342506dd2SJohannes Berg int size; 2404514c3069SLuca Coelho struct ieee80211_sta *sta; 2405514c3069SLuca Coelho u32 flags; 2406514c3069SLuca Coelho int i; 240742506dd2SJohannes Berg void *cmd; 240842506dd2SJohannes Berg 240942506dd2SJohannes Berg if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) 241042506dd2SJohannes Berg ver = 1; 241142506dd2SJohannes Berg 241242506dd2SJohannes Berg switch (ver) { 241342506dd2SJohannes Berg case 1: 241442506dd2SJohannes Berg /* same layout as v2 except some data at the end */ 241542506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 241642506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v1); 241742506dd2SJohannes Berg break; 241842506dd2SJohannes Berg case 2: 241942506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 242042506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v2); 242142506dd2SJohannes Berg break; 242242506dd2SJohannes Berg case 3: 242342506dd2SJohannes Berg cmd = &sta_ctxt_cmd; 242442506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v3); 242542506dd2SJohannes Berg break; 242642506dd2SJohannes Berg default: 242742506dd2SJohannes Berg IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); 242842506dd2SJohannes Berg return; 242942506dd2SJohannes Berg } 2430514c3069SLuca Coelho 2431514c3069SLuca Coelho rcu_read_lock(); 2432514c3069SLuca Coelho 2433514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 243412d47f0eSAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) { 2435514c3069SLuca Coelho rcu_read_unlock(); 2436514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 2437514c3069SLuca Coelho return; 2438514c3069SLuca Coelho } 2439514c3069SLuca Coelho 2440046d2e7cSSriram R if (!sta->deflink.he_cap.has_he) { 2441514c3069SLuca Coelho rcu_read_unlock(); 2442514c3069SLuca Coelho return; 2443514c3069SLuca Coelho } 2444514c3069SLuca Coelho 2445514c3069SLuca Coelho flags = 0; 2446514c3069SLuca Coelho 24474f58121dSIlan Peer /* Block 26-tone RU OFDMA transmissions */ 2448650cadb7SGregory Greenman if (mvmvif->deflink.he_ru_2mhz_block) 24494f58121dSIlan Peer flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 24504f58121dSIlan Peer 2451514c3069SLuca Coelho /* HTC flags */ 245257974a55SGregory Greenman sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta, &sta->deflink); 2453514c3069SLuca Coelho 24544df6a075SMiri Korenblit /* PPE Thresholds */ 245557974a55SGregory Greenman if (!iwl_mvm_set_sta_pkt_ext(mvm, &sta->deflink, &sta_ctxt_cmd.pkt_ext)) 2456cb63eb43SMiri Korenblit flags |= STA_CTXT_HE_PACKET_EXT; 245773f23d91SShaul Triebitz 2458046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 245973f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 246073f23d91SShaul Triebitz flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 246173f23d91SShaul Triebitz 2462046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 246373f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN) 246473f23d91SShaul Triebitz flags |= STA_CTXT_HE_ACK_ENABLED; 246573f23d91SShaul Triebitz 2466514c3069SLuca Coelho rcu_read_unlock(); 2467514c3069SLuca Coelho 2468e119e740SEmmanuel Grumbach if (iwl_mvm_set_fw_mu_edca_params(mvm, &mvmvif->deflink, 24699c4f15caSMiri Korenblit &sta_ctxt_cmd.trig_based_txf[0])) 2470514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 2471514c3069SLuca Coelho 2472514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2473514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2474514c3069SLuca Coelho 2475514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2476514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2477514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2478514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2479514c3069SLuca Coelho } 2480514c3069SLuca Coelho 24819c4f15caSMiri Korenblit if (!iwl_mvm_is_nic_ack_enabled(mvm, vif)) 2482ee1a02d7SShaul Triebitz flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2483ee1a02d7SShaul Triebitz 2484918cbf39SSara Sharon if (vif->bss_conf.nontransmitted) { 2485918cbf39SSara Sharon flags |= STA_CTXT_HE_REF_BSSID_VALID; 2486918cbf39SSara Sharon ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2487918cbf39SSara Sharon vif->bss_conf.transmitter_bssid); 2488d14ae796SSara Sharon sta_ctxt_cmd.max_bssid_indicator = 2489d14ae796SSara Sharon vif->bss_conf.bssid_indicator; 2490d14ae796SSara Sharon sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2491d14ae796SSara Sharon sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2492d14ae796SSara Sharon sta_ctxt_cmd.profile_periodicity = 2493d14ae796SSara Sharon vif->bss_conf.profile_periodicity; 2494918cbf39SSara Sharon } 2495514c3069SLuca Coelho 2496514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2497514c3069SLuca Coelho 249842506dd2SJohannes Berg if (ver < 3) { 249942506dd2SJohannes Berg /* fields before pkt_ext */ 250042506dd2SJohannes Berg BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != 250142506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); 250242506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, 250342506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd), pkt_ext)); 250442506dd2SJohannes Berg 250542506dd2SJohannes Berg /* pkt_ext */ 250642506dd2SJohannes Berg for (i = 0; 250742506dd2SJohannes Berg i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); 250842506dd2SJohannes Berg i++) { 250942506dd2SJohannes Berg u8 bw; 251042506dd2SJohannes Berg 251142506dd2SJohannes Berg for (bw = 0; 251242506dd2SJohannes Berg bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); 251342506dd2SJohannes Berg bw++) { 251442506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != 251542506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); 251642506dd2SJohannes Berg 251742506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], 251842506dd2SJohannes Berg &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], 251942506dd2SJohannes Berg sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); 252042506dd2SJohannes Berg } 252142506dd2SJohannes Berg } 252242506dd2SJohannes Berg 252342506dd2SJohannes Berg /* fields after pkt_ext */ 252442506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - 252542506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != 252642506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2) - 252742506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); 252842506dd2SJohannes Berg memcpy((u8 *)&sta_ctxt_cmd_v2 + 252942506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), 253042506dd2SJohannes Berg (u8 *)&sta_ctxt_cmd + 253142506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext), 253242506dd2SJohannes Berg sizeof(sta_ctxt_cmd) - 253342506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); 253442506dd2SJohannes Berg sta_ctxt_cmd_v2.reserved3 = 0; 253542506dd2SJohannes Berg } 253642506dd2SJohannes Berg 253742506dd2SJohannes Berg if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) 2538514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2539514c3069SLuca Coelho } 2540514c3069SLuca Coelho 2541660eba5aSMiri Korenblit void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 254223673041SMiri Korenblit u32 duration_override, unsigned int link_id) 2543af84ac57SJohannes Berg { 2544af84ac57SJohannes Berg u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2545af84ac57SJohannes Berg u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2546af84ac57SJohannes Berg 2547af84ac57SJohannes Berg if (duration_override > duration) 2548af84ac57SJohannes Berg duration = duration_override; 2549af84ac57SJohannes Berg 2550af84ac57SJohannes Berg /* Try really hard to protect the session and hear a beacon 2551af84ac57SJohannes Berg * The new session protection command allows us to protect the 2552af84ac57SJohannes Berg * session for a much longer time since the firmware will internally 2553af84ac57SJohannes Berg * create two events: a 300TU one with a very high priority that 2554af84ac57SJohannes Berg * won't be fragmented which should be enough for 99% of the cases, 2555af84ac57SJohannes Berg * and another one (which we configure here to be 900TU long) which 2556af84ac57SJohannes Berg * will have a slightly lower priority, but more importantly, can be 2557af84ac57SJohannes Berg * fragmented so that it'll allow other activities to run. 2558af84ac57SJohannes Berg */ 2559af84ac57SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 2560af84ac57SJohannes Berg IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2561af84ac57SJohannes Berg iwl_mvm_schedule_session_protection(mvm, vif, 900, 256223673041SMiri Korenblit min_duration, false, 256323673041SMiri Korenblit link_id); 2564af84ac57SJohannes Berg else 2565af84ac57SJohannes Berg iwl_mvm_protect_session(mvm, vif, duration, 2566af84ac57SJohannes Berg min_duration, 500, false); 2567af84ac57SJohannes Berg } 2568af84ac57SJohannes Berg 2569660eba5aSMiri Korenblit /* Handle association common part to MLD and non-MLD modes */ 2570660eba5aSMiri Korenblit void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm, 2571660eba5aSMiri Korenblit struct ieee80211_vif *vif, 2572660eba5aSMiri Korenblit u64 changes) 2573660eba5aSMiri Korenblit { 2574660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2575660eba5aSMiri Korenblit int ret; 2576c1e458b9SIlan Peer int link_id; 2577660eba5aSMiri Korenblit 2578660eba5aSMiri Korenblit /* The firmware tracks the MU-MIMO group on its own. 2579660eba5aSMiri Korenblit * However, on HW restart we should restore this data. 2580660eba5aSMiri Korenblit */ 2581660eba5aSMiri Korenblit if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2582660eba5aSMiri Korenblit (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { 2583660eba5aSMiri Korenblit ret = iwl_mvm_update_mu_groups(mvm, vif); 2584660eba5aSMiri Korenblit if (ret) 2585660eba5aSMiri Korenblit IWL_ERR(mvm, 2586660eba5aSMiri Korenblit "failed to update VHT MU_MIMO groups\n"); 2587660eba5aSMiri Korenblit } 2588660eba5aSMiri Korenblit 2589660eba5aSMiri Korenblit iwl_mvm_recalc_multicast(mvm); 2590660eba5aSMiri Korenblit 2591660eba5aSMiri Korenblit /* reset rssi values */ 2592c1e458b9SIlan Peer for_each_mvm_vif_valid_link(mvmvif, link_id) 2593c1e458b9SIlan Peer mvmvif->link[link_id]->bf_data.ave_beacon_signal = 0; 2594660eba5aSMiri Korenblit 2595660eba5aSMiri Korenblit iwl_mvm_bt_coex_vif_change(mvm); 25961a3e7039SGregory Greenman iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2597660eba5aSMiri Korenblit IEEE80211_SMPS_AUTOMATIC); 2598660eba5aSMiri Korenblit if (fw_has_capa(&mvm->fw->ucode_capa, 2599660eba5aSMiri Korenblit IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2600660eba5aSMiri Korenblit iwl_mvm_config_scan(mvm); 2601660eba5aSMiri Korenblit } 2602660eba5aSMiri Korenblit 2603660eba5aSMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 26041a3e7039SGregory Greenman void 26051a3e7039SGregory Greenman iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm, 2606660eba5aSMiri Korenblit struct ieee80211_vif *vif, 26071a3e7039SGregory Greenman struct ieee80211_bss_conf *link_conf, 2608660eba5aSMiri Korenblit u64 changes) 2609660eba5aSMiri Korenblit { 2610660eba5aSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2611660eba5aSMiri Korenblit int ret; 2612660eba5aSMiri Korenblit 2613660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BEACON_INFO) { 2614660eba5aSMiri Korenblit /* We received a beacon from the associated AP so 2615660eba5aSMiri Korenblit * remove the session protection. 2616660eba5aSMiri Korenblit */ 2617660eba5aSMiri Korenblit iwl_mvm_stop_session_protection(mvm, vif); 2618660eba5aSMiri Korenblit 2619660eba5aSMiri Korenblit iwl_mvm_sf_update(mvm, vif, false); 262087f5b5f2SJohannes Berg WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 2621660eba5aSMiri Korenblit } 2622660eba5aSMiri Korenblit 2623660eba5aSMiri Korenblit if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2624660eba5aSMiri Korenblit /* Send power command on every beacon change, 2625660eba5aSMiri Korenblit * because we may have not enabled beacon abort yet. 2626660eba5aSMiri Korenblit */ 2627660eba5aSMiri Korenblit BSS_CHANGED_BEACON_INFO)) { 2628660eba5aSMiri Korenblit ret = iwl_mvm_power_update_mac(mvm); 2629660eba5aSMiri Korenblit if (ret) 2630660eba5aSMiri Korenblit IWL_ERR(mvm, "failed to update power mode\n"); 2631660eba5aSMiri Korenblit } 2632660eba5aSMiri Korenblit 2633660eba5aSMiri Korenblit if (changes & BSS_CHANGED_CQM) { 2634c1e458b9SIlan Peer struct iwl_mvm_vif_link_info *link_info = 2635c1e458b9SIlan Peer mvmvif->link[link_conf->link_id]; 2636c1e458b9SIlan Peer 2637c1e458b9SIlan Peer IWL_DEBUG_MAC80211(mvm, "CQM info_changed\n"); 2638c1e458b9SIlan Peer if (link_info) 2639c1e458b9SIlan Peer link_info->bf_data.last_cqm_event = 0; 2640c1e458b9SIlan Peer 2641c1e458b9SIlan Peer if (mvmvif->bf_enabled) { 264222c58834SGregory Greenman /* FIXME: need to update per link when FW API will 264322c58834SGregory Greenman * support it 264422c58834SGregory Greenman */ 264587f5b5f2SJohannes Berg ret = iwl_mvm_enable_beacon_filter(mvm, vif); 2646660eba5aSMiri Korenblit if (ret) 2647660eba5aSMiri Korenblit IWL_ERR(mvm, 2648660eba5aSMiri Korenblit "failed to update CQM thresholds\n"); 2649660eba5aSMiri Korenblit } 2650660eba5aSMiri Korenblit } 2651660eba5aSMiri Korenblit 2652660eba5aSMiri Korenblit if (changes & BSS_CHANGED_BANDWIDTH) 26531a3e7039SGregory Greenman iwl_mvm_update_link_smps(vif, link_conf); 2654660eba5aSMiri Korenblit } 2655660eba5aSMiri Korenblit 2656e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2657e705c121SKalle Valo struct ieee80211_vif *vif, 2658e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 26597b7090b4SJohannes Berg u64 changes) 2660e705c121SKalle Valo { 2661e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2662e705c121SKalle Valo int ret; 2663b6e3d1baSAnjaneyulu int i; 2664e705c121SKalle Valo 2665e705c121SKalle Valo /* 2666cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend 2667cdaba917SEmmanuel Grumbach * on the beacon interval, which was not known when the station 2668cdaba917SEmmanuel Grumbach * interface was added. 2669e705c121SKalle Valo */ 2670f276e20bSJohannes Berg if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { 2671cb63eb43SMiri Korenblit if ((vif->bss_conf.he_support && 267283f57c93SJohannes Berg !iwlwifi_mod_params.disable_11ax)) 2673650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 2674514c3069SLuca Coelho 2675e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2676514c3069SLuca Coelho } 2677e705c121SKalle Valo 267840ecdd01SShaul Triebitz /* Update MU EDCA params */ 267940ecdd01SShaul Triebitz if (changes & BSS_CHANGED_QOS && mvmvif->associated && 2680cb63eb43SMiri Korenblit vif->cfg.assoc && 268183f57c93SJohannes Berg (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax)) 2682650cadb7SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id); 268340ecdd01SShaul Triebitz 2684e705c121SKalle Valo /* 2685e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2686e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2687e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2688e705c121SKalle Valo * branch for disassociation below. 2689e705c121SKalle Valo */ 2690e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2691650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2692e705c121SKalle Valo 2693650cadb7SGregory Greenman ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid); 2694e705c121SKalle Valo if (ret) 2695e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2696e705c121SKalle Valo 2697e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2698650cadb7SGregory Greenman memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN); 2699f276e20bSJohannes Berg mvmvif->associated = vif->cfg.assoc; 2700e705c121SKalle Valo 2701e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2702f276e20bSJohannes Berg if (vif->cfg.assoc) { 2703e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2704e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2705b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 2706b6e3d1baSAnjaneyulu memset(&mvmvif->link[i]->beacon_stats, 0, 2707b6e3d1baSAnjaneyulu sizeof(mvmvif->link[i]->beacon_stats)); 2708e705c121SKalle Valo 2709e705c121SKalle Valo /* add quota for this interface */ 2710e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2711e705c121SKalle Valo if (ret) { 2712e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2713e705c121SKalle Valo return; 2714e705c121SKalle Valo } 2715e705c121SKalle Valo 2716e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2717fe959c7bSEmmanuel Grumbach &mvm->status) && 2718fe959c7bSEmmanuel Grumbach !fw_has_capa(&mvm->fw->ucode_capa, 2719fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2720e705c121SKalle Valo /* 2721e705c121SKalle Valo * If we're restarting then the firmware will 2722e705c121SKalle Valo * obviously have lost synchronisation with 2723e705c121SKalle Valo * the AP. It will attempt to synchronise by 2724e705c121SKalle Valo * itself, but we can make it more reliable by 2725e705c121SKalle Valo * scheduling a session protection time event. 2726e705c121SKalle Valo * 2727e705c121SKalle Valo * The firmware needs to receive a beacon to 2728e705c121SKalle Valo * catch up with synchronisation, use 110% of 2729e705c121SKalle Valo * the beacon interval. 2730e705c121SKalle Valo * 2731e705c121SKalle Valo * Set a large maximum delay to allow for more 2732e705c121SKalle Valo * than a single interface. 2733fe959c7bSEmmanuel Grumbach * 2734fe959c7bSEmmanuel Grumbach * For new firmware versions, rely on the 2735fe959c7bSEmmanuel Grumbach * firmware. This is relevant for DCM scenarios 2736fe959c7bSEmmanuel Grumbach * only anyway. 2737e705c121SKalle Valo */ 2738e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2739e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2740e705c121SKalle Valo 5 * dur, false); 2741af84ac57SJohannes Berg } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2742af84ac57SJohannes Berg &mvm->status) && 2743af84ac57SJohannes Berg !vif->bss_conf.dtim_period) { 2744af84ac57SJohannes Berg /* 2745af84ac57SJohannes Berg * If we're not restarting and still haven't 2746af84ac57SJohannes Berg * heard a beacon (dtim period unknown) then 2747af84ac57SJohannes Berg * make sure we still have enough minimum time 2748af84ac57SJohannes Berg * remaining in the time event, since the auth 2749af84ac57SJohannes Berg * might actually have taken quite a while 2750af84ac57SJohannes Berg * (especially for SAE) and so the remaining 2751af84ac57SJohannes Berg * time could be small without us having heard 2752af84ac57SJohannes Berg * a beacon yet. 2753af84ac57SJohannes Berg */ 275423673041SMiri Korenblit iwl_mvm_protect_assoc(mvm, vif, 0, 0); 2755e705c121SKalle Valo } 2756e705c121SKalle Valo 2757e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2758e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2759e705c121SKalle Valo if (vif->p2p) { 2760e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2761e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 27621a3e7039SGregory Greenman IEEE80211_SMPS_DYNAMIC, 0); 2763e705c121SKalle Valo } 2764650cadb7SGregory Greenman } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) { 27656d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_disassociated(mvm); 2766e705c121SKalle Valo /* 2767e705c121SKalle Valo * If update fails - SF might be running in associated 2768e705c121SKalle Valo * mode while disassociated - which is forbidden. 2769e705c121SKalle Valo */ 277069e508b4SIlan Peer ret = iwl_mvm_sf_update(mvm, vif, false); 277169e508b4SIlan Peer WARN_ONCE(ret && 277269e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 277369e508b4SIlan Peer &mvm->status), 2774e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2775e705c121SKalle Valo 27766b28f978SEmmanuel Grumbach /* 27776b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 27786b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 27796b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 27806b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 27816b28f978SEmmanuel Grumbach * associated, we would remove the station here and 27826b28f978SEmmanuel Grumbach * this would fail the recovery. 27836b28f978SEmmanuel Grumbach */ 27846b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 27856b28f978SEmmanuel Grumbach &mvm->status)) { 27865c75a208SJohannes Berg /* first remove remaining keys */ 2787ba9eef6bSGregory Greenman iwl_mvm_sec_key_remove_ap(mvm, vif, 2788072573f6SJohannes Berg &mvmvif->deflink, 0); 27895c75a208SJohannes Berg 27906b28f978SEmmanuel Grumbach /* 27916b28f978SEmmanuel Grumbach * Remove AP station now that 27926b28f978SEmmanuel Grumbach * the MAC is unassoc 27936b28f978SEmmanuel Grumbach */ 27946b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 2795650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id); 2796e705c121SKalle Valo if (ret) 27976b28f978SEmmanuel Grumbach IWL_ERR(mvm, 27986b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2799e705c121SKalle Valo 2800650cadb7SGregory Greenman mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA; 28016b28f978SEmmanuel Grumbach } 28026b28f978SEmmanuel Grumbach 2803e705c121SKalle Valo /* remove quota for this interface */ 2804e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2805e705c121SKalle Valo if (ret) 2806e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2807e705c121SKalle Valo 2808e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2809e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2810e705c121SKalle Valo if (ret) 2811e705c121SKalle Valo IWL_ERR(mvm, 2812e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2813e705c121SKalle Valo vif->addr); 2814e705c121SKalle Valo } 2815e705c121SKalle Valo 2816660eba5aSMiri Korenblit iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes); 2817a07a8f37SSara Sharon } 2818a07a8f37SSara Sharon 28191a3e7039SGregory Greenman iwl_mvm_bss_info_changed_station_common(mvm, vif, &vif->bss_conf, 28201a3e7039SGregory Greenman changes); 2821b45242c9SAvraham Stern } 2822b45242c9SAvraham Stern 2823f947b62cSMiri Korenblit bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw, 2824f947b62cSMiri Korenblit struct ieee80211_vif *vif, 2825f947b62cSMiri Korenblit int *ret) 2826f947b62cSMiri Korenblit { 2827f947b62cSMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2828f947b62cSMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2829f947b62cSMiri Korenblit int i; 2830e705c121SKalle Valo 2831f947b62cSMiri Korenblit lockdep_assert_held(&mvm->mutex); 2832f947b62cSMiri Korenblit 2833f947b62cSMiri Korenblit mvmvif->ap_assoc_sta_count = 0; 2834f947b62cSMiri Korenblit 2835f947b62cSMiri Korenblit /* must be set before quota calculations */ 2836f947b62cSMiri Korenblit mvmvif->ap_ibss_active = true; 2837f947b62cSMiri Korenblit 2838f947b62cSMiri Korenblit /* send all the early keys to the device now */ 2839f947b62cSMiri Korenblit for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2840f947b62cSMiri Korenblit struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2841f947b62cSMiri Korenblit 2842f947b62cSMiri Korenblit if (!key) 2843f947b62cSMiri Korenblit continue; 2844f947b62cSMiri Korenblit 2845f947b62cSMiri Korenblit mvmvif->ap_early_keys[i] = NULL; 2846f947b62cSMiri Korenblit 2847f947b62cSMiri Korenblit *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2848f947b62cSMiri Korenblit if (*ret) 2849f947b62cSMiri Korenblit return true; 2850e705c121SKalle Valo } 2851e705c121SKalle Valo 2852f947b62cSMiri Korenblit if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 2853f947b62cSMiri Korenblit iwl_mvm_vif_set_low_latency(mvmvif, true, 2854f947b62cSMiri Korenblit LOW_LATENCY_VIF_TYPE); 2855f947b62cSMiri Korenblit iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 2856e705c121SKalle Valo } 2857e705c121SKalle Valo 2858f947b62cSMiri Korenblit /* power updated needs to be done before quotas */ 2859f947b62cSMiri Korenblit iwl_mvm_power_update_mac(mvm); 2860e705c121SKalle Valo 2861f947b62cSMiri Korenblit return false; 2862e705c121SKalle Valo } 2863e705c121SKalle Valo 2864e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2865ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2866b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2867e705c121SKalle Valo { 2868e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2869e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2870f947b62cSMiri Korenblit int ret; 2871e705c121SKalle Valo 2872e705c121SKalle Valo mutex_lock(&mvm->mutex); 2873e705c121SKalle Valo 2874e705c121SKalle Valo /* 2875cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend on 2876cdaba917SEmmanuel Grumbach * the beacon interval, which was not known when the AP interface 2877cdaba917SEmmanuel Grumbach * was added. 2878e705c121SKalle Valo */ 2879e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2880e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2881e705c121SKalle Valo 288236cf5377SGregory Greenman /* For older devices need to send beacon template before adding mac 288336cf5377SGregory Greenman * context. For the newer, the beacon is a resource that belongs to a 288436cf5377SGregory Greenman * MAC, so need to send beacon template after adding the mac. 288536cf5377SGregory Greenman */ 288636cf5377SGregory Greenman if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) { 2887e705c121SKalle Valo /* Add the mac context */ 2888e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2889e705c121SKalle Valo if (ret) 2890e705c121SKalle Valo goto out_unlock; 2891e705c121SKalle Valo 289236cf5377SGregory Greenman /* Send the beacon template */ 289336cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 289436cf5377SGregory Greenman if (ret) 289536cf5377SGregory Greenman goto out_unlock; 289636cf5377SGregory Greenman } else { 289736cf5377SGregory Greenman /* Send the beacon template */ 289836cf5377SGregory Greenman ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); 289936cf5377SGregory Greenman if (ret) 290036cf5377SGregory Greenman goto out_unlock; 2901e705c121SKalle Valo 2902e705c121SKalle Valo /* Add the mac context */ 2903e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2904e705c121SKalle Valo if (ret) 2905e705c121SKalle Valo goto out_unlock; 290636cf5377SGregory Greenman } 2907e705c121SKalle Valo 2908e705c121SKalle Valo /* Perform the binding */ 2909e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2910e705c121SKalle Valo if (ret) 2911e705c121SKalle Valo goto out_remove; 2912e705c121SKalle Valo 291363dd5d02SSara Sharon /* 291463dd5d02SSara Sharon * This is not very nice, but the simplest: 291563dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 291663dd5d02SSara Sharon * cause assert 0x2b00. 291763dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 291863dd5d02SSara Sharon * the TLV 291963dd5d02SSara Sharon */ 292063dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2921ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2922ced19f26SSara Sharon if (ret) 2923ced19f26SSara Sharon goto out_unbind; 292463dd5d02SSara Sharon /* 292563dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 292663dd5d02SSara Sharon * events are added and applied to the scheduler 292763dd5d02SSara Sharon */ 2928e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 292963dd5d02SSara Sharon if (ret) { 293063dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 293163dd5d02SSara Sharon goto out_unbind; 293263dd5d02SSara Sharon } 293363dd5d02SSara Sharon } else { 293463dd5d02SSara Sharon /* 293563dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 293663dd5d02SSara Sharon * events are added and applied to the scheduler 293763dd5d02SSara Sharon */ 293875fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2939e705c121SKalle Valo if (ret) 294063dd5d02SSara Sharon goto out_unbind; 294175fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 294263dd5d02SSara Sharon if (ret) { 294363dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 294463dd5d02SSara Sharon goto out_unbind; 294563dd5d02SSara Sharon } 294663dd5d02SSara Sharon } 294726d6c16bSSara Sharon 2948f947b62cSMiri Korenblit if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) 2949f947b62cSMiri Korenblit goto out_failed; 2950e705c121SKalle Valo 2951e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2952e705c121SKalle Valo if (ret) 2953f947b62cSMiri Korenblit goto out_failed; 2954e705c121SKalle Valo 2955e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2956e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2957e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2958e705c121SKalle Valo 2959e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2960e705c121SKalle Valo 2961e705c121SKalle Valo /* we don't support TDLS during DCM */ 2962e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2963e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2964e705c121SKalle Valo 2965fd940de7SAvraham Stern iwl_mvm_ftm_restart_responder(mvm, vif, &vif->bss_conf); 2966b73f9a4aSJohannes Berg 2967e705c121SKalle Valo goto out_unlock; 2968e705c121SKalle Valo 2969f947b62cSMiri Korenblit out_failed: 2970e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2971e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2972e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2973ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2974e705c121SKalle Valo out_unbind: 2975e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2976e705c121SKalle Valo out_remove: 2977e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2978e705c121SKalle Valo out_unlock: 2979e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2980e705c121SKalle Valo return ret; 2981e705c121SKalle Valo } 2982e705c121SKalle Valo 2983ae7ba17bSShaul Triebitz static int iwl_mvm_start_ap(struct ieee80211_hw *hw, 2984ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2985b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2986ae7ba17bSShaul Triebitz { 2987b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, link_conf); 2988ae7ba17bSShaul Triebitz } 2989ae7ba17bSShaul Triebitz 2990ae7ba17bSShaul Triebitz static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, 2991e705c121SKalle Valo struct ieee80211_vif *vif) 2992e705c121SKalle Valo { 2993b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); 2994ae7ba17bSShaul Triebitz } 2995ae7ba17bSShaul Triebitz 2996fd1a54c1SMiri Korenblit /* Common part for MLD and non-MLD ops */ 2997fd1a54c1SMiri Korenblit void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm, 2998fd1a54c1SMiri Korenblit struct ieee80211_vif *vif) 2999ae7ba17bSShaul Triebitz { 3000e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3001e705c121SKalle Valo 3002fd1a54c1SMiri Korenblit lockdep_assert_held(&mvm->mutex); 3003e705c121SKalle Valo 3004fd1a54c1SMiri Korenblit iwl_mvm_prepare_mac_removal(mvm, vif); 3005e705c121SKalle Valo 3006e705c121SKalle Valo /* Handle AP stop while in CSA */ 3007e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 3008e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 3009e705c121SKalle Valo &mvmvif->time_event_data); 3010e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 3011e705c121SKalle Valo mvmvif->csa_countdown = false; 3012e705c121SKalle Valo } 3013e705c121SKalle Valo 3014e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 3015e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 3016e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 3017e705c121SKalle Valo } 3018e705c121SKalle Valo 3019e705c121SKalle Valo mvmvif->ap_ibss_active = false; 3020e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 3021e705c121SKalle Valo 302247242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 302347242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 302447242744STova Mussai LOW_LATENCY_VIF_TYPE); 302547242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 302647242744STova Mussai } 302747242744STova Mussai 3028e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 3029fd1a54c1SMiri Korenblit } 3030fd1a54c1SMiri Korenblit 3031fd1a54c1SMiri Korenblit static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 3032fd1a54c1SMiri Korenblit struct ieee80211_vif *vif, 3033fd1a54c1SMiri Korenblit struct ieee80211_bss_conf *link_conf) 3034fd1a54c1SMiri Korenblit { 3035fd1a54c1SMiri Korenblit struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3036fd1a54c1SMiri Korenblit 3037fd1a54c1SMiri Korenblit mutex_lock(&mvm->mutex); 3038fd1a54c1SMiri Korenblit 3039fd1a54c1SMiri Korenblit iwl_mvm_stop_ap_ibss_common(mvm, vif); 3040e705c121SKalle Valo 3041e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 3042e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 3043e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 3044e705c121SKalle Valo 3045e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3046ced19f26SSara Sharon 3047be82ecd3SAvraham Stern iwl_mvm_ftm_responder_clear(mvm, vif); 3048be82ecd3SAvraham Stern 3049ced19f26SSara Sharon /* 3050ced19f26SSara Sharon * This is not very nice, but the simplest: 3051ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 3052ced19f26SSara Sharon * cause assert 0x2b00. 3053ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 3054ced19f26SSara Sharon * bcast station). 3055ced19f26SSara Sharon * So make the order of removal depend on the TLV 3056ced19f26SSara Sharon */ 3057ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 305826d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 3059e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 3060ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 3061ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 3062e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3063e705c121SKalle Valo 3064e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3065e705c121SKalle Valo 3066e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 3067e705c121SKalle Valo 3068e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3069e705c121SKalle Valo } 3070e705c121SKalle Valo 3071ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, 3072ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 3073b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 3074ae7ba17bSShaul Triebitz { 3075b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, link_conf); 3076ae7ba17bSShaul Triebitz } 3077ae7ba17bSShaul Triebitz 3078ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, 3079ae7ba17bSShaul Triebitz struct ieee80211_vif *vif) 3080ae7ba17bSShaul Triebitz { 3081b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); 3082ae7ba17bSShaul Triebitz } 3083ae7ba17bSShaul Triebitz 3084e705c121SKalle Valo static void 3085e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 3086e705c121SKalle Valo struct ieee80211_vif *vif, 3087e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 30887b7090b4SJohannes Berg u64 changes) 3089e705c121SKalle Valo { 3090e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3091e705c121SKalle Valo 3092e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 3093e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 3094e705c121SKalle Valo return; 3095e705c121SKalle Valo 3096e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 3097e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 3098e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 3099e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 3100e705c121SKalle Valo 3101e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 3102e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 310336cf5377SGregory Greenman iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf)) 3104e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 3105e705c121SKalle Valo 3106b73f9a4aSJohannes Berg if (changes & BSS_CHANGED_FTM_RESPONDER) { 3107fd940de7SAvraham Stern int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf); 3108b73f9a4aSJohannes Berg 3109b73f9a4aSJohannes Berg if (ret) 3110b73f9a4aSJohannes Berg IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 3111b73f9a4aSJohannes Berg ret); 3112b73f9a4aSJohannes Berg } 3113b73f9a4aSJohannes Berg 3114e705c121SKalle Valo } 3115e705c121SKalle Valo 3116e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 3117e705c121SKalle Valo struct ieee80211_vif *vif, 3118e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 31197b7090b4SJohannes Berg u64 changes) 3120e705c121SKalle Valo { 3121e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3122e705c121SKalle Valo 3123e705c121SKalle Valo mutex_lock(&mvm->mutex); 3124e705c121SKalle Valo 3125f276e20bSJohannes Berg if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 3126e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 3127e705c121SKalle Valo 3128e705c121SKalle Valo switch (vif->type) { 3129e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3130df7e3098SMiri Korenblit iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 3131e705c121SKalle Valo break; 3132e705c121SKalle Valo case NL80211_IFTYPE_AP: 3133e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3134df7e3098SMiri Korenblit iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 3135e705c121SKalle Valo break; 313691b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 313791b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 313891b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 313991b08c2dSAviya Erenfeld break; 3140e705c121SKalle Valo default: 3141e705c121SKalle Valo /* shouldn't happen */ 3142e705c121SKalle Valo WARN_ON_ONCE(1); 3143e705c121SKalle Valo } 3144e705c121SKalle Valo 31459aae43a4SJohannes Berg if (changes & BSS_CHANGED_TXPOWER) { 31469aae43a4SJohannes Berg IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 31479aae43a4SJohannes Berg bss_conf->txpower); 31489aae43a4SJohannes Berg iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 31499aae43a4SJohannes Berg } 31509aae43a4SJohannes Berg 3151e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3152e705c121SKalle Valo } 3153e705c121SKalle Valo 3154cbce62a3SMiri Korenblit int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3155e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 3156e705c121SKalle Valo { 3157e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3158e705c121SKalle Valo int ret; 3159e705c121SKalle Valo 3160e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 3161e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 3162e705c121SKalle Valo return -EINVAL; 3163e705c121SKalle Valo 3164e705c121SKalle Valo mutex_lock(&mvm->mutex); 3165e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 3166e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3167e705c121SKalle Valo 3168e705c121SKalle Valo return ret; 3169e705c121SKalle Valo } 3170e705c121SKalle Valo 3171cbce62a3SMiri Korenblit void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 3172e705c121SKalle Valo struct ieee80211_vif *vif) 3173e705c121SKalle Valo { 3174e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3175e705c121SKalle Valo 3176e705c121SKalle Valo mutex_lock(&mvm->mutex); 3177e705c121SKalle Valo 3178e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3179e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 3180e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 3181e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 3182e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 3183e705c121SKalle Valo * To handle that, simply return if the scan is not running. 3184e705c121SKalle Valo */ 3185e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 3186e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 3187e705c121SKalle Valo 3188e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3189e705c121SKalle Valo } 3190e705c121SKalle Valo 3191cbce62a3SMiri Korenblit void 3192e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 3193e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3194e705c121SKalle Valo int num_frames, 3195e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3196e705c121SKalle Valo bool more_data) 3197e705c121SKalle Valo { 3198e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3199e705c121SKalle Valo 3200e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 3201e705c121SKalle Valo 3202e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3203e705c121SKalle Valo tids, more_data, false); 3204e705c121SKalle Valo } 3205e705c121SKalle Valo 3206cbce62a3SMiri Korenblit void 3207e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 3208e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 3209e705c121SKalle Valo int num_frames, 3210e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3211e705c121SKalle Valo bool more_data) 3212e705c121SKalle Valo { 3213e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3214e705c121SKalle Valo 32159a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 3216e705c121SKalle Valo 3217e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 3218e705c121SKalle Valo tids, more_data, true); 3219e705c121SKalle Valo } 3220e705c121SKalle Valo 322165e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 3222e705c121SKalle Valo enum sta_notify_cmd cmd, 3223e705c121SKalle Valo struct ieee80211_sta *sta) 3224e705c121SKalle Valo { 3225e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3226e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3227e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 3228e705c121SKalle Valo int tid; 3229e705c121SKalle Valo 3230960f864bSJohannes Berg /* 3231960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 3232960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 3233960f864bSJohannes Berg * should have firmware supporting buffer station offload. 3234960f864bSJohannes Berg */ 3235960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 3236960f864bSJohannes Berg return; 3237960f864bSJohannes Berg 3238e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 3239311590a3SEmmanuel Grumbach for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 3240e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 3241e705c121SKalle Valo 32426862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 32431c17627bSSara Sharon continue; 32441c17627bSSara Sharon 3245e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 3246e705c121SKalle Valo 3247dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 3248e705c121SKalle Valo continue; 3249e705c121SKalle Valo 3250e705c121SKalle Valo __set_bit(tid, &tids); 3251e705c121SKalle Valo } 3252e705c121SKalle Valo 3253e705c121SKalle Valo switch (cmd) { 3254e705c121SKalle Valo case STA_NOTIFY_SLEEP: 3255e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 3256e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 3257e705c121SKalle Valo 3258e705c121SKalle Valo if (txqs) 3259e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 3260e705c121SKalle Valo /* 3261e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 3262e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 3263e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 3264e705c121SKalle Valo */ 3265e705c121SKalle Valo break; 3266e705c121SKalle Valo case STA_NOTIFY_AWAKE: 3267c8ee33e1SGregory Greenman if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA)) 3268e705c121SKalle Valo break; 3269e705c121SKalle Valo 3270e705c121SKalle Valo if (txqs) 3271e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 3272e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 3273e705c121SKalle Valo break; 3274e705c121SKalle Valo default: 3275e705c121SKalle Valo break; 3276e705c121SKalle Valo } 3277e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 3278e705c121SKalle Valo } 3279e705c121SKalle Valo 3280cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 3281cbce62a3SMiri Korenblit enum sta_notify_cmd cmd, struct ieee80211_sta *sta) 328265e25482SJohannes Berg { 328365e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 328465e25482SJohannes Berg } 328565e25482SJohannes Berg 328665e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 328765e25482SJohannes Berg { 328865e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 328965e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 329065e25482SJohannes Berg struct ieee80211_sta *sta; 329165e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 329265e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 329365e25482SJohannes Berg 3294be9ae34eSNathan Errera if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 329565e25482SJohannes Berg return; 329665e25482SJohannes Berg 329765e25482SJohannes Berg rcu_read_lock(); 3298a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 329965e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 330065e25482SJohannes Berg rcu_read_unlock(); 330165e25482SJohannes Berg return; 330265e25482SJohannes Berg } 330365e25482SJohannes Berg 330465e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 330565e25482SJohannes Berg 330665e25482SJohannes Berg if (!mvmsta->vif || 330765e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 330865e25482SJohannes Berg rcu_read_unlock(); 330965e25482SJohannes Berg return; 331065e25482SJohannes Berg } 331165e25482SJohannes Berg 331265e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 331365e25482SJohannes Berg mvmsta->sleeping = sleeping; 331465e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 331565e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 331665e25482SJohannes Berg sta); 331765e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 331865e25482SJohannes Berg } 331965e25482SJohannes Berg 332065e25482SJohannes Berg if (sleeping) { 332165e25482SJohannes Berg switch (notif->type) { 332265e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 332365e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 332465e25482SJohannes Berg break; 332565e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 332665e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 332765e25482SJohannes Berg break; 332865e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 332965e25482SJohannes Berg ieee80211_sta_pspoll(sta); 333065e25482SJohannes Berg break; 333165e25482SJohannes Berg default: 333265e25482SJohannes Berg break; 333365e25482SJohannes Berg } 333465e25482SJohannes Berg } 333565e25482SJohannes Berg 333665e25482SJohannes Berg rcu_read_unlock(); 333765e25482SJohannes Berg } 333865e25482SJohannes Berg 3339cbce62a3SMiri Korenblit void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 3340e705c121SKalle Valo struct ieee80211_vif *vif, 3341e705c121SKalle Valo struct ieee80211_sta *sta) 3342e705c121SKalle Valo { 3343e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3344e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 334579faae3aSGregory Greenman unsigned int link_id; 3346e705c121SKalle Valo 3347e705c121SKalle Valo /* 3348e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 3349e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 3350e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 3351e705c121SKalle Valo * be able to find the station this way, and we don't rely 3352e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 3353e705c121SKalle Valo * callback deleted the station. 335479faae3aSGregory Greenman * Since there's mvm->mutex here, no need to have RCU lock for 335579faae3aSGregory Greenman * mvm_sta->link access. 3356e705c121SKalle Valo */ 3357e705c121SKalle Valo mutex_lock(&mvm->mutex); 335879faae3aSGregory Greenman for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) { 335979faae3aSGregory Greenman struct iwl_mvm_link_sta *link_sta; 336079faae3aSGregory Greenman u32 sta_id; 3361e705c121SKalle Valo 336279faae3aSGregory Greenman if (!mvm_sta->link[link_id]) 336379faae3aSGregory Greenman continue; 336479faae3aSGregory Greenman 336579faae3aSGregory Greenman link_sta = rcu_dereference_protected(mvm_sta->link[link_id], 336679faae3aSGregory Greenman lockdep_is_held(&mvm->mutex)); 336779faae3aSGregory Greenman sta_id = link_sta->sta_id; 3368b8a85a1dSJohannes Berg if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[sta_id])) { 33693e75668bSJohannes Berg RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], 337079faae3aSGregory Greenman ERR_PTR(-ENOENT)); 3371b8a85a1dSJohannes Berg RCU_INIT_POINTER(mvm->fw_id_to_link_sta[sta_id], NULL); 3372b8a85a1dSJohannes Berg } 337379faae3aSGregory Greenman } 3374e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3375e705c121SKalle Valo } 3376e705c121SKalle Valo 3377e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 3378e705c121SKalle Valo const u8 *bssid) 3379e705c121SKalle Valo { 3380b0ffe455SJohannes Berg int i; 3381b0ffe455SJohannes Berg 3382b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3383b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 3384b0ffe455SJohannes Berg 3385b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 3386b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 3387b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 3388b0ffe455SJohannes Berg } 3389b0ffe455SJohannes Berg 3390e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 3391e705c121SKalle Valo return; 3392e705c121SKalle Valo 3393c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 3394cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3395cee5a882SAvri Altman return; 3396cee5a882SAvri Altman } 3397cee5a882SAvri Altman 339811dee0b4SEmmanuel Grumbach if (!vif->p2p && 339911dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 3400e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3401e705c121SKalle Valo return; 3402e705c121SKalle Valo } 3403e705c121SKalle Valo 3404b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 3405b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 3406b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3407b0ffe455SJohannes Berg return; 3408b0ffe455SJohannes Berg } 3409b0ffe455SJohannes Berg } 3410b0ffe455SJohannes Berg 3411e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 3412e705c121SKalle Valo } 3413e705c121SKalle Valo 34141e8f1329SGolan Ben-Ami static void 34151e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 34161e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 34171e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 34181e8f1329SGolan Ben-Ami { 34191e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 34201e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 34211e8f1329SGolan Ben-Ami 34226c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 34236c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 34246c042d75SSara Sharon if (!trig) 34251e8f1329SGolan Ben-Ami return; 34261e8f1329SGolan Ben-Ami 34271e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 34281e8f1329SGolan Ben-Ami 34291e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 34301e8f1329SGolan Ben-Ami return; 34311e8f1329SGolan Ben-Ami 34321e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 34331e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 34341e8f1329SGolan Ben-Ami return; 34351e8f1329SGolan Ben-Ami 34367174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 34371e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 34381e8f1329SGolan Ben-Ami peer_addr, action); 34391e8f1329SGolan Ben-Ami } 34401e8f1329SGolan Ben-Ami 34414f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data { 34424f58121dSIlan Peer bool tolerated; 34434f58121dSIlan Peer }; 34444f58121dSIlan Peer 34454f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 34464f58121dSIlan Peer struct cfg80211_bss *bss, 34474f58121dSIlan Peer void *_data) 34484f58121dSIlan Peer { 34494f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 34506c608cd6SJohannes Berg const struct cfg80211_bss_ies *ies; 34514f58121dSIlan Peer const struct element *elem; 34524f58121dSIlan Peer 34536c608cd6SJohannes Berg rcu_read_lock(); 34546c608cd6SJohannes Berg ies = rcu_dereference(bss->ies); 34556c608cd6SJohannes Berg elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 34566c608cd6SJohannes Berg ies->len); 34574f58121dSIlan Peer 34584f58121dSIlan Peer if (!elem || elem->datalen < 10 || 34594f58121dSIlan Peer !(elem->data[10] & 34604f58121dSIlan Peer WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 34614f58121dSIlan Peer data->tolerated = false; 34624f58121dSIlan Peer } 34636c608cd6SJohannes Berg rcu_read_unlock(); 34644f58121dSIlan Peer } 34654f58121dSIlan Peer 34666e1b5956SJohannes Berg static void 34676e1b5956SJohannes Berg iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 34686e1b5956SJohannes Berg struct ieee80211_vif *vif, 34696e1b5956SJohannes Berg unsigned int link_id, 34706e1b5956SJohannes Berg struct ieee80211_bss_conf *link_conf) 34714f58121dSIlan Peer { 34724f58121dSIlan Peer struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 34734f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 34744f58121dSIlan Peer .tolerated = true, 34754f58121dSIlan Peer }; 34764f58121dSIlan Peer 34776092077aSJohannes Berg if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan || 34786e1b5956SJohannes Berg !mvmvif->link[link_id])) 34796e1b5956SJohannes Berg return; 34806e1b5956SJohannes Berg 34816092077aSJohannes Berg if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) { 34826e1b5956SJohannes Berg mvmvif->link[link_id]->he_ru_2mhz_block = false; 34834f58121dSIlan Peer return; 34844f58121dSIlan Peer } 34854f58121dSIlan Peer 34866092077aSJohannes Berg cfg80211_bss_iter(hw->wiphy, &link_conf->chanreq.oper, 34874f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru_iter, 34884f58121dSIlan Peer &iter_data); 34894f58121dSIlan Peer 34904f58121dSIlan Peer /* 34914f58121dSIlan Peer * If there is at least one AP on radar channel that cannot 34924f58121dSIlan Peer * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 34934f58121dSIlan Peer */ 34946e1b5956SJohannes Berg mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated; 34954f58121dSIlan Peer } 34964f58121dSIlan Peer 3497f7d6ef33SJohannes Berg static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3498f7d6ef33SJohannes Berg struct ieee80211_vif *vif) 3499f7d6ef33SJohannes Berg { 3500f7d6ef33SJohannes Berg struct ieee80211_supported_band *sband; 3501f7d6ef33SJohannes Berg const struct ieee80211_sta_he_cap *he_cap; 3502f7d6ef33SJohannes Berg 3503f7d6ef33SJohannes Berg if (vif->type != NL80211_IFTYPE_STATION) 3504f7d6ef33SJohannes Berg return; 3505f7d6ef33SJohannes Berg 3506f7d6ef33SJohannes Berg if (!mvm->cca_40mhz_workaround) 3507f7d6ef33SJohannes Berg return; 3508f7d6ef33SJohannes Berg 3509f7d6ef33SJohannes Berg /* decrement and check that we reached zero */ 3510f7d6ef33SJohannes Berg mvm->cca_40mhz_workaround--; 3511f7d6ef33SJohannes Berg if (mvm->cca_40mhz_workaround) 3512f7d6ef33SJohannes Berg return; 3513f7d6ef33SJohannes Berg 3514f7d6ef33SJohannes Berg sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3515f7d6ef33SJohannes Berg 3516f7d6ef33SJohannes Berg sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3517f7d6ef33SJohannes Berg 35181ec7291eSJohannes Berg he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif); 3519f7d6ef33SJohannes Berg 3520f7d6ef33SJohannes Berg if (he_cap) { 3521f7d6ef33SJohannes Berg /* we know that ours is writable */ 35220301bcd5SBjoern A. Zeeb struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; 3523f7d6ef33SJohannes Berg 3524f7d6ef33SJohannes Berg he->he_cap_elem.phy_cap_info[0] |= 3525f7d6ef33SJohannes Berg IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3526f7d6ef33SJohannes Berg } 3527f7d6ef33SJohannes Berg } 3528f7d6ef33SJohannes Berg 35296d19a5ebSEmmanuel Grumbach static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 35306d19a5ebSEmmanuel Grumbach struct ieee80211_vif *vif, 35316d19a5ebSEmmanuel Grumbach struct iwl_mvm_sta *mvm_sta) 35326d19a5ebSEmmanuel Grumbach { 35336d19a5ebSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI) 35346d19a5ebSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 35356d19a5ebSEmmanuel Grumbach struct iwl_mei_conn_info conn_info = { 3536f276e20bSJohannes Berg .ssid_len = vif->cfg.ssid_len, 35376d19a5ebSEmmanuel Grumbach }; 35386d19a5ebSEmmanuel Grumbach 35396d19a5ebSEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 35406d19a5ebSEmmanuel Grumbach return; 35416d19a5ebSEmmanuel Grumbach 35426d19a5ebSEmmanuel Grumbach if (!mvm->mei_registered) 35436d19a5ebSEmmanuel Grumbach return; 35446d19a5ebSEmmanuel Grumbach 35456c07b73eSJohannes Berg /* FIXME: MEI needs to be updated for MLO */ 35466092077aSJohannes Berg if (!vif->bss_conf.chanreq.oper.chan) 35476c07b73eSJohannes Berg return; 35486c07b73eSJohannes Berg 35496092077aSJohannes Berg conn_info.channel = vif->bss_conf.chanreq.oper.chan->hw_value; 35506c07b73eSJohannes Berg 35516d19a5ebSEmmanuel Grumbach switch (mvm_sta->pairwise_cipher) { 3552e5d3a64eSAvraham Stern case WLAN_CIPHER_SUITE_TKIP: 3553e5d3a64eSAvraham Stern conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP; 3554e5d3a64eSAvraham Stern break; 35556d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_CCMP: 35566d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 35576d19a5ebSEmmanuel Grumbach break; 35586d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP: 35596d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 35606d19a5ebSEmmanuel Grumbach break; 35616d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP_256: 35626d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 35636d19a5ebSEmmanuel Grumbach break; 35646d19a5ebSEmmanuel Grumbach case 0: 35656d19a5ebSEmmanuel Grumbach /* open profile */ 35666d19a5ebSEmmanuel Grumbach break; 35676d19a5ebSEmmanuel Grumbach default: 35686d19a5ebSEmmanuel Grumbach /* cipher not supported, don't send anything to iwlmei */ 35696d19a5ebSEmmanuel Grumbach return; 35706d19a5ebSEmmanuel Grumbach } 35716d19a5ebSEmmanuel Grumbach 35726d19a5ebSEmmanuel Grumbach switch (mvmvif->rekey_data.akm) { 35736d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_SAE & 0xff: 35746d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 35756d19a5ebSEmmanuel Grumbach break; 35766d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_PSK & 0xff: 35776d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 35786d19a5ebSEmmanuel Grumbach break; 35796d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_8021X & 0xff: 35806d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 35816d19a5ebSEmmanuel Grumbach break; 35826d19a5ebSEmmanuel Grumbach case 0: 35836d19a5ebSEmmanuel Grumbach /* open profile */ 35846d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 35856d19a5ebSEmmanuel Grumbach break; 35866d19a5ebSEmmanuel Grumbach default: 35876d19a5ebSEmmanuel Grumbach /* auth method / AKM not supported */ 35886d19a5ebSEmmanuel Grumbach /* TODO: All the FT vesions of these? */ 35896d19a5ebSEmmanuel Grumbach return; 35906d19a5ebSEmmanuel Grumbach } 35916d19a5ebSEmmanuel Grumbach 3592f276e20bSJohannes Berg memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 35936d19a5ebSEmmanuel Grumbach memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 35946d19a5ebSEmmanuel Grumbach 35956d19a5ebSEmmanuel Grumbach /* TODO: add support for collocated AP data */ 35966d19a5ebSEmmanuel Grumbach iwl_mei_host_associated(&conn_info, NULL); 35976d19a5ebSEmmanuel Grumbach #endif 35986d19a5ebSEmmanuel Grumbach } 35996d19a5ebSEmmanuel Grumbach 360087f7e243SMiri Korenblit static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm, 360187f7e243SMiri Korenblit struct ieee80211_vif *vif, 360287f7e243SMiri Korenblit bool force_assoc_off) 360387f7e243SMiri Korenblit { 360487f7e243SMiri Korenblit return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL); 360587f7e243SMiri Korenblit } 360687f7e243SMiri Korenblit 3607e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3608e705c121SKalle Valo struct ieee80211_vif *vif, 3609e705c121SKalle Valo struct ieee80211_sta *sta, 3610e705c121SKalle Valo enum ieee80211_sta_state old_state, 3611e705c121SKalle Valo enum ieee80211_sta_state new_state) 3612e705c121SKalle Valo { 3613a2906ea6SJohannes Berg static const struct iwl_mvm_sta_state_ops callbacks = { 361487f7e243SMiri Korenblit .add_sta = iwl_mvm_add_sta, 361587f7e243SMiri Korenblit .update_sta = iwl_mvm_update_sta, 361687f7e243SMiri Korenblit .rm_sta = iwl_mvm_rm_sta, 361787f7e243SMiri Korenblit .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper, 361887f7e243SMiri Korenblit }; 361987f7e243SMiri Korenblit 362087f7e243SMiri Korenblit return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state, 362187f7e243SMiri Korenblit &callbacks); 362287f7e243SMiri Korenblit } 362387f7e243SMiri Korenblit 362457974a55SGregory Greenman /* FIXME: temporary making two assumptions in all sta handling functions: 362557974a55SGregory Greenman * (1) when setting sta state, the link exists and protected 362657974a55SGregory Greenman * (2) if a link is valid in sta then it's valid in vif (can 362757974a55SGregory Greenman * use same index in the link array) 362857974a55SGregory Greenman */ 3629f53be9c4SGregory Greenman static void iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm, 3630f53be9c4SGregory Greenman struct ieee80211_vif *vif, 363115d41834SJohannes Berg struct ieee80211_sta *sta) 3632f53be9c4SGregory Greenman { 3633f53be9c4SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3634f53be9c4SGregory Greenman unsigned int link_id; 363557974a55SGregory Greenman 3636f53be9c4SGregory Greenman for_each_mvm_vif_valid_link(mvmvif, link_id) { 3637f53be9c4SGregory Greenman struct ieee80211_bss_conf *conf = 3638a705a782SJohannes Berg link_conf_dereference_check(vif, link_id); 3639f53be9c4SGregory Greenman struct ieee80211_link_sta *link_sta = 3640a705a782SJohannes Berg link_sta_dereference_check(sta, link_id); 3641f53be9c4SGregory Greenman 3642f53be9c4SGregory Greenman if (!conf || !link_sta || !mvmvif->link[link_id]->phy_ctxt) 3643f53be9c4SGregory Greenman continue; 3644f53be9c4SGregory Greenman 3645c45217bdSJohannes Berg iwl_mvm_rs_rate_init(mvm, vif, sta, conf, link_sta, 364615d41834SJohannes Berg mvmvif->link[link_id]->phy_ctxt->channel->band); 3647f53be9c4SGregory Greenman } 3648f53be9c4SGregory Greenman } 364957974a55SGregory Greenman 365057974a55SGregory Greenman #define IWL_MVM_MIN_BEACON_INTERVAL_TU 16 365157974a55SGregory Greenman 365257974a55SGregory Greenman static bool iwl_mvm_vif_conf_from_sta(struct iwl_mvm *mvm, 365357974a55SGregory Greenman struct ieee80211_vif *vif, 365457974a55SGregory Greenman struct ieee80211_sta *sta) 365557974a55SGregory Greenman { 3656207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3657207be64fSMiri Korenblit unsigned int link_id; 365857974a55SGregory Greenman 365957974a55SGregory Greenman /* Beacon interval check - firmware will crash if the beacon 366057974a55SGregory Greenman * interval is less than 16. We can't avoid connecting at all, 366157974a55SGregory Greenman * so refuse the station state change, this will cause mac80211 366257974a55SGregory Greenman * to abandon attempts to connect to this AP, and eventually 366357974a55SGregory Greenman * wpa_s will blocklist the AP... 366457974a55SGregory Greenman */ 366557974a55SGregory Greenman 3666207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 366757974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3668207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 366957974a55SGregory Greenman 3670207be64fSMiri Korenblit if (!link_conf) 367157974a55SGregory Greenman continue; 367257974a55SGregory Greenman 367357974a55SGregory Greenman if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) { 367457974a55SGregory Greenman IWL_ERR(mvm, 367557974a55SGregory Greenman "Beacon interval %d for AP %pM is too small\n", 367657974a55SGregory Greenman link_conf->beacon_int, link_sta->addr); 367757974a55SGregory Greenman return false; 367857974a55SGregory Greenman } 367957974a55SGregory Greenman 368057974a55SGregory Greenman link_conf->he_support = link_sta->he_cap.has_he; 368157974a55SGregory Greenman } 368257974a55SGregory Greenman 368357974a55SGregory Greenman return true; 368457974a55SGregory Greenman } 368557974a55SGregory Greenman 368657974a55SGregory Greenman static void iwl_mvm_vif_set_he_support(struct ieee80211_hw *hw, 368757974a55SGregory Greenman struct ieee80211_vif *vif, 368857974a55SGregory Greenman struct ieee80211_sta *sta, 368957974a55SGregory Greenman bool is_sta) 369057974a55SGregory Greenman { 369157974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3692207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3693207be64fSMiri Korenblit unsigned int link_id; 369457974a55SGregory Greenman 3695207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 369657974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3697207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 369857974a55SGregory Greenman 3699207be64fSMiri Korenblit if (!link_conf || !mvmvif->link[link_id]) 370057974a55SGregory Greenman continue; 370157974a55SGregory Greenman 370257974a55SGregory Greenman link_conf->he_support = link_sta->he_cap.has_he; 370357974a55SGregory Greenman 370457974a55SGregory Greenman if (is_sta) { 3705207be64fSMiri Korenblit mvmvif->link[link_id]->he_ru_2mhz_block = false; 370657974a55SGregory Greenman if (link_sta->he_cap.has_he) 3707207be64fSMiri Korenblit iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif, 3708207be64fSMiri Korenblit link_id, 37096e1b5956SJohannes Berg link_conf); 371057974a55SGregory Greenman } 371157974a55SGregory Greenman } 371257974a55SGregory Greenman } 371357974a55SGregory Greenman 371457974a55SGregory Greenman static int 371557974a55SGregory Greenman iwl_mvm_sta_state_notexist_to_none(struct iwl_mvm *mvm, 371657974a55SGregory Greenman struct ieee80211_vif *vif, 371757974a55SGregory Greenman struct ieee80211_sta *sta, 3718a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 371957974a55SGregory Greenman { 37200c9a8f90SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3721207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 372257974a55SGregory Greenman unsigned int i; 372357974a55SGregory Greenman int ret; 372457974a55SGregory Greenman 372557974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 372657974a55SGregory Greenman 372757974a55SGregory Greenman if (vif->type == NL80211_IFTYPE_STATION && 372857974a55SGregory Greenman !iwl_mvm_vif_conf_from_sta(mvm, vif, sta)) 372957974a55SGregory Greenman return -EINVAL; 373057974a55SGregory Greenman 373157974a55SGregory Greenman if (sta->tdls && 373257974a55SGregory Greenman (vif->p2p || 373357974a55SGregory Greenman iwl_mvm_tdls_sta_count(mvm, NULL) == IWL_MVM_TDLS_STA_COUNT || 373457974a55SGregory Greenman iwl_mvm_phy_ctx_count(mvm) > 1)) { 373557974a55SGregory Greenman IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 373657974a55SGregory Greenman return -EBUSY; 373757974a55SGregory Greenman } 373857974a55SGregory Greenman 373957974a55SGregory Greenman ret = callbacks->add_sta(mvm, vif, sta); 374057974a55SGregory Greenman if (sta->tdls && ret == 0) { 374157974a55SGregory Greenman iwl_mvm_recalc_tdls_state(mvm, vif, true); 374257974a55SGregory Greenman iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 374357974a55SGregory Greenman NL80211_TDLS_SETUP); 374457974a55SGregory Greenman } 374557974a55SGregory Greenman 3746b7198383SEmmanuel Grumbach if (ret) 3747b7198383SEmmanuel Grumbach return ret; 3748b7198383SEmmanuel Grumbach 3749207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, i) 375057974a55SGregory Greenman link_sta->agg.max_rc_amsdu_len = 1; 3751207be64fSMiri Korenblit 375257974a55SGregory Greenman ieee80211_sta_recalc_aggregates(sta); 375357974a55SGregory Greenman 37540c9a8f90SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 37550c9a8f90SJohannes Berg mvmvif->ap_sta = sta; 37560c9a8f90SJohannes Berg 3757d3b2c6c6SJohannes Berg /* 3758d3b2c6c6SJohannes Berg * Initialize the rates here already - this really tells 3759d3b2c6c6SJohannes Berg * the firmware only what the supported legacy rates are 3760d3b2c6c6SJohannes Berg * (may be) since it's initialized already from what the 3761d3b2c6c6SJohannes Berg * AP advertised in the beacon/probe response. This will 3762d3b2c6c6SJohannes Berg * allow the firmware to send auth/assoc frames with one 3763d3b2c6c6SJohannes Berg * of the supported rates already, rather than having to 3764d3b2c6c6SJohannes Berg * use a mandatory rate. 3765d3b2c6c6SJohannes Berg * If we're the AP, we'll just assume mandatory rates at 3766d3b2c6c6SJohannes Berg * this point, but we know nothing about the STA anyway. 3767d3b2c6c6SJohannes Berg */ 3768d3b2c6c6SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 3769d3b2c6c6SJohannes Berg 377057974a55SGregory Greenman return 0; 377157974a55SGregory Greenman } 377257974a55SGregory Greenman 377357974a55SGregory Greenman static int 377457974a55SGregory Greenman iwl_mvm_sta_state_auth_to_assoc(struct ieee80211_hw *hw, 377557974a55SGregory Greenman struct iwl_mvm *mvm, 377657974a55SGregory Greenman struct ieee80211_vif *vif, 377757974a55SGregory Greenman struct ieee80211_sta *sta, 3778a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 377957974a55SGregory Greenman { 378057974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 378157974a55SGregory Greenman struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3782207be64fSMiri Korenblit struct ieee80211_link_sta *link_sta; 3783207be64fSMiri Korenblit unsigned int link_id; 378457974a55SGregory Greenman 378557974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 378657974a55SGregory Greenman 378757974a55SGregory Greenman if (vif->type == NL80211_IFTYPE_AP) { 378857974a55SGregory Greenman iwl_mvm_vif_set_he_support(hw, vif, sta, false); 378957974a55SGregory Greenman mvmvif->ap_assoc_sta_count++; 379057974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 379157974a55SGregory Greenman 379257974a55SGregory Greenman /* since the below is not for MLD API, it's ok to use 379357974a55SGregory Greenman * the default bss_conf 379457974a55SGregory Greenman */ 379557974a55SGregory Greenman if (!mvm->mld_api_is_used && 379683f57c93SJohannes Berg (vif->bss_conf.he_support && 379783f57c93SJohannes Berg !iwlwifi_mod_params.disable_11ax)) 379857974a55SGregory Greenman iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id); 379957974a55SGregory Greenman } else if (vif->type == NL80211_IFTYPE_STATION) { 380057974a55SGregory Greenman iwl_mvm_vif_set_he_support(hw, vif, sta, true); 380157974a55SGregory Greenman 380257974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 380357974a55SGregory Greenman 380457974a55SGregory Greenman if (!mvm->mld_api_is_used) 380557974a55SGregory Greenman goto out; 380657974a55SGregory Greenman 3807207be64fSMiri Korenblit for_each_sta_active_link(vif, sta, link_sta, link_id) { 380857974a55SGregory Greenman struct ieee80211_bss_conf *link_conf = 3809207be64fSMiri Korenblit link_conf_dereference_protected(vif, link_id); 381057974a55SGregory Greenman 381157974a55SGregory Greenman if (WARN_ON(!link_conf)) 381257974a55SGregory Greenman return -EINVAL; 3813207be64fSMiri Korenblit if (!mvmvif->link[link_id]) 3814f14ad95aSJohannes Berg continue; 381557974a55SGregory Greenman 381657974a55SGregory Greenman iwl_mvm_link_changed(mvm, vif, link_conf, 381757974a55SGregory Greenman LINK_CONTEXT_MODIFY_ALL & 381857974a55SGregory Greenman ~LINK_CONTEXT_MODIFY_ACTIVE, 381957974a55SGregory Greenman true); 382057974a55SGregory Greenman } 382157974a55SGregory Greenman } 382257974a55SGregory Greenman 382357974a55SGregory Greenman out: 382415d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 382557974a55SGregory Greenman 382657974a55SGregory Greenman return callbacks->update_sta(mvm, vif, sta); 382757974a55SGregory Greenman } 382857974a55SGregory Greenman 382957974a55SGregory Greenman static int 383057974a55SGregory Greenman iwl_mvm_sta_state_assoc_to_authorized(struct iwl_mvm *mvm, 383157974a55SGregory Greenman struct ieee80211_vif *vif, 383257974a55SGregory Greenman struct ieee80211_sta *sta, 3833a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 383457974a55SGregory Greenman { 383557974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 383657974a55SGregory Greenman struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 383757974a55SGregory Greenman 383857974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 383957974a55SGregory Greenman 384057974a55SGregory Greenman /* we don't support TDLS during DCM */ 384157974a55SGregory Greenman if (iwl_mvm_phy_ctx_count(mvm) > 1) 384257974a55SGregory Greenman iwl_mvm_teardown_tdls_peers(mvm); 384357974a55SGregory Greenman 384457974a55SGregory Greenman if (sta->tdls) { 384557974a55SGregory Greenman iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 384657974a55SGregory Greenman NL80211_TDLS_ENABLE_LINK); 384757974a55SGregory Greenman } else { 384857974a55SGregory Greenman /* enable beacon filtering */ 384987f5b5f2SJohannes Berg WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif)); 385057974a55SGregory Greenman 385157974a55SGregory Greenman mvmvif->authorized = 1; 385257974a55SGregory Greenman 385357974a55SGregory Greenman callbacks->mac_ctxt_changed(mvm, vif, false); 385457974a55SGregory Greenman iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 3855b9be67fbSIlan Peer 3856b9be67fbSIlan Peer /* when client is authorized (AP station marked as such), 3857b9be67fbSIlan Peer * try to enable more links 3858b9be67fbSIlan Peer */ 3859b9be67fbSIlan Peer if (vif->type == NL80211_IFTYPE_STATION && 3860b9be67fbSIlan Peer !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 3861b9be67fbSIlan Peer iwl_mvm_mld_select_links(mvm, vif, false); 386257974a55SGregory Greenman } 386357974a55SGregory Greenman 386415d41834SJohannes Berg mvm_sta->authorized = true; 386515d41834SJohannes Berg 38665a86dcb4SAvraham Stern /* MFP is set by default before the station is authorized. 38675a86dcb4SAvraham Stern * Clear it here in case it's not used. 38685a86dcb4SAvraham Stern */ 38690fcdf55fSEmmanuel Grumbach if (!sta->mfp) { 38700fcdf55fSEmmanuel Grumbach int ret = callbacks->update_sta(mvm, vif, sta); 38710fcdf55fSEmmanuel Grumbach 38720fcdf55fSEmmanuel Grumbach if (ret) 38730fcdf55fSEmmanuel Grumbach return ret; 38740fcdf55fSEmmanuel Grumbach } 38750fcdf55fSEmmanuel Grumbach 38760fcdf55fSEmmanuel Grumbach iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 38775a86dcb4SAvraham Stern 387857974a55SGregory Greenman return 0; 387957974a55SGregory Greenman } 388057974a55SGregory Greenman 388157974a55SGregory Greenman static int 388257974a55SGregory Greenman iwl_mvm_sta_state_authorized_to_assoc(struct iwl_mvm *mvm, 388357974a55SGregory Greenman struct ieee80211_vif *vif, 388457974a55SGregory Greenman struct ieee80211_sta *sta, 3885a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 388657974a55SGregory Greenman { 388757974a55SGregory Greenman struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 388815d41834SJohannes Berg struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 388957974a55SGregory Greenman 389057974a55SGregory Greenman lockdep_assert_held(&mvm->mutex); 389157974a55SGregory Greenman 389215d41834SJohannes Berg mvmsta->authorized = false; 389315d41834SJohannes Berg 389457974a55SGregory Greenman /* once we move into assoc state, need to update rate scale to 389557974a55SGregory Greenman * disable using wide bandwidth 389657974a55SGregory Greenman */ 389715d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 389857974a55SGregory Greenman 389957974a55SGregory Greenman if (!sta->tdls) { 390057974a55SGregory Greenman /* Set this but don't call iwl_mvm_mac_ctxt_changed() 390157974a55SGregory Greenman * yet to avoid sending high prio again for a little 390257974a55SGregory Greenman * time. 390357974a55SGregory Greenman */ 390457974a55SGregory Greenman mvmvif->authorized = 0; 390557974a55SGregory Greenman 390657974a55SGregory Greenman /* disable beacon filtering */ 390787f5b5f2SJohannes Berg iwl_mvm_disable_beacon_filter(mvm, vif); 390857974a55SGregory Greenman } 390957974a55SGregory Greenman 391057974a55SGregory Greenman return 0; 391157974a55SGregory Greenman } 391257974a55SGregory Greenman 391387f7e243SMiri Korenblit /* Common part for MLD and non-MLD modes */ 391487f7e243SMiri Korenblit int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw, 391587f7e243SMiri Korenblit struct ieee80211_vif *vif, 391687f7e243SMiri Korenblit struct ieee80211_sta *sta, 391787f7e243SMiri Korenblit enum ieee80211_sta_state old_state, 391887f7e243SMiri Korenblit enum ieee80211_sta_state new_state, 3919a2906ea6SJohannes Berg const struct iwl_mvm_sta_state_ops *callbacks) 392087f7e243SMiri Korenblit { 3921e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3922e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 39236ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3924de107600SJohannes Berg struct ieee80211_link_sta *link_sta; 392557974a55SGregory Greenman unsigned int link_id; 3926e705c121SKalle Valo int ret; 3927e705c121SKalle Valo 3928e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 3929e705c121SKalle Valo sta->addr, old_state, new_state); 3930e705c121SKalle Valo 393124afba76SLiad Kaufman /* 393224afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 393324afba76SLiad Kaufman * 393424afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 393524afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 393624afba76SLiad Kaufman * the queues. 393724afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 393824afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 393924afba76SLiad Kaufman * of. 394024afba76SLiad Kaufman * 394124afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 394224afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 394324afba76SLiad Kaufman */ 394424afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 3945c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 394624afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 394724afba76SLiad Kaufman 394824afba76SLiad Kaufman /* 394924afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 395024afba76SLiad Kaufman * worker will already remove it if it was on 395124afba76SLiad Kaufman */ 3952f7d6ef33SJohannes Berg 3953f7d6ef33SJohannes Berg /* 3954f7d6ef33SJohannes Berg * Additionally, reset the 40 MHz capability if we disconnected 3955f7d6ef33SJohannes Berg * from the AP now. 3956f7d6ef33SJohannes Berg */ 3957f7d6ef33SJohannes Berg iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 3958783336b0SJohannes Berg 3959783336b0SJohannes Berg /* Also free dup data just in case any assertions below fail */ 3960783336b0SJohannes Berg kfree(mvm_sta->dup_data); 396124afba76SLiad Kaufman } 396224afba76SLiad Kaufman 3963e705c121SKalle Valo mutex_lock(&mvm->mutex); 396457974a55SGregory Greenman 3965828c79d9SEmmanuel Grumbach /* this would be a mac80211 bug ... but don't crash, unless we had a 3966828c79d9SEmmanuel Grumbach * firmware crash while we were activating a link, in which case it is 3967828c79d9SEmmanuel Grumbach * legit to have phy_ctxt = NULL. Don't bother not to WARN if we are in 3968828c79d9SEmmanuel Grumbach * recovery flow since we spit tons of error messages anyway. 3969828c79d9SEmmanuel Grumbach */ 3970de107600SJohannes Berg for_each_sta_active_link(vif, sta, link_sta, link_id) { 39713d6d21b2SJohannes Berg if (WARN_ON_ONCE(!mvmvif->link[link_id] || 39723d6d21b2SJohannes Berg !mvmvif->link[link_id]->phy_ctxt)) { 397357974a55SGregory Greenman mutex_unlock(&mvm->mutex); 397457974a55SGregory Greenman return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 397557974a55SGregory Greenman &mvm->status) ? 0 : -EINVAL; 397657974a55SGregory Greenman } 397757974a55SGregory Greenman } 397857974a55SGregory Greenman 39796ea29ce5SJohannes Berg /* track whether or not the station is associated */ 3980d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 39816ea29ce5SJohannes Berg 3982e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3983e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 398457974a55SGregory Greenman ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta, 398557974a55SGregory Greenman callbacks); 398657974a55SGregory Greenman if (ret < 0) 3987e705c121SKalle Valo goto out_unlock; 3988e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3989e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 3990e705c121SKalle Valo /* 3991e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 3992e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 3993e705c121SKalle Valo */ 3994e705c121SKalle Valo mvm->last_ebs_successful = true; 3995e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 3996e705c121SKalle Valo ret = 0; 3997e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3998e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 399957974a55SGregory Greenman ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta, 400057974a55SGregory Greenman callbacks); 4001e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 4002e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 400357974a55SGregory Greenman ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta, 400457974a55SGregory Greenman callbacks); 4005e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 4006e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 400757974a55SGregory Greenman ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta, 400857974a55SGregory Greenman callbacks); 4009e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 4010e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 40118be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 40128be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 401387f7e243SMiri Korenblit callbacks->mac_ctxt_changed(mvm, vif, false); 4014d5d8ee52SEmmanuel Grumbach } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 4015cf7a7457SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 4016e705c121SKalle Valo ret = 0; 4017e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 4018e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 4019e705c121SKalle Valo ret = 0; 4020e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 4021e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 40220c9a8f90SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) { 4023d5d8ee52SEmmanuel Grumbach iwl_mvm_stop_session_protection(mvm, vif); 40240c9a8f90SJohannes Berg mvmvif->ap_sta = NULL; 40250c9a8f90SJohannes Berg } 402687f7e243SMiri Korenblit ret = callbacks->rm_sta(mvm, vif, sta); 40271e8f1329SGolan Ben-Ami if (sta->tdls) { 4028e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 40291e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 40301e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 40311e8f1329SGolan Ben-Ami } 403234a880d8SLiad Kaufman 403344135b7cSIlan Peer if (unlikely(ret && 403444135b7cSIlan Peer test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 403544135b7cSIlan Peer &mvm->status))) 403644135b7cSIlan Peer ret = 0; 4037e705c121SKalle Valo } else { 4038e705c121SKalle Valo ret = -EIO; 4039e705c121SKalle Valo } 4040e705c121SKalle Valo out_unlock: 4041e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4042e705c121SKalle Valo 4043e705c121SKalle Valo if (sta->tdls && ret == 0) { 4044e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 4045e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 4046e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4047e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 4048e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 4049e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 4050e705c121SKalle Valo } 4051e705c121SKalle Valo 4052e705c121SKalle Valo return ret; 4053e705c121SKalle Valo } 4054e705c121SKalle Valo 4055cbce62a3SMiri Korenblit int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 4056e705c121SKalle Valo { 4057e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4058e705c121SKalle Valo 4059e705c121SKalle Valo mvm->rts_threshold = value; 4060e705c121SKalle Valo 4061e705c121SKalle Valo return 0; 4062e705c121SKalle Valo } 4063e705c121SKalle Valo 4064cbce62a3SMiri Korenblit void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4065e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 4066e705c121SKalle Valo { 4067e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4068dcfe3b10SJohannes Berg 4069dcfe3b10SJohannes Berg if (changed & (IEEE80211_RC_BW_CHANGED | 4070dcfe3b10SJohannes Berg IEEE80211_RC_SUPP_RATES_CHANGED | 4071dcfe3b10SJohannes Berg IEEE80211_RC_NSS_CHANGED)) 407215d41834SJohannes Berg iwl_mvm_rs_rate_init_all_links(mvm, vif, sta); 4073e705c121SKalle Valo 4074e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 4075e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 4076e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 4077e705c121SKalle Valo } 4078e705c121SKalle Valo 4079e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 4080b3e2130bSJohannes Berg struct ieee80211_vif *vif, 4081b3e2130bSJohannes Berg unsigned int link_id, u16 ac, 4082e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 4083e705c121SKalle Valo { 4084e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4085e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4086e705c121SKalle Valo 4087650cadb7SGregory Greenman mvmvif->deflink.queue_params[ac] = *params; 4088e705c121SKalle Valo 4089e705c121SKalle Valo /* 4090e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 4091e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 4092e705c121SKalle Valo */ 4093e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 4094e705c121SKalle Valo int ret; 4095e705c121SKalle Valo 4096e705c121SKalle Valo mutex_lock(&mvm->mutex); 4097e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4098e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4099e705c121SKalle Valo return ret; 4100e705c121SKalle Valo } 4101e705c121SKalle Valo return 0; 4102e705c121SKalle Valo } 4103e705c121SKalle Valo 4104cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 4105d4e36e55SIlan Peer struct ieee80211_vif *vif, 410615fae341SJohannes Berg struct ieee80211_prep_tx_info *info) 4107e705c121SKalle Valo { 4108e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4109d4e36e55SIlan Peer 4110e705c121SKalle Valo mutex_lock(&mvm->mutex); 411123673041SMiri Korenblit iwl_mvm_protect_assoc(mvm, vif, info->duration, info->link_id); 4112e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4113e705c121SKalle Valo } 4114e705c121SKalle Valo 4115cbce62a3SMiri Korenblit void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 41166b1259d1SJohannes Berg struct ieee80211_vif *vif, 41176b1259d1SJohannes Berg struct ieee80211_prep_tx_info *info) 41186b1259d1SJohannes Berg { 41196b1259d1SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 41206b1259d1SJohannes Berg 41216b1259d1SJohannes Berg /* for successful cases (auth/assoc), don't cancel session protection */ 41226b1259d1SJohannes Berg if (info->success) 41236b1259d1SJohannes Berg return; 41246b1259d1SJohannes Berg 41256b1259d1SJohannes Berg mutex_lock(&mvm->mutex); 41266b1259d1SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 41276b1259d1SJohannes Berg mutex_unlock(&mvm->mutex); 41286b1259d1SJohannes Berg } 41296b1259d1SJohannes Berg 4130cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 4131e705c121SKalle Valo struct ieee80211_vif *vif, 4132e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 4133e705c121SKalle Valo struct ieee80211_scan_ies *ies) 4134e705c121SKalle Valo { 4135e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4136e705c121SKalle Valo 4137e705c121SKalle Valo int ret; 4138e705c121SKalle Valo 4139e705c121SKalle Valo mutex_lock(&mvm->mutex); 4140e705c121SKalle Valo 4141f276e20bSJohannes Berg if (!vif->cfg.idle) { 4142e705c121SKalle Valo ret = -EBUSY; 4143e705c121SKalle Valo goto out; 4144e705c121SKalle Valo } 4145e705c121SKalle Valo 4146e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 4147e705c121SKalle Valo 4148e705c121SKalle Valo out: 4149e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4150e705c121SKalle Valo return ret; 4151e705c121SKalle Valo } 4152e705c121SKalle Valo 4153cbce62a3SMiri Korenblit int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 4154e705c121SKalle Valo struct ieee80211_vif *vif) 4155e705c121SKalle Valo { 4156e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4157e705c121SKalle Valo int ret; 4158e705c121SKalle Valo 4159e705c121SKalle Valo mutex_lock(&mvm->mutex); 4160e705c121SKalle Valo 4161e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 4162e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 4163e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 4164e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 4165e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 4166e705c121SKalle Valo * could run. To handle this, simply return if the scan is 4167e705c121SKalle Valo * not running. 4168e705c121SKalle Valo */ 4169e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 4170e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4171e705c121SKalle Valo return 0; 4172e705c121SKalle Valo } 4173e705c121SKalle Valo 4174e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 4175e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4176e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 4177e705c121SKalle Valo 4178e705c121SKalle Valo return ret; 4179e705c121SKalle Valo } 4180e705c121SKalle Valo 41816569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 4182e705c121SKalle Valo enum set_key_cmd cmd, 4183e705c121SKalle Valo struct ieee80211_vif *vif, 4184e705c121SKalle Valo struct ieee80211_sta *sta, 4185e705c121SKalle Valo struct ieee80211_key_conf *key) 4186e705c121SKalle Valo { 4187c56e00a3SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4188e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 418946c7b05aSEmmanuel Grumbach struct iwl_mvm_sta *mvmsta = NULL; 4190d066a530SJohannes Berg struct iwl_mvm_key_pn *ptk_pn = NULL; 4191f5e28eacSJohannes Berg int keyidx = key->keyidx; 41925c75a208SJohannes Berg u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD); 41935c75a208SJohannes Berg u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0); 4194c56e00a3SJohannes Berg int ret, i; 41954615fd15SEmmanuel Grumbach u8 key_offset; 4196e705c121SKalle Valo 419746c7b05aSEmmanuel Grumbach if (sta) 41986d19a5ebSEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_mac80211(sta); 41996d19a5ebSEmmanuel Grumbach 4200e705c121SKalle Valo switch (key->cipher) { 4201e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 4202286ca8ebSLuca Coelho if (!mvm->trans->trans_cfg->gen2) { 4203e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 42041ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 42057f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 42067f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 42077f768ad5SDavid Spinadel } else { 42087f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 42097f768ad5SDavid Spinadel return -EOPNOTSUPP; 42107f768ad5SDavid Spinadel } 4211e705c121SKalle Valo break; 4212e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 42132a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 42142a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 421585aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 4216e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 4217e705c121SKalle Valo break; 4218e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 42198e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 42208e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 4221e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 4222e705c121SKalle Valo break; 4223e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 4224e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 4225475c6bdeSJohannes Berg if (vif->type == NL80211_IFTYPE_STATION) 4226e705c121SKalle Valo break; 4227475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 4228475c6bdeSJohannes Berg return -EOPNOTSUPP; 4229475c6bdeSJohannes Berg /* support HW crypto on TX */ 4230475c6bdeSJohannes Berg return 0; 4231e705c121SKalle Valo default: 4232e705c121SKalle Valo return -EOPNOTSUPP; 4233e705c121SKalle Valo } 4234e705c121SKalle Valo 4235e705c121SKalle Valo switch (cmd) { 4236e705c121SKalle Valo case SET_KEY: 4237a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 4238a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 4239b1fdc250SJohannes Berg rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 4240b1fdc250SJohannes Berg key); 4241b1fdc250SJohannes Berg 4242e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 4243e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 4244e705c121SKalle Valo /* 4245e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 4246e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 4247e705c121SKalle Valo * we don't support them for RX, so do the same. 4248f05d1e04SJohannes Berg * CMAC/GMAC in AP/IBSS modes must be done in software 4249f05d1e04SJohannes Berg * on older NICs. 4250a5de7de7SJohannes Berg * 4251a5de7de7SJohannes Berg * Except, of course, beacon protection - it must be 4252f05d1e04SJohannes Berg * offloaded since we just set a beacon template, and 4253f05d1e04SJohannes Berg * then we must also offload the IGTK (not just BIGTK) 4254f05d1e04SJohannes Berg * for firmware reasons. 4255f05d1e04SJohannes Berg * 4256f05d1e04SJohannes Berg * So just check for beacon protection - if we don't 4257f05d1e04SJohannes Berg * have it we cannot get here with keyidx >= 6, and 4258f05d1e04SJohannes Berg * if we do have it we need to send the key to FW in 4259f05d1e04SJohannes Berg * all cases (CMAC/GMAC). 4260e705c121SKalle Valo */ 4261f05d1e04SJohannes Berg if (!wiphy_ext_feature_isset(hw->wiphy, 4262f05d1e04SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION) && 4263a5de7de7SJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 42648e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 4265a5de7de7SJohannes Berg key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) { 426681279c49SJohannes Berg ret = -EOPNOTSUPP; 4267a1c2ff30SAndrei Otcheretianski break; 4268a1c2ff30SAndrei Otcheretianski } 426985aeb58cSDavid Spinadel 427085aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 427185aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 427285aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 4273e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 4274a1c2ff30SAndrei Otcheretianski ret = 0; 4275e705c121SKalle Valo break; 4276e705c121SKalle Valo } 4277c56e00a3SJohannes Berg 4278c56e00a3SJohannes Berg if (!mvmvif->ap_ibss_active) { 4279c56e00a3SJohannes Berg for (i = 0; 4280c56e00a3SJohannes Berg i < ARRAY_SIZE(mvmvif->ap_early_keys); 4281c56e00a3SJohannes Berg i++) { 4282c56e00a3SJohannes Berg if (!mvmvif->ap_early_keys[i]) { 4283c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = key; 4284c56e00a3SJohannes Berg break; 4285c56e00a3SJohannes Berg } 4286c56e00a3SJohannes Berg } 4287c56e00a3SJohannes Berg 4288c56e00a3SJohannes Berg if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 4289c56e00a3SJohannes Berg ret = -ENOSPC; 4290a1c2ff30SAndrei Otcheretianski else 4291a1c2ff30SAndrei Otcheretianski ret = 0; 4292c56e00a3SJohannes Berg 4293c56e00a3SJohannes Berg break; 4294c56e00a3SJohannes Berg } 429585aeb58cSDavid Spinadel } 4296e705c121SKalle Valo 4297e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 4298e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 4299e705c121SKalle Valo */ 4300e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 4301e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 4302e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 4303e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 4304e705c121SKalle Valo ret = 0; 4305e705c121SKalle Valo break; 4306e705c121SKalle Valo } 4307e705c121SKalle Valo 4308f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 430946c7b05aSEmmanuel Grumbach mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4310f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4311f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 43122a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 43132a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4314f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 4315f5e28eacSJohannes Berg int tid, q; 4316f5e28eacSJohannes Berg 4317f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 4318acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 4319acafe7e3SKees Cook mvm->trans->num_rx_queues), 4320f5e28eacSJohannes Berg GFP_KERNEL); 4321f5e28eacSJohannes Berg if (!ptk_pn) { 4322f5e28eacSJohannes Berg ret = -ENOMEM; 4323f5e28eacSJohannes Berg break; 4324f5e28eacSJohannes Berg } 4325f5e28eacSJohannes Berg 4326f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 4327f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 4328f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 4329f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 4330f5e28eacSJohannes Berg seq.ccmp.pn, 4331f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 4332f5e28eacSJohannes Berg } 4333f5e28eacSJohannes Berg 4334f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 4335f5e28eacSJohannes Berg } 4336f5e28eacSJohannes Berg 43374615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 43384615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 43394615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 43404615fd15SEmmanuel Grumbach else 43414615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 43424615fd15SEmmanuel Grumbach 434346c7b05aSEmmanuel Grumbach if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 43446d19a5ebSEmmanuel Grumbach mvmsta->pairwise_cipher = key->cipher; 43456d19a5ebSEmmanuel Grumbach 4346a5de7de7SJohannes Berg IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n", 4347a5de7de7SJohannes Berg sta ? sta->addr : NULL, key->keyidx); 43485c75a208SJohannes Berg 43495c75a208SJohannes Berg if (sec_key_ver) 43505c75a208SJohannes Berg ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); 43515c75a208SJohannes Berg else 43524615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 43535c75a208SJohannes Berg 4354e705c121SKalle Valo if (ret) { 4355e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 4356475c6bdeSJohannes Berg key->hw_key_idx = STA_KEY_IDX_INVALID; 4357d066a530SJohannes Berg if (ptk_pn) { 4358d066a530SJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4359d066a530SJohannes Berg kfree(ptk_pn); 4360d066a530SJohannes Berg } 4361e705c121SKalle Valo /* 4362e705c121SKalle Valo * can't add key for RX, but we don't need it 4363475c6bdeSJohannes Berg * in the device for TX so still return 0, 4364475c6bdeSJohannes Berg * unless we have new TX API where we cannot 4365475c6bdeSJohannes Berg * put key material into the TX_CMD 4366e705c121SKalle Valo */ 4367475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 4368475c6bdeSJohannes Berg ret = -EOPNOTSUPP; 4369475c6bdeSJohannes Berg else 4370e705c121SKalle Valo ret = 0; 4371e705c121SKalle Valo } 4372e705c121SKalle Valo 4373e705c121SKalle Valo break; 4374e705c121SKalle Valo case DISABLE_KEY: 4375a5de7de7SJohannes Berg if (vif->type == NL80211_IFTYPE_STATION && 4376a5de7de7SJohannes Berg (keyidx == 6 || keyidx == 7)) 4377b1fdc250SJohannes Berg RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 4378b1fdc250SJohannes Berg NULL); 4379b1fdc250SJohannes Berg 4380c56e00a3SJohannes Berg ret = -ENOENT; 4381c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 4382c56e00a3SJohannes Berg if (mvmvif->ap_early_keys[i] == key) { 4383c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 4384c56e00a3SJohannes Berg ret = 0; 4385c56e00a3SJohannes Berg } 4386c56e00a3SJohannes Berg } 4387c56e00a3SJohannes Berg 4388c56e00a3SJohannes Berg /* found in pending list - don't do anything else */ 4389c56e00a3SJohannes Berg if (ret == 0) 4390c56e00a3SJohannes Berg break; 4391c56e00a3SJohannes Berg 4392e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 4393e705c121SKalle Valo ret = 0; 4394e705c121SKalle Valo break; 4395e705c121SKalle Valo } 4396e705c121SKalle Valo 439746c7b05aSEmmanuel Grumbach if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 4398f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 4399f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 44002a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 44012a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 4402f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 4403f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 4404f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 4405f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 4406f5e28eacSJohannes Berg if (ptk_pn) 4407f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 4408f5e28eacSJohannes Berg } 4409f5e28eacSJohannes Berg 4410e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 44115c75a208SJohannes Berg if (sec_key_ver) 44125c75a208SJohannes Berg ret = iwl_mvm_sec_key_del(mvm, vif, sta, key); 44135c75a208SJohannes Berg else 4414e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 4415e705c121SKalle Valo break; 4416e705c121SKalle Valo default: 4417e705c121SKalle Valo ret = -EINVAL; 4418e705c121SKalle Valo } 4419e705c121SKalle Valo 44206569e7d3SJohannes Berg return ret; 44216569e7d3SJohannes Berg } 44226569e7d3SJohannes Berg 4423cbce62a3SMiri Korenblit int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 4424cbce62a3SMiri Korenblit struct ieee80211_vif *vif, struct ieee80211_sta *sta, 44256569e7d3SJohannes Berg struct ieee80211_key_conf *key) 44266569e7d3SJohannes Berg { 44276569e7d3SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 44286569e7d3SJohannes Berg int ret; 44296569e7d3SJohannes Berg 44306569e7d3SJohannes Berg mutex_lock(&mvm->mutex); 44316569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 4432e705c121SKalle Valo mutex_unlock(&mvm->mutex); 44336569e7d3SJohannes Berg 4434e705c121SKalle Valo return ret; 4435e705c121SKalle Valo } 4436e705c121SKalle Valo 4437cbce62a3SMiri Korenblit void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 4438e705c121SKalle Valo struct ieee80211_vif *vif, 4439e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 4440e705c121SKalle Valo struct ieee80211_sta *sta, 4441e705c121SKalle Valo u32 iv32, u16 *phase1key) 4442e705c121SKalle Valo { 4443e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4444e705c121SKalle Valo 4445e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 4446e705c121SKalle Valo return; 4447e705c121SKalle Valo 4448e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 4449e705c121SKalle Valo } 4450e705c121SKalle Valo 4451e705c121SKalle Valo 4452e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 4453e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 4454e705c121SKalle Valo { 4455e705c121SKalle Valo struct iwl_mvm *mvm = 4456e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 4457e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 4458e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 4459e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 4460e705c121SKalle Valo 4461e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 4462e705c121SKalle Valo return true; 4463e705c121SKalle Valo 4464e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 4465e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 4466e705c121SKalle Valo return true; 4467e705c121SKalle Valo } 4468e705c121SKalle Valo 4469e705c121SKalle Valo resp = (void *)pkt->data; 4470e705c121SKalle Valo 4471e705c121SKalle Valo IWL_DEBUG_TE(mvm, 4472b71a9c35SColin Ian King "Aux ROC: Received response from ucode: status=%d uid=%d\n", 4473e705c121SKalle Valo resp->status, resp->event_unique_id); 4474e705c121SKalle Valo 4475e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 4476e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 4477e705c121SKalle Valo te_data->uid); 4478e705c121SKalle Valo 4479e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4480e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 4481e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4482e705c121SKalle Valo 4483e705c121SKalle Valo return true; 4484e705c121SKalle Valo } 4485e705c121SKalle Valo 4486e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 4487e705c121SKalle Valo struct ieee80211_channel *channel, 4488e705c121SKalle Valo struct ieee80211_vif *vif, 4489e705c121SKalle Valo int duration) 4490e705c121SKalle Valo { 4491afc1e3b4SAvraham Stern int res; 4492e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4493e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 4494e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 4495e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 4496dc28e12fSMatti Gottlieb u32 req_dur, delay; 4497e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 4498e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 4499e705c121SKalle Valo .id_and_color = 4500e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 4501e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 4502e705c121SKalle Valo }; 450357e861d9SDavid Spinadel struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 450457e861d9SDavid Spinadel &aux_roc_req.channel_info); 450557e861d9SDavid Spinadel u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 450657e861d9SDavid Spinadel 450757e861d9SDavid Spinadel /* Set the channel info data */ 450857e861d9SDavid Spinadel iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 45093717f91aSTova Mussai iwl_mvm_phy_band_from_nl80211(channel->band), 45107ac87575SJohannes Berg IWL_PHY_CHANNEL_MODE20, 451157e861d9SDavid Spinadel 0); 451257e861d9SDavid Spinadel 451357e861d9SDavid Spinadel /* Set the time and duration */ 4514afc1e3b4SAvraham Stern tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 4515e705c121SKalle Valo 451667ac248eSShaul Triebitz iwl_mvm_roc_duration_and_delay(vif, duration, &req_dur, &delay); 451757e861d9SDavid Spinadel tail->duration = cpu_to_le32(req_dur); 451857e861d9SDavid Spinadel tail->apply_time_max_delay = cpu_to_le32(delay); 4519dc28e12fSMatti Gottlieb 4520dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 4521903b3f9bSEmmanuel Grumbach "ROC: Requesting to remain on channel %u for %ums\n", 4522903b3f9bSEmmanuel Grumbach channel->hw_value, req_dur); 4523903b3f9bSEmmanuel Grumbach IWL_DEBUG_TE(mvm, 452467ac248eSShaul Triebitz "\t(requested = %ums, max_delay = %ums)\n", 452567ac248eSShaul Triebitz duration, delay); 4526903b3f9bSEmmanuel Grumbach 4527e705c121SKalle Valo /* Set the node address */ 452857e861d9SDavid Spinadel memcpy(tail->node_addr, vif->addr, ETH_ALEN); 4529e705c121SKalle Valo 4530e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4531e705c121SKalle Valo 4532e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4533e705c121SKalle Valo 4534e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 4535e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4536e705c121SKalle Valo return -EIO; 4537e705c121SKalle Valo } 4538e705c121SKalle Valo 4539e705c121SKalle Valo te_data->vif = vif; 4540e705c121SKalle Valo te_data->duration = duration; 4541e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 4542e705c121SKalle Valo 4543e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4544e705c121SKalle Valo 4545e705c121SKalle Valo /* 4546e705c121SKalle Valo * Use a notification wait, which really just processes the 4547e705c121SKalle Valo * command response and doesn't wait for anything, in order 4548e705c121SKalle Valo * to be able to process the response and get the UID inside 4549e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 4550e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 4551e705c121SKalle Valo * time another notification (that the time event started) 4552e705c121SKalle Valo * might already be processed unsuccessfully. 4553e705c121SKalle Valo */ 4554e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 4555e705c121SKalle Valo time_event_response, 4556e705c121SKalle Valo ARRAY_SIZE(time_event_response), 4557e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 4558e705c121SKalle Valo 455957e861d9SDavid Spinadel res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 4560e705c121SKalle Valo &aux_roc_req); 4561e705c121SKalle Valo 4562e705c121SKalle Valo if (res) { 4563e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 4564e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 4565e705c121SKalle Valo goto out_clear_te; 4566e705c121SKalle Valo } 4567e705c121SKalle Valo 4568e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 4569e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 4570e705c121SKalle Valo /* should never fail */ 4571e705c121SKalle Valo WARN_ON_ONCE(res); 4572e705c121SKalle Valo 4573e705c121SKalle Valo if (res) { 4574e705c121SKalle Valo out_clear_te: 4575e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 4576e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 4577e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 4578e705c121SKalle Valo } 4579e705c121SKalle Valo 4580e705c121SKalle Valo return res; 4581e705c121SKalle Valo } 4582e705c121SKalle Valo 4583feebebaeSMiri Korenblit static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id) 4584feebebaeSMiri Korenblit { 4585feebebaeSMiri Korenblit int ret = 0; 4586feebebaeSMiri Korenblit 4587feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4588feebebaeSMiri Korenblit 4589feebebaeSMiri Korenblit if (!fw_has_capa(&mvm->fw->ucode_capa, 4590feebebaeSMiri Korenblit IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 4591feebebaeSMiri Korenblit IWL_ERR(mvm, "hotspot not supported\n"); 4592feebebaeSMiri Korenblit return -EINVAL; 4593feebebaeSMiri Korenblit } 4594feebebaeSMiri Korenblit 45951724fc78SEmmanuel Grumbach if (iwl_mvm_has_new_station_api(mvm->fw)) { 4596feebebaeSMiri Korenblit ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 4597feebebaeSMiri Korenblit WARN(ret, "Failed to allocate aux station"); 4598feebebaeSMiri Korenblit } 4599feebebaeSMiri Korenblit 4600feebebaeSMiri Korenblit return ret; 4601feebebaeSMiri Korenblit } 4602feebebaeSMiri Korenblit 460384ef7cbeSIlan Peer static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 4604feebebaeSMiri Korenblit { 460584ef7cbeSIlan Peer int ret; 4606feebebaeSMiri Korenblit 4607feebebaeSMiri Korenblit lockdep_assert_held(&mvm->mutex); 4608feebebaeSMiri Korenblit 4609feebebaeSMiri Korenblit ret = iwl_mvm_binding_add_vif(mvm, vif); 461084ef7cbeSIlan Peer if (WARN(ret, "Failed binding P2P_DEVICE\n")) 4611feebebaeSMiri Korenblit return ret; 461284ef7cbeSIlan Peer 461384ef7cbeSIlan Peer /* The station and queue allocation must be done only after the binding 461484ef7cbeSIlan Peer * is done, as otherwise the FW might incorrectly configure its state. 461584ef7cbeSIlan Peer */ 461684ef7cbeSIlan Peer return iwl_mvm_add_p2p_bcast_sta(mvm, vif); 4617feebebaeSMiri Korenblit } 4618feebebaeSMiri Korenblit 4619e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 4620e705c121SKalle Valo struct ieee80211_vif *vif, 4621e705c121SKalle Valo struct ieee80211_channel *channel, 4622e705c121SKalle Valo int duration, 4623e705c121SKalle Valo enum ieee80211_roc_type type) 4624e705c121SKalle Valo { 4625a2906ea6SJohannes Berg static const struct iwl_mvm_roc_ops ops = { 4626fe8b2ad3SMiri Korenblit .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20, 462784ef7cbeSIlan Peer .link = iwl_mvm_roc_link, 4628fe8b2ad3SMiri Korenblit }; 4629fe8b2ad3SMiri Korenblit 4630fe8b2ad3SMiri Korenblit return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops); 4631fe8b2ad3SMiri Korenblit } 4632fe8b2ad3SMiri Korenblit 463367ac248eSShaul Triebitz static int iwl_mvm_roc_station(struct iwl_mvm *mvm, 463467ac248eSShaul Triebitz struct ieee80211_channel *channel, 463567ac248eSShaul Triebitz struct ieee80211_vif *vif, 463667ac248eSShaul Triebitz int duration) 463767ac248eSShaul Triebitz { 463867ac248eSShaul Triebitz int ret; 463967ac248eSShaul Triebitz u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD); 464067ac248eSShaul Triebitz u8 fw_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 464167ac248eSShaul Triebitz IWL_FW_CMD_VER_UNKNOWN); 464267ac248eSShaul Triebitz 464367ac248eSShaul Triebitz if (fw_ver == IWL_FW_CMD_VER_UNKNOWN) { 464467ac248eSShaul Triebitz ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, vif, duration); 464567ac248eSShaul Triebitz } else if (fw_ver == 3) { 464667ac248eSShaul Triebitz ret = iwl_mvm_roc_add_cmd(mvm, channel, vif, duration, 464767ac248eSShaul Triebitz ROC_ACTIVITY_HOTSPOT); 464867ac248eSShaul Triebitz } else { 464967ac248eSShaul Triebitz ret = -EOPNOTSUPP; 465067ac248eSShaul Triebitz IWL_ERR(mvm, "ROC command version %d mismatch!\n", fw_ver); 465167ac248eSShaul Triebitz } 465267ac248eSShaul Triebitz 465367ac248eSShaul Triebitz return ret; 465467ac248eSShaul Triebitz } 465567ac248eSShaul Triebitz 465634cc3a4aSEmmanuel Grumbach static int iwl_mvm_p2p_find_phy_ctxt(struct iwl_mvm *mvm, 465734cc3a4aSEmmanuel Grumbach struct ieee80211_vif *vif, 465834cc3a4aSEmmanuel Grumbach struct ieee80211_channel *channel) 465934cc3a4aSEmmanuel Grumbach { 466034cc3a4aSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 466134cc3a4aSEmmanuel Grumbach struct cfg80211_chan_def chandef; 466234cc3a4aSEmmanuel Grumbach int i; 466334cc3a4aSEmmanuel Grumbach 466434cc3a4aSEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 466534cc3a4aSEmmanuel Grumbach 466634cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt && 466734cc3a4aSEmmanuel Grumbach channel == mvmvif->deflink.phy_ctxt->channel) 466834cc3a4aSEmmanuel Grumbach return 0; 466934cc3a4aSEmmanuel Grumbach 467034cc3a4aSEmmanuel Grumbach /* Try using a PHY context that is already in use */ 467134cc3a4aSEmmanuel Grumbach for (i = 0; i < NUM_PHY_CTX; i++) { 467234cc3a4aSEmmanuel Grumbach struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[i]; 467334cc3a4aSEmmanuel Grumbach 467434cc3a4aSEmmanuel Grumbach if (!phy_ctxt->ref || mvmvif->deflink.phy_ctxt == phy_ctxt) 467534cc3a4aSEmmanuel Grumbach continue; 467634cc3a4aSEmmanuel Grumbach 467734cc3a4aSEmmanuel Grumbach if (channel == phy_ctxt->channel) { 467834cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt) 467934cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_unref(mvm, 468034cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt); 468134cc3a4aSEmmanuel Grumbach 468234cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt = phy_ctxt; 468334cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt); 468434cc3a4aSEmmanuel Grumbach return 0; 468534cc3a4aSEmmanuel Grumbach } 468634cc3a4aSEmmanuel Grumbach } 468734cc3a4aSEmmanuel Grumbach 468834cc3a4aSEmmanuel Grumbach /* We already have a phy_ctxt, but it's not on the right channel */ 468934cc3a4aSEmmanuel Grumbach if (mvmvif->deflink.phy_ctxt) 469034cc3a4aSEmmanuel Grumbach iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt); 469134cc3a4aSEmmanuel Grumbach 469234cc3a4aSEmmanuel Grumbach mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 469334cc3a4aSEmmanuel Grumbach if (!mvmvif->deflink.phy_ctxt) 469434cc3a4aSEmmanuel Grumbach return -ENOSPC; 469534cc3a4aSEmmanuel Grumbach 469634cc3a4aSEmmanuel Grumbach cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 469734cc3a4aSEmmanuel Grumbach 469834cc3a4aSEmmanuel Grumbach return iwl_mvm_phy_ctxt_add(mvm, mvmvif->deflink.phy_ctxt, 469932a5690eSJohannes Berg &chandef, NULL, 1, 1); 470034cc3a4aSEmmanuel Grumbach } 470134cc3a4aSEmmanuel Grumbach 4702fe8b2ad3SMiri Korenblit /* Execute the common part for MLD and non-MLD modes */ 4703fe8b2ad3SMiri Korenblit int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 4704fe8b2ad3SMiri Korenblit struct ieee80211_channel *channel, int duration, 4705fe8b2ad3SMiri Korenblit enum ieee80211_roc_type type, 4706a2906ea6SJohannes Berg const struct iwl_mvm_roc_ops *ops) 4707fe8b2ad3SMiri Korenblit { 4708e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4709feebebaeSMiri Korenblit u32 lmac_id; 471034cc3a4aSEmmanuel Grumbach int ret; 4711e705c121SKalle Valo 4712e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 4713e705c121SKalle Valo duration, type); 4714e705c121SKalle Valo 47159834781cSJohannes Berg /* 47169834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 47179834781cSJohannes Berg * the work it does can complete and we can accept new frames. 47189834781cSJohannes Berg */ 4719e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 4720e705c121SKalle Valo 4721e705c121SKalle Valo mutex_lock(&mvm->mutex); 4722e705c121SKalle Valo 4723e705c121SKalle Valo switch (vif->type) { 4724e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4725d51439a6SAriel Malamud lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band); 47262c2c3647SNathan Errera 4727feebebaeSMiri Korenblit /* Use aux roc framework (HS20) */ 4728fe8b2ad3SMiri Korenblit ret = ops->add_aux_sta_for_hs20(mvm, lmac_id); 4729feebebaeSMiri Korenblit if (!ret) 473067ac248eSShaul Triebitz ret = iwl_mvm_roc_station(mvm, channel, vif, duration); 4731e705c121SKalle Valo goto out_unlock; 4732e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 4733e705c121SKalle Valo /* handle below */ 4734e705c121SKalle Valo break; 4735e705c121SKalle Valo default: 473684ef7cbeSIlan Peer IWL_ERR(mvm, "ROC: Invalid vif type=%u\n", vif->type); 4737e705c121SKalle Valo ret = -EINVAL; 4738e705c121SKalle Valo goto out_unlock; 4739e705c121SKalle Valo } 4740e705c121SKalle Valo 4741e705c121SKalle Valo 474234cc3a4aSEmmanuel Grumbach ret = iwl_mvm_p2p_find_phy_ctxt(mvm, vif, channel); 474334cc3a4aSEmmanuel Grumbach if (ret) 4744e705c121SKalle Valo goto out_unlock; 4745e705c121SKalle Valo 474684ef7cbeSIlan Peer ret = ops->link(mvm, vif); 4747feebebaeSMiri Korenblit if (ret) 4748e705c121SKalle Valo goto out_unlock; 4749e705c121SKalle Valo 4750e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4751e705c121SKalle Valo out_unlock: 4752e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4753e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4754e705c121SKalle Valo return ret; 4755e705c121SKalle Valo } 4756e705c121SKalle Valo 4757fe8b2ad3SMiri Korenblit int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 47585db4c4b9SEmmanuel Grumbach struct ieee80211_vif *vif) 4759e705c121SKalle Valo { 4760e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4761e705c121SKalle Valo 4762e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 4763e705c121SKalle Valo 4764e705c121SKalle Valo mutex_lock(&mvm->mutex); 4765fe959c7bSEmmanuel Grumbach iwl_mvm_stop_roc(mvm, vif); 4766e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4767e705c121SKalle Valo 4768e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4769e705c121SKalle Valo return 0; 4770e705c121SKalle Valo } 4771e705c121SKalle Valo 4772b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data { 4773b73f9a4aSJohannes Berg bool responder; 4774b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx; 4775b73f9a4aSJohannes Berg }; 4776b73f9a4aSJohannes Berg 4777b73f9a4aSJohannes Berg static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4778b73f9a4aSJohannes Berg struct ieee80211_vif *vif) 4779b73f9a4aSJohannes Berg { 4780b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data *data = _data; 4781b73f9a4aSJohannes Berg 4782d0a9123eSJohannes Berg if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && 4783b73f9a4aSJohannes Berg vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4784b73f9a4aSJohannes Berg data->responder = true; 4785b73f9a4aSJohannes Berg } 4786b73f9a4aSJohannes Berg 4787ce1fa3adSJohannes Berg bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4788b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx) 4789b73f9a4aSJohannes Berg { 4790b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data data = { 4791b73f9a4aSJohannes Berg .responder = false, 4792b73f9a4aSJohannes Berg .ctx = ctx, 4793b73f9a4aSJohannes Berg }; 4794b73f9a4aSJohannes Berg 4795b73f9a4aSJohannes Berg ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4796b73f9a4aSJohannes Berg IEEE80211_IFACE_ITER_NORMAL, 4797b73f9a4aSJohannes Berg iwl_mvm_ftm_responder_chanctx_iter, 4798b73f9a4aSJohannes Berg &data); 4799b73f9a4aSJohannes Berg return data.responder; 4800b73f9a4aSJohannes Berg } 4801b73f9a4aSJohannes Berg 4802e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4803e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4804e705c121SKalle Valo { 4805e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4806e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 4807ce1fa3adSJohannes Berg struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4808e705c121SKalle Valo int ret; 4809e705c121SKalle Valo 4810e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4811e705c121SKalle Valo 4812e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4813e705c121SKalle Valo 4814e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4815e705c121SKalle Valo if (!phy_ctxt) { 4816e705c121SKalle Valo ret = -ENOSPC; 4817e705c121SKalle Valo goto out; 4818e705c121SKalle Valo } 4819e705c121SKalle Valo 482032a5690eSJohannes Berg ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, def, &ctx->ap, 4821e705c121SKalle Valo ctx->rx_chains_static, 4822e705c121SKalle Valo ctx->rx_chains_dynamic); 4823e705c121SKalle Valo if (ret) { 4824e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 4825e705c121SKalle Valo goto out; 4826e705c121SKalle Valo } 4827e705c121SKalle Valo 4828e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 4829e705c121SKalle Valo out: 4830e705c121SKalle Valo return ret; 4831e705c121SKalle Valo } 4832e705c121SKalle Valo 4833cbce62a3SMiri Korenblit int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4834e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4835e705c121SKalle Valo { 4836e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4837e705c121SKalle Valo int ret; 4838e705c121SKalle Valo 4839e705c121SKalle Valo mutex_lock(&mvm->mutex); 4840e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 4841e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4842e705c121SKalle Valo 4843e705c121SKalle Valo return ret; 4844e705c121SKalle Valo } 4845e705c121SKalle Valo 4846e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4847e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4848e705c121SKalle Valo { 4849e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4850e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4851e705c121SKalle Valo 4852e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4853e705c121SKalle Valo 4854e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4855e705c121SKalle Valo } 4856e705c121SKalle Valo 4857cbce62a3SMiri Korenblit void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4858e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4859e705c121SKalle Valo { 4860e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4861e705c121SKalle Valo 4862e705c121SKalle Valo mutex_lock(&mvm->mutex); 4863e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 4864e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4865e705c121SKalle Valo } 4866e705c121SKalle Valo 4867cbce62a3SMiri Korenblit void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4868cbce62a3SMiri Korenblit struct ieee80211_chanctx_conf *ctx, u32 changed) 4869e705c121SKalle Valo { 4870e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4871e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4872e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4873ce1fa3adSJohannes Berg struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx); 4874e705c121SKalle Valo 4875e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 4876e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4877e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4878e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 4879e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4880e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 4881e705c121SKalle Valo phy_ctxt->ref, changed)) 4882e705c121SKalle Valo return; 4883e705c121SKalle Valo 4884e705c121SKalle Valo mutex_lock(&mvm->mutex); 48857a20bcceSEmmanuel Grumbach 48867a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 48877a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 4888b73f9a4aSJohannes Berg if (phy_ctxt->width == def->width) 48897a20bcceSEmmanuel Grumbach goto out_unlock; 48907a20bcceSEmmanuel Grumbach 48917a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 48927a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 4893b73f9a4aSJohannes Berg def->width <= NL80211_CHAN_WIDTH_20) 48947a20bcceSEmmanuel Grumbach goto out_unlock; 48957a20bcceSEmmanuel Grumbach } 48967a20bcceSEmmanuel Grumbach 4897e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 489832a5690eSJohannes Berg iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, &ctx->ap, 4899e705c121SKalle Valo ctx->rx_chains_static, 4900e705c121SKalle Valo ctx->rx_chains_dynamic); 49017a20bcceSEmmanuel Grumbach 49027a20bcceSEmmanuel Grumbach out_unlock: 4903e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4904e705c121SKalle Valo } 4905e705c121SKalle Valo 49068a919a78SMiri Korenblit /* 49078a919a78SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 49088a919a78SMiri Korenblit * 49098a919a78SMiri Korenblit * Returns true if we're done assigning the chanctx 49108a919a78SMiri Korenblit * (either on failure or success) 49118a919a78SMiri Korenblit */ 49124263ac7fSGregory Greenman static bool 49134263ac7fSGregory Greenman __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, 4914e705c121SKalle Valo struct ieee80211_vif *vif, 4915e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 491650e81437SMiri Korenblit bool switching_chanctx, int *ret) 4917e705c121SKalle Valo { 4918e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4919e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4920e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4921e705c121SKalle Valo 4922e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4923e705c121SKalle Valo 4924650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = phy_ctxt; 4925e705c121SKalle Valo 4926e705c121SKalle Valo switch (vif->type) { 4927e705c121SKalle Valo case NL80211_IFTYPE_AP: 4928e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 4929e705c121SKalle Valo if (switching_chanctx) { 4930e705c121SKalle Valo mvmvif->ap_ibss_active = true; 4931e705c121SKalle Valo break; 4932e705c121SKalle Valo } 49335a2abdcaSGustavo A. R. Silva fallthrough; 4934e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4935e705c121SKalle Valo /* 4936e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 4937e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 4938e705c121SKalle Valo */ 49398a919a78SMiri Korenblit *ret = 0; 49408a919a78SMiri Korenblit return true; 4941e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4942e705c121SKalle Valo break; 4943e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4944e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 4945e705c121SKalle Valo mvmvif->ps_disabled = true; 4946e705c121SKalle Valo break; 4947e705c121SKalle Valo default: 49488a919a78SMiri Korenblit *ret = -EINVAL; 49498a919a78SMiri Korenblit return true; 4950e705c121SKalle Valo } 49518a919a78SMiri Korenblit return false; 49528a919a78SMiri Korenblit } 49538a919a78SMiri Korenblit 49548a919a78SMiri Korenblit static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 49558a919a78SMiri Korenblit struct ieee80211_vif *vif, 49564263ac7fSGregory Greenman struct ieee80211_bss_conf *link_conf, 49578a919a78SMiri Korenblit struct ieee80211_chanctx_conf *ctx, 49588a919a78SMiri Korenblit bool switching_chanctx) 49598a919a78SMiri Korenblit { 49608a919a78SMiri Korenblit struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 49618a919a78SMiri Korenblit int ret; 49628a919a78SMiri Korenblit 49634263ac7fSGregory Greenman if (WARN_ON(!link_conf)) 49644263ac7fSGregory Greenman return -EINVAL; 49654263ac7fSGregory Greenman 49668a919a78SMiri Korenblit if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx, 49678a919a78SMiri Korenblit switching_chanctx, &ret)) 49688a919a78SMiri Korenblit goto out; 4969e705c121SKalle Valo 4970e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4971e705c121SKalle Valo if (ret) 4972e705c121SKalle Valo goto out; 4973e705c121SKalle Valo 4974e705c121SKalle Valo /* 4975e705c121SKalle Valo * Power state must be updated before quotas, 4976e705c121SKalle Valo * otherwise fw will complain. 4977e705c121SKalle Valo */ 4978e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4979e705c121SKalle Valo 4980e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 4981e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 4982e705c121SKalle Valo * will handle quota settings. 4983e705c121SKalle Valo */ 4984e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 4985e705c121SKalle Valo mvmvif->monitor_active = true; 4986e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 4987e705c121SKalle Valo if (ret) 4988e705c121SKalle Valo goto out_remove_binding; 49890e39eb03SChaya Rachel Ivgi 49900e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 49910e39eb03SChaya Rachel Ivgi if (ret) 49920e39eb03SChaya Rachel Ivgi goto out_remove_binding; 49930e39eb03SChaya Rachel Ivgi 4994e705c121SKalle Valo } 4995e705c121SKalle Valo 4996e705c121SKalle Valo /* Handle binding during CSA */ 4997e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 4998e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4999e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 5000e705c121SKalle Valo } 5001e705c121SKalle Valo 50028a919a78SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION) { 50038a919a78SMiri Korenblit if (!switching_chanctx) { 50048a919a78SMiri Korenblit mvmvif->csa_bcn_pending = false; 50058a919a78SMiri Korenblit goto out; 50068a919a78SMiri Korenblit } 50078a919a78SMiri Korenblit 500874a10252SSara Sharon mvmvif->csa_bcn_pending = true; 500974a10252SSara Sharon 501074a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 501174a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 501211d0d831SJohannes Berg u32 duration = 5 * vif->bss_conf.beacon_int; 5013e705c121SKalle Valo 5014e705c121SKalle Valo /* Protect the session to make sure we hear the first 5015e705c121SKalle Valo * beacon on the new channel. 5016e705c121SKalle Valo */ 5017e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 5018e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 5019e705c121SKalle Valo true); 502074a10252SSara Sharon } 5021e705c121SKalle Valo 5022e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 5023e705c121SKalle Valo } 5024e705c121SKalle Valo 5025e705c121SKalle Valo goto out; 5026e705c121SKalle Valo 5027e705c121SKalle Valo out_remove_binding: 5028e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 5029e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 5030e705c121SKalle Valo out: 5031e705c121SKalle Valo if (ret) 5032650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 5033e705c121SKalle Valo return ret; 5034e705c121SKalle Valo } 50358a919a78SMiri Korenblit 5036e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 5037e705c121SKalle Valo struct ieee80211_vif *vif, 5038727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 5039e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 5040e705c121SKalle Valo { 5041e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5042e705c121SKalle Valo int ret; 5043e705c121SKalle Valo 5044e705c121SKalle Valo mutex_lock(&mvm->mutex); 50454263ac7fSGregory Greenman ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5046e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5047e705c121SKalle Valo 5048e705c121SKalle Valo return ret; 5049e705c121SKalle Valo } 5050e705c121SKalle Valo 5051daddfae5SMiri Korenblit /* 5052daddfae5SMiri Korenblit * This function executes the common part for MLD and non-MLD modes. 5053daddfae5SMiri Korenblit * 5054daddfae5SMiri Korenblit * Returns if chanctx unassign chanctx is done 5055daddfae5SMiri Korenblit * (either on failure or success) 5056daddfae5SMiri Korenblit */ 50574263ac7fSGregory Greenman static bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, 5058e705c121SKalle Valo struct ieee80211_vif *vif, 5059e705c121SKalle Valo bool switching_chanctx) 5060e705c121SKalle Valo { 5061e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5062e705c121SKalle Valo 5063e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 5064650cadb7SGregory Greenman iwl_mvm_remove_time_event(mvm, mvmvif, 5065650cadb7SGregory Greenman &mvmvif->time_event_data); 5066e705c121SKalle Valo 5067e705c121SKalle Valo switch (vif->type) { 5068e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 5069daddfae5SMiri Korenblit return true; 5070e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 5071e705c121SKalle Valo mvmvif->monitor_active = false; 5072e705c121SKalle Valo mvmvif->ps_disabled = false; 5073e705c121SKalle Valo break; 5074e705c121SKalle Valo case NL80211_IFTYPE_AP: 5075e705c121SKalle Valo /* This part is triggered only during CSA */ 5076e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 5077daddfae5SMiri Korenblit return true; 5078e705c121SKalle Valo 5079e705c121SKalle Valo mvmvif->csa_countdown = false; 5080e705c121SKalle Valo 5081e705c121SKalle Valo /* Set CS bit on all the stations */ 5082e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 5083e705c121SKalle Valo 5084e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 5085e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 5086e705c121SKalle Valo 5087e705c121SKalle Valo mvmvif->ap_ibss_active = false; 5088e705c121SKalle Valo break; 5089daddfae5SMiri Korenblit default: 5090e705c121SKalle Valo break; 5091daddfae5SMiri Korenblit } 5092daddfae5SMiri Korenblit return false; 5093daddfae5SMiri Korenblit } 5094e705c121SKalle Valo 5095e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 5096e705c121SKalle Valo struct ieee80211_vif *vif, 50974263ac7fSGregory Greenman struct ieee80211_bss_conf *link_conf, 5098e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 5099e705c121SKalle Valo bool switching_chanctx) 5100e705c121SKalle Valo { 5101e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5102e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 5103e705c121SKalle Valo 5104daddfae5SMiri Korenblit if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx)) 5105e705c121SKalle Valo goto out; 5106daddfae5SMiri Korenblit 5107daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_MONITOR) 5108e705c121SKalle Valo iwl_mvm_rm_snif_sta(mvm, vif); 5109e705c121SKalle Valo 5110e705c121SKalle Valo 5111daddfae5SMiri Korenblit if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) { 5112e705c121SKalle Valo disabled_vif = vif; 511374a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 511474a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 5115e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 5116e705c121SKalle Valo } 5117e705c121SKalle Valo 5118e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 5119e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 5120e705c121SKalle Valo 5121e705c121SKalle Valo out: 5122bf544e9aSSara Sharon if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 5123bf544e9aSSara Sharon switching_chanctx) 5124bf544e9aSSara Sharon return; 5125650cadb7SGregory Greenman mvmvif->deflink.phy_ctxt = NULL; 5126e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 5127e705c121SKalle Valo } 5128e705c121SKalle Valo 5129e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 5130e705c121SKalle Valo struct ieee80211_vif *vif, 5131727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 5132e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 5133e705c121SKalle Valo { 5134e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5135e705c121SKalle Valo 5136e705c121SKalle Valo mutex_lock(&mvm->mutex); 51374263ac7fSGregory Greenman __iwl_mvm_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false); 5138e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5139e705c121SKalle Valo } 5140e705c121SKalle Valo 5141e705c121SKalle Valo static int 5142e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 5143660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5144a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5145e705c121SKalle Valo { 5146e705c121SKalle Valo int ret; 5147e705c121SKalle Valo 5148e705c121SKalle Valo mutex_lock(&mvm->mutex); 51494263ac7fSGregory Greenman ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51504263ac7fSGregory Greenman vifs[0].old_ctx, true); 5151e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 5152e705c121SKalle Valo 5153e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 5154e705c121SKalle Valo if (ret) { 5155e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 5156e705c121SKalle Valo goto out_reassign; 5157e705c121SKalle Valo } 5158e705c121SKalle Valo 51594263ac7fSGregory Greenman ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51604263ac7fSGregory Greenman vifs[0].new_ctx, true); 5161e705c121SKalle Valo if (ret) { 5162e705c121SKalle Valo IWL_ERR(mvm, 5163e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 5164e705c121SKalle Valo goto out_remove; 5165e705c121SKalle Valo } 5166e705c121SKalle Valo 5167e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 5168e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 5169e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 5170e705c121SKalle Valo 5171e705c121SKalle Valo goto out; 5172e705c121SKalle Valo 5173e705c121SKalle Valo out_remove: 5174e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 5175e705c121SKalle Valo 5176e705c121SKalle Valo out_reassign: 5177e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 5178e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 5179e705c121SKalle Valo goto out_restart; 5180e705c121SKalle Valo } 5181e705c121SKalle Valo 51824263ac7fSGregory Greenman if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 51834263ac7fSGregory Greenman vifs[0].old_ctx, true)) { 5184e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5185e705c121SKalle Valo goto out_restart; 5186e705c121SKalle Valo } 5187e705c121SKalle Valo 5188e705c121SKalle Valo goto out; 5189e705c121SKalle Valo 5190e705c121SKalle Valo out_restart: 5191e705c121SKalle Valo /* things keep failing, better restart the hw */ 5192e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 5193e705c121SKalle Valo 5194e705c121SKalle Valo out: 5195e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5196e705c121SKalle Valo 5197e705c121SKalle Valo return ret; 5198e705c121SKalle Valo } 5199e705c121SKalle Valo 5200e705c121SKalle Valo static int 5201e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 5202660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5203a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5204e705c121SKalle Valo { 5205e705c121SKalle Valo int ret; 5206e705c121SKalle Valo 5207e705c121SKalle Valo mutex_lock(&mvm->mutex); 52084263ac7fSGregory Greenman ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52094263ac7fSGregory Greenman vifs[0].old_ctx, true); 5210e705c121SKalle Valo 52114263ac7fSGregory Greenman ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52124263ac7fSGregory Greenman vifs[0].new_ctx, true); 5213e705c121SKalle Valo if (ret) { 5214e705c121SKalle Valo IWL_ERR(mvm, 5215e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 5216e705c121SKalle Valo goto out_reassign; 5217e705c121SKalle Valo } 5218e705c121SKalle Valo 5219e705c121SKalle Valo goto out; 5220e705c121SKalle Valo 5221e705c121SKalle Valo out_reassign: 52224263ac7fSGregory Greenman if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf, 52234263ac7fSGregory Greenman vifs[0].old_ctx, true)) { 5224e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 5225e705c121SKalle Valo goto out_restart; 5226e705c121SKalle Valo } 5227e705c121SKalle Valo 5228e705c121SKalle Valo goto out; 5229e705c121SKalle Valo 5230e705c121SKalle Valo out_restart: 5231e705c121SKalle Valo /* things keep failing, better restart the hw */ 5232e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 5233e705c121SKalle Valo 5234e705c121SKalle Valo out: 5235e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5236e705c121SKalle Valo 5237e705c121SKalle Valo return ret; 5238e705c121SKalle Valo } 5239e705c121SKalle Valo 5240660eba5aSMiri Korenblit /* Execute the common part for both MLD and non-MLD modes */ 5241660eba5aSMiri Korenblit int 5242660eba5aSMiri Korenblit iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw, 5243e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 5244e705c121SKalle Valo int n_vifs, 5245660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode, 5246a2906ea6SJohannes Berg const struct iwl_mvm_switch_vif_chanctx_ops *ops) 5247e705c121SKalle Valo { 5248e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5249e705c121SKalle Valo int ret; 5250e705c121SKalle Valo 5251e705c121SKalle Valo /* we only support a single-vif right now */ 5252e705c121SKalle Valo if (n_vifs > 1) 5253e705c121SKalle Valo return -EOPNOTSUPP; 5254e705c121SKalle Valo 5255e705c121SKalle Valo switch (mode) { 5256e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 5257660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops); 5258e705c121SKalle Valo break; 5259e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 5260660eba5aSMiri Korenblit ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops); 5261e705c121SKalle Valo break; 5262e705c121SKalle Valo default: 5263e705c121SKalle Valo ret = -EOPNOTSUPP; 5264e705c121SKalle Valo break; 5265e705c121SKalle Valo } 5266e705c121SKalle Valo 5267e705c121SKalle Valo return ret; 5268e705c121SKalle Valo } 5269e705c121SKalle Valo 5270660eba5aSMiri Korenblit static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 5271660eba5aSMiri Korenblit struct ieee80211_vif_chanctx_switch *vifs, 5272660eba5aSMiri Korenblit int n_vifs, 5273660eba5aSMiri Korenblit enum ieee80211_chanctx_switch_mode mode) 5274660eba5aSMiri Korenblit { 5275a2906ea6SJohannes Berg static const struct iwl_mvm_switch_vif_chanctx_ops ops = { 5276660eba5aSMiri Korenblit .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx, 5277660eba5aSMiri Korenblit .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx, 5278660eba5aSMiri Korenblit }; 5279660eba5aSMiri Korenblit 5280660eba5aSMiri Korenblit return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops); 5281660eba5aSMiri Korenblit } 5282660eba5aSMiri Korenblit 5283cbce62a3SMiri Korenblit int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 52842f0282dbSJohannes Berg { 52852f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 52862f0282dbSJohannes Berg 52872f0282dbSJohannes Berg return mvm->ibss_manager; 52882f0282dbSJohannes Berg } 52892f0282dbSJohannes Berg 5290a32973eeSJohannes Berg static int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 5291e705c121SKalle Valo bool set) 5292e705c121SKalle Valo { 5293e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5294e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 5295e705c121SKalle Valo 5296e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 5297e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 5298e705c121SKalle Valo return -EINVAL; 5299e705c121SKalle Valo } 5300e705c121SKalle Valo 530136cf5377SGregory Greenman return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif, 530236cf5377SGregory Greenman &mvm_sta->vif->bss_conf); 5303e705c121SKalle Valo } 5304e705c121SKalle Valo 5305e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 5306e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 5307e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 5308e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 5309e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 5310e705c121SKalle Valo }; 5311e705c121SKalle Valo 5312e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 5313e705c121SKalle Valo struct ieee80211_vif *vif, 5314e705c121SKalle Valo void *data, int len) 5315e705c121SKalle Valo { 5316e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 5317e705c121SKalle Valo int err; 5318e705c121SKalle Valo u32 noa_duration; 5319e705c121SKalle Valo 53208cb08174SJohannes Berg err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 53218cb08174SJohannes Berg iwl_mvm_tm_policy, NULL); 5322e705c121SKalle Valo if (err) 5323e705c121SKalle Valo return err; 5324e705c121SKalle Valo 5325e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 5326e705c121SKalle Valo return -EINVAL; 5327e705c121SKalle Valo 5328e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 5329e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 5330e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 5331e705c121SKalle Valo !vif->bss_conf.enable_beacon || 5332e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 5333e705c121SKalle Valo return -EINVAL; 5334e705c121SKalle Valo 5335e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 5336e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 5337e705c121SKalle Valo return -EINVAL; 5338e705c121SKalle Valo 5339e705c121SKalle Valo mvm->noa_duration = noa_duration; 5340e705c121SKalle Valo mvm->noa_vif = vif; 5341e705c121SKalle Valo 534222b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 5343e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 5344e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 5345e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 5346f276e20bSJohannes Berg !vif->cfg.assoc || !vif->bss_conf.dtim_period || 5347e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 5348e705c121SKalle Valo return -EINVAL; 5349e705c121SKalle Valo 5350e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 535187f5b5f2SJohannes Berg return iwl_mvm_enable_beacon_filter(mvm, vif); 535287f5b5f2SJohannes Berg return iwl_mvm_disable_beacon_filter(mvm, vif); 5353e705c121SKalle Valo } 5354e705c121SKalle Valo 5355e705c121SKalle Valo return -EOPNOTSUPP; 5356e705c121SKalle Valo } 5357e705c121SKalle Valo 5358cbce62a3SMiri Korenblit int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 5359e705c121SKalle Valo struct ieee80211_vif *vif, 5360e705c121SKalle Valo void *data, int len) 5361e705c121SKalle Valo { 5362e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5363e705c121SKalle Valo int err; 5364e705c121SKalle Valo 5365e705c121SKalle Valo mutex_lock(&mvm->mutex); 5366e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 5367e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5368e705c121SKalle Valo 5369e705c121SKalle Valo return err; 5370e705c121SKalle Valo } 5371e705c121SKalle Valo #endif 5372e705c121SKalle Valo 5373cbce62a3SMiri Korenblit void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5374e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5375e705c121SKalle Valo { 5376e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 5377e705c121SKalle Valo * starting its own channel switch timer, so that we can call 5378e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 5379e705c121SKalle Valo * (which is when the absence time event starts). 5380e705c121SKalle Valo */ 5381e705c121SKalle Valo 5382e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 5383e705c121SKalle Valo "dummy channel switch op\n"); 5384e705c121SKalle Valo } 5385e705c121SKalle Valo 538674a10252SSara Sharon static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 538774a10252SSara Sharon struct ieee80211_vif *vif, 538874a10252SSara Sharon struct ieee80211_channel_switch *chsw) 538974a10252SSara Sharon { 539074a10252SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 539174a10252SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 539274a10252SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 539374a10252SSara Sharon mvmvif->color)), 539474a10252SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 539574a10252SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 539674a10252SSara Sharon .cs_count = chsw->count, 539777738865SSara Sharon .cs_mode = chsw->block_tx, 539874a10252SSara Sharon }; 539974a10252SSara Sharon 540074a10252SSara Sharon lockdep_assert_held(&mvm->mutex); 540174a10252SSara Sharon 54029cfcf71cSSara Sharon if (chsw->delay) 54039cfcf71cSSara Sharon cmd.cs_delayed_bcn_count = 54049cfcf71cSSara Sharon DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 54059cfcf71cSSara Sharon 540674a10252SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 540774a10252SSara Sharon WIDE_ID(MAC_CONF_GROUP, 540874a10252SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 540974a10252SSara Sharon 0, sizeof(cmd), &cmd); 541074a10252SSara Sharon } 541174a10252SSara Sharon 54120202bcf0SEmmanuel Grumbach static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 54130202bcf0SEmmanuel Grumbach struct ieee80211_vif *vif, 54140202bcf0SEmmanuel Grumbach struct ieee80211_channel_switch *chsw) 54150202bcf0SEmmanuel Grumbach { 54160202bcf0SEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 54170202bcf0SEmmanuel Grumbach u32 apply_time; 54180202bcf0SEmmanuel Grumbach 54190202bcf0SEmmanuel Grumbach /* Schedule the time event to a bit before beacon 1, 54200202bcf0SEmmanuel Grumbach * to make sure we're in the new channel when the 54210202bcf0SEmmanuel Grumbach * GO/AP arrives. In case count <= 1 immediately schedule the 54220202bcf0SEmmanuel Grumbach * TE (this might result with some packet loss or connection 54230202bcf0SEmmanuel Grumbach * loss). 54240202bcf0SEmmanuel Grumbach */ 54250202bcf0SEmmanuel Grumbach if (chsw->count <= 1) 54260202bcf0SEmmanuel Grumbach apply_time = 0; 54270202bcf0SEmmanuel Grumbach else 54280202bcf0SEmmanuel Grumbach apply_time = chsw->device_timestamp + 54290202bcf0SEmmanuel Grumbach ((vif->bss_conf.beacon_int * (chsw->count - 1) - 54300202bcf0SEmmanuel Grumbach IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 54310202bcf0SEmmanuel Grumbach 54320202bcf0SEmmanuel Grumbach if (chsw->block_tx) 54330202bcf0SEmmanuel Grumbach iwl_mvm_csa_client_absent(mvm, vif); 54340202bcf0SEmmanuel Grumbach 5435c1e458b9SIlan Peer if (mvmvif->bf_enabled) { 543687f5b5f2SJohannes Berg int ret = iwl_mvm_disable_beacon_filter(mvm, vif); 54370202bcf0SEmmanuel Grumbach 54380202bcf0SEmmanuel Grumbach if (ret) 54390202bcf0SEmmanuel Grumbach return ret; 54400202bcf0SEmmanuel Grumbach } 54410202bcf0SEmmanuel Grumbach 54420202bcf0SEmmanuel Grumbach iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 54430202bcf0SEmmanuel Grumbach apply_time); 54440202bcf0SEmmanuel Grumbach 54450202bcf0SEmmanuel Grumbach return 0; 54460202bcf0SEmmanuel Grumbach } 54470202bcf0SEmmanuel Grumbach 5448*bbd6d0f8SJohannes Berg static void iwl_mvm_csa_block_txqs(void *data, struct ieee80211_sta *sta) 5449*bbd6d0f8SJohannes Berg { 5450*bbd6d0f8SJohannes Berg int i; 5451*bbd6d0f8SJohannes Berg 5452*bbd6d0f8SJohannes Berg for (i = 0; i < ARRAY_SIZE(sta->txq); i++) { 5453*bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq = 5454*bbd6d0f8SJohannes Berg iwl_mvm_txq_from_mac80211(sta->txq[i]); 5455*bbd6d0f8SJohannes Berg 5456*bbd6d0f8SJohannes Berg set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5457*bbd6d0f8SJohannes Berg } 5458*bbd6d0f8SJohannes Berg } 5459*bbd6d0f8SJohannes Berg 5460f6780614SSara Sharon #define IWL_MAX_CSA_BLOCK_TX 1500 5461cbce62a3SMiri Korenblit int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 5462e705c121SKalle Valo struct ieee80211_vif *vif, 5463e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 5464e705c121SKalle Valo { 5465e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5466e705c121SKalle Valo struct ieee80211_vif *csa_vif; 5467e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5468*bbd6d0f8SJohannes Berg struct iwl_mvm_txq *mvmtxq; 5469e705c121SKalle Valo int ret; 5470e705c121SKalle Valo 5471e705c121SKalle Valo mutex_lock(&mvm->mutex); 5472e705c121SKalle Valo 5473e705c121SKalle Valo mvmvif->csa_failed = false; 54742964b57fSJohannes Berg mvmvif->csa_blocks_tx = false; 5475e705c121SKalle Valo 5476e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 5477e705c121SKalle Valo chsw->chandef.center_freq1); 5478e705c121SKalle Valo 54797174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 54807174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 54817174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 5482e705c121SKalle Valo 5483e705c121SKalle Valo switch (vif->type) { 5484e705c121SKalle Valo case NL80211_IFTYPE_AP: 5485e705c121SKalle Valo csa_vif = 5486e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 5487e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5488d0a9123eSJohannes Berg if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, 5489e705c121SKalle Valo "Another CSA is already in progress")) { 5490e705c121SKalle Valo ret = -EBUSY; 5491e705c121SKalle Valo goto out_unlock; 5492e705c121SKalle Valo } 5493e705c121SKalle Valo 5494d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 5495d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 5496d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 5497d3a108a4SAndrei Otcheretianski ret = -EBUSY; 5498d3a108a4SAndrei Otcheretianski goto out_unlock; 5499d3a108a4SAndrei Otcheretianski } 5500d3a108a4SAndrei Otcheretianski 5501e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 5502e705c121SKalle Valo 5503e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 5504e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 5505e705c121SKalle Valo ret = -EBUSY; 5506e705c121SKalle Valo goto out_unlock; 5507e705c121SKalle Valo } 5508e705c121SKalle Valo 5509d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 5510d3a108a4SAndrei Otcheretianski 5511*bbd6d0f8SJohannes Berg if (!chsw->block_tx) 5512*bbd6d0f8SJohannes Berg break; 5513*bbd6d0f8SJohannes Berg /* don't need blocking in driver otherwise - mac80211 will do */ 5514*bbd6d0f8SJohannes Berg if (!ieee80211_hw_check(mvm->hw, HANDLES_QUIET_CSA)) 5515*bbd6d0f8SJohannes Berg break; 5516*bbd6d0f8SJohannes Berg 5517*bbd6d0f8SJohannes Berg mvmvif->csa_blocks_tx = true; 5518*bbd6d0f8SJohannes Berg mvmtxq = iwl_mvm_txq_from_mac80211(vif->txq); 5519*bbd6d0f8SJohannes Berg set_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA, &mvmtxq->state); 5520*bbd6d0f8SJohannes Berg ieee80211_iterate_stations_atomic(mvm->hw, 5521*bbd6d0f8SJohannes Berg iwl_mvm_csa_block_txqs, 5522*bbd6d0f8SJohannes Berg NULL); 5523e705c121SKalle Valo break; 5524e705c121SKalle Valo case NL80211_IFTYPE_STATION: 55252964b57fSJohannes Berg mvmvif->csa_blocks_tx = chsw->block_tx; 55262964b57fSJohannes Berg 55272360acbdSEmmanuel Grumbach /* 5528ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there 5529ad12b231SNathan Errera * is no need for all of this 5530ad12b231SNathan Errera */ 5531ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5532ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 5533ad12b231SNathan Errera 0)) 5534ad12b231SNathan Errera break; 5535ad12b231SNathan Errera 5536ad12b231SNathan Errera /* 55372360acbdSEmmanuel Grumbach * We haven't configured the firmware to be associated yet since 55382360acbdSEmmanuel Grumbach * we don't know the dtim period. In this case, the firmware can't 55392360acbdSEmmanuel Grumbach * track the beacons. 55402360acbdSEmmanuel Grumbach */ 5541f276e20bSJohannes Berg if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) { 55422360acbdSEmmanuel Grumbach ret = -EBUSY; 55432360acbdSEmmanuel Grumbach goto out_unlock; 55442360acbdSEmmanuel Grumbach } 55452360acbdSEmmanuel Grumbach 5546aee2eac7SJohannes Berg if (chsw->delay > IWL_MAX_CSA_BLOCK_TX && 5547aee2eac7SJohannes Berg hweight16(vif->valid_links) <= 1) 554887d9564eSJohannes Berg schedule_delayed_work(&mvmvif->csa_work, 0); 554987d9564eSJohannes Berg 5550f6780614SSara Sharon if (chsw->block_tx) { 5551f6780614SSara Sharon /* 5552f6780614SSara Sharon * In case of undetermined / long time with immediate 5553f6780614SSara Sharon * quiet monitor status to gracefully disconnect 5554f6780614SSara Sharon */ 5555f6780614SSara Sharon if (!chsw->count || 5556f6780614SSara Sharon chsw->count * vif->bss_conf.beacon_int > 5557f6780614SSara Sharon IWL_MAX_CSA_BLOCK_TX) 5558f6780614SSara Sharon schedule_delayed_work(&mvmvif->csa_work, 5559f6780614SSara Sharon msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 5560f6780614SSara Sharon } 5561e705c121SKalle Valo 55620202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 55630202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 55640202bcf0SEmmanuel Grumbach ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 5565e705c121SKalle Valo if (ret) 5566e705c121SKalle Valo goto out_unlock; 55670202bcf0SEmmanuel Grumbach } else { 556874a10252SSara Sharon iwl_mvm_schedule_client_csa(mvm, vif, chsw); 55690202bcf0SEmmanuel Grumbach } 557081b4e44eSSara Sharon 557181b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 557281b4e44eSSara Sharon mvmvif->csa_misbehave = false; 5573e705c121SKalle Valo break; 5574e705c121SKalle Valo default: 5575e705c121SKalle Valo break; 5576e705c121SKalle Valo } 5577e705c121SKalle Valo 5578e705c121SKalle Valo mvmvif->ps_disabled = true; 5579e705c121SKalle Valo 5580e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 5581e705c121SKalle Valo if (ret) 5582e705c121SKalle Valo goto out_unlock; 5583e705c121SKalle Valo 5584e705c121SKalle Valo /* we won't be on this channel any longer */ 5585e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 5586e705c121SKalle Valo 5587e705c121SKalle Valo out_unlock: 5588e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5589e705c121SKalle Valo 5590e705c121SKalle Valo return ret; 5591e705c121SKalle Valo } 5592e705c121SKalle Valo 5593cbce62a3SMiri Korenblit void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 5594c37763d2SSara Sharon struct ieee80211_vif *vif, 5595c37763d2SSara Sharon struct ieee80211_channel_switch *chsw) 5596e705c121SKalle Valo { 5597e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5598c37763d2SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5599c37763d2SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 5600c37763d2SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 5601c37763d2SSara Sharon mvmvif->color)), 5602c37763d2SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 5603c37763d2SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 5604c37763d2SSara Sharon .cs_count = chsw->count, 560577738865SSara Sharon .cs_mode = chsw->block_tx, 5606c37763d2SSara Sharon }; 5607e705c121SKalle Valo 5608ad12b231SNathan Errera /* 5609ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there is no 5610ad12b231SNathan Errera * need for all of this 5611ad12b231SNathan Errera */ 5612ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 5613ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 5614ad12b231SNathan Errera return; 5615ad12b231SNathan Errera 5616c37763d2SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 5617c37763d2SSara Sharon return; 5618e705c121SKalle Valo 5619c3eae059SGregory Greenman IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 5620c3eae059SGregory Greenman mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 5621c3eae059SGregory Greenman 562281b4e44eSSara Sharon if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 562381b4e44eSSara Sharon if (mvmvif->csa_misbehave) { 56245ecd5d82SJohannes Berg struct ieee80211_bss_conf *link_conf; 56255ecd5d82SJohannes Berg 562681b4e44eSSara Sharon /* Second time, give up on this AP*/ 56275ecd5d82SJohannes Berg 56285ecd5d82SJohannes Berg link_conf = wiphy_dereference(hw->wiphy, 56295ecd5d82SJohannes Berg vif->link_conf[chsw->link_id]); 56305ecd5d82SJohannes Berg if (WARN_ON(!link_conf)) 56315ecd5d82SJohannes Berg return; 56325ecd5d82SJohannes Berg 56335ecd5d82SJohannes Berg iwl_mvm_abort_channel_switch(hw, vif, link_conf); 5634a469a593SEmmanuel Grumbach ieee80211_chswitch_done(vif, false, 0); 563581b4e44eSSara Sharon mvmvif->csa_misbehave = false; 563681b4e44eSSara Sharon return; 5637e705c121SKalle Valo } 563881b4e44eSSara Sharon mvmvif->csa_misbehave = true; 5639e705c121SKalle Valo } 564081b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 5641e705c121SKalle Valo 5642caf46377SSara Sharon mutex_lock(&mvm->mutex); 5643caf46377SSara Sharon if (mvmvif->csa_failed) 5644caf46377SSara Sharon goto out_unlock; 5645e705c121SKalle Valo 5646c37763d2SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 5647c37763d2SSara Sharon WIDE_ID(MAC_CONF_GROUP, 5648c37763d2SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 5649caf46377SSara Sharon 0, sizeof(cmd), &cmd)); 5650caf46377SSara Sharon out_unlock: 5651caf46377SSara Sharon mutex_unlock(&mvm->mutex); 5652e705c121SKalle Valo } 5653e705c121SKalle Valo 56546110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 56556110d9e5SDavid Spinadel { 5656435d0827SSara Sharon int i; 5657435d0827SSara Sharon 565806195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 5659309c4848SLuca Coelho if (drop) { 5660309c4848SLuca Coelho mutex_lock(&mvm->mutex); 56616110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 5662d4e3a341SMordechay Goodstein iwl_mvm_flushable_queues(mvm) & queues); 5663309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 5664309c4848SLuca Coelho } else { 5665435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 5666309c4848SLuca Coelho } 5667435d0827SSara Sharon return; 5668435d0827SSara Sharon } 56696110d9e5SDavid Spinadel 56706110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 5671be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5672435d0827SSara Sharon struct ieee80211_sta *sta; 5673435d0827SSara Sharon 5674435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 56756110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 56766110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 56776110d9e5SDavid Spinadel continue; 56786110d9e5SDavid Spinadel 567906195639SSara Sharon if (drop) 5680d4e3a341SMordechay Goodstein iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 568106195639SSara Sharon else 56826110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 56836110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 56846110d9e5SDavid Spinadel } 56856110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 56866110d9e5SDavid Spinadel } 56876110d9e5SDavid Spinadel 5688cbce62a3SMiri Korenblit void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5689cbce62a3SMiri Korenblit u32 queues, bool drop) 5690e705c121SKalle Valo { 56912964b57fSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5692e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5693e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 5694e705c121SKalle Valo struct ieee80211_sta *sta; 5695d3f9cd61SJohannes Berg bool ap_sta_done = false; 5696e705c121SKalle Valo int i; 5697e705c121SKalle Valo u32 msk = 0; 5698e705c121SKalle Valo 56996110d9e5SDavid Spinadel if (!vif) { 57006110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 57016110d9e5SDavid Spinadel return; 57026110d9e5SDavid Spinadel } 57036110d9e5SDavid Spinadel 57042964b57fSJohannes Berg if (!drop && hweight16(vif->active_links) <= 1) { 57052964b57fSJohannes Berg int link_id = vif->active_links ? __ffs(vif->active_links) : 0; 57062964b57fSJohannes Berg struct ieee80211_bss_conf *link_conf; 57072964b57fSJohannes Berg 57082964b57fSJohannes Berg link_conf = wiphy_dereference(hw->wiphy, 57092964b57fSJohannes Berg vif->link_conf[link_id]); 57102964b57fSJohannes Berg if (WARN_ON(!link_conf)) 57112964b57fSJohannes Berg return; 57122964b57fSJohannes Berg if (link_conf->csa_active && mvmvif->csa_blocks_tx) 57132964b57fSJohannes Berg drop = true; 57142964b57fSJohannes Berg } 57152964b57fSJohannes Berg 571624afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 571724afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 571824afba76SLiad Kaufman 5719e705c121SKalle Valo mutex_lock(&mvm->mutex); 5720e705c121SKalle Valo 5721e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 5722be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 5723e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 5724e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 5725e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 5726e705c121SKalle Valo continue; 5727e705c121SKalle Valo 5728e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 5729e705c121SKalle Valo if (mvmsta->vif != vif) 5730e705c121SKalle Valo continue; 5731e705c121SKalle Valo 5732d3f9cd61SJohannes Berg if (sta == mvmvif->ap_sta) { 5733d3f9cd61SJohannes Berg if (ap_sta_done) 5734d3f9cd61SJohannes Berg continue; 5735d3f9cd61SJohannes Berg ap_sta_done = true; 5736d3f9cd61SJohannes Berg } 5737d3f9cd61SJohannes Berg 5738d49394a1SSara Sharon if (drop) { 573939176296SJohannes Berg if (iwl_mvm_flush_sta(mvm, mvmsta->deflink.sta_id, 574039176296SJohannes Berg mvmsta->tfd_queue_msk)) 5741d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 5742d49394a1SSara Sharon } else { 5743d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 5744d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 5745f7bd883bSJohannes Berg else /* only used for !iwl_mvm_has_new_tx_api() below */ 5746f7bd883bSJohannes Berg msk |= mvmsta->tfd_queue_msk; 5747e705c121SKalle Valo } 5748d49394a1SSara Sharon } 5749e705c121SKalle Valo 5750e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5751e705c121SKalle Valo 5752e705c121SKalle Valo /* this can take a while, and we may need/want other operations 5753e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 5754e705c121SKalle Valo */ 5755d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 5756a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 5757e705c121SKalle Valo } 5758e705c121SKalle Valo 5759a6cc6ccbSJohannes Berg void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 5760a6cc6ccbSJohannes Berg struct ieee80211_sta *sta) 5761a6cc6ccbSJohannes Berg { 576243874283SJohannes Berg struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5763a6cc6ccbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 576443874283SJohannes Berg struct iwl_mvm_link_sta *mvm_link_sta; 576543874283SJohannes Berg struct ieee80211_link_sta *link_sta; 576643874283SJohannes Berg int link_id; 5767a6cc6ccbSJohannes Berg 5768a6cc6ccbSJohannes Berg mutex_lock(&mvm->mutex); 576943874283SJohannes Berg for_each_sta_active_link(vif, sta, link_sta, link_id) { 577043874283SJohannes Berg mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_id], 5771a6cc6ccbSJohannes Berg lockdep_is_held(&mvm->mutex)); 577243874283SJohannes Berg if (!mvm_link_sta) 5773a6cc6ccbSJohannes Berg continue; 5774a6cc6ccbSJohannes Berg 577543874283SJohannes Berg if (iwl_mvm_flush_sta(mvm, mvm_link_sta->sta_id, 577639176296SJohannes Berg mvmsta->tfd_queue_msk)) 5777a6cc6ccbSJohannes Berg IWL_ERR(mvm, "flush request fail\n"); 5778a6cc6ccbSJohannes Berg } 5779a6cc6ccbSJohannes Berg mutex_unlock(&mvm->mutex); 5780a6cc6ccbSJohannes Berg } 5781a6cc6ccbSJohannes Berg 5782cbce62a3SMiri Korenblit int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 5783e705c121SKalle Valo struct survey_info *survey) 5784e705c121SKalle Valo { 5785e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5786b6e3d1baSAnjaneyulu int ret = 0; 5787b6e3d1baSAnjaneyulu u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, 5788b6e3d1baSAnjaneyulu WIDE_ID(SYSTEM_GROUP, 5789b6e3d1baSAnjaneyulu SYSTEM_STATISTICS_CMD), 5790b6e3d1baSAnjaneyulu IWL_FW_CMD_VER_UNKNOWN); 5791e705c121SKalle Valo 5792e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 5793e705c121SKalle Valo 5794e705c121SKalle Valo /* only support global statistics right now */ 5795e705c121SKalle Valo if (idx != 0) 5796e705c121SKalle Valo return -ENOENT; 5797e705c121SKalle Valo 5798280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 5799e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 5800e705c121SKalle Valo return -ENOENT; 5801e705c121SKalle Valo 5802e705c121SKalle Valo mutex_lock(&mvm->mutex); 5803e705c121SKalle Valo 5804aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 5805e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 5806e705c121SKalle Valo if (ret) 5807e705c121SKalle Valo goto out; 5808e705c121SKalle Valo } 5809e705c121SKalle Valo 5810b6e3d1baSAnjaneyulu survey->filled = SURVEY_INFO_TIME_RX | 5811b6e3d1baSAnjaneyulu SURVEY_INFO_TIME_TX; 5812e705c121SKalle Valo 5813e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 5814e705c121SKalle Valo mvm->radio_stats.rx_time; 5815e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 5816e705c121SKalle Valo 5817e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 5818e705c121SKalle Valo mvm->radio_stats.tx_time; 5819e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 5820e705c121SKalle Valo 5821b6e3d1baSAnjaneyulu /* the new fw api doesn't support the following fields */ 5822b6e3d1baSAnjaneyulu if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN) 5823b6e3d1baSAnjaneyulu goto out; 5824b6e3d1baSAnjaneyulu 5825b6e3d1baSAnjaneyulu survey->filled |= SURVEY_INFO_TIME | 5826b6e3d1baSAnjaneyulu SURVEY_INFO_TIME_SCAN; 5827b6e3d1baSAnjaneyulu survey->time = mvm->accu_radio_stats.on_time_rf + 5828b6e3d1baSAnjaneyulu mvm->radio_stats.on_time_rf; 5829b6e3d1baSAnjaneyulu do_div(survey->time, USEC_PER_MSEC); 5830b6e3d1baSAnjaneyulu 5831e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 5832e705c121SKalle Valo mvm->radio_stats.on_time_scan; 5833e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 5834e705c121SKalle Valo 5835e705c121SKalle Valo out: 5836e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5837e705c121SKalle Valo return ret; 5838e705c121SKalle Valo } 5839e705c121SKalle Valo 5840ed780545SJohannes Berg static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 5841ed780545SJohannes Berg { 584282cdbd11SMiri Korenblit u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 58437138763eSJohannes Berg u32 gi_ltf; 584482cdbd11SMiri Korenblit 584582cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 5846ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_20: 5847ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_20; 5848ed780545SJohannes Berg break; 5849ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_40: 5850ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_40; 5851ed780545SJohannes Berg break; 5852ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_80: 5853ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_80; 5854ed780545SJohannes Berg break; 5855ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_160: 5856ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_160; 5857ed780545SJohannes Berg break; 585823dcee94SJohannes Berg case RATE_MCS_CHAN_WIDTH_320: 585923dcee94SJohannes Berg rinfo->bw = RATE_INFO_BW_320; 586023dcee94SJohannes Berg break; 5861ed780545SJohannes Berg } 5862ed780545SJohannes Berg 586382cdbd11SMiri Korenblit if (format == RATE_MCS_CCK_MSK || 586482cdbd11SMiri Korenblit format == RATE_MCS_LEGACY_OFDM_MSK) { 586582cdbd11SMiri Korenblit int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 586682cdbd11SMiri Korenblit 586782cdbd11SMiri Korenblit /* add the offset needed to get to the legacy ofdm indices */ 586882cdbd11SMiri Korenblit if (format == RATE_MCS_LEGACY_OFDM_MSK) 586982cdbd11SMiri Korenblit rate += IWL_FIRST_OFDM_RATE; 587082cdbd11SMiri Korenblit 587182cdbd11SMiri Korenblit switch (rate) { 587282cdbd11SMiri Korenblit case IWL_RATE_1M_INDEX: 587382cdbd11SMiri Korenblit rinfo->legacy = 10; 587482cdbd11SMiri Korenblit break; 587582cdbd11SMiri Korenblit case IWL_RATE_2M_INDEX: 587682cdbd11SMiri Korenblit rinfo->legacy = 20; 587782cdbd11SMiri Korenblit break; 587882cdbd11SMiri Korenblit case IWL_RATE_5M_INDEX: 587982cdbd11SMiri Korenblit rinfo->legacy = 55; 588082cdbd11SMiri Korenblit break; 588182cdbd11SMiri Korenblit case IWL_RATE_11M_INDEX: 588282cdbd11SMiri Korenblit rinfo->legacy = 110; 588382cdbd11SMiri Korenblit break; 588482cdbd11SMiri Korenblit case IWL_RATE_6M_INDEX: 588582cdbd11SMiri Korenblit rinfo->legacy = 60; 588682cdbd11SMiri Korenblit break; 588782cdbd11SMiri Korenblit case IWL_RATE_9M_INDEX: 588882cdbd11SMiri Korenblit rinfo->legacy = 90; 588982cdbd11SMiri Korenblit break; 589082cdbd11SMiri Korenblit case IWL_RATE_12M_INDEX: 589182cdbd11SMiri Korenblit rinfo->legacy = 120; 589282cdbd11SMiri Korenblit break; 589382cdbd11SMiri Korenblit case IWL_RATE_18M_INDEX: 589482cdbd11SMiri Korenblit rinfo->legacy = 180; 589582cdbd11SMiri Korenblit break; 589682cdbd11SMiri Korenblit case IWL_RATE_24M_INDEX: 589782cdbd11SMiri Korenblit rinfo->legacy = 240; 589882cdbd11SMiri Korenblit break; 589982cdbd11SMiri Korenblit case IWL_RATE_36M_INDEX: 590082cdbd11SMiri Korenblit rinfo->legacy = 360; 590182cdbd11SMiri Korenblit break; 590282cdbd11SMiri Korenblit case IWL_RATE_48M_INDEX: 590382cdbd11SMiri Korenblit rinfo->legacy = 480; 590482cdbd11SMiri Korenblit break; 590582cdbd11SMiri Korenblit case IWL_RATE_54M_INDEX: 590682cdbd11SMiri Korenblit rinfo->legacy = 540; 590782cdbd11SMiri Korenblit } 590882cdbd11SMiri Korenblit return; 590982cdbd11SMiri Korenblit } 591082cdbd11SMiri Korenblit 5911ed780545SJohannes Berg rinfo->nss = u32_get_bits(rate_n_flags, 591282cdbd11SMiri Korenblit RATE_MCS_NSS_MSK) + 1; 591382cdbd11SMiri Korenblit rinfo->mcs = format == RATE_MCS_HT_MSK ? 591482cdbd11SMiri Korenblit RATE_HT_MCS_INDEX(rate_n_flags) : 591582cdbd11SMiri Korenblit u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 591682cdbd11SMiri Korenblit 59177138763eSJohannes Berg if (rate_n_flags & RATE_MCS_SGI_MSK) 59187138763eSJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 59197138763eSJohannes Berg 59207138763eSJohannes Berg switch (format) { 592123dcee94SJohannes Berg case RATE_MCS_EHT_MSK: 592223dcee94SJohannes Berg /* TODO: GI/LTF/RU. How does the firmware encode them? */ 592323dcee94SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; 592423dcee94SJohannes Berg break; 59257138763eSJohannes Berg case RATE_MCS_HE_MSK: 59267138763eSJohannes Berg gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK); 5927ed780545SJohannes Berg 5928ed780545SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 5929ed780545SJohannes Berg 593082cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 5931ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_HE_RU; 5932ed780545SJohannes Berg rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 5933ed780545SJohannes Berg } 5934ed780545SJohannes Berg 593582cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 593682cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_SU: 593782cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_EXT_SU: 5938ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5939ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5940ed780545SJohannes Berg else if (gi_ltf == 2) 5941ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 594282cdbd11SMiri Korenblit else if (gi_ltf == 3) 5943ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 594482cdbd11SMiri Korenblit else 594582cdbd11SMiri Korenblit rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5946ed780545SJohannes Berg break; 594782cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_MU: 5948ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5949ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5950ed780545SJohannes Berg else if (gi_ltf == 2) 5951ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5952ed780545SJohannes Berg else 5953ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5954ed780545SJohannes Berg break; 595582cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_TRIG: 5956ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5957ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5958ed780545SJohannes Berg else 5959ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5960ed780545SJohannes Berg break; 5961ed780545SJohannes Berg } 5962ed780545SJohannes Berg 5963ed780545SJohannes Berg if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 5964ed780545SJohannes Berg rinfo->he_dcm = 1; 59657138763eSJohannes Berg break; 59667138763eSJohannes Berg case RATE_MCS_HT_MSK: 596782cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_MCS; 59687138763eSJohannes Berg break; 59697138763eSJohannes Berg case RATE_MCS_VHT_MSK: 597082cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 59717138763eSJohannes Berg break; 5972ed780545SJohannes Berg } 5973ed780545SJohannes Berg } 5974ed780545SJohannes Berg 5975cbce62a3SMiri Korenblit void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 5976e705c121SKalle Valo struct ieee80211_vif *vif, 5977e705c121SKalle Valo struct ieee80211_sta *sta, 5978e705c121SKalle Valo struct station_info *sinfo) 5979e705c121SKalle Valo { 5980e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5981e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5982e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5983b6e3d1baSAnjaneyulu int i; 5984e705c121SKalle Valo 5985c8ee33e1SGregory Greenman if (mvmsta->deflink.avg_energy) { 5986c8ee33e1SGregory Greenman sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy; 598722d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 5988988b5968SSara Sharon } 5989988b5968SSara Sharon 5990ed780545SJohannes Berg if (iwl_mvm_has_tlc_offload(mvm)) { 5991c8ee33e1SGregory Greenman struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw; 5992ed780545SJohannes Berg 5993ed780545SJohannes Berg iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 5994ed780545SJohannes Berg sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 5995ed780545SJohannes Berg } 5996ed780545SJohannes Berg 5997e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 5998e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 5999e705c121SKalle Valo return; 6000e705c121SKalle Valo 6001f276e20bSJohannes Berg if (!vif->cfg.assoc) 6002e705c121SKalle Valo return; 6003e705c121SKalle Valo 6004e705c121SKalle Valo mutex_lock(&mvm->mutex); 6005e705c121SKalle Valo 6006c8ee33e1SGregory Greenman if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id) 6007e705c121SKalle Valo goto unlock; 6008e705c121SKalle Valo 6009e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 6010e705c121SKalle Valo goto unlock; 6011e705c121SKalle Valo 6012b6e3d1baSAnjaneyulu sinfo->rx_beacon = 0; 6013b6e3d1baSAnjaneyulu for_each_mvm_vif_valid_link(mvmvif, i) 6014b6e3d1baSAnjaneyulu sinfo->rx_beacon += mvmvif->link[i]->beacon_stats.num_beacons + 6015b6e3d1baSAnjaneyulu mvmvif->link[i]->beacon_stats.accu_num_beacons; 6016b6e3d1baSAnjaneyulu 601722d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 6018650cadb7SGregory Greenman if (mvmvif->deflink.beacon_stats.avg_signal) { 6019e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 6020650cadb7SGregory Greenman sinfo->rx_beacon_signal_avg = 6021650cadb7SGregory Greenman mvmvif->deflink.beacon_stats.avg_signal; 602222d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 6023e705c121SKalle Valo } 6024e705c121SKalle Valo unlock: 6025e705c121SKalle Valo mutex_unlock(&mvm->mutex); 6026e705c121SKalle Valo } 6027e705c121SKalle Valo 6028119c2a13SMordechay Goodstein static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 6029119c2a13SMordechay Goodstein struct ieee80211_vif *vif, 6030119c2a13SMordechay Goodstein const struct ieee80211_mlme_event *mlme) 6031119c2a13SMordechay Goodstein { 60321a81bddfSMordechay Goodstein if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 60331a81bddfSMordechay Goodstein (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 6034119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 6035119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 6036119c2a13SMordechay Goodstein NULL); 6037119c2a13SMordechay Goodstein return; 6038119c2a13SMordechay Goodstein } 6039119c2a13SMordechay Goodstein 6040119c2a13SMordechay Goodstein if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 6041119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 6042119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_DEASSOC, 6043119c2a13SMordechay Goodstein NULL); 6044119c2a13SMordechay Goodstein return; 6045119c2a13SMordechay Goodstein } 6046119c2a13SMordechay Goodstein } 6047119c2a13SMordechay Goodstein 6048e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 6049e705c121SKalle Valo struct ieee80211_vif *vif, 6050e705c121SKalle Valo const struct ieee80211_event *event) 6051e705c121SKalle Valo { 60524c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 6053e705c121SKalle Valo do { \ 60544c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 6055e705c121SKalle Valo break; \ 60567174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 6057e705c121SKalle Valo } while (0) 6058e705c121SKalle Valo 6059e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 6060e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 6061e705c121SKalle Valo 6062119c2a13SMordechay Goodstein if (iwl_trans_dbg_ini_valid(mvm->trans)) { 6063119c2a13SMordechay Goodstein iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 6064119c2a13SMordechay Goodstein return; 6065119c2a13SMordechay Goodstein } 6066119c2a13SMordechay Goodstein 60676c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 60686c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 60696c042d75SSara Sharon if (!trig) 6070e705c121SKalle Valo return; 6071e705c121SKalle Valo 6072e705c121SKalle Valo trig_mlme = (void *)trig->data; 6073e705c121SKalle Valo 6074e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 6075e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 60764c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 6077e705c121SKalle Valo "DENIED ASSOC: reason %d", 6078e705c121SKalle Valo event->u.mlme.reason); 6079e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 60804c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 6081e705c121SKalle Valo "ASSOC TIMEOUT"); 6082e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 6083e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 60844c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 6085e705c121SKalle Valo "DENIED AUTH: reason %d", 6086e705c121SKalle Valo event->u.mlme.reason); 6087e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 60884c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 6089e705c121SKalle Valo "AUTH TIMEOUT"); 6090e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 60914c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 6092e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 6093e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 60944c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 6095e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 6096e705c121SKalle Valo } 6097e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 6098e705c121SKalle Valo } 6099e705c121SKalle Valo 6100e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 6101e705c121SKalle Valo struct ieee80211_vif *vif, 6102e705c121SKalle Valo const struct ieee80211_event *event) 6103e705c121SKalle Valo { 6104e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 6105e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 6106e705c121SKalle Valo 61076c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 61086c042d75SSara Sharon FW_DBG_TRIGGER_BA); 61096c042d75SSara Sharon if (!trig) 6110e705c121SKalle Valo return; 6111e705c121SKalle Valo 6112e705c121SKalle Valo ba_trig = (void *)trig->data; 6113e705c121SKalle Valo 6114e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 6115e705c121SKalle Valo return; 6116e705c121SKalle Valo 61177174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 6118e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 6119e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 6120e705c121SKalle Valo event->u.ba.ssn); 6121e705c121SKalle Valo } 6122e705c121SKalle Valo 6123cbce62a3SMiri Korenblit void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 6124e705c121SKalle Valo struct ieee80211_vif *vif, 6125e705c121SKalle Valo const struct ieee80211_event *event) 6126e705c121SKalle Valo { 6127e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6128e705c121SKalle Valo 6129e705c121SKalle Valo switch (event->type) { 6130e705c121SKalle Valo case MLME_EVENT: 6131e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 6132e705c121SKalle Valo break; 6133e705c121SKalle Valo case BAR_RX_EVENT: 6134e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 6135e705c121SKalle Valo break; 6136e705c121SKalle Valo case BA_FRAME_TIMEOUT: 6137528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 6138528a542aSEmmanuel Grumbach event->u.ba.tid); 6139e705c121SKalle Valo break; 6140e705c121SKalle Valo default: 6141e705c121SKalle Valo break; 6142e705c121SKalle Valo } 6143e705c121SKalle Valo } 6144e705c121SKalle Valo 614587f690f5SShaul Triebitz #define SYNC_RX_QUEUE_TIMEOUT (HZ) 6146d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 61475e1688ceSJohannes Berg enum iwl_mvm_rxq_notif_type type, 61485e1688ceSJohannes Berg bool sync, 61495e1688ceSJohannes Berg const void *data, u32 size) 61500636b938SSara Sharon { 61515e1688ceSJohannes Berg struct { 61525e1688ceSJohannes Berg struct iwl_rxq_sync_cmd cmd; 61535e1688ceSJohannes Berg struct iwl_mvm_internal_rxq_notif notif; 61545e1688ceSJohannes Berg } __packed cmd = { 61555e1688ceSJohannes Berg .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 61565e1688ceSJohannes Berg .cmd.count = 61575e1688ceSJohannes Berg cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 61585e1688ceSJohannes Berg size), 61595e1688ceSJohannes Berg .notif.type = type, 61605e1688ceSJohannes Berg .notif.sync = sync, 61615e1688ceSJohannes Berg }; 61625e1688ceSJohannes Berg struct iwl_host_cmd hcmd = { 61635e1688ceSJohannes Berg .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 61645e1688ceSJohannes Berg .data[0] = &cmd, 61655e1688ceSJohannes Berg .len[0] = sizeof(cmd), 61665e1688ceSJohannes Berg .data[1] = data, 61675e1688ceSJohannes Berg .len[1] = size, 61685e1688ceSJohannes Berg .flags = sync ? 0 : CMD_ASYNC, 61695e1688ceSJohannes Berg }; 61700636b938SSara Sharon int ret; 61710636b938SSara Sharon 61725e1688ceSJohannes Berg /* size must be a multiple of DWORD */ 61735e1688ceSJohannes Berg if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 61745e1688ceSJohannes Berg return; 61750636b938SSara Sharon 6176cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 61770636b938SSara Sharon return; 61780636b938SSara Sharon 61795e1688ceSJohannes Berg if (sync) { 61805e1688ceSJohannes Berg cmd.notif.cookie = mvm->queue_sync_cookie; 61812f7a04c7SJohannes Berg mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 6182a2113cc4SNaftali Goldstein } 6183d0ff5d22SSara Sharon 61845e1688ceSJohannes Berg ret = iwl_mvm_send_cmd(mvm, &hcmd); 61850636b938SSara Sharon if (ret) { 61860636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 61870636b938SSara Sharon goto out; 61880636b938SSara Sharon } 6189d0ff5d22SSara Sharon 61905e1688ceSJohannes Berg if (sync) { 61913c514bf8SEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 61923a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 61932f7a04c7SJohannes Berg READ_ONCE(mvm->queue_sync_state) == 0 || 61940dd2b42cSJohannes Berg iwl_mvm_is_radio_hw_killed(mvm), 619587f690f5SShaul Triebitz SYNC_RX_QUEUE_TIMEOUT); 61960dd2b42cSJohannes Berg WARN_ONCE(!ret && !iwl_mvm_is_radio_hw_killed(mvm), 6197f4eedfd8SJohannes Berg "queue sync: failed to sync, state is 0x%lx, cookie %d\n", 6198f4eedfd8SJohannes Berg mvm->queue_sync_state, 6199f4eedfd8SJohannes Berg mvm->queue_sync_cookie); 62006ad04359SJohannes Berg } 62010636b938SSara Sharon 62020636b938SSara Sharon out: 62035e1688ceSJohannes Berg if (sync) { 62042f7a04c7SJohannes Berg mvm->queue_sync_state = 0; 62050636b938SSara Sharon mvm->queue_sync_cookie++; 62060636b938SSara Sharon } 62075f8a3561SJohannes Berg } 62080636b938SSara Sharon 6209cbce62a3SMiri Korenblit void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 62100636b938SSara Sharon { 62110636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 62120636b938SSara Sharon 62130636b938SSara Sharon mutex_lock(&mvm->mutex); 62145e1688ceSJohannes Berg iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 62150636b938SSara Sharon mutex_unlock(&mvm->mutex); 62160636b938SSara Sharon } 62170636b938SSara Sharon 6218cbce62a3SMiri Korenblit int 6219b73f9a4aSJohannes Berg iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 6220b73f9a4aSJohannes Berg struct ieee80211_vif *vif, 6221b73f9a4aSJohannes Berg struct cfg80211_ftm_responder_stats *stats) 6222b73f9a4aSJohannes Berg { 6223b73f9a4aSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6224b73f9a4aSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 6225b73f9a4aSJohannes Berg 6226b73f9a4aSJohannes Berg if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 6227b73f9a4aSJohannes Berg !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 6228b73f9a4aSJohannes Berg return -EINVAL; 6229b73f9a4aSJohannes Berg 6230b73f9a4aSJohannes Berg mutex_lock(&mvm->mutex); 6231b73f9a4aSJohannes Berg *stats = mvm->ftm_resp_stats; 6232b73f9a4aSJohannes Berg mutex_unlock(&mvm->mutex); 6233b73f9a4aSJohannes Berg 6234b73f9a4aSJohannes Berg stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 6235b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 6236b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_FAILED_NUM) | 6237b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_ASAP_NUM) | 6238b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 6239b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 6240b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 6241b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 6242b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 6243b73f9a4aSJohannes Berg 6244b73f9a4aSJohannes Berg return 0; 6245b73f9a4aSJohannes Berg } 6246b73f9a4aSJohannes Berg 6247cbce62a3SMiri Korenblit int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6248fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 6249fc36ffdaSJohannes Berg { 6250fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6251fc36ffdaSJohannes Berg int ret; 6252fc36ffdaSJohannes Berg 6253fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 6254fc36ffdaSJohannes Berg ret = iwl_mvm_ftm_start(mvm, vif, request); 6255fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 6256fc36ffdaSJohannes Berg 6257fc36ffdaSJohannes Berg return ret; 6258fc36ffdaSJohannes Berg } 6259fc36ffdaSJohannes Berg 6260cbce62a3SMiri Korenblit void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 6261fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 6262fc36ffdaSJohannes Berg { 6263fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6264fc36ffdaSJohannes Berg 6265fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 6266fc36ffdaSJohannes Berg iwl_mvm_ftm_abort(mvm, request); 6267fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 6268fc36ffdaSJohannes Berg } 6269fc36ffdaSJohannes Berg 6270438af969SSara Sharon static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 6271438af969SSara Sharon { 6272438af969SSara Sharon u8 protocol = ip_hdr(skb)->protocol; 6273438af969SSara Sharon 6274438af969SSara Sharon if (!IS_ENABLED(CONFIG_INET)) 6275438af969SSara Sharon return false; 6276438af969SSara Sharon 6277438af969SSara Sharon return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 6278438af969SSara Sharon } 6279438af969SSara Sharon 6280438af969SSara Sharon static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 6281438af969SSara Sharon struct sk_buff *head, 6282438af969SSara Sharon struct sk_buff *skb) 6283438af969SSara Sharon { 6284438af969SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6285438af969SSara Sharon 6286438af969SSara Sharon /* For now don't aggregate IPv6 in AMSDU */ 6287438af969SSara Sharon if (skb->protocol != htons(ETH_P_IP)) 6288438af969SSara Sharon return false; 6289438af969SSara Sharon 6290438af969SSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) 6291438af969SSara Sharon return true; 6292438af969SSara Sharon 6293438af969SSara Sharon return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 6294438af969SSara Sharon } 6295438af969SSara Sharon 6296be8897e2SAvraham Stern int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw, 6297cf85123aSAvraham Stern struct ieee80211_vif *vif, 6298cf85123aSAvraham Stern struct cfg80211_set_hw_timestamp *hwts) 6299cf85123aSAvraham Stern { 6300cf85123aSAvraham Stern struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 6301cf85123aSAvraham Stern u32 protocols = 0; 6302cf85123aSAvraham Stern int ret; 6303cf85123aSAvraham Stern 6304cf85123aSAvraham Stern /* HW timestamping is only supported for a specific station */ 6305cf85123aSAvraham Stern if (!hwts->macaddr) 6306cf85123aSAvraham Stern return -EOPNOTSUPP; 6307cf85123aSAvraham Stern 6308cf85123aSAvraham Stern if (hwts->enable) 6309cf85123aSAvraham Stern protocols = 6310cf85123aSAvraham Stern IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM; 6311cf85123aSAvraham Stern 6312cf85123aSAvraham Stern mutex_lock(&mvm->mutex); 6313cf85123aSAvraham Stern ret = iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols); 6314cf85123aSAvraham Stern mutex_unlock(&mvm->mutex); 6315cf85123aSAvraham Stern 6316cf85123aSAvraham Stern return ret; 6317cf85123aSAvraham Stern } 6318cf85123aSAvraham Stern 6319e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 6320e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 6321cfbc6c4cSSara Sharon .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 6322e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 6323e8503aecSBen Greear .get_antenna = iwl_mvm_op_get_antenna, 63244ea1ed1dSEmmanuel Grumbach .set_antenna = iwl_mvm_op_set_antenna, 6325e705c121SKalle Valo .start = iwl_mvm_mac_start, 6326e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 6327e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 6328e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 6329e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 6330e705c121SKalle Valo .config = iwl_mvm_mac_config, 6331e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 6332e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 6333e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 6334e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 6335e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 6336e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 6337e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 6338e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 6339e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 6340e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 6341e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 6342e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 6343e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 6344e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 6345e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 63466b1259d1SJohannes Berg .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 6347e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 6348e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 6349a6cc6ccbSJohannes Berg .flush_sta = iwl_mvm_mac_flush_sta, 6350e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 6351e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 6352e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 6353e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 6354e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 6355e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 6356e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 6357e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 6358e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 6359e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 6360e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 6361e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 6362e705c121SKalle Valo 6363ae7ba17bSShaul Triebitz .start_ap = iwl_mvm_start_ap, 6364ae7ba17bSShaul Triebitz .stop_ap = iwl_mvm_stop_ap, 6365ae7ba17bSShaul Triebitz .join_ibss = iwl_mvm_start_ibss, 6366ae7ba17bSShaul Triebitz .leave_ibss = iwl_mvm_stop_ibss, 6367e705c121SKalle Valo 63682f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 63692f0282dbSJohannes Berg 6370e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 6371e705c121SKalle Valo 6372e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 6373e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 6374e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 637579221126SSara Sharon .abort_channel_switch = iwl_mvm_abort_channel_switch, 6376c37763d2SSara Sharon .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 6377e705c121SKalle Valo 6378e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 6379e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 6380e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 6381e705c121SKalle Valo 6382e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 6383e705c121SKalle Valo 63840636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 63850636b938SSara Sharon 6386e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 6387e705c121SKalle Valo 6388e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 6389e705c121SKalle Valo /* look at d3.c */ 6390e705c121SKalle Valo .suspend = iwl_mvm_suspend, 6391e705c121SKalle Valo .resume = iwl_mvm_resume, 6392e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 6393e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 6394e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 6395e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 6396e705c121SKalle Valo #endif 6397e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 6398e705c121SKalle Valo #endif 6399e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 6400e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 6401b73f9a4aSJohannes Berg .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 6402fc36ffdaSJohannes Berg .start_pmsr = iwl_mvm_start_pmsr, 6403fc36ffdaSJohannes Berg .abort_pmsr = iwl_mvm_abort_pmsr, 6404b73f9a4aSJohannes Berg 6405438af969SSara Sharon .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 6406177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 6407c36235acSJohannes Berg .vif_add_debugfs = iwl_mvm_vif_add_debugfs, 64083f244876SBenjamin Berg .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs, 6409177a11cfSGregory Greenman #endif 6410cf85123aSAvraham Stern .set_hw_timestamp = iwl_mvm_set_hw_timestamp, 6411e705c121SKalle Valo }; 6412