1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
27 * The full GNU General Public License is included in this distribution
28 * in the file called COPYING.
30 * Contact Information:
31 * Intel Linux Wireless <linuxwifi@intel.com>
32 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * Copyright(c) 2018 Intel Corporation
40 * All rights reserved.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
46 * * Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * * Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in
50 * the documentation and/or other materials provided with the
52 * * Neither the name Intel Corporation nor the names of its
53 * contributors may be used to endorse or promote products derived
54 * from this software without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
57 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
58 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
59 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
60 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 *****************************************************************************/
69 #include <linux/kernel.h>
70 #include <linux/slab.h>
71 #include <linux/skbuff.h>
72 #include <linux/netdevice.h>
73 #include <linux/etherdevice.h>
75 #include <linux/if_arp.h>
76 #include <linux/time.h>
77 #include <net/mac80211.h>
78 #include <net/ieee80211_radiotap.h>
81 #include "iwl-op-mode.h"
85 #include "time-event.h"
86 #include "iwl-eeprom-parse.h"
87 #include "iwl-phy-db.h"
89 #include "fw/error-dump.h"
91 #include "iwl-nvm-parse.h"
93 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
96 .types = BIT(NL80211_IFTYPE_STATION),
100 .types = BIT(NL80211_IFTYPE_AP) |
101 BIT(NL80211_IFTYPE_P2P_CLIENT) |
102 BIT(NL80211_IFTYPE_P2P_GO),
106 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
110 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
112 .num_different_channels = 2,
114 .limits = iwl_mvm_limits,
115 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
119 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
121 * Use the reserved field to indicate magic values.
122 * these values will only be used internally by the driver,
123 * and won't make it to the fw (reserved will be 0).
124 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
125 * be the vif's ip address. in case there is not a single
126 * ip address (0, or more than 1), this attribute will
128 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
129 * the LSB bytes of the vif's mac address
132 BC_FILTER_MAGIC_NONE = 0,
137 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
141 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
144 /* frame type - arp, hw type - ethernet */
146 BCAST_FILTER_OFFSET_PAYLOAD_START,
147 .offset = sizeof(rfc1042_header),
148 .val = cpu_to_be32(0x08060001),
149 .mask = cpu_to_be32(0xffffffff),
154 BCAST_FILTER_OFFSET_PAYLOAD_START,
155 .offset = sizeof(rfc1042_header) + 2 +
156 sizeof(struct arphdr) +
157 ETH_ALEN + sizeof(__be32) +
159 .mask = cpu_to_be32(0xffffffff),
160 /* mark it as special field */
161 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
166 /* dhcp offer bcast */
168 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
171 /* udp dest port - 68 (bootp client)*/
172 .offset_type = BCAST_FILTER_OFFSET_IP_END,
173 .offset = offsetof(struct udphdr, dest),
174 .val = cpu_to_be32(0x00440000),
175 .mask = cpu_to_be32(0xffff0000),
178 /* dhcp - lsb bytes of client hw address */
179 .offset_type = BCAST_FILTER_OFFSET_IP_END,
181 .mask = cpu_to_be32(0xffffffff),
182 /* mark it as special field */
183 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
187 /* last filter must be empty */
192 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
194 if (!iwl_mvm_is_d0i3_supported(mvm))
197 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
198 spin_lock_bh(&mvm->refs_lock);
199 mvm->refs[ref_type]++;
200 spin_unlock_bh(&mvm->refs_lock);
201 iwl_trans_ref(mvm->trans);
204 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
206 if (!iwl_mvm_is_d0i3_supported(mvm))
209 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
210 spin_lock_bh(&mvm->refs_lock);
211 if (WARN_ON(!mvm->refs[ref_type])) {
212 spin_unlock_bh(&mvm->refs_lock);
215 mvm->refs[ref_type]--;
216 spin_unlock_bh(&mvm->refs_lock);
217 iwl_trans_unref(mvm->trans);
220 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
221 enum iwl_mvm_ref_type except_ref)
225 if (!iwl_mvm_is_d0i3_supported(mvm))
228 spin_lock_bh(&mvm->refs_lock);
229 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
230 if (except_ref == i || !mvm->refs[i])
233 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
235 for (j = 0; j < mvm->refs[i]; j++)
236 iwl_trans_unref(mvm->trans);
239 spin_unlock_bh(&mvm->refs_lock);
242 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
247 if (!iwl_mvm_is_d0i3_supported(mvm))
250 spin_lock_bh(&mvm->refs_lock);
251 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
257 spin_unlock_bh(&mvm->refs_lock);
262 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
264 iwl_mvm_ref(mvm, ref_type);
266 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
267 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
270 iwl_mvm_unref(mvm, ref_type);
277 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
281 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
282 for (i = 0; i < NUM_PHY_CTX; i++) {
283 mvm->phy_ctxts[i].id = i;
284 mvm->phy_ctxts[i].ref = 0;
288 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
290 enum iwl_mcc_source src_id,
293 struct ieee80211_regdomain *regd = NULL;
294 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
295 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
296 struct iwl_mcc_update_resp *resp;
298 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
300 lockdep_assert_held(&mvm->mutex);
302 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
303 if (IS_ERR_OR_NULL(resp)) {
304 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
305 PTR_ERR_OR_ZERO(resp));
310 u32 status = le32_to_cpu(resp->status);
312 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
313 status == MCC_RESP_ILLEGAL);
316 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
317 __le32_to_cpu(resp->n_channels),
319 __le16_to_cpu(resp->mcc),
320 __le16_to_cpu(resp->geo_info),
321 __le16_to_cpu(resp->cap));
322 /* Store the return source id */
323 src_id = resp->source_id;
325 if (IS_ERR_OR_NULL(regd)) {
326 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
327 PTR_ERR_OR_ZERO(regd));
331 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
332 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
333 mvm->lar_regdom_set = true;
334 mvm->mcc_src = src_id;
340 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
343 struct ieee80211_regdomain *regd;
345 if (!iwl_mvm_is_lar_supported(mvm))
348 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
349 if (!IS_ERR_OR_NULL(regd)) {
350 /* only update the regulatory core if changed */
352 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
358 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
361 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
362 iwl_mvm_is_wifi_mcc_supported(mvm) ?
363 MCC_SOURCE_GET_CURRENT :
364 MCC_SOURCE_OLD_FW, changed);
367 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
369 enum iwl_mcc_source used_src;
370 struct ieee80211_regdomain *regd;
373 const struct ieee80211_regdomain *r =
374 rtnl_dereference(mvm->hw->wiphy->regd);
379 /* save the last source in case we overwrite it below */
380 used_src = mvm->mcc_src;
381 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
382 /* Notify the firmware we support wifi location updates */
383 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
384 if (!IS_ERR_OR_NULL(regd))
388 /* Now set our last stored MCC and source */
389 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
391 if (IS_ERR_OR_NULL(regd))
394 /* update cfg80211 if the regdomain was changed */
396 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
404 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
406 struct ieee80211_hw *hw = mvm->hw;
408 static const u32 mvm_ciphers[] = {
409 WLAN_CIPHER_SUITE_WEP40,
410 WLAN_CIPHER_SUITE_WEP104,
411 WLAN_CIPHER_SUITE_TKIP,
412 WLAN_CIPHER_SUITE_CCMP,
415 /* Tell mac80211 our characteristics */
416 ieee80211_hw_set(hw, SIGNAL_DBM);
417 ieee80211_hw_set(hw, SPECTRUM_MGMT);
418 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
419 ieee80211_hw_set(hw, QUEUE_CONTROL);
420 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
421 ieee80211_hw_set(hw, SUPPORTS_PS);
422 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
423 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
424 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
425 ieee80211_hw_set(hw, CONNECTION_MONITOR);
426 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
427 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
428 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
429 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
430 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
431 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
433 if (iwl_mvm_has_tlc_offload(mvm)) {
434 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
435 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
438 if (iwl_mvm_has_new_rx_api(mvm))
439 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
441 if (fw_has_capa(&mvm->fw->ucode_capa,
442 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
443 ieee80211_hw_set(hw, AP_LINK_PS);
444 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
446 * we absolutely need this for the new TX API since that comes
447 * with many more queues than the current code can deal with
448 * for station powersave
453 if (mvm->trans->num_rx_queues > 1)
454 ieee80211_hw_set(hw, USES_RSS);
456 if (mvm->trans->max_skb_frags)
457 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
459 hw->queues = IEEE80211_MAX_QUEUES;
460 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
461 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
462 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
463 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
464 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
466 hw->radiotap_timestamp.units_pos =
467 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
468 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
469 /* this is the case for CCK frames, it's better (only 8) for OFDM */
470 hw->radiotap_timestamp.accuracy = 22;
472 if (!iwl_mvm_has_tlc_offload(mvm))
473 hw->rate_control_algorithm = RS_NAME;
475 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
476 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
478 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
479 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
480 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
481 hw->wiphy->cipher_suites = mvm->ciphers;
483 if (iwl_mvm_has_new_rx_api(mvm)) {
484 mvm->ciphers[hw->wiphy->n_cipher_suites] =
485 WLAN_CIPHER_SUITE_GCMP;
486 hw->wiphy->n_cipher_suites++;
487 mvm->ciphers[hw->wiphy->n_cipher_suites] =
488 WLAN_CIPHER_SUITE_GCMP_256;
489 hw->wiphy->n_cipher_suites++;
492 /* Enable 11w if software crypto is not enabled (as the
493 * firmware will interpret some mgmt packets, so enabling it
494 * with software crypto isn't safe).
496 if (!iwlwifi_mod_params.swcrypto) {
497 ieee80211_hw_set(hw, MFP_CAPABLE);
498 mvm->ciphers[hw->wiphy->n_cipher_suites] =
499 WLAN_CIPHER_SUITE_AES_CMAC;
500 hw->wiphy->n_cipher_suites++;
501 if (iwl_mvm_has_new_rx_api(mvm)) {
502 mvm->ciphers[hw->wiphy->n_cipher_suites] =
503 WLAN_CIPHER_SUITE_BIP_GMAC_128;
504 hw->wiphy->n_cipher_suites++;
505 mvm->ciphers[hw->wiphy->n_cipher_suites] =
506 WLAN_CIPHER_SUITE_BIP_GMAC_256;
507 hw->wiphy->n_cipher_suites++;
511 /* currently FW API supports only one optional cipher scheme */
512 if (mvm->fw->cs[0].cipher) {
513 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
514 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
516 mvm->hw->n_cipher_schemes = 1;
518 cs->cipher = le32_to_cpu(fwcs->cipher);
519 cs->iftype = BIT(NL80211_IFTYPE_STATION);
520 cs->hdr_len = fwcs->hdr_len;
521 cs->pn_len = fwcs->pn_len;
522 cs->pn_off = fwcs->pn_off;
523 cs->key_idx_off = fwcs->key_idx_off;
524 cs->key_idx_mask = fwcs->key_idx_mask;
525 cs->key_idx_shift = fwcs->key_idx_shift;
526 cs->mic_len = fwcs->mic_len;
528 mvm->hw->cipher_schemes = mvm->cs;
529 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
530 hw->wiphy->n_cipher_suites++;
533 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
534 hw->wiphy->features |=
535 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
536 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
537 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
539 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
540 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
541 hw->chanctx_data_size = sizeof(u16);
543 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
544 BIT(NL80211_IFTYPE_P2P_CLIENT) |
545 BIT(NL80211_IFTYPE_AP) |
546 BIT(NL80211_IFTYPE_P2P_GO) |
547 BIT(NL80211_IFTYPE_P2P_DEVICE) |
548 BIT(NL80211_IFTYPE_ADHOC);
550 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
551 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
552 if (iwl_mvm_is_lar_supported(mvm))
553 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
555 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
556 REGULATORY_DISABLE_BEACON_HINTS;
558 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
559 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
561 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
562 hw->wiphy->n_iface_combinations =
563 ARRAY_SIZE(iwl_mvm_iface_combinations);
565 hw->wiphy->max_remain_on_channel_duration = 10000;
566 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
567 /* we can compensate an offset of up to 3 channels = 15 MHz */
568 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
570 /* Extract MAC address */
571 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
572 hw->wiphy->addresses = mvm->addresses;
573 hw->wiphy->n_addresses = 1;
575 /* Extract additional MAC addresses if available */
576 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
577 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
579 for (i = 1; i < num_mac; i++) {
580 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
582 mvm->addresses[i].addr[5]++;
583 hw->wiphy->n_addresses++;
586 iwl_mvm_reset_phy_ctxts(mvm);
588 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
590 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
592 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
593 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
594 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
596 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
597 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
599 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
601 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
602 hw->wiphy->bands[NL80211_BAND_2GHZ] =
603 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
604 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
605 hw->wiphy->bands[NL80211_BAND_5GHZ] =
606 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
608 if (fw_has_capa(&mvm->fw->ucode_capa,
609 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
610 fw_has_api(&mvm->fw->ucode_capa,
611 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
612 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
613 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
616 hw->wiphy->hw_version = mvm->trans->hw_id;
618 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
619 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
621 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
623 hw->wiphy->max_sched_scan_reqs = 1;
624 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
625 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
626 /* we create the 802.11 header and zero length SSID IE. */
627 hw->wiphy->max_sched_scan_ie_len =
628 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
629 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
630 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
633 * the firmware uses u8 for num of iterations, but 0xff is saved for
634 * infinite loop, so the maximum number of iterations is actually 254.
636 hw->wiphy->max_sched_scan_plan_iterations = 254;
638 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
639 NL80211_FEATURE_LOW_PRIORITY_SCAN |
640 NL80211_FEATURE_P2P_GO_OPPPS |
641 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
642 NL80211_FEATURE_DYNAMIC_SMPS |
643 NL80211_FEATURE_STATIC_SMPS |
644 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
646 if (fw_has_capa(&mvm->fw->ucode_capa,
647 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
648 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
649 if (fw_has_capa(&mvm->fw->ucode_capa,
650 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
651 hw->wiphy->features |= NL80211_FEATURE_QUIET;
653 if (fw_has_capa(&mvm->fw->ucode_capa,
654 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
655 hw->wiphy->features |=
656 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
658 if (fw_has_capa(&mvm->fw->ucode_capa,
659 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
660 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
662 if (fw_has_api(&mvm->fw->ucode_capa,
663 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
664 wiphy_ext_feature_set(hw->wiphy,
665 NL80211_EXT_FEATURE_SCAN_START_TIME);
666 wiphy_ext_feature_set(hw->wiphy,
667 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
668 wiphy_ext_feature_set(hw->wiphy,
669 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
672 if (iwl_mvm_is_oce_supported(mvm)) {
673 wiphy_ext_feature_set(hw->wiphy,
674 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
675 wiphy_ext_feature_set(hw->wiphy,
676 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
677 wiphy_ext_feature_set(hw->wiphy,
678 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
679 wiphy_ext_feature_set(hw->wiphy,
680 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
683 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
685 #ifdef CONFIG_PM_SLEEP
686 if (iwl_mvm_is_d0i3_supported(mvm) &&
687 device_can_wakeup(mvm->trans->dev)) {
688 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
689 hw->wiphy->wowlan = &mvm->wowlan;
692 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
693 mvm->trans->ops->d3_suspend &&
694 mvm->trans->ops->d3_resume &&
695 device_can_wakeup(mvm->trans->dev)) {
696 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
697 WIPHY_WOWLAN_DISCONNECT |
698 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
699 WIPHY_WOWLAN_RFKILL_RELEASE |
700 WIPHY_WOWLAN_NET_DETECT;
701 if (!iwlwifi_mod_params.swcrypto)
702 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
703 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
704 WIPHY_WOWLAN_4WAY_HANDSHAKE;
706 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
707 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
708 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
709 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
710 hw->wiphy->wowlan = &mvm->wowlan;
714 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
715 /* assign default bcast filtering configuration */
716 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
719 ret = iwl_mvm_leds_init(mvm);
723 if (fw_has_capa(&mvm->fw->ucode_capa,
724 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
725 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
726 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
727 ieee80211_hw_set(hw, TDLS_WIDER_BW);
730 if (fw_has_capa(&mvm->fw->ucode_capa,
731 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
732 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
733 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
736 hw->netdev_features |= mvm->cfg->features;
737 if (!iwl_mvm_is_csum_supported(mvm)) {
738 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
740 /* We may support SW TX CSUM */
741 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
742 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
745 ret = ieee80211_register_hw(mvm->hw);
747 iwl_mvm_leds_exit(mvm);
748 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
750 if (mvm->cfg->vht_mu_mimo_supported)
751 wiphy_ext_feature_set(hw->wiphy,
752 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
757 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
758 struct ieee80211_sta *sta,
761 struct iwl_mvm_sta *mvmsta;
765 * double check the IN_D0I3 flag both before and after
766 * taking the spinlock, in order to prevent taking
767 * the spinlock when not needed.
769 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
772 spin_lock(&mvm->d0i3_tx_lock);
774 * testing the flag again ensures the skb dequeue
775 * loop (on d0i3 exit) hasn't run yet.
777 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
780 mvmsta = iwl_mvm_sta_from_mac80211(sta);
781 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
782 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
785 __skb_queue_tail(&mvm->d0i3_tx, skb);
786 ieee80211_stop_queues(mvm->hw);
789 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
790 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
794 spin_unlock(&mvm->d0i3_tx_lock);
798 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
799 struct ieee80211_tx_control *control,
802 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
803 struct ieee80211_sta *sta = control->sta;
804 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
805 struct ieee80211_hdr *hdr = (void *)skb->data;
807 if (iwl_mvm_is_radio_killed(mvm)) {
808 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
812 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
813 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
814 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
817 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
818 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
819 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
820 ieee80211_is_mgmt(hdr->frame_control) &&
821 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
824 /* If there is no sta, and it's not offchannel - send through AP */
825 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
826 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
827 struct iwl_mvm_vif *mvmvif =
828 iwl_mvm_vif_from_mac80211(info->control.vif);
829 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
831 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
832 /* mac80211 holds rcu read lock */
833 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
834 if (IS_ERR_OR_NULL(sta))
840 if (iwl_mvm_defer_tx(mvm, sta, skb))
842 if (iwl_mvm_tx_skb(mvm, skb, sta))
847 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
851 ieee80211_free_txskb(hw, skb);
854 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
856 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
861 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
863 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
865 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
868 /* enabled by default */
872 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
874 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
876 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
880 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
881 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
882 enum ieee80211_ampdu_mlme_action action)
884 struct iwl_fw_dbg_trigger_tlv *trig;
885 struct iwl_fw_dbg_trigger_ba *ba_trig;
887 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
890 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
891 ba_trig = (void *)trig->data;
893 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
894 ieee80211_vif_to_wdev(vif), trig))
898 case IEEE80211_AMPDU_TX_OPERATIONAL: {
899 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
900 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
902 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
903 "TX AGG START: MAC %pM tid %d ssn %d\n",
904 sta->addr, tid, tid_data->ssn);
907 case IEEE80211_AMPDU_TX_STOP_CONT:
908 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
909 "TX AGG STOP: MAC %pM tid %d\n",
912 case IEEE80211_AMPDU_RX_START:
913 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
914 "RX AGG START: MAC %pM tid %d ssn %d\n",
915 sta->addr, tid, rx_ba_ssn);
917 case IEEE80211_AMPDU_RX_STOP:
918 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
919 "RX AGG STOP: MAC %pM tid %d\n",
927 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
928 struct ieee80211_vif *vif,
929 struct ieee80211_ampdu_params *params)
931 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
933 bool tx_agg_ref = false;
934 struct ieee80211_sta *sta = params->sta;
935 enum ieee80211_ampdu_mlme_action action = params->action;
936 u16 tid = params->tid;
937 u16 *ssn = ¶ms->ssn;
938 u16 buf_size = params->buf_size;
939 bool amsdu = params->amsdu;
940 u16 timeout = params->timeout;
942 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
943 sta->addr, tid, action);
945 if (!(mvm->nvm_data->sku_cap_11n_enable))
948 /* return from D0i3 before starting a new Tx aggregation */
950 case IEEE80211_AMPDU_TX_START:
951 case IEEE80211_AMPDU_TX_STOP_CONT:
952 case IEEE80211_AMPDU_TX_STOP_FLUSH:
953 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
954 case IEEE80211_AMPDU_TX_OPERATIONAL:
956 * for tx start, wait synchronously until D0i3 exit to
957 * get the correct sequence number for the tid.
958 * additionally, some other ampdu actions use direct
959 * target access, which is not handled automatically
960 * by the trans layer (unlike commands), so wait for
961 * d0i3 exit in these cases as well.
963 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
973 mutex_lock(&mvm->mutex);
976 case IEEE80211_AMPDU_RX_START:
977 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
978 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
979 struct iwl_mvm_vif *mvmvif;
980 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
981 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
983 mdata->opened_rx_ba_sessions = true;
984 mvmvif = iwl_mvm_vif_from_mac80211(vif);
985 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
987 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
991 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
994 case IEEE80211_AMPDU_RX_STOP:
995 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
998 case IEEE80211_AMPDU_TX_START:
999 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
1003 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1005 case IEEE80211_AMPDU_TX_STOP_CONT:
1006 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1008 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1009 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1010 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1012 case IEEE80211_AMPDU_TX_OPERATIONAL:
1013 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1025 if (action == IEEE80211_AMPDU_RX_START)
1028 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1031 mutex_unlock(&mvm->mutex);
1034 * If the tid is marked as started, we won't use it for offloaded
1035 * traffic on the next D0i3 entry. It's safe to unref.
1038 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1043 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1044 struct ieee80211_vif *vif)
1046 struct iwl_mvm *mvm = data;
1047 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1049 mvmvif->uploaded = false;
1050 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1052 spin_lock_bh(&mvm->time_event_lock);
1053 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1054 spin_unlock_bh(&mvm->time_event_lock);
1056 mvmvif->phy_ctxt = NULL;
1057 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1060 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1062 /* clear the D3 reconfig, we only need it to avoid dumping a
1063 * firmware coredump on reconfiguration, we shouldn't do that
1064 * on D3->D0 transition
1066 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1067 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1068 iwl_fw_error_dump(&mvm->fwrt);
1071 /* cleanup all stale references (scan, roc), but keep the
1072 * ucode_down ref until reconfig is complete
1074 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1076 iwl_mvm_stop_device(mvm);
1078 mvm->scan_status = 0;
1079 mvm->ps_disabled = false;
1080 mvm->calibrating = false;
1082 /* just in case one was running */
1083 iwl_mvm_cleanup_roc_te(mvm);
1084 ieee80211_remain_on_channel_expired(mvm->hw);
1087 * cleanup all interfaces, even inactive ones, as some might have
1088 * gone down during the HW restart
1090 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1092 mvm->p2p_device_vif = NULL;
1093 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1095 iwl_mvm_reset_phy_ctxts(mvm);
1096 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1097 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1098 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1099 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1101 ieee80211_wake_queues(mvm->hw);
1103 /* clear any stale d0i3 state */
1104 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1107 mvm->rx_ba_sessions = 0;
1108 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1109 mvm->monitor_on = false;
1111 /* keep statistics ticking */
1112 iwl_mvm_accu_radio_stats(mvm);
1115 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1119 lockdep_assert_held(&mvm->mutex);
1121 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1123 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1124 * so later code will - from now on - see that we're doing it.
1126 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1127 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1128 /* Clean up some internal and mac80211 state on restart */
1129 iwl_mvm_restart_cleanup(mvm);
1131 /* Hold the reference to prevent runtime suspend while
1132 * the start procedure runs. It's a bit confusing
1133 * that the UCODE_DOWN reference is taken, but it just
1134 * means "UCODE is not UP yet". ( TODO: rename this
1137 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1139 ret = iwl_mvm_up(mvm);
1141 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1142 /* Something went wrong - we need to finish some cleanup
1143 * that normally iwl_mvm_mac_restart_complete() below
1146 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1147 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1153 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1158 /* Some hw restart cleanups must not hold the mutex */
1159 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1161 * Make sure we are out of d0i3. This is needed
1162 * to make sure the reference accounting is correct
1163 * (and there is no stale d0i3_exit_work).
1165 wait_event_timeout(mvm->d0i3_exit_waitq,
1166 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1171 mutex_lock(&mvm->mutex);
1172 ret = __iwl_mvm_mac_start(mvm);
1173 mutex_unlock(&mvm->mutex);
1178 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1182 mutex_lock(&mvm->mutex);
1184 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1185 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1186 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1188 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1191 /* allow transport/FW low power modes */
1192 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1195 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1196 * of packets the FW sent out, so we must reconnect.
1198 iwl_mvm_teardown_tdls_peers(mvm);
1200 mutex_unlock(&mvm->mutex);
1203 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1205 if (iwl_mvm_is_d0i3_supported(mvm) &&
1206 iwl_mvm_enter_d0i3_on_suspend(mvm))
1207 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1208 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1211 "D0i3 exit on resume timed out\n");
1215 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1216 enum ieee80211_reconfig_type reconfig_type)
1218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1220 switch (reconfig_type) {
1221 case IEEE80211_RECONFIG_TYPE_RESTART:
1222 iwl_mvm_restart_complete(mvm);
1224 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1225 iwl_mvm_resume_complete(mvm);
1230 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1232 lockdep_assert_held(&mvm->mutex);
1234 /* firmware counters are obviously reset now, but we shouldn't
1235 * partially track so also clear the fw_reset_accu counters.
1237 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1239 /* async_handlers_wk is now blocked */
1242 * The work item could be running or queued if the
1243 * ROC time event stops just as we get here.
1245 flush_work(&mvm->roc_done_wk);
1247 iwl_mvm_stop_device(mvm);
1249 iwl_mvm_async_handlers_purge(mvm);
1250 /* async_handlers_list is empty and will stay empty: HW is stopped */
1252 /* the fw is stopped, the aux sta is dead: clean up driver state */
1253 iwl_mvm_del_aux_sta(mvm);
1256 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1257 * hw (as restart_complete() won't be called in this case) and mac80211
1258 * won't execute the restart.
1259 * But make sure to cleanup interfaces that have gone down before/during
1260 * HW restart was requested.
1262 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1263 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1265 ieee80211_iterate_interfaces(mvm->hw, 0,
1266 iwl_mvm_cleanup_iterator, mvm);
1268 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1269 * make sure there's nothing left there and warn if any is found.
1271 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1274 for (i = 0; i < mvm->max_scans; i++) {
1275 if (WARN_ONCE(mvm->scan_uid_status[i],
1276 "UMAC scan UID %d status was not cleaned\n",
1278 mvm->scan_uid_status[i] = 0;
1283 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1285 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1287 flush_work(&mvm->d0i3_exit_work);
1288 flush_work(&mvm->async_handlers_wk);
1289 flush_work(&mvm->add_stream_wk);
1292 * Lock and clear the firmware running bit here already, so that
1293 * new commands coming in elsewhere, e.g. from debugfs, will not
1294 * be able to proceed. This is important here because one of those
1295 * debugfs files causes the firmware dump to be triggered, and if we
1296 * don't stop debugfs accesses before canceling that it could be
1297 * retriggered after we flush it but before we've cleared the bit.
1299 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1301 iwl_fw_cancel_dump(&mvm->fwrt);
1302 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1303 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1304 iwl_fw_free_dump_desc(&mvm->fwrt);
1306 mutex_lock(&mvm->mutex);
1307 __iwl_mvm_mac_stop(mvm);
1308 mutex_unlock(&mvm->mutex);
1311 * The worker might have been waiting for the mutex, let it run and
1312 * discover that its list is now empty.
1314 cancel_work_sync(&mvm->async_handlers_wk);
1317 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1321 lockdep_assert_held(&mvm->mutex);
1323 for (i = 0; i < NUM_PHY_CTX; i++)
1324 if (!mvm->phy_ctxts[i].ref)
1325 return &mvm->phy_ctxts[i];
1327 IWL_ERR(mvm, "No available PHY context\n");
1331 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1334 struct iwl_dev_tx_power_cmd cmd = {
1335 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1336 .v3.mac_context_id =
1337 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1338 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1340 int len = sizeof(cmd);
1342 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1343 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1345 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1346 len = sizeof(cmd.v3);
1348 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1351 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1352 struct ieee80211_vif *vif)
1354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1355 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1361 * make sure D0i3 exit is completed, otherwise a target access
1362 * during tx queue configuration could be done when still in
1365 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1370 * Not much to do here. The stack will not allow interface
1371 * types or combinations that we didn't advertise, so we
1372 * don't really have to check the types.
1375 mutex_lock(&mvm->mutex);
1377 /* make sure that beacon statistics don't go backwards with FW reset */
1378 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1379 mvmvif->beacon_stats.accu_num_beacons +=
1380 mvmvif->beacon_stats.num_beacons;
1382 /* Allocate resources for the MAC context, and add it to the fw */
1383 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1387 /* Counting number of interfaces is needed for legacy PM */
1388 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1392 * The AP binding flow can be done only after the beacon
1393 * template is configured (which happens only in the mac80211
1394 * start_ap() flow), and adding the broadcast station can happen
1395 * only after the binding.
1396 * In addition, since modifying the MAC before adding a bcast
1397 * station is not allowed by the FW, delay the adding of MAC context to
1398 * the point where we can also add the bcast station.
1399 * In short: there's not much we can do at this point, other than
1400 * allocating resources :)
1402 if (vif->type == NL80211_IFTYPE_AP ||
1403 vif->type == NL80211_IFTYPE_ADHOC) {
1404 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1406 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1411 * Only queue for this station is the mcast queue,
1412 * which shouldn't be in TFD mask anyway
1414 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1420 iwl_mvm_vif_dbgfs_register(mvm, vif);
1424 mvmvif->features |= hw->netdev_features;
1426 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1430 ret = iwl_mvm_power_update_mac(mvm);
1432 goto out_remove_mac;
1434 /* beacon filtering */
1435 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1437 goto out_remove_mac;
1439 if (!mvm->bf_allowed_vif &&
1440 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1441 mvm->bf_allowed_vif = mvmvif;
1442 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1443 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1447 * P2P_DEVICE interface does not have a channel context assigned to it,
1448 * so a dedicated PHY context is allocated to it and the corresponding
1449 * MAC context is bound to it at this stage.
1451 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1453 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1454 if (!mvmvif->phy_ctxt) {
1459 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1460 ret = iwl_mvm_binding_add_vif(mvm, vif);
1464 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1468 /* Save a pointer to p2p device vif, so it can later be used to
1469 * update the p2p device MAC when a GO is started/stopped */
1470 mvm->p2p_device_vif = vif;
1473 iwl_mvm_tcm_add_vif(mvm, vif);
1475 if (vif->type == NL80211_IFTYPE_MONITOR)
1476 mvm->monitor_on = true;
1478 iwl_mvm_vif_dbgfs_register(mvm, vif);
1482 iwl_mvm_binding_remove_vif(mvm, vif);
1484 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1486 if (mvm->bf_allowed_vif == mvmvif) {
1487 mvm->bf_allowed_vif = NULL;
1488 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1489 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1492 mvmvif->phy_ctxt = NULL;
1493 iwl_mvm_mac_ctxt_remove(mvm, vif);
1495 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1498 mutex_unlock(&mvm->mutex);
1500 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1505 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1506 struct ieee80211_vif *vif)
1508 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1510 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1511 * We assume here that all the packets sent to the OFFCHANNEL
1512 * queue are sent in ROC session.
1514 flush_work(&mvm->roc_done_wk);
1518 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1519 struct ieee80211_vif *vif)
1521 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1522 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1524 iwl_mvm_prepare_mac_removal(mvm, vif);
1526 if (!(vif->type == NL80211_IFTYPE_AP ||
1527 vif->type == NL80211_IFTYPE_ADHOC))
1528 iwl_mvm_tcm_rm_vif(mvm, vif);
1530 mutex_lock(&mvm->mutex);
1532 if (mvm->bf_allowed_vif == mvmvif) {
1533 mvm->bf_allowed_vif = NULL;
1534 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1535 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1538 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1541 * For AP/GO interface, the tear down of the resources allocated to the
1542 * interface is be handled as part of the stop_ap flow.
1544 if (vif->type == NL80211_IFTYPE_AP ||
1545 vif->type == NL80211_IFTYPE_ADHOC) {
1546 #ifdef CONFIG_NL80211_TESTMODE
1547 if (vif == mvm->noa_vif) {
1548 mvm->noa_vif = NULL;
1549 mvm->noa_duration = 0;
1552 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1553 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1557 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1558 mvm->p2p_device_vif = NULL;
1559 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1560 iwl_mvm_binding_remove_vif(mvm, vif);
1561 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1562 mvmvif->phy_ctxt = NULL;
1565 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1568 iwl_mvm_power_update_mac(mvm);
1569 iwl_mvm_mac_ctxt_remove(mvm, vif);
1571 if (vif->type == NL80211_IFTYPE_MONITOR)
1572 mvm->monitor_on = false;
1575 mutex_unlock(&mvm->mutex);
1578 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1583 struct iwl_mvm_mc_iter_data {
1584 struct iwl_mvm *mvm;
1588 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1589 struct ieee80211_vif *vif)
1591 struct iwl_mvm_mc_iter_data *data = _data;
1592 struct iwl_mvm *mvm = data->mvm;
1593 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1594 struct iwl_host_cmd hcmd = {
1595 .id = MCAST_FILTER_CMD,
1597 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1601 /* if we don't have free ports, mcast frames will be dropped */
1602 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1605 if (vif->type != NL80211_IFTYPE_STATION ||
1606 !vif->bss_conf.assoc)
1609 cmd->port_id = data->port_id++;
1610 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1611 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1616 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1618 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1621 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1623 struct iwl_mvm_mc_iter_data iter_data = {
1627 lockdep_assert_held(&mvm->mutex);
1629 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1632 ieee80211_iterate_active_interfaces_atomic(
1633 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1634 iwl_mvm_mc_iface_iterator, &iter_data);
1637 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1638 struct netdev_hw_addr_list *mc_list)
1640 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1641 struct iwl_mcast_filter_cmd *cmd;
1642 struct netdev_hw_addr *addr;
1647 addr_count = netdev_hw_addr_list_count(mc_list);
1648 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1649 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1653 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1654 cmd = kzalloc(len, GFP_ATOMIC);
1660 return (u64)(unsigned long)cmd;
1663 netdev_hw_addr_list_for_each(addr, mc_list) {
1664 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1665 cmd->count, addr->addr);
1666 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1667 addr->addr, ETH_ALEN);
1671 return (u64)(unsigned long)cmd;
1674 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1675 unsigned int changed_flags,
1676 unsigned int *total_flags,
1679 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1680 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1682 mutex_lock(&mvm->mutex);
1684 /* replace previous configuration */
1685 kfree(mvm->mcast_filter_cmd);
1686 mvm->mcast_filter_cmd = cmd;
1691 if (changed_flags & FIF_ALLMULTI)
1692 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1697 iwl_mvm_recalc_multicast(mvm);
1699 mutex_unlock(&mvm->mutex);
1703 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1704 struct ieee80211_vif *vif,
1705 unsigned int filter_flags,
1706 unsigned int changed_flags)
1708 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1710 /* We support only filter for probe requests */
1711 if (!(changed_flags & FIF_PROBE_REQ))
1714 /* Supported only for p2p client interfaces */
1715 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1719 mutex_lock(&mvm->mutex);
1720 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1721 mutex_unlock(&mvm->mutex);
1724 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1725 struct iwl_bcast_iter_data {
1726 struct iwl_mvm *mvm;
1727 struct iwl_bcast_filter_cmd *cmd;
1732 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1733 const struct iwl_fw_bcast_filter *in_filter,
1734 struct iwl_fw_bcast_filter *out_filter)
1736 struct iwl_fw_bcast_filter_attr *attr;
1739 memcpy(out_filter, in_filter, sizeof(*out_filter));
1741 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1742 attr = &out_filter->attrs[i];
1747 switch (attr->reserved1) {
1748 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1749 if (vif->bss_conf.arp_addr_cnt != 1) {
1754 attr->val = vif->bss_conf.arp_addr_list[0];
1756 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1757 attr->val = *(__be32 *)&vif->addr[2];
1762 attr->reserved1 = 0;
1763 out_filter->num_attrs++;
1767 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1768 struct ieee80211_vif *vif)
1770 struct iwl_bcast_iter_data *data = _data;
1771 struct iwl_mvm *mvm = data->mvm;
1772 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1773 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1774 struct iwl_fw_bcast_mac *bcast_mac;
1777 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1780 bcast_mac = &cmd->macs[mvmvif->id];
1783 * enable filtering only for associated stations, but not for P2P
1786 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1787 !vif->bss_conf.assoc)
1790 bcast_mac->default_discard = 1;
1792 /* copy all configured filters */
1793 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1795 * Make sure we don't exceed our filters limit.
1796 * if there is still a valid filter to be configured,
1797 * be on the safe side and just allow bcast for this mac.
1799 if (WARN_ON_ONCE(data->current_filter >=
1800 ARRAY_SIZE(cmd->filters))) {
1801 bcast_mac->default_discard = 0;
1802 bcast_mac->attached_filters = 0;
1806 iwl_mvm_set_bcast_filter(vif,
1807 &mvm->bcast_filters[i],
1808 &cmd->filters[data->current_filter]);
1810 /* skip current filter if it contains no attributes */
1811 if (!cmd->filters[data->current_filter].num_attrs)
1814 /* attach the filter to current mac */
1815 bcast_mac->attached_filters |=
1816 cpu_to_le16(BIT(data->current_filter));
1818 data->current_filter++;
1822 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1823 struct iwl_bcast_filter_cmd *cmd)
1825 struct iwl_bcast_iter_data iter_data = {
1830 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1833 memset(cmd, 0, sizeof(*cmd));
1834 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1835 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1837 #ifdef CONFIG_IWLWIFI_DEBUGFS
1838 /* use debugfs filters/macs if override is configured */
1839 if (mvm->dbgfs_bcast_filtering.override) {
1840 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1841 sizeof(cmd->filters));
1842 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1848 /* if no filters are configured, do nothing */
1849 if (!mvm->bcast_filters)
1852 /* configure and attach these filters for each associated sta vif */
1853 ieee80211_iterate_active_interfaces(
1854 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1855 iwl_mvm_bcast_filter_iterator, &iter_data);
1860 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1862 struct iwl_bcast_filter_cmd cmd;
1864 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1867 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1870 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1874 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1880 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1881 struct ieee80211_vif *vif)
1883 struct iwl_mu_group_mgmt_cmd cmd = {};
1885 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1886 WLAN_MEMBERSHIP_LEN);
1887 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1888 WLAN_USER_POSITION_LEN);
1890 return iwl_mvm_send_cmd_pdu(mvm,
1891 WIDE_ID(DATA_PATH_GROUP,
1892 UPDATE_MU_GROUPS_CMD),
1893 0, sizeof(cmd), &cmd);
1896 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1897 struct ieee80211_vif *vif)
1899 if (vif->mu_mimo_owner) {
1900 struct iwl_mu_group_mgmt_notif *notif = _data;
1903 * MU-MIMO Group Id action frame is little endian. We treat
1904 * the data received from firmware as if it came from the
1905 * action frame, so no conversion is needed.
1907 ieee80211_update_mu_groups(vif,
1908 (u8 *)¬if->membership_status,
1909 (u8 *)¬if->user_position);
1913 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1914 struct iwl_rx_cmd_buffer *rxb)
1916 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1917 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1919 ieee80211_iterate_active_interfaces_atomic(
1920 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1921 iwl_mvm_mu_mimo_iface_iterator, notif);
1924 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1926 u8 byte_num = ppe_pos_bit / 8;
1927 u8 bit_num = ppe_pos_bit % 8;
1932 return (ppe[byte_num] >> bit_num) &
1933 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1936 * If bit_num > 5, we have to combine bits with next byte.
1937 * Calculate how many bits we need to take from current byte (called
1938 * here "residue_bits"), and add them to bits from next byte.
1941 residue_bits = 8 - bit_num;
1943 res = (ppe[byte_num + 1] &
1944 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1946 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1951 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1952 struct ieee80211_vif *vif, u8 sta_id)
1954 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1955 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1957 .tid_limit = IWL_MAX_TID_COUNT,
1958 .bss_color = vif->bss_conf.bss_color,
1959 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1960 .frame_time_rts_th =
1961 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1963 struct ieee80211_sta *sta;
1969 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1972 WARN(1, "Can't find STA to configure HE\n");
1976 if (!sta->he_cap.has_he) {
1984 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1985 IEEE80211_HE_MAC_CAP0_HTC_HE)
1986 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1987 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1988 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1989 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1990 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
1992 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
1993 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
1994 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
1995 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
1998 sta_ctxt_cmd.htc_flags |=
1999 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2000 else if (link_adap == 3)
2001 sta_ctxt_cmd.htc_flags |=
2002 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2004 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2005 IEEE80211_HE_MAC_CAP2_UL_MU_RESP_SCHED)
2006 sta_ctxt_cmd.htc_flags |=
2007 cpu_to_le32(IWL_HE_HTC_UL_MU_RESP_SCHED);
2008 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2009 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2010 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2011 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2012 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2013 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2014 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2017 * Initialize the PPE thresholds to "None" (7), as described in Table
2018 * 9-262ac of 80211.ax/D3.0.
2020 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2022 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2023 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2024 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2025 u8 nss = (sta->he_cap.ppe_thres[0] &
2026 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2027 u8 ru_index_bitmap =
2028 (sta->he_cap.ppe_thres[0] &
2029 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2030 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2031 u8 *ppe = &sta->he_cap.ppe_thres[0];
2032 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2035 * FW currently supports only nss == MAX_HE_SUPP_NSS
2037 * If nss > MAX: we can ignore values we don't support
2038 * If nss < MAX: we can set zeros in other streams
2040 if (nss > MAX_HE_SUPP_NSS) {
2041 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2043 nss = MAX_HE_SUPP_NSS;
2046 for (i = 0; i < nss; i++) {
2047 u8 ru_index_tmp = ru_index_bitmap << 1;
2050 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2052 if (!(ru_index_tmp & 1))
2055 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2056 iwl_mvm_he_get_ppe_val(ppe,
2059 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2060 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2061 iwl_mvm_he_get_ppe_val(ppe,
2064 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2068 flags |= STA_CTXT_HE_PACKET_EXT;
2072 /* Mark MU EDCA as enabled, unless none detected on some AC */
2073 flags |= STA_CTXT_HE_MU_EDCA_CW;
2074 for (i = 0; i < AC_NUM; i++) {
2075 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2076 &mvmvif->queue_params[i].mu_edca_param_rec;
2078 if (!mvmvif->queue_params[i].mu_edca) {
2079 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2083 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2084 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2085 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2086 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2087 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2088 cpu_to_le16(mu_edca->aifsn);
2089 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2090 cpu_to_le16(mu_edca->mu_edca_timer);
2093 if (vif->bss_conf.multi_sta_back_32bit)
2094 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2096 if (vif->bss_conf.ack_enabled)
2097 flags |= STA_CTXT_HE_ACK_ENABLED;
2099 if (vif->bss_conf.uora_exists) {
2100 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2102 sta_ctxt_cmd.rand_alloc_ecwmin =
2103 vif->bss_conf.uora_ocw_range & 0x7;
2104 sta_ctxt_cmd.rand_alloc_ecwmax =
2105 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2108 /* TODO: support Multi BSSID IE */
2110 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2112 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2113 DATA_PATH_GROUP, 0),
2114 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2115 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2118 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2119 struct ieee80211_vif *vif,
2120 struct ieee80211_bss_conf *bss_conf,
2123 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2127 * Re-calculate the tsf id, as the master-slave relations depend on the
2128 * beacon interval, which was not known when the station interface was
2131 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2132 if (vif->bss_conf.he_support &&
2133 !iwlwifi_mod_params.disable_11ax)
2134 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2136 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2140 * If we're not associated yet, take the (new) BSSID before associating
2141 * so the firmware knows. If we're already associated, then use the old
2142 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2143 * branch for disassociation below.
2145 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2146 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2148 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2150 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2152 /* after sending it once, adopt mac80211 data */
2153 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2154 mvmvif->associated = bss_conf->assoc;
2156 if (changes & BSS_CHANGED_ASSOC) {
2157 if (bss_conf->assoc) {
2158 /* clear statistics to get clean beacon counter */
2159 iwl_mvm_request_statistics(mvm, true);
2160 memset(&mvmvif->beacon_stats, 0,
2161 sizeof(mvmvif->beacon_stats));
2163 /* add quota for this interface */
2164 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2166 IWL_ERR(mvm, "failed to update quotas\n");
2170 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2173 * If we're restarting then the firmware will
2174 * obviously have lost synchronisation with
2175 * the AP. It will attempt to synchronise by
2176 * itself, but we can make it more reliable by
2177 * scheduling a session protection time event.
2179 * The firmware needs to receive a beacon to
2180 * catch up with synchronisation, use 110% of
2181 * the beacon interval.
2183 * Set a large maximum delay to allow for more
2184 * than a single interface.
2186 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2187 iwl_mvm_protect_session(mvm, vif, dur, dur,
2191 iwl_mvm_sf_update(mvm, vif, false);
2192 iwl_mvm_power_vif_assoc(mvm, vif);
2194 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2195 iwl_mvm_update_smps(mvm, vif,
2196 IWL_MVM_SMPS_REQ_PROT,
2197 IEEE80211_SMPS_DYNAMIC);
2199 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2201 * If update fails - SF might be running in associated
2202 * mode while disassociated - which is forbidden.
2204 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2205 "Failed to update SF upon disassociation\n");
2208 * If we get an assert during the connection (after the
2209 * station has been added, but before the vif is set
2210 * to associated), mac80211 will re-add the station and
2211 * then configure the vif. Since the vif is not
2212 * associated, we would remove the station here and
2213 * this would fail the recovery.
2215 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2218 * Remove AP station now that
2219 * the MAC is unassoc
2221 ret = iwl_mvm_rm_sta_id(mvm, vif,
2225 "failed to remove AP station\n");
2227 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2228 mvm->d0i3_ap_sta_id =
2229 IWL_MVM_INVALID_STA;
2230 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2233 /* remove quota for this interface */
2234 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2236 IWL_ERR(mvm, "failed to update quotas\n");
2239 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2241 /* this will take the cleared BSSID from bss_conf */
2242 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2245 "failed to update MAC %pM (clear after unassoc)\n",
2250 * The firmware tracks the MU-MIMO group on its own.
2251 * However, on HW restart we should restore this data.
2253 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2254 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2255 ret = iwl_mvm_update_mu_groups(mvm, vif);
2258 "failed to update VHT MU_MIMO groups\n");
2261 iwl_mvm_recalc_multicast(mvm);
2262 iwl_mvm_configure_bcast_filter(mvm);
2264 /* reset rssi values */
2265 mvmvif->bf_data.ave_beacon_signal = 0;
2267 iwl_mvm_bt_coex_vif_change(mvm);
2268 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2269 IEEE80211_SMPS_AUTOMATIC);
2270 if (fw_has_capa(&mvm->fw->ucode_capa,
2271 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2272 iwl_mvm_config_scan(mvm);
2275 if (changes & BSS_CHANGED_BEACON_INFO) {
2277 * We received a beacon from the associated AP so
2278 * remove the session protection.
2280 iwl_mvm_stop_session_protection(mvm, vif);
2282 iwl_mvm_sf_update(mvm, vif, false);
2283 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2286 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2288 * Send power command on every beacon change,
2289 * because we may have not enabled beacon abort yet.
2291 BSS_CHANGED_BEACON_INFO)) {
2292 ret = iwl_mvm_power_update_mac(mvm);
2294 IWL_ERR(mvm, "failed to update power mode\n");
2297 if (changes & BSS_CHANGED_TXPOWER) {
2298 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2300 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2303 if (changes & BSS_CHANGED_CQM) {
2304 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2305 /* reset cqm events tracking */
2306 mvmvif->bf_data.last_cqm_event = 0;
2307 if (mvmvif->bf_data.bf_enabled) {
2308 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2311 "failed to update CQM thresholds\n");
2315 if (changes & BSS_CHANGED_ARP_FILTER) {
2316 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2317 iwl_mvm_configure_bcast_filter(mvm);
2321 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2322 struct ieee80211_vif *vif)
2324 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2325 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2329 * iwl_mvm_mac_ctxt_add() might read directly from the device
2330 * (the system time), so make sure it is available.
2332 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2336 mutex_lock(&mvm->mutex);
2338 /* Send the beacon template */
2339 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2344 * Re-calculate the tsf id, as the master-slave relations depend on the
2345 * beacon interval, which was not known when the AP interface was added.
2347 if (vif->type == NL80211_IFTYPE_AP)
2348 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2350 mvmvif->ap_assoc_sta_count = 0;
2352 /* Add the mac context */
2353 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2357 /* Perform the binding */
2358 ret = iwl_mvm_binding_add_vif(mvm, vif);
2363 * This is not very nice, but the simplest:
2364 * For older FWs adding the mcast sta before the bcast station may
2365 * cause assert 0x2b00.
2366 * This is fixed in later FW so make the order of removal depend on
2369 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2370 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2374 * Send the bcast station. At this stage the TBTT and DTIM time
2375 * events are added and applied to the scheduler
2377 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2379 iwl_mvm_rm_mcast_sta(mvm, vif);
2384 * Send the bcast station. At this stage the TBTT and DTIM time
2385 * events are added and applied to the scheduler
2387 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2390 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2392 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2397 /* must be set before quota calculations */
2398 mvmvif->ap_ibss_active = true;
2400 /* power updated needs to be done before quotas */
2401 iwl_mvm_power_update_mac(mvm);
2403 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2405 goto out_quota_failed;
2407 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2408 if (vif->p2p && mvm->p2p_device_vif)
2409 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2411 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2413 iwl_mvm_bt_coex_vif_change(mvm);
2415 /* we don't support TDLS during DCM */
2416 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2417 iwl_mvm_teardown_tdls_peers(mvm);
2422 iwl_mvm_power_update_mac(mvm);
2423 mvmvif->ap_ibss_active = false;
2424 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2425 iwl_mvm_rm_mcast_sta(mvm, vif);
2427 iwl_mvm_binding_remove_vif(mvm, vif);
2429 iwl_mvm_mac_ctxt_remove(mvm, vif);
2431 mutex_unlock(&mvm->mutex);
2432 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2436 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2437 struct ieee80211_vif *vif)
2439 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2440 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2442 iwl_mvm_prepare_mac_removal(mvm, vif);
2444 mutex_lock(&mvm->mutex);
2446 /* Handle AP stop while in CSA */
2447 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2448 iwl_mvm_remove_time_event(mvm, mvmvif,
2449 &mvmvif->time_event_data);
2450 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2451 mvmvif->csa_countdown = false;
2454 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2455 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2456 mvm->csa_tx_block_bcn_timeout = 0;
2459 mvmvif->ap_ibss_active = false;
2460 mvm->ap_last_beacon_gp2 = 0;
2462 iwl_mvm_bt_coex_vif_change(mvm);
2464 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2466 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2467 if (vif->p2p && mvm->p2p_device_vif)
2468 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2470 iwl_mvm_update_quotas(mvm, false, NULL);
2473 * This is not very nice, but the simplest:
2474 * For older FWs removing the mcast sta before the bcast station may
2475 * cause assert 0x2b00.
2476 * This is fixed in later FW (which will stop beaconing when removing
2478 * So make the order of removal depend on the TLV
2480 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2481 iwl_mvm_rm_mcast_sta(mvm, vif);
2482 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2483 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2484 iwl_mvm_rm_mcast_sta(mvm, vif);
2485 iwl_mvm_binding_remove_vif(mvm, vif);
2487 iwl_mvm_power_update_mac(mvm);
2489 iwl_mvm_mac_ctxt_remove(mvm, vif);
2491 mutex_unlock(&mvm->mutex);
2495 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2496 struct ieee80211_vif *vif,
2497 struct ieee80211_bss_conf *bss_conf,
2500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2502 /* Changes will be applied when the AP/IBSS is started */
2503 if (!mvmvif->ap_ibss_active)
2506 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2507 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2508 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2509 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2511 /* Need to send a new beacon template to the FW */
2512 if (changes & BSS_CHANGED_BEACON &&
2513 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2514 IWL_WARN(mvm, "Failed updating beacon data\n");
2516 if (changes & BSS_CHANGED_TXPOWER) {
2517 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2519 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2523 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2524 struct ieee80211_vif *vif,
2525 struct ieee80211_bss_conf *bss_conf,
2528 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2531 * iwl_mvm_bss_info_changed_station() might call
2532 * iwl_mvm_protect_session(), which reads directly from
2533 * the device (the system time), so make sure it is available.
2535 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2538 mutex_lock(&mvm->mutex);
2540 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2541 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2543 switch (vif->type) {
2544 case NL80211_IFTYPE_STATION:
2545 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2547 case NL80211_IFTYPE_AP:
2548 case NL80211_IFTYPE_ADHOC:
2549 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2551 case NL80211_IFTYPE_MONITOR:
2552 if (changes & BSS_CHANGED_MU_GROUPS)
2553 iwl_mvm_update_mu_groups(mvm, vif);
2556 /* shouldn't happen */
2560 mutex_unlock(&mvm->mutex);
2561 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2564 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2565 struct ieee80211_vif *vif,
2566 struct ieee80211_scan_request *hw_req)
2568 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2571 if (hw_req->req.n_channels == 0 ||
2572 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2575 mutex_lock(&mvm->mutex);
2576 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2577 mutex_unlock(&mvm->mutex);
2582 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2583 struct ieee80211_vif *vif)
2585 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2587 mutex_lock(&mvm->mutex);
2589 /* Due to a race condition, it's possible that mac80211 asks
2590 * us to stop a hw_scan when it's already stopped. This can
2591 * happen, for instance, if we stopped the scan ourselves,
2592 * called ieee80211_scan_completed() and the userspace called
2593 * cancel scan scan before ieee80211_scan_work() could run.
2594 * To handle that, simply return if the scan is not running.
2596 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2597 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2599 mutex_unlock(&mvm->mutex);
2603 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2604 struct ieee80211_sta *sta, u16 tids,
2606 enum ieee80211_frame_release_type reason,
2609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2611 /* Called when we need to transmit (a) frame(s) from mac80211 */
2613 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2614 tids, more_data, false);
2618 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2619 struct ieee80211_sta *sta, u16 tids,
2621 enum ieee80211_frame_release_type reason,
2624 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2626 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2628 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2629 tids, more_data, true);
2632 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2633 enum sta_notify_cmd cmd,
2634 struct ieee80211_sta *sta)
2636 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2637 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2638 unsigned long txqs = 0, tids = 0;
2642 * If we have TVQM then we get too high queue numbers - luckily
2643 * we really shouldn't get here with that because such hardware
2644 * should have firmware supporting buffer station offload.
2646 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2649 spin_lock_bh(&mvmsta->lock);
2650 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2651 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2653 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2656 __set_bit(tid_data->txq_id, &txqs);
2658 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2661 __set_bit(tid, &tids);
2665 case STA_NOTIFY_SLEEP:
2666 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2667 ieee80211_sta_set_buffered(sta, tid, true);
2670 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2672 * The fw updates the STA to be asleep. Tx packets on the Tx
2673 * queues to this station will not be transmitted. The fw will
2674 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2677 case STA_NOTIFY_AWAKE:
2678 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2682 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2683 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2688 spin_unlock_bh(&mvmsta->lock);
2691 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2692 struct ieee80211_vif *vif,
2693 enum sta_notify_cmd cmd,
2694 struct ieee80211_sta *sta)
2696 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2699 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2701 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2702 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2703 struct ieee80211_sta *sta;
2704 struct iwl_mvm_sta *mvmsta;
2705 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2707 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2711 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2712 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2717 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2720 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2725 if (mvmsta->sleeping != sleeping) {
2726 mvmsta->sleeping = sleeping;
2727 __iwl_mvm_mac_sta_notify(mvm->hw,
2728 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2730 ieee80211_sta_ps_transition(sta, sleeping);
2734 switch (notif->type) {
2735 case IWL_MVM_PM_EVENT_AWAKE:
2736 case IWL_MVM_PM_EVENT_ASLEEP:
2738 case IWL_MVM_PM_EVENT_UAPSD:
2739 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2741 case IWL_MVM_PM_EVENT_PS_POLL:
2742 ieee80211_sta_pspoll(sta);
2752 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2753 struct ieee80211_vif *vif,
2754 struct ieee80211_sta *sta)
2756 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2757 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2760 * This is called before mac80211 does RCU synchronisation,
2761 * so here we already invalidate our internal RCU-protected
2762 * station pointer. The rest of the code will thus no longer
2763 * be able to find the station this way, and we don't rely
2764 * on further RCU synchronisation after the sta_state()
2765 * callback deleted the station.
2767 mutex_lock(&mvm->mutex);
2768 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2769 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2772 mutex_unlock(&mvm->mutex);
2775 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2780 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2781 struct iwl_mvm_tcm_mac *mdata;
2783 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2784 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2785 mdata->opened_rx_ba_sessions = false;
2788 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2791 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2792 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2797 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2798 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2802 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2803 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2804 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2809 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2813 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2814 struct ieee80211_vif *vif, u8 *peer_addr,
2815 enum nl80211_tdls_operation action)
2817 struct iwl_fw_dbg_trigger_tlv *trig;
2818 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2820 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2823 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2824 tdls_trig = (void *)trig->data;
2825 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2826 ieee80211_vif_to_wdev(vif), trig))
2829 if (!(tdls_trig->action_bitmap & BIT(action)))
2832 if (tdls_trig->peer_mode &&
2833 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2836 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2837 "TDLS event occurred, peer %pM, action %d",
2841 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2842 struct iwl_mvm_sta *mvm_sta)
2844 struct iwl_mvm_tid_data *tid_data;
2845 struct sk_buff *skb;
2848 spin_lock_bh(&mvm_sta->lock);
2849 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2850 tid_data = &mvm_sta->tid_data[i];
2852 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2853 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2856 * The first deferred frame should've stopped the MAC
2857 * queues, so we should never get a second deferred
2858 * frame for the RA/TID.
2860 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2861 ieee80211_free_txskb(mvm->hw, skb);
2864 spin_unlock_bh(&mvm_sta->lock);
2867 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2868 struct ieee80211_vif *vif,
2869 struct ieee80211_sta *sta,
2870 enum ieee80211_sta_state old_state,
2871 enum ieee80211_sta_state new_state)
2873 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2874 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2875 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2878 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2879 sta->addr, old_state, new_state);
2881 /* this would be a mac80211 bug ... but don't crash */
2882 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2883 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
2886 * If we are in a STA removal flow and in DQA mode:
2888 * This is after the sync_rcu part, so the queues have already been
2889 * flushed. No more TXs on their way in mac80211's path, and no more in
2891 * Also, we won't be getting any new TX frames for this station.
2892 * What we might have are deferred TX frames that need to be taken care
2895 * Drop any still-queued deferred-frame before removing the STA, and
2896 * make sure the worker is no longer handling frames for this STA.
2898 if (old_state == IEEE80211_STA_NONE &&
2899 new_state == IEEE80211_STA_NOTEXIST) {
2900 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2901 flush_work(&mvm->add_stream_wk);
2904 * No need to make sure deferred TX indication is off since the
2905 * worker will already remove it if it was on
2909 mutex_lock(&mvm->mutex);
2910 /* track whether or not the station is associated */
2911 mvm_sta->sta_state = new_state;
2913 if (old_state == IEEE80211_STA_NOTEXIST &&
2914 new_state == IEEE80211_STA_NONE) {
2916 * Firmware bug - it'll crash if the beacon interval is less
2917 * than 16. We can't avoid connecting at all, so refuse the
2918 * station state change, this will cause mac80211 to abandon
2919 * attempts to connect to this AP, and eventually wpa_s will
2920 * blacklist the AP...
2922 if (vif->type == NL80211_IFTYPE_STATION &&
2923 vif->bss_conf.beacon_int < 16) {
2925 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2926 sta->addr, vif->bss_conf.beacon_int);
2933 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2934 IWL_MVM_TDLS_STA_COUNT ||
2935 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2936 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2941 ret = iwl_mvm_add_sta(mvm, vif, sta);
2942 if (sta->tdls && ret == 0) {
2943 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2944 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2945 NL80211_TDLS_SETUP);
2947 } else if (old_state == IEEE80211_STA_NONE &&
2948 new_state == IEEE80211_STA_AUTH) {
2950 * EBS may be disabled due to previous failures reported by FW.
2951 * Reset EBS status here assuming environment has been changed.
2953 mvm->last_ebs_successful = true;
2954 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2956 } else if (old_state == IEEE80211_STA_AUTH &&
2957 new_state == IEEE80211_STA_ASSOC) {
2958 if (vif->type == NL80211_IFTYPE_AP) {
2959 mvmvif->ap_assoc_sta_count++;
2960 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2963 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2965 ret = iwl_mvm_update_sta(mvm, vif, sta);
2966 } else if (old_state == IEEE80211_STA_ASSOC &&
2967 new_state == IEEE80211_STA_AUTHORIZED) {
2969 /* we don't support TDLS during DCM */
2970 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2971 iwl_mvm_teardown_tdls_peers(mvm);
2974 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2975 NL80211_TDLS_ENABLE_LINK);
2977 /* enable beacon filtering */
2978 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2980 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2984 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2985 new_state == IEEE80211_STA_ASSOC) {
2986 /* disable beacon filtering */
2987 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2989 } else if (old_state == IEEE80211_STA_ASSOC &&
2990 new_state == IEEE80211_STA_AUTH) {
2991 if (vif->type == NL80211_IFTYPE_AP) {
2992 mvmvif->ap_assoc_sta_count--;
2993 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2996 } else if (old_state == IEEE80211_STA_AUTH &&
2997 new_state == IEEE80211_STA_NONE) {
2999 } else if (old_state == IEEE80211_STA_NONE &&
3000 new_state == IEEE80211_STA_NOTEXIST) {
3001 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3003 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3004 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3005 NL80211_TDLS_DISABLE_LINK);
3011 mutex_unlock(&mvm->mutex);
3013 if (sta->tdls && ret == 0) {
3014 if (old_state == IEEE80211_STA_NOTEXIST &&
3015 new_state == IEEE80211_STA_NONE)
3016 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3017 else if (old_state == IEEE80211_STA_NONE &&
3018 new_state == IEEE80211_STA_NOTEXIST)
3019 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3025 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3027 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3029 mvm->rts_threshold = value;
3034 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3035 struct ieee80211_vif *vif,
3036 struct ieee80211_sta *sta, u32 changed)
3038 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3040 if (vif->type == NL80211_IFTYPE_STATION &&
3041 changed & IEEE80211_RC_NSS_CHANGED)
3042 iwl_mvm_sf_update(mvm, vif, false);
3045 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3046 struct ieee80211_vif *vif, u16 ac,
3047 const struct ieee80211_tx_queue_params *params)
3049 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3050 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3052 mvmvif->queue_params[ac] = *params;
3055 * No need to update right away, we'll get BSS_CHANGED_QOS
3056 * The exception is P2P_DEVICE interface which needs immediate update.
3058 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3061 mutex_lock(&mvm->mutex);
3062 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3063 mutex_unlock(&mvm->mutex);
3069 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3070 struct ieee80211_vif *vif,
3073 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3074 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3075 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3078 * iwl_mvm_protect_session() reads directly from the device
3079 * (the system time), so make sure it is available.
3081 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3084 if (req_duration > duration)
3085 duration = req_duration;
3087 mutex_lock(&mvm->mutex);
3088 /* Try really hard to protect the session and hear a beacon */
3089 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3090 mutex_unlock(&mvm->mutex);
3092 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3095 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3096 struct ieee80211_vif *vif,
3097 struct cfg80211_sched_scan_request *req,
3098 struct ieee80211_scan_ies *ies)
3100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3104 mutex_lock(&mvm->mutex);
3106 if (!vif->bss_conf.idle) {
3111 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3114 mutex_unlock(&mvm->mutex);
3118 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3119 struct ieee80211_vif *vif)
3121 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3124 mutex_lock(&mvm->mutex);
3126 /* Due to a race condition, it's possible that mac80211 asks
3127 * us to stop a sched_scan when it's already stopped. This
3128 * can happen, for instance, if we stopped the scan ourselves,
3129 * called ieee80211_sched_scan_stopped() and the userspace called
3130 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3131 * could run. To handle this, simply return if the scan is
3134 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3135 mutex_unlock(&mvm->mutex);
3139 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3140 mutex_unlock(&mvm->mutex);
3141 iwl_mvm_wait_for_async_handlers(mvm);
3146 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3147 enum set_key_cmd cmd,
3148 struct ieee80211_vif *vif,
3149 struct ieee80211_sta *sta,
3150 struct ieee80211_key_conf *key)
3152 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3153 struct iwl_mvm_sta *mvmsta;
3154 struct iwl_mvm_key_pn *ptk_pn;
3155 int keyidx = key->keyidx;
3159 if (iwlwifi_mod_params.swcrypto) {
3160 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3164 switch (key->cipher) {
3165 case WLAN_CIPHER_SUITE_TKIP:
3166 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3167 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3169 case WLAN_CIPHER_SUITE_CCMP:
3170 case WLAN_CIPHER_SUITE_GCMP:
3171 case WLAN_CIPHER_SUITE_GCMP_256:
3172 if (!iwl_mvm_has_new_tx_api(mvm))
3173 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3175 case WLAN_CIPHER_SUITE_AES_CMAC:
3176 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3177 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3178 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3180 case WLAN_CIPHER_SUITE_WEP40:
3181 case WLAN_CIPHER_SUITE_WEP104:
3182 /* For non-client mode, only use WEP keys for TX as we probably
3183 * don't have a station yet anyway and would then have to keep
3184 * track of the keys, linking them to each of the clients/peers
3185 * as they appear. For now, don't do that, for performance WEP
3186 * offload doesn't really matter much, but we need it for some
3187 * other offload features in client mode.
3189 if (vif->type != NL80211_IFTYPE_STATION)
3193 /* currently FW supports only one optional cipher scheme */
3194 if (hw->n_cipher_schemes &&
3195 hw->cipher_schemes->cipher == key->cipher)
3196 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3201 mutex_lock(&mvm->mutex);
3205 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3206 vif->type == NL80211_IFTYPE_AP) && !sta) {
3208 * GTK on AP interface is a TX-only key, return 0;
3209 * on IBSS they're per-station and because we're lazy
3210 * we don't support them for RX, so do the same.
3211 * CMAC/GMAC in AP/IBSS modes must be done in software.
3213 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3214 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3215 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3220 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3221 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3222 !iwl_mvm_has_new_tx_api(mvm)) {
3223 key->hw_key_idx = STA_KEY_IDX_INVALID;
3228 /* During FW restart, in order to restore the state as it was,
3229 * don't try to reprogram keys we previously failed for.
3231 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3232 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3233 IWL_DEBUG_MAC80211(mvm,
3234 "skip invalid idx key programming during restart\n");
3239 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3240 sta && iwl_mvm_has_new_rx_api(mvm) &&
3241 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3242 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3243 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3244 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3245 struct ieee80211_key_seq seq;
3248 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3249 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3250 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3251 mvm->trans->num_rx_queues),
3258 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3259 ieee80211_get_key_rx_seq(key, tid, &seq);
3260 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3261 memcpy(ptk_pn->q[q].pn[tid],
3263 IEEE80211_CCMP_PN_LEN);
3266 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3269 /* in HW restart reuse the index, otherwise request a new one */
3270 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3271 key_offset = key->hw_key_idx;
3273 key_offset = STA_KEY_IDX_INVALID;
3275 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3276 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3278 IWL_WARN(mvm, "set key failed\n");
3280 * can't add key for RX, but we don't need it
3281 * in the device for TX so still return 0
3283 key->hw_key_idx = STA_KEY_IDX_INVALID;
3289 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3294 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3295 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3296 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3297 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3298 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3299 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3300 ptk_pn = rcu_dereference_protected(
3301 mvmsta->ptk_pn[keyidx],
3302 lockdep_is_held(&mvm->mutex));
3303 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3305 kfree_rcu(ptk_pn, rcu_head);
3308 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3309 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3315 mutex_unlock(&mvm->mutex);
3319 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3320 struct ieee80211_vif *vif,
3321 struct ieee80211_key_conf *keyconf,
3322 struct ieee80211_sta *sta,
3323 u32 iv32, u16 *phase1key)
3325 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3327 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3330 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3334 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3335 struct iwl_rx_packet *pkt, void *data)
3337 struct iwl_mvm *mvm =
3338 container_of(notif_wait, struct iwl_mvm, notif_wait);
3339 struct iwl_hs20_roc_res *resp;
3340 int resp_len = iwl_rx_packet_payload_len(pkt);
3341 struct iwl_mvm_time_event_data *te_data = data;
3343 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3346 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3347 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3351 resp = (void *)pkt->data;
3354 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3355 resp->status, resp->event_unique_id);
3357 te_data->uid = le32_to_cpu(resp->event_unique_id);
3358 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3361 spin_lock_bh(&mvm->time_event_lock);
3362 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3363 spin_unlock_bh(&mvm->time_event_lock);
3368 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3369 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3370 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3371 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3372 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3373 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3374 struct ieee80211_channel *channel,
3375 struct ieee80211_vif *vif,
3378 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3379 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3380 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3381 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3382 struct iwl_notification_wait wait_time_event;
3383 u32 dtim_interval = vif->bss_conf.dtim_period *
3384 vif->bss_conf.beacon_int;
3386 struct iwl_hs20_roc_req aux_roc_req = {
3387 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3389 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3390 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3391 /* Set the channel info data */
3392 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3393 PHY_BAND_24 : PHY_BAND_5,
3394 .channel_info.channel = channel->hw_value,
3395 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3396 /* Set the time and duration */
3397 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3400 delay = AUX_ROC_MIN_DELAY;
3401 req_dur = MSEC_TO_TU(duration);
3404 * If we are associated we want the delay time to be at least one
3405 * dtim interval so that the FW can wait until after the DTIM and
3406 * then start the time event, this will potentially allow us to
3407 * remain off-channel for the max duration.
3408 * Since we want to use almost a whole dtim interval we would also
3409 * like the delay to be for 2-3 dtim intervals, in case there are
3410 * other time events with higher priority.
3412 if (vif->bss_conf.assoc) {
3413 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3414 /* We cannot remain off-channel longer than the DTIM interval */
3415 if (dtim_interval <= req_dur) {
3416 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3417 if (req_dur <= AUX_ROC_MIN_DURATION)
3418 req_dur = dtim_interval -
3419 AUX_ROC_MIN_SAFETY_BUFFER;
3423 aux_roc_req.duration = cpu_to_le32(req_dur);
3424 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3427 "ROC: Requesting to remain on channel %u for %ums\n",
3428 channel->hw_value, req_dur);
3430 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3431 duration, delay, dtim_interval);
3433 /* Set the node address */
3434 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3436 lockdep_assert_held(&mvm->mutex);
3438 spin_lock_bh(&mvm->time_event_lock);
3440 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3441 spin_unlock_bh(&mvm->time_event_lock);
3446 te_data->duration = duration;
3447 te_data->id = HOT_SPOT_CMD;
3449 spin_unlock_bh(&mvm->time_event_lock);
3452 * Use a notification wait, which really just processes the
3453 * command response and doesn't wait for anything, in order
3454 * to be able to process the response and get the UID inside
3455 * the RX path. Using CMD_WANT_SKB doesn't work because it
3456 * stores the buffer and then wakes up this thread, by which
3457 * time another notification (that the time event started)
3458 * might already be processed unsuccessfully.
3460 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3461 time_event_response,
3462 ARRAY_SIZE(time_event_response),
3463 iwl_mvm_rx_aux_roc, te_data);
3465 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3469 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3470 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3474 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3475 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3476 /* should never fail */
3481 spin_lock_bh(&mvm->time_event_lock);
3482 iwl_mvm_te_clear_data(mvm, te_data);
3483 spin_unlock_bh(&mvm->time_event_lock);
3489 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3490 struct ieee80211_vif *vif,
3491 struct ieee80211_channel *channel,
3493 enum ieee80211_roc_type type)
3495 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3496 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3497 struct cfg80211_chan_def chandef;
3498 struct iwl_mvm_phy_ctxt *phy_ctxt;
3499 bool band_change_removal;
3502 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3506 * Flush the done work, just in case it's still pending, so that
3507 * the work it does can complete and we can accept new frames.
3509 flush_work(&mvm->roc_done_wk);
3511 mutex_lock(&mvm->mutex);
3513 switch (vif->type) {
3514 case NL80211_IFTYPE_STATION:
3515 if (fw_has_capa(&mvm->fw->ucode_capa,
3516 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3517 /* Use aux roc framework (HS20) */
3518 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3522 IWL_ERR(mvm, "hotspot not supported\n");
3525 case NL80211_IFTYPE_P2P_DEVICE:
3529 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3534 for (i = 0; i < NUM_PHY_CTX; i++) {
3535 phy_ctxt = &mvm->phy_ctxts[i];
3536 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3539 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3541 * Unbind the P2P_DEVICE from the current PHY context,
3542 * and if the PHY context is not used remove it.
3544 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3545 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3548 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3550 /* Bind the P2P_DEVICE to the current PHY Context */
3551 mvmvif->phy_ctxt = phy_ctxt;
3553 ret = iwl_mvm_binding_add_vif(mvm, vif);
3554 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3557 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3558 goto schedule_time_event;
3562 /* Need to update the PHY context only if the ROC channel changed */
3563 if (channel == mvmvif->phy_ctxt->channel)
3564 goto schedule_time_event;
3566 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3569 * Check if the remain-on-channel is on a different band and that
3570 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3571 * so, we'll need to release and then re-configure here, since we
3572 * must not remove a PHY context that's part of a binding.
3574 band_change_removal =
3575 fw_has_capa(&mvm->fw->ucode_capa,
3576 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3577 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3579 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3581 * Change the PHY context configuration as it is currently
3582 * referenced only by the P2P Device MAC (and we can modify it)
3584 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3590 * The PHY context is shared with other MACs (or we're trying to
3591 * switch bands), so remove the P2P Device from the binding,
3592 * allocate an new PHY context and create a new binding.
3594 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3600 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3603 IWL_ERR(mvm, "Failed to change PHY context\n");
3607 /* Unbind the P2P_DEVICE from the current PHY context */
3608 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3609 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3612 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3614 /* Bind the P2P_DEVICE to the new allocated PHY context */
3615 mvmvif->phy_ctxt = phy_ctxt;
3617 ret = iwl_mvm_binding_add_vif(mvm, vif);
3618 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3621 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3624 schedule_time_event:
3625 /* Schedule the time events */
3626 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3629 mutex_unlock(&mvm->mutex);
3630 IWL_DEBUG_MAC80211(mvm, "leave\n");
3634 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3636 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3638 IWL_DEBUG_MAC80211(mvm, "enter\n");
3640 mutex_lock(&mvm->mutex);
3641 iwl_mvm_stop_roc(mvm);
3642 mutex_unlock(&mvm->mutex);
3644 IWL_DEBUG_MAC80211(mvm, "leave\n");
3648 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3649 struct ieee80211_chanctx_conf *ctx)
3651 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3652 struct iwl_mvm_phy_ctxt *phy_ctxt;
3655 lockdep_assert_held(&mvm->mutex);
3657 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3659 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3665 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3666 ctx->rx_chains_static,
3667 ctx->rx_chains_dynamic);
3669 IWL_ERR(mvm, "Failed to add PHY context\n");
3673 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3674 *phy_ctxt_id = phy_ctxt->id;
3679 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3680 struct ieee80211_chanctx_conf *ctx)
3682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3685 mutex_lock(&mvm->mutex);
3686 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3687 mutex_unlock(&mvm->mutex);
3692 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3693 struct ieee80211_chanctx_conf *ctx)
3695 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3696 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3698 lockdep_assert_held(&mvm->mutex);
3700 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3703 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3704 struct ieee80211_chanctx_conf *ctx)
3706 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3708 mutex_lock(&mvm->mutex);
3709 __iwl_mvm_remove_chanctx(mvm, ctx);
3710 mutex_unlock(&mvm->mutex);
3713 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3714 struct ieee80211_chanctx_conf *ctx,
3717 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3718 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3719 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3721 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3722 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3723 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3724 IEEE80211_CHANCTX_CHANGE_RADAR |
3725 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3726 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3727 phy_ctxt->ref, changed))
3730 mutex_lock(&mvm->mutex);
3732 /* we are only changing the min_width, may be a noop */
3733 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3734 if (phy_ctxt->width == ctx->min_def.width)
3737 /* we are just toggling between 20_NOHT and 20 */
3738 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3739 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3743 iwl_mvm_bt_coex_vif_change(mvm);
3744 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3745 ctx->rx_chains_static,
3746 ctx->rx_chains_dynamic);
3749 mutex_unlock(&mvm->mutex);
3752 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3753 struct ieee80211_vif *vif,
3754 struct ieee80211_chanctx_conf *ctx,
3755 bool switching_chanctx)
3757 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3758 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3759 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3762 lockdep_assert_held(&mvm->mutex);
3764 mvmvif->phy_ctxt = phy_ctxt;
3766 switch (vif->type) {
3767 case NL80211_IFTYPE_AP:
3768 /* only needed if we're switching chanctx (i.e. during CSA) */
3769 if (switching_chanctx) {
3770 mvmvif->ap_ibss_active = true;
3773 case NL80211_IFTYPE_ADHOC:
3775 * The AP binding flow is handled as part of the start_ap flow
3776 * (in bss_info_changed), similarly for IBSS.
3780 case NL80211_IFTYPE_STATION:
3781 mvmvif->csa_bcn_pending = false;
3783 case NL80211_IFTYPE_MONITOR:
3784 /* always disable PS when a monitor interface is active */
3785 mvmvif->ps_disabled = true;
3792 ret = iwl_mvm_binding_add_vif(mvm, vif);
3797 * Power state must be updated before quotas,
3798 * otherwise fw will complain.
3800 iwl_mvm_power_update_mac(mvm);
3802 /* Setting the quota at this stage is only required for monitor
3803 * interfaces. For the other types, the bss_info changed flow
3804 * will handle quota settings.
3806 if (vif->type == NL80211_IFTYPE_MONITOR) {
3807 mvmvif->monitor_active = true;
3808 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3810 goto out_remove_binding;
3812 ret = iwl_mvm_add_snif_sta(mvm, vif);
3814 goto out_remove_binding;
3818 /* Handle binding during CSA */
3819 if (vif->type == NL80211_IFTYPE_AP) {
3820 iwl_mvm_update_quotas(mvm, false, NULL);
3821 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3824 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3825 u32 duration = 3 * vif->bss_conf.beacon_int;
3827 /* iwl_mvm_protect_session() reads directly from the
3828 * device (the system time), so make sure it is
3831 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3833 goto out_remove_binding;
3835 /* Protect the session to make sure we hear the first
3836 * beacon on the new channel.
3838 mvmvif->csa_bcn_pending = true;
3839 iwl_mvm_protect_session(mvm, vif, duration, duration,
3840 vif->bss_conf.beacon_int / 2,
3843 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3845 iwl_mvm_update_quotas(mvm, false, NULL);
3851 iwl_mvm_binding_remove_vif(mvm, vif);
3852 iwl_mvm_power_update_mac(mvm);
3855 mvmvif->phy_ctxt = NULL;
3858 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3859 struct ieee80211_vif *vif,
3860 struct ieee80211_chanctx_conf *ctx)
3862 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3865 mutex_lock(&mvm->mutex);
3866 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3867 mutex_unlock(&mvm->mutex);
3872 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3873 struct ieee80211_vif *vif,
3874 struct ieee80211_chanctx_conf *ctx,
3875 bool switching_chanctx)
3877 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3878 struct ieee80211_vif *disabled_vif = NULL;
3880 lockdep_assert_held(&mvm->mutex);
3882 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3884 switch (vif->type) {
3885 case NL80211_IFTYPE_ADHOC:
3887 case NL80211_IFTYPE_MONITOR:
3888 mvmvif->monitor_active = false;
3889 mvmvif->ps_disabled = false;
3890 iwl_mvm_rm_snif_sta(mvm, vif);
3892 case NL80211_IFTYPE_AP:
3893 /* This part is triggered only during CSA */
3894 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3897 mvmvif->csa_countdown = false;
3899 /* Set CS bit on all the stations */
3900 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3902 /* Save blocked iface, the timeout is set on the next beacon */
3903 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3905 mvmvif->ap_ibss_active = false;
3907 case NL80211_IFTYPE_STATION:
3908 if (!switching_chanctx)
3913 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3919 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3920 iwl_mvm_binding_remove_vif(mvm, vif);
3923 mvmvif->phy_ctxt = NULL;
3924 iwl_mvm_power_update_mac(mvm);
3927 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3928 struct ieee80211_vif *vif,
3929 struct ieee80211_chanctx_conf *ctx)
3931 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3933 mutex_lock(&mvm->mutex);
3934 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3935 mutex_unlock(&mvm->mutex);
3939 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3940 struct ieee80211_vif_chanctx_switch *vifs)
3944 mutex_lock(&mvm->mutex);
3945 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3946 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3948 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3950 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3954 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3958 "failed to assign new_ctx during channel switch\n");
3962 /* we don't support TDLS during DCM - can be caused by channel switch */
3963 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3964 iwl_mvm_teardown_tdls_peers(mvm);
3969 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3972 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3973 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3977 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3979 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3986 /* things keep failing, better restart the hw */
3987 iwl_mvm_nic_restart(mvm, false);
3990 mutex_unlock(&mvm->mutex);
3996 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3997 struct ieee80211_vif_chanctx_switch *vifs)
4001 mutex_lock(&mvm->mutex);
4002 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4004 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4008 "failed to assign new_ctx during channel switch\n");
4015 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4017 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4024 /* things keep failing, better restart the hw */
4025 iwl_mvm_nic_restart(mvm, false);
4028 mutex_unlock(&mvm->mutex);
4033 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4034 struct ieee80211_vif_chanctx_switch *vifs,
4036 enum ieee80211_chanctx_switch_mode mode)
4038 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4041 /* we only support a single-vif right now */
4046 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4047 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4049 case CHANCTX_SWMODE_REASSIGN_VIF:
4050 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4060 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4064 return mvm->ibss_manager;
4067 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4068 struct ieee80211_sta *sta,
4071 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4072 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4074 if (!mvm_sta || !mvm_sta->vif) {
4075 IWL_ERR(mvm, "Station is not associated to a vif\n");
4079 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4082 #ifdef CONFIG_NL80211_TESTMODE
4083 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4084 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4085 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4086 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4089 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4090 struct ieee80211_vif *vif,
4091 void *data, int len)
4093 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4097 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4102 if (!tb[IWL_MVM_TM_ATTR_CMD])
4105 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4106 case IWL_MVM_TM_CMD_SET_NOA:
4107 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4108 !vif->bss_conf.enable_beacon ||
4109 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4112 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4113 if (noa_duration >= vif->bss_conf.beacon_int)
4116 mvm->noa_duration = noa_duration;
4119 return iwl_mvm_update_quotas(mvm, true, NULL);
4120 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4121 /* must be associated client vif - ignore authorized */
4122 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4123 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4124 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4127 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4128 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4129 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4135 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4136 struct ieee80211_vif *vif,
4137 void *data, int len)
4139 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4142 mutex_lock(&mvm->mutex);
4143 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4144 mutex_unlock(&mvm->mutex);
4150 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4151 struct ieee80211_vif *vif,
4152 struct ieee80211_channel_switch *chsw)
4154 /* By implementing this operation, we prevent mac80211 from
4155 * starting its own channel switch timer, so that we can call
4156 * ieee80211_chswitch_done() ourselves at the right time
4157 * (which is when the absence time event starts).
4160 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4161 "dummy channel switch op\n");
4164 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4165 struct ieee80211_vif *vif,
4166 struct ieee80211_channel_switch *chsw)
4168 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4169 struct ieee80211_vif *csa_vif;
4170 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4174 mutex_lock(&mvm->mutex);
4176 mvmvif->csa_failed = false;
4178 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4179 chsw->chandef.center_freq1);
4181 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4182 ieee80211_vif_to_wdev(vif),
4183 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4185 switch (vif->type) {
4186 case NL80211_IFTYPE_AP:
4188 rcu_dereference_protected(mvm->csa_vif,
4189 lockdep_is_held(&mvm->mutex));
4190 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4191 "Another CSA is already in progress")) {
4196 /* we still didn't unblock tx. prevent new CS meanwhile */
4197 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4198 lockdep_is_held(&mvm->mutex))) {
4203 rcu_assign_pointer(mvm->csa_vif, vif);
4205 if (WARN_ONCE(mvmvif->csa_countdown,
4206 "Previous CSA countdown didn't complete")) {
4211 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4214 case NL80211_IFTYPE_STATION:
4215 /* Schedule the time event to a bit before beacon 1,
4216 * to make sure we're in the new channel when the
4217 * GO/AP arrives. In case count <= 1 immediately schedule the
4218 * TE (this might result with some packet loss or connection
4221 if (chsw->count <= 1)
4224 apply_time = chsw->device_timestamp +
4225 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4226 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4229 iwl_mvm_csa_client_absent(mvm, vif);
4231 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4233 if (mvmvif->bf_data.bf_enabled) {
4234 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4244 mvmvif->ps_disabled = true;
4246 ret = iwl_mvm_power_update_ps(mvm);
4250 /* we won't be on this channel any longer */
4251 iwl_mvm_teardown_tdls_peers(mvm);
4254 mutex_unlock(&mvm->mutex);
4259 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4260 struct ieee80211_vif *vif)
4262 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4263 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4266 mutex_lock(&mvm->mutex);
4268 if (mvmvif->csa_failed) {
4269 mvmvif->csa_failed = false;
4274 if (vif->type == NL80211_IFTYPE_STATION) {
4275 struct iwl_mvm_sta *mvmsta;
4277 mvmvif->csa_bcn_pending = false;
4278 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4281 if (WARN_ON(!mvmsta)) {
4286 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4288 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4290 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4294 iwl_mvm_stop_session_protection(mvm, vif);
4297 mvmvif->ps_disabled = false;
4299 ret = iwl_mvm_power_update_ps(mvm);
4302 mutex_unlock(&mvm->mutex);
4307 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4311 if (!iwl_mvm_has_new_tx_api(mvm)) {
4313 mutex_lock(&mvm->mutex);
4314 iwl_mvm_flush_tx_path(mvm,
4315 iwl_mvm_flushable_queues(mvm) & queues, 0);
4316 mutex_unlock(&mvm->mutex);
4318 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4323 mutex_lock(&mvm->mutex);
4324 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4325 struct ieee80211_sta *sta;
4327 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4328 lockdep_is_held(&mvm->mutex));
4329 if (IS_ERR_OR_NULL(sta))
4333 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4335 iwl_mvm_wait_sta_queues_empty(mvm,
4336 iwl_mvm_sta_from_mac80211(sta));
4338 mutex_unlock(&mvm->mutex);
4341 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4342 struct ieee80211_vif *vif, u32 queues, bool drop)
4344 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4345 struct iwl_mvm_vif *mvmvif;
4346 struct iwl_mvm_sta *mvmsta;
4347 struct ieee80211_sta *sta;
4352 iwl_mvm_flush_no_vif(mvm, queues, drop);
4356 if (vif->type != NL80211_IFTYPE_STATION)
4359 /* Make sure we're done with the deferred traffic before flushing */
4360 flush_work(&mvm->add_stream_wk);
4362 mutex_lock(&mvm->mutex);
4363 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4365 /* flush the AP-station and all TDLS peers */
4366 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4367 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4368 lockdep_is_held(&mvm->mutex));
4369 if (IS_ERR_OR_NULL(sta))
4372 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4373 if (mvmsta->vif != vif)
4376 /* make sure only TDLS peers or the AP are flushed */
4377 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4380 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4381 IWL_ERR(mvm, "flush request fail\n");
4383 msk |= mvmsta->tfd_queue_msk;
4384 if (iwl_mvm_has_new_tx_api(mvm))
4385 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4389 mutex_unlock(&mvm->mutex);
4391 /* this can take a while, and we may need/want other operations
4392 * to succeed while doing this, so do it without the mutex held
4394 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4395 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4398 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4399 struct survey_info *survey)
4401 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4404 memset(survey, 0, sizeof(*survey));
4406 /* only support global statistics right now */
4410 if (!fw_has_capa(&mvm->fw->ucode_capa,
4411 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4414 mutex_lock(&mvm->mutex);
4416 if (iwl_mvm_firmware_running(mvm)) {
4417 ret = iwl_mvm_request_statistics(mvm, false);
4422 survey->filled = SURVEY_INFO_TIME |
4423 SURVEY_INFO_TIME_RX |
4424 SURVEY_INFO_TIME_TX |
4425 SURVEY_INFO_TIME_SCAN;
4426 survey->time = mvm->accu_radio_stats.on_time_rf +
4427 mvm->radio_stats.on_time_rf;
4428 do_div(survey->time, USEC_PER_MSEC);
4430 survey->time_rx = mvm->accu_radio_stats.rx_time +
4431 mvm->radio_stats.rx_time;
4432 do_div(survey->time_rx, USEC_PER_MSEC);
4434 survey->time_tx = mvm->accu_radio_stats.tx_time +
4435 mvm->radio_stats.tx_time;
4436 do_div(survey->time_tx, USEC_PER_MSEC);
4438 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4439 mvm->radio_stats.on_time_scan;
4440 do_div(survey->time_scan, USEC_PER_MSEC);
4444 mutex_unlock(&mvm->mutex);
4448 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4449 struct ieee80211_vif *vif,
4450 struct ieee80211_sta *sta,
4451 struct station_info *sinfo)
4453 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4454 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4455 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4457 if (mvmsta->avg_energy) {
4458 sinfo->signal_avg = mvmsta->avg_energy;
4459 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4462 /* if beacon filtering isn't on mac80211 does it anyway */
4463 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4466 if (!vif->bss_conf.assoc)
4469 mutex_lock(&mvm->mutex);
4471 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4474 if (iwl_mvm_request_statistics(mvm, false))
4477 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4478 mvmvif->beacon_stats.accu_num_beacons;
4479 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4480 if (mvmvif->beacon_stats.avg_signal) {
4481 /* firmware only reports a value after RXing a few beacons */
4482 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4483 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4486 mutex_unlock(&mvm->mutex);
4489 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4490 struct ieee80211_vif *vif,
4491 const struct ieee80211_event *event)
4493 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4495 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4497 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4500 struct iwl_fw_dbg_trigger_tlv *trig;
4501 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4503 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4506 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4507 trig_mlme = (void *)trig->data;
4508 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4509 ieee80211_vif_to_wdev(vif), trig))
4512 if (event->u.mlme.data == ASSOC_EVENT) {
4513 if (event->u.mlme.status == MLME_DENIED)
4514 CHECK_MLME_TRIGGER(stop_assoc_denied,
4515 "DENIED ASSOC: reason %d",
4516 event->u.mlme.reason);
4517 else if (event->u.mlme.status == MLME_TIMEOUT)
4518 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4520 } else if (event->u.mlme.data == AUTH_EVENT) {
4521 if (event->u.mlme.status == MLME_DENIED)
4522 CHECK_MLME_TRIGGER(stop_auth_denied,
4523 "DENIED AUTH: reason %d",
4524 event->u.mlme.reason);
4525 else if (event->u.mlme.status == MLME_TIMEOUT)
4526 CHECK_MLME_TRIGGER(stop_auth_timeout,
4528 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4529 CHECK_MLME_TRIGGER(stop_rx_deauth,
4530 "DEAUTH RX %d", event->u.mlme.reason);
4531 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4532 CHECK_MLME_TRIGGER(stop_tx_deauth,
4533 "DEAUTH TX %d", event->u.mlme.reason);
4535 #undef CHECK_MLME_TRIGGER
4538 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4539 struct ieee80211_vif *vif,
4540 const struct ieee80211_event *event)
4542 struct iwl_fw_dbg_trigger_tlv *trig;
4543 struct iwl_fw_dbg_trigger_ba *ba_trig;
4545 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4548 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4549 ba_trig = (void *)trig->data;
4550 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4551 ieee80211_vif_to_wdev(vif), trig))
4554 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4557 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4558 "BAR received from %pM, tid %d, ssn %d",
4559 event->u.ba.sta->addr, event->u.ba.tid,
4563 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4564 struct ieee80211_vif *vif,
4565 const struct ieee80211_event *event)
4567 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4569 switch (event->type) {
4571 iwl_mvm_event_mlme_callback(mvm, vif, event);
4574 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4576 case BA_FRAME_TIMEOUT:
4577 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4585 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4586 struct iwl_mvm_internal_rxq_notif *notif,
4589 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4592 lockdep_assert_held(&mvm->mutex);
4594 if (!iwl_mvm_has_new_rx_api(mvm))
4597 notif->cookie = mvm->queue_sync_cookie;
4600 atomic_set(&mvm->queue_sync_counter,
4601 mvm->trans->num_rx_queues);
4603 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4605 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4610 ret = wait_event_timeout(mvm->rx_sync_waitq,
4611 atomic_read(&mvm->queue_sync_counter) == 0 ||
4612 iwl_mvm_is_radio_killed(mvm),
4614 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4618 atomic_set(&mvm->queue_sync_counter, 0);
4619 mvm->queue_sync_cookie++;
4622 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4624 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4625 struct iwl_mvm_internal_rxq_notif data = {
4626 .type = IWL_MVM_RXQ_EMPTY,
4630 mutex_lock(&mvm->mutex);
4631 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4632 mutex_unlock(&mvm->mutex);
4635 const struct ieee80211_ops iwl_mvm_hw_ops = {
4636 .tx = iwl_mvm_mac_tx,
4637 .ampdu_action = iwl_mvm_mac_ampdu_action,
4638 .start = iwl_mvm_mac_start,
4639 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4640 .stop = iwl_mvm_mac_stop,
4641 .add_interface = iwl_mvm_mac_add_interface,
4642 .remove_interface = iwl_mvm_mac_remove_interface,
4643 .config = iwl_mvm_mac_config,
4644 .prepare_multicast = iwl_mvm_prepare_multicast,
4645 .configure_filter = iwl_mvm_configure_filter,
4646 .config_iface_filter = iwl_mvm_config_iface_filter,
4647 .bss_info_changed = iwl_mvm_bss_info_changed,
4648 .hw_scan = iwl_mvm_mac_hw_scan,
4649 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4650 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4651 .sta_state = iwl_mvm_mac_sta_state,
4652 .sta_notify = iwl_mvm_mac_sta_notify,
4653 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4654 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4655 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4656 .sta_rc_update = iwl_mvm_sta_rc_update,
4657 .conf_tx = iwl_mvm_mac_conf_tx,
4658 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4659 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4660 .flush = iwl_mvm_mac_flush,
4661 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4662 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4663 .set_key = iwl_mvm_mac_set_key,
4664 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4665 .remain_on_channel = iwl_mvm_roc,
4666 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4667 .add_chanctx = iwl_mvm_add_chanctx,
4668 .remove_chanctx = iwl_mvm_remove_chanctx,
4669 .change_chanctx = iwl_mvm_change_chanctx,
4670 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4671 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4672 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4674 .start_ap = iwl_mvm_start_ap_ibss,
4675 .stop_ap = iwl_mvm_stop_ap_ibss,
4676 .join_ibss = iwl_mvm_start_ap_ibss,
4677 .leave_ibss = iwl_mvm_stop_ap_ibss,
4679 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4681 .set_tim = iwl_mvm_set_tim,
4683 .channel_switch = iwl_mvm_channel_switch,
4684 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4685 .post_channel_switch = iwl_mvm_post_channel_switch,
4687 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4688 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4689 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4691 .event_callback = iwl_mvm_mac_event_callback,
4693 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4695 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4697 #ifdef CONFIG_PM_SLEEP
4699 .suspend = iwl_mvm_suspend,
4700 .resume = iwl_mvm_resume,
4701 .set_wakeup = iwl_mvm_set_wakeup,
4702 .set_rekey_data = iwl_mvm_set_rekey_data,
4703 #if IS_ENABLED(CONFIG_IPV6)
4704 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4706 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4708 .get_survey = iwl_mvm_mac_get_survey,
4709 .sta_statistics = iwl_mvm_mac_sta_statistics,
4710 #ifdef CONFIG_IWLWIFI_DEBUGFS
4711 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,