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 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
189 if (!iwl_mvm_is_d0i3_supported(mvm))
192 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
193 spin_lock_bh(&mvm->refs_lock);
194 mvm->refs[ref_type]++;
195 spin_unlock_bh(&mvm->refs_lock);
196 iwl_trans_ref(mvm->trans);
199 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
201 if (!iwl_mvm_is_d0i3_supported(mvm))
204 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
205 spin_lock_bh(&mvm->refs_lock);
206 if (WARN_ON(!mvm->refs[ref_type])) {
207 spin_unlock_bh(&mvm->refs_lock);
210 mvm->refs[ref_type]--;
211 spin_unlock_bh(&mvm->refs_lock);
212 iwl_trans_unref(mvm->trans);
215 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
216 enum iwl_mvm_ref_type except_ref)
220 if (!iwl_mvm_is_d0i3_supported(mvm))
223 spin_lock_bh(&mvm->refs_lock);
224 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
225 if (except_ref == i || !mvm->refs[i])
228 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
230 for (j = 0; j < mvm->refs[i]; j++)
231 iwl_trans_unref(mvm->trans);
234 spin_unlock_bh(&mvm->refs_lock);
237 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
242 if (!iwl_mvm_is_d0i3_supported(mvm))
245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
252 spin_unlock_bh(&mvm->refs_lock);
257 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
259 iwl_mvm_ref(mvm, ref_type);
261 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
262 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
265 iwl_mvm_unref(mvm, ref_type);
272 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
276 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
277 for (i = 0; i < NUM_PHY_CTX; i++) {
278 mvm->phy_ctxts[i].id = i;
279 mvm->phy_ctxts[i].ref = 0;
283 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
285 enum iwl_mcc_source src_id,
288 struct ieee80211_regdomain *regd = NULL;
289 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
291 struct iwl_mcc_update_resp *resp;
293 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
295 lockdep_assert_held(&mvm->mutex);
297 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
298 if (IS_ERR_OR_NULL(resp)) {
299 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
300 PTR_ERR_OR_ZERO(resp));
305 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
307 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
308 __le32_to_cpu(resp->n_channels),
310 __le16_to_cpu(resp->mcc),
311 __le16_to_cpu(resp->geo_info));
312 /* Store the return source id */
313 src_id = resp->source_id;
315 if (IS_ERR_OR_NULL(regd)) {
316 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
317 PTR_ERR_OR_ZERO(regd));
321 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
322 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
323 mvm->lar_regdom_set = true;
324 mvm->mcc_src = src_id;
330 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
333 struct ieee80211_regdomain *regd;
335 if (!iwl_mvm_is_lar_supported(mvm))
338 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
339 if (!IS_ERR_OR_NULL(regd)) {
340 /* only update the regulatory core if changed */
342 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
348 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
351 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
352 iwl_mvm_is_wifi_mcc_supported(mvm) ?
353 MCC_SOURCE_GET_CURRENT :
354 MCC_SOURCE_OLD_FW, changed);
357 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
359 enum iwl_mcc_source used_src;
360 struct ieee80211_regdomain *regd;
363 const struct ieee80211_regdomain *r =
364 rtnl_dereference(mvm->hw->wiphy->regd);
369 /* save the last source in case we overwrite it below */
370 used_src = mvm->mcc_src;
371 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
372 /* Notify the firmware we support wifi location updates */
373 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
374 if (!IS_ERR_OR_NULL(regd))
378 /* Now set our last stored MCC and source */
379 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
381 if (IS_ERR_OR_NULL(regd))
384 /* update cfg80211 if the regdomain was changed */
386 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
394 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
396 struct ieee80211_hw *hw = mvm->hw;
398 static const u32 mvm_ciphers[] = {
399 WLAN_CIPHER_SUITE_WEP40,
400 WLAN_CIPHER_SUITE_WEP104,
401 WLAN_CIPHER_SUITE_TKIP,
402 WLAN_CIPHER_SUITE_CCMP,
405 /* Tell mac80211 our characteristics */
406 ieee80211_hw_set(hw, SIGNAL_DBM);
407 ieee80211_hw_set(hw, SPECTRUM_MGMT);
408 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
409 ieee80211_hw_set(hw, QUEUE_CONTROL);
410 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
411 ieee80211_hw_set(hw, SUPPORTS_PS);
412 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
413 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
414 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
415 ieee80211_hw_set(hw, CONNECTION_MONITOR);
416 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
417 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
418 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
419 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
420 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
421 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
423 if (iwl_mvm_has_tlc_offload(mvm)) {
424 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
425 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
428 if (iwl_mvm_has_new_rx_api(mvm))
429 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
431 if (fw_has_capa(&mvm->fw->ucode_capa,
432 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
433 ieee80211_hw_set(hw, AP_LINK_PS);
434 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
436 * we absolutely need this for the new TX API since that comes
437 * with many more queues than the current code can deal with
438 * for station powersave
443 if (mvm->trans->num_rx_queues > 1)
444 ieee80211_hw_set(hw, USES_RSS);
446 if (mvm->trans->max_skb_frags)
447 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
449 hw->queues = IEEE80211_MAX_QUEUES;
450 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
451 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
452 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
453 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
454 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
456 hw->radiotap_timestamp.units_pos =
457 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
458 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
459 /* this is the case for CCK frames, it's better (only 8) for OFDM */
460 hw->radiotap_timestamp.accuracy = 22;
462 if (!iwl_mvm_has_tlc_offload(mvm))
463 hw->rate_control_algorithm = RS_NAME;
465 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
466 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
468 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
469 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
470 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
471 hw->wiphy->cipher_suites = mvm->ciphers;
473 if (iwl_mvm_has_new_rx_api(mvm)) {
474 mvm->ciphers[hw->wiphy->n_cipher_suites] =
475 WLAN_CIPHER_SUITE_GCMP;
476 hw->wiphy->n_cipher_suites++;
477 mvm->ciphers[hw->wiphy->n_cipher_suites] =
478 WLAN_CIPHER_SUITE_GCMP_256;
479 hw->wiphy->n_cipher_suites++;
482 /* Enable 11w if software crypto is not enabled (as the
483 * firmware will interpret some mgmt packets, so enabling it
484 * with software crypto isn't safe).
486 if (!iwlwifi_mod_params.swcrypto) {
487 ieee80211_hw_set(hw, MFP_CAPABLE);
488 mvm->ciphers[hw->wiphy->n_cipher_suites] =
489 WLAN_CIPHER_SUITE_AES_CMAC;
490 hw->wiphy->n_cipher_suites++;
491 if (iwl_mvm_has_new_rx_api(mvm)) {
492 mvm->ciphers[hw->wiphy->n_cipher_suites] =
493 WLAN_CIPHER_SUITE_BIP_GMAC_128;
494 hw->wiphy->n_cipher_suites++;
495 mvm->ciphers[hw->wiphy->n_cipher_suites] =
496 WLAN_CIPHER_SUITE_BIP_GMAC_256;
497 hw->wiphy->n_cipher_suites++;
501 /* currently FW API supports only one optional cipher scheme */
502 if (mvm->fw->cs[0].cipher) {
503 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
504 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
506 mvm->hw->n_cipher_schemes = 1;
508 cs->cipher = le32_to_cpu(fwcs->cipher);
509 cs->iftype = BIT(NL80211_IFTYPE_STATION);
510 cs->hdr_len = fwcs->hdr_len;
511 cs->pn_len = fwcs->pn_len;
512 cs->pn_off = fwcs->pn_off;
513 cs->key_idx_off = fwcs->key_idx_off;
514 cs->key_idx_mask = fwcs->key_idx_mask;
515 cs->key_idx_shift = fwcs->key_idx_shift;
516 cs->mic_len = fwcs->mic_len;
518 mvm->hw->cipher_schemes = mvm->cs;
519 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
520 hw->wiphy->n_cipher_suites++;
523 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
524 hw->wiphy->features |=
525 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
526 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
527 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
529 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
530 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
531 hw->chanctx_data_size = sizeof(u16);
533 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
534 BIT(NL80211_IFTYPE_P2P_CLIENT) |
535 BIT(NL80211_IFTYPE_AP) |
536 BIT(NL80211_IFTYPE_P2P_GO) |
537 BIT(NL80211_IFTYPE_P2P_DEVICE) |
538 BIT(NL80211_IFTYPE_ADHOC);
540 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
541 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
542 if (iwl_mvm_is_lar_supported(mvm))
543 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
545 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
546 REGULATORY_DISABLE_BEACON_HINTS;
548 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
549 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
551 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
552 hw->wiphy->n_iface_combinations =
553 ARRAY_SIZE(iwl_mvm_iface_combinations);
555 hw->wiphy->max_remain_on_channel_duration = 10000;
556 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
558 /* Extract MAC address */
559 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
560 hw->wiphy->addresses = mvm->addresses;
561 hw->wiphy->n_addresses = 1;
563 /* Extract additional MAC addresses if available */
564 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
565 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
567 for (i = 1; i < num_mac; i++) {
568 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
570 mvm->addresses[i].addr[5]++;
571 hw->wiphy->n_addresses++;
574 iwl_mvm_reset_phy_ctxts(mvm);
576 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
578 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
580 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
581 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
582 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
584 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
585 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
587 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
589 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
590 hw->wiphy->bands[NL80211_BAND_2GHZ] =
591 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
592 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
593 hw->wiphy->bands[NL80211_BAND_5GHZ] =
594 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
596 if (fw_has_capa(&mvm->fw->ucode_capa,
597 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
598 fw_has_api(&mvm->fw->ucode_capa,
599 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
600 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
601 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
604 hw->wiphy->hw_version = mvm->trans->hw_id;
606 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
607 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
609 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
611 hw->wiphy->max_sched_scan_reqs = 1;
612 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
613 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
614 /* we create the 802.11 header and zero length SSID IE. */
615 hw->wiphy->max_sched_scan_ie_len =
616 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
617 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
618 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
621 * the firmware uses u8 for num of iterations, but 0xff is saved for
622 * infinite loop, so the maximum number of iterations is actually 254.
624 hw->wiphy->max_sched_scan_plan_iterations = 254;
626 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
627 NL80211_FEATURE_LOW_PRIORITY_SCAN |
628 NL80211_FEATURE_P2P_GO_OPPPS |
629 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
630 NL80211_FEATURE_DYNAMIC_SMPS |
631 NL80211_FEATURE_STATIC_SMPS |
632 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
634 if (fw_has_capa(&mvm->fw->ucode_capa,
635 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
636 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
637 if (fw_has_capa(&mvm->fw->ucode_capa,
638 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
639 hw->wiphy->features |= NL80211_FEATURE_QUIET;
641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
643 hw->wiphy->features |=
644 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
646 if (fw_has_capa(&mvm->fw->ucode_capa,
647 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
648 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
650 if (fw_has_api(&mvm->fw->ucode_capa,
651 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
652 wiphy_ext_feature_set(hw->wiphy,
653 NL80211_EXT_FEATURE_SCAN_START_TIME);
654 wiphy_ext_feature_set(hw->wiphy,
655 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
656 wiphy_ext_feature_set(hw->wiphy,
657 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
660 if (iwl_mvm_is_oce_supported(mvm)) {
661 wiphy_ext_feature_set(hw->wiphy,
662 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
663 wiphy_ext_feature_set(hw->wiphy,
664 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
665 wiphy_ext_feature_set(hw->wiphy,
666 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
667 wiphy_ext_feature_set(hw->wiphy,
668 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
671 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
673 #ifdef CONFIG_PM_SLEEP
674 if (iwl_mvm_is_d0i3_supported(mvm) &&
675 device_can_wakeup(mvm->trans->dev)) {
676 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
677 hw->wiphy->wowlan = &mvm->wowlan;
680 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
681 mvm->trans->ops->d3_suspend &&
682 mvm->trans->ops->d3_resume &&
683 device_can_wakeup(mvm->trans->dev)) {
684 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
685 WIPHY_WOWLAN_DISCONNECT |
686 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
687 WIPHY_WOWLAN_RFKILL_RELEASE |
688 WIPHY_WOWLAN_NET_DETECT;
689 if (!iwlwifi_mod_params.swcrypto)
690 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
691 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
692 WIPHY_WOWLAN_4WAY_HANDSHAKE;
694 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
695 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
696 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
697 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
698 hw->wiphy->wowlan = &mvm->wowlan;
702 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
703 /* assign default bcast filtering configuration */
704 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
707 ret = iwl_mvm_leds_init(mvm);
711 if (fw_has_capa(&mvm->fw->ucode_capa,
712 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
713 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
714 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
715 ieee80211_hw_set(hw, TDLS_WIDER_BW);
718 if (fw_has_capa(&mvm->fw->ucode_capa,
719 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
720 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
721 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
724 hw->netdev_features |= mvm->cfg->features;
725 if (!iwl_mvm_is_csum_supported(mvm)) {
726 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
728 /* We may support SW TX CSUM */
729 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
730 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
733 ret = ieee80211_register_hw(mvm->hw);
735 iwl_mvm_leds_exit(mvm);
736 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
738 if (mvm->cfg->vht_mu_mimo_supported)
739 wiphy_ext_feature_set(hw->wiphy,
740 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
745 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
746 struct ieee80211_sta *sta,
749 struct iwl_mvm_sta *mvmsta;
753 * double check the IN_D0I3 flag both before and after
754 * taking the spinlock, in order to prevent taking
755 * the spinlock when not needed.
757 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
760 spin_lock(&mvm->d0i3_tx_lock);
762 * testing the flag again ensures the skb dequeue
763 * loop (on d0i3 exit) hasn't run yet.
765 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
768 mvmsta = iwl_mvm_sta_from_mac80211(sta);
769 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
770 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
773 __skb_queue_tail(&mvm->d0i3_tx, skb);
774 ieee80211_stop_queues(mvm->hw);
777 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
778 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
782 spin_unlock(&mvm->d0i3_tx_lock);
786 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
787 struct ieee80211_tx_control *control,
790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
791 struct ieee80211_sta *sta = control->sta;
792 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
793 struct ieee80211_hdr *hdr = (void *)skb->data;
795 if (iwl_mvm_is_radio_killed(mvm)) {
796 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
800 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
801 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
802 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
805 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
806 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
807 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
808 ieee80211_is_mgmt(hdr->frame_control) &&
809 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
813 if (iwl_mvm_defer_tx(mvm, sta, skb))
815 if (iwl_mvm_tx_skb(mvm, skb, sta))
820 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
824 ieee80211_free_txskb(hw, skb);
827 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
829 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
834 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
836 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
838 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
841 /* enabled by default */
845 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
847 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
849 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
853 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
854 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
855 enum ieee80211_ampdu_mlme_action action)
857 struct iwl_fw_dbg_trigger_tlv *trig;
858 struct iwl_fw_dbg_trigger_ba *ba_trig;
860 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
865 ba_trig = (void *)trig->data;
868 case IEEE80211_AMPDU_TX_OPERATIONAL: {
869 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
870 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
872 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
873 "TX AGG START: MAC %pM tid %d ssn %d\n",
874 sta->addr, tid, tid_data->ssn);
877 case IEEE80211_AMPDU_TX_STOP_CONT:
878 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
879 "TX AGG STOP: MAC %pM tid %d\n",
882 case IEEE80211_AMPDU_RX_START:
883 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
884 "RX AGG START: MAC %pM tid %d ssn %d\n",
885 sta->addr, tid, rx_ba_ssn);
887 case IEEE80211_AMPDU_RX_STOP:
888 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
889 "RX AGG STOP: MAC %pM tid %d\n",
897 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
898 struct ieee80211_vif *vif,
899 struct ieee80211_ampdu_params *params)
901 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
903 bool tx_agg_ref = false;
904 struct ieee80211_sta *sta = params->sta;
905 enum ieee80211_ampdu_mlme_action action = params->action;
906 u16 tid = params->tid;
907 u16 *ssn = ¶ms->ssn;
908 u16 buf_size = params->buf_size;
909 bool amsdu = params->amsdu;
910 u16 timeout = params->timeout;
912 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
913 sta->addr, tid, action);
915 if (!(mvm->nvm_data->sku_cap_11n_enable))
918 /* return from D0i3 before starting a new Tx aggregation */
920 case IEEE80211_AMPDU_TX_START:
921 case IEEE80211_AMPDU_TX_STOP_CONT:
922 case IEEE80211_AMPDU_TX_STOP_FLUSH:
923 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
924 case IEEE80211_AMPDU_TX_OPERATIONAL:
926 * for tx start, wait synchronously until D0i3 exit to
927 * get the correct sequence number for the tid.
928 * additionally, some other ampdu actions use direct
929 * target access, which is not handled automatically
930 * by the trans layer (unlike commands), so wait for
931 * d0i3 exit in these cases as well.
933 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
943 mutex_lock(&mvm->mutex);
946 case IEEE80211_AMPDU_RX_START:
947 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
948 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
949 struct iwl_mvm_vif *mvmvif;
950 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
951 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
953 mdata->opened_rx_ba_sessions = true;
954 mvmvif = iwl_mvm_vif_from_mac80211(vif);
955 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
957 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
961 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
964 case IEEE80211_AMPDU_RX_STOP:
965 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
968 case IEEE80211_AMPDU_TX_START:
969 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
973 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
975 case IEEE80211_AMPDU_TX_STOP_CONT:
976 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
978 case IEEE80211_AMPDU_TX_STOP_FLUSH:
979 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
980 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
982 case IEEE80211_AMPDU_TX_OPERATIONAL:
983 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
995 if (action == IEEE80211_AMPDU_RX_START)
998 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1001 mutex_unlock(&mvm->mutex);
1004 * If the tid is marked as started, we won't use it for offloaded
1005 * traffic on the next D0i3 entry. It's safe to unref.
1008 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1013 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1014 struct ieee80211_vif *vif)
1016 struct iwl_mvm *mvm = data;
1017 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1019 mvmvif->uploaded = false;
1020 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1022 spin_lock_bh(&mvm->time_event_lock);
1023 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1024 spin_unlock_bh(&mvm->time_event_lock);
1026 mvmvif->phy_ctxt = NULL;
1027 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1028 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1031 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1033 /* clear the D3 reconfig, we only need it to avoid dumping a
1034 * firmware coredump on reconfiguration, we shouldn't do that
1035 * on D3->D0 transition
1037 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1038 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1039 iwl_fw_error_dump(&mvm->fwrt);
1042 /* cleanup all stale references (scan, roc), but keep the
1043 * ucode_down ref until reconfig is complete
1045 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1047 iwl_mvm_stop_device(mvm);
1049 mvm->scan_status = 0;
1050 mvm->ps_disabled = false;
1051 mvm->calibrating = false;
1053 /* just in case one was running */
1054 iwl_mvm_cleanup_roc_te(mvm);
1055 ieee80211_remain_on_channel_expired(mvm->hw);
1058 * cleanup all interfaces, even inactive ones, as some might have
1059 * gone down during the HW restart
1061 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1063 mvm->p2p_device_vif = NULL;
1064 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1066 iwl_mvm_reset_phy_ctxts(mvm);
1067 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1068 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1069 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1070 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1072 ieee80211_wake_queues(mvm->hw);
1074 /* clear any stale d0i3 state */
1075 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1078 mvm->rx_ba_sessions = 0;
1079 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1080 mvm->monitor_on = false;
1082 /* keep statistics ticking */
1083 iwl_mvm_accu_radio_stats(mvm);
1086 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1090 lockdep_assert_held(&mvm->mutex);
1092 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1094 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1095 * so later code will - from now on - see that we're doing it.
1097 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1098 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1099 /* Clean up some internal and mac80211 state on restart */
1100 iwl_mvm_restart_cleanup(mvm);
1102 /* Hold the reference to prevent runtime suspend while
1103 * the start procedure runs. It's a bit confusing
1104 * that the UCODE_DOWN reference is taken, but it just
1105 * means "UCODE is not UP yet". ( TODO: rename this
1108 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1110 ret = iwl_mvm_up(mvm);
1112 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1113 /* Something went wrong - we need to finish some cleanup
1114 * that normally iwl_mvm_mac_restart_complete() below
1117 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1119 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1126 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1128 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1131 /* Some hw restart cleanups must not hold the mutex */
1132 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1134 * Make sure we are out of d0i3. This is needed
1135 * to make sure the reference accounting is correct
1136 * (and there is no stale d0i3_exit_work).
1138 wait_event_timeout(mvm->d0i3_exit_waitq,
1139 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1144 mutex_lock(&mvm->mutex);
1145 ret = __iwl_mvm_mac_start(mvm);
1146 mutex_unlock(&mvm->mutex);
1151 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1155 mutex_lock(&mvm->mutex);
1157 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1159 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1161 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1163 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1166 /* allow transport/FW low power modes */
1167 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1170 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1171 * of packets the FW sent out, so we must reconnect.
1173 iwl_mvm_teardown_tdls_peers(mvm);
1175 mutex_unlock(&mvm->mutex);
1178 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1180 if (iwl_mvm_is_d0i3_supported(mvm) &&
1181 iwl_mvm_enter_d0i3_on_suspend(mvm))
1182 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1183 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1186 "D0i3 exit on resume timed out\n");
1190 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1191 enum ieee80211_reconfig_type reconfig_type)
1193 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1195 switch (reconfig_type) {
1196 case IEEE80211_RECONFIG_TYPE_RESTART:
1197 iwl_mvm_restart_complete(mvm);
1199 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1200 iwl_mvm_resume_complete(mvm);
1205 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1207 lockdep_assert_held(&mvm->mutex);
1209 /* firmware counters are obviously reset now, but we shouldn't
1210 * partially track so also clear the fw_reset_accu counters.
1212 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1214 /* async_handlers_wk is now blocked */
1217 * The work item could be running or queued if the
1218 * ROC time event stops just as we get here.
1220 flush_work(&mvm->roc_done_wk);
1222 iwl_mvm_stop_device(mvm);
1224 iwl_mvm_async_handlers_purge(mvm);
1225 /* async_handlers_list is empty and will stay empty: HW is stopped */
1227 /* the fw is stopped, the aux sta is dead: clean up driver state */
1228 iwl_mvm_del_aux_sta(mvm);
1231 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1232 * hw (as restart_complete() won't be called in this case) and mac80211
1233 * won't execute the restart.
1234 * But make sure to cleanup interfaces that have gone down before/during
1235 * HW restart was requested.
1237 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1238 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1240 ieee80211_iterate_interfaces(mvm->hw, 0,
1241 iwl_mvm_cleanup_iterator, mvm);
1243 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1244 * make sure there's nothing left there and warn if any is found.
1246 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1249 for (i = 0; i < mvm->max_scans; i++) {
1250 if (WARN_ONCE(mvm->scan_uid_status[i],
1251 "UMAC scan UID %d status was not cleaned\n",
1253 mvm->scan_uid_status[i] = 0;
1258 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1262 flush_work(&mvm->d0i3_exit_work);
1263 flush_work(&mvm->async_handlers_wk);
1264 flush_work(&mvm->add_stream_wk);
1267 * Lock and clear the firmware running bit here already, so that
1268 * new commands coming in elsewhere, e.g. from debugfs, will not
1269 * be able to proceed. This is important here because one of those
1270 * debugfs files causes the firmware dump to be triggered, and if we
1271 * don't stop debugfs accesses before canceling that it could be
1272 * retriggered after we flush it but before we've cleared the bit.
1274 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1276 iwl_fw_cancel_dump(&mvm->fwrt);
1277 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1278 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1279 iwl_fw_free_dump_desc(&mvm->fwrt);
1281 mutex_lock(&mvm->mutex);
1282 __iwl_mvm_mac_stop(mvm);
1283 mutex_unlock(&mvm->mutex);
1286 * The worker might have been waiting for the mutex, let it run and
1287 * discover that its list is now empty.
1289 cancel_work_sync(&mvm->async_handlers_wk);
1292 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1296 lockdep_assert_held(&mvm->mutex);
1298 for (i = 0; i < NUM_PHY_CTX; i++)
1299 if (!mvm->phy_ctxts[i].ref)
1300 return &mvm->phy_ctxts[i];
1302 IWL_ERR(mvm, "No available PHY context\n");
1306 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1311 struct iwl_dev_tx_power_cmd v5;
1312 struct iwl_dev_tx_power_cmd_v4 v4;
1314 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1315 .v5.v3.mac_context_id =
1316 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1317 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1320 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1321 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1323 if (fw_has_api(&mvm->fw->ucode_capa,
1324 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1325 len = sizeof(cmd.v5);
1326 else if (fw_has_capa(&mvm->fw->ucode_capa,
1327 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1328 len = sizeof(cmd.v4);
1330 len = sizeof(cmd.v4.v3);
1332 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1335 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1336 struct ieee80211_vif *vif)
1338 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1339 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1343 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1346 * make sure D0i3 exit is completed, otherwise a target access
1347 * during tx queue configuration could be done when still in
1350 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1355 * Not much to do here. The stack will not allow interface
1356 * types or combinations that we didn't advertise, so we
1357 * don't really have to check the types.
1360 mutex_lock(&mvm->mutex);
1362 /* make sure that beacon statistics don't go backwards with FW reset */
1363 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1364 mvmvif->beacon_stats.accu_num_beacons +=
1365 mvmvif->beacon_stats.num_beacons;
1367 /* Allocate resources for the MAC context, and add it to the fw */
1368 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1372 /* Counting number of interfaces is needed for legacy PM */
1373 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1377 * The AP binding flow can be done only after the beacon
1378 * template is configured (which happens only in the mac80211
1379 * start_ap() flow), and adding the broadcast station can happen
1380 * only after the binding.
1381 * In addition, since modifying the MAC before adding a bcast
1382 * station is not allowed by the FW, delay the adding of MAC context to
1383 * the point where we can also add the bcast station.
1384 * In short: there's not much we can do at this point, other than
1385 * allocating resources :)
1387 if (vif->type == NL80211_IFTYPE_AP ||
1388 vif->type == NL80211_IFTYPE_ADHOC) {
1389 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1391 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1396 * Only queue for this station is the mcast queue,
1397 * which shouldn't be in TFD mask anyway
1399 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1405 iwl_mvm_vif_dbgfs_register(mvm, vif);
1409 mvmvif->features |= hw->netdev_features;
1411 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1415 ret = iwl_mvm_power_update_mac(mvm);
1417 goto out_remove_mac;
1419 /* beacon filtering */
1420 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1422 goto out_remove_mac;
1424 if (!mvm->bf_allowed_vif &&
1425 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1426 mvm->bf_allowed_vif = mvmvif;
1427 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1428 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1432 * P2P_DEVICE interface does not have a channel context assigned to it,
1433 * so a dedicated PHY context is allocated to it and the corresponding
1434 * MAC context is bound to it at this stage.
1436 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1438 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1439 if (!mvmvif->phy_ctxt) {
1444 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1445 ret = iwl_mvm_binding_add_vif(mvm, vif);
1449 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1453 /* Save a pointer to p2p device vif, so it can later be used to
1454 * update the p2p device MAC when a GO is started/stopped */
1455 mvm->p2p_device_vif = vif;
1458 iwl_mvm_tcm_add_vif(mvm, vif);
1460 if (vif->type == NL80211_IFTYPE_MONITOR)
1461 mvm->monitor_on = true;
1463 iwl_mvm_vif_dbgfs_register(mvm, vif);
1467 iwl_mvm_binding_remove_vif(mvm, vif);
1469 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1471 if (mvm->bf_allowed_vif == mvmvif) {
1472 mvm->bf_allowed_vif = NULL;
1473 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1474 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1477 mvmvif->phy_ctxt = NULL;
1478 iwl_mvm_mac_ctxt_remove(mvm, vif);
1480 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1483 mutex_unlock(&mvm->mutex);
1485 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1490 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1491 struct ieee80211_vif *vif)
1493 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1495 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1496 * We assume here that all the packets sent to the OFFCHANNEL
1497 * queue are sent in ROC session.
1499 flush_work(&mvm->roc_done_wk);
1503 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif)
1506 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1507 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1508 struct iwl_probe_resp_data *probe_data;
1510 iwl_mvm_prepare_mac_removal(mvm, vif);
1512 if (!(vif->type == NL80211_IFTYPE_AP ||
1513 vif->type == NL80211_IFTYPE_ADHOC))
1514 iwl_mvm_tcm_rm_vif(mvm, vif);
1516 mutex_lock(&mvm->mutex);
1518 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1519 lockdep_is_held(&mvm->mutex));
1520 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1522 kfree_rcu(probe_data, rcu_head);
1524 if (mvm->bf_allowed_vif == mvmvif) {
1525 mvm->bf_allowed_vif = NULL;
1526 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1527 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1530 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1533 * For AP/GO interface, the tear down of the resources allocated to the
1534 * interface is be handled as part of the stop_ap flow.
1536 if (vif->type == NL80211_IFTYPE_AP ||
1537 vif->type == NL80211_IFTYPE_ADHOC) {
1538 #ifdef CONFIG_NL80211_TESTMODE
1539 if (vif == mvm->noa_vif) {
1540 mvm->noa_vif = NULL;
1541 mvm->noa_duration = 0;
1544 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1545 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1549 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1550 mvm->p2p_device_vif = NULL;
1551 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1552 iwl_mvm_binding_remove_vif(mvm, vif);
1553 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1554 mvmvif->phy_ctxt = NULL;
1557 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1560 iwl_mvm_power_update_mac(mvm);
1561 iwl_mvm_mac_ctxt_remove(mvm, vif);
1563 if (vif->type == NL80211_IFTYPE_MONITOR)
1564 mvm->monitor_on = false;
1567 mutex_unlock(&mvm->mutex);
1570 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1575 struct iwl_mvm_mc_iter_data {
1576 struct iwl_mvm *mvm;
1580 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1581 struct ieee80211_vif *vif)
1583 struct iwl_mvm_mc_iter_data *data = _data;
1584 struct iwl_mvm *mvm = data->mvm;
1585 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1586 struct iwl_host_cmd hcmd = {
1587 .id = MCAST_FILTER_CMD,
1589 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1593 /* if we don't have free ports, mcast frames will be dropped */
1594 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1597 if (vif->type != NL80211_IFTYPE_STATION ||
1598 !vif->bss_conf.assoc)
1601 cmd->port_id = data->port_id++;
1602 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1603 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1608 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1610 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1613 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1615 struct iwl_mvm_mc_iter_data iter_data = {
1619 lockdep_assert_held(&mvm->mutex);
1621 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1624 ieee80211_iterate_active_interfaces_atomic(
1625 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1626 iwl_mvm_mc_iface_iterator, &iter_data);
1629 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1630 struct netdev_hw_addr_list *mc_list)
1632 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1633 struct iwl_mcast_filter_cmd *cmd;
1634 struct netdev_hw_addr *addr;
1639 addr_count = netdev_hw_addr_list_count(mc_list);
1640 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1641 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1645 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1646 cmd = kzalloc(len, GFP_ATOMIC);
1652 return (u64)(unsigned long)cmd;
1655 netdev_hw_addr_list_for_each(addr, mc_list) {
1656 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1657 cmd->count, addr->addr);
1658 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1659 addr->addr, ETH_ALEN);
1663 return (u64)(unsigned long)cmd;
1666 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1667 unsigned int changed_flags,
1668 unsigned int *total_flags,
1671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1672 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1674 mutex_lock(&mvm->mutex);
1676 /* replace previous configuration */
1677 kfree(mvm->mcast_filter_cmd);
1678 mvm->mcast_filter_cmd = cmd;
1683 if (changed_flags & FIF_ALLMULTI)
1684 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1689 iwl_mvm_recalc_multicast(mvm);
1691 mutex_unlock(&mvm->mutex);
1695 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1696 struct ieee80211_vif *vif,
1697 unsigned int filter_flags,
1698 unsigned int changed_flags)
1700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1702 /* We support only filter for probe requests */
1703 if (!(changed_flags & FIF_PROBE_REQ))
1706 /* Supported only for p2p client interfaces */
1707 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1711 mutex_lock(&mvm->mutex);
1712 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1713 mutex_unlock(&mvm->mutex);
1716 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1717 struct iwl_bcast_iter_data {
1718 struct iwl_mvm *mvm;
1719 struct iwl_bcast_filter_cmd *cmd;
1724 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1725 const struct iwl_fw_bcast_filter *in_filter,
1726 struct iwl_fw_bcast_filter *out_filter)
1728 struct iwl_fw_bcast_filter_attr *attr;
1731 memcpy(out_filter, in_filter, sizeof(*out_filter));
1733 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1734 attr = &out_filter->attrs[i];
1739 switch (attr->reserved1) {
1740 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1741 if (vif->bss_conf.arp_addr_cnt != 1) {
1746 attr->val = vif->bss_conf.arp_addr_list[0];
1748 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1749 attr->val = *(__be32 *)&vif->addr[2];
1754 attr->reserved1 = 0;
1755 out_filter->num_attrs++;
1759 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1760 struct ieee80211_vif *vif)
1762 struct iwl_bcast_iter_data *data = _data;
1763 struct iwl_mvm *mvm = data->mvm;
1764 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1765 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1766 struct iwl_fw_bcast_mac *bcast_mac;
1769 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1772 bcast_mac = &cmd->macs[mvmvif->id];
1775 * enable filtering only for associated stations, but not for P2P
1778 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1779 !vif->bss_conf.assoc)
1782 bcast_mac->default_discard = 1;
1784 /* copy all configured filters */
1785 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1787 * Make sure we don't exceed our filters limit.
1788 * if there is still a valid filter to be configured,
1789 * be on the safe side and just allow bcast for this mac.
1791 if (WARN_ON_ONCE(data->current_filter >=
1792 ARRAY_SIZE(cmd->filters))) {
1793 bcast_mac->default_discard = 0;
1794 bcast_mac->attached_filters = 0;
1798 iwl_mvm_set_bcast_filter(vif,
1799 &mvm->bcast_filters[i],
1800 &cmd->filters[data->current_filter]);
1802 /* skip current filter if it contains no attributes */
1803 if (!cmd->filters[data->current_filter].num_attrs)
1806 /* attach the filter to current mac */
1807 bcast_mac->attached_filters |=
1808 cpu_to_le16(BIT(data->current_filter));
1810 data->current_filter++;
1814 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1815 struct iwl_bcast_filter_cmd *cmd)
1817 struct iwl_bcast_iter_data iter_data = {
1822 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1825 memset(cmd, 0, sizeof(*cmd));
1826 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1827 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1829 #ifdef CONFIG_IWLWIFI_DEBUGFS
1830 /* use debugfs filters/macs if override is configured */
1831 if (mvm->dbgfs_bcast_filtering.override) {
1832 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1833 sizeof(cmd->filters));
1834 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1840 /* if no filters are configured, do nothing */
1841 if (!mvm->bcast_filters)
1844 /* configure and attach these filters for each associated sta vif */
1845 ieee80211_iterate_active_interfaces(
1846 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1847 iwl_mvm_bcast_filter_iterator, &iter_data);
1852 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1854 struct iwl_bcast_filter_cmd cmd;
1856 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1859 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1862 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1866 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1872 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1873 struct ieee80211_vif *vif)
1875 struct iwl_mu_group_mgmt_cmd cmd = {};
1877 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1878 WLAN_MEMBERSHIP_LEN);
1879 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1880 WLAN_USER_POSITION_LEN);
1882 return iwl_mvm_send_cmd_pdu(mvm,
1883 WIDE_ID(DATA_PATH_GROUP,
1884 UPDATE_MU_GROUPS_CMD),
1885 0, sizeof(cmd), &cmd);
1888 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1889 struct ieee80211_vif *vif)
1891 if (vif->mu_mimo_owner) {
1892 struct iwl_mu_group_mgmt_notif *notif = _data;
1895 * MU-MIMO Group Id action frame is little endian. We treat
1896 * the data received from firmware as if it came from the
1897 * action frame, so no conversion is needed.
1899 ieee80211_update_mu_groups(vif,
1900 (u8 *)¬if->membership_status,
1901 (u8 *)¬if->user_position);
1905 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1906 struct iwl_rx_cmd_buffer *rxb)
1908 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1909 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1911 ieee80211_iterate_active_interfaces_atomic(
1912 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1913 iwl_mvm_mu_mimo_iface_iterator, notif);
1916 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1918 u8 byte_num = ppe_pos_bit / 8;
1919 u8 bit_num = ppe_pos_bit % 8;
1924 return (ppe[byte_num] >> bit_num) &
1925 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1928 * If bit_num > 5, we have to combine bits with next byte.
1929 * Calculate how many bits we need to take from current byte (called
1930 * here "residue_bits"), and add them to bits from next byte.
1933 residue_bits = 8 - bit_num;
1935 res = (ppe[byte_num + 1] &
1936 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1938 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1943 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1944 struct ieee80211_vif *vif, u8 sta_id)
1946 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1947 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1949 .tid_limit = IWL_MAX_TID_COUNT,
1950 .bss_color = vif->bss_conf.bss_color,
1951 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1952 .frame_time_rts_th =
1953 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1955 struct ieee80211_sta *sta;
1961 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1964 WARN(1, "Can't find STA to configure HE\n");
1968 if (!sta->he_cap.has_he) {
1976 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1977 IEEE80211_HE_MAC_CAP0_HTC_HE)
1978 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1979 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1980 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1981 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1982 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
1984 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
1985 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
1986 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
1987 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
1990 sta_ctxt_cmd.htc_flags |=
1991 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
1992 else if (link_adap == 3)
1993 sta_ctxt_cmd.htc_flags |=
1994 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
1996 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
1997 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
1998 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
1999 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2000 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2001 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2002 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2004 /* If PPE Thresholds exist, parse them into a FW-familiar format */
2005 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2006 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2007 u8 nss = (sta->he_cap.ppe_thres[0] &
2008 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2009 u8 ru_index_bitmap =
2010 (sta->he_cap.ppe_thres[0] &
2011 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2012 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2013 u8 *ppe = &sta->he_cap.ppe_thres[0];
2014 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2017 * FW currently supports only nss == MAX_HE_SUPP_NSS
2019 * If nss > MAX: we can ignore values we don't support
2020 * If nss < MAX: we can set zeros in other streams
2022 if (nss > MAX_HE_SUPP_NSS) {
2023 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2025 nss = MAX_HE_SUPP_NSS;
2028 for (i = 0; i < nss; i++) {
2029 u8 ru_index_tmp = ru_index_bitmap << 1;
2032 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2034 if (!(ru_index_tmp & 1))
2037 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2038 iwl_mvm_he_get_ppe_val(ppe,
2041 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2042 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2043 iwl_mvm_he_get_ppe_val(ppe,
2046 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2050 flags |= STA_CTXT_HE_PACKET_EXT;
2054 /* Mark MU EDCA as enabled, unless none detected on some AC */
2055 flags |= STA_CTXT_HE_MU_EDCA_CW;
2056 for (i = 0; i < AC_NUM; i++) {
2057 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2058 &mvmvif->queue_params[i].mu_edca_param_rec;
2060 if (!mvmvif->queue_params[i].mu_edca) {
2061 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2065 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2066 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2067 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2068 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2069 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2070 cpu_to_le16(mu_edca->aifsn);
2071 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2072 cpu_to_le16(mu_edca->mu_edca_timer);
2075 if (vif->bss_conf.multi_sta_back_32bit)
2076 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2078 if (vif->bss_conf.ack_enabled)
2079 flags |= STA_CTXT_HE_ACK_ENABLED;
2081 if (vif->bss_conf.uora_exists) {
2082 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2084 sta_ctxt_cmd.rand_alloc_ecwmin =
2085 vif->bss_conf.uora_ocw_range & 0x7;
2086 sta_ctxt_cmd.rand_alloc_ecwmax =
2087 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2090 /* TODO: support Multi BSSID IE */
2092 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2094 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2095 DATA_PATH_GROUP, 0),
2096 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2097 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2100 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2101 struct ieee80211_vif *vif,
2102 struct ieee80211_bss_conf *bss_conf,
2105 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2109 * Re-calculate the tsf id, as the master-slave relations depend on the
2110 * beacon interval, which was not known when the station interface was
2113 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2114 if (vif->bss_conf.he_support &&
2115 !iwlwifi_mod_params.disable_11ax)
2116 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2118 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2122 * If we're not associated yet, take the (new) BSSID before associating
2123 * so the firmware knows. If we're already associated, then use the old
2124 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2125 * branch for disassociation below.
2127 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2128 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2130 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2132 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2134 /* after sending it once, adopt mac80211 data */
2135 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2136 mvmvif->associated = bss_conf->assoc;
2138 if (changes & BSS_CHANGED_ASSOC) {
2139 if (bss_conf->assoc) {
2140 /* clear statistics to get clean beacon counter */
2141 iwl_mvm_request_statistics(mvm, true);
2142 memset(&mvmvif->beacon_stats, 0,
2143 sizeof(mvmvif->beacon_stats));
2145 /* add quota for this interface */
2146 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2148 IWL_ERR(mvm, "failed to update quotas\n");
2152 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2155 * If we're restarting then the firmware will
2156 * obviously have lost synchronisation with
2157 * the AP. It will attempt to synchronise by
2158 * itself, but we can make it more reliable by
2159 * scheduling a session protection time event.
2161 * The firmware needs to receive a beacon to
2162 * catch up with synchronisation, use 110% of
2163 * the beacon interval.
2165 * Set a large maximum delay to allow for more
2166 * than a single interface.
2168 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2169 iwl_mvm_protect_session(mvm, vif, dur, dur,
2173 iwl_mvm_sf_update(mvm, vif, false);
2174 iwl_mvm_power_vif_assoc(mvm, vif);
2176 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2177 iwl_mvm_update_smps(mvm, vif,
2178 IWL_MVM_SMPS_REQ_PROT,
2179 IEEE80211_SMPS_DYNAMIC);
2181 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2183 * If update fails - SF might be running in associated
2184 * mode while disassociated - which is forbidden.
2186 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2187 "Failed to update SF upon disassociation\n");
2190 * If we get an assert during the connection (after the
2191 * station has been added, but before the vif is set
2192 * to associated), mac80211 will re-add the station and
2193 * then configure the vif. Since the vif is not
2194 * associated, we would remove the station here and
2195 * this would fail the recovery.
2197 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2200 * Remove AP station now that
2201 * the MAC is unassoc
2203 ret = iwl_mvm_rm_sta_id(mvm, vif,
2207 "failed to remove AP station\n");
2209 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2210 mvm->d0i3_ap_sta_id =
2211 IWL_MVM_INVALID_STA;
2212 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2215 /* remove quota for this interface */
2216 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2218 IWL_ERR(mvm, "failed to update quotas\n");
2221 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2223 /* this will take the cleared BSSID from bss_conf */
2224 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2227 "failed to update MAC %pM (clear after unassoc)\n",
2232 * The firmware tracks the MU-MIMO group on its own.
2233 * However, on HW restart we should restore this data.
2235 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2236 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2237 ret = iwl_mvm_update_mu_groups(mvm, vif);
2240 "failed to update VHT MU_MIMO groups\n");
2243 iwl_mvm_recalc_multicast(mvm);
2244 iwl_mvm_configure_bcast_filter(mvm);
2246 /* reset rssi values */
2247 mvmvif->bf_data.ave_beacon_signal = 0;
2249 iwl_mvm_bt_coex_vif_change(mvm);
2250 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2251 IEEE80211_SMPS_AUTOMATIC);
2252 if (fw_has_capa(&mvm->fw->ucode_capa,
2253 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2254 iwl_mvm_config_scan(mvm);
2257 if (changes & BSS_CHANGED_BEACON_INFO) {
2259 * We received a beacon from the associated AP so
2260 * remove the session protection.
2262 iwl_mvm_stop_session_protection(mvm, vif);
2264 iwl_mvm_sf_update(mvm, vif, false);
2265 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2268 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2270 * Send power command on every beacon change,
2271 * because we may have not enabled beacon abort yet.
2273 BSS_CHANGED_BEACON_INFO)) {
2274 ret = iwl_mvm_power_update_mac(mvm);
2276 IWL_ERR(mvm, "failed to update power mode\n");
2279 if (changes & BSS_CHANGED_TXPOWER) {
2280 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2282 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2285 if (changes & BSS_CHANGED_CQM) {
2286 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2287 /* reset cqm events tracking */
2288 mvmvif->bf_data.last_cqm_event = 0;
2289 if (mvmvif->bf_data.bf_enabled) {
2290 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2293 "failed to update CQM thresholds\n");
2297 if (changes & BSS_CHANGED_ARP_FILTER) {
2298 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2299 iwl_mvm_configure_bcast_filter(mvm);
2303 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2304 struct ieee80211_vif *vif)
2306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2307 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2311 * iwl_mvm_mac_ctxt_add() might read directly from the device
2312 * (the system time), so make sure it is available.
2314 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2318 mutex_lock(&mvm->mutex);
2320 /* Send the beacon template */
2321 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2326 * Re-calculate the tsf id, as the master-slave relations depend on the
2327 * beacon interval, which was not known when the AP interface was added.
2329 if (vif->type == NL80211_IFTYPE_AP)
2330 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2332 mvmvif->ap_assoc_sta_count = 0;
2334 /* Add the mac context */
2335 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2339 /* Perform the binding */
2340 ret = iwl_mvm_binding_add_vif(mvm, vif);
2345 * This is not very nice, but the simplest:
2346 * For older FWs adding the mcast sta before the bcast station may
2347 * cause assert 0x2b00.
2348 * This is fixed in later FW so make the order of removal depend on
2351 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2352 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2356 * Send the bcast station. At this stage the TBTT and DTIM time
2357 * events are added and applied to the scheduler
2359 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2361 iwl_mvm_rm_mcast_sta(mvm, vif);
2366 * Send the bcast station. At this stage the TBTT and DTIM time
2367 * events are added and applied to the scheduler
2369 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2372 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2374 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2379 /* must be set before quota calculations */
2380 mvmvif->ap_ibss_active = true;
2382 /* power updated needs to be done before quotas */
2383 iwl_mvm_power_update_mac(mvm);
2385 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2387 goto out_quota_failed;
2389 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2390 if (vif->p2p && mvm->p2p_device_vif)
2391 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2393 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2395 iwl_mvm_bt_coex_vif_change(mvm);
2397 /* we don't support TDLS during DCM */
2398 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2399 iwl_mvm_teardown_tdls_peers(mvm);
2404 iwl_mvm_power_update_mac(mvm);
2405 mvmvif->ap_ibss_active = false;
2406 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2407 iwl_mvm_rm_mcast_sta(mvm, vif);
2409 iwl_mvm_binding_remove_vif(mvm, vif);
2411 iwl_mvm_mac_ctxt_remove(mvm, vif);
2413 mutex_unlock(&mvm->mutex);
2414 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2418 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2419 struct ieee80211_vif *vif)
2421 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2422 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2424 iwl_mvm_prepare_mac_removal(mvm, vif);
2426 mutex_lock(&mvm->mutex);
2428 /* Handle AP stop while in CSA */
2429 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2430 iwl_mvm_remove_time_event(mvm, mvmvif,
2431 &mvmvif->time_event_data);
2432 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2433 mvmvif->csa_countdown = false;
2436 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2437 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2438 mvm->csa_tx_block_bcn_timeout = 0;
2441 mvmvif->ap_ibss_active = false;
2442 mvm->ap_last_beacon_gp2 = 0;
2444 iwl_mvm_bt_coex_vif_change(mvm);
2446 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2448 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2449 if (vif->p2p && mvm->p2p_device_vif)
2450 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2452 iwl_mvm_update_quotas(mvm, false, NULL);
2455 * This is not very nice, but the simplest:
2456 * For older FWs removing the mcast sta before the bcast station may
2457 * cause assert 0x2b00.
2458 * This is fixed in later FW (which will stop beaconing when removing
2460 * So make the order of removal depend on the TLV
2462 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2463 iwl_mvm_rm_mcast_sta(mvm, vif);
2464 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2465 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2466 iwl_mvm_rm_mcast_sta(mvm, vif);
2467 iwl_mvm_binding_remove_vif(mvm, vif);
2469 iwl_mvm_power_update_mac(mvm);
2471 iwl_mvm_mac_ctxt_remove(mvm, vif);
2473 kfree(mvmvif->ap_wep_key);
2474 mvmvif->ap_wep_key = NULL;
2476 mutex_unlock(&mvm->mutex);
2480 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2481 struct ieee80211_vif *vif,
2482 struct ieee80211_bss_conf *bss_conf,
2485 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2487 /* Changes will be applied when the AP/IBSS is started */
2488 if (!mvmvif->ap_ibss_active)
2491 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2492 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2493 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2494 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2496 /* Need to send a new beacon template to the FW */
2497 if (changes & BSS_CHANGED_BEACON &&
2498 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2499 IWL_WARN(mvm, "Failed updating beacon data\n");
2501 if (changes & BSS_CHANGED_TXPOWER) {
2502 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2504 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2508 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2509 struct ieee80211_vif *vif,
2510 struct ieee80211_bss_conf *bss_conf,
2513 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2516 * iwl_mvm_bss_info_changed_station() might call
2517 * iwl_mvm_protect_session(), which reads directly from
2518 * the device (the system time), so make sure it is available.
2520 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2523 mutex_lock(&mvm->mutex);
2525 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2526 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2528 switch (vif->type) {
2529 case NL80211_IFTYPE_STATION:
2530 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2532 case NL80211_IFTYPE_AP:
2533 case NL80211_IFTYPE_ADHOC:
2534 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2536 case NL80211_IFTYPE_MONITOR:
2537 if (changes & BSS_CHANGED_MU_GROUPS)
2538 iwl_mvm_update_mu_groups(mvm, vif);
2541 /* shouldn't happen */
2545 mutex_unlock(&mvm->mutex);
2546 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2549 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2550 struct ieee80211_vif *vif,
2551 struct ieee80211_scan_request *hw_req)
2553 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2556 if (hw_req->req.n_channels == 0 ||
2557 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2560 mutex_lock(&mvm->mutex);
2561 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2562 mutex_unlock(&mvm->mutex);
2567 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2568 struct ieee80211_vif *vif)
2570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2572 mutex_lock(&mvm->mutex);
2574 /* Due to a race condition, it's possible that mac80211 asks
2575 * us to stop a hw_scan when it's already stopped. This can
2576 * happen, for instance, if we stopped the scan ourselves,
2577 * called ieee80211_scan_completed() and the userspace called
2578 * cancel scan scan before ieee80211_scan_work() could run.
2579 * To handle that, simply return if the scan is not running.
2581 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2582 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2584 mutex_unlock(&mvm->mutex);
2588 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2589 struct ieee80211_sta *sta, u16 tids,
2591 enum ieee80211_frame_release_type reason,
2594 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2596 /* Called when we need to transmit (a) frame(s) from mac80211 */
2598 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2599 tids, more_data, false);
2603 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2604 struct ieee80211_sta *sta, u16 tids,
2606 enum ieee80211_frame_release_type reason,
2609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2611 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2613 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2614 tids, more_data, true);
2617 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2618 enum sta_notify_cmd cmd,
2619 struct ieee80211_sta *sta)
2621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2622 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2623 unsigned long txqs = 0, tids = 0;
2627 * If we have TVQM then we get too high queue numbers - luckily
2628 * we really shouldn't get here with that because such hardware
2629 * should have firmware supporting buffer station offload.
2631 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2634 spin_lock_bh(&mvmsta->lock);
2635 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2636 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2638 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2641 __set_bit(tid_data->txq_id, &txqs);
2643 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2646 __set_bit(tid, &tids);
2650 case STA_NOTIFY_SLEEP:
2651 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2652 ieee80211_sta_set_buffered(sta, tid, true);
2655 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2657 * The fw updates the STA to be asleep. Tx packets on the Tx
2658 * queues to this station will not be transmitted. The fw will
2659 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2662 case STA_NOTIFY_AWAKE:
2663 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2667 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2668 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2673 spin_unlock_bh(&mvmsta->lock);
2676 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2677 struct ieee80211_vif *vif,
2678 enum sta_notify_cmd cmd,
2679 struct ieee80211_sta *sta)
2681 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2684 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2686 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2687 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2688 struct ieee80211_sta *sta;
2689 struct iwl_mvm_sta *mvmsta;
2690 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2692 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2696 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2697 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2702 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2705 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2710 if (mvmsta->sleeping != sleeping) {
2711 mvmsta->sleeping = sleeping;
2712 __iwl_mvm_mac_sta_notify(mvm->hw,
2713 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2715 ieee80211_sta_ps_transition(sta, sleeping);
2719 switch (notif->type) {
2720 case IWL_MVM_PM_EVENT_AWAKE:
2721 case IWL_MVM_PM_EVENT_ASLEEP:
2723 case IWL_MVM_PM_EVENT_UAPSD:
2724 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2726 case IWL_MVM_PM_EVENT_PS_POLL:
2727 ieee80211_sta_pspoll(sta);
2737 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2738 struct ieee80211_vif *vif,
2739 struct ieee80211_sta *sta)
2741 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2742 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2745 * This is called before mac80211 does RCU synchronisation,
2746 * so here we already invalidate our internal RCU-protected
2747 * station pointer. The rest of the code will thus no longer
2748 * be able to find the station this way, and we don't rely
2749 * on further RCU synchronisation after the sta_state()
2750 * callback deleted the station.
2752 mutex_lock(&mvm->mutex);
2753 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2754 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2757 mutex_unlock(&mvm->mutex);
2760 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2765 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2766 struct iwl_mvm_tcm_mac *mdata;
2768 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2769 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2770 mdata->opened_rx_ba_sessions = false;
2773 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2776 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2777 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2782 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2783 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2787 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2788 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2789 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2794 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2798 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2799 struct ieee80211_vif *vif, u8 *peer_addr,
2800 enum nl80211_tdls_operation action)
2802 struct iwl_fw_dbg_trigger_tlv *trig;
2803 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2805 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2806 FW_DBG_TRIGGER_TDLS);
2810 tdls_trig = (void *)trig->data;
2812 if (!(tdls_trig->action_bitmap & BIT(action)))
2815 if (tdls_trig->peer_mode &&
2816 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2819 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2820 "TDLS event occurred, peer %pM, action %d",
2824 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2825 struct iwl_mvm_sta *mvm_sta)
2827 struct iwl_mvm_tid_data *tid_data;
2828 struct sk_buff *skb;
2831 spin_lock_bh(&mvm_sta->lock);
2832 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2833 tid_data = &mvm_sta->tid_data[i];
2835 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2836 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2839 * The first deferred frame should've stopped the MAC
2840 * queues, so we should never get a second deferred
2841 * frame for the RA/TID.
2843 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2844 ieee80211_free_txskb(mvm->hw, skb);
2847 spin_unlock_bh(&mvm_sta->lock);
2850 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2851 struct ieee80211_vif *vif,
2852 struct ieee80211_sta *sta,
2853 enum ieee80211_sta_state old_state,
2854 enum ieee80211_sta_state new_state)
2856 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2857 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2858 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2861 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2862 sta->addr, old_state, new_state);
2864 /* this would be a mac80211 bug ... but don't crash */
2865 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2869 * If we are in a STA removal flow and in DQA mode:
2871 * This is after the sync_rcu part, so the queues have already been
2872 * flushed. No more TXs on their way in mac80211's path, and no more in
2874 * Also, we won't be getting any new TX frames for this station.
2875 * What we might have are deferred TX frames that need to be taken care
2878 * Drop any still-queued deferred-frame before removing the STA, and
2879 * make sure the worker is no longer handling frames for this STA.
2881 if (old_state == IEEE80211_STA_NONE &&
2882 new_state == IEEE80211_STA_NOTEXIST) {
2883 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2884 flush_work(&mvm->add_stream_wk);
2887 * No need to make sure deferred TX indication is off since the
2888 * worker will already remove it if it was on
2892 mutex_lock(&mvm->mutex);
2893 /* track whether or not the station is associated */
2894 mvm_sta->sta_state = new_state;
2896 if (old_state == IEEE80211_STA_NOTEXIST &&
2897 new_state == IEEE80211_STA_NONE) {
2899 * Firmware bug - it'll crash if the beacon interval is less
2900 * than 16. We can't avoid connecting at all, so refuse the
2901 * station state change, this will cause mac80211 to abandon
2902 * attempts to connect to this AP, and eventually wpa_s will
2903 * blacklist the AP...
2905 if (vif->type == NL80211_IFTYPE_STATION &&
2906 vif->bss_conf.beacon_int < 16) {
2908 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2909 sta->addr, vif->bss_conf.beacon_int);
2916 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2917 IWL_MVM_TDLS_STA_COUNT ||
2918 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2919 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2924 ret = iwl_mvm_add_sta(mvm, vif, sta);
2925 if (sta->tdls && ret == 0) {
2926 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2927 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2928 NL80211_TDLS_SETUP);
2930 } else if (old_state == IEEE80211_STA_NONE &&
2931 new_state == IEEE80211_STA_AUTH) {
2933 * EBS may be disabled due to previous failures reported by FW.
2934 * Reset EBS status here assuming environment has been changed.
2936 mvm->last_ebs_successful = true;
2937 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2939 } else if (old_state == IEEE80211_STA_AUTH &&
2940 new_state == IEEE80211_STA_ASSOC) {
2941 if (vif->type == NL80211_IFTYPE_AP) {
2942 mvmvif->ap_assoc_sta_count++;
2943 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2946 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2948 ret = iwl_mvm_update_sta(mvm, vif, sta);
2949 } else if (old_state == IEEE80211_STA_ASSOC &&
2950 new_state == IEEE80211_STA_AUTHORIZED) {
2952 /* we don't support TDLS during DCM */
2953 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2954 iwl_mvm_teardown_tdls_peers(mvm);
2957 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2958 NL80211_TDLS_ENABLE_LINK);
2960 /* enable beacon filtering */
2961 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2963 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2966 /* if wep is used, need to set the key for the station now */
2967 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
2968 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
2970 STA_KEY_IDX_INVALID);
2973 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2974 new_state == IEEE80211_STA_ASSOC) {
2975 /* disable beacon filtering */
2976 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2978 } else if (old_state == IEEE80211_STA_ASSOC &&
2979 new_state == IEEE80211_STA_AUTH) {
2980 if (vif->type == NL80211_IFTYPE_AP) {
2981 mvmvif->ap_assoc_sta_count--;
2982 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2985 } else if (old_state == IEEE80211_STA_AUTH &&
2986 new_state == IEEE80211_STA_NONE) {
2988 } else if (old_state == IEEE80211_STA_NONE &&
2989 new_state == IEEE80211_STA_NOTEXIST) {
2990 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2992 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2993 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2994 NL80211_TDLS_DISABLE_LINK);
3000 mutex_unlock(&mvm->mutex);
3002 if (sta->tdls && ret == 0) {
3003 if (old_state == IEEE80211_STA_NOTEXIST &&
3004 new_state == IEEE80211_STA_NONE)
3005 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3006 else if (old_state == IEEE80211_STA_NONE &&
3007 new_state == IEEE80211_STA_NOTEXIST)
3008 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3014 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3016 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3018 mvm->rts_threshold = value;
3023 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3024 struct ieee80211_vif *vif,
3025 struct ieee80211_sta *sta, u32 changed)
3027 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3029 if (vif->type == NL80211_IFTYPE_STATION &&
3030 changed & IEEE80211_RC_NSS_CHANGED)
3031 iwl_mvm_sf_update(mvm, vif, false);
3034 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3035 struct ieee80211_vif *vif, u16 ac,
3036 const struct ieee80211_tx_queue_params *params)
3038 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3039 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3041 mvmvif->queue_params[ac] = *params;
3044 * No need to update right away, we'll get BSS_CHANGED_QOS
3045 * The exception is P2P_DEVICE interface which needs immediate update.
3047 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3050 mutex_lock(&mvm->mutex);
3051 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3052 mutex_unlock(&mvm->mutex);
3058 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3059 struct ieee80211_vif *vif,
3062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3063 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3064 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3067 * iwl_mvm_protect_session() reads directly from the device
3068 * (the system time), so make sure it is available.
3070 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3073 if (req_duration > duration)
3074 duration = req_duration;
3076 mutex_lock(&mvm->mutex);
3077 /* Try really hard to protect the session and hear a beacon */
3078 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3079 mutex_unlock(&mvm->mutex);
3081 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3084 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3085 struct ieee80211_vif *vif,
3086 struct cfg80211_sched_scan_request *req,
3087 struct ieee80211_scan_ies *ies)
3089 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3093 mutex_lock(&mvm->mutex);
3095 if (!vif->bss_conf.idle) {
3100 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3103 mutex_unlock(&mvm->mutex);
3107 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3108 struct ieee80211_vif *vif)
3110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3113 mutex_lock(&mvm->mutex);
3115 /* Due to a race condition, it's possible that mac80211 asks
3116 * us to stop a sched_scan when it's already stopped. This
3117 * can happen, for instance, if we stopped the scan ourselves,
3118 * called ieee80211_sched_scan_stopped() and the userspace called
3119 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3120 * could run. To handle this, simply return if the scan is
3123 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3124 mutex_unlock(&mvm->mutex);
3128 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3129 mutex_unlock(&mvm->mutex);
3130 iwl_mvm_wait_for_async_handlers(mvm);
3135 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3136 enum set_key_cmd cmd,
3137 struct ieee80211_vif *vif,
3138 struct ieee80211_sta *sta,
3139 struct ieee80211_key_conf *key)
3141 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3142 struct iwl_mvm_sta *mvmsta;
3143 struct iwl_mvm_key_pn *ptk_pn;
3144 int keyidx = key->keyidx;
3148 if (iwlwifi_mod_params.swcrypto) {
3149 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3153 switch (key->cipher) {
3154 case WLAN_CIPHER_SUITE_TKIP:
3155 if (!mvm->trans->cfg->gen2) {
3156 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3157 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3158 } else if (vif->type == NL80211_IFTYPE_STATION) {
3159 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3161 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3165 case WLAN_CIPHER_SUITE_CCMP:
3166 case WLAN_CIPHER_SUITE_GCMP:
3167 case WLAN_CIPHER_SUITE_GCMP_256:
3168 if (!iwl_mvm_has_new_tx_api(mvm))
3169 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3171 case WLAN_CIPHER_SUITE_AES_CMAC:
3172 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3173 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3174 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3176 case WLAN_CIPHER_SUITE_WEP40:
3177 case WLAN_CIPHER_SUITE_WEP104:
3178 if (vif->type == NL80211_IFTYPE_AP) {
3179 struct iwl_mvm_vif *mvmvif =
3180 iwl_mvm_vif_from_mac80211(vif);
3182 mvmvif->ap_wep_key = kmemdup(key,
3183 sizeof(*key) + key->keylen,
3185 if (!mvmvif->ap_wep_key)
3189 if (vif->type != NL80211_IFTYPE_STATION)
3193 /* currently FW supports only one optional cipher scheme */
3194 if (hw->n_cipher_schemes &&
3195 hw->cipher_schemes->cipher == key->cipher)
3196 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3201 mutex_lock(&mvm->mutex);
3205 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3206 vif->type == NL80211_IFTYPE_AP) && !sta) {
3208 * GTK on AP interface is a TX-only key, return 0;
3209 * on IBSS they're per-station and because we're lazy
3210 * we don't support them for RX, so do the same.
3211 * CMAC/GMAC in AP/IBSS modes must be done in software.
3213 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3214 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3215 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3220 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3221 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3222 !iwl_mvm_has_new_tx_api(mvm)) {
3223 key->hw_key_idx = STA_KEY_IDX_INVALID;
3228 /* During FW restart, in order to restore the state as it was,
3229 * don't try to reprogram keys we previously failed for.
3231 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3232 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3233 IWL_DEBUG_MAC80211(mvm,
3234 "skip invalid idx key programming during restart\n");
3239 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3240 sta && iwl_mvm_has_new_rx_api(mvm) &&
3241 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3242 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3243 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3244 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3245 struct ieee80211_key_seq seq;
3248 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3249 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3250 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3251 mvm->trans->num_rx_queues),
3258 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3259 ieee80211_get_key_rx_seq(key, tid, &seq);
3260 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3261 memcpy(ptk_pn->q[q].pn[tid],
3263 IEEE80211_CCMP_PN_LEN);
3266 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3269 /* in HW restart reuse the index, otherwise request a new one */
3270 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3271 key_offset = key->hw_key_idx;
3273 key_offset = STA_KEY_IDX_INVALID;
3275 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3276 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3278 IWL_WARN(mvm, "set key failed\n");
3280 * can't add key for RX, but we don't need it
3281 * in the device for TX so still return 0
3283 key->hw_key_idx = STA_KEY_IDX_INVALID;
3289 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3294 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3295 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3296 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3297 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3298 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3299 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3300 ptk_pn = rcu_dereference_protected(
3301 mvmsta->ptk_pn[keyidx],
3302 lockdep_is_held(&mvm->mutex));
3303 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3305 kfree_rcu(ptk_pn, rcu_head);
3308 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3309 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3315 mutex_unlock(&mvm->mutex);
3319 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3320 struct ieee80211_vif *vif,
3321 struct ieee80211_key_conf *keyconf,
3322 struct ieee80211_sta *sta,
3323 u32 iv32, u16 *phase1key)
3325 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3327 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3330 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3334 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3335 struct iwl_rx_packet *pkt, void *data)
3337 struct iwl_mvm *mvm =
3338 container_of(notif_wait, struct iwl_mvm, notif_wait);
3339 struct iwl_hs20_roc_res *resp;
3340 int resp_len = iwl_rx_packet_payload_len(pkt);
3341 struct iwl_mvm_time_event_data *te_data = data;
3343 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3346 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3347 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3351 resp = (void *)pkt->data;
3354 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3355 resp->status, resp->event_unique_id);
3357 te_data->uid = le32_to_cpu(resp->event_unique_id);
3358 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3361 spin_lock_bh(&mvm->time_event_lock);
3362 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3363 spin_unlock_bh(&mvm->time_event_lock);
3368 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3369 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3370 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3371 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3372 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3373 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3374 struct ieee80211_channel *channel,
3375 struct ieee80211_vif *vif,
3378 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3379 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3380 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3381 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3382 struct iwl_notification_wait wait_time_event;
3383 u32 dtim_interval = vif->bss_conf.dtim_period *
3384 vif->bss_conf.beacon_int;
3386 struct iwl_hs20_roc_req aux_roc_req = {
3387 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3389 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3390 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3391 /* Set the channel info data */
3392 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3393 PHY_BAND_24 : PHY_BAND_5,
3394 .channel_info.channel = channel->hw_value,
3395 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3396 /* Set the time and duration */
3397 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3400 delay = AUX_ROC_MIN_DELAY;
3401 req_dur = MSEC_TO_TU(duration);
3404 * If we are associated we want the delay time to be at least one
3405 * dtim interval so that the FW can wait until after the DTIM and
3406 * then start the time event, this will potentially allow us to
3407 * remain off-channel for the max duration.
3408 * Since we want to use almost a whole dtim interval we would also
3409 * like the delay to be for 2-3 dtim intervals, in case there are
3410 * other time events with higher priority.
3412 if (vif->bss_conf.assoc) {
3413 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3414 /* We cannot remain off-channel longer than the DTIM interval */
3415 if (dtim_interval <= req_dur) {
3416 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3417 if (req_dur <= AUX_ROC_MIN_DURATION)
3418 req_dur = dtim_interval -
3419 AUX_ROC_MIN_SAFETY_BUFFER;
3423 aux_roc_req.duration = cpu_to_le32(req_dur);
3424 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3427 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3428 channel->hw_value, req_dur, duration, delay,
3430 /* Set the node address */
3431 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3433 lockdep_assert_held(&mvm->mutex);
3435 spin_lock_bh(&mvm->time_event_lock);
3437 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3438 spin_unlock_bh(&mvm->time_event_lock);
3443 te_data->duration = duration;
3444 te_data->id = HOT_SPOT_CMD;
3446 spin_unlock_bh(&mvm->time_event_lock);
3449 * Use a notification wait, which really just processes the
3450 * command response and doesn't wait for anything, in order
3451 * to be able to process the response and get the UID inside
3452 * the RX path. Using CMD_WANT_SKB doesn't work because it
3453 * stores the buffer and then wakes up this thread, by which
3454 * time another notification (that the time event started)
3455 * might already be processed unsuccessfully.
3457 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3458 time_event_response,
3459 ARRAY_SIZE(time_event_response),
3460 iwl_mvm_rx_aux_roc, te_data);
3462 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3466 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3467 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3471 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3472 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3473 /* should never fail */
3478 spin_lock_bh(&mvm->time_event_lock);
3479 iwl_mvm_te_clear_data(mvm, te_data);
3480 spin_unlock_bh(&mvm->time_event_lock);
3486 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3487 struct ieee80211_vif *vif,
3488 struct ieee80211_channel *channel,
3490 enum ieee80211_roc_type type)
3492 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3493 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3494 struct cfg80211_chan_def chandef;
3495 struct iwl_mvm_phy_ctxt *phy_ctxt;
3498 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3502 * Flush the done work, just in case it's still pending, so that
3503 * the work it does can complete and we can accept new frames.
3505 flush_work(&mvm->roc_done_wk);
3507 mutex_lock(&mvm->mutex);
3509 switch (vif->type) {
3510 case NL80211_IFTYPE_STATION:
3511 if (fw_has_capa(&mvm->fw->ucode_capa,
3512 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3513 /* Use aux roc framework (HS20) */
3514 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3518 IWL_ERR(mvm, "hotspot not supported\n");
3521 case NL80211_IFTYPE_P2P_DEVICE:
3525 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3530 for (i = 0; i < NUM_PHY_CTX; i++) {
3531 phy_ctxt = &mvm->phy_ctxts[i];
3532 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3535 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3537 * Unbind the P2P_DEVICE from the current PHY context,
3538 * and if the PHY context is not used remove it.
3540 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3541 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3544 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3546 /* Bind the P2P_DEVICE to the current PHY Context */
3547 mvmvif->phy_ctxt = phy_ctxt;
3549 ret = iwl_mvm_binding_add_vif(mvm, vif);
3550 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3553 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3554 goto schedule_time_event;
3558 /* Need to update the PHY context only if the ROC channel changed */
3559 if (channel == mvmvif->phy_ctxt->channel)
3560 goto schedule_time_event;
3562 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3565 * Change the PHY context configuration as it is currently referenced
3566 * only by the P2P Device MAC
3568 if (mvmvif->phy_ctxt->ref == 1) {
3569 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3575 * The PHY context is shared with other MACs. Need to remove the
3576 * P2P Device from the binding, allocate an new PHY context and
3577 * create a new binding
3579 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3585 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3588 IWL_ERR(mvm, "Failed to change PHY context\n");
3592 /* Unbind the P2P_DEVICE from the current PHY context */
3593 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3594 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3597 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3599 /* Bind the P2P_DEVICE to the new allocated PHY context */
3600 mvmvif->phy_ctxt = phy_ctxt;
3602 ret = iwl_mvm_binding_add_vif(mvm, vif);
3603 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3606 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3609 schedule_time_event:
3610 /* Schedule the time events */
3611 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3614 mutex_unlock(&mvm->mutex);
3615 IWL_DEBUG_MAC80211(mvm, "leave\n");
3619 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3623 IWL_DEBUG_MAC80211(mvm, "enter\n");
3625 mutex_lock(&mvm->mutex);
3626 iwl_mvm_stop_roc(mvm);
3627 mutex_unlock(&mvm->mutex);
3629 IWL_DEBUG_MAC80211(mvm, "leave\n");
3633 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3634 struct ieee80211_chanctx_conf *ctx)
3636 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3637 struct iwl_mvm_phy_ctxt *phy_ctxt;
3640 lockdep_assert_held(&mvm->mutex);
3642 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3644 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3650 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3651 ctx->rx_chains_static,
3652 ctx->rx_chains_dynamic);
3654 IWL_ERR(mvm, "Failed to add PHY context\n");
3658 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3659 *phy_ctxt_id = phy_ctxt->id;
3664 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3665 struct ieee80211_chanctx_conf *ctx)
3667 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3670 mutex_lock(&mvm->mutex);
3671 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3672 mutex_unlock(&mvm->mutex);
3677 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3678 struct ieee80211_chanctx_conf *ctx)
3680 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3681 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3683 lockdep_assert_held(&mvm->mutex);
3685 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3688 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3689 struct ieee80211_chanctx_conf *ctx)
3691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3693 mutex_lock(&mvm->mutex);
3694 __iwl_mvm_remove_chanctx(mvm, ctx);
3695 mutex_unlock(&mvm->mutex);
3698 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3699 struct ieee80211_chanctx_conf *ctx,
3702 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3703 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3704 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3706 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3707 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3708 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3709 IEEE80211_CHANCTX_CHANGE_RADAR |
3710 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3711 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3712 phy_ctxt->ref, changed))
3715 mutex_lock(&mvm->mutex);
3717 /* we are only changing the min_width, may be a noop */
3718 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3719 if (phy_ctxt->width == ctx->min_def.width)
3722 /* we are just toggling between 20_NOHT and 20 */
3723 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3724 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3728 iwl_mvm_bt_coex_vif_change(mvm);
3729 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3730 ctx->rx_chains_static,
3731 ctx->rx_chains_dynamic);
3734 mutex_unlock(&mvm->mutex);
3737 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3738 struct ieee80211_vif *vif,
3739 struct ieee80211_chanctx_conf *ctx,
3740 bool switching_chanctx)
3742 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3743 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3744 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3747 lockdep_assert_held(&mvm->mutex);
3749 mvmvif->phy_ctxt = phy_ctxt;
3751 switch (vif->type) {
3752 case NL80211_IFTYPE_AP:
3753 /* only needed if we're switching chanctx (i.e. during CSA) */
3754 if (switching_chanctx) {
3755 mvmvif->ap_ibss_active = true;
3758 case NL80211_IFTYPE_ADHOC:
3760 * The AP binding flow is handled as part of the start_ap flow
3761 * (in bss_info_changed), similarly for IBSS.
3765 case NL80211_IFTYPE_STATION:
3766 mvmvif->csa_bcn_pending = false;
3768 case NL80211_IFTYPE_MONITOR:
3769 /* always disable PS when a monitor interface is active */
3770 mvmvif->ps_disabled = true;
3777 ret = iwl_mvm_binding_add_vif(mvm, vif);
3782 * Power state must be updated before quotas,
3783 * otherwise fw will complain.
3785 iwl_mvm_power_update_mac(mvm);
3787 /* Setting the quota at this stage is only required for monitor
3788 * interfaces. For the other types, the bss_info changed flow
3789 * will handle quota settings.
3791 if (vif->type == NL80211_IFTYPE_MONITOR) {
3792 mvmvif->monitor_active = true;
3793 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3795 goto out_remove_binding;
3797 ret = iwl_mvm_add_snif_sta(mvm, vif);
3799 goto out_remove_binding;
3803 /* Handle binding during CSA */
3804 if (vif->type == NL80211_IFTYPE_AP) {
3805 iwl_mvm_update_quotas(mvm, false, NULL);
3806 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3809 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3810 u32 duration = 3 * vif->bss_conf.beacon_int;
3812 /* iwl_mvm_protect_session() reads directly from the
3813 * device (the system time), so make sure it is
3816 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3818 goto out_remove_binding;
3820 /* Protect the session to make sure we hear the first
3821 * beacon on the new channel.
3823 mvmvif->csa_bcn_pending = true;
3824 iwl_mvm_protect_session(mvm, vif, duration, duration,
3825 vif->bss_conf.beacon_int / 2,
3828 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3830 iwl_mvm_update_quotas(mvm, false, NULL);
3836 iwl_mvm_binding_remove_vif(mvm, vif);
3837 iwl_mvm_power_update_mac(mvm);
3840 mvmvif->phy_ctxt = NULL;
3843 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3844 struct ieee80211_vif *vif,
3845 struct ieee80211_chanctx_conf *ctx)
3847 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3850 mutex_lock(&mvm->mutex);
3851 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3852 mutex_unlock(&mvm->mutex);
3857 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3858 struct ieee80211_vif *vif,
3859 struct ieee80211_chanctx_conf *ctx,
3860 bool switching_chanctx)
3862 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3863 struct ieee80211_vif *disabled_vif = NULL;
3865 lockdep_assert_held(&mvm->mutex);
3867 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3869 switch (vif->type) {
3870 case NL80211_IFTYPE_ADHOC:
3872 case NL80211_IFTYPE_MONITOR:
3873 mvmvif->monitor_active = false;
3874 mvmvif->ps_disabled = false;
3875 iwl_mvm_rm_snif_sta(mvm, vif);
3877 case NL80211_IFTYPE_AP:
3878 /* This part is triggered only during CSA */
3879 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3882 mvmvif->csa_countdown = false;
3884 /* Set CS bit on all the stations */
3885 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3887 /* Save blocked iface, the timeout is set on the next beacon */
3888 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3890 mvmvif->ap_ibss_active = false;
3892 case NL80211_IFTYPE_STATION:
3893 if (!switching_chanctx)
3898 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3904 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3905 iwl_mvm_binding_remove_vif(mvm, vif);
3908 mvmvif->phy_ctxt = NULL;
3909 iwl_mvm_power_update_mac(mvm);
3912 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3913 struct ieee80211_vif *vif,
3914 struct ieee80211_chanctx_conf *ctx)
3916 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3918 mutex_lock(&mvm->mutex);
3919 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3920 mutex_unlock(&mvm->mutex);
3924 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3925 struct ieee80211_vif_chanctx_switch *vifs)
3929 mutex_lock(&mvm->mutex);
3930 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3931 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3933 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3935 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3939 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3943 "failed to assign new_ctx during channel switch\n");
3947 /* we don't support TDLS during DCM - can be caused by channel switch */
3948 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3949 iwl_mvm_teardown_tdls_peers(mvm);
3954 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3957 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3958 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3962 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3964 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3971 /* things keep failing, better restart the hw */
3972 iwl_mvm_nic_restart(mvm, false);
3975 mutex_unlock(&mvm->mutex);
3981 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3982 struct ieee80211_vif_chanctx_switch *vifs)
3986 mutex_lock(&mvm->mutex);
3987 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3989 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3993 "failed to assign new_ctx during channel switch\n");
4000 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4002 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4009 /* things keep failing, better restart the hw */
4010 iwl_mvm_nic_restart(mvm, false);
4013 mutex_unlock(&mvm->mutex);
4018 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4019 struct ieee80211_vif_chanctx_switch *vifs,
4021 enum ieee80211_chanctx_switch_mode mode)
4023 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4026 /* we only support a single-vif right now */
4031 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4032 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4034 case CHANCTX_SWMODE_REASSIGN_VIF:
4035 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4045 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4047 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4049 return mvm->ibss_manager;
4052 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4053 struct ieee80211_sta *sta,
4056 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4057 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4059 if (!mvm_sta || !mvm_sta->vif) {
4060 IWL_ERR(mvm, "Station is not associated to a vif\n");
4064 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4067 #ifdef CONFIG_NL80211_TESTMODE
4068 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4069 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4070 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4071 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4074 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4075 struct ieee80211_vif *vif,
4076 void *data, int len)
4078 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4082 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4087 if (!tb[IWL_MVM_TM_ATTR_CMD])
4090 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4091 case IWL_MVM_TM_CMD_SET_NOA:
4092 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4093 !vif->bss_conf.enable_beacon ||
4094 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4097 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4098 if (noa_duration >= vif->bss_conf.beacon_int)
4101 mvm->noa_duration = noa_duration;
4104 return iwl_mvm_update_quotas(mvm, true, NULL);
4105 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4106 /* must be associated client vif - ignore authorized */
4107 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4108 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4109 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4112 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4113 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4114 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4120 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4121 struct ieee80211_vif *vif,
4122 void *data, int len)
4124 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4127 mutex_lock(&mvm->mutex);
4128 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4129 mutex_unlock(&mvm->mutex);
4135 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4136 struct ieee80211_vif *vif,
4137 struct ieee80211_channel_switch *chsw)
4139 /* By implementing this operation, we prevent mac80211 from
4140 * starting its own channel switch timer, so that we can call
4141 * ieee80211_chswitch_done() ourselves at the right time
4142 * (which is when the absence time event starts).
4145 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4146 "dummy channel switch op\n");
4149 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4150 struct ieee80211_vif *vif,
4151 struct ieee80211_channel_switch *chsw)
4153 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4154 struct ieee80211_vif *csa_vif;
4155 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4159 mutex_lock(&mvm->mutex);
4161 mvmvif->csa_failed = false;
4163 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4164 chsw->chandef.center_freq1);
4166 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4167 ieee80211_vif_to_wdev(vif),
4168 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4170 switch (vif->type) {
4171 case NL80211_IFTYPE_AP:
4173 rcu_dereference_protected(mvm->csa_vif,
4174 lockdep_is_held(&mvm->mutex));
4175 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4176 "Another CSA is already in progress")) {
4181 /* we still didn't unblock tx. prevent new CS meanwhile */
4182 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4183 lockdep_is_held(&mvm->mutex))) {
4188 rcu_assign_pointer(mvm->csa_vif, vif);
4190 if (WARN_ONCE(mvmvif->csa_countdown,
4191 "Previous CSA countdown didn't complete")) {
4196 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4199 case NL80211_IFTYPE_STATION:
4200 /* Schedule the time event to a bit before beacon 1,
4201 * to make sure we're in the new channel when the
4202 * GO/AP arrives. In case count <= 1 immediately schedule the
4203 * TE (this might result with some packet loss or connection
4206 if (chsw->count <= 1)
4209 apply_time = chsw->device_timestamp +
4210 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4211 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4214 iwl_mvm_csa_client_absent(mvm, vif);
4216 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4218 if (mvmvif->bf_data.bf_enabled) {
4219 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4229 mvmvif->ps_disabled = true;
4231 ret = iwl_mvm_power_update_ps(mvm);
4235 /* we won't be on this channel any longer */
4236 iwl_mvm_teardown_tdls_peers(mvm);
4239 mutex_unlock(&mvm->mutex);
4244 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4245 struct ieee80211_vif *vif)
4247 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4248 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4251 mutex_lock(&mvm->mutex);
4253 if (mvmvif->csa_failed) {
4254 mvmvif->csa_failed = false;
4259 if (vif->type == NL80211_IFTYPE_STATION) {
4260 struct iwl_mvm_sta *mvmsta;
4262 mvmvif->csa_bcn_pending = false;
4263 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4266 if (WARN_ON(!mvmsta)) {
4271 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4273 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4275 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4279 iwl_mvm_stop_session_protection(mvm, vif);
4282 mvmvif->ps_disabled = false;
4284 ret = iwl_mvm_power_update_ps(mvm);
4287 mutex_unlock(&mvm->mutex);
4292 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4296 if (!iwl_mvm_has_new_tx_api(mvm)) {
4298 mutex_lock(&mvm->mutex);
4299 iwl_mvm_flush_tx_path(mvm,
4300 iwl_mvm_flushable_queues(mvm) & queues, 0);
4301 mutex_unlock(&mvm->mutex);
4303 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4308 mutex_lock(&mvm->mutex);
4309 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4310 struct ieee80211_sta *sta;
4312 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4313 lockdep_is_held(&mvm->mutex));
4314 if (IS_ERR_OR_NULL(sta))
4318 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4320 iwl_mvm_wait_sta_queues_empty(mvm,
4321 iwl_mvm_sta_from_mac80211(sta));
4323 mutex_unlock(&mvm->mutex);
4326 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4327 struct ieee80211_vif *vif, u32 queues, bool drop)
4329 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4330 struct iwl_mvm_vif *mvmvif;
4331 struct iwl_mvm_sta *mvmsta;
4332 struct ieee80211_sta *sta;
4337 iwl_mvm_flush_no_vif(mvm, queues, drop);
4341 if (vif->type != NL80211_IFTYPE_STATION)
4344 /* Make sure we're done with the deferred traffic before flushing */
4345 flush_work(&mvm->add_stream_wk);
4347 mutex_lock(&mvm->mutex);
4348 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4350 /* flush the AP-station and all TDLS peers */
4351 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4352 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4353 lockdep_is_held(&mvm->mutex));
4354 if (IS_ERR_OR_NULL(sta))
4357 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4358 if (mvmsta->vif != vif)
4361 /* make sure only TDLS peers or the AP are flushed */
4362 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4365 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4366 IWL_ERR(mvm, "flush request fail\n");
4368 msk |= mvmsta->tfd_queue_msk;
4369 if (iwl_mvm_has_new_tx_api(mvm))
4370 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4374 mutex_unlock(&mvm->mutex);
4376 /* this can take a while, and we may need/want other operations
4377 * to succeed while doing this, so do it without the mutex held
4379 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4380 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4383 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4384 struct survey_info *survey)
4386 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4389 memset(survey, 0, sizeof(*survey));
4391 /* only support global statistics right now */
4395 if (!fw_has_capa(&mvm->fw->ucode_capa,
4396 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4399 mutex_lock(&mvm->mutex);
4401 if (iwl_mvm_firmware_running(mvm)) {
4402 ret = iwl_mvm_request_statistics(mvm, false);
4407 survey->filled = SURVEY_INFO_TIME |
4408 SURVEY_INFO_TIME_RX |
4409 SURVEY_INFO_TIME_TX |
4410 SURVEY_INFO_TIME_SCAN;
4411 survey->time = mvm->accu_radio_stats.on_time_rf +
4412 mvm->radio_stats.on_time_rf;
4413 do_div(survey->time, USEC_PER_MSEC);
4415 survey->time_rx = mvm->accu_radio_stats.rx_time +
4416 mvm->radio_stats.rx_time;
4417 do_div(survey->time_rx, USEC_PER_MSEC);
4419 survey->time_tx = mvm->accu_radio_stats.tx_time +
4420 mvm->radio_stats.tx_time;
4421 do_div(survey->time_tx, USEC_PER_MSEC);
4423 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4424 mvm->radio_stats.on_time_scan;
4425 do_div(survey->time_scan, USEC_PER_MSEC);
4429 mutex_unlock(&mvm->mutex);
4433 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4434 struct ieee80211_vif *vif,
4435 struct ieee80211_sta *sta,
4436 struct station_info *sinfo)
4438 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4439 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4440 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4442 if (mvmsta->avg_energy) {
4443 sinfo->signal_avg = mvmsta->avg_energy;
4444 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4447 if (!fw_has_capa(&mvm->fw->ucode_capa,
4448 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4451 /* if beacon filtering isn't on mac80211 does it anyway */
4452 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4455 if (!vif->bss_conf.assoc)
4458 mutex_lock(&mvm->mutex);
4460 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4463 if (iwl_mvm_request_statistics(mvm, false))
4466 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4467 mvmvif->beacon_stats.accu_num_beacons;
4468 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4469 if (mvmvif->beacon_stats.avg_signal) {
4470 /* firmware only reports a value after RXing a few beacons */
4471 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4472 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4475 mutex_unlock(&mvm->mutex);
4478 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4479 struct ieee80211_vif *vif,
4480 const struct ieee80211_event *event)
4482 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4484 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4486 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4489 struct iwl_fw_dbg_trigger_tlv *trig;
4490 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4492 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4493 FW_DBG_TRIGGER_MLME);
4497 trig_mlme = (void *)trig->data;
4499 if (event->u.mlme.data == ASSOC_EVENT) {
4500 if (event->u.mlme.status == MLME_DENIED)
4501 CHECK_MLME_TRIGGER(stop_assoc_denied,
4502 "DENIED ASSOC: reason %d",
4503 event->u.mlme.reason);
4504 else if (event->u.mlme.status == MLME_TIMEOUT)
4505 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4507 } else if (event->u.mlme.data == AUTH_EVENT) {
4508 if (event->u.mlme.status == MLME_DENIED)
4509 CHECK_MLME_TRIGGER(stop_auth_denied,
4510 "DENIED AUTH: reason %d",
4511 event->u.mlme.reason);
4512 else if (event->u.mlme.status == MLME_TIMEOUT)
4513 CHECK_MLME_TRIGGER(stop_auth_timeout,
4515 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4516 CHECK_MLME_TRIGGER(stop_rx_deauth,
4517 "DEAUTH RX %d", event->u.mlme.reason);
4518 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4519 CHECK_MLME_TRIGGER(stop_tx_deauth,
4520 "DEAUTH TX %d", event->u.mlme.reason);
4522 #undef CHECK_MLME_TRIGGER
4525 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4526 struct ieee80211_vif *vif,
4527 const struct ieee80211_event *event)
4529 struct iwl_fw_dbg_trigger_tlv *trig;
4530 struct iwl_fw_dbg_trigger_ba *ba_trig;
4532 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4537 ba_trig = (void *)trig->data;
4539 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4542 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4543 "BAR received from %pM, tid %d, ssn %d",
4544 event->u.ba.sta->addr, event->u.ba.tid,
4548 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4549 struct ieee80211_vif *vif,
4550 const struct ieee80211_event *event)
4552 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4554 switch (event->type) {
4556 iwl_mvm_event_mlme_callback(mvm, vif, event);
4559 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4561 case BA_FRAME_TIMEOUT:
4562 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4570 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4571 struct iwl_mvm_internal_rxq_notif *notif,
4574 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4577 lockdep_assert_held(&mvm->mutex);
4579 if (!iwl_mvm_has_new_rx_api(mvm))
4582 notif->cookie = mvm->queue_sync_cookie;
4585 atomic_set(&mvm->queue_sync_counter,
4586 mvm->trans->num_rx_queues);
4588 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4590 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4595 ret = wait_event_timeout(mvm->rx_sync_waitq,
4596 atomic_read(&mvm->queue_sync_counter) == 0 ||
4597 iwl_mvm_is_radio_killed(mvm),
4599 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4603 atomic_set(&mvm->queue_sync_counter, 0);
4604 mvm->queue_sync_cookie++;
4607 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4610 struct iwl_mvm_internal_rxq_notif data = {
4611 .type = IWL_MVM_RXQ_EMPTY,
4615 mutex_lock(&mvm->mutex);
4616 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4617 mutex_unlock(&mvm->mutex);
4620 const struct ieee80211_ops iwl_mvm_hw_ops = {
4621 .tx = iwl_mvm_mac_tx,
4622 .ampdu_action = iwl_mvm_mac_ampdu_action,
4623 .start = iwl_mvm_mac_start,
4624 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4625 .stop = iwl_mvm_mac_stop,
4626 .add_interface = iwl_mvm_mac_add_interface,
4627 .remove_interface = iwl_mvm_mac_remove_interface,
4628 .config = iwl_mvm_mac_config,
4629 .prepare_multicast = iwl_mvm_prepare_multicast,
4630 .configure_filter = iwl_mvm_configure_filter,
4631 .config_iface_filter = iwl_mvm_config_iface_filter,
4632 .bss_info_changed = iwl_mvm_bss_info_changed,
4633 .hw_scan = iwl_mvm_mac_hw_scan,
4634 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4635 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4636 .sta_state = iwl_mvm_mac_sta_state,
4637 .sta_notify = iwl_mvm_mac_sta_notify,
4638 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4639 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4640 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4641 .sta_rc_update = iwl_mvm_sta_rc_update,
4642 .conf_tx = iwl_mvm_mac_conf_tx,
4643 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4644 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4645 .flush = iwl_mvm_mac_flush,
4646 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4647 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4648 .set_key = iwl_mvm_mac_set_key,
4649 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4650 .remain_on_channel = iwl_mvm_roc,
4651 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4652 .add_chanctx = iwl_mvm_add_chanctx,
4653 .remove_chanctx = iwl_mvm_remove_chanctx,
4654 .change_chanctx = iwl_mvm_change_chanctx,
4655 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4656 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4657 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4659 .start_ap = iwl_mvm_start_ap_ibss,
4660 .stop_ap = iwl_mvm_stop_ap_ibss,
4661 .join_ibss = iwl_mvm_start_ap_ibss,
4662 .leave_ibss = iwl_mvm_stop_ap_ibss,
4664 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4666 .set_tim = iwl_mvm_set_tim,
4668 .channel_switch = iwl_mvm_channel_switch,
4669 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4670 .post_channel_switch = iwl_mvm_post_channel_switch,
4672 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4673 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4674 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4676 .event_callback = iwl_mvm_mac_event_callback,
4678 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4680 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4682 #ifdef CONFIG_PM_SLEEP
4684 .suspend = iwl_mvm_suspend,
4685 .resume = iwl_mvm_resume,
4686 .set_wakeup = iwl_mvm_set_wakeup,
4687 .set_rekey_data = iwl_mvm_set_rekey_data,
4688 #if IS_ENABLED(CONFIG_IPV6)
4689 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4691 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4693 .get_survey = iwl_mvm_mac_get_survey,
4694 .sta_statistics = iwl_mvm_mac_sta_statistics,
4695 #ifdef CONFIG_IWLWIFI_DEBUGFS
4696 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,