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);
477 ieee80211_hw_set(hw, TX_AMSDU);
478 ieee80211_hw_set(hw, TX_FRAG_LIST);
480 if (iwl_mvm_has_tlc_offload(mvm)) {
481 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
482 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
485 if (iwl_mvm_has_new_rx_api(mvm))
486 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
488 if (fw_has_capa(&mvm->fw->ucode_capa,
489 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
490 ieee80211_hw_set(hw, AP_LINK_PS);
491 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
493 * we absolutely need this for the new TX API since that comes
494 * with many more queues than the current code can deal with
495 * for station powersave
500 if (mvm->trans->num_rx_queues > 1)
501 ieee80211_hw_set(hw, USES_RSS);
503 if (mvm->trans->max_skb_frags)
504 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
506 hw->queues = IEEE80211_MAX_QUEUES;
507 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
508 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
509 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
510 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
511 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
513 hw->radiotap_timestamp.units_pos =
514 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
515 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
516 /* this is the case for CCK frames, it's better (only 8) for OFDM */
517 hw->radiotap_timestamp.accuracy = 22;
519 if (!iwl_mvm_has_tlc_offload(mvm))
520 hw->rate_control_algorithm = RS_NAME;
522 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
523 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
524 hw->max_tx_fragments = mvm->trans->max_skb_frags;
526 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
527 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
528 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
529 hw->wiphy->cipher_suites = mvm->ciphers;
531 if (iwl_mvm_has_new_rx_api(mvm)) {
532 mvm->ciphers[hw->wiphy->n_cipher_suites] =
533 WLAN_CIPHER_SUITE_GCMP;
534 hw->wiphy->n_cipher_suites++;
535 mvm->ciphers[hw->wiphy->n_cipher_suites] =
536 WLAN_CIPHER_SUITE_GCMP_256;
537 hw->wiphy->n_cipher_suites++;
540 /* Enable 11w if software crypto is not enabled (as the
541 * firmware will interpret some mgmt packets, so enabling it
542 * with software crypto isn't safe).
544 if (!iwlwifi_mod_params.swcrypto) {
545 ieee80211_hw_set(hw, MFP_CAPABLE);
546 mvm->ciphers[hw->wiphy->n_cipher_suites] =
547 WLAN_CIPHER_SUITE_AES_CMAC;
548 hw->wiphy->n_cipher_suites++;
549 if (iwl_mvm_has_new_rx_api(mvm)) {
550 mvm->ciphers[hw->wiphy->n_cipher_suites] =
551 WLAN_CIPHER_SUITE_BIP_GMAC_128;
552 hw->wiphy->n_cipher_suites++;
553 mvm->ciphers[hw->wiphy->n_cipher_suites] =
554 WLAN_CIPHER_SUITE_BIP_GMAC_256;
555 hw->wiphy->n_cipher_suites++;
559 /* currently FW API supports only one optional cipher scheme */
560 if (mvm->fw->cs[0].cipher) {
561 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
562 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
564 mvm->hw->n_cipher_schemes = 1;
566 cs->cipher = le32_to_cpu(fwcs->cipher);
567 cs->iftype = BIT(NL80211_IFTYPE_STATION);
568 cs->hdr_len = fwcs->hdr_len;
569 cs->pn_len = fwcs->pn_len;
570 cs->pn_off = fwcs->pn_off;
571 cs->key_idx_off = fwcs->key_idx_off;
572 cs->key_idx_mask = fwcs->key_idx_mask;
573 cs->key_idx_shift = fwcs->key_idx_shift;
574 cs->mic_len = fwcs->mic_len;
576 mvm->hw->cipher_schemes = mvm->cs;
577 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
578 hw->wiphy->n_cipher_suites++;
581 if (fw_has_capa(&mvm->fw->ucode_capa,
582 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
583 wiphy_ext_feature_set(hw->wiphy,
584 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
585 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
588 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
589 hw->wiphy->features |=
590 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
591 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
592 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
594 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
595 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
596 hw->chanctx_data_size = sizeof(u16);
597 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
599 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
600 BIT(NL80211_IFTYPE_P2P_CLIENT) |
601 BIT(NL80211_IFTYPE_AP) |
602 BIT(NL80211_IFTYPE_P2P_GO) |
603 BIT(NL80211_IFTYPE_P2P_DEVICE) |
604 BIT(NL80211_IFTYPE_ADHOC);
606 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
607 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
608 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
610 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
611 if (iwl_mvm_is_lar_supported(mvm))
612 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
614 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
615 REGULATORY_DISABLE_BEACON_HINTS;
617 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
618 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
620 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
621 hw->wiphy->n_iface_combinations =
622 ARRAY_SIZE(iwl_mvm_iface_combinations);
624 hw->wiphy->max_remain_on_channel_duration = 10000;
625 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
627 /* Extract MAC address */
628 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
629 hw->wiphy->addresses = mvm->addresses;
630 hw->wiphy->n_addresses = 1;
632 /* Extract additional MAC addresses if available */
633 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
634 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
636 for (i = 1; i < num_mac; i++) {
637 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
639 mvm->addresses[i].addr[5]++;
640 hw->wiphy->n_addresses++;
643 iwl_mvm_reset_phy_ctxts(mvm);
645 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
647 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
649 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
650 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
651 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
653 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
654 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
656 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
658 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
659 hw->wiphy->bands[NL80211_BAND_2GHZ] =
660 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
661 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
662 hw->wiphy->bands[NL80211_BAND_5GHZ] =
663 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
665 if (fw_has_capa(&mvm->fw->ucode_capa,
666 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
667 fw_has_api(&mvm->fw->ucode_capa,
668 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
669 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
670 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
673 hw->wiphy->hw_version = mvm->trans->hw_id;
675 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
676 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
678 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
680 hw->wiphy->max_sched_scan_reqs = 1;
681 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
682 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
683 /* we create the 802.11 header and zero length SSID IE. */
684 hw->wiphy->max_sched_scan_ie_len =
685 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
686 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
687 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
690 * the firmware uses u8 for num of iterations, but 0xff is saved for
691 * infinite loop, so the maximum number of iterations is actually 254.
693 hw->wiphy->max_sched_scan_plan_iterations = 254;
695 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
696 NL80211_FEATURE_LOW_PRIORITY_SCAN |
697 NL80211_FEATURE_P2P_GO_OPPPS |
698 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
699 NL80211_FEATURE_DYNAMIC_SMPS |
700 NL80211_FEATURE_STATIC_SMPS |
701 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
703 if (fw_has_capa(&mvm->fw->ucode_capa,
704 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
705 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
706 if (fw_has_capa(&mvm->fw->ucode_capa,
707 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
708 hw->wiphy->features |= NL80211_FEATURE_QUIET;
710 if (fw_has_capa(&mvm->fw->ucode_capa,
711 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
712 hw->wiphy->features |=
713 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
715 if (fw_has_capa(&mvm->fw->ucode_capa,
716 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
717 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
719 if (fw_has_api(&mvm->fw->ucode_capa,
720 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
721 wiphy_ext_feature_set(hw->wiphy,
722 NL80211_EXT_FEATURE_SCAN_START_TIME);
723 wiphy_ext_feature_set(hw->wiphy,
724 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
725 wiphy_ext_feature_set(hw->wiphy,
726 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
729 if (iwl_mvm_is_oce_supported(mvm)) {
730 wiphy_ext_feature_set(hw->wiphy,
731 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
732 wiphy_ext_feature_set(hw->wiphy,
733 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
734 wiphy_ext_feature_set(hw->wiphy,
735 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
736 wiphy_ext_feature_set(hw->wiphy,
737 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
740 if (mvm->nvm_data->sku_cap_11ax_enable &&
741 !iwlwifi_mod_params.disable_11ax) {
742 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
743 hw->wiphy->num_iftype_ext_capab =
744 ARRAY_SIZE(he_iftypes_ext_capa);
746 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
747 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
750 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
752 #ifdef CONFIG_PM_SLEEP
753 if (iwl_mvm_is_d0i3_supported(mvm) &&
754 device_can_wakeup(mvm->trans->dev)) {
755 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
756 hw->wiphy->wowlan = &mvm->wowlan;
759 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
760 mvm->trans->ops->d3_suspend &&
761 mvm->trans->ops->d3_resume &&
762 device_can_wakeup(mvm->trans->dev)) {
763 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
764 WIPHY_WOWLAN_DISCONNECT |
765 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
766 WIPHY_WOWLAN_RFKILL_RELEASE |
767 WIPHY_WOWLAN_NET_DETECT;
768 if (!iwlwifi_mod_params.swcrypto)
769 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
770 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
771 WIPHY_WOWLAN_4WAY_HANDSHAKE;
773 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
774 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
775 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
776 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
777 hw->wiphy->wowlan = &mvm->wowlan;
781 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
782 /* assign default bcast filtering configuration */
783 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
786 ret = iwl_mvm_leds_init(mvm);
790 if (fw_has_capa(&mvm->fw->ucode_capa,
791 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
792 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
793 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
794 ieee80211_hw_set(hw, TDLS_WIDER_BW);
797 if (fw_has_capa(&mvm->fw->ucode_capa,
798 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
799 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
800 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
803 hw->netdev_features |= mvm->cfg->features;
804 if (!iwl_mvm_is_csum_supported(mvm)) {
805 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
807 /* We may support SW TX CSUM */
808 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
809 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
812 if (mvm->cfg->vht_mu_mimo_supported)
813 wiphy_ext_feature_set(hw->wiphy,
814 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
816 ret = ieee80211_register_hw(mvm->hw);
818 iwl_mvm_leds_exit(mvm);
824 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
825 struct ieee80211_sta *sta,
828 struct iwl_mvm_sta *mvmsta;
832 * double check the IN_D0I3 flag both before and after
833 * taking the spinlock, in order to prevent taking
834 * the spinlock when not needed.
836 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
839 spin_lock(&mvm->d0i3_tx_lock);
841 * testing the flag again ensures the skb dequeue
842 * loop (on d0i3 exit) hasn't run yet.
844 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
847 mvmsta = iwl_mvm_sta_from_mac80211(sta);
848 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
849 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
852 __skb_queue_tail(&mvm->d0i3_tx, skb);
855 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
856 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
860 spin_unlock(&mvm->d0i3_tx_lock);
864 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
865 struct ieee80211_tx_control *control,
868 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
869 struct ieee80211_sta *sta = control->sta;
870 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
871 struct ieee80211_hdr *hdr = (void *)skb->data;
872 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
873 IEEE80211_TX_CTL_TX_OFFCHAN;
875 if (iwl_mvm_is_radio_killed(mvm)) {
876 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
881 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
882 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
885 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
886 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
887 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
888 ieee80211_is_mgmt(hdr->frame_control) &&
889 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
892 /* If there is no sta, and it's not offchannel - send through AP */
893 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
895 struct iwl_mvm_vif *mvmvif =
896 iwl_mvm_vif_from_mac80211(info->control.vif);
897 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
899 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
900 /* mac80211 holds rcu read lock */
901 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
902 if (IS_ERR_OR_NULL(sta))
908 if (iwl_mvm_defer_tx(mvm, sta, skb))
910 if (iwl_mvm_tx_skb(mvm, skb, sta))
915 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
919 ieee80211_free_txskb(hw, skb);
922 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
924 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
925 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
926 struct sk_buff *skb = NULL;
929 * No need for threads to be pending here, they can leave the first
930 * taker all the work.
932 * mvmtxq->tx_request logic:
934 * If 0, no one is currently TXing, set to 1 to indicate current thread
935 * will now start TX and other threads should quit.
937 * If 1, another thread is currently TXing, set to 2 to indicate to
938 * that thread that there was another request. Since that request may
939 * have raced with the check whether the queue is empty, the TXing
940 * thread should check the queue's status one more time before leaving.
941 * This check is done in order to not leave any TX hanging in the queue
942 * until the next TX invocation (which may not even happen).
944 * If 2, another thread is currently TXing, and it will already double
945 * check the queue, so do nothing.
947 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
952 while (likely(!mvmtxq->stopped &&
953 (mvm->trans->system_pm_mode ==
954 IWL_PLAT_PM_MODE_DISABLED))) {
955 skb = ieee80211_tx_dequeue(hw, txq);
960 "TXQ of sta %pM tid %d is now empty\n",
967 iwl_mvm_tx_skb_non_sta(mvm, skb);
969 iwl_mvm_tx_skb(mvm, skb, txq->sta);
971 } while (atomic_dec_return(&mvmtxq->tx_request));
975 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
976 struct ieee80211_txq *txq)
978 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
979 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
982 * Please note that racing is handled very carefully here:
983 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
984 * deleted afterwards.
985 * This means that if:
986 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
987 * queue is allocated and we can TX.
988 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
989 * a race, should defer the frame.
990 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
991 * need to allocate the queue and defer the frame.
992 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
993 * queue is already scheduled for allocation, no need to allocate,
994 * should defer the frame.
997 /* If the queue is allocated TX and return. */
998 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
1000 * Check that list is empty to avoid a race where txq_id is
1001 * already updated, but the queue allocation work wasn't
1004 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
1007 iwl_mvm_mac_itxq_xmit(hw, txq);
1011 /* The list is being deleted only after the queue is fully allocated. */
1012 if (!list_empty(&mvmtxq->list))
1015 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
1016 schedule_work(&mvm->add_stream_wk);
1019 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
1021 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
1023 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
1027 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1028 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
1029 enum ieee80211_ampdu_mlme_action action)
1031 struct iwl_fw_dbg_trigger_tlv *trig;
1032 struct iwl_fw_dbg_trigger_ba *ba_trig;
1034 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1039 ba_trig = (void *)trig->data;
1042 case IEEE80211_AMPDU_TX_OPERATIONAL: {
1043 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1044 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1046 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
1047 "TX AGG START: MAC %pM tid %d ssn %d\n",
1048 sta->addr, tid, tid_data->ssn);
1051 case IEEE80211_AMPDU_TX_STOP_CONT:
1052 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
1053 "TX AGG STOP: MAC %pM tid %d\n",
1056 case IEEE80211_AMPDU_RX_START:
1057 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
1058 "RX AGG START: MAC %pM tid %d ssn %d\n",
1059 sta->addr, tid, rx_ba_ssn);
1061 case IEEE80211_AMPDU_RX_STOP:
1062 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
1063 "RX AGG STOP: MAC %pM tid %d\n",
1071 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
1072 struct ieee80211_vif *vif,
1073 struct ieee80211_ampdu_params *params)
1075 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1077 bool tx_agg_ref = false;
1078 struct ieee80211_sta *sta = params->sta;
1079 enum ieee80211_ampdu_mlme_action action = params->action;
1080 u16 tid = params->tid;
1081 u16 *ssn = ¶ms->ssn;
1082 u16 buf_size = params->buf_size;
1083 bool amsdu = params->amsdu;
1084 u16 timeout = params->timeout;
1086 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
1087 sta->addr, tid, action);
1089 if (!(mvm->nvm_data->sku_cap_11n_enable))
1092 /* return from D0i3 before starting a new Tx aggregation */
1094 case IEEE80211_AMPDU_TX_START:
1095 case IEEE80211_AMPDU_TX_STOP_CONT:
1096 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1097 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1098 case IEEE80211_AMPDU_TX_OPERATIONAL:
1100 * for tx start, wait synchronously until D0i3 exit to
1101 * get the correct sequence number for the tid.
1102 * additionally, some other ampdu actions use direct
1103 * target access, which is not handled automatically
1104 * by the trans layer (unlike commands), so wait for
1105 * d0i3 exit in these cases as well.
1107 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
1117 mutex_lock(&mvm->mutex);
1120 case IEEE80211_AMPDU_RX_START:
1121 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
1122 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
1123 struct iwl_mvm_vif *mvmvif;
1124 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
1125 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
1127 mdata->opened_rx_ba_sessions = true;
1128 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1129 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
1131 if (!iwl_enable_rx_ampdu()) {
1135 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1138 case IEEE80211_AMPDU_RX_STOP:
1139 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1142 case IEEE80211_AMPDU_TX_START:
1143 if (!iwl_enable_tx_ampdu()) {
1147 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1149 case IEEE80211_AMPDU_TX_STOP_CONT:
1150 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1152 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1153 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1154 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1156 case IEEE80211_AMPDU_TX_OPERATIONAL:
1157 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1169 if (action == IEEE80211_AMPDU_RX_START)
1172 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1175 mutex_unlock(&mvm->mutex);
1178 * If the tid is marked as started, we won't use it for offloaded
1179 * traffic on the next D0i3 entry. It's safe to unref.
1182 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1187 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1188 struct ieee80211_vif *vif)
1190 struct iwl_mvm *mvm = data;
1191 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1193 mvmvif->uploaded = false;
1194 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1196 spin_lock_bh(&mvm->time_event_lock);
1197 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1198 spin_unlock_bh(&mvm->time_event_lock);
1200 mvmvif->phy_ctxt = NULL;
1201 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1202 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1205 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1207 /* cleanup all stale references (scan, roc), but keep the
1208 * ucode_down ref until reconfig is complete
1210 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1212 iwl_mvm_stop_device(mvm);
1216 mvm->scan_status = 0;
1217 mvm->ps_disabled = false;
1218 mvm->rfkill_safe_init_done = false;
1220 /* just in case one was running */
1221 iwl_mvm_cleanup_roc_te(mvm);
1222 ieee80211_remain_on_channel_expired(mvm->hw);
1224 iwl_mvm_ftm_restart(mvm);
1227 * cleanup all interfaces, even inactive ones, as some might have
1228 * gone down during the HW restart
1230 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1232 mvm->p2p_device_vif = NULL;
1233 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1235 iwl_mvm_reset_phy_ctxts(mvm);
1236 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1237 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1238 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1240 ieee80211_wake_queues(mvm->hw);
1242 /* clear any stale d0i3 state */
1243 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1246 mvm->rx_ba_sessions = 0;
1247 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1248 mvm->monitor_on = false;
1250 /* keep statistics ticking */
1251 iwl_mvm_accu_radio_stats(mvm);
1254 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1258 lockdep_assert_held(&mvm->mutex);
1260 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1262 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1263 * so later code will - from now on - see that we're doing it.
1265 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1266 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1267 /* Clean up some internal and mac80211 state on restart */
1268 iwl_mvm_restart_cleanup(mvm);
1270 /* Hold the reference to prevent runtime suspend while
1271 * the start procedure runs. It's a bit confusing
1272 * that the UCODE_DOWN reference is taken, but it just
1273 * means "UCODE is not UP yet". ( TODO: rename this
1276 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1278 ret = iwl_mvm_up(mvm);
1280 iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_POST_INIT);
1282 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1283 /* Something went wrong - we need to finish some cleanup
1284 * that normally iwl_mvm_mac_restart_complete() below
1287 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1289 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1296 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1301 /* Some hw restart cleanups must not hold the mutex */
1302 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1304 * Make sure we are out of d0i3. This is needed
1305 * to make sure the reference accounting is correct
1306 * (and there is no stale d0i3_exit_work).
1308 wait_event_timeout(mvm->d0i3_exit_waitq,
1309 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1314 mutex_lock(&mvm->mutex);
1315 ret = __iwl_mvm_mac_start(mvm);
1316 mutex_unlock(&mvm->mutex);
1321 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1325 mutex_lock(&mvm->mutex);
1327 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1329 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1331 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1333 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1336 /* allow transport/FW low power modes */
1337 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1339 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1342 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1343 * of packets the FW sent out, so we must reconnect.
1345 iwl_mvm_teardown_tdls_peers(mvm);
1347 mutex_unlock(&mvm->mutex);
1350 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1352 if (iwl_mvm_is_d0i3_supported(mvm) &&
1353 iwl_mvm_enter_d0i3_on_suspend(mvm))
1354 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1355 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1358 "D0i3 exit on resume timed out\n");
1362 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1363 enum ieee80211_reconfig_type reconfig_type)
1365 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1367 switch (reconfig_type) {
1368 case IEEE80211_RECONFIG_TYPE_RESTART:
1369 iwl_mvm_restart_complete(mvm);
1371 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1372 iwl_mvm_resume_complete(mvm);
1377 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1379 lockdep_assert_held(&mvm->mutex);
1381 /* firmware counters are obviously reset now, but we shouldn't
1382 * partially track so also clear the fw_reset_accu counters.
1384 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1386 /* async_handlers_wk is now blocked */
1389 * The work item could be running or queued if the
1390 * ROC time event stops just as we get here.
1392 flush_work(&mvm->roc_done_wk);
1394 iwl_mvm_stop_device(mvm);
1396 iwl_mvm_async_handlers_purge(mvm);
1397 /* async_handlers_list is empty and will stay empty: HW is stopped */
1399 /* the fw is stopped, the aux sta is dead: clean up driver state */
1400 iwl_mvm_del_aux_sta(mvm);
1403 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1404 * hw (as restart_complete() won't be called in this case) and mac80211
1405 * won't execute the restart.
1406 * But make sure to cleanup interfaces that have gone down before/during
1407 * HW restart was requested.
1409 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1410 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1412 ieee80211_iterate_interfaces(mvm->hw, 0,
1413 iwl_mvm_cleanup_iterator, mvm);
1415 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1416 * make sure there's nothing left there and warn if any is found.
1418 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1421 for (i = 0; i < mvm->max_scans; i++) {
1422 if (WARN_ONCE(mvm->scan_uid_status[i],
1423 "UMAC scan UID %d status was not cleaned\n",
1425 mvm->scan_uid_status[i] = 0;
1430 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1434 flush_work(&mvm->d0i3_exit_work);
1435 flush_work(&mvm->async_handlers_wk);
1436 flush_work(&mvm->add_stream_wk);
1439 * Lock and clear the firmware running bit here already, so that
1440 * new commands coming in elsewhere, e.g. from debugfs, will not
1441 * be able to proceed. This is important here because one of those
1442 * debugfs files causes the firmware dump to be triggered, and if we
1443 * don't stop debugfs accesses before canceling that it could be
1444 * retriggered after we flush it but before we've cleared the bit.
1446 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1448 iwl_fw_cancel_dumps(&mvm->fwrt);
1449 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1450 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1451 iwl_fw_free_dump_desc(&mvm->fwrt);
1453 mutex_lock(&mvm->mutex);
1454 __iwl_mvm_mac_stop(mvm);
1455 mutex_unlock(&mvm->mutex);
1458 * The worker might have been waiting for the mutex, let it run and
1459 * discover that its list is now empty.
1461 cancel_work_sync(&mvm->async_handlers_wk);
1464 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1468 lockdep_assert_held(&mvm->mutex);
1470 for (i = 0; i < NUM_PHY_CTX; i++)
1471 if (!mvm->phy_ctxts[i].ref)
1472 return &mvm->phy_ctxts[i];
1474 IWL_ERR(mvm, "No available PHY context\n");
1478 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1483 struct iwl_dev_tx_power_cmd v5;
1484 struct iwl_dev_tx_power_cmd_v4 v4;
1486 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1487 .v5.v3.mac_context_id =
1488 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1489 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1492 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1493 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1495 if (fw_has_api(&mvm->fw->ucode_capa,
1496 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1497 len = sizeof(cmd.v5);
1498 else if (fw_has_capa(&mvm->fw->ucode_capa,
1499 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1500 len = sizeof(cmd.v4);
1502 len = sizeof(cmd.v4.v3);
1504 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1507 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1508 struct ieee80211_vif *vif)
1510 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1511 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1514 mutex_lock(&mvm->mutex);
1516 if (mvmvif->csa_failed) {
1517 mvmvif->csa_failed = false;
1522 if (vif->type == NL80211_IFTYPE_STATION) {
1523 struct iwl_mvm_sta *mvmsta;
1525 mvmvif->csa_bcn_pending = false;
1526 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1529 if (WARN_ON(!mvmsta)) {
1534 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1536 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1538 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1542 iwl_mvm_stop_session_protection(mvm, vif);
1545 mvmvif->ps_disabled = false;
1547 ret = iwl_mvm_power_update_ps(mvm);
1550 mutex_unlock(&mvm->mutex);
1555 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1556 struct ieee80211_vif *vif)
1558 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1559 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1560 struct iwl_chan_switch_te_cmd cmd = {
1561 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1563 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1566 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1568 mutex_lock(&mvm->mutex);
1569 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1570 WIDE_ID(MAC_CONF_GROUP,
1571 CHANNEL_SWITCH_TIME_EVENT_CMD),
1572 0, sizeof(cmd), &cmd));
1573 mutex_unlock(&mvm->mutex);
1575 WARN_ON(iwl_mvm_post_channel_switch(hw, vif));
1578 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1580 struct iwl_mvm *mvm;
1581 struct iwl_mvm_vif *mvmvif;
1582 struct ieee80211_vif *vif;
1584 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1585 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1588 iwl_mvm_abort_channel_switch(mvm->hw, vif);
1589 ieee80211_chswitch_done(vif, false);
1592 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1593 struct ieee80211_vif *vif)
1595 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1596 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1600 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1603 * make sure D0i3 exit is completed, otherwise a target access
1604 * during tx queue configuration could be done when still in
1607 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1612 * Not much to do here. The stack will not allow interface
1613 * types or combinations that we didn't advertise, so we
1614 * don't really have to check the types.
1617 mutex_lock(&mvm->mutex);
1619 /* make sure that beacon statistics don't go backwards with FW reset */
1620 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1621 mvmvif->beacon_stats.accu_num_beacons +=
1622 mvmvif->beacon_stats.num_beacons;
1624 /* Allocate resources for the MAC context, and add it to the fw */
1625 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1629 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1631 /* Counting number of interfaces is needed for legacy PM */
1632 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1636 * The AP binding flow can be done only after the beacon
1637 * template is configured (which happens only in the mac80211
1638 * start_ap() flow), and adding the broadcast station can happen
1639 * only after the binding.
1640 * In addition, since modifying the MAC before adding a bcast
1641 * station is not allowed by the FW, delay the adding of MAC context to
1642 * the point where we can also add the bcast station.
1643 * In short: there's not much we can do at this point, other than
1644 * allocating resources :)
1646 if (vif->type == NL80211_IFTYPE_AP ||
1647 vif->type == NL80211_IFTYPE_ADHOC) {
1648 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1650 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1655 * Only queue for this station is the mcast queue,
1656 * which shouldn't be in TFD mask anyway
1658 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1664 iwl_mvm_vif_dbgfs_register(mvm, vif);
1668 mvmvif->features |= hw->netdev_features;
1670 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1674 ret = iwl_mvm_power_update_mac(mvm);
1676 goto out_remove_mac;
1678 /* beacon filtering */
1679 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1681 goto out_remove_mac;
1683 if (!mvm->bf_allowed_vif &&
1684 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1685 mvm->bf_allowed_vif = mvmvif;
1686 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1687 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1691 * P2P_DEVICE interface does not have a channel context assigned to it,
1692 * so a dedicated PHY context is allocated to it and the corresponding
1693 * MAC context is bound to it at this stage.
1695 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1697 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1698 if (!mvmvif->phy_ctxt) {
1703 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1704 ret = iwl_mvm_binding_add_vif(mvm, vif);
1708 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1712 /* Save a pointer to p2p device vif, so it can later be used to
1713 * update the p2p device MAC when a GO is started/stopped */
1714 mvm->p2p_device_vif = vif;
1717 iwl_mvm_tcm_add_vif(mvm, vif);
1718 INIT_DELAYED_WORK(&mvmvif->csa_work,
1719 iwl_mvm_channel_switch_disconnect_wk);
1721 if (vif->type == NL80211_IFTYPE_MONITOR)
1722 mvm->monitor_on = true;
1724 iwl_mvm_vif_dbgfs_register(mvm, vif);
1728 iwl_mvm_binding_remove_vif(mvm, vif);
1730 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1732 if (mvm->bf_allowed_vif == mvmvif) {
1733 mvm->bf_allowed_vif = NULL;
1734 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1735 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1738 mvmvif->phy_ctxt = NULL;
1739 iwl_mvm_mac_ctxt_remove(mvm, vif);
1741 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1744 mutex_unlock(&mvm->mutex);
1746 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1751 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1752 struct ieee80211_vif *vif)
1754 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1756 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1757 * We assume here that all the packets sent to the OFFCHANNEL
1758 * queue are sent in ROC session.
1760 flush_work(&mvm->roc_done_wk);
1764 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1765 struct ieee80211_vif *vif)
1767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1768 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1769 struct iwl_probe_resp_data *probe_data;
1771 iwl_mvm_prepare_mac_removal(mvm, vif);
1773 if (!(vif->type == NL80211_IFTYPE_AP ||
1774 vif->type == NL80211_IFTYPE_ADHOC))
1775 iwl_mvm_tcm_rm_vif(mvm, vif);
1777 mutex_lock(&mvm->mutex);
1779 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1780 lockdep_is_held(&mvm->mutex));
1781 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1783 kfree_rcu(probe_data, rcu_head);
1785 if (mvm->bf_allowed_vif == mvmvif) {
1786 mvm->bf_allowed_vif = NULL;
1787 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1788 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1791 if (vif->bss_conf.ftm_responder)
1792 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1794 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1797 * For AP/GO interface, the tear down of the resources allocated to the
1798 * interface is be handled as part of the stop_ap flow.
1800 if (vif->type == NL80211_IFTYPE_AP ||
1801 vif->type == NL80211_IFTYPE_ADHOC) {
1802 #ifdef CONFIG_NL80211_TESTMODE
1803 if (vif == mvm->noa_vif) {
1804 mvm->noa_vif = NULL;
1805 mvm->noa_duration = 0;
1808 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1809 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1813 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1814 mvm->p2p_device_vif = NULL;
1815 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1816 iwl_mvm_binding_remove_vif(mvm, vif);
1817 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1818 mvmvif->phy_ctxt = NULL;
1821 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1824 iwl_mvm_power_update_mac(mvm);
1825 iwl_mvm_mac_ctxt_remove(mvm, vif);
1827 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1829 if (vif->type == NL80211_IFTYPE_MONITOR)
1830 mvm->monitor_on = false;
1833 mutex_unlock(&mvm->mutex);
1836 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1841 struct iwl_mvm_mc_iter_data {
1842 struct iwl_mvm *mvm;
1846 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1847 struct ieee80211_vif *vif)
1849 struct iwl_mvm_mc_iter_data *data = _data;
1850 struct iwl_mvm *mvm = data->mvm;
1851 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1852 struct iwl_host_cmd hcmd = {
1853 .id = MCAST_FILTER_CMD,
1855 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1859 /* if we don't have free ports, mcast frames will be dropped */
1860 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1863 if (vif->type != NL80211_IFTYPE_STATION ||
1864 !vif->bss_conf.assoc)
1867 cmd->port_id = data->port_id++;
1868 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1869 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1874 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1876 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1879 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1881 struct iwl_mvm_mc_iter_data iter_data = {
1885 lockdep_assert_held(&mvm->mutex);
1887 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1890 ieee80211_iterate_active_interfaces_atomic(
1891 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1892 iwl_mvm_mc_iface_iterator, &iter_data);
1895 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1896 struct netdev_hw_addr_list *mc_list)
1898 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1899 struct iwl_mcast_filter_cmd *cmd;
1900 struct netdev_hw_addr *addr;
1905 addr_count = netdev_hw_addr_list_count(mc_list);
1906 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1907 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1911 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1912 cmd = kzalloc(len, GFP_ATOMIC);
1918 return (u64)(unsigned long)cmd;
1921 netdev_hw_addr_list_for_each(addr, mc_list) {
1922 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1923 cmd->count, addr->addr);
1924 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1925 addr->addr, ETH_ALEN);
1929 return (u64)(unsigned long)cmd;
1932 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1933 unsigned int changed_flags,
1934 unsigned int *total_flags,
1937 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1938 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1940 mutex_lock(&mvm->mutex);
1942 /* replace previous configuration */
1943 kfree(mvm->mcast_filter_cmd);
1944 mvm->mcast_filter_cmd = cmd;
1949 if (changed_flags & FIF_ALLMULTI)
1950 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1955 iwl_mvm_recalc_multicast(mvm);
1957 mutex_unlock(&mvm->mutex);
1961 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1962 struct ieee80211_vif *vif,
1963 unsigned int filter_flags,
1964 unsigned int changed_flags)
1966 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1968 /* We support only filter for probe requests */
1969 if (!(changed_flags & FIF_PROBE_REQ))
1972 /* Supported only for p2p client interfaces */
1973 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1977 mutex_lock(&mvm->mutex);
1978 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1979 mutex_unlock(&mvm->mutex);
1982 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1983 struct iwl_bcast_iter_data {
1984 struct iwl_mvm *mvm;
1985 struct iwl_bcast_filter_cmd *cmd;
1990 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1991 const struct iwl_fw_bcast_filter *in_filter,
1992 struct iwl_fw_bcast_filter *out_filter)
1994 struct iwl_fw_bcast_filter_attr *attr;
1997 memcpy(out_filter, in_filter, sizeof(*out_filter));
1999 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
2000 attr = &out_filter->attrs[i];
2005 switch (attr->reserved1) {
2006 case cpu_to_le16(BC_FILTER_MAGIC_IP):
2007 if (vif->bss_conf.arp_addr_cnt != 1) {
2012 attr->val = vif->bss_conf.arp_addr_list[0];
2014 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
2015 attr->val = *(__be32 *)&vif->addr[2];
2020 attr->reserved1 = 0;
2021 out_filter->num_attrs++;
2025 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
2026 struct ieee80211_vif *vif)
2028 struct iwl_bcast_iter_data *data = _data;
2029 struct iwl_mvm *mvm = data->mvm;
2030 struct iwl_bcast_filter_cmd *cmd = data->cmd;
2031 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2032 struct iwl_fw_bcast_mac *bcast_mac;
2035 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
2038 bcast_mac = &cmd->macs[mvmvif->id];
2041 * enable filtering only for associated stations, but not for P2P
2044 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
2045 !vif->bss_conf.assoc)
2048 bcast_mac->default_discard = 1;
2050 /* copy all configured filters */
2051 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
2053 * Make sure we don't exceed our filters limit.
2054 * if there is still a valid filter to be configured,
2055 * be on the safe side and just allow bcast for this mac.
2057 if (WARN_ON_ONCE(data->current_filter >=
2058 ARRAY_SIZE(cmd->filters))) {
2059 bcast_mac->default_discard = 0;
2060 bcast_mac->attached_filters = 0;
2064 iwl_mvm_set_bcast_filter(vif,
2065 &mvm->bcast_filters[i],
2066 &cmd->filters[data->current_filter]);
2068 /* skip current filter if it contains no attributes */
2069 if (!cmd->filters[data->current_filter].num_attrs)
2072 /* attach the filter to current mac */
2073 bcast_mac->attached_filters |=
2074 cpu_to_le16(BIT(data->current_filter));
2076 data->current_filter++;
2080 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
2081 struct iwl_bcast_filter_cmd *cmd)
2083 struct iwl_bcast_iter_data iter_data = {
2088 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
2091 memset(cmd, 0, sizeof(*cmd));
2092 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
2093 cmd->max_macs = ARRAY_SIZE(cmd->macs);
2095 #ifdef CONFIG_IWLWIFI_DEBUGFS
2096 /* use debugfs filters/macs if override is configured */
2097 if (mvm->dbgfs_bcast_filtering.override) {
2098 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
2099 sizeof(cmd->filters));
2100 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
2106 /* if no filters are configured, do nothing */
2107 if (!mvm->bcast_filters)
2110 /* configure and attach these filters for each associated sta vif */
2111 ieee80211_iterate_active_interfaces(
2112 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2113 iwl_mvm_bcast_filter_iterator, &iter_data);
2118 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2120 struct iwl_bcast_filter_cmd cmd;
2122 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
2125 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
2128 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
2132 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2138 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
2139 struct ieee80211_vif *vif)
2141 struct iwl_mu_group_mgmt_cmd cmd = {};
2143 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
2144 WLAN_MEMBERSHIP_LEN);
2145 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
2146 WLAN_USER_POSITION_LEN);
2148 return iwl_mvm_send_cmd_pdu(mvm,
2149 WIDE_ID(DATA_PATH_GROUP,
2150 UPDATE_MU_GROUPS_CMD),
2151 0, sizeof(cmd), &cmd);
2154 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
2155 struct ieee80211_vif *vif)
2157 if (vif->mu_mimo_owner) {
2158 struct iwl_mu_group_mgmt_notif *notif = _data;
2161 * MU-MIMO Group Id action frame is little endian. We treat
2162 * the data received from firmware as if it came from the
2163 * action frame, so no conversion is needed.
2165 ieee80211_update_mu_groups(vif,
2166 (u8 *)¬if->membership_status,
2167 (u8 *)¬if->user_position);
2171 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2172 struct iwl_rx_cmd_buffer *rxb)
2174 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2175 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
2177 ieee80211_iterate_active_interfaces_atomic(
2178 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2179 iwl_mvm_mu_mimo_iface_iterator, notif);
2182 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
2184 u8 byte_num = ppe_pos_bit / 8;
2185 u8 bit_num = ppe_pos_bit % 8;
2190 return (ppe[byte_num] >> bit_num) &
2191 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
2194 * If bit_num > 5, we have to combine bits with next byte.
2195 * Calculate how many bits we need to take from current byte (called
2196 * here "residue_bits"), and add them to bits from next byte.
2199 residue_bits = 8 - bit_num;
2201 res = (ppe[byte_num + 1] &
2202 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
2204 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
2209 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2210 struct ieee80211_vif *vif, u8 sta_id)
2212 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2213 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
2215 .tid_limit = IWL_MAX_TID_COUNT,
2216 .bss_color = vif->bss_conf.bss_color,
2217 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2218 .frame_time_rts_th =
2219 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2221 int size = fw_has_api(&mvm->fw->ucode_capa,
2222 IWL_UCODE_TLV_API_MBSSID_HE) ?
2223 sizeof(sta_ctxt_cmd) :
2224 sizeof(struct iwl_he_sta_context_cmd_v1);
2225 struct ieee80211_sta *sta;
2231 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2234 WARN(1, "Can't find STA to configure HE\n");
2238 if (!sta->he_cap.has_he) {
2246 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2247 IEEE80211_HE_MAC_CAP0_HTC_HE)
2248 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2249 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2250 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2251 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2252 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2254 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2255 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2256 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2257 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2260 sta_ctxt_cmd.htc_flags |=
2261 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2262 else if (link_adap == 3)
2263 sta_ctxt_cmd.htc_flags |=
2264 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2266 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2267 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2268 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2269 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2270 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2271 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2272 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2275 * Initialize the PPE thresholds to "None" (7), as described in Table
2276 * 9-262ac of 80211.ax/D3.0.
2278 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2280 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2281 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2282 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2283 u8 nss = (sta->he_cap.ppe_thres[0] &
2284 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2285 u8 ru_index_bitmap =
2286 (sta->he_cap.ppe_thres[0] &
2287 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2288 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2289 u8 *ppe = &sta->he_cap.ppe_thres[0];
2290 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2293 * FW currently supports only nss == MAX_HE_SUPP_NSS
2295 * If nss > MAX: we can ignore values we don't support
2296 * If nss < MAX: we can set zeros in other streams
2298 if (nss > MAX_HE_SUPP_NSS) {
2299 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2301 nss = MAX_HE_SUPP_NSS;
2304 for (i = 0; i < nss; i++) {
2305 u8 ru_index_tmp = ru_index_bitmap << 1;
2308 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2310 if (!(ru_index_tmp & 1))
2313 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2314 iwl_mvm_he_get_ppe_val(ppe,
2317 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2318 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2319 iwl_mvm_he_get_ppe_val(ppe,
2322 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2326 flags |= STA_CTXT_HE_PACKET_EXT;
2327 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2328 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2329 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2333 /* Take the PPE thresholds from the nominal padding info */
2334 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2335 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2336 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2337 low_th = IWL_HE_PKT_EXT_NONE;
2338 high_th = IWL_HE_PKT_EXT_NONE;
2340 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2341 low_th = IWL_HE_PKT_EXT_BPSK;
2342 high_th = IWL_HE_PKT_EXT_NONE;
2344 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2345 low_th = IWL_HE_PKT_EXT_NONE;
2346 high_th = IWL_HE_PKT_EXT_BPSK;
2350 /* Set the PPE thresholds accordingly */
2351 if (low_th >= 0 && high_th >= 0) {
2352 struct iwl_he_pkt_ext *pkt_ext =
2353 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
2355 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2358 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2360 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2362 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2367 flags |= STA_CTXT_HE_PACKET_EXT;
2372 /* Mark MU EDCA as enabled, unless none detected on some AC */
2373 flags |= STA_CTXT_HE_MU_EDCA_CW;
2374 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2375 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2376 &mvmvif->queue_params[i].mu_edca_param_rec;
2377 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2379 if (!mvmvif->queue_params[i].mu_edca) {
2380 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2384 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2385 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2386 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2387 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2388 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2389 cpu_to_le16(mu_edca->aifsn);
2390 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2391 cpu_to_le16(mu_edca->mu_edca_timer);
2394 if (vif->bss_conf.multi_sta_back_32bit)
2395 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2397 if (vif->bss_conf.ack_enabled)
2398 flags |= STA_CTXT_HE_ACK_ENABLED;
2400 if (vif->bss_conf.uora_exists) {
2401 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2403 sta_ctxt_cmd.rand_alloc_ecwmin =
2404 vif->bss_conf.uora_ocw_range & 0x7;
2405 sta_ctxt_cmd.rand_alloc_ecwmax =
2406 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2409 if (vif->bss_conf.nontransmitted) {
2410 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2411 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2412 vif->bss_conf.transmitter_bssid);
2413 sta_ctxt_cmd.max_bssid_indicator =
2414 vif->bss_conf.bssid_indicator;
2415 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2416 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2417 sta_ctxt_cmd.profile_periodicity =
2418 vif->bss_conf.profile_periodicity;
2421 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2423 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2424 DATA_PATH_GROUP, 0),
2425 0, size, &sta_ctxt_cmd))
2426 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2429 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2430 struct ieee80211_vif *vif,
2431 struct ieee80211_bss_conf *bss_conf,
2434 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2438 * Re-calculate the tsf id, as the master-slave relations depend on the
2439 * beacon interval, which was not known when the station interface was
2442 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2443 if (vif->bss_conf.he_support &&
2444 !iwlwifi_mod_params.disable_11ax)
2445 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2447 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2450 /* Update MU EDCA params */
2451 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2452 bss_conf->assoc && vif->bss_conf.he_support &&
2453 !iwlwifi_mod_params.disable_11ax)
2454 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2457 * If we're not associated yet, take the (new) BSSID before associating
2458 * so the firmware knows. If we're already associated, then use the old
2459 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2460 * branch for disassociation below.
2462 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2463 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2465 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2467 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2469 /* after sending it once, adopt mac80211 data */
2470 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2471 mvmvif->associated = bss_conf->assoc;
2473 if (changes & BSS_CHANGED_ASSOC) {
2474 if (bss_conf->assoc) {
2475 /* clear statistics to get clean beacon counter */
2476 iwl_mvm_request_statistics(mvm, true);
2477 memset(&mvmvif->beacon_stats, 0,
2478 sizeof(mvmvif->beacon_stats));
2480 /* add quota for this interface */
2481 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2483 IWL_ERR(mvm, "failed to update quotas\n");
2487 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2490 * If we're restarting then the firmware will
2491 * obviously have lost synchronisation with
2492 * the AP. It will attempt to synchronise by
2493 * itself, but we can make it more reliable by
2494 * scheduling a session protection time event.
2496 * The firmware needs to receive a beacon to
2497 * catch up with synchronisation, use 110% of
2498 * the beacon interval.
2500 * Set a large maximum delay to allow for more
2501 * than a single interface.
2503 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2504 iwl_mvm_protect_session(mvm, vif, dur, dur,
2508 iwl_mvm_sf_update(mvm, vif, false);
2509 iwl_mvm_power_vif_assoc(mvm, vif);
2511 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2512 iwl_mvm_update_smps(mvm, vif,
2513 IWL_MVM_SMPS_REQ_PROT,
2514 IEEE80211_SMPS_DYNAMIC);
2516 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2518 * If update fails - SF might be running in associated
2519 * mode while disassociated - which is forbidden.
2521 ret = iwl_mvm_sf_update(mvm, vif, false);
2523 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2525 "Failed to update SF upon disassociation\n");
2528 * If we get an assert during the connection (after the
2529 * station has been added, but before the vif is set
2530 * to associated), mac80211 will re-add the station and
2531 * then configure the vif. Since the vif is not
2532 * associated, we would remove the station here and
2533 * this would fail the recovery.
2535 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2538 * Remove AP station now that
2539 * the MAC is unassoc
2541 ret = iwl_mvm_rm_sta_id(mvm, vif,
2545 "failed to remove AP station\n");
2547 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2548 mvm->d0i3_ap_sta_id =
2549 IWL_MVM_INVALID_STA;
2550 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2553 /* remove quota for this interface */
2554 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2556 IWL_ERR(mvm, "failed to update quotas\n");
2559 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2561 /* this will take the cleared BSSID from bss_conf */
2562 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2565 "failed to update MAC %pM (clear after unassoc)\n",
2570 * The firmware tracks the MU-MIMO group on its own.
2571 * However, on HW restart we should restore this data.
2573 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2574 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2575 ret = iwl_mvm_update_mu_groups(mvm, vif);
2578 "failed to update VHT MU_MIMO groups\n");
2581 iwl_mvm_recalc_multicast(mvm);
2582 iwl_mvm_configure_bcast_filter(mvm);
2584 /* reset rssi values */
2585 mvmvif->bf_data.ave_beacon_signal = 0;
2587 iwl_mvm_bt_coex_vif_change(mvm);
2588 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2589 IEEE80211_SMPS_AUTOMATIC);
2590 if (fw_has_capa(&mvm->fw->ucode_capa,
2591 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2592 iwl_mvm_config_scan(mvm);
2595 if (changes & BSS_CHANGED_BEACON_INFO) {
2597 * We received a beacon from the associated AP so
2598 * remove the session protection.
2600 iwl_mvm_stop_session_protection(mvm, vif);
2602 iwl_mvm_sf_update(mvm, vif, false);
2603 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2606 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2608 * Send power command on every beacon change,
2609 * because we may have not enabled beacon abort yet.
2611 BSS_CHANGED_BEACON_INFO)) {
2612 ret = iwl_mvm_power_update_mac(mvm);
2614 IWL_ERR(mvm, "failed to update power mode\n");
2617 if (changes & BSS_CHANGED_TXPOWER) {
2618 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2620 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2623 if (changes & BSS_CHANGED_CQM) {
2624 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2625 /* reset cqm events tracking */
2626 mvmvif->bf_data.last_cqm_event = 0;
2627 if (mvmvif->bf_data.bf_enabled) {
2628 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2631 "failed to update CQM thresholds\n");
2635 if (changes & BSS_CHANGED_ARP_FILTER) {
2636 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2637 iwl_mvm_configure_bcast_filter(mvm);
2641 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2642 struct ieee80211_vif *vif)
2644 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2645 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2649 * iwl_mvm_mac_ctxt_add() might read directly from the device
2650 * (the system time), so make sure it is available.
2652 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2656 mutex_lock(&mvm->mutex);
2658 /* Send the beacon template */
2659 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2664 * Re-calculate the tsf id, as the master-slave relations depend on the
2665 * beacon interval, which was not known when the AP interface was added.
2667 if (vif->type == NL80211_IFTYPE_AP)
2668 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2670 mvmvif->ap_assoc_sta_count = 0;
2672 /* Add the mac context */
2673 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2677 /* Perform the binding */
2678 ret = iwl_mvm_binding_add_vif(mvm, vif);
2683 * This is not very nice, but the simplest:
2684 * For older FWs adding the mcast sta before the bcast station may
2685 * cause assert 0x2b00.
2686 * This is fixed in later FW so make the order of removal depend on
2689 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2690 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2694 * Send the bcast station. At this stage the TBTT and DTIM time
2695 * events are added and applied to the scheduler
2697 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2699 iwl_mvm_rm_mcast_sta(mvm, vif);
2704 * Send the bcast station. At this stage the TBTT and DTIM time
2705 * events are added and applied to the scheduler
2707 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2710 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2712 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2717 /* must be set before quota calculations */
2718 mvmvif->ap_ibss_active = true;
2720 /* send all the early keys to the device now */
2721 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2722 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2727 mvmvif->ap_early_keys[i] = NULL;
2729 ret = iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2731 goto out_quota_failed;
2734 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2735 iwl_mvm_vif_set_low_latency(mvmvif, true,
2736 LOW_LATENCY_VIF_TYPE);
2737 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2740 /* power updated needs to be done before quotas */
2741 iwl_mvm_power_update_mac(mvm);
2743 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2745 goto out_quota_failed;
2747 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2748 if (vif->p2p && mvm->p2p_device_vif)
2749 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2751 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2753 iwl_mvm_bt_coex_vif_change(mvm);
2755 /* we don't support TDLS during DCM */
2756 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2757 iwl_mvm_teardown_tdls_peers(mvm);
2759 iwl_mvm_ftm_restart_responder(mvm, vif);
2764 iwl_mvm_power_update_mac(mvm);
2765 mvmvif->ap_ibss_active = false;
2766 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2767 iwl_mvm_rm_mcast_sta(mvm, vif);
2769 iwl_mvm_binding_remove_vif(mvm, vif);
2771 iwl_mvm_mac_ctxt_remove(mvm, vif);
2773 mutex_unlock(&mvm->mutex);
2774 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2778 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2779 struct ieee80211_vif *vif)
2781 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2782 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2784 iwl_mvm_prepare_mac_removal(mvm, vif);
2786 mutex_lock(&mvm->mutex);
2788 /* Handle AP stop while in CSA */
2789 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2790 iwl_mvm_remove_time_event(mvm, mvmvif,
2791 &mvmvif->time_event_data);
2792 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2793 mvmvif->csa_countdown = false;
2796 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2797 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2798 mvm->csa_tx_block_bcn_timeout = 0;
2801 mvmvif->ap_ibss_active = false;
2802 mvm->ap_last_beacon_gp2 = 0;
2804 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2805 iwl_mvm_vif_set_low_latency(mvmvif, false,
2806 LOW_LATENCY_VIF_TYPE);
2807 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2810 iwl_mvm_bt_coex_vif_change(mvm);
2812 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2814 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2815 if (vif->p2p && mvm->p2p_device_vif)
2816 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2818 iwl_mvm_update_quotas(mvm, false, NULL);
2821 * This is not very nice, but the simplest:
2822 * For older FWs removing the mcast sta before the bcast station may
2823 * cause assert 0x2b00.
2824 * This is fixed in later FW (which will stop beaconing when removing
2826 * So make the order of removal depend on the TLV
2828 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2829 iwl_mvm_rm_mcast_sta(mvm, vif);
2830 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2831 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2832 iwl_mvm_rm_mcast_sta(mvm, vif);
2833 iwl_mvm_binding_remove_vif(mvm, vif);
2835 iwl_mvm_power_update_mac(mvm);
2837 iwl_mvm_mac_ctxt_remove(mvm, vif);
2839 mutex_unlock(&mvm->mutex);
2843 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2844 struct ieee80211_vif *vif,
2845 struct ieee80211_bss_conf *bss_conf,
2848 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2850 /* Changes will be applied when the AP/IBSS is started */
2851 if (!mvmvif->ap_ibss_active)
2854 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2855 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2856 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2857 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2859 /* Need to send a new beacon template to the FW */
2860 if (changes & BSS_CHANGED_BEACON &&
2861 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2862 IWL_WARN(mvm, "Failed updating beacon data\n");
2864 if (changes & BSS_CHANGED_TXPOWER) {
2865 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2867 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2870 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2871 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2874 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2880 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2881 struct ieee80211_vif *vif,
2882 struct ieee80211_bss_conf *bss_conf,
2885 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2888 * iwl_mvm_bss_info_changed_station() might call
2889 * iwl_mvm_protect_session(), which reads directly from
2890 * the device (the system time), so make sure it is available.
2892 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2895 mutex_lock(&mvm->mutex);
2897 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2898 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2900 switch (vif->type) {
2901 case NL80211_IFTYPE_STATION:
2902 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2904 case NL80211_IFTYPE_AP:
2905 case NL80211_IFTYPE_ADHOC:
2906 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2908 case NL80211_IFTYPE_MONITOR:
2909 if (changes & BSS_CHANGED_MU_GROUPS)
2910 iwl_mvm_update_mu_groups(mvm, vif);
2913 /* shouldn't happen */
2917 mutex_unlock(&mvm->mutex);
2918 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2921 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2922 struct ieee80211_vif *vif,
2923 struct ieee80211_scan_request *hw_req)
2925 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2928 if (hw_req->req.n_channels == 0 ||
2929 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2932 mutex_lock(&mvm->mutex);
2933 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2934 mutex_unlock(&mvm->mutex);
2939 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2940 struct ieee80211_vif *vif)
2942 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2944 mutex_lock(&mvm->mutex);
2946 /* Due to a race condition, it's possible that mac80211 asks
2947 * us to stop a hw_scan when it's already stopped. This can
2948 * happen, for instance, if we stopped the scan ourselves,
2949 * called ieee80211_scan_completed() and the userspace called
2950 * cancel scan scan before ieee80211_scan_work() could run.
2951 * To handle that, simply return if the scan is not running.
2953 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2954 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2956 mutex_unlock(&mvm->mutex);
2960 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2961 struct ieee80211_sta *sta, u16 tids,
2963 enum ieee80211_frame_release_type reason,
2966 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2968 /* Called when we need to transmit (a) frame(s) from mac80211 */
2970 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2971 tids, more_data, false);
2975 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2976 struct ieee80211_sta *sta, u16 tids,
2978 enum ieee80211_frame_release_type reason,
2981 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2983 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2985 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2986 tids, more_data, true);
2989 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2990 enum sta_notify_cmd cmd,
2991 struct ieee80211_sta *sta)
2993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2994 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2995 unsigned long txqs = 0, tids = 0;
2999 * If we have TVQM then we get too high queue numbers - luckily
3000 * we really shouldn't get here with that because such hardware
3001 * should have firmware supporting buffer station offload.
3003 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
3006 spin_lock_bh(&mvmsta->lock);
3007 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
3008 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3010 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
3013 __set_bit(tid_data->txq_id, &txqs);
3015 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
3018 __set_bit(tid, &tids);
3022 case STA_NOTIFY_SLEEP:
3023 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
3024 ieee80211_sta_set_buffered(sta, tid, true);
3027 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
3029 * The fw updates the STA to be asleep. Tx packets on the Tx
3030 * queues to this station will not be transmitted. The fw will
3031 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
3034 case STA_NOTIFY_AWAKE:
3035 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
3039 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
3040 iwl_mvm_sta_modify_ps_wake(mvm, sta);
3045 spin_unlock_bh(&mvmsta->lock);
3048 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
3049 struct ieee80211_vif *vif,
3050 enum sta_notify_cmd cmd,
3051 struct ieee80211_sta *sta)
3053 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
3056 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
3058 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3059 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
3060 struct ieee80211_sta *sta;
3061 struct iwl_mvm_sta *mvmsta;
3062 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
3064 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
3068 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
3069 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
3074 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3077 mvmsta->vif->type != NL80211_IFTYPE_AP) {
3082 if (mvmsta->sleeping != sleeping) {
3083 mvmsta->sleeping = sleeping;
3084 __iwl_mvm_mac_sta_notify(mvm->hw,
3085 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
3087 ieee80211_sta_ps_transition(sta, sleeping);
3091 switch (notif->type) {
3092 case IWL_MVM_PM_EVENT_AWAKE:
3093 case IWL_MVM_PM_EVENT_ASLEEP:
3095 case IWL_MVM_PM_EVENT_UAPSD:
3096 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
3098 case IWL_MVM_PM_EVENT_PS_POLL:
3099 ieee80211_sta_pspoll(sta);
3109 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
3110 struct ieee80211_vif *vif,
3111 struct ieee80211_sta *sta)
3113 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3114 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3117 * This is called before mac80211 does RCU synchronisation,
3118 * so here we already invalidate our internal RCU-protected
3119 * station pointer. The rest of the code will thus no longer
3120 * be able to find the station this way, and we don't rely
3121 * on further RCU synchronisation after the sta_state()
3122 * callback deleted the station.
3124 mutex_lock(&mvm->mutex);
3125 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
3126 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
3129 mutex_unlock(&mvm->mutex);
3132 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3137 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3138 struct iwl_mvm_tcm_mac *mdata;
3140 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
3141 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
3142 mdata->opened_rx_ba_sessions = false;
3145 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
3148 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
3149 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3154 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
3155 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3159 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
3160 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
3161 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3166 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3170 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
3171 struct ieee80211_vif *vif, u8 *peer_addr,
3172 enum nl80211_tdls_operation action)
3174 struct iwl_fw_dbg_trigger_tlv *trig;
3175 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3177 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3178 FW_DBG_TRIGGER_TDLS);
3182 tdls_trig = (void *)trig->data;
3184 if (!(tdls_trig->action_bitmap & BIT(action)))
3187 if (tdls_trig->peer_mode &&
3188 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3191 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3192 "TDLS event occurred, peer %pM, action %d",
3196 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3197 struct ieee80211_vif *vif,
3198 struct ieee80211_sta *sta,
3199 enum ieee80211_sta_state old_state,
3200 enum ieee80211_sta_state new_state)
3202 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3203 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3204 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3207 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3208 sta->addr, old_state, new_state);
3210 /* this would be a mac80211 bug ... but don't crash */
3211 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3215 * If we are in a STA removal flow and in DQA mode:
3217 * This is after the sync_rcu part, so the queues have already been
3218 * flushed. No more TXs on their way in mac80211's path, and no more in
3220 * Also, we won't be getting any new TX frames for this station.
3221 * What we might have are deferred TX frames that need to be taken care
3224 * Drop any still-queued deferred-frame before removing the STA, and
3225 * make sure the worker is no longer handling frames for this STA.
3227 if (old_state == IEEE80211_STA_NONE &&
3228 new_state == IEEE80211_STA_NOTEXIST) {
3229 flush_work(&mvm->add_stream_wk);
3232 * No need to make sure deferred TX indication is off since the
3233 * worker will already remove it if it was on
3237 mutex_lock(&mvm->mutex);
3238 /* track whether or not the station is associated */
3239 mvm_sta->sta_state = new_state;
3241 if (old_state == IEEE80211_STA_NOTEXIST &&
3242 new_state == IEEE80211_STA_NONE) {
3244 * Firmware bug - it'll crash if the beacon interval is less
3245 * than 16. We can't avoid connecting at all, so refuse the
3246 * station state change, this will cause mac80211 to abandon
3247 * attempts to connect to this AP, and eventually wpa_s will
3248 * blacklist the AP...
3250 if (vif->type == NL80211_IFTYPE_STATION &&
3251 vif->bss_conf.beacon_int < 16) {
3253 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3254 sta->addr, vif->bss_conf.beacon_int);
3261 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3262 IWL_MVM_TDLS_STA_COUNT ||
3263 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3264 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3269 ret = iwl_mvm_add_sta(mvm, vif, sta);
3270 if (sta->tdls && ret == 0) {
3271 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3272 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3273 NL80211_TDLS_SETUP);
3276 sta->max_rc_amsdu_len = 1;
3277 } else if (old_state == IEEE80211_STA_NONE &&
3278 new_state == IEEE80211_STA_AUTH) {
3280 * EBS may be disabled due to previous failures reported by FW.
3281 * Reset EBS status here assuming environment has been changed.
3283 mvm->last_ebs_successful = true;
3284 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3286 } else if (old_state == IEEE80211_STA_AUTH &&
3287 new_state == IEEE80211_STA_ASSOC) {
3288 if (vif->type == NL80211_IFTYPE_AP) {
3289 vif->bss_conf.he_support = sta->he_cap.has_he;
3290 mvmvif->ap_assoc_sta_count++;
3291 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3292 if (vif->bss_conf.he_support &&
3293 !iwlwifi_mod_params.disable_11ax)
3294 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3295 } else if (vif->type == NL80211_IFTYPE_STATION) {
3296 vif->bss_conf.he_support = sta->he_cap.has_he;
3297 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3300 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3302 ret = iwl_mvm_update_sta(mvm, vif, sta);
3303 } else if (old_state == IEEE80211_STA_ASSOC &&
3304 new_state == IEEE80211_STA_AUTHORIZED) {
3307 /* we don't support TDLS during DCM */
3308 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3309 iwl_mvm_teardown_tdls_peers(mvm);
3312 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3313 NL80211_TDLS_ENABLE_LINK);
3315 /* enable beacon filtering */
3316 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3318 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3320 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3321 new_state == IEEE80211_STA_ASSOC) {
3322 /* disable beacon filtering */
3323 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3325 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3328 } else if (old_state == IEEE80211_STA_ASSOC &&
3329 new_state == IEEE80211_STA_AUTH) {
3330 if (vif->type == NL80211_IFTYPE_AP) {
3331 mvmvif->ap_assoc_sta_count--;
3332 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3335 } else if (old_state == IEEE80211_STA_AUTH &&
3336 new_state == IEEE80211_STA_NONE) {
3338 } else if (old_state == IEEE80211_STA_NONE &&
3339 new_state == IEEE80211_STA_NOTEXIST) {
3340 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3342 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3343 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3344 NL80211_TDLS_DISABLE_LINK);
3348 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3355 mutex_unlock(&mvm->mutex);
3357 if (sta->tdls && ret == 0) {
3358 if (old_state == IEEE80211_STA_NOTEXIST &&
3359 new_state == IEEE80211_STA_NONE)
3360 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3361 else if (old_state == IEEE80211_STA_NONE &&
3362 new_state == IEEE80211_STA_NOTEXIST)
3363 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3369 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3371 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3373 mvm->rts_threshold = value;
3378 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3379 struct ieee80211_vif *vif,
3380 struct ieee80211_sta *sta, u32 changed)
3382 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3383 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3385 if (changed & (IEEE80211_RC_BW_CHANGED |
3386 IEEE80211_RC_SUPP_RATES_CHANGED |
3387 IEEE80211_RC_NSS_CHANGED))
3388 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3391 if (vif->type == NL80211_IFTYPE_STATION &&
3392 changed & IEEE80211_RC_NSS_CHANGED)
3393 iwl_mvm_sf_update(mvm, vif, false);
3396 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3397 struct ieee80211_vif *vif, u16 ac,
3398 const struct ieee80211_tx_queue_params *params)
3400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3401 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3403 mvmvif->queue_params[ac] = *params;
3406 * No need to update right away, we'll get BSS_CHANGED_QOS
3407 * The exception is P2P_DEVICE interface which needs immediate update.
3409 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3412 mutex_lock(&mvm->mutex);
3413 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3414 mutex_unlock(&mvm->mutex);
3420 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3421 struct ieee80211_vif *vif,
3424 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3425 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3426 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3429 * iwl_mvm_protect_session() reads directly from the device
3430 * (the system time), so make sure it is available.
3432 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3435 if (req_duration > duration)
3436 duration = req_duration;
3438 mutex_lock(&mvm->mutex);
3439 /* Try really hard to protect the session and hear a beacon */
3440 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3441 mutex_unlock(&mvm->mutex);
3443 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3446 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3447 struct ieee80211_vif *vif,
3448 struct cfg80211_sched_scan_request *req,
3449 struct ieee80211_scan_ies *ies)
3451 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3455 mutex_lock(&mvm->mutex);
3457 if (!vif->bss_conf.idle) {
3462 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3465 mutex_unlock(&mvm->mutex);
3469 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3470 struct ieee80211_vif *vif)
3472 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3475 mutex_lock(&mvm->mutex);
3477 /* Due to a race condition, it's possible that mac80211 asks
3478 * us to stop a sched_scan when it's already stopped. This
3479 * can happen, for instance, if we stopped the scan ourselves,
3480 * called ieee80211_sched_scan_stopped() and the userspace called
3481 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3482 * could run. To handle this, simply return if the scan is
3485 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3486 mutex_unlock(&mvm->mutex);
3490 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3491 mutex_unlock(&mvm->mutex);
3492 iwl_mvm_wait_for_async_handlers(mvm);
3497 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3498 enum set_key_cmd cmd,
3499 struct ieee80211_vif *vif,
3500 struct ieee80211_sta *sta,
3501 struct ieee80211_key_conf *key)
3503 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3504 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3505 struct iwl_mvm_sta *mvmsta;
3506 struct iwl_mvm_key_pn *ptk_pn;
3507 int keyidx = key->keyidx;
3511 if (iwlwifi_mod_params.swcrypto) {
3512 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3516 switch (key->cipher) {
3517 case WLAN_CIPHER_SUITE_TKIP:
3518 if (!mvm->trans->cfg->gen2) {
3519 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3520 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3521 } else if (vif->type == NL80211_IFTYPE_STATION) {
3522 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3524 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3528 case WLAN_CIPHER_SUITE_CCMP:
3529 case WLAN_CIPHER_SUITE_GCMP:
3530 case WLAN_CIPHER_SUITE_GCMP_256:
3531 if (!iwl_mvm_has_new_tx_api(mvm))
3532 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3534 case WLAN_CIPHER_SUITE_AES_CMAC:
3535 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3536 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3537 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3539 case WLAN_CIPHER_SUITE_WEP40:
3540 case WLAN_CIPHER_SUITE_WEP104:
3541 if (vif->type == NL80211_IFTYPE_STATION)
3543 if (iwl_mvm_has_new_tx_api(mvm))
3545 /* support HW crypto on TX */
3548 /* currently FW supports only one optional cipher scheme */
3549 if (hw->n_cipher_schemes &&
3550 hw->cipher_schemes->cipher == key->cipher)
3551 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3556 mutex_lock(&mvm->mutex);
3560 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3561 vif->type == NL80211_IFTYPE_AP) && !sta) {
3563 * GTK on AP interface is a TX-only key, return 0;
3564 * on IBSS they're per-station and because we're lazy
3565 * we don't support them for RX, so do the same.
3566 * CMAC/GMAC in AP/IBSS modes must be done in software.
3568 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3569 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3570 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3575 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3576 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3577 !iwl_mvm_has_new_tx_api(mvm)) {
3578 key->hw_key_idx = STA_KEY_IDX_INVALID;
3582 if (!mvmvif->ap_ibss_active) {
3584 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3586 if (!mvmvif->ap_early_keys[i]) {
3587 mvmvif->ap_early_keys[i] = key;
3592 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3599 /* During FW restart, in order to restore the state as it was,
3600 * don't try to reprogram keys we previously failed for.
3602 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3603 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3604 IWL_DEBUG_MAC80211(mvm,
3605 "skip invalid idx key programming during restart\n");
3610 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3611 sta && iwl_mvm_has_new_rx_api(mvm) &&
3612 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3613 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3614 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3615 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3616 struct ieee80211_key_seq seq;
3619 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3620 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3621 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3622 mvm->trans->num_rx_queues),
3629 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3630 ieee80211_get_key_rx_seq(key, tid, &seq);
3631 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3632 memcpy(ptk_pn->q[q].pn[tid],
3634 IEEE80211_CCMP_PN_LEN);
3637 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3640 /* in HW restart reuse the index, otherwise request a new one */
3641 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3642 key_offset = key->hw_key_idx;
3644 key_offset = STA_KEY_IDX_INVALID;
3646 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3647 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3649 IWL_WARN(mvm, "set key failed\n");
3650 key->hw_key_idx = STA_KEY_IDX_INVALID;
3652 * can't add key for RX, but we don't need it
3653 * in the device for TX so still return 0,
3654 * unless we have new TX API where we cannot
3655 * put key material into the TX_CMD
3657 if (iwl_mvm_has_new_tx_api(mvm))
3666 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3667 if (mvmvif->ap_early_keys[i] == key) {
3668 mvmvif->ap_early_keys[i] = NULL;
3673 /* found in pending list - don't do anything else */
3677 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3682 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3683 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3684 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3685 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3686 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3687 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3688 ptk_pn = rcu_dereference_protected(
3689 mvmsta->ptk_pn[keyidx],
3690 lockdep_is_held(&mvm->mutex));
3691 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3693 kfree_rcu(ptk_pn, rcu_head);
3696 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3697 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3703 mutex_unlock(&mvm->mutex);
3707 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3708 struct ieee80211_vif *vif,
3709 struct ieee80211_key_conf *keyconf,
3710 struct ieee80211_sta *sta,
3711 u32 iv32, u16 *phase1key)
3713 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3715 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3718 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3722 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3723 struct iwl_rx_packet *pkt, void *data)
3725 struct iwl_mvm *mvm =
3726 container_of(notif_wait, struct iwl_mvm, notif_wait);
3727 struct iwl_hs20_roc_res *resp;
3728 int resp_len = iwl_rx_packet_payload_len(pkt);
3729 struct iwl_mvm_time_event_data *te_data = data;
3731 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3734 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3735 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3739 resp = (void *)pkt->data;
3742 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3743 resp->status, resp->event_unique_id);
3745 te_data->uid = le32_to_cpu(resp->event_unique_id);
3746 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3749 spin_lock_bh(&mvm->time_event_lock);
3750 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3751 spin_unlock_bh(&mvm->time_event_lock);
3756 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3757 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3758 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3759 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3760 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3761 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3762 struct ieee80211_channel *channel,
3763 struct ieee80211_vif *vif,
3767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3768 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3769 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3770 struct iwl_notification_wait wait_time_event;
3771 u32 dtim_interval = vif->bss_conf.dtim_period *
3772 vif->bss_conf.beacon_int;
3774 struct iwl_hs20_roc_req aux_roc_req = {
3775 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3777 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3778 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3780 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3781 &aux_roc_req.channel_info);
3782 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3784 /* Set the channel info data */
3785 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3786 (channel->band == NL80211_BAND_2GHZ) ?
3787 PHY_BAND_24 : PHY_BAND_5,
3788 PHY_VHT_CHANNEL_MODE20,
3791 /* Set the time and duration */
3792 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3794 delay = AUX_ROC_MIN_DELAY;
3795 req_dur = MSEC_TO_TU(duration);
3798 * If we are associated we want the delay time to be at least one
3799 * dtim interval so that the FW can wait until after the DTIM and
3800 * then start the time event, this will potentially allow us to
3801 * remain off-channel for the max duration.
3802 * Since we want to use almost a whole dtim interval we would also
3803 * like the delay to be for 2-3 dtim intervals, in case there are
3804 * other time events with higher priority.
3806 if (vif->bss_conf.assoc) {
3807 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3808 /* We cannot remain off-channel longer than the DTIM interval */
3809 if (dtim_interval <= req_dur) {
3810 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3811 if (req_dur <= AUX_ROC_MIN_DURATION)
3812 req_dur = dtim_interval -
3813 AUX_ROC_MIN_SAFETY_BUFFER;
3817 tail->duration = cpu_to_le32(req_dur);
3818 tail->apply_time_max_delay = cpu_to_le32(delay);
3821 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3822 channel->hw_value, req_dur, duration, delay,
3824 /* Set the node address */
3825 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3827 lockdep_assert_held(&mvm->mutex);
3829 spin_lock_bh(&mvm->time_event_lock);
3831 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3832 spin_unlock_bh(&mvm->time_event_lock);
3837 te_data->duration = duration;
3838 te_data->id = HOT_SPOT_CMD;
3840 spin_unlock_bh(&mvm->time_event_lock);
3843 * Use a notification wait, which really just processes the
3844 * command response and doesn't wait for anything, in order
3845 * to be able to process the response and get the UID inside
3846 * the RX path. Using CMD_WANT_SKB doesn't work because it
3847 * stores the buffer and then wakes up this thread, by which
3848 * time another notification (that the time event started)
3849 * might already be processed unsuccessfully.
3851 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3852 time_event_response,
3853 ARRAY_SIZE(time_event_response),
3854 iwl_mvm_rx_aux_roc, te_data);
3856 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3860 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3861 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3865 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3866 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3867 /* should never fail */
3872 spin_lock_bh(&mvm->time_event_lock);
3873 iwl_mvm_te_clear_data(mvm, te_data);
3874 spin_unlock_bh(&mvm->time_event_lock);
3880 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3881 struct ieee80211_vif *vif,
3882 struct ieee80211_channel *channel,
3884 enum ieee80211_roc_type type)
3886 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3887 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3888 struct cfg80211_chan_def chandef;
3889 struct iwl_mvm_phy_ctxt *phy_ctxt;
3892 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3896 * Flush the done work, just in case it's still pending, so that
3897 * the work it does can complete and we can accept new frames.
3899 flush_work(&mvm->roc_done_wk);
3901 mutex_lock(&mvm->mutex);
3903 switch (vif->type) {
3904 case NL80211_IFTYPE_STATION:
3905 if (fw_has_capa(&mvm->fw->ucode_capa,
3906 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3907 /* Use aux roc framework (HS20) */
3908 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3912 IWL_ERR(mvm, "hotspot not supported\n");
3915 case NL80211_IFTYPE_P2P_DEVICE:
3919 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3924 for (i = 0; i < NUM_PHY_CTX; i++) {
3925 phy_ctxt = &mvm->phy_ctxts[i];
3926 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3929 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3931 * Unbind the P2P_DEVICE from the current PHY context,
3932 * and if the PHY context is not used remove it.
3934 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3935 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3938 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3940 /* Bind the P2P_DEVICE to the current PHY Context */
3941 mvmvif->phy_ctxt = phy_ctxt;
3943 ret = iwl_mvm_binding_add_vif(mvm, vif);
3944 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3947 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3948 goto schedule_time_event;
3952 /* Need to update the PHY context only if the ROC channel changed */
3953 if (channel == mvmvif->phy_ctxt->channel)
3954 goto schedule_time_event;
3956 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3959 * Change the PHY context configuration as it is currently referenced
3960 * only by the P2P Device MAC
3962 if (mvmvif->phy_ctxt->ref == 1) {
3963 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3969 * The PHY context is shared with other MACs. Need to remove the
3970 * P2P Device from the binding, allocate an new PHY context and
3971 * create a new binding
3973 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3979 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3982 IWL_ERR(mvm, "Failed to change PHY context\n");
3986 /* Unbind the P2P_DEVICE from the current PHY context */
3987 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3988 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3991 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3993 /* Bind the P2P_DEVICE to the new allocated PHY context */
3994 mvmvif->phy_ctxt = phy_ctxt;
3996 ret = iwl_mvm_binding_add_vif(mvm, vif);
3997 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
4000 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
4003 schedule_time_event:
4004 /* Schedule the time events */
4005 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
4008 mutex_unlock(&mvm->mutex);
4009 IWL_DEBUG_MAC80211(mvm, "leave\n");
4013 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
4015 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4017 IWL_DEBUG_MAC80211(mvm, "enter\n");
4019 mutex_lock(&mvm->mutex);
4020 iwl_mvm_stop_roc(mvm);
4021 mutex_unlock(&mvm->mutex);
4023 IWL_DEBUG_MAC80211(mvm, "leave\n");
4027 struct iwl_mvm_ftm_responder_iter_data {
4029 struct ieee80211_chanctx_conf *ctx;
4032 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4033 struct ieee80211_vif *vif)
4035 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4037 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
4038 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4039 data->responder = true;
4042 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4043 struct ieee80211_chanctx_conf *ctx)
4045 struct iwl_mvm_ftm_responder_iter_data data = {
4050 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4051 IEEE80211_IFACE_ITER_NORMAL,
4052 iwl_mvm_ftm_responder_chanctx_iter,
4054 return data.responder;
4057 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4058 struct ieee80211_chanctx_conf *ctx)
4060 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4061 struct iwl_mvm_phy_ctxt *phy_ctxt;
4062 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4063 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4066 lockdep_assert_held(&mvm->mutex);
4068 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4070 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4076 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4077 ctx->rx_chains_static,
4078 ctx->rx_chains_dynamic);
4080 IWL_ERR(mvm, "Failed to add PHY context\n");
4084 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4085 *phy_ctxt_id = phy_ctxt->id;
4090 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4091 struct ieee80211_chanctx_conf *ctx)
4093 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4096 mutex_lock(&mvm->mutex);
4097 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4098 mutex_unlock(&mvm->mutex);
4103 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4104 struct ieee80211_chanctx_conf *ctx)
4106 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4107 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4109 lockdep_assert_held(&mvm->mutex);
4111 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4114 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4115 struct ieee80211_chanctx_conf *ctx)
4117 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4119 mutex_lock(&mvm->mutex);
4120 __iwl_mvm_remove_chanctx(mvm, ctx);
4121 mutex_unlock(&mvm->mutex);
4124 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4125 struct ieee80211_chanctx_conf *ctx,
4128 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4129 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4130 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4131 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4132 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4134 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4135 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4136 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4137 IEEE80211_CHANCTX_CHANGE_RADAR |
4138 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4139 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4140 phy_ctxt->ref, changed))
4143 mutex_lock(&mvm->mutex);
4145 /* we are only changing the min_width, may be a noop */
4146 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4147 if (phy_ctxt->width == def->width)
4150 /* we are just toggling between 20_NOHT and 20 */
4151 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4152 def->width <= NL80211_CHAN_WIDTH_20)
4156 iwl_mvm_bt_coex_vif_change(mvm);
4157 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4158 ctx->rx_chains_static,
4159 ctx->rx_chains_dynamic);
4162 mutex_unlock(&mvm->mutex);
4165 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4166 struct ieee80211_vif *vif,
4167 struct ieee80211_chanctx_conf *ctx,
4168 bool switching_chanctx)
4170 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4171 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4172 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4175 lockdep_assert_held(&mvm->mutex);
4177 mvmvif->phy_ctxt = phy_ctxt;
4179 switch (vif->type) {
4180 case NL80211_IFTYPE_AP:
4181 /* only needed if we're switching chanctx (i.e. during CSA) */
4182 if (switching_chanctx) {
4183 mvmvif->ap_ibss_active = true;
4187 case NL80211_IFTYPE_ADHOC:
4189 * The AP binding flow is handled as part of the start_ap flow
4190 * (in bss_info_changed), similarly for IBSS.
4194 case NL80211_IFTYPE_STATION:
4195 mvmvif->csa_bcn_pending = false;
4197 case NL80211_IFTYPE_MONITOR:
4198 /* always disable PS when a monitor interface is active */
4199 mvmvif->ps_disabled = true;
4206 ret = iwl_mvm_binding_add_vif(mvm, vif);
4211 * Power state must be updated before quotas,
4212 * otherwise fw will complain.
4214 iwl_mvm_power_update_mac(mvm);
4216 /* Setting the quota at this stage is only required for monitor
4217 * interfaces. For the other types, the bss_info changed flow
4218 * will handle quota settings.
4220 if (vif->type == NL80211_IFTYPE_MONITOR) {
4221 mvmvif->monitor_active = true;
4222 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4224 goto out_remove_binding;
4226 ret = iwl_mvm_add_snif_sta(mvm, vif);
4228 goto out_remove_binding;
4232 /* Handle binding during CSA */
4233 if (vif->type == NL80211_IFTYPE_AP) {
4234 iwl_mvm_update_quotas(mvm, false, NULL);
4235 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4238 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4239 mvmvif->csa_bcn_pending = true;
4241 if (!fw_has_capa(&mvm->fw->ucode_capa,
4242 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4243 u32 duration = 3 * vif->bss_conf.beacon_int;
4246 /* iwl_mvm_protect_session() reads directly from the
4247 * device (the system time), so make sure it is
4250 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
4252 goto out_remove_binding;
4254 /* Protect the session to make sure we hear the first
4255 * beacon on the new channel.
4257 iwl_mvm_protect_session(mvm, vif, duration, duration,
4258 vif->bss_conf.beacon_int / 2,
4261 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
4264 iwl_mvm_update_quotas(mvm, false, NULL);
4270 iwl_mvm_binding_remove_vif(mvm, vif);
4271 iwl_mvm_power_update_mac(mvm);
4274 mvmvif->phy_ctxt = NULL;
4277 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4278 struct ieee80211_vif *vif,
4279 struct ieee80211_chanctx_conf *ctx)
4281 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4284 mutex_lock(&mvm->mutex);
4285 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4286 mutex_unlock(&mvm->mutex);
4291 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4292 struct ieee80211_vif *vif,
4293 struct ieee80211_chanctx_conf *ctx,
4294 bool switching_chanctx)
4296 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4297 struct ieee80211_vif *disabled_vif = NULL;
4299 lockdep_assert_held(&mvm->mutex);
4301 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4303 switch (vif->type) {
4304 case NL80211_IFTYPE_ADHOC:
4306 case NL80211_IFTYPE_MONITOR:
4307 mvmvif->monitor_active = false;
4308 mvmvif->ps_disabled = false;
4309 iwl_mvm_rm_snif_sta(mvm, vif);
4311 case NL80211_IFTYPE_AP:
4312 /* This part is triggered only during CSA */
4313 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4316 mvmvif->csa_countdown = false;
4318 /* Set CS bit on all the stations */
4319 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4321 /* Save blocked iface, the timeout is set on the next beacon */
4322 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4324 mvmvif->ap_ibss_active = false;
4326 case NL80211_IFTYPE_STATION:
4327 if (!switching_chanctx)
4332 if (!fw_has_capa(&mvm->fw->ucode_capa,
4333 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4334 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4340 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4341 iwl_mvm_binding_remove_vif(mvm, vif);
4344 mvmvif->phy_ctxt = NULL;
4345 iwl_mvm_power_update_mac(mvm);
4348 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4349 struct ieee80211_vif *vif,
4350 struct ieee80211_chanctx_conf *ctx)
4352 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4354 mutex_lock(&mvm->mutex);
4355 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4356 mutex_unlock(&mvm->mutex);
4360 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4361 struct ieee80211_vif_chanctx_switch *vifs)
4365 mutex_lock(&mvm->mutex);
4366 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4367 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4369 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4371 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4375 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4379 "failed to assign new_ctx during channel switch\n");
4383 /* we don't support TDLS during DCM - can be caused by channel switch */
4384 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4385 iwl_mvm_teardown_tdls_peers(mvm);
4390 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4393 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4394 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4398 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4400 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4407 /* things keep failing, better restart the hw */
4408 iwl_mvm_nic_restart(mvm, false);
4411 mutex_unlock(&mvm->mutex);
4417 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4418 struct ieee80211_vif_chanctx_switch *vifs)
4422 mutex_lock(&mvm->mutex);
4423 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4425 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4429 "failed to assign new_ctx during channel switch\n");
4436 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4438 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4445 /* things keep failing, better restart the hw */
4446 iwl_mvm_nic_restart(mvm, false);
4449 mutex_unlock(&mvm->mutex);
4454 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4455 struct ieee80211_vif_chanctx_switch *vifs,
4457 enum ieee80211_chanctx_switch_mode mode)
4459 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4462 /* we only support a single-vif right now */
4467 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4468 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4470 case CHANCTX_SWMODE_REASSIGN_VIF:
4471 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4481 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4483 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4485 return mvm->ibss_manager;
4488 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4489 struct ieee80211_sta *sta,
4492 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4493 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4495 if (!mvm_sta || !mvm_sta->vif) {
4496 IWL_ERR(mvm, "Station is not associated to a vif\n");
4500 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4503 #ifdef CONFIG_NL80211_TESTMODE
4504 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4505 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4506 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4507 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4510 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4511 struct ieee80211_vif *vif,
4512 void *data, int len)
4514 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4518 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4519 iwl_mvm_tm_policy, NULL);
4523 if (!tb[IWL_MVM_TM_ATTR_CMD])
4526 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4527 case IWL_MVM_TM_CMD_SET_NOA:
4528 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4529 !vif->bss_conf.enable_beacon ||
4530 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4533 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4534 if (noa_duration >= vif->bss_conf.beacon_int)
4537 mvm->noa_duration = noa_duration;
4540 return iwl_mvm_update_quotas(mvm, true, NULL);
4541 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4542 /* must be associated client vif - ignore authorized */
4543 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4544 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4545 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4548 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4549 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4550 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4556 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4557 struct ieee80211_vif *vif,
4558 void *data, int len)
4560 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4563 mutex_lock(&mvm->mutex);
4564 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4565 mutex_unlock(&mvm->mutex);
4571 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4572 struct ieee80211_vif *vif,
4573 struct ieee80211_channel_switch *chsw)
4575 /* By implementing this operation, we prevent mac80211 from
4576 * starting its own channel switch timer, so that we can call
4577 * ieee80211_chswitch_done() ourselves at the right time
4578 * (which is when the absence time event starts).
4581 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4582 "dummy channel switch op\n");
4585 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4586 struct ieee80211_vif *vif,
4587 struct ieee80211_channel_switch *chsw)
4589 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4590 struct iwl_chan_switch_te_cmd cmd = {
4591 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4593 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4594 .tsf = cpu_to_le32(chsw->timestamp),
4595 .cs_count = chsw->count,
4596 .cs_mode = chsw->block_tx,
4599 lockdep_assert_held(&mvm->mutex);
4602 cmd.cs_delayed_bcn_count =
4603 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4605 return iwl_mvm_send_cmd_pdu(mvm,
4606 WIDE_ID(MAC_CONF_GROUP,
4607 CHANNEL_SWITCH_TIME_EVENT_CMD),
4608 0, sizeof(cmd), &cmd);
4611 #define IWL_MAX_CSA_BLOCK_TX 1500
4612 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4613 struct ieee80211_vif *vif,
4614 struct ieee80211_channel_switch *chsw)
4616 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4617 struct ieee80211_vif *csa_vif;
4618 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4622 mutex_lock(&mvm->mutex);
4624 mvmvif->csa_failed = false;
4626 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4627 chsw->chandef.center_freq1);
4629 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4630 ieee80211_vif_to_wdev(vif),
4631 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4633 switch (vif->type) {
4634 case NL80211_IFTYPE_AP:
4636 rcu_dereference_protected(mvm->csa_vif,
4637 lockdep_is_held(&mvm->mutex));
4638 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4639 "Another CSA is already in progress")) {
4644 /* we still didn't unblock tx. prevent new CS meanwhile */
4645 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4646 lockdep_is_held(&mvm->mutex))) {
4651 rcu_assign_pointer(mvm->csa_vif, vif);
4653 if (WARN_ONCE(mvmvif->csa_countdown,
4654 "Previous CSA countdown didn't complete")) {
4659 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4662 case NL80211_IFTYPE_STATION:
4663 /* Schedule the time event to a bit before beacon 1,
4664 * to make sure we're in the new channel when the
4665 * GO/AP arrives. In case count <= 1 immediately schedule the
4666 * TE (this might result with some packet loss or connection
4669 if (chsw->count <= 1)
4672 apply_time = chsw->device_timestamp +
4673 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4674 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4676 if (chsw->block_tx) {
4677 iwl_mvm_csa_client_absent(mvm, vif);
4679 * In case of undetermined / long time with immediate
4680 * quiet monitor status to gracefully disconnect
4683 chsw->count * vif->bss_conf.beacon_int >
4684 IWL_MAX_CSA_BLOCK_TX)
4685 schedule_delayed_work(&mvmvif->csa_work,
4686 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4689 if (mvmvif->bf_data.bf_enabled) {
4690 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4695 if (fw_has_capa(&mvm->fw->ucode_capa,
4696 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4697 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4699 iwl_mvm_schedule_csa_period(mvm, vif,
4700 vif->bss_conf.beacon_int,
4703 mvmvif->csa_count = chsw->count;
4704 mvmvif->csa_misbehave = false;
4710 mvmvif->ps_disabled = true;
4712 ret = iwl_mvm_power_update_ps(mvm);
4716 /* we won't be on this channel any longer */
4717 iwl_mvm_teardown_tdls_peers(mvm);
4720 mutex_unlock(&mvm->mutex);
4725 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4726 struct ieee80211_vif *vif,
4727 struct ieee80211_channel_switch *chsw)
4729 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4730 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4731 struct iwl_chan_switch_te_cmd cmd = {
4732 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4734 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4735 .tsf = cpu_to_le32(chsw->timestamp),
4736 .cs_count = chsw->count,
4737 .cs_mode = chsw->block_tx,
4740 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4743 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4744 if (mvmvif->csa_misbehave) {
4745 /* Second time, give up on this AP*/
4746 iwl_mvm_abort_channel_switch(hw, vif);
4747 ieee80211_chswitch_done(vif, false);
4748 mvmvif->csa_misbehave = false;
4751 mvmvif->csa_misbehave = true;
4753 mvmvif->csa_count = chsw->count;
4755 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id);
4757 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4758 WIDE_ID(MAC_CONF_GROUP,
4759 CHANNEL_SWITCH_TIME_EVENT_CMD),
4760 CMD_ASYNC, sizeof(cmd), &cmd));
4763 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4767 if (!iwl_mvm_has_new_tx_api(mvm)) {
4769 mutex_lock(&mvm->mutex);
4770 iwl_mvm_flush_tx_path(mvm,
4771 iwl_mvm_flushable_queues(mvm) & queues, 0);
4772 mutex_unlock(&mvm->mutex);
4774 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4779 mutex_lock(&mvm->mutex);
4780 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4781 struct ieee80211_sta *sta;
4783 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4784 lockdep_is_held(&mvm->mutex));
4785 if (IS_ERR_OR_NULL(sta))
4789 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4791 iwl_mvm_wait_sta_queues_empty(mvm,
4792 iwl_mvm_sta_from_mac80211(sta));
4794 mutex_unlock(&mvm->mutex);
4797 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4798 struct ieee80211_vif *vif, u32 queues, bool drop)
4800 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4801 struct iwl_mvm_vif *mvmvif;
4802 struct iwl_mvm_sta *mvmsta;
4803 struct ieee80211_sta *sta;
4808 iwl_mvm_flush_no_vif(mvm, queues, drop);
4812 if (vif->type != NL80211_IFTYPE_STATION)
4815 /* Make sure we're done with the deferred traffic before flushing */
4816 flush_work(&mvm->add_stream_wk);
4818 mutex_lock(&mvm->mutex);
4819 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4821 /* flush the AP-station and all TDLS peers */
4822 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4823 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4824 lockdep_is_held(&mvm->mutex));
4825 if (IS_ERR_OR_NULL(sta))
4828 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4829 if (mvmsta->vif != vif)
4832 /* make sure only TDLS peers or the AP are flushed */
4833 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4836 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4837 IWL_ERR(mvm, "flush request fail\n");
4839 msk |= mvmsta->tfd_queue_msk;
4840 if (iwl_mvm_has_new_tx_api(mvm))
4841 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4845 mutex_unlock(&mvm->mutex);
4847 /* this can take a while, and we may need/want other operations
4848 * to succeed while doing this, so do it without the mutex held
4850 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4851 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4854 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4855 struct survey_info *survey)
4857 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4860 memset(survey, 0, sizeof(*survey));
4862 /* only support global statistics right now */
4866 if (!fw_has_capa(&mvm->fw->ucode_capa,
4867 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4870 mutex_lock(&mvm->mutex);
4872 if (iwl_mvm_firmware_running(mvm)) {
4873 ret = iwl_mvm_request_statistics(mvm, false);
4878 survey->filled = SURVEY_INFO_TIME |
4879 SURVEY_INFO_TIME_RX |
4880 SURVEY_INFO_TIME_TX |
4881 SURVEY_INFO_TIME_SCAN;
4882 survey->time = mvm->accu_radio_stats.on_time_rf +
4883 mvm->radio_stats.on_time_rf;
4884 do_div(survey->time, USEC_PER_MSEC);
4886 survey->time_rx = mvm->accu_radio_stats.rx_time +
4887 mvm->radio_stats.rx_time;
4888 do_div(survey->time_rx, USEC_PER_MSEC);
4890 survey->time_tx = mvm->accu_radio_stats.tx_time +
4891 mvm->radio_stats.tx_time;
4892 do_div(survey->time_tx, USEC_PER_MSEC);
4894 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4895 mvm->radio_stats.on_time_scan;
4896 do_div(survey->time_scan, USEC_PER_MSEC);
4900 mutex_unlock(&mvm->mutex);
4904 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4905 struct ieee80211_vif *vif,
4906 struct ieee80211_sta *sta,
4907 struct station_info *sinfo)
4909 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4910 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4911 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4913 if (mvmsta->avg_energy) {
4914 sinfo->signal_avg = mvmsta->avg_energy;
4915 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4918 /* if beacon filtering isn't on mac80211 does it anyway */
4919 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4922 if (!vif->bss_conf.assoc)
4925 mutex_lock(&mvm->mutex);
4927 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4930 if (iwl_mvm_request_statistics(mvm, false))
4933 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4934 mvmvif->beacon_stats.accu_num_beacons;
4935 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4936 if (mvmvif->beacon_stats.avg_signal) {
4937 /* firmware only reports a value after RXing a few beacons */
4938 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4939 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4942 mutex_unlock(&mvm->mutex);
4945 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4946 struct ieee80211_vif *vif,
4947 const struct ieee80211_event *event)
4949 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4951 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4953 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4956 struct iwl_fw_dbg_trigger_tlv *trig;
4957 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4959 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4960 FW_DBG_TRIGGER_MLME);
4964 trig_mlme = (void *)trig->data;
4966 if (event->u.mlme.data == ASSOC_EVENT) {
4967 if (event->u.mlme.status == MLME_DENIED)
4968 CHECK_MLME_TRIGGER(stop_assoc_denied,
4969 "DENIED ASSOC: reason %d",
4970 event->u.mlme.reason);
4971 else if (event->u.mlme.status == MLME_TIMEOUT)
4972 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4974 } else if (event->u.mlme.data == AUTH_EVENT) {
4975 if (event->u.mlme.status == MLME_DENIED)
4976 CHECK_MLME_TRIGGER(stop_auth_denied,
4977 "DENIED AUTH: reason %d",
4978 event->u.mlme.reason);
4979 else if (event->u.mlme.status == MLME_TIMEOUT)
4980 CHECK_MLME_TRIGGER(stop_auth_timeout,
4982 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4983 CHECK_MLME_TRIGGER(stop_rx_deauth,
4984 "DEAUTH RX %d", event->u.mlme.reason);
4985 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4986 CHECK_MLME_TRIGGER(stop_tx_deauth,
4987 "DEAUTH TX %d", event->u.mlme.reason);
4989 #undef CHECK_MLME_TRIGGER
4992 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4993 struct ieee80211_vif *vif,
4994 const struct ieee80211_event *event)
4996 struct iwl_fw_dbg_trigger_tlv *trig;
4997 struct iwl_fw_dbg_trigger_ba *ba_trig;
4999 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5004 ba_trig = (void *)trig->data;
5006 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5009 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5010 "BAR received from %pM, tid %d, ssn %d",
5011 event->u.ba.sta->addr, event->u.ba.tid,
5015 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5016 struct ieee80211_vif *vif,
5017 const struct ieee80211_event *event)
5019 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5021 switch (event->type) {
5023 iwl_mvm_event_mlme_callback(mvm, vif, event);
5026 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5028 case BA_FRAME_TIMEOUT:
5029 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5037 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5038 struct iwl_mvm_internal_rxq_notif *notif,
5041 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
5044 lockdep_assert_held(&mvm->mutex);
5046 if (!iwl_mvm_has_new_rx_api(mvm))
5049 notif->cookie = mvm->queue_sync_cookie;
5052 atomic_set(&mvm->queue_sync_counter,
5053 mvm->trans->num_rx_queues);
5055 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
5057 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5062 ret = wait_event_timeout(mvm->rx_sync_waitq,
5063 atomic_read(&mvm->queue_sync_counter) == 0 ||
5064 iwl_mvm_is_radio_killed(mvm),
5066 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
5070 atomic_set(&mvm->queue_sync_counter, 0);
5071 mvm->queue_sync_cookie++;
5074 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5076 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5077 struct iwl_mvm_internal_rxq_notif data = {
5078 .type = IWL_MVM_RXQ_EMPTY,
5082 mutex_lock(&mvm->mutex);
5083 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
5084 mutex_unlock(&mvm->mutex);
5088 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5089 struct ieee80211_vif *vif,
5090 struct cfg80211_ftm_responder_stats *stats)
5092 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5093 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5095 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5096 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5099 mutex_lock(&mvm->mutex);
5100 *stats = mvm->ftm_resp_stats;
5101 mutex_unlock(&mvm->mutex);
5103 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5104 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5105 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5106 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5107 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5108 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5109 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5110 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5111 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5116 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5117 struct ieee80211_vif *vif,
5118 struct cfg80211_pmsr_request *request)
5120 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5123 mutex_lock(&mvm->mutex);
5124 ret = iwl_mvm_ftm_start(mvm, vif, request);
5125 mutex_unlock(&mvm->mutex);
5130 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5131 struct ieee80211_vif *vif,
5132 struct cfg80211_pmsr_request *request)
5134 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5136 mutex_lock(&mvm->mutex);
5137 iwl_mvm_ftm_abort(mvm, request);
5138 mutex_unlock(&mvm->mutex);
5141 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5143 u8 protocol = ip_hdr(skb)->protocol;
5145 if (!IS_ENABLED(CONFIG_INET))
5148 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5151 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5152 struct sk_buff *head,
5153 struct sk_buff *skb)
5155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5157 /* For now don't aggregate IPv6 in AMSDU */
5158 if (skb->protocol != htons(ETH_P_IP))
5161 if (!iwl_mvm_is_csum_supported(mvm))
5164 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5167 const struct ieee80211_ops iwl_mvm_hw_ops = {
5168 .tx = iwl_mvm_mac_tx,
5169 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5170 .ampdu_action = iwl_mvm_mac_ampdu_action,
5171 .start = iwl_mvm_mac_start,
5172 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5173 .stop = iwl_mvm_mac_stop,
5174 .add_interface = iwl_mvm_mac_add_interface,
5175 .remove_interface = iwl_mvm_mac_remove_interface,
5176 .config = iwl_mvm_mac_config,
5177 .prepare_multicast = iwl_mvm_prepare_multicast,
5178 .configure_filter = iwl_mvm_configure_filter,
5179 .config_iface_filter = iwl_mvm_config_iface_filter,
5180 .bss_info_changed = iwl_mvm_bss_info_changed,
5181 .hw_scan = iwl_mvm_mac_hw_scan,
5182 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5183 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5184 .sta_state = iwl_mvm_mac_sta_state,
5185 .sta_notify = iwl_mvm_mac_sta_notify,
5186 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5187 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5188 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5189 .sta_rc_update = iwl_mvm_sta_rc_update,
5190 .conf_tx = iwl_mvm_mac_conf_tx,
5191 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5192 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5193 .flush = iwl_mvm_mac_flush,
5194 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5195 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5196 .set_key = iwl_mvm_mac_set_key,
5197 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5198 .remain_on_channel = iwl_mvm_roc,
5199 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5200 .add_chanctx = iwl_mvm_add_chanctx,
5201 .remove_chanctx = iwl_mvm_remove_chanctx,
5202 .change_chanctx = iwl_mvm_change_chanctx,
5203 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5204 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5205 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5207 .start_ap = iwl_mvm_start_ap_ibss,
5208 .stop_ap = iwl_mvm_stop_ap_ibss,
5209 .join_ibss = iwl_mvm_start_ap_ibss,
5210 .leave_ibss = iwl_mvm_stop_ap_ibss,
5212 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5214 .set_tim = iwl_mvm_set_tim,
5216 .channel_switch = iwl_mvm_channel_switch,
5217 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5218 .post_channel_switch = iwl_mvm_post_channel_switch,
5219 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5220 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5222 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5223 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5224 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5226 .event_callback = iwl_mvm_mac_event_callback,
5228 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5230 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5232 #ifdef CONFIG_PM_SLEEP
5234 .suspend = iwl_mvm_suspend,
5235 .resume = iwl_mvm_resume,
5236 .set_wakeup = iwl_mvm_set_wakeup,
5237 .set_rekey_data = iwl_mvm_set_rekey_data,
5238 #if IS_ENABLED(CONFIG_IPV6)
5239 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5241 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5243 .get_survey = iwl_mvm_mac_get_survey,
5244 .sta_statistics = iwl_mvm_mac_sta_statistics,
5245 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5246 .start_pmsr = iwl_mvm_start_pmsr,
5247 .abort_pmsr = iwl_mvm_abort_pmsr,
5249 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5250 #ifdef CONFIG_IWLWIFI_DEBUGFS
5251 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,