1e705c121SKalle Valo /****************************************************************************** 2e705c121SKalle Valo * 3e705c121SKalle Valo * This file is provided under a dual BSD/GPLv2 license. When using or 4e705c121SKalle Valo * redistributing this file, you may do so under either license. 5e705c121SKalle Valo * 6e705c121SKalle Valo * GPL LICENSE SUMMARY 7e705c121SKalle Valo * 8e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 926d6c16bSSara Sharon * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 1026d6c16bSSara Sharon * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 1163dd5d02SSara Sharon * Copyright(c) 2018 Intel Corporation 12e705c121SKalle Valo * 13e705c121SKalle Valo * This program is free software; you can redistribute it and/or modify 14e705c121SKalle Valo * it under the terms of version 2 of the GNU General Public License as 15e705c121SKalle Valo * published by the Free Software Foundation. 16e705c121SKalle Valo * 17e705c121SKalle Valo * This program is distributed in the hope that it will be useful, but 18e705c121SKalle Valo * WITHOUT ANY WARRANTY; without even the implied warranty of 19e705c121SKalle Valo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20e705c121SKalle Valo * General Public License for more details. 21e705c121SKalle Valo * 22e705c121SKalle Valo * The full GNU General Public License is included in this distribution 23e705c121SKalle Valo * in the file called COPYING. 24e705c121SKalle Valo * 25e705c121SKalle Valo * Contact Information: 26cb2f8277SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 27e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 28e705c121SKalle Valo * 29e705c121SKalle Valo * BSD LICENSE 30e705c121SKalle Valo * 31e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 3226d6c16bSSara Sharon * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 3326d6c16bSSara Sharon * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 34514c3069SLuca Coelho * Copyright(c) 2018 Intel Corporation 35e705c121SKalle Valo * All rights reserved. 36e705c121SKalle Valo * 37e705c121SKalle Valo * Redistribution and use in source and binary forms, with or without 38e705c121SKalle Valo * modification, are permitted provided that the following conditions 39e705c121SKalle Valo * are met: 40e705c121SKalle Valo * 41e705c121SKalle Valo * * Redistributions of source code must retain the above copyright 42e705c121SKalle Valo * notice, this list of conditions and the following disclaimer. 43e705c121SKalle Valo * * Redistributions in binary form must reproduce the above copyright 44e705c121SKalle Valo * notice, this list of conditions and the following disclaimer in 45e705c121SKalle Valo * the documentation and/or other materials provided with the 46e705c121SKalle Valo * distribution. 47e705c121SKalle Valo * * Neither the name Intel Corporation nor the names of its 48e705c121SKalle Valo * contributors may be used to endorse or promote products derived 49e705c121SKalle Valo * from this software without specific prior written permission. 50e705c121SKalle Valo * 51e705c121SKalle Valo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52e705c121SKalle Valo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53e705c121SKalle Valo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54e705c121SKalle Valo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55e705c121SKalle Valo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56e705c121SKalle Valo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57e705c121SKalle Valo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58e705c121SKalle Valo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59e705c121SKalle Valo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60e705c121SKalle Valo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61e705c121SKalle Valo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62e705c121SKalle Valo * 63e705c121SKalle Valo *****************************************************************************/ 64e705c121SKalle Valo #include <linux/kernel.h> 65e705c121SKalle Valo #include <linux/slab.h> 66e705c121SKalle Valo #include <linux/skbuff.h> 67e705c121SKalle Valo #include <linux/netdevice.h> 68e705c121SKalle Valo #include <linux/etherdevice.h> 69e705c121SKalle Valo #include <linux/ip.h> 70e705c121SKalle Valo #include <linux/if_arp.h> 712f89a5d7SGolan Ben-Ami #include <linux/time.h> 72e705c121SKalle Valo #include <net/mac80211.h> 73e705c121SKalle Valo #include <net/ieee80211_radiotap.h> 74e705c121SKalle Valo #include <net/tcp.h> 75e705c121SKalle Valo 76e705c121SKalle Valo #include "iwl-op-mode.h" 77e705c121SKalle Valo #include "iwl-io.h" 78e705c121SKalle Valo #include "mvm.h" 79e705c121SKalle Valo #include "sta.h" 80e705c121SKalle Valo #include "time-event.h" 81e705c121SKalle Valo #include "iwl-eeprom-parse.h" 82e705c121SKalle Valo #include "iwl-phy-db.h" 83e705c121SKalle Valo #include "testmode.h" 84d962f9b1SJohannes Berg #include "fw/error-dump.h" 85e705c121SKalle Valo #include "iwl-prph.h" 86e705c121SKalle Valo #include "iwl-nvm-parse.h" 87e705c121SKalle Valo 88e705c121SKalle Valo static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 89e705c121SKalle Valo { 90e705c121SKalle Valo .max = 1, 91e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_STATION), 92e705c121SKalle Valo }, 93e705c121SKalle Valo { 94e705c121SKalle Valo .max = 1, 95e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_AP) | 96e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 97e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO), 98e705c121SKalle Valo }, 99e705c121SKalle Valo { 100e705c121SKalle Valo .max = 1, 101e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 102e705c121SKalle Valo }, 103e705c121SKalle Valo }; 104e705c121SKalle Valo 105e705c121SKalle Valo static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 106e705c121SKalle Valo { 107e705c121SKalle Valo .num_different_channels = 2, 108e705c121SKalle Valo .max_interfaces = 3, 109e705c121SKalle Valo .limits = iwl_mvm_limits, 110e705c121SKalle Valo .n_limits = ARRAY_SIZE(iwl_mvm_limits), 111e705c121SKalle Valo }, 112e705c121SKalle Valo }; 113e705c121SKalle Valo 114e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 115e705c121SKalle Valo /* 116e705c121SKalle Valo * Use the reserved field to indicate magic values. 117e705c121SKalle Valo * these values will only be used internally by the driver, 118e705c121SKalle Valo * and won't make it to the fw (reserved will be 0). 119e705c121SKalle Valo * BC_FILTER_MAGIC_IP - configure the val of this attribute to 120e705c121SKalle Valo * be the vif's ip address. in case there is not a single 121e705c121SKalle Valo * ip address (0, or more than 1), this attribute will 122e705c121SKalle Valo * be skipped. 123e705c121SKalle Valo * BC_FILTER_MAGIC_MAC - set the val of this attribute to 124e705c121SKalle Valo * the LSB bytes of the vif's mac address 125e705c121SKalle Valo */ 126e705c121SKalle Valo enum { 127e705c121SKalle Valo BC_FILTER_MAGIC_NONE = 0, 128e705c121SKalle Valo BC_FILTER_MAGIC_IP, 129e705c121SKalle Valo BC_FILTER_MAGIC_MAC, 130e705c121SKalle Valo }; 131e705c121SKalle Valo 132e705c121SKalle Valo static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { 133e705c121SKalle Valo { 134e705c121SKalle Valo /* arp */ 135e705c121SKalle Valo .discard = 0, 136e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, 137e705c121SKalle Valo .attrs = { 138e705c121SKalle Valo { 139e705c121SKalle Valo /* frame type - arp, hw type - ethernet */ 140e705c121SKalle Valo .offset_type = 141e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 142e705c121SKalle Valo .offset = sizeof(rfc1042_header), 143e705c121SKalle Valo .val = cpu_to_be32(0x08060001), 144e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 145e705c121SKalle Valo }, 146e705c121SKalle Valo { 147e705c121SKalle Valo /* arp dest ip */ 148e705c121SKalle Valo .offset_type = 149e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 150e705c121SKalle Valo .offset = sizeof(rfc1042_header) + 2 + 151e705c121SKalle Valo sizeof(struct arphdr) + 152e705c121SKalle Valo ETH_ALEN + sizeof(__be32) + 153e705c121SKalle Valo ETH_ALEN, 154e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 155e705c121SKalle Valo /* mark it as special field */ 156e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), 157e705c121SKalle Valo }, 158e705c121SKalle Valo }, 159e705c121SKalle Valo }, 160e705c121SKalle Valo { 161e705c121SKalle Valo /* dhcp offer bcast */ 162e705c121SKalle Valo .discard = 0, 163e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, 164e705c121SKalle Valo .attrs = { 165e705c121SKalle Valo { 166e705c121SKalle Valo /* udp dest port - 68 (bootp client)*/ 167e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 168e705c121SKalle Valo .offset = offsetof(struct udphdr, dest), 169e705c121SKalle Valo .val = cpu_to_be32(0x00440000), 170e705c121SKalle Valo .mask = cpu_to_be32(0xffff0000), 171e705c121SKalle Valo }, 172e705c121SKalle Valo { 173e705c121SKalle Valo /* dhcp - lsb bytes of client hw address */ 174e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 175e705c121SKalle Valo .offset = 38, 176e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 177e705c121SKalle Valo /* mark it as special field */ 178e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), 179e705c121SKalle Valo }, 180e705c121SKalle Valo }, 181e705c121SKalle Valo }, 182e705c121SKalle Valo /* last filter must be empty */ 183e705c121SKalle Valo {}, 184e705c121SKalle Valo }; 185e705c121SKalle Valo #endif 186e705c121SKalle Valo 187e705c121SKalle Valo void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 188e705c121SKalle Valo { 189e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 190e705c121SKalle Valo return; 191e705c121SKalle Valo 192e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type); 193e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 194e705c121SKalle Valo mvm->refs[ref_type]++; 195e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 196e705c121SKalle Valo iwl_trans_ref(mvm->trans); 197e705c121SKalle Valo } 198e705c121SKalle Valo 199e705c121SKalle Valo void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 200e705c121SKalle Valo { 201e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 202e705c121SKalle Valo return; 203e705c121SKalle Valo 204e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type); 205e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 20616c45822SSara Sharon if (WARN_ON(!mvm->refs[ref_type])) { 20716c45822SSara Sharon spin_unlock_bh(&mvm->refs_lock); 20816c45822SSara Sharon return; 20916c45822SSara Sharon } 21016c45822SSara Sharon mvm->refs[ref_type]--; 211e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 212e705c121SKalle Valo iwl_trans_unref(mvm->trans); 213e705c121SKalle Valo } 214e705c121SKalle Valo 215e705c121SKalle Valo static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm, 216e705c121SKalle Valo enum iwl_mvm_ref_type except_ref) 217e705c121SKalle Valo { 218e705c121SKalle Valo int i, j; 219e705c121SKalle Valo 220e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 221e705c121SKalle Valo return; 222e705c121SKalle Valo 223e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 224e705c121SKalle Valo for (i = 0; i < IWL_MVM_REF_COUNT; i++) { 225e705c121SKalle Valo if (except_ref == i || !mvm->refs[i]) 226e705c121SKalle Valo continue; 227e705c121SKalle Valo 228e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n", 229e705c121SKalle Valo i, mvm->refs[i]); 230e705c121SKalle Valo for (j = 0; j < mvm->refs[i]; j++) 231e705c121SKalle Valo iwl_trans_unref(mvm->trans); 232e705c121SKalle Valo mvm->refs[i] = 0; 233e705c121SKalle Valo } 234e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 235e705c121SKalle Valo } 236e705c121SKalle Valo 237e705c121SKalle Valo bool iwl_mvm_ref_taken(struct iwl_mvm *mvm) 238e705c121SKalle Valo { 239e705c121SKalle Valo int i; 240e705c121SKalle Valo bool taken = false; 241e705c121SKalle Valo 242e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 243e705c121SKalle Valo return true; 244e705c121SKalle Valo 245e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 246e705c121SKalle Valo for (i = 0; i < IWL_MVM_REF_COUNT; i++) { 247e705c121SKalle Valo if (mvm->refs[i]) { 248e705c121SKalle Valo taken = true; 249e705c121SKalle Valo break; 250e705c121SKalle Valo } 251e705c121SKalle Valo } 252e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 253e705c121SKalle Valo 254e705c121SKalle Valo return taken; 255e705c121SKalle Valo } 256e705c121SKalle Valo 257e705c121SKalle Valo int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 258e705c121SKalle Valo { 259e705c121SKalle Valo iwl_mvm_ref(mvm, ref_type); 260e705c121SKalle Valo 261e705c121SKalle Valo if (!wait_event_timeout(mvm->d0i3_exit_waitq, 262e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), 263e705c121SKalle Valo HZ)) { 264e705c121SKalle Valo WARN_ON_ONCE(1); 265e705c121SKalle Valo iwl_mvm_unref(mvm, ref_type); 266e705c121SKalle Valo return -EIO; 267e705c121SKalle Valo } 268e705c121SKalle Valo 269e705c121SKalle Valo return 0; 270e705c121SKalle Valo } 271e705c121SKalle Valo 272e705c121SKalle Valo static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 273e705c121SKalle Valo { 274e705c121SKalle Valo int i; 275e705c121SKalle Valo 276e705c121SKalle Valo memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 277e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 278e705c121SKalle Valo mvm->phy_ctxts[i].id = i; 279e705c121SKalle Valo mvm->phy_ctxts[i].ref = 0; 280e705c121SKalle Valo } 281e705c121SKalle Valo } 282e705c121SKalle Valo 283e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 284e705c121SKalle Valo const char *alpha2, 285e705c121SKalle Valo enum iwl_mcc_source src_id, 286e705c121SKalle Valo bool *changed) 287e705c121SKalle Valo { 288e705c121SKalle Valo struct ieee80211_regdomain *regd = NULL; 289e705c121SKalle Valo struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 290e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 291e705c121SKalle Valo struct iwl_mcc_update_resp *resp; 292e705c121SKalle Valo 293e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 294e705c121SKalle Valo 295e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 296e705c121SKalle Valo 297e705c121SKalle Valo resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 298e705c121SKalle Valo if (IS_ERR_OR_NULL(resp)) { 299e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 300e705c121SKalle Valo PTR_ERR_OR_ZERO(resp)); 301e705c121SKalle Valo goto out; 302e705c121SKalle Valo } 303e705c121SKalle Valo 304e705c121SKalle Valo if (changed) 305e705c121SKalle Valo *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE); 306e705c121SKalle Valo 307e705c121SKalle Valo regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 308e705c121SKalle Valo __le32_to_cpu(resp->n_channels), 309e705c121SKalle Valo resp->channels, 31077e30e10SHaim Dreyfuss __le16_to_cpu(resp->mcc), 31177e30e10SHaim Dreyfuss __le16_to_cpu(resp->geo_info)); 312e705c121SKalle Valo /* Store the return source id */ 313e705c121SKalle Valo src_id = resp->source_id; 314e705c121SKalle Valo kfree(resp); 315e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 316e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 317e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 318e705c121SKalle Valo goto out; 319e705c121SKalle Valo } 320e705c121SKalle Valo 321e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 322e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 323e705c121SKalle Valo mvm->lar_regdom_set = true; 324e705c121SKalle Valo mvm->mcc_src = src_id; 325e705c121SKalle Valo 326e705c121SKalle Valo out: 327e705c121SKalle Valo return regd; 328e705c121SKalle Valo } 329e705c121SKalle Valo 330e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 331e705c121SKalle Valo { 332e705c121SKalle Valo bool changed; 333e705c121SKalle Valo struct ieee80211_regdomain *regd; 334e705c121SKalle Valo 335e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 336e705c121SKalle Valo return; 337e705c121SKalle Valo 338e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 339e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 340e705c121SKalle Valo /* only update the regulatory core if changed */ 341e705c121SKalle Valo if (changed) 342e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 343e705c121SKalle Valo 344e705c121SKalle Valo kfree(regd); 345e705c121SKalle Valo } 346e705c121SKalle Valo } 347e705c121SKalle Valo 348e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 349e705c121SKalle Valo bool *changed) 350e705c121SKalle Valo { 351e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 352e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 353e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 354e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 355e705c121SKalle Valo } 356e705c121SKalle Valo 357e705c121SKalle Valo int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) 358e705c121SKalle Valo { 359e705c121SKalle Valo enum iwl_mcc_source used_src; 360e705c121SKalle Valo struct ieee80211_regdomain *regd; 361e705c121SKalle Valo int ret; 362e705c121SKalle Valo bool changed; 363e705c121SKalle Valo const struct ieee80211_regdomain *r = 364e705c121SKalle Valo rtnl_dereference(mvm->hw->wiphy->regd); 365e705c121SKalle Valo 366e705c121SKalle Valo if (!r) 367e705c121SKalle Valo return -ENOENT; 368e705c121SKalle Valo 369e705c121SKalle Valo /* save the last source in case we overwrite it below */ 370e705c121SKalle Valo used_src = mvm->mcc_src; 371e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 372e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 373e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 374e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 375e705c121SKalle Valo kfree(regd); 376e705c121SKalle Valo } 377e705c121SKalle Valo 378e705c121SKalle Valo /* Now set our last stored MCC and source */ 379e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 380e705c121SKalle Valo &changed); 381e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 382e705c121SKalle Valo return -EIO; 383e705c121SKalle Valo 384e705c121SKalle Valo /* update cfg80211 if the regdomain was changed */ 385e705c121SKalle Valo if (changed) 386e705c121SKalle Valo ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd); 387e705c121SKalle Valo else 388e705c121SKalle Valo ret = 0; 389e705c121SKalle Valo 390e705c121SKalle Valo kfree(regd); 391e705c121SKalle Valo return ret; 392e705c121SKalle Valo } 393e705c121SKalle Valo 394e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 395e705c121SKalle Valo { 396e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 397e705c121SKalle Valo int num_mac, ret, i; 398e705c121SKalle Valo static const u32 mvm_ciphers[] = { 399e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 400e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 401e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 402e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 403e705c121SKalle Valo }; 404e705c121SKalle Valo 405e705c121SKalle Valo /* Tell mac80211 our characteristics */ 406e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 407e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 408e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 409e705c121SKalle Valo ieee80211_hw_set(hw, QUEUE_CONTROL); 410e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 411e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 412e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 413e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 414e705c121SKalle Valo ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 415e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 416e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 417e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 418e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 419909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 42030433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 421d270e7b8SIlan Peer ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP); 422ecaf71deSGregory Greenman 4234243edb4SEmmanuel Grumbach if (iwl_mvm_has_tlc_offload(mvm)) { 424ecaf71deSGregory Greenman ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW); 425ecaf71deSGregory Greenman ieee80211_hw_set(hw, HAS_RATE_CONTROL); 426ecaf71deSGregory Greenman } 427ecaf71deSGregory Greenman 428b915c101SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 429b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 430960f864bSJohannes Berg 431960f864bSJohannes Berg if (fw_has_capa(&mvm->fw->ucode_capa, 432960f864bSJohannes Berg IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) { 43365e25482SJohannes Berg ieee80211_hw_set(hw, AP_LINK_PS); 434960f864bSJohannes Berg } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { 435960f864bSJohannes Berg /* 436960f864bSJohannes Berg * we absolutely need this for the new TX API since that comes 437960f864bSJohannes Berg * with many more queues than the current code can deal with 438960f864bSJohannes Berg * for station powersave 439960f864bSJohannes Berg */ 440960f864bSJohannes Berg return -EINVAL; 441960f864bSJohannes Berg } 442e705c121SKalle Valo 44380938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 44480938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 44580938abcSJohannes Berg 4462d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 4472d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 4482d7cf549SJohannes Berg 449cf961e16SLiad Kaufman hw->queues = IEEE80211_MAX_QUEUES; 450e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 451e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 452e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 453e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 454e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 455371a17edSJohannes Berg 456371a17edSJohannes Berg hw->radiotap_timestamp.units_pos = 457371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US | 458371a17edSJohannes Berg IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; 459371a17edSJohannes Berg /* this is the case for CCK frames, it's better (only 8) for OFDM */ 460371a17edSJohannes Berg hw->radiotap_timestamp.accuracy = 22; 461371a17edSJohannes Berg 4624243edb4SEmmanuel Grumbach if (!iwl_mvm_has_tlc_offload(mvm)) 4639f66a397SGregory Greenman hw->rate_control_algorithm = RS_NAME; 4649f66a397SGregory Greenman 465e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 466e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 467e705c121SKalle Valo 4688e160ab8SAyala Beker BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6); 469e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 470e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 471e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 472e705c121SKalle Valo 4732a53d166SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4742a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4752a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP; 4762a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4772a53d166SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4782a53d166SAyala Beker WLAN_CIPHER_SUITE_GCMP_256; 4792a53d166SAyala Beker hw->wiphy->n_cipher_suites++; 4802a53d166SAyala Beker } 4812a53d166SAyala Beker 4824b87e5afSLuca Coelho /* Enable 11w if software crypto is not enabled (as the 4834b87e5afSLuca Coelho * firmware will interpret some mgmt packets, so enabling it 4844b87e5afSLuca Coelho * with software crypto isn't safe). 485e705c121SKalle Valo */ 4863b37f4c9SJohannes Berg if (!iwlwifi_mod_params.swcrypto) { 487e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 488e705c121SKalle Valo mvm->ciphers[hw->wiphy->n_cipher_suites] = 489e705c121SKalle Valo WLAN_CIPHER_SUITE_AES_CMAC; 490e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 4918e160ab8SAyala Beker if (iwl_mvm_has_new_rx_api(mvm)) { 4928e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4938e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_128; 4948e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4958e160ab8SAyala Beker mvm->ciphers[hw->wiphy->n_cipher_suites] = 4968e160ab8SAyala Beker WLAN_CIPHER_SUITE_BIP_GMAC_256; 4978e160ab8SAyala Beker hw->wiphy->n_cipher_suites++; 4988e160ab8SAyala Beker } 499e705c121SKalle Valo } 500e705c121SKalle Valo 501e705c121SKalle Valo /* currently FW API supports only one optional cipher scheme */ 502e705c121SKalle Valo if (mvm->fw->cs[0].cipher) { 50324ddddf3SJohannes Berg const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0]; 50424ddddf3SJohannes Berg struct ieee80211_cipher_scheme *cs = &mvm->cs[0]; 50524ddddf3SJohannes Berg 506e705c121SKalle Valo mvm->hw->n_cipher_schemes = 1; 50724ddddf3SJohannes Berg 50824ddddf3SJohannes Berg cs->cipher = le32_to_cpu(fwcs->cipher); 50924ddddf3SJohannes Berg cs->iftype = BIT(NL80211_IFTYPE_STATION); 51024ddddf3SJohannes Berg cs->hdr_len = fwcs->hdr_len; 51124ddddf3SJohannes Berg cs->pn_len = fwcs->pn_len; 51224ddddf3SJohannes Berg cs->pn_off = fwcs->pn_off; 51324ddddf3SJohannes Berg cs->key_idx_off = fwcs->key_idx_off; 51424ddddf3SJohannes Berg cs->key_idx_mask = fwcs->key_idx_mask; 51524ddddf3SJohannes Berg cs->key_idx_shift = fwcs->key_idx_shift; 51624ddddf3SJohannes Berg cs->mic_len = fwcs->mic_len; 51724ddddf3SJohannes Berg 51824ddddf3SJohannes Berg mvm->hw->cipher_schemes = mvm->cs; 51924ddddf3SJohannes Berg mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher; 520e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 521e705c121SKalle Valo } 522e705c121SKalle Valo 523e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 524e705c121SKalle Valo hw->wiphy->features |= 525e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 526e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 527e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 528e705c121SKalle Valo 529e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 530e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 531e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 532e705c121SKalle Valo 533e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 534e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 535e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 536e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 537e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 538e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 539e705c121SKalle Valo 540e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 541e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 542e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 543e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 544e705c121SKalle Valo else 545e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 546e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 547e705c121SKalle Valo 548e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 549e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 550e705c121SKalle Valo 551e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 552e705c121SKalle Valo hw->wiphy->n_iface_combinations = 553e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 554e705c121SKalle Valo 555e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 556e705c121SKalle Valo hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 557e705c121SKalle Valo 558e705c121SKalle Valo /* Extract MAC address */ 559e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 560e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 561e705c121SKalle Valo hw->wiphy->n_addresses = 1; 562e705c121SKalle Valo 563e705c121SKalle Valo /* Extract additional MAC addresses if available */ 564e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 565e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 566e705c121SKalle Valo 567e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 568e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 569e705c121SKalle Valo ETH_ALEN); 570e705c121SKalle Valo mvm->addresses[i].addr[5]++; 571e705c121SKalle Valo hw->wiphy->n_addresses++; 572e705c121SKalle Valo } 573e705c121SKalle Valo 574e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 575e705c121SKalle Valo 576e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 577e705c121SKalle Valo 578e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 579e705c121SKalle Valo 580e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 581e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 582e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 583e705c121SKalle Valo 584e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 585e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 586e705c121SKalle Valo else 587e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 588e705c121SKalle Valo 58957fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 59057fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 59157fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 59257fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 59357fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 59457fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 595e705c121SKalle Valo 596e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 597e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 598e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 599e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 60057fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 601e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 602e705c121SKalle Valo } 603e705c121SKalle Valo 604e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 605e705c121SKalle Valo 606e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 607e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 608e705c121SKalle Valo else 609e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 610e705c121SKalle Valo 611ca986ad9SArend Van Spriel hw->wiphy->max_sched_scan_reqs = 1; 612e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 613e705c121SKalle Valo hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; 614e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 615e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 616e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 617e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 618e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 619e705c121SKalle Valo 620e705c121SKalle Valo /* 621e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 622e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 623e705c121SKalle Valo */ 624e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 625e705c121SKalle Valo 626e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 627e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 628e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 629a904a08bSPeer, Ilan NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | 630e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 631e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 632e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 633e705c121SKalle Valo 634e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 635e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 636e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 637e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 638e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 639e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 640e705c121SKalle Valo 641e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 642e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 643e705c121SKalle Valo hw->wiphy->features |= 644e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 645e705c121SKalle Valo 646e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 647e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 648e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 649e705c121SKalle Valo 650aacf8f18SAvrahams Stern if (fw_has_api(&mvm->fw->ucode_capa, 651aacf8f18SAvrahams Stern IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) { 652aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 653aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SCAN_START_TIME); 654aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 655aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_BSS_PARENT_TSF); 656aacf8f18SAvrahams Stern wiphy_ext_feature_set(hw->wiphy, 657aacf8f18SAvrahams Stern NL80211_EXT_FEATURE_SET_SCAN_DWELL); 658aacf8f18SAvrahams Stern } 659aacf8f18SAvrahams Stern 6608f691af9SZamir, Roee if (iwl_mvm_is_oce_supported(mvm)) { 6618f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6628f691af9SZamir, Roee NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP); 6638f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6648f691af9SZamir, Roee NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME); 6658f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6668f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION); 6678f691af9SZamir, Roee wiphy_ext_feature_set(hw->wiphy, 6688f691af9SZamir, Roee NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE); 6698f691af9SZamir, Roee } 6708f691af9SZamir, Roee 671e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 672e705c121SKalle Valo 673e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 674e705c121SKalle Valo if (iwl_mvm_is_d0i3_supported(mvm) && 675e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 676e705c121SKalle Valo mvm->wowlan.flags = WIPHY_WOWLAN_ANY; 677e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 678e705c121SKalle Valo } 679e705c121SKalle Valo 680eef187a7SSara Sharon if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec && 681e705c121SKalle Valo mvm->trans->ops->d3_suspend && 682e705c121SKalle Valo mvm->trans->ops->d3_resume && 683e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 684e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 685e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 686e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 687e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 688e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 6893b37f4c9SJohannes Berg if (!iwlwifi_mod_params.swcrypto) 690e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 691e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 692e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 693e705c121SKalle Valo 694e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 695e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 696e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 697e705c121SKalle Valo mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES; 698e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 699e705c121SKalle Valo } 700e705c121SKalle Valo #endif 701e705c121SKalle Valo 702e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 703e705c121SKalle Valo /* assign default bcast filtering configuration */ 704e705c121SKalle Valo mvm->bcast_filters = iwl_mvm_default_bcast_filters; 705e705c121SKalle Valo #endif 706e705c121SKalle Valo 707e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 708e705c121SKalle Valo if (ret) 709e705c121SKalle Valo return ret; 710e705c121SKalle Valo 711e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 712e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 713e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 714e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 715e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 716e705c121SKalle Valo } 717e705c121SKalle Valo 718e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 719e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 720e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 721e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 722e705c121SKalle Valo } 723e705c121SKalle Valo 724e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 7255e6a98dcSSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) { 7265e6a98dcSSara Sharon hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS | 7275e6a98dcSSara Sharon NETIF_F_RXCSUM); 7285e6a98dcSSara Sharon /* We may support SW TX CSUM */ 72941837ca9SEmmanuel Grumbach if (IWL_MVM_SW_TX_CSUM_OFFLOAD) 7305e6a98dcSSara Sharon hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS; 7315e6a98dcSSara Sharon } 73241837ca9SEmmanuel Grumbach 733e705c121SKalle Valo ret = ieee80211_register_hw(mvm->hw); 734e705c121SKalle Valo if (ret) 735e705c121SKalle Valo iwl_mvm_leds_exit(mvm); 736de8ba41bSLiad Kaufman mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE; 737e705c121SKalle Valo 73891b08c2dSAviya Erenfeld if (mvm->cfg->vht_mu_mimo_supported) 73991b08c2dSAviya Erenfeld wiphy_ext_feature_set(hw->wiphy, 74091b08c2dSAviya Erenfeld NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER); 74191b08c2dSAviya Erenfeld 742e705c121SKalle Valo return ret; 743e705c121SKalle Valo } 744e705c121SKalle Valo 745e705c121SKalle Valo static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm, 746e705c121SKalle Valo struct ieee80211_sta *sta, 747e705c121SKalle Valo struct sk_buff *skb) 748e705c121SKalle Valo { 749e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 750e705c121SKalle Valo bool defer = false; 751e705c121SKalle Valo 752e705c121SKalle Valo /* 753e705c121SKalle Valo * double check the IN_D0I3 flag both before and after 754e705c121SKalle Valo * taking the spinlock, in order to prevent taking 755e705c121SKalle Valo * the spinlock when not needed. 756e705c121SKalle Valo */ 757e705c121SKalle Valo if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))) 758e705c121SKalle Valo return false; 759e705c121SKalle Valo 760e705c121SKalle Valo spin_lock(&mvm->d0i3_tx_lock); 761e705c121SKalle Valo /* 762e705c121SKalle Valo * testing the flag again ensures the skb dequeue 763e705c121SKalle Valo * loop (on d0i3 exit) hasn't run yet. 764e705c121SKalle Valo */ 765e705c121SKalle Valo if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) 766e705c121SKalle Valo goto out; 767e705c121SKalle Valo 768e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 7690ae98812SSara Sharon if (mvmsta->sta_id == IWL_MVM_INVALID_STA || 770e705c121SKalle Valo mvmsta->sta_id != mvm->d0i3_ap_sta_id) 771e705c121SKalle Valo goto out; 772e705c121SKalle Valo 773e705c121SKalle Valo __skb_queue_tail(&mvm->d0i3_tx, skb); 774e705c121SKalle Valo ieee80211_stop_queues(mvm->hw); 775e705c121SKalle Valo 776e705c121SKalle Valo /* trigger wakeup */ 777e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_TX); 778e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_TX); 779e705c121SKalle Valo 780e705c121SKalle Valo defer = true; 781e705c121SKalle Valo out: 782e705c121SKalle Valo spin_unlock(&mvm->d0i3_tx_lock); 783e705c121SKalle Valo return defer; 784e705c121SKalle Valo } 785e705c121SKalle Valo 786e705c121SKalle Valo static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 787e705c121SKalle Valo struct ieee80211_tx_control *control, 788e705c121SKalle Valo struct sk_buff *skb) 789e705c121SKalle Valo { 790e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 791e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 792e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 793e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 794e705c121SKalle Valo 795e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 796e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 797e705c121SKalle Valo goto drop; 798e705c121SKalle Valo } 799e705c121SKalle Valo 800d20e30afSEmmanuel Grumbach if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && 801e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 802e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 803e705c121SKalle Valo goto drop; 804e705c121SKalle Valo 805eb045e6eSDavid Spinadel /* treat non-bufferable MMPDUs on AP interfaces as broadcast */ 806eb045e6eSDavid Spinadel if ((info->control.vif->type == NL80211_IFTYPE_AP || 807eb045e6eSDavid Spinadel info->control.vif->type == NL80211_IFTYPE_ADHOC) && 808e705c121SKalle Valo ieee80211_is_mgmt(hdr->frame_control) && 809eb045e6eSDavid Spinadel !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) 810e705c121SKalle Valo sta = NULL; 811e705c121SKalle Valo 812dc1aca22SAndrei Otcheretianski /* If there is no sta, and it's not offchannel - send through AP */ 813dc1aca22SAndrei Otcheretianski if (info->control.vif->type == NL80211_IFTYPE_STATION && 814dc1aca22SAndrei Otcheretianski info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) { 815dc1aca22SAndrei Otcheretianski struct iwl_mvm_vif *mvmvif = 816dc1aca22SAndrei Otcheretianski iwl_mvm_vif_from_mac80211(info->control.vif); 817dc1aca22SAndrei Otcheretianski u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id); 818dc1aca22SAndrei Otcheretianski 819dc1aca22SAndrei Otcheretianski if (ap_sta_id < IWL_MVM_STATION_COUNT) { 820dc1aca22SAndrei Otcheretianski /* mac80211 holds rcu read lock */ 821dc1aca22SAndrei Otcheretianski sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]); 822dc1aca22SAndrei Otcheretianski if (IS_ERR_OR_NULL(sta)) 823dc1aca22SAndrei Otcheretianski goto drop; 824dc1aca22SAndrei Otcheretianski } 825dc1aca22SAndrei Otcheretianski } 826dc1aca22SAndrei Otcheretianski 827e705c121SKalle Valo if (sta) { 828e705c121SKalle Valo if (iwl_mvm_defer_tx(mvm, sta, skb)) 829e705c121SKalle Valo return; 830e705c121SKalle Valo if (iwl_mvm_tx_skb(mvm, skb, sta)) 831e705c121SKalle Valo goto drop; 832e705c121SKalle Valo return; 833e705c121SKalle Valo } 834e705c121SKalle Valo 835e705c121SKalle Valo if (iwl_mvm_tx_skb_non_sta(mvm, skb)) 836e705c121SKalle Valo goto drop; 837e705c121SKalle Valo return; 838e705c121SKalle Valo drop: 839e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 840e705c121SKalle Valo } 841e705c121SKalle Valo 842e705c121SKalle Valo static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg) 843e705c121SKalle Valo { 844e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) 845e705c121SKalle Valo return false; 846e705c121SKalle Valo return true; 847e705c121SKalle Valo } 848e705c121SKalle Valo 849e705c121SKalle Valo static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg) 850e705c121SKalle Valo { 851e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) 852e705c121SKalle Valo return false; 853e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG) 854e705c121SKalle Valo return true; 855e705c121SKalle Valo 856e705c121SKalle Valo /* enabled by default */ 857e705c121SKalle Valo return true; 858e705c121SKalle Valo } 859e705c121SKalle Valo 860e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 861e705c121SKalle Valo do { \ 862e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 863e705c121SKalle Valo break; \ 8647174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \ 865e705c121SKalle Valo } while (0) 866e705c121SKalle Valo 867e705c121SKalle Valo static void 868e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 869e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 870e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 871e705c121SKalle Valo { 872e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 873e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 874e705c121SKalle Valo 8756c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 8766c042d75SSara Sharon FW_DBG_TRIGGER_BA); 8776c042d75SSara Sharon if (!trig) 878e705c121SKalle Valo return; 879e705c121SKalle Valo 880e705c121SKalle Valo ba_trig = (void *)trig->data; 881e705c121SKalle Valo 882e705c121SKalle Valo switch (action) { 883e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 884e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 885e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 886e705c121SKalle Valo 887e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 888e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 889e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 890e705c121SKalle Valo break; 891e705c121SKalle Valo } 892e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 893e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 894e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 895e705c121SKalle Valo sta->addr, tid); 896e705c121SKalle Valo break; 897e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 898e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 899e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 900e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 901e705c121SKalle Valo break; 902e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 903e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 904e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 905e705c121SKalle Valo sta->addr, tid); 906e705c121SKalle Valo break; 907e705c121SKalle Valo default: 908e705c121SKalle Valo break; 909e705c121SKalle Valo } 910e705c121SKalle Valo } 911e705c121SKalle Valo 912e705c121SKalle Valo static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 913e705c121SKalle Valo struct ieee80211_vif *vif, 91450ea05efSSara Sharon struct ieee80211_ampdu_params *params) 915e705c121SKalle Valo { 916e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 917e705c121SKalle Valo int ret; 918e705c121SKalle Valo bool tx_agg_ref = false; 91950ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 92050ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 92150ea05efSSara Sharon u16 tid = params->tid; 92250ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 923514c3069SLuca Coelho u16 buf_size = params->buf_size; 924bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 92510b2b201SSara Sharon u16 timeout = params->timeout; 926e705c121SKalle Valo 927e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 928e705c121SKalle Valo sta->addr, tid, action); 929e705c121SKalle Valo 930e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 931e705c121SKalle Valo return -EACCES; 932e705c121SKalle Valo 933e705c121SKalle Valo /* return from D0i3 before starting a new Tx aggregation */ 934e705c121SKalle Valo switch (action) { 935e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 936e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 937e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 938e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 939e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 940e705c121SKalle Valo /* 941e705c121SKalle Valo * for tx start, wait synchronously until D0i3 exit to 942e705c121SKalle Valo * get the correct sequence number for the tid. 943e705c121SKalle Valo * additionally, some other ampdu actions use direct 944e705c121SKalle Valo * target access, which is not handled automatically 945e705c121SKalle Valo * by the trans layer (unlike commands), so wait for 946e705c121SKalle Valo * d0i3 exit in these cases as well. 947e705c121SKalle Valo */ 948e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG); 949e705c121SKalle Valo if (ret) 950e705c121SKalle Valo return ret; 951e705c121SKalle Valo 952e705c121SKalle Valo tx_agg_ref = true; 953e705c121SKalle Valo break; 954e705c121SKalle Valo default: 955e705c121SKalle Valo break; 956e705c121SKalle Valo } 957e705c121SKalle Valo 958e705c121SKalle Valo mutex_lock(&mvm->mutex); 959e705c121SKalle Valo 960e705c121SKalle Valo switch (action) { 961e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 962b0ffe455SJohannes Berg if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id == 963b0ffe455SJohannes Berg iwl_mvm_sta_from_mac80211(sta)->sta_id) { 964b0ffe455SJohannes Berg struct iwl_mvm_vif *mvmvif; 965b0ffe455SJohannes Berg u16 macid = iwl_mvm_vif_from_mac80211(vif)->id; 966b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid]; 967b0ffe455SJohannes Berg 968b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = true; 969b0ffe455SJohannes Berg mvmvif = iwl_mvm_vif_from_mac80211(vif); 970b0ffe455SJohannes Berg cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk); 971b0ffe455SJohannes Berg } 972e705c121SKalle Valo if (!iwl_enable_rx_ampdu(mvm->cfg)) { 973e705c121SKalle Valo ret = -EINVAL; 974e705c121SKalle Valo break; 975e705c121SKalle Valo } 97610b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 97710b2b201SSara Sharon timeout); 978e705c121SKalle Valo break; 979e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 98010b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 98110b2b201SSara Sharon timeout); 982e705c121SKalle Valo break; 983e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 984e705c121SKalle Valo if (!iwl_enable_tx_ampdu(mvm->cfg)) { 985e705c121SKalle Valo ret = -EINVAL; 986e705c121SKalle Valo break; 987e705c121SKalle Valo } 988e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 989e705c121SKalle Valo break; 990e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 991e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 992e705c121SKalle Valo break; 993e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 994e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 995e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 996e705c121SKalle Valo break; 997e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 998bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 999bb81bb68SEmmanuel Grumbach buf_size, amsdu); 1000e705c121SKalle Valo break; 1001e705c121SKalle Valo default: 1002e705c121SKalle Valo WARN_ON_ONCE(1); 1003e705c121SKalle Valo ret = -EINVAL; 1004e705c121SKalle Valo break; 1005e705c121SKalle Valo } 1006e705c121SKalle Valo 1007e705c121SKalle Valo if (!ret) { 1008e705c121SKalle Valo u16 rx_ba_ssn = 0; 1009e705c121SKalle Valo 1010e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 1011e705c121SKalle Valo rx_ba_ssn = *ssn; 1012e705c121SKalle Valo 1013e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 1014e705c121SKalle Valo rx_ba_ssn, action); 1015e705c121SKalle Valo } 1016e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1017e705c121SKalle Valo 1018e705c121SKalle Valo /* 1019e705c121SKalle Valo * If the tid is marked as started, we won't use it for offloaded 1020e705c121SKalle Valo * traffic on the next D0i3 entry. It's safe to unref. 1021e705c121SKalle Valo */ 1022e705c121SKalle Valo if (tx_agg_ref) 1023e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); 1024e705c121SKalle Valo 1025e705c121SKalle Valo return ret; 1026e705c121SKalle Valo } 1027e705c121SKalle Valo 1028e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 1029e705c121SKalle Valo struct ieee80211_vif *vif) 1030e705c121SKalle Valo { 1031e705c121SKalle Valo struct iwl_mvm *mvm = data; 1032e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1033e705c121SKalle Valo 1034e705c121SKalle Valo mvmvif->uploaded = false; 10350ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 1036e705c121SKalle Valo 1037e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 1038e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 1039e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 1040e705c121SKalle Valo 1041e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1042e705c121SKalle Valo memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 104386e177d8SGregory Greenman memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data)); 1044e705c121SKalle Valo } 1045e705c121SKalle Valo 1046e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 1047e705c121SKalle Valo { 1048e705c121SKalle Valo /* clear the D3 reconfig, we only need it to avoid dumping a 1049e705c121SKalle Valo * firmware coredump on reconfiguration, we shouldn't do that 1050e705c121SKalle Valo * on D3->D0 transition 1051e705c121SKalle Valo */ 1052e705c121SKalle Valo if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) { 10537174beb6SJohannes Berg mvm->fwrt.dump.desc = &iwl_dump_desc_assert; 10547174beb6SJohannes Berg iwl_fw_error_dump(&mvm->fwrt); 1055e705c121SKalle Valo } 1056e705c121SKalle Valo 1057e705c121SKalle Valo /* cleanup all stale references (scan, roc), but keep the 1058e705c121SKalle Valo * ucode_down ref until reconfig is complete 1059e705c121SKalle Valo */ 1060e705c121SKalle Valo iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); 1061e705c121SKalle Valo 1062fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1063e705c121SKalle Valo 1064e705c121SKalle Valo mvm->scan_status = 0; 1065e705c121SKalle Valo mvm->ps_disabled = false; 1066e705c121SKalle Valo mvm->calibrating = false; 1067e705c121SKalle Valo 1068e705c121SKalle Valo /* just in case one was running */ 1069305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 1070e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 1071e705c121SKalle Valo 1072e705c121SKalle Valo /* 1073e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 1074e705c121SKalle Valo * gone down during the HW restart 1075e705c121SKalle Valo */ 1076e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1077e705c121SKalle Valo 1078e705c121SKalle Valo mvm->p2p_device_vif = NULL; 10790ae98812SSara Sharon mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA; 1080e705c121SKalle Valo 1081e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 10829c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 108324afba76SLiad Kaufman memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames)); 1084e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1085e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1086e705c121SKalle Valo 1087e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1088e705c121SKalle Valo 1089e705c121SKalle Valo /* clear any stale d0i3 state */ 1090e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status); 1091e705c121SKalle Valo 1092e705c121SKalle Valo mvm->vif_count = 0; 1093e705c121SKalle Valo mvm->rx_ba_sessions = 0; 10947174beb6SJohannes Berg mvm->fwrt.dump.conf = FW_DBG_INVALID; 1095baf41bc3SShaul Triebitz mvm->monitor_on = false; 1096e705c121SKalle Valo 1097e705c121SKalle Valo /* keep statistics ticking */ 1098e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1099e705c121SKalle Valo } 1100e705c121SKalle Valo 1101e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1102e705c121SKalle Valo { 1103e705c121SKalle Valo int ret; 1104e705c121SKalle Valo 1105e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1106e705c121SKalle Valo 1107bf8b286fSJohannes Berg if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { 1108bf8b286fSJohannes Berg /* 1109bf8b286fSJohannes Berg * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART 1110bf8b286fSJohannes Berg * so later code will - from now on - see that we're doing it. 1111bf8b286fSJohannes Berg */ 1112bf8b286fSJohannes Berg set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1113bf8b286fSJohannes Berg clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); 1114e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1115e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1116a42b2af3SLuca Coelho } else { 1117a42b2af3SLuca Coelho /* Hold the reference to prevent runtime suspend while 1118a42b2af3SLuca Coelho * the start procedure runs. It's a bit confusing 1119a42b2af3SLuca Coelho * that the UCODE_DOWN reference is taken, but it just 1120a42b2af3SLuca Coelho * means "UCODE is not UP yet". ( TODO: rename this 1121a42b2af3SLuca Coelho * reference). 1122a42b2af3SLuca Coelho */ 1123a42b2af3SLuca Coelho iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); 1124a42b2af3SLuca Coelho } 1125e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1126e705c121SKalle Valo 1127e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1128e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1129e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1130e705c121SKalle Valo * would do. 1131e705c121SKalle Valo */ 1132e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1133a75b9b33SLuca Coelho #ifdef CONFIG_PM 1134e705c121SKalle Valo iwl_mvm_d0i3_enable_tx(mvm, NULL); 1135a75b9b33SLuca Coelho #endif 1136e705c121SKalle Valo } 1137e705c121SKalle Valo 1138e705c121SKalle Valo return ret; 1139e705c121SKalle Valo } 1140e705c121SKalle Valo 1141e705c121SKalle Valo static int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1142e705c121SKalle Valo { 1143e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1144e705c121SKalle Valo int ret; 1145e705c121SKalle Valo 1146e705c121SKalle Valo /* Some hw restart cleanups must not hold the mutex */ 1147e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1148e705c121SKalle Valo /* 1149e705c121SKalle Valo * Make sure we are out of d0i3. This is needed 1150e705c121SKalle Valo * to make sure the reference accounting is correct 1151e705c121SKalle Valo * (and there is no stale d0i3_exit_work). 1152e705c121SKalle Valo */ 1153e705c121SKalle Valo wait_event_timeout(mvm->d0i3_exit_waitq, 1154e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, 1155e705c121SKalle Valo &mvm->status), 1156e705c121SKalle Valo HZ); 1157e705c121SKalle Valo } 1158e705c121SKalle Valo 1159e705c121SKalle Valo mutex_lock(&mvm->mutex); 1160e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 1161e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1162e705c121SKalle Valo 1163e705c121SKalle Valo return ret; 1164e705c121SKalle Valo } 1165e705c121SKalle Valo 1166e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1167e705c121SKalle Valo { 1168e705c121SKalle Valo int ret; 1169e705c121SKalle Valo 1170e705c121SKalle Valo mutex_lock(&mvm->mutex); 1171e705c121SKalle Valo 1172e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1173a75b9b33SLuca Coelho #ifdef CONFIG_PM 1174e705c121SKalle Valo iwl_mvm_d0i3_enable_tx(mvm, NULL); 1175a75b9b33SLuca Coelho #endif 1176e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1177e705c121SKalle Valo if (ret) 1178e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1179e705c121SKalle Valo ret); 1180e705c121SKalle Valo 1181e705c121SKalle Valo /* allow transport/FW low power modes */ 1182e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); 1183e705c121SKalle Valo 1184e705c121SKalle Valo /* 1185e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1186e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1187e705c121SKalle Valo */ 1188e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1189e705c121SKalle Valo 1190e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1191e705c121SKalle Valo } 1192e705c121SKalle Valo 1193e705c121SKalle Valo static void iwl_mvm_resume_complete(struct iwl_mvm *mvm) 1194e705c121SKalle Valo { 1195b7282643SLuca Coelho if (iwl_mvm_is_d0i3_supported(mvm) && 1196b7282643SLuca Coelho iwl_mvm_enter_d0i3_on_suspend(mvm)) 1197b7282643SLuca Coelho WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq, 1198e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, 1199e705c121SKalle Valo &mvm->status), 1200b7282643SLuca Coelho HZ), 1201b7282643SLuca Coelho "D0i3 exit on resume timed out\n"); 1202e705c121SKalle Valo } 1203e705c121SKalle Valo 1204e705c121SKalle Valo static void 1205e705c121SKalle Valo iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1206e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1207e705c121SKalle Valo { 1208e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1209e705c121SKalle Valo 1210e705c121SKalle Valo switch (reconfig_type) { 1211e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1212e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1213e705c121SKalle Valo break; 1214e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1215e705c121SKalle Valo iwl_mvm_resume_complete(mvm); 1216e705c121SKalle Valo break; 1217e705c121SKalle Valo } 1218e705c121SKalle Valo } 1219e705c121SKalle Valo 1220e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1221e705c121SKalle Valo { 1222e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1223e705c121SKalle Valo 1224e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1225e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1226e705c121SKalle Valo */ 1227e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1228e705c121SKalle Valo 1229e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1230e705c121SKalle Valo 1231e705c121SKalle Valo /* 1232e705c121SKalle Valo * The work item could be running or queued if the 1233e705c121SKalle Valo * ROC time event stops just as we get here. 1234e705c121SKalle Valo */ 1235e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1236e705c121SKalle Valo 1237fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1238e705c121SKalle Valo 1239e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1240e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1241e705c121SKalle Valo 1242e705c121SKalle Valo /* the fw is stopped, the aux sta is dead: clean up driver state */ 1243e705c121SKalle Valo iwl_mvm_del_aux_sta(mvm); 1244e705c121SKalle Valo 1245e705c121SKalle Valo /* 1246155f7e04SEmmanuel Grumbach * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the 1247155f7e04SEmmanuel Grumbach * hw (as restart_complete() won't be called in this case) and mac80211 1248155f7e04SEmmanuel Grumbach * won't execute the restart. 1249e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1250e705c121SKalle Valo * HW restart was requested. 1251e705c121SKalle Valo */ 1252155f7e04SEmmanuel Grumbach if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) || 1253155f7e04SEmmanuel Grumbach test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, 1254155f7e04SEmmanuel Grumbach &mvm->status)) 1255e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1256e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1257e705c121SKalle Valo 1258e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1259e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1260e705c121SKalle Valo */ 1261e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1262e705c121SKalle Valo int i; 1263e705c121SKalle Valo 1264e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1265e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1266e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1267e705c121SKalle Valo i)) 1268e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1269e705c121SKalle Valo } 1270e705c121SKalle Valo } 1271e705c121SKalle Valo } 1272e705c121SKalle Valo 1273e705c121SKalle Valo static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1274e705c121SKalle Valo { 1275e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1276e705c121SKalle Valo 1277e705c121SKalle Valo flush_work(&mvm->d0i3_exit_work); 1278e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 127924afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1280771147b0SJohannes Berg 1281771147b0SJohannes Berg /* 1282771147b0SJohannes Berg * Lock and clear the firmware running bit here already, so that 1283771147b0SJohannes Berg * new commands coming in elsewhere, e.g. from debugfs, will not 1284771147b0SJohannes Berg * be able to proceed. This is important here because one of those 12857174beb6SJohannes Berg * debugfs files causes the firmware dump to be triggered, and if we 1286771147b0SJohannes Berg * don't stop debugfs accesses before canceling that it could be 1287771147b0SJohannes Berg * retriggered after we flush it but before we've cleared the bit. 1288771147b0SJohannes Berg */ 1289771147b0SJohannes Berg clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 1290771147b0SJohannes Berg 12917174beb6SJohannes Berg iwl_fw_cancel_dump(&mvm->fwrt); 1292d3a108a4SAndrei Otcheretianski cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 129369e04642SLuca Coelho cancel_delayed_work_sync(&mvm->scan_timeout_dwork); 12947174beb6SJohannes Berg iwl_fw_free_dump_desc(&mvm->fwrt); 1295e705c121SKalle Valo 1296e705c121SKalle Valo mutex_lock(&mvm->mutex); 1297e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1298e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1299e705c121SKalle Valo 1300e705c121SKalle Valo /* 1301e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1302e705c121SKalle Valo * discover that its list is now empty. 1303e705c121SKalle Valo */ 1304e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1305e705c121SKalle Valo } 1306e705c121SKalle Valo 1307e705c121SKalle Valo static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1308e705c121SKalle Valo { 1309e705c121SKalle Valo u16 i; 1310e705c121SKalle Valo 1311e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1312e705c121SKalle Valo 1313e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1314e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1315e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1316e705c121SKalle Valo 1317e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1318e705c121SKalle Valo return NULL; 1319e705c121SKalle Valo } 1320e705c121SKalle Valo 1321e705c121SKalle Valo static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1322e705c121SKalle Valo s16 tx_power) 1323e705c121SKalle Valo { 13240791c2fcSHaim Dreyfuss int len; 13250791c2fcSHaim Dreyfuss union { 13260791c2fcSHaim Dreyfuss struct iwl_dev_tx_power_cmd v5; 13270791c2fcSHaim Dreyfuss struct iwl_dev_tx_power_cmd_v4 v4; 13280791c2fcSHaim Dreyfuss } cmd = { 13290791c2fcSHaim Dreyfuss .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 13300791c2fcSHaim Dreyfuss .v5.v3.mac_context_id = 1331e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 13320791c2fcSHaim Dreyfuss .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power), 1333e705c121SKalle Valo }; 1334e705c121SKalle Valo 1335e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 13360791c2fcSHaim Dreyfuss cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1337e705c121SKalle Valo 13380791c2fcSHaim Dreyfuss if (fw_has_api(&mvm->fw->ucode_capa, 13390791c2fcSHaim Dreyfuss IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 13400791c2fcSHaim Dreyfuss len = sizeof(cmd.v5); 13410791c2fcSHaim Dreyfuss else if (fw_has_capa(&mvm->fw->ucode_capa, 13420791c2fcSHaim Dreyfuss IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 13430791c2fcSHaim Dreyfuss len = sizeof(cmd.v4); 13440791c2fcSHaim Dreyfuss else 13450791c2fcSHaim Dreyfuss len = sizeof(cmd.v4.v3); 1346e705c121SKalle Valo 1347e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); 1348e705c121SKalle Valo } 1349e705c121SKalle Valo 1350e705c121SKalle Valo static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1351e705c121SKalle Valo struct ieee80211_vif *vif) 1352e705c121SKalle Valo { 1353e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1354e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1355e705c121SKalle Valo int ret; 1356e705c121SKalle Valo 1357e705c121SKalle Valo mvmvif->mvm = mvm; 135886e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 1359e705c121SKalle Valo 1360e705c121SKalle Valo /* 1361e705c121SKalle Valo * make sure D0i3 exit is completed, otherwise a target access 1362e705c121SKalle Valo * during tx queue configuration could be done when still in 1363e705c121SKalle Valo * D0i3 state. 1364e705c121SKalle Valo */ 1365e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF); 1366e705c121SKalle Valo if (ret) 1367e705c121SKalle Valo return ret; 1368e705c121SKalle Valo 1369e705c121SKalle Valo /* 1370e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1371e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1372e705c121SKalle Valo * don't really have to check the types. 1373e705c121SKalle Valo */ 1374e705c121SKalle Valo 1375e705c121SKalle Valo mutex_lock(&mvm->mutex); 1376e705c121SKalle Valo 1377e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1378e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1379e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons += 1380e705c121SKalle Valo mvmvif->beacon_stats.num_beacons; 1381e705c121SKalle Valo 1382e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 1383e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_init(mvm, vif); 1384e705c121SKalle Valo if (ret) 1385e705c121SKalle Valo goto out_unlock; 1386e705c121SKalle Valo 1387e705c121SKalle Valo /* Counting number of interfaces is needed for legacy PM */ 1388e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1389e705c121SKalle Valo mvm->vif_count++; 1390e705c121SKalle Valo 1391e705c121SKalle Valo /* 1392e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1393e705c121SKalle Valo * template is configured (which happens only in the mac80211 1394e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1395e705c121SKalle Valo * only after the binding. 1396e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1397e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1398e705c121SKalle Valo * the point where we can also add the bcast station. 1399e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1400e705c121SKalle Valo * allocating resources :) 1401e705c121SKalle Valo */ 1402e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1403e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1404e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1405e705c121SKalle Valo if (ret) { 1406e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 1407e705c121SKalle Valo goto out_release; 1408e705c121SKalle Valo } 1409e705c121SKalle Valo 141026d6c16bSSara Sharon /* 141126d6c16bSSara Sharon * Only queue for this station is the mcast queue, 141226d6c16bSSara Sharon * which shouldn't be in TFD mask anyway 141326d6c16bSSara Sharon */ 141426d6c16bSSara Sharon ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta, 1415ced19f26SSara Sharon 0, vif->type, 1416ced19f26SSara Sharon IWL_STA_MULTICAST); 141726d6c16bSSara Sharon if (ret) 141826d6c16bSSara Sharon goto out_release; 141926d6c16bSSara Sharon 1420e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1421e705c121SKalle Valo goto out_unlock; 1422e705c121SKalle Valo } 1423e705c121SKalle Valo 1424e705c121SKalle Valo mvmvif->features |= hw->netdev_features; 1425e705c121SKalle Valo 1426e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1427e705c121SKalle Valo if (ret) 1428e705c121SKalle Valo goto out_release; 1429e705c121SKalle Valo 1430e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1431e705c121SKalle Valo if (ret) 1432e705c121SKalle Valo goto out_remove_mac; 1433e705c121SKalle Valo 1434e705c121SKalle Valo /* beacon filtering */ 1435e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 1436e705c121SKalle Valo if (ret) 1437e705c121SKalle Valo goto out_remove_mac; 1438e705c121SKalle Valo 1439e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1440e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1441e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1442e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1443e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1444e705c121SKalle Valo } 1445e705c121SKalle Valo 1446e705c121SKalle Valo /* 1447e705c121SKalle Valo * P2P_DEVICE interface does not have a channel context assigned to it, 1448e705c121SKalle Valo * so a dedicated PHY context is allocated to it and the corresponding 1449e705c121SKalle Valo * MAC context is bound to it at this stage. 1450e705c121SKalle Valo */ 1451e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1452e705c121SKalle Valo 1453e705c121SKalle Valo mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 1454e705c121SKalle Valo if (!mvmvif->phy_ctxt) { 1455e705c121SKalle Valo ret = -ENOSPC; 1456e705c121SKalle Valo goto out_free_bf; 1457e705c121SKalle Valo } 1458e705c121SKalle Valo 1459e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 1460e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 1461e705c121SKalle Valo if (ret) 1462e705c121SKalle Valo goto out_unref_phy; 1463e705c121SKalle Valo 1464d197358bSLuca Coelho ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif); 1465e705c121SKalle Valo if (ret) 1466e705c121SKalle Valo goto out_unbind; 1467e705c121SKalle Valo 1468e705c121SKalle Valo /* Save a pointer to p2p device vif, so it can later be used to 1469e705c121SKalle Valo * update the p2p device MAC when a GO is started/stopped */ 1470e705c121SKalle Valo mvm->p2p_device_vif = vif; 1471e705c121SKalle Valo } 1472e705c121SKalle Valo 1473b0ffe455SJohannes Berg iwl_mvm_tcm_add_vif(mvm, vif); 1474b0ffe455SJohannes Berg 1475baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1476baf41bc3SShaul Triebitz mvm->monitor_on = true; 1477baf41bc3SShaul Triebitz 1478e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1479e705c121SKalle Valo goto out_unlock; 1480e705c121SKalle Valo 1481e705c121SKalle Valo out_unbind: 1482e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1483e705c121SKalle Valo out_unref_phy: 1484e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1485e705c121SKalle Valo out_free_bf: 1486e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1487e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1488e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1489e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1490e705c121SKalle Valo } 1491e705c121SKalle Valo out_remove_mac: 1492e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1493e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1494e705c121SKalle Valo out_release: 1495e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1496e705c121SKalle Valo mvm->vif_count--; 1497e705c121SKalle Valo out_unlock: 1498e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1499e705c121SKalle Valo 1500e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF); 1501e705c121SKalle Valo 1502e705c121SKalle Valo return ret; 1503e705c121SKalle Valo } 1504e705c121SKalle Valo 1505e705c121SKalle Valo static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1506e705c121SKalle Valo struct ieee80211_vif *vif) 1507e705c121SKalle Valo { 1508e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1509e705c121SKalle Valo /* 1510e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1511e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1512e705c121SKalle Valo * queue are sent in ROC session. 1513e705c121SKalle Valo */ 1514e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1515e705c121SKalle Valo } 1516e705c121SKalle Valo } 1517e705c121SKalle Valo 1518e705c121SKalle Valo static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 1519e705c121SKalle Valo struct ieee80211_vif *vif) 1520e705c121SKalle Valo { 1521e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1522e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 152386e177d8SGregory Greenman struct iwl_probe_resp_data *probe_data; 1524e705c121SKalle Valo 1525e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1526e705c121SKalle Valo 1527b0ffe455SJohannes Berg if (!(vif->type == NL80211_IFTYPE_AP || 1528b0ffe455SJohannes Berg vif->type == NL80211_IFTYPE_ADHOC)) 1529b0ffe455SJohannes Berg iwl_mvm_tcm_rm_vif(mvm, vif); 1530b0ffe455SJohannes Berg 1531e705c121SKalle Valo mutex_lock(&mvm->mutex); 1532e705c121SKalle Valo 153386e177d8SGregory Greenman probe_data = rcu_dereference_protected(mvmvif->probe_resp_data, 153486e177d8SGregory Greenman lockdep_is_held(&mvm->mutex)); 153586e177d8SGregory Greenman RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL); 153686e177d8SGregory Greenman if (probe_data) 153786e177d8SGregory Greenman kfree_rcu(probe_data, rcu_head); 153886e177d8SGregory Greenman 1539e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1540e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1541e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1542e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1543e705c121SKalle Valo } 1544e705c121SKalle Valo 1545e705c121SKalle Valo iwl_mvm_vif_dbgfs_clean(mvm, vif); 1546e705c121SKalle Valo 1547e705c121SKalle Valo /* 1548e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1549e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1550e705c121SKalle Valo */ 1551e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1552e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1553e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1554e705c121SKalle Valo if (vif == mvm->noa_vif) { 1555e705c121SKalle Valo mvm->noa_vif = NULL; 1556e705c121SKalle Valo mvm->noa_duration = 0; 1557e705c121SKalle Valo } 1558e705c121SKalle Valo #endif 155926d6c16bSSara Sharon iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta); 1560e705c121SKalle Valo iwl_mvm_dealloc_bcast_sta(mvm, vif); 1561e705c121SKalle Valo goto out_release; 1562e705c121SKalle Valo } 1563e705c121SKalle Valo 1564e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1565e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1566d197358bSLuca Coelho iwl_mvm_rm_p2p_bcast_sta(mvm, vif); 1567e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1568e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1569e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1570e705c121SKalle Valo } 1571e705c121SKalle Valo 1572e705c121SKalle Valo if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) 1573e705c121SKalle Valo mvm->vif_count--; 1574e705c121SKalle Valo 1575e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 1576e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1577e705c121SKalle Valo 1578baf41bc3SShaul Triebitz if (vif->type == NL80211_IFTYPE_MONITOR) 1579baf41bc3SShaul Triebitz mvm->monitor_on = false; 1580baf41bc3SShaul Triebitz 1581e705c121SKalle Valo out_release: 1582e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1583e705c121SKalle Valo } 1584e705c121SKalle Valo 1585e705c121SKalle Valo static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) 1586e705c121SKalle Valo { 1587e705c121SKalle Valo return 0; 1588e705c121SKalle Valo } 1589e705c121SKalle Valo 1590e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1591e705c121SKalle Valo struct iwl_mvm *mvm; 1592e705c121SKalle Valo int port_id; 1593e705c121SKalle Valo }; 1594e705c121SKalle Valo 1595e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1596e705c121SKalle Valo struct ieee80211_vif *vif) 1597e705c121SKalle Valo { 1598e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1599e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1600e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 160197bce57bSLuca Coelho struct iwl_host_cmd hcmd = { 160297bce57bSLuca Coelho .id = MCAST_FILTER_CMD, 160397bce57bSLuca Coelho .flags = CMD_ASYNC, 160497bce57bSLuca Coelho .dataflags[0] = IWL_HCMD_DFL_NOCOPY, 160597bce57bSLuca Coelho }; 1606e705c121SKalle Valo int ret, len; 1607e705c121SKalle Valo 1608e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1609e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1610e705c121SKalle Valo return; 1611e705c121SKalle Valo 1612e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1613e705c121SKalle Valo !vif->bss_conf.assoc) 1614e705c121SKalle Valo return; 1615e705c121SKalle Valo 1616e705c121SKalle Valo cmd->port_id = data->port_id++; 1617e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1618e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1619e705c121SKalle Valo 162097bce57bSLuca Coelho hcmd.len[0] = len; 162197bce57bSLuca Coelho hcmd.data[0] = cmd; 162297bce57bSLuca Coelho 162397bce57bSLuca Coelho ret = iwl_mvm_send_cmd(mvm, &hcmd); 1624e705c121SKalle Valo if (ret) 1625e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1626e705c121SKalle Valo } 1627e705c121SKalle Valo 1628e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1629e705c121SKalle Valo { 1630e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1631e705c121SKalle Valo .mvm = mvm, 1632e705c121SKalle Valo }; 1633e705c121SKalle Valo 1634e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1635e705c121SKalle Valo 1636e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1637e705c121SKalle Valo return; 1638e705c121SKalle Valo 1639e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1640e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1641e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1642e705c121SKalle Valo } 1643e705c121SKalle Valo 1644e705c121SKalle Valo static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1645e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1646e705c121SKalle Valo { 1647e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1648e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1649e705c121SKalle Valo struct netdev_hw_addr *addr; 1650e705c121SKalle Valo int addr_count; 1651e705c121SKalle Valo bool pass_all; 1652e705c121SKalle Valo int len; 1653e705c121SKalle Valo 1654e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1655e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1656e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1657e705c121SKalle Valo if (pass_all) 1658e705c121SKalle Valo addr_count = 0; 1659e705c121SKalle Valo 1660e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1661e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1662e705c121SKalle Valo if (!cmd) 1663e705c121SKalle Valo return 0; 1664e705c121SKalle Valo 1665e705c121SKalle Valo if (pass_all) { 1666e705c121SKalle Valo cmd->pass_all = 1; 1667e705c121SKalle Valo return (u64)(unsigned long)cmd; 1668e705c121SKalle Valo } 1669e705c121SKalle Valo 1670e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1671e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1672e705c121SKalle Valo cmd->count, addr->addr); 1673e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1674e705c121SKalle Valo addr->addr, ETH_ALEN); 1675e705c121SKalle Valo cmd->count++; 1676e705c121SKalle Valo } 1677e705c121SKalle Valo 1678e705c121SKalle Valo return (u64)(unsigned long)cmd; 1679e705c121SKalle Valo } 1680e705c121SKalle Valo 1681e705c121SKalle Valo static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1682e705c121SKalle Valo unsigned int changed_flags, 1683e705c121SKalle Valo unsigned int *total_flags, 1684e705c121SKalle Valo u64 multicast) 1685e705c121SKalle Valo { 1686e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1687e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1688e705c121SKalle Valo 1689e705c121SKalle Valo mutex_lock(&mvm->mutex); 1690e705c121SKalle Valo 1691e705c121SKalle Valo /* replace previous configuration */ 1692e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1693e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1694e705c121SKalle Valo 1695e705c121SKalle Valo if (!cmd) 1696e705c121SKalle Valo goto out; 1697e705c121SKalle Valo 169861e7d91bSLuca Coelho if (changed_flags & FIF_ALLMULTI) 169961e7d91bSLuca Coelho cmd->pass_all = !!(*total_flags & FIF_ALLMULTI); 170061e7d91bSLuca Coelho 170161e7d91bSLuca Coelho if (cmd->pass_all) 170261e7d91bSLuca Coelho cmd->count = 0; 170361e7d91bSLuca Coelho 1704e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1705e705c121SKalle Valo out: 1706e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1707e705c121SKalle Valo *total_flags = 0; 1708e705c121SKalle Valo } 1709e705c121SKalle Valo 1710e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1711e705c121SKalle Valo struct ieee80211_vif *vif, 1712e705c121SKalle Valo unsigned int filter_flags, 1713e705c121SKalle Valo unsigned int changed_flags) 1714e705c121SKalle Valo { 1715e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1716e705c121SKalle Valo 1717e705c121SKalle Valo /* We support only filter for probe requests */ 1718e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1719e705c121SKalle Valo return; 1720e705c121SKalle Valo 1721e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1722e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc || 1723e705c121SKalle Valo !vif->p2p) 1724e705c121SKalle Valo return; 1725e705c121SKalle Valo 1726e705c121SKalle Valo mutex_lock(&mvm->mutex); 1727e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1728e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1729e705c121SKalle Valo } 1730e705c121SKalle Valo 1731e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 1732e705c121SKalle Valo struct iwl_bcast_iter_data { 1733e705c121SKalle Valo struct iwl_mvm *mvm; 1734e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd; 1735e705c121SKalle Valo u8 current_filter; 1736e705c121SKalle Valo }; 1737e705c121SKalle Valo 1738e705c121SKalle Valo static void 1739e705c121SKalle Valo iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, 1740e705c121SKalle Valo const struct iwl_fw_bcast_filter *in_filter, 1741e705c121SKalle Valo struct iwl_fw_bcast_filter *out_filter) 1742e705c121SKalle Valo { 1743e705c121SKalle Valo struct iwl_fw_bcast_filter_attr *attr; 1744e705c121SKalle Valo int i; 1745e705c121SKalle Valo 1746e705c121SKalle Valo memcpy(out_filter, in_filter, sizeof(*out_filter)); 1747e705c121SKalle Valo 1748e705c121SKalle Valo for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { 1749e705c121SKalle Valo attr = &out_filter->attrs[i]; 1750e705c121SKalle Valo 1751e705c121SKalle Valo if (!attr->mask) 1752e705c121SKalle Valo break; 1753e705c121SKalle Valo 1754e705c121SKalle Valo switch (attr->reserved1) { 1755e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_IP): 1756e705c121SKalle Valo if (vif->bss_conf.arp_addr_cnt != 1) { 1757e705c121SKalle Valo attr->mask = 0; 1758e705c121SKalle Valo continue; 1759e705c121SKalle Valo } 1760e705c121SKalle Valo 1761e705c121SKalle Valo attr->val = vif->bss_conf.arp_addr_list[0]; 1762e705c121SKalle Valo break; 1763e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_MAC): 1764e705c121SKalle Valo attr->val = *(__be32 *)&vif->addr[2]; 1765e705c121SKalle Valo break; 1766e705c121SKalle Valo default: 1767e705c121SKalle Valo break; 1768e705c121SKalle Valo } 1769e705c121SKalle Valo attr->reserved1 = 0; 1770e705c121SKalle Valo out_filter->num_attrs++; 1771e705c121SKalle Valo } 1772e705c121SKalle Valo } 1773e705c121SKalle Valo 1774e705c121SKalle Valo static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, 1775e705c121SKalle Valo struct ieee80211_vif *vif) 1776e705c121SKalle Valo { 1777e705c121SKalle Valo struct iwl_bcast_iter_data *data = _data; 1778e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1779e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd = data->cmd; 1780e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1781e705c121SKalle Valo struct iwl_fw_bcast_mac *bcast_mac; 1782e705c121SKalle Valo int i; 1783e705c121SKalle Valo 1784e705c121SKalle Valo if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) 1785e705c121SKalle Valo return; 1786e705c121SKalle Valo 1787e705c121SKalle Valo bcast_mac = &cmd->macs[mvmvif->id]; 1788e705c121SKalle Valo 1789e705c121SKalle Valo /* 1790e705c121SKalle Valo * enable filtering only for associated stations, but not for P2P 1791e705c121SKalle Valo * Clients 1792e705c121SKalle Valo */ 1793e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || 1794e705c121SKalle Valo !vif->bss_conf.assoc) 1795e705c121SKalle Valo return; 1796e705c121SKalle Valo 1797e705c121SKalle Valo bcast_mac->default_discard = 1; 1798e705c121SKalle Valo 1799e705c121SKalle Valo /* copy all configured filters */ 1800e705c121SKalle Valo for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { 1801e705c121SKalle Valo /* 1802e705c121SKalle Valo * Make sure we don't exceed our filters limit. 1803e705c121SKalle Valo * if there is still a valid filter to be configured, 1804e705c121SKalle Valo * be on the safe side and just allow bcast for this mac. 1805e705c121SKalle Valo */ 1806e705c121SKalle Valo if (WARN_ON_ONCE(data->current_filter >= 1807e705c121SKalle Valo ARRAY_SIZE(cmd->filters))) { 1808e705c121SKalle Valo bcast_mac->default_discard = 0; 1809e705c121SKalle Valo bcast_mac->attached_filters = 0; 1810e705c121SKalle Valo break; 1811e705c121SKalle Valo } 1812e705c121SKalle Valo 1813e705c121SKalle Valo iwl_mvm_set_bcast_filter(vif, 1814e705c121SKalle Valo &mvm->bcast_filters[i], 1815e705c121SKalle Valo &cmd->filters[data->current_filter]); 1816e705c121SKalle Valo 1817e705c121SKalle Valo /* skip current filter if it contains no attributes */ 1818e705c121SKalle Valo if (!cmd->filters[data->current_filter].num_attrs) 1819e705c121SKalle Valo continue; 1820e705c121SKalle Valo 1821e705c121SKalle Valo /* attach the filter to current mac */ 1822e705c121SKalle Valo bcast_mac->attached_filters |= 1823e705c121SKalle Valo cpu_to_le16(BIT(data->current_filter)); 1824e705c121SKalle Valo 1825e705c121SKalle Valo data->current_filter++; 1826e705c121SKalle Valo } 1827e705c121SKalle Valo } 1828e705c121SKalle Valo 1829e705c121SKalle Valo bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, 1830e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd) 1831e705c121SKalle Valo { 1832e705c121SKalle Valo struct iwl_bcast_iter_data iter_data = { 1833e705c121SKalle Valo .mvm = mvm, 1834e705c121SKalle Valo .cmd = cmd, 1835e705c121SKalle Valo }; 1836e705c121SKalle Valo 1837e705c121SKalle Valo if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL) 1838e705c121SKalle Valo return false; 1839e705c121SKalle Valo 1840e705c121SKalle Valo memset(cmd, 0, sizeof(*cmd)); 1841e705c121SKalle Valo cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); 1842e705c121SKalle Valo cmd->max_macs = ARRAY_SIZE(cmd->macs); 1843e705c121SKalle Valo 1844e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_DEBUGFS 1845e705c121SKalle Valo /* use debugfs filters/macs if override is configured */ 1846e705c121SKalle Valo if (mvm->dbgfs_bcast_filtering.override) { 1847e705c121SKalle Valo memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, 1848e705c121SKalle Valo sizeof(cmd->filters)); 1849e705c121SKalle Valo memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, 1850e705c121SKalle Valo sizeof(cmd->macs)); 1851e705c121SKalle Valo return true; 1852e705c121SKalle Valo } 1853e705c121SKalle Valo #endif 1854e705c121SKalle Valo 1855e705c121SKalle Valo /* if no filters are configured, do nothing */ 1856e705c121SKalle Valo if (!mvm->bcast_filters) 1857e705c121SKalle Valo return false; 1858e705c121SKalle Valo 1859e705c121SKalle Valo /* configure and attach these filters for each associated sta vif */ 1860e705c121SKalle Valo ieee80211_iterate_active_interfaces( 1861e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1862e705c121SKalle Valo iwl_mvm_bcast_filter_iterator, &iter_data); 1863e705c121SKalle Valo 1864e705c121SKalle Valo return true; 1865e705c121SKalle Valo } 186634672bb3SEliad Peller 186734672bb3SEliad Peller static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1868e705c121SKalle Valo { 1869e705c121SKalle Valo struct iwl_bcast_filter_cmd cmd; 1870e705c121SKalle Valo 1871e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) 1872e705c121SKalle Valo return 0; 1873e705c121SKalle Valo 1874e705c121SKalle Valo if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) 1875e705c121SKalle Valo return 0; 1876e705c121SKalle Valo 1877e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, 1878e705c121SKalle Valo sizeof(cmd), &cmd); 1879e705c121SKalle Valo } 1880e705c121SKalle Valo #else 188134672bb3SEliad Peller static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1882e705c121SKalle Valo { 1883e705c121SKalle Valo return 0; 1884e705c121SKalle Valo } 1885e705c121SKalle Valo #endif 1886e705c121SKalle Valo 1887a07a8f37SSara Sharon static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, 1888a07a8f37SSara Sharon struct ieee80211_vif *vif) 1889a07a8f37SSara Sharon { 1890a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1891a07a8f37SSara Sharon 1892a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 1893a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 1894a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 1895a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 1896a07a8f37SSara Sharon 1897a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 1898a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 1899a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 1900a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 1901a07a8f37SSara Sharon } 1902a07a8f37SSara Sharon 1903f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 1904f92659a1SSara Sharon struct ieee80211_vif *vif) 1905f92659a1SSara Sharon { 1906f92659a1SSara Sharon if (vif->mu_mimo_owner) { 1907f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 1908f92659a1SSara Sharon 1909f92659a1SSara Sharon /* 1910f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 1911f92659a1SSara Sharon * the data received from firmware as if it came from the 1912f92659a1SSara Sharon * action frame, so no conversion is needed. 1913f92659a1SSara Sharon */ 1914f92659a1SSara Sharon ieee80211_update_mu_groups(vif, 1915f92659a1SSara Sharon (u8 *)¬if->membership_status, 1916f92659a1SSara Sharon (u8 *)¬if->user_position); 1917f92659a1SSara Sharon } 1918f92659a1SSara Sharon } 1919f92659a1SSara Sharon 1920f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 1921f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 1922f92659a1SSara Sharon { 1923f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 1924f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 1925f92659a1SSara Sharon 1926f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 1927f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1928f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 1929f92659a1SSara Sharon } 1930f92659a1SSara Sharon 1931514c3069SLuca Coelho static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) 1932514c3069SLuca Coelho { 1933514c3069SLuca Coelho u8 byte_num = ppe_pos_bit / 8; 1934514c3069SLuca Coelho u8 bit_num = ppe_pos_bit % 8; 1935514c3069SLuca Coelho u8 residue_bits; 1936514c3069SLuca Coelho u8 res; 1937514c3069SLuca Coelho 1938514c3069SLuca Coelho if (bit_num <= 5) 1939514c3069SLuca Coelho return (ppe[byte_num] >> bit_num) & 1940514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1); 1941514c3069SLuca Coelho 1942514c3069SLuca Coelho /* 1943514c3069SLuca Coelho * If bit_num > 5, we have to combine bits with next byte. 1944514c3069SLuca Coelho * Calculate how many bits we need to take from current byte (called 1945514c3069SLuca Coelho * here "residue_bits"), and add them to bits from next byte. 1946514c3069SLuca Coelho */ 1947514c3069SLuca Coelho 1948514c3069SLuca Coelho residue_bits = 8 - bit_num; 1949514c3069SLuca Coelho 1950514c3069SLuca Coelho res = (ppe[byte_num + 1] & 1951514c3069SLuca Coelho (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) << 1952514c3069SLuca Coelho residue_bits; 1953514c3069SLuca Coelho res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1); 1954514c3069SLuca Coelho 1955514c3069SLuca Coelho return res; 1956514c3069SLuca Coelho } 1957514c3069SLuca Coelho 1958514c3069SLuca Coelho static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm, 1959514c3069SLuca Coelho struct ieee80211_vif *vif, u8 sta_id) 1960514c3069SLuca Coelho { 1961514c3069SLuca Coelho struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1962514c3069SLuca Coelho struct iwl_he_sta_context_cmd sta_ctxt_cmd = { 1963514c3069SLuca Coelho .sta_id = sta_id, 1964514c3069SLuca Coelho .tid_limit = IWL_MAX_TID_COUNT, 1965514c3069SLuca Coelho .bss_color = vif->bss_conf.bss_color, 1966514c3069SLuca Coelho .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext, 1967514c3069SLuca Coelho .frame_time_rts_th = 1968514c3069SLuca Coelho cpu_to_le16(vif->bss_conf.frame_time_rts_th), 1969514c3069SLuca Coelho }; 1970514c3069SLuca Coelho struct ieee80211_sta *sta; 1971514c3069SLuca Coelho u32 flags; 1972514c3069SLuca Coelho int i; 1973514c3069SLuca Coelho 1974514c3069SLuca Coelho rcu_read_lock(); 1975514c3069SLuca Coelho 1976514c3069SLuca Coelho sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); 1977514c3069SLuca Coelho if (IS_ERR(sta)) { 1978514c3069SLuca Coelho rcu_read_unlock(); 1979514c3069SLuca Coelho WARN(1, "Can't find STA to configure HE\n"); 1980514c3069SLuca Coelho return; 1981514c3069SLuca Coelho } 1982514c3069SLuca Coelho 1983514c3069SLuca Coelho if (!sta->he_cap.has_he) { 1984514c3069SLuca Coelho rcu_read_unlock(); 1985514c3069SLuca Coelho return; 1986514c3069SLuca Coelho } 1987514c3069SLuca Coelho 1988514c3069SLuca Coelho flags = 0; 1989514c3069SLuca Coelho 1990514c3069SLuca Coelho /* HTC flags */ 1991514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[0] & 1992514c3069SLuca Coelho IEEE80211_HE_MAC_CAP0_HTC_HE) 1993514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT); 1994514c3069SLuca Coelho if ((sta->he_cap.he_cap_elem.mac_cap_info[1] & 1995514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) || 1996514c3069SLuca Coelho (sta->he_cap.he_cap_elem.mac_cap_info[2] & 1997514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) { 1998514c3069SLuca Coelho u8 link_adap = 1999514c3069SLuca Coelho ((sta->he_cap.he_cap_elem.mac_cap_info[2] & 2000514c3069SLuca Coelho IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) + 2001514c3069SLuca Coelho (sta->he_cap.he_cap_elem.mac_cap_info[1] & 2002514c3069SLuca Coelho IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION); 2003514c3069SLuca Coelho 2004514c3069SLuca Coelho if (link_adap == 2) 2005514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2006514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED); 2007514c3069SLuca Coelho else if (link_adap == 3) 2008514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= 2009514c3069SLuca Coelho cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH); 2010514c3069SLuca Coelho } 2011514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) 2012514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP); 2013514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[3] & 2014514c3069SLuca Coelho IEEE80211_HE_MAC_CAP3_OMI_CONTROL) 2015514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP); 2016514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) 2017514c3069SLuca Coelho sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP); 2018514c3069SLuca Coelho 2019514c3069SLuca Coelho /* If PPE Thresholds exist, parse them into a FW-familiar format */ 2020514c3069SLuca Coelho if (sta->he_cap.he_cap_elem.phy_cap_info[6] & 2021514c3069SLuca Coelho IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 2022514c3069SLuca Coelho u8 nss = (sta->he_cap.ppe_thres[0] & 2023514c3069SLuca Coelho IEEE80211_PPE_THRES_NSS_MASK) + 1; 2024514c3069SLuca Coelho u8 ru_index_bitmap = 2025514c3069SLuca Coelho (sta->he_cap.ppe_thres[0] & 2026514c3069SLuca Coelho IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >> 2027514c3069SLuca Coelho IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS; 2028514c3069SLuca Coelho u8 *ppe = &sta->he_cap.ppe_thres[0]; 2029514c3069SLuca Coelho u8 ppe_pos_bit = 7; /* Starting after PPE header */ 2030514c3069SLuca Coelho 2031514c3069SLuca Coelho /* 2032514c3069SLuca Coelho * FW currently supports only nss == MAX_HE_SUPP_NSS 2033514c3069SLuca Coelho * 2034514c3069SLuca Coelho * If nss > MAX: we can ignore values we don't support 2035514c3069SLuca Coelho * If nss < MAX: we can set zeros in other streams 2036514c3069SLuca Coelho */ 2037514c3069SLuca Coelho if (nss > MAX_HE_SUPP_NSS) { 2038514c3069SLuca Coelho IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss, 2039514c3069SLuca Coelho MAX_HE_SUPP_NSS); 2040514c3069SLuca Coelho nss = MAX_HE_SUPP_NSS; 2041514c3069SLuca Coelho } 2042514c3069SLuca Coelho 2043514c3069SLuca Coelho for (i = 0; i < nss; i++) { 2044514c3069SLuca Coelho u8 ru_index_tmp = ru_index_bitmap << 1; 2045514c3069SLuca Coelho u8 bw; 2046514c3069SLuca Coelho 2047514c3069SLuca Coelho for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) { 2048514c3069SLuca Coelho ru_index_tmp >>= 1; 2049514c3069SLuca Coelho if (!(ru_index_tmp & 1)) 2050514c3069SLuca Coelho continue; 2051514c3069SLuca Coelho 2052514c3069SLuca Coelho sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] = 2053514c3069SLuca Coelho iwl_mvm_he_get_ppe_val(ppe, 2054514c3069SLuca Coelho ppe_pos_bit); 2055514c3069SLuca Coelho ppe_pos_bit += 2056514c3069SLuca Coelho IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2057514c3069SLuca Coelho sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] = 2058514c3069SLuca Coelho iwl_mvm_he_get_ppe_val(ppe, 2059514c3069SLuca Coelho ppe_pos_bit); 2060514c3069SLuca Coelho ppe_pos_bit += 2061514c3069SLuca Coelho IEEE80211_PPE_THRES_INFO_PPET_SIZE; 2062514c3069SLuca Coelho } 2063514c3069SLuca Coelho } 2064514c3069SLuca Coelho 2065514c3069SLuca Coelho flags |= STA_CTXT_HE_PACKET_EXT; 2066514c3069SLuca Coelho } 2067514c3069SLuca Coelho rcu_read_unlock(); 2068514c3069SLuca Coelho 2069514c3069SLuca Coelho /* Mark MU EDCA as enabled, unless none detected on some AC */ 2070514c3069SLuca Coelho flags |= STA_CTXT_HE_MU_EDCA_CW; 2071514c3069SLuca Coelho for (i = 0; i < AC_NUM; i++) { 2072514c3069SLuca Coelho struct ieee80211_he_mu_edca_param_ac_rec *mu_edca = 2073514c3069SLuca Coelho &mvmvif->queue_params[i].mu_edca_param_rec; 2074514c3069SLuca Coelho 2075514c3069SLuca Coelho if (!mvmvif->queue_params[i].mu_edca) { 2076514c3069SLuca Coelho flags &= ~STA_CTXT_HE_MU_EDCA_CW; 2077514c3069SLuca Coelho break; 2078514c3069SLuca Coelho } 2079514c3069SLuca Coelho 2080514c3069SLuca Coelho sta_ctxt_cmd.trig_based_txf[i].cwmin = 2081514c3069SLuca Coelho cpu_to_le16(mu_edca->ecw_min_max & 0xf); 2082514c3069SLuca Coelho sta_ctxt_cmd.trig_based_txf[i].cwmax = 2083514c3069SLuca Coelho cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4); 2084514c3069SLuca Coelho sta_ctxt_cmd.trig_based_txf[i].aifsn = 2085514c3069SLuca Coelho cpu_to_le16(mu_edca->aifsn); 2086514c3069SLuca Coelho sta_ctxt_cmd.trig_based_txf[i].mu_time = 2087514c3069SLuca Coelho cpu_to_le16(mu_edca->mu_edca_timer); 2088514c3069SLuca Coelho } 2089514c3069SLuca Coelho 2090514c3069SLuca Coelho if (vif->bss_conf.multi_sta_back_32bit) 2091514c3069SLuca Coelho flags |= STA_CTXT_HE_32BIT_BA_BITMAP; 2092514c3069SLuca Coelho 2093514c3069SLuca Coelho if (vif->bss_conf.ack_enabled) 2094514c3069SLuca Coelho flags |= STA_CTXT_HE_ACK_ENABLED; 2095514c3069SLuca Coelho 2096514c3069SLuca Coelho if (vif->bss_conf.uora_exists) { 2097514c3069SLuca Coelho flags |= STA_CTXT_HE_TRIG_RND_ALLOC; 2098514c3069SLuca Coelho 2099514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmin = 2100514c3069SLuca Coelho vif->bss_conf.uora_ocw_range & 0x7; 2101514c3069SLuca Coelho sta_ctxt_cmd.rand_alloc_ecwmax = 2102514c3069SLuca Coelho (vif->bss_conf.uora_ocw_range >> 3) & 0x7; 2103514c3069SLuca Coelho } 2104514c3069SLuca Coelho 2105514c3069SLuca Coelho /* TODO: support Multi BSSID IE */ 2106514c3069SLuca Coelho 2107514c3069SLuca Coelho sta_ctxt_cmd.flags = cpu_to_le32(flags); 2108514c3069SLuca Coelho 2109514c3069SLuca Coelho if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD, 2110514c3069SLuca Coelho DATA_PATH_GROUP, 0), 2111514c3069SLuca Coelho 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd)) 2112514c3069SLuca Coelho IWL_ERR(mvm, "Failed to config FW to work HE!\n"); 2113514c3069SLuca Coelho } 2114514c3069SLuca Coelho 2115e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 2116e705c121SKalle Valo struct ieee80211_vif *vif, 2117e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2118e705c121SKalle Valo u32 changes) 2119e705c121SKalle Valo { 2120e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2121e705c121SKalle Valo int ret; 2122e705c121SKalle Valo 2123e705c121SKalle Valo /* 2124e705c121SKalle Valo * Re-calculate the tsf id, as the master-slave relations depend on the 2125e705c121SKalle Valo * beacon interval, which was not known when the station interface was 2126e705c121SKalle Valo * added. 2127e705c121SKalle Valo */ 2128514c3069SLuca Coelho if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { 2129230ba6c5SLuca Coelho if (vif->bss_conf.he_support && 2130230ba6c5SLuca Coelho !iwlwifi_mod_params.disable_11ax) 2131514c3069SLuca Coelho iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id); 2132514c3069SLuca Coelho 2133e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2134514c3069SLuca Coelho } 2135e705c121SKalle Valo 2136e705c121SKalle Valo /* 2137e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 2138e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 2139e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 2140e705c121SKalle Valo * branch for disassociation below. 2141e705c121SKalle Valo */ 2142e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 2143e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2144e705c121SKalle Valo 2145e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); 2146e705c121SKalle Valo if (ret) 2147e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2148e705c121SKalle Valo 2149e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 2150e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 2151e705c121SKalle Valo mvmvif->associated = bss_conf->assoc; 2152e705c121SKalle Valo 2153e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 2154e705c121SKalle Valo if (bss_conf->assoc) { 2155e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 2156e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 2157e705c121SKalle Valo memset(&mvmvif->beacon_stats, 0, 2158e705c121SKalle Valo sizeof(mvmvif->beacon_stats)); 2159e705c121SKalle Valo 2160e705c121SKalle Valo /* add quota for this interface */ 2161e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 2162e705c121SKalle Valo if (ret) { 2163e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2164e705c121SKalle Valo return; 2165e705c121SKalle Valo } 2166e705c121SKalle Valo 2167e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 2168e705c121SKalle Valo &mvm->status)) { 2169e705c121SKalle Valo /* 2170e705c121SKalle Valo * If we're restarting then the firmware will 2171e705c121SKalle Valo * obviously have lost synchronisation with 2172e705c121SKalle Valo * the AP. It will attempt to synchronise by 2173e705c121SKalle Valo * itself, but we can make it more reliable by 2174e705c121SKalle Valo * scheduling a session protection time event. 2175e705c121SKalle Valo * 2176e705c121SKalle Valo * The firmware needs to receive a beacon to 2177e705c121SKalle Valo * catch up with synchronisation, use 110% of 2178e705c121SKalle Valo * the beacon interval. 2179e705c121SKalle Valo * 2180e705c121SKalle Valo * Set a large maximum delay to allow for more 2181e705c121SKalle Valo * than a single interface. 2182e705c121SKalle Valo */ 2183e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 2184e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 2185e705c121SKalle Valo 5 * dur, false); 2186e705c121SKalle Valo } 2187e705c121SKalle Valo 2188e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2189e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 2190e705c121SKalle Valo if (vif->p2p) { 2191e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT); 2192e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 2193e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 2194e705c121SKalle Valo IEEE80211_SMPS_DYNAMIC); 2195e705c121SKalle Valo } 21960ae98812SSara Sharon } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { 2197e705c121SKalle Valo /* 2198e705c121SKalle Valo * If update fails - SF might be running in associated 2199e705c121SKalle Valo * mode while disassociated - which is forbidden. 2200e705c121SKalle Valo */ 2201e705c121SKalle Valo WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), 2202e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 2203e705c121SKalle Valo 22046b28f978SEmmanuel Grumbach /* 22056b28f978SEmmanuel Grumbach * If we get an assert during the connection (after the 22066b28f978SEmmanuel Grumbach * station has been added, but before the vif is set 22076b28f978SEmmanuel Grumbach * to associated), mac80211 will re-add the station and 22086b28f978SEmmanuel Grumbach * then configure the vif. Since the vif is not 22096b28f978SEmmanuel Grumbach * associated, we would remove the station here and 22106b28f978SEmmanuel Grumbach * this would fail the recovery. 22116b28f978SEmmanuel Grumbach */ 22126b28f978SEmmanuel Grumbach if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 22136b28f978SEmmanuel Grumbach &mvm->status)) { 22146b28f978SEmmanuel Grumbach /* 22156b28f978SEmmanuel Grumbach * Remove AP station now that 22166b28f978SEmmanuel Grumbach * the MAC is unassoc 22176b28f978SEmmanuel Grumbach */ 22186b28f978SEmmanuel Grumbach ret = iwl_mvm_rm_sta_id(mvm, vif, 22196b28f978SEmmanuel Grumbach mvmvif->ap_sta_id); 2220e705c121SKalle Valo if (ret) 22216b28f978SEmmanuel Grumbach IWL_ERR(mvm, 22226b28f978SEmmanuel Grumbach "failed to remove AP station\n"); 2223e705c121SKalle Valo 2224e705c121SKalle Valo if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id) 22256b28f978SEmmanuel Grumbach mvm->d0i3_ap_sta_id = 22266b28f978SEmmanuel Grumbach IWL_MVM_INVALID_STA; 22270ae98812SSara Sharon mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; 22286b28f978SEmmanuel Grumbach } 22296b28f978SEmmanuel Grumbach 2230e705c121SKalle Valo /* remove quota for this interface */ 2231e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2232e705c121SKalle Valo if (ret) 2233e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 2234e705c121SKalle Valo 2235e705c121SKalle Valo if (vif->p2p) 2236e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT); 2237e705c121SKalle Valo 2238e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 2239e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2240e705c121SKalle Valo if (ret) 2241e705c121SKalle Valo IWL_ERR(mvm, 2242e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 2243e705c121SKalle Valo vif->addr); 2244e705c121SKalle Valo } 2245e705c121SKalle Valo 2246a07a8f37SSara Sharon /* 2247a07a8f37SSara Sharon * The firmware tracks the MU-MIMO group on its own. 2248f92659a1SSara Sharon * However, on HW restart we should restore this data. 2249a07a8f37SSara Sharon */ 2250a07a8f37SSara Sharon if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2251f92659a1SSara Sharon (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) { 2252a07a8f37SSara Sharon ret = iwl_mvm_update_mu_groups(mvm, vif); 2253a07a8f37SSara Sharon if (ret) 2254a07a8f37SSara Sharon IWL_ERR(mvm, 2255a07a8f37SSara Sharon "failed to update VHT MU_MIMO groups\n"); 2256a07a8f37SSara Sharon } 2257a07a8f37SSara Sharon 2258e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 225934672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 2260e705c121SKalle Valo 2261e705c121SKalle Valo /* reset rssi values */ 2262e705c121SKalle Valo mvmvif->bf_data.ave_beacon_signal = 0; 2263e705c121SKalle Valo 2264e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2265e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, 2266e705c121SKalle Valo IEEE80211_SMPS_AUTOMATIC); 2267355346baSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 2268355346baSAvraham Stern IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 2269355346baSAvraham Stern iwl_mvm_config_scan(mvm); 2270b45242c9SAvraham Stern } 2271b45242c9SAvraham Stern 2272b45242c9SAvraham Stern if (changes & BSS_CHANGED_BEACON_INFO) { 2273e705c121SKalle Valo /* 2274b45242c9SAvraham Stern * We received a beacon from the associated AP so 2275e705c121SKalle Valo * remove the session protection. 2276e705c121SKalle Valo */ 22773edfb5f4SAvraham Stern iwl_mvm_stop_session_protection(mvm, vif); 2278e705c121SKalle Valo 2279e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2280e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2281e705c121SKalle Valo } 2282e705c121SKalle Valo 2283283115fbSAvri Altman if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 2284283115fbSAvri Altman /* 2285283115fbSAvri Altman * Send power command on every beacon change, 2286283115fbSAvri Altman * because we may have not enabled beacon abort yet. 2287283115fbSAvri Altman */ 2288283115fbSAvri Altman BSS_CHANGED_BEACON_INFO)) { 2289e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 2290e705c121SKalle Valo if (ret) 2291e705c121SKalle Valo IWL_ERR(mvm, "failed to update power mode\n"); 2292e705c121SKalle Valo } 2293e705c121SKalle Valo 2294e705c121SKalle Valo if (changes & BSS_CHANGED_TXPOWER) { 2295e705c121SKalle Valo IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", 2296e705c121SKalle Valo bss_conf->txpower); 2297e705c121SKalle Valo iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 2298e705c121SKalle Valo } 2299e705c121SKalle Valo 2300e705c121SKalle Valo if (changes & BSS_CHANGED_CQM) { 2301e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); 2302e705c121SKalle Valo /* reset cqm events tracking */ 2303e705c121SKalle Valo mvmvif->bf_data.last_cqm_event = 0; 2304e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 2305e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 2306e705c121SKalle Valo if (ret) 2307e705c121SKalle Valo IWL_ERR(mvm, 2308e705c121SKalle Valo "failed to update CQM thresholds\n"); 2309e705c121SKalle Valo } 2310e705c121SKalle Valo } 2311e705c121SKalle Valo 2312e705c121SKalle Valo if (changes & BSS_CHANGED_ARP_FILTER) { 2313e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); 231434672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 2315e705c121SKalle Valo } 2316e705c121SKalle Valo } 2317e705c121SKalle Valo 2318e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2319e705c121SKalle Valo struct ieee80211_vif *vif) 2320e705c121SKalle Valo { 2321e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2322e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2323e705c121SKalle Valo int ret; 2324e705c121SKalle Valo 2325e705c121SKalle Valo /* 2326e705c121SKalle Valo * iwl_mvm_mac_ctxt_add() might read directly from the device 2327e705c121SKalle Valo * (the system time), so make sure it is available. 2328e705c121SKalle Valo */ 2329e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP); 2330e705c121SKalle Valo if (ret) 2331e705c121SKalle Valo return ret; 2332e705c121SKalle Valo 2333e705c121SKalle Valo mutex_lock(&mvm->mutex); 2334e705c121SKalle Valo 2335e705c121SKalle Valo /* Send the beacon template */ 2336e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); 2337e705c121SKalle Valo if (ret) 2338e705c121SKalle Valo goto out_unlock; 2339e705c121SKalle Valo 2340e705c121SKalle Valo /* 2341e705c121SKalle Valo * Re-calculate the tsf id, as the master-slave relations depend on the 2342e705c121SKalle Valo * beacon interval, which was not known when the AP interface was added. 2343e705c121SKalle Valo */ 2344e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2345e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2346e705c121SKalle Valo 2347e705c121SKalle Valo mvmvif->ap_assoc_sta_count = 0; 2348e705c121SKalle Valo 2349e705c121SKalle Valo /* Add the mac context */ 2350e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2351e705c121SKalle Valo if (ret) 2352e705c121SKalle Valo goto out_unlock; 2353e705c121SKalle Valo 2354e705c121SKalle Valo /* Perform the binding */ 2355e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2356e705c121SKalle Valo if (ret) 2357e705c121SKalle Valo goto out_remove; 2358e705c121SKalle Valo 235963dd5d02SSara Sharon /* 236063dd5d02SSara Sharon * This is not very nice, but the simplest: 236163dd5d02SSara Sharon * For older FWs adding the mcast sta before the bcast station may 236263dd5d02SSara Sharon * cause assert 0x2b00. 236363dd5d02SSara Sharon * This is fixed in later FW so make the order of removal depend on 236463dd5d02SSara Sharon * the TLV 236563dd5d02SSara Sharon */ 236663dd5d02SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { 2367ced19f26SSara Sharon ret = iwl_mvm_add_mcast_sta(mvm, vif); 2368ced19f26SSara Sharon if (ret) 2369ced19f26SSara Sharon goto out_unbind; 237063dd5d02SSara Sharon /* 237163dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 237263dd5d02SSara Sharon * events are added and applied to the scheduler 237363dd5d02SSara Sharon */ 2374e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 237563dd5d02SSara Sharon if (ret) { 237663dd5d02SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 237763dd5d02SSara Sharon goto out_unbind; 237863dd5d02SSara Sharon } 237963dd5d02SSara Sharon } else { 238063dd5d02SSara Sharon /* 238163dd5d02SSara Sharon * Send the bcast station. At this stage the TBTT and DTIM time 238263dd5d02SSara Sharon * events are added and applied to the scheduler 238363dd5d02SSara Sharon */ 238475fd4fecSJohannes Berg ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2385e705c121SKalle Valo if (ret) 238663dd5d02SSara Sharon goto out_unbind; 238775fd4fecSJohannes Berg ret = iwl_mvm_add_mcast_sta(mvm, vif); 238863dd5d02SSara Sharon if (ret) { 238963dd5d02SSara Sharon iwl_mvm_send_rm_bcast_sta(mvm, vif); 239063dd5d02SSara Sharon goto out_unbind; 239163dd5d02SSara Sharon } 239263dd5d02SSara Sharon } 239326d6c16bSSara Sharon 2394e705c121SKalle Valo /* must be set before quota calculations */ 2395e705c121SKalle Valo mvmvif->ap_ibss_active = true; 2396e705c121SKalle Valo 239747242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 239847242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, true, 239947242744STova Mussai LOW_LATENCY_VIF_TYPE); 240047242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id); 240147242744STova Mussai } 240247242744STova Mussai 2403e705c121SKalle Valo /* power updated needs to be done before quotas */ 2404e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2405e705c121SKalle Valo 2406e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2407e705c121SKalle Valo if (ret) 2408e705c121SKalle Valo goto out_quota_failed; 2409e705c121SKalle Valo 2410e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2411e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2412e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2413e705c121SKalle Valo 2414e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS); 2415e705c121SKalle Valo 2416e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2417e705c121SKalle Valo 2418e705c121SKalle Valo /* we don't support TDLS during DCM */ 2419e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2420e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2421e705c121SKalle Valo 2422e705c121SKalle Valo goto out_unlock; 2423e705c121SKalle Valo 2424e705c121SKalle Valo out_quota_failed: 2425e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2426e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2427e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2428ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2429e705c121SKalle Valo out_unbind: 2430e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2431e705c121SKalle Valo out_remove: 2432e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2433e705c121SKalle Valo out_unlock: 2434e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2435e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP); 2436e705c121SKalle Valo return ret; 2437e705c121SKalle Valo } 2438e705c121SKalle Valo 2439e705c121SKalle Valo static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 2440e705c121SKalle Valo struct ieee80211_vif *vif) 2441e705c121SKalle Valo { 2442e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2443e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2444e705c121SKalle Valo 2445e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 2446e705c121SKalle Valo 2447e705c121SKalle Valo mutex_lock(&mvm->mutex); 2448e705c121SKalle Valo 2449e705c121SKalle Valo /* Handle AP stop while in CSA */ 2450e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 2451e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 2452e705c121SKalle Valo &mvmvif->time_event_data); 2453e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 2454e705c121SKalle Valo mvmvif->csa_countdown = false; 2455e705c121SKalle Valo } 2456e705c121SKalle Valo 2457e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 2458e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2459e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 2460e705c121SKalle Valo } 2461e705c121SKalle Valo 2462e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2463e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 2464e705c121SKalle Valo 246547242744STova Mussai if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) { 246647242744STova Mussai iwl_mvm_vif_set_low_latency(mvmvif, false, 246747242744STova Mussai LOW_LATENCY_VIF_TYPE); 246847242744STova Mussai iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id); 246947242744STova Mussai } 247047242744STova Mussai 2471e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2472e705c121SKalle Valo 2473e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS); 2474e705c121SKalle Valo 2475e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2476e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2477e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2478e705c121SKalle Valo 2479e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 2480ced19f26SSara Sharon 2481ced19f26SSara Sharon /* 2482ced19f26SSara Sharon * This is not very nice, but the simplest: 2483ced19f26SSara Sharon * For older FWs removing the mcast sta before the bcast station may 2484ced19f26SSara Sharon * cause assert 0x2b00. 2485ced19f26SSara Sharon * This is fixed in later FW (which will stop beaconing when removing 2486ced19f26SSara Sharon * bcast station). 2487ced19f26SSara Sharon * So make the order of removal depend on the TLV 2488ced19f26SSara Sharon */ 2489ced19f26SSara Sharon if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 249026d6c16bSSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2491e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2492ced19f26SSara Sharon if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) 2493ced19f26SSara Sharon iwl_mvm_rm_mcast_sta(mvm, vif); 2494e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2495e705c121SKalle Valo 2496e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2497e705c121SKalle Valo 2498e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2499e705c121SKalle Valo 2500337bfc98SAvraham Stern kfree(mvmvif->ap_wep_key); 2501337bfc98SAvraham Stern mvmvif->ap_wep_key = NULL; 2502337bfc98SAvraham Stern 2503e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2504e705c121SKalle Valo } 2505e705c121SKalle Valo 2506e705c121SKalle Valo static void 2507e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 2508e705c121SKalle Valo struct ieee80211_vif *vif, 2509e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2510e705c121SKalle Valo u32 changes) 2511e705c121SKalle Valo { 2512e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2513e705c121SKalle Valo 2514e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 2515e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 2516e705c121SKalle Valo return; 2517e705c121SKalle Valo 2518e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 2519e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 2520e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 2521e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2522e705c121SKalle Valo 2523e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 2524e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 2525e705c121SKalle Valo iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) 2526e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 2527e705c121SKalle Valo 2528e705c121SKalle Valo if (changes & BSS_CHANGED_TXPOWER) { 2529e705c121SKalle Valo IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", 2530e705c121SKalle Valo bss_conf->txpower); 2531e705c121SKalle Valo iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 2532e705c121SKalle Valo } 2533e705c121SKalle Valo } 2534e705c121SKalle Valo 2535e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 2536e705c121SKalle Valo struct ieee80211_vif *vif, 2537e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2538e705c121SKalle Valo u32 changes) 2539e705c121SKalle Valo { 2540e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2541e705c121SKalle Valo 2542e705c121SKalle Valo /* 2543e705c121SKalle Valo * iwl_mvm_bss_info_changed_station() might call 2544e705c121SKalle Valo * iwl_mvm_protect_session(), which reads directly from 2545e705c121SKalle Valo * the device (the system time), so make sure it is available. 2546e705c121SKalle Valo */ 2547e705c121SKalle Valo if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED)) 2548e705c121SKalle Valo return; 2549e705c121SKalle Valo 2550e705c121SKalle Valo mutex_lock(&mvm->mutex); 2551e705c121SKalle Valo 2552e705c121SKalle Valo if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) 2553e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 2554e705c121SKalle Valo 2555e705c121SKalle Valo switch (vif->type) { 2556e705c121SKalle Valo case NL80211_IFTYPE_STATION: 2557e705c121SKalle Valo iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 2558e705c121SKalle Valo break; 2559e705c121SKalle Valo case NL80211_IFTYPE_AP: 2560e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 2561e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 2562e705c121SKalle Valo break; 256391b08c2dSAviya Erenfeld case NL80211_IFTYPE_MONITOR: 256491b08c2dSAviya Erenfeld if (changes & BSS_CHANGED_MU_GROUPS) 256591b08c2dSAviya Erenfeld iwl_mvm_update_mu_groups(mvm, vif); 256691b08c2dSAviya Erenfeld break; 2567e705c121SKalle Valo default: 2568e705c121SKalle Valo /* shouldn't happen */ 2569e705c121SKalle Valo WARN_ON_ONCE(1); 2570e705c121SKalle Valo } 2571e705c121SKalle Valo 2572e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2573e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED); 2574e705c121SKalle Valo } 2575e705c121SKalle Valo 2576e705c121SKalle Valo static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, 2577e705c121SKalle Valo struct ieee80211_vif *vif, 2578e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 2579e705c121SKalle Valo { 2580e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2581e705c121SKalle Valo int ret; 2582e705c121SKalle Valo 2583e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 2584e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 2585e705c121SKalle Valo return -EINVAL; 2586e705c121SKalle Valo 2587e705c121SKalle Valo mutex_lock(&mvm->mutex); 2588e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 2589e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2590e705c121SKalle Valo 2591e705c121SKalle Valo return ret; 2592e705c121SKalle Valo } 2593e705c121SKalle Valo 2594e705c121SKalle Valo static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 2595e705c121SKalle Valo struct ieee80211_vif *vif) 2596e705c121SKalle Valo { 2597e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2598e705c121SKalle Valo 2599e705c121SKalle Valo mutex_lock(&mvm->mutex); 2600e705c121SKalle Valo 2601e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 2602e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 2603e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 2604e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 2605e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 2606e705c121SKalle Valo * To handle that, simply return if the scan is not running. 2607e705c121SKalle Valo */ 2608e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 2609e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 2610e705c121SKalle Valo 2611e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2612e705c121SKalle Valo } 2613e705c121SKalle Valo 2614e705c121SKalle Valo static void 2615e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 2616e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2617e705c121SKalle Valo int num_frames, 2618e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2619e705c121SKalle Valo bool more_data) 2620e705c121SKalle Valo { 2621e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2622e705c121SKalle Valo 2623e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 2624e705c121SKalle Valo 2625e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2626e705c121SKalle Valo tids, more_data, false); 2627e705c121SKalle Valo } 2628e705c121SKalle Valo 2629e705c121SKalle Valo static void 2630e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 2631e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2632e705c121SKalle Valo int num_frames, 2633e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2634e705c121SKalle Valo bool more_data) 2635e705c121SKalle Valo { 2636e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2637e705c121SKalle Valo 26389a3fcf91SSara Sharon /* Called when we need to transmit (a) frame(s) from agg or dqa queue */ 2639e705c121SKalle Valo 2640e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2641e705c121SKalle Valo tids, more_data, true); 2642e705c121SKalle Valo } 2643e705c121SKalle Valo 264465e25482SJohannes Berg static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 2645e705c121SKalle Valo enum sta_notify_cmd cmd, 2646e705c121SKalle Valo struct ieee80211_sta *sta) 2647e705c121SKalle Valo { 2648e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2649e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2650e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 2651e705c121SKalle Valo int tid; 2652e705c121SKalle Valo 2653960f864bSJohannes Berg /* 2654960f864bSJohannes Berg * If we have TVQM then we get too high queue numbers - luckily 2655960f864bSJohannes Berg * we really shouldn't get here with that because such hardware 2656960f864bSJohannes Berg * should have firmware supporting buffer station offload. 2657960f864bSJohannes Berg */ 2658960f864bSJohannes Berg if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) 2659960f864bSJohannes Berg return; 2660960f864bSJohannes Berg 2661e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2662e705c121SKalle Valo for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 2663e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2664e705c121SKalle Valo 26656862fceeSSara Sharon if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) 26661c17627bSSara Sharon continue; 26671c17627bSSara Sharon 2668e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 2669e705c121SKalle Valo 2670dd32162dSLiad Kaufman if (iwl_mvm_tid_queued(mvm, tid_data) == 0) 2671e705c121SKalle Valo continue; 2672e705c121SKalle Valo 2673e705c121SKalle Valo __set_bit(tid, &tids); 2674e705c121SKalle Valo } 2675e705c121SKalle Valo 2676e705c121SKalle Valo switch (cmd) { 2677e705c121SKalle Valo case STA_NOTIFY_SLEEP: 2678e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 2679e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 2680e705c121SKalle Valo 2681e705c121SKalle Valo if (txqs) 2682e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 2683e705c121SKalle Valo /* 2684e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 2685e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 2686e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 2687e705c121SKalle Valo */ 2688e705c121SKalle Valo break; 2689e705c121SKalle Valo case STA_NOTIFY_AWAKE: 26900ae98812SSara Sharon if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA)) 2691e705c121SKalle Valo break; 2692e705c121SKalle Valo 2693e705c121SKalle Valo if (txqs) 2694e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 2695e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 2696e705c121SKalle Valo break; 2697e705c121SKalle Valo default: 2698e705c121SKalle Valo break; 2699e705c121SKalle Valo } 2700e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2701e705c121SKalle Valo } 2702e705c121SKalle Valo 270365e25482SJohannes Berg static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 270465e25482SJohannes Berg struct ieee80211_vif *vif, 270565e25482SJohannes Berg enum sta_notify_cmd cmd, 270665e25482SJohannes Berg struct ieee80211_sta *sta) 270765e25482SJohannes Berg { 270865e25482SJohannes Berg __iwl_mvm_mac_sta_notify(hw, cmd, sta); 270965e25482SJohannes Berg } 271065e25482SJohannes Berg 271165e25482SJohannes Berg void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb) 271265e25482SJohannes Berg { 271365e25482SJohannes Berg struct iwl_rx_packet *pkt = rxb_addr(rxb); 271465e25482SJohannes Berg struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data; 271565e25482SJohannes Berg struct ieee80211_sta *sta; 271665e25482SJohannes Berg struct iwl_mvm_sta *mvmsta; 271765e25482SJohannes Berg bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE); 271865e25482SJohannes Berg 271965e25482SJohannes Berg if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) 272065e25482SJohannes Berg return; 272165e25482SJohannes Berg 272265e25482SJohannes Berg rcu_read_lock(); 2723a9560029SSara Sharon sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]); 272465e25482SJohannes Berg if (WARN_ON(IS_ERR_OR_NULL(sta))) { 272565e25482SJohannes Berg rcu_read_unlock(); 272665e25482SJohannes Berg return; 272765e25482SJohannes Berg } 272865e25482SJohannes Berg 272965e25482SJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 273065e25482SJohannes Berg 273165e25482SJohannes Berg if (!mvmsta->vif || 273265e25482SJohannes Berg mvmsta->vif->type != NL80211_IFTYPE_AP) { 273365e25482SJohannes Berg rcu_read_unlock(); 273465e25482SJohannes Berg return; 273565e25482SJohannes Berg } 273665e25482SJohannes Berg 273765e25482SJohannes Berg if (mvmsta->sleeping != sleeping) { 273865e25482SJohannes Berg mvmsta->sleeping = sleeping; 273965e25482SJohannes Berg __iwl_mvm_mac_sta_notify(mvm->hw, 274065e25482SJohannes Berg sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, 274165e25482SJohannes Berg sta); 274265e25482SJohannes Berg ieee80211_sta_ps_transition(sta, sleeping); 274365e25482SJohannes Berg } 274465e25482SJohannes Berg 274565e25482SJohannes Berg if (sleeping) { 274665e25482SJohannes Berg switch (notif->type) { 274765e25482SJohannes Berg case IWL_MVM_PM_EVENT_AWAKE: 274865e25482SJohannes Berg case IWL_MVM_PM_EVENT_ASLEEP: 274965e25482SJohannes Berg break; 275065e25482SJohannes Berg case IWL_MVM_PM_EVENT_UAPSD: 275165e25482SJohannes Berg ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); 275265e25482SJohannes Berg break; 275365e25482SJohannes Berg case IWL_MVM_PM_EVENT_PS_POLL: 275465e25482SJohannes Berg ieee80211_sta_pspoll(sta); 275565e25482SJohannes Berg break; 275665e25482SJohannes Berg default: 275765e25482SJohannes Berg break; 275865e25482SJohannes Berg } 275965e25482SJohannes Berg } 276065e25482SJohannes Berg 276165e25482SJohannes Berg rcu_read_unlock(); 276265e25482SJohannes Berg } 276365e25482SJohannes Berg 2764e705c121SKalle Valo static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 2765e705c121SKalle Valo struct ieee80211_vif *vif, 2766e705c121SKalle Valo struct ieee80211_sta *sta) 2767e705c121SKalle Valo { 2768e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2769e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2770e705c121SKalle Valo 2771e705c121SKalle Valo /* 2772e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 2773e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 2774e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 2775e705c121SKalle Valo * be able to find the station this way, and we don't rely 2776e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 2777e705c121SKalle Valo * callback deleted the station. 2778e705c121SKalle Valo */ 2779e705c121SKalle Valo mutex_lock(&mvm->mutex); 2780e705c121SKalle Valo if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) 2781e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], 2782e705c121SKalle Valo ERR_PTR(-ENOENT)); 2783e705c121SKalle Valo 2784e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2785e705c121SKalle Valo } 2786e705c121SKalle Valo 2787e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2788e705c121SKalle Valo const u8 *bssid) 2789e705c121SKalle Valo { 2790b0ffe455SJohannes Berg int i; 2791b0ffe455SJohannes Berg 2792b0ffe455SJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 2793b0ffe455SJohannes Berg struct iwl_mvm_tcm_mac *mdata; 2794b0ffe455SJohannes Berg 2795b0ffe455SJohannes Berg mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id]; 2796b0ffe455SJohannes Berg ewma_rate_init(&mdata->uapsd_nonagg_detect.rate); 2797b0ffe455SJohannes Berg mdata->opened_rx_ba_sessions = false; 2798b0ffe455SJohannes Berg } 2799b0ffe455SJohannes Berg 2800e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 2801e705c121SKalle Valo return; 2802e705c121SKalle Valo 2803c5241b0cSAvraham Stern if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) { 2804cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2805cee5a882SAvri Altman return; 2806cee5a882SAvri Altman } 2807cee5a882SAvri Altman 280811dee0b4SEmmanuel Grumbach if (!vif->p2p && 280911dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 2810e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2811e705c121SKalle Valo return; 2812e705c121SKalle Valo } 2813e705c121SKalle Valo 2814b0ffe455SJohannes Berg for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { 2815b0ffe455SJohannes Berg if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) { 2816b0ffe455SJohannes Berg vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2817b0ffe455SJohannes Berg return; 2818b0ffe455SJohannes Berg } 2819b0ffe455SJohannes Berg } 2820b0ffe455SJohannes Berg 2821e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 2822e705c121SKalle Valo } 2823e705c121SKalle Valo 28241e8f1329SGolan Ben-Ami static void 28251e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 28261e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 28271e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 28281e8f1329SGolan Ben-Ami { 28291e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 28301e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 28311e8f1329SGolan Ben-Ami 28326c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 28336c042d75SSara Sharon FW_DBG_TRIGGER_TDLS); 28346c042d75SSara Sharon if (!trig) 28351e8f1329SGolan Ben-Ami return; 28361e8f1329SGolan Ben-Ami 28371e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 28381e8f1329SGolan Ben-Ami 28391e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 28401e8f1329SGolan Ben-Ami return; 28411e8f1329SGolan Ben-Ami 28421e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 28431e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 28441e8f1329SGolan Ben-Ami return; 28451e8f1329SGolan Ben-Ami 28467174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 28471e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 28481e8f1329SGolan Ben-Ami peer_addr, action); 28491e8f1329SGolan Ben-Ami } 28501e8f1329SGolan Ben-Ami 285124afba76SLiad Kaufman static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm, 285224afba76SLiad Kaufman struct iwl_mvm_sta *mvm_sta) 285324afba76SLiad Kaufman { 285424afba76SLiad Kaufman struct iwl_mvm_tid_data *tid_data; 285524afba76SLiad Kaufman struct sk_buff *skb; 285624afba76SLiad Kaufman int i; 285724afba76SLiad Kaufman 285824afba76SLiad Kaufman spin_lock_bh(&mvm_sta->lock); 285924afba76SLiad Kaufman for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { 286024afba76SLiad Kaufman tid_data = &mvm_sta->tid_data[i]; 28617e39a00dSAvraham Stern 28627e39a00dSAvraham Stern while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) { 28637e39a00dSAvraham Stern struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 28647e39a00dSAvraham Stern 28657e39a00dSAvraham Stern /* 28667e39a00dSAvraham Stern * The first deferred frame should've stopped the MAC 28677e39a00dSAvraham Stern * queues, so we should never get a second deferred 28687e39a00dSAvraham Stern * frame for the RA/TID. 28697e39a00dSAvraham Stern */ 28708458e48aSAvraham Stern iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue)); 287124afba76SLiad Kaufman ieee80211_free_txskb(mvm->hw, skb); 287224afba76SLiad Kaufman } 28737e39a00dSAvraham Stern } 287424afba76SLiad Kaufman spin_unlock_bh(&mvm_sta->lock); 287524afba76SLiad Kaufman } 287624afba76SLiad Kaufman 2877e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 2878e705c121SKalle Valo struct ieee80211_vif *vif, 2879e705c121SKalle Valo struct ieee80211_sta *sta, 2880e705c121SKalle Valo enum ieee80211_sta_state old_state, 2881e705c121SKalle Valo enum ieee80211_sta_state new_state) 2882e705c121SKalle Valo { 2883e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2884e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 28856ea29ce5SJohannes Berg struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2886e705c121SKalle Valo int ret; 2887e705c121SKalle Valo 2888e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 2889e705c121SKalle Valo sta->addr, old_state, new_state); 2890e705c121SKalle Valo 2891e705c121SKalle Valo /* this would be a mac80211 bug ... but don't crash */ 2892e705c121SKalle Valo if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) 2893e705c121SKalle Valo return -EINVAL; 2894e705c121SKalle Valo 289524afba76SLiad Kaufman /* 289624afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 289724afba76SLiad Kaufman * 289824afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 289924afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 290024afba76SLiad Kaufman * the queues. 290124afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 290224afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 290324afba76SLiad Kaufman * of. 290424afba76SLiad Kaufman * 290524afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 290624afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 290724afba76SLiad Kaufman */ 290824afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 2909c8f54701SJohannes Berg new_state == IEEE80211_STA_NOTEXIST) { 291024afba76SLiad Kaufman iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta); 291124afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 291224afba76SLiad Kaufman 291324afba76SLiad Kaufman /* 291424afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 291524afba76SLiad Kaufman * worker will already remove it if it was on 291624afba76SLiad Kaufman */ 291724afba76SLiad Kaufman } 291824afba76SLiad Kaufman 2919e705c121SKalle Valo mutex_lock(&mvm->mutex); 29206ea29ce5SJohannes Berg /* track whether or not the station is associated */ 2921d94c5a82SGregory Greenman mvm_sta->sta_state = new_state; 29226ea29ce5SJohannes Berg 2923e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 2924e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 2925e705c121SKalle Valo /* 2926e705c121SKalle Valo * Firmware bug - it'll crash if the beacon interval is less 2927e705c121SKalle Valo * than 16. We can't avoid connecting at all, so refuse the 2928e705c121SKalle Valo * station state change, this will cause mac80211 to abandon 2929e705c121SKalle Valo * attempts to connect to this AP, and eventually wpa_s will 2930e705c121SKalle Valo * blacklist the AP... 2931e705c121SKalle Valo */ 2932e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 2933e705c121SKalle Valo vif->bss_conf.beacon_int < 16) { 2934e705c121SKalle Valo IWL_ERR(mvm, 2935e705c121SKalle Valo "AP %pM beacon interval is %d, refusing due to firmware bug!\n", 2936e705c121SKalle Valo sta->addr, vif->bss_conf.beacon_int); 2937e705c121SKalle Valo ret = -EINVAL; 2938e705c121SKalle Valo goto out_unlock; 2939e705c121SKalle Valo } 2940e705c121SKalle Valo 2941e705c121SKalle Valo if (sta->tdls && 2942e705c121SKalle Valo (vif->p2p || 2943e705c121SKalle Valo iwl_mvm_tdls_sta_count(mvm, NULL) == 2944e705c121SKalle Valo IWL_MVM_TDLS_STA_COUNT || 2945e705c121SKalle Valo iwl_mvm_phy_ctx_count(mvm) > 1)) { 2946e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 2947e705c121SKalle Valo ret = -EBUSY; 2948e705c121SKalle Valo goto out_unlock; 2949e705c121SKalle Valo } 2950e705c121SKalle Valo 2951e705c121SKalle Valo ret = iwl_mvm_add_sta(mvm, vif, sta); 29521e8f1329SGolan Ben-Ami if (sta->tdls && ret == 0) { 2953e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, true); 29541e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 29551e8f1329SGolan Ben-Ami NL80211_TDLS_SETUP); 29561e8f1329SGolan Ben-Ami } 2957e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 2958e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 2959e705c121SKalle Valo /* 2960e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 2961e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 2962e705c121SKalle Valo */ 2963e705c121SKalle Valo mvm->last_ebs_successful = true; 2964e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 2965e705c121SKalle Valo ret = 0; 2966e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 2967e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 29688be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 29698be30c13SAyala Beker mvmvif->ap_assoc_sta_count++; 29708be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 297102221a81SShaul Triebitz if (vif->bss_conf.he_support && 297202221a81SShaul Triebitz !iwlwifi_mod_params.disable_11ax) 297302221a81SShaul Triebitz iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id); 29748be30c13SAyala Beker } 2975735a0045SGoodstein, Mordechay 29763baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 29773baf7528SAvraham Stern false); 2978735a0045SGoodstein, Mordechay ret = iwl_mvm_update_sta(mvm, vif, sta); 2979e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 2980e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 2981e705c121SKalle Valo 2982e705c121SKalle Valo /* we don't support TDLS during DCM */ 2983e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2984e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2985e705c121SKalle Valo 29861e8f1329SGolan Ben-Ami if (sta->tdls) 29871e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 29881e8f1329SGolan Ben-Ami NL80211_TDLS_ENABLE_LINK); 29891e8f1329SGolan Ben-Ami 2990e705c121SKalle Valo /* enable beacon filtering */ 2991e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 29926b7a5aeaSNaftali Goldstein 29933baf7528SAvraham Stern iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band, 29943baf7528SAvraham Stern true); 29956b7a5aeaSNaftali Goldstein 2996337bfc98SAvraham Stern /* if wep is used, need to set the key for the station now */ 2997337bfc98SAvraham Stern if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key) 2998337bfc98SAvraham Stern ret = iwl_mvm_set_sta_key(mvm, vif, sta, 2999337bfc98SAvraham Stern mvmvif->ap_wep_key, 3000337bfc98SAvraham Stern STA_KEY_IDX_INVALID); 3001337bfc98SAvraham Stern else 3002e705c121SKalle Valo ret = 0; 3003e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 3004e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 3005e705c121SKalle Valo /* disable beacon filtering */ 3006e705c121SKalle Valo WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0)); 3007e705c121SKalle Valo ret = 0; 3008e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 3009e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 30108be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 30118be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 30128be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 30138be30c13SAyala Beker } 3014e705c121SKalle Valo ret = 0; 3015e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 3016e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 3017e705c121SKalle Valo ret = 0; 3018e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 3019e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 3020e705c121SKalle Valo ret = iwl_mvm_rm_sta(mvm, vif, sta); 30211e8f1329SGolan Ben-Ami if (sta->tdls) { 3022e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 30231e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 30241e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 30251e8f1329SGolan Ben-Ami } 3026e705c121SKalle Valo } else { 3027e705c121SKalle Valo ret = -EIO; 3028e705c121SKalle Valo } 3029e705c121SKalle Valo out_unlock: 3030e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3031e705c121SKalle Valo 3032e705c121SKalle Valo if (sta->tdls && ret == 0) { 3033e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 3034e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 3035e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3036e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 3037e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 3038e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 3039e705c121SKalle Valo } 3040e705c121SKalle Valo 3041e705c121SKalle Valo return ret; 3042e705c121SKalle Valo } 3043e705c121SKalle Valo 3044e705c121SKalle Valo static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 3045e705c121SKalle Valo { 3046e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3047e705c121SKalle Valo 3048e705c121SKalle Valo mvm->rts_threshold = value; 3049e705c121SKalle Valo 3050e705c121SKalle Valo return 0; 3051e705c121SKalle Valo } 3052e705c121SKalle Valo 3053e705c121SKalle Valo static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, 3054e705c121SKalle Valo struct ieee80211_vif *vif, 3055e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 3056e705c121SKalle Valo { 3057e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3058e705c121SKalle Valo 3059e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 3060e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 3061e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 3062e705c121SKalle Valo } 3063e705c121SKalle Valo 3064e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 3065e705c121SKalle Valo struct ieee80211_vif *vif, u16 ac, 3066e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 3067e705c121SKalle Valo { 3068e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3069e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3070e705c121SKalle Valo 3071e705c121SKalle Valo mvmvif->queue_params[ac] = *params; 3072e705c121SKalle Valo 3073e705c121SKalle Valo /* 3074e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 3075e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 3076e705c121SKalle Valo */ 3077e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 3078e705c121SKalle Valo int ret; 3079e705c121SKalle Valo 3080e705c121SKalle Valo mutex_lock(&mvm->mutex); 3081e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3082e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3083e705c121SKalle Valo return ret; 3084e705c121SKalle Valo } 3085e705c121SKalle Valo return 0; 3086e705c121SKalle Valo } 3087e705c121SKalle Valo 3088e705c121SKalle Valo static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 3089d4e36e55SIlan Peer struct ieee80211_vif *vif, 3090d4e36e55SIlan Peer u16 req_duration) 3091e705c121SKalle Valo { 3092e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 30937c70fee5SSara Sharon u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 30947c70fee5SSara Sharon u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 3095e705c121SKalle Valo 3096e705c121SKalle Valo /* 3097e705c121SKalle Valo * iwl_mvm_protect_session() reads directly from the device 3098e705c121SKalle Valo * (the system time), so make sure it is available. 3099e705c121SKalle Valo */ 3100e705c121SKalle Valo if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX)) 3101e705c121SKalle Valo return; 3102e705c121SKalle Valo 3103d4e36e55SIlan Peer if (req_duration > duration) 3104d4e36e55SIlan Peer duration = req_duration; 3105d4e36e55SIlan Peer 3106e705c121SKalle Valo mutex_lock(&mvm->mutex); 3107e705c121SKalle Valo /* Try really hard to protect the session and hear a beacon */ 3108e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false); 3109e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3110e705c121SKalle Valo 3111e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX); 3112e705c121SKalle Valo } 3113e705c121SKalle Valo 3114e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 3115e705c121SKalle Valo struct ieee80211_vif *vif, 3116e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 3117e705c121SKalle Valo struct ieee80211_scan_ies *ies) 3118e705c121SKalle Valo { 3119e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3120e705c121SKalle Valo 3121e705c121SKalle Valo int ret; 3122e705c121SKalle Valo 3123e705c121SKalle Valo mutex_lock(&mvm->mutex); 3124e705c121SKalle Valo 3125e705c121SKalle Valo if (!vif->bss_conf.idle) { 3126e705c121SKalle Valo ret = -EBUSY; 3127e705c121SKalle Valo goto out; 3128e705c121SKalle Valo } 3129e705c121SKalle Valo 3130e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 3131e705c121SKalle Valo 3132e705c121SKalle Valo out: 3133e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3134e705c121SKalle Valo return ret; 3135e705c121SKalle Valo } 3136e705c121SKalle Valo 3137e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 3138e705c121SKalle Valo struct ieee80211_vif *vif) 3139e705c121SKalle Valo { 3140e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3141e705c121SKalle Valo int ret; 3142e705c121SKalle Valo 3143e705c121SKalle Valo mutex_lock(&mvm->mutex); 3144e705c121SKalle Valo 3145e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 3146e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 3147e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 3148e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 3149e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 3150e705c121SKalle Valo * could run. To handle this, simply return if the scan is 3151e705c121SKalle Valo * not running. 3152e705c121SKalle Valo */ 3153e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 3154e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3155e705c121SKalle Valo return 0; 3156e705c121SKalle Valo } 3157e705c121SKalle Valo 3158e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 3159e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3160e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 3161e705c121SKalle Valo 3162e705c121SKalle Valo return ret; 3163e705c121SKalle Valo } 3164e705c121SKalle Valo 3165e705c121SKalle Valo static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 3166e705c121SKalle Valo enum set_key_cmd cmd, 3167e705c121SKalle Valo struct ieee80211_vif *vif, 3168e705c121SKalle Valo struct ieee80211_sta *sta, 3169e705c121SKalle Valo struct ieee80211_key_conf *key) 3170e705c121SKalle Valo { 3171e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3172f5e28eacSJohannes Berg struct iwl_mvm_sta *mvmsta; 3173f5e28eacSJohannes Berg struct iwl_mvm_key_pn *ptk_pn; 3174f5e28eacSJohannes Berg int keyidx = key->keyidx; 3175e705c121SKalle Valo int ret; 31764615fd15SEmmanuel Grumbach u8 key_offset; 3177e705c121SKalle Valo 31783b37f4c9SJohannes Berg if (iwlwifi_mod_params.swcrypto) { 3179e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); 3180e705c121SKalle Valo return -EOPNOTSUPP; 3181e705c121SKalle Valo } 3182e705c121SKalle Valo 3183e705c121SKalle Valo switch (key->cipher) { 3184e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 31857f768ad5SDavid Spinadel if (!mvm->trans->cfg->gen2) { 3186e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 31871ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 31887f768ad5SDavid Spinadel } else if (vif->type == NL80211_IFTYPE_STATION) { 31897f768ad5SDavid Spinadel key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE; 31907f768ad5SDavid Spinadel } else { 31917f768ad5SDavid Spinadel IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n"); 31927f768ad5SDavid Spinadel return -EOPNOTSUPP; 31937f768ad5SDavid Spinadel } 3194e705c121SKalle Valo break; 3195e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 31962a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 31972a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 319885aeb58cSDavid Spinadel if (!iwl_mvm_has_new_tx_api(mvm)) 3199e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3200e705c121SKalle Valo break; 3201e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 32028e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 32038e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 3204e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 3205e705c121SKalle Valo break; 3206e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 3207e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 3208337bfc98SAvraham Stern if (vif->type == NL80211_IFTYPE_AP) { 3209337bfc98SAvraham Stern struct iwl_mvm_vif *mvmvif = 3210337bfc98SAvraham Stern iwl_mvm_vif_from_mac80211(vif); 3211337bfc98SAvraham Stern 3212337bfc98SAvraham Stern mvmvif->ap_wep_key = kmemdup(key, 3213337bfc98SAvraham Stern sizeof(*key) + key->keylen, 3214337bfc98SAvraham Stern GFP_KERNEL); 3215337bfc98SAvraham Stern if (!mvmvif->ap_wep_key) 3216337bfc98SAvraham Stern return -ENOMEM; 3217337bfc98SAvraham Stern } 3218337bfc98SAvraham Stern 3219e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION) 3220e705c121SKalle Valo return 0; 3221e705c121SKalle Valo break; 3222e705c121SKalle Valo default: 3223e705c121SKalle Valo /* currently FW supports only one optional cipher scheme */ 3224e705c121SKalle Valo if (hw->n_cipher_schemes && 3225e705c121SKalle Valo hw->cipher_schemes->cipher == key->cipher) 3226e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 3227e705c121SKalle Valo else 3228e705c121SKalle Valo return -EOPNOTSUPP; 3229e705c121SKalle Valo } 3230e705c121SKalle Valo 3231e705c121SKalle Valo mutex_lock(&mvm->mutex); 3232e705c121SKalle Valo 3233e705c121SKalle Valo switch (cmd) { 3234e705c121SKalle Valo case SET_KEY: 3235e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 3236e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 3237e705c121SKalle Valo /* 3238e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 3239e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 3240e705c121SKalle Valo * we don't support them for RX, so do the same. 32418e160ab8SAyala Beker * CMAC/GMAC in AP/IBSS modes must be done in software. 3242e705c121SKalle Valo */ 32438e160ab8SAyala Beker if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 32448e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 32458e160ab8SAyala Beker key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) 324681279c49SJohannes Berg ret = -EOPNOTSUPP; 324781279c49SJohannes Berg else 3248e705c121SKalle Valo ret = 0; 324985aeb58cSDavid Spinadel 325085aeb58cSDavid Spinadel if (key->cipher != WLAN_CIPHER_SUITE_GCMP && 325185aeb58cSDavid Spinadel key->cipher != WLAN_CIPHER_SUITE_GCMP_256 && 325285aeb58cSDavid Spinadel !iwl_mvm_has_new_tx_api(mvm)) { 3253e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 3254e705c121SKalle Valo break; 3255e705c121SKalle Valo } 325685aeb58cSDavid Spinadel } 3257e705c121SKalle Valo 3258e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 3259e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 3260e705c121SKalle Valo */ 3261e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 3262e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 3263e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 3264e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 3265e705c121SKalle Valo ret = 0; 3266e705c121SKalle Valo break; 3267e705c121SKalle Valo } 3268e705c121SKalle Valo 3269f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 3270f5e28eacSJohannes Berg sta && iwl_mvm_has_new_rx_api(mvm) && 3271f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3272f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 32732a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 32742a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3275f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 3276f5e28eacSJohannes Berg int tid, q; 3277f5e28eacSJohannes Berg 3278f5e28eacSJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 3279f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 3280acafe7e3SKees Cook ptk_pn = kzalloc(struct_size(ptk_pn, q, 3281acafe7e3SKees Cook mvm->trans->num_rx_queues), 3282f5e28eacSJohannes Berg GFP_KERNEL); 3283f5e28eacSJohannes Berg if (!ptk_pn) { 3284f5e28eacSJohannes Berg ret = -ENOMEM; 3285f5e28eacSJohannes Berg break; 3286f5e28eacSJohannes Berg } 3287f5e28eacSJohannes Berg 3288f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 3289f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 3290f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 3291f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 3292f5e28eacSJohannes Berg seq.ccmp.pn, 3293f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 3294f5e28eacSJohannes Berg } 3295f5e28eacSJohannes Berg 3296f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 3297f5e28eacSJohannes Berg } 3298f5e28eacSJohannes Berg 32994615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 33004615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 33014615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 33024615fd15SEmmanuel Grumbach else 33034615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 33044615fd15SEmmanuel Grumbach 3305e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); 33064615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 3307e705c121SKalle Valo if (ret) { 3308e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 3309e705c121SKalle Valo /* 3310e705c121SKalle Valo * can't add key for RX, but we don't need it 3311e705c121SKalle Valo * in the device for TX so still return 0 3312e705c121SKalle Valo */ 3313e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 3314e705c121SKalle Valo ret = 0; 3315e705c121SKalle Valo } 3316e705c121SKalle Valo 3317e705c121SKalle Valo break; 3318e705c121SKalle Valo case DISABLE_KEY: 3319e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 3320e705c121SKalle Valo ret = 0; 3321e705c121SKalle Valo break; 3322e705c121SKalle Valo } 3323e705c121SKalle Valo 3324f5e28eacSJohannes Berg if (sta && iwl_mvm_has_new_rx_api(mvm) && 3325f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 3326f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 33272a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP || 33282a53d166SAyala Beker key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) { 3329f5e28eacSJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 3330f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 3331f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 3332f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 3333f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 3334f5e28eacSJohannes Berg if (ptk_pn) 3335f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 3336f5e28eacSJohannes Berg } 3337f5e28eacSJohannes Berg 3338e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 3339e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 3340e705c121SKalle Valo break; 3341e705c121SKalle Valo default: 3342e705c121SKalle Valo ret = -EINVAL; 3343e705c121SKalle Valo } 3344e705c121SKalle Valo 3345e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3346e705c121SKalle Valo return ret; 3347e705c121SKalle Valo } 3348e705c121SKalle Valo 3349e705c121SKalle Valo static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 3350e705c121SKalle Valo struct ieee80211_vif *vif, 3351e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 3352e705c121SKalle Valo struct ieee80211_sta *sta, 3353e705c121SKalle Valo u32 iv32, u16 *phase1key) 3354e705c121SKalle Valo { 3355e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3356e705c121SKalle Valo 3357e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 3358e705c121SKalle Valo return; 3359e705c121SKalle Valo 3360e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 3361e705c121SKalle Valo } 3362e705c121SKalle Valo 3363e705c121SKalle Valo 3364e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 3365e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 3366e705c121SKalle Valo { 3367e705c121SKalle Valo struct iwl_mvm *mvm = 3368e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 3369e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 3370e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 3371e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 3372e705c121SKalle Valo 3373e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 3374e705c121SKalle Valo return true; 3375e705c121SKalle Valo 3376e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 3377e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 3378e705c121SKalle Valo return true; 3379e705c121SKalle Valo } 3380e705c121SKalle Valo 3381e705c121SKalle Valo resp = (void *)pkt->data; 3382e705c121SKalle Valo 3383e705c121SKalle Valo IWL_DEBUG_TE(mvm, 3384e705c121SKalle Valo "Aux ROC: Recieved response from ucode: status=%d uid=%d\n", 3385e705c121SKalle Valo resp->status, resp->event_unique_id); 3386e705c121SKalle Valo 3387e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 3388e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 3389e705c121SKalle Valo te_data->uid); 3390e705c121SKalle Valo 3391e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3392e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 3393e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3394e705c121SKalle Valo 3395e705c121SKalle Valo return true; 3396e705c121SKalle Valo } 3397e705c121SKalle Valo 3398dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) 3399dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) 3400dc28e12fSMatti Gottlieb #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) 3401dc28e12fSMatti Gottlieb #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) 3402dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) 3403e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 3404e705c121SKalle Valo struct ieee80211_channel *channel, 3405e705c121SKalle Valo struct ieee80211_vif *vif, 3406e705c121SKalle Valo int duration) 3407e705c121SKalle Valo { 3408e705c121SKalle Valo int res, time_reg = DEVICE_SYSTEM_TIME_REG; 3409e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3410e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 3411e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 3412e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 3413dc28e12fSMatti Gottlieb u32 dtim_interval = vif->bss_conf.dtim_period * 3414dc28e12fSMatti Gottlieb vif->bss_conf.beacon_int; 3415dc28e12fSMatti Gottlieb u32 req_dur, delay; 3416e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 3417e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 3418e705c121SKalle Valo .id_and_color = 3419e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 3420e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 3421e705c121SKalle Valo /* Set the channel info data */ 342257fbcce3SJohannes Berg .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ? 3423e705c121SKalle Valo PHY_BAND_24 : PHY_BAND_5, 3424e705c121SKalle Valo .channel_info.channel = channel->hw_value, 3425e705c121SKalle Valo .channel_info.width = PHY_VHT_CHANNEL_MODE20, 3426e705c121SKalle Valo /* Set the time and duration */ 3427e705c121SKalle Valo .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)), 3428e705c121SKalle Valo }; 3429e705c121SKalle Valo 3430dc28e12fSMatti Gottlieb delay = AUX_ROC_MIN_DELAY; 3431dc28e12fSMatti Gottlieb req_dur = MSEC_TO_TU(duration); 3432dc28e12fSMatti Gottlieb 3433dc28e12fSMatti Gottlieb /* 3434dc28e12fSMatti Gottlieb * If we are associated we want the delay time to be at least one 3435dc28e12fSMatti Gottlieb * dtim interval so that the FW can wait until after the DTIM and 3436dc28e12fSMatti Gottlieb * then start the time event, this will potentially allow us to 3437dc28e12fSMatti Gottlieb * remain off-channel for the max duration. 3438dc28e12fSMatti Gottlieb * Since we want to use almost a whole dtim interval we would also 3439dc28e12fSMatti Gottlieb * like the delay to be for 2-3 dtim intervals, in case there are 3440dc28e12fSMatti Gottlieb * other time events with higher priority. 3441dc28e12fSMatti Gottlieb */ 3442dc28e12fSMatti Gottlieb if (vif->bss_conf.assoc) { 3443dc28e12fSMatti Gottlieb delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); 3444dc28e12fSMatti Gottlieb /* We cannot remain off-channel longer than the DTIM interval */ 3445dc28e12fSMatti Gottlieb if (dtim_interval <= req_dur) { 3446dc28e12fSMatti Gottlieb req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; 3447dc28e12fSMatti Gottlieb if (req_dur <= AUX_ROC_MIN_DURATION) 3448dc28e12fSMatti Gottlieb req_dur = dtim_interval - 3449dc28e12fSMatti Gottlieb AUX_ROC_MIN_SAFETY_BUFFER; 3450dc28e12fSMatti Gottlieb } 3451dc28e12fSMatti Gottlieb } 3452dc28e12fSMatti Gottlieb 3453dc28e12fSMatti Gottlieb aux_roc_req.duration = cpu_to_le32(req_dur); 3454dc28e12fSMatti Gottlieb aux_roc_req.apply_time_max_delay = cpu_to_le32(delay); 3455dc28e12fSMatti Gottlieb 3456dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 3457dc28e12fSMatti Gottlieb "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", 3458dc28e12fSMatti Gottlieb channel->hw_value, req_dur, duration, delay, 3459dc28e12fSMatti Gottlieb dtim_interval); 3460e705c121SKalle Valo /* Set the node address */ 3461e705c121SKalle Valo memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN); 3462e705c121SKalle Valo 3463e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3464e705c121SKalle Valo 3465e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3466e705c121SKalle Valo 3467e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 3468e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3469e705c121SKalle Valo return -EIO; 3470e705c121SKalle Valo } 3471e705c121SKalle Valo 3472e705c121SKalle Valo te_data->vif = vif; 3473e705c121SKalle Valo te_data->duration = duration; 3474e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 3475e705c121SKalle Valo 3476e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3477e705c121SKalle Valo 3478e705c121SKalle Valo /* 3479e705c121SKalle Valo * Use a notification wait, which really just processes the 3480e705c121SKalle Valo * command response and doesn't wait for anything, in order 3481e705c121SKalle Valo * to be able to process the response and get the UID inside 3482e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 3483e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 3484e705c121SKalle Valo * time another notification (that the time event started) 3485e705c121SKalle Valo * might already be processed unsuccessfully. 3486e705c121SKalle Valo */ 3487e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 3488e705c121SKalle Valo time_event_response, 3489e705c121SKalle Valo ARRAY_SIZE(time_event_response), 3490e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 3491e705c121SKalle Valo 3492e705c121SKalle Valo res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req), 3493e705c121SKalle Valo &aux_roc_req); 3494e705c121SKalle Valo 3495e705c121SKalle Valo if (res) { 3496e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 3497e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 3498e705c121SKalle Valo goto out_clear_te; 3499e705c121SKalle Valo } 3500e705c121SKalle Valo 3501e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 3502e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 3503e705c121SKalle Valo /* should never fail */ 3504e705c121SKalle Valo WARN_ON_ONCE(res); 3505e705c121SKalle Valo 3506e705c121SKalle Valo if (res) { 3507e705c121SKalle Valo out_clear_te: 3508e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3509e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 3510e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3511e705c121SKalle Valo } 3512e705c121SKalle Valo 3513e705c121SKalle Valo return res; 3514e705c121SKalle Valo } 3515e705c121SKalle Valo 3516e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 3517e705c121SKalle Valo struct ieee80211_vif *vif, 3518e705c121SKalle Valo struct ieee80211_channel *channel, 3519e705c121SKalle Valo int duration, 3520e705c121SKalle Valo enum ieee80211_roc_type type) 3521e705c121SKalle Valo { 3522e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3523e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3524e705c121SKalle Valo struct cfg80211_chan_def chandef; 3525e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 3526e705c121SKalle Valo int ret, i; 3527e705c121SKalle Valo 3528e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 3529e705c121SKalle Valo duration, type); 3530e705c121SKalle Valo 35319834781cSJohannes Berg /* 35329834781cSJohannes Berg * Flush the done work, just in case it's still pending, so that 35339834781cSJohannes Berg * the work it does can complete and we can accept new frames. 35349834781cSJohannes Berg */ 3535e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 3536e705c121SKalle Valo 3537e705c121SKalle Valo mutex_lock(&mvm->mutex); 3538e705c121SKalle Valo 3539e705c121SKalle Valo switch (vif->type) { 3540e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3541e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 3542e705c121SKalle Valo IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 3543e705c121SKalle Valo /* Use aux roc framework (HS20) */ 3544e705c121SKalle Valo ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 3545e705c121SKalle Valo vif, duration); 3546e705c121SKalle Valo goto out_unlock; 3547e705c121SKalle Valo } 3548e705c121SKalle Valo IWL_ERR(mvm, "hotspot not supported\n"); 3549e705c121SKalle Valo ret = -EINVAL; 3550e705c121SKalle Valo goto out_unlock; 3551e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 3552e705c121SKalle Valo /* handle below */ 3553e705c121SKalle Valo break; 3554e705c121SKalle Valo default: 3555e705c121SKalle Valo IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); 3556e705c121SKalle Valo ret = -EINVAL; 3557e705c121SKalle Valo goto out_unlock; 3558e705c121SKalle Valo } 3559e705c121SKalle Valo 3560e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 3561e705c121SKalle Valo phy_ctxt = &mvm->phy_ctxts[i]; 3562e705c121SKalle Valo if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) 3563e705c121SKalle Valo continue; 3564e705c121SKalle Valo 3565e705c121SKalle Valo if (phy_ctxt->ref && channel == phy_ctxt->channel) { 3566e705c121SKalle Valo /* 3567e705c121SKalle Valo * Unbind the P2P_DEVICE from the current PHY context, 3568e705c121SKalle Valo * and if the PHY context is not used remove it. 3569e705c121SKalle Valo */ 3570e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3571e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3572e705c121SKalle Valo goto out_unlock; 3573e705c121SKalle Valo 3574e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3575e705c121SKalle Valo 3576e705c121SKalle Valo /* Bind the P2P_DEVICE to the current PHY Context */ 3577e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3578e705c121SKalle Valo 3579e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3580e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3581e705c121SKalle Valo goto out_unlock; 3582e705c121SKalle Valo 3583e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3584e705c121SKalle Valo goto schedule_time_event; 3585e705c121SKalle Valo } 3586e705c121SKalle Valo } 3587e705c121SKalle Valo 3588e705c121SKalle Valo /* Need to update the PHY context only if the ROC channel changed */ 3589e705c121SKalle Valo if (channel == mvmvif->phy_ctxt->channel) 3590e705c121SKalle Valo goto schedule_time_event; 3591e705c121SKalle Valo 3592e705c121SKalle Valo cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 3593e705c121SKalle Valo 3594e705c121SKalle Valo /* 3595e705c121SKalle Valo * Change the PHY context configuration as it is currently referenced 3596e705c121SKalle Valo * only by the P2P Device MAC 3597e705c121SKalle Valo */ 3598e705c121SKalle Valo if (mvmvif->phy_ctxt->ref == 1) { 3599e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, 3600e705c121SKalle Valo &chandef, 1, 1); 3601e705c121SKalle Valo if (ret) 3602e705c121SKalle Valo goto out_unlock; 3603e705c121SKalle Valo } else { 3604e705c121SKalle Valo /* 3605e705c121SKalle Valo * The PHY context is shared with other MACs. Need to remove the 3606e705c121SKalle Valo * P2P Device from the binding, allocate an new PHY context and 3607e705c121SKalle Valo * create a new binding 3608e705c121SKalle Valo */ 3609e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 3610e705c121SKalle Valo if (!phy_ctxt) { 3611e705c121SKalle Valo ret = -ENOSPC; 3612e705c121SKalle Valo goto out_unlock; 3613e705c121SKalle Valo } 3614e705c121SKalle Valo 3615e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, 3616e705c121SKalle Valo 1, 1); 3617e705c121SKalle Valo if (ret) { 3618e705c121SKalle Valo IWL_ERR(mvm, "Failed to change PHY context\n"); 3619e705c121SKalle Valo goto out_unlock; 3620e705c121SKalle Valo } 3621e705c121SKalle Valo 3622e705c121SKalle Valo /* Unbind the P2P_DEVICE from the current PHY context */ 3623e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3624e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3625e705c121SKalle Valo goto out_unlock; 3626e705c121SKalle Valo 3627e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3628e705c121SKalle Valo 3629e705c121SKalle Valo /* Bind the P2P_DEVICE to the new allocated PHY context */ 3630e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3631e705c121SKalle Valo 3632e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3633e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3634e705c121SKalle Valo goto out_unlock; 3635e705c121SKalle Valo 3636e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3637e705c121SKalle Valo } 3638e705c121SKalle Valo 3639e705c121SKalle Valo schedule_time_event: 3640e705c121SKalle Valo /* Schedule the time events */ 3641e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 3642e705c121SKalle Valo 3643e705c121SKalle Valo out_unlock: 3644e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3645e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 3646e705c121SKalle Valo return ret; 3647e705c121SKalle Valo } 3648e705c121SKalle Valo 3649e705c121SKalle Valo static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) 3650e705c121SKalle Valo { 3651e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3652e705c121SKalle Valo 3653e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 3654e705c121SKalle Valo 3655e705c121SKalle Valo mutex_lock(&mvm->mutex); 3656e705c121SKalle Valo iwl_mvm_stop_roc(mvm); 3657e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3658e705c121SKalle Valo 3659e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 3660e705c121SKalle Valo return 0; 3661e705c121SKalle Valo } 3662e705c121SKalle Valo 3663e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 3664e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3665e705c121SKalle Valo { 3666e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3667e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 3668e705c121SKalle Valo int ret; 3669e705c121SKalle Valo 3670e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3671e705c121SKalle Valo 3672e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 3673e705c121SKalle Valo 3674e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 3675e705c121SKalle Valo if (!phy_ctxt) { 3676e705c121SKalle Valo ret = -ENOSPC; 3677e705c121SKalle Valo goto out; 3678e705c121SKalle Valo } 3679e705c121SKalle Valo 3680e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, 3681e705c121SKalle Valo ctx->rx_chains_static, 3682e705c121SKalle Valo ctx->rx_chains_dynamic); 3683e705c121SKalle Valo if (ret) { 3684e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 3685e705c121SKalle Valo goto out; 3686e705c121SKalle Valo } 3687e705c121SKalle Valo 3688e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); 3689e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 3690e705c121SKalle Valo out: 3691e705c121SKalle Valo return ret; 3692e705c121SKalle Valo } 3693e705c121SKalle Valo 3694e705c121SKalle Valo static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 3695e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3696e705c121SKalle Valo { 3697e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3698e705c121SKalle Valo int ret; 3699e705c121SKalle Valo 3700e705c121SKalle Valo mutex_lock(&mvm->mutex); 3701e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 3702e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3703e705c121SKalle Valo 3704e705c121SKalle Valo return ret; 3705e705c121SKalle Valo } 3706e705c121SKalle Valo 3707e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 3708e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3709e705c121SKalle Valo { 3710e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3711e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3712e705c121SKalle Valo 3713e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3714e705c121SKalle Valo 3715e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 3716e705c121SKalle Valo } 3717e705c121SKalle Valo 3718e705c121SKalle Valo static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 3719e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3720e705c121SKalle Valo { 3721e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3722e705c121SKalle Valo 3723e705c121SKalle Valo mutex_lock(&mvm->mutex); 3724e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 3725e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3726e705c121SKalle Valo } 3727e705c121SKalle Valo 3728e705c121SKalle Valo static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 3729e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3730e705c121SKalle Valo u32 changed) 3731e705c121SKalle Valo { 3732e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3733e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3734e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3735e705c121SKalle Valo 3736e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 3737e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 3738e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 3739e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 3740e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 3741e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 3742e705c121SKalle Valo phy_ctxt->ref, changed)) 3743e705c121SKalle Valo return; 3744e705c121SKalle Valo 3745e705c121SKalle Valo mutex_lock(&mvm->mutex); 37467a20bcceSEmmanuel Grumbach 37477a20bcceSEmmanuel Grumbach /* we are only changing the min_width, may be a noop */ 37487a20bcceSEmmanuel Grumbach if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) { 37497a20bcceSEmmanuel Grumbach if (phy_ctxt->width == ctx->min_def.width) 37507a20bcceSEmmanuel Grumbach goto out_unlock; 37517a20bcceSEmmanuel Grumbach 37527a20bcceSEmmanuel Grumbach /* we are just toggling between 20_NOHT and 20 */ 37537a20bcceSEmmanuel Grumbach if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 && 37547a20bcceSEmmanuel Grumbach ctx->min_def.width <= NL80211_CHAN_WIDTH_20) 37557a20bcceSEmmanuel Grumbach goto out_unlock; 37567a20bcceSEmmanuel Grumbach } 37577a20bcceSEmmanuel Grumbach 3758e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 3759e705c121SKalle Valo iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, 3760e705c121SKalle Valo ctx->rx_chains_static, 3761e705c121SKalle Valo ctx->rx_chains_dynamic); 37627a20bcceSEmmanuel Grumbach 37637a20bcceSEmmanuel Grumbach out_unlock: 3764e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3765e705c121SKalle Valo } 3766e705c121SKalle Valo 3767e705c121SKalle Valo static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 3768e705c121SKalle Valo struct ieee80211_vif *vif, 3769e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3770e705c121SKalle Valo bool switching_chanctx) 3771e705c121SKalle Valo { 3772e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3773e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3774e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3775e705c121SKalle Valo int ret; 3776e705c121SKalle Valo 3777e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3778e705c121SKalle Valo 3779e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3780e705c121SKalle Valo 3781e705c121SKalle Valo switch (vif->type) { 3782e705c121SKalle Valo case NL80211_IFTYPE_AP: 3783e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 3784e705c121SKalle Valo if (switching_chanctx) { 3785e705c121SKalle Valo mvmvif->ap_ibss_active = true; 3786e705c121SKalle Valo break; 3787e705c121SKalle Valo } 3788e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3789e705c121SKalle Valo /* 3790e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 3791e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 3792e705c121SKalle Valo */ 3793e705c121SKalle Valo ret = 0; 3794e705c121SKalle Valo goto out; 3795e705c121SKalle Valo case NL80211_IFTYPE_STATION: 379619125cb0SAndrei Otcheretianski mvmvif->csa_bcn_pending = false; 3797e705c121SKalle Valo break; 3798e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 3799e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 3800e705c121SKalle Valo mvmvif->ps_disabled = true; 3801e705c121SKalle Valo break; 3802e705c121SKalle Valo default: 3803e705c121SKalle Valo ret = -EINVAL; 3804e705c121SKalle Valo goto out; 3805e705c121SKalle Valo } 3806e705c121SKalle Valo 3807e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3808e705c121SKalle Valo if (ret) 3809e705c121SKalle Valo goto out; 3810e705c121SKalle Valo 3811e705c121SKalle Valo /* 3812e705c121SKalle Valo * Power state must be updated before quotas, 3813e705c121SKalle Valo * otherwise fw will complain. 3814e705c121SKalle Valo */ 3815e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3816e705c121SKalle Valo 3817e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 3818e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 3819e705c121SKalle Valo * will handle quota settings. 3820e705c121SKalle Valo */ 3821e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 3822e705c121SKalle Valo mvmvif->monitor_active = true; 3823e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 3824e705c121SKalle Valo if (ret) 3825e705c121SKalle Valo goto out_remove_binding; 38260e39eb03SChaya Rachel Ivgi 38270e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 38280e39eb03SChaya Rachel Ivgi if (ret) 38290e39eb03SChaya Rachel Ivgi goto out_remove_binding; 38300e39eb03SChaya Rachel Ivgi 3831e705c121SKalle Valo } 3832e705c121SKalle Valo 3833e705c121SKalle Valo /* Handle binding during CSA */ 3834e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 3835e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3836e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3837e705c121SKalle Valo } 3838e705c121SKalle Valo 3839e705c121SKalle Valo if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { 384019125cb0SAndrei Otcheretianski u32 duration = 3 * vif->bss_conf.beacon_int; 3841e705c121SKalle Valo 3842e705c121SKalle Valo /* iwl_mvm_protect_session() reads directly from the 3843e705c121SKalle Valo * device (the system time), so make sure it is 3844e705c121SKalle Valo * available. 3845e705c121SKalle Valo */ 3846e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA); 3847e705c121SKalle Valo if (ret) 3848e705c121SKalle Valo goto out_remove_binding; 3849e705c121SKalle Valo 3850e705c121SKalle Valo /* Protect the session to make sure we hear the first 3851e705c121SKalle Valo * beacon on the new channel. 3852e705c121SKalle Valo */ 385319125cb0SAndrei Otcheretianski mvmvif->csa_bcn_pending = true; 3854e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 3855e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 3856e705c121SKalle Valo true); 3857e705c121SKalle Valo 3858e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA); 3859e705c121SKalle Valo 3860e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3861e705c121SKalle Valo } 3862e705c121SKalle Valo 3863e705c121SKalle Valo goto out; 3864e705c121SKalle Valo 3865e705c121SKalle Valo out_remove_binding: 3866e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3867e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3868e705c121SKalle Valo out: 3869e705c121SKalle Valo if (ret) 3870e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 3871e705c121SKalle Valo return ret; 3872e705c121SKalle Valo } 3873e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 3874e705c121SKalle Valo struct ieee80211_vif *vif, 3875e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3876e705c121SKalle Valo { 3877e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3878e705c121SKalle Valo int ret; 3879e705c121SKalle Valo 3880e705c121SKalle Valo mutex_lock(&mvm->mutex); 3881e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); 3882e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3883e705c121SKalle Valo 3884e705c121SKalle Valo return ret; 3885e705c121SKalle Valo } 3886e705c121SKalle Valo 3887e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 3888e705c121SKalle Valo struct ieee80211_vif *vif, 3889e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3890e705c121SKalle Valo bool switching_chanctx) 3891e705c121SKalle Valo { 3892e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3893e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 3894e705c121SKalle Valo 3895e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3896e705c121SKalle Valo 3897e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); 3898e705c121SKalle Valo 3899e705c121SKalle Valo switch (vif->type) { 3900e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3901e705c121SKalle Valo goto out; 3902e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 3903e705c121SKalle Valo mvmvif->monitor_active = false; 3904e705c121SKalle Valo mvmvif->ps_disabled = false; 39050e39eb03SChaya Rachel Ivgi iwl_mvm_rm_snif_sta(mvm, vif); 3906e705c121SKalle Valo break; 3907e705c121SKalle Valo case NL80211_IFTYPE_AP: 3908e705c121SKalle Valo /* This part is triggered only during CSA */ 3909e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 3910e705c121SKalle Valo goto out; 3911e705c121SKalle Valo 3912e705c121SKalle Valo mvmvif->csa_countdown = false; 3913e705c121SKalle Valo 3914e705c121SKalle Valo /* Set CS bit on all the stations */ 3915e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 3916e705c121SKalle Valo 3917e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 3918e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 3919e705c121SKalle Valo 3920e705c121SKalle Valo mvmvif->ap_ibss_active = false; 3921e705c121SKalle Valo break; 3922e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3923e705c121SKalle Valo if (!switching_chanctx) 3924e705c121SKalle Valo break; 3925e705c121SKalle Valo 3926e705c121SKalle Valo disabled_vif = vif; 3927e705c121SKalle Valo 3928e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 3929e705c121SKalle Valo break; 3930e705c121SKalle Valo default: 3931e705c121SKalle Valo break; 3932e705c121SKalle Valo } 3933e705c121SKalle Valo 3934e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 3935e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3936e705c121SKalle Valo 3937e705c121SKalle Valo out: 3938e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 3939e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3940e705c121SKalle Valo } 3941e705c121SKalle Valo 3942e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 3943e705c121SKalle Valo struct ieee80211_vif *vif, 3944e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3945e705c121SKalle Valo { 3946e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3947e705c121SKalle Valo 3948e705c121SKalle Valo mutex_lock(&mvm->mutex); 3949e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); 3950e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3951e705c121SKalle Valo } 3952e705c121SKalle Valo 3953e705c121SKalle Valo static int 3954e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 3955e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 3956e705c121SKalle Valo { 3957e705c121SKalle Valo int ret; 3958e705c121SKalle Valo 3959e705c121SKalle Valo mutex_lock(&mvm->mutex); 3960e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 3961e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 3962e705c121SKalle Valo 3963e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 3964e705c121SKalle Valo if (ret) { 3965e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 3966e705c121SKalle Valo goto out_reassign; 3967e705c121SKalle Valo } 3968e705c121SKalle Valo 3969e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 3970e705c121SKalle Valo true); 3971e705c121SKalle Valo if (ret) { 3972e705c121SKalle Valo IWL_ERR(mvm, 3973e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 3974e705c121SKalle Valo goto out_remove; 3975e705c121SKalle Valo } 3976e705c121SKalle Valo 3977e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 3978e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 3979e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3980e705c121SKalle Valo 3981e705c121SKalle Valo goto out; 3982e705c121SKalle Valo 3983e705c121SKalle Valo out_remove: 3984e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 3985e705c121SKalle Valo 3986e705c121SKalle Valo out_reassign: 3987e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 3988e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 3989e705c121SKalle Valo goto out_restart; 3990e705c121SKalle Valo } 3991e705c121SKalle Valo 3992e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 3993e705c121SKalle Valo true)) { 3994e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 3995e705c121SKalle Valo goto out_restart; 3996e705c121SKalle Valo } 3997e705c121SKalle Valo 3998e705c121SKalle Valo goto out; 3999e705c121SKalle Valo 4000e705c121SKalle Valo out_restart: 4001e705c121SKalle Valo /* things keep failing, better restart the hw */ 4002e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4003e705c121SKalle Valo 4004e705c121SKalle Valo out: 4005e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4006e705c121SKalle Valo 4007e705c121SKalle Valo return ret; 4008e705c121SKalle Valo } 4009e705c121SKalle Valo 4010e705c121SKalle Valo static int 4011e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 4012e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 4013e705c121SKalle Valo { 4014e705c121SKalle Valo int ret; 4015e705c121SKalle Valo 4016e705c121SKalle Valo mutex_lock(&mvm->mutex); 4017e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 4018e705c121SKalle Valo 4019e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 4020e705c121SKalle Valo true); 4021e705c121SKalle Valo if (ret) { 4022e705c121SKalle Valo IWL_ERR(mvm, 4023e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 4024e705c121SKalle Valo goto out_reassign; 4025e705c121SKalle Valo } 4026e705c121SKalle Valo 4027e705c121SKalle Valo goto out; 4028e705c121SKalle Valo 4029e705c121SKalle Valo out_reassign: 4030e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 4031e705c121SKalle Valo true)) { 4032e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 4033e705c121SKalle Valo goto out_restart; 4034e705c121SKalle Valo } 4035e705c121SKalle Valo 4036e705c121SKalle Valo goto out; 4037e705c121SKalle Valo 4038e705c121SKalle Valo out_restart: 4039e705c121SKalle Valo /* things keep failing, better restart the hw */ 4040e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 4041e705c121SKalle Valo 4042e705c121SKalle Valo out: 4043e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4044e705c121SKalle Valo 4045e705c121SKalle Valo return ret; 4046e705c121SKalle Valo } 4047e705c121SKalle Valo 4048e705c121SKalle Valo static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 4049e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 4050e705c121SKalle Valo int n_vifs, 4051e705c121SKalle Valo enum ieee80211_chanctx_switch_mode mode) 4052e705c121SKalle Valo { 4053e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4054e705c121SKalle Valo int ret; 4055e705c121SKalle Valo 4056e705c121SKalle Valo /* we only support a single-vif right now */ 4057e705c121SKalle Valo if (n_vifs > 1) 4058e705c121SKalle Valo return -EOPNOTSUPP; 4059e705c121SKalle Valo 4060e705c121SKalle Valo switch (mode) { 4061e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 4062e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); 4063e705c121SKalle Valo break; 4064e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 4065e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); 4066e705c121SKalle Valo break; 4067e705c121SKalle Valo default: 4068e705c121SKalle Valo ret = -EOPNOTSUPP; 4069e705c121SKalle Valo break; 4070e705c121SKalle Valo } 4071e705c121SKalle Valo 4072e705c121SKalle Valo return ret; 4073e705c121SKalle Valo } 4074e705c121SKalle Valo 40752f0282dbSJohannes Berg static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw) 40762f0282dbSJohannes Berg { 40772f0282dbSJohannes Berg struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 40782f0282dbSJohannes Berg 40792f0282dbSJohannes Berg return mvm->ibss_manager; 40802f0282dbSJohannes Berg } 40812f0282dbSJohannes Berg 4082e705c121SKalle Valo static int iwl_mvm_set_tim(struct ieee80211_hw *hw, 4083e705c121SKalle Valo struct ieee80211_sta *sta, 4084e705c121SKalle Valo bool set) 4085e705c121SKalle Valo { 4086e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4087e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 4088e705c121SKalle Valo 4089e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 4090e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 4091e705c121SKalle Valo return -EINVAL; 4092e705c121SKalle Valo } 4093e705c121SKalle Valo 4094e705c121SKalle Valo return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); 4095e705c121SKalle Valo } 4096e705c121SKalle Valo 4097e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 4098e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 4099e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 4100e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 4101e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 4102e705c121SKalle Valo }; 4103e705c121SKalle Valo 4104e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 4105e705c121SKalle Valo struct ieee80211_vif *vif, 4106e705c121SKalle Valo void *data, int len) 4107e705c121SKalle Valo { 4108e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 4109e705c121SKalle Valo int err; 4110e705c121SKalle Valo u32 noa_duration; 4111e705c121SKalle Valo 4112fceb6435SJohannes Berg err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy, 4113fceb6435SJohannes Berg NULL); 4114e705c121SKalle Valo if (err) 4115e705c121SKalle Valo return err; 4116e705c121SKalle Valo 4117e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 4118e705c121SKalle Valo return -EINVAL; 4119e705c121SKalle Valo 4120e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 4121e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 4122e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 4123e705c121SKalle Valo !vif->bss_conf.enable_beacon || 4124e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 4125e705c121SKalle Valo return -EINVAL; 4126e705c121SKalle Valo 4127e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 4128e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 4129e705c121SKalle Valo return -EINVAL; 4130e705c121SKalle Valo 4131e705c121SKalle Valo mvm->noa_duration = noa_duration; 4132e705c121SKalle Valo mvm->noa_vif = vif; 4133e705c121SKalle Valo 413422b21041SShaul Triebitz return iwl_mvm_update_quotas(mvm, true, NULL); 4135e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 4136e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 4137e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 4138e705c121SKalle Valo !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || 4139e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 4140e705c121SKalle Valo return -EINVAL; 4141e705c121SKalle Valo 4142e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 4143e705c121SKalle Valo return iwl_mvm_enable_beacon_filter(mvm, vif, 0); 4144e705c121SKalle Valo return iwl_mvm_disable_beacon_filter(mvm, vif, 0); 4145e705c121SKalle Valo } 4146e705c121SKalle Valo 4147e705c121SKalle Valo return -EOPNOTSUPP; 4148e705c121SKalle Valo } 4149e705c121SKalle Valo 4150e705c121SKalle Valo static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 4151e705c121SKalle Valo struct ieee80211_vif *vif, 4152e705c121SKalle Valo void *data, int len) 4153e705c121SKalle Valo { 4154e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4155e705c121SKalle Valo int err; 4156e705c121SKalle Valo 4157e705c121SKalle Valo mutex_lock(&mvm->mutex); 4158e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 4159e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4160e705c121SKalle Valo 4161e705c121SKalle Valo return err; 4162e705c121SKalle Valo } 4163e705c121SKalle Valo #endif 4164e705c121SKalle Valo 4165e705c121SKalle Valo static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, 4166e705c121SKalle Valo struct ieee80211_vif *vif, 4167e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4168e705c121SKalle Valo { 4169e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 4170e705c121SKalle Valo * starting its own channel switch timer, so that we can call 4171e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 4172e705c121SKalle Valo * (which is when the absence time event starts). 4173e705c121SKalle Valo */ 4174e705c121SKalle Valo 4175e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 4176e705c121SKalle Valo "dummy channel switch op\n"); 4177e705c121SKalle Valo } 4178e705c121SKalle Valo 4179e705c121SKalle Valo static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 4180e705c121SKalle Valo struct ieee80211_vif *vif, 4181e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 4182e705c121SKalle Valo { 4183e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4184e705c121SKalle Valo struct ieee80211_vif *csa_vif; 4185e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4186e705c121SKalle Valo u32 apply_time; 4187e705c121SKalle Valo int ret; 4188e705c121SKalle Valo 4189e705c121SKalle Valo mutex_lock(&mvm->mutex); 4190e705c121SKalle Valo 4191e705c121SKalle Valo mvmvif->csa_failed = false; 4192e705c121SKalle Valo 4193e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 4194e705c121SKalle Valo chsw->chandef.center_freq1); 4195e705c121SKalle Valo 41967174beb6SJohannes Berg iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt, 41977174beb6SJohannes Berg ieee80211_vif_to_wdev(vif), 41987174beb6SJohannes Berg FW_DBG_TRIGGER_CHANNEL_SWITCH); 4199e705c121SKalle Valo 4200e705c121SKalle Valo switch (vif->type) { 4201e705c121SKalle Valo case NL80211_IFTYPE_AP: 4202e705c121SKalle Valo csa_vif = 4203e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 4204e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4205e705c121SKalle Valo if (WARN_ONCE(csa_vif && csa_vif->csa_active, 4206e705c121SKalle Valo "Another CSA is already in progress")) { 4207e705c121SKalle Valo ret = -EBUSY; 4208e705c121SKalle Valo goto out_unlock; 4209e705c121SKalle Valo } 4210e705c121SKalle Valo 4211d3a108a4SAndrei Otcheretianski /* we still didn't unblock tx. prevent new CS meanwhile */ 4212d3a108a4SAndrei Otcheretianski if (rcu_dereference_protected(mvm->csa_tx_blocked_vif, 4213d3a108a4SAndrei Otcheretianski lockdep_is_held(&mvm->mutex))) { 4214d3a108a4SAndrei Otcheretianski ret = -EBUSY; 4215d3a108a4SAndrei Otcheretianski goto out_unlock; 4216d3a108a4SAndrei Otcheretianski } 4217d3a108a4SAndrei Otcheretianski 4218e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 4219e705c121SKalle Valo 4220e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 4221e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 4222e705c121SKalle Valo ret = -EBUSY; 4223e705c121SKalle Valo goto out_unlock; 4224e705c121SKalle Valo } 4225e705c121SKalle Valo 4226d3a108a4SAndrei Otcheretianski mvmvif->csa_target_freq = chsw->chandef.chan->center_freq; 4227d3a108a4SAndrei Otcheretianski 4228e705c121SKalle Valo break; 4229e705c121SKalle Valo case NL80211_IFTYPE_STATION: 4230e705c121SKalle Valo /* Schedule the time event to a bit before beacon 1, 4231e705c121SKalle Valo * to make sure we're in the new channel when the 4232f5d8f50fSIlan Peer * GO/AP arrives. In case count <= 1 immediately schedule the 4233f5d8f50fSIlan Peer * TE (this might result with some packet loss or connection 4234f5d8f50fSIlan Peer * loss). 4235e705c121SKalle Valo */ 4236f5d8f50fSIlan Peer if (chsw->count <= 1) 4237f5d8f50fSIlan Peer apply_time = 0; 4238f5d8f50fSIlan Peer else 4239e705c121SKalle Valo apply_time = chsw->device_timestamp + 4240e705c121SKalle Valo ((vif->bss_conf.beacon_int * (chsw->count - 1) - 4241e705c121SKalle Valo IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 4242e705c121SKalle Valo 4243e705c121SKalle Valo if (chsw->block_tx) 4244e705c121SKalle Valo iwl_mvm_csa_client_absent(mvm, vif); 4245e705c121SKalle Valo 4246e705c121SKalle Valo iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 4247e705c121SKalle Valo apply_time); 4248e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 4249e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 4250e705c121SKalle Valo if (ret) 4251e705c121SKalle Valo goto out_unlock; 4252e705c121SKalle Valo } 4253e705c121SKalle Valo 4254e705c121SKalle Valo break; 4255e705c121SKalle Valo default: 4256e705c121SKalle Valo break; 4257e705c121SKalle Valo } 4258e705c121SKalle Valo 4259e705c121SKalle Valo mvmvif->ps_disabled = true; 4260e705c121SKalle Valo 4261e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 4262e705c121SKalle Valo if (ret) 4263e705c121SKalle Valo goto out_unlock; 4264e705c121SKalle Valo 4265e705c121SKalle Valo /* we won't be on this channel any longer */ 4266e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 4267e705c121SKalle Valo 4268e705c121SKalle Valo out_unlock: 4269e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4270e705c121SKalle Valo 4271e705c121SKalle Valo return ret; 4272e705c121SKalle Valo } 4273e705c121SKalle Valo 4274e705c121SKalle Valo static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 4275e705c121SKalle Valo struct ieee80211_vif *vif) 4276e705c121SKalle Valo { 4277e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4278e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4279e705c121SKalle Valo int ret; 4280e705c121SKalle Valo 4281e705c121SKalle Valo mutex_lock(&mvm->mutex); 4282e705c121SKalle Valo 4283e705c121SKalle Valo if (mvmvif->csa_failed) { 4284e705c121SKalle Valo mvmvif->csa_failed = false; 4285e705c121SKalle Valo ret = -EIO; 4286e705c121SKalle Valo goto out_unlock; 4287e705c121SKalle Valo } 4288e705c121SKalle Valo 4289e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION) { 4290e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 4291e705c121SKalle Valo 429219125cb0SAndrei Otcheretianski mvmvif->csa_bcn_pending = false; 4293e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_staid_protected(mvm, 4294e705c121SKalle Valo mvmvif->ap_sta_id); 4295e705c121SKalle Valo 4296e705c121SKalle Valo if (WARN_ON(!mvmsta)) { 4297e705c121SKalle Valo ret = -EIO; 4298e705c121SKalle Valo goto out_unlock; 4299e705c121SKalle Valo } 4300e705c121SKalle Valo 4301e705c121SKalle Valo iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 4302e705c121SKalle Valo 4303e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 4304e705c121SKalle Valo 4305e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 4306e705c121SKalle Valo if (ret) 4307e705c121SKalle Valo goto out_unlock; 4308e705c121SKalle Valo 4309e705c121SKalle Valo iwl_mvm_stop_session_protection(mvm, vif); 4310e705c121SKalle Valo } 4311e705c121SKalle Valo 4312e705c121SKalle Valo mvmvif->ps_disabled = false; 4313e705c121SKalle Valo 4314e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 4315e705c121SKalle Valo 4316e705c121SKalle Valo out_unlock: 4317e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4318e705c121SKalle Valo 4319e705c121SKalle Valo return ret; 4320e705c121SKalle Valo } 4321e705c121SKalle Valo 43226110d9e5SDavid Spinadel static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop) 43236110d9e5SDavid Spinadel { 4324435d0827SSara Sharon int i; 4325435d0827SSara Sharon 432606195639SSara Sharon if (!iwl_mvm_has_new_tx_api(mvm)) { 4327309c4848SLuca Coelho if (drop) { 4328309c4848SLuca Coelho mutex_lock(&mvm->mutex); 43296110d9e5SDavid Spinadel iwl_mvm_flush_tx_path(mvm, 4330435d0827SSara Sharon iwl_mvm_flushable_queues(mvm) & queues, 0); 4331309c4848SLuca Coelho mutex_unlock(&mvm->mutex); 4332309c4848SLuca Coelho } else { 4333435d0827SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, queues); 4334309c4848SLuca Coelho } 4335435d0827SSara Sharon return; 4336435d0827SSara Sharon } 43376110d9e5SDavid Spinadel 43386110d9e5SDavid Spinadel mutex_lock(&mvm->mutex); 43396110d9e5SDavid Spinadel for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { 4340435d0827SSara Sharon struct ieee80211_sta *sta; 4341435d0827SSara Sharon 4342435d0827SSara Sharon sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 43436110d9e5SDavid Spinadel lockdep_is_held(&mvm->mutex)); 43446110d9e5SDavid Spinadel if (IS_ERR_OR_NULL(sta)) 43456110d9e5SDavid Spinadel continue; 43466110d9e5SDavid Spinadel 434706195639SSara Sharon if (drop) 434806195639SSara Sharon iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0); 434906195639SSara Sharon else 43506110d9e5SDavid Spinadel iwl_mvm_wait_sta_queues_empty(mvm, 43516110d9e5SDavid Spinadel iwl_mvm_sta_from_mac80211(sta)); 43526110d9e5SDavid Spinadel } 43536110d9e5SDavid Spinadel mutex_unlock(&mvm->mutex); 43546110d9e5SDavid Spinadel } 43556110d9e5SDavid Spinadel 4356e705c121SKalle Valo static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, 4357e705c121SKalle Valo struct ieee80211_vif *vif, u32 queues, bool drop) 4358e705c121SKalle Valo { 4359e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4360e705c121SKalle Valo struct iwl_mvm_vif *mvmvif; 4361e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 4362e705c121SKalle Valo struct ieee80211_sta *sta; 4363e705c121SKalle Valo int i; 4364e705c121SKalle Valo u32 msk = 0; 4365e705c121SKalle Valo 43666110d9e5SDavid Spinadel if (!vif) { 43676110d9e5SDavid Spinadel iwl_mvm_flush_no_vif(mvm, queues, drop); 43686110d9e5SDavid Spinadel return; 43696110d9e5SDavid Spinadel } 43706110d9e5SDavid Spinadel 43716110d9e5SDavid Spinadel if (vif->type != NL80211_IFTYPE_STATION) 4372e705c121SKalle Valo return; 4373e705c121SKalle Valo 437424afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 437524afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 437624afba76SLiad Kaufman 4377e705c121SKalle Valo mutex_lock(&mvm->mutex); 4378e705c121SKalle Valo mvmvif = iwl_mvm_vif_from_mac80211(vif); 4379e705c121SKalle Valo 4380e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 43810ae98812SSara Sharon for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { 4382e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 4383e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 4384e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 4385e705c121SKalle Valo continue; 4386e705c121SKalle Valo 4387e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 4388e705c121SKalle Valo if (mvmsta->vif != vif) 4389e705c121SKalle Valo continue; 4390e705c121SKalle Valo 4391e705c121SKalle Valo /* make sure only TDLS peers or the AP are flushed */ 4392e705c121SKalle Valo WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); 4393e705c121SKalle Valo 4394d49394a1SSara Sharon if (drop) { 4395d49394a1SSara Sharon if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0)) 4396d49394a1SSara Sharon IWL_ERR(mvm, "flush request fail\n"); 4397d49394a1SSara Sharon } else { 4398e705c121SKalle Valo msk |= mvmsta->tfd_queue_msk; 4399d6d517b7SSara Sharon if (iwl_mvm_has_new_tx_api(mvm)) 4400d6d517b7SSara Sharon iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); 4401e705c121SKalle Valo } 4402d49394a1SSara Sharon } 4403e705c121SKalle Valo 4404e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4405e705c121SKalle Valo 4406e705c121SKalle Valo /* this can take a while, and we may need/want other operations 4407e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 4408e705c121SKalle Valo */ 4409d6d517b7SSara Sharon if (!drop && !iwl_mvm_has_new_tx_api(mvm)) 4410a1a57877SSara Sharon iwl_trans_wait_tx_queues_empty(mvm->trans, msk); 4411e705c121SKalle Valo } 4412e705c121SKalle Valo 4413e705c121SKalle Valo static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 4414e705c121SKalle Valo struct survey_info *survey) 4415e705c121SKalle Valo { 4416e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4417e705c121SKalle Valo int ret; 4418e705c121SKalle Valo 4419e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 4420e705c121SKalle Valo 4421e705c121SKalle Valo /* only support global statistics right now */ 4422e705c121SKalle Valo if (idx != 0) 4423e705c121SKalle Valo return -ENOENT; 4424e705c121SKalle Valo 4425280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 4426e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 4427e705c121SKalle Valo return -ENOENT; 4428e705c121SKalle Valo 4429e705c121SKalle Valo mutex_lock(&mvm->mutex); 4430e705c121SKalle Valo 4431aab6930dSJohannes Berg if (iwl_mvm_firmware_running(mvm)) { 4432e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 4433e705c121SKalle Valo if (ret) 4434e705c121SKalle Valo goto out; 4435e705c121SKalle Valo } 4436e705c121SKalle Valo 4437e705c121SKalle Valo survey->filled = SURVEY_INFO_TIME | 4438e705c121SKalle Valo SURVEY_INFO_TIME_RX | 4439e705c121SKalle Valo SURVEY_INFO_TIME_TX | 4440e705c121SKalle Valo SURVEY_INFO_TIME_SCAN; 4441e705c121SKalle Valo survey->time = mvm->accu_radio_stats.on_time_rf + 4442e705c121SKalle Valo mvm->radio_stats.on_time_rf; 4443e705c121SKalle Valo do_div(survey->time, USEC_PER_MSEC); 4444e705c121SKalle Valo 4445e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 4446e705c121SKalle Valo mvm->radio_stats.rx_time; 4447e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 4448e705c121SKalle Valo 4449e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 4450e705c121SKalle Valo mvm->radio_stats.tx_time; 4451e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 4452e705c121SKalle Valo 4453e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 4454e705c121SKalle Valo mvm->radio_stats.on_time_scan; 4455e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 4456e705c121SKalle Valo 4457e705c121SKalle Valo ret = 0; 4458e705c121SKalle Valo out: 4459e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4460e705c121SKalle Valo return ret; 4461e705c121SKalle Valo } 4462e705c121SKalle Valo 4463e705c121SKalle Valo static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 4464e705c121SKalle Valo struct ieee80211_vif *vif, 4465e705c121SKalle Valo struct ieee80211_sta *sta, 4466e705c121SKalle Valo struct station_info *sinfo) 4467e705c121SKalle Valo { 4468e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4469e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 4470e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 4471e705c121SKalle Valo 4472988b5968SSara Sharon if (mvmsta->avg_energy) { 4473988b5968SSara Sharon sinfo->signal_avg = mvmsta->avg_energy; 447422d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG); 4475988b5968SSara Sharon } 4476988b5968SSara Sharon 4477280a3efaSJohannes Berg if (!fw_has_capa(&mvm->fw->ucode_capa, 4478e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 4479e705c121SKalle Valo return; 4480e705c121SKalle Valo 4481e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 4482e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 4483e705c121SKalle Valo return; 4484e705c121SKalle Valo 4485e705c121SKalle Valo if (!vif->bss_conf.assoc) 4486e705c121SKalle Valo return; 4487e705c121SKalle Valo 4488e705c121SKalle Valo mutex_lock(&mvm->mutex); 4489e705c121SKalle Valo 4490e705c121SKalle Valo if (mvmvif->ap_sta_id != mvmsta->sta_id) 4491e705c121SKalle Valo goto unlock; 4492e705c121SKalle Valo 4493e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 4494e705c121SKalle Valo goto unlock; 4495e705c121SKalle Valo 4496e705c121SKalle Valo sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + 4497e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons; 449822d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); 4499e705c121SKalle Valo if (mvmvif->beacon_stats.avg_signal) { 4500e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 4501e705c121SKalle Valo sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; 450222d0d2faSOmer Efrat sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 4503e705c121SKalle Valo } 4504e705c121SKalle Valo unlock: 4505e705c121SKalle Valo mutex_unlock(&mvm->mutex); 4506e705c121SKalle Valo } 4507e705c121SKalle Valo 4508e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 4509e705c121SKalle Valo struct ieee80211_vif *vif, 4510e705c121SKalle Valo const struct ieee80211_event *event) 4511e705c121SKalle Valo { 45124c324a51SLuca Coelho #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \ 4513e705c121SKalle Valo do { \ 45144c324a51SLuca Coelho if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \ 4515e705c121SKalle Valo break; \ 45167174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \ 4517e705c121SKalle Valo } while (0) 4518e705c121SKalle Valo 4519e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 4520e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 4521e705c121SKalle Valo 45226c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 45236c042d75SSara Sharon FW_DBG_TRIGGER_MLME); 45246c042d75SSara Sharon if (!trig) 4525e705c121SKalle Valo return; 4526e705c121SKalle Valo 4527e705c121SKalle Valo trig_mlme = (void *)trig->data; 4528e705c121SKalle Valo 4529e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 4530e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 45314c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_denied, 4532e705c121SKalle Valo "DENIED ASSOC: reason %d", 4533e705c121SKalle Valo event->u.mlme.reason); 4534e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 45354c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_assoc_timeout, 4536e705c121SKalle Valo "ASSOC TIMEOUT"); 4537e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 4538e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 45394c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_denied, 4540e705c121SKalle Valo "DENIED AUTH: reason %d", 4541e705c121SKalle Valo event->u.mlme.reason); 4542e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 45434c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_auth_timeout, 4544e705c121SKalle Valo "AUTH TIMEOUT"); 4545e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 45464c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_rx_deauth, 4547e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 4548e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 45494c324a51SLuca Coelho CHECK_MLME_TRIGGER(stop_tx_deauth, 4550e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 4551e705c121SKalle Valo } 4552e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 4553e705c121SKalle Valo } 4554e705c121SKalle Valo 4555e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 4556e705c121SKalle Valo struct ieee80211_vif *vif, 4557e705c121SKalle Valo const struct ieee80211_event *event) 4558e705c121SKalle Valo { 4559e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 4560e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 4561e705c121SKalle Valo 45626c042d75SSara Sharon trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif), 45636c042d75SSara Sharon FW_DBG_TRIGGER_BA); 45646c042d75SSara Sharon if (!trig) 4565e705c121SKalle Valo return; 4566e705c121SKalle Valo 4567e705c121SKalle Valo ba_trig = (void *)trig->data; 4568e705c121SKalle Valo 4569e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 4570e705c121SKalle Valo return; 4571e705c121SKalle Valo 45727174beb6SJohannes Berg iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 4573e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 4574e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 4575e705c121SKalle Valo event->u.ba.ssn); 4576e705c121SKalle Valo } 4577e705c121SKalle Valo 4578e705c121SKalle Valo static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 4579e705c121SKalle Valo struct ieee80211_vif *vif, 4580e705c121SKalle Valo const struct ieee80211_event *event) 4581e705c121SKalle Valo { 4582e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4583e705c121SKalle Valo 4584e705c121SKalle Valo switch (event->type) { 4585e705c121SKalle Valo case MLME_EVENT: 4586e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 4587e705c121SKalle Valo break; 4588e705c121SKalle Valo case BAR_RX_EVENT: 4589e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 4590e705c121SKalle Valo break; 4591e705c121SKalle Valo case BA_FRAME_TIMEOUT: 4592528a542aSEmmanuel Grumbach iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta, 4593528a542aSEmmanuel Grumbach event->u.ba.tid); 4594e705c121SKalle Valo break; 4595e705c121SKalle Valo default: 4596e705c121SKalle Valo break; 4597e705c121SKalle Valo } 4598e705c121SKalle Valo } 4599e705c121SKalle Valo 4600d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 4601d0ff5d22SSara Sharon struct iwl_mvm_internal_rxq_notif *notif, 4602d0ff5d22SSara Sharon u32 size) 46030636b938SSara Sharon { 46040636b938SSara Sharon u32 qmask = BIT(mvm->trans->num_rx_queues) - 1; 46050636b938SSara Sharon int ret; 46060636b938SSara Sharon 46070636b938SSara Sharon lockdep_assert_held(&mvm->mutex); 46080636b938SSara Sharon 4609cb8550e1SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 46100636b938SSara Sharon return; 46110636b938SSara Sharon 4612d0ff5d22SSara Sharon notif->cookie = mvm->queue_sync_cookie; 46130636b938SSara Sharon 4614d0ff5d22SSara Sharon if (notif->sync) 4615d0ff5d22SSara Sharon atomic_set(&mvm->queue_sync_counter, 4616d0ff5d22SSara Sharon mvm->trans->num_rx_queues); 4617d0ff5d22SSara Sharon 4618d0ff5d22SSara Sharon ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size); 46190636b938SSara Sharon if (ret) { 46200636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 46210636b938SSara Sharon goto out; 46220636b938SSara Sharon } 4623d0ff5d22SSara Sharon 46246ad04359SJohannes Berg if (notif->sync) { 46253a732c65SSara Sharon ret = wait_event_timeout(mvm->rx_sync_waitq, 46266ad04359SJohannes Berg atomic_read(&mvm->queue_sync_counter) == 0 || 46276ad04359SJohannes Berg iwl_mvm_is_radio_killed(mvm), 46280636b938SSara Sharon HZ); 46296ad04359SJohannes Berg WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm)); 46306ad04359SJohannes Berg } 46310636b938SSara Sharon 46320636b938SSara Sharon out: 46330636b938SSara Sharon atomic_set(&mvm->queue_sync_counter, 0); 46340636b938SSara Sharon mvm->queue_sync_cookie++; 46350636b938SSara Sharon } 46360636b938SSara Sharon 46370636b938SSara Sharon static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 46380636b938SSara Sharon { 46390636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4640d0ff5d22SSara Sharon struct iwl_mvm_internal_rxq_notif data = { 4641d0ff5d22SSara Sharon .type = IWL_MVM_RXQ_EMPTY, 4642d0ff5d22SSara Sharon .sync = 1, 4643d0ff5d22SSara Sharon }; 46440636b938SSara Sharon 46450636b938SSara Sharon mutex_lock(&mvm->mutex); 4646d0ff5d22SSara Sharon iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data)); 46470636b938SSara Sharon mutex_unlock(&mvm->mutex); 46480636b938SSara Sharon } 46490636b938SSara Sharon 4650e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 4651e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 4652e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 4653e705c121SKalle Valo .start = iwl_mvm_mac_start, 4654e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 4655e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 4656e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 4657e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 4658e705c121SKalle Valo .config = iwl_mvm_mac_config, 4659e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 4660e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 4661e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 4662e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 4663e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 4664e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 4665e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 4666e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 4667e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 4668e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 4669e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 4670e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 4671e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 4672e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 4673e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 4674e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 4675e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 4676e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 4677e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 4678e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 4679e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 4680e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 4681e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 4682e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 4683e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 4684e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 4685e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 4686e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 4687e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 4688e705c121SKalle Valo 4689e705c121SKalle Valo .start_ap = iwl_mvm_start_ap_ibss, 4690e705c121SKalle Valo .stop_ap = iwl_mvm_stop_ap_ibss, 4691e705c121SKalle Valo .join_ibss = iwl_mvm_start_ap_ibss, 4692e705c121SKalle Valo .leave_ibss = iwl_mvm_stop_ap_ibss, 4693e705c121SKalle Valo 46942f0282dbSJohannes Berg .tx_last_beacon = iwl_mvm_tx_last_beacon, 46952f0282dbSJohannes Berg 4696e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 4697e705c121SKalle Valo 4698e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 4699e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 4700e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 4701e705c121SKalle Valo 4702e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 4703e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 4704e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 4705e705c121SKalle Valo 4706e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 4707e705c121SKalle Valo 47080636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 47090636b938SSara Sharon 4710e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 4711e705c121SKalle Valo 4712e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 4713e705c121SKalle Valo /* look at d3.c */ 4714e705c121SKalle Valo .suspend = iwl_mvm_suspend, 4715e705c121SKalle Valo .resume = iwl_mvm_resume, 4716e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 4717e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 4718e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 4719e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 4720e705c121SKalle Valo #endif 4721e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 4722e705c121SKalle Valo #endif 4723e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 4724e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 4725177a11cfSGregory Greenman #ifdef CONFIG_IWLWIFI_DEBUGFS 4726177a11cfSGregory Greenman .sta_add_debugfs = iwl_mvm_sta_add_debugfs, 4727177a11cfSGregory Greenman #endif 4728e705c121SKalle Valo }; 4729