18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 28e99ea8dSJohannes Berg /* 3091296d3SMiri Korenblit * Copyright (C) 2012-2014, 2018-2022 Intel Corporation 48e99ea8dSJohannes Berg * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 58e99ea8dSJohannes Berg * Copyright (C) 2016-2017 Intel Deutschland GmbH 68e99ea8dSJohannes Berg */ 7e705c121SKalle Valo #include <linux/kernel.h> 8e705c121SKalle Valo #include <linux/slab.h> 9e705c121SKalle Valo #include <linux/skbuff.h> 10e705c121SKalle Valo #include <linux/netdevice.h> 11e705c121SKalle Valo #include <linux/etherdevice.h> 12e705c121SKalle Valo #include <linux/ip.h> 13e705c121SKalle Valo #include <linux/if_arp.h> 142f89a5d7SGolan Ben-Ami #include <linux/time.h> 15e705c121SKalle Valo #include <net/mac80211.h> 16e705c121SKalle Valo #include <net/ieee80211_radiotap.h> 17e705c121SKalle Valo #include <net/tcp.h> 18e705c121SKalle Valo 195283dd67SMordechay Goodstein #include "iwl-drv.h" 20e705c121SKalle Valo #include "iwl-op-mode.h" 21e705c121SKalle Valo #include "iwl-io.h" 22e705c121SKalle Valo #include "mvm.h" 23e705c121SKalle Valo #include "sta.h" 24e705c121SKalle Valo #include "time-event.h" 25e705c121SKalle Valo #include "iwl-eeprom-parse.h" 26e705c121SKalle Valo #include "iwl-phy-db.h" 27e705c121SKalle Valo #include "testmode.h" 28d962f9b1SJohannes Berg #include "fw/error-dump.h" 29e705c121SKalle Valo #include "iwl-prph.h" 30e705c121SKalle Valo #include "iwl-nvm-parse.h" 31e705c121SKalle Valo 32e705c121SKalle Valo static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 33e705c121SKalle Valo { 34e705c121SKalle Valo .max = 1, 35e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_STATION), 36e705c121SKalle Valo }, 37e705c121SKalle Valo { 38e705c121SKalle Valo .max = 1, 39e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_AP) | 40e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 41e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO), 42e705c121SKalle Valo }, 43e705c121SKalle Valo { 44e705c121SKalle Valo .max = 1, 45e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 46e705c121SKalle Valo }, 47e705c121SKalle Valo }; 48e705c121SKalle Valo 49e705c121SKalle Valo static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 50e705c121SKalle Valo { 51e705c121SKalle Valo .num_different_channels = 2, 52e705c121SKalle Valo .max_interfaces = 3, 53e705c121SKalle Valo .limits = iwl_mvm_limits, 54e705c121SKalle Valo .n_limits = ARRAY_SIZE(iwl_mvm_limits), 55e705c121SKalle Valo }, 56e705c121SKalle Valo }; 57e705c121SKalle Valo 58fc36ffdaSJohannes Berg static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = { 59fc36ffdaSJohannes Berg .max_peers = IWL_MVM_TOF_MAX_APS, 60fc36ffdaSJohannes Berg .report_ap_tsf = 1, 61fc36ffdaSJohannes Berg .randomize_mac_addr = 1, 62fc36ffdaSJohannes Berg 63fc36ffdaSJohannes Berg .ftm = { 64fc36ffdaSJohannes Berg .supported = 1, 65fc36ffdaSJohannes Berg .asap = 1, 66fc36ffdaSJohannes Berg .non_asap = 1, 67fc36ffdaSJohannes Berg .request_lci = 1, 68fc36ffdaSJohannes Berg .request_civicloc = 1, 696815e3d0SAvraham Stern .trigger_based = 1, 706815e3d0SAvraham Stern .non_trigger_based = 1, 71fc36ffdaSJohannes Berg .max_bursts_exponent = -1, /* all supported */ 72fc36ffdaSJohannes Berg .max_ftms_per_burst = 0, /* no limits */ 73fc36ffdaSJohannes Berg .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 74fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_20) | 75fc36ffdaSJohannes Berg BIT(NL80211_CHAN_WIDTH_40) | 768a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_80) | 778a2c1516SAvraham Stern BIT(NL80211_CHAN_WIDTH_160), 78fc36ffdaSJohannes Berg .preambles = BIT(NL80211_PREAMBLE_LEGACY) | 79fc36ffdaSJohannes Berg BIT(NL80211_PREAMBLE_HT) | 806815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_VHT) | 816815e3d0SAvraham Stern BIT(NL80211_PREAMBLE_HE), 82fc36ffdaSJohannes Berg }, 83fc36ffdaSJohannes Berg }; 84fc36ffdaSJohannes Berg 856569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 86c56e00a3SJohannes Berg enum set_key_cmd cmd, 87c56e00a3SJohannes Berg struct ieee80211_vif *vif, 88c56e00a3SJohannes Berg struct ieee80211_sta *sta, 89c56e00a3SJohannes Berg struct ieee80211_key_conf *key); 90c56e00a3SJohannes Berg 91e705c121SKalle Valo static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 92e705c121SKalle Valo { 93e705c121SKalle Valo int i; 94e705c121SKalle Valo 95e705c121SKalle Valo memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 96e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 97e705c121SKalle Valo mvm->phy_ctxts[i].id = i; 98e705c121SKalle Valo mvm->phy_ctxts[i].ref = 0; 99e705c121SKalle Valo } 100e705c121SKalle Valo } 101e705c121SKalle Valo 102e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 103e705c121SKalle Valo const char *alpha2, 104e705c121SKalle Valo enum iwl_mcc_source src_id, 105e705c121SKalle Valo bool *changed) 106e705c121SKalle Valo { 107e705c121SKalle Valo struct ieee80211_regdomain *regd = NULL; 108e705c121SKalle Valo struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 109e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 110e705c121SKalle Valo struct iwl_mcc_update_resp *resp; 111e27c506aSGil Adam u8 resp_ver; 112e705c121SKalle Valo 113e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 114e705c121SKalle Valo 115e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 116e705c121SKalle Valo 117e705c121SKalle Valo resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 118e705c121SKalle Valo if (IS_ERR_OR_NULL(resp)) { 119e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 120e705c121SKalle Valo PTR_ERR_OR_ZERO(resp)); 1216d19a5ebSEmmanuel Grumbach resp = NULL; 122e705c121SKalle Valo goto out; 123e705c121SKalle Valo } 124e705c121SKalle Valo 12582715ac7SEmmanuel Grumbach if (changed) { 12682715ac7SEmmanuel Grumbach u32 status = le32_to_cpu(resp->status); 12782715ac7SEmmanuel Grumbach 12882715ac7SEmmanuel Grumbach *changed = (status == MCC_RESP_NEW_CHAN_PROFILE || 12982715ac7SEmmanuel Grumbach status == MCC_RESP_ILLEGAL); 13082715ac7SEmmanuel Grumbach } 131e27c506aSGil Adam resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP, 132e27c506aSGil Adam MCC_UPDATE_CMD, 0); 133e27c506aSGil Adam IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver); 134e705c121SKalle Valo 135e705c121SKalle Valo regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 136e705c121SKalle Valo __le32_to_cpu(resp->n_channels), 137e705c121SKalle Valo resp->channels, 13877e30e10SHaim Dreyfuss __le16_to_cpu(resp->mcc), 1392763bba6SHaim Dreyfuss __le16_to_cpu(resp->geo_info), 140e27c506aSGil Adam __le16_to_cpu(resp->cap), resp_ver); 141e705c121SKalle Valo /* Store the return source id */ 142e705c121SKalle Valo src_id = resp->source_id; 143e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 144e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 145e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 146e705c121SKalle Valo goto out; 147e705c121SKalle Valo } 148e705c121SKalle Valo 149e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 150e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 151e705c121SKalle Valo mvm->lar_regdom_set = true; 152e705c121SKalle Valo mvm->mcc_src = src_id; 153e705c121SKalle Valo 1546d19a5ebSEmmanuel Grumbach iwl_mei_set_country_code(__le16_to_cpu(resp->mcc)); 1556d19a5ebSEmmanuel Grumbach 156e705c121SKalle Valo out: 1576d19a5ebSEmmanuel Grumbach kfree(resp); 158e705c121SKalle Valo return regd; 159e705c121SKalle Valo } 160e705c121SKalle Valo 161e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 162e705c121SKalle Valo { 163e705c121SKalle Valo bool changed; 164e705c121SKalle Valo struct ieee80211_regdomain *regd; 165e705c121SKalle Valo 166e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 167e705c121SKalle Valo return; 168e705c121SKalle Valo 169e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 170e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 171e705c121SKalle Valo /* only update the regulatory core if changed */ 172e705c121SKalle Valo if (changed) 173e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 174e705c121SKalle Valo 175e705c121SKalle Valo kfree(regd); 176e705c121SKalle Valo } 177e705c121SKalle Valo } 178e705c121SKalle Valo 179e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 180e705c121SKalle Valo bool *changed) 181e705c121SKalle Valo { 182e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 183e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 184e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 185e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 186e705c121SKalle Valo } 187e705c121SKalle Valo 188e705c121SKalle Valo int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) 189e705c121SKalle Valo { 190e705c121SKalle Valo enum iwl_mcc_source used_src; 191e705c121SKalle Valo struct ieee80211_regdomain *regd; 192e705c121SKalle Valo int ret; 193e705c121SKalle Valo bool changed; 194e705c121SKalle Valo const struct ieee80211_regdomain *r = 195a05829a7SJohannes Berg wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd); 196e705c121SKalle Valo 197e705c121SKalle Valo if (!r) 198e705c121SKalle Valo return -ENOENT; 199e705c121SKalle Valo 200e705c121SKalle Valo /* save the last source in case we overwrite it below */ 201e705c121SKalle Valo used_src = mvm->mcc_src; 202e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 203e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 204e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 205e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 206e705c121SKalle Valo kfree(regd); 207e705c121SKalle Valo } 208e705c121SKalle Valo 209e705c121SKalle Valo /* Now set our last stored MCC and source */ 210e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 211e705c121SKalle Valo &changed); 212e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 213e705c121SKalle Valo return -EIO; 214e705c121SKalle Valo 215e705c121SKalle Valo /* update cfg80211 if the regdomain was changed */ 216e705c121SKalle Valo if (changed) 217a05829a7SJohannes Berg ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); 218e705c121SKalle Valo else 219e705c121SKalle Valo ret = 0; 220e705c121SKalle Valo 221e705c121SKalle Valo kfree(regd); 222e705c121SKalle Valo return ret; 223e705c121SKalle Valo } 224e705c121SKalle Valo 2257f2ea521SYueHaibing static const u8 he_if_types_ext_capa_sta[] = { 2267360f99eSEmmanuel Grumbach [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, 227918cbf39SSara Sharon [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, 2287360f99eSEmmanuel Grumbach [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF, 2297360f99eSEmmanuel Grumbach }; 2307360f99eSEmmanuel Grumbach 2317f2ea521SYueHaibing static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = { 2327360f99eSEmmanuel Grumbach { 2337360f99eSEmmanuel Grumbach .iftype = NL80211_IFTYPE_STATION, 2347360f99eSEmmanuel Grumbach .extended_capabilities = he_if_types_ext_capa_sta, 2357360f99eSEmmanuel Grumbach .extended_capabilities_mask = he_if_types_ext_capa_sta, 2367360f99eSEmmanuel Grumbach .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta), 2377360f99eSEmmanuel Grumbach }, 2387360f99eSEmmanuel Grumbach }; 2397360f99eSEmmanuel Grumbach 240e8503aecSBen Greear static int 241e8503aecSBen Greear iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant) 242e8503aecSBen Greear { 243e8503aecSBen Greear struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 244e8503aecSBen Greear *tx_ant = iwl_mvm_get_valid_tx_ant(mvm); 245e8503aecSBen Greear *rx_ant = iwl_mvm_get_valid_rx_ant(mvm); 246e8503aecSBen Greear return 0; 247e8503aecSBen Greear } 248e8503aecSBen Greear 249e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 250e705c121SKalle Valo { 251e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 252e705c121SKalle Valo int num_mac, ret, i; 253e705c121SKalle Valo static const u32 mvm_ciphers[] = { 254e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 255e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 256e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 257e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 258e705c121SKalle Valo }; 2593f37c229SIdo Yariv #ifdef CONFIG_PM_SLEEP 2603f37c229SIdo Yariv bool unified = fw_has_capa(&mvm->fw->ucode_capa, 2613f37c229SIdo Yariv IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); 2623f37c229SIdo Yariv #endif 263e705c121SKalle Valo 264e705c121SKalle Valo /* Tell mac80211 our characteristics */ 265e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 266e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 267e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 268e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 269e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 270e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 271e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 272e705c121SKalle Valo ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 273e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 274e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 275e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 276e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 277909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 27830433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 279d270e7b8SIlan Peer ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 280520229e4SShaul Triebitz ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW); 281cfbc6c4cSSara Sharon ieee80211_hw_set(hw, BUFF_MMPDU_TXQ); 282cfbc6c4cSSara Sharon ieee80211_hw_set(hw, STA_MMPDU_TXQ); 283cfb21b11SJohannes Berg /* 284cfb21b11SJohannes Berg * On older devices, enabling TX A-MSDU occasionally leads to 285cfb21b11SJohannes Berg * something getting messed up, the command read from the FIFO 286cfb21b11SJohannes Berg * gets out of sync and isn't a TX command, so that we have an 287cfb21b11SJohannes Berg * assert EDC. 288cfb21b11SJohannes Berg * 289cfb21b11SJohannes Berg * It's not clear where the bug is, but since we didn't used to 290cfb21b11SJohannes Berg * support A-MSDU until moving the mac80211 iTXQs, just leave it 291cfb21b11SJohannes Berg * for older devices. We also don't see this issue on any newer 292cfb21b11SJohannes Berg * devices. 293cfb21b11SJohannes Berg */ 2947d34a7d7SLuca Coelho if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000) 295438af969SSara Sharon ieee80211_hw_set(hw, TX_AMSDU); 296438af969SSara Sharon ieee80211_hw_set(hw, TX_FRAG_LIST); 297ecaf71deSGregory Greenman 2984243edb4SEmmanuel Grumbach if (iwl_mvm_has_tlc_offload(mvm)) { 299ecaf71deSGregory Greenman ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 300ecaf71deSGregory Greenman ieee80211_hw_set(hw, HAS_RATE_CONTROL); 301ecaf71deSGregory Greenman } 302ecaf71deSGregory Greenman 303b915c101SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 304b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 305960f864bSJohannes Berg 306960f864bSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 307960f864bSJohannes Berg IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 30865e25482SJohannes Berg ieee80211_hw_set(hw, AP_LINK_PS); 309960f864bSJohannes Berg } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 310960f864bSJohannes Berg /* 311960f864bSJohannes Berg * we absolutely need this for the new TX API since that comes 312960f864bSJohannes Berg * with many more queues than the current code can deal with 313960f864bSJohannes Berg * for station powersave 314960f864bSJohannes Berg */ 315960f864bSJohannes Berg return -EINVAL; 316960f864bSJohannes Berg } 317e705c121SKalle Valo 31880938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 31980938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 32080938abcSJohannes Berg 3212d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 3222d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 3232d7cf549SJohannes Berg 324366fc672SJohannes Berg hw->queues = IEEE80211_NUM_ACS; 325e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 326e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 327e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 328e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 329e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 330371a17edSJohannes Berg 331371a17edSJohannes Berg hw->radiotap_timestamp.units_pos = 332371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 333371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 334371a17edSJohannes Berg /* this is the case for CCK frames, it's better (only 8) for OFDM */ 335371a17edSJohannes Berg hw->radiotap_timestamp.accuracy = 22; 336371a17edSJohannes Berg 3374243edb4SEmmanuel Grumbach if (!iwl_mvm_has_tlc_offload(mvm)) 3389f66a397SGregory Greenman hw->rate_control_algorithm = RS_NAME; 3399f66a397SGregory Greenman 340e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 341e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 342438af969SSara Sharon hw->max_tx_fragments = mvm->trans->max_skb_frags; 343e705c121SKalle Valo 3448e160ab8SAyala Beker BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 345e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 346e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 347e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 348e705c121SKalle Valo 3492a53d166SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 3502a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3512a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP; 3522a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 3532a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3542a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP_256; 3552a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 3562a53d166SAyala Beker } 3572a53d166SAyala Beker 358f4bfdc5eSEmmanuel Grumbach if (iwlwifi_mod_params.swcrypto) 359f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 360f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n"); 361f4bfdc5eSEmmanuel Grumbach if (!iwlwifi_mod_params.bt_coex_active) 362f4bfdc5eSEmmanuel Grumbach IWL_ERR(mvm, 363f4bfdc5eSEmmanuel Grumbach "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n"); 364f4bfdc5eSEmmanuel Grumbach 365e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 366f4bfdc5eSEmmanuel Grumbach mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC; 367e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 3688e160ab8SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 3698e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3708e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_128; 3718e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 3728e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 3738e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_256; 3748e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 3758e160ab8SAyala Beker } 376e705c121SKalle Valo 377b73f9a4aSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 378fc36ffdaSJohannes Berg IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) { 379b73f9a4aSJohannes Berg wiphy_ext_feature_set(hw->wiphy, 380b73f9a4aSJohannes Berg NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); 381fc36ffdaSJohannes Berg hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa; 382fc36ffdaSJohannes Berg } 383b73f9a4aSJohannes Berg 384b1fdc250SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 385b1fdc250SJohannes Berg IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT)) 386b1fdc250SJohannes Berg wiphy_ext_feature_set(hw->wiphy, 387b1fdc250SJohannes Berg NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT); 388b1fdc250SJohannes Berg 389e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 390e705c121SKalle Valo hw->wiphy->features |= 391e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 392e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 393e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 394e705c121SKalle Valo 395e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 396e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 397e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 398cfbc6c4cSSara Sharon hw->txq_data_size = sizeof(struct iwl_mvm_txq); 399e705c121SKalle Valo 400e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 401e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 402e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 403e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 404e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 405e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 406e705c121SKalle Valo 407e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 408e47df5bdSJohannes Berg wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 40933e3fd99SAlexander Wetzel 41033e3fd99SAlexander Wetzel /* The new Tx API does not allow to pass the key or keyid of a MPDU to 41133e3fd99SAlexander Wetzel * the hw, preventing us to control which key(id) to use per MPDU. 41233e3fd99SAlexander Wetzel * Till that's fixed we can't use Extended Key ID for the newer cards. 41333e3fd99SAlexander Wetzel */ 41433e3fd99SAlexander Wetzel if (!iwl_mvm_has_new_tx_api(mvm)) 41533e3fd99SAlexander Wetzel wiphy_ext_feature_set(hw->wiphy, 41633e3fd99SAlexander Wetzel NL80211_EXT_FEATURE_EXT_KEY_ID); 417e47df5bdSJohannes Berg hw->wiphy->features |= NL80211_FEATURE_HT_IBSS; 418e47df5bdSJohannes Berg 419e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 420e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 421e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 422e705c121SKalle Valo else 423e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 424e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 425e705c121SKalle Valo 426e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 427e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 428eae94cf8SLuca Coelho hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ; 429e705c121SKalle Valo 430e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 431e705c121SKalle Valo hw->wiphy->n_iface_combinations = 432e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 433e705c121SKalle Valo 434e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 435e705c121SKalle Valo hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 436e705c121SKalle Valo 437e705c121SKalle Valo /* Extract MAC address */ 438e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 439e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 440e705c121SKalle Valo hw->wiphy->n_addresses = 1; 441e705c121SKalle Valo 442e705c121SKalle Valo /* Extract additional MAC addresses if available */ 443e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 444e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 445e705c121SKalle Valo 446e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 447e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 448e705c121SKalle Valo ETH_ALEN); 449e705c121SKalle Valo mvm->addresses[i].addr[5]++; 450e705c121SKalle Valo hw->wiphy->n_addresses++; 451e705c121SKalle Valo } 452e705c121SKalle Valo 453e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 454e705c121SKalle Valo 455e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 456e705c121SKalle Valo 457e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 458e705c121SKalle Valo 459e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 460e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 461e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 462e705c121SKalle Valo 463e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 464e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 465e705c121SKalle Valo else 466e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 467e705c121SKalle Valo 46857fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 46957fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 47057fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 47157fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 47257fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 47357fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 474e705c121SKalle Valo 475e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 476e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 477e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 478e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 47957fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 480e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 481e705c121SKalle Valo } 482eae94cf8SLuca Coelho if (fw_has_capa(&mvm->fw->ucode_capa, 483eae94cf8SLuca Coelho IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) && 484eae94cf8SLuca Coelho mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels) 485eae94cf8SLuca Coelho hw->wiphy->bands[NL80211_BAND_6GHZ] = 486eae94cf8SLuca Coelho &mvm->nvm_data->bands[NL80211_BAND_6GHZ]; 487e705c121SKalle Valo 488e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 489e705c121SKalle Valo 490e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 491e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 492e705c121SKalle Valo else 493e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 494e705c121SKalle Valo 495ca986ad9SArend Van Spriel hw->wiphy->max_sched_scan_reqs = 1; 496e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 4975d1234baSTova Mussai hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); 498e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 499e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 500e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 501e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 502e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 503e705c121SKalle Valo 504e705c121SKalle Valo /* 505e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 506e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 507e705c121SKalle Valo */ 508e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 509e705c121SKalle Valo 510e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 511e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 512e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 513a904a08bSPeer, Ilan NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 514e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 515e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 516e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 517e705c121SKalle Valo 518e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 519e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 520e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 521e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 522e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 523e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 524e705c121SKalle Valo 525e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 526e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 527e705c121SKalle Valo hw->wiphy->features |= 528e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 529e705c121SKalle Valo 530e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 531e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 532e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 533e705c121SKalle Valo 534971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL, 5352a42aea7SNathan Errera IWL_FW_CMD_VER_UNKNOWN) == 3) 5362a42aea7SNathan Errera hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK; 5372a42aea7SNathan Errera 538aacf8f18SAvrahams Stern if (fw_has_api(&mvm->fw->ucode_capa, 539aacf8f18SAvrahams Stern IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 540aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 541aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SCAN_START_TIME); 542aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 543aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_BSS_PARENT_TSF); 544aacf8f18SAvrahams Stern } 545aacf8f18SAvrahams Stern 5468f691af9SZamir, Roee if (iwl_mvm_is_oce_supported(mvm)) { 547971cbe50SJohannes Berg u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0); 548773a042fSAvraham Stern 5498f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5508f691af9SZamir, Roee NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 5518f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5528f691af9SZamir, Roee NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 5538f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 5548f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 555773a042fSAvraham Stern 556773a042fSAvraham Stern /* Old firmware also supports probe deferral and suppression */ 557773a042fSAvraham Stern if (scan_ver < 15) 558773a042fSAvraham Stern wiphy_ext_feature_set(hw->wiphy, 559773a042fSAvraham Stern NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 5608f691af9SZamir, Roee } 5618f691af9SZamir, Roee 5627360f99eSEmmanuel Grumbach if (mvm->nvm_data->sku_cap_11ax_enable && 5637360f99eSEmmanuel Grumbach !iwlwifi_mod_params.disable_11ax) { 5647360f99eSEmmanuel Grumbach hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa; 5657360f99eSEmmanuel Grumbach hw->wiphy->num_iftype_ext_capab = 5667360f99eSEmmanuel Grumbach ARRAY_SIZE(he_iftypes_ext_capa); 567918cbf39SSara Sharon 568918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); 569918cbf39SSara Sharon ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID); 5707360f99eSEmmanuel Grumbach } 5717360f99eSEmmanuel Grumbach 572e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 573e705c121SKalle Valo 574e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 5753f37c229SIdo Yariv if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) && 576e705c121SKalle Valo mvm->trans->ops->d3_suspend && 577e705c121SKalle Valo mvm->trans->ops->d3_resume && 578e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 579e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 580e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 581e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 582e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 583e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 584e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 585e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 586e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 587e705c121SKalle Valo 588e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 589e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 590e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 5915d1234baSTova Mussai mvm->wowlan.max_nd_match_sets = 5925d1234baSTova Mussai iwl_umac_scan_get_max_profiles(mvm->fw); 593e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 594e705c121SKalle Valo } 595e705c121SKalle Valo #endif 596e705c121SKalle Valo 597e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 598e705c121SKalle Valo if (ret) 599e705c121SKalle Valo return ret; 600e705c121SKalle Valo 601e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 602e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 603e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 604e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 605e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 606e705c121SKalle Valo } 607e705c121SKalle Valo 608e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 609e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 610e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 611e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 612e705c121SKalle Valo } 613e705c121SKalle Valo 614e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 61559fa61f3SEmmanuel Grumbach if (!iwl_mvm_is_csum_supported(mvm)) 6166772aab7SJohannes Berg hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK; 61741837ca9SEmmanuel Grumbach 61891b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 61991b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 62091b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 62191b08c2dSAviya Erenfeld 6229c11d8a9SShaul Triebitz if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT)) 6239c11d8a9SShaul Triebitz wiphy_ext_feature_set(hw->wiphy, 6249c11d8a9SShaul Triebitz NL80211_EXT_FEATURE_PROTECTED_TWT); 6259c11d8a9SShaul Triebitz 626bfcfdb59SEmmanuel Grumbach iwl_mvm_vendor_cmds_register(mvm); 627bfcfdb59SEmmanuel Grumbach 628e8503aecSBen Greear hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm); 629e8503aecSBen Greear hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm); 630e8503aecSBen Greear 631de645e89SJohannes Berg ret = ieee80211_register_hw(mvm->hw); 632de645e89SJohannes Berg if (ret) { 633de645e89SJohannes Berg iwl_mvm_leds_exit(mvm); 634e705c121SKalle Valo } 635e705c121SKalle Valo 636e705c121SKalle Valo return ret; 637e705c121SKalle Valo } 638e705c121SKalle Valo 639df2378abSJohannes Berg static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 640df2378abSJohannes Berg struct ieee80211_sta *sta) 641df2378abSJohannes Berg { 642df2378abSJohannes Berg if (likely(sta)) { 643df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0)) 644df2378abSJohannes Berg return; 645df2378abSJohannes Berg } else { 646df2378abSJohannes Berg if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0)) 647df2378abSJohannes Berg return; 648df2378abSJohannes Berg } 649df2378abSJohannes Berg 650df2378abSJohannes Berg ieee80211_free_txskb(mvm->hw, skb); 651df2378abSJohannes Berg } 652df2378abSJohannes Berg 653e705c121SKalle Valo static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 654e705c121SKalle Valo struct ieee80211_tx_control *control, 655e705c121SKalle Valo struct sk_buff *skb) 656e705c121SKalle Valo { 657e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 658e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 659e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 660e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 661cfbc6c4cSSara Sharon bool offchannel = IEEE80211_SKB_CB(skb)->flags & 662cfbc6c4cSSara Sharon IEEE80211_TX_CTL_TX_OFFCHAN; 663e705c121SKalle Valo 664e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 665e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 666e705c121SKalle Valo goto drop; 667e705c121SKalle Valo } 668e705c121SKalle Valo 669cfbc6c4cSSara Sharon if (offchannel && 670e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 671e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 672e705c121SKalle Valo goto drop; 673e705c121SKalle Valo 67410516783SJohannes Berg /* 67510516783SJohannes Berg * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs 67610516783SJohannes Berg * so we treat the others as broadcast 67710516783SJohannes Berg */ 67810516783SJohannes Berg if (ieee80211_is_mgmt(hdr->frame_control)) 679e705c121SKalle Valo sta = NULL; 680e705c121SKalle Valo 681dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 682cfbc6c4cSSara Sharon if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION && 683cfbc6c4cSSara Sharon !offchannel) { 684dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 685dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 686dc1aca22SAndrei Otcheretianski u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id); 687dc1aca22SAndrei Otcheretianski 688be9ae34eSNathan Errera if (ap_sta_id < mvm->fw->ucode_capa.num_stations) { 689dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 690dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 691dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 692dc1aca22SAndrei Otcheretianski goto drop; 693dc1aca22SAndrei Otcheretianski } 694dc1aca22SAndrei Otcheretianski } 695dc1aca22SAndrei Otcheretianski 696df2378abSJohannes Berg iwl_mvm_tx_skb(mvm, skb, sta); 697e705c121SKalle Valo return; 698e705c121SKalle Valo drop: 699e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 700e705c121SKalle Valo } 701e705c121SKalle Valo 702cfbc6c4cSSara Sharon void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq) 703e705c121SKalle Valo { 704cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 705cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 706cfbc6c4cSSara Sharon struct sk_buff *skb = NULL; 707cfbc6c4cSSara Sharon 708fba8248eSSara Sharon /* 709fba8248eSSara Sharon * No need for threads to be pending here, they can leave the first 710fba8248eSSara Sharon * taker all the work. 711fba8248eSSara Sharon * 712fba8248eSSara Sharon * mvmtxq->tx_request logic: 713fba8248eSSara Sharon * 714fba8248eSSara Sharon * If 0, no one is currently TXing, set to 1 to indicate current thread 715fba8248eSSara Sharon * will now start TX and other threads should quit. 716fba8248eSSara Sharon * 717fba8248eSSara Sharon * If 1, another thread is currently TXing, set to 2 to indicate to 718fba8248eSSara Sharon * that thread that there was another request. Since that request may 719fba8248eSSara Sharon * have raced with the check whether the queue is empty, the TXing 720fba8248eSSara Sharon * thread should check the queue's status one more time before leaving. 721fba8248eSSara Sharon * This check is done in order to not leave any TX hanging in the queue 722fba8248eSSara Sharon * until the next TX invocation (which may not even happen). 723fba8248eSSara Sharon * 724fba8248eSSara Sharon * If 2, another thread is currently TXing, and it will already double 725fba8248eSSara Sharon * check the queue, so do nothing. 726fba8248eSSara Sharon */ 727fba8248eSSara Sharon if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) 728fba8248eSSara Sharon return; 729cfbc6c4cSSara Sharon 730cfbc6c4cSSara Sharon rcu_read_lock(); 731fba8248eSSara Sharon do { 732cfbc6c4cSSara Sharon while (likely(!mvmtxq->stopped && 73300520b7aSEmmanuel Grumbach !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) { 734cfbc6c4cSSara Sharon skb = ieee80211_tx_dequeue(hw, txq); 735cfbc6c4cSSara Sharon 736f50d693bSSara Sharon if (!skb) { 737f50d693bSSara Sharon if (txq->sta) 738f50d693bSSara Sharon IWL_DEBUG_TX(mvm, 739f50d693bSSara Sharon "TXQ of sta %pM tid %d is now empty\n", 740f50d693bSSara Sharon txq->sta->addr, 741f50d693bSSara Sharon txq->tid); 742cfbc6c4cSSara Sharon break; 743f50d693bSSara Sharon } 744cfbc6c4cSSara Sharon 745cfbc6c4cSSara Sharon iwl_mvm_tx_skb(mvm, skb, txq->sta); 746cfbc6c4cSSara Sharon } 747fba8248eSSara Sharon } while (atomic_dec_return(&mvmtxq->tx_request)); 748cfbc6c4cSSara Sharon rcu_read_unlock(); 749e705c121SKalle Valo } 750e705c121SKalle Valo 751cfbc6c4cSSara Sharon static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw, 752cfbc6c4cSSara Sharon struct ieee80211_txq *txq) 753e705c121SKalle Valo { 754cfbc6c4cSSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 755cfbc6c4cSSara Sharon struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq); 756e705c121SKalle Valo 757cfbc6c4cSSara Sharon /* 758cfbc6c4cSSara Sharon * Please note that racing is handled very carefully here: 759cfbc6c4cSSara Sharon * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is 760cfbc6c4cSSara Sharon * deleted afterwards. 761cfbc6c4cSSara Sharon * This means that if: 762cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list): 763cfbc6c4cSSara Sharon * queue is allocated and we can TX. 764cfbc6c4cSSara Sharon * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list): 765cfbc6c4cSSara Sharon * a race, should defer the frame. 766cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list): 767cfbc6c4cSSara Sharon * need to allocate the queue and defer the frame. 768cfbc6c4cSSara Sharon * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list): 769cfbc6c4cSSara Sharon * queue is already scheduled for allocation, no need to allocate, 770cfbc6c4cSSara Sharon * should defer the frame. 771cfbc6c4cSSara Sharon */ 772cfbc6c4cSSara Sharon 773cfbc6c4cSSara Sharon /* If the queue is allocated TX and return. */ 774cfbc6c4cSSara Sharon if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) { 775cfbc6c4cSSara Sharon /* 776cfbc6c4cSSara Sharon * Check that list is empty to avoid a race where txq_id is 777cfbc6c4cSSara Sharon * already updated, but the queue allocation work wasn't 778cfbc6c4cSSara Sharon * finished 779cfbc6c4cSSara Sharon */ 780cfbc6c4cSSara Sharon if (unlikely(txq->sta && !list_empty(&mvmtxq->list))) 781cfbc6c4cSSara Sharon return; 782cfbc6c4cSSara Sharon 783cfbc6c4cSSara Sharon iwl_mvm_mac_itxq_xmit(hw, txq); 784cfbc6c4cSSara Sharon return; 785cfbc6c4cSSara Sharon } 786cfbc6c4cSSara Sharon 787cfbc6c4cSSara Sharon /* The list is being deleted only after the queue is fully allocated. */ 788cfbc6c4cSSara Sharon if (!list_empty(&mvmtxq->list)) 789cfbc6c4cSSara Sharon return; 790cfbc6c4cSSara Sharon 791cfbc6c4cSSara Sharon list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs); 792cfbc6c4cSSara Sharon schedule_work(&mvm->add_stream_wk); 793e705c121SKalle Valo } 794e705c121SKalle Valo 795e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 796e705c121SKalle Valo do { \ 797e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 798e705c121SKalle Valo break; \ 7997174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 800e705c121SKalle Valo } while (0) 801e705c121SKalle Valo 802e705c121SKalle Valo static void 803e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 804e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 805e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 806e705c121SKalle Valo { 807e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 808e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 809e705c121SKalle Valo 8106c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 8116c042d75SSara Sharon FW_DBG_TRIGGER_BA); 8126c042d75SSara Sharon if (!trig) 813e705c121SKalle Valo return; 814e705c121SKalle Valo 815e705c121SKalle Valo ba_trig = (void *)trig->data; 816e705c121SKalle Valo 817e705c121SKalle Valo switch (action) { 818e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 819e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 820e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 821e705c121SKalle Valo 822e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 823e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 824e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 825e705c121SKalle Valo break; 826e705c121SKalle Valo } 827e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 828e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 829e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 830e705c121SKalle Valo sta->addr, tid); 831e705c121SKalle Valo break; 832e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 833e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 834e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 835e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 836e705c121SKalle Valo break; 837e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 838e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 839e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 840e705c121SKalle Valo sta->addr, tid); 841e705c121SKalle Valo break; 842e705c121SKalle Valo default: 843e705c121SKalle Valo break; 844e705c121SKalle Valo } 845e705c121SKalle Valo } 846e705c121SKalle Valo 847e705c121SKalle Valo static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 848e705c121SKalle Valo struct ieee80211_vif *vif, 84950ea05efSSara Sharon struct ieee80211_ampdu_params *params) 850e705c121SKalle Valo { 851e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 852e705c121SKalle Valo int ret; 85350ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 85450ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 85550ea05efSSara Sharon u16 tid = params->tid; 85650ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 857514c3069SLuca Coelho u16 buf_size = params->buf_size; 858bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 85910b2b201SSara Sharon u16 timeout = params->timeout; 860e705c121SKalle Valo 861e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 862e705c121SKalle Valo sta->addr, tid, action); 863e705c121SKalle Valo 864e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 865e705c121SKalle Valo return -EACCES; 866e705c121SKalle Valo 867e705c121SKalle Valo mutex_lock(&mvm->mutex); 868e705c121SKalle Valo 869e705c121SKalle Valo switch (action) { 870e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 871b0ffe455SJohannes Berg if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id == 872b0ffe455SJohannes Berg iwl_mvm_sta_from_mac80211(sta)->sta_id) { 873b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 874b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 875b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 876b0ffe455SJohannes Berg 877b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 878b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 879b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 880b0ffe455SJohannes Berg } 881e78da25eSJohannes Berg if (!iwl_enable_rx_ampdu()) { 882e705c121SKalle Valo ret = -EINVAL; 883e705c121SKalle Valo break; 884e705c121SKalle Valo } 88510b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 88610b2b201SSara Sharon timeout); 887e705c121SKalle Valo break; 888e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 88910b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 89010b2b201SSara Sharon timeout); 891e705c121SKalle Valo break; 892e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 893e78da25eSJohannes Berg if (!iwl_enable_tx_ampdu()) { 894e705c121SKalle Valo ret = -EINVAL; 895e705c121SKalle Valo break; 896e705c121SKalle Valo } 897e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 898e705c121SKalle Valo break; 899e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 900e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 901e705c121SKalle Valo break; 902e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 903e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 904e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 905e705c121SKalle Valo break; 906e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 907bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 908bb81bb68SEmmanuel Grumbach buf_size, amsdu); 909e705c121SKalle Valo break; 910e705c121SKalle Valo default: 911e705c121SKalle Valo WARN_ON_ONCE(1); 912e705c121SKalle Valo ret = -EINVAL; 913e705c121SKalle Valo break; 914e705c121SKalle Valo } 915e705c121SKalle Valo 916e705c121SKalle Valo if (!ret) { 917e705c121SKalle Valo u16 rx_ba_ssn = 0; 918e705c121SKalle Valo 919e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 920e705c121SKalle Valo rx_ba_ssn = *ssn; 921e705c121SKalle Valo 922e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 923e705c121SKalle Valo rx_ba_ssn, action); 924e705c121SKalle Valo } 925e705c121SKalle Valo mutex_unlock(&mvm->mutex); 926e705c121SKalle Valo 927e705c121SKalle Valo return ret; 928e705c121SKalle Valo } 929e705c121SKalle Valo 930e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 931e705c121SKalle Valo struct ieee80211_vif *vif) 932e705c121SKalle Valo { 933e705c121SKalle Valo struct iwl_mvm *mvm = data; 934e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 935e705c121SKalle Valo 936e705c121SKalle Valo mvmvif->uploaded = false; 9370ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 938e705c121SKalle Valo 939e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 940e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 941e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 942e705c121SKalle Valo 943e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 944e705c121SKalle Valo memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 94586e177d8SGregory Greenman memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data)); 946e705c121SKalle Valo } 947e705c121SKalle Valo 948e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 949e705c121SKalle Valo { 950fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 951e705c121SKalle Valo 9529bf13beeSJohannes Berg mvm->cur_aid = 0; 9539bf13beeSJohannes Berg 954e705c121SKalle Valo mvm->scan_status = 0; 955e705c121SKalle Valo mvm->ps_disabled = false; 956b3500b47SEmmanuel Grumbach mvm->rfkill_safe_init_done = false; 957e705c121SKalle Valo 958e705c121SKalle Valo /* just in case one was running */ 959305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 960e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 961e705c121SKalle Valo 962fc36ffdaSJohannes Berg iwl_mvm_ftm_restart(mvm); 963fc36ffdaSJohannes Berg 964e705c121SKalle Valo /* 965e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 966e705c121SKalle Valo * gone down during the HW restart 967e705c121SKalle Valo */ 968e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 969e705c121SKalle Valo 970e705c121SKalle Valo mvm->p2p_device_vif = NULL; 971e705c121SKalle Valo 972e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 9739c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 974e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 975e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 976e705c121SKalle Valo 977e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 978e705c121SKalle Valo 979e705c121SKalle Valo mvm->rx_ba_sessions = 0; 9807174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 981baf41bc3SShaul Triebitz mvm->monitor_on = false; 982e705c121SKalle Valo 983e705c121SKalle Valo /* keep statistics ticking */ 984e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 985e705c121SKalle Valo } 986e705c121SKalle Valo 987e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 988e705c121SKalle Valo { 989e705c121SKalle Valo int ret; 990e705c121SKalle Valo 991e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 992e705c121SKalle Valo 9936d19a5ebSEmmanuel Grumbach ret = iwl_mvm_mei_get_ownership(mvm); 9946d19a5ebSEmmanuel Grumbach if (ret) 9956d19a5ebSEmmanuel Grumbach return ret; 9966d19a5ebSEmmanuel Grumbach 9976d19a5ebSEmmanuel Grumbach if (mvm->mei_nvm_data) { 9986d19a5ebSEmmanuel Grumbach /* We got the NIC, we can now free the MEI NVM data */ 9996d19a5ebSEmmanuel Grumbach kfree(mvm->mei_nvm_data); 10006d19a5ebSEmmanuel Grumbach mvm->mei_nvm_data = NULL; 10016d19a5ebSEmmanuel Grumbach 10026d19a5ebSEmmanuel Grumbach /* 10036d19a5ebSEmmanuel Grumbach * We can't free the nvm_data we allocated based on the SAP 10046d19a5ebSEmmanuel Grumbach * data because we registered to cfg80211 with the channels 10056d19a5ebSEmmanuel Grumbach * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data 10066d19a5ebSEmmanuel Grumbach * just in order to be able free it later. 10076d19a5ebSEmmanuel Grumbach * NULLify nvm_data so that we will read the NVM from the 10086d19a5ebSEmmanuel Grumbach * firmware this time. 10096d19a5ebSEmmanuel Grumbach */ 10106d19a5ebSEmmanuel Grumbach mvm->temp_nvm_data = mvm->nvm_data; 10116d19a5ebSEmmanuel Grumbach mvm->nvm_data = NULL; 10126d19a5ebSEmmanuel Grumbach } 10136d19a5ebSEmmanuel Grumbach 1014bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1015bf8b286fSJohannes Berg /* 1016bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1017bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1018bf8b286fSJohannes Berg */ 1019bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1020bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1021e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1022e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1023a42b2af3SLuca Coelho } 1024e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1025e705c121SKalle Valo 1026b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT, 1027b108d8c7SShahar S Matityahu NULL); 1028b108d8c7SShahar S Matityahu iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC, 1029b108d8c7SShahar S Matityahu NULL); 1030da2eb669SSara Sharon 1031e8fe3b41SIlan Peer mvm->last_reset_or_resume_time_jiffies = jiffies; 1032e8fe3b41SIlan Peer 1033e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1034e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1035e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1036e705c121SKalle Valo * would do. 1037e705c121SKalle Valo */ 1038e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1039e705c121SKalle Valo } 1040e705c121SKalle Valo 1041e705c121SKalle Valo return ret; 1042e705c121SKalle Valo } 1043e705c121SKalle Valo 1044e705c121SKalle Valo static int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1045e705c121SKalle Valo { 1046e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1047e705c121SKalle Valo int ret; 10485283dd67SMordechay Goodstein int retry, max_retry = 0; 1049e705c121SKalle Valo 1050e705c121SKalle Valo mutex_lock(&mvm->mutex); 10515283dd67SMordechay Goodstein 10525283dd67SMordechay Goodstein /* we are starting the mac not in error flow, and restart is enabled */ 10535283dd67SMordechay Goodstein if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) && 10545283dd67SMordechay Goodstein iwlwifi_mod_params.fw_restart) { 10555283dd67SMordechay Goodstein max_retry = IWL_MAX_INIT_RETRY; 10565283dd67SMordechay Goodstein /* 10575283dd67SMordechay Goodstein * This will prevent mac80211 recovery flows to trigger during 10585283dd67SMordechay Goodstein * init failures 10595283dd67SMordechay Goodstein */ 10605283dd67SMordechay Goodstein set_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 10615283dd67SMordechay Goodstein } 10625283dd67SMordechay Goodstein 10635283dd67SMordechay Goodstein for (retry = 0; retry <= max_retry; retry++) { 1064e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 10655283dd67SMordechay Goodstein if (!ret) 10665283dd67SMordechay Goodstein break; 10675283dd67SMordechay Goodstein 10685283dd67SMordechay Goodstein IWL_ERR(mvm, "mac start retry %d\n", retry); 10695283dd67SMordechay Goodstein } 10705283dd67SMordechay Goodstein clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status); 10715283dd67SMordechay Goodstein 1072e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1073e705c121SKalle Valo 10747ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 10757ce1f215SEmmanuel Grumbach 1076e705c121SKalle Valo return ret; 1077e705c121SKalle Valo } 1078e705c121SKalle Valo 1079e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1080e705c121SKalle Valo { 1081e705c121SKalle Valo int ret; 1082e705c121SKalle Valo 1083e705c121SKalle Valo mutex_lock(&mvm->mutex); 1084e705c121SKalle Valo 1085e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 10864d4183c4SEmmanuel Grumbach 1087e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1088e705c121SKalle Valo if (ret) 1089e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1090e705c121SKalle Valo ret); 1091e705c121SKalle Valo 1092f130bb75SMordechay Goodstein iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY); 1093f130bb75SMordechay Goodstein 1094e705c121SKalle Valo /* 1095e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1096e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1097e705c121SKalle Valo */ 1098e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1099e705c121SKalle Valo 1100e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1101e705c121SKalle Valo } 1102e705c121SKalle Valo 1103e705c121SKalle Valo static void 1104e705c121SKalle Valo iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1105e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1106e705c121SKalle Valo { 1107e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1108e705c121SKalle Valo 1109e705c121SKalle Valo switch (reconfig_type) { 1110e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1111e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1112e705c121SKalle Valo break; 1113e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1114e705c121SKalle Valo break; 1115e705c121SKalle Valo } 1116e705c121SKalle Valo } 1117e705c121SKalle Valo 1118e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1119e705c121SKalle Valo { 1120e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1121e705c121SKalle Valo 1122b68bd2e3SIlan Peer iwl_mvm_ftm_initiator_smooth_stop(mvm); 1123b68bd2e3SIlan Peer 1124e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1125e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1126e705c121SKalle Valo */ 1127e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1128e705c121SKalle Valo 1129e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1130e705c121SKalle Valo 1131971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12) 1132f327236dSSharon iwl_mvm_rm_aux_sta(mvm); 1133f327236dSSharon 1134fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1135e705c121SKalle Valo 1136e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1137e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1138e705c121SKalle Valo 1139e705c121SKalle Valo /* 1140155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1141155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1142155f7e04SEmmanuel Grumbach * won't execute the restart. 1143e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1144e705c121SKalle Valo * HW restart was requested. 1145e705c121SKalle Valo */ 1146155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1147155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1148155f7e04SEmmanuel Grumbach &mvm->status)) 1149e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1150e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1151e705c121SKalle Valo 1152e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1153e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1154e705c121SKalle Valo */ 1155e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1156e705c121SKalle Valo int i; 1157e705c121SKalle Valo 1158e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1159e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1160e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1161e705c121SKalle Valo i)) 1162e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1163e705c121SKalle Valo } 1164e705c121SKalle Valo } 1165e705c121SKalle Valo } 1166e705c121SKalle Valo 1167e705c121SKalle Valo static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1168e705c121SKalle Valo { 1169e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1170e705c121SKalle Valo 1171e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 117224afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1173771147b0SJohannes Berg 1174771147b0SJohannes Berg /* 1175771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1176771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1177771147b0SJohannes Berg * be able to proceed. This is important here because one of those 11787174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1179771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1180771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1181771147b0SJohannes Berg */ 1182771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1183771147b0SJohannes Berg 1184d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 118569e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 1186e705c121SKalle Valo 1187f9084775SNathan Errera /* 1188f9084775SNathan Errera * The work item could be running or queued if the 1189f9084775SNathan Errera * ROC time event stops just as we get here. 1190f9084775SNathan Errera */ 1191f9084775SNathan Errera flush_work(&mvm->roc_done_wk); 1192f9084775SNathan Errera 11937ce1f215SEmmanuel Grumbach iwl_mvm_mei_set_sw_rfkill_state(mvm); 11947ce1f215SEmmanuel Grumbach 1195e705c121SKalle Valo mutex_lock(&mvm->mutex); 1196e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1197e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1198e705c121SKalle Valo 1199e705c121SKalle Valo /* 1200e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1201e705c121SKalle Valo * discover that its list is now empty. 1202e705c121SKalle Valo */ 1203e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1204e705c121SKalle Valo } 1205e705c121SKalle Valo 1206e705c121SKalle Valo static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1207e705c121SKalle Valo { 1208e705c121SKalle Valo u16 i; 1209e705c121SKalle Valo 1210e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1211e705c121SKalle Valo 1212e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1213e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1214e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1215e705c121SKalle Valo 1216e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1217e705c121SKalle Valo return NULL; 1218e705c121SKalle Valo } 1219e705c121SKalle Valo 1220e705c121SKalle Valo static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1221e705c121SKalle Valo s16 tx_power) 1222e705c121SKalle Valo { 1223971cbe50SJohannes Berg u32 cmd_id = REDUCE_TX_POWER_CMD; 12240791c2fcSHaim Dreyfuss int len; 1225216cdfb5SLuca Coelho struct iwl_dev_tx_power_cmd cmd = { 1226216cdfb5SLuca Coelho .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1227216cdfb5SLuca Coelho .common.mac_context_id = 1228e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1229216cdfb5SLuca Coelho .common.pwr_restriction = cpu_to_le16(8 * tx_power), 1230e705c121SKalle Valo }; 1231971cbe50SJohannes Berg u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 1232e80bfd11SMordechay Goodstein IWL_FW_CMD_VER_UNKNOWN); 1233e705c121SKalle Valo 1234e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1235216cdfb5SLuca Coelho cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1236e705c121SKalle Valo 1237b0aa02b3SAyala Barazani if (cmd_ver == 7) 1238b0aa02b3SAyala Barazani len = sizeof(cmd.v7); 1239b0aa02b3SAyala Barazani else if (cmd_ver == 6) 1240fbb7957dSLuca Coelho len = sizeof(cmd.v6); 1241fbb7957dSLuca Coelho else if (fw_has_api(&mvm->fw->ucode_capa, 12420791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 12430791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 12440791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 12450791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 12460791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 12470791c2fcSHaim Dreyfuss else 1248216cdfb5SLuca Coelho len = sizeof(cmd.v3); 1249216cdfb5SLuca Coelho 1250216cdfb5SLuca Coelho /* all structs have the same common part, add it */ 1251216cdfb5SLuca Coelho len += sizeof(cmd.common); 1252e705c121SKalle Valo 1253971cbe50SJohannes Berg return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd); 1254e705c121SKalle Valo } 1255e705c121SKalle Valo 1256f6780614SSara Sharon static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 1257f6780614SSara Sharon struct ieee80211_vif *vif) 1258f6780614SSara Sharon { 1259f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1260f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1261f6780614SSara Sharon int ret; 1262f6780614SSara Sharon 1263f6780614SSara Sharon mutex_lock(&mvm->mutex); 1264f6780614SSara Sharon 1265f6780614SSara Sharon if (vif->type == NL80211_IFTYPE_STATION) { 1266f6780614SSara Sharon struct iwl_mvm_sta *mvmsta; 1267f6780614SSara Sharon 1268f6780614SSara Sharon mvmvif->csa_bcn_pending = false; 1269f6780614SSara Sharon mvmsta = iwl_mvm_sta_from_staid_protected(mvm, 1270f6780614SSara Sharon mvmvif->ap_sta_id); 1271f6780614SSara Sharon 1272f6780614SSara Sharon if (WARN_ON(!mvmsta)) { 1273f6780614SSara Sharon ret = -EIO; 1274f6780614SSara Sharon goto out_unlock; 1275f6780614SSara Sharon } 1276f6780614SSara Sharon 1277f6780614SSara Sharon iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 1278f6780614SSara Sharon 1279f6780614SSara Sharon iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1280f6780614SSara Sharon 12810202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 12820202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 1283f6780614SSara Sharon ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 1284f6780614SSara Sharon if (ret) 1285f6780614SSara Sharon goto out_unlock; 1286f6780614SSara Sharon 1287f6780614SSara Sharon iwl_mvm_stop_session_protection(mvm, vif); 1288f6780614SSara Sharon } 12890202bcf0SEmmanuel Grumbach } 1290f6780614SSara Sharon 1291f6780614SSara Sharon mvmvif->ps_disabled = false; 1292f6780614SSara Sharon 1293f6780614SSara Sharon ret = iwl_mvm_power_update_ps(mvm); 1294f6780614SSara Sharon 1295f6780614SSara Sharon out_unlock: 1296caf46377SSara Sharon if (mvmvif->csa_failed) 1297caf46377SSara Sharon ret = -EIO; 1298f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1299f6780614SSara Sharon 1300f6780614SSara Sharon return ret; 1301f6780614SSara Sharon } 1302f6780614SSara Sharon 1303f6780614SSara Sharon static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw, 1304f6780614SSara Sharon struct ieee80211_vif *vif) 1305f6780614SSara Sharon { 1306f6780614SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1307f6780614SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1308f6780614SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 1309f6780614SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 1310f6780614SSara Sharon mvmvif->color)), 1311f6780614SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE), 1312f6780614SSara Sharon }; 1313f6780614SSara Sharon 1314ad12b231SNathan Errera /* 1315ad12b231SNathan Errera * In the new flow since FW is in charge of the timing, 1316ad12b231SNathan Errera * if driver has canceled the channel switch he will receive the 1317ad12b231SNathan Errera * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it 1318ad12b231SNathan Errera */ 1319ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 1320ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 1321ad12b231SNathan Errera return; 1322ad12b231SNathan Errera 1323f6780614SSara Sharon IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id); 1324f6780614SSara Sharon 1325f6780614SSara Sharon mutex_lock(&mvm->mutex); 132658ddd9b6SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 132758ddd9b6SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 132858ddd9b6SEmmanuel Grumbach iwl_mvm_remove_csa_period(mvm, vif); 132958ddd9b6SEmmanuel Grumbach else 1330f6780614SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 1331f6780614SSara Sharon WIDE_ID(MAC_CONF_GROUP, 1332f6780614SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 1333f6780614SSara Sharon 0, sizeof(cmd), &cmd)); 1334caf46377SSara Sharon mvmvif->csa_failed = true; 1335f6780614SSara Sharon mutex_unlock(&mvm->mutex); 1336f6780614SSara Sharon 1337caf46377SSara Sharon iwl_mvm_post_channel_switch(hw, vif); 1338f6780614SSara Sharon } 1339f6780614SSara Sharon 1340f6780614SSara Sharon static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk) 1341f6780614SSara Sharon { 1342f6780614SSara Sharon struct iwl_mvm_vif *mvmvif; 1343f6780614SSara Sharon struct ieee80211_vif *vif; 1344f6780614SSara Sharon 1345f6780614SSara Sharon mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work); 1346f6780614SSara Sharon vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv); 1347f6780614SSara Sharon 134870162580SShaul Triebitz /* Trigger disconnect (should clear the CSA state) */ 1349f6780614SSara Sharon ieee80211_chswitch_done(vif, false); 1350f6780614SSara Sharon } 1351f6780614SSara Sharon 1352e705c121SKalle Valo static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1353e705c121SKalle Valo struct ieee80211_vif *vif) 1354e705c121SKalle Valo { 1355e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1356e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1357e705c121SKalle Valo int ret; 1358e705c121SKalle Valo 1359e705c121SKalle Valo mvmvif->mvm = mvm; 136086e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 1361e705c121SKalle Valo 1362e705c121SKalle Valo /* 1363e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1364e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1365e705c121SKalle Valo * don't really have to check the types. 1366e705c121SKalle Valo */ 1367e705c121SKalle Valo 1368e705c121SKalle Valo mutex_lock(&mvm->mutex); 1369e705c121SKalle Valo 1370e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1371e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1372e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons += 1373e705c121SKalle Valo mvmvif->beacon_stats.num_beacons; 1374e705c121SKalle Valo 1375e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 1376e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_init(mvm, vif); 1377e705c121SKalle Valo if (ret) 1378e705c121SKalle Valo goto out_unlock; 1379e705c121SKalle Valo 1380698478c4SSara Sharon rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif); 1381698478c4SSara Sharon 1382e705c121SKalle Valo /* 1383e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1384e705c121SKalle Valo * template is configured (which happens only in the mac80211 1385e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1386e705c121SKalle Valo * only after the binding. 1387e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1388e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1389e705c121SKalle Valo * the point where we can also add the bcast station. 1390e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1391e705c121SKalle Valo * allocating resources :) 1392e705c121SKalle Valo */ 1393e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1394e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1395e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1396e705c121SKalle Valo if (ret) { 1397e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 139898c0de7bSMiri Korenblit goto out_unlock; 1399e705c121SKalle Valo } 1400e705c121SKalle Valo 140126d6c16bSSara Sharon /* 140226d6c16bSSara Sharon * Only queue for this station is the mcast queue, 140326d6c16bSSara Sharon * which shouldn't be in TFD mask anyway 140426d6c16bSSara Sharon */ 140526d6c16bSSara Sharon ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta, 1406ced19f26SSara Sharon 0, vif->type, 1407ced19f26SSara Sharon IWL_STA_MULTICAST); 140826d6c16bSSara Sharon if (ret) 140998c0de7bSMiri Korenblit goto out_unlock; 141026d6c16bSSara Sharon 1411e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1412e705c121SKalle Valo goto out_unlock; 1413e705c121SKalle Valo } 1414e705c121SKalle Valo 1415e705c121SKalle Valo mvmvif->features |= hw->netdev_features; 1416e705c121SKalle Valo 1417e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1418e705c121SKalle Valo if (ret) 141998c0de7bSMiri Korenblit goto out_unlock; 1420e705c121SKalle Valo 1421e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1422e705c121SKalle Valo if (ret) 1423e705c121SKalle Valo goto out_remove_mac; 1424e705c121SKalle Valo 1425e705c121SKalle Valo /* beacon filtering */ 1426e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 1427e705c121SKalle Valo if (ret) 1428e705c121SKalle Valo goto out_remove_mac; 1429e705c121SKalle Valo 1430e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1431e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1432e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1433e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1434e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1435e705c121SKalle Valo } 1436e705c121SKalle Valo 1437e705c121SKalle Valo /* 1438e705c121SKalle Valo * P2P_DEVICE interface does not have a channel context assigned to it, 1439e705c121SKalle Valo * so a dedicated PHY context is allocated to it and the corresponding 1440e705c121SKalle Valo * MAC context is bound to it at this stage. 1441e705c121SKalle Valo */ 1442e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1443e705c121SKalle Valo 1444e705c121SKalle Valo mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 1445e705c121SKalle Valo if (!mvmvif->phy_ctxt) { 1446e705c121SKalle Valo ret = -ENOSPC; 1447e705c121SKalle Valo goto out_free_bf; 1448e705c121SKalle Valo } 1449e705c121SKalle Valo 1450e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 1451e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 1452e705c121SKalle Valo if (ret) 1453e705c121SKalle Valo goto out_unref_phy; 1454e705c121SKalle Valo 1455d197358bSLuca Coelho ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); 1456e705c121SKalle Valo if (ret) 1457e705c121SKalle Valo goto out_unbind; 1458e705c121SKalle Valo 1459e705c121SKalle Valo /* Save a pointer to p2p device vif, so it can later be used to 1460e705c121SKalle Valo * update the p2p device MAC when a GO is started/stopped */ 1461e705c121SKalle Valo mvm->p2p_device_vif = vif; 1462e705c121SKalle Valo } 1463e705c121SKalle Valo 1464b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1465f6780614SSara Sharon INIT_DELAYED_WORK(&mvmvif->csa_work, 1466f6780614SSara Sharon iwl_mvm_channel_switch_disconnect_wk); 1467b0ffe455SJohannes Berg 1468baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1469baf41bc3SShaul Triebitz mvm->monitor_on = true; 1470baf41bc3SShaul Triebitz 1471e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 14726d19a5ebSEmmanuel Grumbach 14736d19a5ebSEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 14746d19a5ebSEmmanuel Grumbach vif->type == NL80211_IFTYPE_STATION && !vif->p2p && 14756d19a5ebSEmmanuel Grumbach !mvm->csme_vif && mvm->mei_registered) { 14766d19a5ebSEmmanuel Grumbach iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr); 14776d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev); 14786d19a5ebSEmmanuel Grumbach mvm->csme_vif = vif; 14796d19a5ebSEmmanuel Grumbach } 14806d19a5ebSEmmanuel Grumbach 1481e705c121SKalle Valo goto out_unlock; 1482e705c121SKalle Valo 1483e705c121SKalle Valo out_unbind: 1484e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1485e705c121SKalle Valo out_unref_phy: 1486e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1487e705c121SKalle Valo out_free_bf: 1488e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1489e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1490e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1491e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1492e705c121SKalle Valo } 1493e705c121SKalle Valo out_remove_mac: 1494e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1495e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1496e705c121SKalle Valo out_unlock: 1497e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1498e705c121SKalle Valo 1499e705c121SKalle Valo return ret; 1500e705c121SKalle Valo } 1501e705c121SKalle Valo 1502e705c121SKalle Valo static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1503e705c121SKalle Valo struct ieee80211_vif *vif) 1504e705c121SKalle Valo { 1505e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1506e705c121SKalle Valo /* 1507e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1508e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1509e705c121SKalle Valo * queue are sent in ROC session. 1510e705c121SKalle Valo */ 1511e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1512e705c121SKalle Valo } 1513e705c121SKalle Valo } 1514e705c121SKalle Valo 1515e705c121SKalle Valo static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 1516e705c121SKalle Valo struct ieee80211_vif *vif) 1517e705c121SKalle Valo { 1518e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1519e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 152086e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1521e705c121SKalle Valo 1522e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1523e705c121SKalle Valo 1524b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1525b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1526b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1527b0ffe455SJohannes Berg 1528e705c121SKalle Valo mutex_lock(&mvm->mutex); 1529e705c121SKalle Valo 15306d19a5ebSEmmanuel Grumbach if (vif == mvm->csme_vif) { 15316d19a5ebSEmmanuel Grumbach iwl_mei_set_netdev(NULL); 15326d19a5ebSEmmanuel Grumbach mvm->csme_vif = NULL; 15336d19a5ebSEmmanuel Grumbach } 15346d19a5ebSEmmanuel Grumbach 153586e177d8SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->probe_resp_data, 153686e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 153786e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 153886e177d8SGregory Greenman if (probe_data) 153986e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 154086e177d8SGregory Greenman 1541e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1542e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1543e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1544e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1545e705c121SKalle Valo } 1546e705c121SKalle Valo 1547b73f9a4aSJohannes Berg if (vif->bss_conf.ftm_responder) 1548b73f9a4aSJohannes Berg memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats)); 1549b73f9a4aSJohannes Berg 1550e705c121SKalle Valo iwl_mvm_vif_dbgfs_clean(mvm, vif); 1551e705c121SKalle Valo 1552e705c121SKalle Valo /* 1553e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1554e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1555e705c121SKalle Valo */ 1556e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1557e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1558e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1559e705c121SKalle Valo if (vif == mvm->noa_vif) { 1560e705c121SKalle Valo mvm->noa_vif = NULL; 1561e705c121SKalle Valo mvm->noa_duration = 0; 1562e705c121SKalle Valo } 1563e705c121SKalle Valo #endif 156426d6c16bSSara Sharon iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta); 1565e705c121SKalle Valo iwl_mvm_dealloc_bcast_sta(mvm, vif); 1566e705c121SKalle Valo goto out_release; 1567e705c121SKalle Valo } 1568e705c121SKalle Valo 1569e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1570e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1571d197358bSLuca Coelho iwl_mvm_rm_p2p_bcast_sta(mvm, vif); 1572e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1573e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1574e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1575e705c121SKalle Valo } 1576e705c121SKalle Valo 1577e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 1578e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1579e705c121SKalle Valo 1580698478c4SSara Sharon RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL); 1581698478c4SSara Sharon 1582baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1583baf41bc3SShaul Triebitz mvm->monitor_on = false; 1584baf41bc3SShaul Triebitz 1585e705c121SKalle Valo out_release: 1586e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1587e705c121SKalle Valo } 1588e705c121SKalle Valo 1589e705c121SKalle Valo static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) 1590e705c121SKalle Valo { 1591e705c121SKalle Valo return 0; 1592e705c121SKalle Valo } 1593e705c121SKalle Valo 1594e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1595e705c121SKalle Valo struct iwl_mvm *mvm; 1596e705c121SKalle Valo int port_id; 1597e705c121SKalle Valo }; 1598e705c121SKalle Valo 1599e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1600e705c121SKalle Valo struct ieee80211_vif *vif) 1601e705c121SKalle Valo { 1602e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1603e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1604e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 160597bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 160697bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 160797bce57bSLuca Coelho .flags = CMD_ASYNC, 160897bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 160997bce57bSLuca Coelho }; 1610e705c121SKalle Valo int ret, len; 1611e705c121SKalle Valo 1612e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1613e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1614e705c121SKalle Valo return; 1615e705c121SKalle Valo 1616e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1617f276e20bSJohannes Berg !vif->cfg.assoc) 1618e705c121SKalle Valo return; 1619e705c121SKalle Valo 1620e705c121SKalle Valo cmd->port_id = data->port_id++; 1621e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1622e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1623e705c121SKalle Valo 162497bce57bSLuca Coelho hcmd.len[0] = len; 162597bce57bSLuca Coelho hcmd.data[0] = cmd; 162697bce57bSLuca Coelho 162797bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1628e705c121SKalle Valo if (ret) 1629e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1630e705c121SKalle Valo } 1631e705c121SKalle Valo 1632e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1633e705c121SKalle Valo { 1634e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1635e705c121SKalle Valo .mvm = mvm, 1636e705c121SKalle Valo }; 1637db66abeeSJohannes Berg int ret; 1638e705c121SKalle Valo 1639e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1640e705c121SKalle Valo 1641e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1642e705c121SKalle Valo return; 1643e705c121SKalle Valo 1644e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1645e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1646e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1647db66abeeSJohannes Berg 1648db66abeeSJohannes Berg /* 1649db66abeeSJohannes Berg * Send a (synchronous) ech command so that we wait for the 1650db66abeeSJohannes Berg * multiple asynchronous MCAST_FILTER_CMD commands sent by 1651db66abeeSJohannes Berg * the interface iterator. Otherwise, we might get here over 1652db66abeeSJohannes Berg * and over again (by userspace just sending a lot of these) 1653db66abeeSJohannes Berg * and the CPU can send them faster than the firmware can 1654db66abeeSJohannes Berg * process them. 1655db66abeeSJohannes Berg * Note that the CPU is still faster - but with this we'll 1656db66abeeSJohannes Berg * actually send fewer commands overall because the CPU will 1657db66abeeSJohannes Berg * not schedule the work in mac80211 as frequently if it's 1658db66abeeSJohannes Berg * still running when rescheduled (possibly multiple times). 1659db66abeeSJohannes Berg */ 1660db66abeeSJohannes Berg ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); 1661db66abeeSJohannes Berg if (ret) 1662db66abeeSJohannes Berg IWL_ERR(mvm, "Failed to synchronize multicast groups update\n"); 1663e705c121SKalle Valo } 1664e705c121SKalle Valo 1665e705c121SKalle Valo static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1666e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1667e705c121SKalle Valo { 1668e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1669e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1670e705c121SKalle Valo struct netdev_hw_addr *addr; 1671e705c121SKalle Valo int addr_count; 1672e705c121SKalle Valo bool pass_all; 1673e705c121SKalle Valo int len; 1674e705c121SKalle Valo 1675e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1676e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1677e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1678e705c121SKalle Valo if (pass_all) 1679e705c121SKalle Valo addr_count = 0; 1680e705c121SKalle Valo 1681e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1682e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1683e705c121SKalle Valo if (!cmd) 1684e705c121SKalle Valo return 0; 1685e705c121SKalle Valo 1686e705c121SKalle Valo if (pass_all) { 1687e705c121SKalle Valo cmd->pass_all = 1; 1688e705c121SKalle Valo return (u64)(unsigned long)cmd; 1689e705c121SKalle Valo } 1690e705c121SKalle Valo 1691e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1692e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1693e705c121SKalle Valo cmd->count, addr->addr); 1694e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1695e705c121SKalle Valo addr->addr, ETH_ALEN); 1696e705c121SKalle Valo cmd->count++; 1697e705c121SKalle Valo } 1698e705c121SKalle Valo 1699e705c121SKalle Valo return (u64)(unsigned long)cmd; 1700e705c121SKalle Valo } 1701e705c121SKalle Valo 1702e705c121SKalle Valo static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1703e705c121SKalle Valo unsigned int changed_flags, 1704e705c121SKalle Valo unsigned int *total_flags, 1705e705c121SKalle Valo u64 multicast) 1706e705c121SKalle Valo { 1707e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1708e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1709e705c121SKalle Valo 1710e705c121SKalle Valo mutex_lock(&mvm->mutex); 1711e705c121SKalle Valo 1712e705c121SKalle Valo /* replace previous configuration */ 1713e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1714e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1715e705c121SKalle Valo 1716e705c121SKalle Valo if (!cmd) 1717e705c121SKalle Valo goto out; 1718e705c121SKalle Valo 171961e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 172061e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 172161e7d91bSLuca Coelho 172261e7d91bSLuca Coelho if (cmd->pass_all) 172361e7d91bSLuca Coelho cmd->count = 0; 172461e7d91bSLuca Coelho 1725e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1726e705c121SKalle Valo out: 1727e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1728e705c121SKalle Valo *total_flags = 0; 1729e705c121SKalle Valo } 1730e705c121SKalle Valo 1731e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1732e705c121SKalle Valo struct ieee80211_vif *vif, 1733e705c121SKalle Valo unsigned int filter_flags, 1734e705c121SKalle Valo unsigned int changed_flags) 1735e705c121SKalle Valo { 1736e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1737e705c121SKalle Valo 1738e705c121SKalle Valo /* We support only filter for probe requests */ 1739e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1740e705c121SKalle Valo return; 1741e705c121SKalle Valo 1742e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1743f276e20bSJohannes Berg if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc || 1744e705c121SKalle Valo !vif->p2p) 1745e705c121SKalle Valo return; 1746e705c121SKalle Valo 1747e705c121SKalle Valo mutex_lock(&mvm->mutex); 1748e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1749e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1750e705c121SKalle Valo } 1751e705c121SKalle Valo 1752a07a8f37SSara Sharon static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, 1753a07a8f37SSara Sharon struct ieee80211_vif *vif) 1754a07a8f37SSara Sharon { 1755a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1756a07a8f37SSara Sharon 1757a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 1758a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 1759a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 1760a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 1761a07a8f37SSara Sharon 1762a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 1763a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 1764a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 1765a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 1766a07a8f37SSara Sharon } 1767a07a8f37SSara Sharon 1768f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 1769f92659a1SSara Sharon struct ieee80211_vif *vif) 1770f92659a1SSara Sharon { 1771d0a9123eSJohannes Berg if (vif->bss_conf.mu_mimo_owner) { 1772f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 1773f92659a1SSara Sharon 1774f92659a1SSara Sharon /* 1775f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 1776f92659a1SSara Sharon * the data received from firmware as if it came from the 1777f92659a1SSara Sharon * action frame, so no conversion is needed. 1778f92659a1SSara Sharon */ 1779afe0d181SJohannes Berg ieee80211_update_mu_groups(vif, 0, 1780f92659a1SSara Sharon (u8 *)¬if->membership_status, 1781f92659a1SSara Sharon (u8 *)¬if->user_position); 1782f92659a1SSara Sharon } 1783f92659a1SSara Sharon } 1784f92659a1SSara Sharon 1785f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 1786f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 1787f92659a1SSara Sharon { 1788f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 1789f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 1790f92659a1SSara Sharon 1791f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 1792f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1793f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 1794f92659a1SSara Sharon } 1795f92659a1SSara Sharon 1796514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 1797514c3069SLuca Coelho { 1798514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 1799514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 1800514c3069SLuca Coelho u8 residue_bits; 1801514c3069SLuca Coelho u8 res; 1802514c3069SLuca Coelho 1803514c3069SLuca Coelho if (bit_num <= 5) 1804514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 1805514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 1806514c3069SLuca Coelho 1807514c3069SLuca Coelho /* 1808514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 1809514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 1810514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 1811514c3069SLuca Coelho */ 1812514c3069SLuca Coelho 1813514c3069SLuca Coelho residue_bits = 8 - bit_num; 1814514c3069SLuca Coelho 1815514c3069SLuca Coelho res = (ppe[byte_num + 1] & 1816514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 1817514c3069SLuca Coelho residue_bits; 1818514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 1819514c3069SLuca Coelho 1820514c3069SLuca Coelho return res; 1821514c3069SLuca Coelho } 1822514c3069SLuca Coelho 1823091296d3SMiri Korenblit static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm, 1824091296d3SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, 1825091296d3SMiri Korenblit u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit) 1826091296d3SMiri Korenblit { 1827091296d3SMiri Korenblit int i; 1828091296d3SMiri Korenblit 1829091296d3SMiri Korenblit /* 1830091296d3SMiri Korenblit * FW currently supports only nss == MAX_HE_SUPP_NSS 1831091296d3SMiri Korenblit * 1832091296d3SMiri Korenblit * If nss > MAX: we can ignore values we don't support 1833091296d3SMiri Korenblit * If nss < MAX: we can set zeros in other streams 1834091296d3SMiri Korenblit */ 1835091296d3SMiri Korenblit if (nss > MAX_HE_SUPP_NSS) { 1836091296d3SMiri Korenblit IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 1837091296d3SMiri Korenblit MAX_HE_SUPP_NSS); 1838091296d3SMiri Korenblit nss = MAX_HE_SUPP_NSS; 1839091296d3SMiri Korenblit } 1840091296d3SMiri Korenblit 1841091296d3SMiri Korenblit for (i = 0; i < nss; i++) { 1842091296d3SMiri Korenblit u8 ru_index_tmp = ru_index_bitmap << 1; 1843091296d3SMiri Korenblit u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE; 1844091296d3SMiri Korenblit u8 bw; 1845091296d3SMiri Korenblit 1846091296d3SMiri Korenblit for (bw = 0; 1847091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 1848091296d3SMiri Korenblit bw++) { 1849091296d3SMiri Korenblit ru_index_tmp >>= 1; 1850091296d3SMiri Korenblit 1851091296d3SMiri Korenblit if (!(ru_index_tmp & 1)) 1852091296d3SMiri Korenblit continue; 1853091296d3SMiri Korenblit 1854091296d3SMiri Korenblit high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 1855091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 1856091296d3SMiri Korenblit low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit); 1857091296d3SMiri Korenblit ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE; 1858091296d3SMiri Korenblit 1859091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 1860091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 1861091296d3SMiri Korenblit } 1862091296d3SMiri Korenblit } 1863091296d3SMiri Korenblit } 1864091296d3SMiri Korenblit 1865091296d3SMiri Korenblit static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm, 1866091296d3SMiri Korenblit struct ieee80211_sta *sta, 1867091296d3SMiri Korenblit struct iwl_he_pkt_ext_v2 *pkt_ext) 1868091296d3SMiri Korenblit { 1869046d2e7cSSriram R u8 nss = (sta->deflink.he_cap.ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) + 1; 1870046d2e7cSSriram R u8 *ppe = &sta->deflink.he_cap.ppe_thres[0]; 1871091296d3SMiri Korenblit u8 ru_index_bitmap = 1872091296d3SMiri Korenblit u8_get_bits(*ppe, 1873091296d3SMiri Korenblit IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK); 1874091296d3SMiri Korenblit /* Starting after PPE header */ 1875091296d3SMiri Korenblit u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE; 1876091296d3SMiri Korenblit 1877091296d3SMiri Korenblit iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit); 1878091296d3SMiri Korenblit } 1879091296d3SMiri Korenblit 1880091296d3SMiri Korenblit static void iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext, 1881091296d3SMiri Korenblit u8 nominal_padding, 1882091296d3SMiri Korenblit u32 *flags) 1883091296d3SMiri Korenblit { 1884091296d3SMiri Korenblit int low_th = -1; 1885091296d3SMiri Korenblit int high_th = -1; 1886091296d3SMiri Korenblit int i; 1887091296d3SMiri Korenblit 1888091296d3SMiri Korenblit switch (nominal_padding) { 1889091296d3SMiri Korenblit case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_0US: 1890091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 1891091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 1892091296d3SMiri Korenblit break; 1893091296d3SMiri Korenblit case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_8US: 1894091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_BPSK; 1895091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_NONE; 1896091296d3SMiri Korenblit break; 1897091296d3SMiri Korenblit case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US: 1898091296d3SMiri Korenblit low_th = IWL_HE_PKT_EXT_NONE; 1899091296d3SMiri Korenblit high_th = IWL_HE_PKT_EXT_BPSK; 1900091296d3SMiri Korenblit break; 1901091296d3SMiri Korenblit } 1902091296d3SMiri Korenblit 1903091296d3SMiri Korenblit /* Set the PPE thresholds accordingly */ 1904091296d3SMiri Korenblit if (low_th >= 0 && high_th >= 0) { 1905091296d3SMiri Korenblit for (i = 0; i < MAX_HE_SUPP_NSS; i++) { 1906091296d3SMiri Korenblit u8 bw; 1907091296d3SMiri Korenblit 1908091296d3SMiri Korenblit for (bw = 0; 1909091296d3SMiri Korenblit bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]); 1910091296d3SMiri Korenblit bw++) { 1911091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th; 1912091296d3SMiri Korenblit pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th; 1913091296d3SMiri Korenblit } 1914091296d3SMiri Korenblit } 1915091296d3SMiri Korenblit 1916091296d3SMiri Korenblit *flags |= STA_CTXT_HE_PACKET_EXT; 1917091296d3SMiri Korenblit } 1918091296d3SMiri Korenblit } 1919091296d3SMiri Korenblit 1920514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 1921514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 1922514c3069SLuca Coelho { 1923514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 192442506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = { 1925514c3069SLuca Coelho .sta_id = sta_id, 1926514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 1927dd56e902SJohn Crispin .bss_color = vif->bss_conf.he_bss_color.color, 1928514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 1929514c3069SLuca Coelho .frame_time_rts_th = 1930514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 1931514c3069SLuca Coelho }; 193242506dd2SJohannes Berg struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {}; 193342506dd2SJohannes Berg u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD); 193442506dd2SJohannes Berg u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2); 193542506dd2SJohannes Berg int size; 1936514c3069SLuca Coelho struct ieee80211_sta *sta; 1937514c3069SLuca Coelho u32 flags; 1938514c3069SLuca Coelho int i; 1939ee1a02d7SShaul Triebitz const struct ieee80211_sta_he_cap *own_he_cap = NULL; 1940ee1a02d7SShaul Triebitz struct ieee80211_chanctx_conf *chanctx_conf; 1941ee1a02d7SShaul Triebitz const struct ieee80211_supported_band *sband; 194242506dd2SJohannes Berg void *cmd; 194342506dd2SJohannes Berg 194442506dd2SJohannes Berg if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE)) 194542506dd2SJohannes Berg ver = 1; 194642506dd2SJohannes Berg 194742506dd2SJohannes Berg switch (ver) { 194842506dd2SJohannes Berg case 1: 194942506dd2SJohannes Berg /* same layout as v2 except some data at the end */ 195042506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 195142506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v1); 195242506dd2SJohannes Berg break; 195342506dd2SJohannes Berg case 2: 195442506dd2SJohannes Berg cmd = &sta_ctxt_cmd_v2; 195542506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v2); 195642506dd2SJohannes Berg break; 195742506dd2SJohannes Berg case 3: 195842506dd2SJohannes Berg cmd = &sta_ctxt_cmd; 195942506dd2SJohannes Berg size = sizeof(struct iwl_he_sta_context_cmd_v3); 196042506dd2SJohannes Berg break; 196142506dd2SJohannes Berg default: 196242506dd2SJohannes Berg IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); 196342506dd2SJohannes Berg return; 196442506dd2SJohannes Berg } 1965514c3069SLuca Coelho 1966514c3069SLuca Coelho rcu_read_lock(); 1967514c3069SLuca Coelho 1968d0a9123eSJohannes Berg chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf); 1969ee1a02d7SShaul Triebitz if (WARN_ON(!chanctx_conf)) { 1970ee1a02d7SShaul Triebitz rcu_read_unlock(); 1971ee1a02d7SShaul Triebitz return; 1972ee1a02d7SShaul Triebitz } 1973ee1a02d7SShaul Triebitz 1974ee1a02d7SShaul Triebitz sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band]; 19754e6b69ecSJohannes Berg own_he_cap = ieee80211_get_he_iftype_cap(sband, 19764e6b69ecSJohannes Berg ieee80211_vif_type_p2p(vif)); 1977ee1a02d7SShaul Triebitz 1978514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 197912d47f0eSAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) { 1980514c3069SLuca Coelho rcu_read_unlock(); 1981514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 1982514c3069SLuca Coelho return; 1983514c3069SLuca Coelho } 1984514c3069SLuca Coelho 1985046d2e7cSSriram R if (!sta->deflink.he_cap.has_he) { 1986514c3069SLuca Coelho rcu_read_unlock(); 1987514c3069SLuca Coelho return; 1988514c3069SLuca Coelho } 1989514c3069SLuca Coelho 1990514c3069SLuca Coelho flags = 0; 1991514c3069SLuca Coelho 19924f58121dSIlan Peer /* Block 26-tone RU OFDMA transmissions */ 19934f58121dSIlan Peer if (mvmvif->he_ru_2mhz_block) 19944f58121dSIlan Peer flags |= STA_CTXT_HE_RU_2MHZ_BLOCK; 19954f58121dSIlan Peer 1996514c3069SLuca Coelho /* HTC flags */ 1997046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[0] & 1998514c3069SLuca Coelho IEEE80211_HE_MAC_CAP0_HTC_HE) 1999514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 2000046d2e7cSSriram R if ((sta->deflink.he_cap.he_cap_elem.mac_cap_info[1] & 2001514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 2002046d2e7cSSriram R (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 2003514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 2004514c3069SLuca Coelho u8 link_adap = 2005046d2e7cSSriram R ((sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 2006514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 2007046d2e7cSSriram R (sta->deflink.he_cap.he_cap_elem.mac_cap_info[1] & 2008514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 2009514c3069SLuca Coelho 2010514c3069SLuca Coelho if (link_adap == 2) 2011514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2012514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 2013514c3069SLuca Coelho else if (link_adap == 3) 2014514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2015514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 2016514c3069SLuca Coelho } 2017046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 2018514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 2019046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[3] & 2020514c3069SLuca Coelho IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 2021514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 2022046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 2023514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 2024514c3069SLuca Coelho 2025189b8d44SNaftali Goldstein /* 2026189b8d44SNaftali Goldstein * Initialize the PPE thresholds to "None" (7), as described in Table 2027189b8d44SNaftali Goldstein * 9-262ac of 80211.ax/D3.0. 2028189b8d44SNaftali Goldstein */ 2029091296d3SMiri Korenblit memset(&sta_ctxt_cmd.pkt_ext, IWL_HE_PKT_EXT_NONE, 2030091296d3SMiri Korenblit sizeof(sta_ctxt_cmd.pkt_ext)); 2031189b8d44SNaftali Goldstein 2032189b8d44SNaftali Goldstein /* If PPE Thresholds exist, parse them into a FW-familiar format. */ 2033046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] & 2034514c3069SLuca Coelho IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2035091296d3SMiri Korenblit iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta, 2036091296d3SMiri Korenblit &sta_ctxt_cmd.pkt_ext); 2037514c3069SLuca Coelho flags |= STA_CTXT_HE_PACKET_EXT; 2038091296d3SMiri Korenblit /* PPE Thresholds doesn't exist - set the API PPE values 2039091296d3SMiri Korenblit * according to Common Nominal Packet Padding fiels. */ 2040091296d3SMiri Korenblit } else { 2041091296d3SMiri Korenblit u8 nominal_padding = 2042046d2e7cSSriram R u8_get_bits(sta->deflink.he_cap.he_cap_elem.phy_cap_info[9], 2043091296d3SMiri Korenblit IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); 2044091296d3SMiri Korenblit if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED) 2045091296d3SMiri Korenblit iwl_mvm_set_pkt_ext_from_nominal_padding(&sta_ctxt_cmd.pkt_ext, 2046091296d3SMiri Korenblit nominal_padding, 2047091296d3SMiri Korenblit &flags); 2048514c3069SLuca Coelho } 204973f23d91SShaul Triebitz 2050046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 205173f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP) 205273f23d91SShaul Triebitz flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 205373f23d91SShaul Triebitz 2054046d2e7cSSriram R if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & 205573f23d91SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN) 205673f23d91SShaul Triebitz flags |= STA_CTXT_HE_ACK_ENABLED; 205773f23d91SShaul Triebitz 2058514c3069SLuca Coelho rcu_read_unlock(); 2059514c3069SLuca Coelho 2060514c3069SLuca Coelho /* Mark MU EDCA as enabled, unless none detected on some AC */ 2061514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 20625cc74f65SShaul Triebitz for (i = 0; i < IEEE80211_NUM_ACS; i++) { 2063514c3069SLuca Coelho struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2064514c3069SLuca Coelho &mvmvif->queue_params[i].mu_edca_param_rec; 20655cc74f65SShaul Triebitz u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i); 2066514c3069SLuca Coelho 2067514c3069SLuca Coelho if (!mvmvif->queue_params[i].mu_edca) { 2068514c3069SLuca Coelho flags &= ~STA_CTXT_HE_MU_EDCA_CW; 2069514c3069SLuca Coelho break; 2070514c3069SLuca Coelho } 2071514c3069SLuca Coelho 20725cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].cwmin = 2073514c3069SLuca Coelho cpu_to_le16(mu_edca->ecw_min_max & 0xf); 20745cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].cwmax = 2075514c3069SLuca Coelho cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 20765cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].aifsn = 2077514c3069SLuca Coelho cpu_to_le16(mu_edca->aifsn); 20785cc74f65SShaul Triebitz sta_ctxt_cmd.trig_based_txf[ac].mu_time = 2079514c3069SLuca Coelho cpu_to_le16(mu_edca->mu_edca_timer); 2080514c3069SLuca Coelho } 2081514c3069SLuca Coelho 2082514c3069SLuca Coelho 2083514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2084514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2085514c3069SLuca Coelho 2086514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2087514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2088514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2089514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2090514c3069SLuca Coelho } 2091514c3069SLuca Coelho 2092ee1a02d7SShaul Triebitz if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] & 2093ee1a02d7SShaul Triebitz IEEE80211_HE_MAC_CAP2_ACK_EN)) 2094ee1a02d7SShaul Triebitz flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED; 2095ee1a02d7SShaul Triebitz 2096918cbf39SSara Sharon if (vif->bss_conf.nontransmitted) { 2097918cbf39SSara Sharon flags |= STA_CTXT_HE_REF_BSSID_VALID; 2098918cbf39SSara Sharon ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr, 2099918cbf39SSara Sharon vif->bss_conf.transmitter_bssid); 2100d14ae796SSara Sharon sta_ctxt_cmd.max_bssid_indicator = 2101d14ae796SSara Sharon vif->bss_conf.bssid_indicator; 2102d14ae796SSara Sharon sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index; 2103d14ae796SSara Sharon sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap; 2104d14ae796SSara Sharon sta_ctxt_cmd.profile_periodicity = 2105d14ae796SSara Sharon vif->bss_conf.profile_periodicity; 2106918cbf39SSara Sharon } 2107514c3069SLuca Coelho 2108514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2109514c3069SLuca Coelho 211042506dd2SJohannes Berg if (ver < 3) { 211142506dd2SJohannes Berg /* fields before pkt_ext */ 211242506dd2SJohannes Berg BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) != 211342506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext)); 211442506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd, 211542506dd2SJohannes Berg offsetof(typeof(sta_ctxt_cmd), pkt_ext)); 211642506dd2SJohannes Berg 211742506dd2SJohannes Berg /* pkt_ext */ 211842506dd2SJohannes Berg for (i = 0; 211942506dd2SJohannes Berg i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th); 212042506dd2SJohannes Berg i++) { 212142506dd2SJohannes Berg u8 bw; 212242506dd2SJohannes Berg 212342506dd2SJohannes Berg for (bw = 0; 212442506dd2SJohannes Berg bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]); 212542506dd2SJohannes Berg bw++) { 212642506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) != 212742506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw])); 212842506dd2SJohannes Berg 212942506dd2SJohannes Berg memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw], 213042506dd2SJohannes Berg &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw], 213142506dd2SJohannes Berg sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw])); 213242506dd2SJohannes Berg } 213342506dd2SJohannes Berg } 213442506dd2SJohannes Berg 213542506dd2SJohannes Berg /* fields after pkt_ext */ 213642506dd2SJohannes Berg BUILD_BUG_ON(sizeof(sta_ctxt_cmd) - 213742506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext) != 213842506dd2SJohannes Berg sizeof(sta_ctxt_cmd_v2) - 213942506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext)); 214042506dd2SJohannes Berg memcpy((u8 *)&sta_ctxt_cmd_v2 + 214142506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext), 214242506dd2SJohannes Berg (u8 *)&sta_ctxt_cmd + 214342506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext), 214442506dd2SJohannes Berg sizeof(sta_ctxt_cmd) - 214542506dd2SJohannes Berg offsetofend(typeof(sta_ctxt_cmd), pkt_ext)); 214642506dd2SJohannes Berg sta_ctxt_cmd_v2.reserved3 = 0; 214742506dd2SJohannes Berg } 214842506dd2SJohannes Berg 214942506dd2SJohannes Berg if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd)) 2150514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2151514c3069SLuca Coelho } 2152514c3069SLuca Coelho 2153af84ac57SJohannes Berg static void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, 2154af84ac57SJohannes Berg struct ieee80211_vif *vif, 2155af84ac57SJohannes Berg u32 duration_override) 2156af84ac57SJohannes Berg { 2157af84ac57SJohannes Berg u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 2158af84ac57SJohannes Berg u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2159af84ac57SJohannes Berg 2160af84ac57SJohannes Berg if (duration_override > duration) 2161af84ac57SJohannes Berg duration = duration_override; 2162af84ac57SJohannes Berg 2163af84ac57SJohannes Berg /* Try really hard to protect the session and hear a beacon 2164af84ac57SJohannes Berg * The new session protection command allows us to protect the 2165af84ac57SJohannes Berg * session for a much longer time since the firmware will internally 2166af84ac57SJohannes Berg * create two events: a 300TU one with a very high priority that 2167af84ac57SJohannes Berg * won't be fragmented which should be enough for 99% of the cases, 2168af84ac57SJohannes Berg * and another one (which we configure here to be 900TU long) which 2169af84ac57SJohannes Berg * will have a slightly lower priority, but more importantly, can be 2170af84ac57SJohannes Berg * fragmented so that it'll allow other activities to run. 2171af84ac57SJohannes Berg */ 2172af84ac57SJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 2173af84ac57SJohannes Berg IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) 2174af84ac57SJohannes Berg iwl_mvm_schedule_session_protection(mvm, vif, 900, 2175af84ac57SJohannes Berg min_duration, false); 2176af84ac57SJohannes Berg else 2177af84ac57SJohannes Berg iwl_mvm_protect_session(mvm, vif, duration, 2178af84ac57SJohannes Berg min_duration, 500, false); 2179af84ac57SJohannes Berg } 2180af84ac57SJohannes Berg 2181e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2182e705c121SKalle Valo struct ieee80211_vif *vif, 2183e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 21847b7090b4SJohannes Berg u64 changes) 2185e705c121SKalle Valo { 2186e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2187e705c121SKalle Valo int ret; 2188e705c121SKalle Valo 2189e705c121SKalle Valo /* 2190cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend 2191cdaba917SEmmanuel Grumbach * on the beacon interval, which was not known when the station 2192cdaba917SEmmanuel Grumbach * interface was added. 2193e705c121SKalle Valo */ 2194f276e20bSJohannes Berg if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { 2195230ba6c5SLuca Coelho if (vif->bss_conf.he_support && 2196230ba6c5SLuca Coelho !iwlwifi_mod_params.disable_11ax) 2197514c3069SLuca Coelho iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); 2198514c3069SLuca Coelho 2199e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2200514c3069SLuca Coelho } 2201e705c121SKalle Valo 220240ecdd01SShaul Triebitz /* Update MU EDCA params */ 220340ecdd01SShaul Triebitz if (changes & BSS_CHANGED_QOS && mvmvif->associated && 2204f276e20bSJohannes Berg vif->cfg.assoc && vif->bss_conf.he_support && 220540ecdd01SShaul Triebitz !iwlwifi_mod_params.disable_11ax) 220640ecdd01SShaul Triebitz iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); 220740ecdd01SShaul Triebitz 2208e705c121SKalle Valo /* 2209e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2210e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2211e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2212e705c121SKalle Valo * branch for disassociation below. 2213e705c121SKalle Valo */ 2214e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2215e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2216e705c121SKalle Valo 2217e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); 2218e705c121SKalle Valo if (ret) 2219e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2220e705c121SKalle Valo 2221e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2222e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2223f276e20bSJohannes Berg mvmvif->associated = vif->cfg.assoc; 2224e705c121SKalle Valo 2225e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2226f276e20bSJohannes Berg if (vif->cfg.assoc) { 2227e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2228e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2229e705c121SKalle Valo memset(&mvmvif->beacon_stats, 0, 2230e705c121SKalle Valo sizeof(mvmvif->beacon_stats)); 2231e705c121SKalle Valo 2232e705c121SKalle Valo /* add quota for this interface */ 2233e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2234e705c121SKalle Valo if (ret) { 2235e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2236e705c121SKalle Valo return; 2237e705c121SKalle Valo } 2238e705c121SKalle Valo 2239e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2240fe959c7bSEmmanuel Grumbach &mvm->status) && 2241fe959c7bSEmmanuel Grumbach !fw_has_capa(&mvm->fw->ucode_capa, 2242fe959c7bSEmmanuel Grumbach IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { 2243e705c121SKalle Valo /* 2244e705c121SKalle Valo * If we're restarting then the firmware will 2245e705c121SKalle Valo * obviously have lost synchronisation with 2246e705c121SKalle Valo * the AP. It will attempt to synchronise by 2247e705c121SKalle Valo * itself, but we can make it more reliable by 2248e705c121SKalle Valo * scheduling a session protection time event. 2249e705c121SKalle Valo * 2250e705c121SKalle Valo * The firmware needs to receive a beacon to 2251e705c121SKalle Valo * catch up with synchronisation, use 110% of 2252e705c121SKalle Valo * the beacon interval. 2253e705c121SKalle Valo * 2254e705c121SKalle Valo * Set a large maximum delay to allow for more 2255e705c121SKalle Valo * than a single interface. 2256fe959c7bSEmmanuel Grumbach * 2257fe959c7bSEmmanuel Grumbach * For new firmware versions, rely on the 2258fe959c7bSEmmanuel Grumbach * firmware. This is relevant for DCM scenarios 2259fe959c7bSEmmanuel Grumbach * only anyway. 2260e705c121SKalle Valo */ 2261e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2262e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2263e705c121SKalle Valo 5 * dur, false); 2264af84ac57SJohannes Berg } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2265af84ac57SJohannes Berg &mvm->status) && 2266af84ac57SJohannes Berg !vif->bss_conf.dtim_period) { 2267af84ac57SJohannes Berg /* 2268af84ac57SJohannes Berg * If we're not restarting and still haven't 2269af84ac57SJohannes Berg * heard a beacon (dtim period unknown) then 2270af84ac57SJohannes Berg * make sure we still have enough minimum time 2271af84ac57SJohannes Berg * remaining in the time event, since the auth 2272af84ac57SJohannes Berg * might actually have taken quite a while 2273af84ac57SJohannes Berg * (especially for SAE) and so the remaining 2274af84ac57SJohannes Berg * time could be small without us having heard 2275af84ac57SJohannes Berg * a beacon yet. 2276af84ac57SJohannes Berg */ 2277af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, 0); 2278e705c121SKalle Valo } 2279e705c121SKalle Valo 2280e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2281e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2282e705c121SKalle Valo if (vif->p2p) { 2283e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2284e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 2285e705c121SKalle Valo IEEE80211_SMPS_DYNAMIC); 2286e705c121SKalle Valo } 22870ae98812SSara Sharon } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { 22886d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_disassociated(mvm); 2289e705c121SKalle Valo /* 2290e705c121SKalle Valo * If update fails - SF might be running in associated 2291e705c121SKalle Valo * mode while disassociated - which is forbidden. 2292e705c121SKalle Valo */ 229369e508b4SIlan Peer ret = iwl_mvm_sf_update(mvm, vif, false); 229469e508b4SIlan Peer WARN_ONCE(ret && 229569e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 229669e508b4SIlan Peer &mvm->status), 2297e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2298e705c121SKalle Valo 22996b28f978SEmmanuel Grumbach /* 23006b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 23016b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 23026b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 23036b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 23046b28f978SEmmanuel Grumbach * associated, we would remove the station here and 23056b28f978SEmmanuel Grumbach * this would fail the recovery. 23066b28f978SEmmanuel Grumbach */ 23076b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 23086b28f978SEmmanuel Grumbach &mvm->status)) { 23096b28f978SEmmanuel Grumbach /* 23106b28f978SEmmanuel Grumbach * Remove AP station now that 23116b28f978SEmmanuel Grumbach * the MAC is unassoc 23126b28f978SEmmanuel Grumbach */ 23136b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 23146b28f978SEmmanuel Grumbach mvmvif->ap_sta_id); 2315e705c121SKalle Valo if (ret) 23166b28f978SEmmanuel Grumbach IWL_ERR(mvm, 23176b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2318e705c121SKalle Valo 23190ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 23206b28f978SEmmanuel Grumbach } 23216b28f978SEmmanuel Grumbach 2322e705c121SKalle Valo /* remove quota for this interface */ 2323e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2324e705c121SKalle Valo if (ret) 2325e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2326e705c121SKalle Valo 2327e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2328e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2329e705c121SKalle Valo if (ret) 2330e705c121SKalle Valo IWL_ERR(mvm, 2331e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2332e705c121SKalle Valo vif->addr); 2333e705c121SKalle Valo } 2334e705c121SKalle Valo 2335a07a8f37SSara Sharon /* 2336a07a8f37SSara Sharon * The firmware tracks the MU-MIMO group on its own. 2337f92659a1SSara Sharon * However, on HW restart we should restore this data. 2338a07a8f37SSara Sharon */ 2339a07a8f37SSara Sharon if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2340d0a9123eSJohannes Berg (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) { 2341a07a8f37SSara Sharon ret = iwl_mvm_update_mu_groups(mvm, vif); 2342a07a8f37SSara Sharon if (ret) 2343a07a8f37SSara Sharon IWL_ERR(mvm, 2344a07a8f37SSara Sharon "failed to update VHT MU_MIMO groups\n"); 2345a07a8f37SSara Sharon } 2346a07a8f37SSara Sharon 2347e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 2348e705c121SKalle Valo 2349e705c121SKalle Valo /* reset rssi values */ 2350e705c121SKalle Valo mvmvif->bf_data.ave_beacon_signal = 0; 2351e705c121SKalle Valo 2352e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2353e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2354e705c121SKalle Valo IEEE80211_SMPS_AUTOMATIC); 2355355346baSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 2356355346baSAvraham Stern IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2357355346baSAvraham Stern iwl_mvm_config_scan(mvm); 2358b45242c9SAvraham Stern } 2359b45242c9SAvraham Stern 2360b45242c9SAvraham Stern if (changes & BSS_CHANGED_BEACON_INFO) { 2361e705c121SKalle Valo /* 2362b45242c9SAvraham Stern * We received a beacon from the associated AP so 2363e705c121SKalle Valo * remove the session protection. 2364e705c121SKalle Valo */ 23653edfb5f4SAvraham Stern iwl_mvm_stop_session_protection(mvm, vif); 2366e705c121SKalle Valo 2367e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2368e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2369e705c121SKalle Valo } 2370e705c121SKalle Valo 2371283115fbSAvri Altman if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2372283115fbSAvri Altman /* 2373283115fbSAvri Altman * Send power command on every beacon change, 2374283115fbSAvri Altman * because we may have not enabled beacon abort yet. 2375283115fbSAvri Altman */ 2376283115fbSAvri Altman BSS_CHANGED_BEACON_INFO)) { 2377e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 2378e705c121SKalle Valo if (ret) 2379e705c121SKalle Valo IWL_ERR(mvm, "failed to update power mode\n"); 2380e705c121SKalle Valo } 2381e705c121SKalle Valo 2382e705c121SKalle Valo if (changes & BSS_CHANGED_CQM) { 2383e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); 2384e705c121SKalle Valo /* reset cqm events tracking */ 2385e705c121SKalle Valo mvmvif->bf_data.last_cqm_event = 0; 2386e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 2387e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 2388e705c121SKalle Valo if (ret) 2389e705c121SKalle Valo IWL_ERR(mvm, 2390e705c121SKalle Valo "failed to update CQM thresholds\n"); 2391e705c121SKalle Valo } 2392e705c121SKalle Valo } 2393e705c121SKalle Valo 2394de34d1c1SJohannes Berg if (changes & BSS_CHANGED_BANDWIDTH) 2395de34d1c1SJohannes Berg iwl_mvm_apply_fw_smps_request(vif); 2396e705c121SKalle Valo } 2397e705c121SKalle Valo 2398e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2399ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2400b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2401e705c121SKalle Valo { 2402e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2403e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2404c56e00a3SJohannes Berg int ret, i; 2405e705c121SKalle Valo 2406e705c121SKalle Valo mutex_lock(&mvm->mutex); 2407e705c121SKalle Valo 2408e705c121SKalle Valo /* Send the beacon template */ 2409e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); 2410e705c121SKalle Valo if (ret) 2411e705c121SKalle Valo goto out_unlock; 2412e705c121SKalle Valo 2413e705c121SKalle Valo /* 2414cdaba917SEmmanuel Grumbach * Re-calculate the tsf id, as the leader-follower relations depend on 2415cdaba917SEmmanuel Grumbach * the beacon interval, which was not known when the AP interface 2416cdaba917SEmmanuel Grumbach * was added. 2417e705c121SKalle Valo */ 2418e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2419e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2420e705c121SKalle Valo 2421e705c121SKalle Valo mvmvif->ap_assoc_sta_count = 0; 2422e705c121SKalle Valo 2423e705c121SKalle Valo /* Add the mac context */ 2424e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2425e705c121SKalle Valo if (ret) 2426e705c121SKalle Valo goto out_unlock; 2427e705c121SKalle Valo 2428e705c121SKalle Valo /* Perform the binding */ 2429e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2430e705c121SKalle Valo if (ret) 2431e705c121SKalle Valo goto out_remove; 2432e705c121SKalle Valo 243363dd5d02SSara Sharon /* 243463dd5d02SSara Sharon * This is not very nice, but the simplest: 243563dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 243663dd5d02SSara Sharon * cause assert 0x2b00. 243763dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 243863dd5d02SSara Sharon * the TLV 243963dd5d02SSara Sharon */ 244063dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2441ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2442ced19f26SSara Sharon if (ret) 2443ced19f26SSara Sharon goto out_unbind; 244463dd5d02SSara Sharon /* 244563dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 244663dd5d02SSara Sharon * events are added and applied to the scheduler 244763dd5d02SSara Sharon */ 2448e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 244963dd5d02SSara Sharon if (ret) { 245063dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 245163dd5d02SSara Sharon goto out_unbind; 245263dd5d02SSara Sharon } 245363dd5d02SSara Sharon } else { 245463dd5d02SSara Sharon /* 245563dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 245663dd5d02SSara Sharon * events are added and applied to the scheduler 245763dd5d02SSara Sharon */ 245875fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2459e705c121SKalle Valo if (ret) 246063dd5d02SSara Sharon goto out_unbind; 246175fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 246263dd5d02SSara Sharon if (ret) { 246363dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 246463dd5d02SSara Sharon goto out_unbind; 246563dd5d02SSara Sharon } 246663dd5d02SSara Sharon } 246726d6c16bSSara Sharon 2468e705c121SKalle Valo /* must be set before quota calculations */ 2469e705c121SKalle Valo mvmvif->ap_ibss_active = true; 2470e705c121SKalle Valo 2471c56e00a3SJohannes Berg /* send all the early keys to the device now */ 2472c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 2473c56e00a3SJohannes Berg struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i]; 2474c56e00a3SJohannes Berg 2475c56e00a3SJohannes Berg if (!key) 2476c56e00a3SJohannes Berg continue; 2477c56e00a3SJohannes Berg 2478c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 2479c56e00a3SJohannes Berg 24806569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key); 2481c56e00a3SJohannes Berg if (ret) 2482c56e00a3SJohannes Berg goto out_quota_failed; 2483c56e00a3SJohannes Berg } 2484c56e00a3SJohannes Berg 248547242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 248647242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, true, 248747242744STova Mussai LOW_LATENCY_VIF_TYPE); 248847242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 248947242744STova Mussai } 249047242744STova Mussai 2491e705c121SKalle Valo /* power updated needs to be done before quotas */ 2492e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2493e705c121SKalle Valo 2494e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2495e705c121SKalle Valo if (ret) 2496e705c121SKalle Valo goto out_quota_failed; 2497e705c121SKalle Valo 2498e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2499e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2500e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2501e705c121SKalle Valo 2502e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2503e705c121SKalle Valo 2504e705c121SKalle Valo /* we don't support TDLS during DCM */ 2505e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2506e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2507e705c121SKalle Valo 2508b73f9a4aSJohannes Berg iwl_mvm_ftm_restart_responder(mvm, vif); 2509b73f9a4aSJohannes Berg 2510e705c121SKalle Valo goto out_unlock; 2511e705c121SKalle Valo 2512e705c121SKalle Valo out_quota_failed: 2513e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2514e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2515e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2516ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2517e705c121SKalle Valo out_unbind: 2518e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2519e705c121SKalle Valo out_remove: 2520e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2521e705c121SKalle Valo out_unlock: 2522e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2523e705c121SKalle Valo return ret; 2524e705c121SKalle Valo } 2525e705c121SKalle Valo 2526ae7ba17bSShaul Triebitz static int iwl_mvm_start_ap(struct ieee80211_hw *hw, 2527ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2528b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2529ae7ba17bSShaul Triebitz { 2530b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, link_conf); 2531ae7ba17bSShaul Triebitz } 2532ae7ba17bSShaul Triebitz 2533ae7ba17bSShaul Triebitz static int iwl_mvm_start_ibss(struct ieee80211_hw *hw, 2534e705c121SKalle Valo struct ieee80211_vif *vif) 2535e705c121SKalle Valo { 2536b327c84cSGregory Greenman return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf); 2537ae7ba17bSShaul Triebitz } 2538ae7ba17bSShaul Triebitz 2539ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 2540ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2541b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2542ae7ba17bSShaul Triebitz { 2543e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2544e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2545e705c121SKalle Valo 2546e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 2547e705c121SKalle Valo 2548e705c121SKalle Valo mutex_lock(&mvm->mutex); 2549e705c121SKalle Valo 2550e705c121SKalle Valo /* Handle AP stop while in CSA */ 2551e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 2552e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 2553e705c121SKalle Valo &mvmvif->time_event_data); 2554e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 2555e705c121SKalle Valo mvmvif->csa_countdown = false; 2556e705c121SKalle Valo } 2557e705c121SKalle Valo 2558e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 2559e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2560e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 2561e705c121SKalle Valo } 2562e705c121SKalle Valo 2563e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2564e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 2565e705c121SKalle Valo 256647242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 256747242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 256847242744STova Mussai LOW_LATENCY_VIF_TYPE); 256947242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 257047242744STova Mussai } 257147242744STova Mussai 2572e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2573e705c121SKalle Valo 2574e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2575e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2576e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2577e705c121SKalle Valo 2578e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 2579ced19f26SSara Sharon 2580be82ecd3SAvraham Stern iwl_mvm_ftm_responder_clear(mvm, vif); 2581be82ecd3SAvraham Stern 2582ced19f26SSara Sharon /* 2583ced19f26SSara Sharon * This is not very nice, but the simplest: 2584ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 2585ced19f26SSara Sharon * cause assert 0x2b00. 2586ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 2587ced19f26SSara Sharon * bcast station). 2588ced19f26SSara Sharon * So make the order of removal depend on the TLV 2589ced19f26SSara Sharon */ 2590ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 259126d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2592e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2593ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 2594ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2595e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2596e705c121SKalle Valo 2597e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2598e705c121SKalle Valo 2599e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2600e705c121SKalle Valo 2601e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2602e705c121SKalle Valo } 2603e705c121SKalle Valo 2604ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, 2605ae7ba17bSShaul Triebitz struct ieee80211_vif *vif, 2606b327c84cSGregory Greenman struct ieee80211_bss_conf *link_conf) 2607ae7ba17bSShaul Triebitz { 2608b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, link_conf); 2609ae7ba17bSShaul Triebitz } 2610ae7ba17bSShaul Triebitz 2611ae7ba17bSShaul Triebitz static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw, 2612ae7ba17bSShaul Triebitz struct ieee80211_vif *vif) 2613ae7ba17bSShaul Triebitz { 2614b327c84cSGregory Greenman iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf); 2615ae7ba17bSShaul Triebitz } 2616ae7ba17bSShaul Triebitz 2617e705c121SKalle Valo static void 2618e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 2619e705c121SKalle Valo struct ieee80211_vif *vif, 2620e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 26217b7090b4SJohannes Berg u64 changes) 2622e705c121SKalle Valo { 2623e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2624e705c121SKalle Valo 2625e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 2626e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 2627e705c121SKalle Valo return; 2628e705c121SKalle Valo 2629e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 2630e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 2631e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 2632e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2633e705c121SKalle Valo 2634e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 2635e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 2636e705c121SKalle Valo iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) 2637e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 2638e705c121SKalle Valo 2639b73f9a4aSJohannes Berg if (changes & BSS_CHANGED_FTM_RESPONDER) { 2640b73f9a4aSJohannes Berg int ret = iwl_mvm_ftm_start_responder(mvm, vif); 2641b73f9a4aSJohannes Berg 2642b73f9a4aSJohannes Berg if (ret) 2643b73f9a4aSJohannes Berg IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n", 2644b73f9a4aSJohannes Berg ret); 2645b73f9a4aSJohannes Berg } 2646b73f9a4aSJohannes Berg 2647e705c121SKalle Valo } 2648e705c121SKalle Valo 2649e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 2650e705c121SKalle Valo struct ieee80211_vif *vif, 2651e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 26527b7090b4SJohannes Berg u64 changes) 2653e705c121SKalle Valo { 2654e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2655e705c121SKalle Valo 2656e705c121SKalle Valo mutex_lock(&mvm->mutex); 2657e705c121SKalle Valo 2658f276e20bSJohannes Berg if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle) 2659e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 2660e705c121SKalle Valo 2661e705c121SKalle Valo switch (vif->type) { 2662e705c121SKalle Valo case NL80211_IFTYPE_STATION: 2663e705c121SKalle Valo iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 2664e705c121SKalle Valo break; 2665e705c121SKalle Valo case NL80211_IFTYPE_AP: 2666e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 2667e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 2668e705c121SKalle Valo break; 266991b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 267091b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 267191b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 267291b08c2dSAviya Erenfeld break; 2673e705c121SKalle Valo default: 2674e705c121SKalle Valo /* shouldn't happen */ 2675e705c121SKalle Valo WARN_ON_ONCE(1); 2676e705c121SKalle Valo } 2677e705c121SKalle Valo 26789aae43a4SJohannes Berg if (changes & BSS_CHANGED_TXPOWER) { 26799aae43a4SJohannes Berg IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n", 26809aae43a4SJohannes Berg bss_conf->txpower); 26819aae43a4SJohannes Berg iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 26829aae43a4SJohannes Berg } 26839aae43a4SJohannes Berg 2684e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2685e705c121SKalle Valo } 2686e705c121SKalle Valo 2687e705c121SKalle Valo static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, 2688e705c121SKalle Valo struct ieee80211_vif *vif, 2689e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 2690e705c121SKalle Valo { 2691e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2692e705c121SKalle Valo int ret; 2693e705c121SKalle Valo 2694e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 2695e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 2696e705c121SKalle Valo return -EINVAL; 2697e705c121SKalle Valo 2698e705c121SKalle Valo mutex_lock(&mvm->mutex); 2699e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 2700e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2701e705c121SKalle Valo 2702e705c121SKalle Valo return ret; 2703e705c121SKalle Valo } 2704e705c121SKalle Valo 2705e705c121SKalle Valo static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 2706e705c121SKalle Valo struct ieee80211_vif *vif) 2707e705c121SKalle Valo { 2708e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2709e705c121SKalle Valo 2710e705c121SKalle Valo mutex_lock(&mvm->mutex); 2711e705c121SKalle Valo 2712e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 2713e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 2714e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 2715e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 2716e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 2717e705c121SKalle Valo * To handle that, simply return if the scan is not running. 2718e705c121SKalle Valo */ 2719e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 2720e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 2721e705c121SKalle Valo 2722e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2723e705c121SKalle Valo } 2724e705c121SKalle Valo 2725e705c121SKalle Valo static void 2726e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 2727e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2728e705c121SKalle Valo int num_frames, 2729e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2730e705c121SKalle Valo bool more_data) 2731e705c121SKalle Valo { 2732e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2733e705c121SKalle Valo 2734e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 2735e705c121SKalle Valo 2736e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2737e705c121SKalle Valo tids, more_data, false); 2738e705c121SKalle Valo } 2739e705c121SKalle Valo 2740e705c121SKalle Valo static void 2741e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 2742e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2743e705c121SKalle Valo int num_frames, 2744e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2745e705c121SKalle Valo bool more_data) 2746e705c121SKalle Valo { 2747e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2748e705c121SKalle Valo 27499a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 2750e705c121SKalle Valo 2751e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2752e705c121SKalle Valo tids, more_data, true); 2753e705c121SKalle Valo } 2754e705c121SKalle Valo 275565e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 2756e705c121SKalle Valo enum sta_notify_cmd cmd, 2757e705c121SKalle Valo struct ieee80211_sta *sta) 2758e705c121SKalle Valo { 2759e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2760e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2761e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 2762e705c121SKalle Valo int tid; 2763e705c121SKalle Valo 2764960f864bSJohannes Berg /* 2765960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 2766960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 2767960f864bSJohannes Berg * should have firmware supporting buffer station offload. 2768960f864bSJohannes Berg */ 2769960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 2770960f864bSJohannes Berg return; 2771960f864bSJohannes Berg 2772e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2773311590a3SEmmanuel Grumbach for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { 2774e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2775e705c121SKalle Valo 27766862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 27771c17627bSSara Sharon continue; 27781c17627bSSara Sharon 2779e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 2780e705c121SKalle Valo 2781dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 2782e705c121SKalle Valo continue; 2783e705c121SKalle Valo 2784e705c121SKalle Valo __set_bit(tid, &tids); 2785e705c121SKalle Valo } 2786e705c121SKalle Valo 2787e705c121SKalle Valo switch (cmd) { 2788e705c121SKalle Valo case STA_NOTIFY_SLEEP: 2789e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 2790e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 2791e705c121SKalle Valo 2792e705c121SKalle Valo if (txqs) 2793e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 2794e705c121SKalle Valo /* 2795e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 2796e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 2797e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 2798e705c121SKalle Valo */ 2799e705c121SKalle Valo break; 2800e705c121SKalle Valo case STA_NOTIFY_AWAKE: 28010ae98812SSara Sharon if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA)) 2802e705c121SKalle Valo break; 2803e705c121SKalle Valo 2804e705c121SKalle Valo if (txqs) 2805e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 2806e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 2807e705c121SKalle Valo break; 2808e705c121SKalle Valo default: 2809e705c121SKalle Valo break; 2810e705c121SKalle Valo } 2811e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2812e705c121SKalle Valo } 2813e705c121SKalle Valo 281465e25482SJohannes Berg static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 281565e25482SJohannes Berg struct ieee80211_vif *vif, 281665e25482SJohannes Berg enum sta_notify_cmd cmd, 281765e25482SJohannes Berg struct ieee80211_sta *sta) 281865e25482SJohannes Berg { 281965e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 282065e25482SJohannes Berg } 282165e25482SJohannes Berg 282265e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 282365e25482SJohannes Berg { 282465e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 282565e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 282665e25482SJohannes Berg struct ieee80211_sta *sta; 282765e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 282865e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 282965e25482SJohannes Berg 2830be9ae34eSNathan Errera if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations)) 283165e25482SJohannes Berg return; 283265e25482SJohannes Berg 283365e25482SJohannes Berg rcu_read_lock(); 2834a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 283565e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 283665e25482SJohannes Berg rcu_read_unlock(); 283765e25482SJohannes Berg return; 283865e25482SJohannes Berg } 283965e25482SJohannes Berg 284065e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 284165e25482SJohannes Berg 284265e25482SJohannes Berg if (!mvmsta->vif || 284365e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 284465e25482SJohannes Berg rcu_read_unlock(); 284565e25482SJohannes Berg return; 284665e25482SJohannes Berg } 284765e25482SJohannes Berg 284865e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 284965e25482SJohannes Berg mvmsta->sleeping = sleeping; 285065e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 285165e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 285265e25482SJohannes Berg sta); 285365e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 285465e25482SJohannes Berg } 285565e25482SJohannes Berg 285665e25482SJohannes Berg if (sleeping) { 285765e25482SJohannes Berg switch (notif->type) { 285865e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 285965e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 286065e25482SJohannes Berg break; 286165e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 286265e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 286365e25482SJohannes Berg break; 286465e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 286565e25482SJohannes Berg ieee80211_sta_pspoll(sta); 286665e25482SJohannes Berg break; 286765e25482SJohannes Berg default: 286865e25482SJohannes Berg break; 286965e25482SJohannes Berg } 287065e25482SJohannes Berg } 287165e25482SJohannes Berg 287265e25482SJohannes Berg rcu_read_unlock(); 287365e25482SJohannes Berg } 287465e25482SJohannes Berg 2875e705c121SKalle Valo static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 2876e705c121SKalle Valo struct ieee80211_vif *vif, 2877e705c121SKalle Valo struct ieee80211_sta *sta) 2878e705c121SKalle Valo { 2879e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2880e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2881e705c121SKalle Valo 2882e705c121SKalle Valo /* 2883e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 2884e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 2885e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 2886e705c121SKalle Valo * be able to find the station this way, and we don't rely 2887e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 2888e705c121SKalle Valo * callback deleted the station. 2889e705c121SKalle Valo */ 2890e705c121SKalle Valo mutex_lock(&mvm->mutex); 2891e705c121SKalle Valo if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) 2892e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], 2893e705c121SKalle Valo ERR_PTR(-ENOENT)); 2894e705c121SKalle Valo 2895e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2896e705c121SKalle Valo } 2897e705c121SKalle Valo 2898e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2899e705c121SKalle Valo const u8 *bssid) 2900e705c121SKalle Valo { 2901b0ffe455SJohannes Berg int i; 2902b0ffe455SJohannes Berg 2903b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 2904b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 2905b0ffe455SJohannes Berg 2906b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 2907b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 2908b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 2909b0ffe455SJohannes Berg } 2910b0ffe455SJohannes Berg 2911e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 2912e705c121SKalle Valo return; 2913e705c121SKalle Valo 2914c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 2915cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2916cee5a882SAvri Altman return; 2917cee5a882SAvri Altman } 2918cee5a882SAvri Altman 291911dee0b4SEmmanuel Grumbach if (!vif->p2p && 292011dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 2921e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2922e705c121SKalle Valo return; 2923e705c121SKalle Valo } 2924e705c121SKalle Valo 2925b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 2926b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 2927b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2928b0ffe455SJohannes Berg return; 2929b0ffe455SJohannes Berg } 2930b0ffe455SJohannes Berg } 2931b0ffe455SJohannes Berg 2932e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 2933e705c121SKalle Valo } 2934e705c121SKalle Valo 29351e8f1329SGolan Ben-Ami static void 29361e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 29371e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 29381e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 29391e8f1329SGolan Ben-Ami { 29401e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 29411e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 29421e8f1329SGolan Ben-Ami 29436c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 29446c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 29456c042d75SSara Sharon if (!trig) 29461e8f1329SGolan Ben-Ami return; 29471e8f1329SGolan Ben-Ami 29481e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 29491e8f1329SGolan Ben-Ami 29501e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 29511e8f1329SGolan Ben-Ami return; 29521e8f1329SGolan Ben-Ami 29531e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 29541e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 29551e8f1329SGolan Ben-Ami return; 29561e8f1329SGolan Ben-Ami 29577174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 29581e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 29591e8f1329SGolan Ben-Ami peer_addr, action); 29601e8f1329SGolan Ben-Ami } 29611e8f1329SGolan Ben-Ami 29624f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data { 29634f58121dSIlan Peer bool tolerated; 29644f58121dSIlan Peer }; 29654f58121dSIlan Peer 29664f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, 29674f58121dSIlan Peer struct cfg80211_bss *bss, 29684f58121dSIlan Peer void *_data) 29694f58121dSIlan Peer { 29704f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data; 29716c608cd6SJohannes Berg const struct cfg80211_bss_ies *ies; 29724f58121dSIlan Peer const struct element *elem; 29734f58121dSIlan Peer 29746c608cd6SJohannes Berg rcu_read_lock(); 29756c608cd6SJohannes Berg ies = rcu_dereference(bss->ies); 29766c608cd6SJohannes Berg elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data, 29776c608cd6SJohannes Berg ies->len); 29784f58121dSIlan Peer 29794f58121dSIlan Peer if (!elem || elem->datalen < 10 || 29804f58121dSIlan Peer !(elem->data[10] & 29814f58121dSIlan Peer WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) { 29824f58121dSIlan Peer data->tolerated = false; 29834f58121dSIlan Peer } 29846c608cd6SJohannes Berg rcu_read_unlock(); 29854f58121dSIlan Peer } 29864f58121dSIlan Peer 29874f58121dSIlan Peer static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, 29884f58121dSIlan Peer struct ieee80211_vif *vif) 29894f58121dSIlan Peer { 29904f58121dSIlan Peer struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 29914f58121dSIlan Peer struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = { 29924f58121dSIlan Peer .tolerated = true, 29934f58121dSIlan Peer }; 29944f58121dSIlan Peer 29954f58121dSIlan Peer if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) { 29964f58121dSIlan Peer mvmvif->he_ru_2mhz_block = false; 29974f58121dSIlan Peer return; 29984f58121dSIlan Peer } 29994f58121dSIlan Peer 30004f58121dSIlan Peer cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, 30014f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru_iter, 30024f58121dSIlan Peer &iter_data); 30034f58121dSIlan Peer 30044f58121dSIlan Peer /* 30054f58121dSIlan Peer * If there is at least one AP on radar channel that cannot 30064f58121dSIlan Peer * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. 30074f58121dSIlan Peer */ 30084f58121dSIlan Peer mvmvif->he_ru_2mhz_block = !iter_data.tolerated; 30094f58121dSIlan Peer } 30104f58121dSIlan Peer 3011f7d6ef33SJohannes Berg static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm, 3012f7d6ef33SJohannes Berg struct ieee80211_vif *vif) 3013f7d6ef33SJohannes Berg { 3014f7d6ef33SJohannes Berg struct ieee80211_supported_band *sband; 3015f7d6ef33SJohannes Berg const struct ieee80211_sta_he_cap *he_cap; 3016f7d6ef33SJohannes Berg 3017f7d6ef33SJohannes Berg if (vif->type != NL80211_IFTYPE_STATION) 3018f7d6ef33SJohannes Berg return; 3019f7d6ef33SJohannes Berg 3020f7d6ef33SJohannes Berg if (!mvm->cca_40mhz_workaround) 3021f7d6ef33SJohannes Berg return; 3022f7d6ef33SJohannes Berg 3023f7d6ef33SJohannes Berg /* decrement and check that we reached zero */ 3024f7d6ef33SJohannes Berg mvm->cca_40mhz_workaround--; 3025f7d6ef33SJohannes Berg if (mvm->cca_40mhz_workaround) 3026f7d6ef33SJohannes Berg return; 3027f7d6ef33SJohannes Berg 3028f7d6ef33SJohannes Berg sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]; 3029f7d6ef33SJohannes Berg 3030f7d6ef33SJohannes Berg sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; 3031f7d6ef33SJohannes Berg 3032f7d6ef33SJohannes Berg he_cap = ieee80211_get_he_iftype_cap(sband, 3033f7d6ef33SJohannes Berg ieee80211_vif_type_p2p(vif)); 3034f7d6ef33SJohannes Berg 3035f7d6ef33SJohannes Berg if (he_cap) { 3036f7d6ef33SJohannes Berg /* we know that ours is writable */ 30370301bcd5SBjoern A. Zeeb struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap; 3038f7d6ef33SJohannes Berg 3039f7d6ef33SJohannes Berg he->he_cap_elem.phy_cap_info[0] |= 3040f7d6ef33SJohannes Berg IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 3041f7d6ef33SJohannes Berg } 3042f7d6ef33SJohannes Berg } 3043f7d6ef33SJohannes Berg 30446d19a5ebSEmmanuel Grumbach static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm, 30456d19a5ebSEmmanuel Grumbach struct ieee80211_vif *vif, 30466d19a5ebSEmmanuel Grumbach struct iwl_mvm_sta *mvm_sta) 30476d19a5ebSEmmanuel Grumbach { 30486d19a5ebSEmmanuel Grumbach #if IS_ENABLED(CONFIG_IWLMEI) 30496d19a5ebSEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 30506d19a5ebSEmmanuel Grumbach struct iwl_mei_conn_info conn_info = { 3051f276e20bSJohannes Berg .ssid_len = vif->cfg.ssid_len, 30526d19a5ebSEmmanuel Grumbach .channel = vif->bss_conf.chandef.chan->hw_value, 30536d19a5ebSEmmanuel Grumbach }; 30546d19a5ebSEmmanuel Grumbach 30556d19a5ebSEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 30566d19a5ebSEmmanuel Grumbach return; 30576d19a5ebSEmmanuel Grumbach 30586d19a5ebSEmmanuel Grumbach if (!mvm->mei_registered) 30596d19a5ebSEmmanuel Grumbach return; 30606d19a5ebSEmmanuel Grumbach 30616d19a5ebSEmmanuel Grumbach switch (mvm_sta->pairwise_cipher) { 30626d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_CCMP: 30636d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP; 30646d19a5ebSEmmanuel Grumbach break; 30656d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP: 30666d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP; 30676d19a5ebSEmmanuel Grumbach break; 30686d19a5ebSEmmanuel Grumbach case WLAN_CIPHER_SUITE_GCMP_256: 30696d19a5ebSEmmanuel Grumbach conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256; 30706d19a5ebSEmmanuel Grumbach break; 30716d19a5ebSEmmanuel Grumbach case 0: 30726d19a5ebSEmmanuel Grumbach /* open profile */ 30736d19a5ebSEmmanuel Grumbach break; 30746d19a5ebSEmmanuel Grumbach default: 30756d19a5ebSEmmanuel Grumbach /* cipher not supported, don't send anything to iwlmei */ 30766d19a5ebSEmmanuel Grumbach return; 30776d19a5ebSEmmanuel Grumbach } 30786d19a5ebSEmmanuel Grumbach 30796d19a5ebSEmmanuel Grumbach switch (mvmvif->rekey_data.akm) { 30806d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_SAE & 0xff: 30816d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE; 30826d19a5ebSEmmanuel Grumbach break; 30836d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_PSK & 0xff: 30846d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK; 30856d19a5ebSEmmanuel Grumbach break; 30866d19a5ebSEmmanuel Grumbach case WLAN_AKM_SUITE_8021X & 0xff: 30876d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA; 30886d19a5ebSEmmanuel Grumbach break; 30896d19a5ebSEmmanuel Grumbach case 0: 30906d19a5ebSEmmanuel Grumbach /* open profile */ 30916d19a5ebSEmmanuel Grumbach conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN; 30926d19a5ebSEmmanuel Grumbach break; 30936d19a5ebSEmmanuel Grumbach default: 30946d19a5ebSEmmanuel Grumbach /* auth method / AKM not supported */ 30956d19a5ebSEmmanuel Grumbach /* TODO: All the FT vesions of these? */ 30966d19a5ebSEmmanuel Grumbach return; 30976d19a5ebSEmmanuel Grumbach } 30986d19a5ebSEmmanuel Grumbach 3099f276e20bSJohannes Berg memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len); 31006d19a5ebSEmmanuel Grumbach memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN); 31016d19a5ebSEmmanuel Grumbach 31026d19a5ebSEmmanuel Grumbach /* TODO: add support for collocated AP data */ 31036d19a5ebSEmmanuel Grumbach iwl_mei_host_associated(&conn_info, NULL); 31046d19a5ebSEmmanuel Grumbach #endif 31056d19a5ebSEmmanuel Grumbach } 31066d19a5ebSEmmanuel Grumbach 3107e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 3108e705c121SKalle Valo struct ieee80211_vif *vif, 3109e705c121SKalle Valo struct ieee80211_sta *sta, 3110e705c121SKalle Valo enum ieee80211_sta_state old_state, 3111e705c121SKalle Valo enum ieee80211_sta_state new_state) 3112e705c121SKalle Valo { 3113e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3114e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 31156ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3116e705c121SKalle Valo int ret; 3117e705c121SKalle Valo 3118e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 3119e705c121SKalle Valo sta->addr, old_state, new_state); 3120e705c121SKalle Valo 3121e705c121SKalle Valo /* this would be a mac80211 bug ... but don't crash */ 3122e705c121SKalle Valo if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) 3123fe56d05eSSara Sharon return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL; 3124e705c121SKalle Valo 312524afba76SLiad Kaufman /* 312624afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 312724afba76SLiad Kaufman * 312824afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 312924afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 313024afba76SLiad Kaufman * the queues. 313124afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 313224afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 313324afba76SLiad Kaufman * of. 313424afba76SLiad Kaufman * 313524afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 313624afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 313724afba76SLiad Kaufman */ 313824afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 3139c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 314024afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 314124afba76SLiad Kaufman 314224afba76SLiad Kaufman /* 314324afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 314424afba76SLiad Kaufman * worker will already remove it if it was on 314524afba76SLiad Kaufman */ 3146f7d6ef33SJohannes Berg 3147f7d6ef33SJohannes Berg /* 3148f7d6ef33SJohannes Berg * Additionally, reset the 40 MHz capability if we disconnected 3149f7d6ef33SJohannes Berg * from the AP now. 3150f7d6ef33SJohannes Berg */ 3151f7d6ef33SJohannes Berg iwl_mvm_reset_cca_40mhz_workaround(mvm, vif); 315224afba76SLiad Kaufman } 315324afba76SLiad Kaufman 3154e705c121SKalle Valo mutex_lock(&mvm->mutex); 31556ea29ce5SJohannes Berg /* track whether or not the station is associated */ 3156d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 31576ea29ce5SJohannes Berg 3158e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3159e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3160e705c121SKalle Valo /* 3161e705c121SKalle Valo * Firmware bug - it'll crash if the beacon interval is less 3162e705c121SKalle Valo * than 16. We can't avoid connecting at all, so refuse the 3163e705c121SKalle Valo * station state change, this will cause mac80211 to abandon 3164e705c121SKalle Valo * attempts to connect to this AP, and eventually wpa_s will 3165cdaba917SEmmanuel Grumbach * blocklist the AP... 3166e705c121SKalle Valo */ 3167e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3168e705c121SKalle Valo vif->bss_conf.beacon_int < 16) { 3169e705c121SKalle Valo IWL_ERR(mvm, 3170e705c121SKalle Valo "AP %pM beacon interval is %d, refusing due to firmware bug!\n", 3171e705c121SKalle Valo sta->addr, vif->bss_conf.beacon_int); 3172e705c121SKalle Valo ret = -EINVAL; 3173e705c121SKalle Valo goto out_unlock; 3174e705c121SKalle Valo } 3175e705c121SKalle Valo 317697cc1694SAvraham Stern if (vif->type == NL80211_IFTYPE_STATION) 3177046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 317897cc1694SAvraham Stern 3179e705c121SKalle Valo if (sta->tdls && 3180e705c121SKalle Valo (vif->p2p || 3181e705c121SKalle Valo iwl_mvm_tdls_sta_count(mvm, NULL) == 3182e705c121SKalle Valo IWL_MVM_TDLS_STA_COUNT || 3183e705c121SKalle Valo iwl_mvm_phy_ctx_count(mvm) > 1)) { 3184e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 3185e705c121SKalle Valo ret = -EBUSY; 3186e705c121SKalle Valo goto out_unlock; 3187e705c121SKalle Valo } 3188e705c121SKalle Valo 3189e705c121SKalle Valo ret = iwl_mvm_add_sta(mvm, vif, sta); 31901e8f1329SGolan Ben-Ami if (sta->tdls && ret == 0) { 3191e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, true); 31921e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 31931e8f1329SGolan Ben-Ami NL80211_TDLS_SETUP); 31941e8f1329SGolan Ben-Ami } 3195438af969SSara Sharon 3196*4c51541dSBenjamin Berg sta->deflink.agg.max_rc_amsdu_len = 1; 3197e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3198e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 3199e705c121SKalle Valo /* 3200e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 3201e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 3202e705c121SKalle Valo */ 3203e705c121SKalle Valo mvm->last_ebs_successful = true; 3204e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 3205e705c121SKalle Valo ret = 0; 3206e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3207e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 32088be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 3209046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 32108be30c13SAyala Beker mvmvif->ap_assoc_sta_count++; 32118be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 321202221a81SShaul Triebitz if (vif->bss_conf.he_support && 321302221a81SShaul Triebitz !iwlwifi_mod_params.disable_11ax) 321402221a81SShaul Triebitz iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id); 32159394662aSLiad Kaufman } else if (vif->type == NL80211_IFTYPE_STATION) { 3216046d2e7cSSriram R vif->bss_conf.he_support = sta->deflink.he_cap.has_he; 32174f58121dSIlan Peer 32184f58121dSIlan Peer mvmvif->he_ru_2mhz_block = false; 3219046d2e7cSSriram R if (sta->deflink.he_cap.has_he) 32204f58121dSIlan Peer iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif); 32214f58121dSIlan Peer 32229394662aSLiad Kaufman iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 32238be30c13SAyala Beker } 3224735a0045SGoodstein, Mordechay 32253baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 32263baf7528SAvraham Stern false); 3227735a0045SGoodstein, Mordechay ret = iwl_mvm_update_sta(mvm, vif, sta); 3228e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3229e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 323028916a16SEmmanuel Grumbach ret = 0; 3231e705c121SKalle Valo 3232e705c121SKalle Valo /* we don't support TDLS during DCM */ 3233e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 3234e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3235e705c121SKalle Valo 32364634b176SJohannes Berg if (sta->tdls) { 32371e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 32381e8f1329SGolan Ben-Ami NL80211_TDLS_ENABLE_LINK); 32394634b176SJohannes Berg } else { 3240e705c121SKalle Valo /* enable beacon filtering */ 3241e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 32426b7a5aeaSNaftali Goldstein 32438b75858cSJohannes Berg mvmvif->authorized = 1; 32448b75858cSJohannes Berg 324550f56044SIlan Peer /* 324650f56044SIlan Peer * Now that the station is authorized, i.e., keys were already 324750f56044SIlan Peer * installed, need to indicate to the FW that 324850f56044SIlan Peer * multicast data frames can be forwarded to the driver 324950f56044SIlan Peer */ 325050f56044SIlan Peer iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 32516d19a5ebSEmmanuel Grumbach iwl_mvm_mei_host_associated(mvm, vif, mvm_sta); 32524634b176SJohannes Berg } 325350f56044SIlan Peer 32543baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 32553baf7528SAvraham Stern true); 3256e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 3257e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 3258d9e95e35SMordechay Goodstein /* once we move into assoc state, need to update rate scale to 3259d9e95e35SMordechay Goodstein * disable using wide bandwidth 3260d9e95e35SMordechay Goodstein */ 3261d9e95e35SMordechay Goodstein iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 3262d9e95e35SMordechay Goodstein false); 32634634b176SJohannes Berg if (!sta->tdls) { 326450f56044SIlan Peer /* Multicast data frames are no longer allowed */ 326550f56044SIlan Peer iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 326650f56044SIlan Peer 32678b75858cSJohannes Berg /* 32688b75858cSJohannes Berg * Set this after the above iwl_mvm_mac_ctxt_changed() 32698b75858cSJohannes Berg * to avoid sending high prio again for a little time. 32708b75858cSJohannes Berg */ 32718b75858cSJohannes Berg mvmvif->authorized = 0; 32728b75858cSJohannes Berg 3273e705c121SKalle Valo /* disable beacon filtering */ 327469e508b4SIlan Peer ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 327569e508b4SIlan Peer WARN_ON(ret && 327669e508b4SIlan Peer !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 327769e508b4SIlan Peer &mvm->status)); 32784634b176SJohannes Berg } 3279e705c121SKalle Valo ret = 0; 3280e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3281e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 32828be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 32838be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 32848be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3285d5d8ee52SEmmanuel Grumbach } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3286cf7a7457SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 3287e705c121SKalle Valo ret = 0; 3288e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3289e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3290e705c121SKalle Valo ret = 0; 3291e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3292e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 3293d5d8ee52SEmmanuel Grumbach if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) 3294d5d8ee52SEmmanuel Grumbach iwl_mvm_stop_session_protection(mvm, vif); 3295e705c121SKalle Valo ret = iwl_mvm_rm_sta(mvm, vif, sta); 32961e8f1329SGolan Ben-Ami if (sta->tdls) { 3297e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 32981e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 32991e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 33001e8f1329SGolan Ben-Ami } 330134a880d8SLiad Kaufman 330244135b7cSIlan Peer if (unlikely(ret && 330344135b7cSIlan Peer test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 330444135b7cSIlan Peer &mvm->status))) 330544135b7cSIlan Peer ret = 0; 3306e705c121SKalle Valo } else { 3307e705c121SKalle Valo ret = -EIO; 3308e705c121SKalle Valo } 3309e705c121SKalle Valo out_unlock: 3310e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3311e705c121SKalle Valo 3312e705c121SKalle Valo if (sta->tdls && ret == 0) { 3313e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3314e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 3315e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3316e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 3317e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 3318e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3319e705c121SKalle Valo } 3320e705c121SKalle Valo 3321e705c121SKalle Valo return ret; 3322e705c121SKalle Valo } 3323e705c121SKalle Valo 3324e705c121SKalle Valo static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3325e705c121SKalle Valo { 3326e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3327e705c121SKalle Valo 3328e705c121SKalle Valo mvm->rts_threshold = value; 3329e705c121SKalle Valo 3330e705c121SKalle Valo return 0; 3331e705c121SKalle Valo } 3332e705c121SKalle Valo 3333e705c121SKalle Valo static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, 3334e705c121SKalle Valo struct ieee80211_vif *vif, 3335e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 3336e705c121SKalle Valo { 3337e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3338dcfe3b10SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3339dcfe3b10SJohannes Berg 3340dcfe3b10SJohannes Berg if (changed & (IEEE80211_RC_BW_CHANGED | 3341dcfe3b10SJohannes Berg IEEE80211_RC_SUPP_RATES_CHANGED | 3342dcfe3b10SJohannes Berg IEEE80211_RC_NSS_CHANGED)) 3343dcfe3b10SJohannes Berg iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 3344dcfe3b10SJohannes Berg true); 3345e705c121SKalle Valo 3346e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3347e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 3348e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 3349e705c121SKalle Valo } 3350e705c121SKalle Valo 3351e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 3352b3e2130bSJohannes Berg struct ieee80211_vif *vif, 3353b3e2130bSJohannes Berg unsigned int link_id, u16 ac, 3354e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 3355e705c121SKalle Valo { 3356e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3357e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3358e705c121SKalle Valo 3359e705c121SKalle Valo mvmvif->queue_params[ac] = *params; 3360e705c121SKalle Valo 3361e705c121SKalle Valo /* 3362e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 3363e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 3364e705c121SKalle Valo */ 3365e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 3366e705c121SKalle Valo int ret; 3367e705c121SKalle Valo 3368e705c121SKalle Valo mutex_lock(&mvm->mutex); 3369e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3370e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3371e705c121SKalle Valo return ret; 3372e705c121SKalle Valo } 3373e705c121SKalle Valo return 0; 3374e705c121SKalle Valo } 3375e705c121SKalle Valo 3376e705c121SKalle Valo static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 3377d4e36e55SIlan Peer struct ieee80211_vif *vif, 337815fae341SJohannes Berg struct ieee80211_prep_tx_info *info) 3379e705c121SKalle Valo { 3380e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3381d4e36e55SIlan Peer 3382e705c121SKalle Valo mutex_lock(&mvm->mutex); 3383af84ac57SJohannes Berg iwl_mvm_protect_assoc(mvm, vif, info->duration); 3384e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3385e705c121SKalle Valo } 3386e705c121SKalle Valo 33876b1259d1SJohannes Berg static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw, 33886b1259d1SJohannes Berg struct ieee80211_vif *vif, 33896b1259d1SJohannes Berg struct ieee80211_prep_tx_info *info) 33906b1259d1SJohannes Berg { 33916b1259d1SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 33926b1259d1SJohannes Berg 33936b1259d1SJohannes Berg /* for successful cases (auth/assoc), don't cancel session protection */ 33946b1259d1SJohannes Berg if (info->success) 33956b1259d1SJohannes Berg return; 33966b1259d1SJohannes Berg 33976b1259d1SJohannes Berg mutex_lock(&mvm->mutex); 33986b1259d1SJohannes Berg iwl_mvm_stop_session_protection(mvm, vif); 33996b1259d1SJohannes Berg mutex_unlock(&mvm->mutex); 34006b1259d1SJohannes Berg } 34016b1259d1SJohannes Berg 3402e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 3403e705c121SKalle Valo struct ieee80211_vif *vif, 3404e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 3405e705c121SKalle Valo struct ieee80211_scan_ies *ies) 3406e705c121SKalle Valo { 3407e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3408e705c121SKalle Valo 3409e705c121SKalle Valo int ret; 3410e705c121SKalle Valo 3411e705c121SKalle Valo mutex_lock(&mvm->mutex); 3412e705c121SKalle Valo 3413f276e20bSJohannes Berg if (!vif->cfg.idle) { 3414e705c121SKalle Valo ret = -EBUSY; 3415e705c121SKalle Valo goto out; 3416e705c121SKalle Valo } 3417e705c121SKalle Valo 3418e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 3419e705c121SKalle Valo 3420e705c121SKalle Valo out: 3421e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3422e705c121SKalle Valo return ret; 3423e705c121SKalle Valo } 3424e705c121SKalle Valo 3425e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 3426e705c121SKalle Valo struct ieee80211_vif *vif) 3427e705c121SKalle Valo { 3428e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3429e705c121SKalle Valo int ret; 3430e705c121SKalle Valo 3431e705c121SKalle Valo mutex_lock(&mvm->mutex); 3432e705c121SKalle Valo 3433e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3434e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 3435e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 3436e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 3437e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 3438e705c121SKalle Valo * could run. To handle this, simply return if the scan is 3439e705c121SKalle Valo * not running. 3440e705c121SKalle Valo */ 3441e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 3442e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3443e705c121SKalle Valo return 0; 3444e705c121SKalle Valo } 3445e705c121SKalle Valo 3446e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 3447e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3448e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 3449e705c121SKalle Valo 3450e705c121SKalle Valo return ret; 3451e705c121SKalle Valo } 3452e705c121SKalle Valo 34536569e7d3SJohannes Berg static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 3454e705c121SKalle Valo enum set_key_cmd cmd, 3455e705c121SKalle Valo struct ieee80211_vif *vif, 3456e705c121SKalle Valo struct ieee80211_sta *sta, 3457e705c121SKalle Valo struct ieee80211_key_conf *key) 3458e705c121SKalle Valo { 3459c56e00a3SJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3460e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 346146c7b05aSEmmanuel Grumbach struct iwl_mvm_sta *mvmsta = NULL; 3462f5e28eacSJohannes Berg struct iwl_mvm_key_pn *ptk_pn; 3463f5e28eacSJohannes Berg int keyidx = key->keyidx; 3464c56e00a3SJohannes Berg int ret, i; 34654615fd15SEmmanuel Grumbach u8 key_offset; 3466e705c121SKalle Valo 346746c7b05aSEmmanuel Grumbach if (sta) 34686d19a5ebSEmmanuel Grumbach mvmsta = iwl_mvm_sta_from_mac80211(sta); 34696d19a5ebSEmmanuel Grumbach 3470e705c121SKalle Valo switch (key->cipher) { 3471e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 3472286ca8ebSLuca Coelho if (!mvm->trans->trans_cfg->gen2) { 3473e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 34741ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 34757f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 34767f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 34777f768ad5SDavid Spinadel } else { 34787f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 34797f768ad5SDavid Spinadel return -EOPNOTSUPP; 34807f768ad5SDavid Spinadel } 3481e705c121SKalle Valo break; 3482e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 34832a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 34842a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 348585aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 3486e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3487e705c121SKalle Valo break; 3488e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 34898e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 34908e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3491e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 3492e705c121SKalle Valo break; 3493e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 3494e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 3495475c6bdeSJohannes Berg if (vif->type == NL80211_IFTYPE_STATION) 3496e705c121SKalle Valo break; 3497475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 3498475c6bdeSJohannes Berg return -EOPNOTSUPP; 3499475c6bdeSJohannes Berg /* support HW crypto on TX */ 3500475c6bdeSJohannes Berg return 0; 3501e705c121SKalle Valo default: 3502e705c121SKalle Valo return -EOPNOTSUPP; 3503e705c121SKalle Valo } 3504e705c121SKalle Valo 3505e705c121SKalle Valo switch (cmd) { 3506e705c121SKalle Valo case SET_KEY: 3507b1fdc250SJohannes Berg if (keyidx == 6 || keyidx == 7) 3508b1fdc250SJohannes Berg rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], 3509b1fdc250SJohannes Berg key); 3510b1fdc250SJohannes Berg 3511e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 3512e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 3513e705c121SKalle Valo /* 3514e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 3515e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 3516e705c121SKalle Valo * we don't support them for RX, so do the same. 35178e160ab8SAyala Beker * CMAC/GMAC in AP/IBSS modes must be done in software. 3518e705c121SKalle Valo */ 35198e160ab8SAyala Beker if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 35208e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 3521a1c2ff30SAndrei Otcheretianski key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { 352281279c49SJohannes Berg ret = -EOPNOTSUPP; 3523a1c2ff30SAndrei Otcheretianski break; 3524a1c2ff30SAndrei Otcheretianski } 352585aeb58cSDavid Spinadel 352685aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 352785aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 352885aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 3529e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 3530a1c2ff30SAndrei Otcheretianski ret = 0; 3531e705c121SKalle Valo break; 3532e705c121SKalle Valo } 3533c56e00a3SJohannes Berg 3534c56e00a3SJohannes Berg if (!mvmvif->ap_ibss_active) { 3535c56e00a3SJohannes Berg for (i = 0; 3536c56e00a3SJohannes Berg i < ARRAY_SIZE(mvmvif->ap_early_keys); 3537c56e00a3SJohannes Berg i++) { 3538c56e00a3SJohannes Berg if (!mvmvif->ap_early_keys[i]) { 3539c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = key; 3540c56e00a3SJohannes Berg break; 3541c56e00a3SJohannes Berg } 3542c56e00a3SJohannes Berg } 3543c56e00a3SJohannes Berg 3544c56e00a3SJohannes Berg if (i >= ARRAY_SIZE(mvmvif->ap_early_keys)) 3545c56e00a3SJohannes Berg ret = -ENOSPC; 3546a1c2ff30SAndrei Otcheretianski else 3547a1c2ff30SAndrei Otcheretianski ret = 0; 3548c56e00a3SJohannes Berg 3549c56e00a3SJohannes Berg break; 3550c56e00a3SJohannes Berg } 355185aeb58cSDavid Spinadel } 3552e705c121SKalle Valo 3553e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 3554e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 3555e705c121SKalle Valo */ 3556e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 3557e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 3558e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 3559e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 3560e705c121SKalle Valo ret = 0; 3561e705c121SKalle Valo break; 3562e705c121SKalle Valo } 3563e705c121SKalle Valo 3564f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 356546c7b05aSEmmanuel Grumbach mvmsta && iwl_mvm_has_new_rx_api(mvm) && 3566f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3567f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 35682a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 35692a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3570f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 3571f5e28eacSJohannes Berg int tid, q; 3572f5e28eacSJohannes Berg 3573f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 3574acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 3575acafe7e3SKees Cook mvm->trans->num_rx_queues), 3576f5e28eacSJohannes Berg GFP_KERNEL); 3577f5e28eacSJohannes Berg if (!ptk_pn) { 3578f5e28eacSJohannes Berg ret = -ENOMEM; 3579f5e28eacSJohannes Berg break; 3580f5e28eacSJohannes Berg } 3581f5e28eacSJohannes Berg 3582f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 3583f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 3584f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 3585f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 3586f5e28eacSJohannes Berg seq.ccmp.pn, 3587f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 3588f5e28eacSJohannes Berg } 3589f5e28eacSJohannes Berg 3590f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 3591f5e28eacSJohannes Berg } 3592f5e28eacSJohannes Berg 35934615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 35944615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 35954615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 35964615fd15SEmmanuel Grumbach else 35974615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 35984615fd15SEmmanuel Grumbach 359946c7b05aSEmmanuel Grumbach if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE) 36006d19a5ebSEmmanuel Grumbach mvmsta->pairwise_cipher = key->cipher; 36016d19a5ebSEmmanuel Grumbach 3602e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); 36034615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 3604e705c121SKalle Valo if (ret) { 3605e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 3606475c6bdeSJohannes Berg key->hw_key_idx = STA_KEY_IDX_INVALID; 3607e705c121SKalle Valo /* 3608e705c121SKalle Valo * can't add key for RX, but we don't need it 3609475c6bdeSJohannes Berg * in the device for TX so still return 0, 3610475c6bdeSJohannes Berg * unless we have new TX API where we cannot 3611475c6bdeSJohannes Berg * put key material into the TX_CMD 3612e705c121SKalle Valo */ 3613475c6bdeSJohannes Berg if (iwl_mvm_has_new_tx_api(mvm)) 3614475c6bdeSJohannes Berg ret = -EOPNOTSUPP; 3615475c6bdeSJohannes Berg else 3616e705c121SKalle Valo ret = 0; 3617e705c121SKalle Valo } 3618e705c121SKalle Valo 3619e705c121SKalle Valo break; 3620e705c121SKalle Valo case DISABLE_KEY: 3621b1fdc250SJohannes Berg if (keyidx == 6 || keyidx == 7) 3622b1fdc250SJohannes Berg RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6], 3623b1fdc250SJohannes Berg NULL); 3624b1fdc250SJohannes Berg 3625c56e00a3SJohannes Berg ret = -ENOENT; 3626c56e00a3SJohannes Berg for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { 3627c56e00a3SJohannes Berg if (mvmvif->ap_early_keys[i] == key) { 3628c56e00a3SJohannes Berg mvmvif->ap_early_keys[i] = NULL; 3629c56e00a3SJohannes Berg ret = 0; 3630c56e00a3SJohannes Berg } 3631c56e00a3SJohannes Berg } 3632c56e00a3SJohannes Berg 3633c56e00a3SJohannes Berg /* found in pending list - don't do anything else */ 3634c56e00a3SJohannes Berg if (ret == 0) 3635c56e00a3SJohannes Berg break; 3636c56e00a3SJohannes Berg 3637e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 3638e705c121SKalle Valo ret = 0; 3639e705c121SKalle Valo break; 3640e705c121SKalle Valo } 3641e705c121SKalle Valo 364246c7b05aSEmmanuel Grumbach if (mvmsta && iwl_mvm_has_new_rx_api(mvm) && 3643f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3644f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 36452a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 36462a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3647f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 3648f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 3649f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 3650f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 3651f5e28eacSJohannes Berg if (ptk_pn) 3652f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 3653f5e28eacSJohannes Berg } 3654f5e28eacSJohannes Berg 3655e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 3656e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 3657e705c121SKalle Valo break; 3658e705c121SKalle Valo default: 3659e705c121SKalle Valo ret = -EINVAL; 3660e705c121SKalle Valo } 3661e705c121SKalle Valo 36626569e7d3SJohannes Berg return ret; 36636569e7d3SJohannes Berg } 36646569e7d3SJohannes Berg 36656569e7d3SJohannes Berg static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 36666569e7d3SJohannes Berg enum set_key_cmd cmd, 36676569e7d3SJohannes Berg struct ieee80211_vif *vif, 36686569e7d3SJohannes Berg struct ieee80211_sta *sta, 36696569e7d3SJohannes Berg struct ieee80211_key_conf *key) 36706569e7d3SJohannes Berg { 36716569e7d3SJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 36726569e7d3SJohannes Berg int ret; 36736569e7d3SJohannes Berg 36746569e7d3SJohannes Berg mutex_lock(&mvm->mutex); 36756569e7d3SJohannes Berg ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key); 3676e705c121SKalle Valo mutex_unlock(&mvm->mutex); 36776569e7d3SJohannes Berg 3678e705c121SKalle Valo return ret; 3679e705c121SKalle Valo } 3680e705c121SKalle Valo 3681e705c121SKalle Valo static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 3682e705c121SKalle Valo struct ieee80211_vif *vif, 3683e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 3684e705c121SKalle Valo struct ieee80211_sta *sta, 3685e705c121SKalle Valo u32 iv32, u16 *phase1key) 3686e705c121SKalle Valo { 3687e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3688e705c121SKalle Valo 3689e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 3690e705c121SKalle Valo return; 3691e705c121SKalle Valo 3692e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 3693e705c121SKalle Valo } 3694e705c121SKalle Valo 3695e705c121SKalle Valo 3696e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 3697e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 3698e705c121SKalle Valo { 3699e705c121SKalle Valo struct iwl_mvm *mvm = 3700e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 3701e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 3702e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 3703e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 3704e705c121SKalle Valo 3705e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 3706e705c121SKalle Valo return true; 3707e705c121SKalle Valo 3708e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 3709e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 3710e705c121SKalle Valo return true; 3711e705c121SKalle Valo } 3712e705c121SKalle Valo 3713e705c121SKalle Valo resp = (void *)pkt->data; 3714e705c121SKalle Valo 3715e705c121SKalle Valo IWL_DEBUG_TE(mvm, 3716b71a9c35SColin Ian King "Aux ROC: Received response from ucode: status=%d uid=%d\n", 3717e705c121SKalle Valo resp->status, resp->event_unique_id); 3718e705c121SKalle Valo 3719e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 3720e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 3721e705c121SKalle Valo te_data->uid); 3722e705c121SKalle Valo 3723e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3724e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 3725e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3726e705c121SKalle Valo 3727e705c121SKalle Valo return true; 3728e705c121SKalle Valo } 3729e705c121SKalle Valo 3730dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) 3731dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) 3732dc28e12fSMatti Gottlieb #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) 3733dc28e12fSMatti Gottlieb #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) 3734dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) 3735e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 3736e705c121SKalle Valo struct ieee80211_channel *channel, 3737e705c121SKalle Valo struct ieee80211_vif *vif, 3738e705c121SKalle Valo int duration) 3739e705c121SKalle Valo { 3740afc1e3b4SAvraham Stern int res; 3741e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3742e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 3743e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 3744e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 3745dc28e12fSMatti Gottlieb u32 dtim_interval = vif->bss_conf.dtim_period * 3746dc28e12fSMatti Gottlieb vif->bss_conf.beacon_int; 3747dc28e12fSMatti Gottlieb u32 req_dur, delay; 3748e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 3749e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 3750e705c121SKalle Valo .id_and_color = 3751e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 3752e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 3753e705c121SKalle Valo }; 375457e861d9SDavid Spinadel struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm, 375557e861d9SDavid Spinadel &aux_roc_req.channel_info); 375657e861d9SDavid Spinadel u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm); 375757e861d9SDavid Spinadel 375857e861d9SDavid Spinadel /* Set the channel info data */ 375957e861d9SDavid Spinadel iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value, 37603717f91aSTova Mussai iwl_mvm_phy_band_from_nl80211(channel->band), 376157e861d9SDavid Spinadel PHY_VHT_CHANNEL_MODE20, 376257e861d9SDavid Spinadel 0); 376357e861d9SDavid Spinadel 376457e861d9SDavid Spinadel /* Set the time and duration */ 3765afc1e3b4SAvraham Stern tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm)); 3766e705c121SKalle Valo 3767dc28e12fSMatti Gottlieb delay = AUX_ROC_MIN_DELAY; 3768dc28e12fSMatti Gottlieb req_dur = MSEC_TO_TU(duration); 3769dc28e12fSMatti Gottlieb 3770dc28e12fSMatti Gottlieb /* 3771dc28e12fSMatti Gottlieb * If we are associated we want the delay time to be at least one 3772dc28e12fSMatti Gottlieb * dtim interval so that the FW can wait until after the DTIM and 3773dc28e12fSMatti Gottlieb * then start the time event, this will potentially allow us to 3774dc28e12fSMatti Gottlieb * remain off-channel for the max duration. 3775dc28e12fSMatti Gottlieb * Since we want to use almost a whole dtim interval we would also 3776dc28e12fSMatti Gottlieb * like the delay to be for 2-3 dtim intervals, in case there are 3777dc28e12fSMatti Gottlieb * other time events with higher priority. 3778dc28e12fSMatti Gottlieb */ 3779f276e20bSJohannes Berg if (vif->cfg.assoc) { 3780dc28e12fSMatti Gottlieb delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); 3781dc28e12fSMatti Gottlieb /* We cannot remain off-channel longer than the DTIM interval */ 3782dc28e12fSMatti Gottlieb if (dtim_interval <= req_dur) { 3783dc28e12fSMatti Gottlieb req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; 3784dc28e12fSMatti Gottlieb if (req_dur <= AUX_ROC_MIN_DURATION) 3785dc28e12fSMatti Gottlieb req_dur = dtim_interval - 3786dc28e12fSMatti Gottlieb AUX_ROC_MIN_SAFETY_BUFFER; 3787dc28e12fSMatti Gottlieb } 3788dc28e12fSMatti Gottlieb } 3789dc28e12fSMatti Gottlieb 379057e861d9SDavid Spinadel tail->duration = cpu_to_le32(req_dur); 379157e861d9SDavid Spinadel tail->apply_time_max_delay = cpu_to_le32(delay); 3792dc28e12fSMatti Gottlieb 3793dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 3794903b3f9bSEmmanuel Grumbach "ROC: Requesting to remain on channel %u for %ums\n", 3795903b3f9bSEmmanuel Grumbach channel->hw_value, req_dur); 3796903b3f9bSEmmanuel Grumbach IWL_DEBUG_TE(mvm, 3797903b3f9bSEmmanuel Grumbach "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", 3798903b3f9bSEmmanuel Grumbach duration, delay, dtim_interval); 3799903b3f9bSEmmanuel Grumbach 3800e705c121SKalle Valo /* Set the node address */ 380157e861d9SDavid Spinadel memcpy(tail->node_addr, vif->addr, ETH_ALEN); 3802e705c121SKalle Valo 3803e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3804e705c121SKalle Valo 3805e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3806e705c121SKalle Valo 3807e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 3808e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3809e705c121SKalle Valo return -EIO; 3810e705c121SKalle Valo } 3811e705c121SKalle Valo 3812e705c121SKalle Valo te_data->vif = vif; 3813e705c121SKalle Valo te_data->duration = duration; 3814e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 3815e705c121SKalle Valo 3816e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3817e705c121SKalle Valo 3818e705c121SKalle Valo /* 3819e705c121SKalle Valo * Use a notification wait, which really just processes the 3820e705c121SKalle Valo * command response and doesn't wait for anything, in order 3821e705c121SKalle Valo * to be able to process the response and get the UID inside 3822e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 3823e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 3824e705c121SKalle Valo * time another notification (that the time event started) 3825e705c121SKalle Valo * might already be processed unsuccessfully. 3826e705c121SKalle Valo */ 3827e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 3828e705c121SKalle Valo time_event_response, 3829e705c121SKalle Valo ARRAY_SIZE(time_event_response), 3830e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 3831e705c121SKalle Valo 383257e861d9SDavid Spinadel res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len, 3833e705c121SKalle Valo &aux_roc_req); 3834e705c121SKalle Valo 3835e705c121SKalle Valo if (res) { 3836e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 3837e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 3838e705c121SKalle Valo goto out_clear_te; 3839e705c121SKalle Valo } 3840e705c121SKalle Valo 3841e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 3842e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 3843e705c121SKalle Valo /* should never fail */ 3844e705c121SKalle Valo WARN_ON_ONCE(res); 3845e705c121SKalle Valo 3846e705c121SKalle Valo if (res) { 3847e705c121SKalle Valo out_clear_te: 3848e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3849e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 3850e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3851e705c121SKalle Valo } 3852e705c121SKalle Valo 3853e705c121SKalle Valo return res; 3854e705c121SKalle Valo } 3855e705c121SKalle Valo 3856e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 3857e705c121SKalle Valo struct ieee80211_vif *vif, 3858e705c121SKalle Valo struct ieee80211_channel *channel, 3859e705c121SKalle Valo int duration, 3860e705c121SKalle Valo enum ieee80211_roc_type type) 3861e705c121SKalle Valo { 3862e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3863e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3864e705c121SKalle Valo struct cfg80211_chan_def chandef; 3865e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 38668835a64fSJohannes Berg bool band_change_removal; 3867e705c121SKalle Valo int ret, i; 3868e705c121SKalle Valo 3869e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 3870e705c121SKalle Valo duration, type); 3871e705c121SKalle Valo 38729834781cSJohannes Berg /* 38739834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 38749834781cSJohannes Berg * the work it does can complete and we can accept new frames. 38759834781cSJohannes Berg */ 3876e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 3877e705c121SKalle Valo 3878e705c121SKalle Valo mutex_lock(&mvm->mutex); 3879e705c121SKalle Valo 3880e705c121SKalle Valo switch (vif->type) { 3881e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3882e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 3883e705c121SKalle Valo IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 3884e705c121SKalle Valo /* Use aux roc framework (HS20) */ 3885971cbe50SJohannes Berg if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) >= 12) { 38862c2c3647SNathan Errera u32 lmac_id; 38872c2c3647SNathan Errera 38882c2c3647SNathan Errera lmac_id = iwl_mvm_get_lmac_id(mvm->fw, 38892c2c3647SNathan Errera channel->band); 38902c2c3647SNathan Errera ret = iwl_mvm_add_aux_sta(mvm, lmac_id); 38912c2c3647SNathan Errera if (WARN(ret, 38922c2c3647SNathan Errera "Failed to allocate aux station")) 38932c2c3647SNathan Errera goto out_unlock; 38942c2c3647SNathan Errera } 3895e705c121SKalle Valo ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 3896e705c121SKalle Valo vif, duration); 3897e705c121SKalle Valo goto out_unlock; 3898e705c121SKalle Valo } 3899e705c121SKalle Valo IWL_ERR(mvm, "hotspot not supported\n"); 3900e705c121SKalle Valo ret = -EINVAL; 3901e705c121SKalle Valo goto out_unlock; 3902e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 3903e705c121SKalle Valo /* handle below */ 3904e705c121SKalle Valo break; 3905e705c121SKalle Valo default: 3906e705c121SKalle Valo IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); 3907e705c121SKalle Valo ret = -EINVAL; 3908e705c121SKalle Valo goto out_unlock; 3909e705c121SKalle Valo } 3910e705c121SKalle Valo 3911e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 3912e705c121SKalle Valo phy_ctxt = &mvm->phy_ctxts[i]; 3913e705c121SKalle Valo if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) 3914e705c121SKalle Valo continue; 3915e705c121SKalle Valo 3916e705c121SKalle Valo if (phy_ctxt->ref && channel == phy_ctxt->channel) { 3917e705c121SKalle Valo /* 3918e705c121SKalle Valo * Unbind the P2P_DEVICE from the current PHY context, 3919e705c121SKalle Valo * and if the PHY context is not used remove it. 3920e705c121SKalle Valo */ 3921e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3922e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3923e705c121SKalle Valo goto out_unlock; 3924e705c121SKalle Valo 3925e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3926e705c121SKalle Valo 3927e705c121SKalle Valo /* Bind the P2P_DEVICE to the current PHY Context */ 3928e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3929e705c121SKalle Valo 3930e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3931e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3932e705c121SKalle Valo goto out_unlock; 3933e705c121SKalle Valo 3934e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3935e705c121SKalle Valo goto schedule_time_event; 3936e705c121SKalle Valo } 3937e705c121SKalle Valo } 3938e705c121SKalle Valo 3939e705c121SKalle Valo /* Need to update the PHY context only if the ROC channel changed */ 3940e705c121SKalle Valo if (channel == mvmvif->phy_ctxt->channel) 3941e705c121SKalle Valo goto schedule_time_event; 3942e705c121SKalle Valo 3943e705c121SKalle Valo cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 3944e705c121SKalle Valo 3945e705c121SKalle Valo /* 39468835a64fSJohannes Berg * Check if the remain-on-channel is on a different band and that 39478835a64fSJohannes Berg * requires context removal, see iwl_mvm_phy_ctxt_changed(). If 39488835a64fSJohannes Berg * so, we'll need to release and then re-configure here, since we 39498835a64fSJohannes Berg * must not remove a PHY context that's part of a binding. 3950e705c121SKalle Valo */ 39518835a64fSJohannes Berg band_change_removal = 39528835a64fSJohannes Berg fw_has_capa(&mvm->fw->ucode_capa, 39538835a64fSJohannes Berg IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) && 39548835a64fSJohannes Berg mvmvif->phy_ctxt->channel->band != chandef.chan->band; 39558835a64fSJohannes Berg 39568835a64fSJohannes Berg if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) { 39578835a64fSJohannes Berg /* 39588835a64fSJohannes Berg * Change the PHY context configuration as it is currently 39598835a64fSJohannes Berg * referenced only by the P2P Device MAC (and we can modify it) 39608835a64fSJohannes Berg */ 3961e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, 3962e705c121SKalle Valo &chandef, 1, 1); 3963e705c121SKalle Valo if (ret) 3964e705c121SKalle Valo goto out_unlock; 3965e705c121SKalle Valo } else { 3966e705c121SKalle Valo /* 39678835a64fSJohannes Berg * The PHY context is shared with other MACs (or we're trying to 39688835a64fSJohannes Berg * switch bands), so remove the P2P Device from the binding, 39698835a64fSJohannes Berg * allocate an new PHY context and create a new binding. 3970e705c121SKalle Valo */ 3971e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 3972e705c121SKalle Valo if (!phy_ctxt) { 3973e705c121SKalle Valo ret = -ENOSPC; 3974e705c121SKalle Valo goto out_unlock; 3975e705c121SKalle Valo } 3976e705c121SKalle Valo 3977e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, 3978e705c121SKalle Valo 1, 1); 3979e705c121SKalle Valo if (ret) { 3980e705c121SKalle Valo IWL_ERR(mvm, "Failed to change PHY context\n"); 3981e705c121SKalle Valo goto out_unlock; 3982e705c121SKalle Valo } 3983e705c121SKalle Valo 3984e705c121SKalle Valo /* Unbind the P2P_DEVICE from the current PHY context */ 3985e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3986e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3987e705c121SKalle Valo goto out_unlock; 3988e705c121SKalle Valo 3989e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3990e705c121SKalle Valo 3991e705c121SKalle Valo /* Bind the P2P_DEVICE to the new allocated PHY context */ 3992e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3993e705c121SKalle Valo 3994e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3995e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3996e705c121SKalle Valo goto out_unlock; 3997e705c121SKalle Valo 3998e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3999e705c121SKalle Valo } 4000e705c121SKalle Valo 4001e705c121SKalle Valo schedule_time_event: 4002e705c121SKalle Valo /* Schedule the time events */ 4003e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 4004e705c121SKalle Valo 4005e705c121SKalle Valo out_unlock: 4006e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4007e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4008e705c121SKalle Valo return ret; 4009e705c121SKalle Valo } 4010e705c121SKalle Valo 40115db4c4b9SEmmanuel Grumbach static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw, 40125db4c4b9SEmmanuel Grumbach struct ieee80211_vif *vif) 4013e705c121SKalle Valo { 4014e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4015e705c121SKalle Valo 4016e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 4017e705c121SKalle Valo 4018e705c121SKalle Valo mutex_lock(&mvm->mutex); 4019fe959c7bSEmmanuel Grumbach iwl_mvm_stop_roc(mvm, vif); 4020e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4021e705c121SKalle Valo 4022e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 4023e705c121SKalle Valo return 0; 4024e705c121SKalle Valo } 4025e705c121SKalle Valo 4026b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data { 4027b73f9a4aSJohannes Berg bool responder; 4028b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx; 4029b73f9a4aSJohannes Berg }; 4030b73f9a4aSJohannes Berg 4031b73f9a4aSJohannes Berg static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac, 4032b73f9a4aSJohannes Berg struct ieee80211_vif *vif) 4033b73f9a4aSJohannes Berg { 4034b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data *data = _data; 4035b73f9a4aSJohannes Berg 4036d0a9123eSJohannes Berg if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx && 4037b73f9a4aSJohannes Berg vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params) 4038b73f9a4aSJohannes Berg data->responder = true; 4039b73f9a4aSJohannes Berg } 4040b73f9a4aSJohannes Berg 4041b73f9a4aSJohannes Berg static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm, 4042b73f9a4aSJohannes Berg struct ieee80211_chanctx_conf *ctx) 4043b73f9a4aSJohannes Berg { 4044b73f9a4aSJohannes Berg struct iwl_mvm_ftm_responder_iter_data data = { 4045b73f9a4aSJohannes Berg .responder = false, 4046b73f9a4aSJohannes Berg .ctx = ctx, 4047b73f9a4aSJohannes Berg }; 4048b73f9a4aSJohannes Berg 4049b73f9a4aSJohannes Berg ieee80211_iterate_active_interfaces_atomic(mvm->hw, 4050b73f9a4aSJohannes Berg IEEE80211_IFACE_ITER_NORMAL, 4051b73f9a4aSJohannes Berg iwl_mvm_ftm_responder_chanctx_iter, 4052b73f9a4aSJohannes Berg &data); 4053b73f9a4aSJohannes Berg return data.responder; 4054b73f9a4aSJohannes Berg } 4055b73f9a4aSJohannes Berg 4056e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 4057e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4058e705c121SKalle Valo { 4059e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4060e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 4061b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4062b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4063e705c121SKalle Valo int ret; 4064e705c121SKalle Valo 4065e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4066e705c121SKalle Valo 4067e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 4068e705c121SKalle Valo 4069e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 4070e705c121SKalle Valo if (!phy_ctxt) { 4071e705c121SKalle Valo ret = -ENOSPC; 4072e705c121SKalle Valo goto out; 4073e705c121SKalle Valo } 4074e705c121SKalle Valo 4075b73f9a4aSJohannes Berg ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4076e705c121SKalle Valo ctx->rx_chains_static, 4077e705c121SKalle Valo ctx->rx_chains_dynamic); 4078e705c121SKalle Valo if (ret) { 4079e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 4080e705c121SKalle Valo goto out; 4081e705c121SKalle Valo } 4082e705c121SKalle Valo 4083e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); 4084e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 4085e705c121SKalle Valo out: 4086e705c121SKalle Valo return ret; 4087e705c121SKalle Valo } 4088e705c121SKalle Valo 4089e705c121SKalle Valo static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 4090e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4091e705c121SKalle Valo { 4092e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4093e705c121SKalle Valo int ret; 4094e705c121SKalle Valo 4095e705c121SKalle Valo mutex_lock(&mvm->mutex); 4096e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 4097e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4098e705c121SKalle Valo 4099e705c121SKalle Valo return ret; 4100e705c121SKalle Valo } 4101e705c121SKalle Valo 4102e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 4103e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4104e705c121SKalle Valo { 4105e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4106e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4107e705c121SKalle Valo 4108e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4109e705c121SKalle Valo 4110e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 4111e705c121SKalle Valo } 4112e705c121SKalle Valo 4113e705c121SKalle Valo static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 4114e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4115e705c121SKalle Valo { 4116e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4117e705c121SKalle Valo 4118e705c121SKalle Valo mutex_lock(&mvm->mutex); 4119e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 4120e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4121e705c121SKalle Valo } 4122e705c121SKalle Valo 4123e705c121SKalle Valo static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 4124e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4125e705c121SKalle Valo u32 changed) 4126e705c121SKalle Valo { 4127e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4128e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4129e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4130b73f9a4aSJohannes Berg bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx); 4131b73f9a4aSJohannes Berg struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def; 4132e705c121SKalle Valo 4133e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 4134e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 4135e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 4136e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 4137e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 4138e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 4139e705c121SKalle Valo phy_ctxt->ref, changed)) 4140e705c121SKalle Valo return; 4141e705c121SKalle Valo 4142e705c121SKalle Valo mutex_lock(&mvm->mutex); 41437a20bcceSEmmanuel Grumbach 41447a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 41457a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 4146b73f9a4aSJohannes Berg if (phy_ctxt->width == def->width) 41477a20bcceSEmmanuel Grumbach goto out_unlock; 41487a20bcceSEmmanuel Grumbach 41497a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 41507a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 4151b73f9a4aSJohannes Berg def->width <= NL80211_CHAN_WIDTH_20) 41527a20bcceSEmmanuel Grumbach goto out_unlock; 41537a20bcceSEmmanuel Grumbach } 41547a20bcceSEmmanuel Grumbach 4155e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 4156b73f9a4aSJohannes Berg iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, 4157e705c121SKalle Valo ctx->rx_chains_static, 4158e705c121SKalle Valo ctx->rx_chains_dynamic); 41597a20bcceSEmmanuel Grumbach 41607a20bcceSEmmanuel Grumbach out_unlock: 4161e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4162e705c121SKalle Valo } 4163e705c121SKalle Valo 4164e705c121SKalle Valo static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 4165e705c121SKalle Valo struct ieee80211_vif *vif, 4166e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4167e705c121SKalle Valo bool switching_chanctx) 4168e705c121SKalle Valo { 4169e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 4170e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 4171e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4172e705c121SKalle Valo int ret; 4173e705c121SKalle Valo 4174e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4175e705c121SKalle Valo 4176e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 4177e705c121SKalle Valo 4178e705c121SKalle Valo switch (vif->type) { 4179e705c121SKalle Valo case NL80211_IFTYPE_AP: 4180e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 4181e705c121SKalle Valo if (switching_chanctx) { 4182e705c121SKalle Valo mvmvif->ap_ibss_active = true; 4183e705c121SKalle Valo break; 4184e705c121SKalle Valo } 41855a2abdcaSGustavo A. R. Silva fallthrough; 4186e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4187e705c121SKalle Valo /* 4188e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 4189e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 4190e705c121SKalle Valo */ 4191e705c121SKalle Valo ret = 0; 4192e705c121SKalle Valo goto out; 4193e705c121SKalle Valo case NL80211_IFTYPE_STATION: 419419125cb0SAndrei Otcheretianski mvmvif->csa_bcn_pending = false; 4195e705c121SKalle Valo break; 4196e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4197e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 4198e705c121SKalle Valo mvmvif->ps_disabled = true; 4199e705c121SKalle Valo break; 4200e705c121SKalle Valo default: 4201e705c121SKalle Valo ret = -EINVAL; 4202e705c121SKalle Valo goto out; 4203e705c121SKalle Valo } 4204e705c121SKalle Valo 4205e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 4206e705c121SKalle Valo if (ret) 4207e705c121SKalle Valo goto out; 4208e705c121SKalle Valo 4209e705c121SKalle Valo /* 4210e705c121SKalle Valo * Power state must be updated before quotas, 4211e705c121SKalle Valo * otherwise fw will complain. 4212e705c121SKalle Valo */ 4213e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4214e705c121SKalle Valo 4215e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 4216e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 4217e705c121SKalle Valo * will handle quota settings. 4218e705c121SKalle Valo */ 4219e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 4220e705c121SKalle Valo mvmvif->monitor_active = true; 4221e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 4222e705c121SKalle Valo if (ret) 4223e705c121SKalle Valo goto out_remove_binding; 42240e39eb03SChaya Rachel Ivgi 42250e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 42260e39eb03SChaya Rachel Ivgi if (ret) 42270e39eb03SChaya Rachel Ivgi goto out_remove_binding; 42280e39eb03SChaya Rachel Ivgi 4229e705c121SKalle Valo } 4230e705c121SKalle Valo 4231e705c121SKalle Valo /* Handle binding during CSA */ 4232e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 4233e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4234e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4235e705c121SKalle Valo } 4236e705c121SKalle Valo 4237e705c121SKalle Valo if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { 423874a10252SSara Sharon mvmvif->csa_bcn_pending = true; 423974a10252SSara Sharon 424074a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 424174a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 424219125cb0SAndrei Otcheretianski u32 duration = 3 * vif->bss_conf.beacon_int; 4243e705c121SKalle Valo 4244e705c121SKalle Valo /* Protect the session to make sure we hear the first 4245e705c121SKalle Valo * beacon on the new channel. 4246e705c121SKalle Valo */ 4247e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 4248e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 4249e705c121SKalle Valo true); 425074a10252SSara Sharon } 4251e705c121SKalle Valo 4252e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 4253e705c121SKalle Valo } 4254e705c121SKalle Valo 4255e705c121SKalle Valo goto out; 4256e705c121SKalle Valo 4257e705c121SKalle Valo out_remove_binding: 4258e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4259e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4260e705c121SKalle Valo out: 4261e705c121SKalle Valo if (ret) 4262e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 4263e705c121SKalle Valo return ret; 4264e705c121SKalle Valo } 4265e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 4266e705c121SKalle Valo struct ieee80211_vif *vif, 4267727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 4268e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4269e705c121SKalle Valo { 4270e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4271e705c121SKalle Valo int ret; 4272e705c121SKalle Valo 4273e705c121SKalle Valo mutex_lock(&mvm->mutex); 4274e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); 4275e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4276e705c121SKalle Valo 4277e705c121SKalle Valo return ret; 4278e705c121SKalle Valo } 4279e705c121SKalle Valo 4280e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 4281e705c121SKalle Valo struct ieee80211_vif *vif, 4282e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 4283e705c121SKalle Valo bool switching_chanctx) 4284e705c121SKalle Valo { 4285e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4286e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 4287e705c121SKalle Valo 4288e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 4289e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); 4290e705c121SKalle Valo 4291e705c121SKalle Valo switch (vif->type) { 4292e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 4293e705c121SKalle Valo goto out; 4294e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 4295e705c121SKalle Valo mvmvif->monitor_active = false; 4296e705c121SKalle Valo mvmvif->ps_disabled = false; 42970e39eb03SChaya Rachel Ivgi iwl_mvm_rm_snif_sta(mvm, vif); 4298e705c121SKalle Valo break; 4299e705c121SKalle Valo case NL80211_IFTYPE_AP: 4300e705c121SKalle Valo /* This part is triggered only during CSA */ 4301e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 4302e705c121SKalle Valo goto out; 4303e705c121SKalle Valo 4304e705c121SKalle Valo mvmvif->csa_countdown = false; 4305e705c121SKalle Valo 4306e705c121SKalle Valo /* Set CS bit on all the stations */ 4307e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 4308e705c121SKalle Valo 4309e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 4310e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 4311e705c121SKalle Valo 4312e705c121SKalle Valo mvmvif->ap_ibss_active = false; 4313e705c121SKalle Valo break; 4314e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4315e705c121SKalle Valo if (!switching_chanctx) 4316e705c121SKalle Valo break; 4317e705c121SKalle Valo 4318e705c121SKalle Valo disabled_vif = vif; 4319e705c121SKalle Valo 432074a10252SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, 432174a10252SSara Sharon IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) 4322e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 4323e705c121SKalle Valo break; 4324e705c121SKalle Valo default: 4325e705c121SKalle Valo break; 4326e705c121SKalle Valo } 4327e705c121SKalle Valo 4328e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 4329e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 4330e705c121SKalle Valo 4331e705c121SKalle Valo out: 4332bf544e9aSSara Sharon if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) && 4333bf544e9aSSara Sharon switching_chanctx) 4334bf544e9aSSara Sharon return; 4335e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 4336e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 4337e705c121SKalle Valo } 4338e705c121SKalle Valo 4339e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 4340e705c121SKalle Valo struct ieee80211_vif *vif, 4341727eff4dSGregory Greenman struct ieee80211_bss_conf *link_conf, 4342e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 4343e705c121SKalle Valo { 4344e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4345e705c121SKalle Valo 4346e705c121SKalle Valo mutex_lock(&mvm->mutex); 4347e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); 4348e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4349e705c121SKalle Valo } 4350e705c121SKalle Valo 4351e705c121SKalle Valo static int 4352e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 4353e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 4354e705c121SKalle Valo { 4355e705c121SKalle Valo int ret; 4356e705c121SKalle Valo 4357e705c121SKalle Valo mutex_lock(&mvm->mutex); 4358e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4359e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 4360e705c121SKalle Valo 4361e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 4362e705c121SKalle Valo if (ret) { 4363e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 4364e705c121SKalle Valo goto out_reassign; 4365e705c121SKalle Valo } 4366e705c121SKalle Valo 4367e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4368e705c121SKalle Valo true); 4369e705c121SKalle Valo if (ret) { 4370e705c121SKalle Valo IWL_ERR(mvm, 4371e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4372e705c121SKalle Valo goto out_remove; 4373e705c121SKalle Valo } 4374e705c121SKalle Valo 4375e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 4376e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 4377e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4378e705c121SKalle Valo 4379e705c121SKalle Valo goto out; 4380e705c121SKalle Valo 4381e705c121SKalle Valo out_remove: 4382e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 4383e705c121SKalle Valo 4384e705c121SKalle Valo out_reassign: 4385e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 4386e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 4387e705c121SKalle Valo goto out_restart; 4388e705c121SKalle Valo } 4389e705c121SKalle Valo 4390e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4391e705c121SKalle Valo true)) { 4392e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4393e705c121SKalle Valo goto out_restart; 4394e705c121SKalle Valo } 4395e705c121SKalle Valo 4396e705c121SKalle Valo goto out; 4397e705c121SKalle Valo 4398e705c121SKalle Valo out_restart: 4399e705c121SKalle Valo /* things keep failing, better restart the hw */ 4400e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4401e705c121SKalle Valo 4402e705c121SKalle Valo out: 4403e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4404e705c121SKalle Valo 4405e705c121SKalle Valo return ret; 4406e705c121SKalle Valo } 4407e705c121SKalle Valo 4408e705c121SKalle Valo static int 4409e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 4410e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 4411e705c121SKalle Valo { 4412e705c121SKalle Valo int ret; 4413e705c121SKalle Valo 4414e705c121SKalle Valo mutex_lock(&mvm->mutex); 4415e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4416e705c121SKalle Valo 4417e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4418e705c121SKalle Valo true); 4419e705c121SKalle Valo if (ret) { 4420e705c121SKalle Valo IWL_ERR(mvm, 4421e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4422e705c121SKalle Valo goto out_reassign; 4423e705c121SKalle Valo } 4424e705c121SKalle Valo 4425e705c121SKalle Valo goto out; 4426e705c121SKalle Valo 4427e705c121SKalle Valo out_reassign: 4428e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4429e705c121SKalle Valo true)) { 4430e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4431e705c121SKalle Valo goto out_restart; 4432e705c121SKalle Valo } 4433e705c121SKalle Valo 4434e705c121SKalle Valo goto out; 4435e705c121SKalle Valo 4436e705c121SKalle Valo out_restart: 4437e705c121SKalle Valo /* things keep failing, better restart the hw */ 4438e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4439e705c121SKalle Valo 4440e705c121SKalle Valo out: 4441e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4442e705c121SKalle Valo 4443e705c121SKalle Valo return ret; 4444e705c121SKalle Valo } 4445e705c121SKalle Valo 4446e705c121SKalle Valo static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 4447e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 4448e705c121SKalle Valo int n_vifs, 4449e705c121SKalle Valo enum ieee80211_chanctx_switch_mode mode) 4450e705c121SKalle Valo { 4451e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4452e705c121SKalle Valo int ret; 4453e705c121SKalle Valo 4454e705c121SKalle Valo /* we only support a single-vif right now */ 4455e705c121SKalle Valo if (n_vifs > 1) 4456e705c121SKalle Valo return -EOPNOTSUPP; 4457e705c121SKalle Valo 4458e705c121SKalle Valo switch (mode) { 4459e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 4460e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); 4461e705c121SKalle Valo break; 4462e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 4463e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); 4464e705c121SKalle Valo break; 4465e705c121SKalle Valo default: 4466e705c121SKalle Valo ret = -EOPNOTSUPP; 4467e705c121SKalle Valo break; 4468e705c121SKalle Valo } 4469e705c121SKalle Valo 4470e705c121SKalle Valo return ret; 4471e705c121SKalle Valo } 4472e705c121SKalle Valo 44732f0282dbSJohannes Berg static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 44742f0282dbSJohannes Berg { 44752f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 44762f0282dbSJohannes Berg 44772f0282dbSJohannes Berg return mvm->ibss_manager; 44782f0282dbSJohannes Berg } 44792f0282dbSJohannes Berg 4480e705c121SKalle Valo static int iwl_mvm_set_tim(struct ieee80211_hw *hw, 4481e705c121SKalle Valo struct ieee80211_sta *sta, 4482e705c121SKalle Valo bool set) 4483e705c121SKalle Valo { 4484e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4485e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 4486e705c121SKalle Valo 4487e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 4488e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 4489e705c121SKalle Valo return -EINVAL; 4490e705c121SKalle Valo } 4491e705c121SKalle Valo 4492e705c121SKalle Valo return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); 4493e705c121SKalle Valo } 4494e705c121SKalle Valo 4495e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 4496e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 4497e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 4498e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 4499e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 4500e705c121SKalle Valo }; 4501e705c121SKalle Valo 4502e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 4503e705c121SKalle Valo struct ieee80211_vif *vif, 4504e705c121SKalle Valo void *data, int len) 4505e705c121SKalle Valo { 4506e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 4507e705c121SKalle Valo int err; 4508e705c121SKalle Valo u32 noa_duration; 4509e705c121SKalle Valo 45108cb08174SJohannes Berg err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len, 45118cb08174SJohannes Berg iwl_mvm_tm_policy, NULL); 4512e705c121SKalle Valo if (err) 4513e705c121SKalle Valo return err; 4514e705c121SKalle Valo 4515e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 4516e705c121SKalle Valo return -EINVAL; 4517e705c121SKalle Valo 4518e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 4519e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 4520e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 4521e705c121SKalle Valo !vif->bss_conf.enable_beacon || 4522e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 4523e705c121SKalle Valo return -EINVAL; 4524e705c121SKalle Valo 4525e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 4526e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 4527e705c121SKalle Valo return -EINVAL; 4528e705c121SKalle Valo 4529e705c121SKalle Valo mvm->noa_duration = noa_duration; 4530e705c121SKalle Valo mvm->noa_vif = vif; 4531e705c121SKalle Valo 453222b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 4533e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 4534e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 4535e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 4536f276e20bSJohannes Berg !vif->cfg.assoc || !vif->bss_conf.dtim_period || 4537e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 4538e705c121SKalle Valo return -EINVAL; 4539e705c121SKalle Valo 4540e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 4541e705c121SKalle Valo return iwl_mvm_enable_beacon_filter(mvm, vif, 0); 4542e705c121SKalle Valo return iwl_mvm_disable_beacon_filter(mvm, vif, 0); 4543e705c121SKalle Valo } 4544e705c121SKalle Valo 4545e705c121SKalle Valo return -EOPNOTSUPP; 4546e705c121SKalle Valo } 4547e705c121SKalle Valo 4548e705c121SKalle Valo static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 4549e705c121SKalle Valo struct ieee80211_vif *vif, 4550e705c121SKalle Valo void *data, int len) 4551e705c121SKalle Valo { 4552e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4553e705c121SKalle Valo int err; 4554e705c121SKalle Valo 4555e705c121SKalle Valo mutex_lock(&mvm->mutex); 4556e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 4557e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4558e705c121SKalle Valo 4559e705c121SKalle Valo return err; 4560e705c121SKalle Valo } 4561e705c121SKalle Valo #endif 4562e705c121SKalle Valo 4563e705c121SKalle Valo static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, 4564e705c121SKalle Valo struct ieee80211_vif *vif, 4565e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4566e705c121SKalle Valo { 4567e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 4568e705c121SKalle Valo * starting its own channel switch timer, so that we can call 4569e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 4570e705c121SKalle Valo * (which is when the absence time event starts). 4571e705c121SKalle Valo */ 4572e705c121SKalle Valo 4573e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 4574e705c121SKalle Valo "dummy channel switch op\n"); 4575e705c121SKalle Valo } 4576e705c121SKalle Valo 457774a10252SSara Sharon static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm, 457874a10252SSara Sharon struct ieee80211_vif *vif, 457974a10252SSara Sharon struct ieee80211_channel_switch *chsw) 458074a10252SSara Sharon { 458174a10252SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 458274a10252SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 458374a10252SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 458474a10252SSara Sharon mvmvif->color)), 458574a10252SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 458674a10252SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 458774a10252SSara Sharon .cs_count = chsw->count, 458877738865SSara Sharon .cs_mode = chsw->block_tx, 458974a10252SSara Sharon }; 459074a10252SSara Sharon 459174a10252SSara Sharon lockdep_assert_held(&mvm->mutex); 459274a10252SSara Sharon 45939cfcf71cSSara Sharon if (chsw->delay) 45949cfcf71cSSara Sharon cmd.cs_delayed_bcn_count = 45959cfcf71cSSara Sharon DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int); 45969cfcf71cSSara Sharon 459774a10252SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 459874a10252SSara Sharon WIDE_ID(MAC_CONF_GROUP, 459974a10252SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 460074a10252SSara Sharon 0, sizeof(cmd), &cmd); 460174a10252SSara Sharon } 460274a10252SSara Sharon 46030202bcf0SEmmanuel Grumbach static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm, 46040202bcf0SEmmanuel Grumbach struct ieee80211_vif *vif, 46050202bcf0SEmmanuel Grumbach struct ieee80211_channel_switch *chsw) 46060202bcf0SEmmanuel Grumbach { 46070202bcf0SEmmanuel Grumbach struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 46080202bcf0SEmmanuel Grumbach u32 apply_time; 46090202bcf0SEmmanuel Grumbach 46100202bcf0SEmmanuel Grumbach /* Schedule the time event to a bit before beacon 1, 46110202bcf0SEmmanuel Grumbach * to make sure we're in the new channel when the 46120202bcf0SEmmanuel Grumbach * GO/AP arrives. In case count <= 1 immediately schedule the 46130202bcf0SEmmanuel Grumbach * TE (this might result with some packet loss or connection 46140202bcf0SEmmanuel Grumbach * loss). 46150202bcf0SEmmanuel Grumbach */ 46160202bcf0SEmmanuel Grumbach if (chsw->count <= 1) 46170202bcf0SEmmanuel Grumbach apply_time = 0; 46180202bcf0SEmmanuel Grumbach else 46190202bcf0SEmmanuel Grumbach apply_time = chsw->device_timestamp + 46200202bcf0SEmmanuel Grumbach ((vif->bss_conf.beacon_int * (chsw->count - 1) - 46210202bcf0SEmmanuel Grumbach IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 46220202bcf0SEmmanuel Grumbach 46230202bcf0SEmmanuel Grumbach if (chsw->block_tx) 46240202bcf0SEmmanuel Grumbach iwl_mvm_csa_client_absent(mvm, vif); 46250202bcf0SEmmanuel Grumbach 46260202bcf0SEmmanuel Grumbach if (mvmvif->bf_data.bf_enabled) { 46270202bcf0SEmmanuel Grumbach int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 46280202bcf0SEmmanuel Grumbach 46290202bcf0SEmmanuel Grumbach if (ret) 46300202bcf0SEmmanuel Grumbach return ret; 46310202bcf0SEmmanuel Grumbach } 46320202bcf0SEmmanuel Grumbach 46330202bcf0SEmmanuel Grumbach iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 46340202bcf0SEmmanuel Grumbach apply_time); 46350202bcf0SEmmanuel Grumbach 46360202bcf0SEmmanuel Grumbach return 0; 46370202bcf0SEmmanuel Grumbach } 46380202bcf0SEmmanuel Grumbach 4639f6780614SSara Sharon #define IWL_MAX_CSA_BLOCK_TX 1500 4640e705c121SKalle Valo static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 4641e705c121SKalle Valo struct ieee80211_vif *vif, 4642e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4643e705c121SKalle Valo { 4644e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4645e705c121SKalle Valo struct ieee80211_vif *csa_vif; 4646e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4647e705c121SKalle Valo int ret; 4648e705c121SKalle Valo 4649e705c121SKalle Valo mutex_lock(&mvm->mutex); 4650e705c121SKalle Valo 4651e705c121SKalle Valo mvmvif->csa_failed = false; 4652e705c121SKalle Valo 4653e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 4654e705c121SKalle Valo chsw->chandef.center_freq1); 4655e705c121SKalle Valo 46567174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 46577174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 46587174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 4659e705c121SKalle Valo 4660e705c121SKalle Valo switch (vif->type) { 4661e705c121SKalle Valo case NL80211_IFTYPE_AP: 4662e705c121SKalle Valo csa_vif = 4663e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 4664e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4665d0a9123eSJohannes Berg if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, 4666e705c121SKalle Valo "Another CSA is already in progress")) { 4667e705c121SKalle Valo ret = -EBUSY; 4668e705c121SKalle Valo goto out_unlock; 4669e705c121SKalle Valo } 4670e705c121SKalle Valo 4671d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 4672d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 4673d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 4674d3a108a4SAndrei Otcheretianski ret = -EBUSY; 4675d3a108a4SAndrei Otcheretianski goto out_unlock; 4676d3a108a4SAndrei Otcheretianski } 4677d3a108a4SAndrei Otcheretianski 4678e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 4679e705c121SKalle Valo 4680e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 4681e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 4682e705c121SKalle Valo ret = -EBUSY; 4683e705c121SKalle Valo goto out_unlock; 4684e705c121SKalle Valo } 4685e705c121SKalle Valo 4686d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 4687d3a108a4SAndrei Otcheretianski 4688e705c121SKalle Valo break; 4689e705c121SKalle Valo case NL80211_IFTYPE_STATION: 46902360acbdSEmmanuel Grumbach /* 4691ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there 4692ad12b231SNathan Errera * is no need for all of this 4693ad12b231SNathan Errera */ 4694ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 4695ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 4696ad12b231SNathan Errera 0)) 4697ad12b231SNathan Errera break; 4698ad12b231SNathan Errera 4699ad12b231SNathan Errera /* 47002360acbdSEmmanuel Grumbach * We haven't configured the firmware to be associated yet since 47012360acbdSEmmanuel Grumbach * we don't know the dtim period. In this case, the firmware can't 47022360acbdSEmmanuel Grumbach * track the beacons. 47032360acbdSEmmanuel Grumbach */ 4704f276e20bSJohannes Berg if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) { 47052360acbdSEmmanuel Grumbach ret = -EBUSY; 47062360acbdSEmmanuel Grumbach goto out_unlock; 47072360acbdSEmmanuel Grumbach } 47082360acbdSEmmanuel Grumbach 470987d9564eSJohannes Berg if (chsw->delay > IWL_MAX_CSA_BLOCK_TX) 471087d9564eSJohannes Berg schedule_delayed_work(&mvmvif->csa_work, 0); 471187d9564eSJohannes Berg 4712f6780614SSara Sharon if (chsw->block_tx) { 4713f6780614SSara Sharon /* 4714f6780614SSara Sharon * In case of undetermined / long time with immediate 4715f6780614SSara Sharon * quiet monitor status to gracefully disconnect 4716f6780614SSara Sharon */ 4717f6780614SSara Sharon if (!chsw->count || 4718f6780614SSara Sharon chsw->count * vif->bss_conf.beacon_int > 4719f6780614SSara Sharon IWL_MAX_CSA_BLOCK_TX) 4720f6780614SSara Sharon schedule_delayed_work(&mvmvif->csa_work, 4721f6780614SSara Sharon msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX)); 4722f6780614SSara Sharon } 4723e705c121SKalle Valo 47240202bcf0SEmmanuel Grumbach if (!fw_has_capa(&mvm->fw->ucode_capa, 47250202bcf0SEmmanuel Grumbach IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) { 47260202bcf0SEmmanuel Grumbach ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); 4727e705c121SKalle Valo if (ret) 4728e705c121SKalle Valo goto out_unlock; 47290202bcf0SEmmanuel Grumbach } else { 473074a10252SSara Sharon iwl_mvm_schedule_client_csa(mvm, vif, chsw); 47310202bcf0SEmmanuel Grumbach } 473281b4e44eSSara Sharon 473381b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 473481b4e44eSSara Sharon mvmvif->csa_misbehave = false; 4735e705c121SKalle Valo break; 4736e705c121SKalle Valo default: 4737e705c121SKalle Valo break; 4738e705c121SKalle Valo } 4739e705c121SKalle Valo 4740e705c121SKalle Valo mvmvif->ps_disabled = true; 4741e705c121SKalle Valo 4742e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 4743e705c121SKalle Valo if (ret) 4744e705c121SKalle Valo goto out_unlock; 4745e705c121SKalle Valo 4746e705c121SKalle Valo /* we won't be on this channel any longer */ 4747e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4748e705c121SKalle Valo 4749e705c121SKalle Valo out_unlock: 4750e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4751e705c121SKalle Valo 4752e705c121SKalle Valo return ret; 4753e705c121SKalle Valo } 4754e705c121SKalle Valo 4755c37763d2SSara Sharon static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw, 4756c37763d2SSara Sharon struct ieee80211_vif *vif, 4757c37763d2SSara Sharon struct ieee80211_channel_switch *chsw) 4758e705c121SKalle Valo { 4759e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4760c37763d2SSara Sharon struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4761c37763d2SSara Sharon struct iwl_chan_switch_te_cmd cmd = { 4762c37763d2SSara Sharon .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, 4763c37763d2SSara Sharon mvmvif->color)), 4764c37763d2SSara Sharon .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY), 4765c37763d2SSara Sharon .tsf = cpu_to_le32(chsw->timestamp), 4766c37763d2SSara Sharon .cs_count = chsw->count, 476777738865SSara Sharon .cs_mode = chsw->block_tx, 4768c37763d2SSara Sharon }; 4769e705c121SKalle Valo 4770ad12b231SNathan Errera /* 4771ad12b231SNathan Errera * In the new flow FW is in charge of timing the switch so there is no 4772ad12b231SNathan Errera * need for all of this 4773ad12b231SNathan Errera */ 4774ad12b231SNathan Errera if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP, 4775ad12b231SNathan Errera CHANNEL_SWITCH_ERROR_NOTIF, 0)) 4776ad12b231SNathan Errera return; 4777ad12b231SNathan Errera 4778c37763d2SSara Sharon if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) 4779c37763d2SSara Sharon return; 4780e705c121SKalle Valo 4781c3eae059SGregory Greenman IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n", 4782c3eae059SGregory Greenman mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx); 4783c3eae059SGregory Greenman 478481b4e44eSSara Sharon if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { 478581b4e44eSSara Sharon if (mvmvif->csa_misbehave) { 478681b4e44eSSara Sharon /* Second time, give up on this AP*/ 478781b4e44eSSara Sharon iwl_mvm_abort_channel_switch(hw, vif); 478881b4e44eSSara Sharon ieee80211_chswitch_done(vif, false); 478981b4e44eSSara Sharon mvmvif->csa_misbehave = false; 479081b4e44eSSara Sharon return; 4791e705c121SKalle Valo } 479281b4e44eSSara Sharon mvmvif->csa_misbehave = true; 4793e705c121SKalle Valo } 479481b4e44eSSara Sharon mvmvif->csa_count = chsw->count; 4795e705c121SKalle Valo 4796caf46377SSara Sharon mutex_lock(&mvm->mutex); 4797caf46377SSara Sharon if (mvmvif->csa_failed) 4798caf46377SSara Sharon goto out_unlock; 4799e705c121SKalle Valo 4800c37763d2SSara Sharon WARN_ON(iwl_mvm_send_cmd_pdu(mvm, 4801c37763d2SSara Sharon WIDE_ID(MAC_CONF_GROUP, 4802c37763d2SSara Sharon CHANNEL_SWITCH_TIME_EVENT_CMD), 4803caf46377SSara Sharon 0, sizeof(cmd), &cmd)); 4804caf46377SSara Sharon out_unlock: 4805caf46377SSara Sharon mutex_unlock(&mvm->mutex); 4806e705c121SKalle Valo } 4807e705c121SKalle Valo 48086110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 48096110d9e5SDavid Spinadel { 4810435d0827SSara Sharon int i; 4811435d0827SSara Sharon 481206195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 4813309c4848SLuca Coelho if (drop) { 4814309c4848SLuca Coelho mutex_lock(&mvm->mutex); 48156110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 4816d4e3a341SMordechay Goodstein iwl_mvm_flushable_queues(mvm) & queues); 4817309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 4818309c4848SLuca Coelho } else { 4819435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 4820309c4848SLuca Coelho } 4821435d0827SSara Sharon return; 4822435d0827SSara Sharon } 48236110d9e5SDavid Spinadel 48246110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 4825be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 4826435d0827SSara Sharon struct ieee80211_sta *sta; 4827435d0827SSara Sharon 4828435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 48296110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 48306110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 48316110d9e5SDavid Spinadel continue; 48326110d9e5SDavid Spinadel 483306195639SSara Sharon if (drop) 4834d4e3a341SMordechay Goodstein iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); 483506195639SSara Sharon else 48366110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 48376110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 48386110d9e5SDavid Spinadel } 48396110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 48406110d9e5SDavid Spinadel } 48416110d9e5SDavid Spinadel 4842e705c121SKalle Valo static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, 4843e705c121SKalle Valo struct ieee80211_vif *vif, u32 queues, bool drop) 4844e705c121SKalle Valo { 4845e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4846e705c121SKalle Valo struct iwl_mvm_vif *mvmvif; 4847e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 4848e705c121SKalle Valo struct ieee80211_sta *sta; 4849e705c121SKalle Valo int i; 4850e705c121SKalle Valo u32 msk = 0; 4851e705c121SKalle Valo 48526110d9e5SDavid Spinadel if (!vif) { 48536110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 48546110d9e5SDavid Spinadel return; 48556110d9e5SDavid Spinadel } 48566110d9e5SDavid Spinadel 48576110d9e5SDavid Spinadel if (vif->type != NL80211_IFTYPE_STATION) 4858e705c121SKalle Valo return; 4859e705c121SKalle Valo 486024afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 486124afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 486224afba76SLiad Kaufman 4863e705c121SKalle Valo mutex_lock(&mvm->mutex); 4864e705c121SKalle Valo mvmvif = iwl_mvm_vif_from_mac80211(vif); 4865e705c121SKalle Valo 4866e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 4867be9ae34eSNathan Errera for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { 4868e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 4869e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4870e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 4871e705c121SKalle Valo continue; 4872e705c121SKalle Valo 4873e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 4874e705c121SKalle Valo if (mvmsta->vif != vif) 4875e705c121SKalle Valo continue; 4876e705c121SKalle Valo 4877e705c121SKalle Valo /* make sure only TDLS peers or the AP are flushed */ 4878e705c121SKalle Valo WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); 4879e705c121SKalle Valo 4880d49394a1SSara Sharon if (drop) { 4881f9084775SNathan Errera if (iwl_mvm_flush_sta(mvm, mvmsta, false)) 4882d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 4883d49394a1SSara Sharon } else { 4884e705c121SKalle Valo msk |= mvmsta->tfd_queue_msk; 4885d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 4886d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 4887e705c121SKalle Valo } 4888d49394a1SSara Sharon } 4889e705c121SKalle Valo 4890e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4891e705c121SKalle Valo 4892e705c121SKalle Valo /* this can take a while, and we may need/want other operations 4893e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 4894e705c121SKalle Valo */ 4895d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 4896a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 4897e705c121SKalle Valo } 4898e705c121SKalle Valo 4899e705c121SKalle Valo static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 4900e705c121SKalle Valo struct survey_info *survey) 4901e705c121SKalle Valo { 4902e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4903e705c121SKalle Valo int ret; 4904e705c121SKalle Valo 4905e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 4906e705c121SKalle Valo 4907e705c121SKalle Valo /* only support global statistics right now */ 4908e705c121SKalle Valo if (idx != 0) 4909e705c121SKalle Valo return -ENOENT; 4910e705c121SKalle Valo 4911280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 4912e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 4913e705c121SKalle Valo return -ENOENT; 4914e705c121SKalle Valo 4915e705c121SKalle Valo mutex_lock(&mvm->mutex); 4916e705c121SKalle Valo 4917aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 4918e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 4919e705c121SKalle Valo if (ret) 4920e705c121SKalle Valo goto out; 4921e705c121SKalle Valo } 4922e705c121SKalle Valo 4923e705c121SKalle Valo survey->filled = SURVEY_INFO_TIME | 4924e705c121SKalle Valo SURVEY_INFO_TIME_RX | 4925e705c121SKalle Valo SURVEY_INFO_TIME_TX | 4926e705c121SKalle Valo SURVEY_INFO_TIME_SCAN; 4927e705c121SKalle Valo survey->time = mvm->accu_radio_stats.on_time_rf + 4928e705c121SKalle Valo mvm->radio_stats.on_time_rf; 4929e705c121SKalle Valo do_div(survey->time, USEC_PER_MSEC); 4930e705c121SKalle Valo 4931e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 4932e705c121SKalle Valo mvm->radio_stats.rx_time; 4933e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 4934e705c121SKalle Valo 4935e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 4936e705c121SKalle Valo mvm->radio_stats.tx_time; 4937e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 4938e705c121SKalle Valo 4939e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 4940e705c121SKalle Valo mvm->radio_stats.on_time_scan; 4941e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 4942e705c121SKalle Valo 4943e705c121SKalle Valo ret = 0; 4944e705c121SKalle Valo out: 4945e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4946e705c121SKalle Valo return ret; 4947e705c121SKalle Valo } 4948e705c121SKalle Valo 4949ed780545SJohannes Berg static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo) 4950ed780545SJohannes Berg { 495182cdbd11SMiri Korenblit u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 495282cdbd11SMiri Korenblit 495382cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 4954ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_20: 4955ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_20; 4956ed780545SJohannes Berg break; 4957ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_40: 4958ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_40; 4959ed780545SJohannes Berg break; 4960ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_80: 4961ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_80; 4962ed780545SJohannes Berg break; 4963ed780545SJohannes Berg case RATE_MCS_CHAN_WIDTH_160: 4964ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_160; 4965ed780545SJohannes Berg break; 4966ed780545SJohannes Berg } 4967ed780545SJohannes Berg 496882cdbd11SMiri Korenblit if (format == RATE_MCS_CCK_MSK || 496982cdbd11SMiri Korenblit format == RATE_MCS_LEGACY_OFDM_MSK) { 497082cdbd11SMiri Korenblit int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK); 497182cdbd11SMiri Korenblit 497282cdbd11SMiri Korenblit /* add the offset needed to get to the legacy ofdm indices */ 497382cdbd11SMiri Korenblit if (format == RATE_MCS_LEGACY_OFDM_MSK) 497482cdbd11SMiri Korenblit rate += IWL_FIRST_OFDM_RATE; 497582cdbd11SMiri Korenblit 497682cdbd11SMiri Korenblit switch (rate) { 497782cdbd11SMiri Korenblit case IWL_RATE_1M_INDEX: 497882cdbd11SMiri Korenblit rinfo->legacy = 10; 497982cdbd11SMiri Korenblit break; 498082cdbd11SMiri Korenblit case IWL_RATE_2M_INDEX: 498182cdbd11SMiri Korenblit rinfo->legacy = 20; 498282cdbd11SMiri Korenblit break; 498382cdbd11SMiri Korenblit case IWL_RATE_5M_INDEX: 498482cdbd11SMiri Korenblit rinfo->legacy = 55; 498582cdbd11SMiri Korenblit break; 498682cdbd11SMiri Korenblit case IWL_RATE_11M_INDEX: 498782cdbd11SMiri Korenblit rinfo->legacy = 110; 498882cdbd11SMiri Korenblit break; 498982cdbd11SMiri Korenblit case IWL_RATE_6M_INDEX: 499082cdbd11SMiri Korenblit rinfo->legacy = 60; 499182cdbd11SMiri Korenblit break; 499282cdbd11SMiri Korenblit case IWL_RATE_9M_INDEX: 499382cdbd11SMiri Korenblit rinfo->legacy = 90; 499482cdbd11SMiri Korenblit break; 499582cdbd11SMiri Korenblit case IWL_RATE_12M_INDEX: 499682cdbd11SMiri Korenblit rinfo->legacy = 120; 499782cdbd11SMiri Korenblit break; 499882cdbd11SMiri Korenblit case IWL_RATE_18M_INDEX: 499982cdbd11SMiri Korenblit rinfo->legacy = 180; 500082cdbd11SMiri Korenblit break; 500182cdbd11SMiri Korenblit case IWL_RATE_24M_INDEX: 500282cdbd11SMiri Korenblit rinfo->legacy = 240; 500382cdbd11SMiri Korenblit break; 500482cdbd11SMiri Korenblit case IWL_RATE_36M_INDEX: 500582cdbd11SMiri Korenblit rinfo->legacy = 360; 500682cdbd11SMiri Korenblit break; 500782cdbd11SMiri Korenblit case IWL_RATE_48M_INDEX: 500882cdbd11SMiri Korenblit rinfo->legacy = 480; 500982cdbd11SMiri Korenblit break; 501082cdbd11SMiri Korenblit case IWL_RATE_54M_INDEX: 501182cdbd11SMiri Korenblit rinfo->legacy = 540; 501282cdbd11SMiri Korenblit } 501382cdbd11SMiri Korenblit return; 501482cdbd11SMiri Korenblit } 501582cdbd11SMiri Korenblit 5016ed780545SJohannes Berg rinfo->nss = u32_get_bits(rate_n_flags, 501782cdbd11SMiri Korenblit RATE_MCS_NSS_MSK) + 1; 501882cdbd11SMiri Korenblit rinfo->mcs = format == RATE_MCS_HT_MSK ? 501982cdbd11SMiri Korenblit RATE_HT_MCS_INDEX(rate_n_flags) : 502082cdbd11SMiri Korenblit u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK); 502182cdbd11SMiri Korenblit 502282cdbd11SMiri Korenblit if (format == RATE_MCS_HE_MSK) { 5023ed780545SJohannes Berg u32 gi_ltf = u32_get_bits(rate_n_flags, 502482cdbd11SMiri Korenblit RATE_MCS_HE_GI_LTF_MSK); 5025ed780545SJohannes Berg 5026ed780545SJohannes Berg rinfo->flags |= RATE_INFO_FLAGS_HE_MCS; 5027ed780545SJohannes Berg 502882cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_HE_106T_MSK) { 5029ed780545SJohannes Berg rinfo->bw = RATE_INFO_BW_HE_RU; 5030ed780545SJohannes Berg rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106; 5031ed780545SJohannes Berg } 5032ed780545SJohannes Berg 503382cdbd11SMiri Korenblit switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) { 503482cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_SU: 503582cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_EXT_SU: 5036ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5037ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5038ed780545SJohannes Berg else if (gi_ltf == 2) 5039ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 504082cdbd11SMiri Korenblit else if (gi_ltf == 3) 5041ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 504282cdbd11SMiri Korenblit else 504382cdbd11SMiri Korenblit rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5044ed780545SJohannes Berg break; 504582cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_MU: 5046ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5047ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 5048ed780545SJohannes Berg else if (gi_ltf == 2) 5049ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5050ed780545SJohannes Berg else 5051ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5052ed780545SJohannes Berg break; 505382cdbd11SMiri Korenblit case RATE_MCS_HE_TYPE_TRIG: 5054ed780545SJohannes Berg if (gi_ltf == 0 || gi_ltf == 1) 5055ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 5056ed780545SJohannes Berg else 5057ed780545SJohannes Berg rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 5058ed780545SJohannes Berg break; 5059ed780545SJohannes Berg } 5060ed780545SJohannes Berg 5061ed780545SJohannes Berg if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK) 5062ed780545SJohannes Berg rinfo->he_dcm = 1; 506382cdbd11SMiri Korenblit return; 5064ed780545SJohannes Berg } 506582cdbd11SMiri Korenblit 506682cdbd11SMiri Korenblit if (rate_n_flags & RATE_MCS_SGI_MSK) 506782cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; 506882cdbd11SMiri Korenblit 506982cdbd11SMiri Korenblit if (format == RATE_MCS_HT_MSK) { 507082cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_MCS; 507182cdbd11SMiri Korenblit 507282cdbd11SMiri Korenblit } else if (format == RATE_MCS_VHT_MSK) { 507382cdbd11SMiri Korenblit rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; 5074ed780545SJohannes Berg } 507582cdbd11SMiri Korenblit 5076ed780545SJohannes Berg } 5077ed780545SJohannes Berg 5078e705c121SKalle Valo static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 5079e705c121SKalle Valo struct ieee80211_vif *vif, 5080e705c121SKalle Valo struct ieee80211_sta *sta, 5081e705c121SKalle Valo struct station_info *sinfo) 5082e705c121SKalle Valo { 5083e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5084e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5085e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 5086e705c121SKalle Valo 5087988b5968SSara Sharon if (mvmsta->avg_energy) { 508888ad368aSBen Greear sinfo->signal_avg = -(s8)mvmsta->avg_energy; 508922d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 5090988b5968SSara Sharon } 5091988b5968SSara Sharon 5092ed780545SJohannes Berg if (iwl_mvm_has_tlc_offload(mvm)) { 5093ed780545SJohannes Berg struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw; 5094ed780545SJohannes Berg 5095ed780545SJohannes Berg iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate); 5096ed780545SJohannes Berg sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 5097ed780545SJohannes Berg } 5098ed780545SJohannes Berg 5099e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 5100e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 5101e705c121SKalle Valo return; 5102e705c121SKalle Valo 5103f276e20bSJohannes Berg if (!vif->cfg.assoc) 5104e705c121SKalle Valo return; 5105e705c121SKalle Valo 5106e705c121SKalle Valo mutex_lock(&mvm->mutex); 5107e705c121SKalle Valo 5108e705c121SKalle Valo if (mvmvif->ap_sta_id != mvmsta->sta_id) 5109e705c121SKalle Valo goto unlock; 5110e705c121SKalle Valo 5111e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 5112e705c121SKalle Valo goto unlock; 5113e705c121SKalle Valo 5114e705c121SKalle Valo sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + 5115e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons; 511622d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 5117e705c121SKalle Valo if (mvmvif->beacon_stats.avg_signal) { 5118e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 5119e705c121SKalle Valo sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; 512022d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 5121e705c121SKalle Valo } 5122e705c121SKalle Valo unlock: 5123e705c121SKalle Valo mutex_unlock(&mvm->mutex); 5124e705c121SKalle Valo } 5125e705c121SKalle Valo 5126119c2a13SMordechay Goodstein static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm, 5127119c2a13SMordechay Goodstein struct ieee80211_vif *vif, 5128119c2a13SMordechay Goodstein const struct ieee80211_mlme_event *mlme) 5129119c2a13SMordechay Goodstein { 51301a81bddfSMordechay Goodstein if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) && 51311a81bddfSMordechay Goodstein (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) { 5132119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5133119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_ASSOC_FAILED, 5134119c2a13SMordechay Goodstein NULL); 5135119c2a13SMordechay Goodstein return; 5136119c2a13SMordechay Goodstein } 5137119c2a13SMordechay Goodstein 5138119c2a13SMordechay Goodstein if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) { 5139119c2a13SMordechay Goodstein iwl_dbg_tlv_time_point(&mvm->fwrt, 5140119c2a13SMordechay Goodstein IWL_FW_INI_TIME_POINT_DEASSOC, 5141119c2a13SMordechay Goodstein NULL); 5142119c2a13SMordechay Goodstein return; 5143119c2a13SMordechay Goodstein } 5144119c2a13SMordechay Goodstein } 5145119c2a13SMordechay Goodstein 5146e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 5147e705c121SKalle Valo struct ieee80211_vif *vif, 5148e705c121SKalle Valo const struct ieee80211_event *event) 5149e705c121SKalle Valo { 51504c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 5151e705c121SKalle Valo do { \ 51524c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 5153e705c121SKalle Valo break; \ 51547174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 5155e705c121SKalle Valo } while (0) 5156e705c121SKalle Valo 5157e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5158e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 5159e705c121SKalle Valo 5160119c2a13SMordechay Goodstein if (iwl_trans_dbg_ini_valid(mvm->trans)) { 5161119c2a13SMordechay Goodstein iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme); 5162119c2a13SMordechay Goodstein return; 5163119c2a13SMordechay Goodstein } 5164119c2a13SMordechay Goodstein 51656c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 51666c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 51676c042d75SSara Sharon if (!trig) 5168e705c121SKalle Valo return; 5169e705c121SKalle Valo 5170e705c121SKalle Valo trig_mlme = (void *)trig->data; 5171e705c121SKalle Valo 5172e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 5173e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 51744c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 5175e705c121SKalle Valo "DENIED ASSOC: reason %d", 5176e705c121SKalle Valo event->u.mlme.reason); 5177e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 51784c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 5179e705c121SKalle Valo "ASSOC TIMEOUT"); 5180e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 5181e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 51824c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 5183e705c121SKalle Valo "DENIED AUTH: reason %d", 5184e705c121SKalle Valo event->u.mlme.reason); 5185e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 51864c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 5187e705c121SKalle Valo "AUTH TIMEOUT"); 5188e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 51894c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 5190e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 5191e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 51924c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 5193e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 5194e705c121SKalle Valo } 5195e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 5196e705c121SKalle Valo } 5197e705c121SKalle Valo 5198e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 5199e705c121SKalle Valo struct ieee80211_vif *vif, 5200e705c121SKalle Valo const struct ieee80211_event *event) 5201e705c121SKalle Valo { 5202e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 5203e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 5204e705c121SKalle Valo 52056c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 52066c042d75SSara Sharon FW_DBG_TRIGGER_BA); 52076c042d75SSara Sharon if (!trig) 5208e705c121SKalle Valo return; 5209e705c121SKalle Valo 5210e705c121SKalle Valo ba_trig = (void *)trig->data; 5211e705c121SKalle Valo 5212e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 5213e705c121SKalle Valo return; 5214e705c121SKalle Valo 52157174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 5216e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 5217e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 5218e705c121SKalle Valo event->u.ba.ssn); 5219e705c121SKalle Valo } 5220e705c121SKalle Valo 5221e705c121SKalle Valo static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 5222e705c121SKalle Valo struct ieee80211_vif *vif, 5223e705c121SKalle Valo const struct ieee80211_event *event) 5224e705c121SKalle Valo { 5225e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5226e705c121SKalle Valo 5227e705c121SKalle Valo switch (event->type) { 5228e705c121SKalle Valo case MLME_EVENT: 5229e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 5230e705c121SKalle Valo break; 5231e705c121SKalle Valo case BAR_RX_EVENT: 5232e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 5233e705c121SKalle Valo break; 5234e705c121SKalle Valo case BA_FRAME_TIMEOUT: 5235528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 5236528a542aSEmmanuel Grumbach event->u.ba.tid); 5237e705c121SKalle Valo break; 5238e705c121SKalle Valo default: 5239e705c121SKalle Valo break; 5240e705c121SKalle Valo } 5241e705c121SKalle Valo } 5242e705c121SKalle Valo 5243d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 52445e1688ceSJohannes Berg enum iwl_mvm_rxq_notif_type type, 52455e1688ceSJohannes Berg bool sync, 52465e1688ceSJohannes Berg const void *data, u32 size) 52470636b938SSara Sharon { 52485e1688ceSJohannes Berg struct { 52495e1688ceSJohannes Berg struct iwl_rxq_sync_cmd cmd; 52505e1688ceSJohannes Berg struct iwl_mvm_internal_rxq_notif notif; 52515e1688ceSJohannes Berg } __packed cmd = { 52525e1688ceSJohannes Berg .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1), 52535e1688ceSJohannes Berg .cmd.count = 52545e1688ceSJohannes Berg cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) + 52555e1688ceSJohannes Berg size), 52565e1688ceSJohannes Berg .notif.type = type, 52575e1688ceSJohannes Berg .notif.sync = sync, 52585e1688ceSJohannes Berg }; 52595e1688ceSJohannes Berg struct iwl_host_cmd hcmd = { 52605e1688ceSJohannes Berg .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD), 52615e1688ceSJohannes Berg .data[0] = &cmd, 52625e1688ceSJohannes Berg .len[0] = sizeof(cmd), 52635e1688ceSJohannes Berg .data[1] = data, 52645e1688ceSJohannes Berg .len[1] = size, 52655e1688ceSJohannes Berg .flags = sync ? 0 : CMD_ASYNC, 52665e1688ceSJohannes Berg }; 52670636b938SSara Sharon int ret; 52680636b938SSara Sharon 52695e1688ceSJohannes Berg /* size must be a multiple of DWORD */ 52705e1688ceSJohannes Berg if (WARN_ON(cmd.cmd.count & cpu_to_le32(3))) 52715e1688ceSJohannes Berg return; 52720636b938SSara Sharon 5273cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 52740636b938SSara Sharon return; 52750636b938SSara Sharon 52765e1688ceSJohannes Berg if (sync) { 52775e1688ceSJohannes Berg cmd.notif.cookie = mvm->queue_sync_cookie; 52782f7a04c7SJohannes Berg mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1; 5279a2113cc4SNaftali Goldstein } 5280d0ff5d22SSara Sharon 52815e1688ceSJohannes Berg ret = iwl_mvm_send_cmd(mvm, &hcmd); 52820636b938SSara Sharon if (ret) { 52830636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 52840636b938SSara Sharon goto out; 52850636b938SSara Sharon } 5286d0ff5d22SSara Sharon 52875e1688ceSJohannes Berg if (sync) { 52883c514bf8SEmmanuel Grumbach lockdep_assert_held(&mvm->mutex); 52893a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 52902f7a04c7SJohannes Berg READ_ONCE(mvm->queue_sync_state) == 0 || 52916ad04359SJohannes Berg iwl_mvm_is_radio_killed(mvm), 52920636b938SSara Sharon HZ); 52932f7a04c7SJohannes Berg WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm), 52942f7a04c7SJohannes Berg "queue sync: failed to sync, state is 0x%lx\n", 52952f7a04c7SJohannes Berg mvm->queue_sync_state); 52966ad04359SJohannes Berg } 52970636b938SSara Sharon 52980636b938SSara Sharon out: 52995e1688ceSJohannes Berg if (sync) { 53002f7a04c7SJohannes Berg mvm->queue_sync_state = 0; 53010636b938SSara Sharon mvm->queue_sync_cookie++; 53020636b938SSara Sharon } 53035f8a3561SJohannes Berg } 53040636b938SSara Sharon 53050636b938SSara Sharon static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 53060636b938SSara Sharon { 53070636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 53080636b938SSara Sharon 53090636b938SSara Sharon mutex_lock(&mvm->mutex); 53105e1688ceSJohannes Berg iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0); 53110636b938SSara Sharon mutex_unlock(&mvm->mutex); 53120636b938SSara Sharon } 53130636b938SSara Sharon 5314b73f9a4aSJohannes Berg static int 5315b73f9a4aSJohannes Berg iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw, 5316b73f9a4aSJohannes Berg struct ieee80211_vif *vif, 5317b73f9a4aSJohannes Berg struct cfg80211_ftm_responder_stats *stats) 5318b73f9a4aSJohannes Berg { 5319b73f9a4aSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5320b73f9a4aSJohannes Berg struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 5321b73f9a4aSJohannes Berg 5322b73f9a4aSJohannes Berg if (vif->p2p || vif->type != NL80211_IFTYPE_AP || 5323b73f9a4aSJohannes Berg !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder) 5324b73f9a4aSJohannes Berg return -EINVAL; 5325b73f9a4aSJohannes Berg 5326b73f9a4aSJohannes Berg mutex_lock(&mvm->mutex); 5327b73f9a4aSJohannes Berg *stats = mvm->ftm_resp_stats; 5328b73f9a4aSJohannes Berg mutex_unlock(&mvm->mutex); 5329b73f9a4aSJohannes Berg 5330b73f9a4aSJohannes Berg stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) | 5331b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_PARTIAL_NUM) | 5332b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_FAILED_NUM) | 5333b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_ASAP_NUM) | 5334b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_NON_ASAP_NUM) | 5335b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) | 5336b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) | 5337b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) | 5338b73f9a4aSJohannes Berg BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM); 5339b73f9a4aSJohannes Berg 5340b73f9a4aSJohannes Berg return 0; 5341b73f9a4aSJohannes Berg } 5342b73f9a4aSJohannes Berg 5343fc36ffdaSJohannes Berg static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, 5344fc36ffdaSJohannes Berg struct ieee80211_vif *vif, 5345fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5346fc36ffdaSJohannes Berg { 5347fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5348fc36ffdaSJohannes Berg int ret; 5349fc36ffdaSJohannes Berg 5350fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5351fc36ffdaSJohannes Berg ret = iwl_mvm_ftm_start(mvm, vif, request); 5352fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5353fc36ffdaSJohannes Berg 5354fc36ffdaSJohannes Berg return ret; 5355fc36ffdaSJohannes Berg } 5356fc36ffdaSJohannes Berg 5357fc36ffdaSJohannes Berg static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, 5358fc36ffdaSJohannes Berg struct ieee80211_vif *vif, 5359fc36ffdaSJohannes Berg struct cfg80211_pmsr_request *request) 5360fc36ffdaSJohannes Berg { 5361fc36ffdaSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5362fc36ffdaSJohannes Berg 5363fc36ffdaSJohannes Berg mutex_lock(&mvm->mutex); 5364fc36ffdaSJohannes Berg iwl_mvm_ftm_abort(mvm, request); 5365fc36ffdaSJohannes Berg mutex_unlock(&mvm->mutex); 5366fc36ffdaSJohannes Berg } 5367fc36ffdaSJohannes Berg 5368438af969SSara Sharon static bool iwl_mvm_can_hw_csum(struct sk_buff *skb) 5369438af969SSara Sharon { 5370438af969SSara Sharon u8 protocol = ip_hdr(skb)->protocol; 5371438af969SSara Sharon 5372438af969SSara Sharon if (!IS_ENABLED(CONFIG_INET)) 5373438af969SSara Sharon return false; 5374438af969SSara Sharon 5375438af969SSara Sharon return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP; 5376438af969SSara Sharon } 5377438af969SSara Sharon 5378438af969SSara Sharon static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw, 5379438af969SSara Sharon struct sk_buff *head, 5380438af969SSara Sharon struct sk_buff *skb) 5381438af969SSara Sharon { 5382438af969SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 5383438af969SSara Sharon 53840792df68SJohannes Berg if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) 53850792df68SJohannes Berg return iwl_mvm_tx_csum_bz(mvm, head, true) == 53860792df68SJohannes Berg iwl_mvm_tx_csum_bz(mvm, skb, true); 53870792df68SJohannes Berg 5388438af969SSara Sharon /* For now don't aggregate IPv6 in AMSDU */ 5389438af969SSara Sharon if (skb->protocol != htons(ETH_P_IP)) 5390438af969SSara Sharon return false; 5391438af969SSara Sharon 5392438af969SSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) 5393438af969SSara Sharon return true; 5394438af969SSara Sharon 5395438af969SSara Sharon return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head); 5396438af969SSara Sharon } 5397438af969SSara Sharon 5398e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 5399e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 5400cfbc6c4cSSara Sharon .wake_tx_queue = iwl_mvm_mac_wake_tx_queue, 5401e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 5402e8503aecSBen Greear .get_antenna = iwl_mvm_op_get_antenna, 5403e705c121SKalle Valo .start = iwl_mvm_mac_start, 5404e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 5405e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 5406e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 5407e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 5408e705c121SKalle Valo .config = iwl_mvm_mac_config, 5409e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 5410e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 5411e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 5412e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 5413e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 5414e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 5415e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 5416e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 5417e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 5418e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 5419e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 5420e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 5421e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 5422e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 5423e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 54246b1259d1SJohannes Berg .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx, 5425e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 5426e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 5427e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 5428e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 5429e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 5430e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 5431e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 5432e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 5433e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 5434e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 5435e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 5436e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 5437e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 5438e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 5439e705c121SKalle Valo 5440ae7ba17bSShaul Triebitz .start_ap = iwl_mvm_start_ap, 5441ae7ba17bSShaul Triebitz .stop_ap = iwl_mvm_stop_ap, 5442ae7ba17bSShaul Triebitz .join_ibss = iwl_mvm_start_ibss, 5443ae7ba17bSShaul Triebitz .leave_ibss = iwl_mvm_stop_ibss, 5444e705c121SKalle Valo 54452f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 54462f0282dbSJohannes Berg 5447e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 5448e705c121SKalle Valo 5449e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 5450e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 5451e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 545279221126SSara Sharon .abort_channel_switch = iwl_mvm_abort_channel_switch, 5453c37763d2SSara Sharon .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon, 5454e705c121SKalle Valo 5455e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 5456e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 5457e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 5458e705c121SKalle Valo 5459e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 5460e705c121SKalle Valo 54610636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 54620636b938SSara Sharon 5463e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 5464e705c121SKalle Valo 5465e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 5466e705c121SKalle Valo /* look at d3.c */ 5467e705c121SKalle Valo .suspend = iwl_mvm_suspend, 5468e705c121SKalle Valo .resume = iwl_mvm_resume, 5469e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 5470e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 5471e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 5472e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 5473e705c121SKalle Valo #endif 5474e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 5475e705c121SKalle Valo #endif 5476e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 5477e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 5478b73f9a4aSJohannes Berg .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats, 5479fc36ffdaSJohannes Berg .start_pmsr = iwl_mvm_start_pmsr, 5480fc36ffdaSJohannes Berg .abort_pmsr = iwl_mvm_abort_pmsr, 5481b73f9a4aSJohannes Berg 5482438af969SSara Sharon .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate, 5483177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 5484177a11cfSGregory Greenman .sta_add_debugfs = iwl_mvm_sta_add_debugfs, 5485177a11cfSGregory Greenman #endif 5486e705c121SKalle Valo }; 5487