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 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
400 struct ieee80211_hw *hw = mvm->hw;
402 static const u32 mvm_ciphers[] = {
403 WLAN_CIPHER_SUITE_WEP40,
404 WLAN_CIPHER_SUITE_WEP104,
405 WLAN_CIPHER_SUITE_TKIP,
406 WLAN_CIPHER_SUITE_CCMP,
409 /* Tell mac80211 our characteristics */
410 ieee80211_hw_set(hw, SIGNAL_DBM);
411 ieee80211_hw_set(hw, SPECTRUM_MGMT);
412 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
413 ieee80211_hw_set(hw, QUEUE_CONTROL);
414 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
415 ieee80211_hw_set(hw, SUPPORTS_PS);
416 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
417 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
418 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
419 ieee80211_hw_set(hw, CONNECTION_MONITOR);
420 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
421 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
422 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
423 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
424 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
425 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
426 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
428 if (iwl_mvm_has_tlc_offload(mvm)) {
429 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
430 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
433 if (iwl_mvm_has_new_rx_api(mvm))
434 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
436 if (fw_has_capa(&mvm->fw->ucode_capa,
437 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
438 ieee80211_hw_set(hw, AP_LINK_PS);
439 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
441 * we absolutely need this for the new TX API since that comes
442 * with many more queues than the current code can deal with
443 * for station powersave
448 if (mvm->trans->num_rx_queues > 1)
449 ieee80211_hw_set(hw, USES_RSS);
451 if (mvm->trans->max_skb_frags)
452 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
454 hw->queues = IEEE80211_MAX_QUEUES;
455 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
456 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
457 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
458 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
459 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
461 hw->radiotap_timestamp.units_pos =
462 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
463 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
464 /* this is the case for CCK frames, it's better (only 8) for OFDM */
465 hw->radiotap_timestamp.accuracy = 22;
467 if (!iwl_mvm_has_tlc_offload(mvm))
468 hw->rate_control_algorithm = RS_NAME;
470 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
471 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
473 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
474 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
475 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
476 hw->wiphy->cipher_suites = mvm->ciphers;
478 if (iwl_mvm_has_new_rx_api(mvm)) {
479 mvm->ciphers[hw->wiphy->n_cipher_suites] =
480 WLAN_CIPHER_SUITE_GCMP;
481 hw->wiphy->n_cipher_suites++;
482 mvm->ciphers[hw->wiphy->n_cipher_suites] =
483 WLAN_CIPHER_SUITE_GCMP_256;
484 hw->wiphy->n_cipher_suites++;
487 /* Enable 11w if software crypto is not enabled (as the
488 * firmware will interpret some mgmt packets, so enabling it
489 * with software crypto isn't safe).
491 if (!iwlwifi_mod_params.swcrypto) {
492 ieee80211_hw_set(hw, MFP_CAPABLE);
493 mvm->ciphers[hw->wiphy->n_cipher_suites] =
494 WLAN_CIPHER_SUITE_AES_CMAC;
495 hw->wiphy->n_cipher_suites++;
496 if (iwl_mvm_has_new_rx_api(mvm)) {
497 mvm->ciphers[hw->wiphy->n_cipher_suites] =
498 WLAN_CIPHER_SUITE_BIP_GMAC_128;
499 hw->wiphy->n_cipher_suites++;
500 mvm->ciphers[hw->wiphy->n_cipher_suites] =
501 WLAN_CIPHER_SUITE_BIP_GMAC_256;
502 hw->wiphy->n_cipher_suites++;
506 /* currently FW API supports only one optional cipher scheme */
507 if (mvm->fw->cs[0].cipher) {
508 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
509 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
511 mvm->hw->n_cipher_schemes = 1;
513 cs->cipher = le32_to_cpu(fwcs->cipher);
514 cs->iftype = BIT(NL80211_IFTYPE_STATION);
515 cs->hdr_len = fwcs->hdr_len;
516 cs->pn_len = fwcs->pn_len;
517 cs->pn_off = fwcs->pn_off;
518 cs->key_idx_off = fwcs->key_idx_off;
519 cs->key_idx_mask = fwcs->key_idx_mask;
520 cs->key_idx_shift = fwcs->key_idx_shift;
521 cs->mic_len = fwcs->mic_len;
523 mvm->hw->cipher_schemes = mvm->cs;
524 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
525 hw->wiphy->n_cipher_suites++;
528 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
529 hw->wiphy->features |=
530 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
531 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
532 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
534 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
535 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
536 hw->chanctx_data_size = sizeof(u16);
538 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
539 BIT(NL80211_IFTYPE_P2P_CLIENT) |
540 BIT(NL80211_IFTYPE_AP) |
541 BIT(NL80211_IFTYPE_P2P_GO) |
542 BIT(NL80211_IFTYPE_P2P_DEVICE) |
543 BIT(NL80211_IFTYPE_ADHOC);
545 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
546 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
547 if (iwl_mvm_is_lar_supported(mvm))
548 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
550 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
551 REGULATORY_DISABLE_BEACON_HINTS;
553 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
554 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
556 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
557 hw->wiphy->n_iface_combinations =
558 ARRAY_SIZE(iwl_mvm_iface_combinations);
560 hw->wiphy->max_remain_on_channel_duration = 10000;
561 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
563 /* Extract MAC address */
564 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
565 hw->wiphy->addresses = mvm->addresses;
566 hw->wiphy->n_addresses = 1;
568 /* Extract additional MAC addresses if available */
569 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
570 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
572 for (i = 1; i < num_mac; i++) {
573 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
575 mvm->addresses[i].addr[5]++;
576 hw->wiphy->n_addresses++;
579 iwl_mvm_reset_phy_ctxts(mvm);
581 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
583 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
585 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
586 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
587 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
589 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
590 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
592 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
594 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
595 hw->wiphy->bands[NL80211_BAND_2GHZ] =
596 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
597 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
598 hw->wiphy->bands[NL80211_BAND_5GHZ] =
599 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
601 if (fw_has_capa(&mvm->fw->ucode_capa,
602 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
603 fw_has_api(&mvm->fw->ucode_capa,
604 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
605 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
606 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
609 hw->wiphy->hw_version = mvm->trans->hw_id;
611 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
612 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
614 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
616 hw->wiphy->max_sched_scan_reqs = 1;
617 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
618 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
619 /* we create the 802.11 header and zero length SSID IE. */
620 hw->wiphy->max_sched_scan_ie_len =
621 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
622 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
623 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
626 * the firmware uses u8 for num of iterations, but 0xff is saved for
627 * infinite loop, so the maximum number of iterations is actually 254.
629 hw->wiphy->max_sched_scan_plan_iterations = 254;
631 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
632 NL80211_FEATURE_LOW_PRIORITY_SCAN |
633 NL80211_FEATURE_P2P_GO_OPPPS |
634 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
635 NL80211_FEATURE_DYNAMIC_SMPS |
636 NL80211_FEATURE_STATIC_SMPS |
637 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
639 if (fw_has_capa(&mvm->fw->ucode_capa,
640 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
641 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
642 if (fw_has_capa(&mvm->fw->ucode_capa,
643 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
644 hw->wiphy->features |= NL80211_FEATURE_QUIET;
646 if (fw_has_capa(&mvm->fw->ucode_capa,
647 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
648 hw->wiphy->features |=
649 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
651 if (fw_has_capa(&mvm->fw->ucode_capa,
652 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
653 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
655 if (fw_has_api(&mvm->fw->ucode_capa,
656 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
657 wiphy_ext_feature_set(hw->wiphy,
658 NL80211_EXT_FEATURE_SCAN_START_TIME);
659 wiphy_ext_feature_set(hw->wiphy,
660 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
661 wiphy_ext_feature_set(hw->wiphy,
662 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
665 if (iwl_mvm_is_oce_supported(mvm)) {
666 wiphy_ext_feature_set(hw->wiphy,
667 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
668 wiphy_ext_feature_set(hw->wiphy,
669 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
670 wiphy_ext_feature_set(hw->wiphy,
671 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
672 wiphy_ext_feature_set(hw->wiphy,
673 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
676 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
678 #ifdef CONFIG_PM_SLEEP
679 if (iwl_mvm_is_d0i3_supported(mvm) &&
680 device_can_wakeup(mvm->trans->dev)) {
681 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
682 hw->wiphy->wowlan = &mvm->wowlan;
685 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
686 mvm->trans->ops->d3_suspend &&
687 mvm->trans->ops->d3_resume &&
688 device_can_wakeup(mvm->trans->dev)) {
689 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
690 WIPHY_WOWLAN_DISCONNECT |
691 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
692 WIPHY_WOWLAN_RFKILL_RELEASE |
693 WIPHY_WOWLAN_NET_DETECT;
694 if (!iwlwifi_mod_params.swcrypto)
695 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
696 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
697 WIPHY_WOWLAN_4WAY_HANDSHAKE;
699 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
700 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
701 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
702 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
703 hw->wiphy->wowlan = &mvm->wowlan;
707 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
708 /* assign default bcast filtering configuration */
709 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
712 ret = iwl_mvm_leds_init(mvm);
716 if (fw_has_capa(&mvm->fw->ucode_capa,
717 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
718 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
719 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
720 ieee80211_hw_set(hw, TDLS_WIDER_BW);
723 if (fw_has_capa(&mvm->fw->ucode_capa,
724 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
725 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
726 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
729 hw->netdev_features |= mvm->cfg->features;
730 if (!iwl_mvm_is_csum_supported(mvm)) {
731 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
733 /* We may support SW TX CSUM */
734 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
735 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
738 ret = ieee80211_register_hw(mvm->hw);
740 iwl_mvm_leds_exit(mvm);
741 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
743 if (mvm->cfg->vht_mu_mimo_supported)
744 wiphy_ext_feature_set(hw->wiphy,
745 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
750 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
751 struct ieee80211_sta *sta,
754 struct iwl_mvm_sta *mvmsta;
758 * double check the IN_D0I3 flag both before and after
759 * taking the spinlock, in order to prevent taking
760 * the spinlock when not needed.
762 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
765 spin_lock(&mvm->d0i3_tx_lock);
767 * testing the flag again ensures the skb dequeue
768 * loop (on d0i3 exit) hasn't run yet.
770 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
773 mvmsta = iwl_mvm_sta_from_mac80211(sta);
774 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
775 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
778 __skb_queue_tail(&mvm->d0i3_tx, skb);
779 ieee80211_stop_queues(mvm->hw);
782 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
783 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
787 spin_unlock(&mvm->d0i3_tx_lock);
791 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
792 struct ieee80211_tx_control *control,
795 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
796 struct ieee80211_sta *sta = control->sta;
797 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
798 struct ieee80211_hdr *hdr = (void *)skb->data;
800 if (iwl_mvm_is_radio_killed(mvm)) {
801 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
805 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
806 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
807 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
810 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
811 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
812 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
813 ieee80211_is_mgmt(hdr->frame_control) &&
814 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
817 /* If there is no sta, and it's not offchannel - send through AP */
818 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
819 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
820 struct iwl_mvm_vif *mvmvif =
821 iwl_mvm_vif_from_mac80211(info->control.vif);
822 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
824 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
825 /* mac80211 holds rcu read lock */
826 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
827 if (IS_ERR_OR_NULL(sta))
833 if (iwl_mvm_defer_tx(mvm, sta, skb))
835 if (iwl_mvm_tx_skb(mvm, skb, sta))
840 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
844 ieee80211_free_txskb(hw, skb);
847 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
849 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
854 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
856 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
858 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
861 /* enabled by default */
865 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
867 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
869 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
873 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
874 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
875 enum ieee80211_ampdu_mlme_action action)
877 struct iwl_fw_dbg_trigger_tlv *trig;
878 struct iwl_fw_dbg_trigger_ba *ba_trig;
880 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
885 ba_trig = (void *)trig->data;
888 case IEEE80211_AMPDU_TX_OPERATIONAL: {
889 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
890 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
892 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
893 "TX AGG START: MAC %pM tid %d ssn %d\n",
894 sta->addr, tid, tid_data->ssn);
897 case IEEE80211_AMPDU_TX_STOP_CONT:
898 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
899 "TX AGG STOP: MAC %pM tid %d\n",
902 case IEEE80211_AMPDU_RX_START:
903 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
904 "RX AGG START: MAC %pM tid %d ssn %d\n",
905 sta->addr, tid, rx_ba_ssn);
907 case IEEE80211_AMPDU_RX_STOP:
908 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
909 "RX AGG STOP: MAC %pM tid %d\n",
917 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
918 struct ieee80211_vif *vif,
919 struct ieee80211_ampdu_params *params)
921 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
923 bool tx_agg_ref = false;
924 struct ieee80211_sta *sta = params->sta;
925 enum ieee80211_ampdu_mlme_action action = params->action;
926 u16 tid = params->tid;
927 u16 *ssn = ¶ms->ssn;
928 u16 buf_size = params->buf_size;
929 bool amsdu = params->amsdu;
930 u16 timeout = params->timeout;
932 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
933 sta->addr, tid, action);
935 if (!(mvm->nvm_data->sku_cap_11n_enable))
938 /* return from D0i3 before starting a new Tx aggregation */
940 case IEEE80211_AMPDU_TX_START:
941 case IEEE80211_AMPDU_TX_STOP_CONT:
942 case IEEE80211_AMPDU_TX_STOP_FLUSH:
943 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
944 case IEEE80211_AMPDU_TX_OPERATIONAL:
946 * for tx start, wait synchronously until D0i3 exit to
947 * get the correct sequence number for the tid.
948 * additionally, some other ampdu actions use direct
949 * target access, which is not handled automatically
950 * by the trans layer (unlike commands), so wait for
951 * d0i3 exit in these cases as well.
953 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
963 mutex_lock(&mvm->mutex);
966 case IEEE80211_AMPDU_RX_START:
967 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
968 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
969 struct iwl_mvm_vif *mvmvif;
970 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
971 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
973 mdata->opened_rx_ba_sessions = true;
974 mvmvif = iwl_mvm_vif_from_mac80211(vif);
975 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
977 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
981 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
984 case IEEE80211_AMPDU_RX_STOP:
985 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
988 case IEEE80211_AMPDU_TX_START:
989 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
993 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
995 case IEEE80211_AMPDU_TX_STOP_CONT:
996 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
998 case IEEE80211_AMPDU_TX_STOP_FLUSH:
999 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1000 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1002 case IEEE80211_AMPDU_TX_OPERATIONAL:
1003 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1015 if (action == IEEE80211_AMPDU_RX_START)
1018 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1021 mutex_unlock(&mvm->mutex);
1024 * If the tid is marked as started, we won't use it for offloaded
1025 * traffic on the next D0i3 entry. It's safe to unref.
1028 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1033 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1034 struct ieee80211_vif *vif)
1036 struct iwl_mvm *mvm = data;
1037 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1039 mvmvif->uploaded = false;
1040 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1042 spin_lock_bh(&mvm->time_event_lock);
1043 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1044 spin_unlock_bh(&mvm->time_event_lock);
1046 mvmvif->phy_ctxt = NULL;
1047 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1048 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1051 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1053 /* clear the D3 reconfig, we only need it to avoid dumping a
1054 * firmware coredump on reconfiguration, we shouldn't do that
1055 * on D3->D0 transition
1057 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1058 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1059 iwl_fw_error_dump(&mvm->fwrt);
1062 /* cleanup all stale references (scan, roc), but keep the
1063 * ucode_down ref until reconfig is complete
1065 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1067 iwl_mvm_stop_device(mvm);
1069 mvm->scan_status = 0;
1070 mvm->ps_disabled = false;
1071 mvm->calibrating = false;
1073 /* just in case one was running */
1074 iwl_mvm_cleanup_roc_te(mvm);
1075 ieee80211_remain_on_channel_expired(mvm->hw);
1078 * cleanup all interfaces, even inactive ones, as some might have
1079 * gone down during the HW restart
1081 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1083 mvm->p2p_device_vif = NULL;
1084 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1086 iwl_mvm_reset_phy_ctxts(mvm);
1087 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1088 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1089 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1090 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1092 ieee80211_wake_queues(mvm->hw);
1094 /* clear any stale d0i3 state */
1095 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1098 mvm->rx_ba_sessions = 0;
1099 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1100 mvm->monitor_on = false;
1102 /* keep statistics ticking */
1103 iwl_mvm_accu_radio_stats(mvm);
1106 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1110 lockdep_assert_held(&mvm->mutex);
1112 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1114 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1115 * so later code will - from now on - see that we're doing it.
1117 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1118 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1119 /* Clean up some internal and mac80211 state on restart */
1120 iwl_mvm_restart_cleanup(mvm);
1122 /* Hold the reference to prevent runtime suspend while
1123 * the start procedure runs. It's a bit confusing
1124 * that the UCODE_DOWN reference is taken, but it just
1125 * means "UCODE is not UP yet". ( TODO: rename this
1128 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1130 ret = iwl_mvm_up(mvm);
1132 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1133 /* Something went wrong - we need to finish some cleanup
1134 * that normally iwl_mvm_mac_restart_complete() below
1137 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1139 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1146 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1148 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1151 /* Some hw restart cleanups must not hold the mutex */
1152 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1154 * Make sure we are out of d0i3. This is needed
1155 * to make sure the reference accounting is correct
1156 * (and there is no stale d0i3_exit_work).
1158 wait_event_timeout(mvm->d0i3_exit_waitq,
1159 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1164 mutex_lock(&mvm->mutex);
1165 ret = __iwl_mvm_mac_start(mvm);
1166 mutex_unlock(&mvm->mutex);
1171 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1175 mutex_lock(&mvm->mutex);
1177 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1179 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1181 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1183 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1186 /* allow transport/FW low power modes */
1187 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1190 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1191 * of packets the FW sent out, so we must reconnect.
1193 iwl_mvm_teardown_tdls_peers(mvm);
1195 mutex_unlock(&mvm->mutex);
1198 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1200 if (iwl_mvm_is_d0i3_supported(mvm) &&
1201 iwl_mvm_enter_d0i3_on_suspend(mvm))
1202 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1203 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1206 "D0i3 exit on resume timed out\n");
1210 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1211 enum ieee80211_reconfig_type reconfig_type)
1213 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1215 switch (reconfig_type) {
1216 case IEEE80211_RECONFIG_TYPE_RESTART:
1217 iwl_mvm_restart_complete(mvm);
1219 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1220 iwl_mvm_resume_complete(mvm);
1225 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1227 lockdep_assert_held(&mvm->mutex);
1229 /* firmware counters are obviously reset now, but we shouldn't
1230 * partially track so also clear the fw_reset_accu counters.
1232 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1234 /* async_handlers_wk is now blocked */
1237 * The work item could be running or queued if the
1238 * ROC time event stops just as we get here.
1240 flush_work(&mvm->roc_done_wk);
1242 iwl_mvm_stop_device(mvm);
1244 iwl_mvm_async_handlers_purge(mvm);
1245 /* async_handlers_list is empty and will stay empty: HW is stopped */
1247 /* the fw is stopped, the aux sta is dead: clean up driver state */
1248 iwl_mvm_del_aux_sta(mvm);
1251 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1252 * hw (as restart_complete() won't be called in this case) and mac80211
1253 * won't execute the restart.
1254 * But make sure to cleanup interfaces that have gone down before/during
1255 * HW restart was requested.
1257 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1258 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1260 ieee80211_iterate_interfaces(mvm->hw, 0,
1261 iwl_mvm_cleanup_iterator, mvm);
1263 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1264 * make sure there's nothing left there and warn if any is found.
1266 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1269 for (i = 0; i < mvm->max_scans; i++) {
1270 if (WARN_ONCE(mvm->scan_uid_status[i],
1271 "UMAC scan UID %d status was not cleaned\n",
1273 mvm->scan_uid_status[i] = 0;
1278 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1280 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1282 flush_work(&mvm->d0i3_exit_work);
1283 flush_work(&mvm->async_handlers_wk);
1284 flush_work(&mvm->add_stream_wk);
1287 * Lock and clear the firmware running bit here already, so that
1288 * new commands coming in elsewhere, e.g. from debugfs, will not
1289 * be able to proceed. This is important here because one of those
1290 * debugfs files causes the firmware dump to be triggered, and if we
1291 * don't stop debugfs accesses before canceling that it could be
1292 * retriggered after we flush it but before we've cleared the bit.
1294 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1296 iwl_fw_cancel_dump(&mvm->fwrt);
1297 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1298 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1299 iwl_fw_free_dump_desc(&mvm->fwrt);
1301 mutex_lock(&mvm->mutex);
1302 __iwl_mvm_mac_stop(mvm);
1303 mutex_unlock(&mvm->mutex);
1306 * The worker might have been waiting for the mutex, let it run and
1307 * discover that its list is now empty.
1309 cancel_work_sync(&mvm->async_handlers_wk);
1312 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1316 lockdep_assert_held(&mvm->mutex);
1318 for (i = 0; i < NUM_PHY_CTX; i++)
1319 if (!mvm->phy_ctxts[i].ref)
1320 return &mvm->phy_ctxts[i];
1322 IWL_ERR(mvm, "No available PHY context\n");
1326 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1331 struct iwl_dev_tx_power_cmd v5;
1332 struct iwl_dev_tx_power_cmd_v4 v4;
1334 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1335 .v5.v3.mac_context_id =
1336 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1337 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1340 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1341 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1343 if (fw_has_api(&mvm->fw->ucode_capa,
1344 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1345 len = sizeof(cmd.v5);
1346 else if (fw_has_capa(&mvm->fw->ucode_capa,
1347 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1348 len = sizeof(cmd.v4);
1350 len = sizeof(cmd.v4.v3);
1352 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1355 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1356 struct ieee80211_vif *vif)
1358 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1359 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1363 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1366 * make sure D0i3 exit is completed, otherwise a target access
1367 * during tx queue configuration could be done when still in
1370 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1375 * Not much to do here. The stack will not allow interface
1376 * types or combinations that we didn't advertise, so we
1377 * don't really have to check the types.
1380 mutex_lock(&mvm->mutex);
1382 /* make sure that beacon statistics don't go backwards with FW reset */
1383 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1384 mvmvif->beacon_stats.accu_num_beacons +=
1385 mvmvif->beacon_stats.num_beacons;
1387 /* Allocate resources for the MAC context, and add it to the fw */
1388 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1392 /* Counting number of interfaces is needed for legacy PM */
1393 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1397 * The AP binding flow can be done only after the beacon
1398 * template is configured (which happens only in the mac80211
1399 * start_ap() flow), and adding the broadcast station can happen
1400 * only after the binding.
1401 * In addition, since modifying the MAC before adding a bcast
1402 * station is not allowed by the FW, delay the adding of MAC context to
1403 * the point where we can also add the bcast station.
1404 * In short: there's not much we can do at this point, other than
1405 * allocating resources :)
1407 if (vif->type == NL80211_IFTYPE_AP ||
1408 vif->type == NL80211_IFTYPE_ADHOC) {
1409 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1411 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1416 * Only queue for this station is the mcast queue,
1417 * which shouldn't be in TFD mask anyway
1419 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1425 iwl_mvm_vif_dbgfs_register(mvm, vif);
1429 mvmvif->features |= hw->netdev_features;
1431 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1435 ret = iwl_mvm_power_update_mac(mvm);
1437 goto out_remove_mac;
1439 /* beacon filtering */
1440 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1442 goto out_remove_mac;
1444 if (!mvm->bf_allowed_vif &&
1445 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1446 mvm->bf_allowed_vif = mvmvif;
1447 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1448 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1452 * P2P_DEVICE interface does not have a channel context assigned to it,
1453 * so a dedicated PHY context is allocated to it and the corresponding
1454 * MAC context is bound to it at this stage.
1456 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1458 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1459 if (!mvmvif->phy_ctxt) {
1464 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1465 ret = iwl_mvm_binding_add_vif(mvm, vif);
1469 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1473 /* Save a pointer to p2p device vif, so it can later be used to
1474 * update the p2p device MAC when a GO is started/stopped */
1475 mvm->p2p_device_vif = vif;
1478 iwl_mvm_tcm_add_vif(mvm, vif);
1480 if (vif->type == NL80211_IFTYPE_MONITOR)
1481 mvm->monitor_on = true;
1483 iwl_mvm_vif_dbgfs_register(mvm, vif);
1487 iwl_mvm_binding_remove_vif(mvm, vif);
1489 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1491 if (mvm->bf_allowed_vif == mvmvif) {
1492 mvm->bf_allowed_vif = NULL;
1493 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1494 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1497 mvmvif->phy_ctxt = NULL;
1498 iwl_mvm_mac_ctxt_remove(mvm, vif);
1500 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1503 mutex_unlock(&mvm->mutex);
1505 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1510 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1511 struct ieee80211_vif *vif)
1513 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1515 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1516 * We assume here that all the packets sent to the OFFCHANNEL
1517 * queue are sent in ROC session.
1519 flush_work(&mvm->roc_done_wk);
1523 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1524 struct ieee80211_vif *vif)
1526 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1527 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1528 struct iwl_probe_resp_data *probe_data;
1530 iwl_mvm_prepare_mac_removal(mvm, vif);
1532 if (!(vif->type == NL80211_IFTYPE_AP ||
1533 vif->type == NL80211_IFTYPE_ADHOC))
1534 iwl_mvm_tcm_rm_vif(mvm, vif);
1536 mutex_lock(&mvm->mutex);
1538 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1539 lockdep_is_held(&mvm->mutex));
1540 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1542 kfree_rcu(probe_data, rcu_head);
1544 if (mvm->bf_allowed_vif == mvmvif) {
1545 mvm->bf_allowed_vif = NULL;
1546 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1547 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1550 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1553 * For AP/GO interface, the tear down of the resources allocated to the
1554 * interface is be handled as part of the stop_ap flow.
1556 if (vif->type == NL80211_IFTYPE_AP ||
1557 vif->type == NL80211_IFTYPE_ADHOC) {
1558 #ifdef CONFIG_NL80211_TESTMODE
1559 if (vif == mvm->noa_vif) {
1560 mvm->noa_vif = NULL;
1561 mvm->noa_duration = 0;
1564 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1565 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1569 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1570 mvm->p2p_device_vif = NULL;
1571 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1572 iwl_mvm_binding_remove_vif(mvm, vif);
1573 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1574 mvmvif->phy_ctxt = NULL;
1577 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1580 iwl_mvm_power_update_mac(mvm);
1581 iwl_mvm_mac_ctxt_remove(mvm, vif);
1583 if (vif->type == NL80211_IFTYPE_MONITOR)
1584 mvm->monitor_on = false;
1587 mutex_unlock(&mvm->mutex);
1590 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1595 struct iwl_mvm_mc_iter_data {
1596 struct iwl_mvm *mvm;
1600 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1601 struct ieee80211_vif *vif)
1603 struct iwl_mvm_mc_iter_data *data = _data;
1604 struct iwl_mvm *mvm = data->mvm;
1605 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1606 struct iwl_host_cmd hcmd = {
1607 .id = MCAST_FILTER_CMD,
1609 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1613 /* if we don't have free ports, mcast frames will be dropped */
1614 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1617 if (vif->type != NL80211_IFTYPE_STATION ||
1618 !vif->bss_conf.assoc)
1621 cmd->port_id = data->port_id++;
1622 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1623 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1628 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1630 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1633 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1635 struct iwl_mvm_mc_iter_data iter_data = {
1639 lockdep_assert_held(&mvm->mutex);
1641 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1644 ieee80211_iterate_active_interfaces_atomic(
1645 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1646 iwl_mvm_mc_iface_iterator, &iter_data);
1649 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1650 struct netdev_hw_addr_list *mc_list)
1652 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1653 struct iwl_mcast_filter_cmd *cmd;
1654 struct netdev_hw_addr *addr;
1659 addr_count = netdev_hw_addr_list_count(mc_list);
1660 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1661 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1665 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1666 cmd = kzalloc(len, GFP_ATOMIC);
1672 return (u64)(unsigned long)cmd;
1675 netdev_hw_addr_list_for_each(addr, mc_list) {
1676 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1677 cmd->count, addr->addr);
1678 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1679 addr->addr, ETH_ALEN);
1683 return (u64)(unsigned long)cmd;
1686 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1687 unsigned int changed_flags,
1688 unsigned int *total_flags,
1691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1692 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1694 mutex_lock(&mvm->mutex);
1696 /* replace previous configuration */
1697 kfree(mvm->mcast_filter_cmd);
1698 mvm->mcast_filter_cmd = cmd;
1703 if (changed_flags & FIF_ALLMULTI)
1704 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1709 iwl_mvm_recalc_multicast(mvm);
1711 mutex_unlock(&mvm->mutex);
1715 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1716 struct ieee80211_vif *vif,
1717 unsigned int filter_flags,
1718 unsigned int changed_flags)
1720 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1722 /* We support only filter for probe requests */
1723 if (!(changed_flags & FIF_PROBE_REQ))
1726 /* Supported only for p2p client interfaces */
1727 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1731 mutex_lock(&mvm->mutex);
1732 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1733 mutex_unlock(&mvm->mutex);
1736 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1737 struct iwl_bcast_iter_data {
1738 struct iwl_mvm *mvm;
1739 struct iwl_bcast_filter_cmd *cmd;
1744 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1745 const struct iwl_fw_bcast_filter *in_filter,
1746 struct iwl_fw_bcast_filter *out_filter)
1748 struct iwl_fw_bcast_filter_attr *attr;
1751 memcpy(out_filter, in_filter, sizeof(*out_filter));
1753 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1754 attr = &out_filter->attrs[i];
1759 switch (attr->reserved1) {
1760 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1761 if (vif->bss_conf.arp_addr_cnt != 1) {
1766 attr->val = vif->bss_conf.arp_addr_list[0];
1768 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1769 attr->val = *(__be32 *)&vif->addr[2];
1774 attr->reserved1 = 0;
1775 out_filter->num_attrs++;
1779 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1780 struct ieee80211_vif *vif)
1782 struct iwl_bcast_iter_data *data = _data;
1783 struct iwl_mvm *mvm = data->mvm;
1784 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1785 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1786 struct iwl_fw_bcast_mac *bcast_mac;
1789 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1792 bcast_mac = &cmd->macs[mvmvif->id];
1795 * enable filtering only for associated stations, but not for P2P
1798 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1799 !vif->bss_conf.assoc)
1802 bcast_mac->default_discard = 1;
1804 /* copy all configured filters */
1805 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1807 * Make sure we don't exceed our filters limit.
1808 * if there is still a valid filter to be configured,
1809 * be on the safe side and just allow bcast for this mac.
1811 if (WARN_ON_ONCE(data->current_filter >=
1812 ARRAY_SIZE(cmd->filters))) {
1813 bcast_mac->default_discard = 0;
1814 bcast_mac->attached_filters = 0;
1818 iwl_mvm_set_bcast_filter(vif,
1819 &mvm->bcast_filters[i],
1820 &cmd->filters[data->current_filter]);
1822 /* skip current filter if it contains no attributes */
1823 if (!cmd->filters[data->current_filter].num_attrs)
1826 /* attach the filter to current mac */
1827 bcast_mac->attached_filters |=
1828 cpu_to_le16(BIT(data->current_filter));
1830 data->current_filter++;
1834 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1835 struct iwl_bcast_filter_cmd *cmd)
1837 struct iwl_bcast_iter_data iter_data = {
1842 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1845 memset(cmd, 0, sizeof(*cmd));
1846 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1847 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1849 #ifdef CONFIG_IWLWIFI_DEBUGFS
1850 /* use debugfs filters/macs if override is configured */
1851 if (mvm->dbgfs_bcast_filtering.override) {
1852 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1853 sizeof(cmd->filters));
1854 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1860 /* if no filters are configured, do nothing */
1861 if (!mvm->bcast_filters)
1864 /* configure and attach these filters for each associated sta vif */
1865 ieee80211_iterate_active_interfaces(
1866 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1867 iwl_mvm_bcast_filter_iterator, &iter_data);
1872 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1874 struct iwl_bcast_filter_cmd cmd;
1876 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1879 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1882 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1886 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1892 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1893 struct ieee80211_vif *vif)
1895 struct iwl_mu_group_mgmt_cmd cmd = {};
1897 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1898 WLAN_MEMBERSHIP_LEN);
1899 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1900 WLAN_USER_POSITION_LEN);
1902 return iwl_mvm_send_cmd_pdu(mvm,
1903 WIDE_ID(DATA_PATH_GROUP,
1904 UPDATE_MU_GROUPS_CMD),
1905 0, sizeof(cmd), &cmd);
1908 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1909 struct ieee80211_vif *vif)
1911 if (vif->mu_mimo_owner) {
1912 struct iwl_mu_group_mgmt_notif *notif = _data;
1915 * MU-MIMO Group Id action frame is little endian. We treat
1916 * the data received from firmware as if it came from the
1917 * action frame, so no conversion is needed.
1919 ieee80211_update_mu_groups(vif,
1920 (u8 *)¬if->membership_status,
1921 (u8 *)¬if->user_position);
1925 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1926 struct iwl_rx_cmd_buffer *rxb)
1928 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1929 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1931 ieee80211_iterate_active_interfaces_atomic(
1932 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1933 iwl_mvm_mu_mimo_iface_iterator, notif);
1936 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1938 u8 byte_num = ppe_pos_bit / 8;
1939 u8 bit_num = ppe_pos_bit % 8;
1944 return (ppe[byte_num] >> bit_num) &
1945 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1948 * If bit_num > 5, we have to combine bits with next byte.
1949 * Calculate how many bits we need to take from current byte (called
1950 * here "residue_bits"), and add them to bits from next byte.
1953 residue_bits = 8 - bit_num;
1955 res = (ppe[byte_num + 1] &
1956 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1958 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1963 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1964 struct ieee80211_vif *vif, u8 sta_id)
1966 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1967 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1969 .tid_limit = IWL_MAX_TID_COUNT,
1970 .bss_color = vif->bss_conf.bss_color,
1971 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1972 .frame_time_rts_th =
1973 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1975 struct ieee80211_sta *sta;
1981 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1984 WARN(1, "Can't find STA to configure HE\n");
1988 if (!sta->he_cap.has_he) {
1996 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1997 IEEE80211_HE_MAC_CAP0_HTC_HE)
1998 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1999 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2000 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2001 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2002 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2004 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2005 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2006 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2007 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2010 sta_ctxt_cmd.htc_flags |=
2011 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2012 else if (link_adap == 3)
2013 sta_ctxt_cmd.htc_flags |=
2014 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2016 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2017 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2018 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2019 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2020 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2021 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2022 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2024 /* If PPE Thresholds exist, parse them into a FW-familiar format */
2025 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2026 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2027 u8 nss = (sta->he_cap.ppe_thres[0] &
2028 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2029 u8 ru_index_bitmap =
2030 (sta->he_cap.ppe_thres[0] &
2031 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2032 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2033 u8 *ppe = &sta->he_cap.ppe_thres[0];
2034 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2037 * FW currently supports only nss == MAX_HE_SUPP_NSS
2039 * If nss > MAX: we can ignore values we don't support
2040 * If nss < MAX: we can set zeros in other streams
2042 if (nss > MAX_HE_SUPP_NSS) {
2043 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2045 nss = MAX_HE_SUPP_NSS;
2048 for (i = 0; i < nss; i++) {
2049 u8 ru_index_tmp = ru_index_bitmap << 1;
2052 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2054 if (!(ru_index_tmp & 1))
2057 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2058 iwl_mvm_he_get_ppe_val(ppe,
2061 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2062 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2063 iwl_mvm_he_get_ppe_val(ppe,
2066 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2070 flags |= STA_CTXT_HE_PACKET_EXT;
2074 /* Mark MU EDCA as enabled, unless none detected on some AC */
2075 flags |= STA_CTXT_HE_MU_EDCA_CW;
2076 for (i = 0; i < AC_NUM; i++) {
2077 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2078 &mvmvif->queue_params[i].mu_edca_param_rec;
2080 if (!mvmvif->queue_params[i].mu_edca) {
2081 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2085 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2086 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2087 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2088 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2089 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2090 cpu_to_le16(mu_edca->aifsn);
2091 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2092 cpu_to_le16(mu_edca->mu_edca_timer);
2095 if (vif->bss_conf.multi_sta_back_32bit)
2096 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2098 if (vif->bss_conf.ack_enabled)
2099 flags |= STA_CTXT_HE_ACK_ENABLED;
2101 if (vif->bss_conf.uora_exists) {
2102 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2104 sta_ctxt_cmd.rand_alloc_ecwmin =
2105 vif->bss_conf.uora_ocw_range & 0x7;
2106 sta_ctxt_cmd.rand_alloc_ecwmax =
2107 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2110 /* TODO: support Multi BSSID IE */
2112 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2114 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2115 DATA_PATH_GROUP, 0),
2116 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2117 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2120 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2121 struct ieee80211_vif *vif,
2122 struct ieee80211_bss_conf *bss_conf,
2125 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2129 * Re-calculate the tsf id, as the master-slave relations depend on the
2130 * beacon interval, which was not known when the station interface was
2133 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2134 if (vif->bss_conf.he_support &&
2135 !iwlwifi_mod_params.disable_11ax)
2136 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2138 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2142 * If we're not associated yet, take the (new) BSSID before associating
2143 * so the firmware knows. If we're already associated, then use the old
2144 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2145 * branch for disassociation below.
2147 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2148 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2150 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2152 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2154 /* after sending it once, adopt mac80211 data */
2155 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2156 mvmvif->associated = bss_conf->assoc;
2158 if (changes & BSS_CHANGED_ASSOC) {
2159 if (bss_conf->assoc) {
2160 /* clear statistics to get clean beacon counter */
2161 iwl_mvm_request_statistics(mvm, true);
2162 memset(&mvmvif->beacon_stats, 0,
2163 sizeof(mvmvif->beacon_stats));
2165 /* add quota for this interface */
2166 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2168 IWL_ERR(mvm, "failed to update quotas\n");
2172 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2175 * If we're restarting then the firmware will
2176 * obviously have lost synchronisation with
2177 * the AP. It will attempt to synchronise by
2178 * itself, but we can make it more reliable by
2179 * scheduling a session protection time event.
2181 * The firmware needs to receive a beacon to
2182 * catch up with synchronisation, use 110% of
2183 * the beacon interval.
2185 * Set a large maximum delay to allow for more
2186 * than a single interface.
2188 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2189 iwl_mvm_protect_session(mvm, vif, dur, dur,
2193 iwl_mvm_sf_update(mvm, vif, false);
2194 iwl_mvm_power_vif_assoc(mvm, vif);
2196 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2197 iwl_mvm_update_smps(mvm, vif,
2198 IWL_MVM_SMPS_REQ_PROT,
2199 IEEE80211_SMPS_DYNAMIC);
2201 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2203 * If update fails - SF might be running in associated
2204 * mode while disassociated - which is forbidden.
2206 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2207 "Failed to update SF upon disassociation\n");
2210 * If we get an assert during the connection (after the
2211 * station has been added, but before the vif is set
2212 * to associated), mac80211 will re-add the station and
2213 * then configure the vif. Since the vif is not
2214 * associated, we would remove the station here and
2215 * this would fail the recovery.
2217 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2220 * Remove AP station now that
2221 * the MAC is unassoc
2223 ret = iwl_mvm_rm_sta_id(mvm, vif,
2227 "failed to remove AP station\n");
2229 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2230 mvm->d0i3_ap_sta_id =
2231 IWL_MVM_INVALID_STA;
2232 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2235 /* remove quota for this interface */
2236 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2238 IWL_ERR(mvm, "failed to update quotas\n");
2241 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2243 /* this will take the cleared BSSID from bss_conf */
2244 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2247 "failed to update MAC %pM (clear after unassoc)\n",
2252 * The firmware tracks the MU-MIMO group on its own.
2253 * However, on HW restart we should restore this data.
2255 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2256 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2257 ret = iwl_mvm_update_mu_groups(mvm, vif);
2260 "failed to update VHT MU_MIMO groups\n");
2263 iwl_mvm_recalc_multicast(mvm);
2264 iwl_mvm_configure_bcast_filter(mvm);
2266 /* reset rssi values */
2267 mvmvif->bf_data.ave_beacon_signal = 0;
2269 iwl_mvm_bt_coex_vif_change(mvm);
2270 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2271 IEEE80211_SMPS_AUTOMATIC);
2272 if (fw_has_capa(&mvm->fw->ucode_capa,
2273 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2274 iwl_mvm_config_scan(mvm);
2277 if (changes & BSS_CHANGED_BEACON_INFO) {
2279 * We received a beacon from the associated AP so
2280 * remove the session protection.
2282 iwl_mvm_stop_session_protection(mvm, vif);
2284 iwl_mvm_sf_update(mvm, vif, false);
2285 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2288 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2290 * Send power command on every beacon change,
2291 * because we may have not enabled beacon abort yet.
2293 BSS_CHANGED_BEACON_INFO)) {
2294 ret = iwl_mvm_power_update_mac(mvm);
2296 IWL_ERR(mvm, "failed to update power mode\n");
2299 if (changes & BSS_CHANGED_TXPOWER) {
2300 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2302 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2305 if (changes & BSS_CHANGED_CQM) {
2306 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2307 /* reset cqm events tracking */
2308 mvmvif->bf_data.last_cqm_event = 0;
2309 if (mvmvif->bf_data.bf_enabled) {
2310 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2313 "failed to update CQM thresholds\n");
2317 if (changes & BSS_CHANGED_ARP_FILTER) {
2318 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2319 iwl_mvm_configure_bcast_filter(mvm);
2323 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2324 struct ieee80211_vif *vif)
2326 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2327 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2331 * iwl_mvm_mac_ctxt_add() might read directly from the device
2332 * (the system time), so make sure it is available.
2334 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2338 mutex_lock(&mvm->mutex);
2340 /* Send the beacon template */
2341 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2346 * Re-calculate the tsf id, as the master-slave relations depend on the
2347 * beacon interval, which was not known when the AP interface was added.
2349 if (vif->type == NL80211_IFTYPE_AP)
2350 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2352 mvmvif->ap_assoc_sta_count = 0;
2354 /* Add the mac context */
2355 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2359 /* Perform the binding */
2360 ret = iwl_mvm_binding_add_vif(mvm, vif);
2365 * This is not very nice, but the simplest:
2366 * For older FWs adding the mcast sta before the bcast station may
2367 * cause assert 0x2b00.
2368 * This is fixed in later FW so make the order of removal depend on
2371 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2372 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2376 * Send the bcast station. At this stage the TBTT and DTIM time
2377 * events are added and applied to the scheduler
2379 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2381 iwl_mvm_rm_mcast_sta(mvm, vif);
2386 * Send the bcast station. At this stage the TBTT and DTIM time
2387 * events are added and applied to the scheduler
2389 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2392 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2394 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2399 /* must be set before quota calculations */
2400 mvmvif->ap_ibss_active = true;
2402 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2403 iwl_mvm_vif_set_low_latency(mvmvif, true,
2404 LOW_LATENCY_VIF_TYPE);
2405 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2408 /* power updated needs to be done before quotas */
2409 iwl_mvm_power_update_mac(mvm);
2411 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2413 goto out_quota_failed;
2415 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2416 if (vif->p2p && mvm->p2p_device_vif)
2417 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2419 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2421 iwl_mvm_bt_coex_vif_change(mvm);
2423 /* we don't support TDLS during DCM */
2424 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2425 iwl_mvm_teardown_tdls_peers(mvm);
2430 iwl_mvm_power_update_mac(mvm);
2431 mvmvif->ap_ibss_active = false;
2432 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2433 iwl_mvm_rm_mcast_sta(mvm, vif);
2435 iwl_mvm_binding_remove_vif(mvm, vif);
2437 iwl_mvm_mac_ctxt_remove(mvm, vif);
2439 mutex_unlock(&mvm->mutex);
2440 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2444 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2445 struct ieee80211_vif *vif)
2447 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2448 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2450 iwl_mvm_prepare_mac_removal(mvm, vif);
2452 mutex_lock(&mvm->mutex);
2454 /* Handle AP stop while in CSA */
2455 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2456 iwl_mvm_remove_time_event(mvm, mvmvif,
2457 &mvmvif->time_event_data);
2458 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2459 mvmvif->csa_countdown = false;
2462 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2463 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2464 mvm->csa_tx_block_bcn_timeout = 0;
2467 mvmvif->ap_ibss_active = false;
2468 mvm->ap_last_beacon_gp2 = 0;
2470 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2471 iwl_mvm_vif_set_low_latency(mvmvif, false,
2472 LOW_LATENCY_VIF_TYPE);
2473 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2476 iwl_mvm_bt_coex_vif_change(mvm);
2478 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2480 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2481 if (vif->p2p && mvm->p2p_device_vif)
2482 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2484 iwl_mvm_update_quotas(mvm, false, NULL);
2487 * This is not very nice, but the simplest:
2488 * For older FWs removing the mcast sta before the bcast station may
2489 * cause assert 0x2b00.
2490 * This is fixed in later FW (which will stop beaconing when removing
2492 * So make the order of removal depend on the TLV
2494 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2495 iwl_mvm_rm_mcast_sta(mvm, vif);
2496 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2497 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2498 iwl_mvm_rm_mcast_sta(mvm, vif);
2499 iwl_mvm_binding_remove_vif(mvm, vif);
2501 iwl_mvm_power_update_mac(mvm);
2503 iwl_mvm_mac_ctxt_remove(mvm, vif);
2505 kfree(mvmvif->ap_wep_key);
2506 mvmvif->ap_wep_key = NULL;
2508 mutex_unlock(&mvm->mutex);
2512 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2513 struct ieee80211_vif *vif,
2514 struct ieee80211_bss_conf *bss_conf,
2517 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2519 /* Changes will be applied when the AP/IBSS is started */
2520 if (!mvmvif->ap_ibss_active)
2523 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2524 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2525 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2526 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2528 /* Need to send a new beacon template to the FW */
2529 if (changes & BSS_CHANGED_BEACON &&
2530 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2531 IWL_WARN(mvm, "Failed updating beacon data\n");
2533 if (changes & BSS_CHANGED_TXPOWER) {
2534 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2536 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2540 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2541 struct ieee80211_vif *vif,
2542 struct ieee80211_bss_conf *bss_conf,
2545 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2548 * iwl_mvm_bss_info_changed_station() might call
2549 * iwl_mvm_protect_session(), which reads directly from
2550 * the device (the system time), so make sure it is available.
2552 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2555 mutex_lock(&mvm->mutex);
2557 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2558 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2560 switch (vif->type) {
2561 case NL80211_IFTYPE_STATION:
2562 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2564 case NL80211_IFTYPE_AP:
2565 case NL80211_IFTYPE_ADHOC:
2566 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2568 case NL80211_IFTYPE_MONITOR:
2569 if (changes & BSS_CHANGED_MU_GROUPS)
2570 iwl_mvm_update_mu_groups(mvm, vif);
2573 /* shouldn't happen */
2577 mutex_unlock(&mvm->mutex);
2578 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2581 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2582 struct ieee80211_vif *vif,
2583 struct ieee80211_scan_request *hw_req)
2585 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2588 if (hw_req->req.n_channels == 0 ||
2589 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2592 mutex_lock(&mvm->mutex);
2593 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2594 mutex_unlock(&mvm->mutex);
2599 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2600 struct ieee80211_vif *vif)
2602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2604 mutex_lock(&mvm->mutex);
2606 /* Due to a race condition, it's possible that mac80211 asks
2607 * us to stop a hw_scan when it's already stopped. This can
2608 * happen, for instance, if we stopped the scan ourselves,
2609 * called ieee80211_scan_completed() and the userspace called
2610 * cancel scan scan before ieee80211_scan_work() could run.
2611 * To handle that, simply return if the scan is not running.
2613 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2614 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2616 mutex_unlock(&mvm->mutex);
2620 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2621 struct ieee80211_sta *sta, u16 tids,
2623 enum ieee80211_frame_release_type reason,
2626 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2628 /* Called when we need to transmit (a) frame(s) from mac80211 */
2630 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2631 tids, more_data, false);
2635 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2636 struct ieee80211_sta *sta, u16 tids,
2638 enum ieee80211_frame_release_type reason,
2641 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2643 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2645 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2646 tids, more_data, true);
2649 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2650 enum sta_notify_cmd cmd,
2651 struct ieee80211_sta *sta)
2653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2654 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2655 unsigned long txqs = 0, tids = 0;
2659 * If we have TVQM then we get too high queue numbers - luckily
2660 * we really shouldn't get here with that because such hardware
2661 * should have firmware supporting buffer station offload.
2663 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2666 spin_lock_bh(&mvmsta->lock);
2667 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2668 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2670 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2673 __set_bit(tid_data->txq_id, &txqs);
2675 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2678 __set_bit(tid, &tids);
2682 case STA_NOTIFY_SLEEP:
2683 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2684 ieee80211_sta_set_buffered(sta, tid, true);
2687 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2689 * The fw updates the STA to be asleep. Tx packets on the Tx
2690 * queues to this station will not be transmitted. The fw will
2691 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2694 case STA_NOTIFY_AWAKE:
2695 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2699 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2700 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2705 spin_unlock_bh(&mvmsta->lock);
2708 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2709 struct ieee80211_vif *vif,
2710 enum sta_notify_cmd cmd,
2711 struct ieee80211_sta *sta)
2713 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2716 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2718 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2719 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2720 struct ieee80211_sta *sta;
2721 struct iwl_mvm_sta *mvmsta;
2722 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2724 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2728 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2729 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2734 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2737 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2742 if (mvmsta->sleeping != sleeping) {
2743 mvmsta->sleeping = sleeping;
2744 __iwl_mvm_mac_sta_notify(mvm->hw,
2745 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2747 ieee80211_sta_ps_transition(sta, sleeping);
2751 switch (notif->type) {
2752 case IWL_MVM_PM_EVENT_AWAKE:
2753 case IWL_MVM_PM_EVENT_ASLEEP:
2755 case IWL_MVM_PM_EVENT_UAPSD:
2756 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2758 case IWL_MVM_PM_EVENT_PS_POLL:
2759 ieee80211_sta_pspoll(sta);
2769 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2770 struct ieee80211_vif *vif,
2771 struct ieee80211_sta *sta)
2773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2774 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2777 * This is called before mac80211 does RCU synchronisation,
2778 * so here we already invalidate our internal RCU-protected
2779 * station pointer. The rest of the code will thus no longer
2780 * be able to find the station this way, and we don't rely
2781 * on further RCU synchronisation after the sta_state()
2782 * callback deleted the station.
2784 mutex_lock(&mvm->mutex);
2785 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2786 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2789 mutex_unlock(&mvm->mutex);
2792 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2797 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2798 struct iwl_mvm_tcm_mac *mdata;
2800 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2801 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2802 mdata->opened_rx_ba_sessions = false;
2805 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2808 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2809 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2814 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2815 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2819 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2820 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2821 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2826 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2830 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2831 struct ieee80211_vif *vif, u8 *peer_addr,
2832 enum nl80211_tdls_operation action)
2834 struct iwl_fw_dbg_trigger_tlv *trig;
2835 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2837 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2838 FW_DBG_TRIGGER_TDLS);
2842 tdls_trig = (void *)trig->data;
2844 if (!(tdls_trig->action_bitmap & BIT(action)))
2847 if (tdls_trig->peer_mode &&
2848 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2851 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2852 "TDLS event occurred, peer %pM, action %d",
2856 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2857 struct iwl_mvm_sta *mvm_sta)
2859 struct iwl_mvm_tid_data *tid_data;
2860 struct sk_buff *skb;
2863 spin_lock_bh(&mvm_sta->lock);
2864 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2865 tid_data = &mvm_sta->tid_data[i];
2867 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2868 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2871 * The first deferred frame should've stopped the MAC
2872 * queues, so we should never get a second deferred
2873 * frame for the RA/TID.
2875 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2876 ieee80211_free_txskb(mvm->hw, skb);
2879 spin_unlock_bh(&mvm_sta->lock);
2882 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2883 struct ieee80211_vif *vif,
2884 struct ieee80211_sta *sta,
2885 enum ieee80211_sta_state old_state,
2886 enum ieee80211_sta_state new_state)
2888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2889 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2890 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2893 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2894 sta->addr, old_state, new_state);
2896 /* this would be a mac80211 bug ... but don't crash */
2897 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2901 * If we are in a STA removal flow and in DQA mode:
2903 * This is after the sync_rcu part, so the queues have already been
2904 * flushed. No more TXs on their way in mac80211's path, and no more in
2906 * Also, we won't be getting any new TX frames for this station.
2907 * What we might have are deferred TX frames that need to be taken care
2910 * Drop any still-queued deferred-frame before removing the STA, and
2911 * make sure the worker is no longer handling frames for this STA.
2913 if (old_state == IEEE80211_STA_NONE &&
2914 new_state == IEEE80211_STA_NOTEXIST) {
2915 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2916 flush_work(&mvm->add_stream_wk);
2919 * No need to make sure deferred TX indication is off since the
2920 * worker will already remove it if it was on
2924 mutex_lock(&mvm->mutex);
2925 /* track whether or not the station is associated */
2926 mvm_sta->sta_state = new_state;
2928 if (old_state == IEEE80211_STA_NOTEXIST &&
2929 new_state == IEEE80211_STA_NONE) {
2931 * Firmware bug - it'll crash if the beacon interval is less
2932 * than 16. We can't avoid connecting at all, so refuse the
2933 * station state change, this will cause mac80211 to abandon
2934 * attempts to connect to this AP, and eventually wpa_s will
2935 * blacklist the AP...
2937 if (vif->type == NL80211_IFTYPE_STATION &&
2938 vif->bss_conf.beacon_int < 16) {
2940 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2941 sta->addr, vif->bss_conf.beacon_int);
2948 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2949 IWL_MVM_TDLS_STA_COUNT ||
2950 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2951 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2956 ret = iwl_mvm_add_sta(mvm, vif, sta);
2957 if (sta->tdls && ret == 0) {
2958 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2959 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2960 NL80211_TDLS_SETUP);
2962 } else if (old_state == IEEE80211_STA_NONE &&
2963 new_state == IEEE80211_STA_AUTH) {
2965 * EBS may be disabled due to previous failures reported by FW.
2966 * Reset EBS status here assuming environment has been changed.
2968 mvm->last_ebs_successful = true;
2969 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2971 } else if (old_state == IEEE80211_STA_AUTH &&
2972 new_state == IEEE80211_STA_ASSOC) {
2973 if (vif->type == NL80211_IFTYPE_AP) {
2974 mvmvif->ap_assoc_sta_count++;
2975 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2976 if (vif->bss_conf.he_support &&
2977 !iwlwifi_mod_params.disable_11ax)
2978 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
2981 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2983 ret = iwl_mvm_update_sta(mvm, vif, sta);
2984 } else if (old_state == IEEE80211_STA_ASSOC &&
2985 new_state == IEEE80211_STA_AUTHORIZED) {
2987 /* we don't support TDLS during DCM */
2988 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2989 iwl_mvm_teardown_tdls_peers(mvm);
2992 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2993 NL80211_TDLS_ENABLE_LINK);
2995 /* enable beacon filtering */
2996 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2998 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3001 /* if wep is used, need to set the key for the station now */
3002 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
3003 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
3005 STA_KEY_IDX_INVALID);
3008 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3009 new_state == IEEE80211_STA_ASSOC) {
3010 /* disable beacon filtering */
3011 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
3013 } else if (old_state == IEEE80211_STA_ASSOC &&
3014 new_state == IEEE80211_STA_AUTH) {
3015 if (vif->type == NL80211_IFTYPE_AP) {
3016 mvmvif->ap_assoc_sta_count--;
3017 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3020 } else if (old_state == IEEE80211_STA_AUTH &&
3021 new_state == IEEE80211_STA_NONE) {
3023 } else if (old_state == IEEE80211_STA_NONE &&
3024 new_state == IEEE80211_STA_NOTEXIST) {
3025 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3027 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3028 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3029 NL80211_TDLS_DISABLE_LINK);
3035 mutex_unlock(&mvm->mutex);
3037 if (sta->tdls && ret == 0) {
3038 if (old_state == IEEE80211_STA_NOTEXIST &&
3039 new_state == IEEE80211_STA_NONE)
3040 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3041 else if (old_state == IEEE80211_STA_NONE &&
3042 new_state == IEEE80211_STA_NOTEXIST)
3043 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3049 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3051 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3053 mvm->rts_threshold = value;
3058 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3059 struct ieee80211_vif *vif,
3060 struct ieee80211_sta *sta, u32 changed)
3062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3064 if (vif->type == NL80211_IFTYPE_STATION &&
3065 changed & IEEE80211_RC_NSS_CHANGED)
3066 iwl_mvm_sf_update(mvm, vif, false);
3069 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3070 struct ieee80211_vif *vif, u16 ac,
3071 const struct ieee80211_tx_queue_params *params)
3073 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3074 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3076 mvmvif->queue_params[ac] = *params;
3079 * No need to update right away, we'll get BSS_CHANGED_QOS
3080 * The exception is P2P_DEVICE interface which needs immediate update.
3082 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3085 mutex_lock(&mvm->mutex);
3086 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3087 mutex_unlock(&mvm->mutex);
3093 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3094 struct ieee80211_vif *vif,
3097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3098 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3099 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3102 * iwl_mvm_protect_session() reads directly from the device
3103 * (the system time), so make sure it is available.
3105 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3108 if (req_duration > duration)
3109 duration = req_duration;
3111 mutex_lock(&mvm->mutex);
3112 /* Try really hard to protect the session and hear a beacon */
3113 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3114 mutex_unlock(&mvm->mutex);
3116 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3119 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3120 struct ieee80211_vif *vif,
3121 struct cfg80211_sched_scan_request *req,
3122 struct ieee80211_scan_ies *ies)
3124 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3128 mutex_lock(&mvm->mutex);
3130 if (!vif->bss_conf.idle) {
3135 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3138 mutex_unlock(&mvm->mutex);
3142 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3143 struct ieee80211_vif *vif)
3145 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3148 mutex_lock(&mvm->mutex);
3150 /* Due to a race condition, it's possible that mac80211 asks
3151 * us to stop a sched_scan when it's already stopped. This
3152 * can happen, for instance, if we stopped the scan ourselves,
3153 * called ieee80211_sched_scan_stopped() and the userspace called
3154 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3155 * could run. To handle this, simply return if the scan is
3158 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3159 mutex_unlock(&mvm->mutex);
3163 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3164 mutex_unlock(&mvm->mutex);
3165 iwl_mvm_wait_for_async_handlers(mvm);
3170 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3171 enum set_key_cmd cmd,
3172 struct ieee80211_vif *vif,
3173 struct ieee80211_sta *sta,
3174 struct ieee80211_key_conf *key)
3176 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3177 struct iwl_mvm_sta *mvmsta;
3178 struct iwl_mvm_key_pn *ptk_pn;
3179 int keyidx = key->keyidx;
3183 if (iwlwifi_mod_params.swcrypto) {
3184 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3188 switch (key->cipher) {
3189 case WLAN_CIPHER_SUITE_TKIP:
3190 if (!mvm->trans->cfg->gen2) {
3191 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3192 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3193 } else if (vif->type == NL80211_IFTYPE_STATION) {
3194 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3196 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3200 case WLAN_CIPHER_SUITE_CCMP:
3201 case WLAN_CIPHER_SUITE_GCMP:
3202 case WLAN_CIPHER_SUITE_GCMP_256:
3203 if (!iwl_mvm_has_new_tx_api(mvm))
3204 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3206 case WLAN_CIPHER_SUITE_AES_CMAC:
3207 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3208 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3209 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3211 case WLAN_CIPHER_SUITE_WEP40:
3212 case WLAN_CIPHER_SUITE_WEP104:
3213 if (vif->type == NL80211_IFTYPE_AP) {
3214 struct iwl_mvm_vif *mvmvif =
3215 iwl_mvm_vif_from_mac80211(vif);
3217 mvmvif->ap_wep_key = kmemdup(key,
3218 sizeof(*key) + key->keylen,
3220 if (!mvmvif->ap_wep_key)
3224 if (vif->type != NL80211_IFTYPE_STATION)
3228 /* currently FW supports only one optional cipher scheme */
3229 if (hw->n_cipher_schemes &&
3230 hw->cipher_schemes->cipher == key->cipher)
3231 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3236 mutex_lock(&mvm->mutex);
3240 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3241 vif->type == NL80211_IFTYPE_AP) && !sta) {
3243 * GTK on AP interface is a TX-only key, return 0;
3244 * on IBSS they're per-station and because we're lazy
3245 * we don't support them for RX, so do the same.
3246 * CMAC/GMAC in AP/IBSS modes must be done in software.
3248 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3249 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3250 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3255 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3256 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3257 !iwl_mvm_has_new_tx_api(mvm)) {
3258 key->hw_key_idx = STA_KEY_IDX_INVALID;
3263 /* During FW restart, in order to restore the state as it was,
3264 * don't try to reprogram keys we previously failed for.
3266 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3267 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3268 IWL_DEBUG_MAC80211(mvm,
3269 "skip invalid idx key programming during restart\n");
3274 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3275 sta && iwl_mvm_has_new_rx_api(mvm) &&
3276 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3277 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3278 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3279 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3280 struct ieee80211_key_seq seq;
3283 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3284 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3285 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3286 mvm->trans->num_rx_queues),
3293 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3294 ieee80211_get_key_rx_seq(key, tid, &seq);
3295 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3296 memcpy(ptk_pn->q[q].pn[tid],
3298 IEEE80211_CCMP_PN_LEN);
3301 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3304 /* in HW restart reuse the index, otherwise request a new one */
3305 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3306 key_offset = key->hw_key_idx;
3308 key_offset = STA_KEY_IDX_INVALID;
3310 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3311 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3313 IWL_WARN(mvm, "set key failed\n");
3315 * can't add key for RX, but we don't need it
3316 * in the device for TX so still return 0
3318 key->hw_key_idx = STA_KEY_IDX_INVALID;
3324 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3329 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3330 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3331 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3332 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3333 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3334 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3335 ptk_pn = rcu_dereference_protected(
3336 mvmsta->ptk_pn[keyidx],
3337 lockdep_is_held(&mvm->mutex));
3338 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3340 kfree_rcu(ptk_pn, rcu_head);
3343 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3344 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3350 mutex_unlock(&mvm->mutex);
3354 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3355 struct ieee80211_vif *vif,
3356 struct ieee80211_key_conf *keyconf,
3357 struct ieee80211_sta *sta,
3358 u32 iv32, u16 *phase1key)
3360 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3362 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3365 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3369 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3370 struct iwl_rx_packet *pkt, void *data)
3372 struct iwl_mvm *mvm =
3373 container_of(notif_wait, struct iwl_mvm, notif_wait);
3374 struct iwl_hs20_roc_res *resp;
3375 int resp_len = iwl_rx_packet_payload_len(pkt);
3376 struct iwl_mvm_time_event_data *te_data = data;
3378 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3381 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3382 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3386 resp = (void *)pkt->data;
3389 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3390 resp->status, resp->event_unique_id);
3392 te_data->uid = le32_to_cpu(resp->event_unique_id);
3393 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3396 spin_lock_bh(&mvm->time_event_lock);
3397 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3398 spin_unlock_bh(&mvm->time_event_lock);
3403 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3404 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3405 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3406 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3407 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3408 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3409 struct ieee80211_channel *channel,
3410 struct ieee80211_vif *vif,
3413 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3414 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3415 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3416 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3417 struct iwl_notification_wait wait_time_event;
3418 u32 dtim_interval = vif->bss_conf.dtim_period *
3419 vif->bss_conf.beacon_int;
3421 struct iwl_hs20_roc_req aux_roc_req = {
3422 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3424 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3425 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3426 /* Set the channel info data */
3427 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3428 PHY_BAND_24 : PHY_BAND_5,
3429 .channel_info.channel = channel->hw_value,
3430 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3431 /* Set the time and duration */
3432 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3435 delay = AUX_ROC_MIN_DELAY;
3436 req_dur = MSEC_TO_TU(duration);
3439 * If we are associated we want the delay time to be at least one
3440 * dtim interval so that the FW can wait until after the DTIM and
3441 * then start the time event, this will potentially allow us to
3442 * remain off-channel for the max duration.
3443 * Since we want to use almost a whole dtim interval we would also
3444 * like the delay to be for 2-3 dtim intervals, in case there are
3445 * other time events with higher priority.
3447 if (vif->bss_conf.assoc) {
3448 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3449 /* We cannot remain off-channel longer than the DTIM interval */
3450 if (dtim_interval <= req_dur) {
3451 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3452 if (req_dur <= AUX_ROC_MIN_DURATION)
3453 req_dur = dtim_interval -
3454 AUX_ROC_MIN_SAFETY_BUFFER;
3458 aux_roc_req.duration = cpu_to_le32(req_dur);
3459 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3462 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3463 channel->hw_value, req_dur, duration, delay,
3465 /* Set the node address */
3466 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3468 lockdep_assert_held(&mvm->mutex);
3470 spin_lock_bh(&mvm->time_event_lock);
3472 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3473 spin_unlock_bh(&mvm->time_event_lock);
3478 te_data->duration = duration;
3479 te_data->id = HOT_SPOT_CMD;
3481 spin_unlock_bh(&mvm->time_event_lock);
3484 * Use a notification wait, which really just processes the
3485 * command response and doesn't wait for anything, in order
3486 * to be able to process the response and get the UID inside
3487 * the RX path. Using CMD_WANT_SKB doesn't work because it
3488 * stores the buffer and then wakes up this thread, by which
3489 * time another notification (that the time event started)
3490 * might already be processed unsuccessfully.
3492 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3493 time_event_response,
3494 ARRAY_SIZE(time_event_response),
3495 iwl_mvm_rx_aux_roc, te_data);
3497 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3501 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3502 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3506 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3507 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3508 /* should never fail */
3513 spin_lock_bh(&mvm->time_event_lock);
3514 iwl_mvm_te_clear_data(mvm, te_data);
3515 spin_unlock_bh(&mvm->time_event_lock);
3521 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3522 struct ieee80211_vif *vif,
3523 struct ieee80211_channel *channel,
3525 enum ieee80211_roc_type type)
3527 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3528 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3529 struct cfg80211_chan_def chandef;
3530 struct iwl_mvm_phy_ctxt *phy_ctxt;
3533 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3537 * Flush the done work, just in case it's still pending, so that
3538 * the work it does can complete and we can accept new frames.
3540 flush_work(&mvm->roc_done_wk);
3542 mutex_lock(&mvm->mutex);
3544 switch (vif->type) {
3545 case NL80211_IFTYPE_STATION:
3546 if (fw_has_capa(&mvm->fw->ucode_capa,
3547 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3548 /* Use aux roc framework (HS20) */
3549 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3553 IWL_ERR(mvm, "hotspot not supported\n");
3556 case NL80211_IFTYPE_P2P_DEVICE:
3560 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3565 for (i = 0; i < NUM_PHY_CTX; i++) {
3566 phy_ctxt = &mvm->phy_ctxts[i];
3567 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3570 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3572 * Unbind the P2P_DEVICE from the current PHY context,
3573 * and if the PHY context is not used remove it.
3575 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3576 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3579 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3581 /* Bind the P2P_DEVICE to the current PHY Context */
3582 mvmvif->phy_ctxt = phy_ctxt;
3584 ret = iwl_mvm_binding_add_vif(mvm, vif);
3585 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3588 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3589 goto schedule_time_event;
3593 /* Need to update the PHY context only if the ROC channel changed */
3594 if (channel == mvmvif->phy_ctxt->channel)
3595 goto schedule_time_event;
3597 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3600 * Change the PHY context configuration as it is currently referenced
3601 * only by the P2P Device MAC
3603 if (mvmvif->phy_ctxt->ref == 1) {
3604 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3610 * The PHY context is shared with other MACs. Need to remove the
3611 * P2P Device from the binding, allocate an new PHY context and
3612 * create a new binding
3614 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3620 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3623 IWL_ERR(mvm, "Failed to change PHY context\n");
3627 /* Unbind the P2P_DEVICE from the current PHY context */
3628 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3629 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3632 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3634 /* Bind the P2P_DEVICE to the new allocated PHY context */
3635 mvmvif->phy_ctxt = phy_ctxt;
3637 ret = iwl_mvm_binding_add_vif(mvm, vif);
3638 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3641 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3644 schedule_time_event:
3645 /* Schedule the time events */
3646 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3649 mutex_unlock(&mvm->mutex);
3650 IWL_DEBUG_MAC80211(mvm, "leave\n");
3654 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3656 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3658 IWL_DEBUG_MAC80211(mvm, "enter\n");
3660 mutex_lock(&mvm->mutex);
3661 iwl_mvm_stop_roc(mvm);
3662 mutex_unlock(&mvm->mutex);
3664 IWL_DEBUG_MAC80211(mvm, "leave\n");
3668 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3669 struct ieee80211_chanctx_conf *ctx)
3671 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3672 struct iwl_mvm_phy_ctxt *phy_ctxt;
3675 lockdep_assert_held(&mvm->mutex);
3677 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3679 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3685 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3686 ctx->rx_chains_static,
3687 ctx->rx_chains_dynamic);
3689 IWL_ERR(mvm, "Failed to add PHY context\n");
3693 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3694 *phy_ctxt_id = phy_ctxt->id;
3699 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3700 struct ieee80211_chanctx_conf *ctx)
3702 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3705 mutex_lock(&mvm->mutex);
3706 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3707 mutex_unlock(&mvm->mutex);
3712 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3713 struct ieee80211_chanctx_conf *ctx)
3715 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3716 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3718 lockdep_assert_held(&mvm->mutex);
3720 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3723 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3724 struct ieee80211_chanctx_conf *ctx)
3726 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3728 mutex_lock(&mvm->mutex);
3729 __iwl_mvm_remove_chanctx(mvm, ctx);
3730 mutex_unlock(&mvm->mutex);
3733 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3734 struct ieee80211_chanctx_conf *ctx,
3737 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3738 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3739 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3741 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3742 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3743 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3744 IEEE80211_CHANCTX_CHANGE_RADAR |
3745 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3746 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3747 phy_ctxt->ref, changed))
3750 mutex_lock(&mvm->mutex);
3752 /* we are only changing the min_width, may be a noop */
3753 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3754 if (phy_ctxt->width == ctx->min_def.width)
3757 /* we are just toggling between 20_NOHT and 20 */
3758 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3759 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3763 iwl_mvm_bt_coex_vif_change(mvm);
3764 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3765 ctx->rx_chains_static,
3766 ctx->rx_chains_dynamic);
3769 mutex_unlock(&mvm->mutex);
3772 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3773 struct ieee80211_vif *vif,
3774 struct ieee80211_chanctx_conf *ctx,
3775 bool switching_chanctx)
3777 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3778 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3779 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3782 lockdep_assert_held(&mvm->mutex);
3784 mvmvif->phy_ctxt = phy_ctxt;
3786 switch (vif->type) {
3787 case NL80211_IFTYPE_AP:
3788 /* only needed if we're switching chanctx (i.e. during CSA) */
3789 if (switching_chanctx) {
3790 mvmvif->ap_ibss_active = true;
3793 case NL80211_IFTYPE_ADHOC:
3795 * The AP binding flow is handled as part of the start_ap flow
3796 * (in bss_info_changed), similarly for IBSS.
3800 case NL80211_IFTYPE_STATION:
3801 mvmvif->csa_bcn_pending = false;
3803 case NL80211_IFTYPE_MONITOR:
3804 /* always disable PS when a monitor interface is active */
3805 mvmvif->ps_disabled = true;
3812 ret = iwl_mvm_binding_add_vif(mvm, vif);
3817 * Power state must be updated before quotas,
3818 * otherwise fw will complain.
3820 iwl_mvm_power_update_mac(mvm);
3822 /* Setting the quota at this stage is only required for monitor
3823 * interfaces. For the other types, the bss_info changed flow
3824 * will handle quota settings.
3826 if (vif->type == NL80211_IFTYPE_MONITOR) {
3827 mvmvif->monitor_active = true;
3828 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3830 goto out_remove_binding;
3832 ret = iwl_mvm_add_snif_sta(mvm, vif);
3834 goto out_remove_binding;
3838 /* Handle binding during CSA */
3839 if (vif->type == NL80211_IFTYPE_AP) {
3840 iwl_mvm_update_quotas(mvm, false, NULL);
3841 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3844 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3845 u32 duration = 3 * vif->bss_conf.beacon_int;
3847 /* iwl_mvm_protect_session() reads directly from the
3848 * device (the system time), so make sure it is
3851 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3853 goto out_remove_binding;
3855 /* Protect the session to make sure we hear the first
3856 * beacon on the new channel.
3858 mvmvif->csa_bcn_pending = true;
3859 iwl_mvm_protect_session(mvm, vif, duration, duration,
3860 vif->bss_conf.beacon_int / 2,
3863 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3865 iwl_mvm_update_quotas(mvm, false, NULL);
3871 iwl_mvm_binding_remove_vif(mvm, vif);
3872 iwl_mvm_power_update_mac(mvm);
3875 mvmvif->phy_ctxt = NULL;
3878 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3879 struct ieee80211_vif *vif,
3880 struct ieee80211_chanctx_conf *ctx)
3882 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3885 mutex_lock(&mvm->mutex);
3886 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3887 mutex_unlock(&mvm->mutex);
3892 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3893 struct ieee80211_vif *vif,
3894 struct ieee80211_chanctx_conf *ctx,
3895 bool switching_chanctx)
3897 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3898 struct ieee80211_vif *disabled_vif = NULL;
3900 lockdep_assert_held(&mvm->mutex);
3902 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3904 switch (vif->type) {
3905 case NL80211_IFTYPE_ADHOC:
3907 case NL80211_IFTYPE_MONITOR:
3908 mvmvif->monitor_active = false;
3909 mvmvif->ps_disabled = false;
3910 iwl_mvm_rm_snif_sta(mvm, vif);
3912 case NL80211_IFTYPE_AP:
3913 /* This part is triggered only during CSA */
3914 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3917 mvmvif->csa_countdown = false;
3919 /* Set CS bit on all the stations */
3920 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3922 /* Save blocked iface, the timeout is set on the next beacon */
3923 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3925 mvmvif->ap_ibss_active = false;
3927 case NL80211_IFTYPE_STATION:
3928 if (!switching_chanctx)
3933 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3939 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3940 iwl_mvm_binding_remove_vif(mvm, vif);
3943 mvmvif->phy_ctxt = NULL;
3944 iwl_mvm_power_update_mac(mvm);
3947 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3948 struct ieee80211_vif *vif,
3949 struct ieee80211_chanctx_conf *ctx)
3951 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3953 mutex_lock(&mvm->mutex);
3954 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3955 mutex_unlock(&mvm->mutex);
3959 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3960 struct ieee80211_vif_chanctx_switch *vifs)
3964 mutex_lock(&mvm->mutex);
3965 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3966 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3968 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3970 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3974 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3978 "failed to assign new_ctx during channel switch\n");
3982 /* we don't support TDLS during DCM - can be caused by channel switch */
3983 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3984 iwl_mvm_teardown_tdls_peers(mvm);
3989 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3992 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3993 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3997 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3999 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4006 /* things keep failing, better restart the hw */
4007 iwl_mvm_nic_restart(mvm, false);
4010 mutex_unlock(&mvm->mutex);
4016 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4017 struct ieee80211_vif_chanctx_switch *vifs)
4021 mutex_lock(&mvm->mutex);
4022 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4024 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4028 "failed to assign new_ctx during channel switch\n");
4035 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4037 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4044 /* things keep failing, better restart the hw */
4045 iwl_mvm_nic_restart(mvm, false);
4048 mutex_unlock(&mvm->mutex);
4053 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4054 struct ieee80211_vif_chanctx_switch *vifs,
4056 enum ieee80211_chanctx_switch_mode mode)
4058 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4061 /* we only support a single-vif right now */
4066 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4067 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4069 case CHANCTX_SWMODE_REASSIGN_VIF:
4070 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4080 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4082 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4084 return mvm->ibss_manager;
4087 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4088 struct ieee80211_sta *sta,
4091 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4092 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4094 if (!mvm_sta || !mvm_sta->vif) {
4095 IWL_ERR(mvm, "Station is not associated to a vif\n");
4099 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4102 #ifdef CONFIG_NL80211_TESTMODE
4103 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4104 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4105 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4106 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4109 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4110 struct ieee80211_vif *vif,
4111 void *data, int len)
4113 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4117 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4122 if (!tb[IWL_MVM_TM_ATTR_CMD])
4125 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4126 case IWL_MVM_TM_CMD_SET_NOA:
4127 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4128 !vif->bss_conf.enable_beacon ||
4129 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4132 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4133 if (noa_duration >= vif->bss_conf.beacon_int)
4136 mvm->noa_duration = noa_duration;
4139 return iwl_mvm_update_quotas(mvm, true, NULL);
4140 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4141 /* must be associated client vif - ignore authorized */
4142 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4143 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4144 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4147 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4148 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4149 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4155 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4156 struct ieee80211_vif *vif,
4157 void *data, int len)
4159 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4162 mutex_lock(&mvm->mutex);
4163 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4164 mutex_unlock(&mvm->mutex);
4170 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4171 struct ieee80211_vif *vif,
4172 struct ieee80211_channel_switch *chsw)
4174 /* By implementing this operation, we prevent mac80211 from
4175 * starting its own channel switch timer, so that we can call
4176 * ieee80211_chswitch_done() ourselves at the right time
4177 * (which is when the absence time event starts).
4180 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4181 "dummy channel switch op\n");
4184 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4185 struct ieee80211_vif *vif,
4186 struct ieee80211_channel_switch *chsw)
4188 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4189 struct ieee80211_vif *csa_vif;
4190 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4194 mutex_lock(&mvm->mutex);
4196 mvmvif->csa_failed = false;
4198 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4199 chsw->chandef.center_freq1);
4201 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4202 ieee80211_vif_to_wdev(vif),
4203 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4205 switch (vif->type) {
4206 case NL80211_IFTYPE_AP:
4208 rcu_dereference_protected(mvm->csa_vif,
4209 lockdep_is_held(&mvm->mutex));
4210 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4211 "Another CSA is already in progress")) {
4216 /* we still didn't unblock tx. prevent new CS meanwhile */
4217 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4218 lockdep_is_held(&mvm->mutex))) {
4223 rcu_assign_pointer(mvm->csa_vif, vif);
4225 if (WARN_ONCE(mvmvif->csa_countdown,
4226 "Previous CSA countdown didn't complete")) {
4231 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4234 case NL80211_IFTYPE_STATION:
4235 /* Schedule the time event to a bit before beacon 1,
4236 * to make sure we're in the new channel when the
4237 * GO/AP arrives. In case count <= 1 immediately schedule the
4238 * TE (this might result with some packet loss or connection
4241 if (chsw->count <= 1)
4244 apply_time = chsw->device_timestamp +
4245 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4246 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4249 iwl_mvm_csa_client_absent(mvm, vif);
4251 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4253 if (mvmvif->bf_data.bf_enabled) {
4254 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4264 mvmvif->ps_disabled = true;
4266 ret = iwl_mvm_power_update_ps(mvm);
4270 /* we won't be on this channel any longer */
4271 iwl_mvm_teardown_tdls_peers(mvm);
4274 mutex_unlock(&mvm->mutex);
4279 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4280 struct ieee80211_vif *vif)
4282 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4283 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4286 mutex_lock(&mvm->mutex);
4288 if (mvmvif->csa_failed) {
4289 mvmvif->csa_failed = false;
4294 if (vif->type == NL80211_IFTYPE_STATION) {
4295 struct iwl_mvm_sta *mvmsta;
4297 mvmvif->csa_bcn_pending = false;
4298 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4301 if (WARN_ON(!mvmsta)) {
4306 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4308 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4310 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4314 iwl_mvm_stop_session_protection(mvm, vif);
4317 mvmvif->ps_disabled = false;
4319 ret = iwl_mvm_power_update_ps(mvm);
4322 mutex_unlock(&mvm->mutex);
4327 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4331 if (!iwl_mvm_has_new_tx_api(mvm)) {
4333 mutex_lock(&mvm->mutex);
4334 iwl_mvm_flush_tx_path(mvm,
4335 iwl_mvm_flushable_queues(mvm) & queues, 0);
4336 mutex_unlock(&mvm->mutex);
4338 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4343 mutex_lock(&mvm->mutex);
4344 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4345 struct ieee80211_sta *sta;
4347 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4348 lockdep_is_held(&mvm->mutex));
4349 if (IS_ERR_OR_NULL(sta))
4353 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4355 iwl_mvm_wait_sta_queues_empty(mvm,
4356 iwl_mvm_sta_from_mac80211(sta));
4358 mutex_unlock(&mvm->mutex);
4361 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4362 struct ieee80211_vif *vif, u32 queues, bool drop)
4364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4365 struct iwl_mvm_vif *mvmvif;
4366 struct iwl_mvm_sta *mvmsta;
4367 struct ieee80211_sta *sta;
4372 iwl_mvm_flush_no_vif(mvm, queues, drop);
4376 if (vif->type != NL80211_IFTYPE_STATION)
4379 /* Make sure we're done with the deferred traffic before flushing */
4380 flush_work(&mvm->add_stream_wk);
4382 mutex_lock(&mvm->mutex);
4383 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4385 /* flush the AP-station and all TDLS peers */
4386 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4387 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4388 lockdep_is_held(&mvm->mutex));
4389 if (IS_ERR_OR_NULL(sta))
4392 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4393 if (mvmsta->vif != vif)
4396 /* make sure only TDLS peers or the AP are flushed */
4397 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4400 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4401 IWL_ERR(mvm, "flush request fail\n");
4403 msk |= mvmsta->tfd_queue_msk;
4404 if (iwl_mvm_has_new_tx_api(mvm))
4405 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4409 mutex_unlock(&mvm->mutex);
4411 /* this can take a while, and we may need/want other operations
4412 * to succeed while doing this, so do it without the mutex held
4414 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4415 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4418 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4419 struct survey_info *survey)
4421 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4424 memset(survey, 0, sizeof(*survey));
4426 /* only support global statistics right now */
4430 if (!fw_has_capa(&mvm->fw->ucode_capa,
4431 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4434 mutex_lock(&mvm->mutex);
4436 if (iwl_mvm_firmware_running(mvm)) {
4437 ret = iwl_mvm_request_statistics(mvm, false);
4442 survey->filled = SURVEY_INFO_TIME |
4443 SURVEY_INFO_TIME_RX |
4444 SURVEY_INFO_TIME_TX |
4445 SURVEY_INFO_TIME_SCAN;
4446 survey->time = mvm->accu_radio_stats.on_time_rf +
4447 mvm->radio_stats.on_time_rf;
4448 do_div(survey->time, USEC_PER_MSEC);
4450 survey->time_rx = mvm->accu_radio_stats.rx_time +
4451 mvm->radio_stats.rx_time;
4452 do_div(survey->time_rx, USEC_PER_MSEC);
4454 survey->time_tx = mvm->accu_radio_stats.tx_time +
4455 mvm->radio_stats.tx_time;
4456 do_div(survey->time_tx, USEC_PER_MSEC);
4458 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4459 mvm->radio_stats.on_time_scan;
4460 do_div(survey->time_scan, USEC_PER_MSEC);
4464 mutex_unlock(&mvm->mutex);
4468 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4469 struct ieee80211_vif *vif,
4470 struct ieee80211_sta *sta,
4471 struct station_info *sinfo)
4473 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4474 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4475 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4477 if (mvmsta->avg_energy) {
4478 sinfo->signal_avg = mvmsta->avg_energy;
4479 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4482 /* if beacon filtering isn't on mac80211 does it anyway */
4483 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4486 if (!vif->bss_conf.assoc)
4489 mutex_lock(&mvm->mutex);
4491 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4494 if (iwl_mvm_request_statistics(mvm, false))
4497 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4498 mvmvif->beacon_stats.accu_num_beacons;
4499 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4500 if (mvmvif->beacon_stats.avg_signal) {
4501 /* firmware only reports a value after RXing a few beacons */
4502 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4503 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4506 mutex_unlock(&mvm->mutex);
4509 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4510 struct ieee80211_vif *vif,
4511 const struct ieee80211_event *event)
4513 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4515 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4517 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4520 struct iwl_fw_dbg_trigger_tlv *trig;
4521 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4523 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4524 FW_DBG_TRIGGER_MLME);
4528 trig_mlme = (void *)trig->data;
4530 if (event->u.mlme.data == ASSOC_EVENT) {
4531 if (event->u.mlme.status == MLME_DENIED)
4532 CHECK_MLME_TRIGGER(stop_assoc_denied,
4533 "DENIED ASSOC: reason %d",
4534 event->u.mlme.reason);
4535 else if (event->u.mlme.status == MLME_TIMEOUT)
4536 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4538 } else if (event->u.mlme.data == AUTH_EVENT) {
4539 if (event->u.mlme.status == MLME_DENIED)
4540 CHECK_MLME_TRIGGER(stop_auth_denied,
4541 "DENIED AUTH: reason %d",
4542 event->u.mlme.reason);
4543 else if (event->u.mlme.status == MLME_TIMEOUT)
4544 CHECK_MLME_TRIGGER(stop_auth_timeout,
4546 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4547 CHECK_MLME_TRIGGER(stop_rx_deauth,
4548 "DEAUTH RX %d", event->u.mlme.reason);
4549 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4550 CHECK_MLME_TRIGGER(stop_tx_deauth,
4551 "DEAUTH TX %d", event->u.mlme.reason);
4553 #undef CHECK_MLME_TRIGGER
4556 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4557 struct ieee80211_vif *vif,
4558 const struct ieee80211_event *event)
4560 struct iwl_fw_dbg_trigger_tlv *trig;
4561 struct iwl_fw_dbg_trigger_ba *ba_trig;
4563 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4568 ba_trig = (void *)trig->data;
4570 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4573 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4574 "BAR received from %pM, tid %d, ssn %d",
4575 event->u.ba.sta->addr, event->u.ba.tid,
4579 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4580 struct ieee80211_vif *vif,
4581 const struct ieee80211_event *event)
4583 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4585 switch (event->type) {
4587 iwl_mvm_event_mlme_callback(mvm, vif, event);
4590 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4592 case BA_FRAME_TIMEOUT:
4593 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4601 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4602 struct iwl_mvm_internal_rxq_notif *notif,
4605 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4608 lockdep_assert_held(&mvm->mutex);
4610 if (!iwl_mvm_has_new_rx_api(mvm))
4613 notif->cookie = mvm->queue_sync_cookie;
4616 atomic_set(&mvm->queue_sync_counter,
4617 mvm->trans->num_rx_queues);
4619 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4621 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4626 ret = wait_event_timeout(mvm->rx_sync_waitq,
4627 atomic_read(&mvm->queue_sync_counter) == 0 ||
4628 iwl_mvm_is_radio_killed(mvm),
4630 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4634 atomic_set(&mvm->queue_sync_counter, 0);
4635 mvm->queue_sync_cookie++;
4638 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4640 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4641 struct iwl_mvm_internal_rxq_notif data = {
4642 .type = IWL_MVM_RXQ_EMPTY,
4646 mutex_lock(&mvm->mutex);
4647 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4648 mutex_unlock(&mvm->mutex);
4651 const struct ieee80211_ops iwl_mvm_hw_ops = {
4652 .tx = iwl_mvm_mac_tx,
4653 .ampdu_action = iwl_mvm_mac_ampdu_action,
4654 .start = iwl_mvm_mac_start,
4655 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4656 .stop = iwl_mvm_mac_stop,
4657 .add_interface = iwl_mvm_mac_add_interface,
4658 .remove_interface = iwl_mvm_mac_remove_interface,
4659 .config = iwl_mvm_mac_config,
4660 .prepare_multicast = iwl_mvm_prepare_multicast,
4661 .configure_filter = iwl_mvm_configure_filter,
4662 .config_iface_filter = iwl_mvm_config_iface_filter,
4663 .bss_info_changed = iwl_mvm_bss_info_changed,
4664 .hw_scan = iwl_mvm_mac_hw_scan,
4665 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4666 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4667 .sta_state = iwl_mvm_mac_sta_state,
4668 .sta_notify = iwl_mvm_mac_sta_notify,
4669 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4670 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4671 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4672 .sta_rc_update = iwl_mvm_sta_rc_update,
4673 .conf_tx = iwl_mvm_mac_conf_tx,
4674 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4675 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4676 .flush = iwl_mvm_mac_flush,
4677 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4678 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4679 .set_key = iwl_mvm_mac_set_key,
4680 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4681 .remain_on_channel = iwl_mvm_roc,
4682 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4683 .add_chanctx = iwl_mvm_add_chanctx,
4684 .remove_chanctx = iwl_mvm_remove_chanctx,
4685 .change_chanctx = iwl_mvm_change_chanctx,
4686 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4687 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4688 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4690 .start_ap = iwl_mvm_start_ap_ibss,
4691 .stop_ap = iwl_mvm_stop_ap_ibss,
4692 .join_ibss = iwl_mvm_start_ap_ibss,
4693 .leave_ibss = iwl_mvm_stop_ap_ibss,
4695 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4697 .set_tim = iwl_mvm_set_tim,
4699 .channel_switch = iwl_mvm_channel_switch,
4700 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4701 .post_channel_switch = iwl_mvm_post_channel_switch,
4703 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4704 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4705 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4707 .event_callback = iwl_mvm_mac_event_callback,
4709 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4711 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4713 #ifdef CONFIG_PM_SLEEP
4715 .suspend = iwl_mvm_suspend,
4716 .resume = iwl_mvm_resume,
4717 .set_wakeup = iwl_mvm_set_wakeup,
4718 .set_rekey_data = iwl_mvm_set_rekey_data,
4719 #if IS_ENABLED(CONFIG_IPV6)
4720 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4722 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4724 .get_survey = iwl_mvm_mac_get_survey,
4725 .sta_statistics = iwl_mvm_mac_sta_statistics,
4726 #ifdef CONFIG_IWLWIFI_DEBUGFS
4727 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,