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. 9e705c121SKalle Valo * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 10f92659a1SSara Sharon * Copyright(c) 2016 Intel Deutschland GmbH 11e705c121SKalle Valo * 12e705c121SKalle Valo * This program is free software; you can redistribute it and/or modify 13e705c121SKalle Valo * it under the terms of version 2 of the GNU General Public License as 14e705c121SKalle Valo * published by the Free Software Foundation. 15e705c121SKalle Valo * 16e705c121SKalle Valo * This program is distributed in the hope that it will be useful, but 17e705c121SKalle Valo * WITHOUT ANY WARRANTY; without even the implied warranty of 18e705c121SKalle Valo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19e705c121SKalle Valo * General Public License for more details. 20e705c121SKalle Valo * 21e705c121SKalle Valo * You should have received a copy of the GNU General Public License 22e705c121SKalle Valo * along with this program; if not, write to the Free Software 23e705c121SKalle Valo * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 24e705c121SKalle Valo * USA 25e705c121SKalle Valo * 26e705c121SKalle Valo * The full GNU General Public License is included in this distribution 27e705c121SKalle Valo * in the file called COPYING. 28e705c121SKalle Valo * 29e705c121SKalle Valo * Contact Information: 30cb2f8277SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 31e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 32e705c121SKalle Valo * 33e705c121SKalle Valo * BSD LICENSE 34e705c121SKalle Valo * 35e705c121SKalle Valo * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 36e705c121SKalle Valo * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH 37e705c121SKalle Valo * All rights reserved. 38e705c121SKalle Valo * 39e705c121SKalle Valo * Redistribution and use in source and binary forms, with or without 40e705c121SKalle Valo * modification, are permitted provided that the following conditions 41e705c121SKalle Valo * are met: 42e705c121SKalle Valo * 43e705c121SKalle Valo * * Redistributions of source code must retain the above copyright 44e705c121SKalle Valo * notice, this list of conditions and the following disclaimer. 45e705c121SKalle Valo * * Redistributions in binary form must reproduce the above copyright 46e705c121SKalle Valo * notice, this list of conditions and the following disclaimer in 47e705c121SKalle Valo * the documentation and/or other materials provided with the 48e705c121SKalle Valo * distribution. 49e705c121SKalle Valo * * Neither the name Intel Corporation nor the names of its 50e705c121SKalle Valo * contributors may be used to endorse or promote products derived 51e705c121SKalle Valo * from this software without specific prior written permission. 52e705c121SKalle Valo * 53e705c121SKalle Valo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 54e705c121SKalle Valo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 55e705c121SKalle Valo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 56e705c121SKalle Valo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 57e705c121SKalle Valo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 58e705c121SKalle Valo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 59e705c121SKalle Valo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 60e705c121SKalle Valo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 61e705c121SKalle Valo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 62e705c121SKalle Valo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 63e705c121SKalle Valo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 64e705c121SKalle Valo * 65e705c121SKalle Valo *****************************************************************************/ 66e705c121SKalle Valo #include <linux/kernel.h> 67e705c121SKalle Valo #include <linux/slab.h> 68e705c121SKalle Valo #include <linux/skbuff.h> 69e705c121SKalle Valo #include <linux/netdevice.h> 70e705c121SKalle Valo #include <linux/etherdevice.h> 71e705c121SKalle Valo #include <linux/ip.h> 72e705c121SKalle Valo #include <linux/if_arp.h> 732f89a5d7SGolan Ben-Ami #include <linux/time.h> 74e705c121SKalle Valo #include <net/mac80211.h> 75e705c121SKalle Valo #include <net/ieee80211_radiotap.h> 76e705c121SKalle Valo #include <net/tcp.h> 77e705c121SKalle Valo 78e705c121SKalle Valo #include "iwl-op-mode.h" 79e705c121SKalle Valo #include "iwl-io.h" 80e705c121SKalle Valo #include "mvm.h" 81e705c121SKalle Valo #include "sta.h" 82e705c121SKalle Valo #include "time-event.h" 83e705c121SKalle Valo #include "iwl-eeprom-parse.h" 84e705c121SKalle Valo #include "iwl-phy-db.h" 85e705c121SKalle Valo #include "testmode.h" 86e705c121SKalle Valo #include "iwl-fw-error-dump.h" 87e705c121SKalle Valo #include "iwl-prph.h" 88e705c121SKalle Valo #include "iwl-nvm-parse.h" 892f89a5d7SGolan Ben-Ami #include "fw-dbg.h" 90e705c121SKalle Valo 91e705c121SKalle Valo static const struct ieee80211_iface_limit iwl_mvm_limits[] = { 92e705c121SKalle Valo { 93e705c121SKalle Valo .max = 1, 94e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_STATION), 95e705c121SKalle Valo }, 96e705c121SKalle Valo { 97e705c121SKalle Valo .max = 1, 98e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_AP) | 99e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 100e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO), 101e705c121SKalle Valo }, 102e705c121SKalle Valo { 103e705c121SKalle Valo .max = 1, 104e705c121SKalle Valo .types = BIT(NL80211_IFTYPE_P2P_DEVICE), 105e705c121SKalle Valo }, 106e705c121SKalle Valo }; 107e705c121SKalle Valo 108e705c121SKalle Valo static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = { 109e705c121SKalle Valo { 110e705c121SKalle Valo .num_different_channels = 2, 111e705c121SKalle Valo .max_interfaces = 3, 112e705c121SKalle Valo .limits = iwl_mvm_limits, 113e705c121SKalle Valo .n_limits = ARRAY_SIZE(iwl_mvm_limits), 114e705c121SKalle Valo }, 115e705c121SKalle Valo }; 116e705c121SKalle Valo 117e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 118e705c121SKalle Valo static const struct nl80211_wowlan_tcp_data_token_feature 119e705c121SKalle Valo iwl_mvm_wowlan_tcp_token_feature = { 120e705c121SKalle Valo .min_len = 0, 121e705c121SKalle Valo .max_len = 255, 122e705c121SKalle Valo .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS, 123e705c121SKalle Valo }; 124e705c121SKalle Valo 125e705c121SKalle Valo static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = { 126e705c121SKalle Valo .tok = &iwl_mvm_wowlan_tcp_token_feature, 127e705c121SKalle Valo .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN - 128e705c121SKalle Valo sizeof(struct ethhdr) - 129e705c121SKalle Valo sizeof(struct iphdr) - 130e705c121SKalle Valo sizeof(struct tcphdr), 131e705c121SKalle Valo .data_interval_max = 65535, /* __le16 in API */ 132e705c121SKalle Valo .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN - 133e705c121SKalle Valo sizeof(struct ethhdr) - 134e705c121SKalle Valo sizeof(struct iphdr) - 135e705c121SKalle Valo sizeof(struct tcphdr), 136e705c121SKalle Valo .seq = true, 137e705c121SKalle Valo }; 138e705c121SKalle Valo #endif 139e705c121SKalle Valo 140e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 141e705c121SKalle Valo /* 142e705c121SKalle Valo * Use the reserved field to indicate magic values. 143e705c121SKalle Valo * these values will only be used internally by the driver, 144e705c121SKalle Valo * and won't make it to the fw (reserved will be 0). 145e705c121SKalle Valo * BC_FILTER_MAGIC_IP - configure the val of this attribute to 146e705c121SKalle Valo * be the vif's ip address. in case there is not a single 147e705c121SKalle Valo * ip address (0, or more than 1), this attribute will 148e705c121SKalle Valo * be skipped. 149e705c121SKalle Valo * BC_FILTER_MAGIC_MAC - set the val of this attribute to 150e705c121SKalle Valo * the LSB bytes of the vif's mac address 151e705c121SKalle Valo */ 152e705c121SKalle Valo enum { 153e705c121SKalle Valo BC_FILTER_MAGIC_NONE = 0, 154e705c121SKalle Valo BC_FILTER_MAGIC_IP, 155e705c121SKalle Valo BC_FILTER_MAGIC_MAC, 156e705c121SKalle Valo }; 157e705c121SKalle Valo 158e705c121SKalle Valo static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = { 159e705c121SKalle Valo { 160e705c121SKalle Valo /* arp */ 161e705c121SKalle Valo .discard = 0, 162e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_ALL, 163e705c121SKalle Valo .attrs = { 164e705c121SKalle Valo { 165e705c121SKalle Valo /* frame type - arp, hw type - ethernet */ 166e705c121SKalle Valo .offset_type = 167e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 168e705c121SKalle Valo .offset = sizeof(rfc1042_header), 169e705c121SKalle Valo .val = cpu_to_be32(0x08060001), 170e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 171e705c121SKalle Valo }, 172e705c121SKalle Valo { 173e705c121SKalle Valo /* arp dest ip */ 174e705c121SKalle Valo .offset_type = 175e705c121SKalle Valo BCAST_FILTER_OFFSET_PAYLOAD_START, 176e705c121SKalle Valo .offset = sizeof(rfc1042_header) + 2 + 177e705c121SKalle Valo sizeof(struct arphdr) + 178e705c121SKalle Valo ETH_ALEN + sizeof(__be32) + 179e705c121SKalle Valo ETH_ALEN, 180e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 181e705c121SKalle Valo /* mark it as special field */ 182e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP), 183e705c121SKalle Valo }, 184e705c121SKalle Valo }, 185e705c121SKalle Valo }, 186e705c121SKalle Valo { 187e705c121SKalle Valo /* dhcp offer bcast */ 188e705c121SKalle Valo .discard = 0, 189e705c121SKalle Valo .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4, 190e705c121SKalle Valo .attrs = { 191e705c121SKalle Valo { 192e705c121SKalle Valo /* udp dest port - 68 (bootp client)*/ 193e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 194e705c121SKalle Valo .offset = offsetof(struct udphdr, dest), 195e705c121SKalle Valo .val = cpu_to_be32(0x00440000), 196e705c121SKalle Valo .mask = cpu_to_be32(0xffff0000), 197e705c121SKalle Valo }, 198e705c121SKalle Valo { 199e705c121SKalle Valo /* dhcp - lsb bytes of client hw address */ 200e705c121SKalle Valo .offset_type = BCAST_FILTER_OFFSET_IP_END, 201e705c121SKalle Valo .offset = 38, 202e705c121SKalle Valo .mask = cpu_to_be32(0xffffffff), 203e705c121SKalle Valo /* mark it as special field */ 204e705c121SKalle Valo .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC), 205e705c121SKalle Valo }, 206e705c121SKalle Valo }, 207e705c121SKalle Valo }, 208e705c121SKalle Valo /* last filter must be empty */ 209e705c121SKalle Valo {}, 210e705c121SKalle Valo }; 211e705c121SKalle Valo #endif 212e705c121SKalle Valo 213e705c121SKalle Valo void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 214e705c121SKalle Valo { 215e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 216e705c121SKalle Valo return; 217e705c121SKalle Valo 218e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type); 219e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 220e705c121SKalle Valo mvm->refs[ref_type]++; 221e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 222e705c121SKalle Valo iwl_trans_ref(mvm->trans); 223e705c121SKalle Valo } 224e705c121SKalle Valo 225e705c121SKalle Valo void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 226e705c121SKalle Valo { 227e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 228e705c121SKalle Valo return; 229e705c121SKalle Valo 230e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type); 231e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 232*16c45822SSara Sharon if (WARN_ON(!mvm->refs[ref_type])) { 233*16c45822SSara Sharon spin_unlock_bh(&mvm->refs_lock); 234*16c45822SSara Sharon return; 235*16c45822SSara Sharon } 236*16c45822SSara Sharon mvm->refs[ref_type]--; 237e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 238e705c121SKalle Valo iwl_trans_unref(mvm->trans); 239e705c121SKalle Valo } 240e705c121SKalle Valo 241e705c121SKalle Valo static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm, 242e705c121SKalle Valo enum iwl_mvm_ref_type except_ref) 243e705c121SKalle Valo { 244e705c121SKalle Valo int i, j; 245e705c121SKalle Valo 246e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 247e705c121SKalle Valo return; 248e705c121SKalle Valo 249e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 250e705c121SKalle Valo for (i = 0; i < IWL_MVM_REF_COUNT; i++) { 251e705c121SKalle Valo if (except_ref == i || !mvm->refs[i]) 252e705c121SKalle Valo continue; 253e705c121SKalle Valo 254e705c121SKalle Valo IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n", 255e705c121SKalle Valo i, mvm->refs[i]); 256e705c121SKalle Valo for (j = 0; j < mvm->refs[i]; j++) 257e705c121SKalle Valo iwl_trans_unref(mvm->trans); 258e705c121SKalle Valo mvm->refs[i] = 0; 259e705c121SKalle Valo } 260e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 261e705c121SKalle Valo } 262e705c121SKalle Valo 263e705c121SKalle Valo bool iwl_mvm_ref_taken(struct iwl_mvm *mvm) 264e705c121SKalle Valo { 265e705c121SKalle Valo int i; 266e705c121SKalle Valo bool taken = false; 267e705c121SKalle Valo 268e705c121SKalle Valo if (!iwl_mvm_is_d0i3_supported(mvm)) 269e705c121SKalle Valo return true; 270e705c121SKalle Valo 271e705c121SKalle Valo spin_lock_bh(&mvm->refs_lock); 272e705c121SKalle Valo for (i = 0; i < IWL_MVM_REF_COUNT; i++) { 273e705c121SKalle Valo if (mvm->refs[i]) { 274e705c121SKalle Valo taken = true; 275e705c121SKalle Valo break; 276e705c121SKalle Valo } 277e705c121SKalle Valo } 278e705c121SKalle Valo spin_unlock_bh(&mvm->refs_lock); 279e705c121SKalle Valo 280e705c121SKalle Valo return taken; 281e705c121SKalle Valo } 282e705c121SKalle Valo 283e705c121SKalle Valo int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type) 284e705c121SKalle Valo { 285e705c121SKalle Valo iwl_mvm_ref(mvm, ref_type); 286e705c121SKalle Valo 287e705c121SKalle Valo if (!wait_event_timeout(mvm->d0i3_exit_waitq, 288e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), 289e705c121SKalle Valo HZ)) { 290e705c121SKalle Valo WARN_ON_ONCE(1); 291e705c121SKalle Valo iwl_mvm_unref(mvm, ref_type); 292e705c121SKalle Valo return -EIO; 293e705c121SKalle Valo } 294e705c121SKalle Valo 295e705c121SKalle Valo return 0; 296e705c121SKalle Valo } 297e705c121SKalle Valo 298e705c121SKalle Valo static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm) 299e705c121SKalle Valo { 300e705c121SKalle Valo int i; 301e705c121SKalle Valo 302e705c121SKalle Valo memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts)); 303e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 304e705c121SKalle Valo mvm->phy_ctxts[i].id = i; 305e705c121SKalle Valo mvm->phy_ctxts[i].ref = 0; 306e705c121SKalle Valo } 307e705c121SKalle Valo } 308e705c121SKalle Valo 309e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy, 310e705c121SKalle Valo const char *alpha2, 311e705c121SKalle Valo enum iwl_mcc_source src_id, 312e705c121SKalle Valo bool *changed) 313e705c121SKalle Valo { 314e705c121SKalle Valo struct ieee80211_regdomain *regd = NULL; 315e705c121SKalle Valo struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 316e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 317e705c121SKalle Valo struct iwl_mcc_update_resp *resp; 318e705c121SKalle Valo 319e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2); 320e705c121SKalle Valo 321e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 322e705c121SKalle Valo 323e705c121SKalle Valo resp = iwl_mvm_update_mcc(mvm, alpha2, src_id); 324e705c121SKalle Valo if (IS_ERR_OR_NULL(resp)) { 325e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n", 326e705c121SKalle Valo PTR_ERR_OR_ZERO(resp)); 327e705c121SKalle Valo goto out; 328e705c121SKalle Valo } 329e705c121SKalle Valo 330e705c121SKalle Valo if (changed) 331e705c121SKalle Valo *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE); 332e705c121SKalle Valo 333e705c121SKalle Valo regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg, 334e705c121SKalle Valo __le32_to_cpu(resp->n_channels), 335e705c121SKalle Valo resp->channels, 336e705c121SKalle Valo __le16_to_cpu(resp->mcc)); 337e705c121SKalle Valo /* Store the return source id */ 338e705c121SKalle Valo src_id = resp->source_id; 339e705c121SKalle Valo kfree(resp); 340e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) { 341e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n", 342e705c121SKalle Valo PTR_ERR_OR_ZERO(regd)); 343e705c121SKalle Valo goto out; 344e705c121SKalle Valo } 345e705c121SKalle Valo 346e705c121SKalle Valo IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n", 347e705c121SKalle Valo regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id); 348e705c121SKalle Valo mvm->lar_regdom_set = true; 349e705c121SKalle Valo mvm->mcc_src = src_id; 350e705c121SKalle Valo 351e705c121SKalle Valo out: 352e705c121SKalle Valo return regd; 353e705c121SKalle Valo } 354e705c121SKalle Valo 355e705c121SKalle Valo void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm) 356e705c121SKalle Valo { 357e705c121SKalle Valo bool changed; 358e705c121SKalle Valo struct ieee80211_regdomain *regd; 359e705c121SKalle Valo 360e705c121SKalle Valo if (!iwl_mvm_is_lar_supported(mvm)) 361e705c121SKalle Valo return; 362e705c121SKalle Valo 363e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, &changed); 364e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) { 365e705c121SKalle Valo /* only update the regulatory core if changed */ 366e705c121SKalle Valo if (changed) 367e705c121SKalle Valo regulatory_set_wiphy_regd(mvm->hw->wiphy, regd); 368e705c121SKalle Valo 369e705c121SKalle Valo kfree(regd); 370e705c121SKalle Valo } 371e705c121SKalle Valo } 372e705c121SKalle Valo 373e705c121SKalle Valo struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm, 374e705c121SKalle Valo bool *changed) 375e705c121SKalle Valo { 376e705c121SKalle Valo return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ", 377e705c121SKalle Valo iwl_mvm_is_wifi_mcc_supported(mvm) ? 378e705c121SKalle Valo MCC_SOURCE_GET_CURRENT : 379e705c121SKalle Valo MCC_SOURCE_OLD_FW, changed); 380e705c121SKalle Valo } 381e705c121SKalle Valo 382e705c121SKalle Valo int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm) 383e705c121SKalle Valo { 384e705c121SKalle Valo enum iwl_mcc_source used_src; 385e705c121SKalle Valo struct ieee80211_regdomain *regd; 386e705c121SKalle Valo int ret; 387e705c121SKalle Valo bool changed; 388e705c121SKalle Valo const struct ieee80211_regdomain *r = 389e705c121SKalle Valo rtnl_dereference(mvm->hw->wiphy->regd); 390e705c121SKalle Valo 391e705c121SKalle Valo if (!r) 392e705c121SKalle Valo return -ENOENT; 393e705c121SKalle Valo 394e705c121SKalle Valo /* save the last source in case we overwrite it below */ 395e705c121SKalle Valo used_src = mvm->mcc_src; 396e705c121SKalle Valo if (iwl_mvm_is_wifi_mcc_supported(mvm)) { 397e705c121SKalle Valo /* Notify the firmware we support wifi location updates */ 398e705c121SKalle Valo regd = iwl_mvm_get_current_regdomain(mvm, NULL); 399e705c121SKalle Valo if (!IS_ERR_OR_NULL(regd)) 400e705c121SKalle Valo kfree(regd); 401e705c121SKalle Valo } 402e705c121SKalle Valo 403e705c121SKalle Valo /* Now set our last stored MCC and source */ 404e705c121SKalle Valo regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src, 405e705c121SKalle Valo &changed); 406e705c121SKalle Valo if (IS_ERR_OR_NULL(regd)) 407e705c121SKalle Valo return -EIO; 408e705c121SKalle Valo 409e705c121SKalle Valo /* update cfg80211 if the regdomain was changed */ 410e705c121SKalle Valo if (changed) 411e705c121SKalle Valo ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd); 412e705c121SKalle Valo else 413e705c121SKalle Valo ret = 0; 414e705c121SKalle Valo 415e705c121SKalle Valo kfree(regd); 416e705c121SKalle Valo return ret; 417e705c121SKalle Valo } 418e705c121SKalle Valo 419e705c121SKalle Valo int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm) 420e705c121SKalle Valo { 421e705c121SKalle Valo struct ieee80211_hw *hw = mvm->hw; 422e705c121SKalle Valo int num_mac, ret, i; 423e705c121SKalle Valo static const u32 mvm_ciphers[] = { 424e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP40, 425e705c121SKalle Valo WLAN_CIPHER_SUITE_WEP104, 426e705c121SKalle Valo WLAN_CIPHER_SUITE_TKIP, 427e705c121SKalle Valo WLAN_CIPHER_SUITE_CCMP, 428e705c121SKalle Valo }; 429e705c121SKalle Valo 430e705c121SKalle Valo /* Tell mac80211 our characteristics */ 431e705c121SKalle Valo ieee80211_hw_set(hw, SIGNAL_DBM); 432e705c121SKalle Valo ieee80211_hw_set(hw, SPECTRUM_MGMT); 433e705c121SKalle Valo ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); 434e705c121SKalle Valo ieee80211_hw_set(hw, QUEUE_CONTROL); 435e705c121SKalle Valo ieee80211_hw_set(hw, WANT_MONITOR_VIF); 436e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_PS); 437e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 438e705c121SKalle Valo ieee80211_hw_set(hw, AMPDU_AGGREGATION); 439e705c121SKalle Valo ieee80211_hw_set(hw, TIMING_BEACON_ONLY); 440e705c121SKalle Valo ieee80211_hw_set(hw, CONNECTION_MONITOR); 441e705c121SKalle Valo ieee80211_hw_set(hw, CHANCTX_STA_CSA); 442e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); 443e705c121SKalle Valo ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); 444909ddf0bSJohannes Berg ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU); 44530433d3bSJohannes Berg ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR); 446b915c101SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 447b915c101SSara Sharon ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER); 448e705c121SKalle Valo 44980938abcSJohannes Berg if (mvm->trans->num_rx_queues > 1) 45080938abcSJohannes Berg ieee80211_hw_set(hw, USES_RSS); 45180938abcSJohannes Berg 4522d7cf549SJohannes Berg if (mvm->trans->max_skb_frags) 4532d7cf549SJohannes Berg hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG; 4542d7cf549SJohannes Berg 455e705c121SKalle Valo hw->queues = mvm->first_agg_queue; 456e705c121SKalle Valo hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE; 457e705c121SKalle Valo hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC | 458e705c121SKalle Valo IEEE80211_RADIOTAP_MCS_HAVE_STBC; 459e705c121SKalle Valo hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC | 460e705c121SKalle Valo IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED; 461e705c121SKalle Valo hw->rate_control_algorithm = "iwl-mvm-rs"; 462e705c121SKalle Valo hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES; 463e705c121SKalle Valo hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP; 464e705c121SKalle Valo 465e705c121SKalle Valo BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 2); 466e705c121SKalle Valo memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers)); 467e705c121SKalle Valo hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers); 468e705c121SKalle Valo hw->wiphy->cipher_suites = mvm->ciphers; 469e705c121SKalle Valo 470e705c121SKalle Valo /* 471e705c121SKalle Valo * Enable 11w if advertised by firmware and software crypto 472e705c121SKalle Valo * is not enabled (as the firmware will interpret some mgmt 473e705c121SKalle Valo * packets, so enabling it with software crypto isn't safe) 474e705c121SKalle Valo */ 475e705c121SKalle Valo if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP && 476e705c121SKalle Valo !iwlwifi_mod_params.sw_crypto) { 477e705c121SKalle Valo ieee80211_hw_set(hw, MFP_CAPABLE); 478e705c121SKalle Valo mvm->ciphers[hw->wiphy->n_cipher_suites] = 479e705c121SKalle Valo WLAN_CIPHER_SUITE_AES_CMAC; 480e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 481e705c121SKalle Valo } 482e705c121SKalle Valo 483e705c121SKalle Valo /* currently FW API supports only one optional cipher scheme */ 484e705c121SKalle Valo if (mvm->fw->cs[0].cipher) { 485e705c121SKalle Valo mvm->hw->n_cipher_schemes = 1; 486e705c121SKalle Valo mvm->hw->cipher_schemes = &mvm->fw->cs[0]; 487e705c121SKalle Valo mvm->ciphers[hw->wiphy->n_cipher_suites] = 488e705c121SKalle Valo mvm->fw->cs[0].cipher; 489e705c121SKalle Valo hw->wiphy->n_cipher_suites++; 490e705c121SKalle Valo } 491e705c121SKalle Valo 492e705c121SKalle Valo ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 493e705c121SKalle Valo hw->wiphy->features |= 494e705c121SKalle Valo NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 495e705c121SKalle Valo NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 496e705c121SKalle Valo NL80211_FEATURE_ND_RANDOM_MAC_ADDR; 497e705c121SKalle Valo 498e705c121SKalle Valo hw->sta_data_size = sizeof(struct iwl_mvm_sta); 499e705c121SKalle Valo hw->vif_data_size = sizeof(struct iwl_mvm_vif); 500e705c121SKalle Valo hw->chanctx_data_size = sizeof(u16); 501e705c121SKalle Valo 502e705c121SKalle Valo hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | 503e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_CLIENT) | 504e705c121SKalle Valo BIT(NL80211_IFTYPE_AP) | 505e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_GO) | 506e705c121SKalle Valo BIT(NL80211_IFTYPE_P2P_DEVICE) | 507e705c121SKalle Valo BIT(NL80211_IFTYPE_ADHOC); 508e705c121SKalle Valo 509e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; 510e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR; 511e705c121SKalle Valo if (iwl_mvm_is_lar_supported(mvm)) 512e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED; 513e705c121SKalle Valo else 514e705c121SKalle Valo hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG | 515e705c121SKalle Valo REGULATORY_DISABLE_BEACON_HINTS; 516e705c121SKalle Valo 517e705c121SKalle Valo if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD) 518e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; 519e705c121SKalle Valo 520e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 521e705c121SKalle Valo 522e705c121SKalle Valo hw->wiphy->iface_combinations = iwl_mvm_iface_combinations; 523e705c121SKalle Valo hw->wiphy->n_iface_combinations = 524e705c121SKalle Valo ARRAY_SIZE(iwl_mvm_iface_combinations); 525e705c121SKalle Valo 526e705c121SKalle Valo hw->wiphy->max_remain_on_channel_duration = 10000; 527e705c121SKalle Valo hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 528e705c121SKalle Valo /* we can compensate an offset of up to 3 channels = 15 MHz */ 529e705c121SKalle Valo hw->wiphy->max_adj_channel_rssi_comp = 3 * 5; 530e705c121SKalle Valo 531e705c121SKalle Valo /* Extract MAC address */ 532e705c121SKalle Valo memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN); 533e705c121SKalle Valo hw->wiphy->addresses = mvm->addresses; 534e705c121SKalle Valo hw->wiphy->n_addresses = 1; 535e705c121SKalle Valo 536e705c121SKalle Valo /* Extract additional MAC addresses if available */ 537e705c121SKalle Valo num_mac = (mvm->nvm_data->n_hw_addrs > 1) ? 538e705c121SKalle Valo min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1; 539e705c121SKalle Valo 540e705c121SKalle Valo for (i = 1; i < num_mac; i++) { 541e705c121SKalle Valo memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr, 542e705c121SKalle Valo ETH_ALEN); 543e705c121SKalle Valo mvm->addresses[i].addr[5]++; 544e705c121SKalle Valo hw->wiphy->n_addresses++; 545e705c121SKalle Valo } 546e705c121SKalle Valo 547e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 548e705c121SKalle Valo 549e705c121SKalle Valo hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm); 550e705c121SKalle Valo 551e705c121SKalle Valo hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; 552e705c121SKalle Valo 553e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK); 554e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) || 555e705c121SKalle Valo IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK)); 556e705c121SKalle Valo 557e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 558e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS; 559e705c121SKalle Valo else 560e705c121SKalle Valo mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS; 561e705c121SKalle Valo 56257fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels) 56357fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_2GHZ] = 56457fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_2GHZ]; 56557fbcce3SJohannes Berg if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) { 56657fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ] = 56757fbcce3SJohannes Berg &mvm->nvm_data->bands[NL80211_BAND_5GHZ]; 568e705c121SKalle Valo 569e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 570e705c121SKalle Valo IWL_UCODE_TLV_CAPA_BEAMFORMER) && 571e705c121SKalle Valo fw_has_api(&mvm->fw->ucode_capa, 572e705c121SKalle Valo IWL_UCODE_TLV_API_LQ_SS_PARAMS)) 57357fbcce3SJohannes Berg hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |= 574e705c121SKalle Valo IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE; 575e705c121SKalle Valo } 576e705c121SKalle Valo 577e705c121SKalle Valo hw->wiphy->hw_version = mvm->trans->hw_id; 578e705c121SKalle Valo 579e705c121SKalle Valo if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) 580e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT; 581e705c121SKalle Valo else 582e705c121SKalle Valo hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; 583e705c121SKalle Valo 584e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN; 585e705c121SKalle Valo hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX; 586e705c121SKalle Valo hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES; 587e705c121SKalle Valo /* we create the 802.11 header and zero length SSID IE. */ 588e705c121SKalle Valo hw->wiphy->max_sched_scan_ie_len = 589e705c121SKalle Valo SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2; 590e705c121SKalle Valo hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS; 591e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_interval = U16_MAX; 592e705c121SKalle Valo 593e705c121SKalle Valo /* 594e705c121SKalle Valo * the firmware uses u8 for num of iterations, but 0xff is saved for 595e705c121SKalle Valo * infinite loop, so the maximum number of iterations is actually 254. 596e705c121SKalle Valo */ 597e705c121SKalle Valo hw->wiphy->max_sched_scan_plan_iterations = 254; 598e705c121SKalle Valo 599e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN | 600e705c121SKalle Valo NL80211_FEATURE_LOW_PRIORITY_SCAN | 601e705c121SKalle Valo NL80211_FEATURE_P2P_GO_OPPPS | 602e705c121SKalle Valo NL80211_FEATURE_DYNAMIC_SMPS | 603e705c121SKalle Valo NL80211_FEATURE_STATIC_SMPS | 604e705c121SKalle Valo NL80211_FEATURE_SUPPORTS_WMM_ADMISSION; 605e705c121SKalle Valo 606e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 607e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)) 608e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; 609e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 610e705c121SKalle Valo IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)) 611e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_QUIET; 612e705c121SKalle Valo 613e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 614e705c121SKalle Valo IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)) 615e705c121SKalle Valo hw->wiphy->features |= 616e705c121SKalle Valo NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES; 617e705c121SKalle Valo 618e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 619e705c121SKalle Valo IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)) 620e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES; 621e705c121SKalle Valo 622e705c121SKalle Valo mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 623e705c121SKalle Valo 624e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 625e705c121SKalle Valo if (iwl_mvm_is_d0i3_supported(mvm) && 626e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 627e705c121SKalle Valo mvm->wowlan.flags = WIPHY_WOWLAN_ANY; 628e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 629e705c121SKalle Valo } 630e705c121SKalle Valo 631e705c121SKalle Valo if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len && 632e705c121SKalle Valo mvm->trans->ops->d3_suspend && 633e705c121SKalle Valo mvm->trans->ops->d3_resume && 634e705c121SKalle Valo device_can_wakeup(mvm->trans->dev)) { 635e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT | 636e705c121SKalle Valo WIPHY_WOWLAN_DISCONNECT | 637e705c121SKalle Valo WIPHY_WOWLAN_EAP_IDENTITY_REQ | 638e705c121SKalle Valo WIPHY_WOWLAN_RFKILL_RELEASE | 639e705c121SKalle Valo WIPHY_WOWLAN_NET_DETECT; 640e705c121SKalle Valo if (!iwlwifi_mod_params.sw_crypto) 641e705c121SKalle Valo mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY | 642e705c121SKalle Valo WIPHY_WOWLAN_GTK_REKEY_FAILURE | 643e705c121SKalle Valo WIPHY_WOWLAN_4WAY_HANDSHAKE; 644e705c121SKalle Valo 645e705c121SKalle Valo mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS; 646e705c121SKalle Valo mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN; 647e705c121SKalle Valo mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN; 648e705c121SKalle Valo mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES; 649e705c121SKalle Valo mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support; 650e705c121SKalle Valo hw->wiphy->wowlan = &mvm->wowlan; 651e705c121SKalle Valo } 652e705c121SKalle Valo #endif 653e705c121SKalle Valo 654e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 655e705c121SKalle Valo /* assign default bcast filtering configuration */ 656e705c121SKalle Valo mvm->bcast_filters = iwl_mvm_default_bcast_filters; 657e705c121SKalle Valo #endif 658e705c121SKalle Valo 659e705c121SKalle Valo ret = iwl_mvm_leds_init(mvm); 660e705c121SKalle Valo if (ret) 661e705c121SKalle Valo return ret; 662e705c121SKalle Valo 663e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 664e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) { 665e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS supported\n"); 666e705c121SKalle Valo hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; 667e705c121SKalle Valo ieee80211_hw_set(hw, TDLS_WIDER_BW); 668e705c121SKalle Valo } 669e705c121SKalle Valo 670e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 671e705c121SKalle Valo IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) { 672e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n"); 673e705c121SKalle Valo hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH; 674e705c121SKalle Valo } 675e705c121SKalle Valo 676e705c121SKalle Valo hw->netdev_features |= mvm->cfg->features; 6775e6a98dcSSara Sharon if (!iwl_mvm_is_csum_supported(mvm)) { 6785e6a98dcSSara Sharon hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS | 6795e6a98dcSSara Sharon NETIF_F_RXCSUM); 6805e6a98dcSSara Sharon /* We may support SW TX CSUM */ 68141837ca9SEmmanuel Grumbach if (IWL_MVM_SW_TX_CSUM_OFFLOAD) 6825e6a98dcSSara Sharon hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS; 6835e6a98dcSSara Sharon } 68441837ca9SEmmanuel Grumbach 685e705c121SKalle Valo ret = ieee80211_register_hw(mvm->hw); 686e705c121SKalle Valo if (ret) 687e705c121SKalle Valo iwl_mvm_leds_exit(mvm); 688e705c121SKalle Valo 689e705c121SKalle Valo return ret; 690e705c121SKalle Valo } 691e705c121SKalle Valo 692e705c121SKalle Valo static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm, 693e705c121SKalle Valo struct ieee80211_sta *sta, 694e705c121SKalle Valo struct sk_buff *skb) 695e705c121SKalle Valo { 696e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 697e705c121SKalle Valo bool defer = false; 698e705c121SKalle Valo 699e705c121SKalle Valo /* 700e705c121SKalle Valo * double check the IN_D0I3 flag both before and after 701e705c121SKalle Valo * taking the spinlock, in order to prevent taking 702e705c121SKalle Valo * the spinlock when not needed. 703e705c121SKalle Valo */ 704e705c121SKalle Valo if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))) 705e705c121SKalle Valo return false; 706e705c121SKalle Valo 707e705c121SKalle Valo spin_lock(&mvm->d0i3_tx_lock); 708e705c121SKalle Valo /* 709e705c121SKalle Valo * testing the flag again ensures the skb dequeue 710e705c121SKalle Valo * loop (on d0i3 exit) hasn't run yet. 711e705c121SKalle Valo */ 712e705c121SKalle Valo if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) 713e705c121SKalle Valo goto out; 714e705c121SKalle Valo 715e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 716e705c121SKalle Valo if (mvmsta->sta_id == IWL_MVM_STATION_COUNT || 717e705c121SKalle Valo mvmsta->sta_id != mvm->d0i3_ap_sta_id) 718e705c121SKalle Valo goto out; 719e705c121SKalle Valo 720e705c121SKalle Valo __skb_queue_tail(&mvm->d0i3_tx, skb); 721e705c121SKalle Valo ieee80211_stop_queues(mvm->hw); 722e705c121SKalle Valo 723e705c121SKalle Valo /* trigger wakeup */ 724e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_TX); 725e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_TX); 726e705c121SKalle Valo 727e705c121SKalle Valo defer = true; 728e705c121SKalle Valo out: 729e705c121SKalle Valo spin_unlock(&mvm->d0i3_tx_lock); 730e705c121SKalle Valo return defer; 731e705c121SKalle Valo } 732e705c121SKalle Valo 733e705c121SKalle Valo static void iwl_mvm_mac_tx(struct ieee80211_hw *hw, 734e705c121SKalle Valo struct ieee80211_tx_control *control, 735e705c121SKalle Valo struct sk_buff *skb) 736e705c121SKalle Valo { 737e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 738e705c121SKalle Valo struct ieee80211_sta *sta = control->sta; 739e705c121SKalle Valo struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 740e705c121SKalle Valo struct ieee80211_hdr *hdr = (void *)skb->data; 741e705c121SKalle Valo 742e705c121SKalle Valo if (iwl_mvm_is_radio_killed(mvm)) { 743e705c121SKalle Valo IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n"); 744e705c121SKalle Valo goto drop; 745e705c121SKalle Valo } 746e705c121SKalle Valo 747e705c121SKalle Valo if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE && 748e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) && 749e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) 750e705c121SKalle Valo goto drop; 751e705c121SKalle Valo 752e705c121SKalle Valo /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */ 753e705c121SKalle Valo if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER && 754e705c121SKalle Valo ieee80211_is_mgmt(hdr->frame_control) && 755e705c121SKalle Valo !ieee80211_is_deauth(hdr->frame_control) && 756e705c121SKalle Valo !ieee80211_is_disassoc(hdr->frame_control) && 757e705c121SKalle Valo !ieee80211_is_action(hdr->frame_control))) 758e705c121SKalle Valo sta = NULL; 759e705c121SKalle Valo 760e705c121SKalle Valo if (sta) { 761e705c121SKalle Valo if (iwl_mvm_defer_tx(mvm, sta, skb)) 762e705c121SKalle Valo return; 763e705c121SKalle Valo if (iwl_mvm_tx_skb(mvm, skb, sta)) 764e705c121SKalle Valo goto drop; 765e705c121SKalle Valo return; 766e705c121SKalle Valo } 767e705c121SKalle Valo 768e705c121SKalle Valo if (iwl_mvm_tx_skb_non_sta(mvm, skb)) 769e705c121SKalle Valo goto drop; 770e705c121SKalle Valo return; 771e705c121SKalle Valo drop: 772e705c121SKalle Valo ieee80211_free_txskb(hw, skb); 773e705c121SKalle Valo } 774e705c121SKalle Valo 775e705c121SKalle Valo static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg) 776e705c121SKalle Valo { 777e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) 778e705c121SKalle Valo return false; 779e705c121SKalle Valo return true; 780e705c121SKalle Valo } 781e705c121SKalle Valo 782e705c121SKalle Valo static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg) 783e705c121SKalle Valo { 784e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) 785e705c121SKalle Valo return false; 786e705c121SKalle Valo if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG) 787e705c121SKalle Valo return true; 788e705c121SKalle Valo 789e705c121SKalle Valo /* enabled by default */ 790e705c121SKalle Valo return true; 791e705c121SKalle Valo } 792e705c121SKalle Valo 793e705c121SKalle Valo #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ 794e705c121SKalle Valo do { \ 795e705c121SKalle Valo if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ 796e705c121SKalle Valo break; \ 797e705c121SKalle Valo iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt); \ 798e705c121SKalle Valo } while (0) 799e705c121SKalle Valo 800e705c121SKalle Valo static void 801e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 802e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn, 803e705c121SKalle Valo enum ieee80211_ampdu_mlme_action action) 804e705c121SKalle Valo { 805e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 806e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 807e705c121SKalle Valo 808e705c121SKalle Valo if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA)) 809e705c121SKalle Valo return; 810e705c121SKalle Valo 811e705c121SKalle Valo trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA); 812e705c121SKalle Valo ba_trig = (void *)trig->data; 813e705c121SKalle Valo 814e705c121SKalle Valo if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 815e705c121SKalle Valo return; 816e705c121SKalle Valo 817e705c121SKalle Valo switch (action) { 818e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: { 819e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 820e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 821e705c121SKalle Valo 822e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid, 823e705c121SKalle Valo "TX AGG START: MAC %pM tid %d ssn %d\n", 824e705c121SKalle Valo sta->addr, tid, tid_data->ssn); 825e705c121SKalle Valo break; 826e705c121SKalle Valo } 827e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 828e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid, 829e705c121SKalle Valo "TX AGG STOP: MAC %pM tid %d\n", 830e705c121SKalle Valo sta->addr, tid); 831e705c121SKalle Valo break; 832e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 833e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid, 834e705c121SKalle Valo "RX AGG START: MAC %pM tid %d ssn %d\n", 835e705c121SKalle Valo sta->addr, tid, rx_ba_ssn); 836e705c121SKalle Valo break; 837e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 838e705c121SKalle Valo CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid, 839e705c121SKalle Valo "RX AGG STOP: MAC %pM tid %d\n", 840e705c121SKalle Valo sta->addr, tid); 841e705c121SKalle Valo break; 842e705c121SKalle Valo default: 843e705c121SKalle Valo break; 844e705c121SKalle Valo } 845e705c121SKalle Valo } 846e705c121SKalle Valo 847e705c121SKalle Valo static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw, 848e705c121SKalle Valo struct ieee80211_vif *vif, 84950ea05efSSara Sharon struct ieee80211_ampdu_params *params) 850e705c121SKalle Valo { 851e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 852e705c121SKalle Valo int ret; 853e705c121SKalle Valo bool tx_agg_ref = false; 85450ea05efSSara Sharon struct ieee80211_sta *sta = params->sta; 85550ea05efSSara Sharon enum ieee80211_ampdu_mlme_action action = params->action; 85650ea05efSSara Sharon u16 tid = params->tid; 85750ea05efSSara Sharon u16 *ssn = ¶ms->ssn; 85850ea05efSSara Sharon u8 buf_size = params->buf_size; 859bb81bb68SEmmanuel Grumbach bool amsdu = params->amsdu; 86010b2b201SSara Sharon u16 timeout = params->timeout; 861e705c121SKalle Valo 862e705c121SKalle Valo IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n", 863e705c121SKalle Valo sta->addr, tid, action); 864e705c121SKalle Valo 865e705c121SKalle Valo if (!(mvm->nvm_data->sku_cap_11n_enable)) 866e705c121SKalle Valo return -EACCES; 867e705c121SKalle Valo 868e705c121SKalle Valo /* return from D0i3 before starting a new Tx aggregation */ 869e705c121SKalle Valo switch (action) { 870e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 871e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 872e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 873e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 874e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 875e705c121SKalle Valo /* 876e705c121SKalle Valo * for tx start, wait synchronously until D0i3 exit to 877e705c121SKalle Valo * get the correct sequence number for the tid. 878e705c121SKalle Valo * additionally, some other ampdu actions use direct 879e705c121SKalle Valo * target access, which is not handled automatically 880e705c121SKalle Valo * by the trans layer (unlike commands), so wait for 881e705c121SKalle Valo * d0i3 exit in these cases as well. 882e705c121SKalle Valo */ 883e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG); 884e705c121SKalle Valo if (ret) 885e705c121SKalle Valo return ret; 886e705c121SKalle Valo 887e705c121SKalle Valo tx_agg_ref = true; 888e705c121SKalle Valo break; 889e705c121SKalle Valo default: 890e705c121SKalle Valo break; 891e705c121SKalle Valo } 892e705c121SKalle Valo 893e705c121SKalle Valo mutex_lock(&mvm->mutex); 894e705c121SKalle Valo 895e705c121SKalle Valo switch (action) { 896e705c121SKalle Valo case IEEE80211_AMPDU_RX_START: 897e705c121SKalle Valo if (!iwl_enable_rx_ampdu(mvm->cfg)) { 898e705c121SKalle Valo ret = -EINVAL; 899e705c121SKalle Valo break; 900e705c121SKalle Valo } 90110b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size, 90210b2b201SSara Sharon timeout); 903e705c121SKalle Valo break; 904e705c121SKalle Valo case IEEE80211_AMPDU_RX_STOP: 90510b2b201SSara Sharon ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size, 90610b2b201SSara Sharon timeout); 907e705c121SKalle Valo break; 908e705c121SKalle Valo case IEEE80211_AMPDU_TX_START: 909e705c121SKalle Valo if (!iwl_enable_tx_ampdu(mvm->cfg)) { 910e705c121SKalle Valo ret = -EINVAL; 911e705c121SKalle Valo break; 912e705c121SKalle Valo } 913e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn); 914e705c121SKalle Valo break; 915e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_CONT: 916e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid); 917e705c121SKalle Valo break; 918e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH: 919e705c121SKalle Valo case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: 920e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid); 921e705c121SKalle Valo break; 922e705c121SKalle Valo case IEEE80211_AMPDU_TX_OPERATIONAL: 923bb81bb68SEmmanuel Grumbach ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, 924bb81bb68SEmmanuel Grumbach buf_size, amsdu); 925e705c121SKalle Valo break; 926e705c121SKalle Valo default: 927e705c121SKalle Valo WARN_ON_ONCE(1); 928e705c121SKalle Valo ret = -EINVAL; 929e705c121SKalle Valo break; 930e705c121SKalle Valo } 931e705c121SKalle Valo 932e705c121SKalle Valo if (!ret) { 933e705c121SKalle Valo u16 rx_ba_ssn = 0; 934e705c121SKalle Valo 935e705c121SKalle Valo if (action == IEEE80211_AMPDU_RX_START) 936e705c121SKalle Valo rx_ba_ssn = *ssn; 937e705c121SKalle Valo 938e705c121SKalle Valo iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid, 939e705c121SKalle Valo rx_ba_ssn, action); 940e705c121SKalle Valo } 941e705c121SKalle Valo mutex_unlock(&mvm->mutex); 942e705c121SKalle Valo 943e705c121SKalle Valo /* 944e705c121SKalle Valo * If the tid is marked as started, we won't use it for offloaded 945e705c121SKalle Valo * traffic on the next D0i3 entry. It's safe to unref. 946e705c121SKalle Valo */ 947e705c121SKalle Valo if (tx_agg_ref) 948e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG); 949e705c121SKalle Valo 950e705c121SKalle Valo return ret; 951e705c121SKalle Valo } 952e705c121SKalle Valo 953e705c121SKalle Valo static void iwl_mvm_cleanup_iterator(void *data, u8 *mac, 954e705c121SKalle Valo struct ieee80211_vif *vif) 955e705c121SKalle Valo { 956e705c121SKalle Valo struct iwl_mvm *mvm = data; 957e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 958e705c121SKalle Valo 959e705c121SKalle Valo mvmvif->uploaded = false; 960e705c121SKalle Valo mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; 961e705c121SKalle Valo 962e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 963e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data); 964e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 965e705c121SKalle Valo 966e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 967e705c121SKalle Valo memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data)); 968e705c121SKalle Valo } 969e705c121SKalle Valo 970e705c121SKalle Valo static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm) 971e705c121SKalle Valo { 972e705c121SKalle Valo /* clear the D3 reconfig, we only need it to avoid dumping a 973e705c121SKalle Valo * firmware coredump on reconfiguration, we shouldn't do that 974e705c121SKalle Valo * on D3->D0 transition 975e705c121SKalle Valo */ 976e705c121SKalle Valo if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) { 977e705c121SKalle Valo mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert; 978e705c121SKalle Valo iwl_mvm_fw_error_dump(mvm); 979e705c121SKalle Valo } 980e705c121SKalle Valo 981e705c121SKalle Valo /* cleanup all stale references (scan, roc), but keep the 982e705c121SKalle Valo * ucode_down ref until reconfig is complete 983e705c121SKalle Valo */ 984e705c121SKalle Valo iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN); 985e705c121SKalle Valo 986fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 987e705c121SKalle Valo 988e705c121SKalle Valo mvm->scan_status = 0; 989e705c121SKalle Valo mvm->ps_disabled = false; 990e705c121SKalle Valo mvm->calibrating = false; 991e705c121SKalle Valo 992e705c121SKalle Valo /* just in case one was running */ 993305d236eSEliad Peller iwl_mvm_cleanup_roc_te(mvm); 994e705c121SKalle Valo ieee80211_remain_on_channel_expired(mvm->hw); 995e705c121SKalle Valo 996e705c121SKalle Valo /* 997e705c121SKalle Valo * cleanup all interfaces, even inactive ones, as some might have 998e705c121SKalle Valo * gone down during the HW restart 999e705c121SKalle Valo */ 1000e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm); 1001e705c121SKalle Valo 1002e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1003e705c121SKalle Valo mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; 1004e705c121SKalle Valo 1005e705c121SKalle Valo iwl_mvm_reset_phy_ctxts(mvm); 10069c3deeb5SLuca Coelho memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); 1007e705c121SKalle Valo memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained)); 100824afba76SLiad Kaufman memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames)); 1009e705c121SKalle Valo memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained)); 1010e705c121SKalle Valo memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif)); 1011e705c121SKalle Valo memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old)); 1012e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd)); 1013e705c121SKalle Valo memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old)); 1014e705c121SKalle Valo memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk)); 1015e705c121SKalle Valo memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk)); 1016e705c121SKalle Valo 1017e705c121SKalle Valo ieee80211_wake_queues(mvm->hw); 1018e705c121SKalle Valo 1019e705c121SKalle Valo /* clear any stale d0i3 state */ 1020e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status); 1021e705c121SKalle Valo 1022e705c121SKalle Valo mvm->vif_count = 0; 1023e705c121SKalle Valo mvm->rx_ba_sessions = 0; 1024e705c121SKalle Valo mvm->fw_dbg_conf = FW_DBG_INVALID; 1025e705c121SKalle Valo 1026e705c121SKalle Valo /* keep statistics ticking */ 1027e705c121SKalle Valo iwl_mvm_accu_radio_stats(mvm); 1028e705c121SKalle Valo } 1029e705c121SKalle Valo 1030e705c121SKalle Valo int __iwl_mvm_mac_start(struct iwl_mvm *mvm) 1031e705c121SKalle Valo { 1032e705c121SKalle Valo int ret; 1033e705c121SKalle Valo 1034e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1035e705c121SKalle Valo 1036a42b2af3SLuca Coelho if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1037e705c121SKalle Valo /* Clean up some internal and mac80211 state on restart */ 1038e705c121SKalle Valo iwl_mvm_restart_cleanup(mvm); 1039a42b2af3SLuca Coelho } else { 1040a42b2af3SLuca Coelho /* Hold the reference to prevent runtime suspend while 1041a42b2af3SLuca Coelho * the start procedure runs. It's a bit confusing 1042a42b2af3SLuca Coelho * that the UCODE_DOWN reference is taken, but it just 1043a42b2af3SLuca Coelho * means "UCODE is not UP yet". ( TODO: rename this 1044a42b2af3SLuca Coelho * reference). 1045a42b2af3SLuca Coelho */ 1046a42b2af3SLuca Coelho iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); 1047a42b2af3SLuca Coelho } 1048e705c121SKalle Valo ret = iwl_mvm_up(mvm); 1049e705c121SKalle Valo 1050e705c121SKalle Valo if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1051e705c121SKalle Valo /* Something went wrong - we need to finish some cleanup 1052e705c121SKalle Valo * that normally iwl_mvm_mac_restart_complete() below 1053e705c121SKalle Valo * would do. 1054e705c121SKalle Valo */ 1055e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1056e705c121SKalle Valo iwl_mvm_d0i3_enable_tx(mvm, NULL); 1057e705c121SKalle Valo } 1058e705c121SKalle Valo 1059e705c121SKalle Valo return ret; 1060e705c121SKalle Valo } 1061e705c121SKalle Valo 1062e705c121SKalle Valo static int iwl_mvm_mac_start(struct ieee80211_hw *hw) 1063e705c121SKalle Valo { 1064e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1065e705c121SKalle Valo int ret; 1066e705c121SKalle Valo 1067e705c121SKalle Valo /* Some hw restart cleanups must not hold the mutex */ 1068e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1069e705c121SKalle Valo /* 1070e705c121SKalle Valo * Make sure we are out of d0i3. This is needed 1071e705c121SKalle Valo * to make sure the reference accounting is correct 1072e705c121SKalle Valo * (and there is no stale d0i3_exit_work). 1073e705c121SKalle Valo */ 1074e705c121SKalle Valo wait_event_timeout(mvm->d0i3_exit_waitq, 1075e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, 1076e705c121SKalle Valo &mvm->status), 1077e705c121SKalle Valo HZ); 1078e705c121SKalle Valo } 1079e705c121SKalle Valo 1080e705c121SKalle Valo mutex_lock(&mvm->mutex); 1081e705c121SKalle Valo ret = __iwl_mvm_mac_start(mvm); 1082e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1083e705c121SKalle Valo 1084e705c121SKalle Valo return ret; 1085e705c121SKalle Valo } 1086e705c121SKalle Valo 1087e705c121SKalle Valo static void iwl_mvm_restart_complete(struct iwl_mvm *mvm) 1088e705c121SKalle Valo { 1089e705c121SKalle Valo int ret; 1090e705c121SKalle Valo 1091e705c121SKalle Valo mutex_lock(&mvm->mutex); 1092e705c121SKalle Valo 1093e705c121SKalle Valo clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); 1094e705c121SKalle Valo iwl_mvm_d0i3_enable_tx(mvm, NULL); 1095e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1096e705c121SKalle Valo if (ret) 1097e705c121SKalle Valo IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n", 1098e705c121SKalle Valo ret); 1099e705c121SKalle Valo 1100e705c121SKalle Valo /* allow transport/FW low power modes */ 1101e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); 1102e705c121SKalle Valo 1103e705c121SKalle Valo /* 1104e705c121SKalle Valo * If we have TDLS peers, remove them. We don't know the last seqno/PN 1105e705c121SKalle Valo * of packets the FW sent out, so we must reconnect. 1106e705c121SKalle Valo */ 1107e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 1108e705c121SKalle Valo 1109e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1110e705c121SKalle Valo } 1111e705c121SKalle Valo 1112e705c121SKalle Valo static void iwl_mvm_resume_complete(struct iwl_mvm *mvm) 1113e705c121SKalle Valo { 1114b7282643SLuca Coelho if (iwl_mvm_is_d0i3_supported(mvm) && 1115b7282643SLuca Coelho iwl_mvm_enter_d0i3_on_suspend(mvm)) 1116b7282643SLuca Coelho WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq, 1117e705c121SKalle Valo !test_bit(IWL_MVM_STATUS_IN_D0I3, 1118e705c121SKalle Valo &mvm->status), 1119b7282643SLuca Coelho HZ), 1120b7282643SLuca Coelho "D0i3 exit on resume timed out\n"); 1121e705c121SKalle Valo } 1122e705c121SKalle Valo 1123e705c121SKalle Valo static void 1124e705c121SKalle Valo iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw, 1125e705c121SKalle Valo enum ieee80211_reconfig_type reconfig_type) 1126e705c121SKalle Valo { 1127e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1128e705c121SKalle Valo 1129e705c121SKalle Valo switch (reconfig_type) { 1130e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_RESTART: 1131e705c121SKalle Valo iwl_mvm_restart_complete(mvm); 1132e705c121SKalle Valo break; 1133e705c121SKalle Valo case IEEE80211_RECONFIG_TYPE_SUSPEND: 1134e705c121SKalle Valo iwl_mvm_resume_complete(mvm); 1135e705c121SKalle Valo break; 1136e705c121SKalle Valo } 1137e705c121SKalle Valo } 1138e705c121SKalle Valo 1139e705c121SKalle Valo void __iwl_mvm_mac_stop(struct iwl_mvm *mvm) 1140e705c121SKalle Valo { 1141e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1142e705c121SKalle Valo 1143e705c121SKalle Valo /* firmware counters are obviously reset now, but we shouldn't 1144e705c121SKalle Valo * partially track so also clear the fw_reset_accu counters. 1145e705c121SKalle Valo */ 1146e705c121SKalle Valo memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats)); 1147e705c121SKalle Valo 1148e705c121SKalle Valo /* async_handlers_wk is now blocked */ 1149e705c121SKalle Valo 1150e705c121SKalle Valo /* 1151e705c121SKalle Valo * The work item could be running or queued if the 1152e705c121SKalle Valo * ROC time event stops just as we get here. 1153e705c121SKalle Valo */ 1154e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1155e705c121SKalle Valo 1156fcb6b92aSChaya Rachel Ivgi iwl_mvm_stop_device(mvm); 1157e705c121SKalle Valo 1158e705c121SKalle Valo iwl_mvm_async_handlers_purge(mvm); 1159e705c121SKalle Valo /* async_handlers_list is empty and will stay empty: HW is stopped */ 1160e705c121SKalle Valo 1161e705c121SKalle Valo /* the fw is stopped, the aux sta is dead: clean up driver state */ 1162e705c121SKalle Valo iwl_mvm_del_aux_sta(mvm); 1163e705c121SKalle Valo 11647fdf9663SMatti Gottlieb iwl_free_fw_paging(mvm); 11657fdf9663SMatti Gottlieb 1166e705c121SKalle Valo /* 1167e705c121SKalle Valo * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete() 1168e705c121SKalle Valo * won't be called in this case). 1169e705c121SKalle Valo * But make sure to cleanup interfaces that have gone down before/during 1170e705c121SKalle Valo * HW restart was requested. 1171e705c121SKalle Valo */ 1172e705c121SKalle Valo if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1173e705c121SKalle Valo ieee80211_iterate_interfaces(mvm->hw, 0, 1174e705c121SKalle Valo iwl_mvm_cleanup_iterator, mvm); 1175e705c121SKalle Valo 1176e705c121SKalle Valo /* We shouldn't have any UIDs still set. Loop over all the UIDs to 1177e705c121SKalle Valo * make sure there's nothing left there and warn if any is found. 1178e705c121SKalle Valo */ 1179e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1180e705c121SKalle Valo int i; 1181e705c121SKalle Valo 1182e705c121SKalle Valo for (i = 0; i < mvm->max_scans; i++) { 1183e705c121SKalle Valo if (WARN_ONCE(mvm->scan_uid_status[i], 1184e705c121SKalle Valo "UMAC scan UID %d status was not cleaned\n", 1185e705c121SKalle Valo i)) 1186e705c121SKalle Valo mvm->scan_uid_status[i] = 0; 1187e705c121SKalle Valo } 1188e705c121SKalle Valo } 1189e705c121SKalle Valo } 1190e705c121SKalle Valo 1191e705c121SKalle Valo static void iwl_mvm_mac_stop(struct ieee80211_hw *hw) 1192e705c121SKalle Valo { 1193e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1194e705c121SKalle Valo 1195e705c121SKalle Valo flush_work(&mvm->d0i3_exit_work); 1196e705c121SKalle Valo flush_work(&mvm->async_handlers_wk); 119724afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 1198e705c121SKalle Valo cancel_delayed_work_sync(&mvm->fw_dump_wk); 1199e705c121SKalle Valo iwl_mvm_free_fw_dump_desc(mvm); 1200e705c121SKalle Valo 1201e705c121SKalle Valo mutex_lock(&mvm->mutex); 1202e705c121SKalle Valo __iwl_mvm_mac_stop(mvm); 1203e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1204e705c121SKalle Valo 1205e705c121SKalle Valo /* 1206e705c121SKalle Valo * The worker might have been waiting for the mutex, let it run and 1207e705c121SKalle Valo * discover that its list is now empty. 1208e705c121SKalle Valo */ 1209e705c121SKalle Valo cancel_work_sync(&mvm->async_handlers_wk); 1210e705c121SKalle Valo } 1211e705c121SKalle Valo 1212e705c121SKalle Valo static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm) 1213e705c121SKalle Valo { 1214e705c121SKalle Valo u16 i; 1215e705c121SKalle Valo 1216e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1217e705c121SKalle Valo 1218e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) 1219e705c121SKalle Valo if (!mvm->phy_ctxts[i].ref) 1220e705c121SKalle Valo return &mvm->phy_ctxts[i]; 1221e705c121SKalle Valo 1222e705c121SKalle Valo IWL_ERR(mvm, "No available PHY context\n"); 1223e705c121SKalle Valo return NULL; 1224e705c121SKalle Valo } 1225e705c121SKalle Valo 1226e705c121SKalle Valo static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 1227e705c121SKalle Valo s16 tx_power) 1228e705c121SKalle Valo { 1229e705c121SKalle Valo struct iwl_dev_tx_power_cmd cmd = { 1230e705c121SKalle Valo .v2.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC), 1231e705c121SKalle Valo .v2.mac_context_id = 1232e705c121SKalle Valo cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id), 1233e705c121SKalle Valo .v2.pwr_restriction = cpu_to_le16(8 * tx_power), 1234e705c121SKalle Valo }; 1235e705c121SKalle Valo int len = sizeof(cmd); 1236e705c121SKalle Valo 1237e705c121SKalle Valo if (tx_power == IWL_DEFAULT_MAX_TX_POWER) 1238e705c121SKalle Valo cmd.v2.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER); 1239e705c121SKalle Valo 1240e705c121SKalle Valo if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_TX_POWER_CHAIN)) 1241e705c121SKalle Valo len = sizeof(cmd.v2); 1242e705c121SKalle Valo 1243e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); 1244e705c121SKalle Valo } 1245e705c121SKalle Valo 1246e705c121SKalle Valo static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw, 1247e705c121SKalle Valo struct ieee80211_vif *vif) 1248e705c121SKalle Valo { 1249e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1250e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1251e705c121SKalle Valo int ret; 1252e705c121SKalle Valo 1253e705c121SKalle Valo mvmvif->mvm = mvm; 1254e705c121SKalle Valo 1255e705c121SKalle Valo /* 1256e705c121SKalle Valo * make sure D0i3 exit is completed, otherwise a target access 1257e705c121SKalle Valo * during tx queue configuration could be done when still in 1258e705c121SKalle Valo * D0i3 state. 1259e705c121SKalle Valo */ 1260e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF); 1261e705c121SKalle Valo if (ret) 1262e705c121SKalle Valo return ret; 1263e705c121SKalle Valo 1264e705c121SKalle Valo /* 1265e705c121SKalle Valo * Not much to do here. The stack will not allow interface 1266e705c121SKalle Valo * types or combinations that we didn't advertise, so we 1267e705c121SKalle Valo * don't really have to check the types. 1268e705c121SKalle Valo */ 1269e705c121SKalle Valo 1270e705c121SKalle Valo mutex_lock(&mvm->mutex); 1271e705c121SKalle Valo 1272e705c121SKalle Valo /* make sure that beacon statistics don't go backwards with FW reset */ 1273e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1274e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons += 1275e705c121SKalle Valo mvmvif->beacon_stats.num_beacons; 1276e705c121SKalle Valo 1277e705c121SKalle Valo /* Allocate resources for the MAC context, and add it to the fw */ 1278e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_init(mvm, vif); 1279e705c121SKalle Valo if (ret) 1280e705c121SKalle Valo goto out_unlock; 1281e705c121SKalle Valo 1282e705c121SKalle Valo /* Counting number of interfaces is needed for legacy PM */ 1283e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1284e705c121SKalle Valo mvm->vif_count++; 1285e705c121SKalle Valo 1286e705c121SKalle Valo /* 1287e705c121SKalle Valo * The AP binding flow can be done only after the beacon 1288e705c121SKalle Valo * template is configured (which happens only in the mac80211 1289e705c121SKalle Valo * start_ap() flow), and adding the broadcast station can happen 1290e705c121SKalle Valo * only after the binding. 1291e705c121SKalle Valo * In addition, since modifying the MAC before adding a bcast 1292e705c121SKalle Valo * station is not allowed by the FW, delay the adding of MAC context to 1293e705c121SKalle Valo * the point where we can also add the bcast station. 1294e705c121SKalle Valo * In short: there's not much we can do at this point, other than 1295e705c121SKalle Valo * allocating resources :) 1296e705c121SKalle Valo */ 1297e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1298e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1299e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1300e705c121SKalle Valo if (ret) { 1301e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate bcast sta\n"); 1302e705c121SKalle Valo goto out_release; 1303e705c121SKalle Valo } 1304e705c121SKalle Valo 1305e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1306e705c121SKalle Valo goto out_unlock; 1307e705c121SKalle Valo } 1308e705c121SKalle Valo 1309e705c121SKalle Valo mvmvif->features |= hw->netdev_features; 1310e705c121SKalle Valo 1311e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 1312e705c121SKalle Valo if (ret) 1313e705c121SKalle Valo goto out_release; 1314e705c121SKalle Valo 1315e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1316e705c121SKalle Valo if (ret) 1317e705c121SKalle Valo goto out_remove_mac; 1318e705c121SKalle Valo 1319e705c121SKalle Valo /* beacon filtering */ 1320e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 1321e705c121SKalle Valo if (ret) 1322e705c121SKalle Valo goto out_remove_mac; 1323e705c121SKalle Valo 1324e705c121SKalle Valo if (!mvm->bf_allowed_vif && 1325e705c121SKalle Valo vif->type == NL80211_IFTYPE_STATION && !vif->p2p) { 1326e705c121SKalle Valo mvm->bf_allowed_vif = mvmvif; 1327e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER | 1328e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI; 1329e705c121SKalle Valo } 1330e705c121SKalle Valo 1331e705c121SKalle Valo /* 1332e705c121SKalle Valo * P2P_DEVICE interface does not have a channel context assigned to it, 1333e705c121SKalle Valo * so a dedicated PHY context is allocated to it and the corresponding 1334e705c121SKalle Valo * MAC context is bound to it at this stage. 1335e705c121SKalle Valo */ 1336e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1337e705c121SKalle Valo 1338e705c121SKalle Valo mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 1339e705c121SKalle Valo if (!mvmvif->phy_ctxt) { 1340e705c121SKalle Valo ret = -ENOSPC; 1341e705c121SKalle Valo goto out_free_bf; 1342e705c121SKalle Valo } 1343e705c121SKalle Valo 1344e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 1345e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 1346e705c121SKalle Valo if (ret) 1347e705c121SKalle Valo goto out_unref_phy; 1348e705c121SKalle Valo 1349e705c121SKalle Valo ret = iwl_mvm_add_bcast_sta(mvm, vif); 1350e705c121SKalle Valo if (ret) 1351e705c121SKalle Valo goto out_unbind; 1352e705c121SKalle Valo 1353e705c121SKalle Valo /* Save a pointer to p2p device vif, so it can later be used to 1354e705c121SKalle Valo * update the p2p device MAC when a GO is started/stopped */ 1355e705c121SKalle Valo mvm->p2p_device_vif = vif; 1356e705c121SKalle Valo } 1357e705c121SKalle Valo 1358e705c121SKalle Valo iwl_mvm_vif_dbgfs_register(mvm, vif); 1359e705c121SKalle Valo goto out_unlock; 1360e705c121SKalle Valo 1361e705c121SKalle Valo out_unbind: 1362e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1363e705c121SKalle Valo out_unref_phy: 1364e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1365e705c121SKalle Valo out_free_bf: 1366e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1367e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1368e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1369e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1370e705c121SKalle Valo } 1371e705c121SKalle Valo out_remove_mac: 1372e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1373e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1374e705c121SKalle Valo out_release: 1375e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_P2P_DEVICE) 1376e705c121SKalle Valo mvm->vif_count--; 1377e705c121SKalle Valo 1378e705c121SKalle Valo iwl_mvm_mac_ctxt_release(mvm, vif); 1379e705c121SKalle Valo out_unlock: 1380e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1381e705c121SKalle Valo 1382e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF); 1383e705c121SKalle Valo 1384e705c121SKalle Valo return ret; 1385e705c121SKalle Valo } 1386e705c121SKalle Valo 1387e705c121SKalle Valo static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm, 1388e705c121SKalle Valo struct ieee80211_vif *vif) 1389e705c121SKalle Valo { 1390e705c121SKalle Valo u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif); 1391e705c121SKalle Valo 1392e705c121SKalle Valo if (tfd_msk) { 1393e705c121SKalle Valo /* 1394e705c121SKalle Valo * mac80211 first removes all the stations of the vif and 1395e705c121SKalle Valo * then removes the vif. When it removes a station it also 1396e705c121SKalle Valo * flushes the AMPDU session. So by now, all the AMPDU sessions 1397e705c121SKalle Valo * of all the stations of this vif are closed, and the queues 1398e705c121SKalle Valo * of these AMPDU sessions are properly closed. 1399e705c121SKalle Valo * We still need to take care of the shared queues of the vif. 1400e705c121SKalle Valo * Flush them here. 1401e705c121SKalle Valo */ 1402e705c121SKalle Valo mutex_lock(&mvm->mutex); 1403e705c121SKalle Valo iwl_mvm_flush_tx_path(mvm, tfd_msk, 0); 1404e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1405e705c121SKalle Valo 1406e705c121SKalle Valo /* 1407e705c121SKalle Valo * There are transports that buffer a few frames in the host. 1408e705c121SKalle Valo * For these, the flush above isn't enough since while we were 1409e705c121SKalle Valo * flushing, the transport might have sent more frames to the 1410e705c121SKalle Valo * device. To solve this, wait here until the transport is 1411e705c121SKalle Valo * empty. Technically, this could have replaced the flush 1412e705c121SKalle Valo * above, but flush is much faster than draining. So flush 1413e705c121SKalle Valo * first, and drain to make sure we have no frames in the 1414e705c121SKalle Valo * transport anymore. 1415e705c121SKalle Valo * If a station still had frames on the shared queues, it is 1416e705c121SKalle Valo * already marked as draining, so to complete the draining, we 1417e705c121SKalle Valo * just need to wait until the transport is empty. 1418e705c121SKalle Valo */ 1419e705c121SKalle Valo iwl_trans_wait_tx_queue_empty(mvm->trans, tfd_msk); 1420e705c121SKalle Valo } 1421e705c121SKalle Valo 1422e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1423e705c121SKalle Valo /* 1424e705c121SKalle Valo * Flush the ROC worker which will flush the OFFCHANNEL queue. 1425e705c121SKalle Valo * We assume here that all the packets sent to the OFFCHANNEL 1426e705c121SKalle Valo * queue are sent in ROC session. 1427e705c121SKalle Valo */ 1428e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 1429e705c121SKalle Valo } else { 1430e705c121SKalle Valo /* 1431e705c121SKalle Valo * By now, all the AC queues are empty. The AGG queues are 1432e705c121SKalle Valo * empty too. We already got all the Tx responses for all the 1433e705c121SKalle Valo * packets in the queues. The drain work can have been 1434e705c121SKalle Valo * triggered. Flush it. 1435e705c121SKalle Valo */ 1436e705c121SKalle Valo flush_work(&mvm->sta_drained_wk); 1437e705c121SKalle Valo } 1438e705c121SKalle Valo } 1439e705c121SKalle Valo 1440e705c121SKalle Valo static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw, 1441e705c121SKalle Valo struct ieee80211_vif *vif) 1442e705c121SKalle Valo { 1443e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1444e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1445e705c121SKalle Valo 1446e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 1447e705c121SKalle Valo 1448e705c121SKalle Valo mutex_lock(&mvm->mutex); 1449e705c121SKalle Valo 1450e705c121SKalle Valo if (mvm->bf_allowed_vif == mvmvif) { 1451e705c121SKalle Valo mvm->bf_allowed_vif = NULL; 1452e705c121SKalle Valo vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER | 1453e705c121SKalle Valo IEEE80211_VIF_SUPPORTS_CQM_RSSI); 1454e705c121SKalle Valo } 1455e705c121SKalle Valo 1456e705c121SKalle Valo iwl_mvm_vif_dbgfs_clean(mvm, vif); 1457e705c121SKalle Valo 1458e705c121SKalle Valo /* 1459e705c121SKalle Valo * For AP/GO interface, the tear down of the resources allocated to the 1460e705c121SKalle Valo * interface is be handled as part of the stop_ap flow. 1461e705c121SKalle Valo */ 1462e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP || 1463e705c121SKalle Valo vif->type == NL80211_IFTYPE_ADHOC) { 1464e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 1465e705c121SKalle Valo if (vif == mvm->noa_vif) { 1466e705c121SKalle Valo mvm->noa_vif = NULL; 1467e705c121SKalle Valo mvm->noa_duration = 0; 1468e705c121SKalle Valo } 1469e705c121SKalle Valo #endif 1470e705c121SKalle Valo iwl_mvm_dealloc_bcast_sta(mvm, vif); 1471e705c121SKalle Valo goto out_release; 1472e705c121SKalle Valo } 1473e705c121SKalle Valo 1474e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 1475e705c121SKalle Valo mvm->p2p_device_vif = NULL; 1476e705c121SKalle Valo iwl_mvm_rm_bcast_sta(mvm, vif); 1477e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 1478e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 1479e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 1480e705c121SKalle Valo } 1481e705c121SKalle Valo 1482e705c121SKalle Valo if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE) 1483e705c121SKalle Valo mvm->vif_count--; 1484e705c121SKalle Valo 1485e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 1486e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 1487e705c121SKalle Valo 1488e705c121SKalle Valo out_release: 1489e705c121SKalle Valo iwl_mvm_mac_ctxt_release(mvm, vif); 1490e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1491e705c121SKalle Valo } 1492e705c121SKalle Valo 1493e705c121SKalle Valo static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed) 1494e705c121SKalle Valo { 1495e705c121SKalle Valo return 0; 1496e705c121SKalle Valo } 1497e705c121SKalle Valo 1498e705c121SKalle Valo struct iwl_mvm_mc_iter_data { 1499e705c121SKalle Valo struct iwl_mvm *mvm; 1500e705c121SKalle Valo int port_id; 1501e705c121SKalle Valo }; 1502e705c121SKalle Valo 1503e705c121SKalle Valo static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac, 1504e705c121SKalle Valo struct ieee80211_vif *vif) 1505e705c121SKalle Valo { 1506e705c121SKalle Valo struct iwl_mvm_mc_iter_data *data = _data; 1507e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1508e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd; 1509e705c121SKalle Valo int ret, len; 1510e705c121SKalle Valo 1511e705c121SKalle Valo /* if we don't have free ports, mcast frames will be dropped */ 1512e705c121SKalle Valo if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM)) 1513e705c121SKalle Valo return; 1514e705c121SKalle Valo 1515e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || 1516e705c121SKalle Valo !vif->bss_conf.assoc) 1517e705c121SKalle Valo return; 1518e705c121SKalle Valo 1519e705c121SKalle Valo cmd->port_id = data->port_id++; 1520e705c121SKalle Valo memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN); 1521e705c121SKalle Valo len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4); 1522e705c121SKalle Valo 1523e705c121SKalle Valo ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd); 1524e705c121SKalle Valo if (ret) 1525e705c121SKalle Valo IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret); 1526e705c121SKalle Valo } 1527e705c121SKalle Valo 1528e705c121SKalle Valo static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm) 1529e705c121SKalle Valo { 1530e705c121SKalle Valo struct iwl_mvm_mc_iter_data iter_data = { 1531e705c121SKalle Valo .mvm = mvm, 1532e705c121SKalle Valo }; 1533e705c121SKalle Valo 1534e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1535e705c121SKalle Valo 1536e705c121SKalle Valo if (WARN_ON_ONCE(!mvm->mcast_filter_cmd)) 1537e705c121SKalle Valo return; 1538e705c121SKalle Valo 1539e705c121SKalle Valo ieee80211_iterate_active_interfaces_atomic( 1540e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1541e705c121SKalle Valo iwl_mvm_mc_iface_iterator, &iter_data); 1542e705c121SKalle Valo } 1543e705c121SKalle Valo 1544e705c121SKalle Valo static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw, 1545e705c121SKalle Valo struct netdev_hw_addr_list *mc_list) 1546e705c121SKalle Valo { 1547e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1548e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd; 1549e705c121SKalle Valo struct netdev_hw_addr *addr; 1550e705c121SKalle Valo int addr_count; 1551e705c121SKalle Valo bool pass_all; 1552e705c121SKalle Valo int len; 1553e705c121SKalle Valo 1554e705c121SKalle Valo addr_count = netdev_hw_addr_list_count(mc_list); 1555e705c121SKalle Valo pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES || 1556e705c121SKalle Valo IWL_MVM_FW_MCAST_FILTER_PASS_ALL; 1557e705c121SKalle Valo if (pass_all) 1558e705c121SKalle Valo addr_count = 0; 1559e705c121SKalle Valo 1560e705c121SKalle Valo len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4); 1561e705c121SKalle Valo cmd = kzalloc(len, GFP_ATOMIC); 1562e705c121SKalle Valo if (!cmd) 1563e705c121SKalle Valo return 0; 1564e705c121SKalle Valo 1565e705c121SKalle Valo if (pass_all) { 1566e705c121SKalle Valo cmd->pass_all = 1; 1567e705c121SKalle Valo return (u64)(unsigned long)cmd; 1568e705c121SKalle Valo } 1569e705c121SKalle Valo 1570e705c121SKalle Valo netdev_hw_addr_list_for_each(addr, mc_list) { 1571e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n", 1572e705c121SKalle Valo cmd->count, addr->addr); 1573e705c121SKalle Valo memcpy(&cmd->addr_list[cmd->count * ETH_ALEN], 1574e705c121SKalle Valo addr->addr, ETH_ALEN); 1575e705c121SKalle Valo cmd->count++; 1576e705c121SKalle Valo } 1577e705c121SKalle Valo 1578e705c121SKalle Valo return (u64)(unsigned long)cmd; 1579e705c121SKalle Valo } 1580e705c121SKalle Valo 1581e705c121SKalle Valo static void iwl_mvm_configure_filter(struct ieee80211_hw *hw, 1582e705c121SKalle Valo unsigned int changed_flags, 1583e705c121SKalle Valo unsigned int *total_flags, 1584e705c121SKalle Valo u64 multicast) 1585e705c121SKalle Valo { 1586e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1587e705c121SKalle Valo struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast; 1588e705c121SKalle Valo 1589e705c121SKalle Valo mutex_lock(&mvm->mutex); 1590e705c121SKalle Valo 1591e705c121SKalle Valo /* replace previous configuration */ 1592e705c121SKalle Valo kfree(mvm->mcast_filter_cmd); 1593e705c121SKalle Valo mvm->mcast_filter_cmd = cmd; 1594e705c121SKalle Valo 1595e705c121SKalle Valo if (!cmd) 1596e705c121SKalle Valo goto out; 1597e705c121SKalle Valo 1598e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 1599e705c121SKalle Valo out: 1600e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1601e705c121SKalle Valo *total_flags = 0; 1602e705c121SKalle Valo } 1603e705c121SKalle Valo 1604e705c121SKalle Valo static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw, 1605e705c121SKalle Valo struct ieee80211_vif *vif, 1606e705c121SKalle Valo unsigned int filter_flags, 1607e705c121SKalle Valo unsigned int changed_flags) 1608e705c121SKalle Valo { 1609e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 1610e705c121SKalle Valo 1611e705c121SKalle Valo /* We support only filter for probe requests */ 1612e705c121SKalle Valo if (!(changed_flags & FIF_PROBE_REQ)) 1613e705c121SKalle Valo return; 1614e705c121SKalle Valo 1615e705c121SKalle Valo /* Supported only for p2p client interfaces */ 1616e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc || 1617e705c121SKalle Valo !vif->p2p) 1618e705c121SKalle Valo return; 1619e705c121SKalle Valo 1620e705c121SKalle Valo mutex_lock(&mvm->mutex); 1621e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1622e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1623e705c121SKalle Valo } 1624e705c121SKalle Valo 1625e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_BCAST_FILTERING 1626e705c121SKalle Valo struct iwl_bcast_iter_data { 1627e705c121SKalle Valo struct iwl_mvm *mvm; 1628e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd; 1629e705c121SKalle Valo u8 current_filter; 1630e705c121SKalle Valo }; 1631e705c121SKalle Valo 1632e705c121SKalle Valo static void 1633e705c121SKalle Valo iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif, 1634e705c121SKalle Valo const struct iwl_fw_bcast_filter *in_filter, 1635e705c121SKalle Valo struct iwl_fw_bcast_filter *out_filter) 1636e705c121SKalle Valo { 1637e705c121SKalle Valo struct iwl_fw_bcast_filter_attr *attr; 1638e705c121SKalle Valo int i; 1639e705c121SKalle Valo 1640e705c121SKalle Valo memcpy(out_filter, in_filter, sizeof(*out_filter)); 1641e705c121SKalle Valo 1642e705c121SKalle Valo for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) { 1643e705c121SKalle Valo attr = &out_filter->attrs[i]; 1644e705c121SKalle Valo 1645e705c121SKalle Valo if (!attr->mask) 1646e705c121SKalle Valo break; 1647e705c121SKalle Valo 1648e705c121SKalle Valo switch (attr->reserved1) { 1649e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_IP): 1650e705c121SKalle Valo if (vif->bss_conf.arp_addr_cnt != 1) { 1651e705c121SKalle Valo attr->mask = 0; 1652e705c121SKalle Valo continue; 1653e705c121SKalle Valo } 1654e705c121SKalle Valo 1655e705c121SKalle Valo attr->val = vif->bss_conf.arp_addr_list[0]; 1656e705c121SKalle Valo break; 1657e705c121SKalle Valo case cpu_to_le16(BC_FILTER_MAGIC_MAC): 1658e705c121SKalle Valo attr->val = *(__be32 *)&vif->addr[2]; 1659e705c121SKalle Valo break; 1660e705c121SKalle Valo default: 1661e705c121SKalle Valo break; 1662e705c121SKalle Valo } 1663e705c121SKalle Valo attr->reserved1 = 0; 1664e705c121SKalle Valo out_filter->num_attrs++; 1665e705c121SKalle Valo } 1666e705c121SKalle Valo } 1667e705c121SKalle Valo 1668e705c121SKalle Valo static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac, 1669e705c121SKalle Valo struct ieee80211_vif *vif) 1670e705c121SKalle Valo { 1671e705c121SKalle Valo struct iwl_bcast_iter_data *data = _data; 1672e705c121SKalle Valo struct iwl_mvm *mvm = data->mvm; 1673e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd = data->cmd; 1674e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1675e705c121SKalle Valo struct iwl_fw_bcast_mac *bcast_mac; 1676e705c121SKalle Valo int i; 1677e705c121SKalle Valo 1678e705c121SKalle Valo if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs))) 1679e705c121SKalle Valo return; 1680e705c121SKalle Valo 1681e705c121SKalle Valo bcast_mac = &cmd->macs[mvmvif->id]; 1682e705c121SKalle Valo 1683e705c121SKalle Valo /* 1684e705c121SKalle Valo * enable filtering only for associated stations, but not for P2P 1685e705c121SKalle Valo * Clients 1686e705c121SKalle Valo */ 1687e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION || vif->p2p || 1688e705c121SKalle Valo !vif->bss_conf.assoc) 1689e705c121SKalle Valo return; 1690e705c121SKalle Valo 1691e705c121SKalle Valo bcast_mac->default_discard = 1; 1692e705c121SKalle Valo 1693e705c121SKalle Valo /* copy all configured filters */ 1694e705c121SKalle Valo for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) { 1695e705c121SKalle Valo /* 1696e705c121SKalle Valo * Make sure we don't exceed our filters limit. 1697e705c121SKalle Valo * if there is still a valid filter to be configured, 1698e705c121SKalle Valo * be on the safe side and just allow bcast for this mac. 1699e705c121SKalle Valo */ 1700e705c121SKalle Valo if (WARN_ON_ONCE(data->current_filter >= 1701e705c121SKalle Valo ARRAY_SIZE(cmd->filters))) { 1702e705c121SKalle Valo bcast_mac->default_discard = 0; 1703e705c121SKalle Valo bcast_mac->attached_filters = 0; 1704e705c121SKalle Valo break; 1705e705c121SKalle Valo } 1706e705c121SKalle Valo 1707e705c121SKalle Valo iwl_mvm_set_bcast_filter(vif, 1708e705c121SKalle Valo &mvm->bcast_filters[i], 1709e705c121SKalle Valo &cmd->filters[data->current_filter]); 1710e705c121SKalle Valo 1711e705c121SKalle Valo /* skip current filter if it contains no attributes */ 1712e705c121SKalle Valo if (!cmd->filters[data->current_filter].num_attrs) 1713e705c121SKalle Valo continue; 1714e705c121SKalle Valo 1715e705c121SKalle Valo /* attach the filter to current mac */ 1716e705c121SKalle Valo bcast_mac->attached_filters |= 1717e705c121SKalle Valo cpu_to_le16(BIT(data->current_filter)); 1718e705c121SKalle Valo 1719e705c121SKalle Valo data->current_filter++; 1720e705c121SKalle Valo } 1721e705c121SKalle Valo } 1722e705c121SKalle Valo 1723e705c121SKalle Valo bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm, 1724e705c121SKalle Valo struct iwl_bcast_filter_cmd *cmd) 1725e705c121SKalle Valo { 1726e705c121SKalle Valo struct iwl_bcast_iter_data iter_data = { 1727e705c121SKalle Valo .mvm = mvm, 1728e705c121SKalle Valo .cmd = cmd, 1729e705c121SKalle Valo }; 1730e705c121SKalle Valo 1731e705c121SKalle Valo if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL) 1732e705c121SKalle Valo return false; 1733e705c121SKalle Valo 1734e705c121SKalle Valo memset(cmd, 0, sizeof(*cmd)); 1735e705c121SKalle Valo cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters); 1736e705c121SKalle Valo cmd->max_macs = ARRAY_SIZE(cmd->macs); 1737e705c121SKalle Valo 1738e705c121SKalle Valo #ifdef CONFIG_IWLWIFI_DEBUGFS 1739e705c121SKalle Valo /* use debugfs filters/macs if override is configured */ 1740e705c121SKalle Valo if (mvm->dbgfs_bcast_filtering.override) { 1741e705c121SKalle Valo memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters, 1742e705c121SKalle Valo sizeof(cmd->filters)); 1743e705c121SKalle Valo memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs, 1744e705c121SKalle Valo sizeof(cmd->macs)); 1745e705c121SKalle Valo return true; 1746e705c121SKalle Valo } 1747e705c121SKalle Valo #endif 1748e705c121SKalle Valo 1749e705c121SKalle Valo /* if no filters are configured, do nothing */ 1750e705c121SKalle Valo if (!mvm->bcast_filters) 1751e705c121SKalle Valo return false; 1752e705c121SKalle Valo 1753e705c121SKalle Valo /* configure and attach these filters for each associated sta vif */ 1754e705c121SKalle Valo ieee80211_iterate_active_interfaces( 1755e705c121SKalle Valo mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1756e705c121SKalle Valo iwl_mvm_bcast_filter_iterator, &iter_data); 1757e705c121SKalle Valo 1758e705c121SKalle Valo return true; 1759e705c121SKalle Valo } 176034672bb3SEliad Peller 176134672bb3SEliad Peller static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1762e705c121SKalle Valo { 1763e705c121SKalle Valo struct iwl_bcast_filter_cmd cmd; 1764e705c121SKalle Valo 1765e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING)) 1766e705c121SKalle Valo return 0; 1767e705c121SKalle Valo 1768e705c121SKalle Valo if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd)) 1769e705c121SKalle Valo return 0; 1770e705c121SKalle Valo 1771e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0, 1772e705c121SKalle Valo sizeof(cmd), &cmd); 1773e705c121SKalle Valo } 1774e705c121SKalle Valo #else 177534672bb3SEliad Peller static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm) 1776e705c121SKalle Valo { 1777e705c121SKalle Valo return 0; 1778e705c121SKalle Valo } 1779e705c121SKalle Valo #endif 1780e705c121SKalle Valo 1781a07a8f37SSara Sharon static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, 1782a07a8f37SSara Sharon struct ieee80211_vif *vif) 1783a07a8f37SSara Sharon { 1784a07a8f37SSara Sharon struct iwl_mu_group_mgmt_cmd cmd = {}; 1785a07a8f37SSara Sharon 1786a07a8f37SSara Sharon memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership, 1787a07a8f37SSara Sharon WLAN_MEMBERSHIP_LEN); 1788a07a8f37SSara Sharon memcpy(cmd.user_position, vif->bss_conf.mu_group.position, 1789a07a8f37SSara Sharon WLAN_USER_POSITION_LEN); 1790a07a8f37SSara Sharon 1791a07a8f37SSara Sharon return iwl_mvm_send_cmd_pdu(mvm, 1792a07a8f37SSara Sharon WIDE_ID(DATA_PATH_GROUP, 1793a07a8f37SSara Sharon UPDATE_MU_GROUPS_CMD), 1794a07a8f37SSara Sharon 0, sizeof(cmd), &cmd); 1795a07a8f37SSara Sharon } 1796a07a8f37SSara Sharon 1797f92659a1SSara Sharon static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac, 1798f92659a1SSara Sharon struct ieee80211_vif *vif) 1799f92659a1SSara Sharon { 1800f92659a1SSara Sharon if (vif->mu_mimo_owner) { 1801f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = _data; 1802f92659a1SSara Sharon 1803f92659a1SSara Sharon /* 1804f92659a1SSara Sharon * MU-MIMO Group Id action frame is little endian. We treat 1805f92659a1SSara Sharon * the data received from firmware as if it came from the 1806f92659a1SSara Sharon * action frame, so no conversion is needed. 1807f92659a1SSara Sharon */ 1808f92659a1SSara Sharon ieee80211_update_mu_groups(vif, 1809f92659a1SSara Sharon (u8 *)¬if->membership_status, 1810f92659a1SSara Sharon (u8 *)¬if->user_position); 1811f92659a1SSara Sharon } 1812f92659a1SSara Sharon } 1813f92659a1SSara Sharon 1814f92659a1SSara Sharon void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm, 1815f92659a1SSara Sharon struct iwl_rx_cmd_buffer *rxb) 1816f92659a1SSara Sharon { 1817f92659a1SSara Sharon struct iwl_rx_packet *pkt = rxb_addr(rxb); 1818f92659a1SSara Sharon struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data; 1819f92659a1SSara Sharon 1820f92659a1SSara Sharon ieee80211_iterate_active_interfaces_atomic( 1821f92659a1SSara Sharon mvm->hw, IEEE80211_IFACE_ITER_NORMAL, 1822f92659a1SSara Sharon iwl_mvm_mu_mimo_iface_iterator, notif); 1823f92659a1SSara Sharon } 1824f92659a1SSara Sharon 1825e705c121SKalle Valo static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm, 1826e705c121SKalle Valo struct ieee80211_vif *vif, 1827e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 1828e705c121SKalle Valo u32 changes) 1829e705c121SKalle Valo { 1830e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1831e705c121SKalle Valo int ret; 1832e705c121SKalle Valo 1833e705c121SKalle Valo /* 1834e705c121SKalle Valo * Re-calculate the tsf id, as the master-slave relations depend on the 1835e705c121SKalle Valo * beacon interval, which was not known when the station interface was 1836e705c121SKalle Valo * added. 1837e705c121SKalle Valo */ 1838e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) 1839e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 1840e705c121SKalle Valo 184103098268SAviya Erenfeld if (changes & BSS_CHANGED_ASSOC && !bss_conf->assoc && 184203098268SAviya Erenfeld mvmvif->lqm_active) 184303098268SAviya Erenfeld iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_STOP_MEASUREMENT, 184403098268SAviya Erenfeld 0, 0); 184503098268SAviya Erenfeld 1846e705c121SKalle Valo /* 1847e705c121SKalle Valo * If we're not associated yet, take the (new) BSSID before associating 1848e705c121SKalle Valo * so the firmware knows. If we're already associated, then use the old 1849e705c121SKalle Valo * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC 1850e705c121SKalle Valo * branch for disassociation below. 1851e705c121SKalle Valo */ 1852e705c121SKalle Valo if (changes & BSS_CHANGED_BSSID && !mvmvif->associated) 1853e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 1854e705c121SKalle Valo 1855e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid); 1856e705c121SKalle Valo if (ret) 1857e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 1858e705c121SKalle Valo 1859e705c121SKalle Valo /* after sending it once, adopt mac80211 data */ 1860e705c121SKalle Valo memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN); 1861e705c121SKalle Valo mvmvif->associated = bss_conf->assoc; 1862e705c121SKalle Valo 1863e705c121SKalle Valo if (changes & BSS_CHANGED_ASSOC) { 1864e705c121SKalle Valo if (bss_conf->assoc) { 1865e705c121SKalle Valo /* clear statistics to get clean beacon counter */ 1866e705c121SKalle Valo iwl_mvm_request_statistics(mvm, true); 1867e705c121SKalle Valo memset(&mvmvif->beacon_stats, 0, 1868e705c121SKalle Valo sizeof(mvmvif->beacon_stats)); 1869e705c121SKalle Valo 1870e705c121SKalle Valo /* add quota for this interface */ 1871e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, true, NULL); 1872e705c121SKalle Valo if (ret) { 1873e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 1874e705c121SKalle Valo return; 1875e705c121SKalle Valo } 1876e705c121SKalle Valo 1877e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, 1878e705c121SKalle Valo &mvm->status)) { 1879e705c121SKalle Valo /* 1880e705c121SKalle Valo * If we're restarting then the firmware will 1881e705c121SKalle Valo * obviously have lost synchronisation with 1882e705c121SKalle Valo * the AP. It will attempt to synchronise by 1883e705c121SKalle Valo * itself, but we can make it more reliable by 1884e705c121SKalle Valo * scheduling a session protection time event. 1885e705c121SKalle Valo * 1886e705c121SKalle Valo * The firmware needs to receive a beacon to 1887e705c121SKalle Valo * catch up with synchronisation, use 110% of 1888e705c121SKalle Valo * the beacon interval. 1889e705c121SKalle Valo * 1890e705c121SKalle Valo * Set a large maximum delay to allow for more 1891e705c121SKalle Valo * than a single interface. 1892e705c121SKalle Valo */ 1893e705c121SKalle Valo u32 dur = (11 * vif->bss_conf.beacon_int) / 10; 1894e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, dur, dur, 1895e705c121SKalle Valo 5 * dur, false); 1896e705c121SKalle Valo } 1897e705c121SKalle Valo 1898e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 1899e705c121SKalle Valo iwl_mvm_power_vif_assoc(mvm, vif); 1900e705c121SKalle Valo if (vif->p2p) { 1901e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT); 1902e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, 1903e705c121SKalle Valo IWL_MVM_SMPS_REQ_PROT, 1904e705c121SKalle Valo IEEE80211_SMPS_DYNAMIC); 1905e705c121SKalle Valo } 1906e705c121SKalle Valo } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { 1907e705c121SKalle Valo /* 1908e705c121SKalle Valo * If update fails - SF might be running in associated 1909e705c121SKalle Valo * mode while disassociated - which is forbidden. 1910e705c121SKalle Valo */ 1911e705c121SKalle Valo WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false), 1912e705c121SKalle Valo "Failed to update SF upon disassociation\n"); 1913e705c121SKalle Valo 1914e705c121SKalle Valo /* remove AP station now that the MAC is unassoc */ 1915e705c121SKalle Valo ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id); 1916e705c121SKalle Valo if (ret) 1917e705c121SKalle Valo IWL_ERR(mvm, "failed to remove AP station\n"); 1918e705c121SKalle Valo 1919e705c121SKalle Valo if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id) 1920e705c121SKalle Valo mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; 1921e705c121SKalle Valo mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; 1922e705c121SKalle Valo /* remove quota for this interface */ 1923e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 1924e705c121SKalle Valo if (ret) 1925e705c121SKalle Valo IWL_ERR(mvm, "failed to update quotas\n"); 1926e705c121SKalle Valo 1927e705c121SKalle Valo if (vif->p2p) 1928e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT); 1929e705c121SKalle Valo 1930e705c121SKalle Valo /* this will take the cleared BSSID from bss_conf */ 1931e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 1932e705c121SKalle Valo if (ret) 1933e705c121SKalle Valo IWL_ERR(mvm, 1934e705c121SKalle Valo "failed to update MAC %pM (clear after unassoc)\n", 1935e705c121SKalle Valo vif->addr); 1936e705c121SKalle Valo } 1937e705c121SKalle Valo 1938a07a8f37SSara Sharon /* 1939a07a8f37SSara Sharon * The firmware tracks the MU-MIMO group on its own. 1940f92659a1SSara Sharon * However, on HW restart we should restore this data. 1941a07a8f37SSara Sharon */ 1942a07a8f37SSara Sharon if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 1943f92659a1SSara Sharon (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) { 1944a07a8f37SSara Sharon ret = iwl_mvm_update_mu_groups(mvm, vif); 1945a07a8f37SSara Sharon if (ret) 1946a07a8f37SSara Sharon IWL_ERR(mvm, 1947a07a8f37SSara Sharon "failed to update VHT MU_MIMO groups\n"); 1948a07a8f37SSara Sharon } 1949a07a8f37SSara Sharon 1950e705c121SKalle Valo iwl_mvm_recalc_multicast(mvm); 195134672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 1952e705c121SKalle Valo 1953e705c121SKalle Valo /* reset rssi values */ 1954e705c121SKalle Valo mvmvif->bf_data.ave_beacon_signal = 0; 1955e705c121SKalle Valo 1956e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 1957e705c121SKalle Valo iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT, 1958e705c121SKalle Valo IEEE80211_SMPS_AUTOMATIC); 1959355346baSAvraham Stern if (fw_has_capa(&mvm->fw->ucode_capa, 1960355346baSAvraham Stern IWL_UCODE_TLV_CAPA_UMAC_SCAN)) 1961355346baSAvraham Stern iwl_mvm_config_scan(mvm); 1962e705c121SKalle Valo } else if (changes & BSS_CHANGED_BEACON_INFO) { 1963e705c121SKalle Valo /* 1964e705c121SKalle Valo * We received a beacon _after_ association so 1965e705c121SKalle Valo * remove the session protection. 1966e705c121SKalle Valo */ 1967e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 1968e705c121SKalle Valo &mvmvif->time_event_data); 1969e705c121SKalle Valo } 1970e705c121SKalle Valo 1971e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON_INFO) { 1972e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 1973e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 1974e705c121SKalle Valo } 1975e705c121SKalle Valo 1976283115fbSAvri Altman if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | 1977283115fbSAvri Altman /* 1978283115fbSAvri Altman * Send power command on every beacon change, 1979283115fbSAvri Altman * because we may have not enabled beacon abort yet. 1980283115fbSAvri Altman */ 1981283115fbSAvri Altman BSS_CHANGED_BEACON_INFO)) { 1982e705c121SKalle Valo ret = iwl_mvm_power_update_mac(mvm); 1983e705c121SKalle Valo if (ret) 1984e705c121SKalle Valo IWL_ERR(mvm, "failed to update power mode\n"); 1985e705c121SKalle Valo } 1986e705c121SKalle Valo 1987e705c121SKalle Valo if (changes & BSS_CHANGED_TXPOWER) { 1988e705c121SKalle Valo IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", 1989e705c121SKalle Valo bss_conf->txpower); 1990e705c121SKalle Valo iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 1991e705c121SKalle Valo } 1992e705c121SKalle Valo 1993e705c121SKalle Valo if (changes & BSS_CHANGED_CQM) { 1994e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n"); 1995e705c121SKalle Valo /* reset cqm events tracking */ 1996e705c121SKalle Valo mvmvif->bf_data.last_cqm_event = 0; 1997e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 1998e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 1999e705c121SKalle Valo if (ret) 2000e705c121SKalle Valo IWL_ERR(mvm, 2001e705c121SKalle Valo "failed to update CQM thresholds\n"); 2002e705c121SKalle Valo } 2003e705c121SKalle Valo } 2004e705c121SKalle Valo 2005e705c121SKalle Valo if (changes & BSS_CHANGED_ARP_FILTER) { 2006e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "arp filter changed\n"); 200734672bb3SEliad Peller iwl_mvm_configure_bcast_filter(mvm); 2008e705c121SKalle Valo } 2009e705c121SKalle Valo } 2010e705c121SKalle Valo 2011e705c121SKalle Valo static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw, 2012e705c121SKalle Valo struct ieee80211_vif *vif) 2013e705c121SKalle Valo { 2014e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2015e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2016e705c121SKalle Valo int ret; 2017e705c121SKalle Valo 2018e705c121SKalle Valo /* 2019e705c121SKalle Valo * iwl_mvm_mac_ctxt_add() might read directly from the device 2020e705c121SKalle Valo * (the system time), so make sure it is available. 2021e705c121SKalle Valo */ 2022e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP); 2023e705c121SKalle Valo if (ret) 2024e705c121SKalle Valo return ret; 2025e705c121SKalle Valo 2026e705c121SKalle Valo mutex_lock(&mvm->mutex); 2027e705c121SKalle Valo 2028e705c121SKalle Valo /* Send the beacon template */ 2029e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif); 2030e705c121SKalle Valo if (ret) 2031e705c121SKalle Valo goto out_unlock; 2032e705c121SKalle Valo 2033e705c121SKalle Valo /* 2034e705c121SKalle Valo * Re-calculate the tsf id, as the master-slave relations depend on the 2035e705c121SKalle Valo * beacon interval, which was not known when the AP interface was added. 2036e705c121SKalle Valo */ 2037e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) 2038e705c121SKalle Valo iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif); 2039e705c121SKalle Valo 2040e705c121SKalle Valo mvmvif->ap_assoc_sta_count = 0; 2041e705c121SKalle Valo 2042e705c121SKalle Valo /* Add the mac context */ 2043e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_add(mvm, vif); 2044e705c121SKalle Valo if (ret) 2045e705c121SKalle Valo goto out_unlock; 2046e705c121SKalle Valo 2047e705c121SKalle Valo /* Perform the binding */ 2048e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 2049e705c121SKalle Valo if (ret) 2050e705c121SKalle Valo goto out_remove; 2051e705c121SKalle Valo 2052e705c121SKalle Valo /* Send the bcast station. At this stage the TBTT and DTIM time events 2053e705c121SKalle Valo * are added and applied to the scheduler */ 2054e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 2055e705c121SKalle Valo if (ret) 2056e705c121SKalle Valo goto out_unbind; 2057e705c121SKalle Valo 2058e705c121SKalle Valo /* must be set before quota calculations */ 2059e705c121SKalle Valo mvmvif->ap_ibss_active = true; 2060e705c121SKalle Valo 2061e705c121SKalle Valo /* power updated needs to be done before quotas */ 2062e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2063e705c121SKalle Valo 2064e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 2065e705c121SKalle Valo if (ret) 2066e705c121SKalle Valo goto out_quota_failed; 2067e705c121SKalle Valo 2068e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2069e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2070e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2071e705c121SKalle Valo 2072e705c121SKalle Valo iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS); 2073e705c121SKalle Valo 2074e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2075e705c121SKalle Valo 2076e705c121SKalle Valo /* we don't support TDLS during DCM */ 2077e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2078e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2079e705c121SKalle Valo 2080e705c121SKalle Valo goto out_unlock; 2081e705c121SKalle Valo 2082e705c121SKalle Valo out_quota_failed: 2083e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2084e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2085e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2086e705c121SKalle Valo out_unbind: 2087e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2088e705c121SKalle Valo out_remove: 2089e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2090e705c121SKalle Valo out_unlock: 2091e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2092e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP); 2093e705c121SKalle Valo return ret; 2094e705c121SKalle Valo } 2095e705c121SKalle Valo 2096e705c121SKalle Valo static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw, 2097e705c121SKalle Valo struct ieee80211_vif *vif) 2098e705c121SKalle Valo { 2099e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2100e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2101e705c121SKalle Valo 2102e705c121SKalle Valo iwl_mvm_prepare_mac_removal(mvm, vif); 2103e705c121SKalle Valo 2104e705c121SKalle Valo mutex_lock(&mvm->mutex); 2105e705c121SKalle Valo 2106e705c121SKalle Valo /* Handle AP stop while in CSA */ 2107e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_vif) == vif) { 2108e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, 2109e705c121SKalle Valo &mvmvif->time_event_data); 2110e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_vif, NULL); 2111e705c121SKalle Valo mvmvif->csa_countdown = false; 2112e705c121SKalle Valo } 2113e705c121SKalle Valo 2114e705c121SKalle Valo if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) { 2115e705c121SKalle Valo RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2116e705c121SKalle Valo mvm->csa_tx_block_bcn_timeout = 0; 2117e705c121SKalle Valo } 2118e705c121SKalle Valo 2119e705c121SKalle Valo mvmvif->ap_ibss_active = false; 2120e705c121SKalle Valo mvm->ap_last_beacon_gp2 = 0; 2121e705c121SKalle Valo 2122e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 2123e705c121SKalle Valo 2124e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS); 2125e705c121SKalle Valo 2126e705c121SKalle Valo /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ 2127e705c121SKalle Valo if (vif->p2p && mvm->p2p_device_vif) 2128e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL); 2129e705c121SKalle Valo 2130e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 2131e705c121SKalle Valo iwl_mvm_send_rm_bcast_sta(mvm, vif); 2132e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 2133e705c121SKalle Valo 2134e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 2135e705c121SKalle Valo 2136e705c121SKalle Valo iwl_mvm_mac_ctxt_remove(mvm, vif); 2137e705c121SKalle Valo 2138e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2139e705c121SKalle Valo } 2140e705c121SKalle Valo 2141e705c121SKalle Valo static void 2142e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm, 2143e705c121SKalle Valo struct ieee80211_vif *vif, 2144e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2145e705c121SKalle Valo u32 changes) 2146e705c121SKalle Valo { 2147e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2148e705c121SKalle Valo 2149e705c121SKalle Valo /* Changes will be applied when the AP/IBSS is started */ 2150e705c121SKalle Valo if (!mvmvif->ap_ibss_active) 2151e705c121SKalle Valo return; 2152e705c121SKalle Valo 2153e705c121SKalle Valo if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT | 2154e705c121SKalle Valo BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) && 2155e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL)) 2156e705c121SKalle Valo IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr); 2157e705c121SKalle Valo 2158e705c121SKalle Valo /* Need to send a new beacon template to the FW */ 2159e705c121SKalle Valo if (changes & BSS_CHANGED_BEACON && 2160e705c121SKalle Valo iwl_mvm_mac_ctxt_beacon_changed(mvm, vif)) 2161e705c121SKalle Valo IWL_WARN(mvm, "Failed updating beacon data\n"); 2162e705c121SKalle Valo 2163e705c121SKalle Valo if (changes & BSS_CHANGED_TXPOWER) { 2164e705c121SKalle Valo IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n", 2165e705c121SKalle Valo bss_conf->txpower); 2166e705c121SKalle Valo iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower); 2167e705c121SKalle Valo } 2168e705c121SKalle Valo } 2169e705c121SKalle Valo 2170e705c121SKalle Valo static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw, 2171e705c121SKalle Valo struct ieee80211_vif *vif, 2172e705c121SKalle Valo struct ieee80211_bss_conf *bss_conf, 2173e705c121SKalle Valo u32 changes) 2174e705c121SKalle Valo { 2175e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2176e705c121SKalle Valo 2177e705c121SKalle Valo /* 2178e705c121SKalle Valo * iwl_mvm_bss_info_changed_station() might call 2179e705c121SKalle Valo * iwl_mvm_protect_session(), which reads directly from 2180e705c121SKalle Valo * the device (the system time), so make sure it is available. 2181e705c121SKalle Valo */ 2182e705c121SKalle Valo if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED)) 2183e705c121SKalle Valo return; 2184e705c121SKalle Valo 2185e705c121SKalle Valo mutex_lock(&mvm->mutex); 2186e705c121SKalle Valo 2187e705c121SKalle Valo if (changes & BSS_CHANGED_IDLE && !bss_conf->idle) 2188e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); 2189e705c121SKalle Valo 2190e705c121SKalle Valo switch (vif->type) { 2191e705c121SKalle Valo case NL80211_IFTYPE_STATION: 2192e705c121SKalle Valo iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes); 2193e705c121SKalle Valo break; 2194e705c121SKalle Valo case NL80211_IFTYPE_AP: 2195e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 2196e705c121SKalle Valo iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes); 2197e705c121SKalle Valo break; 2198e705c121SKalle Valo default: 2199e705c121SKalle Valo /* shouldn't happen */ 2200e705c121SKalle Valo WARN_ON_ONCE(1); 2201e705c121SKalle Valo } 2202e705c121SKalle Valo 2203e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2204e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED); 2205e705c121SKalle Valo } 2206e705c121SKalle Valo 2207e705c121SKalle Valo static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, 2208e705c121SKalle Valo struct ieee80211_vif *vif, 2209e705c121SKalle Valo struct ieee80211_scan_request *hw_req) 2210e705c121SKalle Valo { 2211e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2212e705c121SKalle Valo int ret; 2213e705c121SKalle Valo 2214e705c121SKalle Valo if (hw_req->req.n_channels == 0 || 2215e705c121SKalle Valo hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) 2216e705c121SKalle Valo return -EINVAL; 2217e705c121SKalle Valo 2218e705c121SKalle Valo mutex_lock(&mvm->mutex); 2219e705c121SKalle Valo ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies); 2220e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2221e705c121SKalle Valo 2222e705c121SKalle Valo return ret; 2223e705c121SKalle Valo } 2224e705c121SKalle Valo 2225e705c121SKalle Valo static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw, 2226e705c121SKalle Valo struct ieee80211_vif *vif) 2227e705c121SKalle Valo { 2228e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2229e705c121SKalle Valo 2230e705c121SKalle Valo mutex_lock(&mvm->mutex); 2231e705c121SKalle Valo 2232e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 2233e705c121SKalle Valo * us to stop a hw_scan when it's already stopped. This can 2234e705c121SKalle Valo * happen, for instance, if we stopped the scan ourselves, 2235e705c121SKalle Valo * called ieee80211_scan_completed() and the userspace called 2236e705c121SKalle Valo * cancel scan scan before ieee80211_scan_work() could run. 2237e705c121SKalle Valo * To handle that, simply return if the scan is not running. 2238e705c121SKalle Valo */ 2239e705c121SKalle Valo if (mvm->scan_status & IWL_MVM_SCAN_REGULAR) 2240e705c121SKalle Valo iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); 2241e705c121SKalle Valo 2242e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2243e705c121SKalle Valo } 2244e705c121SKalle Valo 2245e705c121SKalle Valo static void 2246e705c121SKalle Valo iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw, 2247e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2248e705c121SKalle Valo int num_frames, 2249e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2250e705c121SKalle Valo bool more_data) 2251e705c121SKalle Valo { 2252e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2253e705c121SKalle Valo 2254e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from mac80211 */ 2255e705c121SKalle Valo 2256e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2257e705c121SKalle Valo tids, more_data, false); 2258e705c121SKalle Valo } 2259e705c121SKalle Valo 2260e705c121SKalle Valo static void 2261e705c121SKalle Valo iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw, 2262e705c121SKalle Valo struct ieee80211_sta *sta, u16 tids, 2263e705c121SKalle Valo int num_frames, 2264e705c121SKalle Valo enum ieee80211_frame_release_type reason, 2265e705c121SKalle Valo bool more_data) 2266e705c121SKalle Valo { 2267e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2268e705c121SKalle Valo 2269e705c121SKalle Valo /* Called when we need to transmit (a) frame(s) from agg queue */ 2270e705c121SKalle Valo 2271e705c121SKalle Valo iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames, 2272e705c121SKalle Valo tids, more_data, true); 2273e705c121SKalle Valo } 2274e705c121SKalle Valo 2275e705c121SKalle Valo static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, 2276e705c121SKalle Valo struct ieee80211_vif *vif, 2277e705c121SKalle Valo enum sta_notify_cmd cmd, 2278e705c121SKalle Valo struct ieee80211_sta *sta) 2279e705c121SKalle Valo { 2280e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2281e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2282e705c121SKalle Valo unsigned long txqs = 0, tids = 0; 2283e705c121SKalle Valo int tid; 2284e705c121SKalle Valo 2285e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2286e705c121SKalle Valo for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 2287e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2288e705c121SKalle Valo 2289e705c121SKalle Valo if (tid_data->state != IWL_AGG_ON && 2290e705c121SKalle Valo tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA) 2291e705c121SKalle Valo continue; 2292e705c121SKalle Valo 2293e705c121SKalle Valo __set_bit(tid_data->txq_id, &txqs); 2294e705c121SKalle Valo 2295e705c121SKalle Valo if (iwl_mvm_tid_queued(tid_data) == 0) 2296e705c121SKalle Valo continue; 2297e705c121SKalle Valo 2298e705c121SKalle Valo __set_bit(tid, &tids); 2299e705c121SKalle Valo } 2300e705c121SKalle Valo 2301e705c121SKalle Valo switch (cmd) { 2302e705c121SKalle Valo case STA_NOTIFY_SLEEP: 2303e705c121SKalle Valo if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0) 2304e705c121SKalle Valo ieee80211_sta_block_awake(hw, sta, true); 2305e705c121SKalle Valo 2306e705c121SKalle Valo for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT) 2307e705c121SKalle Valo ieee80211_sta_set_buffered(sta, tid, true); 2308e705c121SKalle Valo 2309e705c121SKalle Valo if (txqs) 2310e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); 2311e705c121SKalle Valo /* 2312e705c121SKalle Valo * The fw updates the STA to be asleep. Tx packets on the Tx 2313e705c121SKalle Valo * queues to this station will not be transmitted. The fw will 2314e705c121SKalle Valo * send a Tx response with TX_STATUS_FAIL_DEST_PS. 2315e705c121SKalle Valo */ 2316e705c121SKalle Valo break; 2317e705c121SKalle Valo case STA_NOTIFY_AWAKE: 2318e705c121SKalle Valo if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT)) 2319e705c121SKalle Valo break; 2320e705c121SKalle Valo 2321e705c121SKalle Valo if (txqs) 2322e705c121SKalle Valo iwl_trans_freeze_txq_timer(mvm->trans, txqs, false); 2323e705c121SKalle Valo iwl_mvm_sta_modify_ps_wake(mvm, sta); 2324e705c121SKalle Valo break; 2325e705c121SKalle Valo default: 2326e705c121SKalle Valo break; 2327e705c121SKalle Valo } 2328e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2329e705c121SKalle Valo } 2330e705c121SKalle Valo 2331e705c121SKalle Valo static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw, 2332e705c121SKalle Valo struct ieee80211_vif *vif, 2333e705c121SKalle Valo struct ieee80211_sta *sta) 2334e705c121SKalle Valo { 2335e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2336e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2337e705c121SKalle Valo 2338e705c121SKalle Valo /* 2339e705c121SKalle Valo * This is called before mac80211 does RCU synchronisation, 2340e705c121SKalle Valo * so here we already invalidate our internal RCU-protected 2341e705c121SKalle Valo * station pointer. The rest of the code will thus no longer 2342e705c121SKalle Valo * be able to find the station this way, and we don't rely 2343e705c121SKalle Valo * on further RCU synchronisation after the sta_state() 2344e705c121SKalle Valo * callback deleted the station. 2345e705c121SKalle Valo */ 2346e705c121SKalle Valo mutex_lock(&mvm->mutex); 2347e705c121SKalle Valo if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id])) 2348e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], 2349e705c121SKalle Valo ERR_PTR(-ENOENT)); 2350e705c121SKalle Valo 2351e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2352e705c121SKalle Valo } 2353e705c121SKalle Valo 2354e705c121SKalle Valo static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2355e705c121SKalle Valo const u8 *bssid) 2356e705c121SKalle Valo { 2357e705c121SKalle Valo if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT)) 2358e705c121SKalle Valo return; 2359e705c121SKalle Valo 2360cee5a882SAvri Altman if (vif->p2p && !iwl_mvm_is_p2p_standalone_uapsd_supported(mvm)) { 2361cee5a882SAvri Altman vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2362cee5a882SAvri Altman return; 2363cee5a882SAvri Altman } 2364cee5a882SAvri Altman 236511dee0b4SEmmanuel Grumbach if (!vif->p2p && 236611dee0b4SEmmanuel Grumbach (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) { 2367e705c121SKalle Valo vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; 2368e705c121SKalle Valo return; 2369e705c121SKalle Valo } 2370e705c121SKalle Valo 2371e705c121SKalle Valo vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD; 2372e705c121SKalle Valo } 2373e705c121SKalle Valo 23741e8f1329SGolan Ben-Ami static void 23751e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm, 23761e8f1329SGolan Ben-Ami struct ieee80211_vif *vif, u8 *peer_addr, 23771e8f1329SGolan Ben-Ami enum nl80211_tdls_operation action) 23781e8f1329SGolan Ben-Ami { 23791e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tlv *trig; 23801e8f1329SGolan Ben-Ami struct iwl_fw_dbg_trigger_tdls *tdls_trig; 23811e8f1329SGolan Ben-Ami 23821e8f1329SGolan Ben-Ami if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS)) 23831e8f1329SGolan Ben-Ami return; 23841e8f1329SGolan Ben-Ami 23851e8f1329SGolan Ben-Ami trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS); 23861e8f1329SGolan Ben-Ami tdls_trig = (void *)trig->data; 23871e8f1329SGolan Ben-Ami if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 23881e8f1329SGolan Ben-Ami return; 23891e8f1329SGolan Ben-Ami 23901e8f1329SGolan Ben-Ami if (!(tdls_trig->action_bitmap & BIT(action))) 23911e8f1329SGolan Ben-Ami return; 23921e8f1329SGolan Ben-Ami 23931e8f1329SGolan Ben-Ami if (tdls_trig->peer_mode && 23941e8f1329SGolan Ben-Ami memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0) 23951e8f1329SGolan Ben-Ami return; 23961e8f1329SGolan Ben-Ami 23971e8f1329SGolan Ben-Ami iwl_mvm_fw_dbg_collect_trig(mvm, trig, 23981e8f1329SGolan Ben-Ami "TDLS event occurred, peer %pM, action %d", 23991e8f1329SGolan Ben-Ami peer_addr, action); 24001e8f1329SGolan Ben-Ami } 24011e8f1329SGolan Ben-Ami 240224afba76SLiad Kaufman static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm, 240324afba76SLiad Kaufman struct iwl_mvm_sta *mvm_sta) 240424afba76SLiad Kaufman { 240524afba76SLiad Kaufman struct iwl_mvm_tid_data *tid_data; 240624afba76SLiad Kaufman struct sk_buff *skb; 240724afba76SLiad Kaufman int i; 240824afba76SLiad Kaufman 240924afba76SLiad Kaufman spin_lock_bh(&mvm_sta->lock); 241024afba76SLiad Kaufman for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { 241124afba76SLiad Kaufman tid_data = &mvm_sta->tid_data[i]; 241224afba76SLiad Kaufman while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) 241324afba76SLiad Kaufman ieee80211_free_txskb(mvm->hw, skb); 241424afba76SLiad Kaufman } 241524afba76SLiad Kaufman spin_unlock_bh(&mvm_sta->lock); 241624afba76SLiad Kaufman } 241724afba76SLiad Kaufman 2418e705c121SKalle Valo static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw, 2419e705c121SKalle Valo struct ieee80211_vif *vif, 2420e705c121SKalle Valo struct ieee80211_sta *sta, 2421e705c121SKalle Valo enum ieee80211_sta_state old_state, 2422e705c121SKalle Valo enum ieee80211_sta_state new_state) 2423e705c121SKalle Valo { 2424e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2425e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2426e705c121SKalle Valo int ret; 2427e705c121SKalle Valo 2428e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n", 2429e705c121SKalle Valo sta->addr, old_state, new_state); 2430e705c121SKalle Valo 2431e705c121SKalle Valo /* this would be a mac80211 bug ... but don't crash */ 2432e705c121SKalle Valo if (WARN_ON_ONCE(!mvmvif->phy_ctxt)) 2433e705c121SKalle Valo return -EINVAL; 2434e705c121SKalle Valo 2435e705c121SKalle Valo /* if a STA is being removed, reuse its ID */ 2436e705c121SKalle Valo flush_work(&mvm->sta_drained_wk); 2437e705c121SKalle Valo 243824afba76SLiad Kaufman /* 243924afba76SLiad Kaufman * If we are in a STA removal flow and in DQA mode: 244024afba76SLiad Kaufman * 244124afba76SLiad Kaufman * This is after the sync_rcu part, so the queues have already been 244224afba76SLiad Kaufman * flushed. No more TXs on their way in mac80211's path, and no more in 244324afba76SLiad Kaufman * the queues. 244424afba76SLiad Kaufman * Also, we won't be getting any new TX frames for this station. 244524afba76SLiad Kaufman * What we might have are deferred TX frames that need to be taken care 244624afba76SLiad Kaufman * of. 244724afba76SLiad Kaufman * 244824afba76SLiad Kaufman * Drop any still-queued deferred-frame before removing the STA, and 244924afba76SLiad Kaufman * make sure the worker is no longer handling frames for this STA. 245024afba76SLiad Kaufman */ 245124afba76SLiad Kaufman if (old_state == IEEE80211_STA_NONE && 245224afba76SLiad Kaufman new_state == IEEE80211_STA_NOTEXIST && 245324afba76SLiad Kaufman iwl_mvm_is_dqa_supported(mvm)) { 245424afba76SLiad Kaufman struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 245524afba76SLiad Kaufman 245624afba76SLiad Kaufman iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta); 245724afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 245824afba76SLiad Kaufman 245924afba76SLiad Kaufman /* 246024afba76SLiad Kaufman * No need to make sure deferred TX indication is off since the 246124afba76SLiad Kaufman * worker will already remove it if it was on 246224afba76SLiad Kaufman */ 246324afba76SLiad Kaufman } 246424afba76SLiad Kaufman 2465e705c121SKalle Valo mutex_lock(&mvm->mutex); 2466e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 2467e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 2468e705c121SKalle Valo /* 2469e705c121SKalle Valo * Firmware bug - it'll crash if the beacon interval is less 2470e705c121SKalle Valo * than 16. We can't avoid connecting at all, so refuse the 2471e705c121SKalle Valo * station state change, this will cause mac80211 to abandon 2472e705c121SKalle Valo * attempts to connect to this AP, and eventually wpa_s will 2473e705c121SKalle Valo * blacklist the AP... 2474e705c121SKalle Valo */ 2475e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 2476e705c121SKalle Valo vif->bss_conf.beacon_int < 16) { 2477e705c121SKalle Valo IWL_ERR(mvm, 2478e705c121SKalle Valo "AP %pM beacon interval is %d, refusing due to firmware bug!\n", 2479e705c121SKalle Valo sta->addr, vif->bss_conf.beacon_int); 2480e705c121SKalle Valo ret = -EINVAL; 2481e705c121SKalle Valo goto out_unlock; 2482e705c121SKalle Valo } 2483e705c121SKalle Valo 2484e705c121SKalle Valo if (sta->tdls && 2485e705c121SKalle Valo (vif->p2p || 2486e705c121SKalle Valo iwl_mvm_tdls_sta_count(mvm, NULL) == 2487e705c121SKalle Valo IWL_MVM_TDLS_STA_COUNT || 2488e705c121SKalle Valo iwl_mvm_phy_ctx_count(mvm) > 1)) { 2489e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n"); 2490e705c121SKalle Valo ret = -EBUSY; 2491e705c121SKalle Valo goto out_unlock; 2492e705c121SKalle Valo } 2493e705c121SKalle Valo 2494e705c121SKalle Valo ret = iwl_mvm_add_sta(mvm, vif, sta); 24951e8f1329SGolan Ben-Ami if (sta->tdls && ret == 0) { 2496e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, true); 24971e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 24981e8f1329SGolan Ben-Ami NL80211_TDLS_SETUP); 24991e8f1329SGolan Ben-Ami } 2500e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 2501e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 2502e705c121SKalle Valo /* 2503e705c121SKalle Valo * EBS may be disabled due to previous failures reported by FW. 2504e705c121SKalle Valo * Reset EBS status here assuming environment has been changed. 2505e705c121SKalle Valo */ 2506e705c121SKalle Valo mvm->last_ebs_successful = true; 2507e705c121SKalle Valo iwl_mvm_check_uapsd(mvm, vif, sta->addr); 2508e705c121SKalle Valo ret = 0; 2509e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 2510e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 25118be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 25128be30c13SAyala Beker mvmvif->ap_assoc_sta_count++; 25138be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 25148be30c13SAyala Beker } 2515e705c121SKalle Valo ret = iwl_mvm_update_sta(mvm, vif, sta); 2516e705c121SKalle Valo if (ret == 0) 2517e705c121SKalle Valo iwl_mvm_rs_rate_init(mvm, sta, 2518e705c121SKalle Valo mvmvif->phy_ctxt->channel->band, 2519e705c121SKalle Valo true); 2520e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 2521e705c121SKalle Valo new_state == IEEE80211_STA_AUTHORIZED) { 2522e705c121SKalle Valo 2523e705c121SKalle Valo /* we don't support TDLS during DCM */ 2524e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 2525e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 2526e705c121SKalle Valo 25271e8f1329SGolan Ben-Ami if (sta->tdls) 25281e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 25291e8f1329SGolan Ben-Ami NL80211_TDLS_ENABLE_LINK); 25301e8f1329SGolan Ben-Ami 2531e705c121SKalle Valo /* enable beacon filtering */ 2532e705c121SKalle Valo WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0)); 2533e705c121SKalle Valo ret = 0; 2534e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTHORIZED && 2535e705c121SKalle Valo new_state == IEEE80211_STA_ASSOC) { 2536e705c121SKalle Valo /* disable beacon filtering */ 2537e705c121SKalle Valo WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0)); 2538e705c121SKalle Valo ret = 0; 2539e705c121SKalle Valo } else if (old_state == IEEE80211_STA_ASSOC && 2540e705c121SKalle Valo new_state == IEEE80211_STA_AUTH) { 25418be30c13SAyala Beker if (vif->type == NL80211_IFTYPE_AP) { 25428be30c13SAyala Beker mvmvif->ap_assoc_sta_count--; 25438be30c13SAyala Beker iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 25448be30c13SAyala Beker } 2545e705c121SKalle Valo ret = 0; 2546e705c121SKalle Valo } else if (old_state == IEEE80211_STA_AUTH && 2547e705c121SKalle Valo new_state == IEEE80211_STA_NONE) { 2548e705c121SKalle Valo ret = 0; 2549e705c121SKalle Valo } else if (old_state == IEEE80211_STA_NONE && 2550e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) { 2551e705c121SKalle Valo ret = iwl_mvm_rm_sta(mvm, vif, sta); 25521e8f1329SGolan Ben-Ami if (sta->tdls) { 2553e705c121SKalle Valo iwl_mvm_recalc_tdls_state(mvm, vif, false); 25541e8f1329SGolan Ben-Ami iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr, 25551e8f1329SGolan Ben-Ami NL80211_TDLS_DISABLE_LINK); 25561e8f1329SGolan Ben-Ami } 2557e705c121SKalle Valo } else { 2558e705c121SKalle Valo ret = -EIO; 2559e705c121SKalle Valo } 2560e705c121SKalle Valo out_unlock: 2561e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2562e705c121SKalle Valo 2563e705c121SKalle Valo if (sta->tdls && ret == 0) { 2564e705c121SKalle Valo if (old_state == IEEE80211_STA_NOTEXIST && 2565e705c121SKalle Valo new_state == IEEE80211_STA_NONE) 2566e705c121SKalle Valo ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); 2567e705c121SKalle Valo else if (old_state == IEEE80211_STA_NONE && 2568e705c121SKalle Valo new_state == IEEE80211_STA_NOTEXIST) 2569e705c121SKalle Valo ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID); 2570e705c121SKalle Valo } 2571e705c121SKalle Valo 2572e705c121SKalle Valo return ret; 2573e705c121SKalle Valo } 2574e705c121SKalle Valo 2575e705c121SKalle Valo static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value) 2576e705c121SKalle Valo { 2577e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2578e705c121SKalle Valo 2579e705c121SKalle Valo mvm->rts_threshold = value; 2580e705c121SKalle Valo 2581e705c121SKalle Valo return 0; 2582e705c121SKalle Valo } 2583e705c121SKalle Valo 2584e705c121SKalle Valo static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, 2585e705c121SKalle Valo struct ieee80211_vif *vif, 2586e705c121SKalle Valo struct ieee80211_sta *sta, u32 changed) 2587e705c121SKalle Valo { 2588e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2589e705c121SKalle Valo 2590e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 2591e705c121SKalle Valo changed & IEEE80211_RC_NSS_CHANGED) 2592e705c121SKalle Valo iwl_mvm_sf_update(mvm, vif, false); 2593e705c121SKalle Valo } 2594e705c121SKalle Valo 2595e705c121SKalle Valo static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw, 2596e705c121SKalle Valo struct ieee80211_vif *vif, u16 ac, 2597e705c121SKalle Valo const struct ieee80211_tx_queue_params *params) 2598e705c121SKalle Valo { 2599e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2600e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2601e705c121SKalle Valo 2602e705c121SKalle Valo mvmvif->queue_params[ac] = *params; 2603e705c121SKalle Valo 2604e705c121SKalle Valo /* 2605e705c121SKalle Valo * No need to update right away, we'll get BSS_CHANGED_QOS 2606e705c121SKalle Valo * The exception is P2P_DEVICE interface which needs immediate update. 2607e705c121SKalle Valo */ 2608e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { 2609e705c121SKalle Valo int ret; 2610e705c121SKalle Valo 2611e705c121SKalle Valo mutex_lock(&mvm->mutex); 2612e705c121SKalle Valo ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 2613e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2614e705c121SKalle Valo return ret; 2615e705c121SKalle Valo } 2616e705c121SKalle Valo return 0; 2617e705c121SKalle Valo } 2618e705c121SKalle Valo 2619e705c121SKalle Valo static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw, 2620e705c121SKalle Valo struct ieee80211_vif *vif) 2621e705c121SKalle Valo { 2622e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 26237c70fee5SSara Sharon u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS; 26247c70fee5SSara Sharon u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS; 2625e705c121SKalle Valo 2626e705c121SKalle Valo if (WARN_ON_ONCE(vif->bss_conf.assoc)) 2627e705c121SKalle Valo return; 2628e705c121SKalle Valo 2629e705c121SKalle Valo /* 2630e705c121SKalle Valo * iwl_mvm_protect_session() reads directly from the device 2631e705c121SKalle Valo * (the system time), so make sure it is available. 2632e705c121SKalle Valo */ 2633e705c121SKalle Valo if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX)) 2634e705c121SKalle Valo return; 2635e705c121SKalle Valo 2636e705c121SKalle Valo mutex_lock(&mvm->mutex); 2637e705c121SKalle Valo /* Try really hard to protect the session and hear a beacon */ 2638e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false); 2639e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2640e705c121SKalle Valo 2641e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX); 2642e705c121SKalle Valo } 2643e705c121SKalle Valo 2644e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw, 2645e705c121SKalle Valo struct ieee80211_vif *vif, 2646e705c121SKalle Valo struct cfg80211_sched_scan_request *req, 2647e705c121SKalle Valo struct ieee80211_scan_ies *ies) 2648e705c121SKalle Valo { 2649e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2650e705c121SKalle Valo 2651e705c121SKalle Valo int ret; 2652e705c121SKalle Valo 2653e705c121SKalle Valo mutex_lock(&mvm->mutex); 2654e705c121SKalle Valo 2655e705c121SKalle Valo if (!vif->bss_conf.idle) { 2656e705c121SKalle Valo ret = -EBUSY; 2657e705c121SKalle Valo goto out; 2658e705c121SKalle Valo } 2659e705c121SKalle Valo 2660e705c121SKalle Valo ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED); 2661e705c121SKalle Valo 2662e705c121SKalle Valo out: 2663e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2664e705c121SKalle Valo return ret; 2665e705c121SKalle Valo } 2666e705c121SKalle Valo 2667e705c121SKalle Valo static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, 2668e705c121SKalle Valo struct ieee80211_vif *vif) 2669e705c121SKalle Valo { 2670e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2671e705c121SKalle Valo int ret; 2672e705c121SKalle Valo 2673e705c121SKalle Valo mutex_lock(&mvm->mutex); 2674e705c121SKalle Valo 2675e705c121SKalle Valo /* Due to a race condition, it's possible that mac80211 asks 2676e705c121SKalle Valo * us to stop a sched_scan when it's already stopped. This 2677e705c121SKalle Valo * can happen, for instance, if we stopped the scan ourselves, 2678e705c121SKalle Valo * called ieee80211_sched_scan_stopped() and the userspace called 2679e705c121SKalle Valo * stop sched scan scan before ieee80211_sched_scan_stopped_work() 2680e705c121SKalle Valo * could run. To handle this, simply return if the scan is 2681e705c121SKalle Valo * not running. 2682e705c121SKalle Valo */ 2683e705c121SKalle Valo if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) { 2684e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2685e705c121SKalle Valo return 0; 2686e705c121SKalle Valo } 2687e705c121SKalle Valo 2688e705c121SKalle Valo ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false); 2689e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2690e705c121SKalle Valo iwl_mvm_wait_for_async_handlers(mvm); 2691e705c121SKalle Valo 2692e705c121SKalle Valo return ret; 2693e705c121SKalle Valo } 2694e705c121SKalle Valo 2695e705c121SKalle Valo static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, 2696e705c121SKalle Valo enum set_key_cmd cmd, 2697e705c121SKalle Valo struct ieee80211_vif *vif, 2698e705c121SKalle Valo struct ieee80211_sta *sta, 2699e705c121SKalle Valo struct ieee80211_key_conf *key) 2700e705c121SKalle Valo { 2701e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2702f5e28eacSJohannes Berg struct iwl_mvm_sta *mvmsta; 2703f5e28eacSJohannes Berg struct iwl_mvm_key_pn *ptk_pn; 2704f5e28eacSJohannes Berg int keyidx = key->keyidx; 2705e705c121SKalle Valo int ret; 27064615fd15SEmmanuel Grumbach u8 key_offset; 2707e705c121SKalle Valo 2708e705c121SKalle Valo if (iwlwifi_mod_params.sw_crypto) { 2709e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n"); 2710e705c121SKalle Valo return -EOPNOTSUPP; 2711e705c121SKalle Valo } 2712e705c121SKalle Valo 2713e705c121SKalle Valo switch (key->cipher) { 2714e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 2715e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC; 27161ad4f639SEliad Peller key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 2717e705c121SKalle Valo break; 2718e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 2719e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 2720e705c121SKalle Valo break; 2721e705c121SKalle Valo case WLAN_CIPHER_SUITE_AES_CMAC: 2722e705c121SKalle Valo WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE)); 2723e705c121SKalle Valo break; 2724e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 2725e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 2726e705c121SKalle Valo /* For non-client mode, only use WEP keys for TX as we probably 2727e705c121SKalle Valo * don't have a station yet anyway and would then have to keep 2728e705c121SKalle Valo * track of the keys, linking them to each of the clients/peers 2729e705c121SKalle Valo * as they appear. For now, don't do that, for performance WEP 2730e705c121SKalle Valo * offload doesn't really matter much, but we need it for some 2731e705c121SKalle Valo * other offload features in client mode. 2732e705c121SKalle Valo */ 2733e705c121SKalle Valo if (vif->type != NL80211_IFTYPE_STATION) 2734e705c121SKalle Valo return 0; 2735e705c121SKalle Valo break; 2736e705c121SKalle Valo default: 2737e705c121SKalle Valo /* currently FW supports only one optional cipher scheme */ 2738e705c121SKalle Valo if (hw->n_cipher_schemes && 2739e705c121SKalle Valo hw->cipher_schemes->cipher == key->cipher) 2740e705c121SKalle Valo key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE; 2741e705c121SKalle Valo else 2742e705c121SKalle Valo return -EOPNOTSUPP; 2743e705c121SKalle Valo } 2744e705c121SKalle Valo 2745e705c121SKalle Valo mutex_lock(&mvm->mutex); 2746e705c121SKalle Valo 2747e705c121SKalle Valo switch (cmd) { 2748e705c121SKalle Valo case SET_KEY: 2749e705c121SKalle Valo if ((vif->type == NL80211_IFTYPE_ADHOC || 2750e705c121SKalle Valo vif->type == NL80211_IFTYPE_AP) && !sta) { 2751e705c121SKalle Valo /* 2752e705c121SKalle Valo * GTK on AP interface is a TX-only key, return 0; 2753e705c121SKalle Valo * on IBSS they're per-station and because we're lazy 2754e705c121SKalle Valo * we don't support them for RX, so do the same. 275581279c49SJohannes Berg * CMAC in AP/IBSS modes must be done in software. 2756e705c121SKalle Valo */ 275781279c49SJohannes Berg if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC) 275881279c49SJohannes Berg ret = -EOPNOTSUPP; 275981279c49SJohannes Berg else 2760e705c121SKalle Valo ret = 0; 2761e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 2762e705c121SKalle Valo break; 2763e705c121SKalle Valo } 2764e705c121SKalle Valo 2765e705c121SKalle Valo /* During FW restart, in order to restore the state as it was, 2766e705c121SKalle Valo * don't try to reprogram keys we previously failed for. 2767e705c121SKalle Valo */ 2768e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2769e705c121SKalle Valo key->hw_key_idx == STA_KEY_IDX_INVALID) { 2770e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, 2771e705c121SKalle Valo "skip invalid idx key programming during restart\n"); 2772e705c121SKalle Valo ret = 0; 2773e705c121SKalle Valo break; 2774e705c121SKalle Valo } 2775e705c121SKalle Valo 2776f5e28eacSJohannes Berg if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && 2777f5e28eacSJohannes Berg sta && iwl_mvm_has_new_rx_api(mvm) && 2778f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 2779f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 2780f5e28eacSJohannes Berg key->cipher == WLAN_CIPHER_SUITE_GCMP)) { 2781f5e28eacSJohannes Berg struct ieee80211_key_seq seq; 2782f5e28eacSJohannes Berg int tid, q; 2783f5e28eacSJohannes Berg 2784f5e28eacSJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 2785f5e28eacSJohannes Berg WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx])); 2786f5e28eacSJohannes Berg ptk_pn = kzalloc(sizeof(*ptk_pn) + 2787f5e28eacSJohannes Berg mvm->trans->num_rx_queues * 2788f5e28eacSJohannes Berg sizeof(ptk_pn->q[0]), 2789f5e28eacSJohannes Berg GFP_KERNEL); 2790f5e28eacSJohannes Berg if (!ptk_pn) { 2791f5e28eacSJohannes Berg ret = -ENOMEM; 2792f5e28eacSJohannes Berg break; 2793f5e28eacSJohannes Berg } 2794f5e28eacSJohannes Berg 2795f5e28eacSJohannes Berg for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { 2796f5e28eacSJohannes Berg ieee80211_get_key_rx_seq(key, tid, &seq); 2797f5e28eacSJohannes Berg for (q = 0; q < mvm->trans->num_rx_queues; q++) 2798f5e28eacSJohannes Berg memcpy(ptk_pn->q[q].pn[tid], 2799f5e28eacSJohannes Berg seq.ccmp.pn, 2800f5e28eacSJohannes Berg IEEE80211_CCMP_PN_LEN); 2801f5e28eacSJohannes Berg } 2802f5e28eacSJohannes Berg 2803f5e28eacSJohannes Berg rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn); 2804f5e28eacSJohannes Berg } 2805f5e28eacSJohannes Berg 28064615fd15SEmmanuel Grumbach /* in HW restart reuse the index, otherwise request a new one */ 28074615fd15SEmmanuel Grumbach if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 28084615fd15SEmmanuel Grumbach key_offset = key->hw_key_idx; 28094615fd15SEmmanuel Grumbach else 28104615fd15SEmmanuel Grumbach key_offset = STA_KEY_IDX_INVALID; 28114615fd15SEmmanuel Grumbach 2812e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n"); 28134615fd15SEmmanuel Grumbach ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset); 2814e705c121SKalle Valo if (ret) { 2815e705c121SKalle Valo IWL_WARN(mvm, "set key failed\n"); 2816e705c121SKalle Valo /* 2817e705c121SKalle Valo * can't add key for RX, but we don't need it 2818e705c121SKalle Valo * in the device for TX so still return 0 2819e705c121SKalle Valo */ 2820e705c121SKalle Valo key->hw_key_idx = STA_KEY_IDX_INVALID; 2821e705c121SKalle Valo ret = 0; 2822e705c121SKalle Valo } 2823e705c121SKalle Valo 2824e705c121SKalle Valo break; 2825e705c121SKalle Valo case DISABLE_KEY: 2826e705c121SKalle Valo if (key->hw_key_idx == STA_KEY_IDX_INVALID) { 2827e705c121SKalle Valo ret = 0; 2828e705c121SKalle Valo break; 2829e705c121SKalle Valo } 2830e705c121SKalle Valo 2831f5e28eacSJohannes Berg if (sta && iwl_mvm_has_new_rx_api(mvm) && 2832f5e28eacSJohannes Berg key->flags & IEEE80211_KEY_FLAG_PAIRWISE && 2833f5e28eacSJohannes Berg (key->cipher == WLAN_CIPHER_SUITE_CCMP || 2834f5e28eacSJohannes Berg key->cipher == WLAN_CIPHER_SUITE_GCMP)) { 2835f5e28eacSJohannes Berg mvmsta = iwl_mvm_sta_from_mac80211(sta); 2836f5e28eacSJohannes Berg ptk_pn = rcu_dereference_protected( 2837f5e28eacSJohannes Berg mvmsta->ptk_pn[keyidx], 2838f5e28eacSJohannes Berg lockdep_is_held(&mvm->mutex)); 2839f5e28eacSJohannes Berg RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL); 2840f5e28eacSJohannes Berg if (ptk_pn) 2841f5e28eacSJohannes Berg kfree_rcu(ptk_pn, rcu_head); 2842f5e28eacSJohannes Berg } 2843f5e28eacSJohannes Berg 2844e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n"); 2845e705c121SKalle Valo ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key); 2846e705c121SKalle Valo break; 2847e705c121SKalle Valo default: 2848e705c121SKalle Valo ret = -EINVAL; 2849e705c121SKalle Valo } 2850e705c121SKalle Valo 2851e705c121SKalle Valo mutex_unlock(&mvm->mutex); 2852e705c121SKalle Valo return ret; 2853e705c121SKalle Valo } 2854e705c121SKalle Valo 2855e705c121SKalle Valo static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw, 2856e705c121SKalle Valo struct ieee80211_vif *vif, 2857e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 2858e705c121SKalle Valo struct ieee80211_sta *sta, 2859e705c121SKalle Valo u32 iv32, u16 *phase1key) 2860e705c121SKalle Valo { 2861e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 2862e705c121SKalle Valo 2863e705c121SKalle Valo if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) 2864e705c121SKalle Valo return; 2865e705c121SKalle Valo 2866e705c121SKalle Valo iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key); 2867e705c121SKalle Valo } 2868e705c121SKalle Valo 2869e705c121SKalle Valo 2870e705c121SKalle Valo static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait, 2871e705c121SKalle Valo struct iwl_rx_packet *pkt, void *data) 2872e705c121SKalle Valo { 2873e705c121SKalle Valo struct iwl_mvm *mvm = 2874e705c121SKalle Valo container_of(notif_wait, struct iwl_mvm, notif_wait); 2875e705c121SKalle Valo struct iwl_hs20_roc_res *resp; 2876e705c121SKalle Valo int resp_len = iwl_rx_packet_payload_len(pkt); 2877e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = data; 2878e705c121SKalle Valo 2879e705c121SKalle Valo if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD)) 2880e705c121SKalle Valo return true; 2881e705c121SKalle Valo 2882e705c121SKalle Valo if (WARN_ON_ONCE(resp_len != sizeof(*resp))) { 2883e705c121SKalle Valo IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n"); 2884e705c121SKalle Valo return true; 2885e705c121SKalle Valo } 2886e705c121SKalle Valo 2887e705c121SKalle Valo resp = (void *)pkt->data; 2888e705c121SKalle Valo 2889e705c121SKalle Valo IWL_DEBUG_TE(mvm, 2890e705c121SKalle Valo "Aux ROC: Recieved response from ucode: status=%d uid=%d\n", 2891e705c121SKalle Valo resp->status, resp->event_unique_id); 2892e705c121SKalle Valo 2893e705c121SKalle Valo te_data->uid = le32_to_cpu(resp->event_unique_id); 2894e705c121SKalle Valo IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n", 2895e705c121SKalle Valo te_data->uid); 2896e705c121SKalle Valo 2897e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 2898e705c121SKalle Valo list_add_tail(&te_data->list, &mvm->aux_roc_te_list); 2899e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 2900e705c121SKalle Valo 2901e705c121SKalle Valo return true; 2902e705c121SKalle Valo } 2903e705c121SKalle Valo 2904dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100) 2905dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200) 2906dc28e12fSMatti Gottlieb #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600) 2907dc28e12fSMatti Gottlieb #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20) 2908dc28e12fSMatti Gottlieb #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10) 2909e705c121SKalle Valo static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm, 2910e705c121SKalle Valo struct ieee80211_channel *channel, 2911e705c121SKalle Valo struct ieee80211_vif *vif, 2912e705c121SKalle Valo int duration) 2913e705c121SKalle Valo { 2914e705c121SKalle Valo int res, time_reg = DEVICE_SYSTEM_TIME_REG; 2915e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2916e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data; 2917e705c121SKalle Valo static const u16 time_event_response[] = { HOT_SPOT_CMD }; 2918e705c121SKalle Valo struct iwl_notification_wait wait_time_event; 2919dc28e12fSMatti Gottlieb u32 dtim_interval = vif->bss_conf.dtim_period * 2920dc28e12fSMatti Gottlieb vif->bss_conf.beacon_int; 2921dc28e12fSMatti Gottlieb u32 req_dur, delay; 2922e705c121SKalle Valo struct iwl_hs20_roc_req aux_roc_req = { 2923e705c121SKalle Valo .action = cpu_to_le32(FW_CTXT_ACTION_ADD), 2924e705c121SKalle Valo .id_and_color = 2925e705c121SKalle Valo cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)), 2926e705c121SKalle Valo .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id), 2927e705c121SKalle Valo /* Set the channel info data */ 292857fbcce3SJohannes Berg .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ? 2929e705c121SKalle Valo PHY_BAND_24 : PHY_BAND_5, 2930e705c121SKalle Valo .channel_info.channel = channel->hw_value, 2931e705c121SKalle Valo .channel_info.width = PHY_VHT_CHANNEL_MODE20, 2932e705c121SKalle Valo /* Set the time and duration */ 2933e705c121SKalle Valo .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)), 2934e705c121SKalle Valo }; 2935e705c121SKalle Valo 2936dc28e12fSMatti Gottlieb delay = AUX_ROC_MIN_DELAY; 2937dc28e12fSMatti Gottlieb req_dur = MSEC_TO_TU(duration); 2938dc28e12fSMatti Gottlieb 2939dc28e12fSMatti Gottlieb /* 2940dc28e12fSMatti Gottlieb * If we are associated we want the delay time to be at least one 2941dc28e12fSMatti Gottlieb * dtim interval so that the FW can wait until after the DTIM and 2942dc28e12fSMatti Gottlieb * then start the time event, this will potentially allow us to 2943dc28e12fSMatti Gottlieb * remain off-channel for the max duration. 2944dc28e12fSMatti Gottlieb * Since we want to use almost a whole dtim interval we would also 2945dc28e12fSMatti Gottlieb * like the delay to be for 2-3 dtim intervals, in case there are 2946dc28e12fSMatti Gottlieb * other time events with higher priority. 2947dc28e12fSMatti Gottlieb */ 2948dc28e12fSMatti Gottlieb if (vif->bss_conf.assoc) { 2949dc28e12fSMatti Gottlieb delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY); 2950dc28e12fSMatti Gottlieb /* We cannot remain off-channel longer than the DTIM interval */ 2951dc28e12fSMatti Gottlieb if (dtim_interval <= req_dur) { 2952dc28e12fSMatti Gottlieb req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER; 2953dc28e12fSMatti Gottlieb if (req_dur <= AUX_ROC_MIN_DURATION) 2954dc28e12fSMatti Gottlieb req_dur = dtim_interval - 2955dc28e12fSMatti Gottlieb AUX_ROC_MIN_SAFETY_BUFFER; 2956dc28e12fSMatti Gottlieb } 2957dc28e12fSMatti Gottlieb } 2958dc28e12fSMatti Gottlieb 2959dc28e12fSMatti Gottlieb aux_roc_req.duration = cpu_to_le32(req_dur); 2960dc28e12fSMatti Gottlieb aux_roc_req.apply_time_max_delay = cpu_to_le32(delay); 2961dc28e12fSMatti Gottlieb 2962dc28e12fSMatti Gottlieb IWL_DEBUG_TE(mvm, 2963dc28e12fSMatti Gottlieb "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n", 2964dc28e12fSMatti Gottlieb channel->hw_value, req_dur, duration, delay, 2965dc28e12fSMatti Gottlieb dtim_interval); 2966e705c121SKalle Valo /* Set the node address */ 2967e705c121SKalle Valo memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN); 2968e705c121SKalle Valo 2969e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2970e705c121SKalle Valo 2971e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 2972e705c121SKalle Valo 2973e705c121SKalle Valo if (WARN_ON(te_data->id == HOT_SPOT_CMD)) { 2974e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 2975e705c121SKalle Valo return -EIO; 2976e705c121SKalle Valo } 2977e705c121SKalle Valo 2978e705c121SKalle Valo te_data->vif = vif; 2979e705c121SKalle Valo te_data->duration = duration; 2980e705c121SKalle Valo te_data->id = HOT_SPOT_CMD; 2981e705c121SKalle Valo 2982e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 2983e705c121SKalle Valo 2984e705c121SKalle Valo /* 2985e705c121SKalle Valo * Use a notification wait, which really just processes the 2986e705c121SKalle Valo * command response and doesn't wait for anything, in order 2987e705c121SKalle Valo * to be able to process the response and get the UID inside 2988e705c121SKalle Valo * the RX path. Using CMD_WANT_SKB doesn't work because it 2989e705c121SKalle Valo * stores the buffer and then wakes up this thread, by which 2990e705c121SKalle Valo * time another notification (that the time event started) 2991e705c121SKalle Valo * might already be processed unsuccessfully. 2992e705c121SKalle Valo */ 2993e705c121SKalle Valo iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, 2994e705c121SKalle Valo time_event_response, 2995e705c121SKalle Valo ARRAY_SIZE(time_event_response), 2996e705c121SKalle Valo iwl_mvm_rx_aux_roc, te_data); 2997e705c121SKalle Valo 2998e705c121SKalle Valo res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req), 2999e705c121SKalle Valo &aux_roc_req); 3000e705c121SKalle Valo 3001e705c121SKalle Valo if (res) { 3002e705c121SKalle Valo IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res); 3003e705c121SKalle Valo iwl_remove_notification(&mvm->notif_wait, &wait_time_event); 3004e705c121SKalle Valo goto out_clear_te; 3005e705c121SKalle Valo } 3006e705c121SKalle Valo 3007e705c121SKalle Valo /* No need to wait for anything, so just pass 1 (0 isn't valid) */ 3008e705c121SKalle Valo res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); 3009e705c121SKalle Valo /* should never fail */ 3010e705c121SKalle Valo WARN_ON_ONCE(res); 3011e705c121SKalle Valo 3012e705c121SKalle Valo if (res) { 3013e705c121SKalle Valo out_clear_te: 3014e705c121SKalle Valo spin_lock_bh(&mvm->time_event_lock); 3015e705c121SKalle Valo iwl_mvm_te_clear_data(mvm, te_data); 3016e705c121SKalle Valo spin_unlock_bh(&mvm->time_event_lock); 3017e705c121SKalle Valo } 3018e705c121SKalle Valo 3019e705c121SKalle Valo return res; 3020e705c121SKalle Valo } 3021e705c121SKalle Valo 3022e705c121SKalle Valo static int iwl_mvm_roc(struct ieee80211_hw *hw, 3023e705c121SKalle Valo struct ieee80211_vif *vif, 3024e705c121SKalle Valo struct ieee80211_channel *channel, 3025e705c121SKalle Valo int duration, 3026e705c121SKalle Valo enum ieee80211_roc_type type) 3027e705c121SKalle Valo { 3028e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3029e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3030e705c121SKalle Valo struct cfg80211_chan_def chandef; 3031e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 3032e705c121SKalle Valo int ret, i; 3033e705c121SKalle Valo 3034e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value, 3035e705c121SKalle Valo duration, type); 3036e705c121SKalle Valo 3037e705c121SKalle Valo flush_work(&mvm->roc_done_wk); 3038e705c121SKalle Valo 3039e705c121SKalle Valo mutex_lock(&mvm->mutex); 3040e705c121SKalle Valo 3041e705c121SKalle Valo switch (vif->type) { 3042e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3043e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 3044e705c121SKalle Valo IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) { 3045e705c121SKalle Valo /* Use aux roc framework (HS20) */ 3046e705c121SKalle Valo ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 3047e705c121SKalle Valo vif, duration); 3048e705c121SKalle Valo goto out_unlock; 3049e705c121SKalle Valo } 3050e705c121SKalle Valo IWL_ERR(mvm, "hotspot not supported\n"); 3051e705c121SKalle Valo ret = -EINVAL; 3052e705c121SKalle Valo goto out_unlock; 3053e705c121SKalle Valo case NL80211_IFTYPE_P2P_DEVICE: 3054e705c121SKalle Valo /* handle below */ 3055e705c121SKalle Valo break; 3056e705c121SKalle Valo default: 3057e705c121SKalle Valo IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type); 3058e705c121SKalle Valo ret = -EINVAL; 3059e705c121SKalle Valo goto out_unlock; 3060e705c121SKalle Valo } 3061e705c121SKalle Valo 3062e705c121SKalle Valo for (i = 0; i < NUM_PHY_CTX; i++) { 3063e705c121SKalle Valo phy_ctxt = &mvm->phy_ctxts[i]; 3064e705c121SKalle Valo if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt) 3065e705c121SKalle Valo continue; 3066e705c121SKalle Valo 3067e705c121SKalle Valo if (phy_ctxt->ref && channel == phy_ctxt->channel) { 3068e705c121SKalle Valo /* 3069e705c121SKalle Valo * Unbind the P2P_DEVICE from the current PHY context, 3070e705c121SKalle Valo * and if the PHY context is not used remove it. 3071e705c121SKalle Valo */ 3072e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3073e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3074e705c121SKalle Valo goto out_unlock; 3075e705c121SKalle Valo 3076e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3077e705c121SKalle Valo 3078e705c121SKalle Valo /* Bind the P2P_DEVICE to the current PHY Context */ 3079e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3080e705c121SKalle Valo 3081e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3082e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3083e705c121SKalle Valo goto out_unlock; 3084e705c121SKalle Valo 3085e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3086e705c121SKalle Valo goto schedule_time_event; 3087e705c121SKalle Valo } 3088e705c121SKalle Valo } 3089e705c121SKalle Valo 3090e705c121SKalle Valo /* Need to update the PHY context only if the ROC channel changed */ 3091e705c121SKalle Valo if (channel == mvmvif->phy_ctxt->channel) 3092e705c121SKalle Valo goto schedule_time_event; 3093e705c121SKalle Valo 3094e705c121SKalle Valo cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT); 3095e705c121SKalle Valo 3096e705c121SKalle Valo /* 3097e705c121SKalle Valo * Change the PHY context configuration as it is currently referenced 3098e705c121SKalle Valo * only by the P2P Device MAC 3099e705c121SKalle Valo */ 3100e705c121SKalle Valo if (mvmvif->phy_ctxt->ref == 1) { 3101e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt, 3102e705c121SKalle Valo &chandef, 1, 1); 3103e705c121SKalle Valo if (ret) 3104e705c121SKalle Valo goto out_unlock; 3105e705c121SKalle Valo } else { 3106e705c121SKalle Valo /* 3107e705c121SKalle Valo * The PHY context is shared with other MACs. Need to remove the 3108e705c121SKalle Valo * P2P Device from the binding, allocate an new PHY context and 3109e705c121SKalle Valo * create a new binding 3110e705c121SKalle Valo */ 3111e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 3112e705c121SKalle Valo if (!phy_ctxt) { 3113e705c121SKalle Valo ret = -ENOSPC; 3114e705c121SKalle Valo goto out_unlock; 3115e705c121SKalle Valo } 3116e705c121SKalle Valo 3117e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef, 3118e705c121SKalle Valo 1, 1); 3119e705c121SKalle Valo if (ret) { 3120e705c121SKalle Valo IWL_ERR(mvm, "Failed to change PHY context\n"); 3121e705c121SKalle Valo goto out_unlock; 3122e705c121SKalle Valo } 3123e705c121SKalle Valo 3124e705c121SKalle Valo /* Unbind the P2P_DEVICE from the current PHY context */ 3125e705c121SKalle Valo ret = iwl_mvm_binding_remove_vif(mvm, vif); 3126e705c121SKalle Valo if (WARN(ret, "Failed unbinding P2P_DEVICE\n")) 3127e705c121SKalle Valo goto out_unlock; 3128e705c121SKalle Valo 3129e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt); 3130e705c121SKalle Valo 3131e705c121SKalle Valo /* Bind the P2P_DEVICE to the new allocated PHY context */ 3132e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3133e705c121SKalle Valo 3134e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3135e705c121SKalle Valo if (WARN(ret, "Failed binding P2P_DEVICE\n")) 3136e705c121SKalle Valo goto out_unlock; 3137e705c121SKalle Valo 3138e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt); 3139e705c121SKalle Valo } 3140e705c121SKalle Valo 3141e705c121SKalle Valo schedule_time_event: 3142e705c121SKalle Valo /* Schedule the time events */ 3143e705c121SKalle Valo ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type); 3144e705c121SKalle Valo 3145e705c121SKalle Valo out_unlock: 3146e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3147e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 3148e705c121SKalle Valo return ret; 3149e705c121SKalle Valo } 3150e705c121SKalle Valo 3151e705c121SKalle Valo static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw) 3152e705c121SKalle Valo { 3153e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3154e705c121SKalle Valo 3155e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "enter\n"); 3156e705c121SKalle Valo 3157e705c121SKalle Valo mutex_lock(&mvm->mutex); 3158e705c121SKalle Valo iwl_mvm_stop_roc(mvm); 3159e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3160e705c121SKalle Valo 3161e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "leave\n"); 3162e705c121SKalle Valo return 0; 3163e705c121SKalle Valo } 3164e705c121SKalle Valo 3165e705c121SKalle Valo static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm, 3166e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3167e705c121SKalle Valo { 3168e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3169e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt; 3170e705c121SKalle Valo int ret; 3171e705c121SKalle Valo 3172e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3173e705c121SKalle Valo 3174e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "Add channel context\n"); 3175e705c121SKalle Valo 3176e705c121SKalle Valo phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); 3177e705c121SKalle Valo if (!phy_ctxt) { 3178e705c121SKalle Valo ret = -ENOSPC; 3179e705c121SKalle Valo goto out; 3180e705c121SKalle Valo } 3181e705c121SKalle Valo 3182e705c121SKalle Valo ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, 3183e705c121SKalle Valo ctx->rx_chains_static, 3184e705c121SKalle Valo ctx->rx_chains_dynamic); 3185e705c121SKalle Valo if (ret) { 3186e705c121SKalle Valo IWL_ERR(mvm, "Failed to add PHY context\n"); 3187e705c121SKalle Valo goto out; 3188e705c121SKalle Valo } 3189e705c121SKalle Valo 3190e705c121SKalle Valo iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt); 3191e705c121SKalle Valo *phy_ctxt_id = phy_ctxt->id; 3192e705c121SKalle Valo out: 3193e705c121SKalle Valo return ret; 3194e705c121SKalle Valo } 3195e705c121SKalle Valo 3196e705c121SKalle Valo static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw, 3197e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3198e705c121SKalle Valo { 3199e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3200e705c121SKalle Valo int ret; 3201e705c121SKalle Valo 3202e705c121SKalle Valo mutex_lock(&mvm->mutex); 3203e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, ctx); 3204e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3205e705c121SKalle Valo 3206e705c121SKalle Valo return ret; 3207e705c121SKalle Valo } 3208e705c121SKalle Valo 3209e705c121SKalle Valo static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm, 3210e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3211e705c121SKalle Valo { 3212e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3213e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3214e705c121SKalle Valo 3215e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3216e705c121SKalle Valo 3217e705c121SKalle Valo iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt); 3218e705c121SKalle Valo } 3219e705c121SKalle Valo 3220e705c121SKalle Valo static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw, 3221e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3222e705c121SKalle Valo { 3223e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3224e705c121SKalle Valo 3225e705c121SKalle Valo mutex_lock(&mvm->mutex); 3226e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, ctx); 3227e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3228e705c121SKalle Valo } 3229e705c121SKalle Valo 3230e705c121SKalle Valo static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw, 3231e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3232e705c121SKalle Valo u32 changed) 3233e705c121SKalle Valo { 3234e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3235e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3236e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3237e705c121SKalle Valo 3238e705c121SKalle Valo if (WARN_ONCE((phy_ctxt->ref > 1) && 3239e705c121SKalle Valo (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH | 3240e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RX_CHAINS | 3241e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_RADAR | 3242e705c121SKalle Valo IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)), 3243e705c121SKalle Valo "Cannot change PHY. Ref=%d, changed=0x%X\n", 3244e705c121SKalle Valo phy_ctxt->ref, changed)) 3245e705c121SKalle Valo return; 3246e705c121SKalle Valo 3247e705c121SKalle Valo mutex_lock(&mvm->mutex); 3248e705c121SKalle Valo iwl_mvm_bt_coex_vif_change(mvm); 3249e705c121SKalle Valo iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def, 3250e705c121SKalle Valo ctx->rx_chains_static, 3251e705c121SKalle Valo ctx->rx_chains_dynamic); 3252e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3253e705c121SKalle Valo } 3254e705c121SKalle Valo 3255e705c121SKalle Valo static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm, 3256e705c121SKalle Valo struct ieee80211_vif *vif, 3257e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3258e705c121SKalle Valo bool switching_chanctx) 3259e705c121SKalle Valo { 3260e705c121SKalle Valo u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; 3261e705c121SKalle Valo struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; 3262e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3263e705c121SKalle Valo int ret; 3264e705c121SKalle Valo 3265e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3266e705c121SKalle Valo 3267e705c121SKalle Valo mvmvif->phy_ctxt = phy_ctxt; 3268e705c121SKalle Valo 3269e705c121SKalle Valo switch (vif->type) { 3270e705c121SKalle Valo case NL80211_IFTYPE_AP: 3271e705c121SKalle Valo /* only needed if we're switching chanctx (i.e. during CSA) */ 3272e705c121SKalle Valo if (switching_chanctx) { 3273e705c121SKalle Valo mvmvif->ap_ibss_active = true; 3274e705c121SKalle Valo break; 3275e705c121SKalle Valo } 3276e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3277e705c121SKalle Valo /* 3278e705c121SKalle Valo * The AP binding flow is handled as part of the start_ap flow 3279e705c121SKalle Valo * (in bss_info_changed), similarly for IBSS. 3280e705c121SKalle Valo */ 3281e705c121SKalle Valo ret = 0; 3282e705c121SKalle Valo goto out; 3283e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3284e705c121SKalle Valo break; 3285e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 3286e705c121SKalle Valo /* always disable PS when a monitor interface is active */ 3287e705c121SKalle Valo mvmvif->ps_disabled = true; 3288e705c121SKalle Valo break; 3289e705c121SKalle Valo default: 3290e705c121SKalle Valo ret = -EINVAL; 3291e705c121SKalle Valo goto out; 3292e705c121SKalle Valo } 3293e705c121SKalle Valo 3294e705c121SKalle Valo ret = iwl_mvm_binding_add_vif(mvm, vif); 3295e705c121SKalle Valo if (ret) 3296e705c121SKalle Valo goto out; 3297e705c121SKalle Valo 3298e705c121SKalle Valo /* 3299e705c121SKalle Valo * Power state must be updated before quotas, 3300e705c121SKalle Valo * otherwise fw will complain. 3301e705c121SKalle Valo */ 3302e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3303e705c121SKalle Valo 3304e705c121SKalle Valo /* Setting the quota at this stage is only required for monitor 3305e705c121SKalle Valo * interfaces. For the other types, the bss_info changed flow 3306e705c121SKalle Valo * will handle quota settings. 3307e705c121SKalle Valo */ 3308e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_MONITOR) { 3309e705c121SKalle Valo mvmvif->monitor_active = true; 3310e705c121SKalle Valo ret = iwl_mvm_update_quotas(mvm, false, NULL); 3311e705c121SKalle Valo if (ret) 3312e705c121SKalle Valo goto out_remove_binding; 33130e39eb03SChaya Rachel Ivgi 33140e39eb03SChaya Rachel Ivgi ret = iwl_mvm_add_snif_sta(mvm, vif); 33150e39eb03SChaya Rachel Ivgi if (ret) 33160e39eb03SChaya Rachel Ivgi goto out_remove_binding; 33170e39eb03SChaya Rachel Ivgi 3318e705c121SKalle Valo } 3319e705c121SKalle Valo 3320e705c121SKalle Valo /* Handle binding during CSA */ 3321e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_AP) { 3322e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3323e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3324e705c121SKalle Valo } 3325e705c121SKalle Valo 3326e705c121SKalle Valo if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) { 3327e705c121SKalle Valo u32 duration = 2 * vif->bss_conf.beacon_int; 3328e705c121SKalle Valo 3329e705c121SKalle Valo /* iwl_mvm_protect_session() reads directly from the 3330e705c121SKalle Valo * device (the system time), so make sure it is 3331e705c121SKalle Valo * available. 3332e705c121SKalle Valo */ 3333e705c121SKalle Valo ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA); 3334e705c121SKalle Valo if (ret) 3335e705c121SKalle Valo goto out_remove_binding; 3336e705c121SKalle Valo 3337e705c121SKalle Valo /* Protect the session to make sure we hear the first 3338e705c121SKalle Valo * beacon on the new channel. 3339e705c121SKalle Valo */ 3340e705c121SKalle Valo iwl_mvm_protect_session(mvm, vif, duration, duration, 3341e705c121SKalle Valo vif->bss_conf.beacon_int / 2, 3342e705c121SKalle Valo true); 3343e705c121SKalle Valo 3344e705c121SKalle Valo iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA); 3345e705c121SKalle Valo 3346e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, NULL); 3347e705c121SKalle Valo } 3348e705c121SKalle Valo 3349e705c121SKalle Valo goto out; 3350e705c121SKalle Valo 3351e705c121SKalle Valo out_remove_binding: 3352e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3353e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3354e705c121SKalle Valo out: 3355e705c121SKalle Valo if (ret) 3356e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 3357e705c121SKalle Valo return ret; 3358e705c121SKalle Valo } 3359e705c121SKalle Valo static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw, 3360e705c121SKalle Valo struct ieee80211_vif *vif, 3361e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3362e705c121SKalle Valo { 3363e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3364e705c121SKalle Valo int ret; 3365e705c121SKalle Valo 3366e705c121SKalle Valo mutex_lock(&mvm->mutex); 3367e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false); 3368e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3369e705c121SKalle Valo 3370e705c121SKalle Valo return ret; 3371e705c121SKalle Valo } 3372e705c121SKalle Valo 3373e705c121SKalle Valo static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm, 3374e705c121SKalle Valo struct ieee80211_vif *vif, 3375e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx, 3376e705c121SKalle Valo bool switching_chanctx) 3377e705c121SKalle Valo { 3378e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3379e705c121SKalle Valo struct ieee80211_vif *disabled_vif = NULL; 3380e705c121SKalle Valo 3381e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3382e705c121SKalle Valo 3383e705c121SKalle Valo iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data); 3384e705c121SKalle Valo 3385e705c121SKalle Valo switch (vif->type) { 3386e705c121SKalle Valo case NL80211_IFTYPE_ADHOC: 3387e705c121SKalle Valo goto out; 3388e705c121SKalle Valo case NL80211_IFTYPE_MONITOR: 3389e705c121SKalle Valo mvmvif->monitor_active = false; 3390e705c121SKalle Valo mvmvif->ps_disabled = false; 33910e39eb03SChaya Rachel Ivgi iwl_mvm_rm_snif_sta(mvm, vif); 3392e705c121SKalle Valo break; 3393e705c121SKalle Valo case NL80211_IFTYPE_AP: 3394e705c121SKalle Valo /* This part is triggered only during CSA */ 3395e705c121SKalle Valo if (!switching_chanctx || !mvmvif->ap_ibss_active) 3396e705c121SKalle Valo goto out; 3397e705c121SKalle Valo 3398e705c121SKalle Valo mvmvif->csa_countdown = false; 3399e705c121SKalle Valo 3400e705c121SKalle Valo /* Set CS bit on all the stations */ 3401e705c121SKalle Valo iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true); 3402e705c121SKalle Valo 3403e705c121SKalle Valo /* Save blocked iface, the timeout is set on the next beacon */ 3404e705c121SKalle Valo rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif); 3405e705c121SKalle Valo 3406e705c121SKalle Valo mvmvif->ap_ibss_active = false; 3407e705c121SKalle Valo break; 3408e705c121SKalle Valo case NL80211_IFTYPE_STATION: 3409e705c121SKalle Valo if (!switching_chanctx) 3410e705c121SKalle Valo break; 3411e705c121SKalle Valo 3412e705c121SKalle Valo disabled_vif = vif; 3413e705c121SKalle Valo 3414e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL); 3415e705c121SKalle Valo break; 3416e705c121SKalle Valo default: 3417e705c121SKalle Valo break; 3418e705c121SKalle Valo } 3419e705c121SKalle Valo 3420e705c121SKalle Valo iwl_mvm_update_quotas(mvm, false, disabled_vif); 3421e705c121SKalle Valo iwl_mvm_binding_remove_vif(mvm, vif); 3422e705c121SKalle Valo 3423e705c121SKalle Valo out: 3424e705c121SKalle Valo mvmvif->phy_ctxt = NULL; 3425e705c121SKalle Valo iwl_mvm_power_update_mac(mvm); 3426e705c121SKalle Valo } 3427e705c121SKalle Valo 3428e705c121SKalle Valo static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw, 3429e705c121SKalle Valo struct ieee80211_vif *vif, 3430e705c121SKalle Valo struct ieee80211_chanctx_conf *ctx) 3431e705c121SKalle Valo { 3432e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3433e705c121SKalle Valo 3434e705c121SKalle Valo mutex_lock(&mvm->mutex); 3435e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false); 3436e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3437e705c121SKalle Valo } 3438e705c121SKalle Valo 3439e705c121SKalle Valo static int 3440e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm, 3441e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 3442e705c121SKalle Valo { 3443e705c121SKalle Valo int ret; 3444e705c121SKalle Valo 3445e705c121SKalle Valo mutex_lock(&mvm->mutex); 3446e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 3447e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx); 3448e705c121SKalle Valo 3449e705c121SKalle Valo ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx); 3450e705c121SKalle Valo if (ret) { 3451e705c121SKalle Valo IWL_ERR(mvm, "failed to add new_ctx during channel switch\n"); 3452e705c121SKalle Valo goto out_reassign; 3453e705c121SKalle Valo } 3454e705c121SKalle Valo 3455e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 3456e705c121SKalle Valo true); 3457e705c121SKalle Valo if (ret) { 3458e705c121SKalle Valo IWL_ERR(mvm, 3459e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 3460e705c121SKalle Valo goto out_remove; 3461e705c121SKalle Valo } 3462e705c121SKalle Valo 3463e705c121SKalle Valo /* we don't support TDLS during DCM - can be caused by channel switch */ 3464e705c121SKalle Valo if (iwl_mvm_phy_ctx_count(mvm) > 1) 3465e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3466e705c121SKalle Valo 3467e705c121SKalle Valo goto out; 3468e705c121SKalle Valo 3469e705c121SKalle Valo out_remove: 3470e705c121SKalle Valo __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx); 3471e705c121SKalle Valo 3472e705c121SKalle Valo out_reassign: 3473e705c121SKalle Valo if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) { 3474e705c121SKalle Valo IWL_ERR(mvm, "failed to add old_ctx back after failure.\n"); 3475e705c121SKalle Valo goto out_restart; 3476e705c121SKalle Valo } 3477e705c121SKalle Valo 3478e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 3479e705c121SKalle Valo true)) { 3480e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 3481e705c121SKalle Valo goto out_restart; 3482e705c121SKalle Valo } 3483e705c121SKalle Valo 3484e705c121SKalle Valo goto out; 3485e705c121SKalle Valo 3486e705c121SKalle Valo out_restart: 3487e705c121SKalle Valo /* things keep failing, better restart the hw */ 3488e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 3489e705c121SKalle Valo 3490e705c121SKalle Valo out: 3491e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3492e705c121SKalle Valo 3493e705c121SKalle Valo return ret; 3494e705c121SKalle Valo } 3495e705c121SKalle Valo 3496e705c121SKalle Valo static int 3497e705c121SKalle Valo iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm, 3498e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs) 3499e705c121SKalle Valo { 3500e705c121SKalle Valo int ret; 3501e705c121SKalle Valo 3502e705c121SKalle Valo mutex_lock(&mvm->mutex); 3503e705c121SKalle Valo __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true); 3504e705c121SKalle Valo 3505e705c121SKalle Valo ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx, 3506e705c121SKalle Valo true); 3507e705c121SKalle Valo if (ret) { 3508e705c121SKalle Valo IWL_ERR(mvm, 3509e705c121SKalle Valo "failed to assign new_ctx during channel switch\n"); 3510e705c121SKalle Valo goto out_reassign; 3511e705c121SKalle Valo } 3512e705c121SKalle Valo 3513e705c121SKalle Valo goto out; 3514e705c121SKalle Valo 3515e705c121SKalle Valo out_reassign: 3516e705c121SKalle Valo if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, 3517e705c121SKalle Valo true)) { 3518e705c121SKalle Valo IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); 3519e705c121SKalle Valo goto out_restart; 3520e705c121SKalle Valo } 3521e705c121SKalle Valo 3522e705c121SKalle Valo goto out; 3523e705c121SKalle Valo 3524e705c121SKalle Valo out_restart: 3525e705c121SKalle Valo /* things keep failing, better restart the hw */ 3526e705c121SKalle Valo iwl_mvm_nic_restart(mvm, false); 3527e705c121SKalle Valo 3528e705c121SKalle Valo out: 3529e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3530e705c121SKalle Valo 3531e705c121SKalle Valo return ret; 3532e705c121SKalle Valo } 3533e705c121SKalle Valo 3534e705c121SKalle Valo static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw, 3535e705c121SKalle Valo struct ieee80211_vif_chanctx_switch *vifs, 3536e705c121SKalle Valo int n_vifs, 3537e705c121SKalle Valo enum ieee80211_chanctx_switch_mode mode) 3538e705c121SKalle Valo { 3539e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3540e705c121SKalle Valo int ret; 3541e705c121SKalle Valo 3542e705c121SKalle Valo /* we only support a single-vif right now */ 3543e705c121SKalle Valo if (n_vifs > 1) 3544e705c121SKalle Valo return -EOPNOTSUPP; 3545e705c121SKalle Valo 3546e705c121SKalle Valo switch (mode) { 3547e705c121SKalle Valo case CHANCTX_SWMODE_SWAP_CONTEXTS: 3548e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs); 3549e705c121SKalle Valo break; 3550e705c121SKalle Valo case CHANCTX_SWMODE_REASSIGN_VIF: 3551e705c121SKalle Valo ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs); 3552e705c121SKalle Valo break; 3553e705c121SKalle Valo default: 3554e705c121SKalle Valo ret = -EOPNOTSUPP; 3555e705c121SKalle Valo break; 3556e705c121SKalle Valo } 3557e705c121SKalle Valo 3558e705c121SKalle Valo return ret; 3559e705c121SKalle Valo } 3560e705c121SKalle Valo 3561e705c121SKalle Valo static int iwl_mvm_set_tim(struct ieee80211_hw *hw, 3562e705c121SKalle Valo struct ieee80211_sta *sta, 3563e705c121SKalle Valo bool set) 3564e705c121SKalle Valo { 3565e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3566e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3567e705c121SKalle Valo 3568e705c121SKalle Valo if (!mvm_sta || !mvm_sta->vif) { 3569e705c121SKalle Valo IWL_ERR(mvm, "Station is not associated to a vif\n"); 3570e705c121SKalle Valo return -EINVAL; 3571e705c121SKalle Valo } 3572e705c121SKalle Valo 3573e705c121SKalle Valo return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif); 3574e705c121SKalle Valo } 3575e705c121SKalle Valo 3576e705c121SKalle Valo #ifdef CONFIG_NL80211_TESTMODE 3577e705c121SKalle Valo static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = { 3578e705c121SKalle Valo [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 }, 3579e705c121SKalle Valo [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 }, 3580e705c121SKalle Valo [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 }, 3581e705c121SKalle Valo }; 3582e705c121SKalle Valo 3583e705c121SKalle Valo static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm, 3584e705c121SKalle Valo struct ieee80211_vif *vif, 3585e705c121SKalle Valo void *data, int len) 3586e705c121SKalle Valo { 3587e705c121SKalle Valo struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1]; 3588e705c121SKalle Valo int err; 3589e705c121SKalle Valo u32 noa_duration; 3590e705c121SKalle Valo 3591e705c121SKalle Valo err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy); 3592e705c121SKalle Valo if (err) 3593e705c121SKalle Valo return err; 3594e705c121SKalle Valo 3595e705c121SKalle Valo if (!tb[IWL_MVM_TM_ATTR_CMD]) 3596e705c121SKalle Valo return -EINVAL; 3597e705c121SKalle Valo 3598e705c121SKalle Valo switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) { 3599e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_NOA: 3600e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p || 3601e705c121SKalle Valo !vif->bss_conf.enable_beacon || 3602e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_NOA_DURATION]) 3603e705c121SKalle Valo return -EINVAL; 3604e705c121SKalle Valo 3605e705c121SKalle Valo noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]); 3606e705c121SKalle Valo if (noa_duration >= vif->bss_conf.beacon_int) 3607e705c121SKalle Valo return -EINVAL; 3608e705c121SKalle Valo 3609e705c121SKalle Valo mvm->noa_duration = noa_duration; 3610e705c121SKalle Valo mvm->noa_vif = vif; 3611e705c121SKalle Valo 3612e705c121SKalle Valo return iwl_mvm_update_quotas(mvm, false, NULL); 3613e705c121SKalle Valo case IWL_MVM_TM_CMD_SET_BEACON_FILTER: 3614e705c121SKalle Valo /* must be associated client vif - ignore authorized */ 3615e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION || 3616e705c121SKalle Valo !vif->bss_conf.assoc || !vif->bss_conf.dtim_period || 3617e705c121SKalle Valo !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]) 3618e705c121SKalle Valo return -EINVAL; 3619e705c121SKalle Valo 3620e705c121SKalle Valo if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])) 3621e705c121SKalle Valo return iwl_mvm_enable_beacon_filter(mvm, vif, 0); 3622e705c121SKalle Valo return iwl_mvm_disable_beacon_filter(mvm, vif, 0); 3623e705c121SKalle Valo } 3624e705c121SKalle Valo 3625e705c121SKalle Valo return -EOPNOTSUPP; 3626e705c121SKalle Valo } 3627e705c121SKalle Valo 3628e705c121SKalle Valo static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw, 3629e705c121SKalle Valo struct ieee80211_vif *vif, 3630e705c121SKalle Valo void *data, int len) 3631e705c121SKalle Valo { 3632e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3633e705c121SKalle Valo int err; 3634e705c121SKalle Valo 3635e705c121SKalle Valo mutex_lock(&mvm->mutex); 3636e705c121SKalle Valo err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len); 3637e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3638e705c121SKalle Valo 3639e705c121SKalle Valo return err; 3640e705c121SKalle Valo } 3641e705c121SKalle Valo #endif 3642e705c121SKalle Valo 3643e705c121SKalle Valo static void iwl_mvm_channel_switch(struct ieee80211_hw *hw, 3644e705c121SKalle Valo struct ieee80211_vif *vif, 3645e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 3646e705c121SKalle Valo { 3647e705c121SKalle Valo /* By implementing this operation, we prevent mac80211 from 3648e705c121SKalle Valo * starting its own channel switch timer, so that we can call 3649e705c121SKalle Valo * ieee80211_chswitch_done() ourselves at the right time 3650e705c121SKalle Valo * (which is when the absence time event starts). 3651e705c121SKalle Valo */ 3652e705c121SKalle Valo 3653e705c121SKalle Valo IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw), 3654e705c121SKalle Valo "dummy channel switch op\n"); 3655e705c121SKalle Valo } 3656e705c121SKalle Valo 3657e705c121SKalle Valo static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw, 3658e705c121SKalle Valo struct ieee80211_vif *vif, 3659e705c121SKalle Valo struct ieee80211_channel_switch *chsw) 3660e705c121SKalle Valo { 3661e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3662e705c121SKalle Valo struct ieee80211_vif *csa_vif; 3663e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3664e705c121SKalle Valo u32 apply_time; 3665e705c121SKalle Valo int ret; 3666e705c121SKalle Valo 3667e705c121SKalle Valo mutex_lock(&mvm->mutex); 3668e705c121SKalle Valo 3669e705c121SKalle Valo mvmvif->csa_failed = false; 3670e705c121SKalle Valo 3671e705c121SKalle Valo IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n", 3672e705c121SKalle Valo chsw->chandef.center_freq1); 3673e705c121SKalle Valo 3674e705c121SKalle Valo iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH); 3675e705c121SKalle Valo 3676e705c121SKalle Valo switch (vif->type) { 3677e705c121SKalle Valo case NL80211_IFTYPE_AP: 3678e705c121SKalle Valo csa_vif = 3679e705c121SKalle Valo rcu_dereference_protected(mvm->csa_vif, 3680e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 3681e705c121SKalle Valo if (WARN_ONCE(csa_vif && csa_vif->csa_active, 3682e705c121SKalle Valo "Another CSA is already in progress")) { 3683e705c121SKalle Valo ret = -EBUSY; 3684e705c121SKalle Valo goto out_unlock; 3685e705c121SKalle Valo } 3686e705c121SKalle Valo 3687e705c121SKalle Valo rcu_assign_pointer(mvm->csa_vif, vif); 3688e705c121SKalle Valo 3689e705c121SKalle Valo if (WARN_ONCE(mvmvif->csa_countdown, 3690e705c121SKalle Valo "Previous CSA countdown didn't complete")) { 3691e705c121SKalle Valo ret = -EBUSY; 3692e705c121SKalle Valo goto out_unlock; 3693e705c121SKalle Valo } 3694e705c121SKalle Valo 3695e705c121SKalle Valo break; 3696e705c121SKalle Valo case NL80211_IFTYPE_STATION: 369703098268SAviya Erenfeld if (mvmvif->lqm_active) 369803098268SAviya Erenfeld iwl_mvm_send_lqm_cmd(vif, 369903098268SAviya Erenfeld LQM_CMD_OPERATION_STOP_MEASUREMENT, 370003098268SAviya Erenfeld 0, 0); 370103098268SAviya Erenfeld 3702e705c121SKalle Valo /* Schedule the time event to a bit before beacon 1, 3703e705c121SKalle Valo * to make sure we're in the new channel when the 3704e705c121SKalle Valo * GO/AP arrives. 3705e705c121SKalle Valo */ 3706e705c121SKalle Valo apply_time = chsw->device_timestamp + 3707e705c121SKalle Valo ((vif->bss_conf.beacon_int * (chsw->count - 1) - 3708e705c121SKalle Valo IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024); 3709e705c121SKalle Valo 3710e705c121SKalle Valo if (chsw->block_tx) 3711e705c121SKalle Valo iwl_mvm_csa_client_absent(mvm, vif); 3712e705c121SKalle Valo 3713e705c121SKalle Valo iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int, 3714e705c121SKalle Valo apply_time); 3715e705c121SKalle Valo if (mvmvif->bf_data.bf_enabled) { 3716e705c121SKalle Valo ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0); 3717e705c121SKalle Valo if (ret) 3718e705c121SKalle Valo goto out_unlock; 3719e705c121SKalle Valo } 3720e705c121SKalle Valo 3721e705c121SKalle Valo break; 3722e705c121SKalle Valo default: 3723e705c121SKalle Valo break; 3724e705c121SKalle Valo } 3725e705c121SKalle Valo 3726e705c121SKalle Valo mvmvif->ps_disabled = true; 3727e705c121SKalle Valo 3728e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 3729e705c121SKalle Valo if (ret) 3730e705c121SKalle Valo goto out_unlock; 3731e705c121SKalle Valo 3732e705c121SKalle Valo /* we won't be on this channel any longer */ 3733e705c121SKalle Valo iwl_mvm_teardown_tdls_peers(mvm); 3734e705c121SKalle Valo 3735e705c121SKalle Valo out_unlock: 3736e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3737e705c121SKalle Valo 3738e705c121SKalle Valo return ret; 3739e705c121SKalle Valo } 3740e705c121SKalle Valo 3741e705c121SKalle Valo static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw, 3742e705c121SKalle Valo struct ieee80211_vif *vif) 3743e705c121SKalle Valo { 3744e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3745e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3746e705c121SKalle Valo int ret; 3747e705c121SKalle Valo 3748e705c121SKalle Valo mutex_lock(&mvm->mutex); 3749e705c121SKalle Valo 3750e705c121SKalle Valo if (mvmvif->csa_failed) { 3751e705c121SKalle Valo mvmvif->csa_failed = false; 3752e705c121SKalle Valo ret = -EIO; 3753e705c121SKalle Valo goto out_unlock; 3754e705c121SKalle Valo } 3755e705c121SKalle Valo 3756e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION) { 3757e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 3758e705c121SKalle Valo 3759e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_staid_protected(mvm, 3760e705c121SKalle Valo mvmvif->ap_sta_id); 3761e705c121SKalle Valo 3762e705c121SKalle Valo if (WARN_ON(!mvmsta)) { 3763e705c121SKalle Valo ret = -EIO; 3764e705c121SKalle Valo goto out_unlock; 3765e705c121SKalle Valo } 3766e705c121SKalle Valo 3767e705c121SKalle Valo iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false); 3768e705c121SKalle Valo 3769e705c121SKalle Valo iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); 3770e705c121SKalle Valo 3771e705c121SKalle Valo ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0); 3772e705c121SKalle Valo if (ret) 3773e705c121SKalle Valo goto out_unlock; 3774e705c121SKalle Valo 3775e705c121SKalle Valo iwl_mvm_stop_session_protection(mvm, vif); 3776e705c121SKalle Valo } 3777e705c121SKalle Valo 3778e705c121SKalle Valo mvmvif->ps_disabled = false; 3779e705c121SKalle Valo 3780e705c121SKalle Valo ret = iwl_mvm_power_update_ps(mvm); 3781e705c121SKalle Valo 3782e705c121SKalle Valo out_unlock: 3783e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3784e705c121SKalle Valo 3785e705c121SKalle Valo return ret; 3786e705c121SKalle Valo } 3787e705c121SKalle Valo 3788e705c121SKalle Valo static void iwl_mvm_mac_flush(struct ieee80211_hw *hw, 3789e705c121SKalle Valo struct ieee80211_vif *vif, u32 queues, bool drop) 3790e705c121SKalle Valo { 3791e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3792e705c121SKalle Valo struct iwl_mvm_vif *mvmvif; 3793e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 3794e705c121SKalle Valo struct ieee80211_sta *sta; 3795e705c121SKalle Valo int i; 3796e705c121SKalle Valo u32 msk = 0; 3797e705c121SKalle Valo 3798e705c121SKalle Valo if (!vif || vif->type != NL80211_IFTYPE_STATION) 3799e705c121SKalle Valo return; 3800e705c121SKalle Valo 380124afba76SLiad Kaufman /* Make sure we're done with the deferred traffic before flushing */ 380224afba76SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) 380324afba76SLiad Kaufman flush_work(&mvm->add_stream_wk); 380424afba76SLiad Kaufman 3805e705c121SKalle Valo mutex_lock(&mvm->mutex); 3806e705c121SKalle Valo mvmvif = iwl_mvm_vif_from_mac80211(vif); 3807e705c121SKalle Valo 3808e705c121SKalle Valo /* flush the AP-station and all TDLS peers */ 3809e705c121SKalle Valo for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { 3810e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 3811e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 3812e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 3813e705c121SKalle Valo continue; 3814e705c121SKalle Valo 3815e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_mac80211(sta); 3816e705c121SKalle Valo if (mvmsta->vif != vif) 3817e705c121SKalle Valo continue; 3818e705c121SKalle Valo 3819e705c121SKalle Valo /* make sure only TDLS peers or the AP are flushed */ 3820e705c121SKalle Valo WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls); 3821e705c121SKalle Valo 3822e705c121SKalle Valo msk |= mvmsta->tfd_queue_msk; 3823e705c121SKalle Valo } 3824e705c121SKalle Valo 3825e705c121SKalle Valo if (drop) { 3826e705c121SKalle Valo if (iwl_mvm_flush_tx_path(mvm, msk, 0)) 3827e705c121SKalle Valo IWL_ERR(mvm, "flush request fail\n"); 3828e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3829e705c121SKalle Valo } else { 3830e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3831e705c121SKalle Valo 3832e705c121SKalle Valo /* this can take a while, and we may need/want other operations 3833e705c121SKalle Valo * to succeed while doing this, so do it without the mutex held 3834e705c121SKalle Valo */ 3835e705c121SKalle Valo iwl_trans_wait_tx_queue_empty(mvm->trans, msk); 3836e705c121SKalle Valo } 3837e705c121SKalle Valo } 3838e705c121SKalle Valo 3839e705c121SKalle Valo static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx, 3840e705c121SKalle Valo struct survey_info *survey) 3841e705c121SKalle Valo { 3842e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3843e705c121SKalle Valo int ret; 3844e705c121SKalle Valo 3845e705c121SKalle Valo memset(survey, 0, sizeof(*survey)); 3846e705c121SKalle Valo 3847e705c121SKalle Valo /* only support global statistics right now */ 3848e705c121SKalle Valo if (idx != 0) 3849e705c121SKalle Valo return -ENOENT; 3850e705c121SKalle Valo 3851e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 3852e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 3853e705c121SKalle Valo return -ENOENT; 3854e705c121SKalle Valo 3855e705c121SKalle Valo mutex_lock(&mvm->mutex); 3856e705c121SKalle Valo 3857e705c121SKalle Valo if (mvm->ucode_loaded) { 3858e705c121SKalle Valo ret = iwl_mvm_request_statistics(mvm, false); 3859e705c121SKalle Valo if (ret) 3860e705c121SKalle Valo goto out; 3861e705c121SKalle Valo } 3862e705c121SKalle Valo 3863e705c121SKalle Valo survey->filled = SURVEY_INFO_TIME | 3864e705c121SKalle Valo SURVEY_INFO_TIME_RX | 3865e705c121SKalle Valo SURVEY_INFO_TIME_TX | 3866e705c121SKalle Valo SURVEY_INFO_TIME_SCAN; 3867e705c121SKalle Valo survey->time = mvm->accu_radio_stats.on_time_rf + 3868e705c121SKalle Valo mvm->radio_stats.on_time_rf; 3869e705c121SKalle Valo do_div(survey->time, USEC_PER_MSEC); 3870e705c121SKalle Valo 3871e705c121SKalle Valo survey->time_rx = mvm->accu_radio_stats.rx_time + 3872e705c121SKalle Valo mvm->radio_stats.rx_time; 3873e705c121SKalle Valo do_div(survey->time_rx, USEC_PER_MSEC); 3874e705c121SKalle Valo 3875e705c121SKalle Valo survey->time_tx = mvm->accu_radio_stats.tx_time + 3876e705c121SKalle Valo mvm->radio_stats.tx_time; 3877e705c121SKalle Valo do_div(survey->time_tx, USEC_PER_MSEC); 3878e705c121SKalle Valo 3879e705c121SKalle Valo survey->time_scan = mvm->accu_radio_stats.on_time_scan + 3880e705c121SKalle Valo mvm->radio_stats.on_time_scan; 3881e705c121SKalle Valo do_div(survey->time_scan, USEC_PER_MSEC); 3882e705c121SKalle Valo 3883e705c121SKalle Valo ret = 0; 3884e705c121SKalle Valo out: 3885e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3886e705c121SKalle Valo return ret; 3887e705c121SKalle Valo } 3888e705c121SKalle Valo 3889e705c121SKalle Valo static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw, 3890e705c121SKalle Valo struct ieee80211_vif *vif, 3891e705c121SKalle Valo struct ieee80211_sta *sta, 3892e705c121SKalle Valo struct station_info *sinfo) 3893e705c121SKalle Valo { 3894e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 3895e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3896e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3897e705c121SKalle Valo 3898e705c121SKalle Valo if (fw_has_capa(&mvm->fw->ucode_capa, 3899e705c121SKalle Valo IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) 3900e705c121SKalle Valo return; 3901e705c121SKalle Valo 3902e705c121SKalle Valo /* if beacon filtering isn't on mac80211 does it anyway */ 3903e705c121SKalle Valo if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER)) 3904e705c121SKalle Valo return; 3905e705c121SKalle Valo 3906e705c121SKalle Valo if (!vif->bss_conf.assoc) 3907e705c121SKalle Valo return; 3908e705c121SKalle Valo 3909e705c121SKalle Valo mutex_lock(&mvm->mutex); 3910e705c121SKalle Valo 3911e705c121SKalle Valo if (mvmvif->ap_sta_id != mvmsta->sta_id) 3912e705c121SKalle Valo goto unlock; 3913e705c121SKalle Valo 3914e705c121SKalle Valo if (iwl_mvm_request_statistics(mvm, false)) 3915e705c121SKalle Valo goto unlock; 3916e705c121SKalle Valo 3917e705c121SKalle Valo sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons + 3918e705c121SKalle Valo mvmvif->beacon_stats.accu_num_beacons; 3919e705c121SKalle Valo sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX); 3920e705c121SKalle Valo if (mvmvif->beacon_stats.avg_signal) { 3921e705c121SKalle Valo /* firmware only reports a value after RXing a few beacons */ 3922e705c121SKalle Valo sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal; 3923e705c121SKalle Valo sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG); 3924e705c121SKalle Valo } 3925e705c121SKalle Valo unlock: 3926e705c121SKalle Valo mutex_unlock(&mvm->mutex); 3927e705c121SKalle Valo } 3928e705c121SKalle Valo 3929e705c121SKalle Valo static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm, 3930e705c121SKalle Valo struct ieee80211_vif *vif, 3931e705c121SKalle Valo const struct ieee80211_event *event) 3932e705c121SKalle Valo { 3933e705c121SKalle Valo #define CHECK_MLME_TRIGGER(_mvm, _trig, _buf, _cnt, _fmt...) \ 3934e705c121SKalle Valo do { \ 3935e705c121SKalle Valo if ((_cnt) && --(_cnt)) \ 3936e705c121SKalle Valo break; \ 3937e705c121SKalle Valo iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt);\ 3938e705c121SKalle Valo } while (0) 3939e705c121SKalle Valo 3940e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 3941e705c121SKalle Valo struct iwl_fw_dbg_trigger_mlme *trig_mlme; 3942e705c121SKalle Valo 3943e705c121SKalle Valo if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME)) 3944e705c121SKalle Valo return; 3945e705c121SKalle Valo 3946e705c121SKalle Valo trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME); 3947e705c121SKalle Valo trig_mlme = (void *)trig->data; 3948e705c121SKalle Valo if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 3949e705c121SKalle Valo return; 3950e705c121SKalle Valo 3951e705c121SKalle Valo if (event->u.mlme.data == ASSOC_EVENT) { 3952e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 3953e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3954e705c121SKalle Valo trig_mlme->stop_assoc_denied, 3955e705c121SKalle Valo "DENIED ASSOC: reason %d", 3956e705c121SKalle Valo event->u.mlme.reason); 3957e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 3958e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3959e705c121SKalle Valo trig_mlme->stop_assoc_timeout, 3960e705c121SKalle Valo "ASSOC TIMEOUT"); 3961e705c121SKalle Valo } else if (event->u.mlme.data == AUTH_EVENT) { 3962e705c121SKalle Valo if (event->u.mlme.status == MLME_DENIED) 3963e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3964e705c121SKalle Valo trig_mlme->stop_auth_denied, 3965e705c121SKalle Valo "DENIED AUTH: reason %d", 3966e705c121SKalle Valo event->u.mlme.reason); 3967e705c121SKalle Valo else if (event->u.mlme.status == MLME_TIMEOUT) 3968e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3969e705c121SKalle Valo trig_mlme->stop_auth_timeout, 3970e705c121SKalle Valo "AUTH TIMEOUT"); 3971e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_RX_EVENT) { 3972e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3973e705c121SKalle Valo trig_mlme->stop_rx_deauth, 3974e705c121SKalle Valo "DEAUTH RX %d", event->u.mlme.reason); 3975e705c121SKalle Valo } else if (event->u.mlme.data == DEAUTH_TX_EVENT) { 3976e705c121SKalle Valo CHECK_MLME_TRIGGER(mvm, trig, buf, 3977e705c121SKalle Valo trig_mlme->stop_tx_deauth, 3978e705c121SKalle Valo "DEAUTH TX %d", event->u.mlme.reason); 3979e705c121SKalle Valo } 3980e705c121SKalle Valo #undef CHECK_MLME_TRIGGER 3981e705c121SKalle Valo } 3982e705c121SKalle Valo 3983e705c121SKalle Valo static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm, 3984e705c121SKalle Valo struct ieee80211_vif *vif, 3985e705c121SKalle Valo const struct ieee80211_event *event) 3986e705c121SKalle Valo { 3987e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 3988e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 3989e705c121SKalle Valo 3990e705c121SKalle Valo if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA)) 3991e705c121SKalle Valo return; 3992e705c121SKalle Valo 3993e705c121SKalle Valo trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA); 3994e705c121SKalle Valo ba_trig = (void *)trig->data; 3995e705c121SKalle Valo if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 3996e705c121SKalle Valo return; 3997e705c121SKalle Valo 3998e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid))) 3999e705c121SKalle Valo return; 4000e705c121SKalle Valo 4001e705c121SKalle Valo iwl_mvm_fw_dbg_collect_trig(mvm, trig, 4002e705c121SKalle Valo "BAR received from %pM, tid %d, ssn %d", 4003e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid, 4004e705c121SKalle Valo event->u.ba.ssn); 4005e705c121SKalle Valo } 4006e705c121SKalle Valo 4007e705c121SKalle Valo static void 4008e705c121SKalle Valo iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm, 4009e705c121SKalle Valo struct ieee80211_vif *vif, 4010e705c121SKalle Valo const struct ieee80211_event *event) 4011e705c121SKalle Valo { 4012e705c121SKalle Valo struct iwl_fw_dbg_trigger_tlv *trig; 4013e705c121SKalle Valo struct iwl_fw_dbg_trigger_ba *ba_trig; 4014e705c121SKalle Valo 4015e705c121SKalle Valo if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA)) 4016e705c121SKalle Valo return; 4017e705c121SKalle Valo 4018e705c121SKalle Valo trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA); 4019e705c121SKalle Valo ba_trig = (void *)trig->data; 4020e705c121SKalle Valo if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig)) 4021e705c121SKalle Valo return; 4022e705c121SKalle Valo 4023e705c121SKalle Valo if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid))) 4024e705c121SKalle Valo return; 4025e705c121SKalle Valo 4026e705c121SKalle Valo iwl_mvm_fw_dbg_collect_trig(mvm, trig, 4027e705c121SKalle Valo "Frame from %pM timed out, tid %d", 4028e705c121SKalle Valo event->u.ba.sta->addr, event->u.ba.tid); 4029e705c121SKalle Valo } 4030e705c121SKalle Valo 4031e705c121SKalle Valo static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw, 4032e705c121SKalle Valo struct ieee80211_vif *vif, 4033e705c121SKalle Valo const struct ieee80211_event *event) 4034e705c121SKalle Valo { 4035e705c121SKalle Valo struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4036e705c121SKalle Valo 4037e705c121SKalle Valo switch (event->type) { 4038e705c121SKalle Valo case MLME_EVENT: 4039e705c121SKalle Valo iwl_mvm_event_mlme_callback(mvm, vif, event); 4040e705c121SKalle Valo break; 4041e705c121SKalle Valo case BAR_RX_EVENT: 4042e705c121SKalle Valo iwl_mvm_event_bar_rx_callback(mvm, vif, event); 4043e705c121SKalle Valo break; 4044e705c121SKalle Valo case BA_FRAME_TIMEOUT: 4045e705c121SKalle Valo iwl_mvm_event_frame_timeout_callback(mvm, vif, event); 4046e705c121SKalle Valo break; 4047e705c121SKalle Valo default: 4048e705c121SKalle Valo break; 4049e705c121SKalle Valo } 4050e705c121SKalle Valo } 4051e705c121SKalle Valo 4052d0ff5d22SSara Sharon void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm, 4053d0ff5d22SSara Sharon struct iwl_mvm_internal_rxq_notif *notif, 4054d0ff5d22SSara Sharon u32 size) 40550636b938SSara Sharon { 40560636b938SSara Sharon DECLARE_WAIT_QUEUE_HEAD_ONSTACK(notif_waitq); 40570636b938SSara Sharon u32 qmask = BIT(mvm->trans->num_rx_queues) - 1; 40580636b938SSara Sharon int ret; 40590636b938SSara Sharon 40600636b938SSara Sharon lockdep_assert_held(&mvm->mutex); 40610636b938SSara Sharon 40620636b938SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 40630636b938SSara Sharon return; 40640636b938SSara Sharon 4065d0ff5d22SSara Sharon notif->cookie = mvm->queue_sync_cookie; 40660636b938SSara Sharon 4067d0ff5d22SSara Sharon if (notif->sync) 4068d0ff5d22SSara Sharon atomic_set(&mvm->queue_sync_counter, 4069d0ff5d22SSara Sharon mvm->trans->num_rx_queues); 4070d0ff5d22SSara Sharon 4071d0ff5d22SSara Sharon ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size); 40720636b938SSara Sharon if (ret) { 40730636b938SSara Sharon IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); 40740636b938SSara Sharon goto out; 40750636b938SSara Sharon } 4076d0ff5d22SSara Sharon 4077d0ff5d22SSara Sharon if (notif->sync) 40780636b938SSara Sharon ret = wait_event_timeout(notif_waitq, 40790636b938SSara Sharon atomic_read(&mvm->queue_sync_counter) == 0, 40800636b938SSara Sharon HZ); 40810636b938SSara Sharon WARN_ON_ONCE(!ret); 40820636b938SSara Sharon 40830636b938SSara Sharon out: 40840636b938SSara Sharon atomic_set(&mvm->queue_sync_counter, 0); 40850636b938SSara Sharon mvm->queue_sync_cookie++; 40860636b938SSara Sharon } 40870636b938SSara Sharon 40880636b938SSara Sharon static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw) 40890636b938SSara Sharon { 40900636b938SSara Sharon struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); 4091d0ff5d22SSara Sharon struct iwl_mvm_internal_rxq_notif data = { 4092d0ff5d22SSara Sharon .type = IWL_MVM_RXQ_EMPTY, 4093d0ff5d22SSara Sharon .sync = 1, 4094d0ff5d22SSara Sharon }; 40950636b938SSara Sharon 40960636b938SSara Sharon mutex_lock(&mvm->mutex); 4097d0ff5d22SSara Sharon iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data)); 40980636b938SSara Sharon mutex_unlock(&mvm->mutex); 40990636b938SSara Sharon } 41000636b938SSara Sharon 4101e705c121SKalle Valo const struct ieee80211_ops iwl_mvm_hw_ops = { 4102e705c121SKalle Valo .tx = iwl_mvm_mac_tx, 4103e705c121SKalle Valo .ampdu_action = iwl_mvm_mac_ampdu_action, 4104e705c121SKalle Valo .start = iwl_mvm_mac_start, 4105e705c121SKalle Valo .reconfig_complete = iwl_mvm_mac_reconfig_complete, 4106e705c121SKalle Valo .stop = iwl_mvm_mac_stop, 4107e705c121SKalle Valo .add_interface = iwl_mvm_mac_add_interface, 4108e705c121SKalle Valo .remove_interface = iwl_mvm_mac_remove_interface, 4109e705c121SKalle Valo .config = iwl_mvm_mac_config, 4110e705c121SKalle Valo .prepare_multicast = iwl_mvm_prepare_multicast, 4111e705c121SKalle Valo .configure_filter = iwl_mvm_configure_filter, 4112e705c121SKalle Valo .config_iface_filter = iwl_mvm_config_iface_filter, 4113e705c121SKalle Valo .bss_info_changed = iwl_mvm_bss_info_changed, 4114e705c121SKalle Valo .hw_scan = iwl_mvm_mac_hw_scan, 4115e705c121SKalle Valo .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan, 4116e705c121SKalle Valo .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove, 4117e705c121SKalle Valo .sta_state = iwl_mvm_mac_sta_state, 4118e705c121SKalle Valo .sta_notify = iwl_mvm_mac_sta_notify, 4119e705c121SKalle Valo .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames, 4120e705c121SKalle Valo .release_buffered_frames = iwl_mvm_mac_release_buffered_frames, 4121e705c121SKalle Valo .set_rts_threshold = iwl_mvm_mac_set_rts_threshold, 4122e705c121SKalle Valo .sta_rc_update = iwl_mvm_sta_rc_update, 4123e705c121SKalle Valo .conf_tx = iwl_mvm_mac_conf_tx, 4124e705c121SKalle Valo .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx, 4125e705c121SKalle Valo .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover, 4126e705c121SKalle Valo .flush = iwl_mvm_mac_flush, 4127e705c121SKalle Valo .sched_scan_start = iwl_mvm_mac_sched_scan_start, 4128e705c121SKalle Valo .sched_scan_stop = iwl_mvm_mac_sched_scan_stop, 4129e705c121SKalle Valo .set_key = iwl_mvm_mac_set_key, 4130e705c121SKalle Valo .update_tkip_key = iwl_mvm_mac_update_tkip_key, 4131e705c121SKalle Valo .remain_on_channel = iwl_mvm_roc, 4132e705c121SKalle Valo .cancel_remain_on_channel = iwl_mvm_cancel_roc, 4133e705c121SKalle Valo .add_chanctx = iwl_mvm_add_chanctx, 4134e705c121SKalle Valo .remove_chanctx = iwl_mvm_remove_chanctx, 4135e705c121SKalle Valo .change_chanctx = iwl_mvm_change_chanctx, 4136e705c121SKalle Valo .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx, 4137e705c121SKalle Valo .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx, 4138e705c121SKalle Valo .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx, 4139e705c121SKalle Valo 4140e705c121SKalle Valo .start_ap = iwl_mvm_start_ap_ibss, 4141e705c121SKalle Valo .stop_ap = iwl_mvm_stop_ap_ibss, 4142e705c121SKalle Valo .join_ibss = iwl_mvm_start_ap_ibss, 4143e705c121SKalle Valo .leave_ibss = iwl_mvm_stop_ap_ibss, 4144e705c121SKalle Valo 4145e705c121SKalle Valo .set_tim = iwl_mvm_set_tim, 4146e705c121SKalle Valo 4147e705c121SKalle Valo .channel_switch = iwl_mvm_channel_switch, 4148e705c121SKalle Valo .pre_channel_switch = iwl_mvm_pre_channel_switch, 4149e705c121SKalle Valo .post_channel_switch = iwl_mvm_post_channel_switch, 4150e705c121SKalle Valo 4151e705c121SKalle Valo .tdls_channel_switch = iwl_mvm_tdls_channel_switch, 4152e705c121SKalle Valo .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch, 4153e705c121SKalle Valo .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch, 4154e705c121SKalle Valo 4155e705c121SKalle Valo .event_callback = iwl_mvm_mac_event_callback, 4156e705c121SKalle Valo 41570636b938SSara Sharon .sync_rx_queues = iwl_mvm_sync_rx_queues, 41580636b938SSara Sharon 4159e705c121SKalle Valo CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd) 4160e705c121SKalle Valo 4161e705c121SKalle Valo #ifdef CONFIG_PM_SLEEP 4162e705c121SKalle Valo /* look at d3.c */ 4163e705c121SKalle Valo .suspend = iwl_mvm_suspend, 4164e705c121SKalle Valo .resume = iwl_mvm_resume, 4165e705c121SKalle Valo .set_wakeup = iwl_mvm_set_wakeup, 4166e705c121SKalle Valo .set_rekey_data = iwl_mvm_set_rekey_data, 4167e705c121SKalle Valo #if IS_ENABLED(CONFIG_IPV6) 4168e705c121SKalle Valo .ipv6_addr_change = iwl_mvm_ipv6_addr_change, 4169e705c121SKalle Valo #endif 4170e705c121SKalle Valo .set_default_unicast_key = iwl_mvm_set_default_unicast_key, 4171e705c121SKalle Valo #endif 4172e705c121SKalle Valo .get_survey = iwl_mvm_mac_get_survey, 4173e705c121SKalle Valo .sta_statistics = iwl_mvm_mac_sta_statistics, 4174e705c121SKalle Valo }; 4175