18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28e99ea8dSJohannes Berg /* 36d19a5ebSEmmanuel Grumbach * Copyright (C) 2012-2014, 2018-2021 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 19e705c121SKalle Valo #include "iwl-op-mode.h" 20e705c121SKalle Valo #include "iwl-io.h" 21e705c121SKalle Valo #include "mvm.h" 22e705c121SKalle Valo #include "sta.h" 23e705c121SKalle Valo #include "time-event.h" 24e705c121SKalle Valo #include "iwl-eeprom-parse.h" 25e705c121SKalle Valo #include "iwl-phy-db.h" 26e705c121SKalle Valo #include "testmode.h" 27d962f9b1SJohannes Berg #include "fw/error-dump.h" 28e705c121SKalle Valo #include "iwl-prph.h" 29e705c121SKalle Valo #include "iwl-nvm-parse.h" 30e705c121SKalle Valo 31e705c121SKalle Valo static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 32e705c121SKalle Valo { 33e705c121SKalle Valo .max = 1, 34e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_STATION), 35e705c121SKalle Valo }, 36e705c121SKalle Valo { 37e705c121SKalle Valo .max = 1, 38e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_AP) | 39e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 40e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO), 41e705c121SKalle Valo }, 42e705c121SKalle Valo { 43e705c121SKalle Valo .max = 1, 44e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 45e705c121SKalle Valo }, 46e705c121SKalle Valo }; 47e705c121SKalle Valo 48e705c121SKalle Valo static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 49e705c121SKalle Valo { 50e705c121SKalle Valo .num_different_channels = 2, 51e705c121SKalle Valo .max_interfaces = 3, 52e705c121SKalle Valo .limits = iwl_mvm_limits, 53e705c121SKalle Valo .n_limits = ARRAY_SIZE(iwl_mvm_limits), 54e705c121SKalle Valo }, 55e705c121SKalle Valo }; 56e705c121SKalle Valo 57e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 58e705c121SKalle Valo /* 59e705c121SKalle Valo * Use the reserved field to indicate magic values. 60e705c121SKalle Valo * these values will only be used internally by the driver, 61e705c121SKalle Valo * and won't make it to the fw (reserved will be 0). 62e705c121SKalle Valo * BC_FILTER_MAGIC_IP - configure the val of this attribute to 63e705c121SKalle Valo * be the vif's ip address. in case there is not a single 64e705c121SKalle Valo * ip address (0, or more than 1), this attribute will 65e705c121SKalle Valo * be skipped. 66e705c121SKalle Valo * BC_FILTER_MAGIC_MAC - set the val of this attribute to 67e705c121SKalle Valo * the LSB bytes of the vif's mac address 68e705c121SKalle Valo */ 69e705c121SKalle Valo enum { 70e705c121SKalle Valo BC_FILTER_MAGIC_NONE = 0, 71e705c121SKalle Valo BC_FILTER_MAGIC_IP, 72e705c121SKalle Valo BC_FILTER_MAGIC_MAC, 73e705c121SKalle Valo }; 74e705c121SKalle Valo 75e705c121SKalle Valo static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { 76e705c121SKalle Valo { 77e705c121SKalle Valo /* arp */ 78e705c121SKalle Valo .discard = 0, 79e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, 80e705c121SKalle Valo .attrs = { 81e705c121SKalle Valo { 82e705c121SKalle Valo /* frame type - arp, hw type - ethernet */ 83e705c121SKalle Valo .offset_type = 84e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 85e705c121SKalle Valo .offset = sizeof(rfc1042_header), 86e705c121SKalle Valo .val = cpu_to_be32(0x08060001), 87e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 88e705c121SKalle Valo }, 89e705c121SKalle Valo { 90e705c121SKalle Valo /* arp dest ip */ 91e705c121SKalle Valo .offset_type = 92e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 93e705c121SKalle Valo .offset = sizeof(rfc1042_header) + 2 + 94e705c121SKalle Valo sizeof(struct arphdr) + 95e705c121SKalle Valo ETH_ALEN + sizeof(__be32) + 96e705c121SKalle Valo ETH_ALEN, 97e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 98e705c121SKalle Valo /* mark it as special field */ 99e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), 100e705c121SKalle Valo }, 101e705c121SKalle Valo }, 102e705c121SKalle Valo }, 103e705c121SKalle Valo { 104e705c121SKalle Valo /* dhcp offer bcast */ 105e705c121SKalle Valo .discard = 0, 106e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, 107e705c121SKalle Valo .attrs = { 108e705c121SKalle Valo { 109e705c121SKalle Valo /* udp dest port - 68 (bootp client)*/ 110e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 111e705c121SKalle Valo .offset = offsetof(struct udphdr, dest), 112e705c121SKalle Valo .val = cpu_to_be32(0x00440000), 113e705c121SKalle Valo .mask = cpu_to_be32(0xffff0000), 114e705c121SKalle Valo }, 115e705c121SKalle Valo { 116e705c121SKalle Valo /* dhcp - lsb bytes of client hw address */ 117e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 118e705c121SKalle Valo .offset = 38, 119e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 120e705c121SKalle Valo /* mark it as special field */ 121e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), 122e705c121SKalle Valo }, 123e705c121SKalle Valo }, 124e705c121SKalle Valo }, 125e705c121SKalle Valo /* last filter must be empty */ 126e705c121SKalle Valo {}, 127e705c121SKalle Valo }; 128e705c121SKalle Valo #endif 129e705c121SKalle Valo 130fc36ffdaSJohannes Berg static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { 131fc36ffdaSJohannes Berg .max_peers = IWL_MVM_TOF_MAX_APS, 132fc36ffdaSJohannes Berg .report_ap_tsf = 1, 133fc36ffdaSJohannes Berg .randomize_mac_addr = 1, 134fc36ffdaSJohannes Berg 135fc36ffdaSJohannes Berg .ftm = { 136fc36ffdaSJohannes Berg .supported = 1, 137fc36ffdaSJohannes Berg .asap = 1, 138fc36ffdaSJohannes Berg .non_asap = 1, 139fc36ffdaSJohannes Berg .request_lci = 1, 140fc36ffdaSJohannes Berg .request_civicloc = 1, 1416815e3d0SAvraham Stern .trigger_based = 1, 1426815e3d0SAvraham Stern .non_trigger_based = 1, 143fc36ffdaSJohannes Berg .max_bursts_exponent = -1, /* all supported */ 144fc36ffdaSJohannes Berg .max_ftms_per_burst = 0, /* no limits */ 145fc36ffdaSJohannes Berg .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 146fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_20) | 147fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_40) | 1488a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_80) | 1498a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_160), 150fc36ffdaSJohannes Berg .preambles = BIT(NL80211_PREAMBLE_LEGACY) | 151fc36ffdaSJohannes Berg BIT(NL80211_PREAMBLE_HT) | 1526815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_VHT) | 1536815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_HE), 154fc36ffdaSJohannes Berg }, 155fc36ffdaSJohannes Berg }; 156fc36ffdaSJohannes Berg 1576569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 158c56e00a3SJohannes Berg enum set_key_cmd cmd, 159c56e00a3SJohannes Berg struct ieee80211_vif *vif, 160c56e00a3SJohannes Berg struct ieee80211_sta *sta, 161c56e00a3SJohannes Berg struct ieee80211_key_conf *key); 162c56e00a3SJohannes Berg 163e705c121SKalle Valo static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 164e705c121SKalle Valo { 165e705c121SKalle Valo int i; 166e705c121SKalle Valo 167e705c121SKalle Valo memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 168e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 169e705c121SKalle Valo mvm->phy_ctxts[i].id = i; 170e705c121SKalle Valo mvm->phy_ctxts[i].ref = 0; 171e705c121SKalle Valo } 172e705c121SKalle Valo } 173e705c121SKalle Valo 174e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 175e705c121SKalle Valo const char *alpha2, 176e705c121SKalle Valo enum iwl_mcc_source src_id, 177e705c121SKalle Valo bool *changed) 178e705c121SKalle Valo { 179e705c121SKalle Valo struct ieee80211_regdomain *regd = NULL; 180e705c121SKalle Valo struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 181e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 182e705c121SKalle Valo struct iwl_mcc_update_resp *resp; 183e27c506aSGil Adam u8 resp_ver; 184e705c121SKalle Valo 185e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 186e705c121SKalle Valo 187e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 188e705c121SKalle Valo 189e705c121SKalle Valo resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 190e705c121SKalle Valo if (IS_ERR_OR_NULL(resp)) { 191e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 192e705c121SKalle Valo PTR_ERR_OR_ZERO(resp)); 1936d19a5ebSEmmanuel Grumbach resp = NULL; 194e705c121SKalle Valo goto out; 195e705c121SKalle Valo } 196e705c121SKalle Valo 19782715ac7SEmmanuel Grumbach if (changed) { 19882715ac7SEmmanuel Grumbach u32 status = le32_to_cpu(resp->status); 19982715ac7SEmmanuel Grumbach 20082715ac7SEmmanuel Grumbach *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || 20182715ac7SEmmanuel Grumbach status == MCC_RESP_ILLEGAL); 20282715ac7SEmmanuel Grumbach } 203e27c506aSGil Adam resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, 204e27c506aSGil Adam MCC_UPDATE_CMD, 0); 205e27c506aSGil Adam IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver); 206e705c121SKalle Valo 207e705c121SKalle Valo regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 208e705c121SKalle Valo __le32_to_cpu(resp->n_channels), 209e705c121SKalle Valo resp->channels, 21077e30e10SHaim Dreyfuss __le16_to_cpu(resp->mcc), 2112763bba6SHaim Dreyfuss __le16_to_cpu(resp->geo_info), 212e27c506aSGil Adam __le16_to_cpu(resp->cap), resp_ver); 213e705c121SKalle Valo /* Store the return source id */ 214e705c121SKalle Valo src_id = resp->source_id; 215e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 216e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 217e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 218e705c121SKalle Valo goto out; 219e705c121SKalle Valo } 220e705c121SKalle Valo 221e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 222e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 223e705c121SKalle Valo mvm->lar_regdom_set = true; 224e705c121SKalle Valo mvm->mcc_src = src_id; 225e705c121SKalle Valo 2266d19a5ebSEmmanuel Grumbach iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); 2276d19a5ebSEmmanuel Grumbach 228e705c121SKalle Valo out: 2296d19a5ebSEmmanuel Grumbach kfree(resp); 230e705c121SKalle Valo return regd; 231e705c121SKalle Valo } 232e705c121SKalle Valo 233e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 234e705c121SKalle Valo { 235e705c121SKalle Valo bool changed; 236e705c121SKalle Valo struct ieee80211_regdomain *regd; 237e705c121SKalle Valo 238e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 239e705c121SKalle Valo return; 240e705c121SKalle Valo 241e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 242e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 243e705c121SKalle Valo /* only update the regulatory core if changed */ 244e705c121SKalle Valo if (changed) 245e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 246e705c121SKalle Valo 247e705c121SKalle Valo kfree(regd); 248e705c121SKalle Valo } 249e705c121SKalle Valo } 250e705c121SKalle Valo 251e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 252e705c121SKalle Valo bool *changed) 253e705c121SKalle Valo { 254e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 255e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 256e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 257e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 258e705c121SKalle Valo } 259e705c121SKalle Valo 260e705c121SKalle Valo int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) 261e705c121SKalle Valo { 262e705c121SKalle Valo enum iwl_mcc_source used_src; 263e705c121SKalle Valo struct ieee80211_regdomain *regd; 264e705c121SKalle Valo int ret; 265e705c121SKalle Valo bool changed; 266e705c121SKalle Valo const struct ieee80211_regdomain *r = 267a05829a7SJohannes Berg wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); 268e705c121SKalle Valo 269e705c121SKalle Valo if (!r) 270e705c121SKalle Valo return -ENOENT; 271e705c121SKalle Valo 272e705c121SKalle Valo /* save the last source in case we overwrite it below */ 273e705c121SKalle Valo used_src = mvm->mcc_src; 274e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 275e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 276e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 277e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 278e705c121SKalle Valo kfree(regd); 279e705c121SKalle Valo } 280e705c121SKalle Valo 281e705c121SKalle Valo /* Now set our last stored MCC and source */ 282e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 283e705c121SKalle Valo &changed); 284e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 285e705c121SKalle Valo return -EIO; 286e705c121SKalle Valo 287e705c121SKalle Valo /* update cfg80211 if the regdomain was changed */ 288e705c121SKalle Valo if (changed) 289a05829a7SJohannes Berg ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); 290e705c121SKalle Valo else 291e705c121SKalle Valo ret = 0; 292e705c121SKalle Valo 293e705c121SKalle Valo kfree(regd); 294e705c121SKalle Valo return ret; 295e705c121SKalle Valo } 296e705c121SKalle Valo 2977f2ea521SYueHaibing static const u8 he_if_types_ext_capa_sta[] = { 2987360f99eSEmmanuel Grumbach [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 299918cbf39SSara Sharon [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 3007360f99eSEmmanuel Grumbach [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 3017360f99eSEmmanuel Grumbach [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT, 3027360f99eSEmmanuel Grumbach }; 3037360f99eSEmmanuel Grumbach 3047f2ea521SYueHaibing static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = { 3057360f99eSEmmanuel Grumbach { 3067360f99eSEmmanuel Grumbach .iftype = NL80211_IFTYPE_STATION, 3077360f99eSEmmanuel Grumbach .extended_capabilities = he_if_types_ext_capa_sta, 3087360f99eSEmmanuel Grumbach .extended_capabilities_mask = he_if_types_ext_capa_sta, 3097360f99eSEmmanuel Grumbach .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), 3107360f99eSEmmanuel Grumbach }, 3117360f99eSEmmanuel Grumbach }; 3127360f99eSEmmanuel Grumbach 313e8503aecSBen Greear static int 314e8503aecSBen Greear iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 315e8503aecSBen Greear { 316e8503aecSBen Greear struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 317e8503aecSBen Greear *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); 318e8503aecSBen Greear *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); 319e8503aecSBen Greear return 0; 320e8503aecSBen Greear } 321e8503aecSBen Greear 322e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 323e705c121SKalle Valo { 324e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 325e705c121SKalle Valo int num_mac, ret, i; 326e705c121SKalle Valo static const u32 mvm_ciphers[] = { 327e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 328e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 329e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 330e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 331e705c121SKalle Valo }; 3323f37c229SIdo Yariv #ifdef CONFIG_PM_SLEEP 3333f37c229SIdo Yariv bool unified = fw_has_capa(&mvm->fw->ucode_capa, 3343f37c229SIdo Yariv IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); 3353f37c229SIdo Yariv #endif 336e705c121SKalle Valo 337e705c121SKalle Valo /* Tell mac80211 our characteristics */ 338e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 339e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 340e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 341e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 342e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 343e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 344e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 345e705c121SKalle Valo ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 346e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 347e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 348e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 349e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 350909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 35130433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 352d270e7b8SIlan Peer ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 353520229e4SShaul Triebitz ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 354cfbc6c4cSSara Sharon ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); 355cfbc6c4cSSara Sharon ieee80211_hw_set(hw, STA_MMPDU_TXQ); 356cfb21b11SJohannes Berg /* 357cfb21b11SJohannes Berg * On older devices, enabling TX A-MSDU occasionally leads to 358cfb21b11SJohannes Berg * something getting messed up, the command read from the FIFO 359cfb21b11SJohannes Berg * gets out of sync and isn't a TX command, so that we have an 360cfb21b11SJohannes Berg * assert EDC. 361cfb21b11SJohannes Berg * 362cfb21b11SJohannes Berg * It's not clear where the bug is, but since we didn't used to 363cfb21b11SJohannes Berg * support A-MSDU until moving the mac80211 iTXQs, just leave it 364cfb21b11SJohannes Berg * for older devices. We also don't see this issue on any newer 365cfb21b11SJohannes Berg * devices. 366cfb21b11SJohannes Berg */ 3677d34a7d7SLuca Coelho if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) 368438af969SSara Sharon ieee80211_hw_set(hw, TX_AMSDU); 369438af969SSara Sharon ieee80211_hw_set(hw, TX_FRAG_LIST); 370ecaf71deSGregory Greenman 3714243edb4SEmmanuel Grumbach if (iwl_mvm_has_tlc_offload(mvm)) { 372ecaf71deSGregory Greenman ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 373ecaf71deSGregory Greenman ieee80211_hw_set(hw, HAS_RATE_CONTROL); 374ecaf71deSGregory Greenman } 375ecaf71deSGregory Greenman 376b915c101SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 377b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 378960f864bSJohannes Berg 379960f864bSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 380960f864bSJohannes Berg IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 38165e25482SJohannes Berg ieee80211_hw_set(hw, AP_LINK_PS); 382960f864bSJohannes Berg } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 383960f864bSJohannes Berg /* 384960f864bSJohannes Berg * we absolutely need this for the new TX API since that comes 385960f864bSJohannes Berg * with many more queues than the current code can deal with 386960f864bSJohannes Berg * for station powersave 387960f864bSJohannes Berg */ 388960f864bSJohannes Berg return -EINVAL; 389960f864bSJohannes Berg } 390e705c121SKalle Valo 39180938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 39280938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 39380938abcSJohannes Berg 3942d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 3952d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 3962d7cf549SJohannes Berg 397366fc672SJohannes Berg hw->queues = IEEE80211_NUM_ACS; 398e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 399e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 400e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 401e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 402e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 403371a17edSJohannes Berg 404371a17edSJohannes Berg hw->radiotap_timestamp.units_pos = 405371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 406371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 407371a17edSJohannes Berg /* this is the case for CCK frames, it's better (only 8) for OFDM */ 408371a17edSJohannes Berg hw->radiotap_timestamp.accuracy = 22; 409371a17edSJohannes Berg 4104243edb4SEmmanuel Grumbach if (!iwl_mvm_has_tlc_offload(mvm)) 4119f66a397SGregory Greenman hw->rate_control_algorithm = RS_NAME; 4129f66a397SGregory Greenman 413e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 414e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 415438af969SSara Sharon hw->max_tx_fragments = mvm->trans->max_skb_frags; 416e705c121SKalle Valo 4178e160ab8SAyala Beker BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 418e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 419e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 420e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 421e705c121SKalle Valo 4222a53d166SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4232a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4242a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP; 4252a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4262a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4272a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP_256; 4282a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4292a53d166SAyala Beker } 4302a53d166SAyala Beker 431f4bfdc5eSEmmanuel Grumbach if (iwlwifi_mod_params.swcrypto) 432f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 433f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); 434f4bfdc5eSEmmanuel Grumbach if (!iwlwifi_mod_params.bt_coex_active) 435f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 436f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); 437f4bfdc5eSEmmanuel Grumbach 438e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 439f4bfdc5eSEmmanuel Grumbach mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; 440e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 4418e160ab8SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4428e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4438e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_128; 4448e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4458e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4468e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_256; 4478e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4488e160ab8SAyala Beker } 449e705c121SKalle Valo 450e705c121SKalle Valo /* currently FW API supports only one optional cipher scheme */ 451e705c121SKalle Valo if (mvm->fw->cs[0].cipher) { 45224ddddf3SJohannes Berg const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0]; 45324ddddf3SJohannes Berg struct ieee80211_cipher_scheme *cs = &mvm->cs[0]; 45424ddddf3SJohannes Berg 455e705c121SKalle Valo mvm->hw->n_cipher_schemes = 1; 45624ddddf3SJohannes Berg 45724ddddf3SJohannes Berg cs->cipher = le32_to_cpu(fwcs->cipher); 45824ddddf3SJohannes Berg cs->iftype = BIT(NL80211_IFTYPE_STATION); 45924ddddf3SJohannes Berg cs->hdr_len = fwcs->hdr_len; 46024ddddf3SJohannes Berg cs->pn_len = fwcs->pn_len; 46124ddddf3SJohannes Berg cs->pn_off = fwcs->pn_off; 46224ddddf3SJohannes Berg cs->key_idx_off = fwcs->key_idx_off; 46324ddddf3SJohannes Berg cs->key_idx_mask = fwcs->key_idx_mask; 46424ddddf3SJohannes Berg cs->key_idx_shift = fwcs->key_idx_shift; 46524ddddf3SJohannes Berg cs->mic_len = fwcs->mic_len; 46624ddddf3SJohannes Berg 46724ddddf3SJohannes Berg mvm->hw->cipher_schemes = mvm->cs; 46824ddddf3SJohannes Berg mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher; 469e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 470e705c121SKalle Valo } 471e705c121SKalle Valo 472b73f9a4aSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 473fc36ffdaSJohannes Berg IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { 474b73f9a4aSJohannes Berg wiphy_ext_feature_set(hw->wiphy, 475b73f9a4aSJohannes Berg NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); 476fc36ffdaSJohannes Berg hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; 477fc36ffdaSJohannes Berg } 478b73f9a4aSJohannes Berg 479b1fdc250SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 480b1fdc250SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) 481b1fdc250SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 482b1fdc250SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); 483b1fdc250SJohannes Berg 484e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 485e705c121SKalle Valo hw->wiphy->features |= 486e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 487e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 488e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 489e705c121SKalle Valo 490e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 491e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 492e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 493cfbc6c4cSSara Sharon hw->txq_data_size = sizeof(struct iwl_mvm_txq); 494e705c121SKalle Valo 495e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 496e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 497e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 498e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 499e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 500e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 501e705c121SKalle Valo 502e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 503e47df5bdSJohannes Berg wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 50433e3fd99SAlexander Wetzel 50533e3fd99SAlexander Wetzel /* The new Tx API does not allow to pass the key or keyid of a MPDU to 50633e3fd99SAlexander Wetzel * the hw, preventing us to control which key(id) to use per MPDU. 50733e3fd99SAlexander Wetzel * Till that's fixed we can't use Extended Key ID for the newer cards. 50833e3fd99SAlexander Wetzel */ 50933e3fd99SAlexander Wetzel if (!iwl_mvm_has_new_tx_api(mvm)) 51033e3fd99SAlexander Wetzel wiphy_ext_feature_set(hw->wiphy, 51133e3fd99SAlexander Wetzel NL80211_EXT_FEATURE_EXT_KEY_ID); 512e47df5bdSJohannes Berg hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; 513e47df5bdSJohannes Berg 514e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 515e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 516e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 517e705c121SKalle Valo else 518e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 519e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 520e705c121SKalle Valo 521e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 522e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 523eae94cf8SLuca Coelho hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; 524e705c121SKalle Valo 525e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 526e705c121SKalle Valo hw->wiphy->n_iface_combinations = 527e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 528e705c121SKalle Valo 529e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 530e705c121SKalle Valo hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 531e705c121SKalle Valo 532e705c121SKalle Valo /* Extract MAC address */ 533e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 534e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 535e705c121SKalle Valo hw->wiphy->n_addresses = 1; 536e705c121SKalle Valo 537e705c121SKalle Valo /* Extract additional MAC addresses if available */ 538e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 539e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 540e705c121SKalle Valo 541e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 542e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 543e705c121SKalle Valo ETH_ALEN); 544e705c121SKalle Valo mvm->addresses[i].addr[5]++; 545e705c121SKalle Valo hw->wiphy->n_addresses++; 546e705c121SKalle Valo } 547e705c121SKalle Valo 548e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 549e705c121SKalle Valo 550e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 551e705c121SKalle Valo 552e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 553e705c121SKalle Valo 554e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 555e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 556e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 557e705c121SKalle Valo 558e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 559e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 560e705c121SKalle Valo else 561e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 562e705c121SKalle Valo 56357fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 56457fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 56557fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 56657fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 56757fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 56857fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 569e705c121SKalle Valo 570e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 571e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 572e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 573e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 57457fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 575e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 576e705c121SKalle Valo } 577eae94cf8SLuca Coelho if (fw_has_capa(&mvm->fw->ucode_capa, 578eae94cf8SLuca Coelho IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && 579eae94cf8SLuca Coelho mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) 580eae94cf8SLuca Coelho hw->wiphy->bands[NL80211_BAND_6GHZ] = 581eae94cf8SLuca Coelho &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; 582e705c121SKalle Valo 583e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 584e705c121SKalle Valo 585e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 586e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 587e705c121SKalle Valo else 588e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 589e705c121SKalle Valo 590ca986ad9SArend Van Spriel hw->wiphy->max_sched_scan_reqs = 1; 591e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 5925d1234baSTova Mussai hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); 593e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 594e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 595e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 596e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 597e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 598e705c121SKalle Valo 599e705c121SKalle Valo /* 600e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 601e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 602e705c121SKalle Valo */ 603e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 604e705c121SKalle Valo 605e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 606e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 607e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 608a904a08bSPeer, Ilan NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 609e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 610e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 611e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 612e705c121SKalle Valo 613e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 614e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 615e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 616e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 617e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 618e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 619e705c121SKalle Valo 620e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 621e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 622e705c121SKalle Valo hw->wiphy->features |= 623e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 624e705c121SKalle Valo 625e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 626e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 627e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 628e705c121SKalle Valo 6292a42aea7SNathan Errera if (iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, 6302a42aea7SNathan Errera WOWLAN_KEK_KCK_MATERIAL, 6312a42aea7SNathan Errera IWL_FW_CMD_VER_UNKNOWN) == 3) 6322a42aea7SNathan Errera hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; 6332a42aea7SNathan Errera 634aacf8f18SAvrahams Stern if (fw_has_api(&mvm->fw->ucode_capa, 635aacf8f18SAvrahams Stern IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 636aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 637aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SCAN_START_TIME); 638aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 639aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_BSS_PARENT_TSF); 640aacf8f18SAvrahams Stern } 641aacf8f18SAvrahams Stern 6428f691af9SZamir, Roee if (iwl_mvm_is_oce_supported(mvm)) { 6438f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6448f691af9SZamir, Roee NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 6458f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6468f691af9SZamir, Roee NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 6478f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6488f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 6498f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6508f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 6518f691af9SZamir, Roee } 6528f691af9SZamir, Roee 6537360f99eSEmmanuel Grumbach if (mvm->nvm_data->sku_cap_11ax_enable && 6547360f99eSEmmanuel Grumbach !iwlwifi_mod_params.disable_11ax) { 6557360f99eSEmmanuel Grumbach hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa; 6567360f99eSEmmanuel Grumbach hw->wiphy->num_iftype_ext_capab = 6577360f99eSEmmanuel Grumbach ARRAY_SIZE(he_iftypes_ext_capa); 658918cbf39SSara Sharon 659918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 660918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 6617360f99eSEmmanuel Grumbach } 6627360f99eSEmmanuel Grumbach 663e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 664e705c121SKalle Valo 665e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 6663f37c229SIdo Yariv if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 667e705c121SKalle Valo mvm->trans->ops->d3_suspend && 668e705c121SKalle Valo mvm->trans->ops->d3_resume && 669e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 670e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 671e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 672e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 673e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 674e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 675e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 676e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 677e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 678e705c121SKalle Valo 679e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 680e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 681e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 6825d1234baSTova Mussai mvm->wowlan.max_nd_match_sets = 6835d1234baSTova Mussai iwl_umac_scan_get_max_profiles(mvm->fw); 684e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 685e705c121SKalle Valo } 686e705c121SKalle Valo #endif 687e705c121SKalle Valo 688e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 689e705c121SKalle Valo /* assign default bcast filtering configuration */ 690e705c121SKalle Valo mvm->bcast_filters = iwl_mvm_default_bcast_filters; 691e705c121SKalle Valo #endif 692e705c121SKalle Valo 693e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 694e705c121SKalle Valo if (ret) 695e705c121SKalle Valo return ret; 696e705c121SKalle Valo 697e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 698e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 699e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 700e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 701e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 702e705c121SKalle Valo } 703e705c121SKalle Valo 704e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 705e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 706e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 707e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 708e705c121SKalle Valo } 709e705c121SKalle Valo 710e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 71159fa61f3SEmmanuel Grumbach if (!iwl_mvm_is_csum_supported(mvm)) 7125e6a98dcSSara Sharon hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS | 7135e6a98dcSSara Sharon NETIF_F_RXCSUM); 71441837ca9SEmmanuel Grumbach 71591b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 71691b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 71791b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 71891b08c2dSAviya Erenfeld 7199c11d8a9SShaul Triebitz if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 7209c11d8a9SShaul Triebitz wiphy_ext_feature_set(hw->wiphy, 7219c11d8a9SShaul Triebitz NL80211_EXT_FEATURE_PROTECTED_TWT); 7229c11d8a9SShaul Triebitz 723bfcfdb59SEmmanuel Grumbach iwl_mvm_vendor_cmds_register(mvm); 724bfcfdb59SEmmanuel Grumbach 725e8503aecSBen Greear hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 726e8503aecSBen Greear hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 727e8503aecSBen Greear 728de645e89SJohannes Berg ret = ieee80211_register_hw(mvm->hw); 729de645e89SJohannes Berg if (ret) { 730de645e89SJohannes Berg iwl_mvm_leds_exit(mvm); 731e705c121SKalle Valo } 732e705c121SKalle Valo 733e705c121SKalle Valo return ret; 734e705c121SKalle Valo } 735e705c121SKalle Valo 736df2378abSJohannes Berg static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 737df2378abSJohannes Berg struct ieee80211_sta *sta) 738df2378abSJohannes Berg { 739df2378abSJohannes Berg if (likely(sta)) { 740df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 741df2378abSJohannes Berg return; 742df2378abSJohannes Berg } else { 743df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 744df2378abSJohannes Berg return; 745df2378abSJohannes Berg } 746df2378abSJohannes Berg 747df2378abSJohannes Berg ieee80211_free_txskb(mvm->hw, skb); 748df2378abSJohannes Berg } 749df2378abSJohannes Berg 750e705c121SKalle Valo static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 751e705c121SKalle Valo struct ieee80211_tx_control *control, 752e705c121SKalle Valo struct sk_buff *skb) 753e705c121SKalle Valo { 754e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 755e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 756e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 757e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 758cfbc6c4cSSara Sharon bool offchannel = IEEE80211_SKB_CB(skb)->flags & 759cfbc6c4cSSara Sharon IEEE80211_TX_CTL_TX_OFFCHAN; 760e705c121SKalle Valo 761e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 762e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 763e705c121SKalle Valo goto drop; 764e705c121SKalle Valo } 765e705c121SKalle Valo 766cfbc6c4cSSara Sharon if (offchannel && 767e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 768e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 769e705c121SKalle Valo goto drop; 770e705c121SKalle Valo 77110516783SJohannes Berg /* 77210516783SJohannes Berg * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 77310516783SJohannes Berg * so we treat the others as broadcast 77410516783SJohannes Berg */ 77510516783SJohannes Berg if (ieee80211_is_mgmt(hdr->frame_control)) 776e705c121SKalle Valo sta = NULL; 777e705c121SKalle Valo 778dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 779cfbc6c4cSSara Sharon if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 780cfbc6c4cSSara Sharon !offchannel) { 781dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 782dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 783dc1aca22SAndrei Otcheretianski u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id); 784dc1aca22SAndrei Otcheretianski 785be9ae34eSNathan Errera if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 786dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 787dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 788dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 789dc1aca22SAndrei Otcheretianski goto drop; 790dc1aca22SAndrei Otcheretianski } 791dc1aca22SAndrei Otcheretianski } 792dc1aca22SAndrei Otcheretianski 793df2378abSJohannes Berg iwl_mvm_tx_skb(mvm, skb, sta); 794e705c121SKalle Valo return; 795e705c121SKalle Valo drop: 796e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 797e705c121SKalle Valo } 798e705c121SKalle Valo 799cfbc6c4cSSara Sharon void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 800e705c121SKalle Valo { 801cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 802cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 803cfbc6c4cSSara Sharon struct sk_buff *skb = NULL; 804cfbc6c4cSSara Sharon 805fba8248eSSara Sharon /* 806fba8248eSSara Sharon * No need for threads to be pending here, they can leave the first 807fba8248eSSara Sharon * taker all the work. 808fba8248eSSara Sharon * 809fba8248eSSara Sharon * mvmtxq->tx_request logic: 810fba8248eSSara Sharon * 811fba8248eSSara Sharon * If 0, no one is currently TXing, set to 1 to indicate current thread 812fba8248eSSara Sharon * will now start TX and other threads should quit. 813fba8248eSSara Sharon * 814fba8248eSSara Sharon * If 1, another thread is currently TXing, set to 2 to indicate to 815fba8248eSSara Sharon * that thread that there was another request. Since that request may 816fba8248eSSara Sharon * have raced with the check whether the queue is empty, the TXing 817fba8248eSSara Sharon * thread should check the queue's status one more time before leaving. 818fba8248eSSara Sharon * This check is done in order to not leave any TX hanging in the queue 819fba8248eSSara Sharon * until the next TX invocation (which may not even happen). 820fba8248eSSara Sharon * 821fba8248eSSara Sharon * If 2, another thread is currently TXing, and it will already double 822fba8248eSSara Sharon * check the queue, so do nothing. 823fba8248eSSara Sharon */ 824fba8248eSSara Sharon if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 825fba8248eSSara Sharon return; 826cfbc6c4cSSara Sharon 827cfbc6c4cSSara Sharon rcu_read_lock(); 828fba8248eSSara Sharon do { 829cfbc6c4cSSara Sharon while (likely(!mvmtxq->stopped && 83000520b7aSEmmanuel Grumbach !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 831cfbc6c4cSSara Sharon skb = ieee80211_tx_dequeue(hw, txq); 832cfbc6c4cSSara Sharon 833f50d693bSSara Sharon if (!skb) { 834f50d693bSSara Sharon if (txq->sta) 835f50d693bSSara Sharon IWL_DEBUG_TX(mvm, 836f50d693bSSara Sharon "TXQ of sta %pM tid %d is now empty\n", 837f50d693bSSara Sharon txq->sta->addr, 838f50d693bSSara Sharon txq->tid); 839cfbc6c4cSSara Sharon break; 840f50d693bSSara Sharon } 841cfbc6c4cSSara Sharon 842cfbc6c4cSSara Sharon iwl_mvm_tx_skb(mvm, skb, txq->sta); 843cfbc6c4cSSara Sharon } 844fba8248eSSara Sharon } while (atomic_dec_return(&mvmtxq->tx_request)); 845cfbc6c4cSSara Sharon rcu_read_unlock(); 846e705c121SKalle Valo } 847e705c121SKalle Valo 848cfbc6c4cSSara Sharon static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 849cfbc6c4cSSara Sharon struct ieee80211_txq *txq) 850e705c121SKalle Valo { 851cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 852cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 853e705c121SKalle Valo 854cfbc6c4cSSara Sharon /* 855cfbc6c4cSSara Sharon * Please note that racing is handled very carefully here: 856cfbc6c4cSSara Sharon * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is 857cfbc6c4cSSara Sharon * deleted afterwards. 858cfbc6c4cSSara Sharon * This means that if: 859cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list): 860cfbc6c4cSSara Sharon * queue is allocated and we can TX. 861cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list): 862cfbc6c4cSSara Sharon * a race, should defer the frame. 863cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list): 864cfbc6c4cSSara Sharon * need to allocate the queue and defer the frame. 865cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list): 866cfbc6c4cSSara Sharon * queue is already scheduled for allocation, no need to allocate, 867cfbc6c4cSSara Sharon * should defer the frame. 868cfbc6c4cSSara Sharon */ 869cfbc6c4cSSara Sharon 870cfbc6c4cSSara Sharon /* If the queue is allocated TX and return. */ 871cfbc6c4cSSara Sharon if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) { 872cfbc6c4cSSara Sharon /* 873cfbc6c4cSSara Sharon * Check that list is empty to avoid a race where txq_id is 874cfbc6c4cSSara Sharon * already updated, but the queue allocation work wasn't 875cfbc6c4cSSara Sharon * finished 876cfbc6c4cSSara Sharon */ 877cfbc6c4cSSara Sharon if (unlikely(txq->sta && !list_empty(&mvmtxq->list))) 878cfbc6c4cSSara Sharon return; 879cfbc6c4cSSara Sharon 880cfbc6c4cSSara Sharon iwl_mvm_mac_itxq_xmit(hw, txq); 881cfbc6c4cSSara Sharon return; 882cfbc6c4cSSara Sharon } 883cfbc6c4cSSara Sharon 884cfbc6c4cSSara Sharon /* The list is being deleted only after the queue is fully allocated. */ 885cfbc6c4cSSara Sharon if (!list_empty(&mvmtxq->list)) 886cfbc6c4cSSara Sharon return; 887cfbc6c4cSSara Sharon 888cfbc6c4cSSara Sharon list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 889cfbc6c4cSSara Sharon schedule_work(&mvm->add_stream_wk); 890e705c121SKalle Valo } 891e705c121SKalle Valo 892e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 893e705c121SKalle Valo do { \ 894e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 895e705c121SKalle Valo break; \ 8967174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 897e705c121SKalle Valo } while (0) 898e705c121SKalle Valo 899e705c121SKalle Valo static void 900e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 901e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 902e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 903e705c121SKalle Valo { 904e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 905e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 906e705c121SKalle Valo 9076c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 9086c042d75SSara Sharon FW_DBG_TRIGGER_BA); 9096c042d75SSara Sharon if (!trig) 910e705c121SKalle Valo return; 911e705c121SKalle Valo 912e705c121SKalle Valo ba_trig = (void *)trig->data; 913e705c121SKalle Valo 914e705c121SKalle Valo switch (action) { 915e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 916e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 917e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 918e705c121SKalle Valo 919e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 920e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 921e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 922e705c121SKalle Valo break; 923e705c121SKalle Valo } 924e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 925e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 926e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 927e705c121SKalle Valo sta->addr, tid); 928e705c121SKalle Valo break; 929e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 930e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 931e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 932e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 933e705c121SKalle Valo break; 934e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 935e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 936e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 937e705c121SKalle Valo sta->addr, tid); 938e705c121SKalle Valo break; 939e705c121SKalle Valo default: 940e705c121SKalle Valo break; 941e705c121SKalle Valo } 942e705c121SKalle Valo } 943e705c121SKalle Valo 944e705c121SKalle Valo static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 945e705c121SKalle Valo struct ieee80211_vif *vif, 94650ea05efSSara Sharon struct ieee80211_ampdu_params *params) 947e705c121SKalle Valo { 948e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 949e705c121SKalle Valo int ret; 95050ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 95150ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 95250ea05efSSara Sharon u16 tid = params->tid; 95350ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 954514c3069SLuca Coelho u16 buf_size = params->buf_size; 955bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 95610b2b201SSara Sharon u16 timeout = params->timeout; 957e705c121SKalle Valo 958e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 959e705c121SKalle Valo sta->addr, tid, action); 960e705c121SKalle Valo 961e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 962e705c121SKalle Valo return -EACCES; 963e705c121SKalle Valo 964e705c121SKalle Valo mutex_lock(&mvm->mutex); 965e705c121SKalle Valo 966e705c121SKalle Valo switch (action) { 967e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 968b0ffe455SJohannes Berg if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id == 969b0ffe455SJohannes Berg iwl_mvm_sta_from_mac80211(sta)->sta_id) { 970b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 971b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 972b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 973b0ffe455SJohannes Berg 974b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 975b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 976b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 977b0ffe455SJohannes Berg } 978e78da25eSJohannes Berg if (!iwl_enable_rx_ampdu()) { 979e705c121SKalle Valo ret = -EINVAL; 980e705c121SKalle Valo break; 981e705c121SKalle Valo } 98210b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 98310b2b201SSara Sharon timeout); 984e705c121SKalle Valo break; 985e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 98610b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 98710b2b201SSara Sharon timeout); 988e705c121SKalle Valo break; 989e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 990e78da25eSJohannes Berg if (!iwl_enable_tx_ampdu()) { 991e705c121SKalle Valo ret = -EINVAL; 992e705c121SKalle Valo break; 993e705c121SKalle Valo } 994e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 995e705c121SKalle Valo break; 996e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 997e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 998e705c121SKalle Valo break; 999e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 1000e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 1001e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 1002e705c121SKalle Valo break; 1003e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 1004bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 1005bb81bb68SEmmanuel Grumbach buf_size, amsdu); 1006e705c121SKalle Valo break; 1007e705c121SKalle Valo default: 1008e705c121SKalle Valo WARN_ON_ONCE(1); 1009e705c121SKalle Valo ret = -EINVAL; 1010e705c121SKalle Valo break; 1011e705c121SKalle Valo } 1012e705c121SKalle Valo 1013e705c121SKalle Valo if (!ret) { 1014e705c121SKalle Valo u16 rx_ba_ssn = 0; 1015e705c121SKalle Valo 1016e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 1017e705c121SKalle Valo rx_ba_ssn = *ssn; 1018e705c121SKalle Valo 1019e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 1020e705c121SKalle Valo rx_ba_ssn, action); 1021e705c121SKalle Valo } 1022e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1023e705c121SKalle Valo 1024e705c121SKalle Valo return ret; 1025e705c121SKalle Valo } 1026e705c121SKalle Valo 1027e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 1028e705c121SKalle Valo struct ieee80211_vif *vif) 1029e705c121SKalle Valo { 1030e705c121SKalle Valo struct iwl_mvm *mvm = data; 1031e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1032e705c121SKalle Valo 1033e705c121SKalle Valo mvmvif->uploaded = false; 10340ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 1035e705c121SKalle Valo 1036e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 1037e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 1038e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 1039e705c121SKalle Valo 1040e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1041e705c121SKalle Valo memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 104286e177d8SGregory Greenman memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data)); 1043e705c121SKalle Valo } 1044e705c121SKalle Valo 1045e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1046e705c121SKalle Valo { 1047fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1048e705c121SKalle Valo 10499bf13beeSJohannes Berg mvm->cur_aid = 0; 10509bf13beeSJohannes Berg 1051e705c121SKalle Valo mvm->scan_status = 0; 1052e705c121SKalle Valo mvm->ps_disabled = false; 1053b3500b47SEmmanuel Grumbach mvm->rfkill_safe_init_done = false; 1054e705c121SKalle Valo 1055e705c121SKalle Valo /* just in case one was running */ 1056305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 1057e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 1058e705c121SKalle Valo 1059fc36ffdaSJohannes Berg iwl_mvm_ftm_restart(mvm); 1060fc36ffdaSJohannes Berg 1061e705c121SKalle Valo /* 1062e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 1063e705c121SKalle Valo * gone down during the HW restart 1064e705c121SKalle Valo */ 1065e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1066e705c121SKalle Valo 1067e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1068e705c121SKalle Valo 1069e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 10709c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1071e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1072e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1073e705c121SKalle Valo 1074e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1075e705c121SKalle Valo 1076e705c121SKalle Valo mvm->vif_count = 0; 1077e705c121SKalle Valo mvm->rx_ba_sessions = 0; 10787174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 1079baf41bc3SShaul Triebitz mvm->monitor_on = false; 1080e705c121SKalle Valo 1081e705c121SKalle Valo /* keep statistics ticking */ 1082e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1083e705c121SKalle Valo } 1084e705c121SKalle Valo 1085e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1086e705c121SKalle Valo { 1087e705c121SKalle Valo int ret; 1088e705c121SKalle Valo 1089e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1090e705c121SKalle Valo 10916d19a5ebSEmmanuel Grumbach ret = iwl_mvm_mei_get_ownership(mvm); 10926d19a5ebSEmmanuel Grumbach if (ret) 10936d19a5ebSEmmanuel Grumbach return ret; 10946d19a5ebSEmmanuel Grumbach 10956d19a5ebSEmmanuel Grumbach if (mvm->mei_nvm_data) { 10966d19a5ebSEmmanuel Grumbach /* We got the NIC, we can now free the MEI NVM data */ 10976d19a5ebSEmmanuel Grumbach kfree(mvm->mei_nvm_data); 10986d19a5ebSEmmanuel Grumbach mvm->mei_nvm_data = NULL; 10996d19a5ebSEmmanuel Grumbach 11006d19a5ebSEmmanuel Grumbach /* 11016d19a5ebSEmmanuel Grumbach * We can't free the nvm_data we allocated based on the SAP 11026d19a5ebSEmmanuel Grumbach * data because we registered to cfg80211 with the channels 11036d19a5ebSEmmanuel Grumbach * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 11046d19a5ebSEmmanuel Grumbach * just in order to be able free it later. 11056d19a5ebSEmmanuel Grumbach * NULLify nvm_data so that we will read the NVM from the 11066d19a5ebSEmmanuel Grumbach * firmware this time. 11076d19a5ebSEmmanuel Grumbach */ 11086d19a5ebSEmmanuel Grumbach mvm->temp_nvm_data = mvm->nvm_data; 11096d19a5ebSEmmanuel Grumbach mvm->nvm_data = NULL; 11106d19a5ebSEmmanuel Grumbach } 11116d19a5ebSEmmanuel Grumbach 1112bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1113bf8b286fSJohannes Berg /* 1114bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1115bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1116bf8b286fSJohannes Berg */ 1117bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1118bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1119e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1120e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1121a42b2af3SLuca Coelho } 1122e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1123e705c121SKalle Valo 1124b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1125b108d8c7SShahar S Matityahu NULL); 1126b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1127b108d8c7SShahar S Matityahu NULL); 1128da2eb669SSara Sharon 1129e8fe3b41SIlan Peer mvm->last_reset_or_resume_time_jiffies = jiffies; 1130e8fe3b41SIlan Peer 1131e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1132e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1133e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1134e705c121SKalle Valo * would do. 1135e705c121SKalle Valo */ 1136e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1137e705c121SKalle Valo } 1138e705c121SKalle Valo 1139e705c121SKalle Valo return ret; 1140e705c121SKalle Valo } 1141e705c121SKalle Valo 1142e705c121SKalle Valo static int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1143e705c121SKalle Valo { 1144e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1145e705c121SKalle Valo int ret; 1146e705c121SKalle Valo 1147e705c121SKalle Valo mutex_lock(&mvm->mutex); 1148e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 1149e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1150e705c121SKalle Valo 11517ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 11527ce1f215SEmmanuel Grumbach 1153e705c121SKalle Valo return ret; 1154e705c121SKalle Valo } 1155e705c121SKalle Valo 1156e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1157e705c121SKalle Valo { 1158e705c121SKalle Valo int ret; 1159e705c121SKalle Valo 1160e705c121SKalle Valo mutex_lock(&mvm->mutex); 1161e705c121SKalle Valo 1162e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 11634d4183c4SEmmanuel Grumbach 1164e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1165e705c121SKalle Valo if (ret) 1166e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1167e705c121SKalle Valo ret); 1168e705c121SKalle Valo 1169f130bb75SMordechay Goodstein iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1170f130bb75SMordechay Goodstein 1171e705c121SKalle Valo /* 1172e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1173e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1174e705c121SKalle Valo */ 1175e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1176e705c121SKalle Valo 1177e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1178e705c121SKalle Valo } 1179e705c121SKalle Valo 1180e705c121SKalle Valo static void 1181e705c121SKalle Valo iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1182e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1183e705c121SKalle Valo { 1184e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1185e705c121SKalle Valo 1186e705c121SKalle Valo switch (reconfig_type) { 1187e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1188e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1189e705c121SKalle Valo break; 1190e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1191e705c121SKalle Valo break; 1192e705c121SKalle Valo } 1193e705c121SKalle Valo } 1194e705c121SKalle Valo 1195e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1196e705c121SKalle Valo { 1197e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1198e705c121SKalle Valo 1199b68bd2e3SIlan Peer iwl_mvm_ftm_initiator_smooth_stop(mvm); 1200b68bd2e3SIlan Peer 1201e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1202e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1203e705c121SKalle Valo */ 1204e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1205e705c121SKalle Valo 1206e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1207e705c121SKalle Valo 12082c2c3647SNathan Errera if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, ADD_STA, 0) < 12) 1209f327236dSSharon iwl_mvm_rm_aux_sta(mvm); 1210f327236dSSharon 1211fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1212e705c121SKalle Valo 1213e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1214e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1215e705c121SKalle Valo 1216e705c121SKalle Valo /* 1217155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1218155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1219155f7e04SEmmanuel Grumbach * won't execute the restart. 1220e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1221e705c121SKalle Valo * HW restart was requested. 1222e705c121SKalle Valo */ 1223155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1224155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1225155f7e04SEmmanuel Grumbach &mvm->status)) 1226e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1227e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1228e705c121SKalle Valo 1229e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1230e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1231e705c121SKalle Valo */ 1232e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1233e705c121SKalle Valo int i; 1234e705c121SKalle Valo 1235e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1236e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1237e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1238e705c121SKalle Valo i)) 1239e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1240e705c121SKalle Valo } 1241e705c121SKalle Valo } 1242e705c121SKalle Valo } 1243e705c121SKalle Valo 1244e705c121SKalle Valo static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1245e705c121SKalle Valo { 1246e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1247e705c121SKalle Valo 1248e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 124924afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1250771147b0SJohannes Berg 1251771147b0SJohannes Berg /* 1252771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1253771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1254771147b0SJohannes Berg * be able to proceed. This is important here because one of those 12557174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1256771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1257771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1258771147b0SJohannes Berg */ 1259771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1260771147b0SJohannes Berg 1261d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 126269e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1263e705c121SKalle Valo 1264f9084775SNathan Errera /* 1265f9084775SNathan Errera * The work item could be running or queued if the 1266f9084775SNathan Errera * ROC time event stops just as we get here. 1267f9084775SNathan Errera */ 1268f9084775SNathan Errera flush_work(&mvm->roc_done_wk); 1269f9084775SNathan Errera 12707ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 12717ce1f215SEmmanuel Grumbach 1272e705c121SKalle Valo mutex_lock(&mvm->mutex); 1273e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1274e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1275e705c121SKalle Valo 1276e705c121SKalle Valo /* 1277e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1278e705c121SKalle Valo * discover that its list is now empty. 1279e705c121SKalle Valo */ 1280e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1281e705c121SKalle Valo } 1282e705c121SKalle Valo 1283e705c121SKalle Valo static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1284e705c121SKalle Valo { 1285e705c121SKalle Valo u16 i; 1286e705c121SKalle Valo 1287e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1288e705c121SKalle Valo 1289e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1290e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1291e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1292e705c121SKalle Valo 1293e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1294e705c121SKalle Valo return NULL; 1295e705c121SKalle Valo } 1296e705c121SKalle Valo 1297e705c121SKalle Valo static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1298e705c121SKalle Valo s16 tx_power) 1299e705c121SKalle Valo { 13000791c2fcSHaim Dreyfuss int len; 1301216cdfb5SLuca Coelho struct iwl_dev_tx_power_cmd cmd = { 1302216cdfb5SLuca Coelho .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1303216cdfb5SLuca Coelho .common.mac_context_id = 1304e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1305216cdfb5SLuca Coelho .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1306e705c121SKalle Valo }; 1307fbb7957dSLuca Coelho u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, 1308e80bfd11SMordechay Goodstein REDUCE_TX_POWER_CMD, 1309e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN); 1310e705c121SKalle Valo 1311e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1312216cdfb5SLuca Coelho cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1313e705c121SKalle Valo 1314fbb7957dSLuca Coelho if (cmd_ver == 6) 1315fbb7957dSLuca Coelho len = sizeof(cmd.v6); 1316fbb7957dSLuca Coelho else if (fw_has_api(&mvm->fw->ucode_capa, 13170791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 13180791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 13190791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 13200791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 13210791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 13220791c2fcSHaim Dreyfuss else 1323216cdfb5SLuca Coelho len = sizeof(cmd.v3); 1324216cdfb5SLuca Coelho 1325216cdfb5SLuca Coelho /* all structs have the same common part, add it */ 1326216cdfb5SLuca Coelho len += sizeof(cmd.common); 1327e705c121SKalle Valo 1328e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); 1329e705c121SKalle Valo } 1330e705c121SKalle Valo 1331f6780614SSara Sharon static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1332f6780614SSara Sharon struct ieee80211_vif *vif) 1333f6780614SSara Sharon { 1334f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1335f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1336f6780614SSara Sharon int ret; 1337f6780614SSara Sharon 1338f6780614SSara Sharon mutex_lock(&mvm->mutex); 1339f6780614SSara Sharon 1340f6780614SSara Sharon if (vif->type == NL80211_IFTYPE_STATION) { 1341f6780614SSara Sharon struct iwl_mvm_sta *mvmsta; 1342f6780614SSara Sharon 1343f6780614SSara Sharon mvmvif->csa_bcn_pending = false; 1344f6780614SSara Sharon mvmsta = iwl_mvm_sta_from_staid_protected(mvm, 1345f6780614SSara Sharon mvmvif->ap_sta_id); 1346f6780614SSara Sharon 1347f6780614SSara Sharon if (WARN_ON(!mvmsta)) { 1348f6780614SSara Sharon ret = -EIO; 1349f6780614SSara Sharon goto out_unlock; 1350f6780614SSara Sharon } 1351f6780614SSara Sharon 1352f6780614SSara Sharon iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 1353f6780614SSara Sharon 1354f6780614SSara Sharon iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1355f6780614SSara Sharon 13560202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 13570202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 1358f6780614SSara Sharon ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 1359f6780614SSara Sharon if (ret) 1360f6780614SSara Sharon goto out_unlock; 1361f6780614SSara Sharon 1362f6780614SSara Sharon iwl_mvm_stop_session_protection(mvm, vif); 1363f6780614SSara Sharon } 13640202bcf0SEmmanuel Grumbach } 1365f6780614SSara Sharon 1366f6780614SSara Sharon mvmvif->ps_disabled = false; 1367f6780614SSara Sharon 1368f6780614SSara Sharon ret = iwl_mvm_power_update_ps(mvm); 1369f6780614SSara Sharon 1370f6780614SSara Sharon out_unlock: 1371caf46377SSara Sharon if (mvmvif->csa_failed) 1372caf46377SSara Sharon ret = -EIO; 1373f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1374f6780614SSara Sharon 1375f6780614SSara Sharon return ret; 1376f6780614SSara Sharon } 1377f6780614SSara Sharon 1378f6780614SSara Sharon static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 1379f6780614SSara Sharon struct ieee80211_vif *vif) 1380f6780614SSara Sharon { 1381f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1382f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1383f6780614SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 1384f6780614SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1385f6780614SSara Sharon mvmvif->color)), 1386f6780614SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1387f6780614SSara Sharon }; 1388f6780614SSara Sharon 1389f6780614SSara Sharon IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1390f6780614SSara Sharon 1391f6780614SSara Sharon mutex_lock(&mvm->mutex); 139258ddd9b6SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 139358ddd9b6SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 139458ddd9b6SEmmanuel Grumbach iwl_mvm_remove_csa_period(mvm, vif); 139558ddd9b6SEmmanuel Grumbach else 1396f6780614SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1397f6780614SSara Sharon WIDE_ID(MAC_CONF_GROUP, 1398f6780614SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 1399f6780614SSara Sharon 0, sizeof(cmd), &cmd)); 1400caf46377SSara Sharon mvmvif->csa_failed = true; 1401f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1402f6780614SSara Sharon 1403caf46377SSara Sharon iwl_mvm_post_channel_switch(hw, vif); 1404f6780614SSara Sharon } 1405f6780614SSara Sharon 1406f6780614SSara Sharon static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1407f6780614SSara Sharon { 1408f6780614SSara Sharon struct iwl_mvm_vif *mvmvif; 1409f6780614SSara Sharon struct ieee80211_vif *vif; 1410f6780614SSara Sharon 1411f6780614SSara Sharon mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1412f6780614SSara Sharon vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1413f6780614SSara Sharon 141470162580SShaul Triebitz /* Trigger disconnect (should clear the CSA state) */ 1415f6780614SSara Sharon ieee80211_chswitch_done(vif, false); 1416f6780614SSara Sharon } 1417f6780614SSara Sharon 1418e705c121SKalle Valo static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1419e705c121SKalle Valo struct ieee80211_vif *vif) 1420e705c121SKalle Valo { 1421e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1422e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1423e705c121SKalle Valo int ret; 1424e705c121SKalle Valo 1425e705c121SKalle Valo mvmvif->mvm = mvm; 142686e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 1427e705c121SKalle Valo 1428e705c121SKalle Valo /* 1429e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1430e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1431e705c121SKalle Valo * don't really have to check the types. 1432e705c121SKalle Valo */ 1433e705c121SKalle Valo 1434e705c121SKalle Valo mutex_lock(&mvm->mutex); 1435e705c121SKalle Valo 1436e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1437e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1438e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons += 1439e705c121SKalle Valo mvmvif->beacon_stats.num_beacons; 1440e705c121SKalle Valo 1441e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 1442e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_init(mvm, vif); 1443e705c121SKalle Valo if (ret) 1444e705c121SKalle Valo goto out_unlock; 1445e705c121SKalle Valo 1446698478c4SSara Sharon rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1447698478c4SSara Sharon 1448e705c121SKalle Valo /* Counting number of interfaces is needed for legacy PM */ 1449e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1450e705c121SKalle Valo mvm->vif_count++; 1451e705c121SKalle Valo 1452e705c121SKalle Valo /* 1453e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1454e705c121SKalle Valo * template is configured (which happens only in the mac80211 1455e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1456e705c121SKalle Valo * only after the binding. 1457e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1458e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1459e705c121SKalle Valo * the point where we can also add the bcast station. 1460e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1461e705c121SKalle Valo * allocating resources :) 1462e705c121SKalle Valo */ 1463e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1464e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1465e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1466e705c121SKalle Valo if (ret) { 1467e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 1468e705c121SKalle Valo goto out_release; 1469e705c121SKalle Valo } 1470e705c121SKalle Valo 147126d6c16bSSara Sharon /* 147226d6c16bSSara Sharon * Only queue for this station is the mcast queue, 147326d6c16bSSara Sharon * which shouldn't be in TFD mask anyway 147426d6c16bSSara Sharon */ 147526d6c16bSSara Sharon ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta, 1476ced19f26SSara Sharon 0, vif->type, 1477ced19f26SSara Sharon IWL_STA_MULTICAST); 147826d6c16bSSara Sharon if (ret) 147926d6c16bSSara Sharon goto out_release; 148026d6c16bSSara Sharon 1481e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1482e705c121SKalle Valo goto out_unlock; 1483e705c121SKalle Valo } 1484e705c121SKalle Valo 1485e705c121SKalle Valo mvmvif->features |= hw->netdev_features; 1486e705c121SKalle Valo 1487e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1488e705c121SKalle Valo if (ret) 1489e705c121SKalle Valo goto out_release; 1490e705c121SKalle Valo 1491e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1492e705c121SKalle Valo if (ret) 1493e705c121SKalle Valo goto out_remove_mac; 1494e705c121SKalle Valo 1495e705c121SKalle Valo /* beacon filtering */ 1496e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 1497e705c121SKalle Valo if (ret) 1498e705c121SKalle Valo goto out_remove_mac; 1499e705c121SKalle Valo 1500e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1501e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1502e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1503e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1504e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1505e705c121SKalle Valo } 1506e705c121SKalle Valo 1507e705c121SKalle Valo /* 1508e705c121SKalle Valo * P2P_DEVICE interface does not have a channel context assigned to it, 1509e705c121SKalle Valo * so a dedicated PHY context is allocated to it and the corresponding 1510e705c121SKalle Valo * MAC context is bound to it at this stage. 1511e705c121SKalle Valo */ 1512e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1513e705c121SKalle Valo 1514e705c121SKalle Valo mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 1515e705c121SKalle Valo if (!mvmvif->phy_ctxt) { 1516e705c121SKalle Valo ret = -ENOSPC; 1517e705c121SKalle Valo goto out_free_bf; 1518e705c121SKalle Valo } 1519e705c121SKalle Valo 1520e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 1521e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 1522e705c121SKalle Valo if (ret) 1523e705c121SKalle Valo goto out_unref_phy; 1524e705c121SKalle Valo 1525d197358bSLuca Coelho ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); 1526e705c121SKalle Valo if (ret) 1527e705c121SKalle Valo goto out_unbind; 1528e705c121SKalle Valo 1529e705c121SKalle Valo /* Save a pointer to p2p device vif, so it can later be used to 1530e705c121SKalle Valo * update the p2p device MAC when a GO is started/stopped */ 1531e705c121SKalle Valo mvm->p2p_device_vif = vif; 1532e705c121SKalle Valo } 1533e705c121SKalle Valo 1534b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1535f6780614SSara Sharon INIT_DELAYED_WORK(&mvmvif->csa_work, 1536f6780614SSara Sharon iwl_mvm_channel_switch_disconnect_wk); 1537b0ffe455SJohannes Berg 1538baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1539baf41bc3SShaul Triebitz mvm->monitor_on = true; 1540baf41bc3SShaul Triebitz 1541e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 15426d19a5ebSEmmanuel Grumbach 15436d19a5ebSEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 15446d19a5ebSEmmanuel Grumbach vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 15456d19a5ebSEmmanuel Grumbach !mvm->csme_vif && mvm->mei_registered) { 15466d19a5ebSEmmanuel Grumbach iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 15476d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 15486d19a5ebSEmmanuel Grumbach mvm->csme_vif = vif; 15496d19a5ebSEmmanuel Grumbach } 15506d19a5ebSEmmanuel Grumbach 1551e705c121SKalle Valo goto out_unlock; 1552e705c121SKalle Valo 1553e705c121SKalle Valo out_unbind: 1554e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1555e705c121SKalle Valo out_unref_phy: 1556e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1557e705c121SKalle Valo out_free_bf: 1558e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1559e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1560e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1561e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1562e705c121SKalle Valo } 1563e705c121SKalle Valo out_remove_mac: 1564e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1565e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1566e705c121SKalle Valo out_release: 1567e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1568e705c121SKalle Valo mvm->vif_count--; 1569e705c121SKalle Valo out_unlock: 1570e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1571e705c121SKalle Valo 1572e705c121SKalle Valo return ret; 1573e705c121SKalle Valo } 1574e705c121SKalle Valo 1575e705c121SKalle Valo static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1576e705c121SKalle Valo struct ieee80211_vif *vif) 1577e705c121SKalle Valo { 1578e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1579e705c121SKalle Valo /* 1580e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1581e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1582e705c121SKalle Valo * queue are sent in ROC session. 1583e705c121SKalle Valo */ 1584e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1585e705c121SKalle Valo } 1586e705c121SKalle Valo } 1587e705c121SKalle Valo 1588e705c121SKalle Valo static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 1589e705c121SKalle Valo struct ieee80211_vif *vif) 1590e705c121SKalle Valo { 1591e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1592e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 159386e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1594e705c121SKalle Valo 1595e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1596e705c121SKalle Valo 1597b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1598b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1599b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1600b0ffe455SJohannes Berg 1601e705c121SKalle Valo mutex_lock(&mvm->mutex); 1602e705c121SKalle Valo 16036d19a5ebSEmmanuel Grumbach if (vif == mvm->csme_vif) { 16046d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(NULL); 16056d19a5ebSEmmanuel Grumbach mvm->csme_vif = NULL; 16066d19a5ebSEmmanuel Grumbach } 16076d19a5ebSEmmanuel Grumbach 160886e177d8SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->probe_resp_data, 160986e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 161086e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 161186e177d8SGregory Greenman if (probe_data) 161286e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 161386e177d8SGregory Greenman 1614e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1615e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1616e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1617e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1618e705c121SKalle Valo } 1619e705c121SKalle Valo 1620b73f9a4aSJohannes Berg if (vif->bss_conf.ftm_responder) 1621b73f9a4aSJohannes Berg memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1622b73f9a4aSJohannes Berg 1623e705c121SKalle Valo iwl_mvm_vif_dbgfs_clean(mvm, vif); 1624e705c121SKalle Valo 1625e705c121SKalle Valo /* 1626e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1627e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1628e705c121SKalle Valo */ 1629e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1630e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1631e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1632e705c121SKalle Valo if (vif == mvm->noa_vif) { 1633e705c121SKalle Valo mvm->noa_vif = NULL; 1634e705c121SKalle Valo mvm->noa_duration = 0; 1635e705c121SKalle Valo } 1636e705c121SKalle Valo #endif 163726d6c16bSSara Sharon iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta); 1638e705c121SKalle Valo iwl_mvm_dealloc_bcast_sta(mvm, vif); 1639e705c121SKalle Valo goto out_release; 1640e705c121SKalle Valo } 1641e705c121SKalle Valo 1642e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1643e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1644d197358bSLuca Coelho iwl_mvm_rm_p2p_bcast_sta(mvm, vif); 1645e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1646e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1647e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1648e705c121SKalle Valo } 1649e705c121SKalle Valo 1650e705c121SKalle Valo if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) 1651e705c121SKalle Valo mvm->vif_count--; 1652e705c121SKalle Valo 1653e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 1654e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1655e705c121SKalle Valo 1656698478c4SSara Sharon RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1657698478c4SSara Sharon 1658baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1659baf41bc3SShaul Triebitz mvm->monitor_on = false; 1660baf41bc3SShaul Triebitz 1661e705c121SKalle Valo out_release: 1662e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1663e705c121SKalle Valo } 1664e705c121SKalle Valo 1665e705c121SKalle Valo static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) 1666e705c121SKalle Valo { 1667e705c121SKalle Valo return 0; 1668e705c121SKalle Valo } 1669e705c121SKalle Valo 1670e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1671e705c121SKalle Valo struct iwl_mvm *mvm; 1672e705c121SKalle Valo int port_id; 1673e705c121SKalle Valo }; 1674e705c121SKalle Valo 1675e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1676e705c121SKalle Valo struct ieee80211_vif *vif) 1677e705c121SKalle Valo { 1678e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1679e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1680e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 168197bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 168297bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 168397bce57bSLuca Coelho .flags = CMD_ASYNC, 168497bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 168597bce57bSLuca Coelho }; 1686e705c121SKalle Valo int ret, len; 1687e705c121SKalle Valo 1688e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1689e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1690e705c121SKalle Valo return; 1691e705c121SKalle Valo 1692e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1693e705c121SKalle Valo !vif->bss_conf.assoc) 1694e705c121SKalle Valo return; 1695e705c121SKalle Valo 1696e705c121SKalle Valo cmd->port_id = data->port_id++; 1697e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1698e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1699e705c121SKalle Valo 170097bce57bSLuca Coelho hcmd.len[0] = len; 170197bce57bSLuca Coelho hcmd.data[0] = cmd; 170297bce57bSLuca Coelho 170397bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1704e705c121SKalle Valo if (ret) 1705e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1706e705c121SKalle Valo } 1707e705c121SKalle Valo 1708e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1709e705c121SKalle Valo { 1710e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1711e705c121SKalle Valo .mvm = mvm, 1712e705c121SKalle Valo }; 1713db66abeeSJohannes Berg int ret; 1714e705c121SKalle Valo 1715e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1716e705c121SKalle Valo 1717e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1718e705c121SKalle Valo return; 1719e705c121SKalle Valo 1720e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1721e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1722e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1723db66abeeSJohannes Berg 1724db66abeeSJohannes Berg /* 1725db66abeeSJohannes Berg * Send a (synchronous) ech command so that we wait for the 1726db66abeeSJohannes Berg * multiple asynchronous MCAST_FILTER_CMD commands sent by 1727db66abeeSJohannes Berg * the interface iterator. Otherwise, we might get here over 1728db66abeeSJohannes Berg * and over again (by userspace just sending a lot of these) 1729db66abeeSJohannes Berg * and the CPU can send them faster than the firmware can 1730db66abeeSJohannes Berg * process them. 1731db66abeeSJohannes Berg * Note that the CPU is still faster - but with this we'll 1732db66abeeSJohannes Berg * actually send fewer commands overall because the CPU will 1733db66abeeSJohannes Berg * not schedule the work in mac80211 as frequently if it's 1734db66abeeSJohannes Berg * still running when rescheduled (possibly multiple times). 1735db66abeeSJohannes Berg */ 1736db66abeeSJohannes Berg ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1737db66abeeSJohannes Berg if (ret) 1738db66abeeSJohannes Berg IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 1739e705c121SKalle Valo } 1740e705c121SKalle Valo 1741e705c121SKalle Valo static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1742e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1743e705c121SKalle Valo { 1744e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1745e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1746e705c121SKalle Valo struct netdev_hw_addr *addr; 1747e705c121SKalle Valo int addr_count; 1748e705c121SKalle Valo bool pass_all; 1749e705c121SKalle Valo int len; 1750e705c121SKalle Valo 1751e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1752e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1753e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1754e705c121SKalle Valo if (pass_all) 1755e705c121SKalle Valo addr_count = 0; 1756e705c121SKalle Valo 1757e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1758e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1759e705c121SKalle Valo if (!cmd) 1760e705c121SKalle Valo return 0; 1761e705c121SKalle Valo 1762e705c121SKalle Valo if (pass_all) { 1763e705c121SKalle Valo cmd->pass_all = 1; 1764e705c121SKalle Valo return (u64)(unsigned long)cmd; 1765e705c121SKalle Valo } 1766e705c121SKalle Valo 1767e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1768e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1769e705c121SKalle Valo cmd->count, addr->addr); 1770e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1771e705c121SKalle Valo addr->addr, ETH_ALEN); 1772e705c121SKalle Valo cmd->count++; 1773e705c121SKalle Valo } 1774e705c121SKalle Valo 1775e705c121SKalle Valo return (u64)(unsigned long)cmd; 1776e705c121SKalle Valo } 1777e705c121SKalle Valo 1778e705c121SKalle Valo static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1779e705c121SKalle Valo unsigned int changed_flags, 1780e705c121SKalle Valo unsigned int *total_flags, 1781e705c121SKalle Valo u64 multicast) 1782e705c121SKalle Valo { 1783e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1784e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1785e705c121SKalle Valo 1786e705c121SKalle Valo mutex_lock(&mvm->mutex); 1787e705c121SKalle Valo 1788e705c121SKalle Valo /* replace previous configuration */ 1789e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1790e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1791e705c121SKalle Valo 1792e705c121SKalle Valo if (!cmd) 1793e705c121SKalle Valo goto out; 1794e705c121SKalle Valo 179561e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 179661e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 179761e7d91bSLuca Coelho 179861e7d91bSLuca Coelho if (cmd->pass_all) 179961e7d91bSLuca Coelho cmd->count = 0; 180061e7d91bSLuca Coelho 1801e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1802e705c121SKalle Valo out: 1803e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1804e705c121SKalle Valo *total_flags = 0; 1805e705c121SKalle Valo } 1806e705c121SKalle Valo 1807e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1808e705c121SKalle Valo struct ieee80211_vif *vif, 1809e705c121SKalle Valo unsigned int filter_flags, 1810e705c121SKalle Valo unsigned int changed_flags) 1811e705c121SKalle Valo { 1812e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1813e705c121SKalle Valo 1814e705c121SKalle Valo /* We support only filter for probe requests */ 1815e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1816e705c121SKalle Valo return; 1817e705c121SKalle Valo 1818e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1819e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc || 1820e705c121SKalle Valo !vif->p2p) 1821e705c121SKalle Valo return; 1822e705c121SKalle Valo 1823e705c121SKalle Valo mutex_lock(&mvm->mutex); 1824e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1825e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1826e705c121SKalle Valo } 1827e705c121SKalle Valo 1828e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 1829e705c121SKalle Valo struct iwl_bcast_iter_data { 1830e705c121SKalle Valo struct iwl_mvm *mvm; 1831e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd; 1832e705c121SKalle Valo u8 current_filter; 1833e705c121SKalle Valo }; 1834e705c121SKalle Valo 1835e705c121SKalle Valo static void 1836e705c121SKalle Valo iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, 1837e705c121SKalle Valo const struct iwl_fw_bcast_filter *in_filter, 1838e705c121SKalle Valo struct iwl_fw_bcast_filter *out_filter) 1839e705c121SKalle Valo { 1840e705c121SKalle Valo struct iwl_fw_bcast_filter_attr *attr; 1841e705c121SKalle Valo int i; 1842e705c121SKalle Valo 1843e705c121SKalle Valo memcpy(out_filter, in_filter, sizeof(*out_filter)); 1844e705c121SKalle Valo 1845e705c121SKalle Valo for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { 1846e705c121SKalle Valo attr = &out_filter->attrs[i]; 1847e705c121SKalle Valo 1848e705c121SKalle Valo if (!attr->mask) 1849e705c121SKalle Valo break; 1850e705c121SKalle Valo 1851e705c121SKalle Valo switch (attr->reserved1) { 1852e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_IP): 1853e705c121SKalle Valo if (vif->bss_conf.arp_addr_cnt != 1) { 1854e705c121SKalle Valo attr->mask = 0; 1855e705c121SKalle Valo continue; 1856e705c121SKalle Valo } 1857e705c121SKalle Valo 1858e705c121SKalle Valo attr->val = vif->bss_conf.arp_addr_list[0]; 1859e705c121SKalle Valo break; 1860e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_MAC): 1861e705c121SKalle Valo attr->val = *(__be32 *)&vif->addr[2]; 1862e705c121SKalle Valo break; 1863e705c121SKalle Valo default: 1864e705c121SKalle Valo break; 1865e705c121SKalle Valo } 1866e705c121SKalle Valo attr->reserved1 = 0; 1867e705c121SKalle Valo out_filter->num_attrs++; 1868e705c121SKalle Valo } 1869e705c121SKalle Valo } 1870e705c121SKalle Valo 1871e705c121SKalle Valo static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, 1872e705c121SKalle Valo struct ieee80211_vif *vif) 1873e705c121SKalle Valo { 1874e705c121SKalle Valo struct iwl_bcast_iter_data *data = _data; 1875e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1876e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd = data->cmd; 1877e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1878e705c121SKalle Valo struct iwl_fw_bcast_mac *bcast_mac; 1879e705c121SKalle Valo int i; 1880e705c121SKalle Valo 1881e705c121SKalle Valo if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) 1882e705c121SKalle Valo return; 1883e705c121SKalle Valo 1884e705c121SKalle Valo bcast_mac = &cmd->macs[mvmvif->id]; 1885e705c121SKalle Valo 1886e705c121SKalle Valo /* 1887e705c121SKalle Valo * enable filtering only for associated stations, but not for P2P 1888e705c121SKalle Valo * Clients 1889e705c121SKalle Valo */ 1890e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || 1891e705c121SKalle Valo !vif->bss_conf.assoc) 1892e705c121SKalle Valo return; 1893e705c121SKalle Valo 1894e705c121SKalle Valo bcast_mac->default_discard = 1; 1895e705c121SKalle Valo 1896e705c121SKalle Valo /* copy all configured filters */ 1897e705c121SKalle Valo for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { 1898e705c121SKalle Valo /* 1899e705c121SKalle Valo * Make sure we don't exceed our filters limit. 1900e705c121SKalle Valo * if there is still a valid filter to be configured, 1901e705c121SKalle Valo * be on the safe side and just allow bcast for this mac. 1902e705c121SKalle Valo */ 1903e705c121SKalle Valo if (WARN_ON_ONCE(data->current_filter >= 1904e705c121SKalle Valo ARRAY_SIZE(cmd->filters))) { 1905e705c121SKalle Valo bcast_mac->default_discard = 0; 1906e705c121SKalle Valo bcast_mac->attached_filters = 0; 1907e705c121SKalle Valo break; 1908e705c121SKalle Valo } 1909e705c121SKalle Valo 1910e705c121SKalle Valo iwl_mvm_set_bcast_filter(vif, 1911e705c121SKalle Valo &mvm->bcast_filters[i], 1912e705c121SKalle Valo &cmd->filters[data->current_filter]); 1913e705c121SKalle Valo 1914e705c121SKalle Valo /* skip current filter if it contains no attributes */ 1915e705c121SKalle Valo if (!cmd->filters[data->current_filter].num_attrs) 1916e705c121SKalle Valo continue; 1917e705c121SKalle Valo 1918e705c121SKalle Valo /* attach the filter to current mac */ 1919e705c121SKalle Valo bcast_mac->attached_filters |= 1920e705c121SKalle Valo cpu_to_le16(BIT(data->current_filter)); 1921e705c121SKalle Valo 1922e705c121SKalle Valo data->current_filter++; 1923e705c121SKalle Valo } 1924e705c121SKalle Valo } 1925e705c121SKalle Valo 1926e705c121SKalle Valo bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, 1927e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd) 1928e705c121SKalle Valo { 1929e705c121SKalle Valo struct iwl_bcast_iter_data iter_data = { 1930e705c121SKalle Valo .mvm = mvm, 1931e705c121SKalle Valo .cmd = cmd, 1932e705c121SKalle Valo }; 1933e705c121SKalle Valo 1934e705c121SKalle Valo if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL) 1935e705c121SKalle Valo return false; 1936e705c121SKalle Valo 1937e705c121SKalle Valo memset(cmd, 0, sizeof(*cmd)); 1938e705c121SKalle Valo cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); 1939e705c121SKalle Valo cmd->max_macs = ARRAY_SIZE(cmd->macs); 1940e705c121SKalle Valo 1941e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_DEBUGFS 1942e705c121SKalle Valo /* use debugfs filters/macs if override is configured */ 1943e705c121SKalle Valo if (mvm->dbgfs_bcast_filtering.override) { 1944e705c121SKalle Valo memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, 1945e705c121SKalle Valo sizeof(cmd->filters)); 1946e705c121SKalle Valo memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, 1947e705c121SKalle Valo sizeof(cmd->macs)); 1948e705c121SKalle Valo return true; 1949e705c121SKalle Valo } 1950e705c121SKalle Valo #endif 1951e705c121SKalle Valo 1952e705c121SKalle Valo /* if no filters are configured, do nothing */ 1953e705c121SKalle Valo if (!mvm->bcast_filters) 1954e705c121SKalle Valo return false; 1955e705c121SKalle Valo 1956e705c121SKalle Valo /* configure and attach these filters for each associated sta vif */ 1957e705c121SKalle Valo ieee80211_iterate_active_interfaces( 1958e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1959e705c121SKalle Valo iwl_mvm_bcast_filter_iterator, &iter_data); 1960e705c121SKalle Valo 1961e705c121SKalle Valo return true; 1962e705c121SKalle Valo } 196334672bb3SEliad Peller 196434672bb3SEliad Peller static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1965e705c121SKalle Valo { 1966e705c121SKalle Valo struct iwl_bcast_filter_cmd cmd; 1967e705c121SKalle Valo 1968e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) 1969e705c121SKalle Valo return 0; 1970e705c121SKalle Valo 1971e705c121SKalle Valo if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) 1972e705c121SKalle Valo return 0; 1973e705c121SKalle Valo 1974e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, 1975e705c121SKalle Valo sizeof(cmd), &cmd); 1976e705c121SKalle Valo } 1977e705c121SKalle Valo #else 197834672bb3SEliad Peller static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1979e705c121SKalle Valo { 1980e705c121SKalle Valo return 0; 1981e705c121SKalle Valo } 1982e705c121SKalle Valo #endif 1983e705c121SKalle Valo 1984a07a8f37SSara Sharon static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, 1985a07a8f37SSara Sharon struct ieee80211_vif *vif) 1986a07a8f37SSara Sharon { 1987a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1988a07a8f37SSara Sharon 1989a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 1990a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 1991a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 1992a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 1993a07a8f37SSara Sharon 1994a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 1995a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 1996a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 1997a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 1998a07a8f37SSara Sharon } 1999a07a8f37SSara Sharon 2000f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 2001f92659a1SSara Sharon struct ieee80211_vif *vif) 2002f92659a1SSara Sharon { 2003f92659a1SSara Sharon if (vif->mu_mimo_owner) { 2004f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 2005f92659a1SSara Sharon 2006f92659a1SSara Sharon /* 2007f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 2008f92659a1SSara Sharon * the data received from firmware as if it came from the 2009f92659a1SSara Sharon * action frame, so no conversion is needed. 2010f92659a1SSara Sharon */ 2011f92659a1SSara Sharon ieee80211_update_mu_groups(vif, 2012f92659a1SSara Sharon (u8 *)¬if->membership_status, 2013f92659a1SSara Sharon (u8 *)¬if->user_position); 2014f92659a1SSara Sharon } 2015f92659a1SSara Sharon } 2016f92659a1SSara Sharon 2017f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 2018f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 2019f92659a1SSara Sharon { 2020f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 2021f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 2022f92659a1SSara Sharon 2023f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 2024f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 2025f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 2026f92659a1SSara Sharon } 2027f92659a1SSara Sharon 2028514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 2029514c3069SLuca Coelho { 2030514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 2031514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 2032514c3069SLuca Coelho u8 residue_bits; 2033514c3069SLuca Coelho u8 res; 2034514c3069SLuca Coelho 2035514c3069SLuca Coelho if (bit_num <= 5) 2036514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 2037514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 2038514c3069SLuca Coelho 2039514c3069SLuca Coelho /* 2040514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 2041514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 2042514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 2043514c3069SLuca Coelho */ 2044514c3069SLuca Coelho 2045514c3069SLuca Coelho residue_bits = 8 - bit_num; 2046514c3069SLuca Coelho 2047514c3069SLuca Coelho res = (ppe[byte_num + 1] & 2048514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 2049514c3069SLuca Coelho residue_bits; 2050514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 2051514c3069SLuca Coelho 2052514c3069SLuca Coelho return res; 2053514c3069SLuca Coelho } 2054514c3069SLuca Coelho 2055514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 2056514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 2057514c3069SLuca Coelho { 2058514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2059514c3069SLuca Coelho struct iwl_he_sta_context_cmd sta_ctxt_cmd = { 2060514c3069SLuca Coelho .sta_id = sta_id, 2061514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 2062dd56e902SJohn Crispin .bss_color = vif->bss_conf.he_bss_color.color, 2063514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 2064514c3069SLuca Coelho .frame_time_rts_th = 2065514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 2066514c3069SLuca Coelho }; 2067d14ae796SSara Sharon int size = fw_has_api(&mvm->fw->ucode_capa, 2068d14ae796SSara Sharon IWL_UCODE_TLV_API_MBSSID_HE) ? 2069d14ae796SSara Sharon sizeof(sta_ctxt_cmd) : 2070d14ae796SSara Sharon sizeof(struct iwl_he_sta_context_cmd_v1); 2071514c3069SLuca Coelho struct ieee80211_sta *sta; 2072514c3069SLuca Coelho u32 flags; 2073514c3069SLuca Coelho int i; 2074ee1a02d7SShaul Triebitz const struct ieee80211_sta_he_cap *own_he_cap = NULL; 2075ee1a02d7SShaul Triebitz struct ieee80211_chanctx_conf *chanctx_conf; 2076ee1a02d7SShaul Triebitz const struct ieee80211_supported_band *sband; 2077514c3069SLuca Coelho 2078514c3069SLuca Coelho rcu_read_lock(); 2079514c3069SLuca Coelho 2080ee1a02d7SShaul Triebitz chanctx_conf = rcu_dereference(vif->chanctx_conf); 2081ee1a02d7SShaul Triebitz if (WARN_ON(!chanctx_conf)) { 2082ee1a02d7SShaul Triebitz rcu_read_unlock(); 2083ee1a02d7SShaul Triebitz return; 2084ee1a02d7SShaul Triebitz } 2085ee1a02d7SShaul Triebitz 2086ee1a02d7SShaul Triebitz sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band]; 20874e6b69ecSJohannes Berg own_he_cap = ieee80211_get_he_iftype_cap(sband, 20884e6b69ecSJohannes Berg ieee80211_vif_type_p2p(vif)); 2089ee1a02d7SShaul Triebitz 2090514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 209112d47f0eSAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) { 2092514c3069SLuca Coelho rcu_read_unlock(); 2093514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 2094514c3069SLuca Coelho return; 2095514c3069SLuca Coelho } 2096514c3069SLuca Coelho 2097514c3069SLuca Coelho if (!sta->he_cap.has_he) { 2098514c3069SLuca Coelho rcu_read_unlock(); 2099514c3069SLuca Coelho return; 2100514c3069SLuca Coelho } 2101514c3069SLuca Coelho 2102514c3069SLuca Coelho flags = 0; 2103514c3069SLuca Coelho 21044f58121dSIlan Peer /* Block 26-tone RU OFDMA transmissions */ 21054f58121dSIlan Peer if (mvmvif->he_ru_2mhz_block) 21064f58121dSIlan Peer flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 21074f58121dSIlan Peer 2108514c3069SLuca Coelho /* HTC flags */ 2109514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[0] & 2110514c3069SLuca Coelho IEEE80211_HE_MAC_CAP0_HTC_HE) 2111514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 2112514c3069SLuca Coelho if ((sta->he_cap.he_cap_elem.mac_cap_info[1] & 2113514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 2114514c3069SLuca Coelho (sta->he_cap.he_cap_elem.mac_cap_info[2] & 2115514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 2116514c3069SLuca Coelho u8 link_adap = 2117514c3069SLuca Coelho ((sta->he_cap.he_cap_elem.mac_cap_info[2] & 2118514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 2119514c3069SLuca Coelho (sta->he_cap.he_cap_elem.mac_cap_info[1] & 2120514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 2121514c3069SLuca Coelho 2122514c3069SLuca Coelho if (link_adap == 2) 2123514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2124514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 2125514c3069SLuca Coelho else if (link_adap == 3) 2126514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2127514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 2128514c3069SLuca Coelho } 2129514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 2130514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 2131514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[3] & 2132514c3069SLuca Coelho IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 2133514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 2134514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 2135514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 2136514c3069SLuca Coelho 2137189b8d44SNaftali Goldstein /* 2138189b8d44SNaftali Goldstein * Initialize the PPE thresholds to "None" (7), as described in Table 2139189b8d44SNaftali Goldstein * 9-262ac of 80211.ax/D3.0. 2140189b8d44SNaftali Goldstein */ 2141189b8d44SNaftali Goldstein memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext)); 2142189b8d44SNaftali Goldstein 2143189b8d44SNaftali Goldstein /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 2144514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.phy_cap_info[6] & 2145514c3069SLuca Coelho IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2146514c3069SLuca Coelho u8 nss = (sta->he_cap.ppe_thres[0] & 2147514c3069SLuca Coelho IEEE80211_PPE_THRES_NSS_MASK) + 1; 2148514c3069SLuca Coelho u8 ru_index_bitmap = 2149514c3069SLuca Coelho (sta->he_cap.ppe_thres[0] & 2150514c3069SLuca Coelho IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> 2151514c3069SLuca Coelho IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; 2152514c3069SLuca Coelho u8 *ppe = &sta->he_cap.ppe_thres[0]; 2153514c3069SLuca Coelho u8 ppe_pos_bit = 7; /* Starting after PPE header */ 2154514c3069SLuca Coelho 2155514c3069SLuca Coelho /* 2156514c3069SLuca Coelho * FW currently supports only nss == MAX_HE_SUPP_NSS 2157514c3069SLuca Coelho * 2158514c3069SLuca Coelho * If nss > MAX: we can ignore values we don't support 2159514c3069SLuca Coelho * If nss < MAX: we can set zeros in other streams 2160514c3069SLuca Coelho */ 2161514c3069SLuca Coelho if (nss > MAX_HE_SUPP_NSS) { 2162514c3069SLuca Coelho IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 2163514c3069SLuca Coelho MAX_HE_SUPP_NSS); 2164514c3069SLuca Coelho nss = MAX_HE_SUPP_NSS; 2165514c3069SLuca Coelho } 2166514c3069SLuca Coelho 2167514c3069SLuca Coelho for (i = 0; i < nss; i++) { 2168514c3069SLuca Coelho u8 ru_index_tmp = ru_index_bitmap << 1; 2169514c3069SLuca Coelho u8 bw; 2170514c3069SLuca Coelho 2171514c3069SLuca Coelho for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) { 2172514c3069SLuca Coelho ru_index_tmp >>= 1; 2173514c3069SLuca Coelho if (!(ru_index_tmp & 1)) 2174514c3069SLuca Coelho continue; 2175514c3069SLuca Coelho 2176514c3069SLuca Coelho sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] = 2177514c3069SLuca Coelho iwl_mvm_he_get_ppe_val(ppe, 2178514c3069SLuca Coelho ppe_pos_bit); 2179514c3069SLuca Coelho ppe_pos_bit += 2180514c3069SLuca Coelho IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2181514c3069SLuca Coelho sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] = 2182514c3069SLuca Coelho iwl_mvm_he_get_ppe_val(ppe, 2183514c3069SLuca Coelho ppe_pos_bit); 2184514c3069SLuca Coelho ppe_pos_bit += 2185514c3069SLuca Coelho IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2186514c3069SLuca Coelho } 2187514c3069SLuca Coelho } 2188514c3069SLuca Coelho 2189514c3069SLuca Coelho flags |= STA_CTXT_HE_PACKET_EXT; 219077ff2c6bSLiad Kaufman } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] & 219177ff2c6bSLiad Kaufman IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) != 219277ff2c6bSLiad Kaufman IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) { 219377ff2c6bSLiad Kaufman int low_th = -1; 219477ff2c6bSLiad Kaufman int high_th = -1; 219577ff2c6bSLiad Kaufman 219677ff2c6bSLiad Kaufman /* Take the PPE thresholds from the nominal padding info */ 219777ff2c6bSLiad Kaufman switch (sta->he_cap.he_cap_elem.phy_cap_info[9] & 219877ff2c6bSLiad Kaufman IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) { 219977ff2c6bSLiad Kaufman case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US: 220077ff2c6bSLiad Kaufman low_th = IWL_HE_PKT_EXT_NONE; 220177ff2c6bSLiad Kaufman high_th = IWL_HE_PKT_EXT_NONE; 220277ff2c6bSLiad Kaufman break; 220377ff2c6bSLiad Kaufman case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US: 220477ff2c6bSLiad Kaufman low_th = IWL_HE_PKT_EXT_BPSK; 220577ff2c6bSLiad Kaufman high_th = IWL_HE_PKT_EXT_NONE; 220677ff2c6bSLiad Kaufman break; 220777ff2c6bSLiad Kaufman case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US: 220877ff2c6bSLiad Kaufman low_th = IWL_HE_PKT_EXT_NONE; 220977ff2c6bSLiad Kaufman high_th = IWL_HE_PKT_EXT_BPSK; 221077ff2c6bSLiad Kaufman break; 221177ff2c6bSLiad Kaufman } 221277ff2c6bSLiad Kaufman 221377ff2c6bSLiad Kaufman /* Set the PPE thresholds accordingly */ 221477ff2c6bSLiad Kaufman if (low_th >= 0 && high_th >= 0) { 22150bfefe2fSLiad Kaufman struct iwl_he_pkt_ext *pkt_ext = 22160bfefe2fSLiad Kaufman (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext; 221777ff2c6bSLiad Kaufman 221877ff2c6bSLiad Kaufman for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 221977ff2c6bSLiad Kaufman u8 bw; 222077ff2c6bSLiad Kaufman 222177ff2c6bSLiad Kaufman for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; 222277ff2c6bSLiad Kaufman bw++) { 22230bfefe2fSLiad Kaufman pkt_ext->pkt_ext_qam_th[i][bw][0] = 22240bfefe2fSLiad Kaufman low_th; 22250bfefe2fSLiad Kaufman pkt_ext->pkt_ext_qam_th[i][bw][1] = 22260bfefe2fSLiad Kaufman high_th; 222777ff2c6bSLiad Kaufman } 222877ff2c6bSLiad Kaufman } 222977ff2c6bSLiad Kaufman 223077ff2c6bSLiad Kaufman flags |= STA_CTXT_HE_PACKET_EXT; 223177ff2c6bSLiad Kaufman } 2232514c3069SLuca Coelho } 223373f23d91SShaul Triebitz 223473f23d91SShaul Triebitz if (sta->he_cap.he_cap_elem.mac_cap_info[2] & 223573f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 223673f23d91SShaul Triebitz flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 223773f23d91SShaul Triebitz 223873f23d91SShaul Triebitz if (sta->he_cap.he_cap_elem.mac_cap_info[2] & 223973f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN) 224073f23d91SShaul Triebitz flags |= STA_CTXT_HE_ACK_ENABLED; 224173f23d91SShaul Triebitz 2242514c3069SLuca Coelho rcu_read_unlock(); 2243514c3069SLuca Coelho 2244514c3069SLuca Coelho /* Mark MU EDCA as enabled, unless none detected on some AC */ 2245514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 22465cc74f65SShaul Triebitz for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2247514c3069SLuca Coelho struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2248514c3069SLuca Coelho &mvmvif->queue_params[i].mu_edca_param_rec; 22495cc74f65SShaul Triebitz u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 2250514c3069SLuca Coelho 2251514c3069SLuca Coelho if (!mvmvif->queue_params[i].mu_edca) { 2252514c3069SLuca Coelho flags &= ~STA_CTXT_HE_MU_EDCA_CW; 2253514c3069SLuca Coelho break; 2254514c3069SLuca Coelho } 2255514c3069SLuca Coelho 22565cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].cwmin = 2257514c3069SLuca Coelho cpu_to_le16(mu_edca->ecw_min_max & 0xf); 22585cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].cwmax = 2259514c3069SLuca Coelho cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 22605cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].aifsn = 2261514c3069SLuca Coelho cpu_to_le16(mu_edca->aifsn); 22625cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].mu_time = 2263514c3069SLuca Coelho cpu_to_le16(mu_edca->mu_edca_timer); 2264514c3069SLuca Coelho } 2265514c3069SLuca Coelho 2266514c3069SLuca Coelho 2267514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2268514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2269514c3069SLuca Coelho 2270514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2271514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2272514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2273514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2274514c3069SLuca Coelho } 2275514c3069SLuca Coelho 2276ee1a02d7SShaul Triebitz if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] & 2277ee1a02d7SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN)) 2278ee1a02d7SShaul Triebitz flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2279ee1a02d7SShaul Triebitz 2280918cbf39SSara Sharon if (vif->bss_conf.nontransmitted) { 2281918cbf39SSara Sharon flags |= STA_CTXT_HE_REF_BSSID_VALID; 2282918cbf39SSara Sharon ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2283918cbf39SSara Sharon vif->bss_conf.transmitter_bssid); 2284d14ae796SSara Sharon sta_ctxt_cmd.max_bssid_indicator = 2285d14ae796SSara Sharon vif->bss_conf.bssid_indicator; 2286d14ae796SSara Sharon sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2287d14ae796SSara Sharon sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2288d14ae796SSara Sharon sta_ctxt_cmd.profile_periodicity = 2289d14ae796SSara Sharon vif->bss_conf.profile_periodicity; 2290918cbf39SSara Sharon } 2291514c3069SLuca Coelho 2292514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2293514c3069SLuca Coelho 2294514c3069SLuca Coelho if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD, 2295514c3069SLuca Coelho DATA_PATH_GROUP, 0), 2296d14ae796SSara Sharon 0, size, &sta_ctxt_cmd)) 2297514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2298514c3069SLuca Coelho } 2299514c3069SLuca Coelho 2300af84ac57SJohannes Berg static void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, 2301af84ac57SJohannes Berg struct ieee80211_vif *vif, 2302af84ac57SJohannes Berg u32 duration_override) 2303af84ac57SJohannes Berg { 2304af84ac57SJohannes Berg u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2305af84ac57SJohannes Berg u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2306af84ac57SJohannes Berg 2307af84ac57SJohannes Berg if (duration_override > duration) 2308af84ac57SJohannes Berg duration = duration_override; 2309af84ac57SJohannes Berg 2310af84ac57SJohannes Berg /* Try really hard to protect the session and hear a beacon 2311af84ac57SJohannes Berg * The new session protection command allows us to protect the 2312af84ac57SJohannes Berg * session for a much longer time since the firmware will internally 2313af84ac57SJohannes Berg * create two events: a 300TU one with a very high priority that 2314af84ac57SJohannes Berg * won't be fragmented which should be enough for 99% of the cases, 2315af84ac57SJohannes Berg * and another one (which we configure here to be 900TU long) which 2316af84ac57SJohannes Berg * will have a slightly lower priority, but more importantly, can be 2317af84ac57SJohannes Berg * fragmented so that it'll allow other activities to run. 2318af84ac57SJohannes Berg */ 2319af84ac57SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 2320af84ac57SJohannes Berg IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2321af84ac57SJohannes Berg iwl_mvm_schedule_session_protection(mvm, vif, 900, 2322af84ac57SJohannes Berg min_duration, false); 2323af84ac57SJohannes Berg else 2324af84ac57SJohannes Berg iwl_mvm_protect_session(mvm, vif, duration, 2325af84ac57SJohannes Berg min_duration, 500, false); 2326af84ac57SJohannes Berg } 2327af84ac57SJohannes Berg 2328e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2329e705c121SKalle Valo struct ieee80211_vif *vif, 2330e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2331e705c121SKalle Valo u32 changes) 2332e705c121SKalle Valo { 2333e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2334e705c121SKalle Valo int ret; 2335e705c121SKalle Valo 2336e705c121SKalle Valo /* 2337cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend 2338cdaba917SEmmanuel Grumbach * on the beacon interval, which was not known when the station 2339cdaba917SEmmanuel Grumbach * interface was added. 2340e705c121SKalle Valo */ 2341514c3069SLuca Coelho if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { 2342230ba6c5SLuca Coelho if (vif->bss_conf.he_support && 2343230ba6c5SLuca Coelho !iwlwifi_mod_params.disable_11ax) 2344514c3069SLuca Coelho iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); 2345514c3069SLuca Coelho 2346e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2347514c3069SLuca Coelho } 2348e705c121SKalle Valo 234940ecdd01SShaul Triebitz /* Update MU EDCA params */ 235040ecdd01SShaul Triebitz if (changes & BSS_CHANGED_QOS && mvmvif->associated && 235140ecdd01SShaul Triebitz bss_conf->assoc && vif->bss_conf.he_support && 235240ecdd01SShaul Triebitz !iwlwifi_mod_params.disable_11ax) 235340ecdd01SShaul Triebitz iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); 235440ecdd01SShaul Triebitz 2355e705c121SKalle Valo /* 2356e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2357e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2358e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2359e705c121SKalle Valo * branch for disassociation below. 2360e705c121SKalle Valo */ 2361e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2362e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2363e705c121SKalle Valo 2364e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); 2365e705c121SKalle Valo if (ret) 2366e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2367e705c121SKalle Valo 2368e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2369e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2370e705c121SKalle Valo mvmvif->associated = bss_conf->assoc; 2371e705c121SKalle Valo 2372e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2373e705c121SKalle Valo if (bss_conf->assoc) { 2374e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2375e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2376e705c121SKalle Valo memset(&mvmvif->beacon_stats, 0, 2377e705c121SKalle Valo sizeof(mvmvif->beacon_stats)); 2378e705c121SKalle Valo 2379e705c121SKalle Valo /* add quota for this interface */ 2380e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2381e705c121SKalle Valo if (ret) { 2382e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2383e705c121SKalle Valo return; 2384e705c121SKalle Valo } 2385e705c121SKalle Valo 2386e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2387fe959c7bSEmmanuel Grumbach &mvm->status) && 2388fe959c7bSEmmanuel Grumbach !fw_has_capa(&mvm->fw->ucode_capa, 2389fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2390e705c121SKalle Valo /* 2391e705c121SKalle Valo * If we're restarting then the firmware will 2392e705c121SKalle Valo * obviously have lost synchronisation with 2393e705c121SKalle Valo * the AP. It will attempt to synchronise by 2394e705c121SKalle Valo * itself, but we can make it more reliable by 2395e705c121SKalle Valo * scheduling a session protection time event. 2396e705c121SKalle Valo * 2397e705c121SKalle Valo * The firmware needs to receive a beacon to 2398e705c121SKalle Valo * catch up with synchronisation, use 110% of 2399e705c121SKalle Valo * the beacon interval. 2400e705c121SKalle Valo * 2401e705c121SKalle Valo * Set a large maximum delay to allow for more 2402e705c121SKalle Valo * than a single interface. 2403fe959c7bSEmmanuel Grumbach * 2404fe959c7bSEmmanuel Grumbach * For new firmware versions, rely on the 2405fe959c7bSEmmanuel Grumbach * firmware. This is relevant for DCM scenarios 2406fe959c7bSEmmanuel Grumbach * only anyway. 2407e705c121SKalle Valo */ 2408e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2409e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2410e705c121SKalle Valo 5 * dur, false); 2411af84ac57SJohannes Berg } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2412af84ac57SJohannes Berg &mvm->status) && 2413af84ac57SJohannes Berg !vif->bss_conf.dtim_period) { 2414af84ac57SJohannes Berg /* 2415af84ac57SJohannes Berg * If we're not restarting and still haven't 2416af84ac57SJohannes Berg * heard a beacon (dtim period unknown) then 2417af84ac57SJohannes Berg * make sure we still have enough minimum time 2418af84ac57SJohannes Berg * remaining in the time event, since the auth 2419af84ac57SJohannes Berg * might actually have taken quite a while 2420af84ac57SJohannes Berg * (especially for SAE) and so the remaining 2421af84ac57SJohannes Berg * time could be small without us having heard 2422af84ac57SJohannes Berg * a beacon yet. 2423af84ac57SJohannes Berg */ 2424af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, 0); 2425e705c121SKalle Valo } 2426e705c121SKalle Valo 2427e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2428e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2429e705c121SKalle Valo if (vif->p2p) { 2430e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2431e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 2432e705c121SKalle Valo IEEE80211_SMPS_DYNAMIC); 2433e705c121SKalle Valo } 24340ae98812SSara Sharon } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { 24356d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_disassociated(mvm); 2436e705c121SKalle Valo /* 2437e705c121SKalle Valo * If update fails - SF might be running in associated 2438e705c121SKalle Valo * mode while disassociated - which is forbidden. 2439e705c121SKalle Valo */ 244069e508b4SIlan Peer ret = iwl_mvm_sf_update(mvm, vif, false); 244169e508b4SIlan Peer WARN_ONCE(ret && 244269e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 244369e508b4SIlan Peer &mvm->status), 2444e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2445e705c121SKalle Valo 24466b28f978SEmmanuel Grumbach /* 24476b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 24486b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 24496b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 24506b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 24516b28f978SEmmanuel Grumbach * associated, we would remove the station here and 24526b28f978SEmmanuel Grumbach * this would fail the recovery. 24536b28f978SEmmanuel Grumbach */ 24546b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 24556b28f978SEmmanuel Grumbach &mvm->status)) { 24566b28f978SEmmanuel Grumbach /* 24576b28f978SEmmanuel Grumbach * Remove AP station now that 24586b28f978SEmmanuel Grumbach * the MAC is unassoc 24596b28f978SEmmanuel Grumbach */ 24606b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 24616b28f978SEmmanuel Grumbach mvmvif->ap_sta_id); 2462e705c121SKalle Valo if (ret) 24636b28f978SEmmanuel Grumbach IWL_ERR(mvm, 24646b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2465e705c121SKalle Valo 24660ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 24676b28f978SEmmanuel Grumbach } 24686b28f978SEmmanuel Grumbach 2469e705c121SKalle Valo /* remove quota for this interface */ 2470e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2471e705c121SKalle Valo if (ret) 2472e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2473e705c121SKalle Valo 2474e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2475e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2476e705c121SKalle Valo if (ret) 2477e705c121SKalle Valo IWL_ERR(mvm, 2478e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2479e705c121SKalle Valo vif->addr); 2480e705c121SKalle Valo } 2481e705c121SKalle Valo 2482a07a8f37SSara Sharon /* 2483a07a8f37SSara Sharon * The firmware tracks the MU-MIMO group on its own. 2484f92659a1SSara Sharon * However, on HW restart we should restore this data. 2485a07a8f37SSara Sharon */ 2486a07a8f37SSara Sharon if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2487f92659a1SSara Sharon (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) { 2488a07a8f37SSara Sharon ret = iwl_mvm_update_mu_groups(mvm, vif); 2489a07a8f37SSara Sharon if (ret) 2490a07a8f37SSara Sharon IWL_ERR(mvm, 2491a07a8f37SSara Sharon "failed to update VHT MU_MIMO groups\n"); 2492a07a8f37SSara Sharon } 2493a07a8f37SSara Sharon 2494e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 249534672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 2496e705c121SKalle Valo 2497e705c121SKalle Valo /* reset rssi values */ 2498e705c121SKalle Valo mvmvif->bf_data.ave_beacon_signal = 0; 2499e705c121SKalle Valo 2500e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2501e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2502e705c121SKalle Valo IEEE80211_SMPS_AUTOMATIC); 2503355346baSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 2504355346baSAvraham Stern IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2505355346baSAvraham Stern iwl_mvm_config_scan(mvm); 2506b45242c9SAvraham Stern } 2507b45242c9SAvraham Stern 2508b45242c9SAvraham Stern if (changes & BSS_CHANGED_BEACON_INFO) { 2509e705c121SKalle Valo /* 2510b45242c9SAvraham Stern * We received a beacon from the associated AP so 2511e705c121SKalle Valo * remove the session protection. 2512fe959c7bSEmmanuel Grumbach * A firmware with the new API will remove it automatically. 2513e705c121SKalle Valo */ 2514fe959c7bSEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 2515fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 25163edfb5f4SAvraham Stern iwl_mvm_stop_session_protection(mvm, vif); 2517e705c121SKalle Valo 2518e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2519e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2520e705c121SKalle Valo } 2521e705c121SKalle Valo 2522283115fbSAvri Altman if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2523283115fbSAvri Altman /* 2524283115fbSAvri Altman * Send power command on every beacon change, 2525283115fbSAvri Altman * because we may have not enabled beacon abort yet. 2526283115fbSAvri Altman */ 2527283115fbSAvri Altman BSS_CHANGED_BEACON_INFO)) { 2528e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 2529e705c121SKalle Valo if (ret) 2530e705c121SKalle Valo IWL_ERR(mvm, "failed to update power mode\n"); 2531e705c121SKalle Valo } 2532e705c121SKalle Valo 2533e705c121SKalle Valo if (changes & BSS_CHANGED_CQM) { 2534e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); 2535e705c121SKalle Valo /* reset cqm events tracking */ 2536e705c121SKalle Valo mvmvif->bf_data.last_cqm_event = 0; 2537e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 2538e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 2539e705c121SKalle Valo if (ret) 2540e705c121SKalle Valo IWL_ERR(mvm, 2541e705c121SKalle Valo "failed to update CQM thresholds\n"); 2542e705c121SKalle Valo } 2543e705c121SKalle Valo } 2544e705c121SKalle Valo 2545e705c121SKalle Valo if (changes & BSS_CHANGED_ARP_FILTER) { 2546e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); 254734672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 2548e705c121SKalle Valo } 2549de34d1c1SJohannes Berg 2550de34d1c1SJohannes Berg if (changes & BSS_CHANGED_BANDWIDTH) 2551de34d1c1SJohannes Berg iwl_mvm_apply_fw_smps_request(vif); 2552e705c121SKalle Valo } 2553e705c121SKalle Valo 2554e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2555e705c121SKalle Valo struct ieee80211_vif *vif) 2556e705c121SKalle Valo { 2557e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2558e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2559c56e00a3SJohannes Berg int ret, i; 2560e705c121SKalle Valo 2561e705c121SKalle Valo mutex_lock(&mvm->mutex); 2562e705c121SKalle Valo 2563e705c121SKalle Valo /* Send the beacon template */ 2564e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); 2565e705c121SKalle Valo if (ret) 2566e705c121SKalle Valo goto out_unlock; 2567e705c121SKalle Valo 2568e705c121SKalle Valo /* 2569cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend on 2570cdaba917SEmmanuel Grumbach * the beacon interval, which was not known when the AP interface 2571cdaba917SEmmanuel Grumbach * was added. 2572e705c121SKalle Valo */ 2573e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2574e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2575e705c121SKalle Valo 2576e705c121SKalle Valo mvmvif->ap_assoc_sta_count = 0; 2577e705c121SKalle Valo 2578e705c121SKalle Valo /* Add the mac context */ 2579e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2580e705c121SKalle Valo if (ret) 2581e705c121SKalle Valo goto out_unlock; 2582e705c121SKalle Valo 2583e705c121SKalle Valo /* Perform the binding */ 2584e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2585e705c121SKalle Valo if (ret) 2586e705c121SKalle Valo goto out_remove; 2587e705c121SKalle Valo 258863dd5d02SSara Sharon /* 258963dd5d02SSara Sharon * This is not very nice, but the simplest: 259063dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 259163dd5d02SSara Sharon * cause assert 0x2b00. 259263dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 259363dd5d02SSara Sharon * the TLV 259463dd5d02SSara Sharon */ 259563dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2596ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2597ced19f26SSara Sharon if (ret) 2598ced19f26SSara Sharon goto out_unbind; 259963dd5d02SSara Sharon /* 260063dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 260163dd5d02SSara Sharon * events are added and applied to the scheduler 260263dd5d02SSara Sharon */ 2603e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 260463dd5d02SSara Sharon if (ret) { 260563dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 260663dd5d02SSara Sharon goto out_unbind; 260763dd5d02SSara Sharon } 260863dd5d02SSara Sharon } else { 260963dd5d02SSara Sharon /* 261063dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 261163dd5d02SSara Sharon * events are added and applied to the scheduler 261263dd5d02SSara Sharon */ 261375fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2614e705c121SKalle Valo if (ret) 261563dd5d02SSara Sharon goto out_unbind; 261675fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 261763dd5d02SSara Sharon if (ret) { 261863dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 261963dd5d02SSara Sharon goto out_unbind; 262063dd5d02SSara Sharon } 262163dd5d02SSara Sharon } 262226d6c16bSSara Sharon 2623e705c121SKalle Valo /* must be set before quota calculations */ 2624e705c121SKalle Valo mvmvif->ap_ibss_active = true; 2625e705c121SKalle Valo 2626c56e00a3SJohannes Berg /* send all the early keys to the device now */ 2627c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2628c56e00a3SJohannes Berg struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2629c56e00a3SJohannes Berg 2630c56e00a3SJohannes Berg if (!key) 2631c56e00a3SJohannes Berg continue; 2632c56e00a3SJohannes Berg 2633c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 2634c56e00a3SJohannes Berg 26356569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2636c56e00a3SJohannes Berg if (ret) 2637c56e00a3SJohannes Berg goto out_quota_failed; 2638c56e00a3SJohannes Berg } 2639c56e00a3SJohannes Berg 264047242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 264147242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, true, 264247242744STova Mussai LOW_LATENCY_VIF_TYPE); 264347242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 264447242744STova Mussai } 264547242744STova Mussai 2646e705c121SKalle Valo /* power updated needs to be done before quotas */ 2647e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2648e705c121SKalle Valo 2649e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2650e705c121SKalle Valo if (ret) 2651e705c121SKalle Valo goto out_quota_failed; 2652e705c121SKalle Valo 2653e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2654e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2655e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2656e705c121SKalle Valo 2657e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2658e705c121SKalle Valo 2659e705c121SKalle Valo /* we don't support TDLS during DCM */ 2660e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2661e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2662e705c121SKalle Valo 2663b73f9a4aSJohannes Berg iwl_mvm_ftm_restart_responder(mvm, vif); 2664b73f9a4aSJohannes Berg 2665e705c121SKalle Valo goto out_unlock; 2666e705c121SKalle Valo 2667e705c121SKalle Valo out_quota_failed: 2668e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2669e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2670e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2671ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2672e705c121SKalle Valo out_unbind: 2673e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2674e705c121SKalle Valo out_remove: 2675e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2676e705c121SKalle Valo out_unlock: 2677e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2678e705c121SKalle Valo return ret; 2679e705c121SKalle Valo } 2680e705c121SKalle Valo 2681e705c121SKalle Valo static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 2682e705c121SKalle Valo struct ieee80211_vif *vif) 2683e705c121SKalle Valo { 2684e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2685e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2686e705c121SKalle Valo 2687e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 2688e705c121SKalle Valo 2689e705c121SKalle Valo mutex_lock(&mvm->mutex); 2690e705c121SKalle Valo 2691e705c121SKalle Valo /* Handle AP stop while in CSA */ 2692e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 2693e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 2694e705c121SKalle Valo &mvmvif->time_event_data); 2695e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 2696e705c121SKalle Valo mvmvif->csa_countdown = false; 2697e705c121SKalle Valo } 2698e705c121SKalle Valo 2699e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 2700e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2701e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 2702e705c121SKalle Valo } 2703e705c121SKalle Valo 2704e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2705e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 2706e705c121SKalle Valo 270747242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 270847242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 270947242744STova Mussai LOW_LATENCY_VIF_TYPE); 271047242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 271147242744STova Mussai } 271247242744STova Mussai 2713e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2714e705c121SKalle Valo 2715e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2716e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2717e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2718e705c121SKalle Valo 2719e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 2720ced19f26SSara Sharon 2721be82ecd3SAvraham Stern iwl_mvm_ftm_responder_clear(mvm, vif); 2722be82ecd3SAvraham Stern 2723ced19f26SSara Sharon /* 2724ced19f26SSara Sharon * This is not very nice, but the simplest: 2725ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 2726ced19f26SSara Sharon * cause assert 0x2b00. 2727ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 2728ced19f26SSara Sharon * bcast station). 2729ced19f26SSara Sharon * So make the order of removal depend on the TLV 2730ced19f26SSara Sharon */ 2731ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 273226d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2733e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2734ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 2735ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2736e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2737e705c121SKalle Valo 2738e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2739e705c121SKalle Valo 2740e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2741e705c121SKalle Valo 2742e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2743e705c121SKalle Valo } 2744e705c121SKalle Valo 2745e705c121SKalle Valo static void 2746e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 2747e705c121SKalle Valo struct ieee80211_vif *vif, 2748e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2749e705c121SKalle Valo u32 changes) 2750e705c121SKalle Valo { 2751e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2752e705c121SKalle Valo 2753e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 2754e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 2755e705c121SKalle Valo return; 2756e705c121SKalle Valo 2757e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 2758e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 2759e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 2760e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2761e705c121SKalle Valo 2762e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 2763e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 2764e705c121SKalle Valo iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) 2765e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 2766e705c121SKalle Valo 2767b73f9a4aSJohannes Berg if (changes & BSS_CHANGED_FTM_RESPONDER) { 2768b73f9a4aSJohannes Berg int ret = iwl_mvm_ftm_start_responder(mvm, vif); 2769b73f9a4aSJohannes Berg 2770b73f9a4aSJohannes Berg if (ret) 2771b73f9a4aSJohannes Berg IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 2772b73f9a4aSJohannes Berg ret); 2773b73f9a4aSJohannes Berg } 2774b73f9a4aSJohannes Berg 2775e705c121SKalle Valo } 2776e705c121SKalle Valo 2777e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 2778e705c121SKalle Valo struct ieee80211_vif *vif, 2779e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2780e705c121SKalle Valo u32 changes) 2781e705c121SKalle Valo { 2782e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2783e705c121SKalle Valo 2784e705c121SKalle Valo mutex_lock(&mvm->mutex); 2785e705c121SKalle Valo 2786e705c121SKalle Valo if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) 2787e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 2788e705c121SKalle Valo 2789e705c121SKalle Valo switch (vif->type) { 2790e705c121SKalle Valo case NL80211_IFTYPE_STATION: 2791e705c121SKalle Valo iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 2792e705c121SKalle Valo break; 2793e705c121SKalle Valo case NL80211_IFTYPE_AP: 2794e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 2795e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 2796e705c121SKalle Valo break; 279791b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 279891b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 279991b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 280091b08c2dSAviya Erenfeld break; 2801e705c121SKalle Valo default: 2802e705c121SKalle Valo /* shouldn't happen */ 2803e705c121SKalle Valo WARN_ON_ONCE(1); 2804e705c121SKalle Valo } 2805e705c121SKalle Valo 28069aae43a4SJohannes Berg if (changes & BSS_CHANGED_TXPOWER) { 28079aae43a4SJohannes Berg IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 28089aae43a4SJohannes Berg bss_conf->txpower); 28099aae43a4SJohannes Berg iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 28109aae43a4SJohannes Berg } 28119aae43a4SJohannes Berg 2812e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2813e705c121SKalle Valo } 2814e705c121SKalle Valo 2815e705c121SKalle Valo static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, 2816e705c121SKalle Valo struct ieee80211_vif *vif, 2817e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 2818e705c121SKalle Valo { 2819e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2820e705c121SKalle Valo int ret; 2821e705c121SKalle Valo 2822e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 2823e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 2824e705c121SKalle Valo return -EINVAL; 2825e705c121SKalle Valo 2826e705c121SKalle Valo mutex_lock(&mvm->mutex); 2827e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 2828e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2829e705c121SKalle Valo 2830e705c121SKalle Valo return ret; 2831e705c121SKalle Valo } 2832e705c121SKalle Valo 2833e705c121SKalle Valo static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 2834e705c121SKalle Valo struct ieee80211_vif *vif) 2835e705c121SKalle Valo { 2836e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2837e705c121SKalle Valo 2838e705c121SKalle Valo mutex_lock(&mvm->mutex); 2839e705c121SKalle Valo 2840e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 2841e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 2842e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 2843e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 2844e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 2845e705c121SKalle Valo * To handle that, simply return if the scan is not running. 2846e705c121SKalle Valo */ 2847e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 2848e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 2849e705c121SKalle Valo 2850e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2851e705c121SKalle Valo } 2852e705c121SKalle Valo 2853e705c121SKalle Valo static void 2854e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 2855e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2856e705c121SKalle Valo int num_frames, 2857e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2858e705c121SKalle Valo bool more_data) 2859e705c121SKalle Valo { 2860e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2861e705c121SKalle Valo 2862e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 2863e705c121SKalle Valo 2864e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2865e705c121SKalle Valo tids, more_data, false); 2866e705c121SKalle Valo } 2867e705c121SKalle Valo 2868e705c121SKalle Valo static void 2869e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 2870e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2871e705c121SKalle Valo int num_frames, 2872e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2873e705c121SKalle Valo bool more_data) 2874e705c121SKalle Valo { 2875e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2876e705c121SKalle Valo 28779a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 2878e705c121SKalle Valo 2879e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2880e705c121SKalle Valo tids, more_data, true); 2881e705c121SKalle Valo } 2882e705c121SKalle Valo 288365e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 2884e705c121SKalle Valo enum sta_notify_cmd cmd, 2885e705c121SKalle Valo struct ieee80211_sta *sta) 2886e705c121SKalle Valo { 2887e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2888e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2889e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 2890e705c121SKalle Valo int tid; 2891e705c121SKalle Valo 2892960f864bSJohannes Berg /* 2893960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 2894960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 2895960f864bSJohannes Berg * should have firmware supporting buffer station offload. 2896960f864bSJohannes Berg */ 2897960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 2898960f864bSJohannes Berg return; 2899960f864bSJohannes Berg 2900e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2901311590a3SEmmanuel Grumbach for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 2902e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2903e705c121SKalle Valo 29046862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 29051c17627bSSara Sharon continue; 29061c17627bSSara Sharon 2907e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 2908e705c121SKalle Valo 2909dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 2910e705c121SKalle Valo continue; 2911e705c121SKalle Valo 2912e705c121SKalle Valo __set_bit(tid, &tids); 2913e705c121SKalle Valo } 2914e705c121SKalle Valo 2915e705c121SKalle Valo switch (cmd) { 2916e705c121SKalle Valo case STA_NOTIFY_SLEEP: 2917e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 2918e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 2919e705c121SKalle Valo 2920e705c121SKalle Valo if (txqs) 2921e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 2922e705c121SKalle Valo /* 2923e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 2924e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 2925e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 2926e705c121SKalle Valo */ 2927e705c121SKalle Valo break; 2928e705c121SKalle Valo case STA_NOTIFY_AWAKE: 29290ae98812SSara Sharon if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA)) 2930e705c121SKalle Valo break; 2931e705c121SKalle Valo 2932e705c121SKalle Valo if (txqs) 2933e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 2934e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 2935e705c121SKalle Valo break; 2936e705c121SKalle Valo default: 2937e705c121SKalle Valo break; 2938e705c121SKalle Valo } 2939e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2940e705c121SKalle Valo } 2941e705c121SKalle Valo 294265e25482SJohannes Berg static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 294365e25482SJohannes Berg struct ieee80211_vif *vif, 294465e25482SJohannes Berg enum sta_notify_cmd cmd, 294565e25482SJohannes Berg struct ieee80211_sta *sta) 294665e25482SJohannes Berg { 294765e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 294865e25482SJohannes Berg } 294965e25482SJohannes Berg 295065e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 295165e25482SJohannes Berg { 295265e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 295365e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 295465e25482SJohannes Berg struct ieee80211_sta *sta; 295565e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 295665e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 295765e25482SJohannes Berg 2958be9ae34eSNathan Errera if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 295965e25482SJohannes Berg return; 296065e25482SJohannes Berg 296165e25482SJohannes Berg rcu_read_lock(); 2962a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 296365e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 296465e25482SJohannes Berg rcu_read_unlock(); 296565e25482SJohannes Berg return; 296665e25482SJohannes Berg } 296765e25482SJohannes Berg 296865e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 296965e25482SJohannes Berg 297065e25482SJohannes Berg if (!mvmsta->vif || 297165e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 297265e25482SJohannes Berg rcu_read_unlock(); 297365e25482SJohannes Berg return; 297465e25482SJohannes Berg } 297565e25482SJohannes Berg 297665e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 297765e25482SJohannes Berg mvmsta->sleeping = sleeping; 297865e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 297965e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 298065e25482SJohannes Berg sta); 298165e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 298265e25482SJohannes Berg } 298365e25482SJohannes Berg 298465e25482SJohannes Berg if (sleeping) { 298565e25482SJohannes Berg switch (notif->type) { 298665e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 298765e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 298865e25482SJohannes Berg break; 298965e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 299065e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 299165e25482SJohannes Berg break; 299265e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 299365e25482SJohannes Berg ieee80211_sta_pspoll(sta); 299465e25482SJohannes Berg break; 299565e25482SJohannes Berg default: 299665e25482SJohannes Berg break; 299765e25482SJohannes Berg } 299865e25482SJohannes Berg } 299965e25482SJohannes Berg 300065e25482SJohannes Berg rcu_read_unlock(); 300165e25482SJohannes Berg } 300265e25482SJohannes Berg 3003e705c121SKalle Valo static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 3004e705c121SKalle Valo struct ieee80211_vif *vif, 3005e705c121SKalle Valo struct ieee80211_sta *sta) 3006e705c121SKalle Valo { 3007e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3008e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3009e705c121SKalle Valo 3010e705c121SKalle Valo /* 3011e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 3012e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 3013e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 3014e705c121SKalle Valo * be able to find the station this way, and we don't rely 3015e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 3016e705c121SKalle Valo * callback deleted the station. 3017e705c121SKalle Valo */ 3018e705c121SKalle Valo mutex_lock(&mvm->mutex); 3019e705c121SKalle Valo if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) 3020e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], 3021e705c121SKalle Valo ERR_PTR(-ENOENT)); 3022e705c121SKalle Valo 3023e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3024e705c121SKalle Valo } 3025e705c121SKalle Valo 3026e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 3027e705c121SKalle Valo const u8 *bssid) 3028e705c121SKalle Valo { 3029b0ffe455SJohannes Berg int i; 3030b0ffe455SJohannes Berg 3031b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 3032b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 3033b0ffe455SJohannes Berg 3034b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 3035b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 3036b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 3037b0ffe455SJohannes Berg } 3038b0ffe455SJohannes Berg 3039e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 3040e705c121SKalle Valo return; 3041e705c121SKalle Valo 3042c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 3043cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3044cee5a882SAvri Altman return; 3045cee5a882SAvri Altman } 3046cee5a882SAvri Altman 304711dee0b4SEmmanuel Grumbach if (!vif->p2p && 304811dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 3049e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3050e705c121SKalle Valo return; 3051e705c121SKalle Valo } 3052e705c121SKalle Valo 3053b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 3054b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 3055b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 3056b0ffe455SJohannes Berg return; 3057b0ffe455SJohannes Berg } 3058b0ffe455SJohannes Berg } 3059b0ffe455SJohannes Berg 3060e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 3061e705c121SKalle Valo } 3062e705c121SKalle Valo 30631e8f1329SGolan Ben-Ami static void 30641e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 30651e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 30661e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 30671e8f1329SGolan Ben-Ami { 30681e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 30691e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 30701e8f1329SGolan Ben-Ami 30716c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 30726c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 30736c042d75SSara Sharon if (!trig) 30741e8f1329SGolan Ben-Ami return; 30751e8f1329SGolan Ben-Ami 30761e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 30771e8f1329SGolan Ben-Ami 30781e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 30791e8f1329SGolan Ben-Ami return; 30801e8f1329SGolan Ben-Ami 30811e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 30821e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 30831e8f1329SGolan Ben-Ami return; 30841e8f1329SGolan Ben-Ami 30857174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 30861e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 30871e8f1329SGolan Ben-Ami peer_addr, action); 30881e8f1329SGolan Ben-Ami } 30891e8f1329SGolan Ben-Ami 30904f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data { 30914f58121dSIlan Peer bool tolerated; 30924f58121dSIlan Peer }; 30934f58121dSIlan Peer 30944f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 30954f58121dSIlan Peer struct cfg80211_bss *bss, 30964f58121dSIlan Peer void *_data) 30974f58121dSIlan Peer { 30984f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 30996c608cd6SJohannes Berg const struct cfg80211_bss_ies *ies; 31004f58121dSIlan Peer const struct element *elem; 31014f58121dSIlan Peer 31026c608cd6SJohannes Berg rcu_read_lock(); 31036c608cd6SJohannes Berg ies = rcu_dereference(bss->ies); 31046c608cd6SJohannes Berg elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 31056c608cd6SJohannes Berg ies->len); 31064f58121dSIlan Peer 31074f58121dSIlan Peer if (!elem || elem->datalen < 10 || 31084f58121dSIlan Peer !(elem->data[10] & 31094f58121dSIlan Peer WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 31104f58121dSIlan Peer data->tolerated = false; 31114f58121dSIlan Peer } 31126c608cd6SJohannes Berg rcu_read_unlock(); 31134f58121dSIlan Peer } 31144f58121dSIlan Peer 31154f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 31164f58121dSIlan Peer struct ieee80211_vif *vif) 31174f58121dSIlan Peer { 31184f58121dSIlan Peer struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 31194f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 31204f58121dSIlan Peer .tolerated = true, 31214f58121dSIlan Peer }; 31224f58121dSIlan Peer 31234f58121dSIlan Peer if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) { 31244f58121dSIlan Peer mvmvif->he_ru_2mhz_block = false; 31254f58121dSIlan Peer return; 31264f58121dSIlan Peer } 31274f58121dSIlan Peer 31284f58121dSIlan Peer cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, 31294f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru_iter, 31304f58121dSIlan Peer &iter_data); 31314f58121dSIlan Peer 31324f58121dSIlan Peer /* 31334f58121dSIlan Peer * If there is at least one AP on radar channel that cannot 31344f58121dSIlan Peer * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 31354f58121dSIlan Peer */ 31364f58121dSIlan Peer mvmvif->he_ru_2mhz_block = !iter_data.tolerated; 31374f58121dSIlan Peer } 31384f58121dSIlan Peer 3139f7d6ef33SJohannes Berg static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3140f7d6ef33SJohannes Berg struct ieee80211_vif *vif) 3141f7d6ef33SJohannes Berg { 3142f7d6ef33SJohannes Berg struct ieee80211_supported_band *sband; 3143f7d6ef33SJohannes Berg const struct ieee80211_sta_he_cap *he_cap; 3144f7d6ef33SJohannes Berg 3145f7d6ef33SJohannes Berg if (vif->type != NL80211_IFTYPE_STATION) 3146f7d6ef33SJohannes Berg return; 3147f7d6ef33SJohannes Berg 3148f7d6ef33SJohannes Berg if (!mvm->cca_40mhz_workaround) 3149f7d6ef33SJohannes Berg return; 3150f7d6ef33SJohannes Berg 3151f7d6ef33SJohannes Berg /* decrement and check that we reached zero */ 3152f7d6ef33SJohannes Berg mvm->cca_40mhz_workaround--; 3153f7d6ef33SJohannes Berg if (mvm->cca_40mhz_workaround) 3154f7d6ef33SJohannes Berg return; 3155f7d6ef33SJohannes Berg 3156f7d6ef33SJohannes Berg sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3157f7d6ef33SJohannes Berg 3158f7d6ef33SJohannes Berg sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3159f7d6ef33SJohannes Berg 3160f7d6ef33SJohannes Berg he_cap = ieee80211_get_he_iftype_cap(sband, 3161f7d6ef33SJohannes Berg ieee80211_vif_type_p2p(vif)); 3162f7d6ef33SJohannes Berg 3163f7d6ef33SJohannes Berg if (he_cap) { 3164f7d6ef33SJohannes Berg /* we know that ours is writable */ 3165f7d6ef33SJohannes Berg struct ieee80211_sta_he_cap *he = (void *)he_cap; 3166f7d6ef33SJohannes Berg 3167f7d6ef33SJohannes Berg he->he_cap_elem.phy_cap_info[0] |= 3168f7d6ef33SJohannes Berg IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3169f7d6ef33SJohannes Berg } 3170f7d6ef33SJohannes Berg } 3171f7d6ef33SJohannes Berg 31726d19a5ebSEmmanuel Grumbach static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 31736d19a5ebSEmmanuel Grumbach struct ieee80211_vif *vif, 31746d19a5ebSEmmanuel Grumbach struct iwl_mvm_sta *mvm_sta) 31756d19a5ebSEmmanuel Grumbach { 31766d19a5ebSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI) 31776d19a5ebSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 31786d19a5ebSEmmanuel Grumbach struct iwl_mei_conn_info conn_info = { 31796d19a5ebSEmmanuel Grumbach .ssid_len = vif->bss_conf.ssid_len, 31806d19a5ebSEmmanuel Grumbach .channel = vif->bss_conf.chandef.chan->hw_value, 31816d19a5ebSEmmanuel Grumbach }; 31826d19a5ebSEmmanuel Grumbach 31836d19a5ebSEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 31846d19a5ebSEmmanuel Grumbach return; 31856d19a5ebSEmmanuel Grumbach 31866d19a5ebSEmmanuel Grumbach if (!mvm->mei_registered) 31876d19a5ebSEmmanuel Grumbach return; 31886d19a5ebSEmmanuel Grumbach 31896d19a5ebSEmmanuel Grumbach switch (mvm_sta->pairwise_cipher) { 31906d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_CCMP: 31916d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 31926d19a5ebSEmmanuel Grumbach break; 31936d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP: 31946d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 31956d19a5ebSEmmanuel Grumbach break; 31966d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP_256: 31976d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 31986d19a5ebSEmmanuel Grumbach break; 31996d19a5ebSEmmanuel Grumbach case 0: 32006d19a5ebSEmmanuel Grumbach /* open profile */ 32016d19a5ebSEmmanuel Grumbach break; 32026d19a5ebSEmmanuel Grumbach default: 32036d19a5ebSEmmanuel Grumbach /* cipher not supported, don't send anything to iwlmei */ 32046d19a5ebSEmmanuel Grumbach return; 32056d19a5ebSEmmanuel Grumbach } 32066d19a5ebSEmmanuel Grumbach 32076d19a5ebSEmmanuel Grumbach switch (mvmvif->rekey_data.akm) { 32086d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_SAE & 0xff: 32096d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 32106d19a5ebSEmmanuel Grumbach break; 32116d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_PSK & 0xff: 32126d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 32136d19a5ebSEmmanuel Grumbach break; 32146d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_8021X & 0xff: 32156d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 32166d19a5ebSEmmanuel Grumbach break; 32176d19a5ebSEmmanuel Grumbach case 0: 32186d19a5ebSEmmanuel Grumbach /* open profile */ 32196d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 32206d19a5ebSEmmanuel Grumbach break; 32216d19a5ebSEmmanuel Grumbach default: 32226d19a5ebSEmmanuel Grumbach /* auth method / AKM not supported */ 32236d19a5ebSEmmanuel Grumbach /* TODO: All the FT vesions of these? */ 32246d19a5ebSEmmanuel Grumbach return; 32256d19a5ebSEmmanuel Grumbach } 32266d19a5ebSEmmanuel Grumbach 32276d19a5ebSEmmanuel Grumbach memcpy(conn_info.ssid, vif->bss_conf.ssid, vif->bss_conf.ssid_len); 32286d19a5ebSEmmanuel Grumbach memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 32296d19a5ebSEmmanuel Grumbach 32306d19a5ebSEmmanuel Grumbach /* TODO: add support for collocated AP data */ 32316d19a5ebSEmmanuel Grumbach iwl_mei_host_associated(&conn_info, NULL); 32326d19a5ebSEmmanuel Grumbach #endif 32336d19a5ebSEmmanuel Grumbach } 32346d19a5ebSEmmanuel Grumbach 3235e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3236e705c121SKalle Valo struct ieee80211_vif *vif, 3237e705c121SKalle Valo struct ieee80211_sta *sta, 3238e705c121SKalle Valo enum ieee80211_sta_state old_state, 3239e705c121SKalle Valo enum ieee80211_sta_state new_state) 3240e705c121SKalle Valo { 3241e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3242e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 32436ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3244e705c121SKalle Valo int ret; 3245e705c121SKalle Valo 3246e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 3247e705c121SKalle Valo sta->addr, old_state, new_state); 3248e705c121SKalle Valo 3249e705c121SKalle Valo /* this would be a mac80211 bug ... but don't crash */ 3250e705c121SKalle Valo if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) 3251fe56d05eSSara Sharon return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL; 3252e705c121SKalle Valo 325324afba76SLiad Kaufman /* 325424afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 325524afba76SLiad Kaufman * 325624afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 325724afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 325824afba76SLiad Kaufman * the queues. 325924afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 326024afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 326124afba76SLiad Kaufman * of. 326224afba76SLiad Kaufman * 326324afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 326424afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 326524afba76SLiad Kaufman */ 326624afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 3267c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 326824afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 326924afba76SLiad Kaufman 327024afba76SLiad Kaufman /* 327124afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 327224afba76SLiad Kaufman * worker will already remove it if it was on 327324afba76SLiad Kaufman */ 3274f7d6ef33SJohannes Berg 3275f7d6ef33SJohannes Berg /* 3276f7d6ef33SJohannes Berg * Additionally, reset the 40 MHz capability if we disconnected 3277f7d6ef33SJohannes Berg * from the AP now. 3278f7d6ef33SJohannes Berg */ 3279f7d6ef33SJohannes Berg iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 328024afba76SLiad Kaufman } 328124afba76SLiad Kaufman 3282e705c121SKalle Valo mutex_lock(&mvm->mutex); 32836ea29ce5SJohannes Berg /* track whether or not the station is associated */ 3284d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 32856ea29ce5SJohannes Berg 3286e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3287e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3288e705c121SKalle Valo /* 3289e705c121SKalle Valo * Firmware bug - it'll crash if the beacon interval is less 3290e705c121SKalle Valo * than 16. We can't avoid connecting at all, so refuse the 3291e705c121SKalle Valo * station state change, this will cause mac80211 to abandon 3292e705c121SKalle Valo * attempts to connect to this AP, and eventually wpa_s will 3293cdaba917SEmmanuel Grumbach * blocklist the AP... 3294e705c121SKalle Valo */ 3295e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3296e705c121SKalle Valo vif->bss_conf.beacon_int < 16) { 3297e705c121SKalle Valo IWL_ERR(mvm, 3298e705c121SKalle Valo "AP %pM beacon interval is %d, refusing due to firmware bug!\n", 3299e705c121SKalle Valo sta->addr, vif->bss_conf.beacon_int); 3300e705c121SKalle Valo ret = -EINVAL; 3301e705c121SKalle Valo goto out_unlock; 3302e705c121SKalle Valo } 3303e705c121SKalle Valo 330497cc1694SAvraham Stern if (vif->type == NL80211_IFTYPE_STATION) 330597cc1694SAvraham Stern vif->bss_conf.he_support = sta->he_cap.has_he; 330697cc1694SAvraham Stern 3307e705c121SKalle Valo if (sta->tdls && 3308e705c121SKalle Valo (vif->p2p || 3309e705c121SKalle Valo iwl_mvm_tdls_sta_count(mvm, NULL) == 3310e705c121SKalle Valo IWL_MVM_TDLS_STA_COUNT || 3311e705c121SKalle Valo iwl_mvm_phy_ctx_count(mvm) > 1)) { 3312e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 3313e705c121SKalle Valo ret = -EBUSY; 3314e705c121SKalle Valo goto out_unlock; 3315e705c121SKalle Valo } 3316e705c121SKalle Valo 3317e705c121SKalle Valo ret = iwl_mvm_add_sta(mvm, vif, sta); 33181e8f1329SGolan Ben-Ami if (sta->tdls && ret == 0) { 3319e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, true); 33201e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 33211e8f1329SGolan Ben-Ami NL80211_TDLS_SETUP); 33221e8f1329SGolan Ben-Ami } 3323438af969SSara Sharon 3324438af969SSara Sharon sta->max_rc_amsdu_len = 1; 3325e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3326e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 3327e705c121SKalle Valo /* 3328e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 3329e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 3330e705c121SKalle Valo */ 3331e705c121SKalle Valo mvm->last_ebs_successful = true; 3332e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 3333e705c121SKalle Valo ret = 0; 3334e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3335e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 33368be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 33379394662aSLiad Kaufman vif->bss_conf.he_support = sta->he_cap.has_he; 33388be30c13SAyala Beker mvmvif->ap_assoc_sta_count++; 33398be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 334002221a81SShaul Triebitz if (vif->bss_conf.he_support && 334102221a81SShaul Triebitz !iwlwifi_mod_params.disable_11ax) 334202221a81SShaul Triebitz iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id); 33439394662aSLiad Kaufman } else if (vif->type == NL80211_IFTYPE_STATION) { 33449394662aSLiad Kaufman vif->bss_conf.he_support = sta->he_cap.has_he; 33454f58121dSIlan Peer 33464f58121dSIlan Peer mvmvif->he_ru_2mhz_block = false; 33474f58121dSIlan Peer if (sta->he_cap.has_he) 33484f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif); 33494f58121dSIlan Peer 33509394662aSLiad Kaufman iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 33518be30c13SAyala Beker } 3352735a0045SGoodstein, Mordechay 33533baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 33543baf7528SAvraham Stern false); 3355735a0045SGoodstein, Mordechay ret = iwl_mvm_update_sta(mvm, vif, sta); 3356e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3357e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 335828916a16SEmmanuel Grumbach ret = 0; 3359e705c121SKalle Valo 3360e705c121SKalle Valo /* we don't support TDLS during DCM */ 3361e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 3362e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3363e705c121SKalle Valo 33644634b176SJohannes Berg if (sta->tdls) { 33651e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 33661e8f1329SGolan Ben-Ami NL80211_TDLS_ENABLE_LINK); 33674634b176SJohannes Berg } else { 3368e705c121SKalle Valo /* enable beacon filtering */ 3369e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 33706b7a5aeaSNaftali Goldstein 33718b75858cSJohannes Berg mvmvif->authorized = 1; 33728b75858cSJohannes Berg 337350f56044SIlan Peer /* 337450f56044SIlan Peer * Now that the station is authorized, i.e., keys were already 337550f56044SIlan Peer * installed, need to indicate to the FW that 337650f56044SIlan Peer * multicast data frames can be forwarded to the driver 337750f56044SIlan Peer */ 337850f56044SIlan Peer iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 33796d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 33804634b176SJohannes Berg } 338150f56044SIlan Peer 33823baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 33833baf7528SAvraham Stern true); 3384e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 3385e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 3386*d9e95e35SMordechay Goodstein /* once we move into assoc state, need to update rate scale to 3387*d9e95e35SMordechay Goodstein * disable using wide bandwidth 3388*d9e95e35SMordechay Goodstein */ 3389*d9e95e35SMordechay Goodstein iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 3390*d9e95e35SMordechay Goodstein false); 33914634b176SJohannes Berg if (!sta->tdls) { 339250f56044SIlan Peer /* Multicast data frames are no longer allowed */ 339350f56044SIlan Peer iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 339450f56044SIlan Peer 33958b75858cSJohannes Berg /* 33968b75858cSJohannes Berg * Set this after the above iwl_mvm_mac_ctxt_changed() 33978b75858cSJohannes Berg * to avoid sending high prio again for a little time. 33988b75858cSJohannes Berg */ 33998b75858cSJohannes Berg mvmvif->authorized = 0; 34008b75858cSJohannes Berg 3401e705c121SKalle Valo /* disable beacon filtering */ 340269e508b4SIlan Peer ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 340369e508b4SIlan Peer WARN_ON(ret && 340469e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 340569e508b4SIlan Peer &mvm->status)); 34064634b176SJohannes Berg } 3407e705c121SKalle Valo ret = 0; 3408e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3409e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 34108be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 34118be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 34128be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3413d5d8ee52SEmmanuel Grumbach } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3414cf7a7457SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 3415e705c121SKalle Valo ret = 0; 3416e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3417e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3418e705c121SKalle Valo ret = 0; 3419e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3420e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 3421d5d8ee52SEmmanuel Grumbach if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3422d5d8ee52SEmmanuel Grumbach iwl_mvm_stop_session_protection(mvm, vif); 3423e705c121SKalle Valo ret = iwl_mvm_rm_sta(mvm, vif, sta); 34241e8f1329SGolan Ben-Ami if (sta->tdls) { 3425e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 34261e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 34271e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 34281e8f1329SGolan Ben-Ami } 342934a880d8SLiad Kaufman 343044135b7cSIlan Peer if (unlikely(ret && 343144135b7cSIlan Peer test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 343244135b7cSIlan Peer &mvm->status))) 343344135b7cSIlan Peer ret = 0; 3434e705c121SKalle Valo } else { 3435e705c121SKalle Valo ret = -EIO; 3436e705c121SKalle Valo } 3437e705c121SKalle Valo out_unlock: 3438e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3439e705c121SKalle Valo 3440e705c121SKalle Valo if (sta->tdls && ret == 0) { 3441e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3442e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 3443e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3444e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 3445e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 3446e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3447e705c121SKalle Valo } 3448e705c121SKalle Valo 3449e705c121SKalle Valo return ret; 3450e705c121SKalle Valo } 3451e705c121SKalle Valo 3452e705c121SKalle Valo static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3453e705c121SKalle Valo { 3454e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3455e705c121SKalle Valo 3456e705c121SKalle Valo mvm->rts_threshold = value; 3457e705c121SKalle Valo 3458e705c121SKalle Valo return 0; 3459e705c121SKalle Valo } 3460e705c121SKalle Valo 3461e705c121SKalle Valo static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, 3462e705c121SKalle Valo struct ieee80211_vif *vif, 3463e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 3464e705c121SKalle Valo { 3465e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3466dcfe3b10SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3467dcfe3b10SJohannes Berg 3468dcfe3b10SJohannes Berg if (changed & (IEEE80211_RC_BW_CHANGED | 3469dcfe3b10SJohannes Berg IEEE80211_RC_SUPP_RATES_CHANGED | 3470dcfe3b10SJohannes Berg IEEE80211_RC_NSS_CHANGED)) 3471dcfe3b10SJohannes Berg iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 3472dcfe3b10SJohannes Berg true); 3473e705c121SKalle Valo 3474e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3475e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 3476e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 3477e705c121SKalle Valo } 3478e705c121SKalle Valo 3479e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 3480e705c121SKalle Valo struct ieee80211_vif *vif, u16 ac, 3481e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 3482e705c121SKalle Valo { 3483e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3484e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3485e705c121SKalle Valo 3486e705c121SKalle Valo mvmvif->queue_params[ac] = *params; 3487e705c121SKalle Valo 3488e705c121SKalle Valo /* 3489e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 3490e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 3491e705c121SKalle Valo */ 3492e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 3493e705c121SKalle Valo int ret; 3494e705c121SKalle Valo 3495e705c121SKalle Valo mutex_lock(&mvm->mutex); 3496e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3497e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3498e705c121SKalle Valo return ret; 3499e705c121SKalle Valo } 3500e705c121SKalle Valo return 0; 3501e705c121SKalle Valo } 3502e705c121SKalle Valo 3503e705c121SKalle Valo static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 3504d4e36e55SIlan Peer struct ieee80211_vif *vif, 350515fae341SJohannes Berg struct ieee80211_prep_tx_info *info) 3506e705c121SKalle Valo { 3507e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3508d4e36e55SIlan Peer 3509e705c121SKalle Valo mutex_lock(&mvm->mutex); 3510af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, info->duration); 3511e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3512e705c121SKalle Valo } 3513e705c121SKalle Valo 35146b1259d1SJohannes Berg static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 35156b1259d1SJohannes Berg struct ieee80211_vif *vif, 35166b1259d1SJohannes Berg struct ieee80211_prep_tx_info *info) 35176b1259d1SJohannes Berg { 35186b1259d1SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 35196b1259d1SJohannes Berg 35206b1259d1SJohannes Berg /* for successful cases (auth/assoc), don't cancel session protection */ 35216b1259d1SJohannes Berg if (info->success) 35226b1259d1SJohannes Berg return; 35236b1259d1SJohannes Berg 35246b1259d1SJohannes Berg mutex_lock(&mvm->mutex); 35256b1259d1SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 35266b1259d1SJohannes Berg mutex_unlock(&mvm->mutex); 35276b1259d1SJohannes Berg } 35286b1259d1SJohannes Berg 3529e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 3530e705c121SKalle Valo struct ieee80211_vif *vif, 3531e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 3532e705c121SKalle Valo struct ieee80211_scan_ies *ies) 3533e705c121SKalle Valo { 3534e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3535e705c121SKalle Valo 3536e705c121SKalle Valo int ret; 3537e705c121SKalle Valo 3538e705c121SKalle Valo mutex_lock(&mvm->mutex); 3539e705c121SKalle Valo 3540e705c121SKalle Valo if (!vif->bss_conf.idle) { 3541e705c121SKalle Valo ret = -EBUSY; 3542e705c121SKalle Valo goto out; 3543e705c121SKalle Valo } 3544e705c121SKalle Valo 3545e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 3546e705c121SKalle Valo 3547e705c121SKalle Valo out: 3548e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3549e705c121SKalle Valo return ret; 3550e705c121SKalle Valo } 3551e705c121SKalle Valo 3552e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 3553e705c121SKalle Valo struct ieee80211_vif *vif) 3554e705c121SKalle Valo { 3555e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3556e705c121SKalle Valo int ret; 3557e705c121SKalle Valo 3558e705c121SKalle Valo mutex_lock(&mvm->mutex); 3559e705c121SKalle Valo 3560e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3561e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 3562e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 3563e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 3564e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 3565e705c121SKalle Valo * could run. To handle this, simply return if the scan is 3566e705c121SKalle Valo * not running. 3567e705c121SKalle Valo */ 3568e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 3569e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3570e705c121SKalle Valo return 0; 3571e705c121SKalle Valo } 3572e705c121SKalle Valo 3573e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 3574e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3575e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 3576e705c121SKalle Valo 3577e705c121SKalle Valo return ret; 3578e705c121SKalle Valo } 3579e705c121SKalle Valo 35806569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 3581e705c121SKalle Valo enum set_key_cmd cmd, 3582e705c121SKalle Valo struct ieee80211_vif *vif, 3583e705c121SKalle Valo struct ieee80211_sta *sta, 3584e705c121SKalle Valo struct ieee80211_key_conf *key) 3585e705c121SKalle Valo { 3586c56e00a3SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3587e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 358846c7b05aSEmmanuel Grumbach struct iwl_mvm_sta *mvmsta = NULL; 3589f5e28eacSJohannes Berg struct iwl_mvm_key_pn *ptk_pn; 3590f5e28eacSJohannes Berg int keyidx = key->keyidx; 3591c56e00a3SJohannes Berg int ret, i; 35924615fd15SEmmanuel Grumbach u8 key_offset; 3593e705c121SKalle Valo 359446c7b05aSEmmanuel Grumbach if (sta) 35956d19a5ebSEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_mac80211(sta); 35966d19a5ebSEmmanuel Grumbach 3597e705c121SKalle Valo switch (key->cipher) { 3598e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 3599286ca8ebSLuca Coelho if (!mvm->trans->trans_cfg->gen2) { 3600e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 36011ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 36027f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 36037f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 36047f768ad5SDavid Spinadel } else { 36057f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 36067f768ad5SDavid Spinadel return -EOPNOTSUPP; 36077f768ad5SDavid Spinadel } 3608e705c121SKalle Valo break; 3609e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 36102a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 36112a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 361285aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 3613e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3614e705c121SKalle Valo break; 3615e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 36168e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 36178e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3618e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 3619e705c121SKalle Valo break; 3620e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 3621e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 3622475c6bdeSJohannes Berg if (vif->type == NL80211_IFTYPE_STATION) 3623e705c121SKalle Valo break; 3624475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 3625475c6bdeSJohannes Berg return -EOPNOTSUPP; 3626475c6bdeSJohannes Berg /* support HW crypto on TX */ 3627475c6bdeSJohannes Berg return 0; 3628e705c121SKalle Valo default: 3629e705c121SKalle Valo /* currently FW supports only one optional cipher scheme */ 3630e705c121SKalle Valo if (hw->n_cipher_schemes && 3631e705c121SKalle Valo hw->cipher_schemes->cipher == key->cipher) 3632e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3633e705c121SKalle Valo else 3634e705c121SKalle Valo return -EOPNOTSUPP; 3635e705c121SKalle Valo } 3636e705c121SKalle Valo 3637e705c121SKalle Valo switch (cmd) { 3638e705c121SKalle Valo case SET_KEY: 3639b1fdc250SJohannes Berg if (keyidx == 6 || keyidx == 7) 3640b1fdc250SJohannes Berg rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 3641b1fdc250SJohannes Berg key); 3642b1fdc250SJohannes Berg 3643e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 3644e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 3645e705c121SKalle Valo /* 3646e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 3647e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 3648e705c121SKalle Valo * we don't support them for RX, so do the same. 36498e160ab8SAyala Beker * CMAC/GMAC in AP/IBSS modes must be done in software. 3650e705c121SKalle Valo */ 36518e160ab8SAyala Beker if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 36528e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 3653a1c2ff30SAndrei Otcheretianski key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { 365481279c49SJohannes Berg ret = -EOPNOTSUPP; 3655a1c2ff30SAndrei Otcheretianski break; 3656a1c2ff30SAndrei Otcheretianski } 365785aeb58cSDavid Spinadel 365885aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 365985aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 366085aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 3661e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 3662a1c2ff30SAndrei Otcheretianski ret = 0; 3663e705c121SKalle Valo break; 3664e705c121SKalle Valo } 3665c56e00a3SJohannes Berg 3666c56e00a3SJohannes Berg if (!mvmvif->ap_ibss_active) { 3667c56e00a3SJohannes Berg for (i = 0; 3668c56e00a3SJohannes Berg i < ARRAY_SIZE(mvmvif->ap_early_keys); 3669c56e00a3SJohannes Berg i++) { 3670c56e00a3SJohannes Berg if (!mvmvif->ap_early_keys[i]) { 3671c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = key; 3672c56e00a3SJohannes Berg break; 3673c56e00a3SJohannes Berg } 3674c56e00a3SJohannes Berg } 3675c56e00a3SJohannes Berg 3676c56e00a3SJohannes Berg if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 3677c56e00a3SJohannes Berg ret = -ENOSPC; 3678a1c2ff30SAndrei Otcheretianski else 3679a1c2ff30SAndrei Otcheretianski ret = 0; 3680c56e00a3SJohannes Berg 3681c56e00a3SJohannes Berg break; 3682c56e00a3SJohannes Berg } 368385aeb58cSDavid Spinadel } 3684e705c121SKalle Valo 3685e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 3686e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 3687e705c121SKalle Valo */ 3688e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 3689e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 3690e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 3691e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 3692e705c121SKalle Valo ret = 0; 3693e705c121SKalle Valo break; 3694e705c121SKalle Valo } 3695e705c121SKalle Valo 3696f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 369746c7b05aSEmmanuel Grumbach mvmsta && iwl_mvm_has_new_rx_api(mvm) && 3698f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3699f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 37002a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 37012a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3702f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 3703f5e28eacSJohannes Berg int tid, q; 3704f5e28eacSJohannes Berg 3705f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 3706acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 3707acafe7e3SKees Cook mvm->trans->num_rx_queues), 3708f5e28eacSJohannes Berg GFP_KERNEL); 3709f5e28eacSJohannes Berg if (!ptk_pn) { 3710f5e28eacSJohannes Berg ret = -ENOMEM; 3711f5e28eacSJohannes Berg break; 3712f5e28eacSJohannes Berg } 3713f5e28eacSJohannes Berg 3714f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 3715f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 3716f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 3717f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 3718f5e28eacSJohannes Berg seq.ccmp.pn, 3719f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 3720f5e28eacSJohannes Berg } 3721f5e28eacSJohannes Berg 3722f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 3723f5e28eacSJohannes Berg } 3724f5e28eacSJohannes Berg 37254615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 37264615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 37274615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 37284615fd15SEmmanuel Grumbach else 37294615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 37304615fd15SEmmanuel Grumbach 373146c7b05aSEmmanuel Grumbach if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 37326d19a5ebSEmmanuel Grumbach mvmsta->pairwise_cipher = key->cipher; 37336d19a5ebSEmmanuel Grumbach 3734e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); 37354615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 3736e705c121SKalle Valo if (ret) { 3737e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 3738475c6bdeSJohannes Berg key->hw_key_idx = STA_KEY_IDX_INVALID; 3739e705c121SKalle Valo /* 3740e705c121SKalle Valo * can't add key for RX, but we don't need it 3741475c6bdeSJohannes Berg * in the device for TX so still return 0, 3742475c6bdeSJohannes Berg * unless we have new TX API where we cannot 3743475c6bdeSJohannes Berg * put key material into the TX_CMD 3744e705c121SKalle Valo */ 3745475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 3746475c6bdeSJohannes Berg ret = -EOPNOTSUPP; 3747475c6bdeSJohannes Berg else 3748e705c121SKalle Valo ret = 0; 3749e705c121SKalle Valo } 3750e705c121SKalle Valo 3751e705c121SKalle Valo break; 3752e705c121SKalle Valo case DISABLE_KEY: 3753b1fdc250SJohannes Berg if (keyidx == 6 || keyidx == 7) 3754b1fdc250SJohannes Berg RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 3755b1fdc250SJohannes Berg NULL); 3756b1fdc250SJohannes Berg 3757c56e00a3SJohannes Berg ret = -ENOENT; 3758c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 3759c56e00a3SJohannes Berg if (mvmvif->ap_early_keys[i] == key) { 3760c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 3761c56e00a3SJohannes Berg ret = 0; 3762c56e00a3SJohannes Berg } 3763c56e00a3SJohannes Berg } 3764c56e00a3SJohannes Berg 3765c56e00a3SJohannes Berg /* found in pending list - don't do anything else */ 3766c56e00a3SJohannes Berg if (ret == 0) 3767c56e00a3SJohannes Berg break; 3768c56e00a3SJohannes Berg 3769e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 3770e705c121SKalle Valo ret = 0; 3771e705c121SKalle Valo break; 3772e705c121SKalle Valo } 3773e705c121SKalle Valo 377446c7b05aSEmmanuel Grumbach if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 3775f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3776f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 37772a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 37782a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3779f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 3780f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 3781f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 3782f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 3783f5e28eacSJohannes Berg if (ptk_pn) 3784f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 3785f5e28eacSJohannes Berg } 3786f5e28eacSJohannes Berg 3787e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 3788e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 3789e705c121SKalle Valo break; 3790e705c121SKalle Valo default: 3791e705c121SKalle Valo ret = -EINVAL; 3792e705c121SKalle Valo } 3793e705c121SKalle Valo 37946569e7d3SJohannes Berg return ret; 37956569e7d3SJohannes Berg } 37966569e7d3SJohannes Berg 37976569e7d3SJohannes Berg static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 37986569e7d3SJohannes Berg enum set_key_cmd cmd, 37996569e7d3SJohannes Berg struct ieee80211_vif *vif, 38006569e7d3SJohannes Berg struct ieee80211_sta *sta, 38016569e7d3SJohannes Berg struct ieee80211_key_conf *key) 38026569e7d3SJohannes Berg { 38036569e7d3SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 38046569e7d3SJohannes Berg int ret; 38056569e7d3SJohannes Berg 38066569e7d3SJohannes Berg mutex_lock(&mvm->mutex); 38076569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 3808e705c121SKalle Valo mutex_unlock(&mvm->mutex); 38096569e7d3SJohannes Berg 3810e705c121SKalle Valo return ret; 3811e705c121SKalle Valo } 3812e705c121SKalle Valo 3813e705c121SKalle Valo static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 3814e705c121SKalle Valo struct ieee80211_vif *vif, 3815e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 3816e705c121SKalle Valo struct ieee80211_sta *sta, 3817e705c121SKalle Valo u32 iv32, u16 *phase1key) 3818e705c121SKalle Valo { 3819e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3820e705c121SKalle Valo 3821e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 3822e705c121SKalle Valo return; 3823e705c121SKalle Valo 3824e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 3825e705c121SKalle Valo } 3826e705c121SKalle Valo 3827e705c121SKalle Valo 3828e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 3829e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 3830e705c121SKalle Valo { 3831e705c121SKalle Valo struct iwl_mvm *mvm = 3832e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 3833e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 3834e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 3835e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 3836e705c121SKalle Valo 3837e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 3838e705c121SKalle Valo return true; 3839e705c121SKalle Valo 3840e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 3841e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 3842e705c121SKalle Valo return true; 3843e705c121SKalle Valo } 3844e705c121SKalle Valo 3845e705c121SKalle Valo resp = (void *)pkt->data; 3846e705c121SKalle Valo 3847e705c121SKalle Valo IWL_DEBUG_TE(mvm, 3848b71a9c35SColin Ian King "Aux ROC: Received response from ucode: status=%d uid=%d\n", 3849e705c121SKalle Valo resp->status, resp->event_unique_id); 3850e705c121SKalle Valo 3851e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 3852e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 3853e705c121SKalle Valo te_data->uid); 3854e705c121SKalle Valo 3855e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3856e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 3857e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3858e705c121SKalle Valo 3859e705c121SKalle Valo return true; 3860e705c121SKalle Valo } 3861e705c121SKalle Valo 3862dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) 3863dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) 3864dc28e12fSMatti Gottlieb #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) 3865dc28e12fSMatti Gottlieb #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) 3866dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) 3867e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 3868e705c121SKalle Valo struct ieee80211_channel *channel, 3869e705c121SKalle Valo struct ieee80211_vif *vif, 3870e705c121SKalle Valo int duration) 3871e705c121SKalle Valo { 3872afc1e3b4SAvraham Stern int res; 3873e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3874e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 3875e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 3876e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 3877dc28e12fSMatti Gottlieb u32 dtim_interval = vif->bss_conf.dtim_period * 3878dc28e12fSMatti Gottlieb vif->bss_conf.beacon_int; 3879dc28e12fSMatti Gottlieb u32 req_dur, delay; 3880e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 3881e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 3882e705c121SKalle Valo .id_and_color = 3883e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 3884e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 3885e705c121SKalle Valo }; 388657e861d9SDavid Spinadel struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 388757e861d9SDavid Spinadel &aux_roc_req.channel_info); 388857e861d9SDavid Spinadel u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 388957e861d9SDavid Spinadel 389057e861d9SDavid Spinadel /* Set the channel info data */ 389157e861d9SDavid Spinadel iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 38923717f91aSTova Mussai iwl_mvm_phy_band_from_nl80211(channel->band), 389357e861d9SDavid Spinadel PHY_VHT_CHANNEL_MODE20, 389457e861d9SDavid Spinadel 0); 389557e861d9SDavid Spinadel 389657e861d9SDavid Spinadel /* Set the time and duration */ 3897afc1e3b4SAvraham Stern tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 3898e705c121SKalle Valo 3899dc28e12fSMatti Gottlieb delay = AUX_ROC_MIN_DELAY; 3900dc28e12fSMatti Gottlieb req_dur = MSEC_TO_TU(duration); 3901dc28e12fSMatti Gottlieb 3902dc28e12fSMatti Gottlieb /* 3903dc28e12fSMatti Gottlieb * If we are associated we want the delay time to be at least one 3904dc28e12fSMatti Gottlieb * dtim interval so that the FW can wait until after the DTIM and 3905dc28e12fSMatti Gottlieb * then start the time event, this will potentially allow us to 3906dc28e12fSMatti Gottlieb * remain off-channel for the max duration. 3907dc28e12fSMatti Gottlieb * Since we want to use almost a whole dtim interval we would also 3908dc28e12fSMatti Gottlieb * like the delay to be for 2-3 dtim intervals, in case there are 3909dc28e12fSMatti Gottlieb * other time events with higher priority. 3910dc28e12fSMatti Gottlieb */ 3911dc28e12fSMatti Gottlieb if (vif->bss_conf.assoc) { 3912dc28e12fSMatti Gottlieb delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); 3913dc28e12fSMatti Gottlieb /* We cannot remain off-channel longer than the DTIM interval */ 3914dc28e12fSMatti Gottlieb if (dtim_interval <= req_dur) { 3915dc28e12fSMatti Gottlieb req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; 3916dc28e12fSMatti Gottlieb if (req_dur <= AUX_ROC_MIN_DURATION) 3917dc28e12fSMatti Gottlieb req_dur = dtim_interval - 3918dc28e12fSMatti Gottlieb AUX_ROC_MIN_SAFETY_BUFFER; 3919dc28e12fSMatti Gottlieb } 3920dc28e12fSMatti Gottlieb } 3921dc28e12fSMatti Gottlieb 392257e861d9SDavid Spinadel tail->duration = cpu_to_le32(req_dur); 392357e861d9SDavid Spinadel tail->apply_time_max_delay = cpu_to_le32(delay); 3924dc28e12fSMatti Gottlieb 3925dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 3926903b3f9bSEmmanuel Grumbach "ROC: Requesting to remain on channel %u for %ums\n", 3927903b3f9bSEmmanuel Grumbach channel->hw_value, req_dur); 3928903b3f9bSEmmanuel Grumbach IWL_DEBUG_TE(mvm, 3929903b3f9bSEmmanuel Grumbach "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", 3930903b3f9bSEmmanuel Grumbach duration, delay, dtim_interval); 3931903b3f9bSEmmanuel Grumbach 3932e705c121SKalle Valo /* Set the node address */ 393357e861d9SDavid Spinadel memcpy(tail->node_addr, vif->addr, ETH_ALEN); 3934e705c121SKalle Valo 3935e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3936e705c121SKalle Valo 3937e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3938e705c121SKalle Valo 3939e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 3940e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3941e705c121SKalle Valo return -EIO; 3942e705c121SKalle Valo } 3943e705c121SKalle Valo 3944e705c121SKalle Valo te_data->vif = vif; 3945e705c121SKalle Valo te_data->duration = duration; 3946e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 3947e705c121SKalle Valo 3948e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3949e705c121SKalle Valo 3950e705c121SKalle Valo /* 3951e705c121SKalle Valo * Use a notification wait, which really just processes the 3952e705c121SKalle Valo * command response and doesn't wait for anything, in order 3953e705c121SKalle Valo * to be able to process the response and get the UID inside 3954e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 3955e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 3956e705c121SKalle Valo * time another notification (that the time event started) 3957e705c121SKalle Valo * might already be processed unsuccessfully. 3958e705c121SKalle Valo */ 3959e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 3960e705c121SKalle Valo time_event_response, 3961e705c121SKalle Valo ARRAY_SIZE(time_event_response), 3962e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 3963e705c121SKalle Valo 396457e861d9SDavid Spinadel res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 3965e705c121SKalle Valo &aux_roc_req); 3966e705c121SKalle Valo 3967e705c121SKalle Valo if (res) { 3968e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 3969e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 3970e705c121SKalle Valo goto out_clear_te; 3971e705c121SKalle Valo } 3972e705c121SKalle Valo 3973e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 3974e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 3975e705c121SKalle Valo /* should never fail */ 3976e705c121SKalle Valo WARN_ON_ONCE(res); 3977e705c121SKalle Valo 3978e705c121SKalle Valo if (res) { 3979e705c121SKalle Valo out_clear_te: 3980e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3981e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 3982e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3983e705c121SKalle Valo } 3984e705c121SKalle Valo 3985e705c121SKalle Valo return res; 3986e705c121SKalle Valo } 3987e705c121SKalle Valo 3988e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 3989e705c121SKalle Valo struct ieee80211_vif *vif, 3990e705c121SKalle Valo struct ieee80211_channel *channel, 3991e705c121SKalle Valo int duration, 3992e705c121SKalle Valo enum ieee80211_roc_type type) 3993e705c121SKalle Valo { 3994e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3995e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3996e705c121SKalle Valo struct cfg80211_chan_def chandef; 3997e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 39988835a64fSJohannes Berg bool band_change_removal; 3999e705c121SKalle Valo int ret, i; 4000e705c121SKalle Valo 4001e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 4002e705c121SKalle Valo duration, type); 4003e705c121SKalle Valo 40049834781cSJohannes Berg /* 40059834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 40069834781cSJohannes Berg * the work it does can complete and we can accept new frames. 40079834781cSJohannes Berg */ 4008e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 4009e705c121SKalle Valo 4010e705c121SKalle Valo mutex_lock(&mvm->mutex); 4011e705c121SKalle Valo 4012e705c121SKalle Valo switch (vif->type) { 4013e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4014e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 4015e705c121SKalle Valo IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 4016e705c121SKalle Valo /* Use aux roc framework (HS20) */ 40172c2c3647SNathan Errera if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, 40182c2c3647SNathan Errera ADD_STA, 0) >= 12) { 40192c2c3647SNathan Errera u32 lmac_id; 40202c2c3647SNathan Errera 40212c2c3647SNathan Errera lmac_id = iwl_mvm_get_lmac_id(mvm->fw, 40222c2c3647SNathan Errera channel->band); 40232c2c3647SNathan Errera ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 40242c2c3647SNathan Errera if (WARN(ret, 40252c2c3647SNathan Errera "Failed to allocate aux station")) 40262c2c3647SNathan Errera goto out_unlock; 40272c2c3647SNathan Errera } 4028e705c121SKalle Valo ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 4029e705c121SKalle Valo vif, duration); 4030e705c121SKalle Valo goto out_unlock; 4031e705c121SKalle Valo } 4032e705c121SKalle Valo IWL_ERR(mvm, "hotspot not supported\n"); 4033e705c121SKalle Valo ret = -EINVAL; 4034e705c121SKalle Valo goto out_unlock; 4035e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 4036e705c121SKalle Valo /* handle below */ 4037e705c121SKalle Valo break; 4038e705c121SKalle Valo default: 4039e705c121SKalle Valo IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); 4040e705c121SKalle Valo ret = -EINVAL; 4041e705c121SKalle Valo goto out_unlock; 4042e705c121SKalle Valo } 4043e705c121SKalle Valo 4044e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 4045e705c121SKalle Valo phy_ctxt = &mvm->phy_ctxts[i]; 4046e705c121SKalle Valo if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) 4047e705c121SKalle Valo continue; 4048e705c121SKalle Valo 4049e705c121SKalle Valo if (phy_ctxt->ref && channel == phy_ctxt->channel) { 4050e705c121SKalle Valo /* 4051e705c121SKalle Valo * Unbind the P2P_DEVICE from the current PHY context, 4052e705c121SKalle Valo * and if the PHY context is not used remove it. 4053e705c121SKalle Valo */ 4054e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 4055e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 4056e705c121SKalle Valo goto out_unlock; 4057e705c121SKalle Valo 4058e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 4059e705c121SKalle Valo 4060e705c121SKalle Valo /* Bind the P2P_DEVICE to the current PHY Context */ 4061e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 4062e705c121SKalle Valo 4063e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4064e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 4065e705c121SKalle Valo goto out_unlock; 4066e705c121SKalle Valo 4067e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 4068e705c121SKalle Valo goto schedule_time_event; 4069e705c121SKalle Valo } 4070e705c121SKalle Valo } 4071e705c121SKalle Valo 4072e705c121SKalle Valo /* Need to update the PHY context only if the ROC channel changed */ 4073e705c121SKalle Valo if (channel == mvmvif->phy_ctxt->channel) 4074e705c121SKalle Valo goto schedule_time_event; 4075e705c121SKalle Valo 4076e705c121SKalle Valo cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 4077e705c121SKalle Valo 4078e705c121SKalle Valo /* 40798835a64fSJohannes Berg * Check if the remain-on-channel is on a different band and that 40808835a64fSJohannes Berg * requires context removal, see iwl_mvm_phy_ctxt_changed(). If 40818835a64fSJohannes Berg * so, we'll need to release and then re-configure here, since we 40828835a64fSJohannes Berg * must not remove a PHY context that's part of a binding. 4083e705c121SKalle Valo */ 40848835a64fSJohannes Berg band_change_removal = 40858835a64fSJohannes Berg fw_has_capa(&mvm->fw->ucode_capa, 40868835a64fSJohannes Berg IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) && 40878835a64fSJohannes Berg mvmvif->phy_ctxt->channel->band != chandef.chan->band; 40888835a64fSJohannes Berg 40898835a64fSJohannes Berg if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) { 40908835a64fSJohannes Berg /* 40918835a64fSJohannes Berg * Change the PHY context configuration as it is currently 40928835a64fSJohannes Berg * referenced only by the P2P Device MAC (and we can modify it) 40938835a64fSJohannes Berg */ 4094e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, 4095e705c121SKalle Valo &chandef, 1, 1); 4096e705c121SKalle Valo if (ret) 4097e705c121SKalle Valo goto out_unlock; 4098e705c121SKalle Valo } else { 4099e705c121SKalle Valo /* 41008835a64fSJohannes Berg * The PHY context is shared with other MACs (or we're trying to 41018835a64fSJohannes Berg * switch bands), so remove the P2P Device from the binding, 41028835a64fSJohannes Berg * allocate an new PHY context and create a new binding. 4103e705c121SKalle Valo */ 4104e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4105e705c121SKalle Valo if (!phy_ctxt) { 4106e705c121SKalle Valo ret = -ENOSPC; 4107e705c121SKalle Valo goto out_unlock; 4108e705c121SKalle Valo } 4109e705c121SKalle Valo 4110e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, 4111e705c121SKalle Valo 1, 1); 4112e705c121SKalle Valo if (ret) { 4113e705c121SKalle Valo IWL_ERR(mvm, "Failed to change PHY context\n"); 4114e705c121SKalle Valo goto out_unlock; 4115e705c121SKalle Valo } 4116e705c121SKalle Valo 4117e705c121SKalle Valo /* Unbind the P2P_DEVICE from the current PHY context */ 4118e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 4119e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 4120e705c121SKalle Valo goto out_unlock; 4121e705c121SKalle Valo 4122e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 4123e705c121SKalle Valo 4124e705c121SKalle Valo /* Bind the P2P_DEVICE to the new allocated PHY context */ 4125e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 4126e705c121SKalle Valo 4127e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4128e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 4129e705c121SKalle Valo goto out_unlock; 4130e705c121SKalle Valo 4131e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 4132e705c121SKalle Valo } 4133e705c121SKalle Valo 4134e705c121SKalle Valo schedule_time_event: 4135e705c121SKalle Valo /* Schedule the time events */ 4136e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4137e705c121SKalle Valo 4138e705c121SKalle Valo out_unlock: 4139e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4140e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4141e705c121SKalle Valo return ret; 4142e705c121SKalle Valo } 4143e705c121SKalle Valo 41445db4c4b9SEmmanuel Grumbach static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 41455db4c4b9SEmmanuel Grumbach struct ieee80211_vif *vif) 4146e705c121SKalle Valo { 4147e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4148e705c121SKalle Valo 4149e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 4150e705c121SKalle Valo 4151e705c121SKalle Valo mutex_lock(&mvm->mutex); 4152fe959c7bSEmmanuel Grumbach iwl_mvm_stop_roc(mvm, vif); 4153e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4154e705c121SKalle Valo 4155e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4156e705c121SKalle Valo return 0; 4157e705c121SKalle Valo } 4158e705c121SKalle Valo 4159b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data { 4160b73f9a4aSJohannes Berg bool responder; 4161b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx; 4162b73f9a4aSJohannes Berg }; 4163b73f9a4aSJohannes Berg 4164b73f9a4aSJohannes Berg static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4165b73f9a4aSJohannes Berg struct ieee80211_vif *vif) 4166b73f9a4aSJohannes Berg { 4167b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data *data = _data; 4168b73f9a4aSJohannes Berg 4169b73f9a4aSJohannes Berg if (rcu_access_pointer(vif->chanctx_conf) == data->ctx && 4170b73f9a4aSJohannes Berg vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4171b73f9a4aSJohannes Berg data->responder = true; 4172b73f9a4aSJohannes Berg } 4173b73f9a4aSJohannes Berg 4174b73f9a4aSJohannes Berg static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4175b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx) 4176b73f9a4aSJohannes Berg { 4177b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data data = { 4178b73f9a4aSJohannes Berg .responder = false, 4179b73f9a4aSJohannes Berg .ctx = ctx, 4180b73f9a4aSJohannes Berg }; 4181b73f9a4aSJohannes Berg 4182b73f9a4aSJohannes Berg ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4183b73f9a4aSJohannes Berg IEEE80211_IFACE_ITER_NORMAL, 4184b73f9a4aSJohannes Berg iwl_mvm_ftm_responder_chanctx_iter, 4185b73f9a4aSJohannes Berg &data); 4186b73f9a4aSJohannes Berg return data.responder; 4187b73f9a4aSJohannes Berg } 4188b73f9a4aSJohannes Berg 4189e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4190e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4191e705c121SKalle Valo { 4192e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4193e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 4194b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4195b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4196e705c121SKalle Valo int ret; 4197e705c121SKalle Valo 4198e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4199e705c121SKalle Valo 4200e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4201e705c121SKalle Valo 4202e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4203e705c121SKalle Valo if (!phy_ctxt) { 4204e705c121SKalle Valo ret = -ENOSPC; 4205e705c121SKalle Valo goto out; 4206e705c121SKalle Valo } 4207e705c121SKalle Valo 4208b73f9a4aSJohannes Berg ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4209e705c121SKalle Valo ctx->rx_chains_static, 4210e705c121SKalle Valo ctx->rx_chains_dynamic); 4211e705c121SKalle Valo if (ret) { 4212e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 4213e705c121SKalle Valo goto out; 4214e705c121SKalle Valo } 4215e705c121SKalle Valo 4216e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); 4217e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 4218e705c121SKalle Valo out: 4219e705c121SKalle Valo return ret; 4220e705c121SKalle Valo } 4221e705c121SKalle Valo 4222e705c121SKalle Valo static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4223e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4224e705c121SKalle Valo { 4225e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4226e705c121SKalle Valo int ret; 4227e705c121SKalle Valo 4228e705c121SKalle Valo mutex_lock(&mvm->mutex); 4229e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 4230e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4231e705c121SKalle Valo 4232e705c121SKalle Valo return ret; 4233e705c121SKalle Valo } 4234e705c121SKalle Valo 4235e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4236e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4237e705c121SKalle Valo { 4238e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4239e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4240e705c121SKalle Valo 4241e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4242e705c121SKalle Valo 4243e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4244e705c121SKalle Valo } 4245e705c121SKalle Valo 4246e705c121SKalle Valo static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4247e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4248e705c121SKalle Valo { 4249e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4250e705c121SKalle Valo 4251e705c121SKalle Valo mutex_lock(&mvm->mutex); 4252e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 4253e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4254e705c121SKalle Valo } 4255e705c121SKalle Valo 4256e705c121SKalle Valo static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4257e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4258e705c121SKalle Valo u32 changed) 4259e705c121SKalle Valo { 4260e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4261e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4262e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4263b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4264b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4265e705c121SKalle Valo 4266e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 4267e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4268e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4269e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 4270e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4271e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 4272e705c121SKalle Valo phy_ctxt->ref, changed)) 4273e705c121SKalle Valo return; 4274e705c121SKalle Valo 4275e705c121SKalle Valo mutex_lock(&mvm->mutex); 42767a20bcceSEmmanuel Grumbach 42777a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 42787a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 4279b73f9a4aSJohannes Berg if (phy_ctxt->width == def->width) 42807a20bcceSEmmanuel Grumbach goto out_unlock; 42817a20bcceSEmmanuel Grumbach 42827a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 42837a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 4284b73f9a4aSJohannes Berg def->width <= NL80211_CHAN_WIDTH_20) 42857a20bcceSEmmanuel Grumbach goto out_unlock; 42867a20bcceSEmmanuel Grumbach } 42877a20bcceSEmmanuel Grumbach 4288e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 4289b73f9a4aSJohannes Berg iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4290e705c121SKalle Valo ctx->rx_chains_static, 4291e705c121SKalle Valo ctx->rx_chains_dynamic); 42927a20bcceSEmmanuel Grumbach 42937a20bcceSEmmanuel Grumbach out_unlock: 4294e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4295e705c121SKalle Valo } 4296e705c121SKalle Valo 4297e705c121SKalle Valo static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 4298e705c121SKalle Valo struct ieee80211_vif *vif, 4299e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4300e705c121SKalle Valo bool switching_chanctx) 4301e705c121SKalle Valo { 4302e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4303e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4304e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4305e705c121SKalle Valo int ret; 4306e705c121SKalle Valo 4307e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4308e705c121SKalle Valo 4309e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 4310e705c121SKalle Valo 4311e705c121SKalle Valo switch (vif->type) { 4312e705c121SKalle Valo case NL80211_IFTYPE_AP: 4313e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 4314e705c121SKalle Valo if (switching_chanctx) { 4315e705c121SKalle Valo mvmvif->ap_ibss_active = true; 4316e705c121SKalle Valo break; 4317e705c121SKalle Valo } 43185a2abdcaSGustavo A. R. Silva fallthrough; 4319e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4320e705c121SKalle Valo /* 4321e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 4322e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 4323e705c121SKalle Valo */ 4324e705c121SKalle Valo ret = 0; 4325e705c121SKalle Valo goto out; 4326e705c121SKalle Valo case NL80211_IFTYPE_STATION: 432719125cb0SAndrei Otcheretianski mvmvif->csa_bcn_pending = false; 4328e705c121SKalle Valo break; 4329e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4330e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 4331e705c121SKalle Valo mvmvif->ps_disabled = true; 4332e705c121SKalle Valo break; 4333e705c121SKalle Valo default: 4334e705c121SKalle Valo ret = -EINVAL; 4335e705c121SKalle Valo goto out; 4336e705c121SKalle Valo } 4337e705c121SKalle Valo 4338e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4339e705c121SKalle Valo if (ret) 4340e705c121SKalle Valo goto out; 4341e705c121SKalle Valo 4342e705c121SKalle Valo /* 4343e705c121SKalle Valo * Power state must be updated before quotas, 4344e705c121SKalle Valo * otherwise fw will complain. 4345e705c121SKalle Valo */ 4346e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4347e705c121SKalle Valo 4348e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 4349e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 4350e705c121SKalle Valo * will handle quota settings. 4351e705c121SKalle Valo */ 4352e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 4353e705c121SKalle Valo mvmvif->monitor_active = true; 4354e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 4355e705c121SKalle Valo if (ret) 4356e705c121SKalle Valo goto out_remove_binding; 43570e39eb03SChaya Rachel Ivgi 43580e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 43590e39eb03SChaya Rachel Ivgi if (ret) 43600e39eb03SChaya Rachel Ivgi goto out_remove_binding; 43610e39eb03SChaya Rachel Ivgi 4362e705c121SKalle Valo } 4363e705c121SKalle Valo 4364e705c121SKalle Valo /* Handle binding during CSA */ 4365e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 4366e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4367e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4368e705c121SKalle Valo } 4369e705c121SKalle Valo 4370e705c121SKalle Valo if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { 437174a10252SSara Sharon mvmvif->csa_bcn_pending = true; 437274a10252SSara Sharon 437374a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 437474a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 437519125cb0SAndrei Otcheretianski u32 duration = 3 * vif->bss_conf.beacon_int; 4376e705c121SKalle Valo 4377e705c121SKalle Valo /* Protect the session to make sure we hear the first 4378e705c121SKalle Valo * beacon on the new channel. 4379e705c121SKalle Valo */ 4380e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 4381e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 4382e705c121SKalle Valo true); 438374a10252SSara Sharon } 4384e705c121SKalle Valo 4385e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4386e705c121SKalle Valo } 4387e705c121SKalle Valo 4388e705c121SKalle Valo goto out; 4389e705c121SKalle Valo 4390e705c121SKalle Valo out_remove_binding: 4391e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4392e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4393e705c121SKalle Valo out: 4394e705c121SKalle Valo if (ret) 4395e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 4396e705c121SKalle Valo return ret; 4397e705c121SKalle Valo } 4398e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 4399e705c121SKalle Valo struct ieee80211_vif *vif, 4400e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4401e705c121SKalle Valo { 4402e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4403e705c121SKalle Valo int ret; 4404e705c121SKalle Valo 4405e705c121SKalle Valo mutex_lock(&mvm->mutex); 4406e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); 4407e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4408e705c121SKalle Valo 4409e705c121SKalle Valo return ret; 4410e705c121SKalle Valo } 4411e705c121SKalle Valo 4412e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 4413e705c121SKalle Valo struct ieee80211_vif *vif, 4414e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4415e705c121SKalle Valo bool switching_chanctx) 4416e705c121SKalle Valo { 4417e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4418e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 4419e705c121SKalle Valo 4420e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4421e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); 4422e705c121SKalle Valo 4423e705c121SKalle Valo switch (vif->type) { 4424e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4425e705c121SKalle Valo goto out; 4426e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4427e705c121SKalle Valo mvmvif->monitor_active = false; 4428e705c121SKalle Valo mvmvif->ps_disabled = false; 44290e39eb03SChaya Rachel Ivgi iwl_mvm_rm_snif_sta(mvm, vif); 4430e705c121SKalle Valo break; 4431e705c121SKalle Valo case NL80211_IFTYPE_AP: 4432e705c121SKalle Valo /* This part is triggered only during CSA */ 4433e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 4434e705c121SKalle Valo goto out; 4435e705c121SKalle Valo 4436e705c121SKalle Valo mvmvif->csa_countdown = false; 4437e705c121SKalle Valo 4438e705c121SKalle Valo /* Set CS bit on all the stations */ 4439e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 4440e705c121SKalle Valo 4441e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 4442e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 4443e705c121SKalle Valo 4444e705c121SKalle Valo mvmvif->ap_ibss_active = false; 4445e705c121SKalle Valo break; 4446e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4447e705c121SKalle Valo if (!switching_chanctx) 4448e705c121SKalle Valo break; 4449e705c121SKalle Valo 4450e705c121SKalle Valo disabled_vif = vif; 4451e705c121SKalle Valo 445274a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 445374a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 4454e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 4455e705c121SKalle Valo break; 4456e705c121SKalle Valo default: 4457e705c121SKalle Valo break; 4458e705c121SKalle Valo } 4459e705c121SKalle Valo 4460e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 4461e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4462e705c121SKalle Valo 4463e705c121SKalle Valo out: 4464bf544e9aSSara Sharon if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 4465bf544e9aSSara Sharon switching_chanctx) 4466bf544e9aSSara Sharon return; 4467e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 4468e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4469e705c121SKalle Valo } 4470e705c121SKalle Valo 4471e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 4472e705c121SKalle Valo struct ieee80211_vif *vif, 4473e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4474e705c121SKalle Valo { 4475e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4476e705c121SKalle Valo 4477e705c121SKalle Valo mutex_lock(&mvm->mutex); 4478e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); 4479e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4480e705c121SKalle Valo } 4481e705c121SKalle Valo 4482e705c121SKalle Valo static int 4483e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 4484e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 4485e705c121SKalle Valo { 4486e705c121SKalle Valo int ret; 4487e705c121SKalle Valo 4488e705c121SKalle Valo mutex_lock(&mvm->mutex); 4489e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4490e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 4491e705c121SKalle Valo 4492e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 4493e705c121SKalle Valo if (ret) { 4494e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 4495e705c121SKalle Valo goto out_reassign; 4496e705c121SKalle Valo } 4497e705c121SKalle Valo 4498e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4499e705c121SKalle Valo true); 4500e705c121SKalle Valo if (ret) { 4501e705c121SKalle Valo IWL_ERR(mvm, 4502e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4503e705c121SKalle Valo goto out_remove; 4504e705c121SKalle Valo } 4505e705c121SKalle Valo 4506e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 4507e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 4508e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4509e705c121SKalle Valo 4510e705c121SKalle Valo goto out; 4511e705c121SKalle Valo 4512e705c121SKalle Valo out_remove: 4513e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 4514e705c121SKalle Valo 4515e705c121SKalle Valo out_reassign: 4516e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 4517e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 4518e705c121SKalle Valo goto out_restart; 4519e705c121SKalle Valo } 4520e705c121SKalle Valo 4521e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4522e705c121SKalle Valo true)) { 4523e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4524e705c121SKalle Valo goto out_restart; 4525e705c121SKalle Valo } 4526e705c121SKalle Valo 4527e705c121SKalle Valo goto out; 4528e705c121SKalle Valo 4529e705c121SKalle Valo out_restart: 4530e705c121SKalle Valo /* things keep failing, better restart the hw */ 4531e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4532e705c121SKalle Valo 4533e705c121SKalle Valo out: 4534e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4535e705c121SKalle Valo 4536e705c121SKalle Valo return ret; 4537e705c121SKalle Valo } 4538e705c121SKalle Valo 4539e705c121SKalle Valo static int 4540e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 4541e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 4542e705c121SKalle Valo { 4543e705c121SKalle Valo int ret; 4544e705c121SKalle Valo 4545e705c121SKalle Valo mutex_lock(&mvm->mutex); 4546e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4547e705c121SKalle Valo 4548e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4549e705c121SKalle Valo true); 4550e705c121SKalle Valo if (ret) { 4551e705c121SKalle Valo IWL_ERR(mvm, 4552e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4553e705c121SKalle Valo goto out_reassign; 4554e705c121SKalle Valo } 4555e705c121SKalle Valo 4556e705c121SKalle Valo goto out; 4557e705c121SKalle Valo 4558e705c121SKalle Valo out_reassign: 4559e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4560e705c121SKalle Valo true)) { 4561e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4562e705c121SKalle Valo goto out_restart; 4563e705c121SKalle Valo } 4564e705c121SKalle Valo 4565e705c121SKalle Valo goto out; 4566e705c121SKalle Valo 4567e705c121SKalle Valo out_restart: 4568e705c121SKalle Valo /* things keep failing, better restart the hw */ 4569e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4570e705c121SKalle Valo 4571e705c121SKalle Valo out: 4572e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4573e705c121SKalle Valo 4574e705c121SKalle Valo return ret; 4575e705c121SKalle Valo } 4576e705c121SKalle Valo 4577e705c121SKalle Valo static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 4578e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 4579e705c121SKalle Valo int n_vifs, 4580e705c121SKalle Valo enum ieee80211_chanctx_switch_mode mode) 4581e705c121SKalle Valo { 4582e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4583e705c121SKalle Valo int ret; 4584e705c121SKalle Valo 4585e705c121SKalle Valo /* we only support a single-vif right now */ 4586e705c121SKalle Valo if (n_vifs > 1) 4587e705c121SKalle Valo return -EOPNOTSUPP; 4588e705c121SKalle Valo 4589e705c121SKalle Valo switch (mode) { 4590e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 4591e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); 4592e705c121SKalle Valo break; 4593e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 4594e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); 4595e705c121SKalle Valo break; 4596e705c121SKalle Valo default: 4597e705c121SKalle Valo ret = -EOPNOTSUPP; 4598e705c121SKalle Valo break; 4599e705c121SKalle Valo } 4600e705c121SKalle Valo 4601e705c121SKalle Valo return ret; 4602e705c121SKalle Valo } 4603e705c121SKalle Valo 46042f0282dbSJohannes Berg static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 46052f0282dbSJohannes Berg { 46062f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 46072f0282dbSJohannes Berg 46082f0282dbSJohannes Berg return mvm->ibss_manager; 46092f0282dbSJohannes Berg } 46102f0282dbSJohannes Berg 4611e705c121SKalle Valo static int iwl_mvm_set_tim(struct ieee80211_hw *hw, 4612e705c121SKalle Valo struct ieee80211_sta *sta, 4613e705c121SKalle Valo bool set) 4614e705c121SKalle Valo { 4615e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4616e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 4617e705c121SKalle Valo 4618e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 4619e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 4620e705c121SKalle Valo return -EINVAL; 4621e705c121SKalle Valo } 4622e705c121SKalle Valo 4623e705c121SKalle Valo return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); 4624e705c121SKalle Valo } 4625e705c121SKalle Valo 4626e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 4627e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 4628e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 4629e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 4630e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 4631e705c121SKalle Valo }; 4632e705c121SKalle Valo 4633e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 4634e705c121SKalle Valo struct ieee80211_vif *vif, 4635e705c121SKalle Valo void *data, int len) 4636e705c121SKalle Valo { 4637e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 4638e705c121SKalle Valo int err; 4639e705c121SKalle Valo u32 noa_duration; 4640e705c121SKalle Valo 46418cb08174SJohannes Berg err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 46428cb08174SJohannes Berg iwl_mvm_tm_policy, NULL); 4643e705c121SKalle Valo if (err) 4644e705c121SKalle Valo return err; 4645e705c121SKalle Valo 4646e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 4647e705c121SKalle Valo return -EINVAL; 4648e705c121SKalle Valo 4649e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 4650e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 4651e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 4652e705c121SKalle Valo !vif->bss_conf.enable_beacon || 4653e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 4654e705c121SKalle Valo return -EINVAL; 4655e705c121SKalle Valo 4656e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 4657e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 4658e705c121SKalle Valo return -EINVAL; 4659e705c121SKalle Valo 4660e705c121SKalle Valo mvm->noa_duration = noa_duration; 4661e705c121SKalle Valo mvm->noa_vif = vif; 4662e705c121SKalle Valo 466322b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 4664e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 4665e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 4666e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 4667e705c121SKalle Valo !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || 4668e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 4669e705c121SKalle Valo return -EINVAL; 4670e705c121SKalle Valo 4671e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 4672e705c121SKalle Valo return iwl_mvm_enable_beacon_filter(mvm, vif, 0); 4673e705c121SKalle Valo return iwl_mvm_disable_beacon_filter(mvm, vif, 0); 4674e705c121SKalle Valo } 4675e705c121SKalle Valo 4676e705c121SKalle Valo return -EOPNOTSUPP; 4677e705c121SKalle Valo } 4678e705c121SKalle Valo 4679e705c121SKalle Valo static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 4680e705c121SKalle Valo struct ieee80211_vif *vif, 4681e705c121SKalle Valo void *data, int len) 4682e705c121SKalle Valo { 4683e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4684e705c121SKalle Valo int err; 4685e705c121SKalle Valo 4686e705c121SKalle Valo mutex_lock(&mvm->mutex); 4687e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 4688e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4689e705c121SKalle Valo 4690e705c121SKalle Valo return err; 4691e705c121SKalle Valo } 4692e705c121SKalle Valo #endif 4693e705c121SKalle Valo 4694e705c121SKalle Valo static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, 4695e705c121SKalle Valo struct ieee80211_vif *vif, 4696e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4697e705c121SKalle Valo { 4698e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 4699e705c121SKalle Valo * starting its own channel switch timer, so that we can call 4700e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 4701e705c121SKalle Valo * (which is when the absence time event starts). 4702e705c121SKalle Valo */ 4703e705c121SKalle Valo 4704e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 4705e705c121SKalle Valo "dummy channel switch op\n"); 4706e705c121SKalle Valo } 4707e705c121SKalle Valo 470874a10252SSara Sharon static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 470974a10252SSara Sharon struct ieee80211_vif *vif, 471074a10252SSara Sharon struct ieee80211_channel_switch *chsw) 471174a10252SSara Sharon { 471274a10252SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 471374a10252SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 471474a10252SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 471574a10252SSara Sharon mvmvif->color)), 471674a10252SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 471774a10252SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 471874a10252SSara Sharon .cs_count = chsw->count, 471977738865SSara Sharon .cs_mode = chsw->block_tx, 472074a10252SSara Sharon }; 472174a10252SSara Sharon 472274a10252SSara Sharon lockdep_assert_held(&mvm->mutex); 472374a10252SSara Sharon 47249cfcf71cSSara Sharon if (chsw->delay) 47259cfcf71cSSara Sharon cmd.cs_delayed_bcn_count = 47269cfcf71cSSara Sharon DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 47279cfcf71cSSara Sharon 472874a10252SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 472974a10252SSara Sharon WIDE_ID(MAC_CONF_GROUP, 473074a10252SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 473174a10252SSara Sharon 0, sizeof(cmd), &cmd); 473274a10252SSara Sharon } 473374a10252SSara Sharon 47340202bcf0SEmmanuel Grumbach static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 47350202bcf0SEmmanuel Grumbach struct ieee80211_vif *vif, 47360202bcf0SEmmanuel Grumbach struct ieee80211_channel_switch *chsw) 47370202bcf0SEmmanuel Grumbach { 47380202bcf0SEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 47390202bcf0SEmmanuel Grumbach u32 apply_time; 47400202bcf0SEmmanuel Grumbach 47410202bcf0SEmmanuel Grumbach /* Schedule the time event to a bit before beacon 1, 47420202bcf0SEmmanuel Grumbach * to make sure we're in the new channel when the 47430202bcf0SEmmanuel Grumbach * GO/AP arrives. In case count <= 1 immediately schedule the 47440202bcf0SEmmanuel Grumbach * TE (this might result with some packet loss or connection 47450202bcf0SEmmanuel Grumbach * loss). 47460202bcf0SEmmanuel Grumbach */ 47470202bcf0SEmmanuel Grumbach if (chsw->count <= 1) 47480202bcf0SEmmanuel Grumbach apply_time = 0; 47490202bcf0SEmmanuel Grumbach else 47500202bcf0SEmmanuel Grumbach apply_time = chsw->device_timestamp + 47510202bcf0SEmmanuel Grumbach ((vif->bss_conf.beacon_int * (chsw->count - 1) - 47520202bcf0SEmmanuel Grumbach IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 47530202bcf0SEmmanuel Grumbach 47540202bcf0SEmmanuel Grumbach if (chsw->block_tx) 47550202bcf0SEmmanuel Grumbach iwl_mvm_csa_client_absent(mvm, vif); 47560202bcf0SEmmanuel Grumbach 47570202bcf0SEmmanuel Grumbach if (mvmvif->bf_data.bf_enabled) { 47580202bcf0SEmmanuel Grumbach int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 47590202bcf0SEmmanuel Grumbach 47600202bcf0SEmmanuel Grumbach if (ret) 47610202bcf0SEmmanuel Grumbach return ret; 47620202bcf0SEmmanuel Grumbach } 47630202bcf0SEmmanuel Grumbach 47640202bcf0SEmmanuel Grumbach iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 47650202bcf0SEmmanuel Grumbach apply_time); 47660202bcf0SEmmanuel Grumbach 47670202bcf0SEmmanuel Grumbach return 0; 47680202bcf0SEmmanuel Grumbach } 47690202bcf0SEmmanuel Grumbach 4770f6780614SSara Sharon #define IWL_MAX_CSA_BLOCK_TX 1500 4771e705c121SKalle Valo static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 4772e705c121SKalle Valo struct ieee80211_vif *vif, 4773e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4774e705c121SKalle Valo { 4775e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4776e705c121SKalle Valo struct ieee80211_vif *csa_vif; 4777e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4778e705c121SKalle Valo int ret; 4779e705c121SKalle Valo 4780e705c121SKalle Valo mutex_lock(&mvm->mutex); 4781e705c121SKalle Valo 4782e705c121SKalle Valo mvmvif->csa_failed = false; 4783e705c121SKalle Valo 4784e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 4785e705c121SKalle Valo chsw->chandef.center_freq1); 4786e705c121SKalle Valo 47877174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 47887174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 47897174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 4790e705c121SKalle Valo 4791e705c121SKalle Valo switch (vif->type) { 4792e705c121SKalle Valo case NL80211_IFTYPE_AP: 4793e705c121SKalle Valo csa_vif = 4794e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 4795e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4796e705c121SKalle Valo if (WARN_ONCE(csa_vif && csa_vif->csa_active, 4797e705c121SKalle Valo "Another CSA is already in progress")) { 4798e705c121SKalle Valo ret = -EBUSY; 4799e705c121SKalle Valo goto out_unlock; 4800e705c121SKalle Valo } 4801e705c121SKalle Valo 4802d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 4803d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 4804d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 4805d3a108a4SAndrei Otcheretianski ret = -EBUSY; 4806d3a108a4SAndrei Otcheretianski goto out_unlock; 4807d3a108a4SAndrei Otcheretianski } 4808d3a108a4SAndrei Otcheretianski 4809e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 4810e705c121SKalle Valo 4811e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 4812e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 4813e705c121SKalle Valo ret = -EBUSY; 4814e705c121SKalle Valo goto out_unlock; 4815e705c121SKalle Valo } 4816e705c121SKalle Valo 4817d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 4818d3a108a4SAndrei Otcheretianski 4819e705c121SKalle Valo break; 4820e705c121SKalle Valo case NL80211_IFTYPE_STATION: 48212360acbdSEmmanuel Grumbach /* 48222360acbdSEmmanuel Grumbach * We haven't configured the firmware to be associated yet since 48232360acbdSEmmanuel Grumbach * we don't know the dtim period. In this case, the firmware can't 48242360acbdSEmmanuel Grumbach * track the beacons. 48252360acbdSEmmanuel Grumbach */ 48262360acbdSEmmanuel Grumbach if (!vif->bss_conf.assoc || !vif->bss_conf.dtim_period) { 48272360acbdSEmmanuel Grumbach ret = -EBUSY; 48282360acbdSEmmanuel Grumbach goto out_unlock; 48292360acbdSEmmanuel Grumbach } 48302360acbdSEmmanuel Grumbach 483187d9564eSJohannes Berg if (chsw->delay > IWL_MAX_CSA_BLOCK_TX) 483287d9564eSJohannes Berg schedule_delayed_work(&mvmvif->csa_work, 0); 483387d9564eSJohannes Berg 4834f6780614SSara Sharon if (chsw->block_tx) { 4835f6780614SSara Sharon /* 4836f6780614SSara Sharon * In case of undetermined / long time with immediate 4837f6780614SSara Sharon * quiet monitor status to gracefully disconnect 4838f6780614SSara Sharon */ 4839f6780614SSara Sharon if (!chsw->count || 4840f6780614SSara Sharon chsw->count * vif->bss_conf.beacon_int > 4841f6780614SSara Sharon IWL_MAX_CSA_BLOCK_TX) 4842f6780614SSara Sharon schedule_delayed_work(&mvmvif->csa_work, 4843f6780614SSara Sharon msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 4844f6780614SSara Sharon } 4845e705c121SKalle Valo 48460202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 48470202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 48480202bcf0SEmmanuel Grumbach ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 4849e705c121SKalle Valo if (ret) 4850e705c121SKalle Valo goto out_unlock; 48510202bcf0SEmmanuel Grumbach } else { 485274a10252SSara Sharon iwl_mvm_schedule_client_csa(mvm, vif, chsw); 48530202bcf0SEmmanuel Grumbach } 485481b4e44eSSara Sharon 485581b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 485681b4e44eSSara Sharon mvmvif->csa_misbehave = false; 4857e705c121SKalle Valo break; 4858e705c121SKalle Valo default: 4859e705c121SKalle Valo break; 4860e705c121SKalle Valo } 4861e705c121SKalle Valo 4862e705c121SKalle Valo mvmvif->ps_disabled = true; 4863e705c121SKalle Valo 4864e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 4865e705c121SKalle Valo if (ret) 4866e705c121SKalle Valo goto out_unlock; 4867e705c121SKalle Valo 4868e705c121SKalle Valo /* we won't be on this channel any longer */ 4869e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4870e705c121SKalle Valo 4871e705c121SKalle Valo out_unlock: 4872e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4873e705c121SKalle Valo 4874e705c121SKalle Valo return ret; 4875e705c121SKalle Valo } 4876e705c121SKalle Valo 4877c37763d2SSara Sharon static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 4878c37763d2SSara Sharon struct ieee80211_vif *vif, 4879c37763d2SSara Sharon struct ieee80211_channel_switch *chsw) 4880e705c121SKalle Valo { 4881e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4882c37763d2SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4883c37763d2SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 4884c37763d2SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 4885c37763d2SSara Sharon mvmvif->color)), 4886c37763d2SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 4887c37763d2SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 4888c37763d2SSara Sharon .cs_count = chsw->count, 488977738865SSara Sharon .cs_mode = chsw->block_tx, 4890c37763d2SSara Sharon }; 4891e705c121SKalle Valo 4892c37763d2SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 4893c37763d2SSara Sharon return; 4894e705c121SKalle Valo 4895c3eae059SGregory Greenman IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 4896c3eae059SGregory Greenman mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 4897c3eae059SGregory Greenman 489881b4e44eSSara Sharon if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 489981b4e44eSSara Sharon if (mvmvif->csa_misbehave) { 490081b4e44eSSara Sharon /* Second time, give up on this AP*/ 490181b4e44eSSara Sharon iwl_mvm_abort_channel_switch(hw, vif); 490281b4e44eSSara Sharon ieee80211_chswitch_done(vif, false); 490381b4e44eSSara Sharon mvmvif->csa_misbehave = false; 490481b4e44eSSara Sharon return; 4905e705c121SKalle Valo } 490681b4e44eSSara Sharon mvmvif->csa_misbehave = true; 4907e705c121SKalle Valo } 490881b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 4909e705c121SKalle Valo 4910caf46377SSara Sharon mutex_lock(&mvm->mutex); 4911caf46377SSara Sharon if (mvmvif->csa_failed) 4912caf46377SSara Sharon goto out_unlock; 4913e705c121SKalle Valo 4914c37763d2SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 4915c37763d2SSara Sharon WIDE_ID(MAC_CONF_GROUP, 4916c37763d2SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 4917caf46377SSara Sharon 0, sizeof(cmd), &cmd)); 4918caf46377SSara Sharon out_unlock: 4919caf46377SSara Sharon mutex_unlock(&mvm->mutex); 4920e705c121SKalle Valo } 4921e705c121SKalle Valo 49226110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 49236110d9e5SDavid Spinadel { 4924435d0827SSara Sharon int i; 4925435d0827SSara Sharon 492606195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 4927309c4848SLuca Coelho if (drop) { 4928309c4848SLuca Coelho mutex_lock(&mvm->mutex); 49296110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 4930d4e3a341SMordechay Goodstein iwl_mvm_flushable_queues(mvm) & queues); 4931309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 4932309c4848SLuca Coelho } else { 4933435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 4934309c4848SLuca Coelho } 4935435d0827SSara Sharon return; 4936435d0827SSara Sharon } 49376110d9e5SDavid Spinadel 49386110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 4939be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 4940435d0827SSara Sharon struct ieee80211_sta *sta; 4941435d0827SSara Sharon 4942435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 49436110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 49446110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 49456110d9e5SDavid Spinadel continue; 49466110d9e5SDavid Spinadel 494706195639SSara Sharon if (drop) 4948d4e3a341SMordechay Goodstein iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 494906195639SSara Sharon else 49506110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 49516110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 49526110d9e5SDavid Spinadel } 49536110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 49546110d9e5SDavid Spinadel } 49556110d9e5SDavid Spinadel 4956e705c121SKalle Valo static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, 4957e705c121SKalle Valo struct ieee80211_vif *vif, u32 queues, bool drop) 4958e705c121SKalle Valo { 4959e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4960e705c121SKalle Valo struct iwl_mvm_vif *mvmvif; 4961e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 4962e705c121SKalle Valo struct ieee80211_sta *sta; 4963e705c121SKalle Valo int i; 4964e705c121SKalle Valo u32 msk = 0; 4965e705c121SKalle Valo 49666110d9e5SDavid Spinadel if (!vif) { 49676110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 49686110d9e5SDavid Spinadel return; 49696110d9e5SDavid Spinadel } 49706110d9e5SDavid Spinadel 49716110d9e5SDavid Spinadel if (vif->type != NL80211_IFTYPE_STATION) 4972e705c121SKalle Valo return; 4973e705c121SKalle Valo 497424afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 497524afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 497624afba76SLiad Kaufman 4977e705c121SKalle Valo mutex_lock(&mvm->mutex); 4978e705c121SKalle Valo mvmvif = iwl_mvm_vif_from_mac80211(vif); 4979e705c121SKalle Valo 4980e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 4981be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 4982e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 4983e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4984e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 4985e705c121SKalle Valo continue; 4986e705c121SKalle Valo 4987e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 4988e705c121SKalle Valo if (mvmsta->vif != vif) 4989e705c121SKalle Valo continue; 4990e705c121SKalle Valo 4991e705c121SKalle Valo /* make sure only TDLS peers or the AP are flushed */ 4992e705c121SKalle Valo WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); 4993e705c121SKalle Valo 4994d49394a1SSara Sharon if (drop) { 4995f9084775SNathan Errera if (iwl_mvm_flush_sta(mvm, mvmsta, false)) 4996d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 4997d49394a1SSara Sharon } else { 4998e705c121SKalle Valo msk |= mvmsta->tfd_queue_msk; 4999d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 5000d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 5001e705c121SKalle Valo } 5002d49394a1SSara Sharon } 5003e705c121SKalle Valo 5004e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5005e705c121SKalle Valo 5006e705c121SKalle Valo /* this can take a while, and we may need/want other operations 5007e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 5008e705c121SKalle Valo */ 5009d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 5010a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 5011e705c121SKalle Valo } 5012e705c121SKalle Valo 5013e705c121SKalle Valo static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 5014e705c121SKalle Valo struct survey_info *survey) 5015e705c121SKalle Valo { 5016e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5017e705c121SKalle Valo int ret; 5018e705c121SKalle Valo 5019e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 5020e705c121SKalle Valo 5021e705c121SKalle Valo /* only support global statistics right now */ 5022e705c121SKalle Valo if (idx != 0) 5023e705c121SKalle Valo return -ENOENT; 5024e705c121SKalle Valo 5025280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 5026e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 5027e705c121SKalle Valo return -ENOENT; 5028e705c121SKalle Valo 5029e705c121SKalle Valo mutex_lock(&mvm->mutex); 5030e705c121SKalle Valo 5031aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 5032e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 5033e705c121SKalle Valo if (ret) 5034e705c121SKalle Valo goto out; 5035e705c121SKalle Valo } 5036e705c121SKalle Valo 5037e705c121SKalle Valo survey->filled = SURVEY_INFO_TIME | 5038e705c121SKalle Valo SURVEY_INFO_TIME_RX | 5039e705c121SKalle Valo SURVEY_INFO_TIME_TX | 5040e705c121SKalle Valo SURVEY_INFO_TIME_SCAN; 5041e705c121SKalle Valo survey->time = mvm->accu_radio_stats.on_time_rf + 5042e705c121SKalle Valo mvm->radio_stats.on_time_rf; 5043e705c121SKalle Valo do_div(survey->time, USEC_PER_MSEC); 5044e705c121SKalle Valo 5045e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 5046e705c121SKalle Valo mvm->radio_stats.rx_time; 5047e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 5048e705c121SKalle Valo 5049e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 5050e705c121SKalle Valo mvm->radio_stats.tx_time; 5051e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 5052e705c121SKalle Valo 5053e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 5054e705c121SKalle Valo mvm->radio_stats.on_time_scan; 5055e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 5056e705c121SKalle Valo 5057e705c121SKalle Valo ret = 0; 5058e705c121SKalle Valo out: 5059e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5060e705c121SKalle Valo return ret; 5061e705c121SKalle Valo } 5062e705c121SKalle Valo 5063ed780545SJohannes Berg static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 5064ed780545SJohannes Berg { 506582cdbd11SMiri Korenblit u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 506682cdbd11SMiri Korenblit 506782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 5068ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_20: 5069ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_20; 5070ed780545SJohannes Berg break; 5071ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_40: 5072ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_40; 5073ed780545SJohannes Berg break; 5074ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_80: 5075ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_80; 5076ed780545SJohannes Berg break; 5077ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_160: 5078ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_160; 5079ed780545SJohannes Berg break; 5080ed780545SJohannes Berg } 5081ed780545SJohannes Berg 508282cdbd11SMiri Korenblit if (format == RATE_MCS_CCK_MSK || 508382cdbd11SMiri Korenblit format == RATE_MCS_LEGACY_OFDM_MSK) { 508482cdbd11SMiri Korenblit int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 508582cdbd11SMiri Korenblit 508682cdbd11SMiri Korenblit /* add the offset needed to get to the legacy ofdm indices */ 508782cdbd11SMiri Korenblit if (format == RATE_MCS_LEGACY_OFDM_MSK) 508882cdbd11SMiri Korenblit rate += IWL_FIRST_OFDM_RATE; 508982cdbd11SMiri Korenblit 509082cdbd11SMiri Korenblit switch (rate) { 509182cdbd11SMiri Korenblit case IWL_RATE_1M_INDEX: 509282cdbd11SMiri Korenblit rinfo->legacy = 10; 509382cdbd11SMiri Korenblit break; 509482cdbd11SMiri Korenblit case IWL_RATE_2M_INDEX: 509582cdbd11SMiri Korenblit rinfo->legacy = 20; 509682cdbd11SMiri Korenblit break; 509782cdbd11SMiri Korenblit case IWL_RATE_5M_INDEX: 509882cdbd11SMiri Korenblit rinfo->legacy = 55; 509982cdbd11SMiri Korenblit break; 510082cdbd11SMiri Korenblit case IWL_RATE_11M_INDEX: 510182cdbd11SMiri Korenblit rinfo->legacy = 110; 510282cdbd11SMiri Korenblit break; 510382cdbd11SMiri Korenblit case IWL_RATE_6M_INDEX: 510482cdbd11SMiri Korenblit rinfo->legacy = 60; 510582cdbd11SMiri Korenblit break; 510682cdbd11SMiri Korenblit case IWL_RATE_9M_INDEX: 510782cdbd11SMiri Korenblit rinfo->legacy = 90; 510882cdbd11SMiri Korenblit break; 510982cdbd11SMiri Korenblit case IWL_RATE_12M_INDEX: 511082cdbd11SMiri Korenblit rinfo->legacy = 120; 511182cdbd11SMiri Korenblit break; 511282cdbd11SMiri Korenblit case IWL_RATE_18M_INDEX: 511382cdbd11SMiri Korenblit rinfo->legacy = 180; 511482cdbd11SMiri Korenblit break; 511582cdbd11SMiri Korenblit case IWL_RATE_24M_INDEX: 511682cdbd11SMiri Korenblit rinfo->legacy = 240; 511782cdbd11SMiri Korenblit break; 511882cdbd11SMiri Korenblit case IWL_RATE_36M_INDEX: 511982cdbd11SMiri Korenblit rinfo->legacy = 360; 512082cdbd11SMiri Korenblit break; 512182cdbd11SMiri Korenblit case IWL_RATE_48M_INDEX: 512282cdbd11SMiri Korenblit rinfo->legacy = 480; 512382cdbd11SMiri Korenblit break; 512482cdbd11SMiri Korenblit case IWL_RATE_54M_INDEX: 512582cdbd11SMiri Korenblit rinfo->legacy = 540; 512682cdbd11SMiri Korenblit } 512782cdbd11SMiri Korenblit return; 512882cdbd11SMiri Korenblit } 512982cdbd11SMiri Korenblit 5130ed780545SJohannes Berg rinfo->nss = u32_get_bits(rate_n_flags, 513182cdbd11SMiri Korenblit RATE_MCS_NSS_MSK) + 1; 513282cdbd11SMiri Korenblit rinfo->mcs = format == RATE_MCS_HT_MSK ? 513382cdbd11SMiri Korenblit RATE_HT_MCS_INDEX(rate_n_flags) : 513482cdbd11SMiri Korenblit u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 513582cdbd11SMiri Korenblit 513682cdbd11SMiri Korenblit if (format == RATE_MCS_HE_MSK) { 5137ed780545SJohannes Berg u32 gi_ltf = u32_get_bits(rate_n_flags, 513882cdbd11SMiri Korenblit RATE_MCS_HE_GI_LTF_MSK); 5139ed780545SJohannes Berg 5140ed780545SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 5141ed780545SJohannes Berg 514282cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 5143ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_HE_RU; 5144ed780545SJohannes Berg rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 5145ed780545SJohannes Berg } 5146ed780545SJohannes Berg 514782cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 514882cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_SU: 514982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_EXT_SU: 5150ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5151ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5152ed780545SJohannes Berg else if (gi_ltf == 2) 5153ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 515482cdbd11SMiri Korenblit else if (gi_ltf == 3) 5155ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 515682cdbd11SMiri Korenblit else 515782cdbd11SMiri Korenblit rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5158ed780545SJohannes Berg break; 515982cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_MU: 5160ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5161ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5162ed780545SJohannes Berg else if (gi_ltf == 2) 5163ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5164ed780545SJohannes Berg else 5165ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5166ed780545SJohannes Berg break; 516782cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_TRIG: 5168ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5169ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5170ed780545SJohannes Berg else 5171ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5172ed780545SJohannes Berg break; 5173ed780545SJohannes Berg } 5174ed780545SJohannes Berg 5175ed780545SJohannes Berg if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 5176ed780545SJohannes Berg rinfo->he_dcm = 1; 517782cdbd11SMiri Korenblit return; 5178ed780545SJohannes Berg } 517982cdbd11SMiri Korenblit 518082cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_SGI_MSK) 518182cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 518282cdbd11SMiri Korenblit 518382cdbd11SMiri Korenblit if (format == RATE_MCS_HT_MSK) { 518482cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_MCS; 518582cdbd11SMiri Korenblit 518682cdbd11SMiri Korenblit } else if (format == RATE_MCS_VHT_MSK) { 518782cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 5188ed780545SJohannes Berg } 518982cdbd11SMiri Korenblit 5190ed780545SJohannes Berg } 5191ed780545SJohannes Berg 5192e705c121SKalle Valo static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 5193e705c121SKalle Valo struct ieee80211_vif *vif, 5194e705c121SKalle Valo struct ieee80211_sta *sta, 5195e705c121SKalle Valo struct station_info *sinfo) 5196e705c121SKalle Valo { 5197e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5198e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5199e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5200e705c121SKalle Valo 5201988b5968SSara Sharon if (mvmsta->avg_energy) { 520288ad368aSBen Greear sinfo->signal_avg = -(s8)mvmsta->avg_energy; 520322d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 5204988b5968SSara Sharon } 5205988b5968SSara Sharon 5206ed780545SJohannes Berg if (iwl_mvm_has_tlc_offload(mvm)) { 5207ed780545SJohannes Berg struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw; 5208ed780545SJohannes Berg 5209ed780545SJohannes Berg iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 5210ed780545SJohannes Berg sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 5211ed780545SJohannes Berg } 5212ed780545SJohannes Berg 5213e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 5214e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 5215e705c121SKalle Valo return; 5216e705c121SKalle Valo 5217e705c121SKalle Valo if (!vif->bss_conf.assoc) 5218e705c121SKalle Valo return; 5219e705c121SKalle Valo 5220e705c121SKalle Valo mutex_lock(&mvm->mutex); 5221e705c121SKalle Valo 5222e705c121SKalle Valo if (mvmvif->ap_sta_id != mvmsta->sta_id) 5223e705c121SKalle Valo goto unlock; 5224e705c121SKalle Valo 5225e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 5226e705c121SKalle Valo goto unlock; 5227e705c121SKalle Valo 5228e705c121SKalle Valo sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + 5229e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons; 523022d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 5231e705c121SKalle Valo if (mvmvif->beacon_stats.avg_signal) { 5232e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 5233e705c121SKalle Valo sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; 523422d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 5235e705c121SKalle Valo } 5236e705c121SKalle Valo unlock: 5237e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5238e705c121SKalle Valo } 5239e705c121SKalle Valo 5240119c2a13SMordechay Goodstein static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 5241119c2a13SMordechay Goodstein struct ieee80211_vif *vif, 5242119c2a13SMordechay Goodstein const struct ieee80211_mlme_event *mlme) 5243119c2a13SMordechay Goodstein { 52441a81bddfSMordechay Goodstein if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 52451a81bddfSMordechay Goodstein (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 5246119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5247119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 5248119c2a13SMordechay Goodstein NULL); 5249119c2a13SMordechay Goodstein return; 5250119c2a13SMordechay Goodstein } 5251119c2a13SMordechay Goodstein 5252119c2a13SMordechay Goodstein if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 5253119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5254119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_DEASSOC, 5255119c2a13SMordechay Goodstein NULL); 5256119c2a13SMordechay Goodstein return; 5257119c2a13SMordechay Goodstein } 5258119c2a13SMordechay Goodstein } 5259119c2a13SMordechay Goodstein 5260e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 5261e705c121SKalle Valo struct ieee80211_vif *vif, 5262e705c121SKalle Valo const struct ieee80211_event *event) 5263e705c121SKalle Valo { 52644c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 5265e705c121SKalle Valo do { \ 52664c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 5267e705c121SKalle Valo break; \ 52687174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 5269e705c121SKalle Valo } while (0) 5270e705c121SKalle Valo 5271e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5272e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 5273e705c121SKalle Valo 5274119c2a13SMordechay Goodstein if (iwl_trans_dbg_ini_valid(mvm->trans)) { 5275119c2a13SMordechay Goodstein iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 5276119c2a13SMordechay Goodstein return; 5277119c2a13SMordechay Goodstein } 5278119c2a13SMordechay Goodstein 52796c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 52806c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 52816c042d75SSara Sharon if (!trig) 5282e705c121SKalle Valo return; 5283e705c121SKalle Valo 5284e705c121SKalle Valo trig_mlme = (void *)trig->data; 5285e705c121SKalle Valo 5286e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 5287e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 52884c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 5289e705c121SKalle Valo "DENIED ASSOC: reason %d", 5290e705c121SKalle Valo event->u.mlme.reason); 5291e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 52924c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 5293e705c121SKalle Valo "ASSOC TIMEOUT"); 5294e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 5295e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 52964c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 5297e705c121SKalle Valo "DENIED AUTH: reason %d", 5298e705c121SKalle Valo event->u.mlme.reason); 5299e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 53004c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 5301e705c121SKalle Valo "AUTH TIMEOUT"); 5302e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 53034c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 5304e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 5305e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 53064c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 5307e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 5308e705c121SKalle Valo } 5309e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 5310e705c121SKalle Valo } 5311e705c121SKalle Valo 5312e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 5313e705c121SKalle Valo struct ieee80211_vif *vif, 5314e705c121SKalle Valo const struct ieee80211_event *event) 5315e705c121SKalle Valo { 5316e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5317e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 5318e705c121SKalle Valo 53196c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 53206c042d75SSara Sharon FW_DBG_TRIGGER_BA); 53216c042d75SSara Sharon if (!trig) 5322e705c121SKalle Valo return; 5323e705c121SKalle Valo 5324e705c121SKalle Valo ba_trig = (void *)trig->data; 5325e705c121SKalle Valo 5326e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 5327e705c121SKalle Valo return; 5328e705c121SKalle Valo 53297174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 5330e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 5331e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 5332e705c121SKalle Valo event->u.ba.ssn); 5333e705c121SKalle Valo } 5334e705c121SKalle Valo 5335e705c121SKalle Valo static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 5336e705c121SKalle Valo struct ieee80211_vif *vif, 5337e705c121SKalle Valo const struct ieee80211_event *event) 5338e705c121SKalle Valo { 5339e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5340e705c121SKalle Valo 5341e705c121SKalle Valo switch (event->type) { 5342e705c121SKalle Valo case MLME_EVENT: 5343e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 5344e705c121SKalle Valo break; 5345e705c121SKalle Valo case BAR_RX_EVENT: 5346e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 5347e705c121SKalle Valo break; 5348e705c121SKalle Valo case BA_FRAME_TIMEOUT: 5349528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 5350528a542aSEmmanuel Grumbach event->u.ba.tid); 5351e705c121SKalle Valo break; 5352e705c121SKalle Valo default: 5353e705c121SKalle Valo break; 5354e705c121SKalle Valo } 5355e705c121SKalle Valo } 5356e705c121SKalle Valo 5357d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 53585e1688ceSJohannes Berg enum iwl_mvm_rxq_notif_type type, 53595e1688ceSJohannes Berg bool sync, 53605e1688ceSJohannes Berg const void *data, u32 size) 53610636b938SSara Sharon { 53625e1688ceSJohannes Berg struct { 53635e1688ceSJohannes Berg struct iwl_rxq_sync_cmd cmd; 53645e1688ceSJohannes Berg struct iwl_mvm_internal_rxq_notif notif; 53655e1688ceSJohannes Berg } __packed cmd = { 53665e1688ceSJohannes Berg .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 53675e1688ceSJohannes Berg .cmd.count = 53685e1688ceSJohannes Berg cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 53695e1688ceSJohannes Berg size), 53705e1688ceSJohannes Berg .notif.type = type, 53715e1688ceSJohannes Berg .notif.sync = sync, 53725e1688ceSJohannes Berg }; 53735e1688ceSJohannes Berg struct iwl_host_cmd hcmd = { 53745e1688ceSJohannes Berg .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 53755e1688ceSJohannes Berg .data[0] = &cmd, 53765e1688ceSJohannes Berg .len[0] = sizeof(cmd), 53775e1688ceSJohannes Berg .data[1] = data, 53785e1688ceSJohannes Berg .len[1] = size, 53795e1688ceSJohannes Berg .flags = sync ? 0 : CMD_ASYNC, 53805e1688ceSJohannes Berg }; 53810636b938SSara Sharon int ret; 53820636b938SSara Sharon 53835e1688ceSJohannes Berg /* size must be a multiple of DWORD */ 53845e1688ceSJohannes Berg if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 53855e1688ceSJohannes Berg return; 53860636b938SSara Sharon 5387cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 53880636b938SSara Sharon return; 53890636b938SSara Sharon 53905e1688ceSJohannes Berg if (sync) { 53915e1688ceSJohannes Berg cmd.notif.cookie = mvm->queue_sync_cookie; 53922f7a04c7SJohannes Berg mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 5393a2113cc4SNaftali Goldstein } 5394d0ff5d22SSara Sharon 53955e1688ceSJohannes Berg ret = iwl_mvm_send_cmd(mvm, &hcmd); 53960636b938SSara Sharon if (ret) { 53970636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 53980636b938SSara Sharon goto out; 53990636b938SSara Sharon } 5400d0ff5d22SSara Sharon 54015e1688ceSJohannes Berg if (sync) { 54023c514bf8SEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 54033a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 54042f7a04c7SJohannes Berg READ_ONCE(mvm->queue_sync_state) == 0 || 54056ad04359SJohannes Berg iwl_mvm_is_radio_killed(mvm), 54060636b938SSara Sharon HZ); 54072f7a04c7SJohannes Berg WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm), 54082f7a04c7SJohannes Berg "queue sync: failed to sync, state is 0x%lx\n", 54092f7a04c7SJohannes Berg mvm->queue_sync_state); 54106ad04359SJohannes Berg } 54110636b938SSara Sharon 54120636b938SSara Sharon out: 54135e1688ceSJohannes Berg if (sync) { 54142f7a04c7SJohannes Berg mvm->queue_sync_state = 0; 54150636b938SSara Sharon mvm->queue_sync_cookie++; 54160636b938SSara Sharon } 54175f8a3561SJohannes Berg } 54180636b938SSara Sharon 54190636b938SSara Sharon static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 54200636b938SSara Sharon { 54210636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 54220636b938SSara Sharon 54230636b938SSara Sharon mutex_lock(&mvm->mutex); 54245e1688ceSJohannes Berg iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 54250636b938SSara Sharon mutex_unlock(&mvm->mutex); 54260636b938SSara Sharon } 54270636b938SSara Sharon 5428b73f9a4aSJohannes Berg static int 5429b73f9a4aSJohannes Berg iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 5430b73f9a4aSJohannes Berg struct ieee80211_vif *vif, 5431b73f9a4aSJohannes Berg struct cfg80211_ftm_responder_stats *stats) 5432b73f9a4aSJohannes Berg { 5433b73f9a4aSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5434b73f9a4aSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5435b73f9a4aSJohannes Berg 5436b73f9a4aSJohannes Berg if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 5437b73f9a4aSJohannes Berg !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 5438b73f9a4aSJohannes Berg return -EINVAL; 5439b73f9a4aSJohannes Berg 5440b73f9a4aSJohannes Berg mutex_lock(&mvm->mutex); 5441b73f9a4aSJohannes Berg *stats = mvm->ftm_resp_stats; 5442b73f9a4aSJohannes Berg mutex_unlock(&mvm->mutex); 5443b73f9a4aSJohannes Berg 5444b73f9a4aSJohannes Berg stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 5445b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 5446b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_FAILED_NUM) | 5447b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_ASAP_NUM) | 5448b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 5449b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 5450b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 5451b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 5452b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 5453b73f9a4aSJohannes Berg 5454b73f9a4aSJohannes Berg return 0; 5455b73f9a4aSJohannes Berg } 5456b73f9a4aSJohannes Berg 5457fc36ffdaSJohannes Berg static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, 5458fc36ffdaSJohannes Berg struct ieee80211_vif *vif, 5459fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5460fc36ffdaSJohannes Berg { 5461fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5462fc36ffdaSJohannes Berg int ret; 5463fc36ffdaSJohannes Berg 5464fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5465fc36ffdaSJohannes Berg ret = iwl_mvm_ftm_start(mvm, vif, request); 5466fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5467fc36ffdaSJohannes Berg 5468fc36ffdaSJohannes Berg return ret; 5469fc36ffdaSJohannes Berg } 5470fc36ffdaSJohannes Berg 5471fc36ffdaSJohannes Berg static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, 5472fc36ffdaSJohannes Berg struct ieee80211_vif *vif, 5473fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5474fc36ffdaSJohannes Berg { 5475fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5476fc36ffdaSJohannes Berg 5477fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5478fc36ffdaSJohannes Berg iwl_mvm_ftm_abort(mvm, request); 5479fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5480fc36ffdaSJohannes Berg } 5481fc36ffdaSJohannes Berg 5482438af969SSara Sharon static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 5483438af969SSara Sharon { 5484438af969SSara Sharon u8 protocol = ip_hdr(skb)->protocol; 5485438af969SSara Sharon 5486438af969SSara Sharon if (!IS_ENABLED(CONFIG_INET)) 5487438af969SSara Sharon return false; 5488438af969SSara Sharon 5489438af969SSara Sharon return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 5490438af969SSara Sharon } 5491438af969SSara Sharon 5492438af969SSara Sharon static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 5493438af969SSara Sharon struct sk_buff *head, 5494438af969SSara Sharon struct sk_buff *skb) 5495438af969SSara Sharon { 5496438af969SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5497438af969SSara Sharon 5498438af969SSara Sharon /* For now don't aggregate IPv6 in AMSDU */ 5499438af969SSara Sharon if (skb->protocol != htons(ETH_P_IP)) 5500438af969SSara Sharon return false; 5501438af969SSara Sharon 5502438af969SSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) 5503438af969SSara Sharon return true; 5504438af969SSara Sharon 5505438af969SSara Sharon return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 5506438af969SSara Sharon } 5507438af969SSara Sharon 5508e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 5509e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 5510cfbc6c4cSSara Sharon .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 5511e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 5512e8503aecSBen Greear .get_antenna = iwl_mvm_op_get_antenna, 5513e705c121SKalle Valo .start = iwl_mvm_mac_start, 5514e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 5515e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 5516e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 5517e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 5518e705c121SKalle Valo .config = iwl_mvm_mac_config, 5519e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 5520e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 5521e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 5522e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 5523e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 5524e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 5525e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 5526e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 5527e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 5528e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 5529e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 5530e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 5531e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 5532e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 5533e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 55346b1259d1SJohannes Berg .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 5535e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 5536e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 5537e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 5538e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 5539e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 5540e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 5541e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 5542e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 5543e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 5544e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 5545e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 5546e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 5547e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 5548e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 5549e705c121SKalle Valo 5550e705c121SKalle Valo .start_ap = iwl_mvm_start_ap_ibss, 5551e705c121SKalle Valo .stop_ap = iwl_mvm_stop_ap_ibss, 5552e705c121SKalle Valo .join_ibss = iwl_mvm_start_ap_ibss, 5553e705c121SKalle Valo .leave_ibss = iwl_mvm_stop_ap_ibss, 5554e705c121SKalle Valo 55552f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 55562f0282dbSJohannes Berg 5557e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 5558e705c121SKalle Valo 5559e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 5560e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 5561e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 556279221126SSara Sharon .abort_channel_switch = iwl_mvm_abort_channel_switch, 5563c37763d2SSara Sharon .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 5564e705c121SKalle Valo 5565e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 5566e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 5567e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 5568e705c121SKalle Valo 5569e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 5570e705c121SKalle Valo 55710636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 55720636b938SSara Sharon 5573e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 5574e705c121SKalle Valo 5575e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 5576e705c121SKalle Valo /* look at d3.c */ 5577e705c121SKalle Valo .suspend = iwl_mvm_suspend, 5578e705c121SKalle Valo .resume = iwl_mvm_resume, 5579e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 5580e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 5581e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 5582e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 5583e705c121SKalle Valo #endif 5584e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 5585e705c121SKalle Valo #endif 5586e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 5587e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 5588b73f9a4aSJohannes Berg .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 5589fc36ffdaSJohannes Berg .start_pmsr = iwl_mvm_start_pmsr, 5590fc36ffdaSJohannes Berg .abort_pmsr = iwl_mvm_abort_pmsr, 5591b73f9a4aSJohannes Berg 5592438af969SSara Sharon .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 5593177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 5594177a11cfSGregory Greenman .sta_add_debugfs = iwl_mvm_sta_add_debugfs, 5595177a11cfSGregory Greenman #endif 5596e705c121SKalle Valo }; 5597