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