1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 - 2019 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 - 2019 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
188 .max_peers = IWL_MVM_TOF_MAX_APS,
190 .randomize_mac_addr = 1,
197 .request_civicloc = 1,
198 .max_bursts_exponent = -1, /* all supported */
199 .max_ftms_per_burst = 0, /* no limits */
200 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
201 BIT(NL80211_CHAN_WIDTH_20) |
202 BIT(NL80211_CHAN_WIDTH_40) |
203 BIT(NL80211_CHAN_WIDTH_80),
204 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
205 BIT(NL80211_PREAMBLE_HT) |
206 BIT(NL80211_PREAMBLE_VHT),
210 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
212 if (!iwl_mvm_is_d0i3_supported(mvm))
215 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
216 spin_lock_bh(&mvm->refs_lock);
217 mvm->refs[ref_type]++;
218 spin_unlock_bh(&mvm->refs_lock);
219 iwl_trans_ref(mvm->trans);
222 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
224 if (!iwl_mvm_is_d0i3_supported(mvm))
227 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
228 spin_lock_bh(&mvm->refs_lock);
229 if (WARN_ON(!mvm->refs[ref_type])) {
230 spin_unlock_bh(&mvm->refs_lock);
233 mvm->refs[ref_type]--;
234 spin_unlock_bh(&mvm->refs_lock);
235 iwl_trans_unref(mvm->trans);
238 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
239 enum iwl_mvm_ref_type except_ref)
243 if (!iwl_mvm_is_d0i3_supported(mvm))
246 spin_lock_bh(&mvm->refs_lock);
247 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
248 if (except_ref == i || !mvm->refs[i])
251 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
253 for (j = 0; j < mvm->refs[i]; j++)
254 iwl_trans_unref(mvm->trans);
257 spin_unlock_bh(&mvm->refs_lock);
260 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
265 if (!iwl_mvm_is_d0i3_supported(mvm))
268 spin_lock_bh(&mvm->refs_lock);
269 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
275 spin_unlock_bh(&mvm->refs_lock);
280 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
282 iwl_mvm_ref(mvm, ref_type);
284 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
285 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
288 iwl_mvm_unref(mvm, ref_type);
295 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
299 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
300 for (i = 0; i < NUM_PHY_CTX; i++) {
301 mvm->phy_ctxts[i].id = i;
302 mvm->phy_ctxts[i].ref = 0;
306 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
308 enum iwl_mcc_source src_id,
311 struct ieee80211_regdomain *regd = NULL;
312 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
314 struct iwl_mcc_update_resp *resp;
316 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
318 lockdep_assert_held(&mvm->mutex);
320 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
321 if (IS_ERR_OR_NULL(resp)) {
322 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
323 PTR_ERR_OR_ZERO(resp));
328 u32 status = le32_to_cpu(resp->status);
330 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
331 status == MCC_RESP_ILLEGAL);
334 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
335 __le32_to_cpu(resp->n_channels),
337 __le16_to_cpu(resp->mcc),
338 __le16_to_cpu(resp->geo_info));
339 /* Store the return source id */
340 src_id = resp->source_id;
342 if (IS_ERR_OR_NULL(regd)) {
343 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
344 PTR_ERR_OR_ZERO(regd));
348 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
349 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
350 mvm->lar_regdom_set = true;
351 mvm->mcc_src = src_id;
357 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
360 struct ieee80211_regdomain *regd;
362 if (!iwl_mvm_is_lar_supported(mvm))
365 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
366 if (!IS_ERR_OR_NULL(regd)) {
367 /* only update the regulatory core if changed */
369 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
375 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
378 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
379 iwl_mvm_is_wifi_mcc_supported(mvm) ?
380 MCC_SOURCE_GET_CURRENT :
381 MCC_SOURCE_OLD_FW, changed);
384 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
386 enum iwl_mcc_source used_src;
387 struct ieee80211_regdomain *regd;
390 const struct ieee80211_regdomain *r =
391 rtnl_dereference(mvm->hw->wiphy->regd);
396 /* save the last source in case we overwrite it below */
397 used_src = mvm->mcc_src;
398 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
399 /* Notify the firmware we support wifi location updates */
400 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
401 if (!IS_ERR_OR_NULL(regd))
405 /* Now set our last stored MCC and source */
406 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
408 if (IS_ERR_OR_NULL(regd))
411 /* update cfg80211 if the regdomain was changed */
413 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
421 const static u8 he_if_types_ext_capa_sta[] = {
422 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
423 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
424 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
427 const static struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
429 .iftype = NL80211_IFTYPE_STATION,
430 .extended_capabilities = he_if_types_ext_capa_sta,
431 .extended_capabilities_mask = he_if_types_ext_capa_sta,
432 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
436 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
438 struct ieee80211_hw *hw = mvm->hw;
440 static const u32 mvm_ciphers[] = {
441 WLAN_CIPHER_SUITE_WEP40,
442 WLAN_CIPHER_SUITE_WEP104,
443 WLAN_CIPHER_SUITE_TKIP,
444 WLAN_CIPHER_SUITE_CCMP,
446 #ifdef CONFIG_PM_SLEEP
447 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
448 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
451 /* Tell mac80211 our characteristics */
452 ieee80211_hw_set(hw, SIGNAL_DBM);
453 ieee80211_hw_set(hw, SPECTRUM_MGMT);
454 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
455 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
456 ieee80211_hw_set(hw, SUPPORTS_PS);
457 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
458 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
459 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
460 ieee80211_hw_set(hw, CONNECTION_MONITOR);
461 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
462 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
463 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
464 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
465 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
466 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
467 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
468 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
469 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
470 ieee80211_hw_set(hw, TX_AMSDU);
471 ieee80211_hw_set(hw, TX_FRAG_LIST);
473 if (iwl_mvm_has_tlc_offload(mvm)) {
474 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
475 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
478 if (iwl_mvm_has_new_rx_api(mvm))
479 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
481 if (fw_has_capa(&mvm->fw->ucode_capa,
482 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
483 ieee80211_hw_set(hw, AP_LINK_PS);
484 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
486 * we absolutely need this for the new TX API since that comes
487 * with many more queues than the current code can deal with
488 * for station powersave
493 if (mvm->trans->num_rx_queues > 1)
494 ieee80211_hw_set(hw, USES_RSS);
496 if (mvm->trans->max_skb_frags)
497 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
499 hw->queues = IEEE80211_MAX_QUEUES;
500 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
501 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
502 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
503 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
504 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
506 hw->radiotap_timestamp.units_pos =
507 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
508 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
509 /* this is the case for CCK frames, it's better (only 8) for OFDM */
510 hw->radiotap_timestamp.accuracy = 22;
512 if (!iwl_mvm_has_tlc_offload(mvm))
513 hw->rate_control_algorithm = RS_NAME;
515 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
516 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
517 hw->max_tx_fragments = mvm->trans->max_skb_frags;
519 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
520 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
521 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
522 hw->wiphy->cipher_suites = mvm->ciphers;
524 if (iwl_mvm_has_new_rx_api(mvm)) {
525 mvm->ciphers[hw->wiphy->n_cipher_suites] =
526 WLAN_CIPHER_SUITE_GCMP;
527 hw->wiphy->n_cipher_suites++;
528 mvm->ciphers[hw->wiphy->n_cipher_suites] =
529 WLAN_CIPHER_SUITE_GCMP_256;
530 hw->wiphy->n_cipher_suites++;
533 /* Enable 11w if software crypto is not enabled (as the
534 * firmware will interpret some mgmt packets, so enabling it
535 * with software crypto isn't safe).
537 if (!iwlwifi_mod_params.swcrypto) {
538 ieee80211_hw_set(hw, MFP_CAPABLE);
539 mvm->ciphers[hw->wiphy->n_cipher_suites] =
540 WLAN_CIPHER_SUITE_AES_CMAC;
541 hw->wiphy->n_cipher_suites++;
542 if (iwl_mvm_has_new_rx_api(mvm)) {
543 mvm->ciphers[hw->wiphy->n_cipher_suites] =
544 WLAN_CIPHER_SUITE_BIP_GMAC_128;
545 hw->wiphy->n_cipher_suites++;
546 mvm->ciphers[hw->wiphy->n_cipher_suites] =
547 WLAN_CIPHER_SUITE_BIP_GMAC_256;
548 hw->wiphy->n_cipher_suites++;
552 /* currently FW API supports only one optional cipher scheme */
553 if (mvm->fw->cs[0].cipher) {
554 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
555 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
557 mvm->hw->n_cipher_schemes = 1;
559 cs->cipher = le32_to_cpu(fwcs->cipher);
560 cs->iftype = BIT(NL80211_IFTYPE_STATION);
561 cs->hdr_len = fwcs->hdr_len;
562 cs->pn_len = fwcs->pn_len;
563 cs->pn_off = fwcs->pn_off;
564 cs->key_idx_off = fwcs->key_idx_off;
565 cs->key_idx_mask = fwcs->key_idx_mask;
566 cs->key_idx_shift = fwcs->key_idx_shift;
567 cs->mic_len = fwcs->mic_len;
569 mvm->hw->cipher_schemes = mvm->cs;
570 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
571 hw->wiphy->n_cipher_suites++;
574 if (fw_has_capa(&mvm->fw->ucode_capa,
575 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
576 wiphy_ext_feature_set(hw->wiphy,
577 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
578 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
581 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
582 hw->wiphy->features |=
583 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
584 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
585 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
587 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
588 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
589 hw->chanctx_data_size = sizeof(u16);
590 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
592 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
593 BIT(NL80211_IFTYPE_P2P_CLIENT) |
594 BIT(NL80211_IFTYPE_AP) |
595 BIT(NL80211_IFTYPE_P2P_GO) |
596 BIT(NL80211_IFTYPE_P2P_DEVICE) |
597 BIT(NL80211_IFTYPE_ADHOC);
599 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
600 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
601 if (iwl_mvm_is_lar_supported(mvm))
602 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
604 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
605 REGULATORY_DISABLE_BEACON_HINTS;
607 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
608 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
610 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
611 hw->wiphy->n_iface_combinations =
612 ARRAY_SIZE(iwl_mvm_iface_combinations);
614 hw->wiphy->max_remain_on_channel_duration = 10000;
615 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
617 /* Extract MAC address */
618 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
619 hw->wiphy->addresses = mvm->addresses;
620 hw->wiphy->n_addresses = 1;
622 /* Extract additional MAC addresses if available */
623 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
624 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
626 for (i = 1; i < num_mac; i++) {
627 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
629 mvm->addresses[i].addr[5]++;
630 hw->wiphy->n_addresses++;
633 iwl_mvm_reset_phy_ctxts(mvm);
635 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
637 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
639 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
640 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
641 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
643 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
644 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
646 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
648 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
649 hw->wiphy->bands[NL80211_BAND_2GHZ] =
650 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
651 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
652 hw->wiphy->bands[NL80211_BAND_5GHZ] =
653 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
655 if (fw_has_capa(&mvm->fw->ucode_capa,
656 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
657 fw_has_api(&mvm->fw->ucode_capa,
658 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
659 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
660 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
663 hw->wiphy->hw_version = mvm->trans->hw_id;
665 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
666 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
668 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
670 hw->wiphy->max_sched_scan_reqs = 1;
671 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
672 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
673 /* we create the 802.11 header and zero length SSID IE. */
674 hw->wiphy->max_sched_scan_ie_len =
675 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
676 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
677 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
680 * the firmware uses u8 for num of iterations, but 0xff is saved for
681 * infinite loop, so the maximum number of iterations is actually 254.
683 hw->wiphy->max_sched_scan_plan_iterations = 254;
685 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
686 NL80211_FEATURE_LOW_PRIORITY_SCAN |
687 NL80211_FEATURE_P2P_GO_OPPPS |
688 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
689 NL80211_FEATURE_DYNAMIC_SMPS |
690 NL80211_FEATURE_STATIC_SMPS |
691 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
693 if (fw_has_capa(&mvm->fw->ucode_capa,
694 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
695 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
696 if (fw_has_capa(&mvm->fw->ucode_capa,
697 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
698 hw->wiphy->features |= NL80211_FEATURE_QUIET;
700 if (fw_has_capa(&mvm->fw->ucode_capa,
701 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
702 hw->wiphy->features |=
703 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
705 if (fw_has_capa(&mvm->fw->ucode_capa,
706 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
707 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
709 if (fw_has_api(&mvm->fw->ucode_capa,
710 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
711 wiphy_ext_feature_set(hw->wiphy,
712 NL80211_EXT_FEATURE_SCAN_START_TIME);
713 wiphy_ext_feature_set(hw->wiphy,
714 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
715 wiphy_ext_feature_set(hw->wiphy,
716 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
719 if (iwl_mvm_is_oce_supported(mvm)) {
720 wiphy_ext_feature_set(hw->wiphy,
721 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
722 wiphy_ext_feature_set(hw->wiphy,
723 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
724 wiphy_ext_feature_set(hw->wiphy,
725 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
726 wiphy_ext_feature_set(hw->wiphy,
727 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
730 if (mvm->nvm_data->sku_cap_11ax_enable &&
731 !iwlwifi_mod_params.disable_11ax) {
732 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
733 hw->wiphy->num_iftype_ext_capab =
734 ARRAY_SIZE(he_iftypes_ext_capa);
737 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
739 #ifdef CONFIG_PM_SLEEP
740 if (iwl_mvm_is_d0i3_supported(mvm) &&
741 device_can_wakeup(mvm->trans->dev)) {
742 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
743 hw->wiphy->wowlan = &mvm->wowlan;
746 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
747 mvm->trans->ops->d3_suspend &&
748 mvm->trans->ops->d3_resume &&
749 device_can_wakeup(mvm->trans->dev)) {
750 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
751 WIPHY_WOWLAN_DISCONNECT |
752 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
753 WIPHY_WOWLAN_RFKILL_RELEASE |
754 WIPHY_WOWLAN_NET_DETECT;
755 if (!iwlwifi_mod_params.swcrypto)
756 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
757 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
758 WIPHY_WOWLAN_4WAY_HANDSHAKE;
760 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
761 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
762 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
763 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
764 hw->wiphy->wowlan = &mvm->wowlan;
768 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
769 /* assign default bcast filtering configuration */
770 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
773 ret = iwl_mvm_leds_init(mvm);
777 if (fw_has_capa(&mvm->fw->ucode_capa,
778 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
779 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
780 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
781 ieee80211_hw_set(hw, TDLS_WIDER_BW);
784 if (fw_has_capa(&mvm->fw->ucode_capa,
785 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
786 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
787 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
790 hw->netdev_features |= mvm->cfg->features;
791 if (!iwl_mvm_is_csum_supported(mvm)) {
792 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
794 /* We may support SW TX CSUM */
795 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
796 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
799 if (mvm->cfg->vht_mu_mimo_supported)
800 wiphy_ext_feature_set(hw->wiphy,
801 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
803 ret = ieee80211_register_hw(mvm->hw);
805 iwl_mvm_leds_exit(mvm);
811 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
812 struct ieee80211_sta *sta,
815 struct iwl_mvm_sta *mvmsta;
819 * double check the IN_D0I3 flag both before and after
820 * taking the spinlock, in order to prevent taking
821 * the spinlock when not needed.
823 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
826 spin_lock(&mvm->d0i3_tx_lock);
828 * testing the flag again ensures the skb dequeue
829 * loop (on d0i3 exit) hasn't run yet.
831 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
834 mvmsta = iwl_mvm_sta_from_mac80211(sta);
835 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
836 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
839 __skb_queue_tail(&mvm->d0i3_tx, skb);
842 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
843 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
847 spin_unlock(&mvm->d0i3_tx_lock);
851 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
852 struct ieee80211_tx_control *control,
855 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
856 struct ieee80211_sta *sta = control->sta;
857 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
858 struct ieee80211_hdr *hdr = (void *)skb->data;
859 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
860 IEEE80211_TX_CTL_TX_OFFCHAN;
862 if (iwl_mvm_is_radio_killed(mvm)) {
863 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
868 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
869 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
872 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
873 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
874 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
875 ieee80211_is_mgmt(hdr->frame_control) &&
876 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
879 /* If there is no sta, and it's not offchannel - send through AP */
880 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
882 struct iwl_mvm_vif *mvmvif =
883 iwl_mvm_vif_from_mac80211(info->control.vif);
884 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
886 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
887 /* mac80211 holds rcu read lock */
888 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
889 if (IS_ERR_OR_NULL(sta))
895 if (iwl_mvm_defer_tx(mvm, sta, skb))
897 if (iwl_mvm_tx_skb(mvm, skb, sta))
902 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
906 ieee80211_free_txskb(hw, skb);
909 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
911 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
912 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
913 struct sk_buff *skb = NULL;
916 * No need for threads to be pending here, they can leave the first
917 * taker all the work.
919 * mvmtxq->tx_request logic:
921 * If 0, no one is currently TXing, set to 1 to indicate current thread
922 * will now start TX and other threads should quit.
924 * If 1, another thread is currently TXing, set to 2 to indicate to
925 * that thread that there was another request. Since that request may
926 * have raced with the check whether the queue is empty, the TXing
927 * thread should check the queue's status one more time before leaving.
928 * This check is done in order to not leave any TX hanging in the queue
929 * until the next TX invocation (which may not even happen).
931 * If 2, another thread is currently TXing, and it will already double
932 * check the queue, so do nothing.
934 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
939 while (likely(!mvmtxq->stopped &&
940 (mvm->trans->system_pm_mode ==
941 IWL_PLAT_PM_MODE_DISABLED))) {
942 skb = ieee80211_tx_dequeue(hw, txq);
947 "TXQ of sta %pM tid %d is now empty\n",
954 iwl_mvm_tx_skb_non_sta(mvm, skb);
956 iwl_mvm_tx_skb(mvm, skb, txq->sta);
958 } while (atomic_dec_return(&mvmtxq->tx_request));
962 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
963 struct ieee80211_txq *txq)
965 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
966 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
969 * Please note that racing is handled very carefully here:
970 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
971 * deleted afterwards.
972 * This means that if:
973 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
974 * queue is allocated and we can TX.
975 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
976 * a race, should defer the frame.
977 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
978 * need to allocate the queue and defer the frame.
979 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
980 * queue is already scheduled for allocation, no need to allocate,
981 * should defer the frame.
984 /* If the queue is allocated TX and return. */
985 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
987 * Check that list is empty to avoid a race where txq_id is
988 * already updated, but the queue allocation work wasn't
991 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
994 iwl_mvm_mac_itxq_xmit(hw, txq);
998 /* The list is being deleted only after the queue is fully allocated. */
999 if (!list_empty(&mvmtxq->list))
1002 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
1003 schedule_work(&mvm->add_stream_wk);
1006 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
1008 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
1010 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
1014 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1015 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
1016 enum ieee80211_ampdu_mlme_action action)
1018 struct iwl_fw_dbg_trigger_tlv *trig;
1019 struct iwl_fw_dbg_trigger_ba *ba_trig;
1021 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
1026 ba_trig = (void *)trig->data;
1029 case IEEE80211_AMPDU_TX_OPERATIONAL: {
1030 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1031 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1033 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
1034 "TX AGG START: MAC %pM tid %d ssn %d\n",
1035 sta->addr, tid, tid_data->ssn);
1038 case IEEE80211_AMPDU_TX_STOP_CONT:
1039 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
1040 "TX AGG STOP: MAC %pM tid %d\n",
1043 case IEEE80211_AMPDU_RX_START:
1044 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
1045 "RX AGG START: MAC %pM tid %d ssn %d\n",
1046 sta->addr, tid, rx_ba_ssn);
1048 case IEEE80211_AMPDU_RX_STOP:
1049 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
1050 "RX AGG STOP: MAC %pM tid %d\n",
1058 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
1059 struct ieee80211_vif *vif,
1060 struct ieee80211_ampdu_params *params)
1062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1064 bool tx_agg_ref = false;
1065 struct ieee80211_sta *sta = params->sta;
1066 enum ieee80211_ampdu_mlme_action action = params->action;
1067 u16 tid = params->tid;
1068 u16 *ssn = ¶ms->ssn;
1069 u16 buf_size = params->buf_size;
1070 bool amsdu = params->amsdu;
1071 u16 timeout = params->timeout;
1073 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
1074 sta->addr, tid, action);
1076 if (!(mvm->nvm_data->sku_cap_11n_enable))
1079 /* return from D0i3 before starting a new Tx aggregation */
1081 case IEEE80211_AMPDU_TX_START:
1082 case IEEE80211_AMPDU_TX_STOP_CONT:
1083 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1084 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1085 case IEEE80211_AMPDU_TX_OPERATIONAL:
1087 * for tx start, wait synchronously until D0i3 exit to
1088 * get the correct sequence number for the tid.
1089 * additionally, some other ampdu actions use direct
1090 * target access, which is not handled automatically
1091 * by the trans layer (unlike commands), so wait for
1092 * d0i3 exit in these cases as well.
1094 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
1104 mutex_lock(&mvm->mutex);
1107 case IEEE80211_AMPDU_RX_START:
1108 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
1109 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
1110 struct iwl_mvm_vif *mvmvif;
1111 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
1112 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
1114 mdata->opened_rx_ba_sessions = true;
1115 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1116 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
1118 if (!iwl_enable_rx_ampdu()) {
1122 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1125 case IEEE80211_AMPDU_RX_STOP:
1126 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1129 case IEEE80211_AMPDU_TX_START:
1130 if (!iwl_enable_tx_ampdu()) {
1134 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1136 case IEEE80211_AMPDU_TX_STOP_CONT:
1137 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1139 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1140 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1141 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1143 case IEEE80211_AMPDU_TX_OPERATIONAL:
1144 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1156 if (action == IEEE80211_AMPDU_RX_START)
1159 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1162 mutex_unlock(&mvm->mutex);
1165 * If the tid is marked as started, we won't use it for offloaded
1166 * traffic on the next D0i3 entry. It's safe to unref.
1169 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1174 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1175 struct ieee80211_vif *vif)
1177 struct iwl_mvm *mvm = data;
1178 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1180 mvmvif->uploaded = false;
1181 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1183 spin_lock_bh(&mvm->time_event_lock);
1184 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1185 spin_unlock_bh(&mvm->time_event_lock);
1187 mvmvif->phy_ctxt = NULL;
1188 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1189 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1192 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1194 /* clear the D3 reconfig, we only need it to avoid dumping a
1195 * firmware coredump on reconfiguration, we shouldn't do that
1196 * on D3->D0 transition
1198 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1199 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1200 iwl_fw_error_dump(&mvm->fwrt);
1203 /* cleanup all stale references (scan, roc), but keep the
1204 * ucode_down ref until reconfig is complete
1206 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1208 iwl_mvm_stop_device(mvm);
1212 mvm->scan_status = 0;
1213 mvm->ps_disabled = false;
1214 mvm->calibrating = false;
1216 /* just in case one was running */
1217 iwl_mvm_cleanup_roc_te(mvm);
1218 ieee80211_remain_on_channel_expired(mvm->hw);
1220 iwl_mvm_ftm_restart(mvm);
1223 * cleanup all interfaces, even inactive ones, as some might have
1224 * gone down during the HW restart
1226 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1228 mvm->p2p_device_vif = NULL;
1229 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1231 iwl_mvm_reset_phy_ctxts(mvm);
1232 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1233 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1234 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1236 ieee80211_wake_queues(mvm->hw);
1238 /* clear any stale d0i3 state */
1239 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1242 mvm->rx_ba_sessions = 0;
1243 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1244 mvm->monitor_on = false;
1246 /* keep statistics ticking */
1247 iwl_mvm_accu_radio_stats(mvm);
1250 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1254 lockdep_assert_held(&mvm->mutex);
1256 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1258 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1259 * so later code will - from now on - see that we're doing it.
1261 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1262 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1263 /* Clean up some internal and mac80211 state on restart */
1264 iwl_mvm_restart_cleanup(mvm);
1266 /* Hold the reference to prevent runtime suspend while
1267 * the start procedure runs. It's a bit confusing
1268 * that the UCODE_DOWN reference is taken, but it just
1269 * means "UCODE is not UP yet". ( TODO: rename this
1272 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1274 ret = iwl_mvm_up(mvm);
1276 iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_POST_INIT);
1278 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1279 /* Something went wrong - we need to finish some cleanup
1280 * that normally iwl_mvm_mac_restart_complete() below
1283 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1285 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1292 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1294 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1297 /* Some hw restart cleanups must not hold the mutex */
1298 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1300 * Make sure we are out of d0i3. This is needed
1301 * to make sure the reference accounting is correct
1302 * (and there is no stale d0i3_exit_work).
1304 wait_event_timeout(mvm->d0i3_exit_waitq,
1305 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1310 mutex_lock(&mvm->mutex);
1311 ret = __iwl_mvm_mac_start(mvm);
1312 mutex_unlock(&mvm->mutex);
1317 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1321 mutex_lock(&mvm->mutex);
1323 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1325 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1327 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1329 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1332 /* allow transport/FW low power modes */
1333 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1335 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1338 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1339 * of packets the FW sent out, so we must reconnect.
1341 iwl_mvm_teardown_tdls_peers(mvm);
1343 mutex_unlock(&mvm->mutex);
1346 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1348 if (iwl_mvm_is_d0i3_supported(mvm) &&
1349 iwl_mvm_enter_d0i3_on_suspend(mvm))
1350 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1351 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1354 "D0i3 exit on resume timed out\n");
1358 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1359 enum ieee80211_reconfig_type reconfig_type)
1361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1363 switch (reconfig_type) {
1364 case IEEE80211_RECONFIG_TYPE_RESTART:
1365 iwl_mvm_restart_complete(mvm);
1367 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1368 iwl_mvm_resume_complete(mvm);
1373 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1375 lockdep_assert_held(&mvm->mutex);
1377 /* firmware counters are obviously reset now, but we shouldn't
1378 * partially track so also clear the fw_reset_accu counters.
1380 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1382 /* async_handlers_wk is now blocked */
1385 * The work item could be running or queued if the
1386 * ROC time event stops just as we get here.
1388 flush_work(&mvm->roc_done_wk);
1390 iwl_mvm_stop_device(mvm);
1392 iwl_mvm_async_handlers_purge(mvm);
1393 /* async_handlers_list is empty and will stay empty: HW is stopped */
1395 /* the fw is stopped, the aux sta is dead: clean up driver state */
1396 iwl_mvm_del_aux_sta(mvm);
1399 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1400 * hw (as restart_complete() won't be called in this case) and mac80211
1401 * won't execute the restart.
1402 * But make sure to cleanup interfaces that have gone down before/during
1403 * HW restart was requested.
1405 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1406 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1408 ieee80211_iterate_interfaces(mvm->hw, 0,
1409 iwl_mvm_cleanup_iterator, mvm);
1411 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1412 * make sure there's nothing left there and warn if any is found.
1414 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1417 for (i = 0; i < mvm->max_scans; i++) {
1418 if (WARN_ONCE(mvm->scan_uid_status[i],
1419 "UMAC scan UID %d status was not cleaned\n",
1421 mvm->scan_uid_status[i] = 0;
1426 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1428 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1430 flush_work(&mvm->d0i3_exit_work);
1431 flush_work(&mvm->async_handlers_wk);
1432 flush_work(&mvm->add_stream_wk);
1435 * Lock and clear the firmware running bit here already, so that
1436 * new commands coming in elsewhere, e.g. from debugfs, will not
1437 * be able to proceed. This is important here because one of those
1438 * debugfs files causes the firmware dump to be triggered, and if we
1439 * don't stop debugfs accesses before canceling that it could be
1440 * retriggered after we flush it but before we've cleared the bit.
1442 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1444 iwl_fw_cancel_dump(&mvm->fwrt);
1445 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1446 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1447 iwl_fw_free_dump_desc(&mvm->fwrt);
1449 mutex_lock(&mvm->mutex);
1450 __iwl_mvm_mac_stop(mvm);
1451 mutex_unlock(&mvm->mutex);
1454 * The worker might have been waiting for the mutex, let it run and
1455 * discover that its list is now empty.
1457 cancel_work_sync(&mvm->async_handlers_wk);
1460 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1464 lockdep_assert_held(&mvm->mutex);
1466 for (i = 0; i < NUM_PHY_CTX; i++)
1467 if (!mvm->phy_ctxts[i].ref)
1468 return &mvm->phy_ctxts[i];
1470 IWL_ERR(mvm, "No available PHY context\n");
1474 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1479 struct iwl_dev_tx_power_cmd v5;
1480 struct iwl_dev_tx_power_cmd_v4 v4;
1482 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1483 .v5.v3.mac_context_id =
1484 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1485 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1488 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1489 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1491 if (fw_has_api(&mvm->fw->ucode_capa,
1492 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1493 len = sizeof(cmd.v5);
1494 else if (fw_has_capa(&mvm->fw->ucode_capa,
1495 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1496 len = sizeof(cmd.v4);
1498 len = sizeof(cmd.v4.v3);
1500 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1503 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif)
1506 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1507 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1511 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1514 * make sure D0i3 exit is completed, otherwise a target access
1515 * during tx queue configuration could be done when still in
1518 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1523 * Not much to do here. The stack will not allow interface
1524 * types or combinations that we didn't advertise, so we
1525 * don't really have to check the types.
1528 mutex_lock(&mvm->mutex);
1530 /* make sure that beacon statistics don't go backwards with FW reset */
1531 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1532 mvmvif->beacon_stats.accu_num_beacons +=
1533 mvmvif->beacon_stats.num_beacons;
1535 /* Allocate resources for the MAC context, and add it to the fw */
1536 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1540 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1542 /* Counting number of interfaces is needed for legacy PM */
1543 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1547 * The AP binding flow can be done only after the beacon
1548 * template is configured (which happens only in the mac80211
1549 * start_ap() flow), and adding the broadcast station can happen
1550 * only after the binding.
1551 * In addition, since modifying the MAC before adding a bcast
1552 * station is not allowed by the FW, delay the adding of MAC context to
1553 * the point where we can also add the bcast station.
1554 * In short: there's not much we can do at this point, other than
1555 * allocating resources :)
1557 if (vif->type == NL80211_IFTYPE_AP ||
1558 vif->type == NL80211_IFTYPE_ADHOC) {
1559 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1561 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1566 * Only queue for this station is the mcast queue,
1567 * which shouldn't be in TFD mask anyway
1569 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1575 iwl_mvm_vif_dbgfs_register(mvm, vif);
1579 mvmvif->features |= hw->netdev_features;
1581 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1585 ret = iwl_mvm_power_update_mac(mvm);
1587 goto out_remove_mac;
1589 /* beacon filtering */
1590 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1592 goto out_remove_mac;
1594 if (!mvm->bf_allowed_vif &&
1595 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1596 mvm->bf_allowed_vif = mvmvif;
1597 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1598 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1602 * P2P_DEVICE interface does not have a channel context assigned to it,
1603 * so a dedicated PHY context is allocated to it and the corresponding
1604 * MAC context is bound to it at this stage.
1606 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1608 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1609 if (!mvmvif->phy_ctxt) {
1614 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1615 ret = iwl_mvm_binding_add_vif(mvm, vif);
1619 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1623 /* Save a pointer to p2p device vif, so it can later be used to
1624 * update the p2p device MAC when a GO is started/stopped */
1625 mvm->p2p_device_vif = vif;
1628 iwl_mvm_tcm_add_vif(mvm, vif);
1630 if (vif->type == NL80211_IFTYPE_MONITOR)
1631 mvm->monitor_on = true;
1633 iwl_mvm_vif_dbgfs_register(mvm, vif);
1637 iwl_mvm_binding_remove_vif(mvm, vif);
1639 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1641 if (mvm->bf_allowed_vif == mvmvif) {
1642 mvm->bf_allowed_vif = NULL;
1643 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1644 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1647 mvmvif->phy_ctxt = NULL;
1648 iwl_mvm_mac_ctxt_remove(mvm, vif);
1650 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1653 mutex_unlock(&mvm->mutex);
1655 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1660 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1661 struct ieee80211_vif *vif)
1663 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1665 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1666 * We assume here that all the packets sent to the OFFCHANNEL
1667 * queue are sent in ROC session.
1669 flush_work(&mvm->roc_done_wk);
1673 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1674 struct ieee80211_vif *vif)
1676 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1677 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1678 struct iwl_probe_resp_data *probe_data;
1680 iwl_mvm_prepare_mac_removal(mvm, vif);
1682 if (!(vif->type == NL80211_IFTYPE_AP ||
1683 vif->type == NL80211_IFTYPE_ADHOC))
1684 iwl_mvm_tcm_rm_vif(mvm, vif);
1686 mutex_lock(&mvm->mutex);
1688 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1689 lockdep_is_held(&mvm->mutex));
1690 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1692 kfree_rcu(probe_data, rcu_head);
1694 if (mvm->bf_allowed_vif == mvmvif) {
1695 mvm->bf_allowed_vif = NULL;
1696 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1697 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1700 if (vif->bss_conf.ftm_responder)
1701 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1703 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1706 * For AP/GO interface, the tear down of the resources allocated to the
1707 * interface is be handled as part of the stop_ap flow.
1709 if (vif->type == NL80211_IFTYPE_AP ||
1710 vif->type == NL80211_IFTYPE_ADHOC) {
1711 #ifdef CONFIG_NL80211_TESTMODE
1712 if (vif == mvm->noa_vif) {
1713 mvm->noa_vif = NULL;
1714 mvm->noa_duration = 0;
1717 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1718 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1722 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1723 mvm->p2p_device_vif = NULL;
1724 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1725 iwl_mvm_binding_remove_vif(mvm, vif);
1726 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1727 mvmvif->phy_ctxt = NULL;
1730 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1733 iwl_mvm_power_update_mac(mvm);
1734 iwl_mvm_mac_ctxt_remove(mvm, vif);
1736 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1738 if (vif->type == NL80211_IFTYPE_MONITOR)
1739 mvm->monitor_on = false;
1742 mutex_unlock(&mvm->mutex);
1745 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1750 struct iwl_mvm_mc_iter_data {
1751 struct iwl_mvm *mvm;
1755 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1756 struct ieee80211_vif *vif)
1758 struct iwl_mvm_mc_iter_data *data = _data;
1759 struct iwl_mvm *mvm = data->mvm;
1760 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1761 struct iwl_host_cmd hcmd = {
1762 .id = MCAST_FILTER_CMD,
1764 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1768 /* if we don't have free ports, mcast frames will be dropped */
1769 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1772 if (vif->type != NL80211_IFTYPE_STATION ||
1773 !vif->bss_conf.assoc)
1776 cmd->port_id = data->port_id++;
1777 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1778 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1783 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1785 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1788 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1790 struct iwl_mvm_mc_iter_data iter_data = {
1794 lockdep_assert_held(&mvm->mutex);
1796 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1799 ieee80211_iterate_active_interfaces_atomic(
1800 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1801 iwl_mvm_mc_iface_iterator, &iter_data);
1804 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1805 struct netdev_hw_addr_list *mc_list)
1807 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1808 struct iwl_mcast_filter_cmd *cmd;
1809 struct netdev_hw_addr *addr;
1814 addr_count = netdev_hw_addr_list_count(mc_list);
1815 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1816 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1820 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1821 cmd = kzalloc(len, GFP_ATOMIC);
1827 return (u64)(unsigned long)cmd;
1830 netdev_hw_addr_list_for_each(addr, mc_list) {
1831 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1832 cmd->count, addr->addr);
1833 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1834 addr->addr, ETH_ALEN);
1838 return (u64)(unsigned long)cmd;
1841 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1842 unsigned int changed_flags,
1843 unsigned int *total_flags,
1846 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1847 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1849 mutex_lock(&mvm->mutex);
1851 /* replace previous configuration */
1852 kfree(mvm->mcast_filter_cmd);
1853 mvm->mcast_filter_cmd = cmd;
1858 if (changed_flags & FIF_ALLMULTI)
1859 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1864 iwl_mvm_recalc_multicast(mvm);
1866 mutex_unlock(&mvm->mutex);
1870 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1871 struct ieee80211_vif *vif,
1872 unsigned int filter_flags,
1873 unsigned int changed_flags)
1875 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1877 /* We support only filter for probe requests */
1878 if (!(changed_flags & FIF_PROBE_REQ))
1881 /* Supported only for p2p client interfaces */
1882 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1886 mutex_lock(&mvm->mutex);
1887 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1888 mutex_unlock(&mvm->mutex);
1891 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1892 struct iwl_bcast_iter_data {
1893 struct iwl_mvm *mvm;
1894 struct iwl_bcast_filter_cmd *cmd;
1899 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1900 const struct iwl_fw_bcast_filter *in_filter,
1901 struct iwl_fw_bcast_filter *out_filter)
1903 struct iwl_fw_bcast_filter_attr *attr;
1906 memcpy(out_filter, in_filter, sizeof(*out_filter));
1908 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1909 attr = &out_filter->attrs[i];
1914 switch (attr->reserved1) {
1915 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1916 if (vif->bss_conf.arp_addr_cnt != 1) {
1921 attr->val = vif->bss_conf.arp_addr_list[0];
1923 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1924 attr->val = *(__be32 *)&vif->addr[2];
1929 attr->reserved1 = 0;
1930 out_filter->num_attrs++;
1934 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1935 struct ieee80211_vif *vif)
1937 struct iwl_bcast_iter_data *data = _data;
1938 struct iwl_mvm *mvm = data->mvm;
1939 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1940 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1941 struct iwl_fw_bcast_mac *bcast_mac;
1944 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1947 bcast_mac = &cmd->macs[mvmvif->id];
1950 * enable filtering only for associated stations, but not for P2P
1953 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1954 !vif->bss_conf.assoc)
1957 bcast_mac->default_discard = 1;
1959 /* copy all configured filters */
1960 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1962 * Make sure we don't exceed our filters limit.
1963 * if there is still a valid filter to be configured,
1964 * be on the safe side and just allow bcast for this mac.
1966 if (WARN_ON_ONCE(data->current_filter >=
1967 ARRAY_SIZE(cmd->filters))) {
1968 bcast_mac->default_discard = 0;
1969 bcast_mac->attached_filters = 0;
1973 iwl_mvm_set_bcast_filter(vif,
1974 &mvm->bcast_filters[i],
1975 &cmd->filters[data->current_filter]);
1977 /* skip current filter if it contains no attributes */
1978 if (!cmd->filters[data->current_filter].num_attrs)
1981 /* attach the filter to current mac */
1982 bcast_mac->attached_filters |=
1983 cpu_to_le16(BIT(data->current_filter));
1985 data->current_filter++;
1989 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1990 struct iwl_bcast_filter_cmd *cmd)
1992 struct iwl_bcast_iter_data iter_data = {
1997 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
2000 memset(cmd, 0, sizeof(*cmd));
2001 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
2002 cmd->max_macs = ARRAY_SIZE(cmd->macs);
2004 #ifdef CONFIG_IWLWIFI_DEBUGFS
2005 /* use debugfs filters/macs if override is configured */
2006 if (mvm->dbgfs_bcast_filtering.override) {
2007 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
2008 sizeof(cmd->filters));
2009 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
2015 /* if no filters are configured, do nothing */
2016 if (!mvm->bcast_filters)
2019 /* configure and attach these filters for each associated sta vif */
2020 ieee80211_iterate_active_interfaces(
2021 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2022 iwl_mvm_bcast_filter_iterator, &iter_data);
2027 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2029 struct iwl_bcast_filter_cmd cmd;
2031 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
2034 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
2037 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
2041 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
2047 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
2048 struct ieee80211_vif *vif)
2050 struct iwl_mu_group_mgmt_cmd cmd = {};
2052 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
2053 WLAN_MEMBERSHIP_LEN);
2054 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
2055 WLAN_USER_POSITION_LEN);
2057 return iwl_mvm_send_cmd_pdu(mvm,
2058 WIDE_ID(DATA_PATH_GROUP,
2059 UPDATE_MU_GROUPS_CMD),
2060 0, sizeof(cmd), &cmd);
2063 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
2064 struct ieee80211_vif *vif)
2066 if (vif->mu_mimo_owner) {
2067 struct iwl_mu_group_mgmt_notif *notif = _data;
2070 * MU-MIMO Group Id action frame is little endian. We treat
2071 * the data received from firmware as if it came from the
2072 * action frame, so no conversion is needed.
2074 ieee80211_update_mu_groups(vif,
2075 (u8 *)¬if->membership_status,
2076 (u8 *)¬if->user_position);
2080 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2081 struct iwl_rx_cmd_buffer *rxb)
2083 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2084 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
2086 ieee80211_iterate_active_interfaces_atomic(
2087 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2088 iwl_mvm_mu_mimo_iface_iterator, notif);
2091 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
2093 u8 byte_num = ppe_pos_bit / 8;
2094 u8 bit_num = ppe_pos_bit % 8;
2099 return (ppe[byte_num] >> bit_num) &
2100 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
2103 * If bit_num > 5, we have to combine bits with next byte.
2104 * Calculate how many bits we need to take from current byte (called
2105 * here "residue_bits"), and add them to bits from next byte.
2108 residue_bits = 8 - bit_num;
2110 res = (ppe[byte_num + 1] &
2111 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
2113 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
2118 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2119 struct ieee80211_vif *vif, u8 sta_id)
2121 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2122 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
2124 .tid_limit = IWL_MAX_TID_COUNT,
2125 .bss_color = vif->bss_conf.bss_color,
2126 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2127 .frame_time_rts_th =
2128 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2130 struct ieee80211_sta *sta;
2136 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2139 WARN(1, "Can't find STA to configure HE\n");
2143 if (!sta->he_cap.has_he) {
2151 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2152 IEEE80211_HE_MAC_CAP0_HTC_HE)
2153 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2154 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2155 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2156 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2157 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2159 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2160 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2161 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2162 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2165 sta_ctxt_cmd.htc_flags |=
2166 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2167 else if (link_adap == 3)
2168 sta_ctxt_cmd.htc_flags |=
2169 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2171 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2172 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2173 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2174 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2175 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2176 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2177 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2180 * Initialize the PPE thresholds to "None" (7), as described in Table
2181 * 9-262ac of 80211.ax/D3.0.
2183 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2185 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2186 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2187 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2188 u8 nss = (sta->he_cap.ppe_thres[0] &
2189 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2190 u8 ru_index_bitmap =
2191 (sta->he_cap.ppe_thres[0] &
2192 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2193 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2194 u8 *ppe = &sta->he_cap.ppe_thres[0];
2195 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2198 * FW currently supports only nss == MAX_HE_SUPP_NSS
2200 * If nss > MAX: we can ignore values we don't support
2201 * If nss < MAX: we can set zeros in other streams
2203 if (nss > MAX_HE_SUPP_NSS) {
2204 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2206 nss = MAX_HE_SUPP_NSS;
2209 for (i = 0; i < nss; i++) {
2210 u8 ru_index_tmp = ru_index_bitmap << 1;
2213 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2215 if (!(ru_index_tmp & 1))
2218 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2219 iwl_mvm_he_get_ppe_val(ppe,
2222 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2223 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2224 iwl_mvm_he_get_ppe_val(ppe,
2227 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2231 flags |= STA_CTXT_HE_PACKET_EXT;
2232 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2233 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2234 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2238 /* Take the PPE thresholds from the nominal padding info */
2239 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2240 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2241 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2242 low_th = IWL_HE_PKT_EXT_NONE;
2243 high_th = IWL_HE_PKT_EXT_NONE;
2245 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2246 low_th = IWL_HE_PKT_EXT_BPSK;
2247 high_th = IWL_HE_PKT_EXT_NONE;
2249 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2250 low_th = IWL_HE_PKT_EXT_NONE;
2251 high_th = IWL_HE_PKT_EXT_BPSK;
2255 /* Set the PPE thresholds accordingly */
2256 if (low_th >= 0 && high_th >= 0) {
2258 (void *)sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th;
2260 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2263 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2265 pkt_ext_qam[i][bw][0] = low_th;
2266 pkt_ext_qam[i][bw][1] = high_th;
2270 flags |= STA_CTXT_HE_PACKET_EXT;
2275 /* Mark MU EDCA as enabled, unless none detected on some AC */
2276 flags |= STA_CTXT_HE_MU_EDCA_CW;
2277 for (i = 0; i < AC_NUM; i++) {
2278 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2279 &mvmvif->queue_params[i].mu_edca_param_rec;
2281 if (!mvmvif->queue_params[i].mu_edca) {
2282 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2286 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2287 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2288 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2289 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2290 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2291 cpu_to_le16(mu_edca->aifsn);
2292 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2293 cpu_to_le16(mu_edca->mu_edca_timer);
2296 if (vif->bss_conf.multi_sta_back_32bit)
2297 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2299 if (vif->bss_conf.ack_enabled)
2300 flags |= STA_CTXT_HE_ACK_ENABLED;
2302 if (vif->bss_conf.uora_exists) {
2303 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2305 sta_ctxt_cmd.rand_alloc_ecwmin =
2306 vif->bss_conf.uora_ocw_range & 0x7;
2307 sta_ctxt_cmd.rand_alloc_ecwmax =
2308 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2311 /* TODO: support Multi BSSID IE */
2313 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2315 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2316 DATA_PATH_GROUP, 0),
2317 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2318 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2321 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2322 struct ieee80211_vif *vif,
2323 struct ieee80211_bss_conf *bss_conf,
2326 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2330 * Re-calculate the tsf id, as the master-slave relations depend on the
2331 * beacon interval, which was not known when the station interface was
2334 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2335 if (vif->bss_conf.he_support &&
2336 !iwlwifi_mod_params.disable_11ax)
2337 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2339 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2342 /* Update MU EDCA params */
2343 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2344 bss_conf->assoc && vif->bss_conf.he_support &&
2345 !iwlwifi_mod_params.disable_11ax)
2346 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2349 * If we're not associated yet, take the (new) BSSID before associating
2350 * so the firmware knows. If we're already associated, then use the old
2351 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2352 * branch for disassociation below.
2354 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2355 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2357 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2359 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2361 /* after sending it once, adopt mac80211 data */
2362 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2363 mvmvif->associated = bss_conf->assoc;
2365 if (changes & BSS_CHANGED_ASSOC) {
2366 if (bss_conf->assoc) {
2367 /* clear statistics to get clean beacon counter */
2368 iwl_mvm_request_statistics(mvm, true);
2369 memset(&mvmvif->beacon_stats, 0,
2370 sizeof(mvmvif->beacon_stats));
2372 /* add quota for this interface */
2373 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2375 IWL_ERR(mvm, "failed to update quotas\n");
2379 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2382 * If we're restarting then the firmware will
2383 * obviously have lost synchronisation with
2384 * the AP. It will attempt to synchronise by
2385 * itself, but we can make it more reliable by
2386 * scheduling a session protection time event.
2388 * The firmware needs to receive a beacon to
2389 * catch up with synchronisation, use 110% of
2390 * the beacon interval.
2392 * Set a large maximum delay to allow for more
2393 * than a single interface.
2395 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2396 iwl_mvm_protect_session(mvm, vif, dur, dur,
2400 iwl_mvm_sf_update(mvm, vif, false);
2401 iwl_mvm_power_vif_assoc(mvm, vif);
2403 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2404 iwl_mvm_update_smps(mvm, vif,
2405 IWL_MVM_SMPS_REQ_PROT,
2406 IEEE80211_SMPS_DYNAMIC);
2408 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2410 * If update fails - SF might be running in associated
2411 * mode while disassociated - which is forbidden.
2413 ret = iwl_mvm_sf_update(mvm, vif, false);
2415 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2417 "Failed to update SF upon disassociation\n");
2420 * If we get an assert during the connection (after the
2421 * station has been added, but before the vif is set
2422 * to associated), mac80211 will re-add the station and
2423 * then configure the vif. Since the vif is not
2424 * associated, we would remove the station here and
2425 * this would fail the recovery.
2427 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2430 * Remove AP station now that
2431 * the MAC is unassoc
2433 ret = iwl_mvm_rm_sta_id(mvm, vif,
2437 "failed to remove AP station\n");
2439 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2440 mvm->d0i3_ap_sta_id =
2441 IWL_MVM_INVALID_STA;
2442 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2445 /* remove quota for this interface */
2446 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2448 IWL_ERR(mvm, "failed to update quotas\n");
2451 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2453 /* this will take the cleared BSSID from bss_conf */
2454 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2457 "failed to update MAC %pM (clear after unassoc)\n",
2462 * The firmware tracks the MU-MIMO group on its own.
2463 * However, on HW restart we should restore this data.
2465 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2466 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2467 ret = iwl_mvm_update_mu_groups(mvm, vif);
2470 "failed to update VHT MU_MIMO groups\n");
2473 iwl_mvm_recalc_multicast(mvm);
2474 iwl_mvm_configure_bcast_filter(mvm);
2476 /* reset rssi values */
2477 mvmvif->bf_data.ave_beacon_signal = 0;
2479 iwl_mvm_bt_coex_vif_change(mvm);
2480 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2481 IEEE80211_SMPS_AUTOMATIC);
2482 if (fw_has_capa(&mvm->fw->ucode_capa,
2483 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2484 iwl_mvm_config_scan(mvm);
2487 if (changes & BSS_CHANGED_BEACON_INFO) {
2489 * We received a beacon from the associated AP so
2490 * remove the session protection.
2492 iwl_mvm_stop_session_protection(mvm, vif);
2494 iwl_mvm_sf_update(mvm, vif, false);
2495 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2498 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2500 * Send power command on every beacon change,
2501 * because we may have not enabled beacon abort yet.
2503 BSS_CHANGED_BEACON_INFO)) {
2504 ret = iwl_mvm_power_update_mac(mvm);
2506 IWL_ERR(mvm, "failed to update power mode\n");
2509 if (changes & BSS_CHANGED_TXPOWER) {
2510 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2512 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2515 if (changes & BSS_CHANGED_CQM) {
2516 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2517 /* reset cqm events tracking */
2518 mvmvif->bf_data.last_cqm_event = 0;
2519 if (mvmvif->bf_data.bf_enabled) {
2520 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2523 "failed to update CQM thresholds\n");
2527 if (changes & BSS_CHANGED_ARP_FILTER) {
2528 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2529 iwl_mvm_configure_bcast_filter(mvm);
2533 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2534 struct ieee80211_vif *vif)
2536 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2537 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2541 * iwl_mvm_mac_ctxt_add() might read directly from the device
2542 * (the system time), so make sure it is available.
2544 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2548 mutex_lock(&mvm->mutex);
2550 /* Send the beacon template */
2551 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2556 * Re-calculate the tsf id, as the master-slave relations depend on the
2557 * beacon interval, which was not known when the AP interface was added.
2559 if (vif->type == NL80211_IFTYPE_AP)
2560 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2562 mvmvif->ap_assoc_sta_count = 0;
2564 /* Add the mac context */
2565 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2569 /* Perform the binding */
2570 ret = iwl_mvm_binding_add_vif(mvm, vif);
2575 * This is not very nice, but the simplest:
2576 * For older FWs adding the mcast sta before the bcast station may
2577 * cause assert 0x2b00.
2578 * This is fixed in later FW so make the order of removal depend on
2581 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2582 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2586 * Send the bcast station. At this stage the TBTT and DTIM time
2587 * events are added and applied to the scheduler
2589 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2591 iwl_mvm_rm_mcast_sta(mvm, vif);
2596 * Send the bcast station. At this stage the TBTT and DTIM time
2597 * events are added and applied to the scheduler
2599 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2602 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2604 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2609 /* must be set before quota calculations */
2610 mvmvif->ap_ibss_active = true;
2612 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2613 iwl_mvm_vif_set_low_latency(mvmvif, true,
2614 LOW_LATENCY_VIF_TYPE);
2615 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2618 /* power updated needs to be done before quotas */
2619 iwl_mvm_power_update_mac(mvm);
2621 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2623 goto out_quota_failed;
2625 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2626 if (vif->p2p && mvm->p2p_device_vif)
2627 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2629 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2631 iwl_mvm_bt_coex_vif_change(mvm);
2633 /* we don't support TDLS during DCM */
2634 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2635 iwl_mvm_teardown_tdls_peers(mvm);
2637 iwl_mvm_ftm_restart_responder(mvm, vif);
2642 iwl_mvm_power_update_mac(mvm);
2643 mvmvif->ap_ibss_active = false;
2644 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2645 iwl_mvm_rm_mcast_sta(mvm, vif);
2647 iwl_mvm_binding_remove_vif(mvm, vif);
2649 iwl_mvm_mac_ctxt_remove(mvm, vif);
2651 mutex_unlock(&mvm->mutex);
2652 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2656 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2657 struct ieee80211_vif *vif)
2659 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2660 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2662 iwl_mvm_prepare_mac_removal(mvm, vif);
2664 mutex_lock(&mvm->mutex);
2666 /* Handle AP stop while in CSA */
2667 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2668 iwl_mvm_remove_time_event(mvm, mvmvif,
2669 &mvmvif->time_event_data);
2670 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2671 mvmvif->csa_countdown = false;
2674 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2675 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2676 mvm->csa_tx_block_bcn_timeout = 0;
2679 mvmvif->ap_ibss_active = false;
2680 mvm->ap_last_beacon_gp2 = 0;
2682 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2683 iwl_mvm_vif_set_low_latency(mvmvif, false,
2684 LOW_LATENCY_VIF_TYPE);
2685 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2688 iwl_mvm_bt_coex_vif_change(mvm);
2690 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2692 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2693 if (vif->p2p && mvm->p2p_device_vif)
2694 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2696 iwl_mvm_update_quotas(mvm, false, NULL);
2699 * This is not very nice, but the simplest:
2700 * For older FWs removing the mcast sta before the bcast station may
2701 * cause assert 0x2b00.
2702 * This is fixed in later FW (which will stop beaconing when removing
2704 * So make the order of removal depend on the TLV
2706 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2707 iwl_mvm_rm_mcast_sta(mvm, vif);
2708 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2709 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2710 iwl_mvm_rm_mcast_sta(mvm, vif);
2711 iwl_mvm_binding_remove_vif(mvm, vif);
2713 iwl_mvm_power_update_mac(mvm);
2715 iwl_mvm_mac_ctxt_remove(mvm, vif);
2717 kfree(mvmvif->ap_wep_key);
2718 mvmvif->ap_wep_key = NULL;
2720 mutex_unlock(&mvm->mutex);
2724 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2725 struct ieee80211_vif *vif,
2726 struct ieee80211_bss_conf *bss_conf,
2729 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2731 /* Changes will be applied when the AP/IBSS is started */
2732 if (!mvmvif->ap_ibss_active)
2735 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2736 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2737 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2738 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2740 /* Need to send a new beacon template to the FW */
2741 if (changes & BSS_CHANGED_BEACON &&
2742 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2743 IWL_WARN(mvm, "Failed updating beacon data\n");
2745 if (changes & BSS_CHANGED_TXPOWER) {
2746 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2748 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2751 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2752 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2755 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2761 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2762 struct ieee80211_vif *vif,
2763 struct ieee80211_bss_conf *bss_conf,
2766 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2769 * iwl_mvm_bss_info_changed_station() might call
2770 * iwl_mvm_protect_session(), which reads directly from
2771 * the device (the system time), so make sure it is available.
2773 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2776 mutex_lock(&mvm->mutex);
2778 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2779 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2781 switch (vif->type) {
2782 case NL80211_IFTYPE_STATION:
2783 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2785 case NL80211_IFTYPE_AP:
2786 case NL80211_IFTYPE_ADHOC:
2787 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2789 case NL80211_IFTYPE_MONITOR:
2790 if (changes & BSS_CHANGED_MU_GROUPS)
2791 iwl_mvm_update_mu_groups(mvm, vif);
2794 /* shouldn't happen */
2798 mutex_unlock(&mvm->mutex);
2799 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2802 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2803 struct ieee80211_vif *vif,
2804 struct ieee80211_scan_request *hw_req)
2806 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2809 if (hw_req->req.n_channels == 0 ||
2810 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2813 mutex_lock(&mvm->mutex);
2814 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2815 mutex_unlock(&mvm->mutex);
2820 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2821 struct ieee80211_vif *vif)
2823 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2825 mutex_lock(&mvm->mutex);
2827 /* Due to a race condition, it's possible that mac80211 asks
2828 * us to stop a hw_scan when it's already stopped. This can
2829 * happen, for instance, if we stopped the scan ourselves,
2830 * called ieee80211_scan_completed() and the userspace called
2831 * cancel scan scan before ieee80211_scan_work() could run.
2832 * To handle that, simply return if the scan is not running.
2834 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2835 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2837 mutex_unlock(&mvm->mutex);
2841 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2842 struct ieee80211_sta *sta, u16 tids,
2844 enum ieee80211_frame_release_type reason,
2847 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2849 /* Called when we need to transmit (a) frame(s) from mac80211 */
2851 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2852 tids, more_data, false);
2856 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2857 struct ieee80211_sta *sta, u16 tids,
2859 enum ieee80211_frame_release_type reason,
2862 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2864 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2866 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2867 tids, more_data, true);
2870 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2871 enum sta_notify_cmd cmd,
2872 struct ieee80211_sta *sta)
2874 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2875 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2876 unsigned long txqs = 0, tids = 0;
2880 * If we have TVQM then we get too high queue numbers - luckily
2881 * we really shouldn't get here with that because such hardware
2882 * should have firmware supporting buffer station offload.
2884 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2887 spin_lock_bh(&mvmsta->lock);
2888 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2889 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2891 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2894 __set_bit(tid_data->txq_id, &txqs);
2896 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2899 __set_bit(tid, &tids);
2903 case STA_NOTIFY_SLEEP:
2904 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2905 ieee80211_sta_set_buffered(sta, tid, true);
2908 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2910 * The fw updates the STA to be asleep. Tx packets on the Tx
2911 * queues to this station will not be transmitted. The fw will
2912 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2915 case STA_NOTIFY_AWAKE:
2916 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2920 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2921 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2926 spin_unlock_bh(&mvmsta->lock);
2929 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2930 struct ieee80211_vif *vif,
2931 enum sta_notify_cmd cmd,
2932 struct ieee80211_sta *sta)
2934 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2937 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2939 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2940 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2941 struct ieee80211_sta *sta;
2942 struct iwl_mvm_sta *mvmsta;
2943 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2945 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2949 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2950 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2955 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2958 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2963 if (mvmsta->sleeping != sleeping) {
2964 mvmsta->sleeping = sleeping;
2965 __iwl_mvm_mac_sta_notify(mvm->hw,
2966 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2968 ieee80211_sta_ps_transition(sta, sleeping);
2972 switch (notif->type) {
2973 case IWL_MVM_PM_EVENT_AWAKE:
2974 case IWL_MVM_PM_EVENT_ASLEEP:
2976 case IWL_MVM_PM_EVENT_UAPSD:
2977 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2979 case IWL_MVM_PM_EVENT_PS_POLL:
2980 ieee80211_sta_pspoll(sta);
2990 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2991 struct ieee80211_vif *vif,
2992 struct ieee80211_sta *sta)
2994 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2995 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2998 * This is called before mac80211 does RCU synchronisation,
2999 * so here we already invalidate our internal RCU-protected
3000 * station pointer. The rest of the code will thus no longer
3001 * be able to find the station this way, and we don't rely
3002 * on further RCU synchronisation after the sta_state()
3003 * callback deleted the station.
3005 mutex_lock(&mvm->mutex);
3006 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
3007 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
3010 mutex_unlock(&mvm->mutex);
3013 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3018 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3019 struct iwl_mvm_tcm_mac *mdata;
3021 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
3022 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
3023 mdata->opened_rx_ba_sessions = false;
3026 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
3029 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
3030 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3035 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
3036 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3040 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
3041 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
3042 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3047 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3051 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
3052 struct ieee80211_vif *vif, u8 *peer_addr,
3053 enum nl80211_tdls_operation action)
3055 struct iwl_fw_dbg_trigger_tlv *trig;
3056 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3058 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3059 FW_DBG_TRIGGER_TDLS);
3063 tdls_trig = (void *)trig->data;
3065 if (!(tdls_trig->action_bitmap & BIT(action)))
3068 if (tdls_trig->peer_mode &&
3069 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3072 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3073 "TDLS event occurred, peer %pM, action %d",
3077 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3078 struct ieee80211_vif *vif,
3079 struct ieee80211_sta *sta,
3080 enum ieee80211_sta_state old_state,
3081 enum ieee80211_sta_state new_state)
3083 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3084 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3085 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3088 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3089 sta->addr, old_state, new_state);
3091 /* this would be a mac80211 bug ... but don't crash */
3092 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3096 * If we are in a STA removal flow and in DQA mode:
3098 * This is after the sync_rcu part, so the queues have already been
3099 * flushed. No more TXs on their way in mac80211's path, and no more in
3101 * Also, we won't be getting any new TX frames for this station.
3102 * What we might have are deferred TX frames that need to be taken care
3105 * Drop any still-queued deferred-frame before removing the STA, and
3106 * make sure the worker is no longer handling frames for this STA.
3108 if (old_state == IEEE80211_STA_NONE &&
3109 new_state == IEEE80211_STA_NOTEXIST) {
3110 flush_work(&mvm->add_stream_wk);
3113 * No need to make sure deferred TX indication is off since the
3114 * worker will already remove it if it was on
3118 mutex_lock(&mvm->mutex);
3119 /* track whether or not the station is associated */
3120 mvm_sta->sta_state = new_state;
3122 if (old_state == IEEE80211_STA_NOTEXIST &&
3123 new_state == IEEE80211_STA_NONE) {
3125 * Firmware bug - it'll crash if the beacon interval is less
3126 * than 16. We can't avoid connecting at all, so refuse the
3127 * station state change, this will cause mac80211 to abandon
3128 * attempts to connect to this AP, and eventually wpa_s will
3129 * blacklist the AP...
3131 if (vif->type == NL80211_IFTYPE_STATION &&
3132 vif->bss_conf.beacon_int < 16) {
3134 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3135 sta->addr, vif->bss_conf.beacon_int);
3142 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3143 IWL_MVM_TDLS_STA_COUNT ||
3144 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3145 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3150 ret = iwl_mvm_add_sta(mvm, vif, sta);
3151 if (sta->tdls && ret == 0) {
3152 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3153 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3154 NL80211_TDLS_SETUP);
3157 sta->max_rc_amsdu_len = 1;
3158 } else if (old_state == IEEE80211_STA_NONE &&
3159 new_state == IEEE80211_STA_AUTH) {
3161 * EBS may be disabled due to previous failures reported by FW.
3162 * Reset EBS status here assuming environment has been changed.
3164 mvm->last_ebs_successful = true;
3165 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3167 } else if (old_state == IEEE80211_STA_AUTH &&
3168 new_state == IEEE80211_STA_ASSOC) {
3169 if (vif->type == NL80211_IFTYPE_AP) {
3170 vif->bss_conf.he_support = sta->he_cap.has_he;
3171 mvmvif->ap_assoc_sta_count++;
3172 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3173 if (vif->bss_conf.he_support &&
3174 !iwlwifi_mod_params.disable_11ax)
3175 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3176 } else if (vif->type == NL80211_IFTYPE_STATION) {
3177 vif->bss_conf.he_support = sta->he_cap.has_he;
3178 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3181 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3183 ret = iwl_mvm_update_sta(mvm, vif, sta);
3184 } else if (old_state == IEEE80211_STA_ASSOC &&
3185 new_state == IEEE80211_STA_AUTHORIZED) {
3186 /* if wep is used, need to set the key for the station now */
3187 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key) {
3189 kmemdup(mvmvif->ap_wep_key,
3190 sizeof(*mvmvif->ap_wep_key) +
3191 mvmvif->ap_wep_key->keylen,
3193 if (!mvm_sta->wep_key) {
3198 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
3200 STA_KEY_IDX_INVALID);
3205 /* we don't support TDLS during DCM */
3206 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3207 iwl_mvm_teardown_tdls_peers(mvm);
3210 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3211 NL80211_TDLS_ENABLE_LINK);
3213 /* enable beacon filtering */
3214 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3216 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3218 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3219 new_state == IEEE80211_STA_ASSOC) {
3220 /* disable beacon filtering */
3221 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3223 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3226 } else if (old_state == IEEE80211_STA_ASSOC &&
3227 new_state == IEEE80211_STA_AUTH) {
3228 if (vif->type == NL80211_IFTYPE_AP) {
3229 mvmvif->ap_assoc_sta_count--;
3230 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3233 } else if (old_state == IEEE80211_STA_AUTH &&
3234 new_state == IEEE80211_STA_NONE) {
3236 } else if (old_state == IEEE80211_STA_NONE &&
3237 new_state == IEEE80211_STA_NOTEXIST) {
3238 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3240 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3241 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3242 NL80211_TDLS_DISABLE_LINK);
3245 /* Remove STA key if this is an AP using WEP */
3246 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key) {
3247 int rm_ret = iwl_mvm_remove_sta_key(mvm, vif, sta,
3252 kfree(mvm_sta->wep_key);
3253 mvm_sta->wep_key = NULL;
3257 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3264 mutex_unlock(&mvm->mutex);
3266 if (sta->tdls && ret == 0) {
3267 if (old_state == IEEE80211_STA_NOTEXIST &&
3268 new_state == IEEE80211_STA_NONE)
3269 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3270 else if (old_state == IEEE80211_STA_NONE &&
3271 new_state == IEEE80211_STA_NOTEXIST)
3272 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3278 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3280 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3282 mvm->rts_threshold = value;
3287 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3288 struct ieee80211_vif *vif,
3289 struct ieee80211_sta *sta, u32 changed)
3291 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3293 if (vif->type == NL80211_IFTYPE_STATION &&
3294 changed & IEEE80211_RC_NSS_CHANGED)
3295 iwl_mvm_sf_update(mvm, vif, false);
3298 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3299 struct ieee80211_vif *vif, u16 ac,
3300 const struct ieee80211_tx_queue_params *params)
3302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3303 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3305 mvmvif->queue_params[ac] = *params;
3308 * No need to update right away, we'll get BSS_CHANGED_QOS
3309 * The exception is P2P_DEVICE interface which needs immediate update.
3311 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3314 mutex_lock(&mvm->mutex);
3315 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3316 mutex_unlock(&mvm->mutex);
3322 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3323 struct ieee80211_vif *vif,
3326 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3327 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3328 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3331 * iwl_mvm_protect_session() reads directly from the device
3332 * (the system time), so make sure it is available.
3334 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3337 if (req_duration > duration)
3338 duration = req_duration;
3340 mutex_lock(&mvm->mutex);
3341 /* Try really hard to protect the session and hear a beacon */
3342 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3343 mutex_unlock(&mvm->mutex);
3345 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3348 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3349 struct ieee80211_vif *vif,
3350 struct cfg80211_sched_scan_request *req,
3351 struct ieee80211_scan_ies *ies)
3353 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3357 mutex_lock(&mvm->mutex);
3359 if (!vif->bss_conf.idle) {
3364 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3367 mutex_unlock(&mvm->mutex);
3371 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3372 struct ieee80211_vif *vif)
3374 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3377 mutex_lock(&mvm->mutex);
3379 /* Due to a race condition, it's possible that mac80211 asks
3380 * us to stop a sched_scan when it's already stopped. This
3381 * can happen, for instance, if we stopped the scan ourselves,
3382 * called ieee80211_sched_scan_stopped() and the userspace called
3383 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3384 * could run. To handle this, simply return if the scan is
3387 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3388 mutex_unlock(&mvm->mutex);
3392 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3393 mutex_unlock(&mvm->mutex);
3394 iwl_mvm_wait_for_async_handlers(mvm);
3399 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3400 enum set_key_cmd cmd,
3401 struct ieee80211_vif *vif,
3402 struct ieee80211_sta *sta,
3403 struct ieee80211_key_conf *key)
3405 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3406 struct iwl_mvm_sta *mvmsta;
3407 struct iwl_mvm_key_pn *ptk_pn;
3408 int keyidx = key->keyidx;
3412 if (iwlwifi_mod_params.swcrypto) {
3413 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3417 switch (key->cipher) {
3418 case WLAN_CIPHER_SUITE_TKIP:
3419 if (!mvm->trans->cfg->gen2) {
3420 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3421 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3422 } else if (vif->type == NL80211_IFTYPE_STATION) {
3423 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3425 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3429 case WLAN_CIPHER_SUITE_CCMP:
3430 case WLAN_CIPHER_SUITE_GCMP:
3431 case WLAN_CIPHER_SUITE_GCMP_256:
3432 if (!iwl_mvm_has_new_tx_api(mvm))
3433 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3435 case WLAN_CIPHER_SUITE_AES_CMAC:
3436 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3437 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3438 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3440 case WLAN_CIPHER_SUITE_WEP40:
3441 case WLAN_CIPHER_SUITE_WEP104:
3442 if (vif->type == NL80211_IFTYPE_AP) {
3443 struct iwl_mvm_vif *mvmvif =
3444 iwl_mvm_vif_from_mac80211(vif);
3446 mvmvif->ap_wep_key = kmemdup(key,
3447 sizeof(*key) + key->keylen,
3449 if (!mvmvif->ap_wep_key)
3453 if (vif->type != NL80211_IFTYPE_STATION)
3457 /* currently FW supports only one optional cipher scheme */
3458 if (hw->n_cipher_schemes &&
3459 hw->cipher_schemes->cipher == key->cipher)
3460 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3465 mutex_lock(&mvm->mutex);
3469 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3470 vif->type == NL80211_IFTYPE_AP) && !sta) {
3472 * GTK on AP interface is a TX-only key, return 0;
3473 * on IBSS they're per-station and because we're lazy
3474 * we don't support them for RX, so do the same.
3475 * CMAC/GMAC in AP/IBSS modes must be done in software.
3477 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3478 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3479 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3484 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3485 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3486 !iwl_mvm_has_new_tx_api(mvm)) {
3487 key->hw_key_idx = STA_KEY_IDX_INVALID;
3492 /* During FW restart, in order to restore the state as it was,
3493 * don't try to reprogram keys we previously failed for.
3495 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3496 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3497 IWL_DEBUG_MAC80211(mvm,
3498 "skip invalid idx key programming during restart\n");
3503 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3504 sta && iwl_mvm_has_new_rx_api(mvm) &&
3505 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3506 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3507 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3508 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3509 struct ieee80211_key_seq seq;
3512 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3513 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3514 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3515 mvm->trans->num_rx_queues),
3522 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3523 ieee80211_get_key_rx_seq(key, tid, &seq);
3524 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3525 memcpy(ptk_pn->q[q].pn[tid],
3527 IEEE80211_CCMP_PN_LEN);
3530 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3533 /* in HW restart reuse the index, otherwise request a new one */
3534 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3535 key_offset = key->hw_key_idx;
3537 key_offset = STA_KEY_IDX_INVALID;
3539 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3540 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3542 IWL_WARN(mvm, "set key failed\n");
3544 * can't add key for RX, but we don't need it
3545 * in the device for TX so still return 0
3547 key->hw_key_idx = STA_KEY_IDX_INVALID;
3553 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3558 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3559 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3560 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3561 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3562 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3563 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3564 ptk_pn = rcu_dereference_protected(
3565 mvmsta->ptk_pn[keyidx],
3566 lockdep_is_held(&mvm->mutex));
3567 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3569 kfree_rcu(ptk_pn, rcu_head);
3572 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3573 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3579 mutex_unlock(&mvm->mutex);
3583 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3584 struct ieee80211_vif *vif,
3585 struct ieee80211_key_conf *keyconf,
3586 struct ieee80211_sta *sta,
3587 u32 iv32, u16 *phase1key)
3589 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3591 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3594 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3598 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3599 struct iwl_rx_packet *pkt, void *data)
3601 struct iwl_mvm *mvm =
3602 container_of(notif_wait, struct iwl_mvm, notif_wait);
3603 struct iwl_hs20_roc_res *resp;
3604 int resp_len = iwl_rx_packet_payload_len(pkt);
3605 struct iwl_mvm_time_event_data *te_data = data;
3607 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3610 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3611 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3615 resp = (void *)pkt->data;
3618 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3619 resp->status, resp->event_unique_id);
3621 te_data->uid = le32_to_cpu(resp->event_unique_id);
3622 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3625 spin_lock_bh(&mvm->time_event_lock);
3626 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3627 spin_unlock_bh(&mvm->time_event_lock);
3632 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3633 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3634 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3635 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3636 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3637 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3638 struct ieee80211_channel *channel,
3639 struct ieee80211_vif *vif,
3642 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3643 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3644 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3645 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3646 struct iwl_notification_wait wait_time_event;
3647 u32 dtim_interval = vif->bss_conf.dtim_period *
3648 vif->bss_conf.beacon_int;
3650 struct iwl_hs20_roc_req aux_roc_req = {
3651 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3653 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3654 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3656 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3657 &aux_roc_req.channel_info);
3658 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3660 /* Set the channel info data */
3661 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3662 (channel->band == NL80211_BAND_2GHZ) ?
3663 PHY_BAND_24 : PHY_BAND_5,
3664 PHY_VHT_CHANNEL_MODE20,
3667 /* Set the time and duration */
3668 tail->apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg));
3670 delay = AUX_ROC_MIN_DELAY;
3671 req_dur = MSEC_TO_TU(duration);
3674 * If we are associated we want the delay time to be at least one
3675 * dtim interval so that the FW can wait until after the DTIM and
3676 * then start the time event, this will potentially allow us to
3677 * remain off-channel for the max duration.
3678 * Since we want to use almost a whole dtim interval we would also
3679 * like the delay to be for 2-3 dtim intervals, in case there are
3680 * other time events with higher priority.
3682 if (vif->bss_conf.assoc) {
3683 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3684 /* We cannot remain off-channel longer than the DTIM interval */
3685 if (dtim_interval <= req_dur) {
3686 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3687 if (req_dur <= AUX_ROC_MIN_DURATION)
3688 req_dur = dtim_interval -
3689 AUX_ROC_MIN_SAFETY_BUFFER;
3693 tail->duration = cpu_to_le32(req_dur);
3694 tail->apply_time_max_delay = cpu_to_le32(delay);
3697 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3698 channel->hw_value, req_dur, duration, delay,
3700 /* Set the node address */
3701 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3703 lockdep_assert_held(&mvm->mutex);
3705 spin_lock_bh(&mvm->time_event_lock);
3707 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3708 spin_unlock_bh(&mvm->time_event_lock);
3713 te_data->duration = duration;
3714 te_data->id = HOT_SPOT_CMD;
3716 spin_unlock_bh(&mvm->time_event_lock);
3719 * Use a notification wait, which really just processes the
3720 * command response and doesn't wait for anything, in order
3721 * to be able to process the response and get the UID inside
3722 * the RX path. Using CMD_WANT_SKB doesn't work because it
3723 * stores the buffer and then wakes up this thread, by which
3724 * time another notification (that the time event started)
3725 * might already be processed unsuccessfully.
3727 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3728 time_event_response,
3729 ARRAY_SIZE(time_event_response),
3730 iwl_mvm_rx_aux_roc, te_data);
3732 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3736 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3737 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3741 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3742 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3743 /* should never fail */
3748 spin_lock_bh(&mvm->time_event_lock);
3749 iwl_mvm_te_clear_data(mvm, te_data);
3750 spin_unlock_bh(&mvm->time_event_lock);
3756 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3757 struct ieee80211_vif *vif,
3758 struct ieee80211_channel *channel,
3760 enum ieee80211_roc_type type)
3762 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3763 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3764 struct cfg80211_chan_def chandef;
3765 struct iwl_mvm_phy_ctxt *phy_ctxt;
3768 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3772 * Flush the done work, just in case it's still pending, so that
3773 * the work it does can complete and we can accept new frames.
3775 flush_work(&mvm->roc_done_wk);
3777 mutex_lock(&mvm->mutex);
3779 switch (vif->type) {
3780 case NL80211_IFTYPE_STATION:
3781 if (fw_has_capa(&mvm->fw->ucode_capa,
3782 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3783 /* Use aux roc framework (HS20) */
3784 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3788 IWL_ERR(mvm, "hotspot not supported\n");
3791 case NL80211_IFTYPE_P2P_DEVICE:
3795 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3800 for (i = 0; i < NUM_PHY_CTX; i++) {
3801 phy_ctxt = &mvm->phy_ctxts[i];
3802 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3805 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3807 * Unbind the P2P_DEVICE from the current PHY context,
3808 * and if the PHY context is not used remove it.
3810 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3811 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3814 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3816 /* Bind the P2P_DEVICE to the current PHY Context */
3817 mvmvif->phy_ctxt = phy_ctxt;
3819 ret = iwl_mvm_binding_add_vif(mvm, vif);
3820 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3823 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3824 goto schedule_time_event;
3828 /* Need to update the PHY context only if the ROC channel changed */
3829 if (channel == mvmvif->phy_ctxt->channel)
3830 goto schedule_time_event;
3832 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3835 * Change the PHY context configuration as it is currently referenced
3836 * only by the P2P Device MAC
3838 if (mvmvif->phy_ctxt->ref == 1) {
3839 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3845 * The PHY context is shared with other MACs. Need to remove the
3846 * P2P Device from the binding, allocate an new PHY context and
3847 * create a new binding
3849 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3855 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3858 IWL_ERR(mvm, "Failed to change PHY context\n");
3862 /* Unbind the P2P_DEVICE from the current PHY context */
3863 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3864 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3867 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3869 /* Bind the P2P_DEVICE to the new allocated PHY context */
3870 mvmvif->phy_ctxt = phy_ctxt;
3872 ret = iwl_mvm_binding_add_vif(mvm, vif);
3873 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3876 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3879 schedule_time_event:
3880 /* Schedule the time events */
3881 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3884 mutex_unlock(&mvm->mutex);
3885 IWL_DEBUG_MAC80211(mvm, "leave\n");
3889 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3891 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3893 IWL_DEBUG_MAC80211(mvm, "enter\n");
3895 mutex_lock(&mvm->mutex);
3896 iwl_mvm_stop_roc(mvm);
3897 mutex_unlock(&mvm->mutex);
3899 IWL_DEBUG_MAC80211(mvm, "leave\n");
3903 struct iwl_mvm_ftm_responder_iter_data {
3905 struct ieee80211_chanctx_conf *ctx;
3908 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
3909 struct ieee80211_vif *vif)
3911 struct iwl_mvm_ftm_responder_iter_data *data = _data;
3913 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
3914 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
3915 data->responder = true;
3918 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
3919 struct ieee80211_chanctx_conf *ctx)
3921 struct iwl_mvm_ftm_responder_iter_data data = {
3926 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
3927 IEEE80211_IFACE_ITER_NORMAL,
3928 iwl_mvm_ftm_responder_chanctx_iter,
3930 return data.responder;
3933 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3934 struct ieee80211_chanctx_conf *ctx)
3936 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3937 struct iwl_mvm_phy_ctxt *phy_ctxt;
3938 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
3939 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
3942 lockdep_assert_held(&mvm->mutex);
3944 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3946 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3952 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
3953 ctx->rx_chains_static,
3954 ctx->rx_chains_dynamic);
3956 IWL_ERR(mvm, "Failed to add PHY context\n");
3960 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3961 *phy_ctxt_id = phy_ctxt->id;
3966 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3967 struct ieee80211_chanctx_conf *ctx)
3969 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3972 mutex_lock(&mvm->mutex);
3973 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3974 mutex_unlock(&mvm->mutex);
3979 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3980 struct ieee80211_chanctx_conf *ctx)
3982 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3983 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3985 lockdep_assert_held(&mvm->mutex);
3987 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3990 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3991 struct ieee80211_chanctx_conf *ctx)
3993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3995 mutex_lock(&mvm->mutex);
3996 __iwl_mvm_remove_chanctx(mvm, ctx);
3997 mutex_unlock(&mvm->mutex);
4000 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4001 struct ieee80211_chanctx_conf *ctx,
4004 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4005 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4006 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4007 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4008 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4010 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4011 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4012 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4013 IEEE80211_CHANCTX_CHANGE_RADAR |
4014 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4015 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4016 phy_ctxt->ref, changed))
4019 mutex_lock(&mvm->mutex);
4021 /* we are only changing the min_width, may be a noop */
4022 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4023 if (phy_ctxt->width == def->width)
4026 /* we are just toggling between 20_NOHT and 20 */
4027 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4028 def->width <= NL80211_CHAN_WIDTH_20)
4032 iwl_mvm_bt_coex_vif_change(mvm);
4033 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4034 ctx->rx_chains_static,
4035 ctx->rx_chains_dynamic);
4038 mutex_unlock(&mvm->mutex);
4041 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4042 struct ieee80211_vif *vif,
4043 struct ieee80211_chanctx_conf *ctx,
4044 bool switching_chanctx)
4046 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4047 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4048 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4051 lockdep_assert_held(&mvm->mutex);
4053 mvmvif->phy_ctxt = phy_ctxt;
4055 switch (vif->type) {
4056 case NL80211_IFTYPE_AP:
4057 /* only needed if we're switching chanctx (i.e. during CSA) */
4058 if (switching_chanctx) {
4059 mvmvif->ap_ibss_active = true;
4063 case NL80211_IFTYPE_ADHOC:
4065 * The AP binding flow is handled as part of the start_ap flow
4066 * (in bss_info_changed), similarly for IBSS.
4070 case NL80211_IFTYPE_STATION:
4071 mvmvif->csa_bcn_pending = false;
4073 case NL80211_IFTYPE_MONITOR:
4074 /* always disable PS when a monitor interface is active */
4075 mvmvif->ps_disabled = true;
4082 ret = iwl_mvm_binding_add_vif(mvm, vif);
4087 * Power state must be updated before quotas,
4088 * otherwise fw will complain.
4090 iwl_mvm_power_update_mac(mvm);
4092 /* Setting the quota at this stage is only required for monitor
4093 * interfaces. For the other types, the bss_info changed flow
4094 * will handle quota settings.
4096 if (vif->type == NL80211_IFTYPE_MONITOR) {
4097 mvmvif->monitor_active = true;
4098 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4100 goto out_remove_binding;
4102 ret = iwl_mvm_add_snif_sta(mvm, vif);
4104 goto out_remove_binding;
4108 /* Handle binding during CSA */
4109 if (vif->type == NL80211_IFTYPE_AP) {
4110 iwl_mvm_update_quotas(mvm, false, NULL);
4111 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4114 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4115 mvmvif->csa_bcn_pending = true;
4117 if (!fw_has_capa(&mvm->fw->ucode_capa,
4118 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4119 u32 duration = 3 * vif->bss_conf.beacon_int;
4122 /* iwl_mvm_protect_session() reads directly from the
4123 * device (the system time), so make sure it is
4126 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
4128 goto out_remove_binding;
4130 /* Protect the session to make sure we hear the first
4131 * beacon on the new channel.
4133 iwl_mvm_protect_session(mvm, vif, duration, duration,
4134 vif->bss_conf.beacon_int / 2,
4137 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
4140 iwl_mvm_update_quotas(mvm, false, NULL);
4146 iwl_mvm_binding_remove_vif(mvm, vif);
4147 iwl_mvm_power_update_mac(mvm);
4150 mvmvif->phy_ctxt = NULL;
4153 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4154 struct ieee80211_vif *vif,
4155 struct ieee80211_chanctx_conf *ctx)
4157 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4160 mutex_lock(&mvm->mutex);
4161 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4162 mutex_unlock(&mvm->mutex);
4167 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4168 struct ieee80211_vif *vif,
4169 struct ieee80211_chanctx_conf *ctx,
4170 bool switching_chanctx)
4172 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4173 struct ieee80211_vif *disabled_vif = NULL;
4175 lockdep_assert_held(&mvm->mutex);
4177 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4179 switch (vif->type) {
4180 case NL80211_IFTYPE_ADHOC:
4182 case NL80211_IFTYPE_MONITOR:
4183 mvmvif->monitor_active = false;
4184 mvmvif->ps_disabled = false;
4185 iwl_mvm_rm_snif_sta(mvm, vif);
4187 case NL80211_IFTYPE_AP:
4188 /* This part is triggered only during CSA */
4189 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4192 mvmvif->csa_countdown = false;
4194 /* Set CS bit on all the stations */
4195 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4197 /* Save blocked iface, the timeout is set on the next beacon */
4198 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4200 mvmvif->ap_ibss_active = false;
4202 case NL80211_IFTYPE_STATION:
4203 if (!switching_chanctx)
4208 if (!fw_has_capa(&mvm->fw->ucode_capa,
4209 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4210 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4216 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4217 iwl_mvm_binding_remove_vif(mvm, vif);
4220 mvmvif->phy_ctxt = NULL;
4221 iwl_mvm_power_update_mac(mvm);
4224 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4225 struct ieee80211_vif *vif,
4226 struct ieee80211_chanctx_conf *ctx)
4228 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4230 mutex_lock(&mvm->mutex);
4231 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4232 mutex_unlock(&mvm->mutex);
4236 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4237 struct ieee80211_vif_chanctx_switch *vifs)
4241 mutex_lock(&mvm->mutex);
4242 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4243 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4245 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4247 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4251 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4255 "failed to assign new_ctx during channel switch\n");
4259 /* we don't support TDLS during DCM - can be caused by channel switch */
4260 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4261 iwl_mvm_teardown_tdls_peers(mvm);
4266 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4269 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4270 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4274 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4276 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4283 /* things keep failing, better restart the hw */
4284 iwl_mvm_nic_restart(mvm, false);
4287 mutex_unlock(&mvm->mutex);
4293 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4294 struct ieee80211_vif_chanctx_switch *vifs)
4298 mutex_lock(&mvm->mutex);
4299 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4301 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4305 "failed to assign new_ctx during channel switch\n");
4312 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4314 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4321 /* things keep failing, better restart the hw */
4322 iwl_mvm_nic_restart(mvm, false);
4325 mutex_unlock(&mvm->mutex);
4330 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4331 struct ieee80211_vif_chanctx_switch *vifs,
4333 enum ieee80211_chanctx_switch_mode mode)
4335 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4338 /* we only support a single-vif right now */
4343 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4344 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4346 case CHANCTX_SWMODE_REASSIGN_VIF:
4347 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4357 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4361 return mvm->ibss_manager;
4364 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4365 struct ieee80211_sta *sta,
4368 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4369 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4371 if (!mvm_sta || !mvm_sta->vif) {
4372 IWL_ERR(mvm, "Station is not associated to a vif\n");
4376 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4379 #ifdef CONFIG_NL80211_TESTMODE
4380 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4381 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4382 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4383 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4386 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4387 struct ieee80211_vif *vif,
4388 void *data, int len)
4390 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4394 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4399 if (!tb[IWL_MVM_TM_ATTR_CMD])
4402 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4403 case IWL_MVM_TM_CMD_SET_NOA:
4404 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4405 !vif->bss_conf.enable_beacon ||
4406 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4409 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4410 if (noa_duration >= vif->bss_conf.beacon_int)
4413 mvm->noa_duration = noa_duration;
4416 return iwl_mvm_update_quotas(mvm, true, NULL);
4417 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4418 /* must be associated client vif - ignore authorized */
4419 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4420 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4421 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4424 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4425 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4426 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4432 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4433 struct ieee80211_vif *vif,
4434 void *data, int len)
4436 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4439 mutex_lock(&mvm->mutex);
4440 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4441 mutex_unlock(&mvm->mutex);
4447 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4448 struct ieee80211_vif *vif,
4449 struct ieee80211_channel_switch *chsw)
4451 /* By implementing this operation, we prevent mac80211 from
4452 * starting its own channel switch timer, so that we can call
4453 * ieee80211_chswitch_done() ourselves at the right time
4454 * (which is when the absence time event starts).
4457 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4458 "dummy channel switch op\n");
4461 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4462 struct ieee80211_vif *vif,
4463 struct ieee80211_channel_switch *chsw)
4465 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4466 struct iwl_chan_switch_te_cmd cmd = {
4467 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4469 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4470 .tsf = cpu_to_le32(chsw->timestamp),
4471 .cs_count = chsw->count,
4474 lockdep_assert_held(&mvm->mutex);
4477 cmd.cs_delayed_bcn_count =
4478 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4480 return iwl_mvm_send_cmd_pdu(mvm,
4481 WIDE_ID(MAC_CONF_GROUP,
4482 CHANNEL_SWITCH_TIME_EVENT_CMD),
4483 0, sizeof(cmd), &cmd);
4486 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4487 struct ieee80211_vif *vif,
4488 struct ieee80211_channel_switch *chsw)
4490 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4491 struct ieee80211_vif *csa_vif;
4492 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4496 mutex_lock(&mvm->mutex);
4498 mvmvif->csa_failed = false;
4500 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4501 chsw->chandef.center_freq1);
4503 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4504 ieee80211_vif_to_wdev(vif),
4505 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4507 switch (vif->type) {
4508 case NL80211_IFTYPE_AP:
4510 rcu_dereference_protected(mvm->csa_vif,
4511 lockdep_is_held(&mvm->mutex));
4512 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4513 "Another CSA is already in progress")) {
4518 /* we still didn't unblock tx. prevent new CS meanwhile */
4519 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4520 lockdep_is_held(&mvm->mutex))) {
4525 rcu_assign_pointer(mvm->csa_vif, vif);
4527 if (WARN_ONCE(mvmvif->csa_countdown,
4528 "Previous CSA countdown didn't complete")) {
4533 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4536 case NL80211_IFTYPE_STATION:
4537 /* Schedule the time event to a bit before beacon 1,
4538 * to make sure we're in the new channel when the
4539 * GO/AP arrives. In case count <= 1 immediately schedule the
4540 * TE (this might result with some packet loss or connection
4543 if (chsw->count <= 1)
4546 apply_time = chsw->device_timestamp +
4547 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4548 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4551 iwl_mvm_csa_client_absent(mvm, vif);
4553 if (mvmvif->bf_data.bf_enabled) {
4554 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4559 if (fw_has_capa(&mvm->fw->ucode_capa,
4560 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4561 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4563 iwl_mvm_schedule_csa_period(mvm, vif,
4564 vif->bss_conf.beacon_int,
4571 mvmvif->ps_disabled = true;
4573 ret = iwl_mvm_power_update_ps(mvm);
4577 /* we won't be on this channel any longer */
4578 iwl_mvm_teardown_tdls_peers(mvm);
4581 mutex_unlock(&mvm->mutex);
4586 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4587 struct ieee80211_vif *vif)
4589 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4590 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4593 mutex_lock(&mvm->mutex);
4595 if (mvmvif->csa_failed) {
4596 mvmvif->csa_failed = false;
4601 if (vif->type == NL80211_IFTYPE_STATION) {
4602 struct iwl_mvm_sta *mvmsta;
4604 mvmvif->csa_bcn_pending = false;
4605 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4608 if (WARN_ON(!mvmsta)) {
4613 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4615 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4617 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4621 iwl_mvm_stop_session_protection(mvm, vif);
4624 mvmvif->ps_disabled = false;
4626 ret = iwl_mvm_power_update_ps(mvm);
4629 mutex_unlock(&mvm->mutex);
4634 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4635 struct ieee80211_vif *vif,
4636 struct ieee80211_channel_switch *chsw)
4638 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4639 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4640 struct iwl_chan_switch_te_cmd cmd = {
4641 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4643 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4644 .tsf = cpu_to_le32(chsw->timestamp),
4645 .cs_count = chsw->count,
4648 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4651 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id);
4653 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4654 WIDE_ID(MAC_CONF_GROUP,
4655 CHANNEL_SWITCH_TIME_EVENT_CMD),
4656 CMD_ASYNC, sizeof(cmd), &cmd));
4659 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
4660 struct ieee80211_vif *vif)
4662 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4663 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4664 struct iwl_chan_switch_te_cmd cmd = {
4665 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4667 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
4670 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
4672 mutex_lock(&mvm->mutex);
4673 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4674 WIDE_ID(MAC_CONF_GROUP,
4675 CHANNEL_SWITCH_TIME_EVENT_CMD),
4676 0, sizeof(cmd), &cmd));
4677 mutex_unlock(&mvm->mutex);
4679 WARN_ON(iwl_mvm_post_channel_switch(hw, vif));
4682 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4686 if (!iwl_mvm_has_new_tx_api(mvm)) {
4688 mutex_lock(&mvm->mutex);
4689 iwl_mvm_flush_tx_path(mvm,
4690 iwl_mvm_flushable_queues(mvm) & queues, 0);
4691 mutex_unlock(&mvm->mutex);
4693 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4698 mutex_lock(&mvm->mutex);
4699 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4700 struct ieee80211_sta *sta;
4702 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4703 lockdep_is_held(&mvm->mutex));
4704 if (IS_ERR_OR_NULL(sta))
4708 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4710 iwl_mvm_wait_sta_queues_empty(mvm,
4711 iwl_mvm_sta_from_mac80211(sta));
4713 mutex_unlock(&mvm->mutex);
4716 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4717 struct ieee80211_vif *vif, u32 queues, bool drop)
4719 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4720 struct iwl_mvm_vif *mvmvif;
4721 struct iwl_mvm_sta *mvmsta;
4722 struct ieee80211_sta *sta;
4727 iwl_mvm_flush_no_vif(mvm, queues, drop);
4731 if (vif->type != NL80211_IFTYPE_STATION)
4734 /* Make sure we're done with the deferred traffic before flushing */
4735 flush_work(&mvm->add_stream_wk);
4737 mutex_lock(&mvm->mutex);
4738 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4740 /* flush the AP-station and all TDLS peers */
4741 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4742 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4743 lockdep_is_held(&mvm->mutex));
4744 if (IS_ERR_OR_NULL(sta))
4747 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4748 if (mvmsta->vif != vif)
4751 /* make sure only TDLS peers or the AP are flushed */
4752 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4755 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4756 IWL_ERR(mvm, "flush request fail\n");
4758 msk |= mvmsta->tfd_queue_msk;
4759 if (iwl_mvm_has_new_tx_api(mvm))
4760 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4764 mutex_unlock(&mvm->mutex);
4766 /* this can take a while, and we may need/want other operations
4767 * to succeed while doing this, so do it without the mutex held
4769 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4770 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4773 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4774 struct survey_info *survey)
4776 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4779 memset(survey, 0, sizeof(*survey));
4781 /* only support global statistics right now */
4785 if (!fw_has_capa(&mvm->fw->ucode_capa,
4786 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4789 mutex_lock(&mvm->mutex);
4791 if (iwl_mvm_firmware_running(mvm)) {
4792 ret = iwl_mvm_request_statistics(mvm, false);
4797 survey->filled = SURVEY_INFO_TIME |
4798 SURVEY_INFO_TIME_RX |
4799 SURVEY_INFO_TIME_TX |
4800 SURVEY_INFO_TIME_SCAN;
4801 survey->time = mvm->accu_radio_stats.on_time_rf +
4802 mvm->radio_stats.on_time_rf;
4803 do_div(survey->time, USEC_PER_MSEC);
4805 survey->time_rx = mvm->accu_radio_stats.rx_time +
4806 mvm->radio_stats.rx_time;
4807 do_div(survey->time_rx, USEC_PER_MSEC);
4809 survey->time_tx = mvm->accu_radio_stats.tx_time +
4810 mvm->radio_stats.tx_time;
4811 do_div(survey->time_tx, USEC_PER_MSEC);
4813 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4814 mvm->radio_stats.on_time_scan;
4815 do_div(survey->time_scan, USEC_PER_MSEC);
4819 mutex_unlock(&mvm->mutex);
4823 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4824 struct ieee80211_vif *vif,
4825 struct ieee80211_sta *sta,
4826 struct station_info *sinfo)
4828 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4829 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4830 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4832 if (mvmsta->avg_energy) {
4833 sinfo->signal_avg = mvmsta->avg_energy;
4834 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4837 /* if beacon filtering isn't on mac80211 does it anyway */
4838 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4841 if (!vif->bss_conf.assoc)
4844 mutex_lock(&mvm->mutex);
4846 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4849 if (iwl_mvm_request_statistics(mvm, false))
4852 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4853 mvmvif->beacon_stats.accu_num_beacons;
4854 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4855 if (mvmvif->beacon_stats.avg_signal) {
4856 /* firmware only reports a value after RXing a few beacons */
4857 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4858 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4861 mutex_unlock(&mvm->mutex);
4864 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4865 struct ieee80211_vif *vif,
4866 const struct ieee80211_event *event)
4868 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4870 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4872 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4875 struct iwl_fw_dbg_trigger_tlv *trig;
4876 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4878 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4879 FW_DBG_TRIGGER_MLME);
4883 trig_mlme = (void *)trig->data;
4885 if (event->u.mlme.data == ASSOC_EVENT) {
4886 if (event->u.mlme.status == MLME_DENIED)
4887 CHECK_MLME_TRIGGER(stop_assoc_denied,
4888 "DENIED ASSOC: reason %d",
4889 event->u.mlme.reason);
4890 else if (event->u.mlme.status == MLME_TIMEOUT)
4891 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4893 } else if (event->u.mlme.data == AUTH_EVENT) {
4894 if (event->u.mlme.status == MLME_DENIED)
4895 CHECK_MLME_TRIGGER(stop_auth_denied,
4896 "DENIED AUTH: reason %d",
4897 event->u.mlme.reason);
4898 else if (event->u.mlme.status == MLME_TIMEOUT)
4899 CHECK_MLME_TRIGGER(stop_auth_timeout,
4901 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4902 CHECK_MLME_TRIGGER(stop_rx_deauth,
4903 "DEAUTH RX %d", event->u.mlme.reason);
4904 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4905 CHECK_MLME_TRIGGER(stop_tx_deauth,
4906 "DEAUTH TX %d", event->u.mlme.reason);
4908 #undef CHECK_MLME_TRIGGER
4911 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4912 struct ieee80211_vif *vif,
4913 const struct ieee80211_event *event)
4915 struct iwl_fw_dbg_trigger_tlv *trig;
4916 struct iwl_fw_dbg_trigger_ba *ba_trig;
4918 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4923 ba_trig = (void *)trig->data;
4925 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4928 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4929 "BAR received from %pM, tid %d, ssn %d",
4930 event->u.ba.sta->addr, event->u.ba.tid,
4934 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4935 struct ieee80211_vif *vif,
4936 const struct ieee80211_event *event)
4938 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4940 switch (event->type) {
4942 iwl_mvm_event_mlme_callback(mvm, vif, event);
4945 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4947 case BA_FRAME_TIMEOUT:
4948 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4956 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4957 struct iwl_mvm_internal_rxq_notif *notif,
4960 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4963 lockdep_assert_held(&mvm->mutex);
4965 if (!iwl_mvm_has_new_rx_api(mvm))
4968 notif->cookie = mvm->queue_sync_cookie;
4971 atomic_set(&mvm->queue_sync_counter,
4972 mvm->trans->num_rx_queues);
4974 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4976 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4981 ret = wait_event_timeout(mvm->rx_sync_waitq,
4982 atomic_read(&mvm->queue_sync_counter) == 0 ||
4983 iwl_mvm_is_radio_killed(mvm),
4985 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4989 atomic_set(&mvm->queue_sync_counter, 0);
4990 mvm->queue_sync_cookie++;
4993 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4995 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4996 struct iwl_mvm_internal_rxq_notif data = {
4997 .type = IWL_MVM_RXQ_EMPTY,
5001 mutex_lock(&mvm->mutex);
5002 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
5003 mutex_unlock(&mvm->mutex);
5007 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5008 struct ieee80211_vif *vif,
5009 struct cfg80211_ftm_responder_stats *stats)
5011 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5012 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5014 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5015 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5018 mutex_lock(&mvm->mutex);
5019 *stats = mvm->ftm_resp_stats;
5020 mutex_unlock(&mvm->mutex);
5022 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5023 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5024 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5025 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5026 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5027 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5028 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5029 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5030 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5035 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5036 struct ieee80211_vif *vif,
5037 struct cfg80211_pmsr_request *request)
5039 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5042 mutex_lock(&mvm->mutex);
5043 ret = iwl_mvm_ftm_start(mvm, vif, request);
5044 mutex_unlock(&mvm->mutex);
5049 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5050 struct ieee80211_vif *vif,
5051 struct cfg80211_pmsr_request *request)
5053 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5055 mutex_lock(&mvm->mutex);
5056 iwl_mvm_ftm_abort(mvm, request);
5057 mutex_unlock(&mvm->mutex);
5060 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5062 u8 protocol = ip_hdr(skb)->protocol;
5064 if (!IS_ENABLED(CONFIG_INET))
5067 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5070 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5071 struct sk_buff *head,
5072 struct sk_buff *skb)
5074 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5076 /* For now don't aggregate IPv6 in AMSDU */
5077 if (skb->protocol != htons(ETH_P_IP))
5080 if (!iwl_mvm_is_csum_supported(mvm))
5083 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5086 const struct ieee80211_ops iwl_mvm_hw_ops = {
5087 .tx = iwl_mvm_mac_tx,
5088 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5089 .ampdu_action = iwl_mvm_mac_ampdu_action,
5090 .start = iwl_mvm_mac_start,
5091 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5092 .stop = iwl_mvm_mac_stop,
5093 .add_interface = iwl_mvm_mac_add_interface,
5094 .remove_interface = iwl_mvm_mac_remove_interface,
5095 .config = iwl_mvm_mac_config,
5096 .prepare_multicast = iwl_mvm_prepare_multicast,
5097 .configure_filter = iwl_mvm_configure_filter,
5098 .config_iface_filter = iwl_mvm_config_iface_filter,
5099 .bss_info_changed = iwl_mvm_bss_info_changed,
5100 .hw_scan = iwl_mvm_mac_hw_scan,
5101 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5102 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5103 .sta_state = iwl_mvm_mac_sta_state,
5104 .sta_notify = iwl_mvm_mac_sta_notify,
5105 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5106 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5107 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5108 .sta_rc_update = iwl_mvm_sta_rc_update,
5109 .conf_tx = iwl_mvm_mac_conf_tx,
5110 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5111 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5112 .flush = iwl_mvm_mac_flush,
5113 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5114 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5115 .set_key = iwl_mvm_mac_set_key,
5116 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5117 .remain_on_channel = iwl_mvm_roc,
5118 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5119 .add_chanctx = iwl_mvm_add_chanctx,
5120 .remove_chanctx = iwl_mvm_remove_chanctx,
5121 .change_chanctx = iwl_mvm_change_chanctx,
5122 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5123 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5124 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5126 .start_ap = iwl_mvm_start_ap_ibss,
5127 .stop_ap = iwl_mvm_stop_ap_ibss,
5128 .join_ibss = iwl_mvm_start_ap_ibss,
5129 .leave_ibss = iwl_mvm_stop_ap_ibss,
5131 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5133 .set_tim = iwl_mvm_set_tim,
5135 .channel_switch = iwl_mvm_channel_switch,
5136 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5137 .post_channel_switch = iwl_mvm_post_channel_switch,
5138 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5139 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5141 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5142 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5143 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5145 .event_callback = iwl_mvm_mac_event_callback,
5147 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5149 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5151 #ifdef CONFIG_PM_SLEEP
5153 .suspend = iwl_mvm_suspend,
5154 .resume = iwl_mvm_resume,
5155 .set_wakeup = iwl_mvm_set_wakeup,
5156 .set_rekey_data = iwl_mvm_set_rekey_data,
5157 #if IS_ENABLED(CONFIG_IPV6)
5158 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5160 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5162 .get_survey = iwl_mvm_mac_get_survey,
5163 .sta_statistics = iwl_mvm_mac_sta_statistics,
5164 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5165 .start_pmsr = iwl_mvm_start_pmsr,
5166 .abort_pmsr = iwl_mvm_abort_pmsr,
5168 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5169 #ifdef CONFIG_IWLWIFI_DEBUGFS
5170 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,