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 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 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
27 * The full GNU General Public License is included in this distribution
28 * in the file called COPYING.
30 * Contact Information:
31 * Intel Linux Wireless <linuxwifi@intel.com>
32 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * Copyright(c) 2018 Intel Corporation
40 * All rights reserved.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
46 * * Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * * Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in
50 * the documentation and/or other materials provided with the
52 * * Neither the name Intel Corporation nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 *****************************************************************************/
69 #include <linux/kernel.h>
70 #include <linux/slab.h>
71 #include <linux/skbuff.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
75 #include <linux/if_arp.h>
76 #include <linux/time.h>
77 #include <net/mac80211.h>
78 #include <net/ieee80211_radiotap.h>
81 #include "iwl-op-mode.h"
85 #include "time-event.h"
86 #include "iwl-eeprom-parse.h"
87 #include "iwl-phy-db.h"
89 #include "fw/error-dump.h"
91 #include "iwl-nvm-parse.h"
93 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
96 .types = BIT(NL80211_IFTYPE_STATION),
100 .types = BIT(NL80211_IFTYPE_AP) |
101 BIT(NL80211_IFTYPE_P2P_CLIENT) |
102 BIT(NL80211_IFTYPE_P2P_GO),
106 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
110 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
112 .num_different_channels = 2,
114 .limits = iwl_mvm_limits,
115 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
119 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
121 * Use the reserved field to indicate magic values.
122 * these values will only be used internally by the driver,
123 * and won't make it to the fw (reserved will be 0).
124 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
125 * be the vif's ip address. in case there is not a single
126 * ip address (0, or more than 1), this attribute will
128 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
129 * the LSB bytes of the vif's mac address
132 BC_FILTER_MAGIC_NONE = 0,
137 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
141 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
144 /* frame type - arp, hw type - ethernet */
146 BCAST_FILTER_OFFSET_PAYLOAD_START,
147 .offset = sizeof(rfc1042_header),
148 .val = cpu_to_be32(0x08060001),
149 .mask = cpu_to_be32(0xffffffff),
154 BCAST_FILTER_OFFSET_PAYLOAD_START,
155 .offset = sizeof(rfc1042_header) + 2 +
156 sizeof(struct arphdr) +
157 ETH_ALEN + sizeof(__be32) +
159 .mask = cpu_to_be32(0xffffffff),
160 /* mark it as special field */
161 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
166 /* dhcp offer bcast */
168 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
171 /* udp dest port - 68 (bootp client)*/
172 .offset_type = BCAST_FILTER_OFFSET_IP_END,
173 .offset = offsetof(struct udphdr, dest),
174 .val = cpu_to_be32(0x00440000),
175 .mask = cpu_to_be32(0xffff0000),
178 /* dhcp - lsb bytes of client hw address */
179 .offset_type = BCAST_FILTER_OFFSET_IP_END,
181 .mask = cpu_to_be32(0xffffffff),
182 /* mark it as special field */
183 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
187 /* last filter must be empty */
192 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
194 if (!iwl_mvm_is_d0i3_supported(mvm))
197 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
198 spin_lock_bh(&mvm->refs_lock);
199 mvm->refs[ref_type]++;
200 spin_unlock_bh(&mvm->refs_lock);
201 iwl_trans_ref(mvm->trans);
204 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
206 if (!iwl_mvm_is_d0i3_supported(mvm))
209 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
210 spin_lock_bh(&mvm->refs_lock);
211 if (WARN_ON(!mvm->refs[ref_type])) {
212 spin_unlock_bh(&mvm->refs_lock);
215 mvm->refs[ref_type]--;
216 spin_unlock_bh(&mvm->refs_lock);
217 iwl_trans_unref(mvm->trans);
220 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
221 enum iwl_mvm_ref_type except_ref)
225 if (!iwl_mvm_is_d0i3_supported(mvm))
228 spin_lock_bh(&mvm->refs_lock);
229 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
230 if (except_ref == i || !mvm->refs[i])
233 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
235 for (j = 0; j < mvm->refs[i]; j++)
236 iwl_trans_unref(mvm->trans);
239 spin_unlock_bh(&mvm->refs_lock);
242 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
247 if (!iwl_mvm_is_d0i3_supported(mvm))
250 spin_lock_bh(&mvm->refs_lock);
251 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
257 spin_unlock_bh(&mvm->refs_lock);
262 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
264 iwl_mvm_ref(mvm, ref_type);
266 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
267 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
270 iwl_mvm_unref(mvm, ref_type);
277 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
281 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
282 for (i = 0; i < NUM_PHY_CTX; i++) {
283 mvm->phy_ctxts[i].id = i;
284 mvm->phy_ctxts[i].ref = 0;
288 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
290 enum iwl_mcc_source src_id,
293 struct ieee80211_regdomain *regd = NULL;
294 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
295 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
296 struct iwl_mcc_update_resp *resp;
298 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
300 lockdep_assert_held(&mvm->mutex);
302 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
303 if (IS_ERR_OR_NULL(resp)) {
304 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
305 PTR_ERR_OR_ZERO(resp));
310 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
312 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
313 __le32_to_cpu(resp->n_channels),
315 __le16_to_cpu(resp->mcc),
316 __le16_to_cpu(resp->geo_info));
317 /* Store the return source id */
318 src_id = resp->source_id;
320 if (IS_ERR_OR_NULL(regd)) {
321 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
322 PTR_ERR_OR_ZERO(regd));
326 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
327 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
328 mvm->lar_regdom_set = true;
329 mvm->mcc_src = src_id;
335 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
338 struct ieee80211_regdomain *regd;
340 if (!iwl_mvm_is_lar_supported(mvm))
343 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
344 if (!IS_ERR_OR_NULL(regd)) {
345 /* only update the regulatory core if changed */
347 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
353 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
356 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
357 iwl_mvm_is_wifi_mcc_supported(mvm) ?
358 MCC_SOURCE_GET_CURRENT :
359 MCC_SOURCE_OLD_FW, changed);
362 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
364 enum iwl_mcc_source used_src;
365 struct ieee80211_regdomain *regd;
368 const struct ieee80211_regdomain *r =
369 rtnl_dereference(mvm->hw->wiphy->regd);
374 /* save the last source in case we overwrite it below */
375 used_src = mvm->mcc_src;
376 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
377 /* Notify the firmware we support wifi location updates */
378 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
379 if (!IS_ERR_OR_NULL(regd))
383 /* Now set our last stored MCC and source */
384 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
386 if (IS_ERR_OR_NULL(regd))
389 /* update cfg80211 if the regdomain was changed */
391 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
399 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
401 struct ieee80211_hw *hw = mvm->hw;
403 static const u32 mvm_ciphers[] = {
404 WLAN_CIPHER_SUITE_WEP40,
405 WLAN_CIPHER_SUITE_WEP104,
406 WLAN_CIPHER_SUITE_TKIP,
407 WLAN_CIPHER_SUITE_CCMP,
410 /* Tell mac80211 our characteristics */
411 ieee80211_hw_set(hw, SIGNAL_DBM);
412 ieee80211_hw_set(hw, SPECTRUM_MGMT);
413 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
414 ieee80211_hw_set(hw, QUEUE_CONTROL);
415 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
416 ieee80211_hw_set(hw, SUPPORTS_PS);
417 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
418 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
419 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
420 ieee80211_hw_set(hw, CONNECTION_MONITOR);
421 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
422 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
423 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
424 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
425 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
426 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
428 if (iwl_mvm_has_tlc_offload(mvm)) {
429 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
430 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
433 if (iwl_mvm_has_new_rx_api(mvm))
434 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
436 if (fw_has_capa(&mvm->fw->ucode_capa,
437 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
438 ieee80211_hw_set(hw, AP_LINK_PS);
439 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
441 * we absolutely need this for the new TX API since that comes
442 * with many more queues than the current code can deal with
443 * for station powersave
448 if (mvm->trans->num_rx_queues > 1)
449 ieee80211_hw_set(hw, USES_RSS);
451 if (mvm->trans->max_skb_frags)
452 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
454 hw->queues = IEEE80211_MAX_QUEUES;
455 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
456 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
457 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
458 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
459 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
461 hw->radiotap_timestamp.units_pos =
462 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
463 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
464 /* this is the case for CCK frames, it's better (only 8) for OFDM */
465 hw->radiotap_timestamp.accuracy = 22;
467 if (!iwl_mvm_has_tlc_offload(mvm))
468 hw->rate_control_algorithm = RS_NAME;
470 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
471 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
473 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
474 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
475 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
476 hw->wiphy->cipher_suites = mvm->ciphers;
478 if (iwl_mvm_has_new_rx_api(mvm)) {
479 mvm->ciphers[hw->wiphy->n_cipher_suites] =
480 WLAN_CIPHER_SUITE_GCMP;
481 hw->wiphy->n_cipher_suites++;
482 mvm->ciphers[hw->wiphy->n_cipher_suites] =
483 WLAN_CIPHER_SUITE_GCMP_256;
484 hw->wiphy->n_cipher_suites++;
487 /* Enable 11w if software crypto is not enabled (as the
488 * firmware will interpret some mgmt packets, so enabling it
489 * with software crypto isn't safe).
491 if (!iwlwifi_mod_params.swcrypto) {
492 ieee80211_hw_set(hw, MFP_CAPABLE);
493 mvm->ciphers[hw->wiphy->n_cipher_suites] =
494 WLAN_CIPHER_SUITE_AES_CMAC;
495 hw->wiphy->n_cipher_suites++;
496 if (iwl_mvm_has_new_rx_api(mvm)) {
497 mvm->ciphers[hw->wiphy->n_cipher_suites] =
498 WLAN_CIPHER_SUITE_BIP_GMAC_128;
499 hw->wiphy->n_cipher_suites++;
500 mvm->ciphers[hw->wiphy->n_cipher_suites] =
501 WLAN_CIPHER_SUITE_BIP_GMAC_256;
502 hw->wiphy->n_cipher_suites++;
506 /* currently FW API supports only one optional cipher scheme */
507 if (mvm->fw->cs[0].cipher) {
508 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
509 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
511 mvm->hw->n_cipher_schemes = 1;
513 cs->cipher = le32_to_cpu(fwcs->cipher);
514 cs->iftype = BIT(NL80211_IFTYPE_STATION);
515 cs->hdr_len = fwcs->hdr_len;
516 cs->pn_len = fwcs->pn_len;
517 cs->pn_off = fwcs->pn_off;
518 cs->key_idx_off = fwcs->key_idx_off;
519 cs->key_idx_mask = fwcs->key_idx_mask;
520 cs->key_idx_shift = fwcs->key_idx_shift;
521 cs->mic_len = fwcs->mic_len;
523 mvm->hw->cipher_schemes = mvm->cs;
524 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
525 hw->wiphy->n_cipher_suites++;
528 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
529 hw->wiphy->features |=
530 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
531 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
532 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
534 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
535 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
536 hw->chanctx_data_size = sizeof(u16);
538 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
539 BIT(NL80211_IFTYPE_P2P_CLIENT) |
540 BIT(NL80211_IFTYPE_AP) |
541 BIT(NL80211_IFTYPE_P2P_GO) |
542 BIT(NL80211_IFTYPE_P2P_DEVICE) |
543 BIT(NL80211_IFTYPE_ADHOC);
545 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
546 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
547 if (iwl_mvm_is_lar_supported(mvm))
548 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
550 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
551 REGULATORY_DISABLE_BEACON_HINTS;
553 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
554 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
556 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
557 hw->wiphy->n_iface_combinations =
558 ARRAY_SIZE(iwl_mvm_iface_combinations);
560 hw->wiphy->max_remain_on_channel_duration = 10000;
561 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
562 /* we can compensate an offset of up to 3 channels = 15 MHz */
563 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
565 /* Extract MAC address */
566 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
567 hw->wiphy->addresses = mvm->addresses;
568 hw->wiphy->n_addresses = 1;
570 /* Extract additional MAC addresses if available */
571 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
572 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
574 for (i = 1; i < num_mac; i++) {
575 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
577 mvm->addresses[i].addr[5]++;
578 hw->wiphy->n_addresses++;
581 iwl_mvm_reset_phy_ctxts(mvm);
583 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
585 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
587 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
588 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
589 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
591 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
592 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
594 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
596 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
597 hw->wiphy->bands[NL80211_BAND_2GHZ] =
598 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
599 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
600 hw->wiphy->bands[NL80211_BAND_5GHZ] =
601 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
603 if (fw_has_capa(&mvm->fw->ucode_capa,
604 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
605 fw_has_api(&mvm->fw->ucode_capa,
606 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
607 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
608 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
611 hw->wiphy->hw_version = mvm->trans->hw_id;
613 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
614 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
616 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
618 hw->wiphy->max_sched_scan_reqs = 1;
619 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
620 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
621 /* we create the 802.11 header and zero length SSID IE. */
622 hw->wiphy->max_sched_scan_ie_len =
623 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
624 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
625 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
628 * the firmware uses u8 for num of iterations, but 0xff is saved for
629 * infinite loop, so the maximum number of iterations is actually 254.
631 hw->wiphy->max_sched_scan_plan_iterations = 254;
633 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
634 NL80211_FEATURE_LOW_PRIORITY_SCAN |
635 NL80211_FEATURE_P2P_GO_OPPPS |
636 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
637 NL80211_FEATURE_DYNAMIC_SMPS |
638 NL80211_FEATURE_STATIC_SMPS |
639 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
643 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
644 if (fw_has_capa(&mvm->fw->ucode_capa,
645 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
646 hw->wiphy->features |= NL80211_FEATURE_QUIET;
648 if (fw_has_capa(&mvm->fw->ucode_capa,
649 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
650 hw->wiphy->features |=
651 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
653 if (fw_has_capa(&mvm->fw->ucode_capa,
654 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
655 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
657 if (fw_has_api(&mvm->fw->ucode_capa,
658 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
659 wiphy_ext_feature_set(hw->wiphy,
660 NL80211_EXT_FEATURE_SCAN_START_TIME);
661 wiphy_ext_feature_set(hw->wiphy,
662 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
663 wiphy_ext_feature_set(hw->wiphy,
664 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
667 if (iwl_mvm_is_oce_supported(mvm)) {
668 wiphy_ext_feature_set(hw->wiphy,
669 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
670 wiphy_ext_feature_set(hw->wiphy,
671 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
672 wiphy_ext_feature_set(hw->wiphy,
673 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
674 wiphy_ext_feature_set(hw->wiphy,
675 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
678 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
680 #ifdef CONFIG_PM_SLEEP
681 if (iwl_mvm_is_d0i3_supported(mvm) &&
682 device_can_wakeup(mvm->trans->dev)) {
683 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
684 hw->wiphy->wowlan = &mvm->wowlan;
687 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
688 mvm->trans->ops->d3_suspend &&
689 mvm->trans->ops->d3_resume &&
690 device_can_wakeup(mvm->trans->dev)) {
691 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
692 WIPHY_WOWLAN_DISCONNECT |
693 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
694 WIPHY_WOWLAN_RFKILL_RELEASE |
695 WIPHY_WOWLAN_NET_DETECT;
696 if (!iwlwifi_mod_params.swcrypto)
697 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
698 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
699 WIPHY_WOWLAN_4WAY_HANDSHAKE;
701 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
702 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
703 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
704 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
705 hw->wiphy->wowlan = &mvm->wowlan;
709 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
710 /* assign default bcast filtering configuration */
711 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
714 ret = iwl_mvm_leds_init(mvm);
718 if (fw_has_capa(&mvm->fw->ucode_capa,
719 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
720 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
721 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
722 ieee80211_hw_set(hw, TDLS_WIDER_BW);
725 if (fw_has_capa(&mvm->fw->ucode_capa,
726 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
727 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
728 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
731 hw->netdev_features |= mvm->cfg->features;
732 if (!iwl_mvm_is_csum_supported(mvm)) {
733 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
735 /* We may support SW TX CSUM */
736 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
737 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
740 ret = ieee80211_register_hw(mvm->hw);
742 iwl_mvm_leds_exit(mvm);
743 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
745 if (mvm->cfg->vht_mu_mimo_supported)
746 wiphy_ext_feature_set(hw->wiphy,
747 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
752 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
753 struct ieee80211_sta *sta,
756 struct iwl_mvm_sta *mvmsta;
760 * double check the IN_D0I3 flag both before and after
761 * taking the spinlock, in order to prevent taking
762 * the spinlock when not needed.
764 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
767 spin_lock(&mvm->d0i3_tx_lock);
769 * testing the flag again ensures the skb dequeue
770 * loop (on d0i3 exit) hasn't run yet.
772 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
775 mvmsta = iwl_mvm_sta_from_mac80211(sta);
776 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
777 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
780 __skb_queue_tail(&mvm->d0i3_tx, skb);
781 ieee80211_stop_queues(mvm->hw);
784 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
785 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
789 spin_unlock(&mvm->d0i3_tx_lock);
793 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
794 struct ieee80211_tx_control *control,
797 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
798 struct ieee80211_sta *sta = control->sta;
799 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
800 struct ieee80211_hdr *hdr = (void *)skb->data;
802 if (iwl_mvm_is_radio_killed(mvm)) {
803 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
807 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
808 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
809 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
812 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
813 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
814 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
815 ieee80211_is_mgmt(hdr->frame_control) &&
816 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
820 if (iwl_mvm_defer_tx(mvm, sta, skb))
822 if (iwl_mvm_tx_skb(mvm, skb, sta))
827 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
831 ieee80211_free_txskb(hw, skb);
834 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
836 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
841 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
843 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
845 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
848 /* enabled by default */
852 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
854 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
856 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
860 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
861 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
862 enum ieee80211_ampdu_mlme_action action)
864 struct iwl_fw_dbg_trigger_tlv *trig;
865 struct iwl_fw_dbg_trigger_ba *ba_trig;
867 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
870 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
871 ba_trig = (void *)trig->data;
873 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
874 ieee80211_vif_to_wdev(vif), trig))
878 case IEEE80211_AMPDU_TX_OPERATIONAL: {
879 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
880 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
882 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
883 "TX AGG START: MAC %pM tid %d ssn %d\n",
884 sta->addr, tid, tid_data->ssn);
887 case IEEE80211_AMPDU_TX_STOP_CONT:
888 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
889 "TX AGG STOP: MAC %pM tid %d\n",
892 case IEEE80211_AMPDU_RX_START:
893 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
894 "RX AGG START: MAC %pM tid %d ssn %d\n",
895 sta->addr, tid, rx_ba_ssn);
897 case IEEE80211_AMPDU_RX_STOP:
898 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
899 "RX AGG STOP: MAC %pM tid %d\n",
907 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
908 struct ieee80211_vif *vif,
909 struct ieee80211_ampdu_params *params)
911 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
913 bool tx_agg_ref = false;
914 struct ieee80211_sta *sta = params->sta;
915 enum ieee80211_ampdu_mlme_action action = params->action;
916 u16 tid = params->tid;
917 u16 *ssn = ¶ms->ssn;
918 u16 buf_size = params->buf_size;
919 bool amsdu = params->amsdu;
920 u16 timeout = params->timeout;
922 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
923 sta->addr, tid, action);
925 if (!(mvm->nvm_data->sku_cap_11n_enable))
928 /* return from D0i3 before starting a new Tx aggregation */
930 case IEEE80211_AMPDU_TX_START:
931 case IEEE80211_AMPDU_TX_STOP_CONT:
932 case IEEE80211_AMPDU_TX_STOP_FLUSH:
933 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
934 case IEEE80211_AMPDU_TX_OPERATIONAL:
936 * for tx start, wait synchronously until D0i3 exit to
937 * get the correct sequence number for the tid.
938 * additionally, some other ampdu actions use direct
939 * target access, which is not handled automatically
940 * by the trans layer (unlike commands), so wait for
941 * d0i3 exit in these cases as well.
943 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
953 mutex_lock(&mvm->mutex);
956 case IEEE80211_AMPDU_RX_START:
957 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
958 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
959 struct iwl_mvm_vif *mvmvif;
960 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
961 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
963 mdata->opened_rx_ba_sessions = true;
964 mvmvif = iwl_mvm_vif_from_mac80211(vif);
965 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
967 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
971 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
974 case IEEE80211_AMPDU_RX_STOP:
975 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
978 case IEEE80211_AMPDU_TX_START:
979 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
983 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
985 case IEEE80211_AMPDU_TX_STOP_CONT:
986 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
988 case IEEE80211_AMPDU_TX_STOP_FLUSH:
989 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
990 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
992 case IEEE80211_AMPDU_TX_OPERATIONAL:
993 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1005 if (action == IEEE80211_AMPDU_RX_START)
1008 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1011 mutex_unlock(&mvm->mutex);
1014 * If the tid is marked as started, we won't use it for offloaded
1015 * traffic on the next D0i3 entry. It's safe to unref.
1018 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1023 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1024 struct ieee80211_vif *vif)
1026 struct iwl_mvm *mvm = data;
1027 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1029 mvmvif->uploaded = false;
1030 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1032 spin_lock_bh(&mvm->time_event_lock);
1033 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1034 spin_unlock_bh(&mvm->time_event_lock);
1036 mvmvif->phy_ctxt = NULL;
1037 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1040 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1042 /* clear the D3 reconfig, we only need it to avoid dumping a
1043 * firmware coredump on reconfiguration, we shouldn't do that
1044 * on D3->D0 transition
1046 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1047 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1048 iwl_fw_error_dump(&mvm->fwrt);
1051 /* cleanup all stale references (scan, roc), but keep the
1052 * ucode_down ref until reconfig is complete
1054 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1056 iwl_mvm_stop_device(mvm);
1058 mvm->scan_status = 0;
1059 mvm->ps_disabled = false;
1060 mvm->calibrating = false;
1062 /* just in case one was running */
1063 iwl_mvm_cleanup_roc_te(mvm);
1064 ieee80211_remain_on_channel_expired(mvm->hw);
1067 * cleanup all interfaces, even inactive ones, as some might have
1068 * gone down during the HW restart
1070 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1072 mvm->p2p_device_vif = NULL;
1073 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1075 iwl_mvm_reset_phy_ctxts(mvm);
1076 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1077 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1078 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1079 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1081 ieee80211_wake_queues(mvm->hw);
1083 /* clear any stale d0i3 state */
1084 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1087 mvm->rx_ba_sessions = 0;
1088 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1089 mvm->monitor_on = false;
1091 /* keep statistics ticking */
1092 iwl_mvm_accu_radio_stats(mvm);
1095 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1099 lockdep_assert_held(&mvm->mutex);
1101 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1103 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1104 * so later code will - from now on - see that we're doing it.
1106 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1107 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1108 /* Clean up some internal and mac80211 state on restart */
1109 iwl_mvm_restart_cleanup(mvm);
1111 /* Hold the reference to prevent runtime suspend while
1112 * the start procedure runs. It's a bit confusing
1113 * that the UCODE_DOWN reference is taken, but it just
1114 * means "UCODE is not UP yet". ( TODO: rename this
1117 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1119 ret = iwl_mvm_up(mvm);
1121 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1122 /* Something went wrong - we need to finish some cleanup
1123 * that normally iwl_mvm_mac_restart_complete() below
1126 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1127 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1133 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1135 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1138 /* Some hw restart cleanups must not hold the mutex */
1139 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1141 * Make sure we are out of d0i3. This is needed
1142 * to make sure the reference accounting is correct
1143 * (and there is no stale d0i3_exit_work).
1145 wait_event_timeout(mvm->d0i3_exit_waitq,
1146 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1151 mutex_lock(&mvm->mutex);
1152 ret = __iwl_mvm_mac_start(mvm);
1153 mutex_unlock(&mvm->mutex);
1158 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1162 mutex_lock(&mvm->mutex);
1164 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1165 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1166 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1168 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1171 /* allow transport/FW low power modes */
1172 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1175 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1176 * of packets the FW sent out, so we must reconnect.
1178 iwl_mvm_teardown_tdls_peers(mvm);
1180 mutex_unlock(&mvm->mutex);
1183 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1185 if (iwl_mvm_is_d0i3_supported(mvm) &&
1186 iwl_mvm_enter_d0i3_on_suspend(mvm))
1187 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1188 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1191 "D0i3 exit on resume timed out\n");
1195 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1196 enum ieee80211_reconfig_type reconfig_type)
1198 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1200 switch (reconfig_type) {
1201 case IEEE80211_RECONFIG_TYPE_RESTART:
1202 iwl_mvm_restart_complete(mvm);
1204 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1205 iwl_mvm_resume_complete(mvm);
1210 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1212 lockdep_assert_held(&mvm->mutex);
1214 /* firmware counters are obviously reset now, but we shouldn't
1215 * partially track so also clear the fw_reset_accu counters.
1217 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1219 /* async_handlers_wk is now blocked */
1222 * The work item could be running or queued if the
1223 * ROC time event stops just as we get here.
1225 flush_work(&mvm->roc_done_wk);
1227 iwl_mvm_stop_device(mvm);
1229 iwl_mvm_async_handlers_purge(mvm);
1230 /* async_handlers_list is empty and will stay empty: HW is stopped */
1232 /* the fw is stopped, the aux sta is dead: clean up driver state */
1233 iwl_mvm_del_aux_sta(mvm);
1236 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1237 * hw (as restart_complete() won't be called in this case) and mac80211
1238 * won't execute the restart.
1239 * But make sure to cleanup interfaces that have gone down before/during
1240 * HW restart was requested.
1242 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1243 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1245 ieee80211_iterate_interfaces(mvm->hw, 0,
1246 iwl_mvm_cleanup_iterator, mvm);
1248 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1249 * make sure there's nothing left there and warn if any is found.
1251 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1254 for (i = 0; i < mvm->max_scans; i++) {
1255 if (WARN_ONCE(mvm->scan_uid_status[i],
1256 "UMAC scan UID %d status was not cleaned\n",
1258 mvm->scan_uid_status[i] = 0;
1263 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1265 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1267 flush_work(&mvm->d0i3_exit_work);
1268 flush_work(&mvm->async_handlers_wk);
1269 flush_work(&mvm->add_stream_wk);
1272 * Lock and clear the firmware running bit here already, so that
1273 * new commands coming in elsewhere, e.g. from debugfs, will not
1274 * be able to proceed. This is important here because one of those
1275 * debugfs files causes the firmware dump to be triggered, and if we
1276 * don't stop debugfs accesses before canceling that it could be
1277 * retriggered after we flush it but before we've cleared the bit.
1279 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1281 iwl_fw_cancel_dump(&mvm->fwrt);
1282 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1283 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1284 iwl_fw_free_dump_desc(&mvm->fwrt);
1286 mutex_lock(&mvm->mutex);
1287 __iwl_mvm_mac_stop(mvm);
1288 mutex_unlock(&mvm->mutex);
1291 * The worker might have been waiting for the mutex, let it run and
1292 * discover that its list is now empty.
1294 cancel_work_sync(&mvm->async_handlers_wk);
1297 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1301 lockdep_assert_held(&mvm->mutex);
1303 for (i = 0; i < NUM_PHY_CTX; i++)
1304 if (!mvm->phy_ctxts[i].ref)
1305 return &mvm->phy_ctxts[i];
1307 IWL_ERR(mvm, "No available PHY context\n");
1311 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1314 struct iwl_dev_tx_power_cmd cmd = {
1315 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1316 .v3.mac_context_id =
1317 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1318 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1320 int len = sizeof(cmd);
1322 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1323 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1325 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1326 len = sizeof(cmd.v3);
1328 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1331 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1332 struct ieee80211_vif *vif)
1334 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1335 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1341 * make sure D0i3 exit is completed, otherwise a target access
1342 * during tx queue configuration could be done when still in
1345 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1350 * Not much to do here. The stack will not allow interface
1351 * types or combinations that we didn't advertise, so we
1352 * don't really have to check the types.
1355 mutex_lock(&mvm->mutex);
1357 /* make sure that beacon statistics don't go backwards with FW reset */
1358 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1359 mvmvif->beacon_stats.accu_num_beacons +=
1360 mvmvif->beacon_stats.num_beacons;
1362 /* Allocate resources for the MAC context, and add it to the fw */
1363 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1367 /* Counting number of interfaces is needed for legacy PM */
1368 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1372 * The AP binding flow can be done only after the beacon
1373 * template is configured (which happens only in the mac80211
1374 * start_ap() flow), and adding the broadcast station can happen
1375 * only after the binding.
1376 * In addition, since modifying the MAC before adding a bcast
1377 * station is not allowed by the FW, delay the adding of MAC context to
1378 * the point where we can also add the bcast station.
1379 * In short: there's not much we can do at this point, other than
1380 * allocating resources :)
1382 if (vif->type == NL80211_IFTYPE_AP ||
1383 vif->type == NL80211_IFTYPE_ADHOC) {
1384 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1386 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1391 * Only queue for this station is the mcast queue,
1392 * which shouldn't be in TFD mask anyway
1394 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1400 iwl_mvm_vif_dbgfs_register(mvm, vif);
1404 mvmvif->features |= hw->netdev_features;
1406 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1410 ret = iwl_mvm_power_update_mac(mvm);
1412 goto out_remove_mac;
1414 /* beacon filtering */
1415 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1417 goto out_remove_mac;
1419 if (!mvm->bf_allowed_vif &&
1420 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1421 mvm->bf_allowed_vif = mvmvif;
1422 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1423 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1427 * P2P_DEVICE interface does not have a channel context assigned to it,
1428 * so a dedicated PHY context is allocated to it and the corresponding
1429 * MAC context is bound to it at this stage.
1431 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1433 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1434 if (!mvmvif->phy_ctxt) {
1439 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1440 ret = iwl_mvm_binding_add_vif(mvm, vif);
1444 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1448 /* Save a pointer to p2p device vif, so it can later be used to
1449 * update the p2p device MAC when a GO is started/stopped */
1450 mvm->p2p_device_vif = vif;
1453 iwl_mvm_tcm_add_vif(mvm, vif);
1455 if (vif->type == NL80211_IFTYPE_MONITOR)
1456 mvm->monitor_on = true;
1458 iwl_mvm_vif_dbgfs_register(mvm, vif);
1462 iwl_mvm_binding_remove_vif(mvm, vif);
1464 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1466 if (mvm->bf_allowed_vif == mvmvif) {
1467 mvm->bf_allowed_vif = NULL;
1468 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1469 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1472 mvmvif->phy_ctxt = NULL;
1473 iwl_mvm_mac_ctxt_remove(mvm, vif);
1475 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1478 mutex_unlock(&mvm->mutex);
1480 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1485 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1486 struct ieee80211_vif *vif)
1488 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1490 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1491 * We assume here that all the packets sent to the OFFCHANNEL
1492 * queue are sent in ROC session.
1494 flush_work(&mvm->roc_done_wk);
1498 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1499 struct ieee80211_vif *vif)
1501 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1502 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1504 iwl_mvm_prepare_mac_removal(mvm, vif);
1506 if (!(vif->type == NL80211_IFTYPE_AP ||
1507 vif->type == NL80211_IFTYPE_ADHOC))
1508 iwl_mvm_tcm_rm_vif(mvm, vif);
1510 mutex_lock(&mvm->mutex);
1512 if (mvm->bf_allowed_vif == mvmvif) {
1513 mvm->bf_allowed_vif = NULL;
1514 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1515 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1518 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1521 * For AP/GO interface, the tear down of the resources allocated to the
1522 * interface is be handled as part of the stop_ap flow.
1524 if (vif->type == NL80211_IFTYPE_AP ||
1525 vif->type == NL80211_IFTYPE_ADHOC) {
1526 #ifdef CONFIG_NL80211_TESTMODE
1527 if (vif == mvm->noa_vif) {
1528 mvm->noa_vif = NULL;
1529 mvm->noa_duration = 0;
1532 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1533 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1537 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1538 mvm->p2p_device_vif = NULL;
1539 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1540 iwl_mvm_binding_remove_vif(mvm, vif);
1541 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1542 mvmvif->phy_ctxt = NULL;
1545 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1548 iwl_mvm_power_update_mac(mvm);
1549 iwl_mvm_mac_ctxt_remove(mvm, vif);
1551 if (vif->type == NL80211_IFTYPE_MONITOR)
1552 mvm->monitor_on = false;
1555 mutex_unlock(&mvm->mutex);
1558 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1563 struct iwl_mvm_mc_iter_data {
1564 struct iwl_mvm *mvm;
1568 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1569 struct ieee80211_vif *vif)
1571 struct iwl_mvm_mc_iter_data *data = _data;
1572 struct iwl_mvm *mvm = data->mvm;
1573 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1574 struct iwl_host_cmd hcmd = {
1575 .id = MCAST_FILTER_CMD,
1577 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1581 /* if we don't have free ports, mcast frames will be dropped */
1582 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1585 if (vif->type != NL80211_IFTYPE_STATION ||
1586 !vif->bss_conf.assoc)
1589 cmd->port_id = data->port_id++;
1590 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1591 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1596 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1598 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1601 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1603 struct iwl_mvm_mc_iter_data iter_data = {
1607 lockdep_assert_held(&mvm->mutex);
1609 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1612 ieee80211_iterate_active_interfaces_atomic(
1613 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1614 iwl_mvm_mc_iface_iterator, &iter_data);
1617 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1618 struct netdev_hw_addr_list *mc_list)
1620 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1621 struct iwl_mcast_filter_cmd *cmd;
1622 struct netdev_hw_addr *addr;
1627 addr_count = netdev_hw_addr_list_count(mc_list);
1628 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1629 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1633 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1634 cmd = kzalloc(len, GFP_ATOMIC);
1640 return (u64)(unsigned long)cmd;
1643 netdev_hw_addr_list_for_each(addr, mc_list) {
1644 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1645 cmd->count, addr->addr);
1646 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1647 addr->addr, ETH_ALEN);
1651 return (u64)(unsigned long)cmd;
1654 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1655 unsigned int changed_flags,
1656 unsigned int *total_flags,
1659 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1660 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1662 mutex_lock(&mvm->mutex);
1664 /* replace previous configuration */
1665 kfree(mvm->mcast_filter_cmd);
1666 mvm->mcast_filter_cmd = cmd;
1671 if (changed_flags & FIF_ALLMULTI)
1672 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1677 iwl_mvm_recalc_multicast(mvm);
1679 mutex_unlock(&mvm->mutex);
1683 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1684 struct ieee80211_vif *vif,
1685 unsigned int filter_flags,
1686 unsigned int changed_flags)
1688 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1690 /* We support only filter for probe requests */
1691 if (!(changed_flags & FIF_PROBE_REQ))
1694 /* Supported only for p2p client interfaces */
1695 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1699 mutex_lock(&mvm->mutex);
1700 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1701 mutex_unlock(&mvm->mutex);
1704 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1705 struct iwl_bcast_iter_data {
1706 struct iwl_mvm *mvm;
1707 struct iwl_bcast_filter_cmd *cmd;
1712 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1713 const struct iwl_fw_bcast_filter *in_filter,
1714 struct iwl_fw_bcast_filter *out_filter)
1716 struct iwl_fw_bcast_filter_attr *attr;
1719 memcpy(out_filter, in_filter, sizeof(*out_filter));
1721 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1722 attr = &out_filter->attrs[i];
1727 switch (attr->reserved1) {
1728 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1729 if (vif->bss_conf.arp_addr_cnt != 1) {
1734 attr->val = vif->bss_conf.arp_addr_list[0];
1736 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1737 attr->val = *(__be32 *)&vif->addr[2];
1742 attr->reserved1 = 0;
1743 out_filter->num_attrs++;
1747 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1748 struct ieee80211_vif *vif)
1750 struct iwl_bcast_iter_data *data = _data;
1751 struct iwl_mvm *mvm = data->mvm;
1752 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1753 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1754 struct iwl_fw_bcast_mac *bcast_mac;
1757 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1760 bcast_mac = &cmd->macs[mvmvif->id];
1763 * enable filtering only for associated stations, but not for P2P
1766 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1767 !vif->bss_conf.assoc)
1770 bcast_mac->default_discard = 1;
1772 /* copy all configured filters */
1773 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1775 * Make sure we don't exceed our filters limit.
1776 * if there is still a valid filter to be configured,
1777 * be on the safe side and just allow bcast for this mac.
1779 if (WARN_ON_ONCE(data->current_filter >=
1780 ARRAY_SIZE(cmd->filters))) {
1781 bcast_mac->default_discard = 0;
1782 bcast_mac->attached_filters = 0;
1786 iwl_mvm_set_bcast_filter(vif,
1787 &mvm->bcast_filters[i],
1788 &cmd->filters[data->current_filter]);
1790 /* skip current filter if it contains no attributes */
1791 if (!cmd->filters[data->current_filter].num_attrs)
1794 /* attach the filter to current mac */
1795 bcast_mac->attached_filters |=
1796 cpu_to_le16(BIT(data->current_filter));
1798 data->current_filter++;
1802 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1803 struct iwl_bcast_filter_cmd *cmd)
1805 struct iwl_bcast_iter_data iter_data = {
1810 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1813 memset(cmd, 0, sizeof(*cmd));
1814 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1815 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1817 #ifdef CONFIG_IWLWIFI_DEBUGFS
1818 /* use debugfs filters/macs if override is configured */
1819 if (mvm->dbgfs_bcast_filtering.override) {
1820 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1821 sizeof(cmd->filters));
1822 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1828 /* if no filters are configured, do nothing */
1829 if (!mvm->bcast_filters)
1832 /* configure and attach these filters for each associated sta vif */
1833 ieee80211_iterate_active_interfaces(
1834 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1835 iwl_mvm_bcast_filter_iterator, &iter_data);
1840 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1842 struct iwl_bcast_filter_cmd cmd;
1844 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1847 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1850 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1854 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1860 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1861 struct ieee80211_vif *vif)
1863 struct iwl_mu_group_mgmt_cmd cmd = {};
1865 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1866 WLAN_MEMBERSHIP_LEN);
1867 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1868 WLAN_USER_POSITION_LEN);
1870 return iwl_mvm_send_cmd_pdu(mvm,
1871 WIDE_ID(DATA_PATH_GROUP,
1872 UPDATE_MU_GROUPS_CMD),
1873 0, sizeof(cmd), &cmd);
1876 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1877 struct ieee80211_vif *vif)
1879 if (vif->mu_mimo_owner) {
1880 struct iwl_mu_group_mgmt_notif *notif = _data;
1883 * MU-MIMO Group Id action frame is little endian. We treat
1884 * the data received from firmware as if it came from the
1885 * action frame, so no conversion is needed.
1887 ieee80211_update_mu_groups(vif,
1888 (u8 *)¬if->membership_status,
1889 (u8 *)¬if->user_position);
1893 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1894 struct iwl_rx_cmd_buffer *rxb)
1896 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1897 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1899 ieee80211_iterate_active_interfaces_atomic(
1900 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1901 iwl_mvm_mu_mimo_iface_iterator, notif);
1904 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1906 u8 byte_num = ppe_pos_bit / 8;
1907 u8 bit_num = ppe_pos_bit % 8;
1912 return (ppe[byte_num] >> bit_num) &
1913 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1916 * If bit_num > 5, we have to combine bits with next byte.
1917 * Calculate how many bits we need to take from current byte (called
1918 * here "residue_bits"), and add them to bits from next byte.
1921 residue_bits = 8 - bit_num;
1923 res = (ppe[byte_num + 1] &
1924 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1926 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1931 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1932 struct ieee80211_vif *vif, u8 sta_id)
1934 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1935 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1937 .tid_limit = IWL_MAX_TID_COUNT,
1938 .bss_color = vif->bss_conf.bss_color,
1939 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1940 .frame_time_rts_th =
1941 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1943 struct ieee80211_sta *sta;
1949 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1952 WARN(1, "Can't find STA to configure HE\n");
1956 if (!sta->he_cap.has_he) {
1964 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1965 IEEE80211_HE_MAC_CAP0_HTC_HE)
1966 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1967 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1968 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1969 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1970 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
1972 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
1973 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
1974 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
1975 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
1978 sta_ctxt_cmd.htc_flags |=
1979 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
1980 else if (link_adap == 3)
1981 sta_ctxt_cmd.htc_flags |=
1982 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
1984 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1985 IEEE80211_HE_MAC_CAP2_UL_MU_RESP_SCHED)
1986 sta_ctxt_cmd.htc_flags |=
1987 cpu_to_le32(IWL_HE_HTC_UL_MU_RESP_SCHED);
1988 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
1989 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
1990 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
1991 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
1992 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
1993 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
1994 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
1996 /* If PPE Thresholds exist, parse them into a FW-familiar format */
1997 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
1998 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
1999 u8 nss = (sta->he_cap.ppe_thres[0] &
2000 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2001 u8 ru_index_bitmap =
2002 (sta->he_cap.ppe_thres[0] &
2003 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2004 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2005 u8 *ppe = &sta->he_cap.ppe_thres[0];
2006 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2009 * FW currently supports only nss == MAX_HE_SUPP_NSS
2011 * If nss > MAX: we can ignore values we don't support
2012 * If nss < MAX: we can set zeros in other streams
2014 if (nss > MAX_HE_SUPP_NSS) {
2015 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2017 nss = MAX_HE_SUPP_NSS;
2020 for (i = 0; i < nss; i++) {
2021 u8 ru_index_tmp = ru_index_bitmap << 1;
2024 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2026 if (!(ru_index_tmp & 1))
2029 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2030 iwl_mvm_he_get_ppe_val(ppe,
2033 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2034 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2035 iwl_mvm_he_get_ppe_val(ppe,
2038 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2042 flags |= STA_CTXT_HE_PACKET_EXT;
2046 /* Mark MU EDCA as enabled, unless none detected on some AC */
2047 flags |= STA_CTXT_HE_MU_EDCA_CW;
2048 for (i = 0; i < AC_NUM; i++) {
2049 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2050 &mvmvif->queue_params[i].mu_edca_param_rec;
2052 if (!mvmvif->queue_params[i].mu_edca) {
2053 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2057 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2058 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2059 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2060 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2061 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2062 cpu_to_le16(mu_edca->aifsn);
2063 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2064 cpu_to_le16(mu_edca->mu_edca_timer);
2067 if (vif->bss_conf.multi_sta_back_32bit)
2068 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2070 if (vif->bss_conf.ack_enabled)
2071 flags |= STA_CTXT_HE_ACK_ENABLED;
2073 if (vif->bss_conf.uora_exists) {
2074 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2076 sta_ctxt_cmd.rand_alloc_ecwmin =
2077 vif->bss_conf.uora_ocw_range & 0x7;
2078 sta_ctxt_cmd.rand_alloc_ecwmax =
2079 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2082 /* TODO: support Multi BSSID IE */
2084 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2086 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2087 DATA_PATH_GROUP, 0),
2088 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2089 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2092 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2093 struct ieee80211_vif *vif,
2094 struct ieee80211_bss_conf *bss_conf,
2097 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2101 * Re-calculate the tsf id, as the master-slave relations depend on the
2102 * beacon interval, which was not known when the station interface was
2105 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2106 if (vif->bss_conf.he_support &&
2107 !iwlwifi_mod_params.disable_11ax)
2108 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2110 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2114 * If we're not associated yet, take the (new) BSSID before associating
2115 * so the firmware knows. If we're already associated, then use the old
2116 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2117 * branch for disassociation below.
2119 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2120 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2122 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2124 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2126 /* after sending it once, adopt mac80211 data */
2127 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2128 mvmvif->associated = bss_conf->assoc;
2130 if (changes & BSS_CHANGED_ASSOC) {
2131 if (bss_conf->assoc) {
2132 /* clear statistics to get clean beacon counter */
2133 iwl_mvm_request_statistics(mvm, true);
2134 memset(&mvmvif->beacon_stats, 0,
2135 sizeof(mvmvif->beacon_stats));
2137 /* add quota for this interface */
2138 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2140 IWL_ERR(mvm, "failed to update quotas\n");
2144 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2147 * If we're restarting then the firmware will
2148 * obviously have lost synchronisation with
2149 * the AP. It will attempt to synchronise by
2150 * itself, but we can make it more reliable by
2151 * scheduling a session protection time event.
2153 * The firmware needs to receive a beacon to
2154 * catch up with synchronisation, use 110% of
2155 * the beacon interval.
2157 * Set a large maximum delay to allow for more
2158 * than a single interface.
2160 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2161 iwl_mvm_protect_session(mvm, vif, dur, dur,
2165 iwl_mvm_sf_update(mvm, vif, false);
2166 iwl_mvm_power_vif_assoc(mvm, vif);
2168 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2169 iwl_mvm_update_smps(mvm, vif,
2170 IWL_MVM_SMPS_REQ_PROT,
2171 IEEE80211_SMPS_DYNAMIC);
2173 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2175 * If update fails - SF might be running in associated
2176 * mode while disassociated - which is forbidden.
2178 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2179 "Failed to update SF upon disassociation\n");
2182 * If we get an assert during the connection (after the
2183 * station has been added, but before the vif is set
2184 * to associated), mac80211 will re-add the station and
2185 * then configure the vif. Since the vif is not
2186 * associated, we would remove the station here and
2187 * this would fail the recovery.
2189 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2192 * Remove AP station now that
2193 * the MAC is unassoc
2195 ret = iwl_mvm_rm_sta_id(mvm, vif,
2199 "failed to remove AP station\n");
2201 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2202 mvm->d0i3_ap_sta_id =
2203 IWL_MVM_INVALID_STA;
2204 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2207 /* remove quota for this interface */
2208 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2210 IWL_ERR(mvm, "failed to update quotas\n");
2213 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2215 /* this will take the cleared BSSID from bss_conf */
2216 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2219 "failed to update MAC %pM (clear after unassoc)\n",
2224 * The firmware tracks the MU-MIMO group on its own.
2225 * However, on HW restart we should restore this data.
2227 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2228 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2229 ret = iwl_mvm_update_mu_groups(mvm, vif);
2232 "failed to update VHT MU_MIMO groups\n");
2235 iwl_mvm_recalc_multicast(mvm);
2236 iwl_mvm_configure_bcast_filter(mvm);
2238 /* reset rssi values */
2239 mvmvif->bf_data.ave_beacon_signal = 0;
2241 iwl_mvm_bt_coex_vif_change(mvm);
2242 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2243 IEEE80211_SMPS_AUTOMATIC);
2244 if (fw_has_capa(&mvm->fw->ucode_capa,
2245 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2246 iwl_mvm_config_scan(mvm);
2249 if (changes & BSS_CHANGED_BEACON_INFO) {
2251 * We received a beacon from the associated AP so
2252 * remove the session protection.
2254 iwl_mvm_stop_session_protection(mvm, vif);
2256 iwl_mvm_sf_update(mvm, vif, false);
2257 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2260 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2262 * Send power command on every beacon change,
2263 * because we may have not enabled beacon abort yet.
2265 BSS_CHANGED_BEACON_INFO)) {
2266 ret = iwl_mvm_power_update_mac(mvm);
2268 IWL_ERR(mvm, "failed to update power mode\n");
2271 if (changes & BSS_CHANGED_TXPOWER) {
2272 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2274 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2277 if (changes & BSS_CHANGED_CQM) {
2278 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2279 /* reset cqm events tracking */
2280 mvmvif->bf_data.last_cqm_event = 0;
2281 if (mvmvif->bf_data.bf_enabled) {
2282 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2285 "failed to update CQM thresholds\n");
2289 if (changes & BSS_CHANGED_ARP_FILTER) {
2290 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2291 iwl_mvm_configure_bcast_filter(mvm);
2295 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2296 struct ieee80211_vif *vif)
2298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2299 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2303 * iwl_mvm_mac_ctxt_add() might read directly from the device
2304 * (the system time), so make sure it is available.
2306 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2310 mutex_lock(&mvm->mutex);
2312 /* Send the beacon template */
2313 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2318 * Re-calculate the tsf id, as the master-slave relations depend on the
2319 * beacon interval, which was not known when the AP interface was added.
2321 if (vif->type == NL80211_IFTYPE_AP)
2322 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2324 mvmvif->ap_assoc_sta_count = 0;
2326 /* Add the mac context */
2327 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2331 /* Perform the binding */
2332 ret = iwl_mvm_binding_add_vif(mvm, vif);
2337 * This is not very nice, but the simplest:
2338 * For older FWs adding the mcast sta before the bcast station may
2339 * cause assert 0x2b00.
2340 * This is fixed in later FW so make the order of removal depend on
2343 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2344 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2348 * Send the bcast station. At this stage the TBTT and DTIM time
2349 * events are added and applied to the scheduler
2351 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2353 iwl_mvm_rm_mcast_sta(mvm, vif);
2358 * Send the bcast station. At this stage the TBTT and DTIM time
2359 * events are added and applied to the scheduler
2361 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2364 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2366 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2371 /* must be set before quota calculations */
2372 mvmvif->ap_ibss_active = true;
2374 /* power updated needs to be done before quotas */
2375 iwl_mvm_power_update_mac(mvm);
2377 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2379 goto out_quota_failed;
2381 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2382 if (vif->p2p && mvm->p2p_device_vif)
2383 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2385 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2387 iwl_mvm_bt_coex_vif_change(mvm);
2389 /* we don't support TDLS during DCM */
2390 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2391 iwl_mvm_teardown_tdls_peers(mvm);
2396 iwl_mvm_power_update_mac(mvm);
2397 mvmvif->ap_ibss_active = false;
2398 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2399 iwl_mvm_rm_mcast_sta(mvm, vif);
2401 iwl_mvm_binding_remove_vif(mvm, vif);
2403 iwl_mvm_mac_ctxt_remove(mvm, vif);
2405 mutex_unlock(&mvm->mutex);
2406 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2410 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2411 struct ieee80211_vif *vif)
2413 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2414 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2416 iwl_mvm_prepare_mac_removal(mvm, vif);
2418 mutex_lock(&mvm->mutex);
2420 /* Handle AP stop while in CSA */
2421 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2422 iwl_mvm_remove_time_event(mvm, mvmvif,
2423 &mvmvif->time_event_data);
2424 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2425 mvmvif->csa_countdown = false;
2428 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2429 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2430 mvm->csa_tx_block_bcn_timeout = 0;
2433 mvmvif->ap_ibss_active = false;
2434 mvm->ap_last_beacon_gp2 = 0;
2436 iwl_mvm_bt_coex_vif_change(mvm);
2438 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2440 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2441 if (vif->p2p && mvm->p2p_device_vif)
2442 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2444 iwl_mvm_update_quotas(mvm, false, NULL);
2447 * This is not very nice, but the simplest:
2448 * For older FWs removing the mcast sta before the bcast station may
2449 * cause assert 0x2b00.
2450 * This is fixed in later FW (which will stop beaconing when removing
2452 * So make the order of removal depend on the TLV
2454 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2455 iwl_mvm_rm_mcast_sta(mvm, vif);
2456 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2457 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2458 iwl_mvm_rm_mcast_sta(mvm, vif);
2459 iwl_mvm_binding_remove_vif(mvm, vif);
2461 iwl_mvm_power_update_mac(mvm);
2463 iwl_mvm_mac_ctxt_remove(mvm, vif);
2465 mutex_unlock(&mvm->mutex);
2469 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2470 struct ieee80211_vif *vif,
2471 struct ieee80211_bss_conf *bss_conf,
2474 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2476 /* Changes will be applied when the AP/IBSS is started */
2477 if (!mvmvif->ap_ibss_active)
2480 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2481 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2482 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2483 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2485 /* Need to send a new beacon template to the FW */
2486 if (changes & BSS_CHANGED_BEACON &&
2487 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2488 IWL_WARN(mvm, "Failed updating beacon data\n");
2490 if (changes & BSS_CHANGED_TXPOWER) {
2491 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2493 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2497 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2498 struct ieee80211_vif *vif,
2499 struct ieee80211_bss_conf *bss_conf,
2502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2505 * iwl_mvm_bss_info_changed_station() might call
2506 * iwl_mvm_protect_session(), which reads directly from
2507 * the device (the system time), so make sure it is available.
2509 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2512 mutex_lock(&mvm->mutex);
2514 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2515 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2517 switch (vif->type) {
2518 case NL80211_IFTYPE_STATION:
2519 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2521 case NL80211_IFTYPE_AP:
2522 case NL80211_IFTYPE_ADHOC:
2523 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2525 case NL80211_IFTYPE_MONITOR:
2526 if (changes & BSS_CHANGED_MU_GROUPS)
2527 iwl_mvm_update_mu_groups(mvm, vif);
2530 /* shouldn't happen */
2534 mutex_unlock(&mvm->mutex);
2535 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2538 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2539 struct ieee80211_vif *vif,
2540 struct ieee80211_scan_request *hw_req)
2542 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2545 if (hw_req->req.n_channels == 0 ||
2546 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2549 mutex_lock(&mvm->mutex);
2550 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2551 mutex_unlock(&mvm->mutex);
2556 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2557 struct ieee80211_vif *vif)
2559 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2561 mutex_lock(&mvm->mutex);
2563 /* Due to a race condition, it's possible that mac80211 asks
2564 * us to stop a hw_scan when it's already stopped. This can
2565 * happen, for instance, if we stopped the scan ourselves,
2566 * called ieee80211_scan_completed() and the userspace called
2567 * cancel scan scan before ieee80211_scan_work() could run.
2568 * To handle that, simply return if the scan is not running.
2570 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2571 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2573 mutex_unlock(&mvm->mutex);
2577 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2578 struct ieee80211_sta *sta, u16 tids,
2580 enum ieee80211_frame_release_type reason,
2583 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2585 /* Called when we need to transmit (a) frame(s) from mac80211 */
2587 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2588 tids, more_data, false);
2592 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2593 struct ieee80211_sta *sta, u16 tids,
2595 enum ieee80211_frame_release_type reason,
2598 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2600 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2602 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2603 tids, more_data, true);
2606 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2607 enum sta_notify_cmd cmd,
2608 struct ieee80211_sta *sta)
2610 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2611 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2612 unsigned long txqs = 0, tids = 0;
2616 * If we have TVQM then we get too high queue numbers - luckily
2617 * we really shouldn't get here with that because such hardware
2618 * should have firmware supporting buffer station offload.
2620 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2623 spin_lock_bh(&mvmsta->lock);
2624 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2625 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2627 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2630 __set_bit(tid_data->txq_id, &txqs);
2632 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2635 __set_bit(tid, &tids);
2639 case STA_NOTIFY_SLEEP:
2640 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2641 ieee80211_sta_set_buffered(sta, tid, true);
2644 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2646 * The fw updates the STA to be asleep. Tx packets on the Tx
2647 * queues to this station will not be transmitted. The fw will
2648 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2651 case STA_NOTIFY_AWAKE:
2652 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2656 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2657 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2662 spin_unlock_bh(&mvmsta->lock);
2665 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2666 struct ieee80211_vif *vif,
2667 enum sta_notify_cmd cmd,
2668 struct ieee80211_sta *sta)
2670 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2673 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2675 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2676 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2677 struct ieee80211_sta *sta;
2678 struct iwl_mvm_sta *mvmsta;
2679 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2681 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2685 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2686 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2691 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2694 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2699 if (mvmsta->sleeping != sleeping) {
2700 mvmsta->sleeping = sleeping;
2701 __iwl_mvm_mac_sta_notify(mvm->hw,
2702 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2704 ieee80211_sta_ps_transition(sta, sleeping);
2708 switch (notif->type) {
2709 case IWL_MVM_PM_EVENT_AWAKE:
2710 case IWL_MVM_PM_EVENT_ASLEEP:
2712 case IWL_MVM_PM_EVENT_UAPSD:
2713 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2715 case IWL_MVM_PM_EVENT_PS_POLL:
2716 ieee80211_sta_pspoll(sta);
2726 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2727 struct ieee80211_vif *vif,
2728 struct ieee80211_sta *sta)
2730 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2731 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2734 * This is called before mac80211 does RCU synchronisation,
2735 * so here we already invalidate our internal RCU-protected
2736 * station pointer. The rest of the code will thus no longer
2737 * be able to find the station this way, and we don't rely
2738 * on further RCU synchronisation after the sta_state()
2739 * callback deleted the station.
2741 mutex_lock(&mvm->mutex);
2742 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2743 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2746 mutex_unlock(&mvm->mutex);
2749 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2754 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2755 struct iwl_mvm_tcm_mac *mdata;
2757 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2758 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2759 mdata->opened_rx_ba_sessions = false;
2762 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2765 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2766 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2771 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2772 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2776 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2777 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2778 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2783 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2787 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2788 struct ieee80211_vif *vif, u8 *peer_addr,
2789 enum nl80211_tdls_operation action)
2791 struct iwl_fw_dbg_trigger_tlv *trig;
2792 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2794 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2797 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2798 tdls_trig = (void *)trig->data;
2799 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2800 ieee80211_vif_to_wdev(vif), trig))
2803 if (!(tdls_trig->action_bitmap & BIT(action)))
2806 if (tdls_trig->peer_mode &&
2807 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2810 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2811 "TDLS event occurred, peer %pM, action %d",
2815 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2816 struct iwl_mvm_sta *mvm_sta)
2818 struct iwl_mvm_tid_data *tid_data;
2819 struct sk_buff *skb;
2822 spin_lock_bh(&mvm_sta->lock);
2823 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2824 tid_data = &mvm_sta->tid_data[i];
2826 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2827 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2830 * The first deferred frame should've stopped the MAC
2831 * queues, so we should never get a second deferred
2832 * frame for the RA/TID.
2834 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2835 ieee80211_free_txskb(mvm->hw, skb);
2838 spin_unlock_bh(&mvm_sta->lock);
2841 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2842 struct ieee80211_vif *vif,
2843 struct ieee80211_sta *sta,
2844 enum ieee80211_sta_state old_state,
2845 enum ieee80211_sta_state new_state)
2847 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2848 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2849 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2852 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2853 sta->addr, old_state, new_state);
2855 /* this would be a mac80211 bug ... but don't crash */
2856 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2860 * If we are in a STA removal flow and in DQA mode:
2862 * This is after the sync_rcu part, so the queues have already been
2863 * flushed. No more TXs on their way in mac80211's path, and no more in
2865 * Also, we won't be getting any new TX frames for this station.
2866 * What we might have are deferred TX frames that need to be taken care
2869 * Drop any still-queued deferred-frame before removing the STA, and
2870 * make sure the worker is no longer handling frames for this STA.
2872 if (old_state == IEEE80211_STA_NONE &&
2873 new_state == IEEE80211_STA_NOTEXIST) {
2874 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2875 flush_work(&mvm->add_stream_wk);
2878 * No need to make sure deferred TX indication is off since the
2879 * worker will already remove it if it was on
2883 mutex_lock(&mvm->mutex);
2884 /* track whether or not the station is associated */
2885 mvm_sta->sta_state = new_state;
2887 if (old_state == IEEE80211_STA_NOTEXIST &&
2888 new_state == IEEE80211_STA_NONE) {
2890 * Firmware bug - it'll crash if the beacon interval is less
2891 * than 16. We can't avoid connecting at all, so refuse the
2892 * station state change, this will cause mac80211 to abandon
2893 * attempts to connect to this AP, and eventually wpa_s will
2894 * blacklist the AP...
2896 if (vif->type == NL80211_IFTYPE_STATION &&
2897 vif->bss_conf.beacon_int < 16) {
2899 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2900 sta->addr, vif->bss_conf.beacon_int);
2907 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2908 IWL_MVM_TDLS_STA_COUNT ||
2909 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2910 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2915 ret = iwl_mvm_add_sta(mvm, vif, sta);
2916 if (sta->tdls && ret == 0) {
2917 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2918 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2919 NL80211_TDLS_SETUP);
2921 } else if (old_state == IEEE80211_STA_NONE &&
2922 new_state == IEEE80211_STA_AUTH) {
2924 * EBS may be disabled due to previous failures reported by FW.
2925 * Reset EBS status here assuming environment has been changed.
2927 mvm->last_ebs_successful = true;
2928 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2930 } else if (old_state == IEEE80211_STA_AUTH &&
2931 new_state == IEEE80211_STA_ASSOC) {
2932 if (vif->type == NL80211_IFTYPE_AP) {
2933 mvmvif->ap_assoc_sta_count++;
2934 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2937 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band);
2938 ret = iwl_mvm_update_sta(mvm, vif, sta);
2939 } else if (old_state == IEEE80211_STA_ASSOC &&
2940 new_state == IEEE80211_STA_AUTHORIZED) {
2942 /* we don't support TDLS during DCM */
2943 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2944 iwl_mvm_teardown_tdls_peers(mvm);
2947 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2948 NL80211_TDLS_ENABLE_LINK);
2950 /* enable beacon filtering */
2951 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2953 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band);
2956 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2957 new_state == IEEE80211_STA_ASSOC) {
2958 /* disable beacon filtering */
2959 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2961 } else if (old_state == IEEE80211_STA_ASSOC &&
2962 new_state == IEEE80211_STA_AUTH) {
2963 if (vif->type == NL80211_IFTYPE_AP) {
2964 mvmvif->ap_assoc_sta_count--;
2965 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2968 } else if (old_state == IEEE80211_STA_AUTH &&
2969 new_state == IEEE80211_STA_NONE) {
2971 } else if (old_state == IEEE80211_STA_NONE &&
2972 new_state == IEEE80211_STA_NOTEXIST) {
2973 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2975 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2976 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2977 NL80211_TDLS_DISABLE_LINK);
2983 mutex_unlock(&mvm->mutex);
2985 if (sta->tdls && ret == 0) {
2986 if (old_state == IEEE80211_STA_NOTEXIST &&
2987 new_state == IEEE80211_STA_NONE)
2988 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2989 else if (old_state == IEEE80211_STA_NONE &&
2990 new_state == IEEE80211_STA_NOTEXIST)
2991 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2997 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2999 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3001 mvm->rts_threshold = value;
3006 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3007 struct ieee80211_vif *vif,
3008 struct ieee80211_sta *sta, u32 changed)
3010 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3012 if (vif->type == NL80211_IFTYPE_STATION &&
3013 changed & IEEE80211_RC_NSS_CHANGED)
3014 iwl_mvm_sf_update(mvm, vif, false);
3017 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3018 struct ieee80211_vif *vif, u16 ac,
3019 const struct ieee80211_tx_queue_params *params)
3021 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3022 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3024 mvmvif->queue_params[ac] = *params;
3027 * No need to update right away, we'll get BSS_CHANGED_QOS
3028 * The exception is P2P_DEVICE interface which needs immediate update.
3030 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3033 mutex_lock(&mvm->mutex);
3034 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3035 mutex_unlock(&mvm->mutex);
3041 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3042 struct ieee80211_vif *vif,
3045 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3046 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3047 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3050 * iwl_mvm_protect_session() reads directly from the device
3051 * (the system time), so make sure it is available.
3053 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3056 if (req_duration > duration)
3057 duration = req_duration;
3059 mutex_lock(&mvm->mutex);
3060 /* Try really hard to protect the session and hear a beacon */
3061 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3062 mutex_unlock(&mvm->mutex);
3064 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3067 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3068 struct ieee80211_vif *vif,
3069 struct cfg80211_sched_scan_request *req,
3070 struct ieee80211_scan_ies *ies)
3072 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3076 mutex_lock(&mvm->mutex);
3078 if (!vif->bss_conf.idle) {
3083 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3086 mutex_unlock(&mvm->mutex);
3090 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3091 struct ieee80211_vif *vif)
3093 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3096 mutex_lock(&mvm->mutex);
3098 /* Due to a race condition, it's possible that mac80211 asks
3099 * us to stop a sched_scan when it's already stopped. This
3100 * can happen, for instance, if we stopped the scan ourselves,
3101 * called ieee80211_sched_scan_stopped() and the userspace called
3102 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3103 * could run. To handle this, simply return if the scan is
3106 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3107 mutex_unlock(&mvm->mutex);
3111 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3112 mutex_unlock(&mvm->mutex);
3113 iwl_mvm_wait_for_async_handlers(mvm);
3118 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3119 enum set_key_cmd cmd,
3120 struct ieee80211_vif *vif,
3121 struct ieee80211_sta *sta,
3122 struct ieee80211_key_conf *key)
3124 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3125 struct iwl_mvm_sta *mvmsta;
3126 struct iwl_mvm_key_pn *ptk_pn;
3127 int keyidx = key->keyidx;
3131 if (iwlwifi_mod_params.swcrypto) {
3132 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3136 switch (key->cipher) {
3137 case WLAN_CIPHER_SUITE_TKIP:
3138 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3139 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3141 case WLAN_CIPHER_SUITE_CCMP:
3142 case WLAN_CIPHER_SUITE_GCMP:
3143 case WLAN_CIPHER_SUITE_GCMP_256:
3144 if (!iwl_mvm_has_new_tx_api(mvm))
3145 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3147 case WLAN_CIPHER_SUITE_AES_CMAC:
3148 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3149 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3150 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3152 case WLAN_CIPHER_SUITE_WEP40:
3153 case WLAN_CIPHER_SUITE_WEP104:
3154 /* For non-client mode, only use WEP keys for TX as we probably
3155 * don't have a station yet anyway and would then have to keep
3156 * track of the keys, linking them to each of the clients/peers
3157 * as they appear. For now, don't do that, for performance WEP
3158 * offload doesn't really matter much, but we need it for some
3159 * other offload features in client mode.
3161 if (vif->type != NL80211_IFTYPE_STATION)
3165 /* currently FW supports only one optional cipher scheme */
3166 if (hw->n_cipher_schemes &&
3167 hw->cipher_schemes->cipher == key->cipher)
3168 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3173 mutex_lock(&mvm->mutex);
3177 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3178 vif->type == NL80211_IFTYPE_AP) && !sta) {
3180 * GTK on AP interface is a TX-only key, return 0;
3181 * on IBSS they're per-station and because we're lazy
3182 * we don't support them for RX, so do the same.
3183 * CMAC/GMAC in AP/IBSS modes must be done in software.
3185 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3186 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3187 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3192 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3193 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3194 !iwl_mvm_has_new_tx_api(mvm)) {
3195 key->hw_key_idx = STA_KEY_IDX_INVALID;
3200 /* During FW restart, in order to restore the state as it was,
3201 * don't try to reprogram keys we previously failed for.
3203 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3204 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3205 IWL_DEBUG_MAC80211(mvm,
3206 "skip invalid idx key programming during restart\n");
3211 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3212 sta && iwl_mvm_has_new_rx_api(mvm) &&
3213 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3214 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3215 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3216 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3217 struct ieee80211_key_seq seq;
3220 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3221 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3222 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3223 mvm->trans->num_rx_queues),
3230 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3231 ieee80211_get_key_rx_seq(key, tid, &seq);
3232 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3233 memcpy(ptk_pn->q[q].pn[tid],
3235 IEEE80211_CCMP_PN_LEN);
3238 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3241 /* in HW restart reuse the index, otherwise request a new one */
3242 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3243 key_offset = key->hw_key_idx;
3245 key_offset = STA_KEY_IDX_INVALID;
3247 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3248 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3250 IWL_WARN(mvm, "set key failed\n");
3252 * can't add key for RX, but we don't need it
3253 * in the device for TX so still return 0
3255 key->hw_key_idx = STA_KEY_IDX_INVALID;
3261 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3266 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3267 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3268 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3269 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3270 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3271 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3272 ptk_pn = rcu_dereference_protected(
3273 mvmsta->ptk_pn[keyidx],
3274 lockdep_is_held(&mvm->mutex));
3275 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3277 kfree_rcu(ptk_pn, rcu_head);
3280 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3281 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3287 mutex_unlock(&mvm->mutex);
3291 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3292 struct ieee80211_vif *vif,
3293 struct ieee80211_key_conf *keyconf,
3294 struct ieee80211_sta *sta,
3295 u32 iv32, u16 *phase1key)
3297 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3299 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3302 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3306 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3307 struct iwl_rx_packet *pkt, void *data)
3309 struct iwl_mvm *mvm =
3310 container_of(notif_wait, struct iwl_mvm, notif_wait);
3311 struct iwl_hs20_roc_res *resp;
3312 int resp_len = iwl_rx_packet_payload_len(pkt);
3313 struct iwl_mvm_time_event_data *te_data = data;
3315 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3318 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3319 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3323 resp = (void *)pkt->data;
3326 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3327 resp->status, resp->event_unique_id);
3329 te_data->uid = le32_to_cpu(resp->event_unique_id);
3330 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3333 spin_lock_bh(&mvm->time_event_lock);
3334 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3335 spin_unlock_bh(&mvm->time_event_lock);
3340 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3341 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3342 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3343 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3344 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3345 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3346 struct ieee80211_channel *channel,
3347 struct ieee80211_vif *vif,
3350 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3351 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3352 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3353 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3354 struct iwl_notification_wait wait_time_event;
3355 u32 dtim_interval = vif->bss_conf.dtim_period *
3356 vif->bss_conf.beacon_int;
3358 struct iwl_hs20_roc_req aux_roc_req = {
3359 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3361 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3362 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3363 /* Set the channel info data */
3364 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3365 PHY_BAND_24 : PHY_BAND_5,
3366 .channel_info.channel = channel->hw_value,
3367 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3368 /* Set the time and duration */
3369 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3372 delay = AUX_ROC_MIN_DELAY;
3373 req_dur = MSEC_TO_TU(duration);
3376 * If we are associated we want the delay time to be at least one
3377 * dtim interval so that the FW can wait until after the DTIM and
3378 * then start the time event, this will potentially allow us to
3379 * remain off-channel for the max duration.
3380 * Since we want to use almost a whole dtim interval we would also
3381 * like the delay to be for 2-3 dtim intervals, in case there are
3382 * other time events with higher priority.
3384 if (vif->bss_conf.assoc) {
3385 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3386 /* We cannot remain off-channel longer than the DTIM interval */
3387 if (dtim_interval <= req_dur) {
3388 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3389 if (req_dur <= AUX_ROC_MIN_DURATION)
3390 req_dur = dtim_interval -
3391 AUX_ROC_MIN_SAFETY_BUFFER;
3395 aux_roc_req.duration = cpu_to_le32(req_dur);
3396 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3399 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3400 channel->hw_value, req_dur, duration, delay,
3402 /* Set the node address */
3403 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3405 lockdep_assert_held(&mvm->mutex);
3407 spin_lock_bh(&mvm->time_event_lock);
3409 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3410 spin_unlock_bh(&mvm->time_event_lock);
3415 te_data->duration = duration;
3416 te_data->id = HOT_SPOT_CMD;
3418 spin_unlock_bh(&mvm->time_event_lock);
3421 * Use a notification wait, which really just processes the
3422 * command response and doesn't wait for anything, in order
3423 * to be able to process the response and get the UID inside
3424 * the RX path. Using CMD_WANT_SKB doesn't work because it
3425 * stores the buffer and then wakes up this thread, by which
3426 * time another notification (that the time event started)
3427 * might already be processed unsuccessfully.
3429 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3430 time_event_response,
3431 ARRAY_SIZE(time_event_response),
3432 iwl_mvm_rx_aux_roc, te_data);
3434 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3438 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3439 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3443 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3444 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3445 /* should never fail */
3450 spin_lock_bh(&mvm->time_event_lock);
3451 iwl_mvm_te_clear_data(mvm, te_data);
3452 spin_unlock_bh(&mvm->time_event_lock);
3458 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3459 struct ieee80211_vif *vif,
3460 struct ieee80211_channel *channel,
3462 enum ieee80211_roc_type type)
3464 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3465 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3466 struct cfg80211_chan_def chandef;
3467 struct iwl_mvm_phy_ctxt *phy_ctxt;
3470 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3474 * Flush the done work, just in case it's still pending, so that
3475 * the work it does can complete and we can accept new frames.
3477 flush_work(&mvm->roc_done_wk);
3479 mutex_lock(&mvm->mutex);
3481 switch (vif->type) {
3482 case NL80211_IFTYPE_STATION:
3483 if (fw_has_capa(&mvm->fw->ucode_capa,
3484 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3485 /* Use aux roc framework (HS20) */
3486 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3490 IWL_ERR(mvm, "hotspot not supported\n");
3493 case NL80211_IFTYPE_P2P_DEVICE:
3497 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3502 for (i = 0; i < NUM_PHY_CTX; i++) {
3503 phy_ctxt = &mvm->phy_ctxts[i];
3504 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3507 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3509 * Unbind the P2P_DEVICE from the current PHY context,
3510 * and if the PHY context is not used remove it.
3512 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3513 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3516 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3518 /* Bind the P2P_DEVICE to the current PHY Context */
3519 mvmvif->phy_ctxt = phy_ctxt;
3521 ret = iwl_mvm_binding_add_vif(mvm, vif);
3522 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3525 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3526 goto schedule_time_event;
3530 /* Need to update the PHY context only if the ROC channel changed */
3531 if (channel == mvmvif->phy_ctxt->channel)
3532 goto schedule_time_event;
3534 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3537 * Change the PHY context configuration as it is currently referenced
3538 * only by the P2P Device MAC
3540 if (mvmvif->phy_ctxt->ref == 1) {
3541 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3547 * The PHY context is shared with other MACs. Need to remove the
3548 * P2P Device from the binding, allocate an new PHY context and
3549 * create a new binding
3551 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3557 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3560 IWL_ERR(mvm, "Failed to change PHY context\n");
3564 /* Unbind the P2P_DEVICE from the current PHY context */
3565 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3566 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3569 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3571 /* Bind the P2P_DEVICE to the new allocated PHY context */
3572 mvmvif->phy_ctxt = phy_ctxt;
3574 ret = iwl_mvm_binding_add_vif(mvm, vif);
3575 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3578 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3581 schedule_time_event:
3582 /* Schedule the time events */
3583 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3586 mutex_unlock(&mvm->mutex);
3587 IWL_DEBUG_MAC80211(mvm, "leave\n");
3591 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3593 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3595 IWL_DEBUG_MAC80211(mvm, "enter\n");
3597 mutex_lock(&mvm->mutex);
3598 iwl_mvm_stop_roc(mvm);
3599 mutex_unlock(&mvm->mutex);
3601 IWL_DEBUG_MAC80211(mvm, "leave\n");
3605 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3606 struct ieee80211_chanctx_conf *ctx)
3608 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3609 struct iwl_mvm_phy_ctxt *phy_ctxt;
3612 lockdep_assert_held(&mvm->mutex);
3614 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3616 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3622 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3623 ctx->rx_chains_static,
3624 ctx->rx_chains_dynamic);
3626 IWL_ERR(mvm, "Failed to add PHY context\n");
3630 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3631 *phy_ctxt_id = phy_ctxt->id;
3636 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3637 struct ieee80211_chanctx_conf *ctx)
3639 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3642 mutex_lock(&mvm->mutex);
3643 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3644 mutex_unlock(&mvm->mutex);
3649 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3650 struct ieee80211_chanctx_conf *ctx)
3652 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3653 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3655 lockdep_assert_held(&mvm->mutex);
3657 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3660 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3661 struct ieee80211_chanctx_conf *ctx)
3663 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3665 mutex_lock(&mvm->mutex);
3666 __iwl_mvm_remove_chanctx(mvm, ctx);
3667 mutex_unlock(&mvm->mutex);
3670 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3671 struct ieee80211_chanctx_conf *ctx,
3674 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3675 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3676 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3678 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3679 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3680 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3681 IEEE80211_CHANCTX_CHANGE_RADAR |
3682 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3683 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3684 phy_ctxt->ref, changed))
3687 mutex_lock(&mvm->mutex);
3689 /* we are only changing the min_width, may be a noop */
3690 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3691 if (phy_ctxt->width == ctx->min_def.width)
3694 /* we are just toggling between 20_NOHT and 20 */
3695 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3696 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3700 iwl_mvm_bt_coex_vif_change(mvm);
3701 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3702 ctx->rx_chains_static,
3703 ctx->rx_chains_dynamic);
3706 mutex_unlock(&mvm->mutex);
3709 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3710 struct ieee80211_vif *vif,
3711 struct ieee80211_chanctx_conf *ctx,
3712 bool switching_chanctx)
3714 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3715 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3716 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3719 lockdep_assert_held(&mvm->mutex);
3721 mvmvif->phy_ctxt = phy_ctxt;
3723 switch (vif->type) {
3724 case NL80211_IFTYPE_AP:
3725 /* only needed if we're switching chanctx (i.e. during CSA) */
3726 if (switching_chanctx) {
3727 mvmvif->ap_ibss_active = true;
3730 case NL80211_IFTYPE_ADHOC:
3732 * The AP binding flow is handled as part of the start_ap flow
3733 * (in bss_info_changed), similarly for IBSS.
3737 case NL80211_IFTYPE_STATION:
3738 mvmvif->csa_bcn_pending = false;
3740 case NL80211_IFTYPE_MONITOR:
3741 /* always disable PS when a monitor interface is active */
3742 mvmvif->ps_disabled = true;
3749 ret = iwl_mvm_binding_add_vif(mvm, vif);
3754 * Power state must be updated before quotas,
3755 * otherwise fw will complain.
3757 iwl_mvm_power_update_mac(mvm);
3759 /* Setting the quota at this stage is only required for monitor
3760 * interfaces. For the other types, the bss_info changed flow
3761 * will handle quota settings.
3763 if (vif->type == NL80211_IFTYPE_MONITOR) {
3764 mvmvif->monitor_active = true;
3765 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3767 goto out_remove_binding;
3769 ret = iwl_mvm_add_snif_sta(mvm, vif);
3771 goto out_remove_binding;
3775 /* Handle binding during CSA */
3776 if (vif->type == NL80211_IFTYPE_AP) {
3777 iwl_mvm_update_quotas(mvm, false, NULL);
3778 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3781 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3782 u32 duration = 3 * vif->bss_conf.beacon_int;
3784 /* iwl_mvm_protect_session() reads directly from the
3785 * device (the system time), so make sure it is
3788 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3790 goto out_remove_binding;
3792 /* Protect the session to make sure we hear the first
3793 * beacon on the new channel.
3795 mvmvif->csa_bcn_pending = true;
3796 iwl_mvm_protect_session(mvm, vif, duration, duration,
3797 vif->bss_conf.beacon_int / 2,
3800 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3802 iwl_mvm_update_quotas(mvm, false, NULL);
3808 iwl_mvm_binding_remove_vif(mvm, vif);
3809 iwl_mvm_power_update_mac(mvm);
3812 mvmvif->phy_ctxt = NULL;
3815 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3816 struct ieee80211_vif *vif,
3817 struct ieee80211_chanctx_conf *ctx)
3819 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3822 mutex_lock(&mvm->mutex);
3823 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3824 mutex_unlock(&mvm->mutex);
3829 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3830 struct ieee80211_vif *vif,
3831 struct ieee80211_chanctx_conf *ctx,
3832 bool switching_chanctx)
3834 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3835 struct ieee80211_vif *disabled_vif = NULL;
3837 lockdep_assert_held(&mvm->mutex);
3839 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3841 switch (vif->type) {
3842 case NL80211_IFTYPE_ADHOC:
3844 case NL80211_IFTYPE_MONITOR:
3845 mvmvif->monitor_active = false;
3846 mvmvif->ps_disabled = false;
3847 iwl_mvm_rm_snif_sta(mvm, vif);
3849 case NL80211_IFTYPE_AP:
3850 /* This part is triggered only during CSA */
3851 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3854 mvmvif->csa_countdown = false;
3856 /* Set CS bit on all the stations */
3857 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3859 /* Save blocked iface, the timeout is set on the next beacon */
3860 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3862 mvmvif->ap_ibss_active = false;
3864 case NL80211_IFTYPE_STATION:
3865 if (!switching_chanctx)
3870 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3876 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3877 iwl_mvm_binding_remove_vif(mvm, vif);
3880 mvmvif->phy_ctxt = NULL;
3881 iwl_mvm_power_update_mac(mvm);
3884 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3885 struct ieee80211_vif *vif,
3886 struct ieee80211_chanctx_conf *ctx)
3888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3890 mutex_lock(&mvm->mutex);
3891 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3892 mutex_unlock(&mvm->mutex);
3896 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3897 struct ieee80211_vif_chanctx_switch *vifs)
3901 mutex_lock(&mvm->mutex);
3902 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3903 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3905 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3907 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3911 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3915 "failed to assign new_ctx during channel switch\n");
3919 /* we don't support TDLS during DCM - can be caused by channel switch */
3920 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3921 iwl_mvm_teardown_tdls_peers(mvm);
3926 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3929 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3930 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3934 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3936 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3943 /* things keep failing, better restart the hw */
3944 iwl_mvm_nic_restart(mvm, false);
3947 mutex_unlock(&mvm->mutex);
3953 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3954 struct ieee80211_vif_chanctx_switch *vifs)
3958 mutex_lock(&mvm->mutex);
3959 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3961 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3965 "failed to assign new_ctx during channel switch\n");
3972 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3974 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3981 /* things keep failing, better restart the hw */
3982 iwl_mvm_nic_restart(mvm, false);
3985 mutex_unlock(&mvm->mutex);
3990 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3991 struct ieee80211_vif_chanctx_switch *vifs,
3993 enum ieee80211_chanctx_switch_mode mode)
3995 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3998 /* we only support a single-vif right now */
4003 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4004 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4006 case CHANCTX_SWMODE_REASSIGN_VIF:
4007 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4017 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4019 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4021 return mvm->ibss_manager;
4024 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4025 struct ieee80211_sta *sta,
4028 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4029 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4031 if (!mvm_sta || !mvm_sta->vif) {
4032 IWL_ERR(mvm, "Station is not associated to a vif\n");
4036 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4039 #ifdef CONFIG_NL80211_TESTMODE
4040 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4041 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4042 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4043 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4046 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4047 struct ieee80211_vif *vif,
4048 void *data, int len)
4050 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4054 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4059 if (!tb[IWL_MVM_TM_ATTR_CMD])
4062 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4063 case IWL_MVM_TM_CMD_SET_NOA:
4064 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4065 !vif->bss_conf.enable_beacon ||
4066 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4069 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4070 if (noa_duration >= vif->bss_conf.beacon_int)
4073 mvm->noa_duration = noa_duration;
4076 return iwl_mvm_update_quotas(mvm, true, NULL);
4077 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4078 /* must be associated client vif - ignore authorized */
4079 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4080 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4081 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4084 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4085 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4086 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4092 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4093 struct ieee80211_vif *vif,
4094 void *data, int len)
4096 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4099 mutex_lock(&mvm->mutex);
4100 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4101 mutex_unlock(&mvm->mutex);
4107 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4108 struct ieee80211_vif *vif,
4109 struct ieee80211_channel_switch *chsw)
4111 /* By implementing this operation, we prevent mac80211 from
4112 * starting its own channel switch timer, so that we can call
4113 * ieee80211_chswitch_done() ourselves at the right time
4114 * (which is when the absence time event starts).
4117 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4118 "dummy channel switch op\n");
4121 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4122 struct ieee80211_vif *vif,
4123 struct ieee80211_channel_switch *chsw)
4125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4126 struct ieee80211_vif *csa_vif;
4127 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4131 mutex_lock(&mvm->mutex);
4133 mvmvif->csa_failed = false;
4135 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4136 chsw->chandef.center_freq1);
4138 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4139 ieee80211_vif_to_wdev(vif),
4140 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4142 switch (vif->type) {
4143 case NL80211_IFTYPE_AP:
4145 rcu_dereference_protected(mvm->csa_vif,
4146 lockdep_is_held(&mvm->mutex));
4147 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4148 "Another CSA is already in progress")) {
4153 /* we still didn't unblock tx. prevent new CS meanwhile */
4154 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4155 lockdep_is_held(&mvm->mutex))) {
4160 rcu_assign_pointer(mvm->csa_vif, vif);
4162 if (WARN_ONCE(mvmvif->csa_countdown,
4163 "Previous CSA countdown didn't complete")) {
4168 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4171 case NL80211_IFTYPE_STATION:
4172 /* Schedule the time event to a bit before beacon 1,
4173 * to make sure we're in the new channel when the
4174 * GO/AP arrives. In case count <= 1 immediately schedule the
4175 * TE (this might result with some packet loss or connection
4178 if (chsw->count <= 1)
4181 apply_time = chsw->device_timestamp +
4182 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4183 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4186 iwl_mvm_csa_client_absent(mvm, vif);
4188 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4190 if (mvmvif->bf_data.bf_enabled) {
4191 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4201 mvmvif->ps_disabled = true;
4203 ret = iwl_mvm_power_update_ps(mvm);
4207 /* we won't be on this channel any longer */
4208 iwl_mvm_teardown_tdls_peers(mvm);
4211 mutex_unlock(&mvm->mutex);
4216 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4217 struct ieee80211_vif *vif)
4219 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4220 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4223 mutex_lock(&mvm->mutex);
4225 if (mvmvif->csa_failed) {
4226 mvmvif->csa_failed = false;
4231 if (vif->type == NL80211_IFTYPE_STATION) {
4232 struct iwl_mvm_sta *mvmsta;
4234 mvmvif->csa_bcn_pending = false;
4235 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4238 if (WARN_ON(!mvmsta)) {
4243 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4245 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4247 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4251 iwl_mvm_stop_session_protection(mvm, vif);
4254 mvmvif->ps_disabled = false;
4256 ret = iwl_mvm_power_update_ps(mvm);
4259 mutex_unlock(&mvm->mutex);
4264 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4268 if (!iwl_mvm_has_new_tx_api(mvm)) {
4270 mutex_lock(&mvm->mutex);
4271 iwl_mvm_flush_tx_path(mvm,
4272 iwl_mvm_flushable_queues(mvm) & queues, 0);
4273 mutex_unlock(&mvm->mutex);
4275 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4280 mutex_lock(&mvm->mutex);
4281 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4282 struct ieee80211_sta *sta;
4284 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4285 lockdep_is_held(&mvm->mutex));
4286 if (IS_ERR_OR_NULL(sta))
4290 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4292 iwl_mvm_wait_sta_queues_empty(mvm,
4293 iwl_mvm_sta_from_mac80211(sta));
4295 mutex_unlock(&mvm->mutex);
4298 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4299 struct ieee80211_vif *vif, u32 queues, bool drop)
4301 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4302 struct iwl_mvm_vif *mvmvif;
4303 struct iwl_mvm_sta *mvmsta;
4304 struct ieee80211_sta *sta;
4309 iwl_mvm_flush_no_vif(mvm, queues, drop);
4313 if (vif->type != NL80211_IFTYPE_STATION)
4316 /* Make sure we're done with the deferred traffic before flushing */
4317 flush_work(&mvm->add_stream_wk);
4319 mutex_lock(&mvm->mutex);
4320 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4322 /* flush the AP-station and all TDLS peers */
4323 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4324 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4325 lockdep_is_held(&mvm->mutex));
4326 if (IS_ERR_OR_NULL(sta))
4329 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4330 if (mvmsta->vif != vif)
4333 /* make sure only TDLS peers or the AP are flushed */
4334 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4337 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4338 IWL_ERR(mvm, "flush request fail\n");
4340 msk |= mvmsta->tfd_queue_msk;
4341 if (iwl_mvm_has_new_tx_api(mvm))
4342 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4346 mutex_unlock(&mvm->mutex);
4348 /* this can take a while, and we may need/want other operations
4349 * to succeed while doing this, so do it without the mutex held
4351 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4352 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4355 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4356 struct survey_info *survey)
4358 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4361 memset(survey, 0, sizeof(*survey));
4363 /* only support global statistics right now */
4367 if (!fw_has_capa(&mvm->fw->ucode_capa,
4368 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4371 mutex_lock(&mvm->mutex);
4373 if (iwl_mvm_firmware_running(mvm)) {
4374 ret = iwl_mvm_request_statistics(mvm, false);
4379 survey->filled = SURVEY_INFO_TIME |
4380 SURVEY_INFO_TIME_RX |
4381 SURVEY_INFO_TIME_TX |
4382 SURVEY_INFO_TIME_SCAN;
4383 survey->time = mvm->accu_radio_stats.on_time_rf +
4384 mvm->radio_stats.on_time_rf;
4385 do_div(survey->time, USEC_PER_MSEC);
4387 survey->time_rx = mvm->accu_radio_stats.rx_time +
4388 mvm->radio_stats.rx_time;
4389 do_div(survey->time_rx, USEC_PER_MSEC);
4391 survey->time_tx = mvm->accu_radio_stats.tx_time +
4392 mvm->radio_stats.tx_time;
4393 do_div(survey->time_tx, USEC_PER_MSEC);
4395 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4396 mvm->radio_stats.on_time_scan;
4397 do_div(survey->time_scan, USEC_PER_MSEC);
4401 mutex_unlock(&mvm->mutex);
4405 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4406 struct ieee80211_vif *vif,
4407 struct ieee80211_sta *sta,
4408 struct station_info *sinfo)
4410 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4411 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4412 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4414 if (mvmsta->avg_energy) {
4415 sinfo->signal_avg = mvmsta->avg_energy;
4416 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4419 /* if beacon filtering isn't on mac80211 does it anyway */
4420 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4423 if (!vif->bss_conf.assoc)
4426 mutex_lock(&mvm->mutex);
4428 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4431 if (iwl_mvm_request_statistics(mvm, false))
4434 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4435 mvmvif->beacon_stats.accu_num_beacons;
4436 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4437 if (mvmvif->beacon_stats.avg_signal) {
4438 /* firmware only reports a value after RXing a few beacons */
4439 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4440 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4443 mutex_unlock(&mvm->mutex);
4446 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4447 struct ieee80211_vif *vif,
4448 const struct ieee80211_event *event)
4450 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4452 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4454 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4457 struct iwl_fw_dbg_trigger_tlv *trig;
4458 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4460 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4463 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4464 trig_mlme = (void *)trig->data;
4465 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4466 ieee80211_vif_to_wdev(vif), trig))
4469 if (event->u.mlme.data == ASSOC_EVENT) {
4470 if (event->u.mlme.status == MLME_DENIED)
4471 CHECK_MLME_TRIGGER(stop_assoc_denied,
4472 "DENIED ASSOC: reason %d",
4473 event->u.mlme.reason);
4474 else if (event->u.mlme.status == MLME_TIMEOUT)
4475 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4477 } else if (event->u.mlme.data == AUTH_EVENT) {
4478 if (event->u.mlme.status == MLME_DENIED)
4479 CHECK_MLME_TRIGGER(stop_auth_denied,
4480 "DENIED AUTH: reason %d",
4481 event->u.mlme.reason);
4482 else if (event->u.mlme.status == MLME_TIMEOUT)
4483 CHECK_MLME_TRIGGER(stop_auth_timeout,
4485 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4486 CHECK_MLME_TRIGGER(stop_rx_deauth,
4487 "DEAUTH RX %d", event->u.mlme.reason);
4488 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4489 CHECK_MLME_TRIGGER(stop_tx_deauth,
4490 "DEAUTH TX %d", event->u.mlme.reason);
4492 #undef CHECK_MLME_TRIGGER
4495 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4496 struct ieee80211_vif *vif,
4497 const struct ieee80211_event *event)
4499 struct iwl_fw_dbg_trigger_tlv *trig;
4500 struct iwl_fw_dbg_trigger_ba *ba_trig;
4502 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4505 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4506 ba_trig = (void *)trig->data;
4507 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4508 ieee80211_vif_to_wdev(vif), trig))
4511 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4514 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4515 "BAR received from %pM, tid %d, ssn %d",
4516 event->u.ba.sta->addr, event->u.ba.tid,
4520 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4521 struct ieee80211_vif *vif,
4522 const struct ieee80211_event *event)
4524 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4526 switch (event->type) {
4528 iwl_mvm_event_mlme_callback(mvm, vif, event);
4531 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4533 case BA_FRAME_TIMEOUT:
4534 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4542 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4543 struct iwl_mvm_internal_rxq_notif *notif,
4546 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4549 lockdep_assert_held(&mvm->mutex);
4551 if (!iwl_mvm_has_new_rx_api(mvm))
4554 notif->cookie = mvm->queue_sync_cookie;
4557 atomic_set(&mvm->queue_sync_counter,
4558 mvm->trans->num_rx_queues);
4560 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4562 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4567 ret = wait_event_timeout(mvm->rx_sync_waitq,
4568 atomic_read(&mvm->queue_sync_counter) == 0 ||
4569 iwl_mvm_is_radio_killed(mvm),
4571 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4575 atomic_set(&mvm->queue_sync_counter, 0);
4576 mvm->queue_sync_cookie++;
4579 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4581 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4582 struct iwl_mvm_internal_rxq_notif data = {
4583 .type = IWL_MVM_RXQ_EMPTY,
4587 mutex_lock(&mvm->mutex);
4588 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4589 mutex_unlock(&mvm->mutex);
4592 const struct ieee80211_ops iwl_mvm_hw_ops = {
4593 .tx = iwl_mvm_mac_tx,
4594 .ampdu_action = iwl_mvm_mac_ampdu_action,
4595 .start = iwl_mvm_mac_start,
4596 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4597 .stop = iwl_mvm_mac_stop,
4598 .add_interface = iwl_mvm_mac_add_interface,
4599 .remove_interface = iwl_mvm_mac_remove_interface,
4600 .config = iwl_mvm_mac_config,
4601 .prepare_multicast = iwl_mvm_prepare_multicast,
4602 .configure_filter = iwl_mvm_configure_filter,
4603 .config_iface_filter = iwl_mvm_config_iface_filter,
4604 .bss_info_changed = iwl_mvm_bss_info_changed,
4605 .hw_scan = iwl_mvm_mac_hw_scan,
4606 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4607 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4608 .sta_state = iwl_mvm_mac_sta_state,
4609 .sta_notify = iwl_mvm_mac_sta_notify,
4610 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4611 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4612 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4613 .sta_rc_update = iwl_mvm_sta_rc_update,
4614 .conf_tx = iwl_mvm_mac_conf_tx,
4615 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4616 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4617 .flush = iwl_mvm_mac_flush,
4618 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4619 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4620 .set_key = iwl_mvm_mac_set_key,
4621 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4622 .remain_on_channel = iwl_mvm_roc,
4623 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4624 .add_chanctx = iwl_mvm_add_chanctx,
4625 .remove_chanctx = iwl_mvm_remove_chanctx,
4626 .change_chanctx = iwl_mvm_change_chanctx,
4627 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4628 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4629 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4631 .start_ap = iwl_mvm_start_ap_ibss,
4632 .stop_ap = iwl_mvm_stop_ap_ibss,
4633 .join_ibss = iwl_mvm_start_ap_ibss,
4634 .leave_ibss = iwl_mvm_stop_ap_ibss,
4636 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4638 .set_tim = iwl_mvm_set_tim,
4640 .channel_switch = iwl_mvm_channel_switch,
4641 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4642 .post_channel_switch = iwl_mvm_post_channel_switch,
4644 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4645 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4646 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4648 .event_callback = iwl_mvm_mac_event_callback,
4650 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4652 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4654 #ifdef CONFIG_PM_SLEEP
4656 .suspend = iwl_mvm_suspend,
4657 .resume = iwl_mvm_resume,
4658 .set_wakeup = iwl_mvm_set_wakeup,
4659 .set_rekey_data = iwl_mvm_set_rekey_data,
4660 #if IS_ENABLED(CONFIG_IPV6)
4661 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4663 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4665 .get_survey = iwl_mvm_mac_get_survey,
4666 .sta_statistics = iwl_mvm_mac_sta_statistics,
4667 #ifdef CONFIG_IWLWIFI_DEBUGFS
4668 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,