1 /******************************************************************************
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.
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 - 2019 Intel Corporation
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.
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.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 - 2019 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
188 .max_peers = IWL_MVM_TOF_MAX_APS,
190 .randomize_mac_addr = 1,
197 .request_civicloc = 1,
198 .max_bursts_exponent = -1, /* all supported */
199 .max_ftms_per_burst = 0, /* no limits */
200 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
201 BIT(NL80211_CHAN_WIDTH_20) |
202 BIT(NL80211_CHAN_WIDTH_40) |
203 BIT(NL80211_CHAN_WIDTH_80),
204 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
205 BIT(NL80211_PREAMBLE_HT) |
206 BIT(NL80211_PREAMBLE_VHT),
210 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
211 enum set_key_cmd cmd,
212 struct ieee80211_vif *vif,
213 struct ieee80211_sta *sta,
214 struct ieee80211_key_conf *key);
216 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
218 if (!iwl_mvm_is_d0i3_supported(mvm))
221 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
222 spin_lock_bh(&mvm->refs_lock);
223 mvm->refs[ref_type]++;
224 spin_unlock_bh(&mvm->refs_lock);
225 iwl_trans_ref(mvm->trans);
228 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
230 if (!iwl_mvm_is_d0i3_supported(mvm))
233 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
234 spin_lock_bh(&mvm->refs_lock);
235 if (WARN_ON(!mvm->refs[ref_type])) {
236 spin_unlock_bh(&mvm->refs_lock);
239 mvm->refs[ref_type]--;
240 spin_unlock_bh(&mvm->refs_lock);
241 iwl_trans_unref(mvm->trans);
244 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
245 enum iwl_mvm_ref_type except_ref)
249 if (!iwl_mvm_is_d0i3_supported(mvm))
252 spin_lock_bh(&mvm->refs_lock);
253 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
254 if (except_ref == i || !mvm->refs[i])
257 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
259 for (j = 0; j < mvm->refs[i]; j++)
260 iwl_trans_unref(mvm->trans);
263 spin_unlock_bh(&mvm->refs_lock);
266 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
271 if (!iwl_mvm_is_d0i3_supported(mvm))
274 spin_lock_bh(&mvm->refs_lock);
275 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
281 spin_unlock_bh(&mvm->refs_lock);
286 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
288 iwl_mvm_ref(mvm, ref_type);
290 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
291 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
294 iwl_mvm_unref(mvm, ref_type);
301 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
305 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
306 for (i = 0; i < NUM_PHY_CTX; i++) {
307 mvm->phy_ctxts[i].id = i;
308 mvm->phy_ctxts[i].ref = 0;
312 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
314 enum iwl_mcc_source src_id,
317 struct ieee80211_regdomain *regd = NULL;
318 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
319 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
320 struct iwl_mcc_update_resp *resp;
322 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
324 lockdep_assert_held(&mvm->mutex);
326 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
327 if (IS_ERR_OR_NULL(resp)) {
328 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
329 PTR_ERR_OR_ZERO(resp));
334 u32 status = le32_to_cpu(resp->status);
336 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
337 status == MCC_RESP_ILLEGAL);
340 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
341 __le32_to_cpu(resp->n_channels),
343 __le16_to_cpu(resp->mcc),
344 __le16_to_cpu(resp->geo_info));
345 /* Store the return source id */
346 src_id = resp->source_id;
348 if (IS_ERR_OR_NULL(regd)) {
349 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
350 PTR_ERR_OR_ZERO(regd));
354 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
355 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
356 mvm->lar_regdom_set = true;
357 mvm->mcc_src = src_id;
363 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
366 struct ieee80211_regdomain *regd;
368 if (!iwl_mvm_is_lar_supported(mvm))
371 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
372 if (!IS_ERR_OR_NULL(regd)) {
373 /* only update the regulatory core if changed */
375 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
381 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
384 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
385 iwl_mvm_is_wifi_mcc_supported(mvm) ?
386 MCC_SOURCE_GET_CURRENT :
387 MCC_SOURCE_OLD_FW, changed);
390 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
392 enum iwl_mcc_source used_src;
393 struct ieee80211_regdomain *regd;
396 const struct ieee80211_regdomain *r =
397 rtnl_dereference(mvm->hw->wiphy->regd);
402 /* save the last source in case we overwrite it below */
403 used_src = mvm->mcc_src;
404 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
405 /* Notify the firmware we support wifi location updates */
406 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
407 if (!IS_ERR_OR_NULL(regd))
411 /* Now set our last stored MCC and source */
412 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
414 if (IS_ERR_OR_NULL(regd))
417 /* update cfg80211 if the regdomain was changed */
419 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
427 const static u8 he_if_types_ext_capa_sta[] = {
428 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
429 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
430 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
431 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
434 const static struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
436 .iftype = NL80211_IFTYPE_STATION,
437 .extended_capabilities = he_if_types_ext_capa_sta,
438 .extended_capabilities_mask = he_if_types_ext_capa_sta,
439 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
443 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
445 struct ieee80211_hw *hw = mvm->hw;
447 static const u32 mvm_ciphers[] = {
448 WLAN_CIPHER_SUITE_WEP40,
449 WLAN_CIPHER_SUITE_WEP104,
450 WLAN_CIPHER_SUITE_TKIP,
451 WLAN_CIPHER_SUITE_CCMP,
453 #ifdef CONFIG_PM_SLEEP
454 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
455 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
458 /* Tell mac80211 our characteristics */
459 ieee80211_hw_set(hw, SIGNAL_DBM);
460 ieee80211_hw_set(hw, SPECTRUM_MGMT);
461 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
462 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
463 ieee80211_hw_set(hw, SUPPORTS_PS);
464 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
465 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
466 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
467 ieee80211_hw_set(hw, CONNECTION_MONITOR);
468 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
469 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
470 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
471 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
472 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
473 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
474 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
475 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
476 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
478 * On older devices, enabling TX A-MSDU occasionally leads to
479 * something getting messed up, the command read from the FIFO
480 * gets out of sync and isn't a TX command, so that we have an
483 * It's not clear where the bug is, but since we didn't used to
484 * support A-MSDU until moving the mac80211 iTXQs, just leave it
485 * for older devices. We also don't see this issue on any newer
488 if (mvm->cfg->device_family >= IWL_DEVICE_FAMILY_9000)
489 ieee80211_hw_set(hw, TX_AMSDU);
490 ieee80211_hw_set(hw, TX_FRAG_LIST);
492 if (iwl_mvm_has_tlc_offload(mvm)) {
493 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
494 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
497 if (iwl_mvm_has_new_rx_api(mvm))
498 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
500 if (fw_has_capa(&mvm->fw->ucode_capa,
501 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
502 ieee80211_hw_set(hw, AP_LINK_PS);
503 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
505 * we absolutely need this for the new TX API since that comes
506 * with many more queues than the current code can deal with
507 * for station powersave
512 if (mvm->trans->num_rx_queues > 1)
513 ieee80211_hw_set(hw, USES_RSS);
515 if (mvm->trans->max_skb_frags)
516 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
518 hw->queues = IEEE80211_MAX_QUEUES;
519 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
520 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
521 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
522 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
523 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
525 hw->radiotap_timestamp.units_pos =
526 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
527 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
528 /* this is the case for CCK frames, it's better (only 8) for OFDM */
529 hw->radiotap_timestamp.accuracy = 22;
531 if (!iwl_mvm_has_tlc_offload(mvm))
532 hw->rate_control_algorithm = RS_NAME;
534 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
535 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
536 hw->max_tx_fragments = mvm->trans->max_skb_frags;
538 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
539 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
540 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
541 hw->wiphy->cipher_suites = mvm->ciphers;
543 if (iwl_mvm_has_new_rx_api(mvm)) {
544 mvm->ciphers[hw->wiphy->n_cipher_suites] =
545 WLAN_CIPHER_SUITE_GCMP;
546 hw->wiphy->n_cipher_suites++;
547 mvm->ciphers[hw->wiphy->n_cipher_suites] =
548 WLAN_CIPHER_SUITE_GCMP_256;
549 hw->wiphy->n_cipher_suites++;
552 /* Enable 11w if software crypto is not enabled (as the
553 * firmware will interpret some mgmt packets, so enabling it
554 * with software crypto isn't safe).
556 if (!iwlwifi_mod_params.swcrypto) {
557 ieee80211_hw_set(hw, MFP_CAPABLE);
558 mvm->ciphers[hw->wiphy->n_cipher_suites] =
559 WLAN_CIPHER_SUITE_AES_CMAC;
560 hw->wiphy->n_cipher_suites++;
561 if (iwl_mvm_has_new_rx_api(mvm)) {
562 mvm->ciphers[hw->wiphy->n_cipher_suites] =
563 WLAN_CIPHER_SUITE_BIP_GMAC_128;
564 hw->wiphy->n_cipher_suites++;
565 mvm->ciphers[hw->wiphy->n_cipher_suites] =
566 WLAN_CIPHER_SUITE_BIP_GMAC_256;
567 hw->wiphy->n_cipher_suites++;
571 /* currently FW API supports only one optional cipher scheme */
572 if (mvm->fw->cs[0].cipher) {
573 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
574 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
576 mvm->hw->n_cipher_schemes = 1;
578 cs->cipher = le32_to_cpu(fwcs->cipher);
579 cs->iftype = BIT(NL80211_IFTYPE_STATION);
580 cs->hdr_len = fwcs->hdr_len;
581 cs->pn_len = fwcs->pn_len;
582 cs->pn_off = fwcs->pn_off;
583 cs->key_idx_off = fwcs->key_idx_off;
584 cs->key_idx_mask = fwcs->key_idx_mask;
585 cs->key_idx_shift = fwcs->key_idx_shift;
586 cs->mic_len = fwcs->mic_len;
588 mvm->hw->cipher_schemes = mvm->cs;
589 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
590 hw->wiphy->n_cipher_suites++;
593 if (fw_has_capa(&mvm->fw->ucode_capa,
594 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
595 wiphy_ext_feature_set(hw->wiphy,
596 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
597 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
600 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
601 hw->wiphy->features |=
602 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
603 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
604 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
606 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
607 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
608 hw->chanctx_data_size = sizeof(u16);
609 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
611 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
612 BIT(NL80211_IFTYPE_P2P_CLIENT) |
613 BIT(NL80211_IFTYPE_AP) |
614 BIT(NL80211_IFTYPE_P2P_GO) |
615 BIT(NL80211_IFTYPE_P2P_DEVICE) |
616 BIT(NL80211_IFTYPE_ADHOC);
618 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
619 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
620 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
622 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
623 if (iwl_mvm_is_lar_supported(mvm))
624 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
626 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
627 REGULATORY_DISABLE_BEACON_HINTS;
629 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
630 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
632 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
633 hw->wiphy->n_iface_combinations =
634 ARRAY_SIZE(iwl_mvm_iface_combinations);
636 hw->wiphy->max_remain_on_channel_duration = 10000;
637 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
639 /* Extract MAC address */
640 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
641 hw->wiphy->addresses = mvm->addresses;
642 hw->wiphy->n_addresses = 1;
644 /* Extract additional MAC addresses if available */
645 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
646 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
648 for (i = 1; i < num_mac; i++) {
649 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
651 mvm->addresses[i].addr[5]++;
652 hw->wiphy->n_addresses++;
655 iwl_mvm_reset_phy_ctxts(mvm);
657 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
659 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
661 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
662 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
663 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
665 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
666 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
668 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
670 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
671 hw->wiphy->bands[NL80211_BAND_2GHZ] =
672 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
673 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
674 hw->wiphy->bands[NL80211_BAND_5GHZ] =
675 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
677 if (fw_has_capa(&mvm->fw->ucode_capa,
678 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
679 fw_has_api(&mvm->fw->ucode_capa,
680 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
681 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
682 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
685 hw->wiphy->hw_version = mvm->trans->hw_id;
687 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
688 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
690 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
692 hw->wiphy->max_sched_scan_reqs = 1;
693 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
694 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
695 /* we create the 802.11 header and zero length SSID IE. */
696 hw->wiphy->max_sched_scan_ie_len =
697 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
698 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
699 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
702 * the firmware uses u8 for num of iterations, but 0xff is saved for
703 * infinite loop, so the maximum number of iterations is actually 254.
705 hw->wiphy->max_sched_scan_plan_iterations = 254;
707 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
708 NL80211_FEATURE_LOW_PRIORITY_SCAN |
709 NL80211_FEATURE_P2P_GO_OPPPS |
710 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
711 NL80211_FEATURE_DYNAMIC_SMPS |
712 NL80211_FEATURE_STATIC_SMPS |
713 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
715 if (fw_has_capa(&mvm->fw->ucode_capa,
716 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
717 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
718 if (fw_has_capa(&mvm->fw->ucode_capa,
719 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
720 hw->wiphy->features |= NL80211_FEATURE_QUIET;
722 if (fw_has_capa(&mvm->fw->ucode_capa,
723 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
724 hw->wiphy->features |=
725 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
727 if (fw_has_capa(&mvm->fw->ucode_capa,
728 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
729 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
731 if (fw_has_api(&mvm->fw->ucode_capa,
732 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
733 wiphy_ext_feature_set(hw->wiphy,
734 NL80211_EXT_FEATURE_SCAN_START_TIME);
735 wiphy_ext_feature_set(hw->wiphy,
736 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
737 wiphy_ext_feature_set(hw->wiphy,
738 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
741 if (iwl_mvm_is_oce_supported(mvm)) {
742 wiphy_ext_feature_set(hw->wiphy,
743 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
744 wiphy_ext_feature_set(hw->wiphy,
745 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
746 wiphy_ext_feature_set(hw->wiphy,
747 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
748 wiphy_ext_feature_set(hw->wiphy,
749 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
752 if (mvm->nvm_data->sku_cap_11ax_enable &&
753 !iwlwifi_mod_params.disable_11ax) {
754 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
755 hw->wiphy->num_iftype_ext_capab =
756 ARRAY_SIZE(he_iftypes_ext_capa);
758 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
759 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
762 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
764 #ifdef CONFIG_PM_SLEEP
765 if (iwl_mvm_is_d0i3_supported(mvm) &&
766 device_can_wakeup(mvm->trans->dev)) {
767 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
768 hw->wiphy->wowlan = &mvm->wowlan;
771 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
772 mvm->trans->ops->d3_suspend &&
773 mvm->trans->ops->d3_resume &&
774 device_can_wakeup(mvm->trans->dev)) {
775 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
776 WIPHY_WOWLAN_DISCONNECT |
777 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
778 WIPHY_WOWLAN_RFKILL_RELEASE |
779 WIPHY_WOWLAN_NET_DETECT;
780 if (!iwlwifi_mod_params.swcrypto)
781 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
782 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
783 WIPHY_WOWLAN_4WAY_HANDSHAKE;
785 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
786 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
787 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
788 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
789 hw->wiphy->wowlan = &mvm->wowlan;
793 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
794 /* assign default bcast filtering configuration */
795 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
798 ret = iwl_mvm_leds_init(mvm);
802 if (fw_has_capa(&mvm->fw->ucode_capa,
803 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
804 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
805 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
806 ieee80211_hw_set(hw, TDLS_WIDER_BW);
809 if (fw_has_capa(&mvm->fw->ucode_capa,
810 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
811 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
812 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
815 hw->netdev_features |= mvm->cfg->features;
816 if (!iwl_mvm_is_csum_supported(mvm)) {
817 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
819 /* We may support SW TX CSUM */
820 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
821 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
824 if (mvm->cfg->vht_mu_mimo_supported)
825 wiphy_ext_feature_set(hw->wiphy,
826 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
828 ret = ieee80211_register_hw(mvm->hw);
830 iwl_mvm_leds_exit(mvm);
836 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
837 struct ieee80211_sta *sta,
840 struct iwl_mvm_sta *mvmsta;
844 * double check the IN_D0I3 flag both before and after
845 * taking the spinlock, in order to prevent taking
846 * the spinlock when not needed.
848 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
851 spin_lock(&mvm->d0i3_tx_lock);
853 * testing the flag again ensures the skb dequeue
854 * loop (on d0i3 exit) hasn't run yet.
856 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
859 mvmsta = iwl_mvm_sta_from_mac80211(sta);
860 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
861 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
864 __skb_queue_tail(&mvm->d0i3_tx, skb);
867 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
868 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
872 spin_unlock(&mvm->d0i3_tx_lock);
876 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
877 struct ieee80211_tx_control *control,
880 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
881 struct ieee80211_sta *sta = control->sta;
882 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
883 struct ieee80211_hdr *hdr = (void *)skb->data;
884 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
885 IEEE80211_TX_CTL_TX_OFFCHAN;
887 if (iwl_mvm_is_radio_killed(mvm)) {
888 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
893 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
894 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
897 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
898 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
899 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
900 ieee80211_is_mgmt(hdr->frame_control) &&
901 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
904 /* If there is no sta, and it's not offchannel - send through AP */
905 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
907 struct iwl_mvm_vif *mvmvif =
908 iwl_mvm_vif_from_mac80211(info->control.vif);
909 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
911 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
912 /* mac80211 holds rcu read lock */
913 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
914 if (IS_ERR_OR_NULL(sta))
920 if (iwl_mvm_defer_tx(mvm, sta, skb))
922 if (iwl_mvm_tx_skb(mvm, skb, sta))
927 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
931 ieee80211_free_txskb(hw, skb);
934 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
936 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
937 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
938 struct sk_buff *skb = NULL;
941 * No need for threads to be pending here, they can leave the first
942 * taker all the work.
944 * mvmtxq->tx_request logic:
946 * If 0, no one is currently TXing, set to 1 to indicate current thread
947 * will now start TX and other threads should quit.
949 * If 1, another thread is currently TXing, set to 2 to indicate to
950 * that thread that there was another request. Since that request may
951 * have raced with the check whether the queue is empty, the TXing
952 * thread should check the queue's status one more time before leaving.
953 * This check is done in order to not leave any TX hanging in the queue
954 * until the next TX invocation (which may not even happen).
956 * If 2, another thread is currently TXing, and it will already double
957 * check the queue, so do nothing.
959 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
964 while (likely(!mvmtxq->stopped &&
965 (mvm->trans->system_pm_mode ==
966 IWL_PLAT_PM_MODE_DISABLED))) {
967 skb = ieee80211_tx_dequeue(hw, txq);
972 "TXQ of sta %pM tid %d is now empty\n",
979 iwl_mvm_tx_skb_non_sta(mvm, skb);
981 iwl_mvm_tx_skb(mvm, skb, txq->sta);
983 } while (atomic_dec_return(&mvmtxq->tx_request));
987 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
988 struct ieee80211_txq *txq)
990 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
991 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
994 * Please note that racing is handled very carefully here:
995 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
996 * deleted afterwards.
997 * This means that if:
998 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
999 * queue is allocated and we can TX.
1000 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
1001 * a race, should defer the frame.
1002 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
1003 * need to allocate the queue and defer the frame.
1004 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
1005 * queue is already scheduled for allocation, no need to allocate,
1006 * should defer the frame.
1009 /* If the queue is allocated TX and return. */
1010 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
1012 * Check that list is empty to avoid a race where txq_id is
1013 * already updated, but the queue allocation work wasn't
1016 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
1019 iwl_mvm_mac_itxq_xmit(hw, txq);
1023 /* The list is being deleted only after the queue is fully allocated. */
1024 if (!list_empty(&mvmtxq->list))
1027 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
1028 schedule_work(&mvm->add_stream_wk);
1031 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
1033 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
1035 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
1039 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1040 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
1041 enum ieee80211_ampdu_mlme_action action)
1043 struct iwl_fw_dbg_trigger_tlv *trig;
1044 struct iwl_fw_dbg_trigger_ba *ba_trig;
1046 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1051 ba_trig = (void *)trig->data;
1054 case IEEE80211_AMPDU_TX_OPERATIONAL: {
1055 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1056 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1058 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
1059 "TX AGG START: MAC %pM tid %d ssn %d\n",
1060 sta->addr, tid, tid_data->ssn);
1063 case IEEE80211_AMPDU_TX_STOP_CONT:
1064 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
1065 "TX AGG STOP: MAC %pM tid %d\n",
1068 case IEEE80211_AMPDU_RX_START:
1069 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
1070 "RX AGG START: MAC %pM tid %d ssn %d\n",
1071 sta->addr, tid, rx_ba_ssn);
1073 case IEEE80211_AMPDU_RX_STOP:
1074 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
1075 "RX AGG STOP: MAC %pM tid %d\n",
1083 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
1084 struct ieee80211_vif *vif,
1085 struct ieee80211_ampdu_params *params)
1087 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1089 bool tx_agg_ref = false;
1090 struct ieee80211_sta *sta = params->sta;
1091 enum ieee80211_ampdu_mlme_action action = params->action;
1092 u16 tid = params->tid;
1093 u16 *ssn = ¶ms->ssn;
1094 u16 buf_size = params->buf_size;
1095 bool amsdu = params->amsdu;
1096 u16 timeout = params->timeout;
1098 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
1099 sta->addr, tid, action);
1101 if (!(mvm->nvm_data->sku_cap_11n_enable))
1104 /* return from D0i3 before starting a new Tx aggregation */
1106 case IEEE80211_AMPDU_TX_START:
1107 case IEEE80211_AMPDU_TX_STOP_CONT:
1108 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1109 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1110 case IEEE80211_AMPDU_TX_OPERATIONAL:
1112 * for tx start, wait synchronously until D0i3 exit to
1113 * get the correct sequence number for the tid.
1114 * additionally, some other ampdu actions use direct
1115 * target access, which is not handled automatically
1116 * by the trans layer (unlike commands), so wait for
1117 * d0i3 exit in these cases as well.
1119 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
1129 mutex_lock(&mvm->mutex);
1132 case IEEE80211_AMPDU_RX_START:
1133 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
1134 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
1135 struct iwl_mvm_vif *mvmvif;
1136 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
1137 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
1139 mdata->opened_rx_ba_sessions = true;
1140 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1141 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
1143 if (!iwl_enable_rx_ampdu()) {
1147 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1150 case IEEE80211_AMPDU_RX_STOP:
1151 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1154 case IEEE80211_AMPDU_TX_START:
1155 if (!iwl_enable_tx_ampdu()) {
1159 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1161 case IEEE80211_AMPDU_TX_STOP_CONT:
1162 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1164 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1165 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1166 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1168 case IEEE80211_AMPDU_TX_OPERATIONAL:
1169 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1181 if (action == IEEE80211_AMPDU_RX_START)
1184 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1187 mutex_unlock(&mvm->mutex);
1190 * If the tid is marked as started, we won't use it for offloaded
1191 * traffic on the next D0i3 entry. It's safe to unref.
1194 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1199 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1200 struct ieee80211_vif *vif)
1202 struct iwl_mvm *mvm = data;
1203 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1205 mvmvif->uploaded = false;
1206 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1208 spin_lock_bh(&mvm->time_event_lock);
1209 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1210 spin_unlock_bh(&mvm->time_event_lock);
1212 mvmvif->phy_ctxt = NULL;
1213 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1214 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1217 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1219 /* cleanup all stale references (scan, roc), but keep the
1220 * ucode_down ref until reconfig is complete
1222 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1224 iwl_mvm_stop_device(mvm);
1228 mvm->scan_status = 0;
1229 mvm->ps_disabled = false;
1230 mvm->rfkill_safe_init_done = false;
1232 /* just in case one was running */
1233 iwl_mvm_cleanup_roc_te(mvm);
1234 ieee80211_remain_on_channel_expired(mvm->hw);
1236 iwl_mvm_ftm_restart(mvm);
1239 * cleanup all interfaces, even inactive ones, as some might have
1240 * gone down during the HW restart
1242 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1244 mvm->p2p_device_vif = NULL;
1245 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1247 iwl_mvm_reset_phy_ctxts(mvm);
1248 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1249 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1250 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1252 ieee80211_wake_queues(mvm->hw);
1254 /* clear any stale d0i3 state */
1255 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1258 mvm->rx_ba_sessions = 0;
1259 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1260 mvm->monitor_on = false;
1262 /* keep statistics ticking */
1263 iwl_mvm_accu_radio_stats(mvm);
1266 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1270 lockdep_assert_held(&mvm->mutex);
1272 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1274 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1275 * so later code will - from now on - see that we're doing it.
1277 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1278 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1279 /* Clean up some internal and mac80211 state on restart */
1280 iwl_mvm_restart_cleanup(mvm);
1282 /* Hold the reference to prevent runtime suspend while
1283 * the start procedure runs. It's a bit confusing
1284 * that the UCODE_DOWN reference is taken, but it just
1285 * means "UCODE is not UP yet". ( TODO: rename this
1288 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1290 ret = iwl_mvm_up(mvm);
1292 iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_POST_INIT);
1294 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1295 /* Something went wrong - we need to finish some cleanup
1296 * that normally iwl_mvm_mac_restart_complete() below
1299 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1301 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1308 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1313 /* Some hw restart cleanups must not hold the mutex */
1314 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1316 * Make sure we are out of d0i3. This is needed
1317 * to make sure the reference accounting is correct
1318 * (and there is no stale d0i3_exit_work).
1320 wait_event_timeout(mvm->d0i3_exit_waitq,
1321 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1326 mutex_lock(&mvm->mutex);
1327 ret = __iwl_mvm_mac_start(mvm);
1328 mutex_unlock(&mvm->mutex);
1333 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1337 mutex_lock(&mvm->mutex);
1339 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1341 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1343 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1345 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1348 /* allow transport/FW low power modes */
1349 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1351 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1354 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1355 * of packets the FW sent out, so we must reconnect.
1357 iwl_mvm_teardown_tdls_peers(mvm);
1359 mutex_unlock(&mvm->mutex);
1362 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1364 if (iwl_mvm_is_d0i3_supported(mvm) &&
1365 iwl_mvm_enter_d0i3_on_suspend(mvm))
1366 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1367 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1370 "D0i3 exit on resume timed out\n");
1374 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1375 enum ieee80211_reconfig_type reconfig_type)
1377 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1379 switch (reconfig_type) {
1380 case IEEE80211_RECONFIG_TYPE_RESTART:
1381 iwl_mvm_restart_complete(mvm);
1383 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1384 iwl_mvm_resume_complete(mvm);
1389 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1391 lockdep_assert_held(&mvm->mutex);
1393 /* firmware counters are obviously reset now, but we shouldn't
1394 * partially track so also clear the fw_reset_accu counters.
1396 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1398 /* async_handlers_wk is now blocked */
1401 * The work item could be running or queued if the
1402 * ROC time event stops just as we get here.
1404 flush_work(&mvm->roc_done_wk);
1406 iwl_mvm_stop_device(mvm);
1408 iwl_mvm_async_handlers_purge(mvm);
1409 /* async_handlers_list is empty and will stay empty: HW is stopped */
1411 /* the fw is stopped, the aux sta is dead: clean up driver state */
1412 iwl_mvm_del_aux_sta(mvm);
1415 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1416 * hw (as restart_complete() won't be called in this case) and mac80211
1417 * won't execute the restart.
1418 * But make sure to cleanup interfaces that have gone down before/during
1419 * HW restart was requested.
1421 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1422 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1424 ieee80211_iterate_interfaces(mvm->hw, 0,
1425 iwl_mvm_cleanup_iterator, mvm);
1427 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1428 * make sure there's nothing left there and warn if any is found.
1430 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1433 for (i = 0; i < mvm->max_scans; i++) {
1434 if (WARN_ONCE(mvm->scan_uid_status[i],
1435 "UMAC scan UID %d status was not cleaned\n",
1437 mvm->scan_uid_status[i] = 0;
1442 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1444 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1446 flush_work(&mvm->d0i3_exit_work);
1447 flush_work(&mvm->async_handlers_wk);
1448 flush_work(&mvm->add_stream_wk);
1451 * Lock and clear the firmware running bit here already, so that
1452 * new commands coming in elsewhere, e.g. from debugfs, will not
1453 * be able to proceed. This is important here because one of those
1454 * debugfs files causes the firmware dump to be triggered, and if we
1455 * don't stop debugfs accesses before canceling that it could be
1456 * retriggered after we flush it but before we've cleared the bit.
1458 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1460 iwl_fw_cancel_dumps(&mvm->fwrt);
1461 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1462 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1463 iwl_fw_free_dump_desc(&mvm->fwrt);
1465 mutex_lock(&mvm->mutex);
1466 __iwl_mvm_mac_stop(mvm);
1467 mutex_unlock(&mvm->mutex);
1470 * The worker might have been waiting for the mutex, let it run and
1471 * discover that its list is now empty.
1473 cancel_work_sync(&mvm->async_handlers_wk);
1476 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1480 lockdep_assert_held(&mvm->mutex);
1482 for (i = 0; i < NUM_PHY_CTX; i++)
1483 if (!mvm->phy_ctxts[i].ref)
1484 return &mvm->phy_ctxts[i];
1486 IWL_ERR(mvm, "No available PHY context\n");
1490 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1495 struct iwl_dev_tx_power_cmd v5;
1496 struct iwl_dev_tx_power_cmd_v4 v4;
1498 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1499 .v5.v3.mac_context_id =
1500 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1501 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1504 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1505 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1507 if (fw_has_api(&mvm->fw->ucode_capa,
1508 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1509 len = sizeof(cmd.v5);
1510 else if (fw_has_capa(&mvm->fw->ucode_capa,
1511 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1512 len = sizeof(cmd.v4);
1514 len = sizeof(cmd.v4.v3);
1516 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1519 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1520 struct ieee80211_vif *vif)
1522 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1523 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1526 mutex_lock(&mvm->mutex);
1528 if (mvmvif->csa_failed) {
1529 mvmvif->csa_failed = false;
1534 if (vif->type == NL80211_IFTYPE_STATION) {
1535 struct iwl_mvm_sta *mvmsta;
1537 mvmvif->csa_bcn_pending = false;
1538 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1541 if (WARN_ON(!mvmsta)) {
1546 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1548 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1550 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1554 iwl_mvm_stop_session_protection(mvm, vif);
1557 mvmvif->ps_disabled = false;
1559 ret = iwl_mvm_power_update_ps(mvm);
1562 mutex_unlock(&mvm->mutex);
1567 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1568 struct ieee80211_vif *vif)
1570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1571 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1572 struct iwl_chan_switch_te_cmd cmd = {
1573 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1575 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1578 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1580 mutex_lock(&mvm->mutex);
1581 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1582 WIDE_ID(MAC_CONF_GROUP,
1583 CHANNEL_SWITCH_TIME_EVENT_CMD),
1584 0, sizeof(cmd), &cmd));
1585 mutex_unlock(&mvm->mutex);
1587 WARN_ON(iwl_mvm_post_channel_switch(hw, vif));
1590 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1592 struct iwl_mvm *mvm;
1593 struct iwl_mvm_vif *mvmvif;
1594 struct ieee80211_vif *vif;
1596 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1597 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1600 iwl_mvm_abort_channel_switch(mvm->hw, vif);
1601 ieee80211_chswitch_done(vif, false);
1604 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1605 struct ieee80211_vif *vif)
1607 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1608 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1612 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1615 * make sure D0i3 exit is completed, otherwise a target access
1616 * during tx queue configuration could be done when still in
1619 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1624 * Not much to do here. The stack will not allow interface
1625 * types or combinations that we didn't advertise, so we
1626 * don't really have to check the types.
1629 mutex_lock(&mvm->mutex);
1631 /* make sure that beacon statistics don't go backwards with FW reset */
1632 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1633 mvmvif->beacon_stats.accu_num_beacons +=
1634 mvmvif->beacon_stats.num_beacons;
1636 /* Allocate resources for the MAC context, and add it to the fw */
1637 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1641 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1643 /* Counting number of interfaces is needed for legacy PM */
1644 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1648 * The AP binding flow can be done only after the beacon
1649 * template is configured (which happens only in the mac80211
1650 * start_ap() flow), and adding the broadcast station can happen
1651 * only after the binding.
1652 * In addition, since modifying the MAC before adding a bcast
1653 * station is not allowed by the FW, delay the adding of MAC context to
1654 * the point where we can also add the bcast station.
1655 * In short: there's not much we can do at this point, other than
1656 * allocating resources :)
1658 if (vif->type == NL80211_IFTYPE_AP ||
1659 vif->type == NL80211_IFTYPE_ADHOC) {
1660 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1662 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1667 * Only queue for this station is the mcast queue,
1668 * which shouldn't be in TFD mask anyway
1670 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1676 iwl_mvm_vif_dbgfs_register(mvm, vif);
1680 mvmvif->features |= hw->netdev_features;
1682 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1686 ret = iwl_mvm_power_update_mac(mvm);
1688 goto out_remove_mac;
1690 /* beacon filtering */
1691 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1693 goto out_remove_mac;
1695 if (!mvm->bf_allowed_vif &&
1696 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1697 mvm->bf_allowed_vif = mvmvif;
1698 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1699 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1703 * P2P_DEVICE interface does not have a channel context assigned to it,
1704 * so a dedicated PHY context is allocated to it and the corresponding
1705 * MAC context is bound to it at this stage.
1707 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1709 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1710 if (!mvmvif->phy_ctxt) {
1715 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1716 ret = iwl_mvm_binding_add_vif(mvm, vif);
1720 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1724 /* Save a pointer to p2p device vif, so it can later be used to
1725 * update the p2p device MAC when a GO is started/stopped */
1726 mvm->p2p_device_vif = vif;
1729 iwl_mvm_tcm_add_vif(mvm, vif);
1730 INIT_DELAYED_WORK(&mvmvif->csa_work,
1731 iwl_mvm_channel_switch_disconnect_wk);
1733 if (vif->type == NL80211_IFTYPE_MONITOR)
1734 mvm->monitor_on = true;
1736 iwl_mvm_vif_dbgfs_register(mvm, vif);
1740 iwl_mvm_binding_remove_vif(mvm, vif);
1742 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1744 if (mvm->bf_allowed_vif == mvmvif) {
1745 mvm->bf_allowed_vif = NULL;
1746 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1747 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1750 mvmvif->phy_ctxt = NULL;
1751 iwl_mvm_mac_ctxt_remove(mvm, vif);
1753 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1756 mutex_unlock(&mvm->mutex);
1758 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1763 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1764 struct ieee80211_vif *vif)
1766 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1768 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1769 * We assume here that all the packets sent to the OFFCHANNEL
1770 * queue are sent in ROC session.
1772 flush_work(&mvm->roc_done_wk);
1776 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1777 struct ieee80211_vif *vif)
1779 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1780 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1781 struct iwl_probe_resp_data *probe_data;
1783 iwl_mvm_prepare_mac_removal(mvm, vif);
1785 if (!(vif->type == NL80211_IFTYPE_AP ||
1786 vif->type == NL80211_IFTYPE_ADHOC))
1787 iwl_mvm_tcm_rm_vif(mvm, vif);
1789 mutex_lock(&mvm->mutex);
1791 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1792 lockdep_is_held(&mvm->mutex));
1793 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1795 kfree_rcu(probe_data, rcu_head);
1797 if (mvm->bf_allowed_vif == mvmvif) {
1798 mvm->bf_allowed_vif = NULL;
1799 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1800 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1803 if (vif->bss_conf.ftm_responder)
1804 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1806 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1809 * For AP/GO interface, the tear down of the resources allocated to the
1810 * interface is be handled as part of the stop_ap flow.
1812 if (vif->type == NL80211_IFTYPE_AP ||
1813 vif->type == NL80211_IFTYPE_ADHOC) {
1814 #ifdef CONFIG_NL80211_TESTMODE
1815 if (vif == mvm->noa_vif) {
1816 mvm->noa_vif = NULL;
1817 mvm->noa_duration = 0;
1820 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1821 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1825 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1826 mvm->p2p_device_vif = NULL;
1827 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1828 iwl_mvm_binding_remove_vif(mvm, vif);
1829 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1830 mvmvif->phy_ctxt = NULL;
1833 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1836 iwl_mvm_power_update_mac(mvm);
1837 iwl_mvm_mac_ctxt_remove(mvm, vif);
1839 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1841 if (vif->type == NL80211_IFTYPE_MONITOR)
1842 mvm->monitor_on = false;
1845 mutex_unlock(&mvm->mutex);
1848 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1853 struct iwl_mvm_mc_iter_data {
1854 struct iwl_mvm *mvm;
1858 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1859 struct ieee80211_vif *vif)
1861 struct iwl_mvm_mc_iter_data *data = _data;
1862 struct iwl_mvm *mvm = data->mvm;
1863 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1864 struct iwl_host_cmd hcmd = {
1865 .id = MCAST_FILTER_CMD,
1867 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1871 /* if we don't have free ports, mcast frames will be dropped */
1872 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1875 if (vif->type != NL80211_IFTYPE_STATION ||
1876 !vif->bss_conf.assoc)
1879 cmd->port_id = data->port_id++;
1880 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1881 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1886 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1888 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1891 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1893 struct iwl_mvm_mc_iter_data iter_data = {
1897 lockdep_assert_held(&mvm->mutex);
1899 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1902 ieee80211_iterate_active_interfaces_atomic(
1903 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1904 iwl_mvm_mc_iface_iterator, &iter_data);
1907 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1908 struct netdev_hw_addr_list *mc_list)
1910 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1911 struct iwl_mcast_filter_cmd *cmd;
1912 struct netdev_hw_addr *addr;
1917 addr_count = netdev_hw_addr_list_count(mc_list);
1918 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1919 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1923 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1924 cmd = kzalloc(len, GFP_ATOMIC);
1930 return (u64)(unsigned long)cmd;
1933 netdev_hw_addr_list_for_each(addr, mc_list) {
1934 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1935 cmd->count, addr->addr);
1936 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1937 addr->addr, ETH_ALEN);
1941 return (u64)(unsigned long)cmd;
1944 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1945 unsigned int changed_flags,
1946 unsigned int *total_flags,
1949 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1950 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1952 mutex_lock(&mvm->mutex);
1954 /* replace previous configuration */
1955 kfree(mvm->mcast_filter_cmd);
1956 mvm->mcast_filter_cmd = cmd;
1961 if (changed_flags & FIF_ALLMULTI)
1962 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1967 iwl_mvm_recalc_multicast(mvm);
1969 mutex_unlock(&mvm->mutex);
1973 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1974 struct ieee80211_vif *vif,
1975 unsigned int filter_flags,
1976 unsigned int changed_flags)
1978 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1980 /* We support only filter for probe requests */
1981 if (!(changed_flags & FIF_PROBE_REQ))
1984 /* Supported only for p2p client interfaces */
1985 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1989 mutex_lock(&mvm->mutex);
1990 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1991 mutex_unlock(&mvm->mutex);
1994 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1995 struct iwl_bcast_iter_data {
1996 struct iwl_mvm *mvm;
1997 struct iwl_bcast_filter_cmd *cmd;
2002 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
2003 const struct iwl_fw_bcast_filter *in_filter,
2004 struct iwl_fw_bcast_filter *out_filter)
2006 struct iwl_fw_bcast_filter_attr *attr;
2009 memcpy(out_filter, in_filter, sizeof(*out_filter));
2011 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
2012 attr = &out_filter->attrs[i];
2017 switch (attr->reserved1) {
2018 case cpu_to_le16(BC_FILTER_MAGIC_IP):
2019 if (vif->bss_conf.arp_addr_cnt != 1) {
2024 attr->val = vif->bss_conf.arp_addr_list[0];
2026 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
2027 attr->val = *(__be32 *)&vif->addr[2];
2032 attr->reserved1 = 0;
2033 out_filter->num_attrs++;
2037 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
2038 struct ieee80211_vif *vif)
2040 struct iwl_bcast_iter_data *data = _data;
2041 struct iwl_mvm *mvm = data->mvm;
2042 struct iwl_bcast_filter_cmd *cmd = data->cmd;
2043 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2044 struct iwl_fw_bcast_mac *bcast_mac;
2047 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
2050 bcast_mac = &cmd->macs[mvmvif->id];
2053 * enable filtering only for associated stations, but not for P2P
2056 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
2057 !vif->bss_conf.assoc)
2060 bcast_mac->default_discard = 1;
2062 /* copy all configured filters */
2063 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
2065 * Make sure we don't exceed our filters limit.
2066 * if there is still a valid filter to be configured,
2067 * be on the safe side and just allow bcast for this mac.
2069 if (WARN_ON_ONCE(data->current_filter >=
2070 ARRAY_SIZE(cmd->filters))) {
2071 bcast_mac->default_discard = 0;
2072 bcast_mac->attached_filters = 0;
2076 iwl_mvm_set_bcast_filter(vif,
2077 &mvm->bcast_filters[i],
2078 &cmd->filters[data->current_filter]);
2080 /* skip current filter if it contains no attributes */
2081 if (!cmd->filters[data->current_filter].num_attrs)
2084 /* attach the filter to current mac */
2085 bcast_mac->attached_filters |=
2086 cpu_to_le16(BIT(data->current_filter));
2088 data->current_filter++;
2092 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
2093 struct iwl_bcast_filter_cmd *cmd)
2095 struct iwl_bcast_iter_data iter_data = {
2100 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
2103 memset(cmd, 0, sizeof(*cmd));
2104 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
2105 cmd->max_macs = ARRAY_SIZE(cmd->macs);
2107 #ifdef CONFIG_IWLWIFI_DEBUGFS
2108 /* use debugfs filters/macs if override is configured */
2109 if (mvm->dbgfs_bcast_filtering.override) {
2110 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
2111 sizeof(cmd->filters));
2112 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
2118 /* if no filters are configured, do nothing */
2119 if (!mvm->bcast_filters)
2122 /* configure and attach these filters for each associated sta vif */
2123 ieee80211_iterate_active_interfaces(
2124 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2125 iwl_mvm_bcast_filter_iterator, &iter_data);
2130 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2132 struct iwl_bcast_filter_cmd cmd;
2134 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
2137 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
2140 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
2144 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2150 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
2151 struct ieee80211_vif *vif)
2153 struct iwl_mu_group_mgmt_cmd cmd = {};
2155 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
2156 WLAN_MEMBERSHIP_LEN);
2157 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
2158 WLAN_USER_POSITION_LEN);
2160 return iwl_mvm_send_cmd_pdu(mvm,
2161 WIDE_ID(DATA_PATH_GROUP,
2162 UPDATE_MU_GROUPS_CMD),
2163 0, sizeof(cmd), &cmd);
2166 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
2167 struct ieee80211_vif *vif)
2169 if (vif->mu_mimo_owner) {
2170 struct iwl_mu_group_mgmt_notif *notif = _data;
2173 * MU-MIMO Group Id action frame is little endian. We treat
2174 * the data received from firmware as if it came from the
2175 * action frame, so no conversion is needed.
2177 ieee80211_update_mu_groups(vif,
2178 (u8 *)¬if->membership_status,
2179 (u8 *)¬if->user_position);
2183 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2184 struct iwl_rx_cmd_buffer *rxb)
2186 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2187 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
2189 ieee80211_iterate_active_interfaces_atomic(
2190 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2191 iwl_mvm_mu_mimo_iface_iterator, notif);
2194 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
2196 u8 byte_num = ppe_pos_bit / 8;
2197 u8 bit_num = ppe_pos_bit % 8;
2202 return (ppe[byte_num] >> bit_num) &
2203 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
2206 * If bit_num > 5, we have to combine bits with next byte.
2207 * Calculate how many bits we need to take from current byte (called
2208 * here "residue_bits"), and add them to bits from next byte.
2211 residue_bits = 8 - bit_num;
2213 res = (ppe[byte_num + 1] &
2214 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
2216 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
2221 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2222 struct ieee80211_vif *vif, u8 sta_id)
2224 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2225 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
2227 .tid_limit = IWL_MAX_TID_COUNT,
2228 .bss_color = vif->bss_conf.bss_color,
2229 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2230 .frame_time_rts_th =
2231 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2233 int size = fw_has_api(&mvm->fw->ucode_capa,
2234 IWL_UCODE_TLV_API_MBSSID_HE) ?
2235 sizeof(sta_ctxt_cmd) :
2236 sizeof(struct iwl_he_sta_context_cmd_v1);
2237 struct ieee80211_sta *sta;
2243 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2246 WARN(1, "Can't find STA to configure HE\n");
2250 if (!sta->he_cap.has_he) {
2258 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2259 IEEE80211_HE_MAC_CAP0_HTC_HE)
2260 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2261 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2262 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2263 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2264 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2266 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2267 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2268 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2269 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2272 sta_ctxt_cmd.htc_flags |=
2273 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2274 else if (link_adap == 3)
2275 sta_ctxt_cmd.htc_flags |=
2276 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2278 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2279 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2280 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2281 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2282 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2283 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2284 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2287 * Initialize the PPE thresholds to "None" (7), as described in Table
2288 * 9-262ac of 80211.ax/D3.0.
2290 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2292 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2293 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2294 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2295 u8 nss = (sta->he_cap.ppe_thres[0] &
2296 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2297 u8 ru_index_bitmap =
2298 (sta->he_cap.ppe_thres[0] &
2299 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2300 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2301 u8 *ppe = &sta->he_cap.ppe_thres[0];
2302 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2305 * FW currently supports only nss == MAX_HE_SUPP_NSS
2307 * If nss > MAX: we can ignore values we don't support
2308 * If nss < MAX: we can set zeros in other streams
2310 if (nss > MAX_HE_SUPP_NSS) {
2311 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2313 nss = MAX_HE_SUPP_NSS;
2316 for (i = 0; i < nss; i++) {
2317 u8 ru_index_tmp = ru_index_bitmap << 1;
2320 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2322 if (!(ru_index_tmp & 1))
2325 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2326 iwl_mvm_he_get_ppe_val(ppe,
2329 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2330 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2331 iwl_mvm_he_get_ppe_val(ppe,
2334 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2338 flags |= STA_CTXT_HE_PACKET_EXT;
2339 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2340 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2341 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2345 /* Take the PPE thresholds from the nominal padding info */
2346 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2347 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2348 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2349 low_th = IWL_HE_PKT_EXT_NONE;
2350 high_th = IWL_HE_PKT_EXT_NONE;
2352 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2353 low_th = IWL_HE_PKT_EXT_BPSK;
2354 high_th = IWL_HE_PKT_EXT_NONE;
2356 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2357 low_th = IWL_HE_PKT_EXT_NONE;
2358 high_th = IWL_HE_PKT_EXT_BPSK;
2362 /* Set the PPE thresholds accordingly */
2363 if (low_th >= 0 && high_th >= 0) {
2364 struct iwl_he_pkt_ext *pkt_ext =
2365 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
2367 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2370 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2372 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2374 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2379 flags |= STA_CTXT_HE_PACKET_EXT;
2384 /* Mark MU EDCA as enabled, unless none detected on some AC */
2385 flags |= STA_CTXT_HE_MU_EDCA_CW;
2386 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2387 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2388 &mvmvif->queue_params[i].mu_edca_param_rec;
2389 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2391 if (!mvmvif->queue_params[i].mu_edca) {
2392 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2396 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2397 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2398 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2399 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2400 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2401 cpu_to_le16(mu_edca->aifsn);
2402 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2403 cpu_to_le16(mu_edca->mu_edca_timer);
2406 if (vif->bss_conf.multi_sta_back_32bit)
2407 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2409 if (vif->bss_conf.ack_enabled)
2410 flags |= STA_CTXT_HE_ACK_ENABLED;
2412 if (vif->bss_conf.uora_exists) {
2413 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2415 sta_ctxt_cmd.rand_alloc_ecwmin =
2416 vif->bss_conf.uora_ocw_range & 0x7;
2417 sta_ctxt_cmd.rand_alloc_ecwmax =
2418 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2421 if (vif->bss_conf.nontransmitted) {
2422 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2423 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2424 vif->bss_conf.transmitter_bssid);
2425 sta_ctxt_cmd.max_bssid_indicator =
2426 vif->bss_conf.bssid_indicator;
2427 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2428 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2429 sta_ctxt_cmd.profile_periodicity =
2430 vif->bss_conf.profile_periodicity;
2433 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2435 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2436 DATA_PATH_GROUP, 0),
2437 0, size, &sta_ctxt_cmd))
2438 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2441 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2442 struct ieee80211_vif *vif,
2443 struct ieee80211_bss_conf *bss_conf,
2446 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2450 * Re-calculate the tsf id, as the master-slave relations depend on the
2451 * beacon interval, which was not known when the station interface was
2454 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2455 if (vif->bss_conf.he_support &&
2456 !iwlwifi_mod_params.disable_11ax)
2457 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2459 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2462 /* Update MU EDCA params */
2463 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2464 bss_conf->assoc && vif->bss_conf.he_support &&
2465 !iwlwifi_mod_params.disable_11ax)
2466 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2469 * If we're not associated yet, take the (new) BSSID before associating
2470 * so the firmware knows. If we're already associated, then use the old
2471 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2472 * branch for disassociation below.
2474 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2475 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2477 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2479 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2481 /* after sending it once, adopt mac80211 data */
2482 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2483 mvmvif->associated = bss_conf->assoc;
2485 if (changes & BSS_CHANGED_ASSOC) {
2486 if (bss_conf->assoc) {
2487 /* clear statistics to get clean beacon counter */
2488 iwl_mvm_request_statistics(mvm, true);
2489 memset(&mvmvif->beacon_stats, 0,
2490 sizeof(mvmvif->beacon_stats));
2492 /* add quota for this interface */
2493 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2495 IWL_ERR(mvm, "failed to update quotas\n");
2499 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2502 * If we're restarting then the firmware will
2503 * obviously have lost synchronisation with
2504 * the AP. It will attempt to synchronise by
2505 * itself, but we can make it more reliable by
2506 * scheduling a session protection time event.
2508 * The firmware needs to receive a beacon to
2509 * catch up with synchronisation, use 110% of
2510 * the beacon interval.
2512 * Set a large maximum delay to allow for more
2513 * than a single interface.
2515 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2516 iwl_mvm_protect_session(mvm, vif, dur, dur,
2520 iwl_mvm_sf_update(mvm, vif, false);
2521 iwl_mvm_power_vif_assoc(mvm, vif);
2523 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2524 iwl_mvm_update_smps(mvm, vif,
2525 IWL_MVM_SMPS_REQ_PROT,
2526 IEEE80211_SMPS_DYNAMIC);
2528 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2530 * If update fails - SF might be running in associated
2531 * mode while disassociated - which is forbidden.
2533 ret = iwl_mvm_sf_update(mvm, vif, false);
2535 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2537 "Failed to update SF upon disassociation\n");
2540 * If we get an assert during the connection (after the
2541 * station has been added, but before the vif is set
2542 * to associated), mac80211 will re-add the station and
2543 * then configure the vif. Since the vif is not
2544 * associated, we would remove the station here and
2545 * this would fail the recovery.
2547 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2550 * Remove AP station now that
2551 * the MAC is unassoc
2553 ret = iwl_mvm_rm_sta_id(mvm, vif,
2557 "failed to remove AP station\n");
2559 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2560 mvm->d0i3_ap_sta_id =
2561 IWL_MVM_INVALID_STA;
2562 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2565 /* remove quota for this interface */
2566 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2568 IWL_ERR(mvm, "failed to update quotas\n");
2571 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2573 /* this will take the cleared BSSID from bss_conf */
2574 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2577 "failed to update MAC %pM (clear after unassoc)\n",
2582 * The firmware tracks the MU-MIMO group on its own.
2583 * However, on HW restart we should restore this data.
2585 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2586 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2587 ret = iwl_mvm_update_mu_groups(mvm, vif);
2590 "failed to update VHT MU_MIMO groups\n");
2593 iwl_mvm_recalc_multicast(mvm);
2594 iwl_mvm_configure_bcast_filter(mvm);
2596 /* reset rssi values */
2597 mvmvif->bf_data.ave_beacon_signal = 0;
2599 iwl_mvm_bt_coex_vif_change(mvm);
2600 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2601 IEEE80211_SMPS_AUTOMATIC);
2602 if (fw_has_capa(&mvm->fw->ucode_capa,
2603 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2604 iwl_mvm_config_scan(mvm);
2607 if (changes & BSS_CHANGED_BEACON_INFO) {
2609 * We received a beacon from the associated AP so
2610 * remove the session protection.
2612 iwl_mvm_stop_session_protection(mvm, vif);
2614 iwl_mvm_sf_update(mvm, vif, false);
2615 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2618 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2620 * Send power command on every beacon change,
2621 * because we may have not enabled beacon abort yet.
2623 BSS_CHANGED_BEACON_INFO)) {
2624 ret = iwl_mvm_power_update_mac(mvm);
2626 IWL_ERR(mvm, "failed to update power mode\n");
2629 if (changes & BSS_CHANGED_TXPOWER) {
2630 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2632 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2635 if (changes & BSS_CHANGED_CQM) {
2636 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2637 /* reset cqm events tracking */
2638 mvmvif->bf_data.last_cqm_event = 0;
2639 if (mvmvif->bf_data.bf_enabled) {
2640 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2643 "failed to update CQM thresholds\n");
2647 if (changes & BSS_CHANGED_ARP_FILTER) {
2648 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2649 iwl_mvm_configure_bcast_filter(mvm);
2653 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2654 struct ieee80211_vif *vif)
2656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2657 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2661 * iwl_mvm_mac_ctxt_add() might read directly from the device
2662 * (the system time), so make sure it is available.
2664 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2668 mutex_lock(&mvm->mutex);
2670 /* Send the beacon template */
2671 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2676 * Re-calculate the tsf id, as the master-slave relations depend on the
2677 * beacon interval, which was not known when the AP interface was added.
2679 if (vif->type == NL80211_IFTYPE_AP)
2680 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2682 mvmvif->ap_assoc_sta_count = 0;
2684 /* Add the mac context */
2685 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2689 /* Perform the binding */
2690 ret = iwl_mvm_binding_add_vif(mvm, vif);
2695 * This is not very nice, but the simplest:
2696 * For older FWs adding the mcast sta before the bcast station may
2697 * cause assert 0x2b00.
2698 * This is fixed in later FW so make the order of removal depend on
2701 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2702 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2706 * Send the bcast station. At this stage the TBTT and DTIM time
2707 * events are added and applied to the scheduler
2709 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2711 iwl_mvm_rm_mcast_sta(mvm, vif);
2716 * Send the bcast station. At this stage the TBTT and DTIM time
2717 * events are added and applied to the scheduler
2719 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2722 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2724 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2729 /* must be set before quota calculations */
2730 mvmvif->ap_ibss_active = true;
2732 /* send all the early keys to the device now */
2733 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2734 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2739 mvmvif->ap_early_keys[i] = NULL;
2741 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2743 goto out_quota_failed;
2746 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2747 iwl_mvm_vif_set_low_latency(mvmvif, true,
2748 LOW_LATENCY_VIF_TYPE);
2749 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2752 /* power updated needs to be done before quotas */
2753 iwl_mvm_power_update_mac(mvm);
2755 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2757 goto out_quota_failed;
2759 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2760 if (vif->p2p && mvm->p2p_device_vif)
2761 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2763 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2765 iwl_mvm_bt_coex_vif_change(mvm);
2767 /* we don't support TDLS during DCM */
2768 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2769 iwl_mvm_teardown_tdls_peers(mvm);
2771 iwl_mvm_ftm_restart_responder(mvm, vif);
2776 iwl_mvm_power_update_mac(mvm);
2777 mvmvif->ap_ibss_active = false;
2778 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2779 iwl_mvm_rm_mcast_sta(mvm, vif);
2781 iwl_mvm_binding_remove_vif(mvm, vif);
2783 iwl_mvm_mac_ctxt_remove(mvm, vif);
2785 mutex_unlock(&mvm->mutex);
2786 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2790 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2791 struct ieee80211_vif *vif)
2793 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2794 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2796 iwl_mvm_prepare_mac_removal(mvm, vif);
2798 mutex_lock(&mvm->mutex);
2800 /* Handle AP stop while in CSA */
2801 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2802 iwl_mvm_remove_time_event(mvm, mvmvif,
2803 &mvmvif->time_event_data);
2804 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2805 mvmvif->csa_countdown = false;
2808 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2809 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2810 mvm->csa_tx_block_bcn_timeout = 0;
2813 mvmvif->ap_ibss_active = false;
2814 mvm->ap_last_beacon_gp2 = 0;
2816 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2817 iwl_mvm_vif_set_low_latency(mvmvif, false,
2818 LOW_LATENCY_VIF_TYPE);
2819 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2822 iwl_mvm_bt_coex_vif_change(mvm);
2824 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2826 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2827 if (vif->p2p && mvm->p2p_device_vif)
2828 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2830 iwl_mvm_update_quotas(mvm, false, NULL);
2833 * This is not very nice, but the simplest:
2834 * For older FWs removing the mcast sta before the bcast station may
2835 * cause assert 0x2b00.
2836 * This is fixed in later FW (which will stop beaconing when removing
2838 * So make the order of removal depend on the TLV
2840 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2841 iwl_mvm_rm_mcast_sta(mvm, vif);
2842 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2843 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2844 iwl_mvm_rm_mcast_sta(mvm, vif);
2845 iwl_mvm_binding_remove_vif(mvm, vif);
2847 iwl_mvm_power_update_mac(mvm);
2849 iwl_mvm_mac_ctxt_remove(mvm, vif);
2851 mutex_unlock(&mvm->mutex);
2855 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2856 struct ieee80211_vif *vif,
2857 struct ieee80211_bss_conf *bss_conf,
2860 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2862 /* Changes will be applied when the AP/IBSS is started */
2863 if (!mvmvif->ap_ibss_active)
2866 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2867 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2868 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2869 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2871 /* Need to send a new beacon template to the FW */
2872 if (changes & BSS_CHANGED_BEACON &&
2873 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2874 IWL_WARN(mvm, "Failed updating beacon data\n");
2876 if (changes & BSS_CHANGED_TXPOWER) {
2877 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2879 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2882 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2883 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2886 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2892 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2893 struct ieee80211_vif *vif,
2894 struct ieee80211_bss_conf *bss_conf,
2897 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2900 * iwl_mvm_bss_info_changed_station() might call
2901 * iwl_mvm_protect_session(), which reads directly from
2902 * the device (the system time), so make sure it is available.
2904 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2907 mutex_lock(&mvm->mutex);
2909 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2910 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2912 switch (vif->type) {
2913 case NL80211_IFTYPE_STATION:
2914 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2916 case NL80211_IFTYPE_AP:
2917 case NL80211_IFTYPE_ADHOC:
2918 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2920 case NL80211_IFTYPE_MONITOR:
2921 if (changes & BSS_CHANGED_MU_GROUPS)
2922 iwl_mvm_update_mu_groups(mvm, vif);
2925 /* shouldn't happen */
2929 mutex_unlock(&mvm->mutex);
2930 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2933 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2934 struct ieee80211_vif *vif,
2935 struct ieee80211_scan_request *hw_req)
2937 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2940 if (hw_req->req.n_channels == 0 ||
2941 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2944 mutex_lock(&mvm->mutex);
2945 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2946 mutex_unlock(&mvm->mutex);
2951 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2952 struct ieee80211_vif *vif)
2954 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2956 mutex_lock(&mvm->mutex);
2958 /* Due to a race condition, it's possible that mac80211 asks
2959 * us to stop a hw_scan when it's already stopped. This can
2960 * happen, for instance, if we stopped the scan ourselves,
2961 * called ieee80211_scan_completed() and the userspace called
2962 * cancel scan scan before ieee80211_scan_work() could run.
2963 * To handle that, simply return if the scan is not running.
2965 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2966 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2968 mutex_unlock(&mvm->mutex);
2972 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2973 struct ieee80211_sta *sta, u16 tids,
2975 enum ieee80211_frame_release_type reason,
2978 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2980 /* Called when we need to transmit (a) frame(s) from mac80211 */
2982 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2983 tids, more_data, false);
2987 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2988 struct ieee80211_sta *sta, u16 tids,
2990 enum ieee80211_frame_release_type reason,
2993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2995 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2997 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2998 tids, more_data, true);
3001 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
3002 enum sta_notify_cmd cmd,
3003 struct ieee80211_sta *sta)
3005 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3006 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3007 unsigned long txqs = 0, tids = 0;
3011 * If we have TVQM then we get too high queue numbers - luckily
3012 * we really shouldn't get here with that because such hardware
3013 * should have firmware supporting buffer station offload.
3015 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
3018 spin_lock_bh(&mvmsta->lock);
3019 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
3020 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3022 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
3025 __set_bit(tid_data->txq_id, &txqs);
3027 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
3030 __set_bit(tid, &tids);
3034 case STA_NOTIFY_SLEEP:
3035 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
3036 ieee80211_sta_set_buffered(sta, tid, true);
3039 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
3041 * The fw updates the STA to be asleep. Tx packets on the Tx
3042 * queues to this station will not be transmitted. The fw will
3043 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
3046 case STA_NOTIFY_AWAKE:
3047 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
3051 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
3052 iwl_mvm_sta_modify_ps_wake(mvm, sta);
3057 spin_unlock_bh(&mvmsta->lock);
3060 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
3061 struct ieee80211_vif *vif,
3062 enum sta_notify_cmd cmd,
3063 struct ieee80211_sta *sta)
3065 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
3068 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
3070 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3071 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
3072 struct ieee80211_sta *sta;
3073 struct iwl_mvm_sta *mvmsta;
3074 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
3076 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
3080 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
3081 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
3086 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3089 mvmsta->vif->type != NL80211_IFTYPE_AP) {
3094 if (mvmsta->sleeping != sleeping) {
3095 mvmsta->sleeping = sleeping;
3096 __iwl_mvm_mac_sta_notify(mvm->hw,
3097 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
3099 ieee80211_sta_ps_transition(sta, sleeping);
3103 switch (notif->type) {
3104 case IWL_MVM_PM_EVENT_AWAKE:
3105 case IWL_MVM_PM_EVENT_ASLEEP:
3107 case IWL_MVM_PM_EVENT_UAPSD:
3108 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
3110 case IWL_MVM_PM_EVENT_PS_POLL:
3111 ieee80211_sta_pspoll(sta);
3121 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
3122 struct ieee80211_vif *vif,
3123 struct ieee80211_sta *sta)
3125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3126 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3129 * This is called before mac80211 does RCU synchronisation,
3130 * so here we already invalidate our internal RCU-protected
3131 * station pointer. The rest of the code will thus no longer
3132 * be able to find the station this way, and we don't rely
3133 * on further RCU synchronisation after the sta_state()
3134 * callback deleted the station.
3136 mutex_lock(&mvm->mutex);
3137 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
3138 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
3141 mutex_unlock(&mvm->mutex);
3144 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3149 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3150 struct iwl_mvm_tcm_mac *mdata;
3152 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
3153 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
3154 mdata->opened_rx_ba_sessions = false;
3157 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
3160 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
3161 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3166 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
3167 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3171 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
3172 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
3173 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3178 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3182 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
3183 struct ieee80211_vif *vif, u8 *peer_addr,
3184 enum nl80211_tdls_operation action)
3186 struct iwl_fw_dbg_trigger_tlv *trig;
3187 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3189 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3190 FW_DBG_TRIGGER_TDLS);
3194 tdls_trig = (void *)trig->data;
3196 if (!(tdls_trig->action_bitmap & BIT(action)))
3199 if (tdls_trig->peer_mode &&
3200 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3203 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3204 "TDLS event occurred, peer %pM, action %d",
3208 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3209 struct ieee80211_vif *vif,
3210 struct ieee80211_sta *sta,
3211 enum ieee80211_sta_state old_state,
3212 enum ieee80211_sta_state new_state)
3214 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3215 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3216 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3219 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3220 sta->addr, old_state, new_state);
3222 /* this would be a mac80211 bug ... but don't crash */
3223 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3227 * If we are in a STA removal flow and in DQA mode:
3229 * This is after the sync_rcu part, so the queues have already been
3230 * flushed. No more TXs on their way in mac80211's path, and no more in
3232 * Also, we won't be getting any new TX frames for this station.
3233 * What we might have are deferred TX frames that need to be taken care
3236 * Drop any still-queued deferred-frame before removing the STA, and
3237 * make sure the worker is no longer handling frames for this STA.
3239 if (old_state == IEEE80211_STA_NONE &&
3240 new_state == IEEE80211_STA_NOTEXIST) {
3241 flush_work(&mvm->add_stream_wk);
3244 * No need to make sure deferred TX indication is off since the
3245 * worker will already remove it if it was on
3249 mutex_lock(&mvm->mutex);
3250 /* track whether or not the station is associated */
3251 mvm_sta->sta_state = new_state;
3253 if (old_state == IEEE80211_STA_NOTEXIST &&
3254 new_state == IEEE80211_STA_NONE) {
3256 * Firmware bug - it'll crash if the beacon interval is less
3257 * than 16. We can't avoid connecting at all, so refuse the
3258 * station state change, this will cause mac80211 to abandon
3259 * attempts to connect to this AP, and eventually wpa_s will
3260 * blacklist the AP...
3262 if (vif->type == NL80211_IFTYPE_STATION &&
3263 vif->bss_conf.beacon_int < 16) {
3265 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3266 sta->addr, vif->bss_conf.beacon_int);
3273 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3274 IWL_MVM_TDLS_STA_COUNT ||
3275 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3276 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3281 ret = iwl_mvm_add_sta(mvm, vif, sta);
3282 if (sta->tdls && ret == 0) {
3283 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3284 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3285 NL80211_TDLS_SETUP);
3288 sta->max_rc_amsdu_len = 1;
3289 } else if (old_state == IEEE80211_STA_NONE &&
3290 new_state == IEEE80211_STA_AUTH) {
3292 * EBS may be disabled due to previous failures reported by FW.
3293 * Reset EBS status here assuming environment has been changed.
3295 mvm->last_ebs_successful = true;
3296 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3298 } else if (old_state == IEEE80211_STA_AUTH &&
3299 new_state == IEEE80211_STA_ASSOC) {
3300 if (vif->type == NL80211_IFTYPE_AP) {
3301 vif->bss_conf.he_support = sta->he_cap.has_he;
3302 mvmvif->ap_assoc_sta_count++;
3303 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3304 if (vif->bss_conf.he_support &&
3305 !iwlwifi_mod_params.disable_11ax)
3306 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3307 } else if (vif->type == NL80211_IFTYPE_STATION) {
3308 vif->bss_conf.he_support = sta->he_cap.has_he;
3309 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3312 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3314 ret = iwl_mvm_update_sta(mvm, vif, sta);
3315 } else if (old_state == IEEE80211_STA_ASSOC &&
3316 new_state == IEEE80211_STA_AUTHORIZED) {
3319 /* we don't support TDLS during DCM */
3320 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3321 iwl_mvm_teardown_tdls_peers(mvm);
3324 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3325 NL80211_TDLS_ENABLE_LINK);
3327 /* enable beacon filtering */
3328 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3330 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3332 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3333 new_state == IEEE80211_STA_ASSOC) {
3334 /* disable beacon filtering */
3335 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3337 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3340 } else if (old_state == IEEE80211_STA_ASSOC &&
3341 new_state == IEEE80211_STA_AUTH) {
3342 if (vif->type == NL80211_IFTYPE_AP) {
3343 mvmvif->ap_assoc_sta_count--;
3344 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3347 } else if (old_state == IEEE80211_STA_AUTH &&
3348 new_state == IEEE80211_STA_NONE) {
3350 } else if (old_state == IEEE80211_STA_NONE &&
3351 new_state == IEEE80211_STA_NOTEXIST) {
3352 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3354 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3355 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3356 NL80211_TDLS_DISABLE_LINK);
3360 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3367 mutex_unlock(&mvm->mutex);
3369 if (sta->tdls && ret == 0) {
3370 if (old_state == IEEE80211_STA_NOTEXIST &&
3371 new_state == IEEE80211_STA_NONE)
3372 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3373 else if (old_state == IEEE80211_STA_NONE &&
3374 new_state == IEEE80211_STA_NOTEXIST)
3375 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3381 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3383 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3385 mvm->rts_threshold = value;
3390 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3391 struct ieee80211_vif *vif,
3392 struct ieee80211_sta *sta, u32 changed)
3394 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3395 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3397 if (changed & (IEEE80211_RC_BW_CHANGED |
3398 IEEE80211_RC_SUPP_RATES_CHANGED |
3399 IEEE80211_RC_NSS_CHANGED))
3400 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3403 if (vif->type == NL80211_IFTYPE_STATION &&
3404 changed & IEEE80211_RC_NSS_CHANGED)
3405 iwl_mvm_sf_update(mvm, vif, false);
3408 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3409 struct ieee80211_vif *vif, u16 ac,
3410 const struct ieee80211_tx_queue_params *params)
3412 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3413 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3415 mvmvif->queue_params[ac] = *params;
3418 * No need to update right away, we'll get BSS_CHANGED_QOS
3419 * The exception is P2P_DEVICE interface which needs immediate update.
3421 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3424 mutex_lock(&mvm->mutex);
3425 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3426 mutex_unlock(&mvm->mutex);
3432 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3433 struct ieee80211_vif *vif,
3436 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3437 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3438 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3441 * iwl_mvm_protect_session() reads directly from the device
3442 * (the system time), so make sure it is available.
3444 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3447 if (req_duration > duration)
3448 duration = req_duration;
3450 mutex_lock(&mvm->mutex);
3451 /* Try really hard to protect the session and hear a beacon */
3452 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3453 mutex_unlock(&mvm->mutex);
3455 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3458 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3459 struct ieee80211_vif *vif,
3460 struct cfg80211_sched_scan_request *req,
3461 struct ieee80211_scan_ies *ies)
3463 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3467 mutex_lock(&mvm->mutex);
3469 if (!vif->bss_conf.idle) {
3474 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3477 mutex_unlock(&mvm->mutex);
3481 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3482 struct ieee80211_vif *vif)
3484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3487 mutex_lock(&mvm->mutex);
3489 /* Due to a race condition, it's possible that mac80211 asks
3490 * us to stop a sched_scan when it's already stopped. This
3491 * can happen, for instance, if we stopped the scan ourselves,
3492 * called ieee80211_sched_scan_stopped() and the userspace called
3493 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3494 * could run. To handle this, simply return if the scan is
3497 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3498 mutex_unlock(&mvm->mutex);
3502 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3503 mutex_unlock(&mvm->mutex);
3504 iwl_mvm_wait_for_async_handlers(mvm);
3509 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3510 enum set_key_cmd cmd,
3511 struct ieee80211_vif *vif,
3512 struct ieee80211_sta *sta,
3513 struct ieee80211_key_conf *key)
3515 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3516 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3517 struct iwl_mvm_sta *mvmsta;
3518 struct iwl_mvm_key_pn *ptk_pn;
3519 int keyidx = key->keyidx;
3523 if (iwlwifi_mod_params.swcrypto) {
3524 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3528 switch (key->cipher) {
3529 case WLAN_CIPHER_SUITE_TKIP:
3530 if (!mvm->trans->cfg->gen2) {
3531 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3532 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3533 } else if (vif->type == NL80211_IFTYPE_STATION) {
3534 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3536 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3540 case WLAN_CIPHER_SUITE_CCMP:
3541 case WLAN_CIPHER_SUITE_GCMP:
3542 case WLAN_CIPHER_SUITE_GCMP_256:
3543 if (!iwl_mvm_has_new_tx_api(mvm))
3544 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3546 case WLAN_CIPHER_SUITE_AES_CMAC:
3547 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3548 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3549 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3551 case WLAN_CIPHER_SUITE_WEP40:
3552 case WLAN_CIPHER_SUITE_WEP104:
3553 if (vif->type == NL80211_IFTYPE_STATION)
3555 if (iwl_mvm_has_new_tx_api(mvm))
3557 /* support HW crypto on TX */
3560 /* currently FW supports only one optional cipher scheme */
3561 if (hw->n_cipher_schemes &&
3562 hw->cipher_schemes->cipher == key->cipher)
3563 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3570 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3571 vif->type == NL80211_IFTYPE_AP) && !sta) {
3573 * GTK on AP interface is a TX-only key, return 0;
3574 * on IBSS they're per-station and because we're lazy
3575 * we don't support them for RX, so do the same.
3576 * CMAC/GMAC in AP/IBSS modes must be done in software.
3578 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3579 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3580 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3585 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3586 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3587 !iwl_mvm_has_new_tx_api(mvm)) {
3588 key->hw_key_idx = STA_KEY_IDX_INVALID;
3592 if (!mvmvif->ap_ibss_active) {
3594 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3596 if (!mvmvif->ap_early_keys[i]) {
3597 mvmvif->ap_early_keys[i] = key;
3602 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3609 /* During FW restart, in order to restore the state as it was,
3610 * don't try to reprogram keys we previously failed for.
3612 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3613 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3614 IWL_DEBUG_MAC80211(mvm,
3615 "skip invalid idx key programming during restart\n");
3620 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3621 sta && iwl_mvm_has_new_rx_api(mvm) &&
3622 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3623 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3624 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3625 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3626 struct ieee80211_key_seq seq;
3629 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3630 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3631 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3632 mvm->trans->num_rx_queues),
3639 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3640 ieee80211_get_key_rx_seq(key, tid, &seq);
3641 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3642 memcpy(ptk_pn->q[q].pn[tid],
3644 IEEE80211_CCMP_PN_LEN);
3647 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3650 /* in HW restart reuse the index, otherwise request a new one */
3651 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3652 key_offset = key->hw_key_idx;
3654 key_offset = STA_KEY_IDX_INVALID;
3656 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3657 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3659 IWL_WARN(mvm, "set key failed\n");
3660 key->hw_key_idx = STA_KEY_IDX_INVALID;
3662 * can't add key for RX, but we don't need it
3663 * in the device for TX so still return 0,
3664 * unless we have new TX API where we cannot
3665 * put key material into the TX_CMD
3667 if (iwl_mvm_has_new_tx_api(mvm))
3676 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3677 if (mvmvif->ap_early_keys[i] == key) {
3678 mvmvif->ap_early_keys[i] = NULL;
3683 /* found in pending list - don't do anything else */
3687 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3692 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3693 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3694 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3695 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3696 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3697 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3698 ptk_pn = rcu_dereference_protected(
3699 mvmsta->ptk_pn[keyidx],
3700 lockdep_is_held(&mvm->mutex));
3701 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3703 kfree_rcu(ptk_pn, rcu_head);
3706 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3707 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3716 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3717 enum set_key_cmd cmd,
3718 struct ieee80211_vif *vif,
3719 struct ieee80211_sta *sta,
3720 struct ieee80211_key_conf *key)
3722 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3725 mutex_lock(&mvm->mutex);
3726 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3727 mutex_unlock(&mvm->mutex);
3732 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3733 struct ieee80211_vif *vif,
3734 struct ieee80211_key_conf *keyconf,
3735 struct ieee80211_sta *sta,
3736 u32 iv32, u16 *phase1key)
3738 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3740 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3743 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3747 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3748 struct iwl_rx_packet *pkt, void *data)
3750 struct iwl_mvm *mvm =
3751 container_of(notif_wait, struct iwl_mvm, notif_wait);
3752 struct iwl_hs20_roc_res *resp;
3753 int resp_len = iwl_rx_packet_payload_len(pkt);
3754 struct iwl_mvm_time_event_data *te_data = data;
3756 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3759 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3760 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3764 resp = (void *)pkt->data;
3767 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3768 resp->status, resp->event_unique_id);
3770 te_data->uid = le32_to_cpu(resp->event_unique_id);
3771 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3774 spin_lock_bh(&mvm->time_event_lock);
3775 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3776 spin_unlock_bh(&mvm->time_event_lock);
3781 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3782 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3783 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3784 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3785 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3786 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3787 struct ieee80211_channel *channel,
3788 struct ieee80211_vif *vif,
3792 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3793 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3794 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3795 struct iwl_notification_wait wait_time_event;
3796 u32 dtim_interval = vif->bss_conf.dtim_period *
3797 vif->bss_conf.beacon_int;
3799 struct iwl_hs20_roc_req aux_roc_req = {
3800 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3802 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3803 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3805 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3806 &aux_roc_req.channel_info);
3807 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3809 /* Set the channel info data */
3810 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3811 (channel->band == NL80211_BAND_2GHZ) ?
3812 PHY_BAND_24 : PHY_BAND_5,
3813 PHY_VHT_CHANNEL_MODE20,
3816 /* Set the time and duration */
3817 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3819 delay = AUX_ROC_MIN_DELAY;
3820 req_dur = MSEC_TO_TU(duration);
3823 * If we are associated we want the delay time to be at least one
3824 * dtim interval so that the FW can wait until after the DTIM and
3825 * then start the time event, this will potentially allow us to
3826 * remain off-channel for the max duration.
3827 * Since we want to use almost a whole dtim interval we would also
3828 * like the delay to be for 2-3 dtim intervals, in case there are
3829 * other time events with higher priority.
3831 if (vif->bss_conf.assoc) {
3832 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3833 /* We cannot remain off-channel longer than the DTIM interval */
3834 if (dtim_interval <= req_dur) {
3835 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3836 if (req_dur <= AUX_ROC_MIN_DURATION)
3837 req_dur = dtim_interval -
3838 AUX_ROC_MIN_SAFETY_BUFFER;
3842 tail->duration = cpu_to_le32(req_dur);
3843 tail->apply_time_max_delay = cpu_to_le32(delay);
3846 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3847 channel->hw_value, req_dur, duration, delay,
3849 /* Set the node address */
3850 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3852 lockdep_assert_held(&mvm->mutex);
3854 spin_lock_bh(&mvm->time_event_lock);
3856 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3857 spin_unlock_bh(&mvm->time_event_lock);
3862 te_data->duration = duration;
3863 te_data->id = HOT_SPOT_CMD;
3865 spin_unlock_bh(&mvm->time_event_lock);
3868 * Use a notification wait, which really just processes the
3869 * command response and doesn't wait for anything, in order
3870 * to be able to process the response and get the UID inside
3871 * the RX path. Using CMD_WANT_SKB doesn't work because it
3872 * stores the buffer and then wakes up this thread, by which
3873 * time another notification (that the time event started)
3874 * might already be processed unsuccessfully.
3876 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3877 time_event_response,
3878 ARRAY_SIZE(time_event_response),
3879 iwl_mvm_rx_aux_roc, te_data);
3881 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3885 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3886 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3890 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3891 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3892 /* should never fail */
3897 spin_lock_bh(&mvm->time_event_lock);
3898 iwl_mvm_te_clear_data(mvm, te_data);
3899 spin_unlock_bh(&mvm->time_event_lock);
3905 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3906 struct ieee80211_vif *vif,
3907 struct ieee80211_channel *channel,
3909 enum ieee80211_roc_type type)
3911 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3912 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3913 struct cfg80211_chan_def chandef;
3914 struct iwl_mvm_phy_ctxt *phy_ctxt;
3917 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3921 * Flush the done work, just in case it's still pending, so that
3922 * the work it does can complete and we can accept new frames.
3924 flush_work(&mvm->roc_done_wk);
3926 mutex_lock(&mvm->mutex);
3928 switch (vif->type) {
3929 case NL80211_IFTYPE_STATION:
3930 if (fw_has_capa(&mvm->fw->ucode_capa,
3931 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3932 /* Use aux roc framework (HS20) */
3933 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3937 IWL_ERR(mvm, "hotspot not supported\n");
3940 case NL80211_IFTYPE_P2P_DEVICE:
3944 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3949 for (i = 0; i < NUM_PHY_CTX; i++) {
3950 phy_ctxt = &mvm->phy_ctxts[i];
3951 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3954 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3956 * Unbind the P2P_DEVICE from the current PHY context,
3957 * and if the PHY context is not used remove it.
3959 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3960 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3963 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3965 /* Bind the P2P_DEVICE to the current PHY Context */
3966 mvmvif->phy_ctxt = phy_ctxt;
3968 ret = iwl_mvm_binding_add_vif(mvm, vif);
3969 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3972 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3973 goto schedule_time_event;
3977 /* Need to update the PHY context only if the ROC channel changed */
3978 if (channel == mvmvif->phy_ctxt->channel)
3979 goto schedule_time_event;
3981 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3984 * Change the PHY context configuration as it is currently referenced
3985 * only by the P2P Device MAC
3987 if (mvmvif->phy_ctxt->ref == 1) {
3988 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3994 * The PHY context is shared with other MACs. Need to remove the
3995 * P2P Device from the binding, allocate an new PHY context and
3996 * create a new binding
3998 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4004 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
4007 IWL_ERR(mvm, "Failed to change PHY context\n");
4011 /* Unbind the P2P_DEVICE from the current PHY context */
4012 ret = iwl_mvm_binding_remove_vif(mvm, vif);
4013 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
4016 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
4018 /* Bind the P2P_DEVICE to the new allocated PHY context */
4019 mvmvif->phy_ctxt = phy_ctxt;
4021 ret = iwl_mvm_binding_add_vif(mvm, vif);
4022 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
4025 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
4028 schedule_time_event:
4029 /* Schedule the time events */
4030 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
4033 mutex_unlock(&mvm->mutex);
4034 IWL_DEBUG_MAC80211(mvm, "leave\n");
4038 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
4040 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4042 IWL_DEBUG_MAC80211(mvm, "enter\n");
4044 mutex_lock(&mvm->mutex);
4045 iwl_mvm_stop_roc(mvm);
4046 mutex_unlock(&mvm->mutex);
4048 IWL_DEBUG_MAC80211(mvm, "leave\n");
4052 struct iwl_mvm_ftm_responder_iter_data {
4054 struct ieee80211_chanctx_conf *ctx;
4057 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4058 struct ieee80211_vif *vif)
4060 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4062 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
4063 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4064 data->responder = true;
4067 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4068 struct ieee80211_chanctx_conf *ctx)
4070 struct iwl_mvm_ftm_responder_iter_data data = {
4075 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4076 IEEE80211_IFACE_ITER_NORMAL,
4077 iwl_mvm_ftm_responder_chanctx_iter,
4079 return data.responder;
4082 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4083 struct ieee80211_chanctx_conf *ctx)
4085 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4086 struct iwl_mvm_phy_ctxt *phy_ctxt;
4087 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4088 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4091 lockdep_assert_held(&mvm->mutex);
4093 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4095 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4101 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4102 ctx->rx_chains_static,
4103 ctx->rx_chains_dynamic);
4105 IWL_ERR(mvm, "Failed to add PHY context\n");
4109 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4110 *phy_ctxt_id = phy_ctxt->id;
4115 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4116 struct ieee80211_chanctx_conf *ctx)
4118 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4121 mutex_lock(&mvm->mutex);
4122 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4123 mutex_unlock(&mvm->mutex);
4128 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4129 struct ieee80211_chanctx_conf *ctx)
4131 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4132 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4134 lockdep_assert_held(&mvm->mutex);
4136 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4139 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4140 struct ieee80211_chanctx_conf *ctx)
4142 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4144 mutex_lock(&mvm->mutex);
4145 __iwl_mvm_remove_chanctx(mvm, ctx);
4146 mutex_unlock(&mvm->mutex);
4149 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4150 struct ieee80211_chanctx_conf *ctx,
4153 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4154 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4155 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4156 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4157 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4159 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4160 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4161 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4162 IEEE80211_CHANCTX_CHANGE_RADAR |
4163 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4164 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4165 phy_ctxt->ref, changed))
4168 mutex_lock(&mvm->mutex);
4170 /* we are only changing the min_width, may be a noop */
4171 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4172 if (phy_ctxt->width == def->width)
4175 /* we are just toggling between 20_NOHT and 20 */
4176 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4177 def->width <= NL80211_CHAN_WIDTH_20)
4181 iwl_mvm_bt_coex_vif_change(mvm);
4182 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4183 ctx->rx_chains_static,
4184 ctx->rx_chains_dynamic);
4187 mutex_unlock(&mvm->mutex);
4190 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4191 struct ieee80211_vif *vif,
4192 struct ieee80211_chanctx_conf *ctx,
4193 bool switching_chanctx)
4195 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4196 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4197 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4200 lockdep_assert_held(&mvm->mutex);
4202 mvmvif->phy_ctxt = phy_ctxt;
4204 switch (vif->type) {
4205 case NL80211_IFTYPE_AP:
4206 /* only needed if we're switching chanctx (i.e. during CSA) */
4207 if (switching_chanctx) {
4208 mvmvif->ap_ibss_active = true;
4212 case NL80211_IFTYPE_ADHOC:
4214 * The AP binding flow is handled as part of the start_ap flow
4215 * (in bss_info_changed), similarly for IBSS.
4219 case NL80211_IFTYPE_STATION:
4220 mvmvif->csa_bcn_pending = false;
4222 case NL80211_IFTYPE_MONITOR:
4223 /* always disable PS when a monitor interface is active */
4224 mvmvif->ps_disabled = true;
4231 ret = iwl_mvm_binding_add_vif(mvm, vif);
4236 * Power state must be updated before quotas,
4237 * otherwise fw will complain.
4239 iwl_mvm_power_update_mac(mvm);
4241 /* Setting the quota at this stage is only required for monitor
4242 * interfaces. For the other types, the bss_info changed flow
4243 * will handle quota settings.
4245 if (vif->type == NL80211_IFTYPE_MONITOR) {
4246 mvmvif->monitor_active = true;
4247 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4249 goto out_remove_binding;
4251 ret = iwl_mvm_add_snif_sta(mvm, vif);
4253 goto out_remove_binding;
4257 /* Handle binding during CSA */
4258 if (vif->type == NL80211_IFTYPE_AP) {
4259 iwl_mvm_update_quotas(mvm, false, NULL);
4260 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4263 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4264 mvmvif->csa_bcn_pending = true;
4266 if (!fw_has_capa(&mvm->fw->ucode_capa,
4267 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4268 u32 duration = 3 * vif->bss_conf.beacon_int;
4271 /* iwl_mvm_protect_session() reads directly from the
4272 * device (the system time), so make sure it is
4275 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
4277 goto out_remove_binding;
4279 /* Protect the session to make sure we hear the first
4280 * beacon on the new channel.
4282 iwl_mvm_protect_session(mvm, vif, duration, duration,
4283 vif->bss_conf.beacon_int / 2,
4286 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
4289 iwl_mvm_update_quotas(mvm, false, NULL);
4295 iwl_mvm_binding_remove_vif(mvm, vif);
4296 iwl_mvm_power_update_mac(mvm);
4299 mvmvif->phy_ctxt = NULL;
4302 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4303 struct ieee80211_vif *vif,
4304 struct ieee80211_chanctx_conf *ctx)
4306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4309 mutex_lock(&mvm->mutex);
4310 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4311 mutex_unlock(&mvm->mutex);
4316 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4317 struct ieee80211_vif *vif,
4318 struct ieee80211_chanctx_conf *ctx,
4319 bool switching_chanctx)
4321 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4322 struct ieee80211_vif *disabled_vif = NULL;
4324 lockdep_assert_held(&mvm->mutex);
4326 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4328 switch (vif->type) {
4329 case NL80211_IFTYPE_ADHOC:
4331 case NL80211_IFTYPE_MONITOR:
4332 mvmvif->monitor_active = false;
4333 mvmvif->ps_disabled = false;
4334 iwl_mvm_rm_snif_sta(mvm, vif);
4336 case NL80211_IFTYPE_AP:
4337 /* This part is triggered only during CSA */
4338 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4341 mvmvif->csa_countdown = false;
4343 /* Set CS bit on all the stations */
4344 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4346 /* Save blocked iface, the timeout is set on the next beacon */
4347 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4349 mvmvif->ap_ibss_active = false;
4351 case NL80211_IFTYPE_STATION:
4352 if (!switching_chanctx)
4357 if (!fw_has_capa(&mvm->fw->ucode_capa,
4358 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4359 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4365 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4366 iwl_mvm_binding_remove_vif(mvm, vif);
4369 mvmvif->phy_ctxt = NULL;
4370 iwl_mvm_power_update_mac(mvm);
4373 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4374 struct ieee80211_vif *vif,
4375 struct ieee80211_chanctx_conf *ctx)
4377 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4379 mutex_lock(&mvm->mutex);
4380 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4381 mutex_unlock(&mvm->mutex);
4385 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4386 struct ieee80211_vif_chanctx_switch *vifs)
4390 mutex_lock(&mvm->mutex);
4391 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4392 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4394 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4396 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4400 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4404 "failed to assign new_ctx during channel switch\n");
4408 /* we don't support TDLS during DCM - can be caused by channel switch */
4409 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4410 iwl_mvm_teardown_tdls_peers(mvm);
4415 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4418 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4419 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4423 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4425 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4432 /* things keep failing, better restart the hw */
4433 iwl_mvm_nic_restart(mvm, false);
4436 mutex_unlock(&mvm->mutex);
4442 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4443 struct ieee80211_vif_chanctx_switch *vifs)
4447 mutex_lock(&mvm->mutex);
4448 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4450 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4454 "failed to assign new_ctx during channel switch\n");
4461 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4463 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4470 /* things keep failing, better restart the hw */
4471 iwl_mvm_nic_restart(mvm, false);
4474 mutex_unlock(&mvm->mutex);
4479 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4480 struct ieee80211_vif_chanctx_switch *vifs,
4482 enum ieee80211_chanctx_switch_mode mode)
4484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4487 /* we only support a single-vif right now */
4492 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4493 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4495 case CHANCTX_SWMODE_REASSIGN_VIF:
4496 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4506 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4508 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4510 return mvm->ibss_manager;
4513 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4514 struct ieee80211_sta *sta,
4517 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4518 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4520 if (!mvm_sta || !mvm_sta->vif) {
4521 IWL_ERR(mvm, "Station is not associated to a vif\n");
4525 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4528 #ifdef CONFIG_NL80211_TESTMODE
4529 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4530 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4531 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4532 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4535 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4536 struct ieee80211_vif *vif,
4537 void *data, int len)
4539 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4543 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4544 iwl_mvm_tm_policy, NULL);
4548 if (!tb[IWL_MVM_TM_ATTR_CMD])
4551 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4552 case IWL_MVM_TM_CMD_SET_NOA:
4553 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4554 !vif->bss_conf.enable_beacon ||
4555 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4558 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4559 if (noa_duration >= vif->bss_conf.beacon_int)
4562 mvm->noa_duration = noa_duration;
4565 return iwl_mvm_update_quotas(mvm, true, NULL);
4566 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4567 /* must be associated client vif - ignore authorized */
4568 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4569 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4570 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4573 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4574 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4575 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4581 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4582 struct ieee80211_vif *vif,
4583 void *data, int len)
4585 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4588 mutex_lock(&mvm->mutex);
4589 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4590 mutex_unlock(&mvm->mutex);
4596 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4597 struct ieee80211_vif *vif,
4598 struct ieee80211_channel_switch *chsw)
4600 /* By implementing this operation, we prevent mac80211 from
4601 * starting its own channel switch timer, so that we can call
4602 * ieee80211_chswitch_done() ourselves at the right time
4603 * (which is when the absence time event starts).
4606 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4607 "dummy channel switch op\n");
4610 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4611 struct ieee80211_vif *vif,
4612 struct ieee80211_channel_switch *chsw)
4614 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4615 struct iwl_chan_switch_te_cmd cmd = {
4616 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4618 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4619 .tsf = cpu_to_le32(chsw->timestamp),
4620 .cs_count = chsw->count,
4621 .cs_mode = chsw->block_tx,
4624 lockdep_assert_held(&mvm->mutex);
4627 cmd.cs_delayed_bcn_count =
4628 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4630 return iwl_mvm_send_cmd_pdu(mvm,
4631 WIDE_ID(MAC_CONF_GROUP,
4632 CHANNEL_SWITCH_TIME_EVENT_CMD),
4633 0, sizeof(cmd), &cmd);
4636 #define IWL_MAX_CSA_BLOCK_TX 1500
4637 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4638 struct ieee80211_vif *vif,
4639 struct ieee80211_channel_switch *chsw)
4641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4642 struct ieee80211_vif *csa_vif;
4643 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4647 mutex_lock(&mvm->mutex);
4649 mvmvif->csa_failed = false;
4651 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4652 chsw->chandef.center_freq1);
4654 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4655 ieee80211_vif_to_wdev(vif),
4656 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4658 switch (vif->type) {
4659 case NL80211_IFTYPE_AP:
4661 rcu_dereference_protected(mvm->csa_vif,
4662 lockdep_is_held(&mvm->mutex));
4663 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4664 "Another CSA is already in progress")) {
4669 /* we still didn't unblock tx. prevent new CS meanwhile */
4670 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4671 lockdep_is_held(&mvm->mutex))) {
4676 rcu_assign_pointer(mvm->csa_vif, vif);
4678 if (WARN_ONCE(mvmvif->csa_countdown,
4679 "Previous CSA countdown didn't complete")) {
4684 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4687 case NL80211_IFTYPE_STATION:
4688 /* Schedule the time event to a bit before beacon 1,
4689 * to make sure we're in the new channel when the
4690 * GO/AP arrives. In case count <= 1 immediately schedule the
4691 * TE (this might result with some packet loss or connection
4694 if (chsw->count <= 1)
4697 apply_time = chsw->device_timestamp +
4698 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4699 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4701 if (chsw->block_tx) {
4702 iwl_mvm_csa_client_absent(mvm, vif);
4704 * In case of undetermined / long time with immediate
4705 * quiet monitor status to gracefully disconnect
4708 chsw->count * vif->bss_conf.beacon_int >
4709 IWL_MAX_CSA_BLOCK_TX)
4710 schedule_delayed_work(&mvmvif->csa_work,
4711 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4714 if (mvmvif->bf_data.bf_enabled) {
4715 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4720 if (fw_has_capa(&mvm->fw->ucode_capa,
4721 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4722 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4724 iwl_mvm_schedule_csa_period(mvm, vif,
4725 vif->bss_conf.beacon_int,
4728 mvmvif->csa_count = chsw->count;
4729 mvmvif->csa_misbehave = false;
4735 mvmvif->ps_disabled = true;
4737 ret = iwl_mvm_power_update_ps(mvm);
4741 /* we won't be on this channel any longer */
4742 iwl_mvm_teardown_tdls_peers(mvm);
4745 mutex_unlock(&mvm->mutex);
4750 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4751 struct ieee80211_vif *vif,
4752 struct ieee80211_channel_switch *chsw)
4754 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4755 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4756 struct iwl_chan_switch_te_cmd cmd = {
4757 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4759 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4760 .tsf = cpu_to_le32(chsw->timestamp),
4761 .cs_count = chsw->count,
4762 .cs_mode = chsw->block_tx,
4765 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4768 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4769 if (mvmvif->csa_misbehave) {
4770 /* Second time, give up on this AP*/
4771 iwl_mvm_abort_channel_switch(hw, vif);
4772 ieee80211_chswitch_done(vif, false);
4773 mvmvif->csa_misbehave = false;
4776 mvmvif->csa_misbehave = true;
4778 mvmvif->csa_count = chsw->count;
4780 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id);
4782 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4783 WIDE_ID(MAC_CONF_GROUP,
4784 CHANNEL_SWITCH_TIME_EVENT_CMD),
4785 CMD_ASYNC, sizeof(cmd), &cmd));
4788 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4792 if (!iwl_mvm_has_new_tx_api(mvm)) {
4794 mutex_lock(&mvm->mutex);
4795 iwl_mvm_flush_tx_path(mvm,
4796 iwl_mvm_flushable_queues(mvm) & queues, 0);
4797 mutex_unlock(&mvm->mutex);
4799 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4804 mutex_lock(&mvm->mutex);
4805 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4806 struct ieee80211_sta *sta;
4808 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4809 lockdep_is_held(&mvm->mutex));
4810 if (IS_ERR_OR_NULL(sta))
4814 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4816 iwl_mvm_wait_sta_queues_empty(mvm,
4817 iwl_mvm_sta_from_mac80211(sta));
4819 mutex_unlock(&mvm->mutex);
4822 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4823 struct ieee80211_vif *vif, u32 queues, bool drop)
4825 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4826 struct iwl_mvm_vif *mvmvif;
4827 struct iwl_mvm_sta *mvmsta;
4828 struct ieee80211_sta *sta;
4833 iwl_mvm_flush_no_vif(mvm, queues, drop);
4837 if (vif->type != NL80211_IFTYPE_STATION)
4840 /* Make sure we're done with the deferred traffic before flushing */
4841 flush_work(&mvm->add_stream_wk);
4843 mutex_lock(&mvm->mutex);
4844 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4846 /* flush the AP-station and all TDLS peers */
4847 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4848 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4849 lockdep_is_held(&mvm->mutex));
4850 if (IS_ERR_OR_NULL(sta))
4853 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4854 if (mvmsta->vif != vif)
4857 /* make sure only TDLS peers or the AP are flushed */
4858 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4861 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4862 IWL_ERR(mvm, "flush request fail\n");
4864 msk |= mvmsta->tfd_queue_msk;
4865 if (iwl_mvm_has_new_tx_api(mvm))
4866 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4870 mutex_unlock(&mvm->mutex);
4872 /* this can take a while, and we may need/want other operations
4873 * to succeed while doing this, so do it without the mutex held
4875 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4876 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4879 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4880 struct survey_info *survey)
4882 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4885 memset(survey, 0, sizeof(*survey));
4887 /* only support global statistics right now */
4891 if (!fw_has_capa(&mvm->fw->ucode_capa,
4892 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4895 mutex_lock(&mvm->mutex);
4897 if (iwl_mvm_firmware_running(mvm)) {
4898 ret = iwl_mvm_request_statistics(mvm, false);
4903 survey->filled = SURVEY_INFO_TIME |
4904 SURVEY_INFO_TIME_RX |
4905 SURVEY_INFO_TIME_TX |
4906 SURVEY_INFO_TIME_SCAN;
4907 survey->time = mvm->accu_radio_stats.on_time_rf +
4908 mvm->radio_stats.on_time_rf;
4909 do_div(survey->time, USEC_PER_MSEC);
4911 survey->time_rx = mvm->accu_radio_stats.rx_time +
4912 mvm->radio_stats.rx_time;
4913 do_div(survey->time_rx, USEC_PER_MSEC);
4915 survey->time_tx = mvm->accu_radio_stats.tx_time +
4916 mvm->radio_stats.tx_time;
4917 do_div(survey->time_tx, USEC_PER_MSEC);
4919 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4920 mvm->radio_stats.on_time_scan;
4921 do_div(survey->time_scan, USEC_PER_MSEC);
4925 mutex_unlock(&mvm->mutex);
4929 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4930 struct ieee80211_vif *vif,
4931 struct ieee80211_sta *sta,
4932 struct station_info *sinfo)
4934 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4935 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4936 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4938 if (mvmsta->avg_energy) {
4939 sinfo->signal_avg = mvmsta->avg_energy;
4940 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4943 /* if beacon filtering isn't on mac80211 does it anyway */
4944 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4947 if (!vif->bss_conf.assoc)
4950 mutex_lock(&mvm->mutex);
4952 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4955 if (iwl_mvm_request_statistics(mvm, false))
4958 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4959 mvmvif->beacon_stats.accu_num_beacons;
4960 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4961 if (mvmvif->beacon_stats.avg_signal) {
4962 /* firmware only reports a value after RXing a few beacons */
4963 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4964 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4967 mutex_unlock(&mvm->mutex);
4970 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4971 struct ieee80211_vif *vif,
4972 const struct ieee80211_event *event)
4974 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4976 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4978 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4981 struct iwl_fw_dbg_trigger_tlv *trig;
4982 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4984 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4985 FW_DBG_TRIGGER_MLME);
4989 trig_mlme = (void *)trig->data;
4991 if (event->u.mlme.data == ASSOC_EVENT) {
4992 if (event->u.mlme.status == MLME_DENIED)
4993 CHECK_MLME_TRIGGER(stop_assoc_denied,
4994 "DENIED ASSOC: reason %d",
4995 event->u.mlme.reason);
4996 else if (event->u.mlme.status == MLME_TIMEOUT)
4997 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4999 } else if (event->u.mlme.data == AUTH_EVENT) {
5000 if (event->u.mlme.status == MLME_DENIED)
5001 CHECK_MLME_TRIGGER(stop_auth_denied,
5002 "DENIED AUTH: reason %d",
5003 event->u.mlme.reason);
5004 else if (event->u.mlme.status == MLME_TIMEOUT)
5005 CHECK_MLME_TRIGGER(stop_auth_timeout,
5007 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5008 CHECK_MLME_TRIGGER(stop_rx_deauth,
5009 "DEAUTH RX %d", event->u.mlme.reason);
5010 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5011 CHECK_MLME_TRIGGER(stop_tx_deauth,
5012 "DEAUTH TX %d", event->u.mlme.reason);
5014 #undef CHECK_MLME_TRIGGER
5017 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5018 struct ieee80211_vif *vif,
5019 const struct ieee80211_event *event)
5021 struct iwl_fw_dbg_trigger_tlv *trig;
5022 struct iwl_fw_dbg_trigger_ba *ba_trig;
5024 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5029 ba_trig = (void *)trig->data;
5031 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5034 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5035 "BAR received from %pM, tid %d, ssn %d",
5036 event->u.ba.sta->addr, event->u.ba.tid,
5040 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5041 struct ieee80211_vif *vif,
5042 const struct ieee80211_event *event)
5044 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5046 switch (event->type) {
5048 iwl_mvm_event_mlme_callback(mvm, vif, event);
5051 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5053 case BA_FRAME_TIMEOUT:
5054 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5062 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5063 struct iwl_mvm_internal_rxq_notif *notif,
5066 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
5070 if (!iwl_mvm_has_new_rx_api(mvm))
5073 notif->cookie = mvm->queue_sync_cookie;
5076 atomic_set(&mvm->queue_sync_counter,
5077 mvm->trans->num_rx_queues);
5079 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif,
5080 size, !notif->sync);
5082 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5087 lockdep_assert_held(&mvm->mutex);
5088 ret = wait_event_timeout(mvm->rx_sync_waitq,
5089 atomic_read(&mvm->queue_sync_counter) == 0 ||
5090 iwl_mvm_is_radio_killed(mvm),
5092 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
5096 atomic_set(&mvm->queue_sync_counter, 0);
5097 mvm->queue_sync_cookie++;
5100 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5102 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5103 struct iwl_mvm_internal_rxq_notif data = {
5104 .type = IWL_MVM_RXQ_EMPTY,
5108 mutex_lock(&mvm->mutex);
5109 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
5110 mutex_unlock(&mvm->mutex);
5114 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5115 struct ieee80211_vif *vif,
5116 struct cfg80211_ftm_responder_stats *stats)
5118 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5119 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5121 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5122 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5125 mutex_lock(&mvm->mutex);
5126 *stats = mvm->ftm_resp_stats;
5127 mutex_unlock(&mvm->mutex);
5129 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5130 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5131 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5132 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5133 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5134 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5135 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5136 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5137 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5142 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5143 struct ieee80211_vif *vif,
5144 struct cfg80211_pmsr_request *request)
5146 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5149 mutex_lock(&mvm->mutex);
5150 ret = iwl_mvm_ftm_start(mvm, vif, request);
5151 mutex_unlock(&mvm->mutex);
5156 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5157 struct ieee80211_vif *vif,
5158 struct cfg80211_pmsr_request *request)
5160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5162 mutex_lock(&mvm->mutex);
5163 iwl_mvm_ftm_abort(mvm, request);
5164 mutex_unlock(&mvm->mutex);
5167 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5169 u8 protocol = ip_hdr(skb)->protocol;
5171 if (!IS_ENABLED(CONFIG_INET))
5174 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5177 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5178 struct sk_buff *head,
5179 struct sk_buff *skb)
5181 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5183 /* For now don't aggregate IPv6 in AMSDU */
5184 if (skb->protocol != htons(ETH_P_IP))
5187 if (!iwl_mvm_is_csum_supported(mvm))
5190 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5193 const struct ieee80211_ops iwl_mvm_hw_ops = {
5194 .tx = iwl_mvm_mac_tx,
5195 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5196 .ampdu_action = iwl_mvm_mac_ampdu_action,
5197 .start = iwl_mvm_mac_start,
5198 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5199 .stop = iwl_mvm_mac_stop,
5200 .add_interface = iwl_mvm_mac_add_interface,
5201 .remove_interface = iwl_mvm_mac_remove_interface,
5202 .config = iwl_mvm_mac_config,
5203 .prepare_multicast = iwl_mvm_prepare_multicast,
5204 .configure_filter = iwl_mvm_configure_filter,
5205 .config_iface_filter = iwl_mvm_config_iface_filter,
5206 .bss_info_changed = iwl_mvm_bss_info_changed,
5207 .hw_scan = iwl_mvm_mac_hw_scan,
5208 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5209 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5210 .sta_state = iwl_mvm_mac_sta_state,
5211 .sta_notify = iwl_mvm_mac_sta_notify,
5212 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5213 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5214 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5215 .sta_rc_update = iwl_mvm_sta_rc_update,
5216 .conf_tx = iwl_mvm_mac_conf_tx,
5217 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5218 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5219 .flush = iwl_mvm_mac_flush,
5220 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5221 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5222 .set_key = iwl_mvm_mac_set_key,
5223 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5224 .remain_on_channel = iwl_mvm_roc,
5225 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5226 .add_chanctx = iwl_mvm_add_chanctx,
5227 .remove_chanctx = iwl_mvm_remove_chanctx,
5228 .change_chanctx = iwl_mvm_change_chanctx,
5229 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5230 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5231 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5233 .start_ap = iwl_mvm_start_ap_ibss,
5234 .stop_ap = iwl_mvm_stop_ap_ibss,
5235 .join_ibss = iwl_mvm_start_ap_ibss,
5236 .leave_ibss = iwl_mvm_stop_ap_ibss,
5238 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5240 .set_tim = iwl_mvm_set_tim,
5242 .channel_switch = iwl_mvm_channel_switch,
5243 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5244 .post_channel_switch = iwl_mvm_post_channel_switch,
5245 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5246 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5248 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5249 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5250 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5252 .event_callback = iwl_mvm_mac_event_callback,
5254 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5256 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5258 #ifdef CONFIG_PM_SLEEP
5260 .suspend = iwl_mvm_suspend,
5261 .resume = iwl_mvm_resume,
5262 .set_wakeup = iwl_mvm_set_wakeup,
5263 .set_rekey_data = iwl_mvm_set_rekey_data,
5264 #if IS_ENABLED(CONFIG_IPV6)
5265 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5267 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5269 .get_survey = iwl_mvm_mac_get_survey,
5270 .sta_statistics = iwl_mvm_mac_sta_statistics,
5271 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5272 .start_pmsr = iwl_mvm_start_pmsr,
5273 .abort_pmsr = iwl_mvm_abort_pmsr,
5275 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5276 #ifdef CONFIG_IWLWIFI_DEBUGFS
5277 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,