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 = {
1628 lockdep_assert_held(&mvm->mutex);
1630 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1633 ieee80211_iterate_active_interfaces_atomic(
1634 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1635 iwl_mvm_mc_iface_iterator, &iter_data);
1638 * Send a (synchronous) ech command so that we wait for the
1639 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1640 * the interface iterator. Otherwise, we might get here over
1641 * and over again (by userspace just sending a lot of these)
1642 * and the CPU can send them faster than the firmware can
1644 * Note that the CPU is still faster - but with this we'll
1645 * actually send fewer commands overall because the CPU will
1646 * not schedule the work in mac80211 as frequently if it's
1647 * still running when rescheduled (possibly multiple times).
1649 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1651 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1654 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1655 struct netdev_hw_addr_list *mc_list)
1657 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1658 struct iwl_mcast_filter_cmd *cmd;
1659 struct netdev_hw_addr *addr;
1664 addr_count = netdev_hw_addr_list_count(mc_list);
1665 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1666 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1670 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1671 cmd = kzalloc(len, GFP_ATOMIC);
1677 return (u64)(unsigned long)cmd;
1680 netdev_hw_addr_list_for_each(addr, mc_list) {
1681 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1682 cmd->count, addr->addr);
1683 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1684 addr->addr, ETH_ALEN);
1688 return (u64)(unsigned long)cmd;
1691 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1692 unsigned int changed_flags,
1693 unsigned int *total_flags,
1696 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1697 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1699 mutex_lock(&mvm->mutex);
1701 /* replace previous configuration */
1702 kfree(mvm->mcast_filter_cmd);
1703 mvm->mcast_filter_cmd = cmd;
1708 if (changed_flags & FIF_ALLMULTI)
1709 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1714 iwl_mvm_recalc_multicast(mvm);
1716 mutex_unlock(&mvm->mutex);
1720 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1721 struct ieee80211_vif *vif,
1722 unsigned int filter_flags,
1723 unsigned int changed_flags)
1725 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1727 /* We support only filter for probe requests */
1728 if (!(changed_flags & FIF_PROBE_REQ))
1731 /* Supported only for p2p client interfaces */
1732 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1736 mutex_lock(&mvm->mutex);
1737 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1738 mutex_unlock(&mvm->mutex);
1741 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1742 struct iwl_bcast_iter_data {
1743 struct iwl_mvm *mvm;
1744 struct iwl_bcast_filter_cmd *cmd;
1749 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1750 const struct iwl_fw_bcast_filter *in_filter,
1751 struct iwl_fw_bcast_filter *out_filter)
1753 struct iwl_fw_bcast_filter_attr *attr;
1756 memcpy(out_filter, in_filter, sizeof(*out_filter));
1758 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1759 attr = &out_filter->attrs[i];
1764 switch (attr->reserved1) {
1765 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1766 if (vif->bss_conf.arp_addr_cnt != 1) {
1771 attr->val = vif->bss_conf.arp_addr_list[0];
1773 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1774 attr->val = *(__be32 *)&vif->addr[2];
1779 attr->reserved1 = 0;
1780 out_filter->num_attrs++;
1784 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1785 struct ieee80211_vif *vif)
1787 struct iwl_bcast_iter_data *data = _data;
1788 struct iwl_mvm *mvm = data->mvm;
1789 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1790 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1791 struct iwl_fw_bcast_mac *bcast_mac;
1794 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1797 bcast_mac = &cmd->macs[mvmvif->id];
1800 * enable filtering only for associated stations, but not for P2P
1803 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1804 !vif->bss_conf.assoc)
1807 bcast_mac->default_discard = 1;
1809 /* copy all configured filters */
1810 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1812 * Make sure we don't exceed our filters limit.
1813 * if there is still a valid filter to be configured,
1814 * be on the safe side and just allow bcast for this mac.
1816 if (WARN_ON_ONCE(data->current_filter >=
1817 ARRAY_SIZE(cmd->filters))) {
1818 bcast_mac->default_discard = 0;
1819 bcast_mac->attached_filters = 0;
1823 iwl_mvm_set_bcast_filter(vif,
1824 &mvm->bcast_filters[i],
1825 &cmd->filters[data->current_filter]);
1827 /* skip current filter if it contains no attributes */
1828 if (!cmd->filters[data->current_filter].num_attrs)
1831 /* attach the filter to current mac */
1832 bcast_mac->attached_filters |=
1833 cpu_to_le16(BIT(data->current_filter));
1835 data->current_filter++;
1839 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1840 struct iwl_bcast_filter_cmd *cmd)
1842 struct iwl_bcast_iter_data iter_data = {
1847 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1850 memset(cmd, 0, sizeof(*cmd));
1851 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1852 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1854 #ifdef CONFIG_IWLWIFI_DEBUGFS
1855 /* use debugfs filters/macs if override is configured */
1856 if (mvm->dbgfs_bcast_filtering.override) {
1857 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1858 sizeof(cmd->filters));
1859 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1865 /* if no filters are configured, do nothing */
1866 if (!mvm->bcast_filters)
1869 /* configure and attach these filters for each associated sta vif */
1870 ieee80211_iterate_active_interfaces(
1871 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1872 iwl_mvm_bcast_filter_iterator, &iter_data);
1877 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1879 struct iwl_bcast_filter_cmd cmd;
1881 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1884 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1887 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1891 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1897 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1898 struct ieee80211_vif *vif)
1900 struct iwl_mu_group_mgmt_cmd cmd = {};
1902 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1903 WLAN_MEMBERSHIP_LEN);
1904 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1905 WLAN_USER_POSITION_LEN);
1907 return iwl_mvm_send_cmd_pdu(mvm,
1908 WIDE_ID(DATA_PATH_GROUP,
1909 UPDATE_MU_GROUPS_CMD),
1910 0, sizeof(cmd), &cmd);
1913 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1914 struct ieee80211_vif *vif)
1916 if (vif->mu_mimo_owner) {
1917 struct iwl_mu_group_mgmt_notif *notif = _data;
1920 * MU-MIMO Group Id action frame is little endian. We treat
1921 * the data received from firmware as if it came from the
1922 * action frame, so no conversion is needed.
1924 ieee80211_update_mu_groups(vif,
1925 (u8 *)¬if->membership_status,
1926 (u8 *)¬if->user_position);
1930 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1931 struct iwl_rx_cmd_buffer *rxb)
1933 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1934 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1936 ieee80211_iterate_active_interfaces_atomic(
1937 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1938 iwl_mvm_mu_mimo_iface_iterator, notif);
1941 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1943 u8 byte_num = ppe_pos_bit / 8;
1944 u8 bit_num = ppe_pos_bit % 8;
1949 return (ppe[byte_num] >> bit_num) &
1950 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1953 * If bit_num > 5, we have to combine bits with next byte.
1954 * Calculate how many bits we need to take from current byte (called
1955 * here "residue_bits"), and add them to bits from next byte.
1958 residue_bits = 8 - bit_num;
1960 res = (ppe[byte_num + 1] &
1961 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1963 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1968 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1969 struct ieee80211_vif *vif, u8 sta_id)
1971 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1972 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1974 .tid_limit = IWL_MAX_TID_COUNT,
1975 .bss_color = vif->bss_conf.bss_color,
1976 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1977 .frame_time_rts_th =
1978 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1980 struct ieee80211_sta *sta;
1986 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1989 WARN(1, "Can't find STA to configure HE\n");
1993 if (!sta->he_cap.has_he) {
2001 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2002 IEEE80211_HE_MAC_CAP0_HTC_HE)
2003 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2004 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2005 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2006 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2007 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2009 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2010 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2011 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2012 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2015 sta_ctxt_cmd.htc_flags |=
2016 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2017 else if (link_adap == 3)
2018 sta_ctxt_cmd.htc_flags |=
2019 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2021 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2022 IEEE80211_HE_MAC_CAP2_UL_MU_RESP_SCHED)
2023 sta_ctxt_cmd.htc_flags |=
2024 cpu_to_le32(IWL_HE_HTC_UL_MU_RESP_SCHED);
2025 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2026 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2027 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2028 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2029 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2030 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2031 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2034 * Initialize the PPE thresholds to "None" (7), as described in Table
2035 * 9-262ac of 80211.ax/D3.0.
2037 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2039 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2040 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2041 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2042 u8 nss = (sta->he_cap.ppe_thres[0] &
2043 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2044 u8 ru_index_bitmap =
2045 (sta->he_cap.ppe_thres[0] &
2046 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2047 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2048 u8 *ppe = &sta->he_cap.ppe_thres[0];
2049 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2052 * FW currently supports only nss == MAX_HE_SUPP_NSS
2054 * If nss > MAX: we can ignore values we don't support
2055 * If nss < MAX: we can set zeros in other streams
2057 if (nss > MAX_HE_SUPP_NSS) {
2058 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2060 nss = MAX_HE_SUPP_NSS;
2063 for (i = 0; i < nss; i++) {
2064 u8 ru_index_tmp = ru_index_bitmap << 1;
2067 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2069 if (!(ru_index_tmp & 1))
2072 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2073 iwl_mvm_he_get_ppe_val(ppe,
2076 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2077 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2078 iwl_mvm_he_get_ppe_val(ppe,
2081 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2085 flags |= STA_CTXT_HE_PACKET_EXT;
2089 /* Mark MU EDCA as enabled, unless none detected on some AC */
2090 flags |= STA_CTXT_HE_MU_EDCA_CW;
2091 for (i = 0; i < AC_NUM; i++) {
2092 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2093 &mvmvif->queue_params[i].mu_edca_param_rec;
2095 if (!mvmvif->queue_params[i].mu_edca) {
2096 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2100 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2101 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2102 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2103 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2104 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2105 cpu_to_le16(mu_edca->aifsn);
2106 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2107 cpu_to_le16(mu_edca->mu_edca_timer);
2110 if (vif->bss_conf.multi_sta_back_32bit)
2111 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2113 if (vif->bss_conf.ack_enabled)
2114 flags |= STA_CTXT_HE_ACK_ENABLED;
2116 if (vif->bss_conf.uora_exists) {
2117 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2119 sta_ctxt_cmd.rand_alloc_ecwmin =
2120 vif->bss_conf.uora_ocw_range & 0x7;
2121 sta_ctxt_cmd.rand_alloc_ecwmax =
2122 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2125 /* TODO: support Multi BSSID IE */
2127 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2129 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2130 DATA_PATH_GROUP, 0),
2131 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2132 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2135 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2136 struct ieee80211_vif *vif,
2137 struct ieee80211_bss_conf *bss_conf,
2140 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2144 * Re-calculate the tsf id, as the master-slave relations depend on the
2145 * beacon interval, which was not known when the station interface was
2148 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2149 if (vif->bss_conf.he_support &&
2150 !iwlwifi_mod_params.disable_11ax)
2151 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2153 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2157 * If we're not associated yet, take the (new) BSSID before associating
2158 * so the firmware knows. If we're already associated, then use the old
2159 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2160 * branch for disassociation below.
2162 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2163 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2165 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2167 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2169 /* after sending it once, adopt mac80211 data */
2170 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2171 mvmvif->associated = bss_conf->assoc;
2173 if (changes & BSS_CHANGED_ASSOC) {
2174 if (bss_conf->assoc) {
2175 /* clear statistics to get clean beacon counter */
2176 iwl_mvm_request_statistics(mvm, true);
2177 memset(&mvmvif->beacon_stats, 0,
2178 sizeof(mvmvif->beacon_stats));
2180 /* add quota for this interface */
2181 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2183 IWL_ERR(mvm, "failed to update quotas\n");
2187 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2190 * If we're restarting then the firmware will
2191 * obviously have lost synchronisation with
2192 * the AP. It will attempt to synchronise by
2193 * itself, but we can make it more reliable by
2194 * scheduling a session protection time event.
2196 * The firmware needs to receive a beacon to
2197 * catch up with synchronisation, use 110% of
2198 * the beacon interval.
2200 * Set a large maximum delay to allow for more
2201 * than a single interface.
2203 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2204 iwl_mvm_protect_session(mvm, vif, dur, dur,
2208 iwl_mvm_sf_update(mvm, vif, false);
2209 iwl_mvm_power_vif_assoc(mvm, vif);
2211 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2212 iwl_mvm_update_smps(mvm, vif,
2213 IWL_MVM_SMPS_REQ_PROT,
2214 IEEE80211_SMPS_DYNAMIC);
2216 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2218 * If update fails - SF might be running in associated
2219 * mode while disassociated - which is forbidden.
2221 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2222 "Failed to update SF upon disassociation\n");
2225 * If we get an assert during the connection (after the
2226 * station has been added, but before the vif is set
2227 * to associated), mac80211 will re-add the station and
2228 * then configure the vif. Since the vif is not
2229 * associated, we would remove the station here and
2230 * this would fail the recovery.
2232 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2235 * Remove AP station now that
2236 * the MAC is unassoc
2238 ret = iwl_mvm_rm_sta_id(mvm, vif,
2242 "failed to remove AP station\n");
2244 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2245 mvm->d0i3_ap_sta_id =
2246 IWL_MVM_INVALID_STA;
2247 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2250 /* remove quota for this interface */
2251 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2253 IWL_ERR(mvm, "failed to update quotas\n");
2256 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2258 /* this will take the cleared BSSID from bss_conf */
2259 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2262 "failed to update MAC %pM (clear after unassoc)\n",
2267 * The firmware tracks the MU-MIMO group on its own.
2268 * However, on HW restart we should restore this data.
2270 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2271 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2272 ret = iwl_mvm_update_mu_groups(mvm, vif);
2275 "failed to update VHT MU_MIMO groups\n");
2278 iwl_mvm_recalc_multicast(mvm);
2279 iwl_mvm_configure_bcast_filter(mvm);
2281 /* reset rssi values */
2282 mvmvif->bf_data.ave_beacon_signal = 0;
2284 iwl_mvm_bt_coex_vif_change(mvm);
2285 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2286 IEEE80211_SMPS_AUTOMATIC);
2287 if (fw_has_capa(&mvm->fw->ucode_capa,
2288 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2289 iwl_mvm_config_scan(mvm);
2292 if (changes & BSS_CHANGED_BEACON_INFO) {
2294 * We received a beacon from the associated AP so
2295 * remove the session protection.
2297 iwl_mvm_stop_session_protection(mvm, vif);
2299 iwl_mvm_sf_update(mvm, vif, false);
2300 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2303 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2305 * Send power command on every beacon change,
2306 * because we may have not enabled beacon abort yet.
2308 BSS_CHANGED_BEACON_INFO)) {
2309 ret = iwl_mvm_power_update_mac(mvm);
2311 IWL_ERR(mvm, "failed to update power mode\n");
2314 if (changes & BSS_CHANGED_TXPOWER) {
2315 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2317 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2320 if (changes & BSS_CHANGED_CQM) {
2321 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2322 /* reset cqm events tracking */
2323 mvmvif->bf_data.last_cqm_event = 0;
2324 if (mvmvif->bf_data.bf_enabled) {
2325 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2328 "failed to update CQM thresholds\n");
2332 if (changes & BSS_CHANGED_ARP_FILTER) {
2333 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2334 iwl_mvm_configure_bcast_filter(mvm);
2338 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2339 struct ieee80211_vif *vif)
2341 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2342 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2346 * iwl_mvm_mac_ctxt_add() might read directly from the device
2347 * (the system time), so make sure it is available.
2349 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2353 mutex_lock(&mvm->mutex);
2355 /* Send the beacon template */
2356 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2361 * Re-calculate the tsf id, as the master-slave relations depend on the
2362 * beacon interval, which was not known when the AP interface was added.
2364 if (vif->type == NL80211_IFTYPE_AP)
2365 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2367 mvmvif->ap_assoc_sta_count = 0;
2369 /* Add the mac context */
2370 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2374 /* Perform the binding */
2375 ret = iwl_mvm_binding_add_vif(mvm, vif);
2380 * This is not very nice, but the simplest:
2381 * For older FWs adding the mcast sta before the bcast station may
2382 * cause assert 0x2b00.
2383 * This is fixed in later FW so make the order of removal depend on
2386 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2387 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2391 * Send the bcast station. At this stage the TBTT and DTIM time
2392 * events are added and applied to the scheduler
2394 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2396 iwl_mvm_rm_mcast_sta(mvm, vif);
2401 * Send the bcast station. At this stage the TBTT and DTIM time
2402 * events are added and applied to the scheduler
2404 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2407 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2409 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2414 /* must be set before quota calculations */
2415 mvmvif->ap_ibss_active = true;
2417 /* power updated needs to be done before quotas */
2418 iwl_mvm_power_update_mac(mvm);
2420 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2422 goto out_quota_failed;
2424 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2425 if (vif->p2p && mvm->p2p_device_vif)
2426 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2428 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2430 iwl_mvm_bt_coex_vif_change(mvm);
2432 /* we don't support TDLS during DCM */
2433 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2434 iwl_mvm_teardown_tdls_peers(mvm);
2439 iwl_mvm_power_update_mac(mvm);
2440 mvmvif->ap_ibss_active = false;
2441 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2442 iwl_mvm_rm_mcast_sta(mvm, vif);
2444 iwl_mvm_binding_remove_vif(mvm, vif);
2446 iwl_mvm_mac_ctxt_remove(mvm, vif);
2448 mutex_unlock(&mvm->mutex);
2449 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2453 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2454 struct ieee80211_vif *vif)
2456 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2457 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2459 iwl_mvm_prepare_mac_removal(mvm, vif);
2461 mutex_lock(&mvm->mutex);
2463 /* Handle AP stop while in CSA */
2464 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2465 iwl_mvm_remove_time_event(mvm, mvmvif,
2466 &mvmvif->time_event_data);
2467 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2468 mvmvif->csa_countdown = false;
2471 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2472 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2473 mvm->csa_tx_block_bcn_timeout = 0;
2476 mvmvif->ap_ibss_active = false;
2477 mvm->ap_last_beacon_gp2 = 0;
2479 iwl_mvm_bt_coex_vif_change(mvm);
2481 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2483 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2484 if (vif->p2p && mvm->p2p_device_vif)
2485 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2487 iwl_mvm_update_quotas(mvm, false, NULL);
2490 * This is not very nice, but the simplest:
2491 * For older FWs removing the mcast sta before the bcast station may
2492 * cause assert 0x2b00.
2493 * This is fixed in later FW (which will stop beaconing when removing
2495 * So make the order of removal depend on the TLV
2497 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2498 iwl_mvm_rm_mcast_sta(mvm, vif);
2499 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2500 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2501 iwl_mvm_rm_mcast_sta(mvm, vif);
2502 iwl_mvm_binding_remove_vif(mvm, vif);
2504 iwl_mvm_power_update_mac(mvm);
2506 iwl_mvm_mac_ctxt_remove(mvm, vif);
2508 mutex_unlock(&mvm->mutex);
2512 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2513 struct ieee80211_vif *vif,
2514 struct ieee80211_bss_conf *bss_conf,
2517 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2519 /* Changes will be applied when the AP/IBSS is started */
2520 if (!mvmvif->ap_ibss_active)
2523 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2524 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2525 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2526 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2528 /* Need to send a new beacon template to the FW */
2529 if (changes & BSS_CHANGED_BEACON &&
2530 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2531 IWL_WARN(mvm, "Failed updating beacon data\n");
2533 if (changes & BSS_CHANGED_TXPOWER) {
2534 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2536 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2540 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2541 struct ieee80211_vif *vif,
2542 struct ieee80211_bss_conf *bss_conf,
2545 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2548 * iwl_mvm_bss_info_changed_station() might call
2549 * iwl_mvm_protect_session(), which reads directly from
2550 * the device (the system time), so make sure it is available.
2552 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2555 mutex_lock(&mvm->mutex);
2557 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2558 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2560 switch (vif->type) {
2561 case NL80211_IFTYPE_STATION:
2562 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2564 case NL80211_IFTYPE_AP:
2565 case NL80211_IFTYPE_ADHOC:
2566 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2568 case NL80211_IFTYPE_MONITOR:
2569 if (changes & BSS_CHANGED_MU_GROUPS)
2570 iwl_mvm_update_mu_groups(mvm, vif);
2573 /* shouldn't happen */
2577 mutex_unlock(&mvm->mutex);
2578 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2581 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2582 struct ieee80211_vif *vif,
2583 struct ieee80211_scan_request *hw_req)
2585 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2588 if (hw_req->req.n_channels == 0 ||
2589 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2592 mutex_lock(&mvm->mutex);
2593 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2594 mutex_unlock(&mvm->mutex);
2599 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2600 struct ieee80211_vif *vif)
2602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2604 mutex_lock(&mvm->mutex);
2606 /* Due to a race condition, it's possible that mac80211 asks
2607 * us to stop a hw_scan when it's already stopped. This can
2608 * happen, for instance, if we stopped the scan ourselves,
2609 * called ieee80211_scan_completed() and the userspace called
2610 * cancel scan scan before ieee80211_scan_work() could run.
2611 * To handle that, simply return if the scan is not running.
2613 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2614 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2616 mutex_unlock(&mvm->mutex);
2620 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2621 struct ieee80211_sta *sta, u16 tids,
2623 enum ieee80211_frame_release_type reason,
2626 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2628 /* Called when we need to transmit (a) frame(s) from mac80211 */
2630 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2631 tids, more_data, false);
2635 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2636 struct ieee80211_sta *sta, u16 tids,
2638 enum ieee80211_frame_release_type reason,
2641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2643 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2645 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2646 tids, more_data, true);
2649 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2650 enum sta_notify_cmd cmd,
2651 struct ieee80211_sta *sta)
2653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2654 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2655 unsigned long txqs = 0, tids = 0;
2659 * If we have TVQM then we get too high queue numbers - luckily
2660 * we really shouldn't get here with that because such hardware
2661 * should have firmware supporting buffer station offload.
2663 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2666 spin_lock_bh(&mvmsta->lock);
2667 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2668 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2670 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2673 __set_bit(tid_data->txq_id, &txqs);
2675 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2678 __set_bit(tid, &tids);
2682 case STA_NOTIFY_SLEEP:
2683 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2684 ieee80211_sta_set_buffered(sta, tid, true);
2687 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2689 * The fw updates the STA to be asleep. Tx packets on the Tx
2690 * queues to this station will not be transmitted. The fw will
2691 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2694 case STA_NOTIFY_AWAKE:
2695 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2699 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2700 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2705 spin_unlock_bh(&mvmsta->lock);
2708 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2709 struct ieee80211_vif *vif,
2710 enum sta_notify_cmd cmd,
2711 struct ieee80211_sta *sta)
2713 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2716 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2718 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2719 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2720 struct ieee80211_sta *sta;
2721 struct iwl_mvm_sta *mvmsta;
2722 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2724 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2728 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2729 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2734 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2737 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2742 if (mvmsta->sleeping != sleeping) {
2743 mvmsta->sleeping = sleeping;
2744 __iwl_mvm_mac_sta_notify(mvm->hw,
2745 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2747 ieee80211_sta_ps_transition(sta, sleeping);
2751 switch (notif->type) {
2752 case IWL_MVM_PM_EVENT_AWAKE:
2753 case IWL_MVM_PM_EVENT_ASLEEP:
2755 case IWL_MVM_PM_EVENT_UAPSD:
2756 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2758 case IWL_MVM_PM_EVENT_PS_POLL:
2759 ieee80211_sta_pspoll(sta);
2769 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2770 struct ieee80211_vif *vif,
2771 struct ieee80211_sta *sta)
2773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2774 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2777 * This is called before mac80211 does RCU synchronisation,
2778 * so here we already invalidate our internal RCU-protected
2779 * station pointer. The rest of the code will thus no longer
2780 * be able to find the station this way, and we don't rely
2781 * on further RCU synchronisation after the sta_state()
2782 * callback deleted the station.
2784 mutex_lock(&mvm->mutex);
2785 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2786 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2789 mutex_unlock(&mvm->mutex);
2792 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2797 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2798 struct iwl_mvm_tcm_mac *mdata;
2800 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2801 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2802 mdata->opened_rx_ba_sessions = false;
2805 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2808 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2809 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2814 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2815 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2819 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2820 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2821 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2826 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2830 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2831 struct ieee80211_vif *vif, u8 *peer_addr,
2832 enum nl80211_tdls_operation action)
2834 struct iwl_fw_dbg_trigger_tlv *trig;
2835 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2837 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2840 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2841 tdls_trig = (void *)trig->data;
2842 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2843 ieee80211_vif_to_wdev(vif), trig))
2846 if (!(tdls_trig->action_bitmap & BIT(action)))
2849 if (tdls_trig->peer_mode &&
2850 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2853 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2854 "TDLS event occurred, peer %pM, action %d",
2858 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2859 struct iwl_mvm_sta *mvm_sta)
2861 struct iwl_mvm_tid_data *tid_data;
2862 struct sk_buff *skb;
2865 spin_lock_bh(&mvm_sta->lock);
2866 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2867 tid_data = &mvm_sta->tid_data[i];
2869 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2870 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2873 * The first deferred frame should've stopped the MAC
2874 * queues, so we should never get a second deferred
2875 * frame for the RA/TID.
2877 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2878 ieee80211_free_txskb(mvm->hw, skb);
2881 spin_unlock_bh(&mvm_sta->lock);
2884 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2885 struct ieee80211_vif *vif,
2886 struct ieee80211_sta *sta,
2887 enum ieee80211_sta_state old_state,
2888 enum ieee80211_sta_state new_state)
2890 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2891 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2892 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2895 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2896 sta->addr, old_state, new_state);
2898 /* this would be a mac80211 bug ... but don't crash */
2899 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2900 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
2903 * If we are in a STA removal flow and in DQA mode:
2905 * This is after the sync_rcu part, so the queues have already been
2906 * flushed. No more TXs on their way in mac80211's path, and no more in
2908 * Also, we won't be getting any new TX frames for this station.
2909 * What we might have are deferred TX frames that need to be taken care
2912 * Drop any still-queued deferred-frame before removing the STA, and
2913 * make sure the worker is no longer handling frames for this STA.
2915 if (old_state == IEEE80211_STA_NONE &&
2916 new_state == IEEE80211_STA_NOTEXIST) {
2917 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2918 flush_work(&mvm->add_stream_wk);
2921 * No need to make sure deferred TX indication is off since the
2922 * worker will already remove it if it was on
2926 mutex_lock(&mvm->mutex);
2927 /* track whether or not the station is associated */
2928 mvm_sta->sta_state = new_state;
2930 if (old_state == IEEE80211_STA_NOTEXIST &&
2931 new_state == IEEE80211_STA_NONE) {
2933 * Firmware bug - it'll crash if the beacon interval is less
2934 * than 16. We can't avoid connecting at all, so refuse the
2935 * station state change, this will cause mac80211 to abandon
2936 * attempts to connect to this AP, and eventually wpa_s will
2937 * blacklist the AP...
2939 if (vif->type == NL80211_IFTYPE_STATION &&
2940 vif->bss_conf.beacon_int < 16) {
2942 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2943 sta->addr, vif->bss_conf.beacon_int);
2950 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2951 IWL_MVM_TDLS_STA_COUNT ||
2952 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2953 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2958 ret = iwl_mvm_add_sta(mvm, vif, sta);
2959 if (sta->tdls && ret == 0) {
2960 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2961 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2962 NL80211_TDLS_SETUP);
2964 } else if (old_state == IEEE80211_STA_NONE &&
2965 new_state == IEEE80211_STA_AUTH) {
2967 * EBS may be disabled due to previous failures reported by FW.
2968 * Reset EBS status here assuming environment has been changed.
2970 mvm->last_ebs_successful = true;
2971 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2973 } else if (old_state == IEEE80211_STA_AUTH &&
2974 new_state == IEEE80211_STA_ASSOC) {
2975 if (vif->type == NL80211_IFTYPE_AP) {
2976 mvmvif->ap_assoc_sta_count++;
2977 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2980 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2982 ret = iwl_mvm_update_sta(mvm, vif, sta);
2983 } else if (old_state == IEEE80211_STA_ASSOC &&
2984 new_state == IEEE80211_STA_AUTHORIZED) {
2986 /* we don't support TDLS during DCM */
2987 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2988 iwl_mvm_teardown_tdls_peers(mvm);
2991 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2992 NL80211_TDLS_ENABLE_LINK);
2994 /* enable beacon filtering */
2995 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2997 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3001 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3002 new_state == IEEE80211_STA_ASSOC) {
3003 /* disable beacon filtering */
3004 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
3006 } else if (old_state == IEEE80211_STA_ASSOC &&
3007 new_state == IEEE80211_STA_AUTH) {
3008 if (vif->type == NL80211_IFTYPE_AP) {
3009 mvmvif->ap_assoc_sta_count--;
3010 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3013 } else if (old_state == IEEE80211_STA_AUTH &&
3014 new_state == IEEE80211_STA_NONE) {
3016 } else if (old_state == IEEE80211_STA_NONE &&
3017 new_state == IEEE80211_STA_NOTEXIST) {
3018 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3020 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3021 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3022 NL80211_TDLS_DISABLE_LINK);
3028 mutex_unlock(&mvm->mutex);
3030 if (sta->tdls && ret == 0) {
3031 if (old_state == IEEE80211_STA_NOTEXIST &&
3032 new_state == IEEE80211_STA_NONE)
3033 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3034 else if (old_state == IEEE80211_STA_NONE &&
3035 new_state == IEEE80211_STA_NOTEXIST)
3036 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3042 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3044 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3046 mvm->rts_threshold = value;
3051 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3052 struct ieee80211_vif *vif,
3053 struct ieee80211_sta *sta, u32 changed)
3055 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3057 if (vif->type == NL80211_IFTYPE_STATION &&
3058 changed & IEEE80211_RC_NSS_CHANGED)
3059 iwl_mvm_sf_update(mvm, vif, false);
3062 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3063 struct ieee80211_vif *vif, u16 ac,
3064 const struct ieee80211_tx_queue_params *params)
3066 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3067 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3069 mvmvif->queue_params[ac] = *params;
3072 * No need to update right away, we'll get BSS_CHANGED_QOS
3073 * The exception is P2P_DEVICE interface which needs immediate update.
3075 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3078 mutex_lock(&mvm->mutex);
3079 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3080 mutex_unlock(&mvm->mutex);
3086 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3087 struct ieee80211_vif *vif,
3090 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3091 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3092 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3095 * iwl_mvm_protect_session() reads directly from the device
3096 * (the system time), so make sure it is available.
3098 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3101 if (req_duration > duration)
3102 duration = req_duration;
3104 mutex_lock(&mvm->mutex);
3105 /* Try really hard to protect the session and hear a beacon */
3106 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3107 mutex_unlock(&mvm->mutex);
3109 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3112 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3113 struct ieee80211_vif *vif,
3114 struct cfg80211_sched_scan_request *req,
3115 struct ieee80211_scan_ies *ies)
3117 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3121 mutex_lock(&mvm->mutex);
3123 if (!vif->bss_conf.idle) {
3128 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3131 mutex_unlock(&mvm->mutex);
3135 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3136 struct ieee80211_vif *vif)
3138 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3141 mutex_lock(&mvm->mutex);
3143 /* Due to a race condition, it's possible that mac80211 asks
3144 * us to stop a sched_scan when it's already stopped. This
3145 * can happen, for instance, if we stopped the scan ourselves,
3146 * called ieee80211_sched_scan_stopped() and the userspace called
3147 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3148 * could run. To handle this, simply return if the scan is
3151 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3152 mutex_unlock(&mvm->mutex);
3156 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3157 mutex_unlock(&mvm->mutex);
3158 iwl_mvm_wait_for_async_handlers(mvm);
3163 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3164 enum set_key_cmd cmd,
3165 struct ieee80211_vif *vif,
3166 struct ieee80211_sta *sta,
3167 struct ieee80211_key_conf *key)
3169 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3170 struct iwl_mvm_sta *mvmsta;
3171 struct iwl_mvm_key_pn *ptk_pn;
3172 int keyidx = key->keyidx;
3176 if (iwlwifi_mod_params.swcrypto) {
3177 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3181 switch (key->cipher) {
3182 case WLAN_CIPHER_SUITE_TKIP:
3183 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3184 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3186 case WLAN_CIPHER_SUITE_CCMP:
3187 case WLAN_CIPHER_SUITE_GCMP:
3188 case WLAN_CIPHER_SUITE_GCMP_256:
3189 if (!iwl_mvm_has_new_tx_api(mvm))
3190 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3192 case WLAN_CIPHER_SUITE_AES_CMAC:
3193 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3194 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3195 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3197 case WLAN_CIPHER_SUITE_WEP40:
3198 case WLAN_CIPHER_SUITE_WEP104:
3199 /* For non-client mode, only use WEP keys for TX as we probably
3200 * don't have a station yet anyway and would then have to keep
3201 * track of the keys, linking them to each of the clients/peers
3202 * as they appear. For now, don't do that, for performance WEP
3203 * offload doesn't really matter much, but we need it for some
3204 * other offload features in client mode.
3206 if (vif->type != NL80211_IFTYPE_STATION)
3210 /* currently FW supports only one optional cipher scheme */
3211 if (hw->n_cipher_schemes &&
3212 hw->cipher_schemes->cipher == key->cipher)
3213 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3218 mutex_lock(&mvm->mutex);
3222 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3223 vif->type == NL80211_IFTYPE_AP) && !sta) {
3225 * GTK on AP interface is a TX-only key, return 0;
3226 * on IBSS they're per-station and because we're lazy
3227 * we don't support them for RX, so do the same.
3228 * CMAC/GMAC in AP/IBSS modes must be done in software.
3230 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3231 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3232 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3237 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3238 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3239 !iwl_mvm_has_new_tx_api(mvm)) {
3240 key->hw_key_idx = STA_KEY_IDX_INVALID;
3245 /* During FW restart, in order to restore the state as it was,
3246 * don't try to reprogram keys we previously failed for.
3248 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3249 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3250 IWL_DEBUG_MAC80211(mvm,
3251 "skip invalid idx key programming during restart\n");
3256 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3257 sta && iwl_mvm_has_new_rx_api(mvm) &&
3258 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3259 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3260 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3261 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3262 struct ieee80211_key_seq seq;
3265 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3266 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3267 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3268 mvm->trans->num_rx_queues),
3275 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3276 ieee80211_get_key_rx_seq(key, tid, &seq);
3277 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3278 memcpy(ptk_pn->q[q].pn[tid],
3280 IEEE80211_CCMP_PN_LEN);
3283 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3286 /* in HW restart reuse the index, otherwise request a new one */
3287 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3288 key_offset = key->hw_key_idx;
3290 key_offset = STA_KEY_IDX_INVALID;
3292 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3293 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3295 IWL_WARN(mvm, "set key failed\n");
3297 * can't add key for RX, but we don't need it
3298 * in the device for TX so still return 0
3300 key->hw_key_idx = STA_KEY_IDX_INVALID;
3306 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3311 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3312 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3313 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3314 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3315 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3316 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3317 ptk_pn = rcu_dereference_protected(
3318 mvmsta->ptk_pn[keyidx],
3319 lockdep_is_held(&mvm->mutex));
3320 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3322 kfree_rcu(ptk_pn, rcu_head);
3325 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3326 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3332 mutex_unlock(&mvm->mutex);
3336 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3337 struct ieee80211_vif *vif,
3338 struct ieee80211_key_conf *keyconf,
3339 struct ieee80211_sta *sta,
3340 u32 iv32, u16 *phase1key)
3342 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3344 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3347 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3351 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3352 struct iwl_rx_packet *pkt, void *data)
3354 struct iwl_mvm *mvm =
3355 container_of(notif_wait, struct iwl_mvm, notif_wait);
3356 struct iwl_hs20_roc_res *resp;
3357 int resp_len = iwl_rx_packet_payload_len(pkt);
3358 struct iwl_mvm_time_event_data *te_data = data;
3360 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3363 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3364 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3368 resp = (void *)pkt->data;
3371 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3372 resp->status, resp->event_unique_id);
3374 te_data->uid = le32_to_cpu(resp->event_unique_id);
3375 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3378 spin_lock_bh(&mvm->time_event_lock);
3379 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3380 spin_unlock_bh(&mvm->time_event_lock);
3385 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3386 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3387 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3388 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3389 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3390 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3391 struct ieee80211_channel *channel,
3392 struct ieee80211_vif *vif,
3395 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3396 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3397 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3398 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3399 struct iwl_notification_wait wait_time_event;
3400 u32 dtim_interval = vif->bss_conf.dtim_period *
3401 vif->bss_conf.beacon_int;
3403 struct iwl_hs20_roc_req aux_roc_req = {
3404 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3406 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3407 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3408 /* Set the channel info data */
3409 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3410 PHY_BAND_24 : PHY_BAND_5,
3411 .channel_info.channel = channel->hw_value,
3412 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3413 /* Set the time and duration */
3414 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3417 delay = AUX_ROC_MIN_DELAY;
3418 req_dur = MSEC_TO_TU(duration);
3421 * If we are associated we want the delay time to be at least one
3422 * dtim interval so that the FW can wait until after the DTIM and
3423 * then start the time event, this will potentially allow us to
3424 * remain off-channel for the max duration.
3425 * Since we want to use almost a whole dtim interval we would also
3426 * like the delay to be for 2-3 dtim intervals, in case there are
3427 * other time events with higher priority.
3429 if (vif->bss_conf.assoc) {
3430 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3431 /* We cannot remain off-channel longer than the DTIM interval */
3432 if (dtim_interval <= req_dur) {
3433 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3434 if (req_dur <= AUX_ROC_MIN_DURATION)
3435 req_dur = dtim_interval -
3436 AUX_ROC_MIN_SAFETY_BUFFER;
3440 aux_roc_req.duration = cpu_to_le32(req_dur);
3441 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3444 "ROC: Requesting to remain on channel %u for %ums\n",
3445 channel->hw_value, req_dur);
3447 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3448 duration, delay, dtim_interval);
3450 /* Set the node address */
3451 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3453 lockdep_assert_held(&mvm->mutex);
3455 spin_lock_bh(&mvm->time_event_lock);
3457 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3458 spin_unlock_bh(&mvm->time_event_lock);
3463 te_data->duration = duration;
3464 te_data->id = HOT_SPOT_CMD;
3466 spin_unlock_bh(&mvm->time_event_lock);
3469 * Use a notification wait, which really just processes the
3470 * command response and doesn't wait for anything, in order
3471 * to be able to process the response and get the UID inside
3472 * the RX path. Using CMD_WANT_SKB doesn't work because it
3473 * stores the buffer and then wakes up this thread, by which
3474 * time another notification (that the time event started)
3475 * might already be processed unsuccessfully.
3477 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3478 time_event_response,
3479 ARRAY_SIZE(time_event_response),
3480 iwl_mvm_rx_aux_roc, te_data);
3482 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3486 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3487 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3491 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3492 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3493 /* should never fail */
3498 spin_lock_bh(&mvm->time_event_lock);
3499 iwl_mvm_te_clear_data(mvm, te_data);
3500 spin_unlock_bh(&mvm->time_event_lock);
3506 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3507 struct ieee80211_vif *vif,
3508 struct ieee80211_channel *channel,
3510 enum ieee80211_roc_type type)
3512 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3513 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3514 struct cfg80211_chan_def chandef;
3515 struct iwl_mvm_phy_ctxt *phy_ctxt;
3516 bool band_change_removal;
3519 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3523 * Flush the done work, just in case it's still pending, so that
3524 * the work it does can complete and we can accept new frames.
3526 flush_work(&mvm->roc_done_wk);
3528 mutex_lock(&mvm->mutex);
3530 switch (vif->type) {
3531 case NL80211_IFTYPE_STATION:
3532 if (fw_has_capa(&mvm->fw->ucode_capa,
3533 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3534 /* Use aux roc framework (HS20) */
3535 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3539 IWL_ERR(mvm, "hotspot not supported\n");
3542 case NL80211_IFTYPE_P2P_DEVICE:
3546 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3551 for (i = 0; i < NUM_PHY_CTX; i++) {
3552 phy_ctxt = &mvm->phy_ctxts[i];
3553 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3556 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3558 * Unbind the P2P_DEVICE from the current PHY context,
3559 * and if the PHY context is not used remove it.
3561 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3562 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3565 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3567 /* Bind the P2P_DEVICE to the current PHY Context */
3568 mvmvif->phy_ctxt = phy_ctxt;
3570 ret = iwl_mvm_binding_add_vif(mvm, vif);
3571 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3574 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3575 goto schedule_time_event;
3579 /* Need to update the PHY context only if the ROC channel changed */
3580 if (channel == mvmvif->phy_ctxt->channel)
3581 goto schedule_time_event;
3583 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3586 * Check if the remain-on-channel is on a different band and that
3587 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3588 * so, we'll need to release and then re-configure here, since we
3589 * must not remove a PHY context that's part of a binding.
3591 band_change_removal =
3592 fw_has_capa(&mvm->fw->ucode_capa,
3593 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3594 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3596 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3598 * Change the PHY context configuration as it is currently
3599 * referenced only by the P2P Device MAC (and we can modify it)
3601 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3607 * The PHY context is shared with other MACs (or we're trying to
3608 * switch bands), so remove the P2P Device from the binding,
3609 * allocate an new PHY context and create a new binding.
3611 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3617 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3620 IWL_ERR(mvm, "Failed to change PHY context\n");
3624 /* Unbind the P2P_DEVICE from the current PHY context */
3625 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3626 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3629 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3631 /* Bind the P2P_DEVICE to the new allocated PHY context */
3632 mvmvif->phy_ctxt = phy_ctxt;
3634 ret = iwl_mvm_binding_add_vif(mvm, vif);
3635 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3638 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3641 schedule_time_event:
3642 /* Schedule the time events */
3643 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3646 mutex_unlock(&mvm->mutex);
3647 IWL_DEBUG_MAC80211(mvm, "leave\n");
3651 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3655 IWL_DEBUG_MAC80211(mvm, "enter\n");
3657 mutex_lock(&mvm->mutex);
3658 iwl_mvm_stop_roc(mvm);
3659 mutex_unlock(&mvm->mutex);
3661 IWL_DEBUG_MAC80211(mvm, "leave\n");
3665 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3666 struct ieee80211_chanctx_conf *ctx)
3668 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3669 struct iwl_mvm_phy_ctxt *phy_ctxt;
3672 lockdep_assert_held(&mvm->mutex);
3674 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3676 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3682 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3683 ctx->rx_chains_static,
3684 ctx->rx_chains_dynamic);
3686 IWL_ERR(mvm, "Failed to add PHY context\n");
3690 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3691 *phy_ctxt_id = phy_ctxt->id;
3696 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3697 struct ieee80211_chanctx_conf *ctx)
3699 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3702 mutex_lock(&mvm->mutex);
3703 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3704 mutex_unlock(&mvm->mutex);
3709 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3710 struct ieee80211_chanctx_conf *ctx)
3712 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3713 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3715 lockdep_assert_held(&mvm->mutex);
3717 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3720 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3721 struct ieee80211_chanctx_conf *ctx)
3723 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3725 mutex_lock(&mvm->mutex);
3726 __iwl_mvm_remove_chanctx(mvm, ctx);
3727 mutex_unlock(&mvm->mutex);
3730 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3731 struct ieee80211_chanctx_conf *ctx,
3734 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3735 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3736 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3738 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3739 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3740 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3741 IEEE80211_CHANCTX_CHANGE_RADAR |
3742 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3743 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3744 phy_ctxt->ref, changed))
3747 mutex_lock(&mvm->mutex);
3749 /* we are only changing the min_width, may be a noop */
3750 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3751 if (phy_ctxt->width == ctx->min_def.width)
3754 /* we are just toggling between 20_NOHT and 20 */
3755 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3756 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3760 iwl_mvm_bt_coex_vif_change(mvm);
3761 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3762 ctx->rx_chains_static,
3763 ctx->rx_chains_dynamic);
3766 mutex_unlock(&mvm->mutex);
3769 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3770 struct ieee80211_vif *vif,
3771 struct ieee80211_chanctx_conf *ctx,
3772 bool switching_chanctx)
3774 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3775 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3776 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3779 lockdep_assert_held(&mvm->mutex);
3781 mvmvif->phy_ctxt = phy_ctxt;
3783 switch (vif->type) {
3784 case NL80211_IFTYPE_AP:
3785 /* only needed if we're switching chanctx (i.e. during CSA) */
3786 if (switching_chanctx) {
3787 mvmvif->ap_ibss_active = true;
3790 case NL80211_IFTYPE_ADHOC:
3792 * The AP binding flow is handled as part of the start_ap flow
3793 * (in bss_info_changed), similarly for IBSS.
3797 case NL80211_IFTYPE_STATION:
3798 mvmvif->csa_bcn_pending = false;
3800 case NL80211_IFTYPE_MONITOR:
3801 /* always disable PS when a monitor interface is active */
3802 mvmvif->ps_disabled = true;
3809 ret = iwl_mvm_binding_add_vif(mvm, vif);
3814 * Power state must be updated before quotas,
3815 * otherwise fw will complain.
3817 iwl_mvm_power_update_mac(mvm);
3819 /* Setting the quota at this stage is only required for monitor
3820 * interfaces. For the other types, the bss_info changed flow
3821 * will handle quota settings.
3823 if (vif->type == NL80211_IFTYPE_MONITOR) {
3824 mvmvif->monitor_active = true;
3825 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3827 goto out_remove_binding;
3829 ret = iwl_mvm_add_snif_sta(mvm, vif);
3831 goto out_remove_binding;
3835 /* Handle binding during CSA */
3836 if (vif->type == NL80211_IFTYPE_AP) {
3837 iwl_mvm_update_quotas(mvm, false, NULL);
3838 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3841 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3842 u32 duration = 3 * vif->bss_conf.beacon_int;
3844 /* iwl_mvm_protect_session() reads directly from the
3845 * device (the system time), so make sure it is
3848 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3850 goto out_remove_binding;
3852 /* Protect the session to make sure we hear the first
3853 * beacon on the new channel.
3855 mvmvif->csa_bcn_pending = true;
3856 iwl_mvm_protect_session(mvm, vif, duration, duration,
3857 vif->bss_conf.beacon_int / 2,
3860 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3862 iwl_mvm_update_quotas(mvm, false, NULL);
3868 iwl_mvm_binding_remove_vif(mvm, vif);
3869 iwl_mvm_power_update_mac(mvm);
3872 mvmvif->phy_ctxt = NULL;
3875 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3876 struct ieee80211_vif *vif,
3877 struct ieee80211_chanctx_conf *ctx)
3879 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3882 mutex_lock(&mvm->mutex);
3883 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3884 mutex_unlock(&mvm->mutex);
3889 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3890 struct ieee80211_vif *vif,
3891 struct ieee80211_chanctx_conf *ctx,
3892 bool switching_chanctx)
3894 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3895 struct ieee80211_vif *disabled_vif = NULL;
3897 lockdep_assert_held(&mvm->mutex);
3899 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3901 switch (vif->type) {
3902 case NL80211_IFTYPE_ADHOC:
3904 case NL80211_IFTYPE_MONITOR:
3905 mvmvif->monitor_active = false;
3906 mvmvif->ps_disabled = false;
3907 iwl_mvm_rm_snif_sta(mvm, vif);
3909 case NL80211_IFTYPE_AP:
3910 /* This part is triggered only during CSA */
3911 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3914 mvmvif->csa_countdown = false;
3916 /* Set CS bit on all the stations */
3917 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3919 /* Save blocked iface, the timeout is set on the next beacon */
3920 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3922 mvmvif->ap_ibss_active = false;
3924 case NL80211_IFTYPE_STATION:
3925 if (!switching_chanctx)
3930 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3936 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3937 iwl_mvm_binding_remove_vif(mvm, vif);
3940 mvmvif->phy_ctxt = NULL;
3941 iwl_mvm_power_update_mac(mvm);
3944 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3945 struct ieee80211_vif *vif,
3946 struct ieee80211_chanctx_conf *ctx)
3948 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3950 mutex_lock(&mvm->mutex);
3951 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3952 mutex_unlock(&mvm->mutex);
3956 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3957 struct ieee80211_vif_chanctx_switch *vifs)
3961 mutex_lock(&mvm->mutex);
3962 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3963 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3965 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3967 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3971 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3975 "failed to assign new_ctx during channel switch\n");
3979 /* we don't support TDLS during DCM - can be caused by channel switch */
3980 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3981 iwl_mvm_teardown_tdls_peers(mvm);
3986 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3989 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3990 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3994 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3996 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4003 /* things keep failing, better restart the hw */
4004 iwl_mvm_nic_restart(mvm, false);
4007 mutex_unlock(&mvm->mutex);
4013 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4014 struct ieee80211_vif_chanctx_switch *vifs)
4018 mutex_lock(&mvm->mutex);
4019 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4021 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4025 "failed to assign new_ctx during channel switch\n");
4032 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4034 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4041 /* things keep failing, better restart the hw */
4042 iwl_mvm_nic_restart(mvm, false);
4045 mutex_unlock(&mvm->mutex);
4050 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4051 struct ieee80211_vif_chanctx_switch *vifs,
4053 enum ieee80211_chanctx_switch_mode mode)
4055 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4058 /* we only support a single-vif right now */
4063 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4064 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4066 case CHANCTX_SWMODE_REASSIGN_VIF:
4067 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4077 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4079 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4081 return mvm->ibss_manager;
4084 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4085 struct ieee80211_sta *sta,
4088 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4089 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4091 if (!mvm_sta || !mvm_sta->vif) {
4092 IWL_ERR(mvm, "Station is not associated to a vif\n");
4096 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4099 #ifdef CONFIG_NL80211_TESTMODE
4100 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4101 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4102 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4103 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4106 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4107 struct ieee80211_vif *vif,
4108 void *data, int len)
4110 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4114 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4119 if (!tb[IWL_MVM_TM_ATTR_CMD])
4122 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4123 case IWL_MVM_TM_CMD_SET_NOA:
4124 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4125 !vif->bss_conf.enable_beacon ||
4126 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4129 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4130 if (noa_duration >= vif->bss_conf.beacon_int)
4133 mvm->noa_duration = noa_duration;
4136 return iwl_mvm_update_quotas(mvm, true, NULL);
4137 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4138 /* must be associated client vif - ignore authorized */
4139 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4140 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4141 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4144 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4145 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4146 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4152 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4153 struct ieee80211_vif *vif,
4154 void *data, int len)
4156 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4159 mutex_lock(&mvm->mutex);
4160 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4161 mutex_unlock(&mvm->mutex);
4167 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4168 struct ieee80211_vif *vif,
4169 struct ieee80211_channel_switch *chsw)
4171 /* By implementing this operation, we prevent mac80211 from
4172 * starting its own channel switch timer, so that we can call
4173 * ieee80211_chswitch_done() ourselves at the right time
4174 * (which is when the absence time event starts).
4177 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4178 "dummy channel switch op\n");
4181 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4182 struct ieee80211_vif *vif,
4183 struct ieee80211_channel_switch *chsw)
4185 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4186 struct ieee80211_vif *csa_vif;
4187 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4191 mutex_lock(&mvm->mutex);
4193 mvmvif->csa_failed = false;
4195 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4196 chsw->chandef.center_freq1);
4198 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4199 ieee80211_vif_to_wdev(vif),
4200 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4202 switch (vif->type) {
4203 case NL80211_IFTYPE_AP:
4205 rcu_dereference_protected(mvm->csa_vif,
4206 lockdep_is_held(&mvm->mutex));
4207 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4208 "Another CSA is already in progress")) {
4213 /* we still didn't unblock tx. prevent new CS meanwhile */
4214 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4215 lockdep_is_held(&mvm->mutex))) {
4220 rcu_assign_pointer(mvm->csa_vif, vif);
4222 if (WARN_ONCE(mvmvif->csa_countdown,
4223 "Previous CSA countdown didn't complete")) {
4228 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4231 case NL80211_IFTYPE_STATION:
4232 /* Schedule the time event to a bit before beacon 1,
4233 * to make sure we're in the new channel when the
4234 * GO/AP arrives. In case count <= 1 immediately schedule the
4235 * TE (this might result with some packet loss or connection
4238 if (chsw->count <= 1)
4241 apply_time = chsw->device_timestamp +
4242 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4243 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4246 iwl_mvm_csa_client_absent(mvm, vif);
4248 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4250 if (mvmvif->bf_data.bf_enabled) {
4251 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4261 mvmvif->ps_disabled = true;
4263 ret = iwl_mvm_power_update_ps(mvm);
4267 /* we won't be on this channel any longer */
4268 iwl_mvm_teardown_tdls_peers(mvm);
4271 mutex_unlock(&mvm->mutex);
4276 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4277 struct ieee80211_vif *vif)
4279 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4280 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4283 mutex_lock(&mvm->mutex);
4285 if (mvmvif->csa_failed) {
4286 mvmvif->csa_failed = false;
4291 if (vif->type == NL80211_IFTYPE_STATION) {
4292 struct iwl_mvm_sta *mvmsta;
4294 mvmvif->csa_bcn_pending = false;
4295 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4298 if (WARN_ON(!mvmsta)) {
4303 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4305 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4307 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4311 iwl_mvm_stop_session_protection(mvm, vif);
4314 mvmvif->ps_disabled = false;
4316 ret = iwl_mvm_power_update_ps(mvm);
4319 mutex_unlock(&mvm->mutex);
4324 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4328 if (!iwl_mvm_has_new_tx_api(mvm)) {
4330 mutex_lock(&mvm->mutex);
4331 iwl_mvm_flush_tx_path(mvm,
4332 iwl_mvm_flushable_queues(mvm) & queues, 0);
4333 mutex_unlock(&mvm->mutex);
4335 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4340 mutex_lock(&mvm->mutex);
4341 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4342 struct ieee80211_sta *sta;
4344 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4345 lockdep_is_held(&mvm->mutex));
4346 if (IS_ERR_OR_NULL(sta))
4350 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4352 iwl_mvm_wait_sta_queues_empty(mvm,
4353 iwl_mvm_sta_from_mac80211(sta));
4355 mutex_unlock(&mvm->mutex);
4358 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4359 struct ieee80211_vif *vif, u32 queues, bool drop)
4361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4362 struct iwl_mvm_vif *mvmvif;
4363 struct iwl_mvm_sta *mvmsta;
4364 struct ieee80211_sta *sta;
4369 iwl_mvm_flush_no_vif(mvm, queues, drop);
4373 if (vif->type != NL80211_IFTYPE_STATION)
4376 /* Make sure we're done with the deferred traffic before flushing */
4377 flush_work(&mvm->add_stream_wk);
4379 mutex_lock(&mvm->mutex);
4380 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4382 /* flush the AP-station and all TDLS peers */
4383 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4384 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4385 lockdep_is_held(&mvm->mutex));
4386 if (IS_ERR_OR_NULL(sta))
4389 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4390 if (mvmsta->vif != vif)
4393 /* make sure only TDLS peers or the AP are flushed */
4394 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4397 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4398 IWL_ERR(mvm, "flush request fail\n");
4400 msk |= mvmsta->tfd_queue_msk;
4401 if (iwl_mvm_has_new_tx_api(mvm))
4402 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4406 mutex_unlock(&mvm->mutex);
4408 /* this can take a while, and we may need/want other operations
4409 * to succeed while doing this, so do it without the mutex held
4411 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4412 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4415 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4416 struct survey_info *survey)
4418 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4421 memset(survey, 0, sizeof(*survey));
4423 /* only support global statistics right now */
4427 if (!fw_has_capa(&mvm->fw->ucode_capa,
4428 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4431 mutex_lock(&mvm->mutex);
4433 if (iwl_mvm_firmware_running(mvm)) {
4434 ret = iwl_mvm_request_statistics(mvm, false);
4439 survey->filled = SURVEY_INFO_TIME |
4440 SURVEY_INFO_TIME_RX |
4441 SURVEY_INFO_TIME_TX |
4442 SURVEY_INFO_TIME_SCAN;
4443 survey->time = mvm->accu_radio_stats.on_time_rf +
4444 mvm->radio_stats.on_time_rf;
4445 do_div(survey->time, USEC_PER_MSEC);
4447 survey->time_rx = mvm->accu_radio_stats.rx_time +
4448 mvm->radio_stats.rx_time;
4449 do_div(survey->time_rx, USEC_PER_MSEC);
4451 survey->time_tx = mvm->accu_radio_stats.tx_time +
4452 mvm->radio_stats.tx_time;
4453 do_div(survey->time_tx, USEC_PER_MSEC);
4455 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4456 mvm->radio_stats.on_time_scan;
4457 do_div(survey->time_scan, USEC_PER_MSEC);
4461 mutex_unlock(&mvm->mutex);
4465 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4466 struct ieee80211_vif *vif,
4467 struct ieee80211_sta *sta,
4468 struct station_info *sinfo)
4470 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4472 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4474 if (mvmsta->avg_energy) {
4475 sinfo->signal_avg = mvmsta->avg_energy;
4476 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4479 /* if beacon filtering isn't on mac80211 does it anyway */
4480 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4483 if (!vif->bss_conf.assoc)
4486 mutex_lock(&mvm->mutex);
4488 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4491 if (iwl_mvm_request_statistics(mvm, false))
4494 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4495 mvmvif->beacon_stats.accu_num_beacons;
4496 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4497 if (mvmvif->beacon_stats.avg_signal) {
4498 /* firmware only reports a value after RXing a few beacons */
4499 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4500 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4503 mutex_unlock(&mvm->mutex);
4506 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4507 struct ieee80211_vif *vif,
4508 const struct ieee80211_event *event)
4510 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4512 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4514 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4517 struct iwl_fw_dbg_trigger_tlv *trig;
4518 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4520 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4523 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4524 trig_mlme = (void *)trig->data;
4525 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4526 ieee80211_vif_to_wdev(vif), trig))
4529 if (event->u.mlme.data == ASSOC_EVENT) {
4530 if (event->u.mlme.status == MLME_DENIED)
4531 CHECK_MLME_TRIGGER(stop_assoc_denied,
4532 "DENIED ASSOC: reason %d",
4533 event->u.mlme.reason);
4534 else if (event->u.mlme.status == MLME_TIMEOUT)
4535 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4537 } else if (event->u.mlme.data == AUTH_EVENT) {
4538 if (event->u.mlme.status == MLME_DENIED)
4539 CHECK_MLME_TRIGGER(stop_auth_denied,
4540 "DENIED AUTH: reason %d",
4541 event->u.mlme.reason);
4542 else if (event->u.mlme.status == MLME_TIMEOUT)
4543 CHECK_MLME_TRIGGER(stop_auth_timeout,
4545 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4546 CHECK_MLME_TRIGGER(stop_rx_deauth,
4547 "DEAUTH RX %d", event->u.mlme.reason);
4548 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4549 CHECK_MLME_TRIGGER(stop_tx_deauth,
4550 "DEAUTH TX %d", event->u.mlme.reason);
4552 #undef CHECK_MLME_TRIGGER
4555 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4556 struct ieee80211_vif *vif,
4557 const struct ieee80211_event *event)
4559 struct iwl_fw_dbg_trigger_tlv *trig;
4560 struct iwl_fw_dbg_trigger_ba *ba_trig;
4562 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4565 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4566 ba_trig = (void *)trig->data;
4567 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4568 ieee80211_vif_to_wdev(vif), trig))
4571 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4574 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4575 "BAR received from %pM, tid %d, ssn %d",
4576 event->u.ba.sta->addr, event->u.ba.tid,
4580 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4581 struct ieee80211_vif *vif,
4582 const struct ieee80211_event *event)
4584 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4586 switch (event->type) {
4588 iwl_mvm_event_mlme_callback(mvm, vif, event);
4591 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4593 case BA_FRAME_TIMEOUT:
4594 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4602 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4603 struct iwl_mvm_internal_rxq_notif *notif,
4606 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4609 lockdep_assert_held(&mvm->mutex);
4611 if (!iwl_mvm_has_new_rx_api(mvm))
4614 notif->cookie = mvm->queue_sync_cookie;
4617 atomic_set(&mvm->queue_sync_counter,
4618 mvm->trans->num_rx_queues);
4620 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4622 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4627 ret = wait_event_timeout(mvm->rx_sync_waitq,
4628 atomic_read(&mvm->queue_sync_counter) == 0 ||
4629 iwl_mvm_is_radio_killed(mvm),
4631 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4635 atomic_set(&mvm->queue_sync_counter, 0);
4636 mvm->queue_sync_cookie++;
4639 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4642 struct iwl_mvm_internal_rxq_notif data = {
4643 .type = IWL_MVM_RXQ_EMPTY,
4647 mutex_lock(&mvm->mutex);
4648 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4649 mutex_unlock(&mvm->mutex);
4652 const struct ieee80211_ops iwl_mvm_hw_ops = {
4653 .tx = iwl_mvm_mac_tx,
4654 .ampdu_action = iwl_mvm_mac_ampdu_action,
4655 .start = iwl_mvm_mac_start,
4656 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4657 .stop = iwl_mvm_mac_stop,
4658 .add_interface = iwl_mvm_mac_add_interface,
4659 .remove_interface = iwl_mvm_mac_remove_interface,
4660 .config = iwl_mvm_mac_config,
4661 .prepare_multicast = iwl_mvm_prepare_multicast,
4662 .configure_filter = iwl_mvm_configure_filter,
4663 .config_iface_filter = iwl_mvm_config_iface_filter,
4664 .bss_info_changed = iwl_mvm_bss_info_changed,
4665 .hw_scan = iwl_mvm_mac_hw_scan,
4666 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4667 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4668 .sta_state = iwl_mvm_mac_sta_state,
4669 .sta_notify = iwl_mvm_mac_sta_notify,
4670 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4671 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4672 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4673 .sta_rc_update = iwl_mvm_sta_rc_update,
4674 .conf_tx = iwl_mvm_mac_conf_tx,
4675 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4676 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4677 .flush = iwl_mvm_mac_flush,
4678 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4679 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4680 .set_key = iwl_mvm_mac_set_key,
4681 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4682 .remain_on_channel = iwl_mvm_roc,
4683 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4684 .add_chanctx = iwl_mvm_add_chanctx,
4685 .remove_chanctx = iwl_mvm_remove_chanctx,
4686 .change_chanctx = iwl_mvm_change_chanctx,
4687 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4688 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4689 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4691 .start_ap = iwl_mvm_start_ap_ibss,
4692 .stop_ap = iwl_mvm_stop_ap_ibss,
4693 .join_ibss = iwl_mvm_start_ap_ibss,
4694 .leave_ibss = iwl_mvm_stop_ap_ibss,
4696 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4698 .set_tim = iwl_mvm_set_tim,
4700 .channel_switch = iwl_mvm_channel_switch,
4701 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4702 .post_channel_switch = iwl_mvm_post_channel_switch,
4704 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4705 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4706 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4708 .event_callback = iwl_mvm_mac_event_callback,
4710 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4712 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4714 #ifdef CONFIG_PM_SLEEP
4716 .suspend = iwl_mvm_suspend,
4717 .resume = iwl_mvm_resume,
4718 .set_wakeup = iwl_mvm_set_wakeup,
4719 .set_rekey_data = iwl_mvm_set_rekey_data,
4720 #if IS_ENABLED(CONFIG_IPV6)
4721 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4723 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4725 .get_survey = iwl_mvm_mac_get_survey,
4726 .sta_statistics = iwl_mvm_mac_sta_statistics,
4727 #ifdef CONFIG_IWLWIFI_DEBUGFS
4728 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,