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:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 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 u32 status = le32_to_cpu(resp->status);
307 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
308 status == MCC_RESP_ILLEGAL);
311 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
312 __le32_to_cpu(resp->n_channels),
314 __le16_to_cpu(resp->mcc),
315 __le16_to_cpu(resp->geo_info));
316 /* Store the return source id */
317 src_id = resp->source_id;
319 if (IS_ERR_OR_NULL(regd)) {
320 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
321 PTR_ERR_OR_ZERO(regd));
325 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
326 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
327 mvm->lar_regdom_set = true;
328 mvm->mcc_src = src_id;
334 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
337 struct ieee80211_regdomain *regd;
339 if (!iwl_mvm_is_lar_supported(mvm))
342 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
343 if (!IS_ERR_OR_NULL(regd)) {
344 /* only update the regulatory core if changed */
346 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
352 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
355 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
356 iwl_mvm_is_wifi_mcc_supported(mvm) ?
357 MCC_SOURCE_GET_CURRENT :
358 MCC_SOURCE_OLD_FW, changed);
361 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
363 enum iwl_mcc_source used_src;
364 struct ieee80211_regdomain *regd;
367 const struct ieee80211_regdomain *r =
368 rtnl_dereference(mvm->hw->wiphy->regd);
373 /* save the last source in case we overwrite it below */
374 used_src = mvm->mcc_src;
375 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
376 /* Notify the firmware we support wifi location updates */
377 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
378 if (!IS_ERR_OR_NULL(regd))
382 /* Now set our last stored MCC and source */
383 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
385 if (IS_ERR_OR_NULL(regd))
388 /* update cfg80211 if the regdomain was changed */
390 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
398 const static u8 he_if_types_ext_capa_sta[] = {
399 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
400 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
401 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
404 const static struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
406 .iftype = NL80211_IFTYPE_STATION,
407 .extended_capabilities = he_if_types_ext_capa_sta,
408 .extended_capabilities_mask = he_if_types_ext_capa_sta,
409 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
413 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
415 struct ieee80211_hw *hw = mvm->hw;
417 static const u32 mvm_ciphers[] = {
418 WLAN_CIPHER_SUITE_WEP40,
419 WLAN_CIPHER_SUITE_WEP104,
420 WLAN_CIPHER_SUITE_TKIP,
421 WLAN_CIPHER_SUITE_CCMP,
424 /* Tell mac80211 our characteristics */
425 ieee80211_hw_set(hw, SIGNAL_DBM);
426 ieee80211_hw_set(hw, SPECTRUM_MGMT);
427 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
428 ieee80211_hw_set(hw, QUEUE_CONTROL);
429 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
430 ieee80211_hw_set(hw, SUPPORTS_PS);
431 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
432 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
433 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
434 ieee80211_hw_set(hw, CONNECTION_MONITOR);
435 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
436 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
437 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
438 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
439 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
440 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
441 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
443 if (iwl_mvm_has_tlc_offload(mvm)) {
444 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
445 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
448 if (iwl_mvm_has_new_rx_api(mvm))
449 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
451 if (fw_has_capa(&mvm->fw->ucode_capa,
452 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
453 ieee80211_hw_set(hw, AP_LINK_PS);
454 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
456 * we absolutely need this for the new TX API since that comes
457 * with many more queues than the current code can deal with
458 * for station powersave
463 if (mvm->trans->num_rx_queues > 1)
464 ieee80211_hw_set(hw, USES_RSS);
466 if (mvm->trans->max_skb_frags)
467 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
469 hw->queues = IEEE80211_MAX_QUEUES;
470 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
471 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
472 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
473 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
474 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
476 hw->radiotap_timestamp.units_pos =
477 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
478 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
479 /* this is the case for CCK frames, it's better (only 8) for OFDM */
480 hw->radiotap_timestamp.accuracy = 22;
482 if (!iwl_mvm_has_tlc_offload(mvm))
483 hw->rate_control_algorithm = RS_NAME;
485 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
486 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
488 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
489 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
490 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
491 hw->wiphy->cipher_suites = mvm->ciphers;
493 if (iwl_mvm_has_new_rx_api(mvm)) {
494 mvm->ciphers[hw->wiphy->n_cipher_suites] =
495 WLAN_CIPHER_SUITE_GCMP;
496 hw->wiphy->n_cipher_suites++;
497 mvm->ciphers[hw->wiphy->n_cipher_suites] =
498 WLAN_CIPHER_SUITE_GCMP_256;
499 hw->wiphy->n_cipher_suites++;
502 /* Enable 11w if software crypto is not enabled (as the
503 * firmware will interpret some mgmt packets, so enabling it
504 * with software crypto isn't safe).
506 if (!iwlwifi_mod_params.swcrypto) {
507 ieee80211_hw_set(hw, MFP_CAPABLE);
508 mvm->ciphers[hw->wiphy->n_cipher_suites] =
509 WLAN_CIPHER_SUITE_AES_CMAC;
510 hw->wiphy->n_cipher_suites++;
511 if (iwl_mvm_has_new_rx_api(mvm)) {
512 mvm->ciphers[hw->wiphy->n_cipher_suites] =
513 WLAN_CIPHER_SUITE_BIP_GMAC_128;
514 hw->wiphy->n_cipher_suites++;
515 mvm->ciphers[hw->wiphy->n_cipher_suites] =
516 WLAN_CIPHER_SUITE_BIP_GMAC_256;
517 hw->wiphy->n_cipher_suites++;
521 /* currently FW API supports only one optional cipher scheme */
522 if (mvm->fw->cs[0].cipher) {
523 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
524 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
526 mvm->hw->n_cipher_schemes = 1;
528 cs->cipher = le32_to_cpu(fwcs->cipher);
529 cs->iftype = BIT(NL80211_IFTYPE_STATION);
530 cs->hdr_len = fwcs->hdr_len;
531 cs->pn_len = fwcs->pn_len;
532 cs->pn_off = fwcs->pn_off;
533 cs->key_idx_off = fwcs->key_idx_off;
534 cs->key_idx_mask = fwcs->key_idx_mask;
535 cs->key_idx_shift = fwcs->key_idx_shift;
536 cs->mic_len = fwcs->mic_len;
538 mvm->hw->cipher_schemes = mvm->cs;
539 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
540 hw->wiphy->n_cipher_suites++;
543 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
544 hw->wiphy->features |=
545 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
546 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
547 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
549 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
550 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
551 hw->chanctx_data_size = sizeof(u16);
553 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
554 BIT(NL80211_IFTYPE_P2P_CLIENT) |
555 BIT(NL80211_IFTYPE_AP) |
556 BIT(NL80211_IFTYPE_P2P_GO) |
557 BIT(NL80211_IFTYPE_P2P_DEVICE) |
558 BIT(NL80211_IFTYPE_ADHOC);
560 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
561 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
562 if (iwl_mvm_is_lar_supported(mvm))
563 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
565 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
566 REGULATORY_DISABLE_BEACON_HINTS;
568 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
569 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
571 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
572 hw->wiphy->n_iface_combinations =
573 ARRAY_SIZE(iwl_mvm_iface_combinations);
575 hw->wiphy->max_remain_on_channel_duration = 10000;
576 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
578 /* Extract MAC address */
579 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
580 hw->wiphy->addresses = mvm->addresses;
581 hw->wiphy->n_addresses = 1;
583 /* Extract additional MAC addresses if available */
584 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
585 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
587 for (i = 1; i < num_mac; i++) {
588 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
590 mvm->addresses[i].addr[5]++;
591 hw->wiphy->n_addresses++;
594 iwl_mvm_reset_phy_ctxts(mvm);
596 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
598 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
600 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
601 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
602 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
604 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
605 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
607 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
609 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
610 hw->wiphy->bands[NL80211_BAND_2GHZ] =
611 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
612 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
613 hw->wiphy->bands[NL80211_BAND_5GHZ] =
614 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
616 if (fw_has_capa(&mvm->fw->ucode_capa,
617 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
618 fw_has_api(&mvm->fw->ucode_capa,
619 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
620 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
621 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
624 hw->wiphy->hw_version = mvm->trans->hw_id;
626 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
627 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
629 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
631 hw->wiphy->max_sched_scan_reqs = 1;
632 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
633 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
634 /* we create the 802.11 header and zero length SSID IE. */
635 hw->wiphy->max_sched_scan_ie_len =
636 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
637 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
638 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
641 * the firmware uses u8 for num of iterations, but 0xff is saved for
642 * infinite loop, so the maximum number of iterations is actually 254.
644 hw->wiphy->max_sched_scan_plan_iterations = 254;
646 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
647 NL80211_FEATURE_LOW_PRIORITY_SCAN |
648 NL80211_FEATURE_P2P_GO_OPPPS |
649 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
650 NL80211_FEATURE_DYNAMIC_SMPS |
651 NL80211_FEATURE_STATIC_SMPS |
652 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
654 if (fw_has_capa(&mvm->fw->ucode_capa,
655 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
656 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
657 if (fw_has_capa(&mvm->fw->ucode_capa,
658 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
659 hw->wiphy->features |= NL80211_FEATURE_QUIET;
661 if (fw_has_capa(&mvm->fw->ucode_capa,
662 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
663 hw->wiphy->features |=
664 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
666 if (fw_has_capa(&mvm->fw->ucode_capa,
667 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
668 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
670 if (fw_has_api(&mvm->fw->ucode_capa,
671 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
672 wiphy_ext_feature_set(hw->wiphy,
673 NL80211_EXT_FEATURE_SCAN_START_TIME);
674 wiphy_ext_feature_set(hw->wiphy,
675 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
676 wiphy_ext_feature_set(hw->wiphy,
677 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
680 if (iwl_mvm_is_oce_supported(mvm)) {
681 wiphy_ext_feature_set(hw->wiphy,
682 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
683 wiphy_ext_feature_set(hw->wiphy,
684 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
685 wiphy_ext_feature_set(hw->wiphy,
686 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
687 wiphy_ext_feature_set(hw->wiphy,
688 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
691 if (mvm->nvm_data->sku_cap_11ax_enable &&
692 !iwlwifi_mod_params.disable_11ax) {
693 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
694 hw->wiphy->num_iftype_ext_capab =
695 ARRAY_SIZE(he_iftypes_ext_capa);
698 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
700 #ifdef CONFIG_PM_SLEEP
701 if (iwl_mvm_is_d0i3_supported(mvm) &&
702 device_can_wakeup(mvm->trans->dev)) {
703 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
704 hw->wiphy->wowlan = &mvm->wowlan;
707 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
708 mvm->trans->ops->d3_suspend &&
709 mvm->trans->ops->d3_resume &&
710 device_can_wakeup(mvm->trans->dev)) {
711 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
712 WIPHY_WOWLAN_DISCONNECT |
713 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
714 WIPHY_WOWLAN_RFKILL_RELEASE |
715 WIPHY_WOWLAN_NET_DETECT;
716 if (!iwlwifi_mod_params.swcrypto)
717 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
718 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
719 WIPHY_WOWLAN_4WAY_HANDSHAKE;
721 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
722 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
723 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
724 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
725 hw->wiphy->wowlan = &mvm->wowlan;
729 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
730 /* assign default bcast filtering configuration */
731 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
734 ret = iwl_mvm_leds_init(mvm);
738 if (fw_has_capa(&mvm->fw->ucode_capa,
739 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
740 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
741 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
742 ieee80211_hw_set(hw, TDLS_WIDER_BW);
745 if (fw_has_capa(&mvm->fw->ucode_capa,
746 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
747 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
748 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
751 hw->netdev_features |= mvm->cfg->features;
752 if (!iwl_mvm_is_csum_supported(mvm)) {
753 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
755 /* We may support SW TX CSUM */
756 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
757 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
760 ret = ieee80211_register_hw(mvm->hw);
762 iwl_mvm_leds_exit(mvm);
763 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
765 if (mvm->cfg->vht_mu_mimo_supported)
766 wiphy_ext_feature_set(hw->wiphy,
767 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
772 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
773 struct ieee80211_sta *sta,
776 struct iwl_mvm_sta *mvmsta;
780 * double check the IN_D0I3 flag both before and after
781 * taking the spinlock, in order to prevent taking
782 * the spinlock when not needed.
784 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
787 spin_lock(&mvm->d0i3_tx_lock);
789 * testing the flag again ensures the skb dequeue
790 * loop (on d0i3 exit) hasn't run yet.
792 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
795 mvmsta = iwl_mvm_sta_from_mac80211(sta);
796 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
797 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
800 __skb_queue_tail(&mvm->d0i3_tx, skb);
801 ieee80211_stop_queues(mvm->hw);
804 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
805 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
809 spin_unlock(&mvm->d0i3_tx_lock);
813 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
814 struct ieee80211_tx_control *control,
817 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
818 struct ieee80211_sta *sta = control->sta;
819 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
820 struct ieee80211_hdr *hdr = (void *)skb->data;
822 if (iwl_mvm_is_radio_killed(mvm)) {
823 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
827 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
828 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
829 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
832 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
833 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
834 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
835 ieee80211_is_mgmt(hdr->frame_control) &&
836 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
839 /* If there is no sta, and it's not offchannel - send through AP */
840 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
841 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
842 struct iwl_mvm_vif *mvmvif =
843 iwl_mvm_vif_from_mac80211(info->control.vif);
844 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
846 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
847 /* mac80211 holds rcu read lock */
848 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
849 if (IS_ERR_OR_NULL(sta))
855 if (iwl_mvm_defer_tx(mvm, sta, skb))
857 if (iwl_mvm_tx_skb(mvm, skb, sta))
862 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
866 ieee80211_free_txskb(hw, skb);
869 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
871 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
876 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
878 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
880 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
883 /* enabled by default */
887 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
889 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
891 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
895 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
896 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
897 enum ieee80211_ampdu_mlme_action action)
899 struct iwl_fw_dbg_trigger_tlv *trig;
900 struct iwl_fw_dbg_trigger_ba *ba_trig;
902 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
907 ba_trig = (void *)trig->data;
910 case IEEE80211_AMPDU_TX_OPERATIONAL: {
911 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
912 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
914 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
915 "TX AGG START: MAC %pM tid %d ssn %d\n",
916 sta->addr, tid, tid_data->ssn);
919 case IEEE80211_AMPDU_TX_STOP_CONT:
920 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
921 "TX AGG STOP: MAC %pM tid %d\n",
924 case IEEE80211_AMPDU_RX_START:
925 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
926 "RX AGG START: MAC %pM tid %d ssn %d\n",
927 sta->addr, tid, rx_ba_ssn);
929 case IEEE80211_AMPDU_RX_STOP:
930 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
931 "RX AGG STOP: MAC %pM tid %d\n",
939 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
940 struct ieee80211_vif *vif,
941 struct ieee80211_ampdu_params *params)
943 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
945 bool tx_agg_ref = false;
946 struct ieee80211_sta *sta = params->sta;
947 enum ieee80211_ampdu_mlme_action action = params->action;
948 u16 tid = params->tid;
949 u16 *ssn = ¶ms->ssn;
950 u16 buf_size = params->buf_size;
951 bool amsdu = params->amsdu;
952 u16 timeout = params->timeout;
954 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
955 sta->addr, tid, action);
957 if (!(mvm->nvm_data->sku_cap_11n_enable))
960 /* return from D0i3 before starting a new Tx aggregation */
962 case IEEE80211_AMPDU_TX_START:
963 case IEEE80211_AMPDU_TX_STOP_CONT:
964 case IEEE80211_AMPDU_TX_STOP_FLUSH:
965 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
966 case IEEE80211_AMPDU_TX_OPERATIONAL:
968 * for tx start, wait synchronously until D0i3 exit to
969 * get the correct sequence number for the tid.
970 * additionally, some other ampdu actions use direct
971 * target access, which is not handled automatically
972 * by the trans layer (unlike commands), so wait for
973 * d0i3 exit in these cases as well.
975 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
985 mutex_lock(&mvm->mutex);
988 case IEEE80211_AMPDU_RX_START:
989 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
990 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
991 struct iwl_mvm_vif *mvmvif;
992 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
993 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
995 mdata->opened_rx_ba_sessions = true;
996 mvmvif = iwl_mvm_vif_from_mac80211(vif);
997 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
999 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
1003 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1006 case IEEE80211_AMPDU_RX_STOP:
1007 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1010 case IEEE80211_AMPDU_TX_START:
1011 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
1015 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1017 case IEEE80211_AMPDU_TX_STOP_CONT:
1018 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1020 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1021 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1022 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1024 case IEEE80211_AMPDU_TX_OPERATIONAL:
1025 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1037 if (action == IEEE80211_AMPDU_RX_START)
1040 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1043 mutex_unlock(&mvm->mutex);
1046 * If the tid is marked as started, we won't use it for offloaded
1047 * traffic on the next D0i3 entry. It's safe to unref.
1050 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1055 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1056 struct ieee80211_vif *vif)
1058 struct iwl_mvm *mvm = data;
1059 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1061 mvmvif->uploaded = false;
1062 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1064 spin_lock_bh(&mvm->time_event_lock);
1065 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1066 spin_unlock_bh(&mvm->time_event_lock);
1068 mvmvif->phy_ctxt = NULL;
1069 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1070 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1073 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1075 /* clear the D3 reconfig, we only need it to avoid dumping a
1076 * firmware coredump on reconfiguration, we shouldn't do that
1077 * on D3->D0 transition
1079 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1080 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1081 iwl_fw_error_dump(&mvm->fwrt);
1084 /* cleanup all stale references (scan, roc), but keep the
1085 * ucode_down ref until reconfig is complete
1087 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1089 iwl_mvm_stop_device(mvm);
1091 mvm->scan_status = 0;
1092 mvm->ps_disabled = false;
1093 mvm->calibrating = false;
1095 /* just in case one was running */
1096 iwl_mvm_cleanup_roc_te(mvm);
1097 ieee80211_remain_on_channel_expired(mvm->hw);
1100 * cleanup all interfaces, even inactive ones, as some might have
1101 * gone down during the HW restart
1103 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1105 mvm->p2p_device_vif = NULL;
1106 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1108 iwl_mvm_reset_phy_ctxts(mvm);
1109 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1110 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1111 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1112 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1114 ieee80211_wake_queues(mvm->hw);
1116 /* clear any stale d0i3 state */
1117 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1120 mvm->rx_ba_sessions = 0;
1121 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1122 mvm->monitor_on = false;
1124 /* keep statistics ticking */
1125 iwl_mvm_accu_radio_stats(mvm);
1128 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1132 lockdep_assert_held(&mvm->mutex);
1134 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1136 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1137 * so later code will - from now on - see that we're doing it.
1139 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1140 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1141 /* Clean up some internal and mac80211 state on restart */
1142 iwl_mvm_restart_cleanup(mvm);
1144 /* Hold the reference to prevent runtime suspend while
1145 * the start procedure runs. It's a bit confusing
1146 * that the UCODE_DOWN reference is taken, but it just
1147 * means "UCODE is not UP yet". ( TODO: rename this
1150 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1152 ret = iwl_mvm_up(mvm);
1154 iwl_fw_dbg_apply_point(&mvm->fwrt, IWL_FW_INI_APPLY_POST_INIT);
1156 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1157 /* Something went wrong - we need to finish some cleanup
1158 * that normally iwl_mvm_mac_restart_complete() below
1161 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1163 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1170 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1172 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1175 /* Some hw restart cleanups must not hold the mutex */
1176 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1178 * Make sure we are out of d0i3. This is needed
1179 * to make sure the reference accounting is correct
1180 * (and there is no stale d0i3_exit_work).
1182 wait_event_timeout(mvm->d0i3_exit_waitq,
1183 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1188 mutex_lock(&mvm->mutex);
1189 ret = __iwl_mvm_mac_start(mvm);
1190 mutex_unlock(&mvm->mutex);
1195 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1199 mutex_lock(&mvm->mutex);
1201 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1203 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1205 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1207 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1210 /* allow transport/FW low power modes */
1211 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1214 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1215 * of packets the FW sent out, so we must reconnect.
1217 iwl_mvm_teardown_tdls_peers(mvm);
1219 mutex_unlock(&mvm->mutex);
1222 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1224 if (iwl_mvm_is_d0i3_supported(mvm) &&
1225 iwl_mvm_enter_d0i3_on_suspend(mvm))
1226 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1227 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1230 "D0i3 exit on resume timed out\n");
1234 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1235 enum ieee80211_reconfig_type reconfig_type)
1237 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1239 switch (reconfig_type) {
1240 case IEEE80211_RECONFIG_TYPE_RESTART:
1241 iwl_mvm_restart_complete(mvm);
1243 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1244 iwl_mvm_resume_complete(mvm);
1249 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1251 lockdep_assert_held(&mvm->mutex);
1253 /* firmware counters are obviously reset now, but we shouldn't
1254 * partially track so also clear the fw_reset_accu counters.
1256 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1258 /* async_handlers_wk is now blocked */
1261 * The work item could be running or queued if the
1262 * ROC time event stops just as we get here.
1264 flush_work(&mvm->roc_done_wk);
1266 iwl_mvm_stop_device(mvm);
1268 iwl_mvm_async_handlers_purge(mvm);
1269 /* async_handlers_list is empty and will stay empty: HW is stopped */
1271 /* the fw is stopped, the aux sta is dead: clean up driver state */
1272 iwl_mvm_del_aux_sta(mvm);
1275 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1276 * hw (as restart_complete() won't be called in this case) and mac80211
1277 * won't execute the restart.
1278 * But make sure to cleanup interfaces that have gone down before/during
1279 * HW restart was requested.
1281 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1282 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1284 ieee80211_iterate_interfaces(mvm->hw, 0,
1285 iwl_mvm_cleanup_iterator, mvm);
1287 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1288 * make sure there's nothing left there and warn if any is found.
1290 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1293 for (i = 0; i < mvm->max_scans; i++) {
1294 if (WARN_ONCE(mvm->scan_uid_status[i],
1295 "UMAC scan UID %d status was not cleaned\n",
1297 mvm->scan_uid_status[i] = 0;
1302 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1304 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1306 flush_work(&mvm->d0i3_exit_work);
1307 flush_work(&mvm->async_handlers_wk);
1308 flush_work(&mvm->add_stream_wk);
1311 * Lock and clear the firmware running bit here already, so that
1312 * new commands coming in elsewhere, e.g. from debugfs, will not
1313 * be able to proceed. This is important here because one of those
1314 * debugfs files causes the firmware dump to be triggered, and if we
1315 * don't stop debugfs accesses before canceling that it could be
1316 * retriggered after we flush it but before we've cleared the bit.
1318 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1320 iwl_fw_cancel_dump(&mvm->fwrt);
1321 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1322 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1323 iwl_fw_free_dump_desc(&mvm->fwrt);
1325 mutex_lock(&mvm->mutex);
1326 __iwl_mvm_mac_stop(mvm);
1327 mutex_unlock(&mvm->mutex);
1330 * The worker might have been waiting for the mutex, let it run and
1331 * discover that its list is now empty.
1333 cancel_work_sync(&mvm->async_handlers_wk);
1336 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1340 lockdep_assert_held(&mvm->mutex);
1342 for (i = 0; i < NUM_PHY_CTX; i++)
1343 if (!mvm->phy_ctxts[i].ref)
1344 return &mvm->phy_ctxts[i];
1346 IWL_ERR(mvm, "No available PHY context\n");
1350 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1355 struct iwl_dev_tx_power_cmd v5;
1356 struct iwl_dev_tx_power_cmd_v4 v4;
1358 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1359 .v5.v3.mac_context_id =
1360 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1361 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1364 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1365 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1367 if (fw_has_api(&mvm->fw->ucode_capa,
1368 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1369 len = sizeof(cmd.v5);
1370 else if (fw_has_capa(&mvm->fw->ucode_capa,
1371 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1372 len = sizeof(cmd.v4);
1374 len = sizeof(cmd.v4.v3);
1376 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1379 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1380 struct ieee80211_vif *vif)
1382 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1383 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1387 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1390 * make sure D0i3 exit is completed, otherwise a target access
1391 * during tx queue configuration could be done when still in
1394 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1399 * Not much to do here. The stack will not allow interface
1400 * types or combinations that we didn't advertise, so we
1401 * don't really have to check the types.
1404 mutex_lock(&mvm->mutex);
1406 /* make sure that beacon statistics don't go backwards with FW reset */
1407 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1408 mvmvif->beacon_stats.accu_num_beacons +=
1409 mvmvif->beacon_stats.num_beacons;
1411 /* Allocate resources for the MAC context, and add it to the fw */
1412 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1416 /* Counting number of interfaces is needed for legacy PM */
1417 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1421 * The AP binding flow can be done only after the beacon
1422 * template is configured (which happens only in the mac80211
1423 * start_ap() flow), and adding the broadcast station can happen
1424 * only after the binding.
1425 * In addition, since modifying the MAC before adding a bcast
1426 * station is not allowed by the FW, delay the adding of MAC context to
1427 * the point where we can also add the bcast station.
1428 * In short: there's not much we can do at this point, other than
1429 * allocating resources :)
1431 if (vif->type == NL80211_IFTYPE_AP ||
1432 vif->type == NL80211_IFTYPE_ADHOC) {
1433 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1435 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1440 * Only queue for this station is the mcast queue,
1441 * which shouldn't be in TFD mask anyway
1443 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1449 iwl_mvm_vif_dbgfs_register(mvm, vif);
1453 mvmvif->features |= hw->netdev_features;
1455 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1459 ret = iwl_mvm_power_update_mac(mvm);
1461 goto out_remove_mac;
1463 /* beacon filtering */
1464 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1466 goto out_remove_mac;
1468 if (!mvm->bf_allowed_vif &&
1469 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1470 mvm->bf_allowed_vif = mvmvif;
1471 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1472 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1476 * P2P_DEVICE interface does not have a channel context assigned to it,
1477 * so a dedicated PHY context is allocated to it and the corresponding
1478 * MAC context is bound to it at this stage.
1480 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1482 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1483 if (!mvmvif->phy_ctxt) {
1488 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1489 ret = iwl_mvm_binding_add_vif(mvm, vif);
1493 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1497 /* Save a pointer to p2p device vif, so it can later be used to
1498 * update the p2p device MAC when a GO is started/stopped */
1499 mvm->p2p_device_vif = vif;
1502 iwl_mvm_tcm_add_vif(mvm, vif);
1504 if (vif->type == NL80211_IFTYPE_MONITOR)
1505 mvm->monitor_on = true;
1507 iwl_mvm_vif_dbgfs_register(mvm, vif);
1511 iwl_mvm_binding_remove_vif(mvm, vif);
1513 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1515 if (mvm->bf_allowed_vif == mvmvif) {
1516 mvm->bf_allowed_vif = NULL;
1517 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1518 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1521 mvmvif->phy_ctxt = NULL;
1522 iwl_mvm_mac_ctxt_remove(mvm, vif);
1524 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1527 mutex_unlock(&mvm->mutex);
1529 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1534 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1535 struct ieee80211_vif *vif)
1537 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1539 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1540 * We assume here that all the packets sent to the OFFCHANNEL
1541 * queue are sent in ROC session.
1543 flush_work(&mvm->roc_done_wk);
1547 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1548 struct ieee80211_vif *vif)
1550 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1551 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1552 struct iwl_probe_resp_data *probe_data;
1554 iwl_mvm_prepare_mac_removal(mvm, vif);
1556 if (!(vif->type == NL80211_IFTYPE_AP ||
1557 vif->type == NL80211_IFTYPE_ADHOC))
1558 iwl_mvm_tcm_rm_vif(mvm, vif);
1560 mutex_lock(&mvm->mutex);
1562 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1563 lockdep_is_held(&mvm->mutex));
1564 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1566 kfree_rcu(probe_data, rcu_head);
1568 if (mvm->bf_allowed_vif == mvmvif) {
1569 mvm->bf_allowed_vif = NULL;
1570 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1571 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1574 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1577 * For AP/GO interface, the tear down of the resources allocated to the
1578 * interface is be handled as part of the stop_ap flow.
1580 if (vif->type == NL80211_IFTYPE_AP ||
1581 vif->type == NL80211_IFTYPE_ADHOC) {
1582 #ifdef CONFIG_NL80211_TESTMODE
1583 if (vif == mvm->noa_vif) {
1584 mvm->noa_vif = NULL;
1585 mvm->noa_duration = 0;
1588 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1589 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1593 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1594 mvm->p2p_device_vif = NULL;
1595 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1596 iwl_mvm_binding_remove_vif(mvm, vif);
1597 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1598 mvmvif->phy_ctxt = NULL;
1601 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1604 iwl_mvm_power_update_mac(mvm);
1605 iwl_mvm_mac_ctxt_remove(mvm, vif);
1607 if (vif->type == NL80211_IFTYPE_MONITOR)
1608 mvm->monitor_on = false;
1611 mutex_unlock(&mvm->mutex);
1614 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1619 struct iwl_mvm_mc_iter_data {
1620 struct iwl_mvm *mvm;
1624 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1625 struct ieee80211_vif *vif)
1627 struct iwl_mvm_mc_iter_data *data = _data;
1628 struct iwl_mvm *mvm = data->mvm;
1629 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1630 struct iwl_host_cmd hcmd = {
1631 .id = MCAST_FILTER_CMD,
1633 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1637 /* if we don't have free ports, mcast frames will be dropped */
1638 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1641 if (vif->type != NL80211_IFTYPE_STATION ||
1642 !vif->bss_conf.assoc)
1645 cmd->port_id = data->port_id++;
1646 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1647 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1652 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1654 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1657 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1659 struct iwl_mvm_mc_iter_data iter_data = {
1663 lockdep_assert_held(&mvm->mutex);
1665 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1668 ieee80211_iterate_active_interfaces_atomic(
1669 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1670 iwl_mvm_mc_iface_iterator, &iter_data);
1673 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1674 struct netdev_hw_addr_list *mc_list)
1676 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1677 struct iwl_mcast_filter_cmd *cmd;
1678 struct netdev_hw_addr *addr;
1683 addr_count = netdev_hw_addr_list_count(mc_list);
1684 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1685 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1689 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1690 cmd = kzalloc(len, GFP_ATOMIC);
1696 return (u64)(unsigned long)cmd;
1699 netdev_hw_addr_list_for_each(addr, mc_list) {
1700 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1701 cmd->count, addr->addr);
1702 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1703 addr->addr, ETH_ALEN);
1707 return (u64)(unsigned long)cmd;
1710 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1711 unsigned int changed_flags,
1712 unsigned int *total_flags,
1715 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1716 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1718 mutex_lock(&mvm->mutex);
1720 /* replace previous configuration */
1721 kfree(mvm->mcast_filter_cmd);
1722 mvm->mcast_filter_cmd = cmd;
1727 if (changed_flags & FIF_ALLMULTI)
1728 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1733 iwl_mvm_recalc_multicast(mvm);
1735 mutex_unlock(&mvm->mutex);
1739 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1740 struct ieee80211_vif *vif,
1741 unsigned int filter_flags,
1742 unsigned int changed_flags)
1744 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1746 /* We support only filter for probe requests */
1747 if (!(changed_flags & FIF_PROBE_REQ))
1750 /* Supported only for p2p client interfaces */
1751 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1755 mutex_lock(&mvm->mutex);
1756 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1757 mutex_unlock(&mvm->mutex);
1760 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1761 struct iwl_bcast_iter_data {
1762 struct iwl_mvm *mvm;
1763 struct iwl_bcast_filter_cmd *cmd;
1768 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1769 const struct iwl_fw_bcast_filter *in_filter,
1770 struct iwl_fw_bcast_filter *out_filter)
1772 struct iwl_fw_bcast_filter_attr *attr;
1775 memcpy(out_filter, in_filter, sizeof(*out_filter));
1777 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1778 attr = &out_filter->attrs[i];
1783 switch (attr->reserved1) {
1784 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1785 if (vif->bss_conf.arp_addr_cnt != 1) {
1790 attr->val = vif->bss_conf.arp_addr_list[0];
1792 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1793 attr->val = *(__be32 *)&vif->addr[2];
1798 attr->reserved1 = 0;
1799 out_filter->num_attrs++;
1803 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1804 struct ieee80211_vif *vif)
1806 struct iwl_bcast_iter_data *data = _data;
1807 struct iwl_mvm *mvm = data->mvm;
1808 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1809 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1810 struct iwl_fw_bcast_mac *bcast_mac;
1813 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1816 bcast_mac = &cmd->macs[mvmvif->id];
1819 * enable filtering only for associated stations, but not for P2P
1822 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1823 !vif->bss_conf.assoc)
1826 bcast_mac->default_discard = 1;
1828 /* copy all configured filters */
1829 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1831 * Make sure we don't exceed our filters limit.
1832 * if there is still a valid filter to be configured,
1833 * be on the safe side and just allow bcast for this mac.
1835 if (WARN_ON_ONCE(data->current_filter >=
1836 ARRAY_SIZE(cmd->filters))) {
1837 bcast_mac->default_discard = 0;
1838 bcast_mac->attached_filters = 0;
1842 iwl_mvm_set_bcast_filter(vif,
1843 &mvm->bcast_filters[i],
1844 &cmd->filters[data->current_filter]);
1846 /* skip current filter if it contains no attributes */
1847 if (!cmd->filters[data->current_filter].num_attrs)
1850 /* attach the filter to current mac */
1851 bcast_mac->attached_filters |=
1852 cpu_to_le16(BIT(data->current_filter));
1854 data->current_filter++;
1858 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1859 struct iwl_bcast_filter_cmd *cmd)
1861 struct iwl_bcast_iter_data iter_data = {
1866 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1869 memset(cmd, 0, sizeof(*cmd));
1870 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1871 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1873 #ifdef CONFIG_IWLWIFI_DEBUGFS
1874 /* use debugfs filters/macs if override is configured */
1875 if (mvm->dbgfs_bcast_filtering.override) {
1876 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1877 sizeof(cmd->filters));
1878 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1884 /* if no filters are configured, do nothing */
1885 if (!mvm->bcast_filters)
1888 /* configure and attach these filters for each associated sta vif */
1889 ieee80211_iterate_active_interfaces(
1890 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1891 iwl_mvm_bcast_filter_iterator, &iter_data);
1896 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1898 struct iwl_bcast_filter_cmd cmd;
1900 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1903 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1906 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1910 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1916 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1917 struct ieee80211_vif *vif)
1919 struct iwl_mu_group_mgmt_cmd cmd = {};
1921 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1922 WLAN_MEMBERSHIP_LEN);
1923 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1924 WLAN_USER_POSITION_LEN);
1926 return iwl_mvm_send_cmd_pdu(mvm,
1927 WIDE_ID(DATA_PATH_GROUP,
1928 UPDATE_MU_GROUPS_CMD),
1929 0, sizeof(cmd), &cmd);
1932 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1933 struct ieee80211_vif *vif)
1935 if (vif->mu_mimo_owner) {
1936 struct iwl_mu_group_mgmt_notif *notif = _data;
1939 * MU-MIMO Group Id action frame is little endian. We treat
1940 * the data received from firmware as if it came from the
1941 * action frame, so no conversion is needed.
1943 ieee80211_update_mu_groups(vif,
1944 (u8 *)¬if->membership_status,
1945 (u8 *)¬if->user_position);
1949 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1950 struct iwl_rx_cmd_buffer *rxb)
1952 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1953 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1955 ieee80211_iterate_active_interfaces_atomic(
1956 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1957 iwl_mvm_mu_mimo_iface_iterator, notif);
1960 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1962 u8 byte_num = ppe_pos_bit / 8;
1963 u8 bit_num = ppe_pos_bit % 8;
1968 return (ppe[byte_num] >> bit_num) &
1969 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1972 * If bit_num > 5, we have to combine bits with next byte.
1973 * Calculate how many bits we need to take from current byte (called
1974 * here "residue_bits"), and add them to bits from next byte.
1977 residue_bits = 8 - bit_num;
1979 res = (ppe[byte_num + 1] &
1980 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1982 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1987 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1988 struct ieee80211_vif *vif, u8 sta_id)
1990 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1991 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1993 .tid_limit = IWL_MAX_TID_COUNT,
1994 .bss_color = vif->bss_conf.bss_color,
1995 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1996 .frame_time_rts_th =
1997 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1999 struct ieee80211_sta *sta;
2005 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2008 WARN(1, "Can't find STA to configure HE\n");
2012 if (!sta->he_cap.has_he) {
2020 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2021 IEEE80211_HE_MAC_CAP0_HTC_HE)
2022 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2023 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2024 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2025 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2026 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2028 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2029 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2030 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2031 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2034 sta_ctxt_cmd.htc_flags |=
2035 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2036 else if (link_adap == 3)
2037 sta_ctxt_cmd.htc_flags |=
2038 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2040 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2041 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2042 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2043 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2044 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2045 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2046 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2049 * Initialize the PPE thresholds to "None" (7), as described in Table
2050 * 9-262ac of 80211.ax/D3.0.
2052 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2054 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2055 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2056 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2057 u8 nss = (sta->he_cap.ppe_thres[0] &
2058 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2059 u8 ru_index_bitmap =
2060 (sta->he_cap.ppe_thres[0] &
2061 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2062 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2063 u8 *ppe = &sta->he_cap.ppe_thres[0];
2064 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2067 * FW currently supports only nss == MAX_HE_SUPP_NSS
2069 * If nss > MAX: we can ignore values we don't support
2070 * If nss < MAX: we can set zeros in other streams
2072 if (nss > MAX_HE_SUPP_NSS) {
2073 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2075 nss = MAX_HE_SUPP_NSS;
2078 for (i = 0; i < nss; i++) {
2079 u8 ru_index_tmp = ru_index_bitmap << 1;
2082 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2084 if (!(ru_index_tmp & 1))
2087 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2088 iwl_mvm_he_get_ppe_val(ppe,
2091 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2092 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2093 iwl_mvm_he_get_ppe_val(ppe,
2096 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2100 flags |= STA_CTXT_HE_PACKET_EXT;
2104 /* Mark MU EDCA as enabled, unless none detected on some AC */
2105 flags |= STA_CTXT_HE_MU_EDCA_CW;
2106 for (i = 0; i < AC_NUM; i++) {
2107 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2108 &mvmvif->queue_params[i].mu_edca_param_rec;
2110 if (!mvmvif->queue_params[i].mu_edca) {
2111 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2115 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2116 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2117 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2118 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2119 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2120 cpu_to_le16(mu_edca->aifsn);
2121 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2122 cpu_to_le16(mu_edca->mu_edca_timer);
2125 if (vif->bss_conf.multi_sta_back_32bit)
2126 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2128 if (vif->bss_conf.ack_enabled)
2129 flags |= STA_CTXT_HE_ACK_ENABLED;
2131 if (vif->bss_conf.uora_exists) {
2132 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2134 sta_ctxt_cmd.rand_alloc_ecwmin =
2135 vif->bss_conf.uora_ocw_range & 0x7;
2136 sta_ctxt_cmd.rand_alloc_ecwmax =
2137 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2140 /* TODO: support Multi BSSID IE */
2142 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2144 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2145 DATA_PATH_GROUP, 0),
2146 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2147 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2150 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2151 struct ieee80211_vif *vif,
2152 struct ieee80211_bss_conf *bss_conf,
2155 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2159 * Re-calculate the tsf id, as the master-slave relations depend on the
2160 * beacon interval, which was not known when the station interface was
2163 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2164 if (vif->bss_conf.he_support &&
2165 !iwlwifi_mod_params.disable_11ax)
2166 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2168 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2172 * If we're not associated yet, take the (new) BSSID before associating
2173 * so the firmware knows. If we're already associated, then use the old
2174 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2175 * branch for disassociation below.
2177 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2178 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2180 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2182 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2184 /* after sending it once, adopt mac80211 data */
2185 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2186 mvmvif->associated = bss_conf->assoc;
2188 if (changes & BSS_CHANGED_ASSOC) {
2189 if (bss_conf->assoc) {
2190 /* clear statistics to get clean beacon counter */
2191 iwl_mvm_request_statistics(mvm, true);
2192 memset(&mvmvif->beacon_stats, 0,
2193 sizeof(mvmvif->beacon_stats));
2195 /* add quota for this interface */
2196 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2198 IWL_ERR(mvm, "failed to update quotas\n");
2202 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2205 * If we're restarting then the firmware will
2206 * obviously have lost synchronisation with
2207 * the AP. It will attempt to synchronise by
2208 * itself, but we can make it more reliable by
2209 * scheduling a session protection time event.
2211 * The firmware needs to receive a beacon to
2212 * catch up with synchronisation, use 110% of
2213 * the beacon interval.
2215 * Set a large maximum delay to allow for more
2216 * than a single interface.
2218 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2219 iwl_mvm_protect_session(mvm, vif, dur, dur,
2223 iwl_mvm_sf_update(mvm, vif, false);
2224 iwl_mvm_power_vif_assoc(mvm, vif);
2226 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2227 iwl_mvm_update_smps(mvm, vif,
2228 IWL_MVM_SMPS_REQ_PROT,
2229 IEEE80211_SMPS_DYNAMIC);
2231 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2233 * If update fails - SF might be running in associated
2234 * mode while disassociated - which is forbidden.
2236 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2237 "Failed to update SF upon disassociation\n");
2240 * If we get an assert during the connection (after the
2241 * station has been added, but before the vif is set
2242 * to associated), mac80211 will re-add the station and
2243 * then configure the vif. Since the vif is not
2244 * associated, we would remove the station here and
2245 * this would fail the recovery.
2247 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2250 * Remove AP station now that
2251 * the MAC is unassoc
2253 ret = iwl_mvm_rm_sta_id(mvm, vif,
2257 "failed to remove AP station\n");
2259 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2260 mvm->d0i3_ap_sta_id =
2261 IWL_MVM_INVALID_STA;
2262 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2265 /* remove quota for this interface */
2266 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2268 IWL_ERR(mvm, "failed to update quotas\n");
2271 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2273 /* this will take the cleared BSSID from bss_conf */
2274 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2277 "failed to update MAC %pM (clear after unassoc)\n",
2282 * The firmware tracks the MU-MIMO group on its own.
2283 * However, on HW restart we should restore this data.
2285 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2286 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2287 ret = iwl_mvm_update_mu_groups(mvm, vif);
2290 "failed to update VHT MU_MIMO groups\n");
2293 iwl_mvm_recalc_multicast(mvm);
2294 iwl_mvm_configure_bcast_filter(mvm);
2296 /* reset rssi values */
2297 mvmvif->bf_data.ave_beacon_signal = 0;
2299 iwl_mvm_bt_coex_vif_change(mvm);
2300 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2301 IEEE80211_SMPS_AUTOMATIC);
2302 if (fw_has_capa(&mvm->fw->ucode_capa,
2303 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2304 iwl_mvm_config_scan(mvm);
2307 if (changes & BSS_CHANGED_BEACON_INFO) {
2309 * We received a beacon from the associated AP so
2310 * remove the session protection.
2312 iwl_mvm_stop_session_protection(mvm, vif);
2314 iwl_mvm_sf_update(mvm, vif, false);
2315 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2318 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2320 * Send power command on every beacon change,
2321 * because we may have not enabled beacon abort yet.
2323 BSS_CHANGED_BEACON_INFO)) {
2324 ret = iwl_mvm_power_update_mac(mvm);
2326 IWL_ERR(mvm, "failed to update power mode\n");
2329 if (changes & BSS_CHANGED_TXPOWER) {
2330 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2332 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2335 if (changes & BSS_CHANGED_CQM) {
2336 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2337 /* reset cqm events tracking */
2338 mvmvif->bf_data.last_cqm_event = 0;
2339 if (mvmvif->bf_data.bf_enabled) {
2340 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2343 "failed to update CQM thresholds\n");
2347 if (changes & BSS_CHANGED_ARP_FILTER) {
2348 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2349 iwl_mvm_configure_bcast_filter(mvm);
2353 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2354 struct ieee80211_vif *vif)
2356 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2357 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2361 * iwl_mvm_mac_ctxt_add() might read directly from the device
2362 * (the system time), so make sure it is available.
2364 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2368 mutex_lock(&mvm->mutex);
2370 /* Send the beacon template */
2371 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2376 * Re-calculate the tsf id, as the master-slave relations depend on the
2377 * beacon interval, which was not known when the AP interface was added.
2379 if (vif->type == NL80211_IFTYPE_AP)
2380 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2382 mvmvif->ap_assoc_sta_count = 0;
2384 /* Add the mac context */
2385 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2389 /* Perform the binding */
2390 ret = iwl_mvm_binding_add_vif(mvm, vif);
2395 * This is not very nice, but the simplest:
2396 * For older FWs adding the mcast sta before the bcast station may
2397 * cause assert 0x2b00.
2398 * This is fixed in later FW so make the order of removal depend on
2401 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2402 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2406 * Send the bcast station. At this stage the TBTT and DTIM time
2407 * events are added and applied to the scheduler
2409 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2411 iwl_mvm_rm_mcast_sta(mvm, vif);
2416 * Send the bcast station. At this stage the TBTT and DTIM time
2417 * events are added and applied to the scheduler
2419 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2422 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2424 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2429 /* must be set before quota calculations */
2430 mvmvif->ap_ibss_active = true;
2432 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2433 iwl_mvm_vif_set_low_latency(mvmvif, true,
2434 LOW_LATENCY_VIF_TYPE);
2435 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2438 /* power updated needs to be done before quotas */
2439 iwl_mvm_power_update_mac(mvm);
2441 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2443 goto out_quota_failed;
2445 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2446 if (vif->p2p && mvm->p2p_device_vif)
2447 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2449 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2451 iwl_mvm_bt_coex_vif_change(mvm);
2453 /* we don't support TDLS during DCM */
2454 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2455 iwl_mvm_teardown_tdls_peers(mvm);
2460 iwl_mvm_power_update_mac(mvm);
2461 mvmvif->ap_ibss_active = false;
2462 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2463 iwl_mvm_rm_mcast_sta(mvm, vif);
2465 iwl_mvm_binding_remove_vif(mvm, vif);
2467 iwl_mvm_mac_ctxt_remove(mvm, vif);
2469 mutex_unlock(&mvm->mutex);
2470 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2474 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2475 struct ieee80211_vif *vif)
2477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2478 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2480 iwl_mvm_prepare_mac_removal(mvm, vif);
2482 mutex_lock(&mvm->mutex);
2484 /* Handle AP stop while in CSA */
2485 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2486 iwl_mvm_remove_time_event(mvm, mvmvif,
2487 &mvmvif->time_event_data);
2488 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2489 mvmvif->csa_countdown = false;
2492 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2493 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2494 mvm->csa_tx_block_bcn_timeout = 0;
2497 mvmvif->ap_ibss_active = false;
2498 mvm->ap_last_beacon_gp2 = 0;
2500 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2501 iwl_mvm_vif_set_low_latency(mvmvif, false,
2502 LOW_LATENCY_VIF_TYPE);
2503 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2506 iwl_mvm_bt_coex_vif_change(mvm);
2508 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2510 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2511 if (vif->p2p && mvm->p2p_device_vif)
2512 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2514 iwl_mvm_update_quotas(mvm, false, NULL);
2517 * This is not very nice, but the simplest:
2518 * For older FWs removing the mcast sta before the bcast station may
2519 * cause assert 0x2b00.
2520 * This is fixed in later FW (which will stop beaconing when removing
2522 * So make the order of removal depend on the TLV
2524 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2525 iwl_mvm_rm_mcast_sta(mvm, vif);
2526 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2527 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2528 iwl_mvm_rm_mcast_sta(mvm, vif);
2529 iwl_mvm_binding_remove_vif(mvm, vif);
2531 iwl_mvm_power_update_mac(mvm);
2533 iwl_mvm_mac_ctxt_remove(mvm, vif);
2535 kfree(mvmvif->ap_wep_key);
2536 mvmvif->ap_wep_key = NULL;
2538 mutex_unlock(&mvm->mutex);
2542 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2543 struct ieee80211_vif *vif,
2544 struct ieee80211_bss_conf *bss_conf,
2547 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2549 /* Changes will be applied when the AP/IBSS is started */
2550 if (!mvmvif->ap_ibss_active)
2553 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2554 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2555 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2556 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2558 /* Need to send a new beacon template to the FW */
2559 if (changes & BSS_CHANGED_BEACON &&
2560 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2561 IWL_WARN(mvm, "Failed updating beacon data\n");
2563 if (changes & BSS_CHANGED_TXPOWER) {
2564 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2566 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2570 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2571 struct ieee80211_vif *vif,
2572 struct ieee80211_bss_conf *bss_conf,
2575 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2578 * iwl_mvm_bss_info_changed_station() might call
2579 * iwl_mvm_protect_session(), which reads directly from
2580 * the device (the system time), so make sure it is available.
2582 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2585 mutex_lock(&mvm->mutex);
2587 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2588 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2590 switch (vif->type) {
2591 case NL80211_IFTYPE_STATION:
2592 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2594 case NL80211_IFTYPE_AP:
2595 case NL80211_IFTYPE_ADHOC:
2596 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2598 case NL80211_IFTYPE_MONITOR:
2599 if (changes & BSS_CHANGED_MU_GROUPS)
2600 iwl_mvm_update_mu_groups(mvm, vif);
2603 /* shouldn't happen */
2607 mutex_unlock(&mvm->mutex);
2608 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2611 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2612 struct ieee80211_vif *vif,
2613 struct ieee80211_scan_request *hw_req)
2615 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2618 if (hw_req->req.n_channels == 0 ||
2619 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2622 mutex_lock(&mvm->mutex);
2623 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2624 mutex_unlock(&mvm->mutex);
2629 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2630 struct ieee80211_vif *vif)
2632 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2634 mutex_lock(&mvm->mutex);
2636 /* Due to a race condition, it's possible that mac80211 asks
2637 * us to stop a hw_scan when it's already stopped. This can
2638 * happen, for instance, if we stopped the scan ourselves,
2639 * called ieee80211_scan_completed() and the userspace called
2640 * cancel scan scan before ieee80211_scan_work() could run.
2641 * To handle that, simply return if the scan is not running.
2643 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2644 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2646 mutex_unlock(&mvm->mutex);
2650 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2651 struct ieee80211_sta *sta, u16 tids,
2653 enum ieee80211_frame_release_type reason,
2656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2658 /* Called when we need to transmit (a) frame(s) from mac80211 */
2660 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2661 tids, more_data, false);
2665 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2666 struct ieee80211_sta *sta, u16 tids,
2668 enum ieee80211_frame_release_type reason,
2671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2673 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2675 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2676 tids, more_data, true);
2679 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2680 enum sta_notify_cmd cmd,
2681 struct ieee80211_sta *sta)
2683 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2684 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2685 unsigned long txqs = 0, tids = 0;
2689 * If we have TVQM then we get too high queue numbers - luckily
2690 * we really shouldn't get here with that because such hardware
2691 * should have firmware supporting buffer station offload.
2693 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2696 spin_lock_bh(&mvmsta->lock);
2697 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2698 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2700 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2703 __set_bit(tid_data->txq_id, &txqs);
2705 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2708 __set_bit(tid, &tids);
2712 case STA_NOTIFY_SLEEP:
2713 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2714 ieee80211_sta_set_buffered(sta, tid, true);
2717 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2719 * The fw updates the STA to be asleep. Tx packets on the Tx
2720 * queues to this station will not be transmitted. The fw will
2721 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2724 case STA_NOTIFY_AWAKE:
2725 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2729 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2730 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2735 spin_unlock_bh(&mvmsta->lock);
2738 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2739 struct ieee80211_vif *vif,
2740 enum sta_notify_cmd cmd,
2741 struct ieee80211_sta *sta)
2743 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2746 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2748 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2749 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2750 struct ieee80211_sta *sta;
2751 struct iwl_mvm_sta *mvmsta;
2752 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2754 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2758 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2759 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2764 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2767 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2772 if (mvmsta->sleeping != sleeping) {
2773 mvmsta->sleeping = sleeping;
2774 __iwl_mvm_mac_sta_notify(mvm->hw,
2775 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2777 ieee80211_sta_ps_transition(sta, sleeping);
2781 switch (notif->type) {
2782 case IWL_MVM_PM_EVENT_AWAKE:
2783 case IWL_MVM_PM_EVENT_ASLEEP:
2785 case IWL_MVM_PM_EVENT_UAPSD:
2786 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2788 case IWL_MVM_PM_EVENT_PS_POLL:
2789 ieee80211_sta_pspoll(sta);
2799 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2800 struct ieee80211_vif *vif,
2801 struct ieee80211_sta *sta)
2803 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2804 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2807 * This is called before mac80211 does RCU synchronisation,
2808 * so here we already invalidate our internal RCU-protected
2809 * station pointer. The rest of the code will thus no longer
2810 * be able to find the station this way, and we don't rely
2811 * on further RCU synchronisation after the sta_state()
2812 * callback deleted the station.
2814 mutex_lock(&mvm->mutex);
2815 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2816 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2819 mutex_unlock(&mvm->mutex);
2822 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2827 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2828 struct iwl_mvm_tcm_mac *mdata;
2830 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2831 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2832 mdata->opened_rx_ba_sessions = false;
2835 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2838 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2839 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2844 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2845 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2849 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2850 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2851 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2856 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2860 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2861 struct ieee80211_vif *vif, u8 *peer_addr,
2862 enum nl80211_tdls_operation action)
2864 struct iwl_fw_dbg_trigger_tlv *trig;
2865 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2867 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2868 FW_DBG_TRIGGER_TDLS);
2872 tdls_trig = (void *)trig->data;
2874 if (!(tdls_trig->action_bitmap & BIT(action)))
2877 if (tdls_trig->peer_mode &&
2878 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2881 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2882 "TDLS event occurred, peer %pM, action %d",
2886 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2887 struct iwl_mvm_sta *mvm_sta)
2889 struct iwl_mvm_tid_data *tid_data;
2890 struct sk_buff *skb;
2893 spin_lock_bh(&mvm_sta->lock);
2894 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2895 tid_data = &mvm_sta->tid_data[i];
2897 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2898 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2901 * The first deferred frame should've stopped the MAC
2902 * queues, so we should never get a second deferred
2903 * frame for the RA/TID.
2905 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2906 ieee80211_free_txskb(mvm->hw, skb);
2909 spin_unlock_bh(&mvm_sta->lock);
2912 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2913 struct ieee80211_vif *vif,
2914 struct ieee80211_sta *sta,
2915 enum ieee80211_sta_state old_state,
2916 enum ieee80211_sta_state new_state)
2918 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2919 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2920 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2923 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2924 sta->addr, old_state, new_state);
2926 /* this would be a mac80211 bug ... but don't crash */
2927 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2931 * If we are in a STA removal flow and in DQA mode:
2933 * This is after the sync_rcu part, so the queues have already been
2934 * flushed. No more TXs on their way in mac80211's path, and no more in
2936 * Also, we won't be getting any new TX frames for this station.
2937 * What we might have are deferred TX frames that need to be taken care
2940 * Drop any still-queued deferred-frame before removing the STA, and
2941 * make sure the worker is no longer handling frames for this STA.
2943 if (old_state == IEEE80211_STA_NONE &&
2944 new_state == IEEE80211_STA_NOTEXIST) {
2945 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2946 flush_work(&mvm->add_stream_wk);
2949 * No need to make sure deferred TX indication is off since the
2950 * worker will already remove it if it was on
2954 mutex_lock(&mvm->mutex);
2955 /* track whether or not the station is associated */
2956 mvm_sta->sta_state = new_state;
2958 if (old_state == IEEE80211_STA_NOTEXIST &&
2959 new_state == IEEE80211_STA_NONE) {
2961 * Firmware bug - it'll crash if the beacon interval is less
2962 * than 16. We can't avoid connecting at all, so refuse the
2963 * station state change, this will cause mac80211 to abandon
2964 * attempts to connect to this AP, and eventually wpa_s will
2965 * blacklist the AP...
2967 if (vif->type == NL80211_IFTYPE_STATION &&
2968 vif->bss_conf.beacon_int < 16) {
2970 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2971 sta->addr, vif->bss_conf.beacon_int);
2978 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2979 IWL_MVM_TDLS_STA_COUNT ||
2980 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2981 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2986 ret = iwl_mvm_add_sta(mvm, vif, sta);
2987 if (sta->tdls && ret == 0) {
2988 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2989 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2990 NL80211_TDLS_SETUP);
2992 } else if (old_state == IEEE80211_STA_NONE &&
2993 new_state == IEEE80211_STA_AUTH) {
2995 * EBS may be disabled due to previous failures reported by FW.
2996 * Reset EBS status here assuming environment has been changed.
2998 mvm->last_ebs_successful = true;
2999 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3001 } else if (old_state == IEEE80211_STA_AUTH &&
3002 new_state == IEEE80211_STA_ASSOC) {
3003 if (vif->type == NL80211_IFTYPE_AP) {
3004 mvmvif->ap_assoc_sta_count++;
3005 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3006 if (vif->bss_conf.he_support &&
3007 !iwlwifi_mod_params.disable_11ax)
3008 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3011 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3013 ret = iwl_mvm_update_sta(mvm, vif, sta);
3014 } else if (old_state == IEEE80211_STA_ASSOC &&
3015 new_state == IEEE80211_STA_AUTHORIZED) {
3017 /* we don't support TDLS during DCM */
3018 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3019 iwl_mvm_teardown_tdls_peers(mvm);
3022 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3023 NL80211_TDLS_ENABLE_LINK);
3025 /* enable beacon filtering */
3026 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3028 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3031 /* if wep is used, need to set the key for the station now */
3032 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
3033 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
3035 STA_KEY_IDX_INVALID);
3038 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3039 new_state == IEEE80211_STA_ASSOC) {
3040 /* disable beacon filtering */
3041 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
3043 } else if (old_state == IEEE80211_STA_ASSOC &&
3044 new_state == IEEE80211_STA_AUTH) {
3045 if (vif->type == NL80211_IFTYPE_AP) {
3046 mvmvif->ap_assoc_sta_count--;
3047 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3050 } else if (old_state == IEEE80211_STA_AUTH &&
3051 new_state == IEEE80211_STA_NONE) {
3053 } else if (old_state == IEEE80211_STA_NONE &&
3054 new_state == IEEE80211_STA_NOTEXIST) {
3055 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3057 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3058 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3059 NL80211_TDLS_DISABLE_LINK);
3065 mutex_unlock(&mvm->mutex);
3067 if (sta->tdls && ret == 0) {
3068 if (old_state == IEEE80211_STA_NOTEXIST &&
3069 new_state == IEEE80211_STA_NONE)
3070 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3071 else if (old_state == IEEE80211_STA_NONE &&
3072 new_state == IEEE80211_STA_NOTEXIST)
3073 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3079 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3081 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3083 mvm->rts_threshold = value;
3088 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3089 struct ieee80211_vif *vif,
3090 struct ieee80211_sta *sta, u32 changed)
3092 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3094 if (vif->type == NL80211_IFTYPE_STATION &&
3095 changed & IEEE80211_RC_NSS_CHANGED)
3096 iwl_mvm_sf_update(mvm, vif, false);
3099 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3100 struct ieee80211_vif *vif, u16 ac,
3101 const struct ieee80211_tx_queue_params *params)
3103 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3104 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3106 mvmvif->queue_params[ac] = *params;
3109 * No need to update right away, we'll get BSS_CHANGED_QOS
3110 * The exception is P2P_DEVICE interface which needs immediate update.
3112 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3115 mutex_lock(&mvm->mutex);
3116 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3117 mutex_unlock(&mvm->mutex);
3123 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3124 struct ieee80211_vif *vif,
3127 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3128 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3129 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3132 * iwl_mvm_protect_session() reads directly from the device
3133 * (the system time), so make sure it is available.
3135 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3138 if (req_duration > duration)
3139 duration = req_duration;
3141 mutex_lock(&mvm->mutex);
3142 /* Try really hard to protect the session and hear a beacon */
3143 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3144 mutex_unlock(&mvm->mutex);
3146 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3149 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3150 struct ieee80211_vif *vif,
3151 struct cfg80211_sched_scan_request *req,
3152 struct ieee80211_scan_ies *ies)
3154 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3158 mutex_lock(&mvm->mutex);
3160 if (!vif->bss_conf.idle) {
3165 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3168 mutex_unlock(&mvm->mutex);
3172 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3173 struct ieee80211_vif *vif)
3175 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3178 mutex_lock(&mvm->mutex);
3180 /* Due to a race condition, it's possible that mac80211 asks
3181 * us to stop a sched_scan when it's already stopped. This
3182 * can happen, for instance, if we stopped the scan ourselves,
3183 * called ieee80211_sched_scan_stopped() and the userspace called
3184 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3185 * could run. To handle this, simply return if the scan is
3188 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3189 mutex_unlock(&mvm->mutex);
3193 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3194 mutex_unlock(&mvm->mutex);
3195 iwl_mvm_wait_for_async_handlers(mvm);
3200 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3201 enum set_key_cmd cmd,
3202 struct ieee80211_vif *vif,
3203 struct ieee80211_sta *sta,
3204 struct ieee80211_key_conf *key)
3206 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3207 struct iwl_mvm_sta *mvmsta;
3208 struct iwl_mvm_key_pn *ptk_pn;
3209 int keyidx = key->keyidx;
3213 if (iwlwifi_mod_params.swcrypto) {
3214 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3218 switch (key->cipher) {
3219 case WLAN_CIPHER_SUITE_TKIP:
3220 if (!mvm->trans->cfg->gen2) {
3221 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3222 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3223 } else if (vif->type == NL80211_IFTYPE_STATION) {
3224 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3226 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3230 case WLAN_CIPHER_SUITE_CCMP:
3231 case WLAN_CIPHER_SUITE_GCMP:
3232 case WLAN_CIPHER_SUITE_GCMP_256:
3233 if (!iwl_mvm_has_new_tx_api(mvm))
3234 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3236 case WLAN_CIPHER_SUITE_AES_CMAC:
3237 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3238 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3239 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3241 case WLAN_CIPHER_SUITE_WEP40:
3242 case WLAN_CIPHER_SUITE_WEP104:
3243 if (vif->type == NL80211_IFTYPE_AP) {
3244 struct iwl_mvm_vif *mvmvif =
3245 iwl_mvm_vif_from_mac80211(vif);
3247 mvmvif->ap_wep_key = kmemdup(key,
3248 sizeof(*key) + key->keylen,
3250 if (!mvmvif->ap_wep_key)
3254 if (vif->type != NL80211_IFTYPE_STATION)
3258 /* currently FW supports only one optional cipher scheme */
3259 if (hw->n_cipher_schemes &&
3260 hw->cipher_schemes->cipher == key->cipher)
3261 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3266 mutex_lock(&mvm->mutex);
3270 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3271 vif->type == NL80211_IFTYPE_AP) && !sta) {
3273 * GTK on AP interface is a TX-only key, return 0;
3274 * on IBSS they're per-station and because we're lazy
3275 * we don't support them for RX, so do the same.
3276 * CMAC/GMAC in AP/IBSS modes must be done in software.
3278 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3279 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3280 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3285 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3286 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3287 !iwl_mvm_has_new_tx_api(mvm)) {
3288 key->hw_key_idx = STA_KEY_IDX_INVALID;
3293 /* During FW restart, in order to restore the state as it was,
3294 * don't try to reprogram keys we previously failed for.
3296 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3297 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3298 IWL_DEBUG_MAC80211(mvm,
3299 "skip invalid idx key programming during restart\n");
3304 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3305 sta && iwl_mvm_has_new_rx_api(mvm) &&
3306 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3307 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3308 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3309 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3310 struct ieee80211_key_seq seq;
3313 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3314 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3315 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3316 mvm->trans->num_rx_queues),
3323 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3324 ieee80211_get_key_rx_seq(key, tid, &seq);
3325 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3326 memcpy(ptk_pn->q[q].pn[tid],
3328 IEEE80211_CCMP_PN_LEN);
3331 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3334 /* in HW restart reuse the index, otherwise request a new one */
3335 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3336 key_offset = key->hw_key_idx;
3338 key_offset = STA_KEY_IDX_INVALID;
3340 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3341 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3343 IWL_WARN(mvm, "set key failed\n");
3345 * can't add key for RX, but we don't need it
3346 * in the device for TX so still return 0
3348 key->hw_key_idx = STA_KEY_IDX_INVALID;
3354 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3359 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3360 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3361 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3362 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3363 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3364 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3365 ptk_pn = rcu_dereference_protected(
3366 mvmsta->ptk_pn[keyidx],
3367 lockdep_is_held(&mvm->mutex));
3368 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3370 kfree_rcu(ptk_pn, rcu_head);
3373 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3374 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3380 mutex_unlock(&mvm->mutex);
3384 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3385 struct ieee80211_vif *vif,
3386 struct ieee80211_key_conf *keyconf,
3387 struct ieee80211_sta *sta,
3388 u32 iv32, u16 *phase1key)
3390 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3392 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3395 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3399 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3400 struct iwl_rx_packet *pkt, void *data)
3402 struct iwl_mvm *mvm =
3403 container_of(notif_wait, struct iwl_mvm, notif_wait);
3404 struct iwl_hs20_roc_res *resp;
3405 int resp_len = iwl_rx_packet_payload_len(pkt);
3406 struct iwl_mvm_time_event_data *te_data = data;
3408 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3411 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3412 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3416 resp = (void *)pkt->data;
3419 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3420 resp->status, resp->event_unique_id);
3422 te_data->uid = le32_to_cpu(resp->event_unique_id);
3423 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3426 spin_lock_bh(&mvm->time_event_lock);
3427 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3428 spin_unlock_bh(&mvm->time_event_lock);
3433 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3434 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3435 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3436 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3437 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3438 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3439 struct ieee80211_channel *channel,
3440 struct ieee80211_vif *vif,
3443 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3445 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3446 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3447 struct iwl_notification_wait wait_time_event;
3448 u32 dtim_interval = vif->bss_conf.dtim_period *
3449 vif->bss_conf.beacon_int;
3451 struct iwl_hs20_roc_req aux_roc_req = {
3452 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3454 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3455 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3456 /* Set the channel info data */
3457 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3458 PHY_BAND_24 : PHY_BAND_5,
3459 .channel_info.channel = channel->hw_value,
3460 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3461 /* Set the time and duration */
3462 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3465 delay = AUX_ROC_MIN_DELAY;
3466 req_dur = MSEC_TO_TU(duration);
3469 * If we are associated we want the delay time to be at least one
3470 * dtim interval so that the FW can wait until after the DTIM and
3471 * then start the time event, this will potentially allow us to
3472 * remain off-channel for the max duration.
3473 * Since we want to use almost a whole dtim interval we would also
3474 * like the delay to be for 2-3 dtim intervals, in case there are
3475 * other time events with higher priority.
3477 if (vif->bss_conf.assoc) {
3478 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3479 /* We cannot remain off-channel longer than the DTIM interval */
3480 if (dtim_interval <= req_dur) {
3481 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3482 if (req_dur <= AUX_ROC_MIN_DURATION)
3483 req_dur = dtim_interval -
3484 AUX_ROC_MIN_SAFETY_BUFFER;
3488 aux_roc_req.duration = cpu_to_le32(req_dur);
3489 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3492 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3493 channel->hw_value, req_dur, duration, delay,
3495 /* Set the node address */
3496 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3498 lockdep_assert_held(&mvm->mutex);
3500 spin_lock_bh(&mvm->time_event_lock);
3502 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3503 spin_unlock_bh(&mvm->time_event_lock);
3508 te_data->duration = duration;
3509 te_data->id = HOT_SPOT_CMD;
3511 spin_unlock_bh(&mvm->time_event_lock);
3514 * Use a notification wait, which really just processes the
3515 * command response and doesn't wait for anything, in order
3516 * to be able to process the response and get the UID inside
3517 * the RX path. Using CMD_WANT_SKB doesn't work because it
3518 * stores the buffer and then wakes up this thread, by which
3519 * time another notification (that the time event started)
3520 * might already be processed unsuccessfully.
3522 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3523 time_event_response,
3524 ARRAY_SIZE(time_event_response),
3525 iwl_mvm_rx_aux_roc, te_data);
3527 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3531 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3532 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3536 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3537 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3538 /* should never fail */
3543 spin_lock_bh(&mvm->time_event_lock);
3544 iwl_mvm_te_clear_data(mvm, te_data);
3545 spin_unlock_bh(&mvm->time_event_lock);
3551 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3552 struct ieee80211_vif *vif,
3553 struct ieee80211_channel *channel,
3555 enum ieee80211_roc_type type)
3557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3558 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3559 struct cfg80211_chan_def chandef;
3560 struct iwl_mvm_phy_ctxt *phy_ctxt;
3563 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3567 * Flush the done work, just in case it's still pending, so that
3568 * the work it does can complete and we can accept new frames.
3570 flush_work(&mvm->roc_done_wk);
3572 mutex_lock(&mvm->mutex);
3574 switch (vif->type) {
3575 case NL80211_IFTYPE_STATION:
3576 if (fw_has_capa(&mvm->fw->ucode_capa,
3577 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3578 /* Use aux roc framework (HS20) */
3579 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3583 IWL_ERR(mvm, "hotspot not supported\n");
3586 case NL80211_IFTYPE_P2P_DEVICE:
3590 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3595 for (i = 0; i < NUM_PHY_CTX; i++) {
3596 phy_ctxt = &mvm->phy_ctxts[i];
3597 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3600 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3602 * Unbind the P2P_DEVICE from the current PHY context,
3603 * and if the PHY context is not used remove it.
3605 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3606 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3609 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3611 /* Bind the P2P_DEVICE to the current PHY Context */
3612 mvmvif->phy_ctxt = phy_ctxt;
3614 ret = iwl_mvm_binding_add_vif(mvm, vif);
3615 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3618 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3619 goto schedule_time_event;
3623 /* Need to update the PHY context only if the ROC channel changed */
3624 if (channel == mvmvif->phy_ctxt->channel)
3625 goto schedule_time_event;
3627 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3630 * Change the PHY context configuration as it is currently referenced
3631 * only by the P2P Device MAC
3633 if (mvmvif->phy_ctxt->ref == 1) {
3634 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3640 * The PHY context is shared with other MACs. Need to remove the
3641 * P2P Device from the binding, allocate an new PHY context and
3642 * create a new binding
3644 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3650 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3653 IWL_ERR(mvm, "Failed to change PHY context\n");
3657 /* Unbind the P2P_DEVICE from the current PHY context */
3658 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3659 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3662 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3664 /* Bind the P2P_DEVICE to the new allocated PHY context */
3665 mvmvif->phy_ctxt = phy_ctxt;
3667 ret = iwl_mvm_binding_add_vif(mvm, vif);
3668 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3671 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3674 schedule_time_event:
3675 /* Schedule the time events */
3676 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3679 mutex_unlock(&mvm->mutex);
3680 IWL_DEBUG_MAC80211(mvm, "leave\n");
3684 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3686 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3688 IWL_DEBUG_MAC80211(mvm, "enter\n");
3690 mutex_lock(&mvm->mutex);
3691 iwl_mvm_stop_roc(mvm);
3692 mutex_unlock(&mvm->mutex);
3694 IWL_DEBUG_MAC80211(mvm, "leave\n");
3698 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3699 struct ieee80211_chanctx_conf *ctx)
3701 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3702 struct iwl_mvm_phy_ctxt *phy_ctxt;
3705 lockdep_assert_held(&mvm->mutex);
3707 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3709 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3715 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3716 ctx->rx_chains_static,
3717 ctx->rx_chains_dynamic);
3719 IWL_ERR(mvm, "Failed to add PHY context\n");
3723 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3724 *phy_ctxt_id = phy_ctxt->id;
3729 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3730 struct ieee80211_chanctx_conf *ctx)
3732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3735 mutex_lock(&mvm->mutex);
3736 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3737 mutex_unlock(&mvm->mutex);
3742 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3743 struct ieee80211_chanctx_conf *ctx)
3745 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3746 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3748 lockdep_assert_held(&mvm->mutex);
3750 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3753 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3754 struct ieee80211_chanctx_conf *ctx)
3756 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3758 mutex_lock(&mvm->mutex);
3759 __iwl_mvm_remove_chanctx(mvm, ctx);
3760 mutex_unlock(&mvm->mutex);
3763 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3764 struct ieee80211_chanctx_conf *ctx,
3767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3768 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3769 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3771 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3772 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3773 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3774 IEEE80211_CHANCTX_CHANGE_RADAR |
3775 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3776 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3777 phy_ctxt->ref, changed))
3780 mutex_lock(&mvm->mutex);
3782 /* we are only changing the min_width, may be a noop */
3783 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3784 if (phy_ctxt->width == ctx->min_def.width)
3787 /* we are just toggling between 20_NOHT and 20 */
3788 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3789 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3793 iwl_mvm_bt_coex_vif_change(mvm);
3794 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3795 ctx->rx_chains_static,
3796 ctx->rx_chains_dynamic);
3799 mutex_unlock(&mvm->mutex);
3802 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3803 struct ieee80211_vif *vif,
3804 struct ieee80211_chanctx_conf *ctx,
3805 bool switching_chanctx)
3807 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3808 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3809 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3812 lockdep_assert_held(&mvm->mutex);
3814 mvmvif->phy_ctxt = phy_ctxt;
3816 switch (vif->type) {
3817 case NL80211_IFTYPE_AP:
3818 /* only needed if we're switching chanctx (i.e. during CSA) */
3819 if (switching_chanctx) {
3820 mvmvif->ap_ibss_active = true;
3823 case NL80211_IFTYPE_ADHOC:
3825 * The AP binding flow is handled as part of the start_ap flow
3826 * (in bss_info_changed), similarly for IBSS.
3830 case NL80211_IFTYPE_STATION:
3831 mvmvif->csa_bcn_pending = false;
3833 case NL80211_IFTYPE_MONITOR:
3834 /* always disable PS when a monitor interface is active */
3835 mvmvif->ps_disabled = true;
3842 ret = iwl_mvm_binding_add_vif(mvm, vif);
3847 * Power state must be updated before quotas,
3848 * otherwise fw will complain.
3850 iwl_mvm_power_update_mac(mvm);
3852 /* Setting the quota at this stage is only required for monitor
3853 * interfaces. For the other types, the bss_info changed flow
3854 * will handle quota settings.
3856 if (vif->type == NL80211_IFTYPE_MONITOR) {
3857 mvmvif->monitor_active = true;
3858 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3860 goto out_remove_binding;
3862 ret = iwl_mvm_add_snif_sta(mvm, vif);
3864 goto out_remove_binding;
3868 /* Handle binding during CSA */
3869 if (vif->type == NL80211_IFTYPE_AP) {
3870 iwl_mvm_update_quotas(mvm, false, NULL);
3871 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3874 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3875 u32 duration = 3 * vif->bss_conf.beacon_int;
3877 /* iwl_mvm_protect_session() reads directly from the
3878 * device (the system time), so make sure it is
3881 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3883 goto out_remove_binding;
3885 /* Protect the session to make sure we hear the first
3886 * beacon on the new channel.
3888 mvmvif->csa_bcn_pending = true;
3889 iwl_mvm_protect_session(mvm, vif, duration, duration,
3890 vif->bss_conf.beacon_int / 2,
3893 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3895 iwl_mvm_update_quotas(mvm, false, NULL);
3901 iwl_mvm_binding_remove_vif(mvm, vif);
3902 iwl_mvm_power_update_mac(mvm);
3905 mvmvif->phy_ctxt = NULL;
3908 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3909 struct ieee80211_vif *vif,
3910 struct ieee80211_chanctx_conf *ctx)
3912 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3915 mutex_lock(&mvm->mutex);
3916 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3917 mutex_unlock(&mvm->mutex);
3922 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3923 struct ieee80211_vif *vif,
3924 struct ieee80211_chanctx_conf *ctx,
3925 bool switching_chanctx)
3927 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3928 struct ieee80211_vif *disabled_vif = NULL;
3930 lockdep_assert_held(&mvm->mutex);
3932 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3934 switch (vif->type) {
3935 case NL80211_IFTYPE_ADHOC:
3937 case NL80211_IFTYPE_MONITOR:
3938 mvmvif->monitor_active = false;
3939 mvmvif->ps_disabled = false;
3940 iwl_mvm_rm_snif_sta(mvm, vif);
3942 case NL80211_IFTYPE_AP:
3943 /* This part is triggered only during CSA */
3944 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3947 mvmvif->csa_countdown = false;
3949 /* Set CS bit on all the stations */
3950 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3952 /* Save blocked iface, the timeout is set on the next beacon */
3953 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3955 mvmvif->ap_ibss_active = false;
3957 case NL80211_IFTYPE_STATION:
3958 if (!switching_chanctx)
3963 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3969 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3970 iwl_mvm_binding_remove_vif(mvm, vif);
3973 mvmvif->phy_ctxt = NULL;
3974 iwl_mvm_power_update_mac(mvm);
3977 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3978 struct ieee80211_vif *vif,
3979 struct ieee80211_chanctx_conf *ctx)
3981 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3983 mutex_lock(&mvm->mutex);
3984 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3985 mutex_unlock(&mvm->mutex);
3989 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3990 struct ieee80211_vif_chanctx_switch *vifs)
3994 mutex_lock(&mvm->mutex);
3995 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3996 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3998 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4000 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4004 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4008 "failed to assign new_ctx during channel switch\n");
4012 /* we don't support TDLS during DCM - can be caused by channel switch */
4013 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4014 iwl_mvm_teardown_tdls_peers(mvm);
4019 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4022 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4023 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4027 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4029 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4036 /* things keep failing, better restart the hw */
4037 iwl_mvm_nic_restart(mvm, false);
4040 mutex_unlock(&mvm->mutex);
4046 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4047 struct ieee80211_vif_chanctx_switch *vifs)
4051 mutex_lock(&mvm->mutex);
4052 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4054 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4058 "failed to assign new_ctx during channel switch\n");
4065 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4067 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4074 /* things keep failing, better restart the hw */
4075 iwl_mvm_nic_restart(mvm, false);
4078 mutex_unlock(&mvm->mutex);
4083 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4084 struct ieee80211_vif_chanctx_switch *vifs,
4086 enum ieee80211_chanctx_switch_mode mode)
4088 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4091 /* we only support a single-vif right now */
4096 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4097 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4099 case CHANCTX_SWMODE_REASSIGN_VIF:
4100 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4110 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4112 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4114 return mvm->ibss_manager;
4117 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4118 struct ieee80211_sta *sta,
4121 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4122 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4124 if (!mvm_sta || !mvm_sta->vif) {
4125 IWL_ERR(mvm, "Station is not associated to a vif\n");
4129 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4132 #ifdef CONFIG_NL80211_TESTMODE
4133 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4134 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4135 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4136 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4139 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4140 struct ieee80211_vif *vif,
4141 void *data, int len)
4143 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4147 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4152 if (!tb[IWL_MVM_TM_ATTR_CMD])
4155 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4156 case IWL_MVM_TM_CMD_SET_NOA:
4157 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4158 !vif->bss_conf.enable_beacon ||
4159 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4162 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4163 if (noa_duration >= vif->bss_conf.beacon_int)
4166 mvm->noa_duration = noa_duration;
4169 return iwl_mvm_update_quotas(mvm, true, NULL);
4170 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4171 /* must be associated client vif - ignore authorized */
4172 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4173 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4174 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4177 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4178 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4179 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4185 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4186 struct ieee80211_vif *vif,
4187 void *data, int len)
4189 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4192 mutex_lock(&mvm->mutex);
4193 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4194 mutex_unlock(&mvm->mutex);
4200 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4201 struct ieee80211_vif *vif,
4202 struct ieee80211_channel_switch *chsw)
4204 /* By implementing this operation, we prevent mac80211 from
4205 * starting its own channel switch timer, so that we can call
4206 * ieee80211_chswitch_done() ourselves at the right time
4207 * (which is when the absence time event starts).
4210 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4211 "dummy channel switch op\n");
4214 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4215 struct ieee80211_vif *vif,
4216 struct ieee80211_channel_switch *chsw)
4218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4219 struct ieee80211_vif *csa_vif;
4220 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4224 mutex_lock(&mvm->mutex);
4226 mvmvif->csa_failed = false;
4228 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4229 chsw->chandef.center_freq1);
4231 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4232 ieee80211_vif_to_wdev(vif),
4233 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4235 switch (vif->type) {
4236 case NL80211_IFTYPE_AP:
4238 rcu_dereference_protected(mvm->csa_vif,
4239 lockdep_is_held(&mvm->mutex));
4240 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4241 "Another CSA is already in progress")) {
4246 /* we still didn't unblock tx. prevent new CS meanwhile */
4247 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4248 lockdep_is_held(&mvm->mutex))) {
4253 rcu_assign_pointer(mvm->csa_vif, vif);
4255 if (WARN_ONCE(mvmvif->csa_countdown,
4256 "Previous CSA countdown didn't complete")) {
4261 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4264 case NL80211_IFTYPE_STATION:
4265 /* Schedule the time event to a bit before beacon 1,
4266 * to make sure we're in the new channel when the
4267 * GO/AP arrives. In case count <= 1 immediately schedule the
4268 * TE (this might result with some packet loss or connection
4271 if (chsw->count <= 1)
4274 apply_time = chsw->device_timestamp +
4275 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4276 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4279 iwl_mvm_csa_client_absent(mvm, vif);
4281 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4283 if (mvmvif->bf_data.bf_enabled) {
4284 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4294 mvmvif->ps_disabled = true;
4296 ret = iwl_mvm_power_update_ps(mvm);
4300 /* we won't be on this channel any longer */
4301 iwl_mvm_teardown_tdls_peers(mvm);
4304 mutex_unlock(&mvm->mutex);
4309 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4310 struct ieee80211_vif *vif)
4312 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4316 mutex_lock(&mvm->mutex);
4318 if (mvmvif->csa_failed) {
4319 mvmvif->csa_failed = false;
4324 if (vif->type == NL80211_IFTYPE_STATION) {
4325 struct iwl_mvm_sta *mvmsta;
4327 mvmvif->csa_bcn_pending = false;
4328 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4331 if (WARN_ON(!mvmsta)) {
4336 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4338 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4340 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4344 iwl_mvm_stop_session_protection(mvm, vif);
4347 mvmvif->ps_disabled = false;
4349 ret = iwl_mvm_power_update_ps(mvm);
4352 mutex_unlock(&mvm->mutex);
4357 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4361 if (!iwl_mvm_has_new_tx_api(mvm)) {
4363 mutex_lock(&mvm->mutex);
4364 iwl_mvm_flush_tx_path(mvm,
4365 iwl_mvm_flushable_queues(mvm) & queues, 0);
4366 mutex_unlock(&mvm->mutex);
4368 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4373 mutex_lock(&mvm->mutex);
4374 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4375 struct ieee80211_sta *sta;
4377 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4378 lockdep_is_held(&mvm->mutex));
4379 if (IS_ERR_OR_NULL(sta))
4383 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4385 iwl_mvm_wait_sta_queues_empty(mvm,
4386 iwl_mvm_sta_from_mac80211(sta));
4388 mutex_unlock(&mvm->mutex);
4391 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4392 struct ieee80211_vif *vif, u32 queues, bool drop)
4394 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4395 struct iwl_mvm_vif *mvmvif;
4396 struct iwl_mvm_sta *mvmsta;
4397 struct ieee80211_sta *sta;
4402 iwl_mvm_flush_no_vif(mvm, queues, drop);
4406 if (vif->type != NL80211_IFTYPE_STATION)
4409 /* Make sure we're done with the deferred traffic before flushing */
4410 flush_work(&mvm->add_stream_wk);
4412 mutex_lock(&mvm->mutex);
4413 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4415 /* flush the AP-station and all TDLS peers */
4416 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4417 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4418 lockdep_is_held(&mvm->mutex));
4419 if (IS_ERR_OR_NULL(sta))
4422 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4423 if (mvmsta->vif != vif)
4426 /* make sure only TDLS peers or the AP are flushed */
4427 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4430 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4431 IWL_ERR(mvm, "flush request fail\n");
4433 msk |= mvmsta->tfd_queue_msk;
4434 if (iwl_mvm_has_new_tx_api(mvm))
4435 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4439 mutex_unlock(&mvm->mutex);
4441 /* this can take a while, and we may need/want other operations
4442 * to succeed while doing this, so do it without the mutex held
4444 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4445 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4448 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4449 struct survey_info *survey)
4451 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4454 memset(survey, 0, sizeof(*survey));
4456 /* only support global statistics right now */
4460 if (!fw_has_capa(&mvm->fw->ucode_capa,
4461 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4464 mutex_lock(&mvm->mutex);
4466 if (iwl_mvm_firmware_running(mvm)) {
4467 ret = iwl_mvm_request_statistics(mvm, false);
4472 survey->filled = SURVEY_INFO_TIME |
4473 SURVEY_INFO_TIME_RX |
4474 SURVEY_INFO_TIME_TX |
4475 SURVEY_INFO_TIME_SCAN;
4476 survey->time = mvm->accu_radio_stats.on_time_rf +
4477 mvm->radio_stats.on_time_rf;
4478 do_div(survey->time, USEC_PER_MSEC);
4480 survey->time_rx = mvm->accu_radio_stats.rx_time +
4481 mvm->radio_stats.rx_time;
4482 do_div(survey->time_rx, USEC_PER_MSEC);
4484 survey->time_tx = mvm->accu_radio_stats.tx_time +
4485 mvm->radio_stats.tx_time;
4486 do_div(survey->time_tx, USEC_PER_MSEC);
4488 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4489 mvm->radio_stats.on_time_scan;
4490 do_div(survey->time_scan, USEC_PER_MSEC);
4494 mutex_unlock(&mvm->mutex);
4498 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4499 struct ieee80211_vif *vif,
4500 struct ieee80211_sta *sta,
4501 struct station_info *sinfo)
4503 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4504 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4505 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4507 if (mvmsta->avg_energy) {
4508 sinfo->signal_avg = mvmsta->avg_energy;
4509 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4512 /* if beacon filtering isn't on mac80211 does it anyway */
4513 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4516 if (!vif->bss_conf.assoc)
4519 mutex_lock(&mvm->mutex);
4521 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4524 if (iwl_mvm_request_statistics(mvm, false))
4527 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4528 mvmvif->beacon_stats.accu_num_beacons;
4529 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4530 if (mvmvif->beacon_stats.avg_signal) {
4531 /* firmware only reports a value after RXing a few beacons */
4532 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4533 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4536 mutex_unlock(&mvm->mutex);
4539 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4540 struct ieee80211_vif *vif,
4541 const struct ieee80211_event *event)
4543 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4545 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4547 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4550 struct iwl_fw_dbg_trigger_tlv *trig;
4551 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4553 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4554 FW_DBG_TRIGGER_MLME);
4558 trig_mlme = (void *)trig->data;
4560 if (event->u.mlme.data == ASSOC_EVENT) {
4561 if (event->u.mlme.status == MLME_DENIED)
4562 CHECK_MLME_TRIGGER(stop_assoc_denied,
4563 "DENIED ASSOC: reason %d",
4564 event->u.mlme.reason);
4565 else if (event->u.mlme.status == MLME_TIMEOUT)
4566 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4568 } else if (event->u.mlme.data == AUTH_EVENT) {
4569 if (event->u.mlme.status == MLME_DENIED)
4570 CHECK_MLME_TRIGGER(stop_auth_denied,
4571 "DENIED AUTH: reason %d",
4572 event->u.mlme.reason);
4573 else if (event->u.mlme.status == MLME_TIMEOUT)
4574 CHECK_MLME_TRIGGER(stop_auth_timeout,
4576 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4577 CHECK_MLME_TRIGGER(stop_rx_deauth,
4578 "DEAUTH RX %d", event->u.mlme.reason);
4579 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4580 CHECK_MLME_TRIGGER(stop_tx_deauth,
4581 "DEAUTH TX %d", event->u.mlme.reason);
4583 #undef CHECK_MLME_TRIGGER
4586 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4587 struct ieee80211_vif *vif,
4588 const struct ieee80211_event *event)
4590 struct iwl_fw_dbg_trigger_tlv *trig;
4591 struct iwl_fw_dbg_trigger_ba *ba_trig;
4593 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4598 ba_trig = (void *)trig->data;
4600 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4603 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4604 "BAR received from %pM, tid %d, ssn %d",
4605 event->u.ba.sta->addr, event->u.ba.tid,
4609 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4610 struct ieee80211_vif *vif,
4611 const struct ieee80211_event *event)
4613 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4615 switch (event->type) {
4617 iwl_mvm_event_mlme_callback(mvm, vif, event);
4620 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4622 case BA_FRAME_TIMEOUT:
4623 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4631 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4632 struct iwl_mvm_internal_rxq_notif *notif,
4635 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4638 lockdep_assert_held(&mvm->mutex);
4640 if (!iwl_mvm_has_new_rx_api(mvm))
4643 notif->cookie = mvm->queue_sync_cookie;
4646 atomic_set(&mvm->queue_sync_counter,
4647 mvm->trans->num_rx_queues);
4649 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4651 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4656 ret = wait_event_timeout(mvm->rx_sync_waitq,
4657 atomic_read(&mvm->queue_sync_counter) == 0 ||
4658 iwl_mvm_is_radio_killed(mvm),
4660 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4664 atomic_set(&mvm->queue_sync_counter, 0);
4665 mvm->queue_sync_cookie++;
4668 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4670 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4671 struct iwl_mvm_internal_rxq_notif data = {
4672 .type = IWL_MVM_RXQ_EMPTY,
4676 mutex_lock(&mvm->mutex);
4677 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4678 mutex_unlock(&mvm->mutex);
4681 const struct ieee80211_ops iwl_mvm_hw_ops = {
4682 .tx = iwl_mvm_mac_tx,
4683 .ampdu_action = iwl_mvm_mac_ampdu_action,
4684 .start = iwl_mvm_mac_start,
4685 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4686 .stop = iwl_mvm_mac_stop,
4687 .add_interface = iwl_mvm_mac_add_interface,
4688 .remove_interface = iwl_mvm_mac_remove_interface,
4689 .config = iwl_mvm_mac_config,
4690 .prepare_multicast = iwl_mvm_prepare_multicast,
4691 .configure_filter = iwl_mvm_configure_filter,
4692 .config_iface_filter = iwl_mvm_config_iface_filter,
4693 .bss_info_changed = iwl_mvm_bss_info_changed,
4694 .hw_scan = iwl_mvm_mac_hw_scan,
4695 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4696 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4697 .sta_state = iwl_mvm_mac_sta_state,
4698 .sta_notify = iwl_mvm_mac_sta_notify,
4699 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4700 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4701 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4702 .sta_rc_update = iwl_mvm_sta_rc_update,
4703 .conf_tx = iwl_mvm_mac_conf_tx,
4704 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4705 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4706 .flush = iwl_mvm_mac_flush,
4707 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4708 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4709 .set_key = iwl_mvm_mac_set_key,
4710 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4711 .remain_on_channel = iwl_mvm_roc,
4712 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4713 .add_chanctx = iwl_mvm_add_chanctx,
4714 .remove_chanctx = iwl_mvm_remove_chanctx,
4715 .change_chanctx = iwl_mvm_change_chanctx,
4716 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4717 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4718 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4720 .start_ap = iwl_mvm_start_ap_ibss,
4721 .stop_ap = iwl_mvm_stop_ap_ibss,
4722 .join_ibss = iwl_mvm_start_ap_ibss,
4723 .leave_ibss = iwl_mvm_stop_ap_ibss,
4725 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4727 .set_tim = iwl_mvm_set_tim,
4729 .channel_switch = iwl_mvm_channel_switch,
4730 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4731 .post_channel_switch = iwl_mvm_post_channel_switch,
4733 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4734 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4735 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4737 .event_callback = iwl_mvm_mac_event_callback,
4739 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4741 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4743 #ifdef CONFIG_PM_SLEEP
4745 .suspend = iwl_mvm_suspend,
4746 .resume = iwl_mvm_resume,
4747 .set_wakeup = iwl_mvm_set_wakeup,
4748 .set_rekey_data = iwl_mvm_set_rekey_data,
4749 #if IS_ENABLED(CONFIG_IPV6)
4750 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4752 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4754 .get_survey = iwl_mvm_mac_get_survey,
4755 .sta_statistics = iwl_mvm_mac_sta_statistics,
4756 #ifdef CONFIG_IWLWIFI_DEBUGFS
4757 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,